GzcAddByBillCommand.php 5.5 KB

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