GzcAddByBillCommand.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. try {
  54. $cursor = Db::name('user_bill')
  55. ->where('status', 1)
  56. ->where('is_gzc', 0)
  57. ->where('commission_type', 5)
  58. ->whereNotIn('uid', $testUserIdList)
  59. ->select();
  60. } catch (DataNotFoundException|ModelNotFoundException|DbException $e) {
  61. }
  62. if(!empty($cursor)) {
  63. foreach ($cursor as $bill) {
  64. $type_shop = $bill['type_shop'] ?? 0;
  65. switch ($type_shop){
  66. case "0":
  67. $online = Db::table('rrx_store_order')->where('uid', $bill['uid'])->where('order_sn', $bill['order_sn'])->where('paid', 1)->find();
  68. break;
  69. case "1":
  70. $online = Db::table('rrx_order_pdd')->where('uid', $bill['uid'])->where('order_sn', $bill['order_sn'])->find();
  71. break;
  72. case "2":
  73. $online = Db::table('rrx_order_vip')->where('uid', $bill['uid'])->where('order_sn', $bill['order_sn'])->find();
  74. break;
  75. case "3":
  76. $online = Db::table('rrx_order_su')->where('uid', $bill['uid'])->where('order_sn', $bill['order_sn'])->find();
  77. break;
  78. case "4":
  79. $online = '';
  80. break;
  81. case "5":
  82. $online = Db::table('rrx_order_tb')->where('uid', $bill['uid'])->where('order_sn', $bill['order_sn'])->find();
  83. break;
  84. case "6":
  85. $online = Db::table('rrx_order_jd')->where('uid', $bill['uid'])->where('order_sn', $bill['order_sn'])->find();
  86. break;
  87. case "7":
  88. $online = '';
  89. break;
  90. case "8":
  91. $online = '';
  92. break;
  93. case "9":
  94. $online = Db::table('rrx_order_huafei')->where('uid', $bill['uid'])->where('order_sn', $bill['order_sn'])->find();
  95. break;
  96. case "10":
  97. $online = Db::table('rrx_order_merchant')
  98. ->where('uid', $bill['uid'])
  99. ->where('out_trade_no', $bill['order_sn'])
  100. ->where('paid', 1)
  101. ->where('status', 1)
  102. ->find();
  103. if (!empty($online)) {
  104. $online['order_sn'] = $online['out_trade_no'];
  105. }
  106. break;
  107. default:
  108. $online = Db::table('rrx_store_order')->where('uid', $bill['uid'])->where('order_sn', $bill['order_sn'])->where('paid', 1)->find();
  109. }
  110. if (!$online) {
  111. Log::info($bill['uid'] . '查询不到订单');
  112. continue;
  113. }
  114. $certification = UserCertification::getInstance()->where('uid', $bill['uid'])->find();
  115. if (!$certification) {
  116. Log::info($online['uid'] . '没有实名认证');
  117. continue;
  118. }
  119. $pension = $bill['number'] ?? 0;
  120. if ($pension <= 0) {
  121. Log::info($online['order_sn'] . 'pension' . $pension);
  122. continue;
  123. }
  124. //新增入账明细记录
  125. $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  126. $create = [
  127. 'uid' => $online['uid'],
  128. 'platform_no' => $orderId,
  129. 'account_type' => 1,
  130. 'user_name' => $certification['user_name'],
  131. 'mobile' => $certification['mobile'],
  132. 'user_card' => $certification['user_card'],
  133. 'pension' => $pension,
  134. 'order_type' => $type_shop,
  135. 'out_trade_no' => $online['order_sn'],
  136. 'link_id'=> $bill['bill_id']
  137. ];
  138. $test_user = Db::name('user')->where('uid', $online['uid'])->value('test_user');
  139. $check = Db::name("gzc_logs")->where("link_id", $bill['bill_id'])->where("order_type", $type_shop)->count();
  140. if ($test_user == 0 && $check <= 0) {
  141. $OrderGzcRepository->create($create);
  142. Db::name('user_bill')
  143. ->where('bill_id', $bill['bill_id'])
  144. ->where('commission_type', 5)
  145. ->update([
  146. 'is_gzc' => 1,
  147. 'gzc' => 1
  148. ]);
  149. }
  150. }
  151. }
  152. }
  153. }