HuafeiOrderIndependentAccount.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace app\command;
  3. use app\common\model\store\order\StoreOrder;
  4. use app\common\model\user\UserCertification;
  5. use app\common\repositories\merchant\order\OrderGzcRepository;
  6. use app\common\repositories\merchant\order\OrderMerchantRepository;
  7. use app\common\repositories\store\order\StoreOrderRepository;
  8. use app\common\repositories\store\order\StoreOrderStatusRepository;
  9. use app\common\repositories\user\UserBillRepository;
  10. use app\common\repositories\user\UserRepository;
  11. use Carbon\Carbon;
  12. use think\console\Command;
  13. use think\console\Input;
  14. use think\console\Output;
  15. use think\facade\Db;
  16. use think\facade\Log;
  17. class HuafeiOrderIndependentAccount extends Command
  18. {
  19. protected function configure()
  20. {
  21. // 指令配置
  22. $this->setName('huafei-order-independent-account')
  23. ->setDescription('话费订单分账');
  24. }
  25. protected function execute(Input $input, Output $output)
  26. {
  27. // @todo 精彩生活区订单分账
  28. $this->doHuafeiOrderIndependentAccount();
  29. }
  30. /**
  31. * 会员专区、精彩生活区订单分账
  32. *
  33. * @param $merId
  34. * @param $timeLimit
  35. * @return void
  36. * @throws \think\db\exception\DataNotFoundException
  37. * @throws \think\db\exception\DbException
  38. * @throws \think\db\exception\ModelNotFoundException
  39. */
  40. private function doHuafeiOrderIndependentAccount($timeLimit = 1)
  41. {
  42. $dst_mer_id = systemConfig('mer_365');
  43. // 商户信息
  44. $merchants = [];
  45. $time = time();
  46. // 订单状态(0:待发货;1:待收货;2:待评价;3:已完成;4已申请退款;-1:已退款)5未支付 6已取消'
  47. $status = [2];
  48. // 普通订单
  49. $cursor = Db::table('rrx_store_order')->where('is_independentaccount', 0)->whereIn('status', $status)->cursor();
  50. /** @var StoreOrderRepository $storeOrderRepository */
  51. $storeOrderRepository = app()->make(StoreOrderRepository::class);
  52. foreach ($cursor as $key => $value) {
  53. $settlement_period_time = strtotime($value['create_time']) + $timeLimit * 24 * 3600;
  54. // @todo 下单后第{$timeLimit}天后可分账
  55. if ($settlement_period_time >= $time) {
  56. $merchants['496'] = Db::name('merchant')->where('mer_id', 496)->find();
  57. $order_huafei_hf = Db::name('order_huafei_hf')->where('order_no', $value['order_sn'])->find();
  58. if(!$order_huafei_hf) continue;
  59. $value['mer_id'] = 496;
  60. $order_huafei_hf['mer_id'] = 496;
  61. // 分账账号 496:表示{会员专区}账户,分账到{会员专区}账户
  62. $independentAccount = $storeOrderRepository->getIndependentAccountHuafei($order_huafei_hf, $dst_mer_id, $merchants['496']['hf_member_id']);
  63. // @todo 预分账处理 分账到{会员专区}账户,故:hf_platform_member_id 为入账账户
  64. $isSuccessed = $storeOrderRepository->prepareExecuteIndependentAccountHuafei(
  65. $value, $order_huafei_hf, $independentAccount['api_key'], $independentAccount['hf_platform_member_id'], '', $value['pay_price'], 0
  66. );
  67. if ($isSuccessed) {
  68. Db::name("log")->insert(array('data' => '话费-订单分账:' . json_encode($value, JSON_FORCE_OBJECT)));//日志记录
  69. Db::table('rrx_store_order')->where('order_sn', $value['order_sn'])->update(['is_independentaccount' => 1]);
  70. }
  71. }
  72. }
  73. }
  74. }