AgentTools.Class.php 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614
  1. <?php
  2. namespace Util\Common;
  3. use Mall\Framework\Factory;
  4. use JinDouYun\Dao\Customer\DCustomer;
  5. use JinDouYun\Dao\UserCenter\DUserCenter;
  6. use JinDouYun\Cache\CustomerCache;
  7. use JinDouYun\Dao\Order\DOrderIndex;
  8. use JinDouYun\Dao\Order\DOrder;
  9. use JinDouYun\Dao\Shop\DShop;
  10. use JinDouYun\Dao\Purchase\DPurchase;
  11. use JinDouYun\Dao\CommissionPartner\DNewAgentBalanceDetail;
  12. use JinDouYun\Dao\CommissionPartner\DNewAgentCash;
  13. use JinDouYun\Dao\CommissionPartner\DNewAgentDetail;
  14. use JinDouYun\Dao\CommissionPartner\DNewAgent;
  15. use JinDouYun\Dao\CommissionPartner\DNewAgentTask;
  16. use JinDouYun\Dao\CommissionPartner\DNewAgentSetting;
  17. class AgentTools{
  18. private $dbCustomer;
  19. private $dbUserCenter;
  20. private $dbShop;
  21. private $dbPurchase;
  22. private $dbNewAgent;
  23. private $dbNewAgentDetail;
  24. private $dbNewAgentCash;
  25. private $dbNewAgentBalanceDetail;
  26. private $dbNewAgentTask;
  27. private $dbNewAgentSetting;
  28. private $enterpriseId;
  29. private $cache;
  30. private $cutTable = 1;//客户按照企业id分表
  31. private $agentSettingData = null;
  32. private $codeAr = [
  33. "purchase_calc"=>"采购单完成分佣",
  34. "agent_calc"=>"子级代理收益分佣",
  35. "cash_balance"=>"门店代理余额提现",
  36. "cash_no_balance"=>"提现驳回返还余额",
  37. ];
  38. public function __construct($enterpriseId){
  39. $this->enterpriseId = $enterpriseId;
  40. $this->cache = Factory::cache('systask');
  41. //用户表
  42. $this->dbCustomer = new DCustomer('default');
  43. $customerTableName = $this->dbCustomer->getTableName($this->dbCustomer->get_Table(), $this->enterpriseId, $this->cutTable);
  44. $this->dbCustomer->setTable($customerTableName);
  45. //用户账号表
  46. $this->dbUserCenter = new DUserCenter();
  47. //设置表
  48. $this->dbNewAgentSetting = new DNewAgentSetting('default');
  49. $this->agentSettingData = $this->dbNewAgentSetting->get(["enterpriseId"=>$this->enterpriseId]);
  50. //门店表
  51. $this->dbShop = new DShop();
  52. $this->dbShop->setTable('qianniao_shop_1');
  53. //采购单表
  54. $this->dbPurchase = new DPurchase();
  55. $this->dbPurchase->setTable('qianniao_purchase_'.$this->enterpriseId);
  56. //新分销门店代理表
  57. $this->dbNewAgent = new DNewAgent('default');
  58. $newCommissionPartnerTableName = $this->dbNewAgent->getTableName($this->dbNewAgent->get_Table(), $this->enterpriseId, $this->cutTable);
  59. $this->dbNewAgent->setTable($newCommissionPartnerTableName);
  60. //新分销佣金明细表
  61. $this->dbNewAgentDetail = new DNewAgentDetail('default');
  62. $newCommissionDetailTableName = $this->dbNewAgentDetail->getTableName($this->dbNewAgentDetail->get_Table(), $this->enterpriseId, $this->cutTable);
  63. $this->dbNewAgentDetail->setTable($newCommissionDetailTableName);
  64. //新分销门店代理提现表
  65. $this->dbNewAgentCash = new DNewAgentCash('default');
  66. $newCommissionCashTableName = $this->dbNewAgentCash->getTableName($this->dbNewAgentCash->get_Table(), $this->enterpriseId, $this->cutTable);
  67. $this->dbNewAgentCash->setTable($newCommissionCashTableName);
  68. //新分销门店代理余额明细表
  69. $this->dbNewAgentBalanceDetail = new DNewAgentBalanceDetail('default');
  70. $newCommissionBalanceDetailTableName = $this->dbNewAgentBalanceDetail->getTableName($this->dbNewAgentBalanceDetail->get_Table(), $this->enterpriseId, $this->cutTable);
  71. $this->dbNewAgentBalanceDetail->setTable($newCommissionBalanceDetailTableName);
  72. //新分销门店代理分佣任务表
  73. $this->dbNewAgentTask = new DNewAgentTask('default');
  74. $newCommissionTaskTableName = $this->dbNewAgentTask->getTableName($this->dbNewAgentTask->get_Table(), $this->enterpriseId, $this->cutTable);
  75. $this->dbNewAgentTask->setTable($newCommissionTaskTableName);
  76. }
  77. public function cacheTest(){
  78. $key = "agenttaskcache".'::'.$this->enterpriseId;
  79. $result = $this->cache->get($key);
  80. if(!empty($result)){
  81. return "重复操作";
  82. }
  83. $this->cache->set($key,1,10);
  84. return "开始执行操作";
  85. }
  86. /**
  87. * 门店推荐
  88. */
  89. public function pushShop($parentShopId=0,$childShopId=0){
  90. if($parentShopId == 0 || $childShopId == 0 || $parentShopId == $childShopId){
  91. return ["code"=>-1,"msg"=>"参数错误","data"=>null];
  92. }
  93. //子级门店
  94. $childShopData = $this->dbShop->get($childShopId);
  95. if(empty($childShopData)){
  96. return ["code"=>-1,"msg"=>"子门店不存在","data"=>null];
  97. }
  98. if($childShopData["level"]>0){
  99. return ["code"=>-1,"msg"=>"当前门店不能被绑定为子级门店","data"=>null];
  100. }
  101. if(!empty($childShopData["pTwoShopId"])){
  102. return ["code"=>-1,"msg"=>"子门店已被其他门店绑定","data"=>null];
  103. }
  104. //父级门店
  105. $parentShopData = $this->dbShop->get($parentShopId);
  106. if(empty($parentShopData)){
  107. return ["code"=>-1,"msg"=>"父门店不存在","data"=>null];
  108. }
  109. $pOneShopId = 0;
  110. $pTwoShopId = $parentShopId;
  111. if(!$parentShopData["pTwoShopId"]){
  112. $pOneShopId = $parentShopData["pTwoShopId"];
  113. }
  114. $parentShopData["parentPath"] = empty($parentShopData["parentPath"])?"": trim($parentShopData["parentPath"]);
  115. $parentPath = empty($parentShopData["parentPath"]) ? $parentShopId : $parentShopData["parentPath"] . "," . $parentShopId;
  116. //更新子级门店数据
  117. $save=[
  118. "level"=>1,//门店级别,1为社区门店,2为代理门店,3为董事门店
  119. "pOneShopId"=>$pOneShopId,//爷爷级门店id
  120. "pTwoShopId"=>$pTwoShopId,//父级门店id
  121. "parentPath"=>$parentPath,//推广路径
  122. ];
  123. $this->dbShop->update($save,["id"=>$childShopId]);
  124. //如果父级门店没绑定过其他子级则更新为1级社区门店
  125. if($parentShopData["level"]<=0){
  126. $this->dbShop->update(["level"=>1],["id"=>$parentShopId]);
  127. }
  128. //更新祖先等级
  129. $this->updateParentShopLevel($childShopId);
  130. return ["code"=>1,"msg"=>"绑定成功","data"=>null];
  131. }
  132. /**
  133. * 【新】更新父级门店等级
  134. * @param type $shopId
  135. * @param type $type 0表示只算两级,1表示算无限极
  136. */
  137. public function updateParentShopLevel($shopId,$type=1){
  138. //子级门店
  139. $shopData = $this->dbShop->get($shopId);
  140. if(empty($shopData) || empty($shopData["parentPath"])){
  141. return false;
  142. }
  143. //从最底层开始更新等级
  144. $pathData = array_reverse(explode(",", trim($shopData["parentPath"])));
  145. $shopList = $this->dbShop->select([["id","in",$pathData]]);
  146. $shopTableName = "qianniao_shop_1";
  147. for($i=0;$i<count($pathData);$i++){
  148. if(empty($pathData[$i])){
  149. continue;
  150. }
  151. $pData=null;
  152. // $pData = $this->dbShop->get((int)$pathData[$i]);
  153. foreach($shopList as $k=>$v){
  154. if($v["id"]==(int)$pathData[$i]){
  155. $pData = $v;
  156. break;
  157. }
  158. }
  159. if(empty($pData)){
  160. continue;
  161. }
  162. if($pData["level"]>=3){
  163. continue;
  164. }
  165. $level = 1;
  166. $levelCount_1 = 0;
  167. $levelCount_2 = 0;
  168. //查询数据
  169. if($type==1){
  170. //无限级查询
  171. $sql1 = "select count(*) as count from {$shopTableName} where level = 1 and FIND_IN_SET(". intval($pData["id"]).",parentPath)";
  172. $countData1 = $this->dbShop->query($sql1);
  173. if(!empty($countData1)){
  174. $levelCount_1 =array_shift($countData1)['count'];//子级社区门店数
  175. }
  176. $sql2 = "select count(*) as count from {$shopTableName} where level = 2 and FIND_IN_SET(". intval($pData["id"]).",parentPath)";
  177. $countData2 = $this->dbShop->query($sql2);
  178. if(!empty($countData2)){
  179. $levelCount_2 =array_shift($countData2)['count'];//子级代理门店数
  180. }
  181. }else{
  182. //只查两级
  183. $levelCount_1 = $this->dbShop->count([["level","=",1],["pOneShopId|pTwoShopId","=",$pData["id"]]]);//子级社区门店数
  184. $levelCount_2 = $this->dbShop->count([["level","=",2],["pOneShopId|pTwoShopId","=",$pData["id"]]]);//子级代理门店数
  185. }
  186. if($levelCount_1 && $this->agentSettingData["oneToTwoNum"]>0 && $levelCount_1>=$this->agentSettingData["oneToTwoNum"]){
  187. $level = 2;//5个升级为代理
  188. }
  189. if($levelCount_2 && $this->agentSettingData["twoToThreeNum"]>0 && $levelCount_2>=$this->agentSettingData["twoToThreeNum"]){
  190. $level = 3;//5个代理升级为董事
  191. }
  192. if($level<=$pData["level"]){
  193. continue;
  194. }
  195. $r = $this->dbShop->update(["level"=>$level],["id"=>$pData["id"]]);
  196. }
  197. return true;
  198. }
  199. /**
  200. * 更新门店等级
  201. * @param type $shopId
  202. */
  203. public function updateShopLevel($shopId){
  204. if(empty($shopId)){
  205. return false;
  206. }
  207. $shopData = $this->dbShop->get($shopId);
  208. if(empty($shopData) || $shopData["level"]==3 || $shopData["level"]==0){
  209. return false;
  210. }
  211. //父级下的社区店数
  212. $level = 1;
  213. $levelCount_1 = $this->dbShop->count([["level","=",1],["pOneShopId|pTwoShopId","=",$shopId]]);
  214. if($levelCount_1 && $levelCount_1>=$this->agentSettingData["oneToTwoNum"]){
  215. $level = 2;//5个升级为代理
  216. }
  217. //父级下的代理店数
  218. $levelCount_2 = $this->dbShop->count([["level","=",2],["pOneShopId|pTwoShopId","=",$shopId]]);
  219. if($levelCount_2 && $levelCount_2>=$this->agentSettingData["twoToThreeNum"]){
  220. $level = 3;//5个代理升级为董事
  221. }
  222. if($level<=$shopData["level"]){
  223. return false;
  224. }
  225. //更新门店等级
  226. $r = $this->dbShop->update(["level"=>$level],["id"=>$shopId]);
  227. if(empty($r)){
  228. return fasle;
  229. }
  230. return true;
  231. }
  232. /**
  233. * 【新】门店推广添加任务
  234. * @param type $purchaseId
  235. * @param type $enterpriseId
  236. * @return bool
  237. */
  238. public static function addTaskNew($purchaseId,$enterpriseId){
  239. try{
  240. if(empty($purchaseId) || empty($enterpriseId)){
  241. return ["code"=>-1,"msg"=>"参数为空"];
  242. }
  243. //获取配置
  244. $dbSetting = new DNewAgentSetting('default');
  245. $settingData = $dbSetting->get(["enterpriseId"=>$enterpriseId]);
  246. if(empty($settingData) || empty($settingData["is_open"])){
  247. return ["code"=>-1,"msg"=>"还未进行分佣配置"];
  248. }
  249. //获取采购单信息
  250. $dbPurchase = new DPurchase();
  251. $dbPurchase->setTable('qianniao_purchase_'.$enterpriseId);
  252. $pwhere=[];
  253. $pwhere["id"]=$purchaseId;
  254. $pwhere["auditStatus"]=2;//审核状态
  255. $pwhere["deleteStatus"]=5;//删除状态
  256. $pwhere["inStatus"]=5;//入库状态
  257. $pwhere["purchaseType"]=4;//采购订单
  258. $purchaseData = $dbPurchase->get($pwhere);
  259. if(empty($purchaseData) || empty($purchaseData["shopId"])){
  260. return ["code"=>-1,"msg"=>"采购单不符合条件".$purchaseData["shopId"]];
  261. }
  262. //验证门店
  263. $shopDb = new DShop();
  264. $shopDb->setTable('qianniao_shop_1');
  265. $shopData = $shopDb->get(["id"=>$purchaseData["shopId"],"enterpriseId"=>$enterpriseId]);
  266. if(empty($shopData) || empty($shopData["pTwoShopId"])){
  267. return ["code"=>-1,"msg"=>"当前门店没有上级门店"];
  268. }
  269. //验证上级门店是否存在
  270. $pShopData = $shopDb->get($shopData["pTwoShopId"]);
  271. if(empty($pShopData) || empty($pShopData["agentId"])){
  272. return ["code"=>-1,"msg"=>"当前门店的上级门店数据配置错误"];
  273. }
  274. //添加任务
  275. $dbTask = new DNewAgentTask('default');
  276. $taskTableName = $dbTask->getTableName($dbTask->get_Table(), $enterpriseId, 1);
  277. $dbTask->setTable($taskTableName);
  278. //验证采购单是否已经添加过任务
  279. $count = $dbTask->count(["purchaseId"=>$purchaseId]);
  280. if($count>0){
  281. return ["code"=>-1,"msg"=>"任务采购单已存在"];
  282. }
  283. $r = $dbTask->insert([
  284. "purchaseId"=>$purchaseId,
  285. "enterpriseId"=>$enterpriseId,
  286. "title"=>"采购单完成计算分佣",
  287. "mono"=>"",
  288. "status"=>0,
  289. "run_time"=>0,
  290. "time"=>time(),
  291. ]);
  292. return ["code"=>1,"msg"=>"任务已插入[{$r}]"];
  293. } catch (\Exception $e){
  294. return ["code"=>-1,"msg"=>"系统错误"];
  295. }
  296. }
  297. /**
  298. * 添加任务
  299. * @param type $purchaseId
  300. * @param type $enterpriseId
  301. * @return bool
  302. */
  303. public static function addTask($purchaseId,$enterpriseId){
  304. try{
  305. if(empty($purchaseId) || empty($enterpriseId)){
  306. return ["code"=>-1,"msg"=>"参数为空"];
  307. }
  308. //获取配置
  309. $dbSetting = new DNewAgentSetting('default');
  310. $settingData = $dbSetting->get(["enterpriseId"=>$enterpriseId]);
  311. if(empty($settingData) || empty($settingData["is_open"]) || $settingData["incomePer"]<=0){
  312. return ["code"=>-1,"msg"=>"还未进行代理推荐分佣配置"];
  313. }
  314. //获取采购单信息
  315. $dbPurchase = new DPurchase();
  316. $dbPurchase->setTable('qianniao_purchase_'.$enterpriseId);
  317. $pwhere=[];
  318. $pwhere["id"]=$purchaseId;
  319. $pwhere["auditStatus"]=2;//审核状态
  320. $pwhere["deleteStatus"]=5;//删除状态
  321. $pwhere["inStatus"]=5;//入库状态
  322. $pwhere["purchaseType"]=4;//采购订单
  323. $purchaseData = $dbPurchase->get($pwhere);
  324. if(empty($purchaseData) || empty($purchaseData["shopId"])){
  325. return ["code"=>-1,"msg"=>"采购单不符合条件".$purchaseData["shopId"]];
  326. }
  327. //验证门店
  328. $shopDb = new DShop();
  329. $shopDb->setTable('qianniao_shop_1');
  330. $shopData = $shopDb->get(["id"=>$purchaseData["shopId"],"enterpriseId"=>$enterpriseId]);
  331. if(empty($shopData) || empty($shopData["agentId"])){
  332. return ["code"=>-1,"msg"=>"当前门店没有代理推荐"];
  333. }
  334. //添加任务
  335. $dbTask = new DNewAgentTask('default');
  336. $taskTableName = $dbTask->getTableName($dbTask->get_Table(), $enterpriseId, 1);
  337. $dbTask->setTable($taskTableName);
  338. //验证采购单是否已经添加过任务
  339. $count = $dbTask->count(["purchaseId"=>$purchaseId]);
  340. if($count>0){
  341. return ["code"=>-1,"msg"=>"任务采购单已存在"];
  342. }
  343. $r = $dbTask->insert([
  344. "purchaseId"=>$purchaseId,
  345. "enterpriseId"=>$enterpriseId,
  346. "title"=>"采购单完成计算分佣",
  347. "mono"=>"",
  348. "status"=>0,
  349. "run_time"=>0,
  350. "time"=>time(),
  351. ]);
  352. return ["code"=>1,"msg"=>"任务已插入[{$r}]"];
  353. } catch (\Exception $e){
  354. return ["code"=>-1,"msg"=>"系统错误"];
  355. }
  356. }
  357. public function runTask(){
  358. if(empty($this->agentSettingData) || empty($this->agentSettingData["is_open"])){
  359. return ["code"=>-1,"msg"=>"未开启配置"];
  360. }
  361. $key = "agenttaskcache".'::'.$this->enterpriseId;
  362. $result = $this->cache->get($key);
  363. if(!empty($result)){
  364. return ["code"=>-1,"msg"=>"操作频繁"];
  365. }
  366. $this->cache->set($key,1,10);
  367. $dbTask = new DNewAgentTask('default');
  368. $taskTableName = $dbTask->getTableName($dbTask->get_Table(), $this->enterpriseId, 1);
  369. $dbTask->setTable($taskTableName);
  370. $data = $dbTask->select(["status"=>0],"*","id asc");
  371. if(empty($data)){
  372. return ["code"=>-1,"msg"=>"没有可执行任务"];
  373. }
  374. $nowTime=time();
  375. foreach($data as $k=>$v){
  376. $res = $this->runCalcMoneyData($v["purchaseId"]);
  377. $save=[];
  378. $save=["status"=>1,"mono"=>"执行成功","run_time"=>$nowTime];
  379. if(empty($res) || $res["code"]==-1){
  380. $save["mono"] = empty($res["msg"])?"系统错误执行失败":$res["msg"];
  381. $save["status"] = -1;
  382. }
  383. $dbTask->update($save, ["id"=>$v["id"]]);
  384. }
  385. $this->cache->set($key,null);
  386. return ["code"=>1,"msg"=>"执行结束"];
  387. }
  388. /**
  389. * 【新】执行任务
  390. * @return type
  391. */
  392. public function runTaskNew(){
  393. if(empty($this->agentSettingData) || empty($this->agentSettingData["is_open"])){
  394. return ["code"=>-1,"msg"=>"未开启配置"];
  395. }
  396. $key = "agenttaskcache".'::'.$this->enterpriseId;
  397. $result = $this->cache->get($key);
  398. if(!empty($result)){
  399. return ["code"=>-1,"msg"=>"操作频繁"];
  400. }
  401. $this->cache->set($key,1,10);
  402. $dbTask = new DNewAgentTask('default');
  403. $taskTableName = $dbTask->getTableName($dbTask->get_Table(), $this->enterpriseId, 1);
  404. $dbTask->setTable($taskTableName);
  405. $data = $dbTask->select(["status"=>0],"*","id asc");
  406. if(empty($data)){
  407. return ["code"=>-1,"msg"=>"没有可执行任务"];
  408. }
  409. $nowTime=time();
  410. foreach($data as $k=>$v){
  411. $res = $this->runCalcMoneyDataNew($v["purchaseId"]);
  412. $save=[];
  413. $save=["status"=>1,"mono"=>"执行成功","run_time"=>$nowTime];
  414. if(empty($res) || $res["code"]==-1){
  415. $save["mono"] = empty($res["msg"])?"系统错误执行失败":$res["msg"];
  416. $save["status"] = -1;
  417. }
  418. $dbTask->update($save, ["id"=>$v["id"]]);
  419. }
  420. $this->cache->set($key,null);
  421. return ["code"=>1,"msg"=>"执行结束"];
  422. }
  423. /**
  424. * 设置门店推广用户
  425. * @param type $parentId
  426. * @param type $shopId
  427. * @return bool
  428. */
  429. public function setPushCustomer($agentCustomerId=0,$shopId=0){
  430. if($agentCustomerId == 0 || $shopId == 0){
  431. return ["code"=>-1,"msg"=>"参数错误","data"=>null];
  432. }
  433. //门店信息
  434. $shopData = $this->dbShop->get(["id"=>$shopId,"enterpriseId"=>$this->enterpriseId]);
  435. if(empty($shopData) || $shopData["agentId"]>0){
  436. return ["code"=>-1,"msg"=>"门店不能被绑定","data"=>$shopData];
  437. }
  438. //父级用户信息
  439. $customeerData = $this->dbCustomer->get($agentCustomerId);
  440. if(empty($customeerData)){
  441. return ["code"=>-1,"msg"=>"代理用户不存在","data"=>null];
  442. }
  443. $this->dbShop->beginTransaction();
  444. $agentData = $this->getAndSetAgentData($customeerData["id"],$customeerData["userCenterId"]);
  445. if(empty($agentData)){
  446. $this->dbShop->rollBack();
  447. return ["code"=>-1,"msg"=>"代理商账户创建失败","data"=>null];
  448. }
  449. //保存门店数据
  450. $res = $this->dbShop->update(["agentId"=>$agentData["id"],"agentCustomerId"=>$agentData["customerId"]], ["id"=>$shopId]);
  451. if(empty($res)){
  452. $this->dbShop->rollBack();
  453. return ["code"=>-1,"msg"=>"绑定失败","data"=>$childSave];
  454. }else{
  455. $this->dbShop->commit();
  456. return ["code"=>1,"msg"=>"绑定成功","data"=>null];
  457. }
  458. }
  459. /**
  460. * 获取代理信息
  461. * @param type $userCenterId
  462. */
  463. public function apiAgentInfoData($userCenterId){
  464. $agentData = $this->dbNewAgent->get(["userCenterId"=>$userCenterId]);
  465. if(empty($agentData)){
  466. return false;
  467. }
  468. $where=[];
  469. $where["agentId"]=$agentData["id"];
  470. $where["deleteStatus"]=5;
  471. $shopData = $this->dbShop->select($where,"id,name");
  472. $agentData["shopData"] = $shopData ? $shopData : [];
  473. $detailCount = $this->dbNewAgentDetail->count(["agentId"=>$agentData["id"]]);
  474. $agentData["detailCount"] = $detailCount?$detailCount:0;
  475. return $agentData;
  476. }
  477. /**
  478. * 获取代理商信息如果不存在则创建
  479. * @param type $customerId
  480. * @param type $userCenterId
  481. * @return bool
  482. */
  483. public function getAndSetAgentData($customerId,$userCenterId=0){
  484. if(empty($customerId)){
  485. return false;
  486. }
  487. if($userCenterId==-1){
  488. $customerData = $this->dbCustomer->get($customerId);
  489. if(!empty($customerData)){
  490. $userCenterId = $customerData["userCenterId"];
  491. }else{
  492. $userCenterId = 0;
  493. }
  494. }
  495. $agentData = $this->dbNewAgent->get(["customerId"=>$customerId]);
  496. if(empty($userCenterId) && empty($agentData)){
  497. return false;
  498. }
  499. if(!empty($userCenterId) && empty($agentData)){
  500. $nowTime = time();
  501. $agentData=[
  502. "userCenterId"=>$userCenterId,
  503. "customerId"=>$customerId,
  504. "balance"=>0,
  505. "waitMoney"=>0,
  506. "withdraw"=>0,
  507. "totalMoney"=>0,
  508. "deleteStatus"=>5,
  509. "createTime"=>$nowTime,
  510. "updateTime"=>$nowTime,
  511. "expand"=>"",
  512. ];
  513. $agentId = $this->dbNewAgent->insert($agentData);
  514. if(empty($agentId)){
  515. return false;
  516. }
  517. $agentData["id"] = $agentId;
  518. $agentData["purchaseNum"] = 0;
  519. }else{
  520. $agentData["purchaseNum"] = $this->getCommissionDetailCount($agentData["id"]);
  521. }
  522. return $agentData;
  523. }
  524. public function getCommissionDetailCount($agentId){
  525. if(empty($agentId) && $type=0){
  526. return 0;
  527. }
  528. $where=[];
  529. if(!empty($agentId)){
  530. $where["agentId"] = $agentId;
  531. }
  532. $count = $this->dbNewAgentDetail->count($where);
  533. return $count?$count:0;
  534. }
  535. /**
  536. * 采购单消费计算佣金
  537. * @param type $purchaseId
  538. * @param type $orderMoney
  539. * @param type $isPart 采购单用户如果是门店代理是否计算
  540. * @return bool
  541. */
  542. public function runCalcMoneyData($purchaseId){
  543. if(empty($this->agentSettingData) || empty($this->agentSettingData["is_open"])){
  544. return ["code"=>-1,"msg"=>"配置信息错误"];
  545. }
  546. //获取采购单信息
  547. if(empty($purchaseId)){
  548. return ["code"=>-1,"msg"=>"采购单id错误"];
  549. }
  550. $pwhere=[];
  551. $pwhere["id"]=$purchaseId;
  552. $pwhere["auditStatus"]=2;//审核状态
  553. $pwhere["deleteStatus"]=5;//删除状态
  554. $pwhere["inStatus"]=5;//入库状态
  555. $pwhere["purchaseType"]=4;//采购订单
  556. $purchaseData = $this->dbPurchase->get($pwhere);
  557. if(empty($purchaseData) || empty($purchaseData["shopId"])){
  558. return ["code"=>-1,"msg"=>"采购单数据不存在或不是门店采购单".$purchaseData["shopId"]];
  559. }
  560. $purchaseShopId = $purchaseData["shopId"];
  561. $shopData = $this->dbShop->get(["id"=>$purchaseShopId,"enterpriseId"=>$this->enterpriseId,"deleteStatus"=>5]);
  562. if(empty($shopData) || empty($shopData["agentId"])){
  563. return ["code"=>-1,"msg"=>"门店被删除或者没有推荐代理"];
  564. }
  565. //开始计算
  566. $purchaseAmount = $purchaseData["purchaseAmount"];//采购金额
  567. $couponAmount = $purchaseData["couponAmount"];//优惠金额
  568. $otherAmount = $purchaseData["otherAmount"];//其它金额
  569. // $purchaseMoney = $purchaseAmount;
  570. $purchaseMoney = $purchaseAmount + $otherAmount - $couponAmount;
  571. if($purchaseMoney<=0){
  572. return ["code"=>-1,"msg"=>"采购实际金额小于等于0"];
  573. }
  574. $agentData = $this->dbNewAgent->get(["id"=>$shopData["agentId"]]);
  575. if(empty($agentData)){
  576. return ["code"=>-1,"msg"=>"推荐代理账号不存在"];
  577. }
  578. $data=[];
  579. $nowTime = time();
  580. //计算收益
  581. $per = $this->agentSettingData["incomePer"];
  582. $commission = bcmul($purchaseMoney,$per,2);
  583. //记录收益
  584. $data[]=[
  585. "purchaseMoney"=>$purchaseMoney,//采购单支付金额
  586. "calcMoney"=>$purchaseMoney,//佣金计算金额
  587. "sourceShopId"=>$purchaseShopId,//来源门店id
  588. "agentId"=>$agentData["id"],//收钱门店代理账号id
  589. "customerId"=>$agentData["customerId"],//收钱门店代理
  590. "userCenterId"=>$agentData["userCenterId"],//收钱门店代理
  591. "commission"=>$commission,//佣金金额
  592. "per"=>$per,//佣金比例
  593. "type"=>0,
  594. "purchaseId"=>$purchaseData["id"],
  595. "purchaseNo"=>$purchaseData["no"],
  596. "status"=>0,//暂时不需要
  597. "title"=>"门店采购单分佣",
  598. "isUpgrade"=>0,
  599. "mono"=>"",
  600. "time"=>$nowTime,
  601. ];
  602. $num=0;
  603. //开启事务
  604. $this->dbNewAgentDetail->beginTransaction();
  605. $lms = "";
  606. foreach($data as $k=>$v){
  607. $count = $this->dbNewAgentDetail->count(["purchaseId"=>$v["purchaseId"],"agentId"=>$v["agentId"]]);
  608. if($count>0){
  609. $lms.="当前采购单已计算佣金[{$v['purchaseId']}];";
  610. continue;
  611. }
  612. $nid = $this->dbNewAgentDetail->insert($v);
  613. if(empty($nid)){
  614. $lms.="佣金明细插入失败[{$v['purchaseId']}];";
  615. continue;
  616. }
  617. //查询门店代理账户
  618. $agentItem = $this->dbNewAgent->get(["id"=>$v["agentId"]]);
  619. if(empty($agentItem)){
  620. $num = 0;
  621. $lms.="门店代理账户不存在[{$v['purchaseId']}];";
  622. break;
  623. }
  624. $update = [
  625. 'balance' => bcadd($agentItem['balance'], $v["commission"], 2),
  626. 'totalMoney' => bcadd($agentItem['totalMoney'], $v["commission"], 2),
  627. 'updateTime' => $nowTime,
  628. ];
  629. //添加账户余额明细记录
  630. $dres = $this->dbNewAgentBalanceDetail->insert([
  631. "type"=>1,
  632. "title"=>$v["title"],
  633. "code"=>$v["type"]==1 ? "agent_calc" : "purchase_calc",
  634. "money"=>$v["commission"],
  635. "content"=>$v["title"],
  636. "admin_id"=>0,
  637. "customer_id"=>$v["customerId"],
  638. "agent_id"=>$v["agentId"],
  639. "user_center_id"=>$v["userCenterId"],
  640. "cash_id"=>0,
  641. "old_balance"=>$agentItem["balance"],
  642. "now_balance"=>$update["balance"],
  643. "time"=>$nowTime,
  644. "expand"=>"",
  645. "detail_id"=>$nid,
  646. ]);
  647. if(empty($dres)){
  648. $num = 0;
  649. $lms.="账户余额明细插入失败[{$v['purchaseId']}];";
  650. break;
  651. }
  652. //更新账户余额
  653. $upRes = $this->dbNewAgent->update($update, ['id' => $v["agentId"]]);
  654. if(empty($upRes)){
  655. $num = 0;
  656. $lms.="更新账户余额失败[{$v['purchaseId']}];";
  657. break;
  658. }
  659. $num++;
  660. }
  661. if($num<=0){
  662. $this->dbNewAgentDetail->rollBack();
  663. return ["code"=>-1,"msg"=>"数据更新失败:".$lms];
  664. }
  665. $this->dbNewAgentDetail->commit();
  666. return ["code"=>1,"msg"=>"执行成功".$lms];
  667. }
  668. /**
  669. * 【新】采购单消费计算佣金
  670. * @param type $purchaseId
  671. * @param type $orderMoney
  672. * @param type $isPart 采购单用户如果是门店代理是否计算
  673. * @return bool
  674. */
  675. public function runCalcMoneyDataNew($purchaseId){
  676. if(empty($this->agentSettingData) || empty($this->agentSettingData["is_open"])){
  677. return ["code"=>-1,"msg"=>"配置信息错误"];
  678. }
  679. //获取采购单信息
  680. if(empty($purchaseId)){
  681. return ["code"=>-1,"msg"=>"采购单id错误"];
  682. }
  683. $pwhere=[];
  684. $pwhere["id"]=$purchaseId;
  685. $pwhere["auditStatus"]=2;//审核状态
  686. $pwhere["deleteStatus"]=5;//删除状态
  687. $pwhere["inStatus"]=5;//入库状态
  688. $pwhere["purchaseType"]=4;//采购订单
  689. $purchaseData = $this->dbPurchase->get($pwhere);
  690. if(empty($purchaseData) || empty($purchaseData["shopId"])){
  691. return ["code"=>-1,"msg"=>"采购单数据不存在或不是门店采购单".$purchaseData["shopId"]];
  692. }
  693. $purchaseShopId = $purchaseData["shopId"];
  694. $shopData = $this->dbShop->get(["id"=>$purchaseShopId,"enterpriseId"=>$this->enterpriseId,"deleteStatus"=>5]);
  695. if(empty($shopData) || empty($shopData["pTwoShopId"])){
  696. return ["code"=>-1,"msg"=>"门店被删除或者没有父级门店"];
  697. }
  698. //开始计算
  699. $purchaseAmount = $purchaseData["purchaseAmount"];//采购金额
  700. $couponAmount = $purchaseData["couponAmount"];//优惠金额
  701. $otherAmount = $purchaseData["otherAmount"];//其它金额
  702. // $purchaseMoney = $purchaseAmount;
  703. $purchaseMoney = $purchaseAmount + $otherAmount - $couponAmount;
  704. if($purchaseMoney<=0){
  705. return ["code"=>-1,"msg"=>"采购实际金额小于等于0"];
  706. }
  707. $data=[];
  708. $nowTime = time();
  709. $levelAr = ["xxxx","one","two"];
  710. //获取门店父级列表
  711. if(empty($shopData["parentPath"])){
  712. return ["code"=>-1,"msg"=>"门店没有父级门店"];
  713. }
  714. //从最底层开始更新等级
  715. $pathData = array_reverse(explode(",", trim($shopData["parentPath"])));
  716. $perData=[];
  717. for($i=0;$i<count($pathData);$i++){
  718. if(empty($pathData[$i])){
  719. continue;
  720. }
  721. $pData = $this->dbShop->get(["id"=>(int)$pathData[$i],"enterpriseId"=>$this->enterpriseId,"deleteStatus"=>5]);
  722. if(empty($pData) || empty($pData["agentId"])){
  723. continue;
  724. }
  725. $per = 0;
  726. if($pData["level"]==3){
  727. $per = empty($this->agentSettingData["threePer"])?0:$this->agentSettingData["threePer"];
  728. }else{
  729. $perKey = $levelAr[(int)$pData["level"]].ucfirst($levelAr[(int)$shopData["level"]])."Per";
  730. if(!empty($perKey)){
  731. $per = empty($this->agentSettingData[$perKey]) ? 0 : $this->agentSettingData[$perKey];
  732. }
  733. }
  734. if($per>0){
  735. $pmoney = bcmul($purchaseMoney,$per,2);
  736. }
  737. }
  738. //先计算父级门店
  739. $twoShopData = $this->dbShop->get(["id"=>$shopData["pTwoShopId"],"enterpriseId"=>$this->enterpriseId,"deleteStatus"=>5]);
  740. if(!empty($twoShopData) && !empty($twoShopData["agentId"])){
  741. $twoAgentData = $this->dbNewAgent->get(["id"=>$twoShopData["agentId"]]);
  742. if(!empty($twoAgentData)){
  743. //董事
  744. $twoPer=0;
  745. if($twoShopData["level"]==3){
  746. $twoPer = empty($this->agentSettingData["threePer"])?0:$this->agentSettingData["threePer"];
  747. }else{
  748. $twoPerKey = $levelAr[(int)$twoShopData["level"]].ucfirst($levelAr[(int)$shopData["level"]])."Per";
  749. var_dump($twoPerKey);
  750. if(!empty($twoPerKey)){
  751. $twoPer = empty($this->agentSettingData[$twoPerKey]) ? 0 : $this->agentSettingData[$twoPerKey];
  752. }
  753. }
  754. if(!empty($twoPer) && $twoPer>0 && $twoPer<1){
  755. //记录收益
  756. $data[]=[
  757. "purchaseMoney"=>$purchaseMoney,//采购单支付金额
  758. "calcMoney"=>$purchaseMoney,//佣金计算金额
  759. "sourceShopId"=>$purchaseShopId,//来源门店id
  760. "agentId"=>$twoAgentData["id"],//收钱门店代理账号id
  761. "shopId"=>$twoShopData["id"],//收钱门店id
  762. "customerId"=>$twoAgentData["customerId"],//收钱门店代理
  763. "userCenterId"=>$twoAgentData["userCenterId"],//收钱门店代理
  764. "commission"=>bcmul($purchaseMoney,$twoPer,2),//佣金金额
  765. "per"=>$twoPer,//佣金比例
  766. "type"=>0,
  767. "purchaseId"=>$purchaseData["id"],
  768. "purchaseNo"=>$purchaseData["no"],
  769. "status"=>0,//暂时不需要
  770. "title"=>"门店采购单分佣",
  771. "isUpgrade"=>0,
  772. "mono"=>"",
  773. "time"=>$nowTime,
  774. ];
  775. }
  776. }
  777. }
  778. //再计算爷爷级门店
  779. if(!empty($shopData["pOneShopId"])){
  780. $oneShopData = $this->dbShop->get(["id"=>$shopData["pOneShopId"],"enterpriseId"=>$this->enterpriseId,"deleteStatus"=>5]);
  781. if(!empty($oneShopData) && !empty($oneShopData["agentId"])){
  782. $oneAgentData = $this->dbNewAgent->get(["id"=>$oneShopData["agentId"]]);
  783. if(!empty($oneAgentData)){
  784. //董事
  785. $onePer=0;
  786. if($oneShopData["level"]==3){
  787. $onePer = empty($this->agentSettingData["threePer"])?0:$this->agentSettingData["threePer"];
  788. }else{
  789. $onePerKey = $levelAr[(int)$oneShopData["level"]].ucfirst($levelAr[(int)$shopData["level"]])."Per";
  790. if(!empty($onePerKey)){
  791. $onePer = empty($this->agentSettingData[$onePerKey]) ? 0 : $this->agentSettingData[$onePerKey];
  792. }
  793. }
  794. if(!empty($onePer) && $onePer>0 && $onePer<1){
  795. //记录收益
  796. $data[]=[
  797. "purchaseMoney"=>$purchaseMoney,//采购单支付金额
  798. "calcMoney"=>$purchaseMoney,//佣金计算金额
  799. "sourceShopId"=>$purchaseShopId,//来源门店id
  800. "agentId"=>$oneAgentData["id"],//收钱门店代理账号id
  801. "shopId"=>$oneShopData["id"],//收钱门店id
  802. "customerId"=>$oneAgentData["customerId"],//收钱门店代理
  803. "userCenterId"=>$oneAgentData["userCenterId"],//收钱门店代理
  804. "commission"=>bcmul($purchaseMoney,$onePer,2),//佣金金额
  805. "per"=>$onePer,//佣金比例
  806. "type"=>0,
  807. "purchaseId"=>$purchaseData["id"],
  808. "purchaseNo"=>$purchaseData["no"],
  809. "status"=>0,//暂时不需要
  810. "title"=>"门店采购单分佣",
  811. "isUpgrade"=>0,
  812. "mono"=>"",
  813. "time"=>$nowTime,
  814. ];
  815. }
  816. }
  817. }
  818. }
  819. if(empty($data)){
  820. return ["code"=>-1,"msg"=>"父级绑定或者配置错误导致数据更新失败"];
  821. }
  822. $num=0;
  823. //开启事务
  824. $this->dbNewAgentDetail->beginTransaction();
  825. $lms = "";
  826. foreach($data as $k=>$v){
  827. $count = $this->dbNewAgentDetail->count(["purchaseId"=>$v["purchaseId"],"agentId"=>$v["agentId"]]);
  828. if($count>0){
  829. $lms.="当前采购单已计算佣金[{$v['purchaseId']}];";
  830. continue;
  831. }
  832. $nid = $this->dbNewAgentDetail->insert($v);
  833. if(empty($nid)){
  834. $lms.="佣金明细插入失败[{$v['purchaseId']}];";
  835. continue;
  836. }
  837. //查询门店代理账户
  838. $agentItem = $this->dbNewAgent->get(["id"=>$v["agentId"]]);
  839. if(empty($agentItem)){
  840. $num = 0;
  841. $lms.="门店代理账户不存在[{$v['purchaseId']}];";
  842. break;
  843. }
  844. $shopItem = $this->dbShop->get($v["shopId"]);
  845. if(empty($shopItem)){
  846. $num = 0;
  847. $lms.="门店不存在[{$v['purchaseId']}];";
  848. break;
  849. }
  850. $update = [
  851. 'balance' => bcadd($agentItem['balance'], $v["commission"], 2),
  852. 'totalMoney' => bcadd($agentItem['totalMoney'], $v["commission"], 2),
  853. 'updateTime' => $nowTime,
  854. ];
  855. //添加账户余额明细记录
  856. $dres = $this->dbNewAgentBalanceDetail->insert([
  857. "type"=>1,
  858. "title"=>$v["title"],
  859. "code"=>$v["type"]==1 ? "agent_calc" : "purchase_calc",
  860. "money"=>$v["commission"],
  861. "content"=>$v["title"],
  862. "admin_id"=>0,
  863. "customer_id"=>$v["customerId"],
  864. "agent_id"=>$v["agentId"],
  865. "user_center_id"=>$v["userCenterId"],
  866. "shop_id"=>$v["shopId"],
  867. "cash_id"=>0,
  868. "old_balance"=>$agentItem["balance"],
  869. "now_balance"=>$update["balance"],
  870. "time"=>$nowTime,
  871. "expand"=>"",
  872. "detail_id"=>$nid,
  873. ]);
  874. if(empty($dres)){
  875. $num = 0;
  876. $lms.="账户余额明细插入失败[{$v['purchaseId']}];";
  877. break;
  878. }
  879. //更新账户余额
  880. $upRes = $this->dbNewAgent->update($update, ['id' => $v["agentId"]]);
  881. if(empty($upRes)){
  882. $num = 0;
  883. $lms.="更新账户余额失败[{$v['purchaseId']}];";
  884. break;
  885. }
  886. $num++;
  887. }
  888. if($num<=0){
  889. $this->dbNewAgentDetail->rollBack();
  890. return ["code"=>-1,"msg"=>"数据更新失败:".$lms];
  891. }
  892. $this->dbNewAgentDetail->commit();
  893. return ["code"=>1,"msg"=>"执行成功".$lms];
  894. }
  895. /**
  896. * 获取分佣明细
  897. */
  898. public function getCommissionDetail($customerId,$parms){
  899. $where=[];
  900. if(!empty($parms["where"])){
  901. $where= $parms["where"];
  902. }
  903. if(!empty($customerId)){
  904. $where["customerId"] = $customerId;
  905. }
  906. $data = $this->dbNewAgentDetail->select($where, "*", "id desc", $parms["limit"], $parms["offset"]);
  907. $total = $this->dbNewAgentDetail->count($where);
  908. if(empty($data)){
  909. $data = [];
  910. }
  911. foreach($data as $k=>$v){
  912. $itemShop = $this->dbShop->get(["id"=>$v["sourceShopId"]],"id,name,logo");
  913. if(empty($itemShop)){
  914. $data[$k]["name"] = "";
  915. $data[$k]["logo"] = "";
  916. }else{
  917. $data[$k]["name"] = $itemShop["name"];
  918. $data[$k]["logo"] = $itemShop["logo"];
  919. }
  920. }
  921. $return = [
  922. 'data' => $data,
  923. 'total' => (isset($total)&&!empty($total)) ? intval($total) : 0,
  924. ];
  925. return $return;
  926. }
  927. /**
  928. * 获取门店代理账户余额明细
  929. */
  930. public function getCommissionBalanceDetail($customerId,$parms){
  931. $where=[];
  932. if(!empty($customerId)){
  933. $where["customer_id"] = $customerId;
  934. }
  935. $data = $this->dbNewAgentBalanceDetail->select($where, "*", "id desc", $parms["limit"], $parms["offset"]);
  936. $total = $this->dbNewAgentBalanceDetail->count($where);
  937. if(empty($data)){
  938. $data = [];
  939. }
  940. $return = [
  941. 'data' => $data,
  942. 'total' => (isset($total)&&!empty($total)) ? intval($total) : 0,
  943. ];
  944. return $return;
  945. }
  946. /**
  947. *
  948. * @param type $type 0返回标题数组,1范围完整数组
  949. * @return type
  950. */
  951. public static function getBankType($type=0,$title=""){
  952. $data = [
  953. ["title"=>"支付宝","code"=>"alipay","icon"=>"ibonumidd17","addefault"=>"支付宝"],
  954. ["title"=>"微信钱包","code"=>"wxpay","icon"=>"ibonweixinzhifu","addefault"=>"微信"],
  955. ["title"=>"银行卡","code"=>"bank","icon"=>"ibonyinhangqia","addefault"=>""],
  956. ];
  957. if(!empty($title)){
  958. foreach($data as $k=>$v){
  959. if($v["title"]==$title){
  960. return $v;
  961. }
  962. }
  963. return [];
  964. }
  965. if($type==1){
  966. return $data;
  967. }
  968. $nameAr= [];
  969. foreach($data as $k=>$v){
  970. $nameAr[]=$v["title"];
  971. }
  972. return $nameAr;
  973. }
  974. /**
  975. * 提现申请
  976. */
  977. public function applyCash($data){
  978. if(empty($data) || empty($data["customerId"]) || empty($data["money"]) || empty($data["bank_type"]) || empty($data["bank_name"]) || empty($data["bank_num"]) || empty($data["bank_ad"])){
  979. return ["code"=>-1,"msg"=>"请填写完整信息"];
  980. }
  981. //频繁操作限制
  982. $key = "agentCashCache_".$data["customerId"].'::'.$this->enterpriseId;
  983. $result = $this->cache->get($key);
  984. if(!empty($result)){
  985. return ["code"=>-1,"msg"=>"操作频繁,请稍后尝试!"];
  986. }
  987. $count = $this->dbNewAgentCash->count(["status"=>0,"customer_id"=>$data["customerId"]]);
  988. if($count>0){
  989. return ["code"=>-1,"msg"=>"上次申请还在处理中"];
  990. }
  991. $this->cache->set($key,1,5);
  992. if(!in_array($data["bank_type"], self::getBankType())){
  993. return ["code"=>-1,"msg"=>"提现方式不存在"];
  994. }
  995. $bankTypeData = self::getBankType(1, $data["bank_type"]);
  996. if(empty($bankTypeData)){
  997. return ["code"=>-1,"msg"=>"提现方式不存在"];
  998. }
  999. if(!is_numeric($data["money"])){
  1000. return ["code"=>-1,"msg"=>"提现金额错误"];
  1001. }
  1002. $data["money"] = bcadd($data["money"],0,2);
  1003. if($data["money"]<=0){
  1004. return ["code"=>-1,"msg"=>"提现金额错误"];
  1005. }
  1006. $agentData = $this->dbNewAgent->get(["customerId"=>$data["customerId"]]);
  1007. if(empty($agentData) || empty($agentData["id"])){
  1008. return ["code"=>-1,"msg"=>"门店代理不存在"];
  1009. }
  1010. if($data["money"]>$agentData["balance"] || $agentData["balance"]<=0){
  1011. return ["code"=>-1,"msg"=>"提现金额不足"];
  1012. }
  1013. $nowTime = time();
  1014. $save=[
  1015. "customer_id" => $agentData["customerId"],
  1016. "user_center_id" => $agentData["userCenterId"],
  1017. "agent_id" => $agentData["id"],
  1018. "bank_type" => $data["bank_type"],
  1019. "bank_type_code" => $bankTypeData["code"],
  1020. "bank_name" => $data["bank_name"],
  1021. "bank_num" => $data["bank_num"],
  1022. "bank_ad" => $data["bank_ad"],
  1023. "money" => $data["money"],
  1024. "status" => 0,
  1025. "time" => $nowTime
  1026. ];
  1027. try{
  1028. $this->dbNewAgent->beginTransaction();
  1029. //插入提现申请
  1030. $applyId = $this->dbNewAgentCash->insert($save);
  1031. if(empty($applyId)){
  1032. return ["code"=>-1,"msg"=>"数据提交失败001"];
  1033. }
  1034. //更新提现账户余额并添加明细
  1035. $update = [
  1036. 'balance' => bcsub($agentData["balance"], $save["money"], 2),//账户余额
  1037. 'withdraw' => bcadd($agentData["withdraw"], $save["money"],2),//已提现金额
  1038. 'updateTime' => $nowTime,
  1039. ];
  1040. if($update["balance"]<=0){
  1041. $this->dbNewAgent->rollBack();
  1042. return ["code"=>-1,"msg"=>"数据提交失败002"];
  1043. }
  1044. //添加账户余额明细记录
  1045. $dres = $this->dbNewAgentBalanceDetail->insert([
  1046. "type"=>-1,
  1047. "title"=>"余额提现",
  1048. "code"=>"cash_balance",
  1049. "money"=>$save["money"],
  1050. "content"=>"门店代理余额提现",
  1051. "admin_id"=>0,
  1052. "customer_id"=>$agentData["customerId"],
  1053. "agent_id"=>$agentData["id"],
  1054. "user_center_id"=>$agentData["userCenterId"],
  1055. "cash_id"=>$applyId,
  1056. "old_balance"=>$agentData["balance"],
  1057. "now_balance"=>$update["balance"],
  1058. "time"=>$nowTime,
  1059. "expand"=>"",
  1060. "detail_id"=>0,
  1061. ]);
  1062. if(empty($dres)){
  1063. $this->dbNewAgent->rollBack();
  1064. return ["code"=>-1,"msg"=>"账户余额明细插入失败"];
  1065. }
  1066. //更新账户余额
  1067. $upRes = $this->dbNewAgent->update($update, ['id' => $agentData["id"]]);
  1068. if(empty($upRes)){
  1069. $this->dbNewAgent->rollBack();
  1070. return ["code"=>-1,"msg"=>"更新账户余额失败"];
  1071. }
  1072. $this->dbNewAgent->commit();
  1073. $this->cache->set($key,null);
  1074. return ["code"=>1,"msg"=>"提现申请提交成功"];
  1075. } catch (\Exception $e){
  1076. $this->dbNewAgent->rollBack();
  1077. $this->cache->set($key,null);
  1078. return ["code"=>1,"msg"=>"提现申请提交失败"];
  1079. }
  1080. }
  1081. /**
  1082. * 获取提现记录
  1083. * @param type $customerId
  1084. * @param type $parms
  1085. * @return type
  1086. */
  1087. public function getPartnerApplyCashList($customerId,$parms){
  1088. $where=[];
  1089. if(!empty($parms["where"])){
  1090. $where= $parms["where"];
  1091. }
  1092. if(!empty($customerId)){
  1093. $where["customer_id"] = $customerId;
  1094. }
  1095. $data = $this->dbNewAgentCash->select($where, "*", "id desc", $parms["limit"], $parms["offset"]);
  1096. $total = $this->dbNewAgentCash->count($where);
  1097. if(empty($data)){
  1098. $data = [];
  1099. }
  1100. $return = [
  1101. 'data' => $data,
  1102. 'total' => (isset($total)&&!empty($total)) ? intval($total) : 0,
  1103. ];
  1104. return $return;
  1105. }
  1106. /**
  1107. * 获取提现详情
  1108. */
  1109. public function getPartnerApplyCashInfo($customerId,$parms){
  1110. $where=[];
  1111. if(!empty($parms["where"])){
  1112. $where= $parms["where"];
  1113. }
  1114. if(!empty($customerId)){
  1115. $where["customer_id"] = $customerId;
  1116. }
  1117. $data = $this->dbNewAgentCash->get($where);
  1118. return $data;
  1119. }
  1120. /**
  1121. * 获取门店代理列表
  1122. * @param type $params
  1123. */
  1124. public function getPartnerList($params = []){
  1125. $customerTableName = 'qianniao_customer_'.$this->enterpriseId;
  1126. $userCenterTableName = 'qianniao_user_center';
  1127. $newCommissionPartnerTableName = 'qianniao_new_agent_'.$this->enterpriseId;
  1128. //查询数据
  1129. $field = "p.*,u.mobile,c.name,c.avatar";
  1130. $sql = "select {$field} from {$newCommissionPartnerTableName} p "
  1131. . "left join {$userCenterTableName} u on u.id = p.userCenterId "
  1132. . "left join {$customerTableName} c on c.id = p.customerId";
  1133. $whereSql = ' where p.deleteStatus = 5 ';
  1134. if(isset($params['search'])){
  1135. $whereSql .= ' and (u.mobile like "%'.$params['search'].'%" or c.name like "%'.$params['search'].'%") ';
  1136. }
  1137. $orderSql = ' order by p.id desc ';
  1138. $limitSql = ' limit '.$params['offset'].','.$params['limit'];
  1139. $querySql = $sql.$whereSql.$orderSql.$limitSql;
  1140. $data = $this->dbNewAgent->query($querySql);
  1141. if(empty($data)){
  1142. $data=[];
  1143. }
  1144. //查询总数
  1145. $countSql = "select count(*) as `count` from {$newCommissionPartnerTableName} p "
  1146. . "left join {$userCenterTableName} u on u.id = p.userCenterId "
  1147. . "left join {$customerTableName} c on c.id = p.customerId";
  1148. $countData = $this->dbNewAgent->query($countSql.$whereSql);
  1149. $total = 0;
  1150. if(!empty($countData)){
  1151. $total =array_shift($countData)['count'];
  1152. }
  1153. return ['data'=>$data,'total'=>($total) ? intval($total) : 0];
  1154. }
  1155. /**
  1156. * 获取门店代理余额明细列表
  1157. * @param type $params
  1158. */
  1159. public function getBalanceDetailList($params = []){
  1160. $customerTableName = 'qianniao_customer_'.$this->enterpriseId;
  1161. $userCenterTableName = 'qianniao_user_center';
  1162. $newCommissionBalanceDetailTableName = 'qianniao_new_agent_balance_detail_'.$this->enterpriseId;
  1163. //查询数据
  1164. $field = "p.*,u.mobile,c.name,c.avatar";
  1165. $sql = "select {$field} from {$newCommissionBalanceDetailTableName} p "
  1166. . "left join {$userCenterTableName} u on u.id = p.user_center_id "
  1167. . "left join {$customerTableName} c on c.id = p.customer_id";
  1168. $whereSql = ' where 1=1 ';
  1169. if(!empty($params['agentId'])){
  1170. $whereSql .= ' and p.agent_id = '.$params['agentId'];
  1171. }
  1172. if(isset($params['search'])){
  1173. $whereSql .= ' and (u.mobile like "%'.$params['search'].'%" or c.name like "%'.$params['search'].'%") ';
  1174. }
  1175. $orderSql = ' order by p.id desc ';
  1176. $limitSql = ' limit '.$params['offset'].','.$params['limit'];
  1177. $querySql = $sql.$whereSql.$orderSql.$limitSql;
  1178. $data = $this->dbNewAgent->query($querySql);
  1179. if(empty($data)){
  1180. $data=[];
  1181. }
  1182. //查询总数
  1183. $countSql = "select count(*) as `count` from {$newCommissionBalanceDetailTableName} p "
  1184. . "left join {$userCenterTableName} u on u.id = p.user_center_id "
  1185. . "left join {$customerTableName} c on c.id = p.customer_id";
  1186. $countData = $this->dbNewAgent->query($countSql.$whereSql);
  1187. $total = 0;
  1188. if(!empty($countData)){
  1189. $total =array_shift($countData)['count'];
  1190. }
  1191. return ['data'=>$data,'total'=>($total) ? intval($total) : 0];
  1192. }
  1193. /**
  1194. * 获取门店代理佣金记录
  1195. * @param type $params
  1196. */
  1197. public function getDetailList($params = []){
  1198. $customerTableName = 'qianniao_customer_'.$this->enterpriseId;
  1199. $userCenterTableName = 'qianniao_user_center';
  1200. $newCommissionDetailTableName = 'qianniao_new_agent_detail_'.$this->enterpriseId;
  1201. $shopTableName = "qianniao_shop_1";
  1202. //查询数据
  1203. $field = "p.*,u.mobile,c.name,c.avatar,s.name as sourceName ";
  1204. $sql = "select {$field} from {$newCommissionDetailTableName} p "
  1205. . "left join {$userCenterTableName} u on u.id = p.userCenterId "
  1206. . "left join {$customerTableName} c on c.id = p.customerId "
  1207. . "left join {$shopTableName} s on s.id = p.sourceShopId";
  1208. $whereSql = ' where 1=1 ';
  1209. if(!empty($params['agentId'])){
  1210. $whereSql .= ' and p.agentId = '.$params['agentId'];
  1211. }
  1212. if(isset($params['search'])){
  1213. $whereSql .= ' and (u.mobile like "%'.$params['search'].'%" or c.name like "%'.$params['search'].'%") ';
  1214. }
  1215. $orderSql = ' order by p.id desc ';
  1216. $limitSql = ' limit '.$params['offset'].','.$params['limit'];
  1217. $querySql = $sql.$whereSql.$orderSql.$limitSql;
  1218. $data = $this->dbNewAgent->query($querySql);
  1219. if(empty($data)){
  1220. $data=[];
  1221. }
  1222. //查询总数
  1223. $countSql = "select count(*) as `count` from {$newCommissionDetailTableName} p "
  1224. . "left join {$userCenterTableName} u on u.id = p.userCenterId "
  1225. . "left join {$customerTableName} c on c.id = p.customerId "
  1226. . "left join {$shopTableName} s on s.id = p.sourceShopId";
  1227. $countData = $this->dbNewAgent->query($countSql.$whereSql);
  1228. $total = 0;
  1229. if(!empty($countData)){
  1230. $total =array_shift($countData)['count'];
  1231. }
  1232. return ['data'=>$data,'total'=>($total) ? intval($total) : 0];
  1233. }
  1234. /**
  1235. * 获取提现记录
  1236. * @param type $params
  1237. */
  1238. public function getPartnerCashList($params = []){
  1239. $customerTableName = 'qianniao_customer_'.$this->enterpriseId;
  1240. $userCenterTableName = 'qianniao_user_center';
  1241. $newCommissionCashTableName = 'qianniao_new_agent_cash_'.$this->enterpriseId;
  1242. //查询数据
  1243. $field = "p.*,u.mobile,c.name,c.avatar ";
  1244. $sql = "select {$field} from {$newCommissionCashTableName} p "
  1245. . "left join {$userCenterTableName} u on u.id = p.user_center_id "
  1246. . "left join {$customerTableName} c on c.id = p.customer_id ";
  1247. $whereSql = ' where 1=1 ';
  1248. if(!empty($params['agentId'])){
  1249. $whereSql .= ' and p.agent_id = '.$params['agentId'];
  1250. }
  1251. if(isset($params['search'])){
  1252. $whereSql .= ' and (u.mobile like "%'.$params['search'].'%" or c.name like "%'.$params['search'].'%") ';
  1253. }
  1254. if(isset($params['status'])){
  1255. $whereSql .= ' and p.status = '.$params['status'];
  1256. }
  1257. if(!empty($params['bank_type_code'])){
  1258. $whereSql .= " and p.bank_type_code = '{$params['bank_type_code']}'";
  1259. }
  1260. if(!empty($params['start_time']) && !empty($params['end_time'])){
  1261. $whereSql .= " and p.time >= {$params['start_time']} and p.time < {$params['end_time']}";
  1262. }
  1263. $orderSql = ' order by p.id desc ';
  1264. $limitSql = ' limit '.$params['offset'].','.$params['limit'];
  1265. $querySql = $sql.$whereSql.$orderSql.$limitSql;
  1266. $data = $this->dbNewAgent->query($querySql);
  1267. if(empty($data)){
  1268. $data=[];
  1269. }
  1270. //查询总数
  1271. $countSql = "select count(*) as `count` from {$newCommissionCashTableName} p "
  1272. . "left join {$userCenterTableName} u on u.id = p.user_center_id "
  1273. . "left join {$customerTableName} c on c.id = p.customer_id ";
  1274. $countData = $this->dbNewAgent->query($countSql.$whereSql);
  1275. $total = 0;
  1276. if(!empty($countData)){
  1277. $total =array_shift($countData)['count'];
  1278. }
  1279. return ['data'=>$data,'total'=>($total) ? intval($total) : 0];
  1280. }
  1281. /**
  1282. * 提现处理
  1283. * @param type $id
  1284. * @param type $mono
  1285. * @param type $type
  1286. */
  1287. public function partnerCashAudit($id,$mono,$type,$audit_id=0){
  1288. if(empty($id)|| empty($mono) || empty($type) || !in_array($type, [1,-1])){
  1289. return ["code"=>-1,"msg"=>"参数错误"];
  1290. }
  1291. $adminData = $this->dbUserCenter->get($this->onlineUserId);
  1292. if(empty($adminData)){
  1293. $adminData=["audit_name"=>"管理人员"];
  1294. }
  1295. //频繁操作限制
  1296. $key = "agentCashDealCache_".$id.'::'.$this->enterpriseId;
  1297. $result = $this->cache->get($key);
  1298. if(!empty($result)){
  1299. return ["code"=>-1,"msg"=>"处理中,请耐心等待!"];
  1300. }
  1301. $this->cache->set($key,1,5);
  1302. $where = ["id"=>$id,"status"=>0];
  1303. $data = $this->dbNewAgentCash->get($where);
  1304. if(empty($data)){
  1305. $this->cache->set($key,null);
  1306. return ["code"=>-1,"msg"=>"数据不存在"];
  1307. }
  1308. //门店代理账户信息
  1309. $agentData = $this->dbNewAgent->get(["id"=>$data["agent_id"]]);
  1310. if(empty($agentData)){
  1311. $this->cache->set($key,null);
  1312. return ["code"=>-1,"msg"=>"门店代理账户不存在"];
  1313. }
  1314. //打款成功
  1315. if($type==1){
  1316. $res = $this->dbNewAgentCash->update([
  1317. "status"=>1,
  1318. "audit_time"=>time(),
  1319. "audit_mono"=>$mono,
  1320. "audit_id"=>$audit_id,
  1321. "audit_name"=>$adminData["mobile"],
  1322. ], $where);
  1323. $this->cache->set($key,null);
  1324. if(empty($res)){
  1325. return ["code"=>-1,"msg"=>"系统繁忙,请稍后重试001!"];
  1326. }
  1327. return ["code"=>1,"msg"=>"处理完成"];
  1328. }
  1329. //审核驳回
  1330. try{
  1331. $this->dbNewAgentCash->beginTransaction();
  1332. $res = $this->dbNewAgentCash->update([
  1333. "status"=>-1,
  1334. "audit_time"=>time(),
  1335. "audit_mono"=>$mono,
  1336. "audit_id"=>$audit_id,
  1337. "audit_name"=>$adminData["mobile"],
  1338. ], $where);
  1339. if(empty($res)){
  1340. $this->dbNewAgentCash->rollBack();
  1341. $this->cache->set($key,null);
  1342. return ["code"=>-1,"msg"=>"操作失败001!"];
  1343. }
  1344. //添加账户余额明细记录
  1345. $dres = $this->dbNewAgentBalanceDetail->insert([
  1346. "type"=>1,
  1347. "title"=>"提现驳回返还余额",
  1348. "code"=>"cash_no_balance",
  1349. "money"=>$data["money"],
  1350. "content"=>"提现驳回返还余额:".$mono,
  1351. "admin_id"=>$audit_id,
  1352. "customer_id"=>$agentData["customerId"],
  1353. "agent_id"=>$agentData["id"],
  1354. "user_center_id"=>$agentData["userCenterId"],
  1355. "cash_id"=>$data["id"],
  1356. "old_balance"=>$agentData["balance"],
  1357. "now_balance"=>$agentData["balance"]+$data["money"],
  1358. "time"=>time(),
  1359. "expand"=>"",
  1360. "detail_id"=>0,
  1361. ]);
  1362. if(empty($dres)){
  1363. $this->dbNewAgentCash->rollBack();
  1364. $this->cache->set($key,null);
  1365. return ["code"=>-1,"msg"=>"操作失败002!"];
  1366. }
  1367. //更新账户数据
  1368. $withdrawRes = $this->dbNewAgent->set_dec("withdraw", ["id"=>$agentData["id"]], $data["money"]);
  1369. if(empty($withdrawRes)){
  1370. $this->dbNewAgentCash->rollBack();
  1371. $this->cache->set($key,null);
  1372. return ["code"=>-1,"msg"=>"操作失败003"];
  1373. }
  1374. $balanceRes = $this->dbNewAgent->set_inc("balance", ["id"=>$agentData["id"]], $data["money"]);
  1375. if(empty($balanceRes)){
  1376. $this->dbNewAgentCash->rollBack();
  1377. $this->cache->set($key,null);
  1378. return ["code"=>-1,"msg"=>"操作失败004"];
  1379. }
  1380. //提交事务
  1381. $this->dbNewAgentCash->commit();
  1382. $this->cache->set($key,null);
  1383. return ["code"=>1,"msg"=>"提现申请处理成功!"];
  1384. } catch (\Exception $e){
  1385. $this->dbNewAgentCash->rollBack();
  1386. $this->cache->set($key,null);
  1387. return ["code"=>-1,"msg"=>"系统繁忙,请稍后重试!"];
  1388. }
  1389. }
  1390. /**
  1391. * 获取设置信息
  1392. * @param type $enterpriseId
  1393. * @return string
  1394. */
  1395. public static function getCommissionSettingData($enterpriseId){
  1396. $dbSetting = new DNewAgentSetting('default');
  1397. $data = $dbSetting->get(["enterpriseId"=>$enterpriseId]);
  1398. if(empty($data)){
  1399. $data=[
  1400. "id"=>0,
  1401. "enterpriseId"=>$enterpriseId,
  1402. "levMoney"=>0,
  1403. "levPer"=>0,
  1404. "incomePer"=>0,
  1405. "is_open"=>0,
  1406. "bankData"=>"",
  1407. "oneToTwoNum"=>0,
  1408. "twoToThreeNum"=>0,
  1409. "oneOnePer"=>0,
  1410. "oneTwoPer"=>0,
  1411. "twoOnePer"=>0,
  1412. "twoTwoPer"=>0,
  1413. "threePer"=>0,
  1414. ];
  1415. }
  1416. return $data;
  1417. }
  1418. /**
  1419. * 推荐代理分佣设置
  1420. * @param type $enterpriseId
  1421. * @param type $parms
  1422. * @return type
  1423. */
  1424. public static function setCommissionSettingData($enterpriseId,$parms){
  1425. if(empty($enterpriseId) || empty($parms)){
  1426. return ["code"=>"-1","msg"=>"参数错误"];
  1427. }
  1428. $dbSetting = new DNewAgentSetting('default');
  1429. $data = $dbSetting->get(["enterpriseId"=>$enterpriseId]);
  1430. $parms["levMoney"] = empty($parms["levMoney"]) ? 0 : $parms["levMoney"];
  1431. $parms["levPer"] = empty($parms["levPer"]) ? 0 : $parms["levPer"];
  1432. $parms["incomePer"] = empty($parms["incomePer"])? 0 : $parms["incomePer"];
  1433. $parms["is_open"] = empty($parms["is_open"]) ? 0 : 1;
  1434. // if(!is_numeric($parms["levMoney"]) || $parms["levMoney"]<=0){
  1435. // return ["code"=>"-1","msg"=>"升级门店代理金额必须大于0"];
  1436. // }
  1437. // if(!is_numeric($parms["levPer"]) || $parms["levPer"]<0 || $parms["levPer"]>=1){
  1438. // return ["code"=>"-1","msg"=>"子级升级门店代理消费佣金比例必须0到1之间"];
  1439. // }
  1440. if(!is_numeric($parms["oneOnePer"]) || $parms["oneOnePer"]<0 || $parms["oneOnePer"]>=1){
  1441. return ["code"=>"-1","msg"=>"佣金比例必须0到1之间"];
  1442. }
  1443. if(!is_numeric($parms["oneTwoPer"]) || $parms["oneTwoPer"]<0 || $parms["oneTwoPer"]>=1){
  1444. return ["code"=>"-1","msg"=>"佣金比例必须0到1之间"];
  1445. }
  1446. if(!is_numeric($parms["twoOnePer"]) || $parms["twoOnePer"]<0 || $parms["twoOnePer"]>=1){
  1447. return ["code"=>"-1","msg"=>"佣金比例必须0到1之间"];
  1448. }
  1449. if(!is_numeric($parms["threePer"]) || $parms["threePer"]<0 || $parms["threePer"]>=1){
  1450. return ["code"=>"-1","msg"=>"佣金比例必须0到1之间"];
  1451. }
  1452. $saveData = [
  1453. "enterpriseId" => $enterpriseId,
  1454. "levMoney" => $parms["levMoney"],
  1455. "levPer" => $parms["levPer"],
  1456. "incomePer" => $parms["incomePer"],
  1457. "is_open" => $parms["is_open"],
  1458. "oneToTwoNum" => $parms["oneToTwoNum"]?:0,
  1459. "twoToThreeNum"=> $parms["twoToThreeNum"]?:0,
  1460. "oneOnePer" => $parms["oneOnePer"]?:0,
  1461. "oneTwoPer" => $parms["oneTwoPer"]?:0,
  1462. "twoOnePer" => $parms["twoOnePer"]?:0,
  1463. "twoTwoPer" => $parms["twoTwoPer"]?:0,
  1464. "threePer" => $parms["threePer"]?:0,
  1465. "updateTime" => time()
  1466. ];
  1467. $res = false;
  1468. if(empty($data)){
  1469. $saveData["enterpriseId"] = $enterpriseId;
  1470. $saveData["time"] = time();
  1471. $res = $dbSetting->insert($saveData);
  1472. }else{
  1473. $res = $dbSetting->update($saveData, ["id"=>$data["id"]]);
  1474. }
  1475. if(empty($res)){
  1476. return ["code"=>"-1","msg"=>"系统繁忙,请稍后重试"];
  1477. }
  1478. return ["code"=>1,"msg"=>"配置成功"];
  1479. }
  1480. public function getCustomerDataByUserCenterId($userCenterId){
  1481. if(empty($userCenterId)){
  1482. return false;
  1483. }
  1484. $data = $this->dbCustomer->get(["userCenterId"=>$userCenterId]);
  1485. if(empty($data)){
  1486. return false;
  1487. }
  1488. return $data;
  1489. }
  1490. }