PensionTasks.php 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368
  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. // 普通订单
  405. $cursor = Db::table('rrx_store_order')->where('paid', 1)->where('gzc', 0)->where('pay_type', 'in', '0,1,2,4')->cursor();
  406. $StoreOrderStatusRepository = app()->make(StoreOrderStatusRepository::class);
  407. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  408. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  409. foreach ($cursor as $online) {
  410. $status = $StoreOrderStatusRepository->getWhere(['order_id' => $online['order_id'], 'change_type' => 'take']);
  411. if ($online['mer_id'] == 496) {
  412. if (!in_array($online['status'], [0, 1, 2, 3])) {
  413. continue;
  414. }
  415. // if (time() < strtotime($online['pay_time']) + 3600 * 24) {
  416. // Log::info('还没有到收货后' . $timeLimit . '天');
  417. // continue;
  418. // }
  419. } else {
  420. if (!in_array($online['status'], [2, 3])) {
  421. continue;
  422. }
  423. if (Carbon::now()->modify("-{$timeLimit} days")->lt($status->change_time ?? $status['change_time'])) {
  424. Log::info('还没有到收货后' . $timeLimit . '天');
  425. continue;
  426. }
  427. }
  428. $certification = UserCertification::getInstance()->where('uid', $online['uid'])->find();
  429. if (!$certification) {
  430. Log::info($online['uid'] . '没有实名认证');
  431. continue;
  432. }
  433. //查询养老金金额
  434. $UserBillRepository = app()->make(UserBillRepository::class);
  435. $bill = $UserBillRepository->getWhere(['uid' => $online['uid'], 'link_id' => $online['order_id'], 'order_sn' => $online['order_sn'], 'commission_type' => 5]);
  436. $pension = $bill->number ?? 0;
  437. if ($pension <= 0) {
  438. Log::info($online['order_sn'] . 'pension' . $pension);
  439. continue;
  440. }
  441. //首信易分账
  442. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  443. if ($online['pay_type'] > 0) {
  444. $StoreOrderRepository->splitOrder($online);
  445. }
  446. Db::transaction(function () use ($certification, $online, $pension, $OrderGzcRepository, $OrderMerchantRepository, $StoreOrderRepository) {
  447. //新增入账明细记录
  448. $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  449. $create = [
  450. 'uid' => $online['uid'],
  451. 'platform_no' => $orderId,
  452. 'account_type' => $online['pay_type'] == 1 ? 3 : 2,
  453. 'user_name' => $certification['user_name'],
  454. 'mobile' => $certification['mobile'],
  455. 'user_card' => $certification['user_card'],
  456. 'pension' => $pension,
  457. 'order_type' => 2,
  458. 'out_trade_no' => $online['order_sn']
  459. ];
  460. $test_user = Db::name('user')->where('uid', $online['uid'])->value('test_user');
  461. $check = Db::name("gzc_logs")->where("out_trade_no", $online['order_sn'])->where("order_type", 2)->count();
  462. if ($test_user == 0 && $check <= 0) {
  463. $OrderGzcRepository->create($create);
  464. }
  465. $order = StoreOrder::getInstance()->find($online['order_id']);
  466. $order->gzc = 1;
  467. $order->save();
  468. // 养老金区域奖励
  469. // $order_data = [
  470. // 'pay_price' => $pension,
  471. // 'user_address_ids' => $online['user_address_ids'],
  472. // 'uid' => $online['uid'],
  473. // 'order_sn' => $online['order_sn']
  474. // ];
  475. // $StoreOrderRepository->area_manage_details($order_data, 8, 2);
  476. });
  477. }
  478. // 普通订单(红包,积分,京东,佣金,复购金,养老金,贡献值)
  479. $cursor = Db::table('rrx_store_order')->where('paid', 1)->where('is_settlement', 0)->where('pay_type', 'in', '0,1,2,4')->cursor();
  480. $StoreOrderStatusRepository = app()->make(StoreOrderStatusRepository::class);
  481. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  482. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  483. foreach ($cursor as $online) {
  484. $status = $StoreOrderStatusRepository->getWhere(['order_id' => $online['order_id'], 'change_type' => 'take']);
  485. if ($online['mer_id'] == 496) {
  486. if (!in_array($online['status'], [0, 1, 2, 3])) {
  487. continue;
  488. }
  489. if (time() < strtotime($online['pay_time']) + 3600 * 24) {
  490. Log::info('还没有到收货后' . $timeLimit . '天');
  491. continue;
  492. }
  493. } else {
  494. if (!in_array($online['status'], [2, 3])) {
  495. continue;
  496. }
  497. if (Carbon::now()->modify("-{$timeLimit} days")->lt($status->change_time ?? $status['change_time'])) {
  498. Log::info('还没有到收货后' . $timeLimit . '天');
  499. continue;
  500. }
  501. }
  502. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  503. Db::transaction(function () use ($online, $StoreOrderRepository) {
  504. $order = StoreOrder::getInstance()->find($online['order_id']);
  505. $order->is_settlement = 1;
  506. $order->settlement_time = date('Y-m-d H:i:s');
  507. $order->save();
  508. // 结算积分
  509. $user_sign_score_list = Db::name('user_sign_score')
  510. ->where('status', -1)
  511. ->where('order_id', $online['order_id'])
  512. ->whereIn('type', [1, 2])
  513. ->select()
  514. ->toArray();
  515. foreach ($user_sign_score_list as $user_sign_score) {
  516. // 修改积分
  517. Db::name('user')
  518. ->where('uid', $user_sign_score['uid'])
  519. ->inc('score', (float)$user_sign_score['reward_socre'])
  520. ->update();
  521. Db::name('user_sign_score')
  522. ->where('status', -1)
  523. ->where('id', $user_sign_score['id'])
  524. ->update([
  525. 'status' => 1,
  526. 'settlement_time' => date('Y-m-d H:i:s')
  527. ]);
  528. }
  529. // 结算红包
  530. $user_sign_hongbao_list = Db::name('user_sign_hongbao')
  531. ->where('status', -1)
  532. ->where('order_id', $online['order_id'])
  533. ->whereIn('type', [1, 2])
  534. ->select()
  535. ->toArray();
  536. foreach ($user_sign_hongbao_list as $user_sign_hongbao) {
  537. // 修改红包
  538. Db::name('user')
  539. ->where('uid', $user_sign_hongbao['uid'])
  540. ->inc('hongbao', (float)$user_sign_hongbao['number'])
  541. ->update();
  542. Db::name('user_sign_hongbao')
  543. ->where('status', -1)
  544. ->where('id', $user_sign_hongbao['id'])
  545. ->update([
  546. 'status' => 1,
  547. 'settlement_time' => date('Y-m-d H:i:s')
  548. ]);
  549. }
  550. // 结算京豆
  551. $user_sign_jingdou_list = Db::name('user_sign_jingdou')
  552. ->where('status', -1)
  553. ->where('order_id', $online['order_id'])
  554. ->whereIn('type', [1, 2])
  555. ->select()
  556. ->toArray();
  557. foreach ($user_sign_jingdou_list as $user_sign_jingdou) {
  558. // 修改京豆
  559. Db::name('user')
  560. ->where('uid', $user_sign_jingdou['uid'])
  561. ->inc('jingdou', (float)$user_sign_jingdou['number'])
  562. ->update();
  563. Db::name('user_sign_jingdou')
  564. ->where('status', -1)
  565. ->where('id', $user_sign_jingdou['id'])
  566. ->update([
  567. 'status' => 1,
  568. 'settlement_time' => date('Y-m-d H:i:s')
  569. ]);
  570. }
  571. // 结算复购金
  572. $user_sign_fugou_list = Db::name('user_sign_fugou')
  573. ->where('status', -1)
  574. ->where('order_id', $online['order_id'])
  575. ->whereIn('type', [1, 2])
  576. ->select()
  577. ->toArray();
  578. foreach ($user_sign_fugou_list as $user_sign_fugou) {
  579. // 修改复购金
  580. Db::name('user')
  581. ->where('uid', $user_sign_fugou['uid'])
  582. ->inc('fugou', (float)$user_sign_fugou['number'])
  583. ->update();
  584. Db::name('user_sign_fugou')
  585. ->where('status', -1)
  586. ->where('id', $user_sign_fugou['id'])
  587. ->update([
  588. 'status' => 1,
  589. 'settlement_time' => date('Y-m-d H:i:s')
  590. ]);
  591. }
  592. // 结算贡献值
  593. $user_sign_gongxian_list = Db::name('user_sign_gongxian')
  594. ->where('status', -1)
  595. ->where('order_id', $online['order_id'])
  596. ->whereIn('type', [1, 2])
  597. ->select()
  598. ->toArray();
  599. foreach ($user_sign_gongxian_list as $user_sign_gongxian) {
  600. // 修改贡献值
  601. Db::name('user')
  602. ->where('uid', $user_sign_gongxian['uid'])
  603. ->inc('contribute', (float)$user_sign_gongxian['number'])
  604. ->update();
  605. Db::name('user_sign_gongxian')
  606. ->where('status', -1)
  607. ->where('id', $user_sign_gongxian['id'])
  608. ->update([
  609. 'status' => 1,
  610. 'settlement_time' => date('Y-m-d H:i:s')
  611. ]);
  612. }
  613. // 结算佣金
  614. $user_bill_list = Db::name('user_bill')
  615. ->where('status', 0)
  616. ->where('commission_type','<>', 5)
  617. ->where([ 'link_id' => $online['order_id'], 'order_sn' => $online['order_sn']])
  618. ->select()
  619. ->toArray();
  620. foreach ($user_bill_list as $user_bill) {
  621. if ($user_bill['commission_type'] != 5) {
  622. if (in_array($user_bill['commission_type'], [7,12,19])) {
  623. Db::name("merchant")
  624. ->where("mer_id", $user_bill['mer_id'])
  625. ->inc('brokerage_price', (float)$user_bill['number'])
  626. ->update();
  627. } else {
  628. Db::name('user')
  629. ->where('uid', $user_bill['uid'])
  630. ->inc('brokerage_price', (float)$user_bill['number'])
  631. ->update();
  632. }
  633. }
  634. if ($online['pay_type'] == 0 && $user_bill['commission_type'] == 5) {
  635. } else {
  636. // 虚拟支付的养老金不修改不结算
  637. Db::name('user_bill')
  638. ->where('status', 0)
  639. ->where('bill_id', $user_bill['bill_id'])
  640. ->update([
  641. 'status' => 1,
  642. 'take_time' => time()
  643. ]);
  644. }
  645. if ($online['pay_type'] == 0 && $user_bill['commission_type'] == 5) {
  646. } else {
  647. // 虚拟支付的养老金不修改不结算
  648. Db::name('user_bill')
  649. ->where('status', 0)
  650. ->where('bill_id', $user_bill['bill_id'])
  651. ->update([
  652. 'status' => 1,
  653. 'take_time' => time()
  654. ]);
  655. }
  656. }
  657. //按角色结算
  658. $StoreOrderRepository->close_order($online['order_id']);
  659. });
  660. }
  661. }
  662. /**
  663. * 第三方订单拼多多IN10入账
  664. * @param $nowTime
  665. * @param $timeLimit
  666. * author: php迷途小书童
  667. * created: 2021/3/20 9:26
  668. */
  669. public function doThridPddOrderGzc($nowTime, $timeLimit)
  670. {
  671. $cursor = Db::table('rrx_order_pdd')
  672. ->where('gzc', 0)
  673. ->where('bill_status', 1)
  674. ->where('commission', '>', 0)
  675. ->whereTime('bill_end_time', '<', $nowTime - bcmul((string)$timeLimit, (string)86400))
  676. ->cursor();
  677. $ProductRepository = app()->make(ProductRepository::class);
  678. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  679. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  680. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  681. foreach ($cursor as $thrid) {
  682. $uid = $thrid['uid'];
  683. if (!$uid)
  684. continue;
  685. $certification = UserCertification::getInstance()->where('uid', $uid)->find();
  686. if (!$certification) {
  687. Log::info('用户ID' . $uid . '未实名认证');
  688. continue;
  689. }
  690. $pension = $ProductRepository->yanglaojin(0, sprintf('%.2f', $thrid['commission']));
  691. Db::transaction(function () use ($uid, $certification, $thrid, $pension, $OrderGzcRepository, $OrderMerchantRepository, $StoreOrderRepository) {
  692. //新增入账明细记录
  693. $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  694. $create = [
  695. 'uid' => $uid,
  696. 'platform_no' => $orderId,
  697. 'user_name' => $certification['user_name'],
  698. 'mobile' => $certification['mobile'],
  699. 'user_card' => $certification['user_card'],
  700. 'pension' => $pension,
  701. 'order_type' => 3,
  702. 'out_trade_no' => $thrid['order_sn']
  703. ];
  704. $test_user = Db::name('user')->where('uid', $uid)->value('test_user');
  705. if ($test_user == 0) {
  706. $OrderGzcRepository->create($create);
  707. }
  708. // $OrderGzcRepository->create($create);
  709. Db::table('rrx_order_pdd')
  710. ->update(['gzc' => 1, 'order_pdd_id' => $thrid['order_pdd_id']]);
  711. // 养老金区域奖励
  712. $order_data = [
  713. 'pay_price' => $pension,
  714. 'user_address_ids' => $thrid['user_address_ids'],
  715. 'uid' => $thrid['uid'],
  716. 'order_sn' => $thrid['order_sn']
  717. ];
  718. // $StoreOrderRepository->area_manage_details($order_data, 1, 2);
  719. });
  720. }
  721. }
  722. /**
  723. * 第三方订单京东IN10入账
  724. * @param $nowTime
  725. * @param $timeLimit
  726. * author: php迷途小书童
  727. * created: 2021/3/20 9:26
  728. */
  729. public function doThridJdOrderGzc($nowTime, $timeLimit)
  730. {
  731. $cursor = Db::table('rrx_order_jd')
  732. ->where('gzc', 0)
  733. ->where('bill_status', 1)
  734. ->where('commission', '>', 0)
  735. ->whereTime('bill_end_time', '<', $nowTime - bcmul((string)$timeLimit, (string)86400))
  736. ->cursor();
  737. // Db::name('log')->insert(['data'=>'abbbb入库语句'.$nowTime - bcmul((string)$timeLimit, (string)86400)]);
  738. // Db::name('log')->insert(['data'=>'abbbb'.json_encode($cursor)]);
  739. $ProductRepository = app()->make(ProductRepository::class);
  740. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  741. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  742. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  743. foreach ($cursor as $thrid) {
  744. $uid = $thrid['uid'];
  745. if (!$uid)
  746. continue;
  747. $certification = UserCertification::getInstance()->where('uid', $uid)->find();
  748. if (!$certification) {
  749. Log::info('用户ID' . $uid . '未实名认证');
  750. continue;
  751. }
  752. $pension = $ProductRepository->yanglaojin(0, sprintf('%.2f', $thrid['commission']));
  753. Db::transaction(function () use ($uid, $certification, $thrid, $pension, $OrderGzcRepository, $OrderMerchantRepository, $StoreOrderRepository) {
  754. //新增入账明细记录
  755. $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  756. $create = [
  757. 'uid' => $uid,
  758. 'platform_no' => $orderId,
  759. 'user_name' => $certification['user_name'],
  760. 'mobile' => $certification['mobile'],
  761. 'user_card' => $certification['user_card'],
  762. 'pension' => $pension,
  763. 'order_type' => 4,
  764. 'out_trade_no' => $thrid['order_sn']
  765. ];
  766. $test_user = Db::name('user')->where('uid', $uid)->value('test_user');
  767. if ($test_user == 0) {
  768. $OrderGzcRepository->create($create);
  769. }
  770. // $OrderGzcRepository->create($create);
  771. Db::table('rrx_order_jd')
  772. ->update(['gzc' => 1, 'order_jd_id' => $thrid['order_jd_id']]);
  773. // 养老金区域奖励
  774. $order_data = [
  775. 'pay_price' => $pension,
  776. 'user_address_ids' => $thrid['user_address_ids'],
  777. 'uid' => $thrid['uid'],
  778. 'order_sn' => $thrid['order_sn']
  779. ];
  780. // $StoreOrderRepository->area_manage_details($order_data, 6, 2);
  781. });
  782. }
  783. }
  784. /**
  785. * 第三方订单苏宁IN10入账
  786. * @param $nowTime
  787. * @param $timeLimit
  788. * author: php迷途小书童
  789. * created: 2021/3/20 9:26
  790. */
  791. public function doThridSnOrderGzc($nowTime, $timeLimit)
  792. {
  793. $cursor = Db::table('rrx_order_su')
  794. ->where('gzc', 0)
  795. ->where('bill_status', 1)
  796. ->where('commission', '>', 0)
  797. ->whereTime('bill_end_time', '<', $nowTime - bcmul((string)$timeLimit, (string)86400))
  798. ->cursor();
  799. $ProductRepository = app()->make(ProductRepository::class);
  800. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  801. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  802. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  803. foreach ($cursor as $thrid) {
  804. $uid = $thrid['uid'];
  805. if (!$uid)
  806. continue;
  807. $certification = UserCertification::getInstance()->where('uid', $uid)->find();
  808. if (!$certification) {
  809. Log::info('用户ID' . $uid . '未实名认证');
  810. continue;
  811. }
  812. $pension = $ProductRepository->yanglaojin(0, sprintf('%.2f', $thrid['commission']));
  813. Db::transaction(function () use ($uid, $certification, $thrid, $pension, $OrderGzcRepository, $OrderMerchantRepository, $StoreOrderRepository) {
  814. //新增入账明细记录
  815. $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  816. $create = [
  817. 'uid' => $uid,
  818. 'platform_no' => $orderId,
  819. 'user_name' => $certification['user_name'],
  820. 'mobile' => $certification['mobile'],
  821. 'user_card' => $certification['user_card'],
  822. 'pension' => $pension,
  823. 'order_type' => 5,
  824. 'out_trade_no' => $thrid['order_sn']
  825. ];
  826. $test_user = Db::name('user')->where('uid', $uid)->value('test_user');
  827. if ($test_user == 0) {
  828. $OrderGzcRepository->create($create);
  829. }
  830. // $OrderGzcRepository->create($create);
  831. Db::table('rrx_order_su')
  832. ->update(['gzc' => 1, 'order_su_id' => $thrid['order_su_id']]);
  833. // 养老金区域奖励
  834. $order_data = [
  835. 'pay_price' => $pension,
  836. 'user_address_ids' => $thrid['user_address_ids'],
  837. 'uid' => $thrid['uid'],
  838. 'order_sn' => $thrid['order_sn']
  839. ];
  840. // $StoreOrderRepository->area_manage_details($order_data, 3, 2);
  841. });
  842. }
  843. }
  844. /**
  845. * 第三方订单话费IN10入账
  846. * @param $nowTime
  847. * @param $timeLimit
  848. * author: php迷途小书童
  849. * created: 2021/3/20 9:26
  850. */
  851. public function doThridHfOrderGzc($nowTime, $timeLimit)
  852. {
  853. $cursor = Db::table('rrx_order_huafei')
  854. ->where('gzc', 0)
  855. ->where('bill_status', 1)
  856. ->where('commission', '>', 0)
  857. ->whereTime('bill_end_time', '<', $nowTime - bcmul((string)$timeLimit, (string)86400))
  858. ->cursor();
  859. $ProductRepository = app()->make(ProductRepository::class);
  860. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  861. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  862. foreach ($cursor as $thrid) {
  863. $uid = $thrid['uid'];
  864. if (!$uid)
  865. continue;
  866. $certification = UserCertification::getInstance()->where('uid', $uid)->find();
  867. if (!$certification) {
  868. Log::info('用户ID' . $uid . '未实名认证');
  869. continue;
  870. }
  871. $pension = $ProductRepository->yanglaojin(0, sprintf('%.2f', $thrid['commission']));
  872. Db::transaction(function () use ($uid, $certification, $thrid, $pension, $OrderGzcRepository, $OrderMerchantRepository) {
  873. //新增入账明细记录
  874. $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  875. $create = [
  876. 'uid' => $uid,
  877. 'platform_no' => $orderId,
  878. 'user_name' => $certification['user_name'],
  879. 'mobile' => $certification['mobile'],
  880. 'user_card' => $certification['user_card'],
  881. 'pension' => $pension,
  882. 'order_type' => 6,
  883. 'out_trade_no' => $thrid['order_sn']
  884. ];
  885. $test_user = Db::name('user')->where('uid', $uid)->value('test_user');
  886. if ($test_user == 0) {
  887. $OrderGzcRepository->create($create);
  888. }
  889. Db::table('rrx_order_huafei')->update(['gzc' => 1, 'order_tb_id' => $thrid['order_tb_id']]);
  890. });
  891. }
  892. }
  893. /**
  894. * 第三方订单淘宝IN10入账
  895. * @param $nowTime
  896. * @param $timeLimit
  897. * author: php迷途小书童
  898. * created: 2021/3/20 9:26
  899. */
  900. public function doThridTaobaoOrderGzc($nowTime, $timeLimit)
  901. {
  902. $cursor = Db::table('rrx_order_tb')
  903. ->where('gzc', 0)
  904. ->where('bill_status', 1)
  905. ->where('commission', '>', 0)
  906. ->whereTime('bill_end_time', '<', $nowTime - bcmul((string)$timeLimit, (string)86400))
  907. ->cursor();
  908. $ProductRepository = app()->make(ProductRepository::class);
  909. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  910. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  911. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  912. foreach ($cursor as $thrid) {
  913. $uid = $thrid['uid'];
  914. if (!$uid)
  915. continue;
  916. $certification = UserCertification::getInstance()->where('uid', $uid)->find();
  917. if (!$certification) {
  918. Log::info('用户ID' . $uid . '未实名认证');
  919. continue;
  920. }
  921. $pension = $ProductRepository->yanglaojin(0, sprintf('%.2f', $thrid['commission']));
  922. Db::transaction(function () use ($uid, $certification, $thrid, $pension, $OrderGzcRepository, $OrderMerchantRepository, $StoreOrderRepository) {
  923. //新增入账明细记录
  924. $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  925. $create = [
  926. 'uid' => $uid,
  927. 'platform_no' => $orderId,
  928. 'user_name' => $certification['user_name'],
  929. 'mobile' => $certification['mobile'],
  930. 'user_card' => $certification['user_card'],
  931. 'pension' => $pension,
  932. 'order_type' => 6,
  933. 'out_trade_no' => $thrid['order_sn']
  934. ];
  935. $test_user = Db::name('user')->where('uid', $uid)->value('test_user');
  936. if ($test_user == 0) {
  937. $OrderGzcRepository->create($create);
  938. }
  939. // $OrderGzcRepository->create($create);
  940. Db::table('rrx_order_tb')
  941. ->update(['gzc' => 1, 'order_tb_id' => $thrid['order_tb_id']]);
  942. // 养老金区域奖励
  943. $order_data = [
  944. 'pay_price' => $pension,
  945. 'user_address_ids' => $thrid['user_address_ids'],
  946. 'uid' => $thrid['uid'],
  947. 'order_sn' => $thrid['order_sn']
  948. ];
  949. // $StoreOrderRepository->area_manage_details($order_data, 5, 2);
  950. });
  951. }
  952. }
  953. /**
  954. * 第三方订单唯品会IN10入账
  955. * @param $nowTime
  956. * @param $timeLimit
  957. * author: php迷途小书童
  958. * created: 2021/3/20 9:26
  959. */
  960. public function doThridVipOrderGzc($nowTime, $timeLimit)
  961. {
  962. $cursor = Db::table('rrx_order_vip')
  963. ->where('gzc', 0)
  964. ->where('bill_status', 1)
  965. ->where('commission', '>', 0)
  966. ->whereTime('bill_end_time', '<', $nowTime - bcmul((string)$timeLimit, (string)86400))
  967. ->cursor();
  968. $ProductRepository = app()->make(ProductRepository::class);
  969. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  970. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  971. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  972. foreach ($cursor as $thrid) {
  973. $uid = $thrid['uid'];
  974. if (!$uid)
  975. continue;
  976. $certification = UserCertification::getInstance()->where('uid', $uid)->find();
  977. if (!$certification) {
  978. Log::info('用户ID' . $uid . '未实名认证');
  979. continue;
  980. }
  981. $pension = $ProductRepository->yanglaojin(0, sprintf('%.2f', $thrid['commission']));
  982. Db::transaction(function () use ($uid, $certification, $thrid, $pension, $OrderGzcRepository, $OrderMerchantRepository, $StoreOrderRepository) {
  983. //新增入账明细记录
  984. $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  985. $create = [
  986. 'uid' => $uid,
  987. 'platform_no' => $orderId,
  988. 'user_name' => $certification['user_name'],
  989. 'mobile' => $certification['mobile'],
  990. 'user_card' => $certification['user_card'],
  991. 'pension' => $pension,
  992. 'order_type' => 7,
  993. 'out_trade_no' => $thrid['order_sn']
  994. ];
  995. $test_user = Db::name('user')->where('uid', $uid)->value('test_user');
  996. if ($test_user == 0) {
  997. $OrderGzcRepository->create($create);
  998. }
  999. // $OrderGzcRepository->create($create);
  1000. Db::table('rrx_order_vip')
  1001. ->update(['gzc' => 1, 'order_vip_id' => $thrid['order_vip_id']]);
  1002. // 养老金区域奖励
  1003. $order_data = [
  1004. 'pay_price' => $pension,
  1005. 'user_address_ids' => $thrid['user_address_ids'],
  1006. 'uid' => $thrid['uid'],
  1007. 'order_sn' => $thrid['order_sn']
  1008. ];
  1009. // $StoreOrderRepository->area_manage_details($order_data, 2, 2);
  1010. });
  1011. }
  1012. }
  1013. /**
  1014. * 第三方订单抖音IN10入账
  1015. * @param $nowTime
  1016. * @param $timeLimit
  1017. * author: php迷途小书童
  1018. * created: 2021/3/20 9:26
  1019. */
  1020. public function doThridDyOrderGzc($nowTime, $timeLimit)
  1021. {
  1022. $cursor = Db::table('rrx_order_dy')
  1023. ->where('gzc', 0)
  1024. ->where('bill_status', 1)
  1025. ->where('commission', '>', 0)
  1026. ->whereTime('bill_end_time', '<', $nowTime - bcmul((string)$timeLimit, (string)86400))
  1027. ->cursor();
  1028. $ProductRepository = app()->make(ProductRepository::class);
  1029. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  1030. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  1031. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  1032. foreach ($cursor as $thrid) {
  1033. $uid = $thrid['uid'];
  1034. if (!$uid)
  1035. continue;
  1036. $certification = UserCertification::getInstance()->where('uid', $uid)->find();
  1037. if (!$certification) {
  1038. Log::info('用户ID' . $uid . '未实名认证');
  1039. continue;
  1040. }
  1041. $pension = $ProductRepository->yanglaojin(0, sprintf('%.2f', $thrid['commission']));
  1042. Db::transaction(function () use ($uid, $certification, $thrid, $pension, $OrderGzcRepository, $OrderMerchantRepository, $StoreOrderRepository) {
  1043. //新增入账明细记录
  1044. $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  1045. $create = [
  1046. 'uid' => $uid,
  1047. 'platform_no' => $orderId,
  1048. 'user_name' => $certification['user_name'],
  1049. 'mobile' => $certification['mobile'],
  1050. 'user_card' => $certification['user_card'],
  1051. 'pension' => $pension,
  1052. 'order_type' => 8,
  1053. 'out_trade_no' => $thrid['order_sn']
  1054. ];
  1055. $test_user = Db::name('user')->where('uid', $uid)->value('test_user');
  1056. if ($test_user == 0) {
  1057. $OrderGzcRepository->create($create);
  1058. }
  1059. Db::table('rrx_order_dy')
  1060. ->update(['gzc' => 1, 'order_dy_id' => $thrid['order_dy_id']]);
  1061. // 养老金区域奖励
  1062. $order_data = [
  1063. 'pay_price' => $pension,
  1064. 'user_address_ids' => $thrid['user_address_ids'],
  1065. 'uid' => $thrid['uid'],
  1066. 'order_sn' => $thrid['order_sn']
  1067. ];
  1068. // $StoreOrderRepository->area_manage_details($order_data, 9, 2);
  1069. });
  1070. }
  1071. }
  1072. /**
  1073. * 志愿者升级
  1074. * */
  1075. public function doUpgrade()
  1076. {
  1077. set_time_limit(0);
  1078. try {
  1079. //志愿者条件
  1080. $volunteer_achievement = systemConfig("volunteer_achievement"); //volunteer_achievement:用户本人满足养老金要求可升级为志愿者
  1081. //一星条件
  1082. $a_volunteer_achievement = systemConfig("a_volunteer_achievement");//团队养老金要求
  1083. $a_volunteer_number = systemConfig("a_volunteer_number"); //团队人数要求
  1084. //二星条件
  1085. $b_volunteer_achievement = systemConfig("b_volunteer_achievement");//团队养老金要求
  1086. $b_volunteer_number = systemConfig("b_volunteer_number"); //团队人数要求
  1087. //三星条件
  1088. $c_volunteer_achievement = systemConfig("c_volunteer_achievement");//团队养老金要求
  1089. $c_volunteer_number = systemConfig("c_volunteer_number"); //团队人数要求
  1090. //董事条件
  1091. $d_volunteer_achievement = systemConfig("d_volunteer_achievement");//团队养老金要求
  1092. $d_volunteer_number = systemConfig("d_volunteer_number"); //团队人数要求
  1093. //用户列表
  1094. $userList = Db::name("User")
  1095. ->field("uid")
  1096. ->select();
  1097. foreach ($userList as $key => $value) {
  1098. $volunteer = $this->volunteer($value['uid']);
  1099. //本人养老金小于志愿者要求
  1100. if ($volunteer['self_yanglao'] < $volunteer_achievement) {
  1101. $this->grade($value['uid'], 0, $volunteer);
  1102. }
  1103. //满足志愿者要求
  1104. if ($volunteer['self_yanglao'] >= $volunteer_achievement) {
  1105. //志愿者
  1106. if ($volunteer['team'] < $a_volunteer_number || $volunteer['yanglao'] < $a_volunteer_achievement) {
  1107. $this->grade($value['uid'], 1, $volunteer);
  1108. }
  1109. //一星
  1110. if ($volunteer['team'] >= $a_volunteer_number && $volunteer['yanglao'] >= $a_volunteer_achievement//满足一星条件
  1111. &&
  1112. ($volunteer['team'] < $b_volunteer_number || $volunteer['yanglao'] < $b_volunteer_achievement)//未满足二星条件
  1113. ) {
  1114. $this->grade($value['uid'], 2, $volunteer);
  1115. }
  1116. //二星
  1117. if ($volunteer['team'] >= $b_volunteer_number && $volunteer['yanglao'] >= $b_volunteer_achievement//满足二星条件
  1118. &&
  1119. ($volunteer['team'] < $c_volunteer_number || $volunteer['yanglao'] < $c_volunteer_achievement)//未满足三星条件
  1120. ) {
  1121. $this->grade($value['uid'], 3, $volunteer);
  1122. }
  1123. //三星
  1124. if ($volunteer['team'] >= $c_volunteer_number && $volunteer['yanglao'] >= $c_volunteer_achievement//满足三星条件
  1125. &&
  1126. ($volunteer['team'] < $d_volunteer_number || $volunteer['yanglao'] < $d_volunteer_achievement)//未满足董事条件
  1127. ) {
  1128. $this->grade($value['uid'], 4, $volunteer);
  1129. }
  1130. //董事
  1131. if ($volunteer['team'] >= $d_volunteer_number && $volunteer['yanglao'] >= $d_volunteer_achievement) {
  1132. $this->grade($value['uid'], 5, $volunteer);
  1133. }
  1134. }
  1135. //团队各等级数量统计
  1136. $this->statistics($value['uid']);
  1137. }
  1138. } catch (Exception $e) {
  1139. Log::info('志愿者升级:' . $e->getMessage());
  1140. }
  1141. }
  1142. //志愿者信息
  1143. public function volunteer($uid)
  1144. {
  1145. if (!$uid) {
  1146. return false;
  1147. }
  1148. //本人养老金
  1149. $data['self_yanglao'] = $this->getYanglao($uid);
  1150. //团队人数
  1151. $data['team'] = $this->volunteer_number($uid);
  1152. //团队养老金
  1153. $data['yanglao'] = $this->volunteer_achievement($uid);
  1154. //直推人数
  1155. $data['extension'] = Db::name("user_identity_log")->where(["uid" => $uid])->count();
  1156. //直推商户数量
  1157. $data['shop'] = Db::name("user_identity_log")->where(["uid" => $uid, 'identity' => 4])->whereNotIn("identity", "0")->count();
  1158. return $data;
  1159. }
  1160. //团队人数
  1161. public function volunteer_number($uid)
  1162. {
  1163. $number = 0;
  1164. $number1 = Db::name("user_identity_log")->where(["uid" => $uid])->field("link_id")->select();
  1165. $number += count($number1);
  1166. foreach ($number1 as $key => $value) {
  1167. $number += Db::name("user_identity_log")->where(["uid" => $value['link_id']])->field("link_id")->count();
  1168. }
  1169. return $number;
  1170. }
  1171. //团队养老金
  1172. public function volunteer_achievement($uid)
  1173. {
  1174. $yanglao = 0;
  1175. $number1 = Db::name("user_identity_log")->where(["uid" => $uid])->field("link_id")->select();
  1176. foreach ($number1 as $key => $value) {
  1177. $yanglao += $this->getYanglao($value['link_id']);
  1178. $number2 = Db::name("user_identity_log")->where(["uid" => $value['link_id']])->field("link_id")->select();
  1179. foreach ($number2 as $k => $v) {
  1180. $yanglao += $this->getYanglao($v['link_id']);
  1181. }
  1182. unset($number2);
  1183. }
  1184. return $yanglao;
  1185. }
  1186. //用户养老金
  1187. public function getYanglao($uid)
  1188. {
  1189. return Db::name("UserBill")
  1190. ->where([
  1191. 'uid' => $uid,
  1192. 'commission_type' => 5,
  1193. 'status' => 1,
  1194. 'pm' => 1
  1195. ])
  1196. ->sum("number");
  1197. }
  1198. //升级
  1199. public function grade($uid, $grade, $volunteer)
  1200. {
  1201. $exist = Db::name("Volunteer")->where(["uid" => $uid])->find();
  1202. if ($exist) {
  1203. Db::name("Volunteer")
  1204. ->where(["uid" => $uid])
  1205. ->update([
  1206. "grade" => $grade,
  1207. "team" => $volunteer['team'],
  1208. "yanglao" => $volunteer['yanglao'],
  1209. "extension" => $volunteer['extension'],
  1210. "shop" => $volunteer['shop'],
  1211. "time" => time()
  1212. ]);
  1213. return true;
  1214. }
  1215. Db::name("Volunteer")
  1216. ->insert([
  1217. "uid" => $uid,
  1218. "grade" => $grade,
  1219. "team" => $volunteer['team'],
  1220. "yanglao" => $volunteer['yanglao'],
  1221. "extension" => $volunteer['extension'],
  1222. "shop" => $volunteer['shop'],
  1223. "time" => time()
  1224. ]
  1225. );
  1226. return true;
  1227. }
  1228. //下级各等级数量统计
  1229. public function statistics($uid)
  1230. {
  1231. $data = [
  1232. 'v' => 0,
  1233. 'v1' => 0,
  1234. 'v2' => 0,
  1235. 'v3' => 0,
  1236. 'v4' => 0
  1237. ];
  1238. $fns = function ($uid) use (&$fns, &$data) {
  1239. $identity = Db::name("user_identity_log")
  1240. ->alias("u")
  1241. ->join("Volunteer v", "u.link_id = v.uid")
  1242. ->where(["u.uid" => $uid])
  1243. ->field("u.link_id,v.grade")
  1244. ->select();
  1245. if ($identity) {
  1246. foreach ($identity as $key => $value) {
  1247. if ($value['grade'] == 1) {
  1248. $data['v']++;
  1249. }
  1250. if ($value['grade'] == 2) {
  1251. $data['v1']++;
  1252. }
  1253. if ($value['grade'] == 3) {
  1254. $data['v2']++;
  1255. }
  1256. if ($value['grade'] == 4) {
  1257. $data['v3']++;
  1258. }
  1259. if ($value['grade'] == 5) {
  1260. $data['v4']++;
  1261. }
  1262. $fns($value['link_id']);
  1263. }
  1264. }
  1265. };
  1266. $fns($uid);
  1267. Db::name("Volunteer")
  1268. ->where(["uid" => $uid])
  1269. ->update([
  1270. "v" => $data['v'],
  1271. "v1" => $data['v1'],
  1272. "v2" => $data['v2'],
  1273. "v3" => $data['v3'],
  1274. "v4" => $data['v4'],
  1275. "time" => time()
  1276. ]);
  1277. return $data;
  1278. }
  1279. }