PensionTasks.php 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949
  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. //在线订单符合条件的养老金收集(线上收货后第8天)
  45. $this->doOnlineOrderGzc($timeLimit = 8);
  46. //第三方订单符合条件的养老金收集(三方结算后第2天)
  47. $this->doThridPddOrderGzc($nowTime, $timeLimit = 2);
  48. $this->doThridJdOrderGzc($nowTime, $timeLimit = 2);
  49. $this->doThridSnOrderGzc($nowTime, $timeLimit = 2);
  50. $this->doThridTaobaoOrderGzc($nowTime, $timeLimit = 2);
  51. $this->doThridVipOrderGzc($nowTime, $timeLimit = 2);
  52. $this->doThridDyOrderGzc($nowTime, $timeLimit = 2);
  53. //升级
  54. // $this -> doUpgrade();
  55. } catch (\Throwable $e) {
  56. Log::info('公证处入账:' . $e->getFile() . ':' . $e->getLine() . '【' . $e->getMessage() . '】');
  57. var_dump('公证处入账:' . $e->getFile() . ':' . $e->getLine() . '【' . $e->getMessage() . '】');
  58. }
  59. // 指令输出
  60. $output->writeln('pensiontask');
  61. }
  62. /**
  63. * 线下支付订单公证处IN10入账
  64. * @param $nowTime
  65. * @param $timeLimit
  66. * author: php迷途小书童
  67. * created: 2021/3/20 9:26
  68. */
  69. public function doOfflineOrderGzc($nowTime, $timeLimit)
  70. {
  71. $cursor = Db::table('rrx_order_merchant')
  72. ->whereNotNull('pay_time')
  73. ->where('paid', 1)
  74. ->where('gzc', 0)
  75. ->whereTime('pay_time', '<', $nowTime - bcmul((string)$timeLimit, (string)86400))
  76. ->cursor();
  77. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  78. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  79. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  80. foreach ($cursor as $offline) {
  81. if ($offline['mer_id'] == 496) {
  82. continue;
  83. }
  84. $uid = 0;
  85. switch ($offline['trade_type']) {
  86. case 'WX':
  87. $uid = User::getInstance()->where('wechat_user_id', $offline['pay_user_id'])->value('uid');
  88. $accountType = 3;
  89. break;
  90. case 'ALI':
  91. $uid = User::getInstance()->where('ali_user_id', $offline['pay_user_id'])->value('uid');
  92. $accountType = 2;
  93. break;
  94. default:
  95. break;
  96. }
  97. if (!$uid) {
  98. Log::info($offline['pay_user_id'] . '未绑定用户');
  99. continue;
  100. }
  101. $certification = UserCertification::getInstance()->where('uid', $uid)->find();
  102. if (!$certification) {
  103. Log::info($offline['pay_user_id'] . '未实名认证');
  104. continue;
  105. }
  106. //查询养老金金额
  107. $UserBillRepository = app()->make(UserBillRepository::class);
  108. $bill = $UserBillRepository->getWhere(['uid' => $uid, 'link_id' => $offline['id'], 'order_sn' => $offline['out_trade_no'], 'title' => '养老金']);
  109. // if ($bill->status == 0) {
  110. // Log::info($offline['out_trade_no'] . 'pension未交年费');
  111. // continue;
  112. // }
  113. $pension = $bill->number ?? 0;
  114. if ($pension <= 0) {
  115. Log::info($offline['out_trade_no'] . 'pension' . $pension);
  116. continue;
  117. }
  118. Db::transaction(function () use ($uid, $certification, $accountType, $offline, $OrderGzcRepository, $OrderMerchantRepository, $pension, $StoreOrderRepository) {
  119. $order = OrderMerchant::getInstance()->find($offline['id']);
  120. $order->gzc = 1;
  121. $order->is_settlement = 1;
  122. $order->settlement_time = date('Y-m-d H:i:s');
  123. $order->save();
  124. //新增入账明细记录
  125. $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  126. $create = [
  127. 'uid' => $uid,
  128. 'platform_no' => $orderId,
  129. 'account_type' => $accountType,
  130. 'user_name' => $certification['user_name'],
  131. 'mobile' => $certification['mobile'],
  132. 'user_card' => $certification['user_card'],
  133. 'pension' => $pension,
  134. 'order_type' => 1,
  135. 'out_trade_no' => $offline['out_trade_no']
  136. ];
  137. $test_user = Db::name('user')->where('uid', $uid)->value('test_user');
  138. if ($test_user == 0) {
  139. $OrderGzcRepository->create($create);
  140. }
  141. // 养老金区域奖励
  142. $order_data = [
  143. 'pay_price' => $pension,
  144. 'user_address_ids' => $offline['user_address_ids'],
  145. 'uid' => $offline['uid'],
  146. 'order_sn' => $offline['out_trade_no']
  147. ];
  148. // $StoreOrderRepository->area_manage_details($order_data, 0, 2);
  149. });
  150. }
  151. }
  152. /**
  153. * 在线支付公证处IN10入账
  154. * @param $nowTime
  155. * @param $timeLimit
  156. * author: php迷途小书童
  157. * created: 2021/3/20 9:25
  158. */
  159. public function doOnlineOrderGzc($timeLimit)
  160. {
  161. $cursor = Db::table('rrx_store_order')
  162. ->where('paid', 1)
  163. ->where('gzc', 0)
  164. ->where('pay_type', 'in', '0,1,2,4')
  165. ->cursor();
  166. $StoreOrderStatusRepository = app()->make(StoreOrderStatusRepository::class);
  167. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  168. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  169. foreach ($cursor as $online) {
  170. $status = $StoreOrderStatusRepository->getWhere(['order_id' => $online['order_id'], 'change_type' => 'take']);
  171. if ($online['mer_id'] == 496) {
  172. if (!in_array($online['status'], [0, 1, 2, 3])) {
  173. continue;
  174. }
  175. if (time() < strtotime($online['pay_time']) + 3600 * 24) {
  176. Log::info('还没有到收货后' . $timeLimit . '天');
  177. continue;
  178. }
  179. } else {
  180. if (!in_array($online['status'], [2, 3])) {
  181. continue;
  182. }
  183. if (Carbon::now()->modify("-{$timeLimit} days")->lt($status->change_time ?? $status['change_time'])) {
  184. Log::info('还没有到收货后' . $timeLimit . '天');
  185. continue;
  186. }
  187. }
  188. $certification = UserCertification::getInstance()->where('uid', $online['uid'])->find();
  189. if (!$certification) {
  190. Log::info($online['uid'] . '没有实名认证');
  191. continue;
  192. }
  193. //查询养老金金额
  194. $UserBillRepository = app()->make(UserBillRepository::class);
  195. $bill = $UserBillRepository->getWhere(['uid' => $online['uid'], 'link_id' => $online['order_id'], 'order_sn' => $online['order_sn'], 'commission_type' => 5]);
  196. $pension = $bill->number ?? 0;
  197. if ($pension <= 0) {
  198. Log::info($online['order_sn'] . 'pension' . $pension);
  199. continue;
  200. }
  201. //首信易分账
  202. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  203. if ($online['pay_type'] > 0) {
  204. $StoreOrderRepository->splitOrder($online);
  205. }
  206. Db::transaction(function () use ($certification, $online, $pension, $OrderGzcRepository, $OrderMerchantRepository, $StoreOrderRepository) {
  207. //新增入账明细记录
  208. $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  209. $create = [
  210. 'uid' => $online['uid'],
  211. 'platform_no' => $orderId,
  212. 'account_type' => $online['pay_type'] == 1 ? 3 : 2,
  213. 'user_name' => $certification['user_name'],
  214. 'mobile' => $certification['mobile'],
  215. 'user_card' => $certification['user_card'],
  216. 'pension' => $pension,
  217. 'order_type' => 2,
  218. 'out_trade_no' => $online['order_sn']
  219. ];
  220. $test_user = Db::name('user')->where('uid', $online['uid'])->value('test_user');
  221. $check = Db::name("gzc_logs")->where("out_trade_no", $online['order_sn'])->where("order_type", 2)->count();
  222. if ($test_user == 0 && $check <= 0) {
  223. $OrderGzcRepository->create($create);
  224. }
  225. $order = StoreOrder::getInstance()->find($online['order_id']);
  226. $order->gzc = 1;
  227. $order->save();
  228. // 养老金区域奖励
  229. // $order_data = [
  230. // 'pay_price' => $pension,
  231. // 'user_address_ids' => $online['user_address_ids'],
  232. // 'uid' => $online['uid'],
  233. // 'order_sn' => $online['order_sn']
  234. // ];
  235. // $StoreOrderRepository->area_manage_details($order_data, 8, 2);
  236. });
  237. }
  238. $cursor = Db::table('rrx_store_order')
  239. ->where('paid', 1)
  240. ->where('is_settlement', 0)
  241. ->where('pay_type', 'in', '0,1,2,4')
  242. ->cursor();
  243. $StoreOrderStatusRepository = app()->make(StoreOrderStatusRepository::class);
  244. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  245. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  246. foreach ($cursor as $online) {
  247. $status = $StoreOrderStatusRepository->getWhere(['order_id' => $online['order_id'], 'change_type' => 'take']);
  248. if ($online['mer_id'] == 496) {
  249. if (!in_array($online['status'], [0, 1, 2, 3])) {
  250. continue;
  251. }
  252. if (time() < strtotime($online['pay_time']) + 3600 * 24) {
  253. Log::info('还没有到收货后' . $timeLimit . '天');
  254. continue;
  255. }
  256. } else {
  257. if (!in_array($online['status'], [2, 3])) {
  258. continue;
  259. }
  260. if (Carbon::now()->modify("-{$timeLimit} days")->lt($status->change_time ?? $status['change_time'])) {
  261. Log::info('还没有到收货后' . $timeLimit . '天');
  262. continue;
  263. }
  264. }
  265. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  266. Db::transaction(function () use ($online, $StoreOrderRepository) {
  267. $order = StoreOrder::getInstance()->find($online['order_id']);
  268. $order->is_settlement = 1;
  269. $order->settlement_time = date('Y-m-d H:i:s');
  270. $order->save();
  271. // 结算积分
  272. $user_sign_score_list = Db::name('user_sign_score')
  273. ->where('status', -1)
  274. ->where('order_id', $online['order_id'])
  275. ->whereIn('type', [1, 2])
  276. ->select()
  277. ->toArray();
  278. foreach ($user_sign_score_list as $user_sign_score) {
  279. // 修改积分
  280. Db::name('user')
  281. ->where('uid', $user_sign_score['uid'])
  282. ->inc('score', (float)$user_sign_score['reward_socre'])
  283. ->update();
  284. Db::name('user_sign_score')
  285. ->where('status', -1)
  286. ->where('id', $user_sign_score['id'])
  287. ->update([
  288. 'status' => 1,
  289. 'settlement_time' => date('Y-m-d H:i:s')
  290. ]);
  291. }
  292. $user_bill_list = Db::name('user_bill')
  293. ->where('status', 0)
  294. ->where('commission_type','<>', 5)
  295. ->where([ 'link_id' => $online['order_id'], 'order_sn' => $online['order_sn']])
  296. ->select()
  297. ->toArray();
  298. foreach ($user_bill_list as $user_bill) {
  299. if ($user_bill['commission_type'] != 5) {
  300. if (in_array($user_bill['commission_type'], [7,12,19])) {
  301. Db::name("merchant")
  302. ->where("mer_id", $user_bill['mer_id'])
  303. ->inc('brokerage_price', (float)$user_bill['number'])
  304. ->update();
  305. } else {
  306. Db::name('user')
  307. ->where('uid', $user_bill['uid'])
  308. ->inc('brokerage_price', (float)$user_bill['number'])
  309. ->update();
  310. }
  311. }
  312. if ($online['pay_type'] == 0 && $user_bill['commission_type'] == 5) {
  313. } else {
  314. // 虚拟支付的养老金不修改不结算
  315. Db::name('user_bill')
  316. ->where('status', 0)
  317. ->where('bill_id', $user_bill['bill_id'])
  318. ->update([
  319. 'status' => 1,
  320. 'take_time' => time()
  321. ]);
  322. }
  323. if ($online['pay_type'] == 0 && $user_bill['commission_type'] == 5) {
  324. } else {
  325. // 虚拟支付的养老金不修改不结算
  326. Db::name('user_bill')
  327. ->where('status', 0)
  328. ->where('bill_id', $user_bill['bill_id'])
  329. ->update([
  330. 'status' => 1,
  331. 'take_time' => time()
  332. ]);
  333. }
  334. }
  335. $StoreOrderRepository->close_order($online['order_id']);
  336. });
  337. }
  338. }
  339. /**
  340. * 第三方订单拼多多IN10入账
  341. * @param $nowTime
  342. * @param $timeLimit
  343. * author: php迷途小书童
  344. * created: 2021/3/20 9:26
  345. */
  346. public function doThridPddOrderGzc($nowTime, $timeLimit)
  347. {
  348. $cursor = Db::table('rrx_order_pdd')
  349. ->where('gzc', 0)
  350. ->where('bill_status', 1)
  351. ->where('commission', '>', 0)
  352. ->whereTime('bill_end_time', '<', $nowTime - bcmul((string)$timeLimit, (string)86400))
  353. ->cursor();
  354. $ProductRepository = app()->make(ProductRepository::class);
  355. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  356. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  357. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  358. foreach ($cursor as $thrid) {
  359. $uid = $thrid['uid'];
  360. if (!$uid)
  361. continue;
  362. $certification = UserCertification::getInstance()->where('uid', $uid)->find();
  363. if (!$certification) {
  364. Log::info('用户ID' . $uid . '未实名认证');
  365. continue;
  366. }
  367. $pension = $ProductRepository->yanglaojin(0, sprintf('%.2f', $thrid['commission']));
  368. Db::transaction(function () use ($uid, $certification, $thrid, $pension, $OrderGzcRepository, $OrderMerchantRepository, $StoreOrderRepository) {
  369. //新增入账明细记录
  370. $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  371. $create = [
  372. 'uid' => $uid,
  373. 'platform_no' => $orderId,
  374. 'user_name' => $certification['user_name'],
  375. 'mobile' => $certification['mobile'],
  376. 'user_card' => $certification['user_card'],
  377. 'pension' => $pension,
  378. 'order_type' => 3,
  379. 'out_trade_no' => $thrid['order_sn']
  380. ];
  381. $test_user = Db::name('user')->where('uid', $uid)->value('test_user');
  382. if ($test_user == 0) {
  383. $OrderGzcRepository->create($create);
  384. }
  385. // $OrderGzcRepository->create($create);
  386. Db::table('rrx_order_pdd')
  387. ->update(['gzc' => 1, 'order_pdd_id' => $thrid['order_pdd_id']]);
  388. // 养老金区域奖励
  389. $order_data = [
  390. 'pay_price' => $pension,
  391. 'user_address_ids' => $thrid['user_address_ids'],
  392. 'uid' => $thrid['uid'],
  393. 'order_sn' => $thrid['order_sn']
  394. ];
  395. // $StoreOrderRepository->area_manage_details($order_data, 1, 2);
  396. });
  397. }
  398. }
  399. /**
  400. * 第三方订单京东IN10入账
  401. * @param $nowTime
  402. * @param $timeLimit
  403. * author: php迷途小书童
  404. * created: 2021/3/20 9:26
  405. */
  406. public function doThridJdOrderGzc($nowTime, $timeLimit)
  407. {
  408. $cursor = Db::table('rrx_order_jd')
  409. ->where('gzc', 0)
  410. ->where('bill_status', 1)
  411. ->where('commission', '>', 0)
  412. ->whereTime('bill_end_time', '<', $nowTime - bcmul((string)$timeLimit, (string)86400))
  413. ->cursor();
  414. // Db::name('log')->insert(['data'=>'abbbb入库语句'.$nowTime - bcmul((string)$timeLimit, (string)86400)]);
  415. // Db::name('log')->insert(['data'=>'abbbb'.json_encode($cursor)]);
  416. $ProductRepository = app()->make(ProductRepository::class);
  417. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  418. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  419. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  420. foreach ($cursor as $thrid) {
  421. $uid = $thrid['uid'];
  422. if (!$uid)
  423. continue;
  424. $certification = UserCertification::getInstance()->where('uid', $uid)->find();
  425. if (!$certification) {
  426. Log::info('用户ID' . $uid . '未实名认证');
  427. continue;
  428. }
  429. $pension = $ProductRepository->yanglaojin(0, sprintf('%.2f', $thrid['commission']));
  430. Db::transaction(function () use ($uid, $certification, $thrid, $pension, $OrderGzcRepository, $OrderMerchantRepository, $StoreOrderRepository) {
  431. //新增入账明细记录
  432. $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  433. $create = [
  434. 'uid' => $uid,
  435. 'platform_no' => $orderId,
  436. 'user_name' => $certification['user_name'],
  437. 'mobile' => $certification['mobile'],
  438. 'user_card' => $certification['user_card'],
  439. 'pension' => $pension,
  440. 'order_type' => 4,
  441. 'out_trade_no' => $thrid['order_sn']
  442. ];
  443. $test_user = Db::name('user')->where('uid', $uid)->value('test_user');
  444. if ($test_user == 0) {
  445. $OrderGzcRepository->create($create);
  446. }
  447. // $OrderGzcRepository->create($create);
  448. Db::table('rrx_order_jd')
  449. ->update(['gzc' => 1, 'order_jd_id' => $thrid['order_jd_id']]);
  450. // 养老金区域奖励
  451. $order_data = [
  452. 'pay_price' => $pension,
  453. 'user_address_ids' => $thrid['user_address_ids'],
  454. 'uid' => $thrid['uid'],
  455. 'order_sn' => $thrid['order_sn']
  456. ];
  457. // $StoreOrderRepository->area_manage_details($order_data, 6, 2);
  458. });
  459. }
  460. }
  461. /**
  462. * 第三方订单苏宁IN10入账
  463. * @param $nowTime
  464. * @param $timeLimit
  465. * author: php迷途小书童
  466. * created: 2021/3/20 9:26
  467. */
  468. public function doThridSnOrderGzc($nowTime, $timeLimit)
  469. {
  470. $cursor = Db::table('rrx_order_su')
  471. ->where('gzc', 0)
  472. ->where('bill_status', 1)
  473. ->where('commission', '>', 0)
  474. ->whereTime('bill_end_time', '<', $nowTime - bcmul((string)$timeLimit, (string)86400))
  475. ->cursor();
  476. $ProductRepository = app()->make(ProductRepository::class);
  477. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  478. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  479. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  480. foreach ($cursor as $thrid) {
  481. $uid = $thrid['uid'];
  482. if (!$uid)
  483. continue;
  484. $certification = UserCertification::getInstance()->where('uid', $uid)->find();
  485. if (!$certification) {
  486. Log::info('用户ID' . $uid . '未实名认证');
  487. continue;
  488. }
  489. $pension = $ProductRepository->yanglaojin(0, sprintf('%.2f', $thrid['commission']));
  490. Db::transaction(function () use ($uid, $certification, $thrid, $pension, $OrderGzcRepository, $OrderMerchantRepository, $StoreOrderRepository) {
  491. //新增入账明细记录
  492. $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  493. $create = [
  494. 'uid' => $uid,
  495. 'platform_no' => $orderId,
  496. 'user_name' => $certification['user_name'],
  497. 'mobile' => $certification['mobile'],
  498. 'user_card' => $certification['user_card'],
  499. 'pension' => $pension,
  500. 'order_type' => 5,
  501. 'out_trade_no' => $thrid['order_sn']
  502. ];
  503. $test_user = Db::name('user')->where('uid', $uid)->value('test_user');
  504. if ($test_user == 0) {
  505. $OrderGzcRepository->create($create);
  506. }
  507. // $OrderGzcRepository->create($create);
  508. Db::table('rrx_order_su')
  509. ->update(['gzc' => 1, 'order_su_id' => $thrid['order_su_id']]);
  510. // 养老金区域奖励
  511. $order_data = [
  512. 'pay_price' => $pension,
  513. 'user_address_ids' => $thrid['user_address_ids'],
  514. 'uid' => $thrid['uid'],
  515. 'order_sn' => $thrid['order_sn']
  516. ];
  517. // $StoreOrderRepository->area_manage_details($order_data, 3, 2);
  518. });
  519. }
  520. }
  521. /**
  522. * 第三方订单淘宝IN10入账
  523. * @param $nowTime
  524. * @param $timeLimit
  525. * author: php迷途小书童
  526. * created: 2021/3/20 9:26
  527. */
  528. public function doThridTaobaoOrderGzc($nowTime, $timeLimit)
  529. {
  530. $cursor = Db::table('rrx_order_tb')
  531. ->where('gzc', 0)
  532. ->where('bill_status', 1)
  533. ->where('commission', '>', 0)
  534. ->whereTime('bill_end_time', '<', $nowTime - bcmul((string)$timeLimit, (string)86400))
  535. ->cursor();
  536. $ProductRepository = app()->make(ProductRepository::class);
  537. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  538. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  539. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  540. foreach ($cursor as $thrid) {
  541. $uid = $thrid['uid'];
  542. if (!$uid)
  543. continue;
  544. $certification = UserCertification::getInstance()->where('uid', $uid)->find();
  545. if (!$certification) {
  546. Log::info('用户ID' . $uid . '未实名认证');
  547. continue;
  548. }
  549. $pension = $ProductRepository->yanglaojin(0, sprintf('%.2f', $thrid['commission']));
  550. Db::transaction(function () use ($uid, $certification, $thrid, $pension, $OrderGzcRepository, $OrderMerchantRepository, $StoreOrderRepository) {
  551. //新增入账明细记录
  552. $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  553. $create = [
  554. 'uid' => $uid,
  555. 'platform_no' => $orderId,
  556. 'user_name' => $certification['user_name'],
  557. 'mobile' => $certification['mobile'],
  558. 'user_card' => $certification['user_card'],
  559. 'pension' => $pension,
  560. 'order_type' => 6,
  561. 'out_trade_no' => $thrid['order_sn']
  562. ];
  563. $test_user = Db::name('user')->where('uid', $uid)->value('test_user');
  564. if ($test_user == 0) {
  565. $OrderGzcRepository->create($create);
  566. }
  567. // $OrderGzcRepository->create($create);
  568. Db::table('rrx_order_tb')
  569. ->update(['gzc' => 1, 'order_tb_id' => $thrid['order_tb_id']]);
  570. // 养老金区域奖励
  571. $order_data = [
  572. 'pay_price' => $pension,
  573. 'user_address_ids' => $thrid['user_address_ids'],
  574. 'uid' => $thrid['uid'],
  575. 'order_sn' => $thrid['order_sn']
  576. ];
  577. // $StoreOrderRepository->area_manage_details($order_data, 5, 2);
  578. });
  579. }
  580. }
  581. /**
  582. * 第三方订单唯品会IN10入账
  583. * @param $nowTime
  584. * @param $timeLimit
  585. * author: php迷途小书童
  586. * created: 2021/3/20 9:26
  587. */
  588. public function doThridVipOrderGzc($nowTime, $timeLimit)
  589. {
  590. $cursor = Db::table('rrx_order_vip')
  591. ->where('gzc', 0)
  592. ->where('bill_status', 1)
  593. ->where('commission', '>', 0)
  594. ->whereTime('bill_end_time', '<', $nowTime - bcmul((string)$timeLimit, (string)86400))
  595. ->cursor();
  596. $ProductRepository = app()->make(ProductRepository::class);
  597. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  598. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  599. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  600. foreach ($cursor as $thrid) {
  601. $uid = $thrid['uid'];
  602. if (!$uid)
  603. continue;
  604. $certification = UserCertification::getInstance()->where('uid', $uid)->find();
  605. if (!$certification) {
  606. Log::info('用户ID' . $uid . '未实名认证');
  607. continue;
  608. }
  609. $pension = $ProductRepository->yanglaojin(0, sprintf('%.2f', $thrid['commission']));
  610. Db::transaction(function () use ($uid, $certification, $thrid, $pension, $OrderGzcRepository, $OrderMerchantRepository, $StoreOrderRepository) {
  611. //新增入账明细记录
  612. $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  613. $create = [
  614. 'uid' => $uid,
  615. 'platform_no' => $orderId,
  616. 'user_name' => $certification['user_name'],
  617. 'mobile' => $certification['mobile'],
  618. 'user_card' => $certification['user_card'],
  619. 'pension' => $pension,
  620. 'order_type' => 7,
  621. 'out_trade_no' => $thrid['order_sn']
  622. ];
  623. $test_user = Db::name('user')->where('uid', $uid)->value('test_user');
  624. if ($test_user == 0) {
  625. $OrderGzcRepository->create($create);
  626. }
  627. // $OrderGzcRepository->create($create);
  628. Db::table('rrx_order_vip')
  629. ->update(['gzc' => 1, 'order_vip_id' => $thrid['order_vip_id']]);
  630. // 养老金区域奖励
  631. $order_data = [
  632. 'pay_price' => $pension,
  633. 'user_address_ids' => $thrid['user_address_ids'],
  634. 'uid' => $thrid['uid'],
  635. 'order_sn' => $thrid['order_sn']
  636. ];
  637. // $StoreOrderRepository->area_manage_details($order_data, 2, 2);
  638. });
  639. }
  640. }
  641. /**
  642. * 第三方订单抖音IN10入账
  643. * @param $nowTime
  644. * @param $timeLimit
  645. * author: php迷途小书童
  646. * created: 2021/3/20 9:26
  647. */
  648. public function doThridDyOrderGzc($nowTime, $timeLimit)
  649. {
  650. $cursor = Db::table('rrx_order_dy')
  651. ->where('gzc', 0)
  652. ->where('bill_status', 1)
  653. ->where('commission', '>', 0)
  654. ->whereTime('bill_end_time', '<', $nowTime - bcmul((string)$timeLimit, (string)86400))
  655. ->cursor();
  656. $ProductRepository = app()->make(ProductRepository::class);
  657. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  658. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  659. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  660. foreach ($cursor as $thrid) {
  661. $uid = $thrid['uid'];
  662. if (!$uid)
  663. continue;
  664. $certification = UserCertification::getInstance()->where('uid', $uid)->find();
  665. if (!$certification) {
  666. Log::info('用户ID' . $uid . '未实名认证');
  667. continue;
  668. }
  669. $pension = $ProductRepository->yanglaojin(0, sprintf('%.2f', $thrid['commission']));
  670. Db::transaction(function () use ($uid, $certification, $thrid, $pension, $OrderGzcRepository, $OrderMerchantRepository, $StoreOrderRepository) {
  671. //新增入账明细记录
  672. $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  673. $create = [
  674. 'uid' => $uid,
  675. 'platform_no' => $orderId,
  676. 'user_name' => $certification['user_name'],
  677. 'mobile' => $certification['mobile'],
  678. 'user_card' => $certification['user_card'],
  679. 'pension' => $pension,
  680. 'order_type' => 8,
  681. 'out_trade_no' => $thrid['order_sn']
  682. ];
  683. $test_user = Db::name('user')->where('uid', $uid)->value('test_user');
  684. if ($test_user == 0) {
  685. $OrderGzcRepository->create($create);
  686. }
  687. Db::table('rrx_order_dy')
  688. ->update(['gzc' => 1, 'order_dy_id' => $thrid['order_dy_id']]);
  689. // 养老金区域奖励
  690. $order_data = [
  691. 'pay_price' => $pension,
  692. 'user_address_ids' => $thrid['user_address_ids'],
  693. 'uid' => $thrid['uid'],
  694. 'order_sn' => $thrid['order_sn']
  695. ];
  696. // $StoreOrderRepository->area_manage_details($order_data, 9, 2);
  697. });
  698. }
  699. }
  700. /**
  701. * 志愿者升级
  702. * */
  703. public function doUpgrade()
  704. {
  705. set_time_limit(0);
  706. try {
  707. //志愿者条件
  708. $volunteer_achievement = systemConfig("volunteer_achievement"); //volunteer_achievement:用户本人满足养老金要求可升级为志愿者
  709. //一星条件
  710. $a_volunteer_achievement = systemConfig("a_volunteer_achievement");//团队养老金要求
  711. $a_volunteer_number = systemConfig("a_volunteer_number"); //团队人数要求
  712. //二星条件
  713. $b_volunteer_achievement = systemConfig("b_volunteer_achievement");//团队养老金要求
  714. $b_volunteer_number = systemConfig("b_volunteer_number"); //团队人数要求
  715. //三星条件
  716. $c_volunteer_achievement = systemConfig("c_volunteer_achievement");//团队养老金要求
  717. $c_volunteer_number = systemConfig("c_volunteer_number"); //团队人数要求
  718. //董事条件
  719. $d_volunteer_achievement = systemConfig("d_volunteer_achievement");//团队养老金要求
  720. $d_volunteer_number = systemConfig("d_volunteer_number"); //团队人数要求
  721. //用户列表
  722. $userList = Db::name("User")
  723. ->field("uid")
  724. ->select();
  725. foreach ($userList as $key => $value) {
  726. $volunteer = $this->volunteer($value['uid']);
  727. //本人养老金小于志愿者要求
  728. if ($volunteer['self_yanglao'] < $volunteer_achievement) {
  729. $this->grade($value['uid'], 0, $volunteer);
  730. }
  731. //满足志愿者要求
  732. if ($volunteer['self_yanglao'] >= $volunteer_achievement) {
  733. //志愿者
  734. if ($volunteer['team'] < $a_volunteer_number || $volunteer['yanglao'] < $a_volunteer_achievement) {
  735. $this->grade($value['uid'], 1, $volunteer);
  736. }
  737. //一星
  738. if ($volunteer['team'] >= $a_volunteer_number && $volunteer['yanglao'] >= $a_volunteer_achievement//满足一星条件
  739. &&
  740. ($volunteer['team'] < $b_volunteer_number || $volunteer['yanglao'] < $b_volunteer_achievement)//未满足二星条件
  741. ) {
  742. $this->grade($value['uid'], 2, $volunteer);
  743. }
  744. //二星
  745. if ($volunteer['team'] >= $b_volunteer_number && $volunteer['yanglao'] >= $b_volunteer_achievement//满足二星条件
  746. &&
  747. ($volunteer['team'] < $c_volunteer_number || $volunteer['yanglao'] < $c_volunteer_achievement)//未满足三星条件
  748. ) {
  749. $this->grade($value['uid'], 3, $volunteer);
  750. }
  751. //三星
  752. if ($volunteer['team'] >= $c_volunteer_number && $volunteer['yanglao'] >= $c_volunteer_achievement//满足三星条件
  753. &&
  754. ($volunteer['team'] < $d_volunteer_number || $volunteer['yanglao'] < $d_volunteer_achievement)//未满足董事条件
  755. ) {
  756. $this->grade($value['uid'], 4, $volunteer);
  757. }
  758. //董事
  759. if ($volunteer['team'] >= $d_volunteer_number && $volunteer['yanglao'] >= $d_volunteer_achievement) {
  760. $this->grade($value['uid'], 5, $volunteer);
  761. }
  762. }
  763. //团队各等级数量统计
  764. $this->statistics($value['uid']);
  765. }
  766. } catch (Exception $e) {
  767. Log::info('志愿者升级:' . $e->getMessage());
  768. }
  769. }
  770. //志愿者信息
  771. public function volunteer($uid)
  772. {
  773. if (!$uid) {
  774. return false;
  775. }
  776. //本人养老金
  777. $data['self_yanglao'] = $this->getYanglao($uid);
  778. //团队人数
  779. $data['team'] = $this->volunteer_number($uid);
  780. //团队养老金
  781. $data['yanglao'] = $this->volunteer_achievement($uid);
  782. //直推人数
  783. $data['extension'] = Db::name("user_identity_log")->where(["uid" => $uid])->count();
  784. //直推商户数量
  785. $data['shop'] = Db::name("user_identity_log")->where(["uid" => $uid, 'identity' => 4])->whereNotIn("identity", "0")->count();
  786. return $data;
  787. }
  788. //团队人数
  789. public function volunteer_number($uid)
  790. {
  791. $number = 0;
  792. $number1 = Db::name("user_identity_log")->where(["uid" => $uid])->field("link_id")->select();
  793. $number += count($number1);
  794. foreach ($number1 as $key => $value) {
  795. $number += Db::name("user_identity_log")->where(["uid" => $value['link_id']])->field("link_id")->count();
  796. }
  797. return $number;
  798. }
  799. //团队养老金
  800. public function volunteer_achievement($uid)
  801. {
  802. $yanglao = 0;
  803. $number1 = Db::name("user_identity_log")->where(["uid" => $uid])->field("link_id")->select();
  804. foreach ($number1 as $key => $value) {
  805. $yanglao += $this->getYanglao($value['link_id']);
  806. $number2 = Db::name("user_identity_log")->where(["uid" => $value['link_id']])->field("link_id")->select();
  807. foreach ($number2 as $k => $v) {
  808. $yanglao += $this->getYanglao($v['link_id']);
  809. }
  810. unset($number2);
  811. }
  812. return $yanglao;
  813. }
  814. //用户养老金
  815. public function getYanglao($uid)
  816. {
  817. return Db::name("UserBill")
  818. ->where([
  819. 'uid' => $uid,
  820. 'commission_type' => 5,
  821. 'status' => 1,
  822. 'pm' => 1
  823. ])
  824. ->sum("number");
  825. }
  826. //升级
  827. public function grade($uid, $grade, $volunteer)
  828. {
  829. $exist = Db::name("Volunteer")->where(["uid" => $uid])->find();
  830. if ($exist) {
  831. Db::name("Volunteer")
  832. ->where(["uid" => $uid])
  833. ->update([
  834. "grade" => $grade,
  835. "team" => $volunteer['team'],
  836. "yanglao" => $volunteer['yanglao'],
  837. "extension" => $volunteer['extension'],
  838. "shop" => $volunteer['shop'],
  839. "time" => time()
  840. ]);
  841. return true;
  842. }
  843. Db::name("Volunteer")
  844. ->insert([
  845. "uid" => $uid,
  846. "grade" => $grade,
  847. "team" => $volunteer['team'],
  848. "yanglao" => $volunteer['yanglao'],
  849. "extension" => $volunteer['extension'],
  850. "shop" => $volunteer['shop'],
  851. "time" => time()
  852. ]
  853. );
  854. return true;
  855. }
  856. //下级各等级数量统计
  857. public function statistics($uid)
  858. {
  859. $data = [
  860. 'v' => 0,
  861. 'v1' => 0,
  862. 'v2' => 0,
  863. 'v3' => 0,
  864. 'v4' => 0
  865. ];
  866. $fns = function ($uid) use (&$fns, &$data) {
  867. $identity = Db::name("user_identity_log")
  868. ->alias("u")
  869. ->join("Volunteer v", "u.link_id = v.uid")
  870. ->where(["u.uid" => $uid])
  871. ->field("u.link_id,v.grade")
  872. ->select();
  873. if ($identity) {
  874. foreach ($identity as $key => $value) {
  875. if ($value['grade'] == 1) {
  876. $data['v']++;
  877. }
  878. if ($value['grade'] == 2) {
  879. $data['v1']++;
  880. }
  881. if ($value['grade'] == 3) {
  882. $data['v2']++;
  883. }
  884. if ($value['grade'] == 4) {
  885. $data['v3']++;
  886. }
  887. if ($value['grade'] == 5) {
  888. $data['v4']++;
  889. }
  890. $fns($value['link_id']);
  891. }
  892. }
  893. };
  894. $fns($uid);
  895. Db::name("Volunteer")
  896. ->where(["uid" => $uid])
  897. ->update([
  898. "v" => $data['v'],
  899. "v1" => $data['v1'],
  900. "v2" => $data['v2'],
  901. "v3" => $data['v3'],
  902. "v4" => $data['v4'],
  903. "time" => time()
  904. ]);
  905. return $data;
  906. }
  907. }