Explorar o código

补充会员专区分账脚本

sunxbiao hai 1 ano
pai
achega
42eddd8ba1
Modificáronse 2 ficheiros con 85 adicións e 4 borrados
  1. 80 0
      app/command/MemberAreaOrderIndependentAccount.php
  2. 5 4
      config/console.php

+ 80 - 0
app/command/MemberAreaOrderIndependentAccount.php

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

+ 5 - 4
config/console.php

@@ -20,13 +20,14 @@ return [
20 20
         'ln:import_store' => 'app\command\test\ln\ImportStore',
21 21
         'ln:user_bill' => 'app\command\test\ln\UserBill',
22 22
         'ln:import_user_cxb' => 'app\command\test\ln\ImportUser2',
23
-//        'great_life_order_independent_account' => 'app\command\GreatLifeOrderIndependentAccount',
24
-//        'commercial_area_order_independent_account' => 'app\command\CommercialAreaOrderIndependentAccount',
25
-        // 'huafei_order_independent_account' => 'app\command\HuafeiOrderIndependentAccount',
23
+        'great_life_order_independent_account' => 'app\command\GreatLifeOrderIndependentAccount',
24
+        'member_area_order_independent_account' => 'app\command\MemberAreaOrderIndependentAccount',
25
+        'commercial_area_order_independent_account' => 'app\command\CommercialAreaOrderIndependentAccount',
26
+        'huafei_order_independent_account' => 'app\command\HuafeiOrderIndependentAccount',
26 27
         'movie_city_area' => 'app\command\MovieCityAreaCommand',
27 28
         'movie_cinema' => 'app\command\MovieCinemaCommand',
28 29
         'movie_film' => 'app\command\MovieFilmCommand',
29
-//        'cinema_film_sched' => 'app\command\CinemaSchedCommand',
30
+        //        'cinema_film_sched' => 'app\command\CinemaSchedCommand',
30 31
         'repair_pv_log' => 'app\command\repairPvLog',
31 32
         'gzcAddByBill' => 'app\command\GzcAddByBillCommand',
32 33
         'movie_order' => 'app\command\MovieOrderCommand',