Просмотр исходного кода

订单分账-共富区订单分账

sunxbiao месяцев назад: 5
Родитель
Сommit
3a9e7c96c5
1 измененных файлов с 53 добавлено и 1 удалено
  1. 53 1
      app/command/MemberAreaOrderIndependentAccount.php

+ 53 - 1
app/command/MemberAreaOrderIndependentAccount.php

@@ -2,6 +2,7 @@
2 2
 
3 3
 namespace app\command;
4 4
 
5
+use app\common\enum\CommonEnum;
5 6
 use app\common\model\store\order\StoreOrder;
6 7
 use app\common\repositories\store\order\StoreOrderRepository;
7 8
 use think\console\Command;
@@ -21,7 +22,8 @@ class MemberAreaOrderIndependentAccount extends Command
21 22
     protected function execute(Input $input, Output $output)
22 23
     {
23 24
         // @todo 会员专区订单分账
24
-        $this->doMemberAreaOrderIndependentAccount([496]);
25
+        $this->doMemberAreaOrderIndependentAccount([CommonEnum::DESIGN_MERCHANT_ID['MemberZone']['code']]);
26
+        $this->doSharedProsperityOrderIndependentAccount([CommonEnum::DESIGN_MERCHANT_ID['SharedProsperity']['code']]);
25 27
     }
26 28
 
27 29
     /**
@@ -77,4 +79,54 @@ class MemberAreaOrderIndependentAccount extends Command
77 79
 
78 80
     }
79 81
 
82
+    /**
83
+     * 共富区订单分账
84
+     *
85
+     * @param $merId
86
+     * @param $timeLimit
87
+     * @return void
88
+     * @throws \think\db\exception\DataNotFoundException
89
+     * @throws \think\db\exception\DbException
90
+     * @throws \think\db\exception\ModelNotFoundException
91
+     */
92
+    private function doSharedProsperityOrderIndependentAccount($merId = [], $timeLimit = 30)
93
+    {
94
+        $dst_mer_id = CommonEnum::DESIGN_MERCHANT_ID['SharedProsperity']['code'];
95
+
96
+        // 商户信息
97
+        $merchants = [];
98
+
99
+        // 已支付、未结算  注意,会员专区之前可能没有去及时 更新结算状态 'is_settlement' => 1,
100
+        $where = ['paid' => 1, 'is_del' => 0, 'is_system_del' => 0, 'is_independentaccount' => 0];
101
+        // 订单状态(0:待发货;1:待收货;2:待评价;3:已完成;4已申请退款;-1:已退款)5未支付 6已取消'
102
+        // $status = [2, 3]; ->whereIn('status', $status)
103
+        // 普通订单
104
+        $cursor = Db::table('rrx_store_order')->where($where)->where('pay_type', 'in', '1,2,4')
105
+            ->where('fzone_pay_price', '>', 0.00)
106
+            ->whereIn('mer_id', $merId)->cursor();
107
+
108
+        /** @var StoreOrderRepository $storeOrderRepository */
109
+        $storeOrderRepository = app()->make(StoreOrderRepository::class);
110
+
111
+        foreach ($cursor as $key => $value) {
112
+            if (!isset($merchants[$value['mer_id']])) {
113
+                $merchants[$value['mer_id']] = Db::name('merchant')->where('mer_id', $value['mer_id'])->find();
114
+            }
115
+            $group_order = Db::name('store_group_order')->alias('sgo')->where('sgo.group_order_id', $value['group_order_id'])->find();
116
+
117
+            $independentAccount = $storeOrderRepository->getIndependentAccount($value, $group_order, $dst_mer_id, $merchants[$value['mer_id']]['hf_member_id']);
118
+
119
+            $isSuccessed = $storeOrderRepository->prepareExecuteIndependentAccount(
120
+                $value, $group_order, $independentAccount['api_key'], $independentAccount['hf_platform_member_id'], '', $value['fzone_pay_price'], 0
121
+            );
122
+            if ($isSuccessed) {
123
+                Db::name("log")->insert(array('data' => '共富区-订单分账:' . json_encode($value, JSON_FORCE_OBJECT)));// 日志记录
124
+
125
+                $order = StoreOrder::getInstance()->where('order_id', $value['order_id'])->find();
126
+                $order->is_independentaccount = 1;
127
+                $order->save();
128
+            }
129
+        }
130
+
131
+    }
80 132
 }