Kaynağa Gözat

优化用户下单方法-进行中

sunxbiao 1 yıl önce
ebeveyn
işleme
f7e6d6ff7f

+ 27 - 0
app/common/dao/store/order/StoreGroupOrderDao.php

@@ -13,6 +13,8 @@ namespace app\common\dao\store\order;
13 13
 
14 14
 use app\common\dao\BaseDao;
15 15
 use app\common\model\store\order\StoreGroupOrder;
16
+use app\entity\CommonEntity;
17
+use app\entity\data\store\StoreGroupOrderEntity;
16 18
 
17 19
 /**
18 20
  * Class StoreGroupOrderDao
@@ -89,4 +91,29 @@ class StoreGroupOrderDao extends BaseDao
89 91
     {
90 92
         return StoreGroupOrder::getDB()->where('pay_type', 0)->where('uid', $uid)->sum('pay_price') ?: 0;
91 93
     }
94
+
95
+    /**
96
+     * @param array $groupOrderIdList
97
+     * @return CommonEntity[]
98
+     */
99
+    public function getStoreGroupOrderEntityListByGroupOrderIdList(array $groupOrderIdList): array
100
+    {
101
+        $entityList = [];
102
+        try {
103
+            /** @var StoreGroupOrder $model */
104
+            $model = $this->getModel();
105
+            $dataRes = $model::getDB()
106
+                ->whereIn('group_order_id', $groupOrderIdList)
107
+                ->select()
108
+                ->toArray();
109
+            if (!empty($dataRes)) {
110
+                $entityList = array_map(function ($data) {
111
+                    return StoreGroupOrderEntity::newInstance($data);
112
+                }, $dataRes);
113
+            }
114
+        } catch (\Exception $e) {
115
+
116
+        }
117
+        return $entityList;
118
+    }
92 119
 }

+ 27 - 0
app/common/dao/user/UserSignFugouDao.php

@@ -4,6 +4,8 @@ namespace app\common\dao\user;
4 4
 
5 5
 use app\common\dao\BaseDao;
6 6
 use app\common\model\user\UserSignFugou;
7
+use app\entity\CommonEntity;
8
+use app\entity\data\user\UserSignFugouEntity;
7 9
 
8 10
 class UserSignFugouDao extends BaseDao
9 11
 {
@@ -11,4 +13,29 @@ class UserSignFugouDao extends BaseDao
11 13
     {
12 14
         return UserSignFugou::class;
13 15
     }
16
+
17
+    /**
18
+     * @param array $idList
19
+     * @return CommonEntity[]
20
+     */
21
+    public function getStoreSignFugouEntityListByIdList(array $idList): array
22
+    {
23
+        $entityList = [];
24
+        try {
25
+            /** @var UserSignFugou $model */
26
+            $model = $this->getModel();
27
+            $dataRes = $model::getDB()
28
+                ->whereIn('id', $idList)
29
+                ->select()
30
+                ->toArray();
31
+            if (!empty($dataRes)) {
32
+                $entityList = array_map(function ($data) {
33
+                    return UserSignFugouEntity::newInstance($data);
34
+                }, $dataRes);
35
+            }
36
+        } catch (\Exception $e) {
37
+
38
+        }
39
+        return $entityList;
40
+    }
14 41
 }

+ 27 - 0
app/common/dao/user/UserSignJingdouDao.php

@@ -4,6 +4,8 @@ namespace app\common\dao\user;
4 4
 
5 5
 use app\common\dao\BaseDao;
6 6
 use app\common\model\user\UserSignJingdou;
7
+use app\entity\CommonEntity;
8
+use app\entity\data\user\UserSignJingdouEntity;
7 9
 
8 10
 class UserSignJingdouDao extends BaseDao
9 11
 {
@@ -11,4 +13,29 @@ class UserSignJingdouDao extends BaseDao
11 13
     {
12 14
         return UserSignJingdou::class;
13 15
     }
16
+
17
+    /**
18
+     * @param array $idList
19
+     * @return CommonEntity[]
20
+     */
21
+    public function getStoreSignJingdouEntityListByIdList(array $idList): array
22
+    {
23
+        $entityList = [];
24
+        try {
25
+            /** @var UserSignJingdou $model */
26
+            $model = $this->getModel();
27
+            $dataRes = $model::getDB()
28
+                ->whereIn('id', $idList)
29
+                ->select()
30
+                ->toArray();
31
+            if (!empty($dataRes)) {
32
+                $entityList = array_map(function ($data) {
33
+                    return UserSignJingdouEntity::newInstance($data);
34
+                }, $dataRes);
35
+            }
36
+        } catch (\Exception $e) {
37
+
38
+        }
39
+        return $entityList;
40
+    }
14 41
 }

+ 27 - 0
app/common/dao/user/UserSignScoreDao.php

@@ -4,6 +4,8 @@ namespace app\common\dao\user;
4 4
 
5 5
 use app\common\dao\BaseDao;
6 6
 use app\common\model\user\UserSignScore;
7
+use app\entity\CommonEntity;
8
+use app\entity\data\user\UserSignScoreEntity;
7 9
 
8 10
 class UserSignScoreDao extends BaseDao
9 11
 {
@@ -11,4 +13,29 @@ class UserSignScoreDao extends BaseDao
11 13
     {
12 14
         return UserSignScore::class;
13 15
     }
16
+
17
+    /**
18
+     * @param array $idList
19
+     * @return CommonEntity[]
20
+     */
21
+    public function getStoreSignScoreEntityListByIdList(array $idList): array
22
+    {
23
+        $entityList = [];
24
+        try {
25
+            /** @var UserSignScore $model */
26
+            $model = $this->getModel();
27
+            $dataRes = $model::getDB()
28
+                ->whereIn('id', $idList)
29
+                ->select()
30
+                ->toArray();
31
+            if (!empty($dataRes)) {
32
+                $entityList = array_map(function ($data) {
33
+                    return UserSignScoreEntity::newInstance($data);
34
+                }, $dataRes);
35
+            }
36
+        } catch (\Exception $e) {
37
+
38
+        }
39
+        return $entityList;
40
+    }
14 41
 }

+ 27 - 0
app/common/dao/user/UserSignVrDao.php

@@ -4,6 +4,8 @@ namespace app\common\dao\user;
4 4
 
5 5
 use app\common\dao\BaseDao;
6 6
 use app\common\model\user\UserSignVr;
7
+use app\entity\CommonEntity;
8
+use app\entity\data\user\UserSignVrEntity;
7 9
 
8 10
 class UserSignVrDao extends BaseDao
9 11
 {
@@ -11,4 +13,29 @@ class UserSignVrDao extends BaseDao
11 13
     {
12 14
         return UserSignVr::class;
13 15
     }
16
+
17
+    /**
18
+     * @param array $idList
19
+     * @return CommonEntity[]
20
+     */
21
+    public function getStoreSignVrEntityListByIdList(array $idList): array
22
+    {
23
+        $entityList = [];
24
+        try {
25
+            /** @var UserSignVr $model */
26
+            $model = $this->getModel();
27
+            $dataRes = $model::getDB()
28
+                ->whereIn('id', $idList)
29
+                ->select()
30
+                ->toArray();
31
+            if (!empty($dataRes)) {
32
+                $entityList = array_map(function ($data) {
33
+                    return UserSignVrEntity::newInstance($data);
34
+                }, $dataRes);
35
+            }
36
+        } catch (\Exception $e) {
37
+
38
+        }
39
+        return $entityList;
40
+    }
14 41
 }

+ 18 - 0
app/common/enum/CommonEnum.php

@@ -36,6 +36,24 @@ class CommonEnum
36 36
         'XingfuXiaodian' => ['code' => 2001, 'name' => '幸福小店'],
37 37
     ];
38 38
 
39
+    // 佣金类型
40
+    const COMMISSION_TYPE = [
41
+        'AGENT_FEE' => ['code' => 1, 'name' => '代理费'],
42
+        'CONSUMPTION_COMMISSION' => ['code' => 2, 'name' => '消费佣金'],
43
+        'DIRECT_REFERRAL' => ['code' => 3, 'name' => '直推奖'],
44
+        'REGION_COMMISSION' => ['code' => 4, 'name' => '辖区佣金'],
45
+        'PENSION' => ['code' => 5, 'name' => '养老金'],
46
+        'AD_FEE' => ['code' => 6, 'name' => '广告费'],
47
+        'LOCKED_CUSTOMER' => ['code' => 7, 'name' => '锁客收益'],
48
+        'PLATFORM_REWARD' => ['code' => 8, 'name' => '平台奖励'],
49
+        'CHANNEL_DEALER' => ['code' => 9, 'name' => '渠道商'],
50
+        'SHOP_REWARD' => ['code' => 10, 'name' => '推广店铺收益'],
51
+        'PARTNER_DIVIDEND' => ['code' => 11, 'name' => '合伙人分红'],
52
+        'JOINT_CREATOR_DIVIDEND' => ['code' => 12, 'name' => '联创分红'],
53
+        'EQUITY_DIVIDEND' => ['code' => 13, 'name' => '股权分红'],
54
+        'SHARE_EARNINGS' => ['code' => 20, 'name' => '分享收益']
55
+    ];
56
+
39 57
     const USER_GROUP = [
40 58
         'RegularUser' => ['code' => 1, 'name' => '普通用户'],
41 59
         'Salesperson' => ['code' => 2, 'name' => '业务员'],

+ 1 - 16
app/common/enum/user/UserBillEnum.php

@@ -20,22 +20,7 @@ class UserBillEnum extends CommonEnum
20 20
     ];
21 21
 
22 22
     // 佣金类型
23
-    const COMMISSION_TYPE = [
24
-        'AGENT_FEE' => ['code' => 1, 'name' => '代理费'],
25
-        'CONSUMPTION_COMMISSION' => ['code' => 2, 'name' => '消费佣金'],
26
-        'DIRECT_REFERRAL' => ['code' => 3, 'name' => '直推奖'],
27
-        'REGION_COMMISSION' => ['code' => 4, 'name' => '辖区佣金'],
28
-        'PENSION' => ['code' => 5, 'name' => '养老金'],
29
-        'AD_FEE' => ['code' => 6, 'name' => '广告费'],
30
-        'LOCKED_CUSTOMER' => ['code' => 7, 'name' => '锁客收益'],
31
-        'PLATFORM_REWARD' => ['code' => 8, 'name' => '平台奖励'],
32
-        'CHANNEL_DEALER' => ['code' => 9, 'name' => '渠道商'],
33
-        'SHOP_REWARD' => ['code' => 10, 'name' => '推广店铺收益'],
34
-        'PARTNER_DIVIDEND' => ['code' => 11, 'name' => '合伙人分红'],
35
-        'JOINT_CREATOR_DIVIDEND' => ['code' => 12, 'name' => '联创分红'],
36
-        'EQUITY_DIVIDEND' => ['code' => 13, 'name' => '股权分红'],
37
-        'SHARE_EARNINGS' => ['code' => 20, 'name' => '分享收益']
38
-    ];
23
+    const COMMISSION_TYPE = parent::COMMISSION_TYPE;
39 24
 
40 25
     // 账单来源
41 26
     const SOURCE = [

+ 1 - 15
app/common/enum/user/UserSignFugouEnum.php

@@ -14,21 +14,7 @@ class UserSignFugouEnum extends CommonEnum
14 14
     ];
15 15
 
16 16
     // 1代理费 2 消费佣金 3直推奖 4辖区佣金 5养老金 6广告费 7锁客收益 8平台奖励 9渠道商 10推广店铺收益 11合伙人分红 12联创分红 13股权分红
17
-    const COMMISSION_TYPE = [
18
-        'AgentFee' => ['code' => 1, 'name' => '代理费'],
19
-        'ConsumeCommission' => ['code' => 2, 'name' => '消费佣金'],
20
-        'DirectPushReward' => ['code' => 3, 'name' => '直推奖'],
21
-        'AreaCommission' => ['code' => 4, 'name' => '辖区佣金'],
22
-        'Pension' => ['code' => 5, 'name' => '养老金'],
23
-        'AdFee' => ['code' => 6, 'name' => '广告费'],
24
-        'CustomerLockRevenue' => ['code' => 7, 'name' => '锁客收益'],
25
-        'PlatformReward' => ['code' => 8, 'name' => '平台奖励'],
26
-        'ChannelDistributor' => ['code' => 9, 'name' => '渠道商'],
27
-        'StorePromotionRevenue' => ['code' => 10, 'name' => '推广店铺收益'],
28
-        'PartnerDividend' => ['code' => 11, 'name' => '合伙人分红'],
29
-        'CoFounderDividend' => ['code' => 12, 'name' => '联创分红'],
30
-        'EquityDividend' => ['code' => 13, 'name' => '股权分红'],
31
-    ];
17
+    const COMMISSION_TYPE = parent::COMMISSION_TYPE;
32 18
 
33 19
     // 1赠送,2消耗
34 20
     const TYPE = [

+ 2 - 0
app/common/enum/user/UserSignVrEnum.php

@@ -11,4 +11,6 @@ class UserSignVrEnum extends CommonEnum
11 11
         'Exchange' => ['code' => 1, 'name' => '兑换'],
12 12
         'Consume' => ['code' => 2, 'name' => '消耗'],
13 13
     ];
14
+
15
+    const ORDER_TYPE = parent::ORDER_TYPE;
14 16
 }

+ 25 - 0
app/common/repositories/store/order/StoreGroupOrderRepository.php

@@ -14,6 +14,7 @@ namespace app\common\repositories\store\order;
14 14
 use app\common\dao\store\order\StoreGroupOrderDao;
15 15
 use app\common\repositories\BaseRepository;
16 16
 use app\common\repositories\store\coupon\StoreCouponUserRepository;
17
+use app\entity\data\store\StoreGroupOrderEntity;
17 18
 use crmeb\jobs\CancelGroupOrderJob;
18 19
 use think\exception\ValidateException;
19 20
 use think\facade\Cache;
@@ -251,4 +252,28 @@ class StoreGroupOrderRepository extends BaseRepository
251 252
         return $order;
252 253
     }
253 254
 
255
+    /**
256
+     * @param int $orderId
257
+     * @return StoreGroupOrderEntity
258
+     */
259
+    public function getStoreGroupOrderEntityByGroupOrderId(int $orderId): StoreGroupOrderEntity
260
+    {
261
+        $entityList = $this->getStoreGroupOrderEntityListByGroupOrderIdList([$orderId]);
262
+        $entity = array_shift($entityList);
263
+        if ($entity instanceof StoreGroupOrderEntity) {
264
+            return $entity;
265
+        } else {
266
+            /** @var StoreGroupOrderEntity */
267
+            return StoreGroupOrderEntity::newInstance();
268
+        }
269
+    }
270
+
271
+    /**
272
+     * @param array $groupOrderIdList
273
+     * @return StoreGroupOrderEntity[]
274
+     */
275
+    public function getStoreGroupOrderEntityListByGroupOrderIdList(array $groupOrderIdList): array
276
+    {
277
+        return $this->dao->getStoreGroupOrderEntityListByGroupOrderIdList($groupOrderIdList);
278
+    }
254 279
 }

+ 169 - 107
app/common/repositories/store/order/StoreOrderRepository.php

@@ -67,6 +67,7 @@ use app\common\repositories\user\UserSignGongxianRepository;
67 67
 use app\common\repositories\user\UserSignHongbaoRepository;
68 68
 use app\common\repositories\user\UserSignJingdouRepository;
69 69
 use app\common\repositories\user\UserSignScoreRepository;
70
+use app\common\repositories\user\UserSignVrRepository;
70 71
 use app\common\repositories\user\UserThirdRepository;
71 72
 use app\common\repositories\wechat\RoutineQrcodeRepository;
72 73
 use app\common\repositories\wechat\WechatUserRepository;
@@ -11065,9 +11066,6 @@ class StoreOrderRepository extends BaseRepository
11065 11066
             $storeOrderEntityList[$key] = $storeOrderEntity;
11066 11067
             $storeOrderIdList[] = $storeOrderEntity->getOrderId();
11067 11068
 
11068
-            // 生成奖励数据
11069
-            $this->createRewardMechanismByStoreOrderId($storeOrderEntity->getOrderId());
11070
-
11071 11069
             // 将每件商品设计到的优惠券要取消掉
11072 11070
 
11073 11071
             // 准备订单的 状态数据
@@ -11104,189 +11102,229 @@ class StoreOrderRepository extends BaseRepository
11104 11102
 
11105 11103
         $storeOrderProductRepository->insertAll($storeOrderProductDataList);
11106 11104
 
11107
-        $paySuccess = false;
11108
-        // 验证支付方式
11109 11105
         /** @var FzonePayTypeEntity $fzonePayTypeEntity */
11110 11106
         $fzonePayTypeEntity = FzonePayTypeEntity::newInstance($storeOrderCreateRequestEntity->getFzonePayType());
11107
+        $paySuccess = $this->abatement($userEntity->getUid(), $storeGroupOrderEntity->getGroupOrderId(), $fzonePayTypeEntity);
11108
+
11109
+        // 非涉及到现金 控件成功后 直接结算
11110
+        if ($paySuccess) {
11111
+            // 修改订单的 支付状态
11112
+            $storeGroupOrderRepository->update($storeGroupOrderEntity->getGroupOrderId(), [
11113
+                'paid' => StoreGroupOrderEnum::PAID['YES']['code'],
11114
+                'pay_time' => date('Y-m-d H:i:s')
11115
+            ]);
11116
+
11117
+            $storeOrderRepository->updates($storeOrderIdList, [
11118
+                'paid' => StoreOrderEnum::PAID['YES']['code'],
11119
+                'pay_time' => date('Y-m-d H:i:s'),
11120
+                'status' => StoreOrderEnum::STATUS['WAITING_SHIPMENT']['code'],
11121
+                'distribution_mode' => StoreOrderEnum::DISTRIBUTION_MODE['ExpressDelivery']
11122
+            ]);
11123
+            $settlementOrderIdList = [];
11124
+            foreach ($storeOrderEntityList as $storeOrderEntity) {
11125
+                // 生成奖励数据
11126
+                $this->createRewardMechanismByStoreOrderId($storeOrderEntity->getOrderId());
11127
+                if ($storeOrderEntity->getMerId() == CommonEnum::DESIGN_MERCHANT_ID['MemberZone']['code']) {
11128
+                    // 会员专区的 订单立即结算
11129
+                    $settlementOrderIdList[] = $storeOrderEntity->getOrderId();
11130
+                }
11131
+            }
11132
+            if (!empty($settlementOrderIdList)) {
11133
+                $this->settlementOrderByOrderIdList($settlementOrderIdList);
11134
+            }
11135
+        }
11136
+
11137
+        return [];
11138
+    }
11139
+
11140
+    /**
11141
+     * @param int $orderId
11142
+     * @return StoreOrderEntity
11143
+     */
11144
+    public function getStoreOrderEntityByOrderId(int $orderId): StoreOrderEntity
11145
+    {
11146
+        $entityList = $this->getStoreOrderEntityListByOrderIdList([$orderId]);
11147
+        $entity = array_shift($entityList);
11148
+        if ($entity instanceof StoreOrderEntity) {
11149
+            return $entity;
11150
+        } else {
11151
+            /** @var StoreOrderEntity */
11152
+            return StoreOrderEntity::newInstance();
11153
+        }
11154
+    }
11155
+
11156
+    /**
11157
+     * @param array $orderIdList
11158
+     * @return StoreOrderEntity[]
11159
+     */
11160
+    public function getStoreOrderEntityListByOrderIdList(array $orderIdList): array
11161
+    {
11162
+        return $this->dao->getStoreOrderEntityListByOrderIdList($orderIdList);
11163
+    }
11164
+
11165
+
11166
+    /**
11167
+     * 根据 用户信息 订单信息 支付信息 判断用户是否满足支付条件,并进行扣款
11168
+     * @param int $uid
11169
+     * @param int $groupOrderId
11170
+     * @param FzonePayTypeEntity $fzonePayTypeEntity
11171
+     * @return bool
11172
+     */
11173
+    public function abatement(int $uid, int $groupOrderId, FzonePayTypeEntity $fzonePayTypeEntity): bool
11174
+    {
11175
+        /** @var UserRepository $userRepository */
11176
+        $userRepository = app()->make(UserRepository::class);
11177
+        $userEntity = $userRepository->getUserEntityByUid($uid);
11178
+        if (empty($userEntity->getUid())) {
11179
+            throw new ValidateException('未查询到用户信息');
11180
+        }
11181
+
11182
+        /** @var StoreGroupOrderRepository $storeGroupOrderRepository */
11183
+        $storeGroupOrderRepository = app()->make(StoreGroupOrderRepository::class);
11184
+        $storeGroupOrderEntity = $storeGroupOrderRepository->getStoreGroupOrderEntityByGroupOrderId($groupOrderId);
11185
+        if (empty($storeGroupOrderEntity->getGroupOrderId())) {
11186
+            throw new ValidateException('未查询到订单信息');
11187
+        }
11188
+
11189
+        /** @var UserSignVrRepository $userSignVrRepository */
11190
+        $userSignVrRepository = app()->make(UserSignVrRepository::class);
11191
+        /** @var UserSignScoreRepository $userSignScoreRepository */
11192
+        $userSignScoreRepository = app()->make(UserSignScoreRepository::class);
11193
+        /** @var UserSignJingdouRepository $userSignJingdouRepository */
11194
+        $userSignJingdouRepository = app()->make(UserSignJingdouRepository::class);
11195
+        /** @var UserSignFugouRepository $userSignFugouRepository */
11196
+        $userSignFugouRepository = app()->make(UserSignFugouRepository::class);
11197
+
11198
+        $paySuccess = false;
11199
+        // 验证支付方式
11111 11200
         if ($fzonePayTypeEntity->getType() == StoreOrderEnum::FZONE_PAY_TYPE['B1-VR+Score']['code']) {
11112 11201
             if ($fzonePayTypeEntity->getPrice() > $userEntity->getVr() || $fzonePayTypeEntity->getOther() > $userEntity->getScore()) {
11113 11202
                 throw new ValidateException('支付失败,VR或积分不足!');
11114 11203
             }
11115
-            // 修改用户的VR值 和 积分值
11116
-            // 修改用户VR
11117
-            $userRepository->updateUserVr(
11204
+            // 创建Vr扣减记录 先有记录 再去执行
11205
+            $userSignVrEntity = $userSignVrRepository->addUserSingVr(
11118 11206
                 $userEntity->getUid(),
11119 11207
                 UserSignVrEnum::TYPE['Consume']['code'],
11120 11208
                 $fzonePayTypeEntity->getPrice(),
11121
-                '购买商品,订单编号:'.$storeGroupOrderEntity->getGroupOrderSn(),
11209
+                '购买商品,订单编号:' . $storeGroupOrderEntity->getGroupOrderSn(),
11122 11210
                 CommonEnum::ORDER_TYPE['Platform-Group']['code'],
11123 11211
                 $storeGroupOrderEntity->getGroupOrderId()
11124 11212
             );
11125
-            // 修改用户积分
11126
-            $userRepository->updateUserScore(
11213
+            // 执行 Vr 增减 操作
11214
+            $userSignVrRepository->execute($userSignVrEntity->getId());
11215
+
11216
+            // 修改用户积分 先有记录 再去执行
11217
+            $userSignScoreEntity = $userSignScoreRepository->addUserSingScore(
11127 11218
                 $userEntity->getUid(),
11219
+                UserSignScoreEnum::SOURCE_TYPE['SelfOrder']['code'],
11128 11220
                 UserSignScoreEnum::PM['Expend']['code'],
11129 11221
                 $fzonePayTypeEntity->getOther(),
11130
-                '购买商品,订单编号:'.$storeGroupOrderEntity->getGroupOrderSn(),
11131
-                CommonEnum::ORDER_TYPE['Platform-Group']['code'],
11222
+                '购买商品,订单编号:' . $storeGroupOrderEntity->getGroupOrderSn(),
11223
+                UserSignHongbaoEnum::ORDER_TYPE['Platform']['code'],
11132 11224
                 $storeGroupOrderEntity->getGroupOrderId()
11133 11225
             );
11226
+            $userSignScoreRepository->execute($userSignScoreEntity->getId());
11227
+
11134 11228
             $paySuccess = true;
11135 11229
         } else if ($fzonePayTypeEntity->getType() == StoreOrderEnum::FZONE_PAY_TYPE['B2-Cash+Score']['code']) {
11136 11230
             if ($fzonePayTypeEntity->getOther() > $userEntity->getScore()) {
11137 11231
                 throw new ValidateException('支付失败,积分不足!');
11138 11232
             }
11139
-            // 修改用户积分
11140
-            $userRepository->updateUserScore(
11141
-                $userEntity->getUid(),
11142
-                UserSignScoreEnum::PM['Expend']['code'],
11143
-                $fzonePayTypeEntity->getOther(),
11144
-                '购买商品,订单编号:'.$storeGroupOrderEntity->getGroupOrderSn(),
11145
-                CommonEnum::ORDER_TYPE['Platform-Group']['code'],
11146
-                $storeGroupOrderEntity->getGroupOrderId()
11147
-            );
11233
+            // 用户下单时 不扣除积分,而是在支付环节 验证 并扣除
11148 11234
         } else if ($fzonePayTypeEntity->getType() == StoreOrderEnum::FZONE_PAY_TYPE['B3-VR+Jingdou']['code']) {
11149 11235
             if ($fzonePayTypeEntity->getPrice() > $userEntity->getVr() || $fzonePayTypeEntity->getOther() > $userEntity->getJingdou()) {
11150 11236
                 throw new ValidateException('支付失败,VR或京豆不足!');
11151 11237
             }
11152
-            // 修改用户VR
11153
-            $userRepository->updateUserVr(
11238
+            // 创建Vr扣减记录 先有记录 再去执行
11239
+            $userSignVrEntity = $userSignVrRepository->addUserSingVr(
11154 11240
                 $userEntity->getUid(),
11155 11241
                 UserSignVrEnum::TYPE['Consume']['code'],
11156 11242
                 $fzonePayTypeEntity->getPrice(),
11157
-                '购买商品,订单编号:'.$storeGroupOrderEntity->getGroupOrderSn(),
11243
+                '购买商品,订单编号:' . $storeGroupOrderEntity->getGroupOrderSn(),
11158 11244
                 CommonEnum::ORDER_TYPE['Platform-Group']['code'],
11159 11245
                 $storeGroupOrderEntity->getGroupOrderId()
11160 11246
             );
11161
-            // 修改用户jingdou
11162
-            $userRepository->updateUserJingdou(
11247
+            // 执行 Vr 增减 操作
11248
+            $userSignVrRepository->execute($userSignVrEntity->getId());
11249
+
11250
+            // 创建 京豆 扣减记录
11251
+            $userSignJingdouEntity = $userSignJingdouRepository->addUserSingJingdou(
11163 11252
                 $userEntity->getUid(),
11164 11253
                 UserSignJingdouEnum::TYPE['Consume']['code'],
11165 11254
                 $fzonePayTypeEntity->getOther(),
11166
-                '购买商品,订单编号:'.$storeGroupOrderEntity->getGroupOrderSn(),
11255
+                0,
11256
+                '购买商品,订单编号:' . $storeGroupOrderEntity->getGroupOrderSn(),
11167 11257
                 CommonEnum::ORDER_TYPE['Platform-Group']['code'],
11168 11258
                 $storeGroupOrderEntity->getGroupOrderId()
11169 11259
             );
11260
+            // 执行 京豆 增减 操作
11261
+            $userSignJingdouRepository->execute($userSignJingdouEntity->getId());
11262
+
11170 11263
             $paySuccess = true;
11171 11264
         } else if ($fzonePayTypeEntity->getType() == StoreOrderEnum::FZONE_PAY_TYPE['B4-Cash+Jingdou']['code']) {
11172 11265
             if ($fzonePayTypeEntity->getPrice() > $userEntity->getVr() || $fzonePayTypeEntity->getOther() > $userEntity->getJingdou()) {
11173 11266
                 throw new ValidateException('支付失败,京豆不足!');
11174 11267
             }
11175
-            // 修改用户jingdou
11176
-            $userRepository->updateUserJingdou(
11177
-                $userEntity->getUid(),
11178
-                UserSignJingdouEnum::TYPE['Consume']['code'],
11179
-                $fzonePayTypeEntity->getOther(),
11180
-                '购买商品,订单编号:'.$storeGroupOrderEntity->getGroupOrderSn(),
11181
-                CommonEnum::ORDER_TYPE['Platform-Group']['code'],
11182
-                $storeGroupOrderEntity->getGroupOrderId()
11183
-            );
11184 11268
         } else if ($fzonePayTypeEntity->getType() == StoreOrderEnum::FZONE_PAY_TYPE['B5-VR']['code']) {
11185 11269
             if ($fzonePayTypeEntity->getPrice() > $userEntity->getVr()) {
11186 11270
                 throw new ValidateException('支付失败,VR不足!');
11187 11271
             }
11188
-            // 修改用户VR
11189
-            $userRepository->updateUserVr(
11272
+            // 创建Vr扣减记录 先有记录 再去执行
11273
+            $userSignVrEntity = $userSignVrRepository->addUserSingVr(
11190 11274
                 $userEntity->getUid(),
11191 11275
                 UserSignVrEnum::TYPE['Consume']['code'],
11192 11276
                 $fzonePayTypeEntity->getPrice(),
11193
-                '购买商品,订单编号:'.$storeGroupOrderEntity->getGroupOrderSn(),
11277
+                '购买商品,订单编号:' . $storeGroupOrderEntity->getGroupOrderSn(),
11194 11278
                 CommonEnum::ORDER_TYPE['Platform-Group']['code'],
11195 11279
                 $storeGroupOrderEntity->getGroupOrderId()
11196 11280
             );
11281
+            // 执行 Vr 增减 操作
11282
+            $userSignVrRepository->execute($userSignVrEntity->getId());
11197 11283
             $paySuccess = true;
11198 11284
         } else if ($fzonePayTypeEntity->getType() == StoreOrderEnum::FZONE_PAY_TYPE['A1-VR']['code']) {
11199 11285
             if ($fzonePayTypeEntity->getPrice() > $userEntity->getVr()) {
11200 11286
                 throw new ValidateException('支付失败,VR不足!');
11201 11287
             }
11202
-            // 修改用户VR
11203
-            $userRepository->updateUserVr(
11288
+            // 创建Vr扣减记录 先有记录 再去执行
11289
+            $userSignVrEntity = $userSignVrRepository->addUserSingVr(
11204 11290
                 $userEntity->getUid(),
11205 11291
                 UserSignVrEnum::TYPE['Consume']['code'],
11206 11292
                 $fzonePayTypeEntity->getPrice(),
11207
-                '购买商品,订单编号:'.$storeGroupOrderEntity->getGroupOrderSn(),
11293
+                '购买商品,订单编号:' . $storeGroupOrderEntity->getGroupOrderSn(),
11208 11294
                 CommonEnum::ORDER_TYPE['Platform-Group']['code'],
11209 11295
                 $storeGroupOrderEntity->getGroupOrderId()
11210 11296
             );
11297
+            // 执行 Vr 增减 操作
11298
+            $userSignVrRepository->execute($userSignVrEntity->getId());
11211 11299
             $paySuccess = true;
11212 11300
         } else if ($fzonePayTypeEntity->getType() == StoreOrderEnum::FZONE_PAY_TYPE['A2-Cash']['code']) {
11213 11301
 
11214
-        } else if ($fzonePayTypeEntity->getType() == StoreOrderEnum::FZONE_PAY_TYPE['A3-Cash+VR']['code']) {
11302
+        }
11303
+        else if ($fzonePayTypeEntity->getType() == StoreOrderEnum::FZONE_PAY_TYPE['A3-Cash+VR']['code']) {
11215 11304
             if ($fzonePayTypeEntity->getOther() > $userEntity->getVr()) {
11216 11305
                 throw new ValidateException('支付失败,VR不足!');
11217 11306
             }
11218
-            // 修改用户VR
11219
-            $userRepository->updateUserVr(
11220
-                $userEntity->getUid(),
11221
-                UserSignVrEnum::TYPE['Consume']['code'],
11222
-                $fzonePayTypeEntity->getOther(),
11223
-                '购买商品,订单编号:'.$storeGroupOrderEntity->getGroupOrderSn(),
11224
-                CommonEnum::ORDER_TYPE['Platform-Group']['code'],
11225
-                $storeGroupOrderEntity->getGroupOrderId()
11226
-            );
11227 11307
         } else if ($fzonePayTypeEntity->getType() == StoreOrderEnum::FZONE_PAY_TYPE['C1-Fugou']['code']) {
11228 11308
             if ($fzonePayTypeEntity->getOther() > $userEntity->getFugou()) {
11229 11309
                 throw new ValidateException('支付失败,复购金不足!');
11230 11310
             }
11231
-            // 修改用户复购金
11232
-            $userRepository->updateUserFugou(
11311
+            // 添加复购金 记录
11312
+            $userSignFugouEntity = $userSignFugouRepository->addUserSingFugou(
11233 11313
                 $userEntity->getUid(),
11234
-                UserSignVrEnum::TYPE['Consume']['code'],
11314
+                UserSignFugouEnum::TYPE['Give']['code'],
11235 11315
                 $fzonePayTypeEntity->getPrice(),
11236
-                '购买商品,订单编号:'.$storeGroupOrderEntity->getGroupOrderSn(),
11316
+                UserSignFugouEnum::COMMISSION_TYPE['DIRECT_REFERRAL']['code'],
11317
+                '购买商品,订单编号:' . $storeGroupOrderEntity->getGroupOrderSn(),
11237 11318
                 CommonEnum::ORDER_TYPE['Platform-Group']['code'],
11238 11319
                 $storeGroupOrderEntity->getGroupOrderId()
11239 11320
             );
11321
+            // 执行
11322
+            $userSignFugouRepository->execute($userSignFugouEntity->getId());
11240 11323
             $paySuccess = true;
11241 11324
         } else {
11242 11325
             throw new ValidateException('支付失败,支付方式错误!');
11243 11326
         }
11244
-
11245
-        // 非涉及到现金 控件成功后 直接结算
11246
-        if ($paySuccess) {
11247
-            // 修改订单的 支付状态
11248
-            $storeGroupOrderRepository->update($storeGroupOrderEntity->getGroupOrderId(), [
11249
-                'paid' => StoreGroupOrderEnum::PAID['YES']['code'],
11250
-                'pay_time' => date('Y-m-d H:i:s')
11251
-            ]);
11252
-
11253
-            $storeOrderRepository->updates($storeOrderIdList, [
11254
-                'paid' => StoreOrderEnum::PAID['YES']['code'],
11255
-                'pay_time' => date('Y-m-d H:i:s'),
11256
-                'status' => StoreOrderEnum::STATUS['WAITING_SHIPMENT']['code'],
11257
-                'distribution_mode' => StoreOrderEnum::DISTRIBUTION_MODE['ExpressDelivery']
11258
-            ]);
11259
-            foreach ($storeOrderEntityList as $storeOrderEntity) {
11260
-
11261
-            }
11262
-        }
11263
-
11264
-        return [];
11265
-    }
11266
-
11267
-    /**
11268
-     * @param int $orderId
11269
-     * @return StoreOrderEntity
11270
-     */
11271
-    public function getStoreOrderEntityByOrderId(int $orderId): StoreOrderEntity
11272
-    {
11273
-        $entityList = $this->getStoreOrderEntityListByOrderIdList([$orderId]);
11274
-        $entity = array_shift($entityList);
11275
-        if ($entity instanceof StoreOrderEntity) {
11276
-            return $entity;
11277
-        } else {
11278
-            /** @var StoreOrderEntity */
11279
-            return StoreOrderEntity::newInstance();
11280
-        }
11281
-    }
11282
-
11283
-    /**
11284
-     * @param array $orderIdList
11285
-     * @return StoreOrderEntity[]
11286
-     */
11287
-    public function getStoreOrderEntityListByOrderIdList(array $orderIdList): array
11288
-    {
11289
-        return $this->dao->getStoreOrderEntityListByOrderIdList($orderIdList);
11327
+        return $paySuccess;
11290 11328
     }
11291 11329
 
11292 11330
     /**
@@ -11394,6 +11432,7 @@ class StoreOrderRepository extends BaseRepository
11394 11432
                         $userEntityBySpreadUid->getUid(),
11395 11433
                         UserSignFugouEnum::TYPE['Give']['code'],
11396 11434
                         $fugouBySpreadUid,
11435
+                        UserSignFugouEnum::COMMISSION_TYPE['DIRECT_REFERRAL']['code'],
11397 11436
                         '推广精彩生活区商品赠送复购金',
11398 11437
                         UserSignFugouEnum::ORDER_TYPE['Platform']['code'],
11399 11438
                         $storeOrderEntity->getOrderId()
@@ -11485,6 +11524,7 @@ class StoreOrderRepository extends BaseRepository
11485 11524
                         $userEntityByShareUid->getUid(),
11486 11525
                         UserSignFugouEnum::TYPE['Give']['code'],
11487 11526
                         $fugouByShareUid,
11527
+                        UserSignFugouEnum::COMMISSION_TYPE['SHARE_EARNINGS']['code'],
11488 11528
                         '分享精彩生活区商品赠送复购金',
11489 11529
                         UserSignFugouEnum::ORDER_TYPE['Platform']['code'],
11490 11530
                         $storeOrderEntity->getOrderId()
@@ -11521,6 +11561,7 @@ class StoreOrderRepository extends BaseRepository
11521 11561
                         $merchantEntity->getUid(),
11522 11562
                         UserSignFugouEnum::TYPE['Give']['code'],
11523 11563
                         $fugouByMerId,
11564
+                        UserSignFugouEnum::COMMISSION_TYPE['LOCKED_CUSTOMER']['code'],
11524 11565
                         '锁客复购金(精彩生活区商品赠送)',
11525 11566
                         UserSignFugouEnum::ORDER_TYPE['Platform']['code'],
11526 11567
                         $storeOrderEntity->getOrderId()
@@ -11602,6 +11643,7 @@ class StoreOrderRepository extends BaseRepository
11602 11643
                                 $userEntityBySpreadUid->getUid(),
11603 11644
                                 UserSignFugouEnum::TYPE['Give']['code'],
11604 11645
                                 $fugouBySpreadUid,
11646
+                                UserSignFugouEnum::COMMISSION_TYPE['DIRECT_REFERRAL']['code'],
11605 11647
                                 '推广会员专区商品赠送复购金',
11606 11648
                                 UserSignFugouEnum::ORDER_TYPE['Platform']['code'],
11607 11649
                                 $storeOrderEntity->getOrderId()
@@ -11828,6 +11870,7 @@ class StoreOrderRepository extends BaseRepository
11828 11870
                         $userEntityBySpreadUid->getUid(),
11829 11871
                         UserSignFugouEnum::TYPE['Give']['code'],
11830 11872
                         $fugouBySpreadUid,
11873
+                        UserSignFugouEnum::COMMISSION_TYPE['DIRECT_REFERRAL']['code'],
11831 11874
                         '推广商贸区商品赠送复购金',
11832 11875
                         UserSignFugouEnum::ORDER_TYPE['Platform']['code'],
11833 11876
                         $storeOrderEntity->getOrderId()
@@ -11922,6 +11965,7 @@ class StoreOrderRepository extends BaseRepository
11922 11965
                         $merchantEntityByLock->getUid(),
11923 11966
                         UserSignFugouEnum::TYPE['Give']['code'],
11924 11967
                         $fugouByMerId,
11968
+                        UserSignFugouEnum::COMMISSION_TYPE['LOCKED_CUSTOMER']['code'],
11925 11969
                         '锁客复购金(精彩生活区商品赠送)',
11926 11970
                         UserSignFugouEnum::ORDER_TYPE['Platform']['code'],
11927 11971
                         $storeOrderEntity->getOrderId()
@@ -11949,25 +11993,43 @@ class StoreOrderRepository extends BaseRepository
11949 11993
         }
11950 11994
     }
11951 11995
 
11996
+    /**
11997
+     * 结算订单 将 奖励设置为 生效
11998
+     * @param array $orderIdList
11999
+     * @return void
12000
+     */
11952 12001
     public function settlementOrderByOrderIdList(array $orderIdList)
11953 12002
     {
11954 12003
         /** @var StoreOrderRepository $storeOrderRepository */
11955 12004
         $storeOrderRepository = app()->make(StoreOrderRepository::class);
11956 12005
         $storeOrderEntityList = $storeOrderRepository->getStoreOrderEntityListByOrderIdList($orderIdList);
11957 12006
         if (!empty($storeOrderEntityList)) {
11958
-            $existOrderIdList = array_map(function ($storeOrderEntity) {
12007
+            /** @var UserRepository $userRepository */
12008
+            $userRepository = app()->make(UserRepository::class);
12009
+
12010
+            // 筛选
12011
+            $existOrderIdList = [];
12012
+            foreach ($storeOrderEntityList as $storeOrderEntity) {
11959 12013
                 if ($storeOrderEntity->getIsSettlement() == StoreOrderEnum::IS_SETTLEMENT['NO']['code']) {
11960
-                    return $storeOrderEntity->getOrderId();
12014
+                    $existOrderIdList[] = $storeOrderEntity->getOrderId();
11961 12015
                 }
11962
-            }, $storeOrderEntityList);
12016
+            }
12017
+            if (empty($existOrderIdList)) {
12018
+                return;
12019
+            }
11963 12020
 
12021
+            /** 养老金 佣金 */
11964 12022
             /** @var UserBillRepository $userBillRepository */
11965 12023
             $userBillRepository = app()->make(UserBillRepository::class);
11966 12024
             $userBillEntityList = $userBillRepository->getUserBillEntityListByOrderIdListAndPending(UserBillEnum::TYPE_SHOP['Platform']['code'], $existOrderIdList);
11967 12025
             if (!empty($userBillEntityList)) {
11968 12026
                 foreach ($userBillEntityList as $userBillEntity) {
11969 12027
                     if ($userBillEntity->getCommissionType() == UserBillEnum::COMMISSION_TYPE['PENSION']['code']) {
11970
-                        // 养老金 todo
12028
+                        // 养老金
12029
+                        $userEntity = $userRepository->getUserEntityByUid($userBillEntity->getUid());
12030
+
12031
+                    } else if ($userBillEntity->getCommissionType() == UserBillEnum::COMMISSION_TYPE['DIRECT_REFERRAL']['code']) {
12032
+                        // 直推奖 佣金
11971 12033
                     }
11972 12034
                 }
11973 12035
             }

+ 2 - 0
app/common/repositories/user/UserRepository.php

@@ -4451,6 +4451,8 @@ class UserRepository extends BaseRepository
4451 4451
         return (float)$surplus;
4452 4452
     }
4453 4453
 
4454
+
4455
+
4454 4456
     /**
4455 4457
      * 更新用户Vr 并 写入Vr变动记录
4456 4458
      * @param int $uid

+ 78 - 1
app/common/repositories/user/UserSignFugouRepository.php

@@ -7,6 +7,7 @@ use app\common\enum\user\UserSignFugouEnum;
7 7
 use app\common\repositories\BaseRepository;
8 8
 use app\common\repositories\store\order\StoreOrderRepository;
9 9
 use app\entity\data\user\UserSignFugouEntity;
10
+use think\db\exception\DbException;
10 11
 use think\exception\ValidateException;
11 12
 
12 13
 class UserSignFugouRepository extends BaseRepository
@@ -16,6 +17,31 @@ class UserSignFugouRepository extends BaseRepository
16 17
         $this->dao = $dao;
17 18
     }
18 19
 
20
+    /**
21
+     * @param int $id
22
+     * @return UserSignFugouEntity
23
+     */
24
+    public function getStoreSignFugouEntityById(int $id): UserSignFugouEntity
25
+    {
26
+        $entityList = $this->getStoreSignFugouEntityListByIdList([$id]);
27
+        $entity = array_shift($entityList);
28
+        if ($entity instanceof UserSignFugouEntity) {
29
+            return $entity;
30
+        } else {
31
+            /** @var UserSignFugouEntity */
32
+            return UserSignFugouEntity::newInstance();
33
+        }
34
+    }
35
+
36
+    /**
37
+     * @param array $idList
38
+     * @return UserSignFugouEntity[]
39
+     */
40
+    public function getStoreSignFugouEntityListByIdList(array $idList): array
41
+    {
42
+        return $this->dao->getStoreSignFugouEntityListByIdList($idList);
43
+    }
44
+
19 45
     public function create($data)
20 46
     {
21 47
         return $this->dao->create($data);
@@ -39,12 +65,13 @@ class UserSignFugouRepository extends BaseRepository
39 65
      * @param int $uid
40 66
      * @param int $type
41 67
      * @param float $number
68
+     * @param int $commissionType
42 69
      * @param string $mark
43 70
      * @param string $orderType
44 71
      * @param string $orderId
45 72
      * @return UserSignFugouEntity
46 73
      */
47
-    public function addUserSingFugou(int $uid, int $type, float $number, string $mark = '', string $orderType = '', string $orderId = ''): UserSignFugouEntity
74
+    public function addUserSingFugou(int $uid, int $type, float $number, int $commissionType, string $mark = '', string $orderType = '', string $orderId = ''): UserSignFugouEntity
48 75
     {
49 76
         if (!empty($orderType)) {
50 77
             if (!empty($orderId)) {
@@ -64,6 +91,7 @@ class UserSignFugouRepository extends BaseRepository
64 91
         $userSignFugouEntity->setUid($uid)
65 92
             ->setType($type)
66 93
             ->setNumber($number)
94
+            ->setCommissionType($commissionType)
67 95
             ->setMark($mark)
68 96
             ->setOrderType($orderType)
69 97
             ->setOrderId($orderId)
@@ -72,4 +100,53 @@ class UserSignFugouRepository extends BaseRepository
72 100
 
73 101
         return $this->createByEntity($userSignFugouEntity);
74 102
     }
103
+
104
+    /**
105
+     * 将 复购 记录设置为生效状态 并对用户的 复购 字段进行增减
106
+     * @param int $id
107
+     * @return UserSignFugouEntity
108
+     */
109
+    public function execute(int $id): UserSignFugouEntity
110
+    {
111
+        $UserSignFugouEntity = $this->getStoreSignFugouEntityById($id);
112
+        if (empty($UserSignFugouEntity->getId()) || empty($UserSignFugouEntity->getUid())) {
113
+            throw new ValidateException('无效的复购记录');
114
+        }
115
+        if ($UserSignFugouEntity->getStatus() == UserSignFugouEnum::STATUS['Invalid']['code']) {
116
+            throw new ValidateException('该复购记录已失效');
117
+        }
118
+        if (!empty($UserSignFugouEntity->getSettlementTime()) || $UserSignFugouEntity->getStatus() == UserSignFugouEnum::STATUS['Valid']['code']) {
119
+            throw new ValidateException('该复购记录已更新,请勿重复操作');
120
+        }
121
+
122
+        /** @var UserRepository $userRepository */
123
+        $userRepository = app()->make(UserRepository::class);
124
+        $userEntity = $userRepository->getUserEntityByUid($UserSignFugouEntity->getUid());
125
+        if (empty($userEntity->getUid())) {
126
+            throw new ValidateException('未查询到用户信息');
127
+        }
128
+        if ($UserSignFugouEntity->getType() == UserSignFugouEnum::TYPE['Consume']['code']) {
129
+            $surplus = bcsub($userEntity->getFugou(), $UserSignFugouEntity->getNumber(), 2);
130
+            if ($surplus < 0.00) {
131
+                throw new ValidateException('用户复购不足');
132
+            }
133
+        } else {
134
+            $surplus = bcadd($userEntity->getFugou(), $UserSignFugouEntity->getNumber(), 2);
135
+        }
136
+        try {
137
+            $UserSignFugouEntity
138
+                ->setSurplus($surplus)
139
+                ->setSettlementTime(date('Y-m-d H:i:s'))
140
+                ->setStatus(UserSignFugouEnum::STATUS['Valid']['code']);
141
+            $userRepository->update($userEntity->getUid(), ['Fugou' => $surplus]);
142
+            $this->dao->update($UserSignFugouEntity->getId(), [
143
+                'surplus' => $UserSignFugouEntity->getSurplus(),
144
+                'settlement_time' => $UserSignFugouEntity->getSettlementTime(),
145
+                'status' => $UserSignFugouEntity->getStatus()
146
+            ]);
147
+        } catch (DbException $e) {
148
+
149
+        }
150
+        return $UserSignFugouEntity;
151
+    }
75 152
 }

+ 74 - 0
app/common/repositories/user/UserSignJingdouRepository.php

@@ -7,6 +7,7 @@ use app\common\enum\user\UserSignJingdouEnum;
7 7
 use app\common\repositories\BaseRepository;
8 8
 use app\common\repositories\store\order\StoreOrderRepository;
9 9
 use app\entity\data\user\UserSignJingdouEntity;
10
+use think\db\exception\DbException;
10 11
 use think\exception\ValidateException;
11 12
 
12 13
 class UserSignJingdouRepository extends BaseRepository
@@ -16,6 +17,31 @@ class UserSignJingdouRepository extends BaseRepository
16 17
         $this->dao = $dao;
17 18
     }
18 19
 
20
+    /**
21
+     * @param int $id
22
+     * @return UserSignJingdouEntity
23
+     */
24
+    public function getStoreSignJingdouEntityById(int $id): UserSignJingdouEntity
25
+    {
26
+        $entityList = $this->getStoreSignJingdouEntityListByIdList([$id]);
27
+        $entity = array_shift($entityList);
28
+        if ($entity instanceof UserSignJingdouEntity) {
29
+            return $entity;
30
+        } else {
31
+            /** @var UserSignJingdouEntity */
32
+            return UserSignJingdouEntity::newInstance();
33
+        }
34
+    }
35
+
36
+    /**
37
+     * @param array $idList
38
+     * @return UserSignJingdouEntity[]
39
+     */
40
+    public function getStoreSignJingdouEntityListByIdList(array $idList): array
41
+    {
42
+        return $this->dao->getStoreSignJingdouEntityListByIdList($idList);
43
+    }
44
+
19 45
     public function create($data)
20 46
     {
21 47
         return $this->dao->create($data);
@@ -39,6 +65,7 @@ class UserSignJingdouRepository extends BaseRepository
39 65
      * @param int $uid
40 66
      * @param int $type
41 67
      * @param float $number
68
+     * @param int $merId
42 69
      * @param string $mark
43 70
      * @param string $orderType
44 71
      * @param string $orderId
@@ -73,4 +100,51 @@ class UserSignJingdouRepository extends BaseRepository
73 100
 
74 101
         return $this->createByEntity($userSignJingdouEntity);
75 102
     }
103
+
104
+    /**
105
+     * 将 京豆 记录设置为生效状态 并对用户的 京豆 字段进行增减
106
+     * @param int $id
107
+     * @return UserSignJingdouEntity
108
+     */
109
+    public function execute(int $id): UserSignJingdouEntity
110
+    {
111
+        $UserSignJingdouEntity = $this->getStoreSignJingdouEntityById($id);
112
+        if (empty($UserSignJingdouEntity->getId()) || empty($UserSignJingdouEntity->getUid())) {
113
+            throw new ValidateException('无效的积分记录');
114
+        }
115
+        if ($UserSignJingdouEntity->getStatus() == UserSignJingdouEnum::STATUS['Invalid']['code']) {
116
+            throw new ValidateException('该积分记录已失效');
117
+        }
118
+        if (!empty($UserSignJingdouEntity->getSettlementTime()) || $UserSignJingdouEntity->getStatus() == UserSignJingdouEnum::STATUS['Valid']['code']) {
119
+            throw new ValidateException('该积分记录已更新,请勿重复操作');
120
+        }
121
+
122
+        /** @var UserRepository $userRepository */
123
+        $userRepository = app()->make(UserRepository::class);
124
+        $userEntity = $userRepository->getUserEntityByUid($UserSignJingdouEntity->getUid());
125
+        if (empty($userEntity->getUid())) {
126
+            throw new ValidateException('未查询到用户信息');
127
+        }
128
+        if ($UserSignJingdouEntity->getType() == UserSignJingdouEnum::TYPE['Consume']['code']) {
129
+            $surplus = bcsub($userEntity->getJingdou(), $UserSignJingdouEntity->getNumber(), 2);
130
+            if ($surplus < 0.00) {
131
+                throw new ValidateException('用户京豆不足');
132
+            }
133
+        } else {
134
+            $surplus = bcadd($userEntity->getJingdou(), $UserSignJingdouEntity->getNumber(), 2);
135
+        }
136
+        try {
137
+            $UserSignJingdouEntity
138
+                ->setSurplus($surplus)
139
+                ->setSettlementTime(date('Y-m-d H:i:s'));
140
+            $userRepository->update($userEntity->getUid(), ['jingdou' => $surplus]);
141
+            $this->dao->update($UserSignJingdouEntity->getId(), [
142
+                'surplus' => $UserSignJingdouEntity->getSurplus(),
143
+                'settlement_time' => $UserSignJingdouEntity->getSettlementTime()
144
+            ]);
145
+        } catch (DbException $e) {
146
+
147
+        }
148
+        return $UserSignJingdouEntity;
149
+    }
76 150
 }

+ 76 - 1
app/common/repositories/user/UserSignScoreRepository.php

@@ -7,6 +7,7 @@ use app\common\enum\user\UserSignScoreEnum;
7 7
 use app\common\repositories\BaseRepository;
8 8
 use app\common\repositories\store\order\StoreOrderRepository;
9 9
 use app\entity\data\user\UserSignScoreEntity;
10
+use think\db\exception\DbException;
10 11
 use think\exception\ValidateException;
11 12
 
12 13
 class UserSignScoreRepository extends BaseRepository
@@ -22,7 +23,32 @@ class UserSignScoreRepository extends BaseRepository
22 23
     }
23 24
 
24 25
     /**
25
-     * 写入贡献值记录
26
+     * @param int $id
27
+     * @return UserSignScoreEntity
28
+     */
29
+    public function getStoreSignScoreEntityById(int $id): UserSignScoreEntity
30
+    {
31
+        $entityList = $this->getStoreSignScoreEntityListByIdList([$id]);
32
+        $entity = array_shift($entityList);
33
+        if ($entity instanceof UserSignScoreEntity) {
34
+            return $entity;
35
+        } else {
36
+            /** @var UserSignScoreEntity */
37
+            return UserSignScoreEntity::newInstance();
38
+        }
39
+    }
40
+
41
+    /**
42
+     * @param array $idList
43
+     * @return UserSignScoreEntity[]
44
+     */
45
+    public function getStoreSignScoreEntityListByIdList(array $idList): array
46
+    {
47
+        return $this->dao->getStoreSignScoreEntityListByIdList($idList);
48
+    }
49
+
50
+    /**
51
+     * 写入积分记录
26 52
      * @param UserSignScoreEntity $userSignScoreEntity
27 53
      * @return UserSignScoreEntity
28 54
      */
@@ -75,4 +101,53 @@ class UserSignScoreRepository extends BaseRepository
75 101
 
76 102
         return $this->createByEntity($userSignScoreEntity);
77 103
     }
104
+
105
+    /**
106
+     * 将 积分 记录设置为生效状态 并对用户的 积分 字段进行增减
107
+     * @param int $id
108
+     * @return UserSignScoreEntity
109
+     */
110
+    public function execute(int $id): UserSignScoreEntity
111
+    {
112
+        $userSignScoreEntity = $this->getStoreSignScoreEntityById($id);
113
+        if (empty($userSignScoreEntity->getId()) || empty($userSignScoreEntity->getUid())) {
114
+            throw new ValidateException('无效的积分记录');
115
+        }
116
+        if ($userSignScoreEntity->getStatus() == UserSignScoreEnum::STATUS['Invalid']['code']) {
117
+            throw new ValidateException('该积分记录已失效');
118
+        }
119
+        if (!empty($userSignScoreEntity->getSettlementTime()) || $userSignScoreEntity->getStatus() == UserSignScoreEnum::STATUS['Valid']['code']) {
120
+            throw new ValidateException('该积分记录已更新,请勿重复操作');
121
+        }
122
+
123
+        /** @var UserRepository $userRepository */
124
+        $userRepository = app()->make(UserRepository::class);
125
+        $userEntity = $userRepository->getUserEntityByUid($userSignScoreEntity->getUid());
126
+        if (empty($userEntity->getUid())) {
127
+            throw new ValidateException('未查询到用户信息');
128
+        }
129
+        if ($userSignScoreEntity->getPm() == UserSignScoreEnum::PM['Expend']['code']) {
130
+            $surplus = bcsub($userEntity->getScore(), $userSignScoreEntity->getRewardScore(), 2);
131
+            if ($surplus < 0.00) {
132
+                throw new ValidateException('用户积分不足');
133
+            }
134
+        } else {
135
+            $surplus = bcadd($userEntity->getScore(), $userSignScoreEntity->getRewardScore(), 2);
136
+        }
137
+        try {
138
+            $userSignScoreEntity
139
+                ->setSurplus($surplus)
140
+                ->setSettlementTime(date('Y-m-d H:i:s'))
141
+                ->setStatus(UserSignScoreEnum::STATUS['Valid']['code']);
142
+            $userRepository->update($userEntity->getUid(), ['score' => $surplus]);
143
+            $this->dao->update($userSignScoreEntity->getId(), [
144
+                'surplus' => $userSignScoreEntity->getSurplus(),
145
+                'settlement_time' => $userSignScoreEntity->getSettlementTime(),
146
+                'status' => $userSignScoreEntity->getStatus()
147
+            ]);
148
+        } catch (DbException $e) {
149
+
150
+        }
151
+        return $userSignScoreEntity;
152
+    }
78 153
 }

+ 126 - 0
app/common/repositories/user/UserSignVrRepository.php

@@ -3,7 +3,12 @@
3 3
 namespace app\common\repositories\user;
4 4
 
5 5
 use app\common\dao\user\UserSignVrDao;
6
+use app\common\enum\user\UserSignVrEnum;
6 7
 use app\common\repositories\BaseRepository;
8
+use app\common\repositories\store\order\StoreOrderRepository;
9
+use app\entity\data\user\UserSignVrEntity;
10
+use think\db\exception\DbException;
11
+use think\exception\ValidateException;
7 12
 
8 13
 class UserSignVrRepository extends BaseRepository
9 14
 {
@@ -16,4 +21,125 @@ class UserSignVrRepository extends BaseRepository
16 21
     {
17 22
         return $this->dao->create($data);
18 23
     }
24
+
25
+    /**
26
+     * @param int $id
27
+     * @return UserSignVrEntity
28
+     */
29
+    public function getStoreSignVrEntityById(int $id): UserSignVrEntity
30
+    {
31
+        $entityList = $this->getStoreSignVrEntityListByIdList([$id]);
32
+        $entity = array_shift($entityList);
33
+        if ($entity instanceof UserSignVrEntity) {
34
+            return $entity;
35
+        } else {
36
+            /** @var UserSignVrEntity */
37
+            return UserSignVrEntity::newInstance();
38
+        }
39
+    }
40
+
41
+    /**
42
+     * @param array $idList
43
+     * @return UserSignVrEntity[]
44
+     */
45
+    public function getStoreSignVrEntityListByIdList(array $idList): array
46
+    {
47
+        return $this->dao->getStoreSignVrEntityListByIdList($idList);
48
+    }
49
+
50
+    /**
51
+     * 写入Vr记录
52
+     * @param UserSignVrEntity $userSignVrEntity
53
+     * @return UserSignVrEntity
54
+     */
55
+    public function createByEntity(UserSignVrEntity $userSignVrEntity): UserSignVrEntity
56
+    {
57
+        $result = $this->dao->create($userSignVrEntity->toUnderlineArray())->toArray();
58
+        /** @var UserSignVrEntity $entity */
59
+        $entity = UserSignVrEntity::newInstance($result);
60
+        return $entity;
61
+    }
62
+
63
+    /**
64
+     * 添加Vr记录
65
+     * @param int $uid
66
+     * @param int $type
67
+     * @param float $number
68
+     * @param string $mark
69
+     * @param string $orderType
70
+     * @param string $orderId
71
+     * @return UserSignVrEntity
72
+     */
73
+    public function addUserSingVr(int $uid, int $type, float $number, string $mark = '', string $orderType = '', string $orderId = ''): UserSignVrEntity
74
+    {
75
+        if (!empty($orderType)) {
76
+            if (!empty($orderId)) {
77
+                if ($orderType == UserSignVrEnum::ORDER_TYPE['Platform']['code']) {
78
+                    /** @var StoreOrderRepository $storeOrderRepository */
79
+                    $storeOrderRepository = app()->make(StoreOrderRepository::class);
80
+                    $storeOrderEntity = $storeOrderRepository->getStoreOrderEntityByOrderId((int)$orderId);
81
+                    if (empty($storeOrderEntity->getOrderId())) {
82
+                        throw new ValidateException('未查询到订单信息');
83
+                    }
84
+                }
85
+            }
86
+        }
87
+
88
+        /** @var UserSignVrEntity $userSignVrEntity */
89
+        $userSignVrEntity = UserSignVrEntity::newInstance();
90
+        $userSignVrEntity->setUid($uid)
91
+            ->setType($type)
92
+            ->setNumber($number)
93
+            ->setMark($mark)
94
+            ->setOrderType($orderType)
95
+            ->setOrderId($orderId)
96
+            ->setSurplus(0.00)
97
+            ->setAddtime(time());
98
+
99
+        return $this->createByEntity($userSignVrEntity);
100
+    }
101
+
102
+    /**
103
+     * 将 Vr 记录设置为生效状态 并对用户的 Vr 字段进行增减
104
+     * @param int $id
105
+     * @return UserSignVrEntity
106
+     */
107
+    public function execute(int $id): UserSignVrEntity
108
+    {
109
+        $userSignVrEntity = $this->getStoreSignVrEntityById($id);
110
+        if (empty($userSignVrEntity->getId()) || empty($userSignVrEntity->getUid())) {
111
+            throw new ValidateException('无效的Vr记录');
112
+        }
113
+        if (!empty($userSignVrEntity->getSettlementTime())) {
114
+            throw new ValidateException('该Vr记录已更新,请勿重复操作');
115
+        }
116
+
117
+        /** @var UserRepository $userRepository */
118
+        $userRepository = app()->make(UserRepository::class);
119
+        $userEntity = $userRepository->getUserEntityByUid($userSignVrEntity->getUid());
120
+        if (empty($userEntity->getUid())) {
121
+            throw new ValidateException('未查询到用户信息');
122
+        }
123
+        if ($userSignVrEntity->getType() == UserSignVrEnum::TYPE['Consume']['code']) {
124
+            $surplus = bcsub($userEntity->getVr(), $userSignVrEntity->getNumber(), 2);
125
+            if ($surplus < 0.00) {
126
+                throw new ValidateException('用户VR不足');
127
+            }
128
+        } else {
129
+            $surplus = bcadd($userEntity->getVr(), $userSignVrEntity->getNumber(), 2);
130
+        }
131
+        try {
132
+            $userSignVrEntity
133
+                ->setSurplus($surplus)
134
+                ->setSettlementTime(date('Y-m-d H:i:s'));
135
+            $userRepository->update($userEntity->getUid(), ['vr' => $surplus]);
136
+            $this->dao->update($userSignVrEntity->getId(), [
137
+                'surplus' => $userSignVrEntity->getSurplus(),
138
+                'settlement_time' => $userSignVrEntity->getSettlementTime()
139
+            ]);
140
+        } catch (DbException $e) {
141
+
142
+        }
143
+        return $userSignVrEntity;
144
+    }
19 145
 }