GreatLifeOrderIndependentAccount.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace app\command;
  3. use app\common\model\store\order\StoreOrder;
  4. use app\common\repositories\store\order\StoreOrderRepository;
  5. use think\console\Command;
  6. use think\console\Input;
  7. use think\console\Output;
  8. use think\facade\Db;
  9. class GreatLifeOrderIndependentAccount extends Command
  10. {
  11. protected function configure()
  12. {
  13. // 指令配置
  14. $this->setName('great-life-order-independent-account')
  15. ->setDescription('精彩生活区订单分账');
  16. }
  17. protected function execute(Input $input, Output $output)
  18. {
  19. // @todo 精彩生活区订单分账
  20. $this->doGreatLifeOrderIndependentAccount([439]);
  21. }
  22. /**
  23. * 会员专区、精彩生活区订单分账
  24. *
  25. * @param $merId
  26. * @param $timeLimit
  27. * @return void
  28. * @throws \think\db\exception\DataNotFoundException
  29. * @throws \think\db\exception\DbException
  30. * @throws \think\db\exception\ModelNotFoundException
  31. */
  32. private function doGreatLifeOrderIndependentAccount($merId = [], $timeLimit = 30)
  33. {
  34. $dst_mer_id = systemConfig('mer_365');
  35. // 商户信息
  36. $merchants = [];
  37. // 已支付、未结算
  38. $where = ['paid' => 1, 'is_independentaccount' => 0, 'is_del' => 0, 'is_system_del' => 0, 'is_settlement' => 1];
  39. // 订单状态(0:待发货;1:待收货;2:待评价;3:已完成;4已申请退款;-1:已退款)5未支付 6已取消'
  40. $status = [2, 3];
  41. // 普通订单
  42. $cursor = Db::table('rrx_store_order')->where($where)->where('pay_type', 'in', '1,2,4')->whereIn('status', $status)
  43. ->whereIn('mer_id', $merId)->cursor();
  44. /** @var StoreOrderRepository $storeOrderRepository */
  45. $storeOrderRepository = app()->make(StoreOrderRepository::class);
  46. foreach ($cursor as $key => $value) {
  47. if (!isset($merchants[$value['mer_id']])) {
  48. $merchants[$value['mer_id']] = Db::name('merchant')->where('mer_id', $value['mer_id'])->find();
  49. }
  50. $group_order = Db::name('store_group_order')->alias('sgo')->where('sgo.group_order_id', $value['group_order_id'])->find();
  51. // 分账账号 496:表示{会员专区}账户,精彩生活区分账到{会员专区}账户
  52. $independentAccount = $storeOrderRepository->getIndependentAccount($value, $group_order, $dst_mer_id, $merchants[$value['mer_id']]['hf_member_id']);
  53. // @todo 预分账处理 496:表示{会员专区}账户,精彩生活区分账到{会员专区}账户,故:hf_platform_member_id 为入账账户
  54. $isSuccessed = $storeOrderRepository->prepareExecuteIndependentAccount(
  55. $value, $group_order, $independentAccount['api_key'], $independentAccount['hf_platform_member_id'], '', $value['pay_price'], 0
  56. );
  57. if ($isSuccessed) {
  58. Db::name("log")->insert(array('data' => '精彩生活区-订单分账:' . json_encode($value, JSON_FORCE_OBJECT)));// 日志记录
  59. $order = StoreOrder::getInstance()->where('order_id', $value['order_id'])->find();
  60. $order->is_independentaccount = 1;
  61. $order->save();
  62. }
  63. }
  64. }
  65. }