GzcAddByBillCommand.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <?php
  2. namespace app\command;
  3. use app\common\model\user\UserCertification;
  4. use app\common\repositories\merchant\order\OrderGzcRepository;
  5. use app\common\repositories\merchant\order\OrderMerchantRepository;
  6. use app\common\repositories\store\order\StoreOrderRepository;
  7. use app\common\repositories\user\UserRepository;
  8. use think\console\Command;
  9. use think\console\Input;
  10. use think\console\Output;
  11. use think\db\exception\DataNotFoundException;
  12. use think\db\exception\DbException;
  13. use think\db\exception\ModelNotFoundException;
  14. use think\facade\Db;
  15. use think\facade\Log;
  16. class GzcAddByBillCommand extends Command
  17. {
  18. protected function configure()
  19. {
  20. // 配置命令名称及描述
  21. $this->setName('gzcAddByBill')
  22. ->setDescription('从bill表中查询未提交到公证处的养老金记录,并提交公证处');
  23. }
  24. protected function execute(Input $input, Output $output)
  25. {
  26. // 在这里执行任务的具体内容
  27. $output->writeln('定时任务执行中...');
  28. $nowTime = time();
  29. $this->billGzcAdd($nowTime);
  30. $output->writeln('定时任务执行完成');
  31. }
  32. /**
  33. * 线下支付订单公证处IN10入账
  34. * @param $nowTime
  35. * author: php迷途小书童
  36. * created: 2021/3/20 9:26
  37. */
  38. public function billGzcAdd($nowTime)
  39. {
  40. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  41. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  42. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  43. $testUserIdList = [];
  44. /** @var UserRepository $userRepository */
  45. $userRepository = app()->make(UserRepository::class);
  46. try {
  47. $userIdData = $userRepository->selectWhere(['test_user' => 1], 'uid')->toArray();
  48. if (!empty($userIdData)) {
  49. $testUserIdList = array_column($userIdData, 'uid');
  50. }
  51. } catch (DataNotFoundException|ModelNotFoundException|DbException $e) {
  52. }
  53. $cursor = Db::name('user_bill')
  54. ->where('status', 1)
  55. ->where('is_gzc', 0)
  56. ->where('commission_type', 5)
  57. ->whereNotIn('uid', $testUserIdList)
  58. ->select()->toArray();
  59. if($cursor) {
  60. foreach ($cursor as $bill) {
  61. $type_shop = $bill['type_shop'] ?? 0;
  62. switch ($type_shop){
  63. case "0":
  64. $online = $cursor = Db::table('rrx_store_order')->where('uid', $bill['uid'])->where('order_sn', $bill['order_sn'])->where('paid', 1)->find();
  65. break;
  66. case "1":
  67. $online = Db::table('rrx_order_pdd')->where('uid', $bill['uid'])->where('order_sn', $bill['order_sn'])->find();
  68. break;
  69. case "2":
  70. $online = Db::table('rrx_order_vip')->where('uid', $bill['uid'])->where('order_sn', $bill['order_sn'])->find();
  71. break;
  72. case "3":
  73. $online = Db::table('rrx_order_su')->where('uid', $bill['uid'])->where('order_sn', $bill['order_sn'])->find();
  74. break;
  75. case "4":
  76. $online = '';
  77. break;
  78. case "5":
  79. $online = Db::table('rrx_order_tb')->where('uid', $bill['uid'])->where('order_sn', $bill['order_sn'])->find();
  80. break;
  81. case "6":
  82. $online = Db::table('rrx_order_jd')->where('uid', $bill['uid'])->where('order_sn', $bill['order_sn'])->find();
  83. break;
  84. case "7":
  85. $online = '';
  86. break;
  87. case "8":
  88. $online = '';
  89. break;
  90. case "9":
  91. $online = Db::table('rrx_order_huafei')->where('uid', $bill['uid'])->where('order_sn', $bill['order_sn'])->find();
  92. break;
  93. case "10":
  94. $online = Db::table('rrx_order_merchant')
  95. ->where('uid', $bill['uid'])
  96. ->where('out_trade_no', $bill['order_sn'])
  97. ->where('paid', 1)
  98. ->where('status', 1)
  99. ->find();
  100. if (!empty($online)) {
  101. $online = $online->toArray();
  102. $online['order_sn'] = $online['out_trade_no'];
  103. }
  104. break;
  105. default:
  106. $online = Db::table('rrx_store_order')->where('uid', $bill['uid'])->where('order_sn', $bill['order_sn'])->where('paid', 1)->find();
  107. }
  108. if (!$online) {
  109. Log::info($bill['uid'] . '查询不到订单');
  110. continue;
  111. }
  112. $certification = UserCertification::getInstance()->where('uid', $bill['uid'])->find();
  113. if (!$certification) {
  114. Log::info($online['uid'] . '没有实名认证');
  115. continue;
  116. }
  117. $pension = $bill['number'] ?? 0;
  118. if ($pension <= 0) {
  119. Log::info($online['order_sn'] . 'pension' . $pension);
  120. continue;
  121. }
  122. //新增入账明细记录
  123. $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  124. $create = [
  125. 'uid' => $online['uid'],
  126. 'platform_no' => $orderId,
  127. 'account_type' => 1,
  128. 'user_name' => $certification['user_name'],
  129. 'mobile' => $certification['mobile'],
  130. 'user_card' => $certification['user_card'],
  131. 'pension' => $pension,
  132. 'order_type' => $type_shop,
  133. 'out_trade_no' => $online['order_sn'],
  134. 'link_id'=> $bill['bill_id']
  135. ];
  136. $test_user = Db::name('user')->where('uid', $online['uid'])->value('test_user');
  137. $check = Db::name("gzc_logs")->where("link_id", $bill['bill_id'])->where("order_type", $type_shop)->count();
  138. if ($test_user == 0 && $check <= 0) {
  139. $OrderGzcRepository->create($create);
  140. Db::name('user_bill')
  141. ->where('bill_id', $bill['bill_id'])
  142. ->where('commission_type', 5)
  143. ->update([
  144. 'is_gzc' => 1,
  145. 'gzc' => 1
  146. ]);
  147. }
  148. }
  149. }
  150. }
  151. }