Procházet zdrojové kódy

优化下单方法结构-调整支付成功回调方法及触发事件

sunxbiao před 9 měsíci
rodič
revize
d7a6c00bf9

+ 36 - 6
app/common/dao/store/order/StoreGroupOrderDao.php

@@ -120,19 +120,49 @@ class StoreGroupOrderDao extends BaseDao
120 120
     }
121 121
 
122 122
     /**
123
-     * @param $groupOrderId
123
+     * @param array $groupOrderSnList
124
+     * @return CommonEntity[]
125
+     */
126
+    public function getStoreGroupOrderEntityListByGroupOrderSnList(array $groupOrderSnList): array
127
+    {
128
+        $entityList = [];
129
+        try {
130
+            /** @var StoreGroupOrder $model */
131
+            $model = $this->getModel();
132
+            $dataRes = $model::getDB()
133
+                ->whereIn('group_order_sn', $groupOrderSnList)
134
+                ->select()
135
+                ->toArray();
136
+            if (!empty($dataRes)) {
137
+                $entityList = array_map(function ($data) {
138
+                    return StoreGroupOrderEntity::newInstance($data);
139
+                }, $dataRes);
140
+            }
141
+        } catch (\Exception $e) {
142
+
143
+        }
144
+        return $entityList;
145
+    }
146
+
147
+    /**
148
+     * @param int $groupOrderId
149
+     * @param string $rand
124 150
      * @return int
125 151
      * @throws DbException
126 152
      */
127
-    public function paySuccess($groupOrderId): int
153
+    public function paySuccessUpdateDB(int $groupOrderId, string $rand = ''): int
128 154
     {
155
+        $data = [
156
+            'paid' => StoreGroupOrderEnum::PAID['YES']['code'],
157
+            'pay_time' => date('Y-m-d H:i:s')
158
+        ];
159
+        if (!empty($rand)) {
160
+            $data['rand'] = $rand;
161
+        }
129 162
         /** @var StoreGroupOrder $model */
130 163
         $model = $this->getModel();
131 164
         return $model::getDB()
132 165
             ->where('group_order_id', '=', $groupOrderId)
133
-            ->update([
134
-                'paid' => StoreGroupOrderEnum::PAID['YES']['code'],
135
-                'pay_time' => date('Y-m-d H:i:s')
136
-            ]);
166
+            ->update($data);
137 167
     }
138 168
 }

+ 51 - 0
app/common/dao/store/order/StoreOrderDao.php

@@ -12,12 +12,14 @@ namespace app\common\dao\store\order;
12 12
 
13 13
 
14 14
 use app\common\dao\BaseDao;
15
+use app\common\enum\store\StoreOrderEnum;
15 16
 use app\common\model\BaseModel;
16 17
 use app\common\model\store\order\StoreOrder;
17 18
 use app\common\model\user\User;
18 19
 use app\common\repositories\user\UserRepository;
19 20
 use app\entity\CommonEntity;
20 21
 use app\entity\data\store\StoreOrderEntity;
22
+use think\db\exception\DbException;
21 23
 use think\facade\Db;
22 24
 
23 25
 /**
@@ -630,4 +632,53 @@ class StoreOrderDao extends BaseDao
630 632
         }
631 633
         return $entityList;
632 634
     }
635
+
636
+    /**
637
+     * @param array $groupOrderIdList
638
+     * @return CommonEntity[]
639
+     */
640
+    public function getStoreOrderEntityListByGroupOrderIdList(array $groupOrderIdList): array
641
+    {
642
+        $entityList = [];
643
+        try {
644
+            /** @var StoreOrder $model */
645
+            $model = $this->getModel();
646
+            $dataRes = $model::getDB()
647
+                ->whereIn('group_order_id', $groupOrderIdList)
648
+                ->select()
649
+                ->toArray();
650
+            if (!empty($dataRes)) {
651
+                $entityList = array_map(function ($data) {
652
+                    return StoreOrderEntity::newInstance($data);
653
+                }, $dataRes);
654
+            }
655
+        } catch (\Exception $e) {
656
+
657
+        }
658
+        return $entityList;
659
+    }
660
+
661
+    /**
662
+     * @param array $storeOrderIdList
663
+     * @param string|null $payOpenId 现金 付款人ID
664
+     * @return int
665
+     * @throws DbException
666
+     */
667
+    public function paySuccessUpdateDB(array $storeOrderIdList, string $payOpenId = null): int
668
+    {
669
+        $data = [
670
+            'paid' => StoreOrderEnum::PAID['YES']['code'],
671
+            'pay_time' => date('Y-m-d H:i:s'),
672
+            'status' => StoreOrderEnum::STATUS['WAITING_SHIPMENT']['code'],
673
+            'distribution_mode' => StoreOrderEnum::DISTRIBUTION_MODE['ExpressDelivery']['code'] // 配送方式
674
+        ];
675
+        if (!empty($payOpenId)) {
676
+            $data['pay_open_id'] = $payOpenId;
677
+        }
678
+        /** @var StoreOrder $model */
679
+        $model = $this->getModel();
680
+        return $model::getDB()
681
+            ->whereIn('group_order_id', $storeOrderIdList)
682
+            ->update($data);
683
+    }
633 684
 }

+ 9 - 0
app/common/enum/store/StoreGroupOrderEnum.php

@@ -6,6 +6,8 @@ use app\common\enum\CommonEnum;
6 6
 
7 7
 class StoreGroupOrderEnum extends CommonEnum
8 8
 {
9
+    const IS_DEL = parent::IS_DEL;
10
+
9 11
     // 支付方式
10 12
     const PAY_TYPE = [
11 13
         'BALANCE' => ['code' => 0, 'name' => '余额支付'],
@@ -39,4 +41,11 @@ class StoreGroupOrderEnum extends CommonEnum
39 41
         'NO' => ['code' => 0, 'name' => '未支付'],
40 42
         'YES' => ['code' => 1, 'name' => '已支付'],
41 43
     ];
44
+
45
+    // 微信支付渠道后台设置
46
+    const PAY_WX = [
47
+        'ONE' => ['code' => 1, 'name' => '未知'], // 代码中有使用 但现在未知是何定义
48
+        'TDBA' => ['code' => 2, 'name' => '天地博爱'],
49
+        'TDYL' => ['code' => 3, 'name' => '天地易联']
50
+    ];
42 51
 }

+ 13 - 0
app/common/enum/store/StoreOrderStatusEnum.php

@@ -0,0 +1,13 @@
1
+<?php
2
+
3
+namespace app\common\enum\store;
4
+
5
+use app\common\enum\CommonEnum;
6
+
7
+class StoreOrderStatusEnum extends CommonEnum
8
+{
9
+    const CHANGE_TYPE = [
10
+        'Create' => ['code' => 'create', 'name' => '订单生成'],
11
+        'PaySuccess' => ['code' => 'pay_success', 'name' => '订单支付成功']
12
+    ];
13
+}

+ 778 - 117
app/common/repositories/store/order/StoreGroupOrderRepository.php

@@ -12,15 +12,39 @@ namespace app\common\repositories\store\order;
12 12
 
13 13
 
14 14
 use app\common\dao\store\order\StoreGroupOrderDao;
15
+use app\common\enum\CommonEnum;
16
+use app\common\enum\store\CartEnum;
17
+use app\common\enum\store\ProductEnum;
18
+use app\common\enum\store\StoreGroupOrderEnum;
19
+use app\common\enum\store\StoreOrderEnum;
20
+use app\common\enum\store\StoreOrderStatusEnum;
15 21
 use app\common\repositories\BaseRepository;
16
-use app\common\repositories\store\coupon\StoreCouponUserRepository;
22
+use app\common\repositories\product\ProductSeckillRepository;
23
+use app\common\repositories\product\ShareRepository;
24
+use app\common\repositories\store\product\ProductAttrValueRepository;
25
+use app\common\repositories\store\product\ProductRepository;
26
+use app\common\repositories\store\StoreSeckillActiveRepository;
27
+use app\common\repositories\system\merchant\MerchantRepository;
28
+use app\common\repositories\user\UserAddressRepository;
29
+use app\common\repositories\user\UserRepository;
30
+use app\entity\data\merchant\MerchantEntity;
31
+use app\entity\data\product\ProductSeckillEntity;
32
+use app\entity\data\product\ShareEntity;
33
+use app\entity\data\store\CartEntity;
17 34
 use app\entity\data\store\StoreGroupOrderEntity;
18
-use crmeb\jobs\CancelGroupOrderJob;
35
+use app\entity\data\store\StoreOrderEntity;
36
+use app\entity\data\store\StoreOrderProductEntity;
37
+use app\entity\data\store\StoreOrderStatusEntity;
38
+use app\entity\data\store\StoreProductAttrValueEntity;
39
+use app\entity\data\store\StoreProductEntity;
40
+use app\entity\data\user\UserAddressEntity;
41
+use app\entity\data\user\UserEntity;
42
+use app\entity\monomer\store\FzonePayTypeEntity;
43
+use app\entity\request\api\store\order\StoreOrderCreateRequestEntity;
19 44
 use think\db\exception\DbException;
20 45
 use think\exception\ValidateException;
21
-use think\facade\Cache;
22 46
 use think\facade\Db;
23
-use think\facade\Queue;
47
+use think\facade\Log;
24 48
 use think\model\Relation;
25 49
 
26 50
 /**
@@ -54,7 +78,7 @@ class StoreGroupOrderRepository extends BaseRepository
54 78
      */
55 79
     public function getList(array $where, $page, $limit)
56 80
     {
57
-        $query = $this->search($where)->where('test_order',0);
81
+        $query = $this->search($where)->where('test_order', 0);
58 82
         $count = $query->count();
59 83
         $list = $query->with(['orderList' => function (Relation $query) {
60 84
             $query->field('order_id,group_order_id')->with('orderProduct');
@@ -76,14 +100,15 @@ class StoreGroupOrderRepository extends BaseRepository
76 100
      */
77 101
     public function detail($uid, $id)
78 102
     {
79
-       $data =  $this->search(['paid' => 0, 'uid' => $uid])->where('group_order_id', $id)->with(['orderList' => function (Relation $query) {
103
+        $data = $this->search(['paid' => 0, 'uid' => $uid])->where('group_order_id', $id)->with(['orderList' => function (Relation $query) {
80 104
             $query->field('order_id,group_order_id,mer_id,order_sn,pay_price,mark,coupon_price,total_price,total_postage')->with(['merchant' => function ($query) {
81 105
                 $query->field('mer_id,mer_name,mer_avatar');
82 106
             }, 'orderProduct']);
83 107
         }])->find();
84
-       $data['pay_end_time'] = strtotime($data['create_time']) + 60*15;
85
-       return $data;
108
+        $data['pay_end_time'] = strtotime($data['create_time']) + 60 * 15;
109
+        return $data;
86 110
     }
111
+
87 112
     /**
88 113
      * @param $uid
89 114
      * @param $id
@@ -96,13 +121,13 @@ class StoreGroupOrderRepository extends BaseRepository
96 121
      */
97 122
     public function detail_noUid($id)
98 123
     {
99
-        $data =  $this->search(['paid' => 0])->where('group_order_id', $id)->with(['orderList' => function (Relation $query) {
124
+        $data = $this->search(['paid' => 0])->where('group_order_id', $id)->with(['orderList' => function (Relation $query) {
100 125
             $query->field('order_id,group_order_id,mer_id,order_sn,pay_price,mark,coupon_price,total_price,total_postage')->with(['merchant' => function ($query) {
101 126
                 $query->field('mer_id,mer_name,mer_avatar');
102 127
             }, 'orderProduct']);
103 128
         }])->find();
104
-        if($data){
105
-            $data['pay_end_time'] = strtotime($data['create_time']) + 60*15;
129
+        if ($data) {
130
+            $data['pay_end_time'] = strtotime($data['create_time']) + 60 * 15;
106 131
         }
107 132
         return $data;
108 133
     }
@@ -127,105 +152,136 @@ class StoreGroupOrderRepository extends BaseRepository
127 152
     }
128 153
 
129 154
     /**
130
-     * @param $id
131
-     * @param null $uid
132
-     * @throws \think\db\exception\DataNotFoundException
133
-     * @throws DbException
134
-     * @throws \think\db\exception\ModelNotFoundException
135
-     * @author xaboy
136
-     * @day 2020/6/10
155
+     * @param int $groupOrderId
156
+     * @param int|null $uid
157
+     * @param string $changeMessage
158
+     * @param string $remark
159
+     * @return void
137 160
      */
138
-    public function cancel($id, $uid = null, $change_message = '', $remark = '')
161
+    public function cancel(int $groupOrderId, int $uid = null, string $changeMessage = '', string $remark = '')
139 162
     {
140
-        $groupOrder = $this->search(['paid' => 0, 'uid' => $uid ?: ''])->where('group_order_id', $id)->with(['orderList'])->find();
141
-        if (!$groupOrder)
163
+        // 1、验证要操作的订单组是否状态合法
164
+        $storeGroupOrderEntity = $this->getStoreGroupOrderEntityByGroupOrderId($groupOrderId);
165
+        if (empty($storeGroupOrderEntity->getGroupOrderId())) {
142 166
             throw new ValidateException('订单不存在');
143
-        if ($groupOrder['paid'] != 0)
144
-            throw new ValidateException('订单状态错误,无法删除');
145
-        //TODO 关闭订单
146
-        Db::transaction(function () use ($remark, $groupOrder, $id, $uid,$change_message) {
147
-            $redis = Cache::store('redis')->handler();
148
-
149
-            $groupOrder->is_del = 1;
150
-            $orderStatus = [];
151
-            foreach ($groupOrder->orderList as $order) {
152
-//                $order->is_del = 1;
153
-                $order->status = 6;
154
-//                $order->is_settlement = -1;
155
-                $order->save();
156
-                $orderStatus[] = [
157
-                    'order_id'       => $order->order_id,
158
-                    'change_type'    => 'cancel',
159
-                    'change_message' => $uid === 0 ? ('取消原因:'.$change_message . "[商家操作]\n 商家备注:" . ($remark ?: '')) : ($change_message ? $change_message : '取消订单' . ($uid ? '' : '[自动]'))
160
-                ];
161
-                // 取消订单时 删除限制合伙人商品代理限制
162
-                $key ='area_manage_order:'.$order['area_manage_address_ids'];
163
-                $redis->del($key);
164
-            }
165
-            $groupOrder->save();
166
-
167
-            //取消订单,返还京豆和积分
168
-            $orderId = $order->order_id;
169
-            $userSignScoreInfo = Db::name('user_sign_score')->where('order_id', $orderId)->where('status',-1)->where('order_type','store_order')->find();
170
-            if($userSignScoreInfo){
171
-                $userDecScore = $userSignScoreInfo['reward_socre'];
172
-                Db::name('user_sign_score')
173
-                    ->where('id', $userSignScoreInfo['id'])
174
-                    ->update([
175
-                        'status' => 0,
176
-                    ]);
177
-
178
-                //返还扣除积分
179
-                $user = Db::name('user')->where('uid', $uid)->find();
180
-                $userScore = $user['score'];
181
-                $ins_data['uid'] = $uid;
182
-                $ins_data['reward_socre'] = $userDecScore;
183
-                $ins_data['addtime'] = time();
184
-                $ins_data['status'] = 1;//京豆状态1-有效 0-失效 -1待确认 创建的时候-1待确认 取消订单返还积分变为0 支付成功变为1
185
-                $ins_data['order_type'] = 'cancel_order';
186
-                $ins_data['order_id'] = $orderId;
187
-                $ins_data['mark'] = "取消订单返还预扣积分";
188
-                $ins_data['desc'] = '取消订单返还预扣积分';
189
-                $ins_data['surplus'] = $userScore + $userDecScore;
190
-                $ins_data['type'] = 4;//没用
191
-                $ins_data['pm'] = 1;
192
-                Db::name('user_sign_score')->insertGetId($ins_data);
193
-                Db::name('user')->where('uid', $uid)->inc('score', $userDecScore)->update();
194
-            }
167
+        }
168
+        if ($storeGroupOrderEntity->getPaid() != StoreGroupOrderEnum::PAID['NO']['code']) {
169
+            throw new ValidateException('订单状态错误');
170
+        }
195 171
 
196
-            $userSignJingdouInfo = Db::name('user_sign_jingdou')->where('order_id', $orderId)->where('status',-1)->where('order_type','store_order')->find();
197
-            if($userSignJingdouInfo){
198
-                $userDecJingScore = $userSignJingdouInfo['number'];
199
-                Db::name('user_sign_jingdou')
200
-                    ->where('id',$userSignJingdouInfo['id'])
201
-                    ->update([
202
-                        'status' => 0,
203
-                    ]);
204
-
205
-                //返还扣除京豆
206
-                $user = Db::name('user')->where('uid', $uid)->find();
207
-                $userJingdou = $user['jingdou'];
208
-                $ins_data['uid'] = $uid;
209
-                $ins_data['number'] = $userDecJingScore;
210
-                $ins_data['status'] = 1;
211
-                $ins_data['mark'] = "取消订单返还预扣京豆";
212
-                $ins_data['desc'] = "取消订单返还预扣京豆";
213
-                $ins_data['order_id'] = $orderId;
214
-                $ins_data['surplus'] = $userJingdou + $userDecJingScore;
215
-                $ins_data['order_type'] = 'cancel_order';
216
-                $ins_data['type'] = 1;
217
-                $ins_data['addtime'] = time();
218
-                Db::name('user_sign_jingdou')
219
-                    ->insertGetId($ins_data);
220
-                Db::name('user')->where('uid', $uid)->inc('jingdou', $userDecJingScore)->update();
221
-            }
172
+        // 2、验证订单信息
173
+        /** @var StoreOrderRepository $storeOrderRepository */
174
+        $storeOrderRepository = app()->make(StoreOrderRepository::class);
175
+        $storeOrderEntityList = $storeOrderRepository->getStoreOrderEntityListByGroupOrderId($storeGroupOrderEntity->getGroupOrderId());
176
+        if (empty($storeOrderEntityList)) {
177
+            throw new ValidateException('订单信息错误');
178
+        }
222 179
 
180
+        // 3、逻辑处理
181
+        (new \think\facade\Db)->startTrans();
182
+        try {
183
+            // 软 删除订单组
184
+            $storeGroupOrderEntity->setIsDel(StoreGroupOrderEnum::IS_DEL['Yes']['code']);
185
+            $this->update($storeGroupOrderEntity->getGroupOrderId(), $storeGroupOrderEntity->toUnderlineArray());
223 186
 
187
+            // 循环关闭订单组内的数据
188
+            foreach ($storeOrderEntityList as $storeOrderEntity) {
189
+                $storeOrderRepository->closeStoreOrder($storeOrderEntity, $uid, $changeMessage, $remark);
190
+            }
224 191
 
225
-            app()->make(StoreOrderStatusRepository::class)->insertAll($orderStatus);
192
+            (new \think\facade\Db)->commit();
193
+        } catch (DbException $e) {
194
+            (new \think\facade\Db)->rollback();
195
+        }
226 196
 
227
-        });
228
-        Queue::push(CancelGroupOrderJob::class, $id);
197
+        // $groupOrder = $this->search(['paid' => 0, 'uid' => $uid ?: ''])->where('group_order_id', $id)->with(['orderList'])->find();
198
+        // if (!$groupOrder)
199
+        //     throw new ValidateException('订单不存在');
200
+        // if ($groupOrder['paid'] != 0)
201
+        //     throw new ValidateException('订单状态错误,无法删除');
202
+        // Db::transaction(function () use ($remark, $groupOrder, $id, $uid,$change_message) {
203
+        //     $redis = Cache::store('redis')->handler();
204
+        //
205
+        //     $groupOrder->is_del = 1;
206
+        //     $orderStatus = [];
207
+        //     foreach ($groupOrder->orderList as $order) {
208
+        //     //                $order->is_del = 1;
209
+        //         $order->status = 6;
210
+        //     //                $order->is_settlement = -1;
211
+        //         $order->save();
212
+        //         $orderStatus[] = [
213
+        //             'order_id'       => $order->order_id,
214
+        //             'change_type'    => 'cancel',
215
+        //             'change_message' => $uid === 0 ? ('取消原因:'.$change_message . "[商家操作]\n 商家备注:" . ($remark ?: '')) : ($change_message ? $change_message : '取消订单' . ($uid ? '' : '[自动]'))
216
+        //         ];
217
+        //         // 取消订单时 删除限制合伙人商品代理限制
218
+        //         $key ='area_manage_order:'.$order['area_manage_address_ids'];
219
+        //         $redis->del($key);
220
+        //     }
221
+        //     $groupOrder->save();
222
+        //
223
+        //     //取消订单,返还京豆和积分
224
+        //     $orderId = $order->order_id;
225
+        //     $userSignScoreInfo = Db::name('user_sign_score')->where('order_id', $orderId)->where('status',-1)->where('order_type','store_order')->find();
226
+        //     if($userSignScoreInfo){
227
+        //         $userDecScore = $userSignScoreInfo['reward_socre'];
228
+        //         Db::name('user_sign_score')
229
+        //             ->where('id', $userSignScoreInfo['id'])
230
+        //             ->update([
231
+        //                 'status' => 0,
232
+        //             ]);
233
+        //
234
+        //         //返还扣除积分
235
+        //         $user = Db::name('user')->where('uid', $uid)->find();
236
+        //         $userScore = $user['score'];
237
+        //         $ins_data['uid'] = $uid;
238
+        //         $ins_data['reward_socre'] = $userDecScore;
239
+        //         $ins_data['addtime'] = time();
240
+        //         $ins_data['status'] = 1;//京豆状态1-有效 0-失效 -1待确认 创建的时候-1待确认 取消订单返还积分变为0 支付成功变为1
241
+        //         $ins_data['order_type'] = 'cancel_order';
242
+        //         $ins_data['order_id'] = $orderId;
243
+        //         $ins_data['mark'] = "取消订单返还预扣积分";
244
+        //         $ins_data['desc'] = '取消订单返还预扣积分';
245
+        //         $ins_data['surplus'] = $userScore + $userDecScore;
246
+        //         $ins_data['type'] = 4;//没用
247
+        //         $ins_data['pm'] = 1;
248
+        //         Db::name('user_sign_score')->insertGetId($ins_data);
249
+        //         Db::name('user')->where('uid', $uid)->inc('score', $userDecScore)->update();
250
+        //     }
251
+        //
252
+        //     $userSignJingdouInfo = Db::name('user_sign_jingdou')->where('order_id', $orderId)->where('status',-1)->where('order_type','store_order')->find();
253
+        //     if($userSignJingdouInfo){
254
+        //         $userDecJingScore = $userSignJingdouInfo['number'];
255
+        //         Db::name('user_sign_jingdou')
256
+        //             ->where('id',$userSignJingdouInfo['id'])
257
+        //             ->update([
258
+        //                 'status' => 0,
259
+        //             ]);
260
+        //
261
+        //         //返还扣除京豆
262
+        //         $user = Db::name('user')->where('uid', $uid)->find();
263
+        //         $userJingdou = $user['jingdou'];
264
+        //         $ins_data['uid'] = $uid;
265
+        //         $ins_data['number'] = $userDecJingScore;
266
+        //         $ins_data['status'] = 1;
267
+        //         $ins_data['mark'] = "取消订单返还预扣京豆";
268
+        //         $ins_data['desc'] = "取消订单返还预扣京豆";
269
+        //         $ins_data['order_id'] = $orderId;
270
+        //         $ins_data['surplus'] = $userJingdou + $userDecJingScore;
271
+        //         $ins_data['order_type'] = 'cancel_order';
272
+        //         $ins_data['type'] = 1;
273
+        //         $ins_data['addtime'] = time();
274
+        //         Db::name('user_sign_jingdou')
275
+        //             ->insertGetId($ins_data);
276
+        //         Db::name('user')->where('uid', $uid)->inc('jingdou', $userDecJingScore)->update();
277
+        //     }
278
+        //
279
+        //
280
+        //
281
+        //     app()->make(StoreOrderStatusRepository::class)->insertAll($orderStatus);
282
+        //
283
+        // });
284
+        // Queue::push(CancelGroupOrderJob::class, $id);
229 285
     }
230 286
 
231 287
     /**
@@ -235,19 +291,20 @@ class StoreGroupOrderRepository extends BaseRepository
235 291
      * @throws DbException
236 292
      * @throws \think\db\exception\ModelNotFoundException
237 293
      */
238
-    public function ProductOutCancel($product_id){
294
+    public function ProductOutCancel($product_id)
295
+    {
239 296
         $order = Db::name('store_order')
240
-            -> alias('so')
241
-            -> join('store_group_order sgo','so.group_order_id= sgo.group_order_id')
242
-            -> join('store_order_product sop','sop.order_id= so.order_id')
243
-            -> where('so.paid',0)
244
-            -> where('so.is_del', 0)
245
-            -> where('so.status', 5)
246
-            -> where('sop.product_id',$product_id)
247
-//            -> where('so.create_time','<','2022-06-26')
248
-            -> field('so.group_order_id,so.order_id,so.status')
249
-            -> select();
250
-        foreach ($order as $v){
297
+            ->alias('so')
298
+            ->join('store_group_order sgo', 'so.group_order_id= sgo.group_order_id')
299
+            ->join('store_order_product sop', 'sop.order_id= so.order_id')
300
+            ->where('so.paid', 0)
301
+            ->where('so.is_del', 0)
302
+            ->where('so.status', 5)
303
+            ->where('sop.product_id', $product_id)
304
+            //            -> where('so.create_time','<','2022-06-26')
305
+            ->field('so.group_order_id,so.order_id,so.status')
306
+            ->select();
307
+        foreach ($order as $v) {
251 308
             $this->cancel($v['group_order_id']);
252 309
         }
253 310
         return $order;
@@ -278,6 +335,31 @@ class StoreGroupOrderRepository extends BaseRepository
278 335
         return $this->dao->getStoreGroupOrderEntityListByGroupOrderIdList($groupOrderIdList);
279 336
     }
280 337
 
338
+    /**
339
+     * @param string $groupOrderSn
340
+     * @return StoreGroupOrderEntity
341
+     */
342
+    public function getStoreGroupOrderEntityByGroupOrderSn(string $groupOrderSn): StoreGroupOrderEntity
343
+    {
344
+        $entityList = $this->getStoreGroupOrderEntityListByGroupOrderSnList([$groupOrderSn]);
345
+        $entity = array_shift($entityList);
346
+        if ($entity instanceof StoreGroupOrderEntity) {
347
+            return $entity;
348
+        } else {
349
+            /** @var StoreGroupOrderEntity */
350
+            return StoreGroupOrderEntity::newInstance();
351
+        }
352
+    }
353
+
354
+    /**
355
+     * @param array $groupOrderSnList
356
+     * @return StoreGroupOrderEntity[]
357
+     */
358
+    public function getStoreGroupOrderEntityListByGroupOrderSnList(array $groupOrderSnList): array
359
+    {
360
+        return $this->dao->getStoreGroupOrderEntityListByGroupOrderSnList($groupOrderSnList);
361
+    }
362
+
281 363
     public function create($data)
282 364
     {
283 365
         return $this->dao->create($data);
@@ -297,12 +379,591 @@ class StoreGroupOrderRepository extends BaseRepository
297 379
     }
298 380
 
299 381
     /**
300
-     * @param $groupOrderId
382
+     * @return string
383
+     * @author xaboy
384
+     * @day 2020/6/9
385
+     */
386
+    public function getNewOrderId(): string
387
+    {
388
+        list($msec, $sec) = explode(' ', microtime());
389
+        $msectime = number_format((floatval($msec) + floatval($sec)) * 1000, 0, '', '');
390
+        $orderId = 'wx' . $msectime . mt_rand(10000, max(intval($msec * 10000) + 10000, 98369));
391
+        return $orderId;
392
+    }
393
+
394
+    /**
395
+     * 验证订单 信息是否 合规
396
+     * @param StoreOrderCreateRequestEntity $storeOrderCreateRequestEntity
397
+     * @return array
398
+     */
399
+    public function verifyRequestInformation(StoreOrderCreateRequestEntity $storeOrderCreateRequestEntity): array
400
+    {
401
+        // 3、验证
402
+        /** 验证 用户信息 */
403
+        /** @var UserRepository $userRepository */
404
+        $userRepository = app()->make(UserRepository::class);
405
+        $userEntity = $userRepository->getUserEntityByUid($storeOrderCreateRequestEntity->getUid());
406
+        if (empty($userEntity->getUid())) {
407
+            throw new ValidateException('获取当前用户信息失败');
408
+        }
409
+
410
+        /** 验证 收货地址 */
411
+        /** @var UserAddressRepository $userAddressRepository */
412
+        $userAddressRepository = app()->make(UserAddressRepository::class);
413
+        $addressEntity = $userAddressRepository->getAddressEntityByAddressId($storeOrderCreateRequestEntity->getAddressId());
414
+        if (empty($addressEntity->getAddressId()) || $addressEntity->getUid() != $storeOrderCreateRequestEntity->getUid()) {
415
+            throw new ValidateException('请选择正确的收货地址');
416
+        }
417
+        if (empty($addressEntity->getCodeList())) {
418
+            throw new ValidateException('地址需要选择4级地址!请修改地址!');
419
+        }
420
+
421
+        /** 验证分享信息 分享 */
422
+        /** @var ShareEntity $shareEntity */
423
+        $shareEntity = ShareEntity::newInstance();
424
+        if (!empty($storeOrderCreateRequestEntity->getShareId())) {
425
+            /** @var ShareRepository $shareRepository */
426
+            $shareRepository = app()->make(ShareRepository::class);
427
+            $shareEntity = $shareRepository->getShareEntityByShareId($storeOrderCreateRequestEntity->getShareId());
428
+            if (empty($shareEntity->getId())) {
429
+                throw new ValidateException('无效的分享信息');
430
+            }
431
+        }
432
+
433
+        /** 验证 购物车信息 */
434
+        // 目前购物车只能添加一件商品,据了解之前 写的购物车,添加多件商品组合支付时计算的 金额和 VR 积分之类的会有问题
435
+        /** @var StoreCartRepository $storeCartRepository */
436
+        $storeCartRepository = app()->make(StoreCartRepository::class);
437
+        $cartEntityList = $storeCartRepository->getCartEntityListByCartIdList($storeOrderCreateRequestEntity->getCartIdList());
438
+        if (empty($cartEntityList) || count($storeOrderCreateRequestEntity->getCartIdList()) != count($cartEntityList)) {
439
+            throw new ValidateException('未查询到购物车信息');
440
+        }
441
+
442
+        $merchantIdList = [];
443
+        $productIdList = [];
444
+        $productAttrUniqueList = [];
445
+        foreach ($cartEntityList as $cartEntity) {
446
+            if (empty($cartEntity->getMerId())) {
447
+                throw new ValidateException('商户不存在');
448
+            }
449
+            if (empty($cartEntity->getProductId())) {
450
+                throw new ValidateException('商品已下架');
451
+            }
452
+            if (empty($cartEntity->getProductAttrUnique())) {
453
+                throw new ValidateException('商品已下架');
454
+            }
455
+            $merchantIdList[] = $cartEntity->getMerId();
456
+            $productIdList[] = $cartEntity->getProductId();
457
+            $productAttrUniqueList[] = $cartEntity->getProductAttrUnique();
458
+        }
459
+        $merchantIdList = array_unique($merchantIdList);
460
+        $productIdList = array_unique($productIdList);
461
+        $productAttrUniqueList = array_unique($productAttrUniqueList);
462
+
463
+
464
+        // 商户
465
+        /** @var MerchantRepository $merchantRepository */
466
+        $merchantRepository = app()->make(MerchantRepository::class);
467
+        $merchantEntityList = $merchantRepository->getMerchantEntityListByMerchantIdList($merchantIdList);
468
+        if (count($merchantIdList) != count($merchantEntityList)) {
469
+            throw new ValidateException('未查询到商户信息');
470
+        }
471
+        // 商户信息 MAP
472
+        /** @var MerchantEntity[] $merchantEntityMap 商户信息 MAP */
473
+        $merchantEntityMap = array_column($merchantEntityList, null, 'merId');
474
+
475
+        // 商品
476
+        /** @var ProductRepository $storeProductRepository */
477
+        $storeProductRepository = app()->make(ProductRepository::class);
478
+        $storeProductEntityList = $storeProductRepository->getStoreProductEntityListByProductIdList($productIdList);
479
+        if (count($productIdList) != count($storeProductEntityList)) {
480
+            throw new ValidateException('未查询到商品信息');
481
+        }
482
+        // 商品信息 MAP
483
+        /** @var StoreProductEntity[] $storeProductEntityMap */
484
+        $storeProductEntityMap = array_column($storeProductEntityList, null, 'productId');
485
+
486
+        // 商品属性
487
+        /** @var ProductAttrValueRepository $storeProductAttrValueRepository */
488
+        $storeProductAttrValueRepository = app()->make(ProductAttrValueRepository::class);
489
+        $storeProductAttrValueEntityList = $storeProductAttrValueRepository->getStoreProductAttrValueEntityListByUniqueList($productAttrUniqueList);
490
+        if (count($productAttrUniqueList) != count($storeProductAttrValueEntityList)) {
491
+            throw new ValidateException('未查询到商品属性信息');
492
+        }
493
+        // 商品属性信息 MAP
494
+        /** @var StoreProductAttrValueEntity[] $storeProductAttrValueEntityMap */
495
+        $storeProductAttrValueEntityMap = array_column($storeProductAttrValueEntityList, null, 'unique');
496
+
497
+        // 订单表
498
+        /** @var StoreOrderRepository $storeOrderRepository */
499
+        $storeOrderRepository = app()->make(StoreOrderRepository::class);
500
+
501
+        // 确认购物车内 微唯宝 的商品 是否满足发货
502
+        foreach ($cartEntityList as $cartEntity) {
503
+            // 验证用户
504
+            if ($cartEntity->getUid() != $userEntity->getUid()) {
505
+                throw new ValidateException('获取购物车内容失败');
506
+            }
507
+
508
+            // 验证商户
509
+            if (empty($merchantEntityMap[$cartEntity->getMerId()])) {
510
+                throw new ValidateException('未查询到商户信息');
511
+            }
512
+
513
+            // 获取购物车商品信息
514
+            if (empty($storeProductEntityMap[$cartEntity->getProductId()])) {
515
+                throw new ValidateException('未查询到商品信息');
516
+            }
517
+            $productEntity = $storeProductEntityMap[$cartEntity->getProductId()];
518
+
519
+            if ($productEntity->getMerId() != $cartEntity->getMerId()) {
520
+                throw new ValidateException('商家已下架该产品');
521
+            }
522
+
523
+            if (empty($storeProductAttrValueEntityMap[$cartEntity->getProductAttrUnique()])) {
524
+                throw new ValidateException('未查询到商品属性信息');
525
+            }
526
+            $productAttrValueEntity = $storeProductAttrValueEntityMap[$cartEntity->getProductAttrUnique()];
527
+
528
+            // 判断订单是否已失效
529
+            if ($cartEntity->getIsFail() == CartEnum::IS_FAIL['Yes']['code']) {
530
+                throw new ValidateException($productEntity->getStoreName() . ' 已失效');
531
+            }
532
+            // 判断订单是否已失效
533
+            if ($cartEntity->getIsPay() == CartEnum::IS_PAY['Yes']['code']) {
534
+                throw new ValidateException($productEntity->getStoreName() . ' 已下单');
535
+            }
536
+
537
+            // 如果商品类型是 普通商品 ,则判断库存是否充足
538
+            if ($cartEntity->getProductType() == CartEnum::PRODUCT_TYPE['Ordinary']['code']) {
539
+                if ($productAttrValueEntity->getStock() < $cartEntity->getCartNum()) {
540
+                    throw new ValidateException($productEntity->getStoreName() . ' 库存不足--' . $cartEntity->getCartNum());
541
+                }
542
+            } else {
543
+                // 如果是秒杀商品 应该首先判断是否还在活动期间内(rrx_store_seckill_active 商户设置秒杀商品关联表)
544
+                // 商户设置秒杀商品关联表
545
+                /** @var StoreSeckillActiveRepository $storeSeckillActiveRepository */
546
+                $storeSeckillActiveRepository = app()->make(StoreSeckillActiveRepository::class);
547
+                $seckillActiveEntity = $storeSeckillActiveRepository->getSeckillActiveEntityByProductIdInActive($cartEntity->getProductId());
548
+                if (empty($seckillActiveEntity->getSeckillActiveId())) {
549
+                    throw new ValidateException($productEntity->getStoreName() . ' 秒杀活动已失效');
550
+                }
551
+
552
+                // 如果不是普通商品 则是否秒杀产品,如果是秒杀产品则判断是否超卖
553
+                if (!$storeOrderRepository->getDayPayCount($cartEntity->getUid(), $cartEntity->getProductId()) || !$storeOrderRepository->getPayCount($cartEntity->getUid(), $cartEntity->getProductId())) {
554
+                    throw new ValidateException($productEntity->getStoreName() . ' 已超出购买限制');
555
+                }
556
+            }
557
+
558
+            // 检查库存 查看 此商品已下架 此商品规格无货 此商品不支持该地区
559
+            // (按照代码中所写的逻辑来推理:从微唯宝拉取过来,从而上架到商品表的商品,都有SPUId,所以去走微唯宝提供的接口验证,而会员专区和商贸区的商品可能是商户自己加的,没有SPUId,所以也就不用走微唯宝的验证)
560
+            $checkGong = $storeProductAttrValueRepository->checkGong($cartEntity->getProductId(), $cartEntity->getProductAttrUnique(), $cartEntity->getCartNum(), $storeOrderCreateRequestEntity->getUid(), $storeOrderCreateRequestEntity->getAddressId());
561
+            if (isset($checkGong['code']) && $checkGong['code'] == -1) {
562
+                throw new ValidateException($checkGong['message']);
563
+            }
564
+        }
565
+
566
+        return [
567
+            'userEntity' => $userEntity,
568
+            'cartEntityList' => $cartEntityList,
569
+            'addressEntity' => $addressEntity,
570
+            'shareEntity' => $shareEntity,
571
+            'merchantEntityMap' => $merchantEntityMap,
572
+            'storeProductEntityMap' => $storeProductEntityMap,
573
+            'storeProductAttrValueEntityMap' => $storeProductAttrValueEntityMap,
574
+        ];
575
+    }
576
+
577
+    /**
578
+     * @param StoreOrderCreateRequestEntity $storeOrderCreateRequestEntity
579
+     * @return array
580
+     */
581
+    public function createStoreGroupOrder(StoreOrderCreateRequestEntity $storeOrderCreateRequestEntity): array
582
+    {
583
+
584
+        // 1、验证数据合规性 并获取 请求 数据
585
+        $verifyResult = $this->verifyRequestInformation($storeOrderCreateRequestEntity);
586
+        /** @var UserEntity $userEntity 当前操作用户 */
587
+        $userEntity = $verifyResult['userEntity'];
588
+        /** @var CartEntity[] $cartEntityList 发起创建订单的购物车列表 */
589
+        $cartEntityList = $verifyResult['cartEntityList'];
590
+        /** @var CartEntity[] $cartEntityMap 发起创建订单的购物车映射 */
591
+        $cartEntityMap = array_column($cartEntityList, null, 'cartId');
592
+        $cartIdList = array_keys($cartEntityMap);
593
+        /** @var UserAddressEntity $addressEntity 地址信息 */
594
+        $addressEntity = $verifyResult['addressEntity'];
595
+        /** @var ShareEntity $shareEntity 订单所带的分享信息 */
596
+        $shareEntity = $verifyResult['shareEntity'];
597
+        /** @var MerchantEntity[] $merchantEntityMap 订单所涉及的商户信息映射 */
598
+        $merchantEntityMap = $verifyResult['merchantEntityMap'];
599
+        /** @var StoreProductEntity[] $storeProductEntityMap 订单所涉及的 商品信息 映射 */
600
+        $storeProductEntityMap = $verifyResult['storeProductEntityMap'];
601
+        /** @var StoreProductAttrValueEntity[] $storeProductAttrValueEntityMap 订单所涉及的 商品属性信息 */
602
+        $storeProductAttrValueEntityMap = $verifyResult['storeProductAttrValueEntityMap'];
603
+
604
+        // 2、加载 需要调用的 模块
605
+        // 商品秒杀
606
+        /** @var ProductSeckillRepository $productSeckillRepository */
607
+        $productSeckillRepository = app()->make(ProductSeckillRepository::class);
608
+        // // 优惠券 列表(商户or平台)
609
+        // /** @var StoreCouponRepository $storeCouponRepository */
610
+        // $storeCouponRepository = app()->make(StoreCouponRepository::class);
611
+        // // 优惠券 商品 关联表
612
+        // /** @var StoreCouponProductRepository $storeCouponProductRepository */
613
+        // $storeCouponProductRepository = app()->make(StoreCouponProductRepository::class);
614
+        // // 用户的优惠券领取记录
615
+        // /** @var StoreCouponUserRepository $storeCouponUserRepository */
616
+        // $storeCouponUserRepository = app()->make(StoreCouponUserRepository::class);
617
+
618
+        // 商品
619
+        /** @var ProductRepository $productRepository */
620
+        $productRepository = app()->make(ProductRepository::class);
621
+        // 商品属性
622
+        /** @var ProductAttrValueRepository $productAttrValueRepository */
623
+        $productAttrValueRepository = app()->make(ProductAttrValueRepository::class);
624
+
625
+        // 购物车
626
+        /** @var StoreCartRepository $storeCartRepository */
627
+        $storeCartRepository = app()->make(StoreCartRepository::class);
628
+
629
+        // 订单组
630
+        /** @var StoreGroupOrderRepository $storeGroupOrderRepository */
631
+        $storeGroupOrderRepository = app()->make(StoreGroupOrderRepository::class);
632
+        // 订单组
633
+        /** @var StoreOrderRepository $storeOrderRepository */
634
+        $storeOrderRepository = app()->make(StoreOrderRepository::class);
635
+
636
+        // 3、创建 变量
637
+        $storeOrderEntityList = []; // 订单数据实体列表 主要用于写入数据,循环获取数据
638
+        $storeCouponUserEntityListByMerIdMap = []; // 订单优惠券 商户 映射
639
+        $totalPrice = 0.00; // 订单总价
640
+        $totalPostage = 0.00; // 订单总邮费
641
+        $totalNum = 0; // 订单总商品数量
642
+        $totalCost = 0.00; // 订单商品 总成本
643
+        $productStockList = []; // 商品 库存更新列表
644
+        $productAttrValueStockList = []; // 商品 属性 库存更新列表
645
+
646
+        // 4、组装数据 每条购物车信息 就是一条订单数据
647
+        // 循环购物车 对购物车内的商品 进行条件验证 以及根据不同的商品 计算邮费
648
+        foreach ($cartEntityMap as $cartId => $cartEntity) {
649
+            // 获取商品 实体
650
+            $productEntity = $storeProductEntityMap[$cartEntity->getProductId()];
651
+            // 获取商品属性 实体
652
+            $productAttrValueEntity = $storeProductAttrValueEntityMap[$cartEntity->getProductAttrUnique()];
653
+
654
+            // 验证是否是秒杀产品 如果是秒杀产品,并且设置了 大仓会员价 则将大仓会员价 设置为 商品价格
655
+            $productSeckillEntity = ProductSeckillEntity::newInstance();
656
+            if ($productEntity->getSeckill() == ProductEnum::SECKILL['Yes']['code'] && !is_null($productEntity->getDcPrice()) && $productEntity->getDcPrice() > 0.00) {
657
+                // 获取 在活动期间内的 秒杀活动记录
658
+                $productSeckillEntity = $productSeckillRepository->getProductSeckillEntityByProductId($cartEntity->getProductId());
659
+                if (!empty($productSeckillEntity->getId())) {
660
+                    // 把 商品属性的 价格 改成 大仓会员价
661
+                    $productAttrValueEntity->setPrice($productEntity->getDcPrice());
662
+                }
663
+            }
664
+
665
+            // 计算优惠券 ******************  优惠券是此步骤(第一步需要考虑的问题,但是目前阶段暂不需要该功能 所以未完成 先注释)
666
+            $youhuiPrice = 0.00;
667
+            // // 商品券 优先于 店铺券
668
+            // // 商品券(平台优惠券)
669
+            // if (!isset($storeCouponUserEntityListByMerIdMap[0])) {
670
+            //     $storeCouponUserEntityListByMerIdMap[0] = $storeCouponUserRepository->getValidStoreCouponUserEntityListByMerIdAndUid(0, $cartEntity->getUid());
671
+            // }
672
+            // // 店铺券(满减券)
673
+            // if (!isset($storeCouponUserEntityListByMerIdMap[$cartEntity->getMerId()])) {
674
+            //     // 查询 当前用户 在当前 店铺的 优惠券
675
+            //     $storeCouponUserEntityListByMerIdMap[$cartEntity->getMerId()] = $storeCouponUserRepository->getValidStoreCouponUserEntityListByMerIdAndUid($cartEntity->getMerId(), $cartEntity->getUid());
676
+            // }
677
+            //
678
+            // if (!empty($storeCouponUserEntityListByMerIdMap[0]) || !empty($storeCouponUserEntityListByMerIdMap[$cartEntity->getMerId()])) {
679
+            //     foreach ([0, $cartEntity->getMerId()] as $merId) {
680
+            //         foreach ($storeCouponUserEntityListByMerIdMap[$merId] as $storeCouponUserEntity) {
681
+            //             // 如果不能明确当前优惠券的 获取方式 ,则忽略当前的优惠券的有效性
682
+            //             if (empty($storeCouponUserEntity->getType())) {
683
+            //                 continue;
684
+            //             }
685
+            //             // 优惠卷关联商品 辅助表
686
+            //             $storeCouponProductEntityList = $storeCouponProductRepository->getStoreCouponProductEntityListByCouponId($storeCouponUserEntity->getCouponId());
687
+            //             if (!empty($storeCouponProductEntityList)) {
688
+            //                 // 商品券
689
+            //                 foreach ($storeCouponProductEntityList as $storeCouponProductEntity) {
690
+            //                     // 如果当前 优惠券 所关联的 商品 是否在当前购买的 该商家的 商品列表中,(没有则说明此条关联记录 无用) 并且当前 该商家内 该商品没有已使用的优惠券
691
+            //                     if (in_array($storeCouponProductEntity->getProductId(), array_keys($productPriceByMerIdMap[$merchantEntity->getMerId()])) && !isset($useCouponProduct[$storeCouponProductEntity->getProductId()][$cartEntity->getCartId()])) {
692
+            //                         // 如果 当前该商家 该商品 的价格 超过了 “最低消费多少金额可用优惠券” 的金额 则记录该优惠金额,并记录该优惠券ID 后续设置为已使用
693
+            //                         if (($productAttrValueEntity->getPrice()) >= $storeCouponUserEntity->getUseMinPrice()) {
694
+            //                             $couponPrice = bcadd($couponPrice, $storeCouponUserEntity->getCouponPrice(), 2);
695
+            //                             // 一个商家的 一种商品 只能使用一次优惠券
696
+            //                             $useCouponProduct[$storeCouponProductEntity->getProductId()][$cartEntity->getCartId()][] = $storeCouponUserEntity->getCouponUserId();
697
+            //                             break;
698
+            //                         }
699
+            //                     }
700
+            //                 }
701
+            //             } else {
702
+            //                 // 店铺券(平台券-满减券)
703
+            //
704
+            //             }
705
+            //         }
706
+            //     }
707
+            // }
708
+
709
+            // 计算 每笔订单的价格
710
+            $price = bcmul($cartEntity->getCartNum(), $productAttrValueEntity->getPrice(), CommonEnum::DECIMAL_PLACES_OF_THE_AMOUNT);
711
+
712
+            // 计算运费 获取该商品的运费模板 运费表
713
+            // 判断商品是否是 供应链(微唯宝)商品
714
+            // $postage = $storeOrderRepository->calculatePostage(
715
+            //     $productEntity,
716
+            //     $productAttrValueEntity,
717
+            //     $cartEntity->getCartNum(),
718
+            //     $addressEntity->getCityId()
719
+            // );
720
+            $postage = 0.00; // 默认全都包邮s
721
+
722
+            // 汇付手续费 (订单价格 + 邮费) * 汇付手续费比例
723
+            $commissionRate = bcmul(bcadd($price, $postage, CommonEnum::DECIMAL_PLACES_OF_THE_AMOUNT), CommonEnum::HUIFU_COMMISSION_CHARGE, CommonEnum::DECIMAL_PLACES_OF_THE_AMOUNT);
724
+            // 平台拿到的钱(商户分润) 商品数量 * 每个商品的单件让利
725
+            $serviceMoney = bcmul($cartEntity->getCartNum(), $productAttrValueEntity->getPlateMerProfit(), CommonEnum::DECIMAL_PLACES_OF_THE_AMOUNT);
726
+            // 商家获利部分(成本) 订单价格 - 平台拿到的钱
727
+            $cost = bcsub($price, $serviceMoney, CommonEnum::DECIMAL_PLACES_OF_THE_AMOUNT);
728
+            // 商家 实际可以得到的钱  商家获利部分 + 邮费 - 订单手续费
729
+            $merMoney = bcsub(bcadd($cost, $postage, CommonEnum::DECIMAL_PLACES_OF_THE_AMOUNT), $commissionRate, CommonEnum::DECIMAL_PLACES_OF_THE_AMOUNT);
730
+
731
+            // 计算总 邮费
732
+            $totalPostage = bcadd($totalPostage, $postage, 2);
733
+            // 计算总价
734
+            $totalPrice = bcadd($totalPrice, $price, 2);
735
+            // 计算总数
736
+            $totalNum = bcadd($totalNum, $cartEntity->getCartNum(), 2);
737
+            // 计算总成本
738
+            $totalCost = bcadd($totalCost, $cost, 2);
739
+
740
+            // 更新库存
741
+            $productStockList[] = ['productId' => $productEntity->getProductId(), 'cartNum' => $cartEntity->getCartNum()];
742
+            $productAttrValueStockList[] = ['productId' => $productAttrValueEntity->getProductId(), 'unique' => $productAttrValueEntity->getUnique(), 'cartNum' => $cartEntity->getCartNum()];
743
+
744
+            // 创建订单
745
+            /** @var StoreOrderEntity $storeOrderEntity */
746
+            $storeOrderEntity = StoreOrderEntity::newInstance();
747
+            $storeOrderEntity
748
+                ->setCommissionRate($commissionRate)
749
+                ->setExtensionOne($productAttrValueEntity->getExtensionOne())
750
+                // 二级佣金 此字段已被用于分佣比例
751
+                ->setExtensionTwo($productAttrValueEntity->getExtensionTwo())
752
+                ->setOrderSn($storeOrderRepository->getNewOrderId())
753
+                ->setUid($cartEntity->getUid())
754
+                ->setRealName($addressEntity->getRealName())
755
+                ->setUserPhone($addressEntity->getPhone())
756
+                ->setUserAddress($addressEntity->getProvince() . $addressEntity->getCity() . $addressEntity->getDistrict() . $addressEntity->getDetail())
757
+                ->setCartId($cartEntity->getCartId())
758
+                ->setTotalNum($cartEntity->getCartNum())
759
+                ->setTotalPrice(bcadd($price, $postage, CommonEnum::DECIMAL_PLACES_OF_THE_AMOUNT))
760
+                ->setTotalPostage($postage)
761
+                ->setPayPostage($postage)
762
+                ->setPayPrice($price)
763
+                ->setMerId($cartEntity->getMerId())
764
+                ->setCost($cost)
765
+                ->setMerMoney($merMoney)
766
+                ->setPayType($storeOrderCreateRequestEntity->getPayType())
767
+                ->setShareId($storeOrderCreateRequestEntity->getShareId())
768
+                ->setShareUid($shareEntity->getUid())
769
+                ->setServiceMoney($serviceMoney)
770
+                ->setTestOrder($userEntity->getTestUser())
771
+                ->setDacangId($productEntity->getDcId())
772
+                ->setDistributionMode(StoreOrderEnum::DISTRIBUTION_MODE['ExpressDelivery']['code'])
773
+                ->setAddressId($addressEntity->getAddressId())
774
+                ->setSeckill($productSeckillEntity->getId())
775
+                ->setYouhuiPrice($youhuiPrice)
776
+                ->setDouhuomall(empty($productEntity->getSpuId()) ? StoreOrderEnum::DOHUOMALL['PlatformOrder']['code'] : StoreOrderEnum::DOHUOMALL['SupplyChainOrder']['code'])
777
+                ->setDouhuomallStatus(empty($productEntity->getSpuId()) ? null : StoreOrderEnum::DOHUOMALL_STATUS['NotSubmittedToWeiweiBao']['code'])
778
+                ->setFzonePaytype($storeOrderCreateRequestEntity->getFzonePayType())
779
+                ->setConPri($serviceMoney);
780
+            $storeOrderEntityList[] = $storeOrderEntity;
781
+        }
782
+
783
+        /** @var StoreGroupOrderEntity $storeGroupOrderEntity */
784
+        $storeGroupOrderEntity = StoreGroupOrderEntity::newInstance();
785
+        $storeGroupOrderEntity
786
+            ->setUid($userEntity->getUid())
787
+            ->setGroupOrderSn($storeGroupOrderRepository->getNewOrderId())
788
+            ->setTotalPostage($totalPostage)
789
+            ->setTotalPrice(bcadd($totalPrice, $totalPostage, CommonEnum::DECIMAL_PLACES_OF_THE_AMOUNT))
790
+            ->setTotalNum($totalNum)
791
+            ->setRealName($addressEntity->getRealName())
792
+            ->setUserPhone($addressEntity->getPhone())
793
+            ->setUserAddress($addressEntity->getProvince() . $addressEntity->getCity() . $addressEntity->getDistrict() . $addressEntity->getDetail())
794
+            ->setPayPrice($totalPrice)
795
+            ->setPayPostage($totalPostage)
796
+            ->setCost($totalCost)
797
+            ->setPayType($storeOrderCreateRequestEntity->getPayType())
798
+            ->setFzonePaytype($storeOrderCreateRequestEntity->getFzonePayType());
799
+
800
+        // 4、写入数据
801
+        (new \think\facade\Db)->startTrans();
802
+        try {
803
+            // 4.1 更细库存
804
+            foreach ($productStockList as $item) {
805
+                $productRepository->descStock($item['productId'], $item['cartNum']);
806
+            }
807
+            foreach ($productAttrValueStockList as $item) {
808
+                $productAttrValueRepository->descStock($item['productId'], $item['unique'], $item['cartNum']);
809
+            }
810
+
811
+            // 4.2 修改 购物车状态
812
+            $storeCartRepository->updateIsPayByCartIdList($cartIdList);
813
+
814
+            // 4.3 写入 组合订单 (支付订单)
815
+            $storeGroupOrderEntity = $storeGroupOrderRepository->createByEntity($storeGroupOrderEntity);
816
+
817
+            // 4.5 写入订单数据
818
+            $storeOrderStatusEntityList = [];
819
+            $storeOrderProductEntityList = [];
820
+            $paySuccess = true; // 是否已完成支付 并支付成功
821
+            foreach ($storeOrderEntityList as $key => $storeOrderEntity) {
822
+                // 将订单数据 写入数据库 并完善实体
823
+                $storeOrderEntity->setGroupOrderId($storeGroupOrderEntity->getGroupOrderId());
824
+                $storeOrderEntity = $storeOrderRepository->createByEntity($storeOrderEntity);
825
+
826
+                // 4.4 验证是否 可以进行支付 因为历史的 用户资金(佣金、养老金、积分、VR等)扣减所绑定的orderId都是订单ID
827
+                /** @var FzonePayTypeEntity $fzonePayTypeEntity */
828
+                $fzonePayTypeEntity = FzonePayTypeEntity::newInstance($storeOrderCreateRequestEntity->getFzonePayType());
829
+                // 当有一笔支付失败时,默认整个 订单组 没有 "完全" 支付成功
830
+                if (!$storeOrderRepository->abatement($userEntity, $storeOrderEntity, $fzonePayTypeEntity)) {
831
+                    $paySuccess = false;
832
+                }
833
+
834
+                // 将每件商品设计到的优惠券要取消掉
835
+
836
+                // 准备订单的 状态数据
837
+                $storeOrderStatusEntityList[] = StoreOrderStatusEntity::newInstance()
838
+                    ->setOrderId($storeOrderEntity->getOrderId())
839
+                    ->setChangeType(StoreOrderStatusEnum::CHANGE_TYPE['Create']['code'])
840
+                    ->setChangeMessage(StoreOrderStatusEnum::CHANGE_TYPE['Create']['name']);
841
+
842
+                // 获取当前 订单绑定的购物车
843
+                $cartEntity = $cartEntityMap[$storeOrderEntity->getCartId()];
844
+                // 准备订单的 订单购物详情表
845
+                $storeOrderProductEntityList[] = StoreOrderProductEntity::newInstance()
846
+                    ->setOrderId($storeOrderEntity->getOrderId())
847
+                    ->setCartId($storeOrderEntity->getCartId())
848
+                    ->setUid($storeOrderEntity->getUid())
849
+                    ->setProductId($cartEntity->getProductId())
850
+                    ->setProductPrice($storeOrderEntity->getTotalPrice())
851
+                    ->setExtensionOne(0.00)
852
+                    ->setExtensionTwo(0.00)
853
+                    ->setProductSku($cartEntity->getProductAttrUnique())
854
+                    ->setProductNum($cartEntity->getCartNum())
855
+                    ->setRefundNum($cartEntity->getCartNum())
856
+                    ->setType($storeProductEntityMap[$cartEntity->getProductId()]->getType())
857
+                    ->setCartInfo(json_encode([
858
+                        'product' => $storeProductEntityMap[$cartEntity->getProductId()]->toUnderlineArray(),
859
+                        'productAttr' => $storeProductAttrValueEntityMap[$cartEntity->getProductAttrUnique()]->toUnderlineArray(),
860
+                        'product_type' => $cartEntity->getProductType()
861
+                    ]));
862
+
863
+            }
864
+
865
+            // 4.6 订单操作记录表
866
+            /** @var StoreOrderStatusRepository $storeOrderStatusRepository */
867
+            $storeOrderStatusRepository = app()->make(StoreOrderStatusRepository::class);
868
+            $storeOrderStatusRepository->createByEntityList($storeOrderStatusEntityList);
869
+
870
+            // 4.7 订单购物详情表
871
+            /** @var StoreOrderProductRepository $storeOrderProductRepository */
872
+            $storeOrderProductRepository = app()->make(StoreOrderProductRepository::class);
873
+            $storeOrderProductRepository->createByEntityList($storeOrderProductEntityList);
874
+
875
+            // 4.8 支付成功后 发放奖励
876
+            // 非现金 支付成功后 直接结算
877
+            if ($paySuccess) {
878
+                $storeGroupOrderRepository->storeGroupOrderPaySuccess($storeGroupOrderEntity->getGroupOrderId());
879
+            }
880
+
881
+            (new \think\facade\Db)->commit();
882
+        } catch (DbException $e) {
883
+            (new \think\facade\Db)->rollback();
884
+            Log::error('StoreGroupOrderRepository-createStoreGroupOrder:' . $e->getMessage());
885
+        }
886
+        return ['order_id' => $storeGroupOrderEntity->getGroupOrderId(), 'groupOrder' => $storeGroupOrderEntity->toArray()];
887
+
888
+    }
889
+
890
+    /**
891
+     * @param int $groupOrderId
892
+     * @param string $rand 当现金支付时,汇付会在订单尾部跟一个随机数
893
+     * @param string|null $payOpenId 当现金支付时,付款人的Id
894
+     * @return void
895
+     * @throws DbException
896
+     */
897
+    public function storeGroupOrderPaySuccess(int $groupOrderId, string $rand = '', string $payOpenId = null): void
898
+    {
899
+        /** @var StoreGroupOrderRepository $storeGroupOrderRepository */
900
+        $storeGroupOrderRepository = app()->make(StoreGroupOrderRepository::class);
901
+        /** @var StoreOrderRepository $storeOrderRepository */
902
+        $storeOrderRepository = app()->make(StoreOrderRepository::class);
903
+
904
+        $storeGroupOrderEntity = $storeGroupOrderRepository->getStoreGroupOrderEntityByGroupOrderId($groupOrderId);
905
+        // 修改订单组的 支付状态
906
+        $storeGroupOrderRepository->paySuccessUpdateDB($storeGroupOrderEntity->getGroupOrderId(), $rand);
907
+
908
+        // 获取订单组 内的 所有订单
909
+        $storeOrderEntityList = $storeOrderRepository->getStoreOrderEntityListByGroupOrderId($storeGroupOrderEntity->getGroupOrderId());
910
+        $storeOrderIdList = array_column($storeOrderEntityList, 'orderId');
911
+        $storeCartIdList = array_column($storeOrderEntityList, 'cartId');
912
+
913
+        // 修改订单的 支付状态
914
+        $storeOrderRepository->paySuccessUpdateDB($storeOrderIdList, $payOpenId);
915
+
916
+        // 获取购物车信息
917
+        /** @var StoreCartRepository $storeCartRepository */
918
+        $storeCartRepository = app()->make(StoreCartRepository::class);
919
+        $cartEntityList = $storeCartRepository->getCartEntityListByCartIdList($storeCartIdList);
920
+        /** @var CartEntity[] $cartEntityMap 发起创建订单的购物车映射 */
921
+        $cartEntityMap = array_column($cartEntityList, null, 'cartId');
922
+
923
+        // 记录 需要立即计算的订单ID
924
+        $settlementOrderIdList = [];
925
+        $storeOrderStatusEntityList = [];
926
+        $financialRecordDataList = [];
927
+        foreach ($storeOrderEntityList as $storeOrderEntity) {
928
+            // 生成奖励数据
929
+            $storeOrderRepository->createRewardMechanismByStoreOrderId($storeOrderEntity->getOrderId());
930
+
931
+            if ($storeOrderEntity->getMerId() == CommonEnum::DESIGN_MERCHANT_ID['MemberZone']['code']) {
932
+                // 会员专区的 订单立即结算
933
+                $settlementOrderIdList[] = $storeOrderEntity->getOrderId();
934
+            }
935
+            // 获取当前 订单绑定的购物车
936
+            $cartEntity = $cartEntityMap[$storeOrderEntity->getCartId()];
937
+            // 准备订单的 状态数据
938
+            $storeOrderStatusEntityList[] = StoreOrderStatusEntity::newInstance()
939
+                ->setOrderId($storeOrderEntity->getOrderId())
940
+                ->setChangeType(StoreOrderStatusEnum::CHANGE_TYPE['PaySuccess']['code'])
941
+                ->setChangeMessage(StoreOrderStatusEnum::CHANGE_TYPE['PaySuccess']['name']);
942
+
943
+            $financialRecordDataList[] = [
944
+
945
+            ];
946
+        }
947
+
948
+        // 4.6 订单操作记录表
949
+        /** @var StoreOrderStatusRepository $storeOrderStatusRepository */
950
+        $storeOrderStatusRepository = app()->make(StoreOrderStatusRepository::class);
951
+        $storeOrderStatusRepository->createByEntityList($storeOrderStatusEntityList);
952
+
953
+        if (!empty($settlementOrderIdList)) {
954
+            // 将订单 生成的奖励数据 立即结算(发放)
955
+            $storeOrderRepository->settlementOrderByOrderIdList($settlementOrderIdList);
956
+        }
957
+    }
958
+
959
+    /**
960
+     * @param int $groupOrderId
961
+     * @param string $rand
301 962
      * @return int
302 963
      * @throws DbException
303 964
      */
304
-    public function paySuccess($groupOrderId): int
965
+    public function paySuccessUpdateDB(int $groupOrderId, string $rand = ''): int
305 966
     {
306
-        return $this->dao->paySuccess($groupOrderId);
967
+        return $this->dao->paySuccessUpdateDB($groupOrderId, $rand);
307 968
     }
308 969
 }

+ 33 - 0
app/common/repositories/store/order/StoreOrderProductRepository.php

@@ -13,6 +13,7 @@ namespace app\common\repositories\store\order;
13 13
 
14 14
 use app\common\dao\store\order\StoreOrderProductDao;
15 15
 use app\common\repositories\BaseRepository;
16
+use app\entity\data\store\StoreOrderProductEntity;
16 17
 
17 18
 /**
18 19
  * Class StoreOrderProductRepository
@@ -31,4 +32,36 @@ class StoreOrderProductRepository extends BaseRepository
31 32
     {
32 33
         $this->dao = $dao;
33 34
     }
35
+
36
+    public function create($data)
37
+    {
38
+        return $this->dao->create($data);
39
+    }
40
+
41
+    /**
42
+     * 写入订单购物详情表
43
+     * @param StoreOrderProductEntity $storeOrderEntity
44
+     * @return StoreOrderProductEntity
45
+     */
46
+    public function createByEntity(StoreOrderProductEntity $storeOrderEntity): StoreOrderProductEntity
47
+    {
48
+        $result = $this->create($storeOrderEntity->toUnderlineArray())->toArray();
49
+        /** @var StoreOrderProductEntity $entity */
50
+        $entity = StoreOrderProductEntity::newInstance($result);
51
+        return $entity;
52
+    }
53
+
54
+    /**
55
+     * 批量写入订单购物详情表
56
+     * @param StoreOrderProductEntity[] $entityList
57
+     * @return int
58
+     */
59
+    public function createByEntityList(array $entityList): int
60
+    {
61
+        $dataList = [];
62
+        foreach ($entityList as $entity) {
63
+            $dataList[] = $entity->toUnderlineArray();
64
+        }
65
+        return $this->insertAll($dataList);
66
+    }
34 67
 }

+ 285 - 545
app/common/repositories/store/order/StoreOrderRepository.php

@@ -15,9 +15,6 @@ use app\common\dao\store\order\StoreOrderDao;
15 15
 use app\common\enum\CommonEnum;
16 16
 use app\common\enum\merchant\MerchantEnum;
17 17
 use app\common\enum\shipping\ShippingTemplateEnum;
18
-use app\common\enum\store\CartEnum;
19
-use app\common\enum\store\ProductEnum;
20
-use app\common\enum\store\StoreGroupOrderEnum;
21 18
 use app\common\enum\store\StoreOrderEnum;
22 19
 use app\common\enum\user\UserBillEnum;
23 20
 use app\common\enum\user\UserEnum;
@@ -33,15 +30,9 @@ use app\common\model\store\order\StoreGroupOrder;
33 30
 use app\common\model\store\order\StoreOrder;
34 31
 use app\common\model\store\order\StoreRefundOrder;
35 32
 use app\common\model\user\User;
36
-use app\common\model\user\UserCertification;
37
-use app\common\model\user\UserRich;
38 33
 use app\common\repositories\merchant\order\OrderGzcRepository;
39 34
 use app\common\repositories\merchant\order\OrderMerchantRepository;
40 35
 use app\common\repositories\BaseRepository;
41
-use app\common\repositories\product\ProductSeckillRepository;
42
-use app\common\repositories\product\ShareRepository;
43
-use app\common\repositories\store\coupon\StoreCouponProductRepository;
44
-use app\common\repositories\store\coupon\StoreCouponRepository;
45 36
 use app\common\repositories\store\coupon\StoreCouponUserRepository;
46 37
 use app\common\repositories\store\MerchantTakeRepository;
47 38
 use app\common\repositories\store\product\ProductAttrValueRepository;
@@ -54,10 +45,8 @@ use app\common\repositories\store\shipping\ShippingTemplateUndeliveRepository;
54 45
 use app\common\repositories\store\StoreSeckillActiveRepository;
55 46
 use app\common\repositories\system\attachment\AttachmentRepository;
56 47
 use app\common\repositories\system\merchant\FinancialRecordRepository;
57
-use app\common\repositories\system\merchant\MerchantCategoryRepository;
58 48
 use app\common\repositories\system\merchant\MerchantContributionRepository;
59 49
 use app\common\repositories\system\merchant\MerchantRepository;
60
-use app\common\repositories\merchant\MerchantRepository as m;
61 50
 use app\common\repositories\user\UserAddressRepository;
62 51
 use app\common\repositories\user\UserBillRepository;
63 52
 use app\common\repositories\user\UserPvLogRepository;
@@ -73,31 +62,20 @@ use app\common\repositories\user\UserThirdRepository;
73 62
 use app\common\repositories\wechat\RoutineQrcodeRepository;
74 63
 use app\common\repositories\wechat\WechatUserRepository;
75 64
 use app\controller\api\user\Volunteer;
76
-use app\entity\data\merchant\MerchantEntity;
77
-use app\entity\data\product\ProductSeckillEntity;
78
-use app\entity\data\product\ShareEntity;
79
-use app\entity\data\store\CartEntity;
80 65
 use app\entity\data\store\StoreProductAttrValueEntity;
81 66
 use app\entity\data\store\StoreProductEntity;
82
-use app\entity\data\store\StoreGroupOrderEntity;
83 67
 use app\entity\data\store\StoreOrderEntity;
84
-use app\entity\data\user\UserAddressEntity;
85
-use app\entity\data\user\UserBillEntity;
86 68
 use app\entity\data\user\UserEntity;
87 69
 use app\entity\monomer\store\FzonePayTypeEntity;
88 70
 use app\entity\request\api\store\order\CalculatePostageRequestEntity;
89
-use app\entity\request\api\store\order\StoreOrderCreateRequestEntity;
90 71
 use app\model\common\JdOrderModel;
91 72
 use app\model\common\TbOrderModel;
92 73
 use app\traits\GongApiRequest;
93 74
 use app\traits\HuiPay;
94 75
 use app\traits\ShouxinyiApiRequest;
95
-use app\utils\ArrayUtil;
96
-use Carbon\Carbon;
97 76
 use crmeb\jobs\PayGiveCouponJob;
98 77
 use crmeb\jobs\SendSmsJob;
99 78
 use crmeb\jobs\SendTemplateMessageJob;
100
-use crmeb\services\AliYunSmsService;
101 79
 use crmeb\services\ExpressService;
102 80
 use crmeb\services\MiniProgramService;
103 81
 use crmeb\services\QrcodeService;
@@ -120,7 +98,6 @@ use think\facade\Route;
120 98
 use Alipay\AopClient;
121 99
 use Alipay\request\AlipayTradeAppPayRequest;
122 100
 use Lakala\src\LakalaBoss;
123
-use vipapis\dvd\DvdAreaSalesService_healthCheck_args;
124 101
 use function Couchbase\basicEncoderV1;
125 102
 
126 103
 /**
@@ -10750,6 +10727,25 @@ class StoreOrderRepository extends BaseRepository
10750 10727
         return $this->dao->getStoreOrderEntityListByOrderIdList($orderIdList);
10751 10728
     }
10752 10729
 
10730
+
10731
+    /**
10732
+     * @param int $groupOrderId
10733
+     * @return StoreOrderEntity[]
10734
+     */
10735
+    public function getStoreOrderEntityListByGroupOrderId(int $groupOrderId): array
10736
+    {
10737
+        return $this->getStoreOrderEntityListByGroupOrderIdList([$groupOrderId]);
10738
+    }
10739
+
10740
+    /**
10741
+     * @param array $groupOrderIdList
10742
+     * @return StoreOrderEntity[]
10743
+     */
10744
+    public function getStoreOrderEntityListByGroupOrderIdList(array $groupOrderIdList): array
10745
+    {
10746
+        return $this->dao->getStoreOrderEntityListByGroupOrderIdList($groupOrderIdList);
10747
+    }
10748
+
10753 10749
     public function create($data)
10754 10750
     {
10755 10751
         return $this->dao->create($data);
@@ -10815,7 +10811,7 @@ class StoreOrderRepository extends BaseRepository
10815 10811
             // 修改用户积分 先有记录 再去执行
10816 10812
             $userSignScoreEntity = $userSignScoreRepository->addUserSingScore(
10817 10813
                 $userEntity->getUid(),
10818
-                UserSignScoreEnum::SOURCE_TYPE['SelfOrder']['code'],
10814
+                UserSignScoreEnum::SOURCE_TYPE['BuyProduct']['code'],
10819 10815
                 UserSignScoreEnum::PM['Expend']['code'],
10820 10816
                 $fzonePayTypeEntity->getOther(),
10821 10817
                 '购买商品,订单编号:' . $storeOrderEntity->getOrderSn(),
@@ -10829,7 +10825,20 @@ class StoreOrderRepository extends BaseRepository
10829 10825
             if ($fzonePayTypeEntity->getOther() > $userEntity->getScore()) {
10830 10826
                 throw new ValidateException('支付失败,积分不足!');
10831 10827
             }
10832
-            // 用户下单时 不扣除积分,而是在支付环节 验证 并扣除
10828
+            // 修改用户积分 先有记录 再去执行
10829
+            $userSignScoreEntity = $userSignScoreRepository->addUserSingScore(
10830
+                $userEntity->getUid(),
10831
+                UserSignScoreEnum::SOURCE_TYPE['BuyProduct']['code'],
10832
+                UserSignScoreEnum::PM['Expend']['code'],
10833
+                $fzonePayTypeEntity->getOther(),
10834
+                '购买商品,订单编号:' . $storeOrderEntity->getOrderSn(),
10835
+                UserSignScoreEnum::ORDER_TYPE['Platform']['code'],
10836
+                $storeOrderEntity->getOrderId()
10837
+            );
10838
+            $userSignScoreRepository->execute($userSignScoreEntity->getId());
10839
+            // 如果订单取消,或者自动取消,会走 取消订单方法 将此笔扣减项返还给用户)
10840
+            // 自动退款 走的事件 app/event.php  AutoCancelGroupOrderListen
10841
+
10833 10842
         } else if ($fzonePayTypeEntity->getType() == StoreOrderEnum::FZONE_PAY_TYPE['B3-VR+Jingdou']['code']) {
10834 10843
             if ($fzonePayTypeEntity->getPrice() > $userEntity->getVr() || $fzonePayTypeEntity->getOther() > $userEntity->getJingdou()) {
10835 10844
                 throw new ValidateException('支付失败,VR或京豆不足!');
@@ -10861,9 +10870,24 @@ class StoreOrderRepository extends BaseRepository
10861 10870
 
10862 10871
             $paySuccess = true;
10863 10872
         } else if ($fzonePayTypeEntity->getType() == StoreOrderEnum::FZONE_PAY_TYPE['B4-Cash+Jingdou']['code']) {
10864
-            if ($fzonePayTypeEntity->getPrice() > $userEntity->getVr() || $fzonePayTypeEntity->getOther() > $userEntity->getJingdou()) {
10873
+            if ($fzonePayTypeEntity->getOther() > $userEntity->getJingdou()) {
10865 10874
                 throw new ValidateException('支付失败,京豆不足!');
10866 10875
             }
10876
+            // 创建 京豆 扣减记录
10877
+            $userSignJingdouEntity = $userSignJingdouRepository->addUserSingJingdou(
10878
+                $userEntity->getUid(),
10879
+                UserSignJingdouEnum::TYPE['Consume']['code'],
10880
+                $fzonePayTypeEntity->getOther(),
10881
+                0,
10882
+                '购买商品,订单编号:' . $storeOrderEntity->getOrderSn(),
10883
+                CommonEnum::ORDER_TYPE['Platform']['code'],
10884
+                $storeOrderEntity->getOrderId()
10885
+            );
10886
+            // 执行 京豆 增减 操作
10887
+            $userSignJingdouRepository->execute($userSignJingdouEntity->getId());
10888
+            // 如果订单取消,或者自动取消,会走 取消订单方法 将此笔扣减项返还给用户)
10889
+            // 自动退款 走的事件 app/event.php  AutoCancelGroupOrderListen
10890
+
10867 10891
         } else if ($fzonePayTypeEntity->getType() == StoreOrderEnum::FZONE_PAY_TYPE['B5-VR']['code']) {
10868 10892
             if ($fzonePayTypeEntity->getPrice() > $userEntity->getVr()) {
10869 10893
                 throw new ValidateException('支付失败,VR不足!');
@@ -10900,11 +10924,23 @@ class StoreOrderRepository extends BaseRepository
10900 10924
             $paySuccess = true;
10901 10925
         } else if ($fzonePayTypeEntity->getType() == StoreOrderEnum::FZONE_PAY_TYPE['A2-Cash']['code']) {
10902 10926
 
10903
-        }
10904
-        else if ($fzonePayTypeEntity->getType() == StoreOrderEnum::FZONE_PAY_TYPE['A3-Cash+VR']['code']) {
10927
+        } else if ($fzonePayTypeEntity->getType() == StoreOrderEnum::FZONE_PAY_TYPE['A3-Cash+VR']['code']) {
10905 10928
             if ($fzonePayTypeEntity->getOther() > $userEntity->getVr()) {
10906 10929
                 throw new ValidateException('支付失败,VR不足!');
10907 10930
             }
10931
+            // 创建Vr扣减记录 先有记录 再去执行
10932
+            $userSignVrEntity = $userSignVrRepository->addUserSingVr(
10933
+                $userEntity->getUid(),
10934
+                UserSignVrEnum::TYPE['Consume']['code'],
10935
+                $fzonePayTypeEntity->getPrice(),
10936
+                '购买商品,订单编号:' . $storeOrderEntity->getOrderSn(),
10937
+                CommonEnum::ORDER_TYPE['Platform']['code'],
10938
+                $storeOrderEntity->getOrderId()
10939
+            );
10940
+            // 执行 Vr 增减 操作
10941
+            $userSignVrRepository->execute($userSignVrEntity->getId());
10942
+            // 如果订单取消,或者自动取消,会走 取消订单方法 将此笔扣减项返还给用户)
10943
+            // 自动退款 走的事件 app/event.php  AutoCancelGroupOrderListen
10908 10944
         } else if ($fzonePayTypeEntity->getType() == StoreOrderEnum::FZONE_PAY_TYPE['C1-Fugou']['code']) {
10909 10945
             if ($fzonePayTypeEntity->getOther() > $userEntity->getFugou()) {
10910 10946
                 throw new ValidateException('支付失败,复购金不足!');
@@ -10912,7 +10948,7 @@ class StoreOrderRepository extends BaseRepository
10912 10948
             // 添加复购金 记录
10913 10949
             $userSignFugouEntity = $userSignFugouRepository->addUserSingFugou(
10914 10950
                 $userEntity->getUid(),
10915
-                UserSignFugouEnum::TYPE['Give']['code'],
10951
+                UserSignFugouEnum::TYPE['Consume']['code'],
10916 10952
                 $fzonePayTypeEntity->getPrice(),
10917 10953
                 UserSignFugouEnum::COMMISSION_TYPE['DIRECT_REFERRAL']['code'],
10918 10954
                 '购买商品,订单编号:' . $storeOrderEntity->getOrderSn(),
@@ -10929,6 +10965,17 @@ class StoreOrderRepository extends BaseRepository
10929 10965
     }
10930 10966
 
10931 10967
     /**
10968
+     * 订单支付成功后,更新订单信息
10969
+     * @param array $storeOrderIdList
10970
+     * @param string|null $payOpenId
10971
+     * @return int
10972
+     * @throws DbException
10973
+     */
10974
+    public function paySuccessUpdateDB(array $storeOrderIdList, string $payOpenId = null): int
10975
+    {
10976
+        return $this->dao->paySuccessUpdateDB($storeOrderIdList, $payOpenId);
10977
+    }
10978
+    /**
10932 10979
      * 根据 订单ID 来生 成奖励数据(待生效)
10933 10980
      * @param int $orderId
10934 10981
      * @return void
@@ -11759,522 +11806,6 @@ class StoreOrderRepository extends BaseRepository
11759 11806
     }
11760 11807
 
11761 11808
     /**
11762
-     * @param StoreOrderCreateRequestEntity $storeOrderCreateRequestEntity
11763
-     * @return array
11764
-     */
11765
-    public function createOrderNew2(StoreOrderCreateRequestEntity $storeOrderCreateRequestEntity): array
11766
-    {
11767
-
11768
-        // 1、验证数据合规性 并获取 请求 数据
11769
-        $verifyResult = $this->verifyRequestInformation($storeOrderCreateRequestEntity);
11770
-        /** @var UserEntity $userEntity 当前操作用户 */
11771
-        $userEntity = $verifyResult['userEntity'];
11772
-        /** @var CartEntity[] $cartEntityList 发起创建订单的购物车列表 */
11773
-        $cartEntityList = $verifyResult['cartEntityList'];
11774
-        /** @var CartEntity[] $cartEntityMap 发起创建订单的购物车映射 */
11775
-        $cartEntityMap = array_column($cartEntityList, null, 'cartId');
11776
-        $cartIdList = array_keys($cartEntityMap);
11777
-        /** @var UserAddressEntity $addressEntity 地址信息 */
11778
-        $addressEntity = $verifyResult['addressEntity'];
11779
-        /** @var ShareEntity $shareEntity 订单所带的分享信息 */
11780
-        $shareEntity = $verifyResult['shareEntity'];
11781
-        /** @var MerchantEntity[] $merchantEntityMap 订单所涉及的商户信息映射 */
11782
-        $merchantEntityMap = $verifyResult['merchantEntityMap'];
11783
-        /** @var StoreProductEntity[] $storeProductEntityMap 订单所涉及的 商品信息 映射 */
11784
-        $storeProductEntityMap = $verifyResult['storeProductEntityMap'];
11785
-        /** @var StoreProductAttrValueEntity[] $storeProductAttrValueEntityMap 订单所涉及的 商品属性信息 */
11786
-        $storeProductAttrValueEntityMap = $verifyResult['storeProductAttrValueEntityMap'];
11787
-
11788
-        // 2、加载 需要调用的 模块
11789
-        // 商品秒杀
11790
-        /** @var ProductSeckillRepository $productSeckillRepository */
11791
-        $productSeckillRepository = app()->make(ProductSeckillRepository::class);
11792
-        // // 优惠券 列表(商户or平台)
11793
-        // /** @var StoreCouponRepository $storeCouponRepository */
11794
-        // $storeCouponRepository = app()->make(StoreCouponRepository::class);
11795
-        // // 优惠券 商品 关联表
11796
-        // /** @var StoreCouponProductRepository $storeCouponProductRepository */
11797
-        // $storeCouponProductRepository = app()->make(StoreCouponProductRepository::class);
11798
-        // // 用户的优惠券领取记录
11799
-        // /** @var StoreCouponUserRepository $storeCouponUserRepository */
11800
-        // $storeCouponUserRepository = app()->make(StoreCouponUserRepository::class);
11801
-
11802
-        // 商品
11803
-        /** @var ProductRepository $productRepository */
11804
-        $productRepository = app()->make(ProductRepository::class);
11805
-        // 商品属性
11806
-        /** @var ProductAttrValueRepository $productAttrValueRepository */
11807
-        $productAttrValueRepository = app()->make(ProductAttrValueRepository::class);
11808
-
11809
-        // 购物车
11810
-        /** @var StoreCartRepository $storeCartRepository */
11811
-        $storeCartRepository = app()->make(StoreCartRepository::class);
11812
-
11813
-        // 3、创建 变量
11814
-        $storeOrderEntityList = []; // 订单数据实体列表 主要用于写入数据,循环获取数据
11815
-        $storeCouponUserEntityListByMerIdMap = []; // 订单优惠券 商户 映射
11816
-        $totalPrice = 0.00; // 订单总价
11817
-        $totalPostage = 0.00; // 订单总邮费
11818
-        $totalNum = 0; // 订单总商品数量
11819
-        $totalCost = 0.00; // 订单商品 总成本
11820
-        $productStockList = []; // 商品 库存更新列表
11821
-        $productAttrValueStockList = []; // 商品 属性 库存更新列表
11822
-
11823
-        // 4、组装数据 每条购物车信息 就是一条订单数据
11824
-        // 循环购物车 对购物车内的商品 进行条件验证 以及根据不同的商品 计算邮费
11825
-        foreach ($cartEntityMap as $cartId => $cartEntity) {
11826
-            // 获取商品 实体
11827
-            $productEntity = $storeProductEntityMap[$cartEntity->getProductId()];
11828
-            // 获取商品属性 实体
11829
-            $productAttrValueEntity = $storeProductAttrValueEntityMap[$cartEntity->getProductAttrUnique()];
11830
-
11831
-            // 验证是否是秒杀产品 如果是秒杀产品,并且设置了 大仓会员价 则将大仓会员价 设置为 商品价格
11832
-            $productSeckillEntity = ProductSeckillEntity::newInstance();
11833
-            if ($productEntity->getSeckill() == ProductEnum::SECKILL['Yes']['code'] && !is_null($productEntity->getDcPrice()) && $productEntity->getDcPrice() > 0.00) {
11834
-                // 获取 在活动期间内的 秒杀活动记录
11835
-                $productSeckillEntity = $productSeckillRepository->getProductSeckillEntityByProductId($cartEntity->getProductId());
11836
-                if (!empty($productSeckillEntity->getId())) {
11837
-                    // 把 商品属性的 价格 改成 大仓会员价
11838
-                    $productAttrValueEntity->setPrice($productEntity->getDcPrice());
11839
-                }
11840
-            }
11841
-
11842
-            // 计算优惠券 ******************  优惠券是此步骤(第一步需要考虑的问题,但是目前阶段暂不需要该功能 所以未完成 先注释)
11843
-            $youhuiPrice = 0.00;
11844
-            // // 商品券 优先于 店铺券
11845
-            // // 商品券(平台优惠券)
11846
-            // if (!isset($storeCouponUserEntityListByMerIdMap[0])) {
11847
-            //     $storeCouponUserEntityListByMerIdMap[0] = $storeCouponUserRepository->getValidStoreCouponUserEntityListByMerIdAndUid(0, $cartEntity->getUid());
11848
-            // }
11849
-            // // 店铺券(满减券)
11850
-            // if (!isset($storeCouponUserEntityListByMerIdMap[$cartEntity->getMerId()])) {
11851
-            //     // 查询 当前用户 在当前 店铺的 优惠券
11852
-            //     $storeCouponUserEntityListByMerIdMap[$cartEntity->getMerId()] = $storeCouponUserRepository->getValidStoreCouponUserEntityListByMerIdAndUid($cartEntity->getMerId(), $cartEntity->getUid());
11853
-            // }
11854
-            //
11855
-            // if (!empty($storeCouponUserEntityListByMerIdMap[0]) || !empty($storeCouponUserEntityListByMerIdMap[$cartEntity->getMerId()])) {
11856
-            //     foreach ([0, $cartEntity->getMerId()] as $merId) {
11857
-            //         foreach ($storeCouponUserEntityListByMerIdMap[$merId] as $storeCouponUserEntity) {
11858
-            //             // 如果不能明确当前优惠券的 获取方式 ,则忽略当前的优惠券的有效性
11859
-            //             if (empty($storeCouponUserEntity->getType())) {
11860
-            //                 continue;
11861
-            //             }
11862
-            //             // 优惠卷关联商品 辅助表
11863
-            //             $storeCouponProductEntityList = $storeCouponProductRepository->getStoreCouponProductEntityListByCouponId($storeCouponUserEntity->getCouponId());
11864
-            //             if (!empty($storeCouponProductEntityList)) {
11865
-            //                 // 商品券
11866
-            //                 foreach ($storeCouponProductEntityList as $storeCouponProductEntity) {
11867
-            //                     // 如果当前 优惠券 所关联的 商品 是否在当前购买的 该商家的 商品列表中,(没有则说明此条关联记录 无用) 并且当前 该商家内 该商品没有已使用的优惠券
11868
-            //                     if (in_array($storeCouponProductEntity->getProductId(), array_keys($productPriceByMerIdMap[$merchantEntity->getMerId()])) && !isset($useCouponProduct[$storeCouponProductEntity->getProductId()][$cartEntity->getCartId()])) {
11869
-            //                         // 如果 当前该商家 该商品 的价格 超过了 “最低消费多少金额可用优惠券” 的金额 则记录该优惠金额,并记录该优惠券ID 后续设置为已使用
11870
-            //                         if (($productAttrValueEntity->getPrice()) >= $storeCouponUserEntity->getUseMinPrice()) {
11871
-            //                             $couponPrice = bcadd($couponPrice, $storeCouponUserEntity->getCouponPrice(), 2);
11872
-            //                             // 一个商家的 一种商品 只能使用一次优惠券
11873
-            //                             $useCouponProduct[$storeCouponProductEntity->getProductId()][$cartEntity->getCartId()][] = $storeCouponUserEntity->getCouponUserId();
11874
-            //                             break;
11875
-            //                         }
11876
-            //                     }
11877
-            //                 }
11878
-            //             } else {
11879
-            //                 // 店铺券(平台券-满减券)
11880
-            //
11881
-            //             }
11882
-            //         }
11883
-            //     }
11884
-            // }
11885
-
11886
-            // 计算 每笔订单的价格
11887
-            $price = bcmul($cartEntity->getCartNum(), $productAttrValueEntity->getPrice(), CommonEnum::DECIMAL_PLACES_OF_THE_AMOUNT);
11888
-
11889
-            // 计算运费 获取该商品的运费模板 运费表
11890
-            // 判断商品是否是 供应链(微唯宝)商品
11891
-            // $postage = $this->calculatePostage(
11892
-            //     $productEntity,
11893
-            //     $productAttrValueEntity,
11894
-            //     $cartEntity->getCartNum(),
11895
-            //     $addressEntity->getCityId()
11896
-            // );
11897
-            $postage = 0.00; // 默认全都包邮s
11898
-
11899
-            // 汇付手续费 (订单价格 + 邮费) * 汇付手续费比例
11900
-            $commissionRate = bcmul(bcadd($price, $postage, CommonEnum::DECIMAL_PLACES_OF_THE_AMOUNT), CommonEnum::HUIFU_COMMISSION_CHARGE, CommonEnum::DECIMAL_PLACES_OF_THE_AMOUNT);
11901
-            // 平台拿到的钱(商户分润) 商品数量 * 每个商品的单件让利
11902
-            $serviceMoney = bcmul($cartEntity->getCartNum(), $productAttrValueEntity->getPlateMerProfit(), CommonEnum::DECIMAL_PLACES_OF_THE_AMOUNT);
11903
-            // 商家获利部分(成本) 订单价格 - 平台拿到的钱
11904
-            $cost = bcsub($price, $serviceMoney, CommonEnum::DECIMAL_PLACES_OF_THE_AMOUNT);
11905
-            // 商家 实际可以得到的钱  商家获利部分 + 邮费 - 订单手续费
11906
-            $merMoney = bcsub(bcadd($cost, $postage, CommonEnum::DECIMAL_PLACES_OF_THE_AMOUNT), $commissionRate, CommonEnum::DECIMAL_PLACES_OF_THE_AMOUNT);
11907
-
11908
-            // 计算总 邮费
11909
-            $totalPostage = bcadd($totalPostage, $postage, 2);
11910
-            // 计算总价
11911
-            $totalPrice = bcadd($totalPrice, $price, 2);
11912
-            // 计算总数
11913
-            $totalNum = bcadd($totalNum, $cartEntity->getCartNum(), 2);
11914
-            // 计算总成本
11915
-            $totalCost = bcadd($totalCost, $cost, 2);
11916
-
11917
-            // 更新库存
11918
-            $productStockList[] = ['productId' => $productEntity->getProductId(), 'cartNum' => $cartEntity->getCartNum()];
11919
-            $productAttrValueStockList[] = ['productId' => $productAttrValueEntity->getProductId(), 'unique' => $productAttrValueEntity->getUnique(),'cartNum' => $cartEntity->getCartNum()];
11920
-
11921
-            // 创建订单
11922
-            /** @var StoreOrderEntity $storeOrderEntity */
11923
-            $storeOrderEntity = StoreOrderEntity::newInstance();
11924
-            $storeOrderEntity
11925
-                ->setCommissionRate($commissionRate)
11926
-                ->setExtensionOne($productAttrValueEntity->getExtensionOne())
11927
-                // 二级佣金 此字段已被用于分佣比例
11928
-                ->setExtensionTwo($productAttrValueEntity->getExtensionTwo())
11929
-                ->setOrderSn($this->getNewOrderId())
11930
-                ->setUid($cartEntity->getUid())
11931
-                ->setRealName($addressEntity->getRealName())
11932
-                ->setUserPhone($addressEntity->getPhone())
11933
-                ->setUserAddress($addressEntity->getProvince() . $addressEntity->getCity() . $addressEntity->getDistrict() . $addressEntity->getDetail())
11934
-                ->setCartId($cartEntity->getCartId())
11935
-                ->setTotalNum($cartEntity->getCartNum())
11936
-                ->setTotalPrice(bcadd($price, $postage, CommonEnum::DECIMAL_PLACES_OF_THE_AMOUNT))
11937
-                ->setTotalPostage($postage)
11938
-                ->setPayPostage($postage)
11939
-                ->setPayPrice($price)
11940
-                ->setMerId($cartEntity->getMerId())
11941
-                ->setCost($cost)
11942
-                ->setMerMoney($merMoney)
11943
-                ->setPayType($storeOrderCreateRequestEntity->getPayType())
11944
-                ->setShareId($storeOrderCreateRequestEntity->getShareId())
11945
-                ->setShareUid($shareEntity->getUid())
11946
-                ->setServiceMoney($serviceMoney)
11947
-                ->setTestOrder($userEntity->getTestUser())
11948
-                ->setDacangId($productEntity->getDcId())
11949
-                ->setDistributionMode(StoreOrderEnum::DISTRIBUTION_MODE['ExpressDelivery']['code'])
11950
-                ->setAddressId($addressEntity->getAddressId())
11951
-                ->setSeckill($productSeckillEntity->getId())
11952
-                ->setYouhuiPrice($youhuiPrice)
11953
-                ->setDouhuomall(empty($productEntity->getSpuId())?StoreOrderEnum::DOHUOMALL['PlatformOrder']['code']:StoreOrderEnum::DOHUOMALL['SupplyChainOrder']['code'])
11954
-                ->setDouhuomallStatus(empty($productEntity->getSpuId()) ? null : StoreOrderEnum::DOHUOMALL_STATUS['NotSubmittedToWeiweiBao']['code'])
11955
-                ->setFzonePaytype($storeOrderCreateRequestEntity->getFzonePayType())
11956
-                ->setConPri($serviceMoney);
11957
-            $storeOrderEntityList[] = $storeOrderEntity;
11958
-        }
11959
-
11960
-        /** @var StoreGroupOrderEntity $storeGroupOrderEntity */
11961
-        $storeGroupOrderEntity = StoreGroupOrderEntity::newInstance();
11962
-        $storeGroupOrderEntity
11963
-            ->setUid($userEntity->getUid())
11964
-            ->setGroupOrderSn($this->getNewOrderId())
11965
-            ->setTotalPostage($totalPostage)
11966
-            ->setTotalPrice(bcadd($totalPrice, $totalPostage, CommonEnum::DECIMAL_PLACES_OF_THE_AMOUNT))
11967
-            ->setTotalNum($totalNum)
11968
-            ->setRealName($addressEntity->getRealName())
11969
-            ->setUserPhone($addressEntity->getPhone())
11970
-            ->setUserAddress($addressEntity->getProvince() . $addressEntity->getCity() . $addressEntity->getDistrict() . $addressEntity->getDetail())
11971
-            ->setPayPrice($totalPrice)
11972
-            ->setPayPostage($totalPostage)
11973
-            ->setCost($totalCost)
11974
-            ->setPayType($storeOrderCreateRequestEntity->getPayType())
11975
-            ->setFzonePaytype($storeOrderCreateRequestEntity->getFzonePayType());
11976
-
11977
-        // 4、写入数据
11978
-        Db::startTrans();
11979
-        try {
11980
-            // 4.1 更细库存
11981
-            foreach ($productStockList as $item) {
11982
-                $productRepository->descStock($item['productId'], $item['cartNum']);
11983
-            }
11984
-            foreach ($productAttrValueStockList as $item) {
11985
-                $productAttrValueRepository->descStock($item['productId'], $item['unique'], $item['cartNum']);
11986
-            }
11987
-
11988
-            // 4.2 修改 购物车状态
11989
-            $storeCartRepository->updateIsPayByCartIdList($cartIdList);
11990
-
11991
-            // 4.3 写入 组合订单 (支付订单)
11992
-            /** @var StoreGroupOrderRepository $storeGroupOrderRepository */
11993
-            $storeGroupOrderRepository = app()->make(StoreGroupOrderRepository::class);
11994
-            $storeGroupOrderEntity = $storeGroupOrderRepository->createByEntity($storeGroupOrderEntity);
11995
-
11996
-            // 4.5 写入订单数据
11997
-            $storeOrderStatusDataList = [];
11998
-            $storeOrderProductDataList = [];
11999
-            $storeOrderIdList = [];
12000
-            $paySuccess = true; // 是否已完成支付 并支付成功
12001
-            foreach ($storeOrderEntityList as $key => $storeOrderEntity) {
12002
-                // 获取当前 订单绑定的购物车
12003
-                $cartEntity = $cartEntityMap[$storeOrderEntity->getCartId()];
12004
-
12005
-                // 将订单数据 写入数据库 并完善实体
12006
-                $storeOrderEntity->setGroupOrderId($storeGroupOrderEntity->getGroupOrderId());
12007
-                $storeOrderEntity = $this->createByEntity($storeOrderEntity);
12008
-
12009
-                $storeOrderEntityList[$key] = $storeOrderEntity;
12010
-                $storeOrderIdList[] = $storeOrderEntity->getOrderId();
12011
-
12012
-                // 4.4 验证是否 可以进行支付 因为历史的 用户资金(佣金、养老金、积分、VR等)扣减所绑定的orderId都是订单ID
12013
-                /** @var FzonePayTypeEntity $fzonePayTypeEntity */
12014
-                $fzonePayTypeEntity = FzonePayTypeEntity::newInstance($storeOrderCreateRequestEntity->getFzonePayType());
12015
-                // 当有一笔支付失败时,默认整个 订单组 没有支付成功
12016
-                if (!$this->abatement($userEntity, $storeOrderEntity, $fzonePayTypeEntity)) {
12017
-                    $paySuccess = false;
12018
-                }
12019
-
12020
-                // 将每件商品设计到的优惠券要取消掉
12021
-
12022
-                // 准备订单的 状态数据
12023
-                $storeOrderStatusDataList[] = [
12024
-                    'order_id' => $storeOrderEntity->getOrderId(),
12025
-                    'change_message' => '订单生成',
12026
-                    'change_type' => 'create'
12027
-                ];
12028
-
12029
-                // 准备订单的
12030
-                $storeOrderProductDataList[] = [
12031
-                    'order_id' => $storeOrderEntity->getOrderId(),
12032
-                    'cart_id' => $storeOrderEntity->getCartId(),
12033
-                    'uid' => $storeOrderEntity->getUid(),
12034
-                    'product_id' => $cartEntity->getProductId(),
12035
-                    'product_price' => $storeOrderEntity->getTotalPrice(),
12036
-                    // 一级佣金
12037
-                    'extension_one' => 0.00,
12038
-                    // 二级佣金
12039
-                    'extension_two' => 0.00,
12040
-                    'product_sku' => $cartEntity->getProductAttrUnique(),
12041
-                    'product_num' => $cartEntity->getCartNum(),
12042
-                    'refund_num' => $cartEntity->getCartNum(),
12043
-                    'type' => $storeProductEntityMap[$cartEntity->getProductId()]->getType(),
12044
-                    'cart_info' => json_encode([
12045
-                        'product' => $storeProductEntityMap[$cartEntity->getProductId()]->toUnderlineArray(),
12046
-                        'productAttr' => $storeProductAttrValueEntityMap[$cartEntity->getProductAttrUnique()]->toUnderlineArray(),
12047
-                        'product_type' => $cartEntity->getProductType()
12048
-                    ])
12049
-                ];
12050
-            }
12051
-
12052
-            // 4.6 订单操作记录表
12053
-            /** @var StoreOrderStatusRepository $storeOrderStatusRepository */
12054
-            $storeOrderStatusRepository = app()->make(StoreOrderStatusRepository::class);
12055
-            $storeOrderStatusRepository->insertAll($storeOrderStatusDataList);
12056
-
12057
-            // 4.7 订单购物详情表
12058
-            /** @var StoreOrderProductRepository $storeOrderProductRepository */
12059
-            $storeOrderProductRepository = app()->make(StoreOrderProductRepository::class);
12060
-            $storeOrderProductRepository->insertAll($storeOrderProductDataList);
12061
-
12062
-            // 4.8 支付成功后 发放奖励
12063
-            // 非现金 支付成功后 直接结算
12064
-            if ($paySuccess) {
12065
-                // 修改订单的 支付状态
12066
-                $storeGroupOrderRepository->paySuccess($storeGroupOrderEntity->getGroupOrderId());
12067
-
12068
-                $this->updates($storeOrderIdList, [
12069
-                    'paid' => StoreOrderEnum::PAID['YES']['code'],
12070
-                    'pay_time' => date('Y-m-d H:i:s'),
12071
-                    'status' => StoreOrderEnum::STATUS['WAITING_SHIPMENT']['code'],
12072
-                    'distribution_mode' => StoreOrderEnum::DISTRIBUTION_MODE['ExpressDelivery']['code']
12073
-                ]);
12074
-                $settlementOrderIdList = [];
12075
-                foreach ($storeOrderEntityList as $storeOrderEntity) {
12076
-                    // 生成奖励数据
12077
-                    $this->createRewardMechanismByStoreOrderId($storeOrderEntity->getOrderId());
12078
-
12079
-                    if ($storeOrderEntity->getMerId() == CommonEnum::DESIGN_MERCHANT_ID['MemberZone']['code']) {
12080
-                        // 会员专区的 订单立即结算
12081
-                        $settlementOrderIdList[] = $storeOrderEntity->getOrderId();
12082
-                    }
12083
-                }
12084
-                if (!empty($settlementOrderIdList)) {
12085
-                    $this->settlementOrderByOrderIdList($settlementOrderIdList);
12086
-                }
12087
-            }
12088
-
12089
-            Db::commit();
12090
-        } catch (DbException $e) {
12091
-            Db::rollback();
12092
-        }
12093
-        return ['order_id' => $storeGroupOrderEntity->getGroupOrderId(), 'groupOrder' => $storeGroupOrderEntity->toArray()];
12094
-
12095
-    }
12096
-
12097
-    /**
12098
-     * 验证订单 信息是否 合规
12099
-     * @param StoreOrderCreateRequestEntity $storeOrderCreateRequestEntity
12100
-     * @return array
12101
-     */
12102
-    public function verifyRequestInformation(StoreOrderCreateRequestEntity $storeOrderCreateRequestEntity): array
12103
-    {
12104
-        // 3、验证
12105
-        /** 验证 用户信息 */
12106
-        /** @var UserRepository $userRepository */
12107
-        $userRepository = app()->make(UserRepository::class);
12108
-        $userEntity = $userRepository->getUserEntityByUid($storeOrderCreateRequestEntity->getUid());
12109
-        if (empty($userEntity->getUid())) {
12110
-            throw new ValidateException('获取当前用户信息失败');
12111
-        }
12112
-
12113
-        /** 验证 收货地址 */
12114
-        /** @var UserAddressRepository $userAddressRepository */
12115
-        $userAddressRepository = app()->make(UserAddressRepository::class);
12116
-        $addressEntity = $userAddressRepository->getAddressEntityByAddressId($storeOrderCreateRequestEntity->getAddressId());
12117
-        if (empty($addressEntity->getAddressId()) || $addressEntity->getUid() != $storeOrderCreateRequestEntity->getUid()) {
12118
-            throw new ValidateException('请选择正确的收货地址');
12119
-        }
12120
-        if (empty($addressEntity->getCodeList())) {
12121
-            throw new ValidateException('地址需要选择4级地址!请修改地址!');
12122
-        }
12123
-
12124
-        /** 验证分享信息 分享 */
12125
-        /** @var ShareEntity $shareEntity */
12126
-        $shareEntity = ShareEntity::newInstance();
12127
-        if (!empty($storeOrderCreateRequestEntity->getShareId())) {
12128
-            /** @var ShareRepository $shareRepository */
12129
-            $shareRepository = app()->make(ShareRepository::class);
12130
-            $shareEntity = $shareRepository->getShareEntityByShareId($storeOrderCreateRequestEntity->getShareId());
12131
-            if (empty($shareEntity->getId())) {
12132
-                throw new ValidateException('无效的分享信息');
12133
-            }
12134
-        }
12135
-
12136
-        /** 验证 购物车信息 */
12137
-        // 目前购物车只能添加一件商品,据了解之前 写的购物车,添加多件商品组合支付时计算的 金额和 VR 积分之类的会有问题
12138
-        /** @var StoreCartRepository $storeCartRepository */
12139
-        $storeCartRepository = app()->make(StoreCartRepository::class);
12140
-        $cartEntityList = $storeCartRepository->getCartEntityListByCartIdList($storeOrderCreateRequestEntity->getCartIdList());
12141
-        if (empty($cartEntityList) || count($storeOrderCreateRequestEntity->getCartIdList()) != count($cartEntityList)) {
12142
-            throw new ValidateException('未查询到购物车信息');
12143
-        }
12144
-
12145
-        $merchantIdList = [];
12146
-        $productIdList = [];
12147
-        $productAttrUniqueList = [];
12148
-        foreach ($cartEntityList as $cartEntity) {
12149
-            if (empty($cartEntity->getMerId())) {
12150
-                throw new ValidateException('商户不存在');
12151
-            }
12152
-            if (empty($cartEntity->getProductId())) {
12153
-                throw new ValidateException('商品已下架');
12154
-            }
12155
-            if (empty($cartEntity->getProductAttrUnique())) {
12156
-                throw new ValidateException('商品已下架');
12157
-            }
12158
-            $merchantIdList[] = $cartEntity->getMerId();
12159
-            $productIdList[] = $cartEntity->getProductId();
12160
-            $productAttrUniqueList[] = $cartEntity->getProductAttrUnique();
12161
-        }
12162
-        $merchantIdList = array_unique($merchantIdList);
12163
-        $productIdList = array_unique($productIdList);
12164
-        $productAttrUniqueList = array_unique($productAttrUniqueList);
12165
-
12166
-
12167
-        // 商户
12168
-        /** @var MerchantRepository $merchantRepository */
12169
-        $merchantRepository = app()->make(MerchantRepository::class);
12170
-        $merchantEntityList = $merchantRepository->getMerchantEntityListByMerchantIdList($merchantIdList);
12171
-        if(count($merchantIdList) != count($merchantEntityList)) {
12172
-            throw new ValidateException('未查询到商户信息');
12173
-        }
12174
-        // 商户信息 MAP
12175
-        /** @var MerchantEntity[] $merchantEntityMap 商户信息 MAP */
12176
-        $merchantEntityMap = array_column($merchantEntityList, null, 'merId');
12177
-
12178
-        // 商品
12179
-        /** @var ProductRepository $storeProductRepository */
12180
-        $storeProductRepository = app()->make(ProductRepository::class);
12181
-        $storeProductEntityList = $storeProductRepository->getStoreProductEntityListByProductIdList($productIdList);
12182
-        if(count($productIdList) != count($storeProductEntityList)) {
12183
-            throw new ValidateException('未查询到商品信息');
12184
-        }
12185
-        // 商品信息 MAP
12186
-        /** @var StoreProductEntity[] $storeProductEntityMap */
12187
-        $storeProductEntityMap = array_column($storeProductEntityList, null, 'productId');
12188
-
12189
-        // 商品属性
12190
-        /** @var ProductAttrValueRepository $storeProductAttrValueRepository */
12191
-        $storeProductAttrValueRepository = app()->make(ProductAttrValueRepository::class);
12192
-        $storeProductAttrValueEntityList = $storeProductAttrValueRepository->getStoreProductAttrValueEntityListByUniqueList($productAttrUniqueList);
12193
-        if(count($productAttrUniqueList) != count($storeProductAttrValueEntityList)) {
12194
-            throw new ValidateException('未查询到商品属性信息');
12195
-        }
12196
-        // 商品属性信息 MAP
12197
-        /** @var StoreProductAttrValueEntity[] $storeProductAttrValueEntityMap */
12198
-        $storeProductAttrValueEntityMap = array_column($storeProductAttrValueEntityList, null, 'unique');
12199
-
12200
-
12201
-        // 确认购物车内 微唯宝 的商品 是否满足发货
12202
-        foreach ($cartEntityList as $cartEntity) {
12203
-            // 验证用户
12204
-            if ($cartEntity->getUid() != $userEntity->getUid()) {
12205
-                throw new ValidateException('获取购物车内容失败');
12206
-            }
12207
-
12208
-            // 验证商户
12209
-            if (empty($merchantEntityMap[$cartEntity->getMerId()])) {
12210
-                throw new ValidateException('未查询到商户信息');
12211
-            }
12212
-
12213
-            // 获取购物车商品信息
12214
-            if (empty($storeProductEntityMap[$cartEntity->getProductId()])) {
12215
-                throw new ValidateException('未查询到商品信息');
12216
-            }
12217
-            $productEntity = $storeProductEntityMap[$cartEntity->getProductId()];
12218
-
12219
-            if ($productEntity->getMerId() != $cartEntity->getMerId()) {
12220
-                throw new ValidateException('商家已下架该产品');
12221
-            }
12222
-
12223
-            if (empty($storeProductAttrValueEntityMap[$cartEntity->getProductAttrUnique()])) {
12224
-                throw new ValidateException('未查询到商品属性信息');
12225
-            }
12226
-            $productAttrValueEntity = $storeProductAttrValueEntityMap[$cartEntity->getProductAttrUnique()];
12227
-
12228
-            // 判断订单是否已失效
12229
-            if ($cartEntity->getIsFail() == CartEnum::IS_FAIL['Yes']['code']) {
12230
-                throw new ValidateException($productEntity->getStoreName() . ' 已失效');
12231
-            }
12232
-            // 判断订单是否已失效
12233
-            if ($cartEntity->getIsPay() == CartEnum::IS_PAY['Yes']['code']) {
12234
-                throw new ValidateException($productEntity->getStoreName() . ' 已下单');
12235
-            }
12236
-
12237
-            // 如果商品类型是 普通商品 ,则判断库存是否充足
12238
-            if ($cartEntity->getProductType() == CartEnum::PRODUCT_TYPE['Ordinary']['code']) {
12239
-                if ($productAttrValueEntity->getStock() < $cartEntity->getCartNum()) {
12240
-                    throw new ValidateException($productEntity->getStoreName() . ' 库存不足--' . $cartEntity->getCartNum());
12241
-                }
12242
-            } else {
12243
-                // 如果是秒杀商品 应该首先判断是否还在活动期间内(rrx_store_seckill_active 商户设置秒杀商品关联表)
12244
-                // 商户设置秒杀商品关联表
12245
-                /** @var StoreSeckillActiveRepository $storeSeckillActiveRepository */
12246
-                $storeSeckillActiveRepository = app()->make(StoreSeckillActiveRepository::class);
12247
-                $seckillActiveEntity = $storeSeckillActiveRepository->getSeckillActiveEntityByProductIdInActive($cartEntity->getProductId());
12248
-                if (empty($seckillActiveEntity->getSeckillActiveId())) {
12249
-                    throw new ValidateException($productEntity->getStoreName() . ' 秒杀活动已失效');
12250
-                }
12251
-
12252
-                // 如果不是普通商品 则是否秒杀产品,如果是秒杀产品则判断是否超卖
12253
-                if (!$this->getDayPayCount($cartEntity->getUid(), $cartEntity->getProductId()) || !$this->getPayCount($cartEntity->getUid(), $cartEntity->getProductId())) {
12254
-                    throw new ValidateException($productEntity->getStoreName() . ' 已超出购买限制');
12255
-                }
12256
-            }
12257
-
12258
-            // 检查库存 查看 此商品已下架 此商品规格无货 此商品不支持该地区
12259
-            // (按照代码中所写的逻辑来推理:从微唯宝拉取过来,从而上架到商品表的商品,都有SPUId,所以去走微唯宝提供的接口验证,而会员专区和商贸区的商品可能是商户自己加的,没有SPUId,所以也就不用走微唯宝的验证)
12260
-            $checkGong = $storeProductAttrValueRepository->checkGong($cartEntity->getProductId(), $cartEntity->getProductAttrUnique(), $cartEntity->getCartNum(), $storeOrderCreateRequestEntity->getUid(), $storeOrderCreateRequestEntity->getAddressId());
12261
-            if (isset($checkGong['code']) && $checkGong['code'] == -1) {
12262
-                throw new ValidateException($checkGong['message']);
12263
-            }
12264
-        }
12265
-
12266
-        return [
12267
-            'userEntity' => $userEntity,
12268
-            'cartEntityList' => $cartEntityList,
12269
-            'addressEntity' => $addressEntity,
12270
-            'shareEntity' => $shareEntity,
12271
-            'merchantEntityMap' => $merchantEntityMap,
12272
-            'storeProductEntityMap' => $storeProductEntityMap,
12273
-            'storeProductAttrValueEntityMap' => $storeProductAttrValueEntityMap,
12274
-        ];
12275
-    }
12276
-
12277
-    /**
12278 11809
      * 根据 商品属性 唯一值、城市ID、数量 计算运费
12279 11810
      * @param CalculatePostageRequestEntity $calculatePostageRequestEntity
12280 11811
      * @return float|int|mixed|string
@@ -12412,4 +11943,213 @@ class StoreOrderRepository extends BaseRepository
12412 11943
 
12413 11944
         return $postage;
12414 11945
     }
11946
+
11947
+    /**
11948
+     * 关闭订单 取消订单 不要使用事务,调用的地方去使用事务
11949
+     * @param StoreOrderEntity $storeOrderEntity
11950
+     * @param $uid
11951
+     * @param string $changeMessage
11952
+     * @param string $remark
11953
+     * @return void
11954
+     */
11955
+    public function closeStoreOrder(StoreOrderEntity $storeOrderEntity, $uid = null, string $changeMessage = '', string $remark = '')
11956
+    {
11957
+        try {
11958
+            // 1、更改订单状态
11959
+            $storeOrderEntity->setStatus(StoreOrderEnum::STATUS['CANCELLED']['code']);
11960
+            $this->update($storeOrderEntity->getOrderId(), $storeOrderEntity->toUnderlineArray());
11961
+
11962
+            // 2、订单操作记录表
11963
+            /** @var StoreOrderStatusRepository $storeOrderStatusRepository */
11964
+            $storeOrderStatusRepository = app()->make(StoreOrderStatusRepository::class);
11965
+            $storeOrderStatusRepository->create([
11966
+                'order_id' => $storeOrderEntity->getOrderId(),
11967
+                'change_message' => $uid === 0 ? ('取消原因:' . $changeMessage . "[商家操作]\n 商家备注:" . ($remark ?: '')) : ($changeMessage ?: '取消订单' . ($uid ? '' : '[自动]')),
11968
+                'change_type' => 'cancel'
11969
+            ]);
11970
+
11971
+            // 3、获取用户信息
11972
+            /** @var UserRepository $userRepository */
11973
+            $userRepository = app()->make(UserRepository::class);
11974
+            $userEntity = $userRepository->getUserEntityByUid($storeOrderEntity->getUid());
11975
+
11976
+            // 4、组装支付数据
11977
+            /** @var FzonePayTypeEntity $fzonePayTypeEntity */
11978
+            $fzonePayTypeEntity = FzonePayTypeEntity::newInstance(json_decode($storeOrderEntity->getFzonePayType(), true));
11979
+
11980
+            // 5、撤回订单扣除的数据项
11981
+            $this->cancellation($userEntity, $storeOrderEntity, $fzonePayTypeEntity);
11982
+        } catch (DbException $e) {
11983
+            throw new ValidateException('支付失败,支付方式错误!');
11984
+        }
11985
+    }
11986
+
11987
+    /**
11988
+     * 根据 用户信息 订单信息 支付信息 返还下单时 扣减 的数据
11989
+     * @param UserEntity $userEntity
11990
+     * @param StoreOrderEntity $storeOrderEntity
11991
+     * @param FzonePayTypeEntity $fzonePayTypeEntity
11992
+     * @return bool
11993
+     */
11994
+    public function cancellation(UserEntity $userEntity, StoreOrderEntity $storeOrderEntity, FzonePayTypeEntity $fzonePayTypeEntity): bool
11995
+    {
11996
+        if (empty($userEntity->getUid())) {
11997
+            throw new ValidateException('未查询到用户信息');
11998
+        }
11999
+
12000
+        if (empty($storeOrderEntity->getOrderId())) {
12001
+            throw new ValidateException('未查询到订单信息');
12002
+        }
12003
+
12004
+        /** @var UserSignVrRepository $userSignVrRepository */
12005
+        $userSignVrRepository = app()->make(UserSignVrRepository::class);
12006
+        /** @var UserSignScoreRepository $userSignScoreRepository */
12007
+        $userSignScoreRepository = app()->make(UserSignScoreRepository::class);
12008
+        /** @var UserSignJingdouRepository $userSignJingdouRepository */
12009
+        $userSignJingdouRepository = app()->make(UserSignJingdouRepository::class);
12010
+        /** @var UserSignFugouRepository $userSignFugouRepository */
12011
+        $userSignFugouRepository = app()->make(UserSignFugouRepository::class);
12012
+
12013
+        $paySuccess = false;
12014
+        // 验证支付方式
12015
+        if ($fzonePayTypeEntity->getType() == StoreOrderEnum::FZONE_PAY_TYPE['B1-VR+Score']['code']) {
12016
+            // 创建Vr 增加记录 先有记录 再去执行
12017
+            $userSignVrEntity = $userSignVrRepository->addUserSingVr(
12018
+                $userEntity->getUid(),
12019
+                UserSignVrEnum::TYPE['Exchange']['code'],
12020
+                $fzonePayTypeEntity->getPrice(),
12021
+                '订单取消,订单编号:' . $storeOrderEntity->getOrderSn(),
12022
+                UserSignVrEnum::ORDER_TYPE['Platform']['code'],
12023
+                $storeOrderEntity->getOrderId()
12024
+            );
12025
+            // 执行 Vr 增减 操作
12026
+            $userSignVrRepository->execute($userSignVrEntity->getId());
12027
+            // 修改用户积分 先有记录 再去执行
12028
+            $userSignScoreEntity = $userSignScoreRepository->addUserSingScore(
12029
+                $userEntity->getUid(),
12030
+                UserSignScoreEnum::SOURCE_TYPE['BuyProduct']['code'],
12031
+                UserSignScoreEnum::PM['Income']['code'],
12032
+                $fzonePayTypeEntity->getOther(),
12033
+                '订单取消,订单编号:' . $storeOrderEntity->getOrderSn(),
12034
+                UserSignScoreEnum::ORDER_TYPE['Platform']['code'],
12035
+                $storeOrderEntity->getOrderId()
12036
+            );
12037
+            $userSignScoreRepository->execute($userSignScoreEntity->getId());
12038
+
12039
+            $paySuccess = true;
12040
+        } else if ($fzonePayTypeEntity->getType() == StoreOrderEnum::FZONE_PAY_TYPE['B2-Cash+Score']['code']) {
12041
+            // 修改用户积分 先有记录 再去执行
12042
+            $userSignScoreEntity = $userSignScoreRepository->addUserSingScore(
12043
+                $userEntity->getUid(),
12044
+                UserSignScoreEnum::SOURCE_TYPE['BuyProduct']['code'],
12045
+                UserSignScoreEnum::PM['Income']['code'],
12046
+                $fzonePayTypeEntity->getOther(),
12047
+                '订单取消,订单编号:' . $storeOrderEntity->getOrderSn(),
12048
+                UserSignScoreEnum::ORDER_TYPE['Platform']['code'],
12049
+                $storeOrderEntity->getOrderId()
12050
+            );
12051
+            $userSignScoreRepository->execute($userSignScoreEntity->getId());
12052
+
12053
+        } else if ($fzonePayTypeEntity->getType() == StoreOrderEnum::FZONE_PAY_TYPE['B3-VR+Jingdou']['code']) {
12054
+            // 创建Vr增加记录 先有记录 再去执行
12055
+            $userSignVrEntity = $userSignVrRepository->addUserSingVr(
12056
+                $userEntity->getUid(),
12057
+                UserSignVrEnum::TYPE['Exchange']['code'],
12058
+                $fzonePayTypeEntity->getPrice(),
12059
+                '订单取消,订单编号:' . $storeOrderEntity->getOrderSn(),
12060
+                UserSignVrEnum::ORDER_TYPE['Platform']['code'],
12061
+                $storeOrderEntity->getOrderId()
12062
+            );
12063
+            // 执行 Vr 增减 操作
12064
+            $userSignVrRepository->execute($userSignVrEntity->getId());
12065
+
12066
+            // 创建 京豆 增加记录
12067
+            $userSignJingdouEntity = $userSignJingdouRepository->addUserSingJingdou(
12068
+                $userEntity->getUid(),
12069
+                UserSignJingdouEnum::TYPE['Gift']['code'],
12070
+                $fzonePayTypeEntity->getOther(),
12071
+                0,
12072
+                '订单取消,订单编号:' . $storeOrderEntity->getOrderSn(),
12073
+                CommonEnum::ORDER_TYPE['Platform']['code'],
12074
+                $storeOrderEntity->getOrderId()
12075
+            );
12076
+            // 执行 京豆 增减 操作
12077
+            $userSignJingdouRepository->execute($userSignJingdouEntity->getId());
12078
+
12079
+            $paySuccess = true;
12080
+        } else if ($fzonePayTypeEntity->getType() == StoreOrderEnum::FZONE_PAY_TYPE['B4-Cash+Jingdou']['code']) {
12081
+            // 创建 京豆 增加记录
12082
+            $userSignJingdouEntity = $userSignJingdouRepository->addUserSingJingdou(
12083
+                $userEntity->getUid(),
12084
+                UserSignJingdouEnum::TYPE['Gift']['code'],
12085
+                $fzonePayTypeEntity->getOther(),
12086
+                0,
12087
+                '订单取消,订单编号:' . $storeOrderEntity->getOrderSn(),
12088
+                CommonEnum::ORDER_TYPE['Platform']['code'],
12089
+                $storeOrderEntity->getOrderId()
12090
+            );
12091
+            // 执行 京豆 增减 操作
12092
+            $userSignJingdouRepository->execute($userSignJingdouEntity->getId());
12093
+
12094
+        } else if ($fzonePayTypeEntity->getType() == StoreOrderEnum::FZONE_PAY_TYPE['B5-VR']['code']) {
12095
+            // 创建Vr增加记录 先有记录 再去执行
12096
+            $userSignVrEntity = $userSignVrRepository->addUserSingVr(
12097
+                $userEntity->getUid(),
12098
+                UserSignVrEnum::TYPE['Exchange']['code'],
12099
+                $fzonePayTypeEntity->getPrice(),
12100
+                '订单取消,订单编号:' . $storeOrderEntity->getOrderSn(),
12101
+                CommonEnum::ORDER_TYPE['Platform']['code'],
12102
+                $storeOrderEntity->getOrderId()
12103
+            );
12104
+            // 执行 Vr 增减 操作
12105
+            $userSignVrRepository->execute($userSignVrEntity->getId());
12106
+            $paySuccess = true;
12107
+        } else if ($fzonePayTypeEntity->getType() == StoreOrderEnum::FZONE_PAY_TYPE['B6-Cash']['code']) {
12108
+
12109
+        } else if ($fzonePayTypeEntity->getType() == StoreOrderEnum::FZONE_PAY_TYPE['A1-VR']['code']) {
12110
+            // 创建Vr增加记录 先有记录 再去执行
12111
+            $userSignVrEntity = $userSignVrRepository->addUserSingVr(
12112
+                $userEntity->getUid(),
12113
+                UserSignVrEnum::TYPE['Exchange']['code'],
12114
+                $fzonePayTypeEntity->getPrice(),
12115
+                '订单取消,订单编号:' . $storeOrderEntity->getOrderSn(),
12116
+                CommonEnum::ORDER_TYPE['Platform']['code'],
12117
+                $storeOrderEntity->getOrderId()
12118
+            );
12119
+            // 执行 Vr 增减 操作
12120
+            $userSignVrRepository->execute($userSignVrEntity->getId());
12121
+            $paySuccess = true;
12122
+        } else if ($fzonePayTypeEntity->getType() == StoreOrderEnum::FZONE_PAY_TYPE['A2-Cash']['code']) {
12123
+
12124
+        } else if ($fzonePayTypeEntity->getType() == StoreOrderEnum::FZONE_PAY_TYPE['A3-Cash+VR']['code']) {
12125
+            // 创建Vr增加记录 先有记录 再去执行
12126
+            $userSignVrEntity = $userSignVrRepository->addUserSingVr(
12127
+                $userEntity->getUid(),
12128
+                UserSignVrEnum::TYPE['Exchange']['code'],
12129
+                $fzonePayTypeEntity->getPrice(),
12130
+                '订单取消,订单编号:' . $storeOrderEntity->getOrderSn(),
12131
+                CommonEnum::ORDER_TYPE['Platform']['code'],
12132
+                $storeOrderEntity->getOrderId()
12133
+            );
12134
+            // 执行 Vr 增减 操作
12135
+            $userSignVrRepository->execute($userSignVrEntity->getId());
12136
+        } else if ($fzonePayTypeEntity->getType() == StoreOrderEnum::FZONE_PAY_TYPE['C1-Fugou']['code']) {
12137
+            // 添加复购金 记录
12138
+            $userSignFugouEntity = $userSignFugouRepository->addUserSingFugou(
12139
+                $userEntity->getUid(),
12140
+                UserSignFugouEnum::TYPE['Give']['code'],
12141
+                $fzonePayTypeEntity->getPrice(),
12142
+                UserSignFugouEnum::COMMISSION_TYPE['DIRECT_REFERRAL']['code'],
12143
+                '订单取消,订单编号:' . $storeOrderEntity->getOrderSn(),
12144
+                CommonEnum::ORDER_TYPE['Platform']['code'],
12145
+                $storeOrderEntity->getOrderId()
12146
+            );
12147
+            // 执行
12148
+            $userSignFugouRepository->execute($userSignFugouEntity->getId());
12149
+            $paySuccess = true;
12150
+        } else {
12151
+            throw new ValidateException('支付失败,支付方式错误!');
12152
+        }
12153
+        return $paySuccess;
12154
+    }
12415 12155
 }

+ 33 - 0
app/common/repositories/store/order/StoreOrderStatusRepository.php

@@ -13,6 +13,7 @@ namespace app\common\repositories\store\order;
13 13
 
14 14
 use app\common\dao\store\order\StoreOrderStatusDao;
15 15
 use app\common\repositories\BaseRepository;
16
+use app\entity\data\store\StoreOrderStatusEntity;
16 17
 
17 18
 /**
18 19
  * Class StoreOrderStatusRepository
@@ -52,4 +53,36 @@ class StoreOrderStatusRepository extends BaseRepository
52 53
         $list = $query->page($page, $limit)->select();
53 54
         return compact('count','list');
54 55
     }
56
+
57
+    public function create($data)
58
+    {
59
+        return $this->dao->create($data);
60
+    }
61
+
62
+    /**
63
+     * 写入订单状态记录
64
+     * @param StoreOrderStatusEntity $storeOrderEntity
65
+     * @return StoreOrderStatusEntity
66
+     */
67
+    public function createByEntity(StoreOrderStatusEntity $storeOrderEntity): StoreOrderStatusEntity
68
+    {
69
+        $result = $this->create($storeOrderEntity->toUnderlineArray())->toArray();
70
+        /** @var StoreOrderStatusEntity $entity */
71
+        $entity = StoreOrderStatusEntity::newInstance($result);
72
+        return $entity;
73
+    }
74
+
75
+    /**
76
+     * 批量写入订单状态记录
77
+     * @param StoreOrderStatusEntity[] $storeOrderEntityList
78
+     * @return int
79
+     */
80
+    public function createByEntityList(array $storeOrderEntityList): int
81
+    {
82
+        $storeOrderDataList = [];
83
+        foreach ($storeOrderEntityList as $storeOrderEntity) {
84
+            $storeOrderDataList[] = $storeOrderEntity->toUnderlineArray();
85
+        }
86
+        return $this->insertAll($storeOrderDataList);
87
+    }
55 88
 }

+ 83 - 7
app/controller/api/Notify.php

@@ -2,8 +2,10 @@
2 2
 namespace app\controller\api;
3 3
 
4 4
 use AdaPaySdk\AdapayTools;
5
+use app\common\enum\store\StoreGroupOrderEnum;
5 6
 use app\common\repositories\merchant\order\OrderMerchantRepository;
6 7
 use app\common\repositories\movie\MovieRepository;
8
+use app\common\repositories\store\order\StoreGroupOrderRepository;
7 9
 use app\common\repositories\store\order\StoreOrderRepository;
8 10
 use app\common\repositories\store\order\StoreRefundOrderRepository;
9 11
 use app\common\repositories\system\merchant\MerchantRepository;
@@ -125,8 +127,84 @@ class Notify
125 127
                             }
126 128
                             break;
127 129
                         case 'pay':
128
-                            //商城集合订单
129
-                            Db::name('store_group_order') -> where('group_order_sn',$requestId[0]) -> update(['rand'=>$requestId[1]]);
130
+                            /** ************** 定义参数 ************** */
131
+                            // 订单编号
132
+                            $groupOrderSn_Rand = $post_data_str['order_no'];
133
+                            // 订单号
134
+                            $groupOrderSn = $requestId[0];
135
+                            // 随机值
136
+                            $rand = $requestId[1];
137
+                            // 支付人ID
138
+                            $payOpenId = $post_data_str['expend']['open_id'];
139
+                            // 支付撤销方法
140
+                            $paymentReverseFunc = function ($payWX, $payType, $groupOrderSn_Rand, $paymentId, $appId, $orderNo, $reverseAmt, $notifyUrl = '') {
141
+                                if ($payWX == StoreGroupOrderEnum::PAY_WX['TDYL']['code']) {
142
+                                    $key = 'api_live_b0a687ec-5450-4ada-a0e4-65bac0f46871';
143
+                                } else {
144
+                                    $key = 'api_live_90ef02e4-54ac-41ee-adf1-e4927d23d58f';
145
+                                }
146
+                                $refundTraits = [
147
+                                    'payment_id' => $paymentId,
148
+                                    'app_id' => $appId,
149
+                                    'order_no' => $orderNo,
150
+                                    'reverse_amt' => $reverseAmt,
151
+                                    'notify_url' => $notifyUrl ?: env('APP_URL') . "/api/hf_notify/reverse_order",
152
+                                ];
153
+                                $hfRefundRes = app()->make(StoreRefundOrderRepository::class)->payment_Reverse($refundTraits, $payType == '1' ? 2 : 1, $payWX, $key);
154
+                                Db::name("log")
155
+                                    ->insert([
156
+                                        'data' => '【订单支付回调】【03】:时间:' . date('Y-m-d H:i:s', time()) . ';订单编号:' . $groupOrderSn_Rand . ';汇付支付撤销请求参数:' . json_encode($refundTraits) . ';汇付支付撤销返回结果:' . json_encode($hfRefundRes)
157
+                                    ]);
158
+                            };
159
+                            /** *************** 定义结束 *************** */
160
+
161
+                            /** 逻辑开始 */
162
+                            // 1、获取订单数据
163
+                            /** @var StoreGroupOrderRepository $storeGroupOrderRepository */
164
+                            $storeGroupOrderRepository = app()->make(StoreGroupOrderRepository::class);
165
+                            // 获取订单组数据
166
+                            $storeGroupOrderEntity = $storeGroupOrderRepository->getStoreGroupOrderEntityByGroupOrderSn($groupOrderSn);
167
+                            if (empty($storeGroupOrderEntity->getGroupOrderId())) {
168
+                                Db::name("log")
169
+                                    ->insert([
170
+                                        'data' => '【订单支付回调】【01】:时间:' . date('Y-m-d H:i:s', time()) . ';订单编号:' . $groupOrderSn_Rand . ';订单组查询失败'
171
+                                    ]);
172
+                                break;
173
+                            }
174
+                            /** @var StoreOrderRepository $storeOrderRepository */
175
+                            $storeOrderRepository = app()->make(StoreOrderRepository::class);
176
+                            // 获取订单集合
177
+                            $storeOrderEntityList = $storeOrderRepository->getStoreOrderEntityListByGroupOrderId($storeGroupOrderEntity->getGroupOrderId());
178
+                            if (empty($storeOrderEntityList)) {
179
+                                Db::name("log")
180
+                                    ->insert([
181
+                                        'data' => '【订单支付回调】【02】:时间:' . date('Y-m-d H:i:s', time()) . ';订单编号:' . $groupOrderSn_Rand . ';订单集合查询失败'
182
+                                    ]);
183
+                                break;
184
+                            }
185
+
186
+                            // 2、判断订单是否已经被代付 如果已记录支付人 并且不是自己,则可能有人代付,则将本次的支付撤回
187
+                            foreach ($storeOrderEntityList as $storeOrderEntity) {
188
+                                if (!empty($storeOrderEntity->getPayOpenId())) {
189
+                                    if ($storeOrderEntity->getPayOpenId() != $payOpenId) {
190
+                                        // 如果已经被用户支付 撤回支付
191
+                                        $orderNo = app()->make(StoreRefundOrderRepository::class)->getNewOrderId();
192
+                                        $paymentReverseFunc($storeGroupOrderEntity->getPayWx(), $pay_type, $groupOrderSn_Rand, $post_data_str['id'], $post['app_id'], $orderNo, $post_data_str['pay_amt']);
193
+                                        break 2;
194
+                                    }
195
+                                } else {
196
+                                    $storeOrderEntity->setPayOpenId($payOpenId);
197
+                                }
198
+                            }
199
+                            // 如果已支付 不做后续处理
200
+                            if ($storeGroupOrderEntity->getPaid() == StoreGroupOrderEnum::PAID['YES']['code']) {
201
+                                break;
202
+                            }
203
+
204
+                            // 3、支付成功 处理逻辑
205
+                            $storeGroupOrderRepository->storeGroupOrderPaySuccess($storeGroupOrderEntity->getGroupOrderId());
206
+
207
+/*
130 208
                             // 判断代付是否支付过
131 209
                             $group_order = Db::name('store_group_order')->where('group_order_sn', $requestId[0])->find();
132 210
                             $group_order_id = $group_order['group_order_id']??'';
@@ -356,7 +434,7 @@ class Notify
356 434
                                 Db::name('store_order')->where('group_order_id', $group_order_id)->update(['is_settlement' => 1]);
357 435
 
358 436
                                 $this->bill_user_log($user_data['uid'],round($pv * 0.035,2),$store_order_data['order_id'],5,$store_order_data['order_sn'],'消费获得养老金'.round($pv * 0.035,2),$store_order_data['mer_id']);
359
- 
437
+
360 438
                                 $this->con_log_pv($user_data['uid'],$gx_jf,$store_order_data['order_id'],0,"购买会员专区商品赠送pv",1);
361 439
                                 // $this->con_log($user_data['uid'],$gx_jf,$store_order_data['order_id'],11,"购买会员专区商品赠送贡献值",1);
362 440
                                 $this->con_log($user_data['uid'],$gx_jf,$store_order_data['order_id'],0,"购买会员专区商品赠送贡献值",1);
@@ -378,7 +456,7 @@ class Notify
378 456
 
379 457
                                 //给推广者分配养老金
380 458
                                 //给推广者分配佣金(2.0系统中)
381
-                           
459
+
382 460
                                  // if ($user_data['spread_uid'] != 0) {
383 461
                                 // if ($user_data['uid'] > 611) {
384 462
 
@@ -660,7 +738,6 @@ class Notify
660 738
                             } else {
661 739
                                 $wenan = '商贸区';
662 740
                                 // 商贸区
663
-                                /** @var \app\common\repositories\merchant\MerchantRepository $merchant */
664 741
                                 $merchant = app()->make(MerchantRepository::class);
665 742
                                 $merchantInfo = $merchant->get($store_order_data['mer_id']);
666 743
                                 // 1企业2个体3个人
@@ -734,7 +811,6 @@ class Notify
734 811
 
735 812
                                     //京豆赠送
736 813
                                     if ($store_order_data['mer_id'] > 0) {
737
-                                        /** @var OrderMerchantRepository $orderMerchantRepository */
738 814
                                         $orderMerchantRepository = app()->make(OrderMerchantRepository::class);
739 815
                                         $jdAndGonxianConfig = $orderMerchantRepository->getMerchantContribution($store_product_attr_value['extension_one']);
740 816
                                         $merchant_data = Db::name('merchant')->where('mer_id', $store_order_data['mer_id'])->find();
@@ -883,7 +959,7 @@ class Notify
883 959
                             $orderss = Db::name('store_order')->where('group_order_id', $group_order_id)->update(['paid'=>1,'pay_time'=>date('Y-m-d H:i:s'),'pay_open_id' => $post_data_str['expend']['open_id']]);
884 960
 
885 961
                             Db::name('store_group_order')->where('group_order_id',$group_order_id)->update(['paid'=>1,'pay_time'=>date('Y-m-d H:i:s')]);
886
-
962
+*/
887 963
                             event('pay_success_order', ['order_sn' => $requestId[0],'pay_type'=>$pay_type]);
888 964
 
889 965
                             break;

Diff nebyl zobrazen, protože je příliš veliký
+ 1860 - 0
app/controller/api/NotifyCopy.php


+ 70 - 0
app/controller/api/store/order/StoreGroupOrder.php

@@ -0,0 +1,70 @@
1
+<?php
2
+
3
+namespace app\controller\api\store\order;
4
+
5
+use app\common\repositories\store\order\StoreGroupOrderRepository;
6
+use app\entity\request\api\store\order\StoreOrderCreateRequestEntity;
7
+use app\validate\api\store\order\StoreOrderCreateValidate;
8
+use crmeb\basic\BaseController;
9
+use think\App;
10
+use think\facade\Cache;
11
+
12
+class StoreGroupOrder extends BaseController
13
+{
14
+
15
+    /**
16
+     * @var StoreGroupOrderRepository
17
+     */
18
+    protected $repository;
19
+    // private $source;
20
+    // private $merId;
21
+
22
+    /**
23
+     * StoreOrder constructor.
24
+     * @param App $app
25
+     * @param StoreGroupOrderRepository $repository
26
+     */
27
+    public function __construct(App $app, StoreGroupOrderRepository $repository)
28
+    {
29
+        parent::__construct($app);
30
+        $this->repository = $repository;
31
+
32
+        // $this->source = request()->header('source');
33
+        // $this->merId = request()->header('merId');
34
+    }
35
+
36
+    /**
37
+     * @param StoreOrderCreateValidate $storeOrderCreateValidate
38
+     * @return mixed
39
+     */
40
+    public function createStoreGroupOrder(StoreOrderCreateValidate $storeOrderCreateValidate)
41
+    {
42
+        // 1、接收参数
43
+        $storeOrderCreateValidateResult = $storeOrderCreateValidate->validateRequest();
44
+        // 如果验证失败,返回错误
45
+        if ($storeOrderCreateValidateResult['status'] == 'error') {
46
+            return app('json')->fail($storeOrderCreateValidateResult['message']);
47
+        }
48
+
49
+        // 根据用户ID 获取用户实体信息
50
+        $uid = $this->request->uid();
51
+        // 验证通过,继续处理数据
52
+        /** @var StoreOrderCreateRequestEntity $storeOrderCreateRequestEntity */
53
+        $storeOrderCreateRequestEntity = $storeOrderCreateValidateResult['data'];
54
+        $storeOrderCreateRequestEntity->setUid($uid);
55
+
56
+        // 2、加锁
57
+        // 增加锁,防止同一用户重读点击
58
+        $redisHandler = Cache::store('redis')->handler();
59
+        $cartIdList = $storeOrderCreateRequestEntity->getCartIdList();
60
+        sort($cartIdList);
61
+        $isSet = $redisHandler->set('createStoreGroupOrder' . '-' . implode('-', $cartIdList), 1, ['nx', 'ex' => 30]);
62
+        if (!$isSet) {
63
+            return app('json')->fail('请勿重复下单');
64
+        }
65
+
66
+        // 3、创建订单
67
+        $result = $this->repository->createStoreGroupOrder($storeOrderCreateRequestEntity);
68
+        return app('json')->success('订单创建成功', $result);
69
+    }
70
+}

+ 0 - 42
app/controller/api/store/order/StoreOrder.php

@@ -11,17 +11,11 @@
11 11
 namespace app\controller\api\store\order;
12 12
 
13 13
 
14
-use app\common\enum\user\UserEnum;
15 14
 use app\common\model\store\order\StoreRefundOrder;
16
-use app\common\model\system\admin\Log;
17 15
 use app\common\repositories\merchant\MerchantRepository;
18
-use app\common\repositories\product\ShareRepository;
19 16
 use app\common\repositories\store\product\ProductAttrValueRepository;
20 17
 use app\common\repositories\user\UserAddressRepository;
21
-use app\common\repositories\user\UserRepository;
22
-use app\entity\data\user\UserEntity;
23 18
 use app\entity\request\api\store\order\CalculatePostageRequestEntity;
24
-use app\entity\request\api\store\order\StoreOrderCreateRequestEntity;
25 19
 use app\traits\ShouxinyiApiRequest;
26 20
 use app\validate\api\store\order\CalculatePostageValidate;
27 21
 use app\validate\api\store\order\StoreOrderCreateValidate;
@@ -31,9 +25,6 @@ use app\common\repositories\store\order\StoreGroupOrderRepository;
31 25
 use app\common\repositories\store\order\StoreOrderRepository;
32 26
 use crmeb\services\ExpressService;
33 27
 use think\App;
34
-use think\db\exception\DataNotFoundException;
35
-use think\db\exception\DbException;
36
-use think\db\exception\ModelNotFoundException;
37 28
 use think\facade\Cache;
38 29
 use think\facade\Db;
39 30
 use think\facade\Request;
@@ -717,40 +708,7 @@ class StoreOrder extends BaseController
717 708
         }
718 709
     }
719 710
 
720
-    /**
721
-     * @param StoreOrderCreateValidate $storeOrderCreateValidate
722
-     * @return mixed
723
-     */
724
-    public function createOrderNew(StoreOrderCreateValidate $storeOrderCreateValidate)
725
-    {
726
-        // 1、接收参数
727
-        $storeOrderCreateValidateResult = $storeOrderCreateValidate->validateRequest();
728
-        // 如果验证失败,返回错误
729
-        if ($storeOrderCreateValidateResult['status'] == 'error') {
730
-            return app('json')->fail($storeOrderCreateValidateResult['message']);
731
-        }
732 711
 
733
-        // 根据用户ID 获取用户实体信息
734
-        $uid = $this->request->uid();
735
-        // 验证通过,继续处理数据
736
-        /** @var StoreOrderCreateRequestEntity $storeOrderCreateRequestEntity */
737
-        $storeOrderCreateRequestEntity = $storeOrderCreateValidateResult['data'];
738
-        $storeOrderCreateRequestEntity->setUid($uid);
739
-
740
-        // 2、加锁
741
-        // 增加锁,防止同一用户重读点击
742
-        $redisHandler = Cache::store('redis')->handler();
743
-        $cartIdList = $storeOrderCreateRequestEntity->getCartIdList();
744
-        sort($cartIdList);
745
-        $isSet = $redisHandler->set('createOrder' . '-' . implode('-', $cartIdList), 1, ['nx', 'ex' => 30]);
746
-        if (!$isSet) {
747
-            return app('json')->fail('请勿重复下单');
748
-        }
749
-
750
-        // 3、创建订单
751
-        $result = $this->repository->createOrderNew2($storeOrderCreateRequestEntity);
752
-        return app('json')->success('订单创建成功', $result);
753
-    }
754 712
 
755 713
     /**
756 714
      *

+ 2 - 2
app/entity/CommonEntity.php

@@ -10,9 +10,9 @@ class CommonEntity
10 10
     /**
11 11
      * 将 参数 实例化到 实体
12 12
      * @param array $data
13
-     * @return CommonEntity
13
+     * @return static|self
14 14
      */
15
-    public static function newInstance(array $data = []): CommonEntity
15
+    public static function newInstance(array $data = []): self
16 16
     {
17 17
         if (empty($data)) {
18 18
             return new static();

+ 313 - 0
app/entity/data/store/StoreOrderProductEntity.php

@@ -0,0 +1,313 @@
1
+<?php
2
+
3
+namespace app\entity\data\store;
4
+
5
+use app\entity\data\DataEntity;
6
+
7
+class StoreOrderProductEntity extends DataEntity
8
+{
9
+    public $orderProductId = null;  // 订单产品 id
10
+    public $orderId = null;  // 订单id
11
+    public $uid = null;  // 用户 id
12
+    public $cartId = null;  // 购物车id
13
+    public $productId = null;  // 商品ID
14
+    public $extensionOne = null;  // 一级佣金
15
+    public $extensionTwo = null;  // 二级佣金
16
+    public $productSku = null;  // 商品 sku
17
+    public $isRefund = null;  // 是否退款
18
+    public $productNum = null;  // 购买数量
19
+    public $refundNum = null;  // 可申请退货数量
20
+    public $isReply = null;  // 是否评价
21
+    public $productPrice = null;  // 商品金额
22
+    public $cartInfo = null;  // 购买东西的详细信息
23
+    public $createTime = null;  // 创建时间
24
+    public $type = null;  // 类型
25
+
26
+    /**
27
+     * @return mixed
28
+     */
29
+    public function getOrderProductId()
30
+    {
31
+        return $this->orderProductId;
32
+    }
33
+
34
+    /**
35
+     * @param mixed $orderProductId
36
+     * @return StoreOrderProductEntity
37
+     */
38
+    public function setOrderProductId($orderProductId): StoreOrderProductEntity
39
+    {
40
+        $this->orderProductId = $orderProductId;
41
+        return $this;
42
+    }
43
+
44
+    /**
45
+     * @return mixed
46
+     */
47
+    public function getOrderId()
48
+    {
49
+        return $this->orderId;
50
+    }
51
+
52
+    /**
53
+     * @param mixed $orderId
54
+     * @return StoreOrderProductEntity
55
+     */
56
+    public function setOrderId($orderId): StoreOrderProductEntity
57
+    {
58
+        $this->orderId = $orderId;
59
+        return $this;
60
+    }
61
+
62
+    /**
63
+     * @return mixed
64
+     */
65
+    public function getUid()
66
+    {
67
+        return $this->uid;
68
+    }
69
+
70
+    /**
71
+     * @param mixed $uid
72
+     * @return StoreOrderProductEntity
73
+     */
74
+    public function setUid($uid): StoreOrderProductEntity
75
+    {
76
+        $this->uid = $uid;
77
+        return $this;
78
+    }
79
+
80
+    /**
81
+     * @return mixed
82
+     */
83
+    public function getCartId()
84
+    {
85
+        return $this->cartId;
86
+    }
87
+
88
+    /**
89
+     * @param mixed $cartId
90
+     * @return StoreOrderProductEntity
91
+     */
92
+    public function setCartId($cartId): StoreOrderProductEntity
93
+    {
94
+        $this->cartId = $cartId;
95
+        return $this;
96
+    }
97
+
98
+    /**
99
+     * @return mixed
100
+     */
101
+    public function getProductId()
102
+    {
103
+        return $this->productId;
104
+    }
105
+
106
+    /**
107
+     * @param mixed $productId
108
+     * @return StoreOrderProductEntity
109
+     */
110
+    public function setProductId($productId): StoreOrderProductEntity
111
+    {
112
+        $this->productId = $productId;
113
+        return $this;
114
+    }
115
+
116
+    /**
117
+     * @return mixed
118
+     */
119
+    public function getExtensionOne()
120
+    {
121
+        return $this->extensionOne;
122
+    }
123
+
124
+    /**
125
+     * @param mixed $extensionOne
126
+     * @return StoreOrderProductEntity
127
+     */
128
+    public function setExtensionOne($extensionOne): StoreOrderProductEntity
129
+    {
130
+        $this->extensionOne = $extensionOne;
131
+        return $this;
132
+    }
133
+
134
+    /**
135
+     * @return mixed
136
+     */
137
+    public function getExtensionTwo()
138
+    {
139
+        return $this->extensionTwo;
140
+    }
141
+
142
+    /**
143
+     * @param mixed $extensionTwo
144
+     * @return StoreOrderProductEntity
145
+     */
146
+    public function setExtensionTwo($extensionTwo): StoreOrderProductEntity
147
+    {
148
+        $this->extensionTwo = $extensionTwo;
149
+        return $this;
150
+    }
151
+
152
+    /**
153
+     * @return mixed
154
+     */
155
+    public function getProductSku()
156
+    {
157
+        return $this->productSku;
158
+    }
159
+
160
+    /**
161
+     * @param mixed $productSku
162
+     * @return StoreOrderProductEntity
163
+     */
164
+    public function setProductSku($productSku): StoreOrderProductEntity
165
+    {
166
+        $this->productSku = $productSku;
167
+        return $this;
168
+    }
169
+
170
+    /**
171
+     * @return mixed
172
+     */
173
+    public function getIsRefund()
174
+    {
175
+        return $this->isRefund;
176
+    }
177
+
178
+    /**
179
+     * @param mixed $isRefund
180
+     * @return StoreOrderProductEntity
181
+     */
182
+    public function setIsRefund($isRefund): StoreOrderProductEntity
183
+    {
184
+        $this->isRefund = $isRefund;
185
+        return $this;
186
+    }
187
+
188
+    /**
189
+     * @return mixed
190
+     */
191
+    public function getProductNum()
192
+    {
193
+        return $this->productNum;
194
+    }
195
+
196
+    /**
197
+     * @param mixed $productNum
198
+     * @return StoreOrderProductEntity
199
+     */
200
+    public function setProductNum($productNum): StoreOrderProductEntity
201
+    {
202
+        $this->productNum = $productNum;
203
+        return $this;
204
+    }
205
+
206
+    /**
207
+     * @return mixed
208
+     */
209
+    public function getRefundNum()
210
+    {
211
+        return $this->refundNum;
212
+    }
213
+
214
+    /**
215
+     * @param mixed $refundNum
216
+     * @return StoreOrderProductEntity
217
+     */
218
+    public function setRefundNum($refundNum): StoreOrderProductEntity
219
+    {
220
+        $this->refundNum = $refundNum;
221
+        return $this;
222
+    }
223
+
224
+    /**
225
+     * @return mixed
226
+     */
227
+    public function getIsReply()
228
+    {
229
+        return $this->isReply;
230
+    }
231
+
232
+    /**
233
+     * @param mixed $isReply
234
+     * @return StoreOrderProductEntity
235
+     */
236
+    public function setIsReply($isReply): StoreOrderProductEntity
237
+    {
238
+        $this->isReply = $isReply;
239
+        return $this;
240
+    }
241
+
242
+    /**
243
+     * @return mixed
244
+     */
245
+    public function getProductPrice()
246
+    {
247
+        return $this->productPrice;
248
+    }
249
+
250
+    /**
251
+     * @param mixed $productPrice
252
+     * @return StoreOrderProductEntity
253
+     */
254
+    public function setProductPrice($productPrice): StoreOrderProductEntity
255
+    {
256
+        $this->productPrice = $productPrice;
257
+        return $this;
258
+    }
259
+
260
+    /**
261
+     * @return mixed
262
+     */
263
+    public function getCartInfo()
264
+    {
265
+        return $this->cartInfo;
266
+    }
267
+
268
+    /**
269
+     * @param mixed $cartInfo
270
+     * @return StoreOrderProductEntity
271
+     */
272
+    public function setCartInfo($cartInfo): StoreOrderProductEntity
273
+    {
274
+        $this->cartInfo = $cartInfo;
275
+        return $this;
276
+    }
277
+
278
+    /**
279
+     * @return mixed
280
+     */
281
+    public function getCreateTime()
282
+    {
283
+        return $this->createTime;
284
+    }
285
+
286
+    /**
287
+     * @param mixed $createTime
288
+     * @return StoreOrderProductEntity
289
+     */
290
+    public function setCreateTime($createTime): StoreOrderProductEntity
291
+    {
292
+        $this->createTime = $createTime;
293
+        return $this;
294
+    }
295
+
296
+    /**
297
+     * @return mixed
298
+     */
299
+    public function getType()
300
+    {
301
+        return $this->type;
302
+    }
303
+
304
+    /**
305
+     * @param mixed $type
306
+     * @return StoreOrderProductEntity
307
+     */
308
+    public function setType($type): StoreOrderProductEntity
309
+    {
310
+        $this->type = $type;
311
+        return $this;
312
+    }
313
+}

+ 85 - 0
app/entity/data/store/StoreOrderStatusEntity.php

@@ -0,0 +1,85 @@
1
+<?php
2
+
3
+namespace app\entity\data\store;
4
+
5
+use app\entity\data\DataEntity;
6
+
7
+class StoreOrderStatusEntity extends DataEntity
8
+{
9
+    public $orderId = null;  // 订单id
10
+    public $changeType = null;  // 操作类型
11
+    public $changeMessage = null;  // 操作备注
12
+    public $changeTime = null;  // 操作时间
13
+
14
+    /**
15
+     * @return mixed
16
+     */
17
+    public function getOrderId()
18
+    {
19
+        return $this->orderId;
20
+    }
21
+
22
+    /**
23
+     * @param mixed $orderId
24
+     * @return StoreOrderStatusEntity
25
+     */
26
+    public function setOrderId($orderId): StoreOrderStatusEntity
27
+    {
28
+        $this->orderId = (string)$orderId;
29
+        return $this;
30
+    }
31
+
32
+    /**
33
+     * @return mixed
34
+     */
35
+    public function getChangeType()
36
+    {
37
+        return $this->changeType;
38
+    }
39
+
40
+    /**
41
+     * @param mixed $changeType
42
+     * @return StoreOrderStatusEntity
43
+     */
44
+    public function setChangeType($changeType): StoreOrderStatusEntity
45
+    {
46
+        $this->changeType = $changeType;
47
+        return $this;
48
+    }
49
+
50
+    /**
51
+     * @return mixed
52
+     */
53
+    public function getChangeMessage()
54
+    {
55
+        return $this->changeMessage;
56
+    }
57
+
58
+    /**
59
+     * @param mixed $changeMessage
60
+     * @return StoreOrderStatusEntity
61
+     */
62
+    public function setChangeMessage($changeMessage): StoreOrderStatusEntity
63
+    {
64
+        $this->changeMessage = $changeMessage;
65
+        return $this;
66
+    }
67
+
68
+    /**
69
+     * @return mixed
70
+     */
71
+    public function getChangeTime()
72
+    {
73
+        return $this->changeTime;
74
+    }
75
+
76
+    /**
77
+     * @param mixed $changeTime
78
+     * @return StoreOrderStatusEntity
79
+     */
80
+    public function setChangeTime($changeTime): StoreOrderStatusEntity
81
+    {
82
+        $this->changeTime = $changeTime;
83
+        return $this;
84
+    }
85
+}

+ 6 - 2
route/api.php

@@ -83,8 +83,8 @@ Route::group('api/', function () {
83 83
         Route::group('order', function () {
84 84
             Route::post('check', '/checkOrder');
85 85
             Route::post('tests/:order_sn', '/tests');
86
-            Route::post('create', '/createOrder');//创建订单
87
-            Route::post('createNew', '/createOrderNew');//创建订单
86
+            // Route::post('create', '/createOrder');//创建订单
87
+            // Route::post('create', '/createOrderNew');//创建订单
88 88
             // 通过 商品ID 商品数量 ,使用商品选用的运费模板 计算邮费
89 89
             Route::get('calculatePostage', '/calculatePostage');
90 90
             Route::post('delete', '/delete');//删除订单
@@ -115,6 +115,10 @@ Route::group('api/', function () {
115 115
 
116 116
         })->prefix('api.store.order.StoreOrder');
117 117
 
118
+        //订单
119
+        Route::group('order', function () {
120
+            Route::post('create', '/createStoreGroupOrder');//创建订单
121
+        })->prefix('api.store.order.StoreGroupOrder');
118 122
 
119 123
         //大仓
120 124
         Route::group('warehouse',function (){