PensionTasks.php 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369
  1. <?php
  2. declare (strict_types=1);
  3. namespace app\command;
  4. use app\common\model\merchant\order\OrderMerchant;
  5. use app\common\model\store\order\StoreOrder;
  6. use app\common\model\user\User;
  7. use app\common\model\user\UserCertification;
  8. use app\common\repositories\merchant\order\OrderGzcRepository;
  9. use app\common\repositories\merchant\order\OrderMerchantRepository;
  10. use app\common\repositories\store\order\StoreOrderStatusRepository;
  11. use app\common\repositories\store\product\ProductRepository;
  12. use app\common\repositories\user\UserBillRepository;
  13. use app\traits\GzcApiRequest;
  14. use Carbon\Carbon;
  15. use think\console\Command;
  16. use think\console\Input;
  17. use think\console\Output;
  18. use think\Exception;
  19. use think\facade\Db;
  20. use think\facade\Log;
  21. use app\common\repositories\store\order\StoreOrderRepository;
  22. /**
  23. * Class PensionTasks
  24. * @package app\command
  25. * @author: php迷途小书童
  26. * @created: 2021/3/19 9:14
  27. */
  28. class PensionTasks extends Command
  29. {
  30. use GzcApiRequest;
  31. protected function configure()
  32. {
  33. // 指令配置
  34. $this->setName('pensiontask')
  35. ->setDescription('the pensiontask command');
  36. }
  37. protected function execute(Input $input, Output $output)
  38. {
  39. //1线下2在线3拼多多4京东5苏宁6淘宝7VIP
  40. $nowTime = time();
  41. try {
  42. //线下符合条件的养老金收集(线下交易后第8天)
  43. $this->doOfflineOrderGzc($nowTime, $timeLimit = 1);
  44. //在线订单符合条件的养老金收集(线上收货后第30天)
  45. $this->doOnlineOrderGzc($timeLimit = 30);
  46. //在线订单符合条件的话费养老金收集(话费到账后第1天)
  47. $this->doOnlineHuuafeiOrderGzc($timeLimit = 1);
  48. //第三方订单符合条件的养老金收集(三方结算后第2天)
  49. $this->doThridPddOrderGzc($nowTime, $timeLimit = 2);
  50. $this->doThridJdOrderGzc($nowTime, $timeLimit = 2);
  51. $this->doThridSnOrderGzc($nowTime, $timeLimit = 2);
  52. $this->doThridTaobaoOrderGzc($nowTime, $timeLimit = 2);
  53. $this->doThridVipOrderGzc($nowTime, $timeLimit = 2);
  54. $this->doThridDyOrderGzc($nowTime, $timeLimit = 2);
  55. $this->doThridHfOrderGzc($nowTime, $timeLimit = 2);
  56. //升级
  57. // $this -> doUpgrade();
  58. } catch (\Throwable $e) {
  59. Log::info('公证处入账:' . $e->getFile() . ':' . $e->getLine() . '【' . $e->getMessage() . '】');
  60. var_dump('公证处入账:' . $e->getFile() . ':' . $e->getLine() . '【' . $e->getMessage() . '】');
  61. }
  62. // 指令输出
  63. $output->writeln('pensiontask');
  64. }
  65. /**
  66. * 线下支付订单公证处IN10入账
  67. * @param $nowTime
  68. * @param $timeLimit
  69. * author: php迷途小书童
  70. * created: 2021/3/20 9:26
  71. */
  72. public function doOfflineOrderGzc($nowTime, $timeLimit)
  73. {
  74. $cursor = Db::table('rrx_order_merchant')
  75. ->whereNotNull('pay_time')
  76. ->where('paid', 1)
  77. ->where('gzc', 0)
  78. ->whereTime('pay_time', '<', $nowTime - bcmul((string)$timeLimit, (string)86400))
  79. ->cursor();
  80. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  81. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  82. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  83. foreach ($cursor as $offline) {
  84. if ($offline['mer_id'] == 496) {
  85. continue;
  86. }
  87. $uid = 0;
  88. switch ($offline['trade_type']) {
  89. case 'WX':
  90. $uid = User::getInstance()->where('wechat_user_id', $offline['pay_user_id'])->value('uid');
  91. $accountType = 3;
  92. break;
  93. case 'ALI':
  94. $uid = User::getInstance()->where('ali_user_id', $offline['pay_user_id'])->value('uid');
  95. $accountType = 2;
  96. break;
  97. default:
  98. break;
  99. }
  100. if (!$uid) {
  101. Log::info($offline['pay_user_id'] . '未绑定用户');
  102. continue;
  103. }
  104. $certification = UserCertification::getInstance()->where('uid', $uid)->find();
  105. if (!$certification) {
  106. Log::info($offline['pay_user_id'] . '未实名认证');
  107. continue;
  108. }
  109. //查询养老金金额
  110. $UserBillRepository = app()->make(UserBillRepository::class);
  111. $bill = $UserBillRepository->getWhere(['uid' => $uid, 'link_id' => $offline['id'], 'order_sn' => $offline['out_trade_no'], 'title' => '养老金']);
  112. // if ($bill->status == 0) {
  113. // Log::info($offline['out_trade_no'] . 'pension未交年费');
  114. // continue;
  115. // }
  116. $pension = $bill->number ?? 0;
  117. if ($pension <= 0) {
  118. Log::info($offline['out_trade_no'] . 'pension' . $pension);
  119. continue;
  120. }
  121. Db::transaction(function () use ($uid, $certification, $accountType, $offline, $OrderGzcRepository, $OrderMerchantRepository, $pension, $StoreOrderRepository) {
  122. $order = OrderMerchant::getInstance()->find($offline['id']);
  123. $order->gzc = 1;
  124. $order->is_settlement = 1;
  125. $order->settlement_time = date('Y-m-d H:i:s');
  126. $order->save();
  127. //新增入账明细记录
  128. $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  129. $create = [
  130. 'uid' => $uid,
  131. 'platform_no' => $orderId,
  132. 'account_type' => $accountType,
  133. 'user_name' => $certification['user_name'],
  134. 'mobile' => $certification['mobile'],
  135. 'user_card' => $certification['user_card'],
  136. 'pension' => $pension,
  137. 'order_type' => 1,
  138. 'out_trade_no' => $offline['out_trade_no']
  139. ];
  140. $test_user = Db::name('user')->where('uid', $uid)->value('test_user');
  141. if ($test_user == 0) {
  142. $OrderGzcRepository->create($create);
  143. }
  144. // 养老金区域奖励
  145. $order_data = [
  146. 'pay_price' => $pension,
  147. 'user_address_ids' => $offline['user_address_ids'],
  148. 'uid' => $offline['uid'],
  149. 'order_sn' => $offline['out_trade_no']
  150. ];
  151. // $StoreOrderRepository->area_manage_details($order_data, 0, 2);
  152. // 结算红包
  153. // $user_sign_hongbao_list = Db::name('user_sign_hongbao')
  154. // ->where('status', -1)
  155. // ->where('order_id', $offline['id'])
  156. // ->whereIn('type', [1, 2])
  157. // ->select()
  158. // ->toArray();
  159. // foreach ($user_sign_hongbao_list as $user_sign_hongbao) {
  160. // if($user_sign_hongbao['uid']){
  161. // // 修改红包
  162. // Db::name('user')
  163. // ->where('uid', $user_sign_hongbao['uid'])
  164. // ->inc('hongbao', (float)$user_sign_hongbao['number'])
  165. // ->update();
  166. // Db::name('user_sign_hongbao')
  167. // ->where('status', -1)
  168. // ->where('id', $user_sign_hongbao['id'])
  169. // ->update([
  170. // 'status' => 1,
  171. // 'settlement_time' => date('Y-m-d H:i:s')
  172. // ]);
  173. // }
  174. // }
  175. // // 结算积分
  176. // $user_sign_score_list = Db::name('user_sign_score')
  177. // ->where('status', -1)
  178. // ->where('order_id', $offline['id'])
  179. // ->whereIn('type', [1, 2])
  180. // ->select()
  181. // ->toArray();
  182. // foreach ($user_sign_score_list as $user_sign_score) {
  183. // if($user_sign_score['uid']){
  184. // // 修改积分
  185. // Db::name('user')
  186. // ->where('uid', $user_sign_score['uid'])
  187. // ->inc('score', (float)$user_sign_score['reward_socre'])
  188. // ->update();
  189. // Db::name('user_sign_score')
  190. // ->where('status', -1)
  191. // ->where('id', $user_sign_score['id'])
  192. // ->update([
  193. // 'status' => 1,
  194. // 'settlement_time' => date('Y-m-d H:i:s')
  195. // ]);
  196. // }
  197. // }
  198. // // 结算贡献值
  199. // $user_sign_gongxian_list = Db::name('user_sign_gongxian')
  200. // ->where('status', -1)
  201. // ->where('order_id', $offline['id'])
  202. // ->whereIn('type', [1, 2])
  203. // ->select()
  204. // ->toArray();
  205. // foreach ($user_sign_gongxian_list as $user_sign_gongxian) {
  206. // if($user_sign_gongxian['uid']){
  207. // // 修改贡献值
  208. // Db::name('user')
  209. // ->where('uid', $user_sign_gongxian['uid'])
  210. // ->inc('contribute', (float)$user_sign_gongxian['number'])
  211. // ->update();
  212. // Db::name('user_sign_gongxian')
  213. // ->where('status', -1)
  214. // ->where('id', $user_sign_gongxian['id'])
  215. // ->update([
  216. // 'status' => 1,
  217. // 'settlement_time' => date('Y-m-d H:i:s')
  218. // ]);
  219. // }
  220. // }
  221. // // 结算佣金
  222. // $user_bill_list = Db::name('user_bill')
  223. // ->where('status', 0)
  224. // ->where('commission_type','<>', 5)
  225. // ->where([ 'link_id' => $offline['id'], 'order_sn' => $offline['order_sn']])
  226. // ->select()
  227. // ->toArray();
  228. // foreach ($user_bill_list as $user_bill) {
  229. // if($user_bill['uid']){
  230. // if ($user_bill['commission_type'] != 5) {
  231. // if (in_array($user_bill['commission_type'], [7,12,19])) {
  232. // Db::name("merchant")
  233. // ->where("mer_id", $user_bill['mer_id'])
  234. // ->inc('brokerage_price', (float)$user_bill['number'])
  235. // ->update();
  236. // } else {
  237. // Db::name('user')
  238. // ->where('uid', $user_bill['uid'])
  239. // ->inc('brokerage_price', (float)$user_bill['number'])
  240. // ->update();
  241. // }
  242. // }
  243. // }
  244. // }
  245. });
  246. }
  247. }
  248. /**
  249. * 话费支付订单公证处IN10入账
  250. * @param $nowTime
  251. * @param $timeLimit
  252. * author: php迷途小书童
  253. * created: 2021/3/20 9:26
  254. */
  255. public function doOnlineHuuafeiOrderGzc($timeLimit)
  256. {
  257. // 普通订单
  258. $cursor = Db::table('rrx_order_huafei')->where('status', 3)->where('gzc', 0)->cursor();
  259. $StoreOrderStatusRepository = app()->make(StoreOrderStatusRepository::class);
  260. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  261. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  262. foreach ($cursor as $online) {
  263. if (time() < strtotime($online['finish_time']) + 3600 * 24) {
  264. Log::info('还没有话费到账后' . $timeLimit . '天');
  265. continue;
  266. }
  267. $certification = UserCertification::getInstance()->where('uid', $online['uid'])->find();
  268. if (!$certification) {
  269. Log::info($online['uid'] . '没有实名认证');
  270. continue;
  271. }
  272. //查询养老金金额
  273. $UserBillRepository = app()->make(UserBillRepository::class);
  274. $bill = $UserBillRepository->getWhere(['uid' => $online['uid'], 'order_sn' => $online['order_sn'], 'commission_type' => 5]);
  275. $pension = $bill->number ?? 0;
  276. if ($pension <= 0) {
  277. Log::info($online['order_sn'] . 'pension' . $pension);
  278. continue;
  279. }
  280. //首信易分账
  281. // $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  282. // if ($online['pay_type'] > 0) {
  283. // $StoreOrderRepository->splitOrder($online);
  284. // }
  285. $StoreOrderRepository = [];
  286. Db::transaction(function () use ($certification, $online, $pension, $OrderGzcRepository, $OrderMerchantRepository, $StoreOrderRepository) {
  287. //新增入账明细记录
  288. $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  289. $create = [
  290. 'uid' => $online['uid'],
  291. 'platform_no' => $orderId,
  292. 'account_type' => 3,//账号类型1银行卡2支付宝3微信
  293. 'user_name' => $certification['user_name'],
  294. 'mobile' => $certification['mobile'],
  295. 'user_card' => $certification['user_card'],
  296. 'pension' => $pension,
  297. 'order_type' => 2,
  298. 'out_trade_no' => $online['order_sn']
  299. ];
  300. $test_user = Db::name('user')->where('uid', $online['uid'])->value('test_user');
  301. $check = Db::name("gzc_logs")->where("out_trade_no", $online['order_sn'])->where("order_type", 2)->count();
  302. if ($test_user == 0 && $check <= 0) {
  303. $OrderGzcRepository->create($create);
  304. }
  305. $order = StoreOrder::getInstance()->find($online['order_id']);
  306. $order->gzc = 1;
  307. $order->save();
  308. });
  309. }
  310. // 普通订单(红包,积分,京东,佣金,复购金,养老金,贡献值)
  311. $cursor = Db::table('rrx_order_huafei')->where('status', 3)->where('bill_status', 0)->cursor();
  312. $StoreOrderStatusRepository = app()->make(StoreOrderStatusRepository::class);
  313. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  314. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  315. foreach ($cursor as $online) {
  316. if (time() < strtotime($online['finish_time']) + 3600 * 24) {
  317. Log::info('还没有话费到账后' . $timeLimit . '天');
  318. continue;
  319. }
  320. Db::transaction(function () use ($online) {
  321. //订单状态改为已结算
  322. Db::name('rrx_order_huafei')
  323. ->where('status', 3)->where('bill_status', 0)
  324. ->where('order_sn', $online['order_sn'])
  325. ->update([
  326. 'bill_status'=> 1,
  327. 'bill_create_time' => time()
  328. ]);
  329. // 结算积分
  330. $user_sign_score_list = Db::name('user_sign_score')
  331. ->where('status', -1)
  332. ->where('order_id', $online['order_sn'])
  333. ->whereIn('type', [1, 2])
  334. ->select()
  335. ->toArray();
  336. foreach ($user_sign_score_list as $user_sign_score) {
  337. // 修改积分
  338. Db::name('user')
  339. ->where('uid', $user_sign_score['uid'])
  340. ->inc('score', (float)$user_sign_score['reward_socre'])
  341. ->update();
  342. Db::name('user_sign_score')
  343. ->where('status', -1)
  344. ->where('id', $user_sign_score['id'])
  345. ->update([
  346. 'status' => 1,
  347. 'settlement_time' => date('Y-m-d H:i:s')
  348. ]);
  349. }
  350. // 结算复购金
  351. $user_sign_fugou_list = Db::name('user_sign_fugou')
  352. ->where('status', -1)
  353. ->where('order_id', $online['order_sn'])
  354. ->whereIn('type', [1, 2])
  355. ->select()
  356. ->toArray();
  357. foreach ($user_sign_fugou_list as $user_sign_fugou) {
  358. // 修改复购金
  359. Db::name('user')
  360. ->where('uid', $user_sign_fugou['uid'])
  361. ->inc('fugou', (float)$user_sign_fugou['number'])
  362. ->update();
  363. Db::name('user_sign_fugou')
  364. ->where('status', -1)
  365. ->where('id', $user_sign_fugou['id'])
  366. ->update([
  367. 'status' => 1,
  368. 'settlement_time' => date('Y-m-d H:i:s')
  369. ]);
  370. }
  371. // 结算贡献值
  372. $user_sign_gongxian_list = Db::name('user_sign_gongxian')
  373. ->where('status', -1)
  374. ->where('order_id', $online['order_sn'])
  375. ->whereIn('type', [1, 2])
  376. ->select()
  377. ->toArray();
  378. foreach ($user_sign_gongxian_list as $user_sign_gongxian) {
  379. // 修改贡献值
  380. Db::name('user')
  381. ->where('uid', $user_sign_gongxian['uid'])
  382. ->inc('contribute', (float)$user_sign_gongxian['number'])
  383. ->update();
  384. Db::name('user_sign_gongxian')
  385. ->where('status', -1)
  386. ->where('id', $user_sign_gongxian['id'])
  387. ->update([
  388. 'status' => 1,
  389. 'settlement_time' => date('Y-m-d H:i:s')
  390. ]);
  391. }
  392. });
  393. }
  394. }
  395. /**
  396. * 在线支付公证处IN10入账 (红包,积分,京东,佣金,复购金,养老金,贡献值)
  397. * @param $nowTime
  398. * @param $timeLimit
  399. * author: php迷途小书童
  400. * created: 2021/3/20 9:25
  401. */
  402. public function doOnlineOrderGzc($timeLimit)
  403. {
  404. return true;
  405. // 普通订单
  406. $cursor = Db::table('rrx_store_order')->where('paid', 1)->where('gzc', 0)->where('pay_type', 'in', '0,1,2,4')->cursor();
  407. $StoreOrderStatusRepository = app()->make(StoreOrderStatusRepository::class);
  408. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  409. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  410. foreach ($cursor as $online) {
  411. $status = $StoreOrderStatusRepository->getWhere(['order_id' => $online['order_id'], 'change_type' => 'take']);
  412. if ($online['mer_id'] == 496) {
  413. if (!in_array($online['status'], [0, 1, 2, 3])) {
  414. continue;
  415. }
  416. // if (time() < strtotime($online['pay_time']) + 3600 * 24) {
  417. // Log::info('还没有到收货后' . $timeLimit . '天');
  418. // continue;
  419. // }
  420. } else {
  421. if (!in_array($online['status'], [2, 3])) {
  422. continue;
  423. }
  424. if (Carbon::now()->modify("-{$timeLimit} days")->lt($status->change_time ?? $status['change_time'])) {
  425. Log::info('还没有到收货后' . $timeLimit . '天');
  426. continue;
  427. }
  428. }
  429. $certification = UserCertification::getInstance()->where('uid', $online['uid'])->find();
  430. if (!$certification) {
  431. Log::info($online['uid'] . '没有实名认证');
  432. continue;
  433. }
  434. //查询养老金金额
  435. $UserBillRepository = app()->make(UserBillRepository::class);
  436. $bill = $UserBillRepository->getWhere(['uid' => $online['uid'], 'link_id' => $online['order_id'], 'order_sn' => $online['order_sn'], 'commission_type' => 5]);
  437. $pension = $bill->number ?? 0;
  438. if ($pension <= 0) {
  439. Log::info($online['order_sn'] . 'pension' . $pension);
  440. continue;
  441. }
  442. //首信易分账
  443. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  444. if ($online['pay_type'] > 0) {
  445. $StoreOrderRepository->splitOrder($online);
  446. }
  447. Db::transaction(function () use ($certification, $online, $pension, $OrderGzcRepository, $OrderMerchantRepository, $StoreOrderRepository) {
  448. //新增入账明细记录
  449. $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  450. $create = [
  451. 'uid' => $online['uid'],
  452. 'platform_no' => $orderId,
  453. 'account_type' => $online['pay_type'] == 1 ? 3 : 2,
  454. 'user_name' => $certification['user_name'],
  455. 'mobile' => $certification['mobile'],
  456. 'user_card' => $certification['user_card'],
  457. 'pension' => $pension,
  458. 'order_type' => 2,
  459. 'out_trade_no' => $online['order_sn']
  460. ];
  461. $test_user = Db::name('user')->where('uid', $online['uid'])->value('test_user');
  462. $check = Db::name("gzc_logs")->where("out_trade_no", $online['order_sn'])->where("order_type", 2)->count();
  463. if ($test_user == 0 && $check <= 0) {
  464. $OrderGzcRepository->create($create);
  465. }
  466. $order = StoreOrder::getInstance()->find($online['order_id']);
  467. $order->gzc = 1;
  468. $order->save();
  469. // 养老金区域奖励
  470. // $order_data = [
  471. // 'pay_price' => $pension,
  472. // 'user_address_ids' => $online['user_address_ids'],
  473. // 'uid' => $online['uid'],
  474. // 'order_sn' => $online['order_sn']
  475. // ];
  476. // $StoreOrderRepository->area_manage_details($order_data, 8, 2);
  477. });
  478. }
  479. // 普通订单(红包,积分,京东,佣金,复购金,养老金,贡献值)
  480. $cursor = Db::table('rrx_store_order')->where('paid', 1)->where('is_settlement', 0)->where('pay_type', 'in', '0,1,2,4')->cursor();
  481. $StoreOrderStatusRepository = app()->make(StoreOrderStatusRepository::class);
  482. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  483. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  484. foreach ($cursor as $online) {
  485. $status = $StoreOrderStatusRepository->getWhere(['order_id' => $online['order_id'], 'change_type' => 'take']);
  486. if ($online['mer_id'] == 496) {
  487. if (!in_array($online['status'], [0, 1, 2, 3])) {
  488. continue;
  489. }
  490. if (time() < strtotime($online['pay_time']) + 3600 * 24) {
  491. Log::info('还没有到收货后' . $timeLimit . '天');
  492. continue;
  493. }
  494. } else {
  495. if (!in_array($online['status'], [2, 3])) {
  496. continue;
  497. }
  498. if (Carbon::now()->modify("-{$timeLimit} days")->lt($status->change_time ?? $status['change_time'])) {
  499. Log::info('还没有到收货后' . $timeLimit . '天');
  500. continue;
  501. }
  502. }
  503. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  504. Db::transaction(function () use ($online, $StoreOrderRepository) {
  505. $order = StoreOrder::getInstance()->find($online['order_id']);
  506. $order->is_settlement = 1;
  507. $order->settlement_time = date('Y-m-d H:i:s');
  508. $order->save();
  509. // 结算积分
  510. $user_sign_score_list = Db::name('user_sign_score')
  511. ->where('status', -1)
  512. ->where('order_id', $online['order_id'])
  513. ->whereIn('type', [1, 2])
  514. ->select()
  515. ->toArray();
  516. foreach ($user_sign_score_list as $user_sign_score) {
  517. // 修改积分
  518. Db::name('user')
  519. ->where('uid', $user_sign_score['uid'])
  520. ->inc('score', (float)$user_sign_score['reward_socre'])
  521. ->update();
  522. Db::name('user_sign_score')
  523. ->where('status', -1)
  524. ->where('id', $user_sign_score['id'])
  525. ->update([
  526. 'status' => 1,
  527. 'settlement_time' => date('Y-m-d H:i:s')
  528. ]);
  529. }
  530. // 结算红包
  531. $user_sign_hongbao_list = Db::name('user_sign_hongbao')
  532. ->where('status', -1)
  533. ->where('order_id', $online['order_id'])
  534. ->whereIn('type', [1, 2])
  535. ->select()
  536. ->toArray();
  537. foreach ($user_sign_hongbao_list as $user_sign_hongbao) {
  538. // 修改红包
  539. Db::name('user')
  540. ->where('uid', $user_sign_hongbao['uid'])
  541. ->inc('hongbao', (float)$user_sign_hongbao['number'])
  542. ->update();
  543. Db::name('user_sign_hongbao')
  544. ->where('status', -1)
  545. ->where('id', $user_sign_hongbao['id'])
  546. ->update([
  547. 'status' => 1,
  548. 'settlement_time' => date('Y-m-d H:i:s')
  549. ]);
  550. }
  551. // 结算京豆
  552. $user_sign_jingdou_list = Db::name('user_sign_jingdou')
  553. ->where('status', -1)
  554. ->where('order_id', $online['order_id'])
  555. ->whereIn('type', [1, 2])
  556. ->select()
  557. ->toArray();
  558. foreach ($user_sign_jingdou_list as $user_sign_jingdou) {
  559. // 修改京豆
  560. Db::name('user')
  561. ->where('uid', $user_sign_jingdou['uid'])
  562. ->inc('jingdou', (float)$user_sign_jingdou['number'])
  563. ->update();
  564. Db::name('user_sign_jingdou')
  565. ->where('status', -1)
  566. ->where('id', $user_sign_jingdou['id'])
  567. ->update([
  568. 'status' => 1,
  569. 'settlement_time' => date('Y-m-d H:i:s')
  570. ]);
  571. }
  572. // 结算复购金
  573. $user_sign_fugou_list = Db::name('user_sign_fugou')
  574. ->where('status', -1)
  575. ->where('order_id', $online['order_id'])
  576. ->whereIn('type', [1, 2])
  577. ->select()
  578. ->toArray();
  579. foreach ($user_sign_fugou_list as $user_sign_fugou) {
  580. // 修改复购金
  581. Db::name('user')
  582. ->where('uid', $user_sign_fugou['uid'])
  583. ->inc('fugou', (float)$user_sign_fugou['number'])
  584. ->update();
  585. Db::name('user_sign_fugou')
  586. ->where('status', -1)
  587. ->where('id', $user_sign_fugou['id'])
  588. ->update([
  589. 'status' => 1,
  590. 'settlement_time' => date('Y-m-d H:i:s')
  591. ]);
  592. }
  593. // 结算贡献值
  594. $user_sign_gongxian_list = Db::name('user_sign_gongxian')
  595. ->where('status', -1)
  596. ->where('order_id', $online['order_id'])
  597. ->whereIn('type', [1, 2])
  598. ->select()
  599. ->toArray();
  600. foreach ($user_sign_gongxian_list as $user_sign_gongxian) {
  601. // 修改贡献值
  602. Db::name('user')
  603. ->where('uid', $user_sign_gongxian['uid'])
  604. ->inc('contribute', (float)$user_sign_gongxian['number'])
  605. ->update();
  606. Db::name('user_sign_gongxian')
  607. ->where('status', -1)
  608. ->where('id', $user_sign_gongxian['id'])
  609. ->update([
  610. 'status' => 1,
  611. 'settlement_time' => date('Y-m-d H:i:s')
  612. ]);
  613. }
  614. // 结算佣金
  615. $user_bill_list = Db::name('user_bill')
  616. ->where('status', 0)
  617. ->where('commission_type','<>', 5)
  618. ->where([ 'link_id' => $online['order_id'], 'order_sn' => $online['order_sn']])
  619. ->select()
  620. ->toArray();
  621. foreach ($user_bill_list as $user_bill) {
  622. if ($user_bill['commission_type'] != 5) {
  623. if (in_array($user_bill['commission_type'], [7,12,19])) {
  624. Db::name("merchant")
  625. ->where("mer_id", $user_bill['mer_id'])
  626. ->inc('brokerage_price', (float)$user_bill['number'])
  627. ->update();
  628. } else {
  629. Db::name('user')
  630. ->where('uid', $user_bill['uid'])
  631. ->inc('brokerage_price', (float)$user_bill['number'])
  632. ->update();
  633. }
  634. }
  635. if ($online['pay_type'] == 0 && $user_bill['commission_type'] == 5) {
  636. } else {
  637. // 虚拟支付的养老金不修改不结算
  638. Db::name('user_bill')
  639. ->where('status', 0)
  640. ->where('bill_id', $user_bill['bill_id'])
  641. ->update([
  642. 'status' => 1,
  643. 'take_time' => time()
  644. ]);
  645. }
  646. if ($online['pay_type'] == 0 && $user_bill['commission_type'] == 5) {
  647. } else {
  648. // 虚拟支付的养老金不修改不结算
  649. Db::name('user_bill')
  650. ->where('status', 0)
  651. ->where('bill_id', $user_bill['bill_id'])
  652. ->update([
  653. 'status' => 1,
  654. 'take_time' => time()
  655. ]);
  656. }
  657. }
  658. //按角色结算
  659. $StoreOrderRepository->close_order($online['order_id']);
  660. });
  661. }
  662. }
  663. /**
  664. * 第三方订单拼多多IN10入账
  665. * @param $nowTime
  666. * @param $timeLimit
  667. * author: php迷途小书童
  668. * created: 2021/3/20 9:26
  669. */
  670. public function doThridPddOrderGzc($nowTime, $timeLimit)
  671. {
  672. $cursor = Db::table('rrx_order_pdd')
  673. ->where('gzc', 0)
  674. ->where('bill_status', 1)
  675. ->where('commission', '>', 0)
  676. ->whereTime('bill_end_time', '<', $nowTime - bcmul((string)$timeLimit, (string)86400))
  677. ->cursor();
  678. $ProductRepository = app()->make(ProductRepository::class);
  679. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  680. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  681. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  682. foreach ($cursor as $thrid) {
  683. $uid = $thrid['uid'];
  684. if (!$uid)
  685. continue;
  686. $certification = UserCertification::getInstance()->where('uid', $uid)->find();
  687. if (!$certification) {
  688. Log::info('用户ID' . $uid . '未实名认证');
  689. continue;
  690. }
  691. $pension = $ProductRepository->yanglaojin(0, sprintf('%.2f', $thrid['commission']));
  692. Db::transaction(function () use ($uid, $certification, $thrid, $pension, $OrderGzcRepository, $OrderMerchantRepository, $StoreOrderRepository) {
  693. //新增入账明细记录
  694. $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  695. $create = [
  696. 'uid' => $uid,
  697. 'platform_no' => $orderId,
  698. 'user_name' => $certification['user_name'],
  699. 'mobile' => $certification['mobile'],
  700. 'user_card' => $certification['user_card'],
  701. 'pension' => $pension,
  702. 'order_type' => 3,
  703. 'out_trade_no' => $thrid['order_sn']
  704. ];
  705. $test_user = Db::name('user')->where('uid', $uid)->value('test_user');
  706. if ($test_user == 0) {
  707. $OrderGzcRepository->create($create);
  708. }
  709. // $OrderGzcRepository->create($create);
  710. Db::table('rrx_order_pdd')
  711. ->update(['gzc' => 1, 'order_pdd_id' => $thrid['order_pdd_id']]);
  712. // 养老金区域奖励
  713. $order_data = [
  714. 'pay_price' => $pension,
  715. 'user_address_ids' => $thrid['user_address_ids'],
  716. 'uid' => $thrid['uid'],
  717. 'order_sn' => $thrid['order_sn']
  718. ];
  719. // $StoreOrderRepository->area_manage_details($order_data, 1, 2);
  720. });
  721. }
  722. }
  723. /**
  724. * 第三方订单京东IN10入账
  725. * @param $nowTime
  726. * @param $timeLimit
  727. * author: php迷途小书童
  728. * created: 2021/3/20 9:26
  729. */
  730. public function doThridJdOrderGzc($nowTime, $timeLimit)
  731. {
  732. $cursor = Db::table('rrx_order_jd')
  733. ->where('gzc', 0)
  734. ->where('bill_status', 1)
  735. ->where('commission', '>', 0)
  736. ->whereTime('bill_end_time', '<', $nowTime - bcmul((string)$timeLimit, (string)86400))
  737. ->cursor();
  738. // Db::name('log')->insert(['data'=>'abbbb入库语句'.$nowTime - bcmul((string)$timeLimit, (string)86400)]);
  739. // Db::name('log')->insert(['data'=>'abbbb'.json_encode($cursor)]);
  740. $ProductRepository = app()->make(ProductRepository::class);
  741. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  742. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  743. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  744. foreach ($cursor as $thrid) {
  745. $uid = $thrid['uid'];
  746. if (!$uid)
  747. continue;
  748. $certification = UserCertification::getInstance()->where('uid', $uid)->find();
  749. if (!$certification) {
  750. Log::info('用户ID' . $uid . '未实名认证');
  751. continue;
  752. }
  753. $pension = $ProductRepository->yanglaojin(0, sprintf('%.2f', $thrid['commission']));
  754. Db::transaction(function () use ($uid, $certification, $thrid, $pension, $OrderGzcRepository, $OrderMerchantRepository, $StoreOrderRepository) {
  755. //新增入账明细记录
  756. $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  757. $create = [
  758. 'uid' => $uid,
  759. 'platform_no' => $orderId,
  760. 'user_name' => $certification['user_name'],
  761. 'mobile' => $certification['mobile'],
  762. 'user_card' => $certification['user_card'],
  763. 'pension' => $pension,
  764. 'order_type' => 4,
  765. 'out_trade_no' => $thrid['order_sn']
  766. ];
  767. $test_user = Db::name('user')->where('uid', $uid)->value('test_user');
  768. if ($test_user == 0) {
  769. $OrderGzcRepository->create($create);
  770. }
  771. // $OrderGzcRepository->create($create);
  772. Db::table('rrx_order_jd')
  773. ->update(['gzc' => 1, 'order_jd_id' => $thrid['order_jd_id']]);
  774. // 养老金区域奖励
  775. $order_data = [
  776. 'pay_price' => $pension,
  777. 'user_address_ids' => $thrid['user_address_ids'],
  778. 'uid' => $thrid['uid'],
  779. 'order_sn' => $thrid['order_sn']
  780. ];
  781. // $StoreOrderRepository->area_manage_details($order_data, 6, 2);
  782. });
  783. }
  784. }
  785. /**
  786. * 第三方订单苏宁IN10入账
  787. * @param $nowTime
  788. * @param $timeLimit
  789. * author: php迷途小书童
  790. * created: 2021/3/20 9:26
  791. */
  792. public function doThridSnOrderGzc($nowTime, $timeLimit)
  793. {
  794. $cursor = Db::table('rrx_order_su')
  795. ->where('gzc', 0)
  796. ->where('bill_status', 1)
  797. ->where('commission', '>', 0)
  798. ->whereTime('bill_end_time', '<', $nowTime - bcmul((string)$timeLimit, (string)86400))
  799. ->cursor();
  800. $ProductRepository = app()->make(ProductRepository::class);
  801. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  802. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  803. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  804. foreach ($cursor as $thrid) {
  805. $uid = $thrid['uid'];
  806. if (!$uid)
  807. continue;
  808. $certification = UserCertification::getInstance()->where('uid', $uid)->find();
  809. if (!$certification) {
  810. Log::info('用户ID' . $uid . '未实名认证');
  811. continue;
  812. }
  813. $pension = $ProductRepository->yanglaojin(0, sprintf('%.2f', $thrid['commission']));
  814. Db::transaction(function () use ($uid, $certification, $thrid, $pension, $OrderGzcRepository, $OrderMerchantRepository, $StoreOrderRepository) {
  815. //新增入账明细记录
  816. $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  817. $create = [
  818. 'uid' => $uid,
  819. 'platform_no' => $orderId,
  820. 'user_name' => $certification['user_name'],
  821. 'mobile' => $certification['mobile'],
  822. 'user_card' => $certification['user_card'],
  823. 'pension' => $pension,
  824. 'order_type' => 5,
  825. 'out_trade_no' => $thrid['order_sn']
  826. ];
  827. $test_user = Db::name('user')->where('uid', $uid)->value('test_user');
  828. if ($test_user == 0) {
  829. $OrderGzcRepository->create($create);
  830. }
  831. // $OrderGzcRepository->create($create);
  832. Db::table('rrx_order_su')
  833. ->update(['gzc' => 1, 'order_su_id' => $thrid['order_su_id']]);
  834. // 养老金区域奖励
  835. $order_data = [
  836. 'pay_price' => $pension,
  837. 'user_address_ids' => $thrid['user_address_ids'],
  838. 'uid' => $thrid['uid'],
  839. 'order_sn' => $thrid['order_sn']
  840. ];
  841. // $StoreOrderRepository->area_manage_details($order_data, 3, 2);
  842. });
  843. }
  844. }
  845. /**
  846. * 第三方订单话费IN10入账
  847. * @param $nowTime
  848. * @param $timeLimit
  849. * author: php迷途小书童
  850. * created: 2021/3/20 9:26
  851. */
  852. public function doThridHfOrderGzc($nowTime, $timeLimit)
  853. {
  854. $cursor = Db::table('rrx_order_huafei')
  855. ->where('gzc', 0)
  856. ->where('bill_status', 1)
  857. ->where('commission', '>', 0)
  858. ->whereTime('bill_end_time', '<', $nowTime - bcmul((string)$timeLimit, (string)86400))
  859. ->cursor();
  860. $ProductRepository = app()->make(ProductRepository::class);
  861. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  862. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  863. foreach ($cursor as $thrid) {
  864. $uid = $thrid['uid'];
  865. if (!$uid)
  866. continue;
  867. $certification = UserCertification::getInstance()->where('uid', $uid)->find();
  868. if (!$certification) {
  869. Log::info('用户ID' . $uid . '未实名认证');
  870. continue;
  871. }
  872. $pension = $ProductRepository->yanglaojin(0, sprintf('%.2f', $thrid['commission']));
  873. Db::transaction(function () use ($uid, $certification, $thrid, $pension, $OrderGzcRepository, $OrderMerchantRepository) {
  874. //新增入账明细记录
  875. $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  876. $create = [
  877. 'uid' => $uid,
  878. 'platform_no' => $orderId,
  879. 'user_name' => $certification['user_name'],
  880. 'mobile' => $certification['mobile'],
  881. 'user_card' => $certification['user_card'],
  882. 'pension' => $pension,
  883. 'order_type' => 6,
  884. 'out_trade_no' => $thrid['order_sn']
  885. ];
  886. $test_user = Db::name('user')->where('uid', $uid)->value('test_user');
  887. if ($test_user == 0) {
  888. $OrderGzcRepository->create($create);
  889. }
  890. Db::table('rrx_order_huafei')->update(['gzc' => 1, 'order_tb_id' => $thrid['order_tb_id']]);
  891. });
  892. }
  893. }
  894. /**
  895. * 第三方订单淘宝IN10入账
  896. * @param $nowTime
  897. * @param $timeLimit
  898. * author: php迷途小书童
  899. * created: 2021/3/20 9:26
  900. */
  901. public function doThridTaobaoOrderGzc($nowTime, $timeLimit)
  902. {
  903. $cursor = Db::table('rrx_order_tb')
  904. ->where('gzc', 0)
  905. ->where('bill_status', 1)
  906. ->where('commission', '>', 0)
  907. ->whereTime('bill_end_time', '<', $nowTime - bcmul((string)$timeLimit, (string)86400))
  908. ->cursor();
  909. $ProductRepository = app()->make(ProductRepository::class);
  910. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  911. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  912. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  913. foreach ($cursor as $thrid) {
  914. $uid = $thrid['uid'];
  915. if (!$uid)
  916. continue;
  917. $certification = UserCertification::getInstance()->where('uid', $uid)->find();
  918. if (!$certification) {
  919. Log::info('用户ID' . $uid . '未实名认证');
  920. continue;
  921. }
  922. $pension = $ProductRepository->yanglaojin(0, sprintf('%.2f', $thrid['commission']));
  923. Db::transaction(function () use ($uid, $certification, $thrid, $pension, $OrderGzcRepository, $OrderMerchantRepository, $StoreOrderRepository) {
  924. //新增入账明细记录
  925. $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  926. $create = [
  927. 'uid' => $uid,
  928. 'platform_no' => $orderId,
  929. 'user_name' => $certification['user_name'],
  930. 'mobile' => $certification['mobile'],
  931. 'user_card' => $certification['user_card'],
  932. 'pension' => $pension,
  933. 'order_type' => 6,
  934. 'out_trade_no' => $thrid['order_sn']
  935. ];
  936. $test_user = Db::name('user')->where('uid', $uid)->value('test_user');
  937. if ($test_user == 0) {
  938. $OrderGzcRepository->create($create);
  939. }
  940. // $OrderGzcRepository->create($create);
  941. Db::table('rrx_order_tb')
  942. ->update(['gzc' => 1, 'order_tb_id' => $thrid['order_tb_id']]);
  943. // 养老金区域奖励
  944. $order_data = [
  945. 'pay_price' => $pension,
  946. 'user_address_ids' => $thrid['user_address_ids'],
  947. 'uid' => $thrid['uid'],
  948. 'order_sn' => $thrid['order_sn']
  949. ];
  950. // $StoreOrderRepository->area_manage_details($order_data, 5, 2);
  951. });
  952. }
  953. }
  954. /**
  955. * 第三方订单唯品会IN10入账
  956. * @param $nowTime
  957. * @param $timeLimit
  958. * author: php迷途小书童
  959. * created: 2021/3/20 9:26
  960. */
  961. public function doThridVipOrderGzc($nowTime, $timeLimit)
  962. {
  963. $cursor = Db::table('rrx_order_vip')
  964. ->where('gzc', 0)
  965. ->where('bill_status', 1)
  966. ->where('commission', '>', 0)
  967. ->whereTime('bill_end_time', '<', $nowTime - bcmul((string)$timeLimit, (string)86400))
  968. ->cursor();
  969. $ProductRepository = app()->make(ProductRepository::class);
  970. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  971. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  972. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  973. foreach ($cursor as $thrid) {
  974. $uid = $thrid['uid'];
  975. if (!$uid)
  976. continue;
  977. $certification = UserCertification::getInstance()->where('uid', $uid)->find();
  978. if (!$certification) {
  979. Log::info('用户ID' . $uid . '未实名认证');
  980. continue;
  981. }
  982. $pension = $ProductRepository->yanglaojin(0, sprintf('%.2f', $thrid['commission']));
  983. Db::transaction(function () use ($uid, $certification, $thrid, $pension, $OrderGzcRepository, $OrderMerchantRepository, $StoreOrderRepository) {
  984. //新增入账明细记录
  985. $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  986. $create = [
  987. 'uid' => $uid,
  988. 'platform_no' => $orderId,
  989. 'user_name' => $certification['user_name'],
  990. 'mobile' => $certification['mobile'],
  991. 'user_card' => $certification['user_card'],
  992. 'pension' => $pension,
  993. 'order_type' => 7,
  994. 'out_trade_no' => $thrid['order_sn']
  995. ];
  996. $test_user = Db::name('user')->where('uid', $uid)->value('test_user');
  997. if ($test_user == 0) {
  998. $OrderGzcRepository->create($create);
  999. }
  1000. // $OrderGzcRepository->create($create);
  1001. Db::table('rrx_order_vip')
  1002. ->update(['gzc' => 1, 'order_vip_id' => $thrid['order_vip_id']]);
  1003. // 养老金区域奖励
  1004. $order_data = [
  1005. 'pay_price' => $pension,
  1006. 'user_address_ids' => $thrid['user_address_ids'],
  1007. 'uid' => $thrid['uid'],
  1008. 'order_sn' => $thrid['order_sn']
  1009. ];
  1010. // $StoreOrderRepository->area_manage_details($order_data, 2, 2);
  1011. });
  1012. }
  1013. }
  1014. /**
  1015. * 第三方订单抖音IN10入账
  1016. * @param $nowTime
  1017. * @param $timeLimit
  1018. * author: php迷途小书童
  1019. * created: 2021/3/20 9:26
  1020. */
  1021. public function doThridDyOrderGzc($nowTime, $timeLimit)
  1022. {
  1023. $cursor = Db::table('rrx_order_dy')
  1024. ->where('gzc', 0)
  1025. ->where('bill_status', 1)
  1026. ->where('commission', '>', 0)
  1027. ->whereTime('bill_end_time', '<', $nowTime - bcmul((string)$timeLimit, (string)86400))
  1028. ->cursor();
  1029. $ProductRepository = app()->make(ProductRepository::class);
  1030. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  1031. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  1032. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  1033. foreach ($cursor as $thrid) {
  1034. $uid = $thrid['uid'];
  1035. if (!$uid)
  1036. continue;
  1037. $certification = UserCertification::getInstance()->where('uid', $uid)->find();
  1038. if (!$certification) {
  1039. Log::info('用户ID' . $uid . '未实名认证');
  1040. continue;
  1041. }
  1042. $pension = $ProductRepository->yanglaojin(0, sprintf('%.2f', $thrid['commission']));
  1043. Db::transaction(function () use ($uid, $certification, $thrid, $pension, $OrderGzcRepository, $OrderMerchantRepository, $StoreOrderRepository) {
  1044. //新增入账明细记录
  1045. $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  1046. $create = [
  1047. 'uid' => $uid,
  1048. 'platform_no' => $orderId,
  1049. 'user_name' => $certification['user_name'],
  1050. 'mobile' => $certification['mobile'],
  1051. 'user_card' => $certification['user_card'],
  1052. 'pension' => $pension,
  1053. 'order_type' => 8,
  1054. 'out_trade_no' => $thrid['order_sn']
  1055. ];
  1056. $test_user = Db::name('user')->where('uid', $uid)->value('test_user');
  1057. if ($test_user == 0) {
  1058. $OrderGzcRepository->create($create);
  1059. }
  1060. Db::table('rrx_order_dy')
  1061. ->update(['gzc' => 1, 'order_dy_id' => $thrid['order_dy_id']]);
  1062. // 养老金区域奖励
  1063. $order_data = [
  1064. 'pay_price' => $pension,
  1065. 'user_address_ids' => $thrid['user_address_ids'],
  1066. 'uid' => $thrid['uid'],
  1067. 'order_sn' => $thrid['order_sn']
  1068. ];
  1069. // $StoreOrderRepository->area_manage_details($order_data, 9, 2);
  1070. });
  1071. }
  1072. }
  1073. /**
  1074. * 志愿者升级
  1075. * */
  1076. public function doUpgrade()
  1077. {
  1078. set_time_limit(0);
  1079. try {
  1080. //志愿者条件
  1081. $volunteer_achievement = systemConfig("volunteer_achievement"); //volunteer_achievement:用户本人满足养老金要求可升级为志愿者
  1082. //一星条件
  1083. $a_volunteer_achievement = systemConfig("a_volunteer_achievement");//团队养老金要求
  1084. $a_volunteer_number = systemConfig("a_volunteer_number"); //团队人数要求
  1085. //二星条件
  1086. $b_volunteer_achievement = systemConfig("b_volunteer_achievement");//团队养老金要求
  1087. $b_volunteer_number = systemConfig("b_volunteer_number"); //团队人数要求
  1088. //三星条件
  1089. $c_volunteer_achievement = systemConfig("c_volunteer_achievement");//团队养老金要求
  1090. $c_volunteer_number = systemConfig("c_volunteer_number"); //团队人数要求
  1091. //董事条件
  1092. $d_volunteer_achievement = systemConfig("d_volunteer_achievement");//团队养老金要求
  1093. $d_volunteer_number = systemConfig("d_volunteer_number"); //团队人数要求
  1094. //用户列表
  1095. $userList = Db::name("User")
  1096. ->field("uid")
  1097. ->select();
  1098. foreach ($userList as $key => $value) {
  1099. $volunteer = $this->volunteer($value['uid']);
  1100. //本人养老金小于志愿者要求
  1101. if ($volunteer['self_yanglao'] < $volunteer_achievement) {
  1102. $this->grade($value['uid'], 0, $volunteer);
  1103. }
  1104. //满足志愿者要求
  1105. if ($volunteer['self_yanglao'] >= $volunteer_achievement) {
  1106. //志愿者
  1107. if ($volunteer['team'] < $a_volunteer_number || $volunteer['yanglao'] < $a_volunteer_achievement) {
  1108. $this->grade($value['uid'], 1, $volunteer);
  1109. }
  1110. //一星
  1111. if ($volunteer['team'] >= $a_volunteer_number && $volunteer['yanglao'] >= $a_volunteer_achievement//满足一星条件
  1112. &&
  1113. ($volunteer['team'] < $b_volunteer_number || $volunteer['yanglao'] < $b_volunteer_achievement)//未满足二星条件
  1114. ) {
  1115. $this->grade($value['uid'], 2, $volunteer);
  1116. }
  1117. //二星
  1118. if ($volunteer['team'] >= $b_volunteer_number && $volunteer['yanglao'] >= $b_volunteer_achievement//满足二星条件
  1119. &&
  1120. ($volunteer['team'] < $c_volunteer_number || $volunteer['yanglao'] < $c_volunteer_achievement)//未满足三星条件
  1121. ) {
  1122. $this->grade($value['uid'], 3, $volunteer);
  1123. }
  1124. //三星
  1125. if ($volunteer['team'] >= $c_volunteer_number && $volunteer['yanglao'] >= $c_volunteer_achievement//满足三星条件
  1126. &&
  1127. ($volunteer['team'] < $d_volunteer_number || $volunteer['yanglao'] < $d_volunteer_achievement)//未满足董事条件
  1128. ) {
  1129. $this->grade($value['uid'], 4, $volunteer);
  1130. }
  1131. //董事
  1132. if ($volunteer['team'] >= $d_volunteer_number && $volunteer['yanglao'] >= $d_volunteer_achievement) {
  1133. $this->grade($value['uid'], 5, $volunteer);
  1134. }
  1135. }
  1136. //团队各等级数量统计
  1137. $this->statistics($value['uid']);
  1138. }
  1139. } catch (Exception $e) {
  1140. Log::info('志愿者升级:' . $e->getMessage());
  1141. }
  1142. }
  1143. //志愿者信息
  1144. public function volunteer($uid)
  1145. {
  1146. if (!$uid) {
  1147. return false;
  1148. }
  1149. //本人养老金
  1150. $data['self_yanglao'] = $this->getYanglao($uid);
  1151. //团队人数
  1152. $data['team'] = $this->volunteer_number($uid);
  1153. //团队养老金
  1154. $data['yanglao'] = $this->volunteer_achievement($uid);
  1155. //直推人数
  1156. $data['extension'] = Db::name("user_identity_log")->where(["uid" => $uid])->count();
  1157. //直推商户数量
  1158. $data['shop'] = Db::name("user_identity_log")->where(["uid" => $uid, 'identity' => 4])->whereNotIn("identity", "0")->count();
  1159. return $data;
  1160. }
  1161. //团队人数
  1162. public function volunteer_number($uid)
  1163. {
  1164. $number = 0;
  1165. $number1 = Db::name("user_identity_log")->where(["uid" => $uid])->field("link_id")->select();
  1166. $number += count($number1);
  1167. foreach ($number1 as $key => $value) {
  1168. $number += Db::name("user_identity_log")->where(["uid" => $value['link_id']])->field("link_id")->count();
  1169. }
  1170. return $number;
  1171. }
  1172. //团队养老金
  1173. public function volunteer_achievement($uid)
  1174. {
  1175. $yanglao = 0;
  1176. $number1 = Db::name("user_identity_log")->where(["uid" => $uid])->field("link_id")->select();
  1177. foreach ($number1 as $key => $value) {
  1178. $yanglao += $this->getYanglao($value['link_id']);
  1179. $number2 = Db::name("user_identity_log")->where(["uid" => $value['link_id']])->field("link_id")->select();
  1180. foreach ($number2 as $k => $v) {
  1181. $yanglao += $this->getYanglao($v['link_id']);
  1182. }
  1183. unset($number2);
  1184. }
  1185. return $yanglao;
  1186. }
  1187. //用户养老金
  1188. public function getYanglao($uid)
  1189. {
  1190. return Db::name("UserBill")
  1191. ->where([
  1192. 'uid' => $uid,
  1193. 'commission_type' => 5,
  1194. 'status' => 1,
  1195. 'pm' => 1
  1196. ])
  1197. ->sum("number");
  1198. }
  1199. //升级
  1200. public function grade($uid, $grade, $volunteer)
  1201. {
  1202. $exist = Db::name("Volunteer")->where(["uid" => $uid])->find();
  1203. if ($exist) {
  1204. Db::name("Volunteer")
  1205. ->where(["uid" => $uid])
  1206. ->update([
  1207. "grade" => $grade,
  1208. "team" => $volunteer['team'],
  1209. "yanglao" => $volunteer['yanglao'],
  1210. "extension" => $volunteer['extension'],
  1211. "shop" => $volunteer['shop'],
  1212. "time" => time()
  1213. ]);
  1214. return true;
  1215. }
  1216. Db::name("Volunteer")
  1217. ->insert([
  1218. "uid" => $uid,
  1219. "grade" => $grade,
  1220. "team" => $volunteer['team'],
  1221. "yanglao" => $volunteer['yanglao'],
  1222. "extension" => $volunteer['extension'],
  1223. "shop" => $volunteer['shop'],
  1224. "time" => time()
  1225. ]
  1226. );
  1227. return true;
  1228. }
  1229. //下级各等级数量统计
  1230. public function statistics($uid)
  1231. {
  1232. $data = [
  1233. 'v' => 0,
  1234. 'v1' => 0,
  1235. 'v2' => 0,
  1236. 'v3' => 0,
  1237. 'v4' => 0
  1238. ];
  1239. $fns = function ($uid) use (&$fns, &$data) {
  1240. $identity = Db::name("user_identity_log")
  1241. ->alias("u")
  1242. ->join("Volunteer v", "u.link_id = v.uid")
  1243. ->where(["u.uid" => $uid])
  1244. ->field("u.link_id,v.grade")
  1245. ->select();
  1246. if ($identity) {
  1247. foreach ($identity as $key => $value) {
  1248. if ($value['grade'] == 1) {
  1249. $data['v']++;
  1250. }
  1251. if ($value['grade'] == 2) {
  1252. $data['v1']++;
  1253. }
  1254. if ($value['grade'] == 3) {
  1255. $data['v2']++;
  1256. }
  1257. if ($value['grade'] == 4) {
  1258. $data['v3']++;
  1259. }
  1260. if ($value['grade'] == 5) {
  1261. $data['v4']++;
  1262. }
  1263. $fns($value['link_id']);
  1264. }
  1265. }
  1266. };
  1267. $fns($uid);
  1268. Db::name("Volunteer")
  1269. ->where(["uid" => $uid])
  1270. ->update([
  1271. "v" => $data['v'],
  1272. "v1" => $data['v1'],
  1273. "v2" => $data['v2'],
  1274. "v3" => $data['v3'],
  1275. "v4" => $data['v4'],
  1276. "time" => time()
  1277. ]);
  1278. return $data;
  1279. }
  1280. }