Преглед изворни кода

提现额度-原来只有共富区有提现额度,现需要全平台消费都发放提现额度,把提现额度从共富区奖励表拆出,单独建表;

sunxbiao пре 5 месеци
родитељ
комит
2059d2b0f0

+ 13 - 0
app/command/PensionTasks.php

@@ -4,6 +4,7 @@ declare (strict_types=1);
4 4
 namespace app\command;
5 5
 
6 6
 use app\common\enum\CommonEnum;
7
+use app\common\enum\user\UserWithdrawalLimitRecordEnum;
7 8
 use app\common\model\merchant\order\OrderMerchant;
8 9
 use app\common\model\store\order\StoreOrder;
9 10
 use app\common\model\user\User;
@@ -15,6 +16,7 @@ use app\common\repositories\store\order\StoreOrderStatusRepository;
15 16
 use app\common\repositories\store\product\ProductRepository;
16 17
 use app\common\repositories\user\UserBillRepository;
17 18
 use app\common\repositories\user\UserRepository;
19
+use app\common\repositories\user\UserWithdrawalLimitRecordRepository;
18 20
 use app\entity\data\shared\SharedProsperityUserEntity;
19 21
 use app\traits\GzcApiRequest;
20 22
 use Carbon\Carbon;
@@ -1798,6 +1800,17 @@ class PensionTasks extends Command
1798 1800
      */
1799 1801
     public function settleAward($online,$order_type)
1800 1802
     {
1803
+        /** 结算 提现佣金 */
1804
+        /** @var UserWithdrawalLimitRecordRepository $userWithdrawalLimitRecordRepository */
1805
+        $userWithdrawalLimitRecordRepository = app()->make(UserWithdrawalLimitRecordRepository::class);
1806
+        $userWithdrawalLimitRecordEntityList = $userWithdrawalLimitRecordRepository->getUserWithdrawalLimitRecordEntityListByOrderSnListAndPending((string)$order_type, [$online['order_sn']]);
1807
+        if (!empty($userWithdrawalLimitRecordEntityList)) {
1808
+            $userWithdrawalLimitRecordIdList = array_map(function ($userWithdrawalLimitRecordEntity) {
1809
+                return $userWithdrawalLimitRecordEntity->getId();
1810
+            }, $userWithdrawalLimitRecordEntityList);
1811
+            $userWithdrawalLimitRecordRepository->executeByIdList($userWithdrawalLimitRecordIdList);
1812
+        }
1813
+
1801 1814
         // 结算积分
1802 1815
         $user_sign_score_list = Db::name('user_sign_score')
1803 1816
             ->where('status', -1)

+ 92 - 0
app/common/dao/user/UserWithdrawalLimitRecordDao.php

@@ -0,0 +1,92 @@
1
+<?php
2
+
3
+namespace app\common\dao\user;
4
+
5
+use app\common\dao\BaseDao;
6
+use app\common\enum\user\UserWithdrawalLimitRecordEnum;
7
+use app\common\model\BaseModel;
8
+use app\common\model\user\UserWithdrawalLimitRecord;
9
+use app\entity\data\user\UserWithdrawalLimitRecordEntity;
10
+use think\db\exception\DataNotFoundException;
11
+use think\db\exception\DbException;
12
+use think\db\exception\ModelNotFoundException;
13
+
14
+class UserWithdrawalLimitRecordDao extends BaseDao
15
+{
16
+    /**
17
+     * @return BaseModel
18
+     */
19
+    protected function getModel(): string
20
+    {
21
+        return UserWithdrawalLimitRecord::class;
22
+    }
23
+
24
+    /**
25
+     * @param array $idList
26
+     * @return UserWithdrawalLimitRecordEntity[]
27
+     */
28
+    public function getUserWithdrawalLimitRecordEntityListByIdList(array $idList): array
29
+    {
30
+        $entityList = [];
31
+        try {
32
+            /** @var UserWithdrawalLimitRecord $model */
33
+            $model = $this->getModel();
34
+            $dataRes = $model::getDB()
35
+                ->whereIn('id', $idList)
36
+                ->select()
37
+                ->toArray();
38
+            if (!empty($dataRes)) {
39
+                $entityList = array_map(function ($data) {
40
+                    return UserWithdrawalLimitRecordEntity::newInstance($data);
41
+                }, $dataRes);
42
+            }
43
+        } catch (\Exception $e) {
44
+
45
+        }
46
+        return $entityList;
47
+    }
48
+
49
+    /**
50
+     * 批量更新
51
+     * @param $dataList
52
+     * @return array
53
+     */
54
+    public function saveAll($dataList): array
55
+    {
56
+        try {
57
+            return $this->getModel()::getInstance()->allowField(array_keys(reset($dataList)))->saveAll($dataList)->toArray();
58
+        } catch (\Exception $e) {
59
+            return [];
60
+        }
61
+    }
62
+
63
+    /**
64
+     * @param string $typeShop
65
+     * @param array $orderSnList
66
+     * @return UserWithdrawalLimitRecordEntity[]
67
+     */
68
+    public function getUserWithdrawalLimitRecordEntityListByOrderSnListAndPending(string $typeShop, array $orderSnList): array
69
+    {
70
+        $entityList = [];
71
+        try {
72
+            /** @var UserWithdrawalLimitRecord $model */
73
+            $model = $this->getModel();
74
+            $dataList = $model::getDB()
75
+                ->where('type_shop', '=', $typeShop)
76
+                ->whereIn('order_sn', $orderSnList)
77
+                ->where('status', '=', UserWithdrawalLimitRecordEnum::STATUS['PENDING']['code'])
78
+                ->select()
79
+                ->toArray();
80
+
81
+            if (!empty($dataList)) {
82
+                $entityList = array_map(function ($data) {
83
+                    return UserWithdrawalLimitRecordEntity::newInstance($data);
84
+                }, $dataList);
85
+            }
86
+        } catch (DataNotFoundException|ModelNotFoundException|DbException $e) {
87
+
88
+        }
89
+        return $entityList;
90
+    }
91
+
92
+}

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

@@ -82,6 +82,9 @@ class CommonEnum
82 82
     // 平台手续费(汇付通道服务费)
83 83
     const HUIFU_COMMISSION_CHARGE = 0.0038;
84 84
 
85
+    // 提现额度比例 ['SharedProsperity']['Self']['WithdrawalLimit']['Ratio']['code']
86
+    const WITHDRAWAL_LIMIT_RATIO = 5;
87
+
85 88
     // 订单 收益 的分配
86 89
     const ORDER_EARNING_ALLOCATION = [
87 90
         // 精彩生活区

+ 24 - 0
app/common/enum/user/UserWithdrawalLimitRecordEnum.php

@@ -0,0 +1,24 @@
1
+<?php
2
+
3
+namespace app\common\enum\user;
4
+
5
+use app\common\enum\CommonEnum;
6
+
7
+class UserWithdrawalLimitRecordEnum extends CommonEnum
8
+{
9
+    // 收支类型
10
+    const PM = [
11
+        'EXPEND' => ['code' => 0, 'name' => '支出'],
12
+        'INCOME' => ['code' => 1, 'name' => '获得'],
13
+    ];
14
+
15
+    // 状态
16
+    const STATUS = [
17
+        'PENDING' => ['code' => 0, 'name' => '待确定'],
18
+        'VALID' => ['code' => 1, 'name' => '有效'],
19
+        'INVALID' => ['code' => -1, 'name' => '无效'],
20
+    ];
21
+
22
+    // 类型商店
23
+    const TYPE_SHOP = parent::ORDER_TYPE;
24
+}

+ 18 - 0
app/common/model/user/UserWithdrawalLimitRecord.php

@@ -0,0 +1,18 @@
1
+<?php
2
+
3
+namespace app\common\model\user;
4
+
5
+use app\common\model\BaseModel;
6
+
7
+class UserWithdrawalLimitRecord extends BaseModel
8
+{
9
+    public static function tablePk(): ?string
10
+    {
11
+        return 'id';
12
+    }
13
+
14
+    public static function tableName(): string
15
+    {
16
+        return 'user_withdrawal_limit_records';
17
+    }
18
+}

+ 38 - 13
app/common/repositories/store/order/StoreOrderRepository.php

@@ -42,6 +42,7 @@ use app\common\enum\user\UserSignHongbaoEnum;
42 42
 use app\common\enum\user\UserSignJingdouEnum;
43 43
 use app\common\enum\user\UserSignScoreEnum;
44 44
 use app\common\enum\user\UserSignVrEnum;
45
+use app\common\enum\user\UserWithdrawalLimitRecordEnum;
45 46
 use app\common\model\store\order\StoreGroupOrder;
46 47
 use app\common\model\store\order\StoreOrder;
47 48
 use app\common\model\store\order\StoreRefundOrder;
@@ -86,6 +87,7 @@ use app\common\repositories\user\UserSignJingdouRepository;
86 87
 use app\common\repositories\user\UserSignScoreRepository;
87 88
 use app\common\repositories\user\UserSignVrRepository;
88 89
 use app\common\repositories\user\UserThirdRepository;
90
+use app\common\repositories\user\UserWithdrawalLimitRecordRepository;
89 91
 use app\common\repositories\wechat\RoutineQrcodeRepository;
90 92
 use app\common\repositories\wechat\WechatUserRepository;
91 93
 use app\controller\api\user\Volunteer;
@@ -11671,19 +11673,19 @@ class StoreOrderRepository extends BaseRepository
11671 11673
                 '购买共富区商品获得消费股'
11672 11674
             );
11673 11675
 
11674
-            // 发放提现额度
11675
-            $withdrawalLimit = bcmul($storeOrderEntity->getTotalPrice(), CommonEnum::ORDER_EARNING_ALLOCATION['SharedProsperity']['Self']['WithdrawalLimit']['Ratio']['code'], CommonEnum::DECIMAL_PLACES_OF_THE_AMOUNT);
11676
-            /** @var SharedProsperityRewardRecordRepository $sharedProsperityRewardRecordRepository */
11677
-            $sharedProsperityRewardRecordRepository = app()->make(SharedProsperityRewardRecordRepository::class);
11678
-            $sharedProsperityRewardRecordRepository->addSharedProsperityRewardRecord(
11679
-                $sharedProsperityUserEntity->getUserId(),
11680
-                SharedProsperityRewardRecordEnum::TYPE['WITHDRAWAL_LIMIT']['code'],
11681
-                SharedProsperityRewardRecordEnum::PM['INCOME']['code'],
11682
-                $withdrawalLimit,
11683
-                SharedProsperityRewardRecordEnum::TYPE_SHOP['Platform']['code'],
11684
-                $storeOrderEntity->getOrderSn(),
11685
-                '购买共富区商品获得提现额度'
11686
-            );
11676
+            // 发放提现额度 此处不再发放,原来只有购买共富区商品才发放该奖励,现在单独把他查出一张表来,每个区域购买商品 都发放提现额度,所以把他放在最外边
11677
+            // $withdrawalLimit = bcmul($storeOrderEntity->getTotalPrice(), CommonEnum::ORDER_EARNING_ALLOCATION['SharedProsperity']['Self']['WithdrawalLimit']['Ratio']['code'], CommonEnum::DECIMAL_PLACES_OF_THE_AMOUNT);
11678
+            // /** @var SharedProsperityRewardRecordRepository $sharedProsperityRewardRecordRepository */
11679
+            // $sharedProsperityRewardRecordRepository = app()->make(SharedProsperityRewardRecordRepository::class);
11680
+            // $sharedProsperityRewardRecordRepository->addSharedProsperityRewardRecord(
11681
+            //     $sharedProsperityUserEntity->getUserId(),
11682
+            //     SharedProsperityRewardRecordEnum::TYPE['WITHDRAWAL_LIMIT']['code'],
11683
+            //     SharedProsperityRewardRecordEnum::PM['INCOME']['code'],
11684
+            //     $withdrawalLimit,
11685
+            //     SharedProsperityRewardRecordEnum::TYPE_SHOP['Platform']['code'],
11686
+            //     $storeOrderEntity->getOrderSn(),
11687
+            //     '购买共富区商品获得提现额度'
11688
+            // );
11687 11689
 
11688 11690
             // 发放共富区PV
11689 11691
             /** @var SharedProsperityRecommendConfigRepository $sharedProsperityRecommendConfigRepository */
@@ -12028,6 +12030,18 @@ class StoreOrderRepository extends BaseRepository
12028 12030
                 );
12029 12031
             }
12030 12032
         }
12033
+
12034
+        $withdrawalLimit = bcmul($storeOrderEntity->getTotalPrice(), CommonEnum::WITHDRAWAL_LIMIT_RATIO, CommonEnum::DECIMAL_PLACES_OF_THE_AMOUNT);
12035
+        /** @var UserWithdrawalLimitRecordRepository $userWithdrawalLimitRecordRepository */
12036
+        $userWithdrawalLimitRecordRepository = app()->make(UserWithdrawalLimitRecordRepository::class);
12037
+        $userWithdrawalLimitRecordRepository->addUserWithdrawalLimitRecord(
12038
+            $userEntity->getUid(),
12039
+            UserWithdrawalLimitRecordEnum::PM['INCOME']['code'],
12040
+            $withdrawalLimit,
12041
+            UserWithdrawalLimitRecordEnum::TYPE_SHOP['Platform']['code'],
12042
+            $storeOrderEntity->getOrderSn(),
12043
+            '消费获得提现额度'
12044
+        );
12031 12045
     }
12032 12046
 
12033 12047
     /**
@@ -12157,6 +12171,17 @@ class StoreOrderRepository extends BaseRepository
12157 12171
                         $sharedProsperityUserRepository->identityUpgrade($affectedUserIdListBySharedProsperity);
12158 12172
                     }
12159 12173
                 }
12174
+
12175
+                /** 结算 提现佣金 */
12176
+                /** @var UserWithdrawalLimitRecordRepository $userWithdrawalLimitRecordRepository */
12177
+                $userWithdrawalLimitRecordRepository = app()->make(UserWithdrawalLimitRecordRepository::class);
12178
+                $userWithdrawalLimitRecordEntityList = $userWithdrawalLimitRecordRepository->getUserWithdrawalLimitRecordEntityListByOrderSnListAndPending(UserWithdrawalLimitRecordEnum::TYPE_SHOP['Platform']['code'], $unsettledOrderSnList);
12179
+                if (!empty($userWithdrawalLimitRecordEntityList)) {
12180
+                    $userWithdrawalLimitRecordIdList = array_map(function ($userWithdrawalLimitRecordEntity) {
12181
+                        return $userWithdrawalLimitRecordEntity->getId();
12182
+                    }, $userWithdrawalLimitRecordEntityList);
12183
+                    $userWithdrawalLimitRecordRepository->executeByIdList($userWithdrawalLimitRecordIdList);
12184
+                }
12160 12185
             } catch (DbException $e) {
12161 12186
                 throw new ValidateException('订单结算失败');
12162 12187
             }

+ 15 - 0
app/common/repositories/user/UserThirdRepository.php

@@ -11,7 +11,9 @@
11 11
 namespace app\common\repositories\user;
12 12
 
13 13
 use app\common\dao\user\UserThirdDao;
14
+use app\common\enum\CommonEnum;
14 15
 use app\common\enum\shared\SharedProsperityRewardRecordEnum;
16
+use app\common\enum\user\UserWithdrawalLimitRecordEnum;
15 17
 use app\common\model\user\User;
16 18
 use app\common\repositories\BaseRepository;
17 19
 
@@ -770,6 +772,19 @@ class UserThirdRepository extends BaseRepository
770 772
         Db::name('log')->insert(['data' => "type_shop:{$type_shop}, $order_sn, $order_sn, 赠送积分, $price"]);
771 773
 
772 774
         try {
775
+            // 所有第三方所下订单,消费者获得 提现额度
776
+            $withdrawalLimit = bcmul($price, CommonEnum::WITHDRAWAL_LIMIT_RATIO, CommonEnum::DECIMAL_PLACES_OF_THE_AMOUNT);
777
+            /** @var UserWithdrawalLimitRecordRepository $userWithdrawalLimitRecordRepository */
778
+            $userWithdrawalLimitRecordRepository = app()->make(UserWithdrawalLimitRecordRepository::class);
779
+            $userWithdrawalLimitRecordRepository->addUserWithdrawalLimitRecord(
780
+                (int)$user_id,
781
+                UserWithdrawalLimitRecordEnum::PM['INCOME']['code'],
782
+                (float)$withdrawalLimit,
783
+                (int)$type_shop,
784
+                $order_sn,
785
+                '消费获得提现额度'
786
+            );
787
+
773 788
             //更新用户积分
774 789
 
775 790
             $user = Db::name('user')->where('uid', $user_id)->find();

+ 248 - 0
app/common/repositories/user/UserWithdrawalLimitRecordRepository.php

@@ -0,0 +1,248 @@
1
+<?php
2
+
3
+namespace app\common\repositories\user;
4
+
5
+use app\common\dao\user\UserWithdrawalLimitRecordDao;
6
+use app\common\enum\user\UserWithdrawalLimitRecordEnum;
7
+use app\common\repositories\BaseRepository;
8
+use app\common\repositories\store\order\StoreOrderRepository;
9
+use app\entity\data\user\UserEntity;
10
+use app\entity\data\user\UserWithdrawalLimitRecordEntity;
11
+use think\db\exception\DbException;
12
+use think\exception\ValidateException;
13
+
14
+class UserWithdrawalLimitRecordRepository extends BaseRepository
15
+{
16
+
17
+    protected $dao;
18
+
19
+    /**
20
+     * UserWithdrawalLimitRecordRepository constructor.
21
+     * @param UserWithdrawalLimitRecordDao $dao
22
+     */
23
+    public function __construct(UserWithdrawalLimitRecordDao $dao)
24
+    {
25
+        $this->dao = $dao;
26
+    }
27
+
28
+    /**
29
+     * @param int $id
30
+     * @return UserWithdrawalLimitRecordEntity
31
+     */
32
+    public function getUserWithdrawalLimitRecordEntityById(int $id): UserWithdrawalLimitRecordEntity
33
+    {
34
+        $entityList = $this->getUserWithdrawalLimitRecordEntityListByIdList([$id]);
35
+        $entity = array_shift($entityList);
36
+        if ($entity instanceof UserWithdrawalLimitRecordEntity) {
37
+            return $entity;
38
+        } else {
39
+            /** @var UserWithdrawalLimitRecordEntity */
40
+            return UserWithdrawalLimitRecordEntity::newInstance();
41
+        }
42
+    }
43
+
44
+    /**
45
+     * @param array $idList
46
+     * @return UserWithdrawalLimitRecordEntity[]
47
+     */
48
+    public function getUserWithdrawalLimitRecordEntityListByIdList(array $idList): array
49
+    {
50
+        return $this->dao->getUserWithdrawalLimitRecordEntityListByIdList($idList);
51
+    }
52
+
53
+    public function create($data)
54
+    {
55
+        return $this->dao->create($data);
56
+    }
57
+
58
+    /**
59
+     * @param UserWithdrawalLimitRecordEntity $userWithdrawalLimitRecordEntity
60
+     * @return UserWithdrawalLimitRecordEntity
61
+     */
62
+    public function createByEntity(UserWithdrawalLimitRecordEntity $userWithdrawalLimitRecordEntity): UserWithdrawalLimitRecordEntity
63
+    {
64
+        $result = $this->create($userWithdrawalLimitRecordEntity->toUnderlineArray())->toArray();
65
+        /** @var UserWithdrawalLimitRecordEntity $entity */
66
+        $entity = UserWithdrawalLimitRecordEntity::newInstance($result);
67
+        return $entity;
68
+    }
69
+
70
+    /**
71
+     * @param $id
72
+     * @param $data
73
+     * @return int
74
+     */
75
+    public function update($id, $data): int
76
+    {
77
+        try {
78
+            return $this->dao->update($id, $data);
79
+        } catch (DbException $e) {
80
+            return 0;
81
+        }
82
+    }
83
+
84
+    /**
85
+     * @param UserWithdrawalLimitRecordEntity $userWithdrawalLimitRecordEntity
86
+     * @return UserWithdrawalLimitRecordEntity
87
+     */
88
+    public function updateByEntity(UserWithdrawalLimitRecordEntity $userWithdrawalLimitRecordEntity): UserWithdrawalLimitRecordEntity
89
+    {
90
+        if (empty($userWithdrawalLimitRecordEntity->getId())) {
91
+            return UserWithdrawalLimitRecordEntity::newInstance();
92
+        }
93
+        $result = $this->update($userWithdrawalLimitRecordEntity->getId(), $userWithdrawalLimitRecordEntity->toUnderlineArray());
94
+        if ($result > 0) {
95
+            return $this->getUserWithdrawalLimitRecordEntityById($userWithdrawalLimitRecordEntity->getId());
96
+        }
97
+        return UserWithdrawalLimitRecordEntity::newInstance();
98
+    }
99
+
100
+    /**
101
+     * 添加 提现额度
102
+     * @param int $uid
103
+     * @param int $pm
104
+     * @param float $number
105
+     * @param int $typeShop
106
+     * @param string $orderSn
107
+     * @param string $remark
108
+     * @return UserWithdrawalLimitRecordEntity
109
+     */
110
+    public function addUserWithdrawalLimitRecord(int $uid, int $pm, float $number, int $typeShop = 0, string $orderSn = '', string $remark = ''): UserWithdrawalLimitRecordEntity
111
+    {
112
+        if ($typeShop == UserWithdrawalLimitRecordEnum::TYPE_SHOP['Platform']['code']) {
113
+            /** @var StoreOrderRepository $storeOrderRepository */
114
+            $storeOrderRepository = app()->make(StoreOrderRepository::class);
115
+            $storeOrderEntity = $storeOrderRepository->getStoreOrderEntityByOrderSn($orderSn);
116
+            if (empty($storeOrderEntity->getOrderId())) {
117
+                throw new ValidateException('未查询到订单信息');
118
+            }
119
+        }
120
+
121
+        /** @var UserWithdrawalLimitRecordEntity $userWithdrawalLimitRecordEntity */
122
+        $userWithdrawalLimitRecordEntity = UserWithdrawalLimitRecordEntity::newInstance();
123
+        $userWithdrawalLimitRecordEntity->setUserId($uid)
124
+            ->setPm($pm)
125
+            ->setNumber($number)
126
+            ->setStatus(UserWithdrawalLimitRecordEnum::STATUS['PENDING']['code'])
127
+            ->setTypeShop($typeShop)
128
+            ->setOrderSn($orderSn)
129
+            ->setRemark($remark);
130
+
131
+        return $this->createByEntity($userWithdrawalLimitRecordEntity);
132
+    }
133
+
134
+    /**
135
+     * @param string $typeShop
136
+     * @param array $orderSnList
137
+     * @return UserWithdrawalLimitRecordEntity[]
138
+     */
139
+    public function getUserWithdrawalLimitRecordEntityListByOrderSnListAndPending(string $typeShop, array $orderSnList): array
140
+    {
141
+        return $this->dao->getUserWithdrawalLimitRecordEntityListByOrderSnListAndPending($typeShop, $orderSnList);
142
+    }
143
+
144
+    /**
145
+     * @param $dataList
146
+     * @return array
147
+     */
148
+    public function batchUpdateUserWithdrawalLimitRecordDataByDataList($dataList): array
149
+    {
150
+        return $this->dao->saveAll($dataList);
151
+    }
152
+
153
+    /**
154
+     * 结算 提现额度
155
+     * @param array $idList
156
+     * @return array
157
+     */
158
+    public function executeByIdList(array $idList): array
159
+    {
160
+        $userWithdrawalLimitRecordEntityList = $this->getUserWithdrawalLimitRecordEntityListByIdList($idList);
161
+        // 忽略 已经生效的 记录
162
+        $userWithdrawalLimitRecordEntityList = array_filter($userWithdrawalLimitRecordEntityList, function ($entity) {
163
+            return $entity->getStatus() != UserWithdrawalLimitRecordEnum::STATUS['VALID']['code'];
164
+        });
165
+
166
+        if (!empty($userWithdrawalLimitRecordEntityList)) {
167
+            // 获取所有记录的 归属人
168
+            $userIdList = array_map(function ($userWithdrawalLimitRecordEntity) {
169
+                return $userWithdrawalLimitRecordEntity->getUserId();
170
+            }, $userWithdrawalLimitRecordEntityList);
171
+
172
+            // 获取用户 映射信息
173
+            /** @var UserRepository $userRepository */
174
+            $userRepository = app()->make(UserRepository::class);
175
+            /** @var UserEntity[] $userEntityMapByUserId */
176
+            $userEntityMapByUserId = [];
177
+            if (!empty($userIdList)) {
178
+                $userEntityMapByUserId = $userRepository->getUserEntityMapByUidList($userIdList);
179
+            }
180
+
181
+            $updateUserEntityList = [];
182
+            $updateUserWithdrawalLimitRecordEntityList = [];
183
+            foreach ($userWithdrawalLimitRecordEntityList as $userWithdrawalLimitRecordEntity) {
184
+                if (empty($userWithdrawalLimitRecordEntity->getId()) || empty($userWithdrawalLimitRecordEntity->getUserId())) {
185
+                    // throw new ValidateException('无效的账单记录');
186
+                    continue;
187
+                }
188
+                if (!empty($userWithdrawalLimitRecordEntity->getTakeTime())) {
189
+                    throw new ValidateException("该奖励记录已更新,请勿重复操作({$userWithdrawalLimitRecordEntity->getId()})");
190
+                }
191
+
192
+                $userEntity = $userEntityMapByUserId[$userWithdrawalLimitRecordEntity->getUserId()];
193
+                if (empty($userEntity) || empty($userEntity->getUid())) {
194
+                    throw new ValidateException("未查询到用户信息({$userWithdrawalLimitRecordEntity->getId()})");
195
+                }
196
+
197
+                // 更新 用户信息
198
+                /** @var UserEntity $updateUserEntity */
199
+                $updateUserEntity = $updateUserEntityList[$userEntity->getUid()] ?? UserEntity::newInstance();
200
+                $updateUserEntity->setUid($userEntity->getUid());
201
+                // 更新 账单 记录
202
+                /** @var UserWithdrawalLimitRecordEntity $updateUserWithdrawalLimitRecord */
203
+                $updateUserWithdrawalLimitRecord = $updateUserWithdrawalLimitRecordEntityList[$userWithdrawalLimitRecordEntity->getId()] ?? UserWithdrawalLimitRecordEntity::newInstance();
204
+
205
+                // 提现额度
206
+                if (is_null($updateUserEntity->getWithdrawalLimit())) {
207
+                    $updateUserEntity->setWithdrawalLimit($userEntity->getWithdrawalLimit());
208
+                }
209
+                // 更新用户 佣金 信息
210
+                if ($userWithdrawalLimitRecordEntity->getPm() == UserWithdrawalLimitRecordEnum::PM['EXPEND']['code']) {
211
+                    if ($updateUserEntity->getWithdrawalLimit() < $userWithdrawalLimitRecordEntity->getNumber()) {
212
+                        throw new ValidateException('用户剩余提现额度不足');
213
+                    }
214
+                    $updateUserEntity->setWithdrawalLimit(bcsub($updateUserEntity->getWithdrawalLimit(), $userWithdrawalLimitRecordEntity->getNumber(), 2));
215
+                } else {
216
+                    $updateUserEntity->setWithdrawalLimit(bcadd($updateUserEntity->getWithdrawalLimit(), $userWithdrawalLimitRecordEntity->getNumber(), 2));
217
+                }
218
+
219
+                // 更新 账单记录 状态
220
+                $updateUserWithdrawalLimitRecord
221
+                    ->setId($userWithdrawalLimitRecordEntity->getId())
222
+                    ->setStatus(UserWithdrawalLimitRecordEnum::STATUS['VALID']['code'])
223
+                    ->setTakeTime(date('Y-m-d H:i:s'))
224
+                    ->setBalance($updateUserEntity->getWithdrawalLimit());
225
+
226
+                $updateUserEntityList[$userEntity->getUid()] = $updateUserEntity;
227
+                $updateUserWithdrawalLimitRecordEntityList[$userWithdrawalLimitRecordEntity->getId()] = $updateUserWithdrawalLimitRecord;
228
+            }
229
+            if (!empty($updateUserEntityList)) {
230
+                $userRepository->batchUpdateUserDataByDataList(
231
+                    array_map(function (UserEntity $updateUserEntity) {
232
+                        return $updateUserEntity->toUnderlineArray();
233
+                    }, $updateUserEntityList)
234
+                );
235
+            }
236
+
237
+            if (!empty($updateUserWithdrawalLimitRecordEntityList)) {
238
+                $this->batchUpdateUserWithdrawalLimitRecordDataByDataList(
239
+                    array_map(function (UserWithdrawalLimitRecordEntity $updateUserWithdrawalLimitRecordEntity) {
240
+                        return $updateUserWithdrawalLimitRecordEntity->toUnderlineArray();
241
+                    }, $updateUserWithdrawalLimitRecordEntityList)
242
+                );
243
+            }
244
+        }
245
+
246
+        return $idList;
247
+    }
248
+}

+ 19 - 0
app/entity/data/user/UserEntity.php

@@ -108,6 +108,7 @@ class UserEntity extends DataEntity
108 108
     public $perContribute = null;  // 个人贡献值中的直推贡献值(用于计算业务经理之前的身份升级)
109 109
     public $withdrawQuotaOld = null;  // 提现额度
110 110
     public $identityUpTime = null;  // 身份升级成业务员的时间
111
+    public $withdrawalLimit = null;  // 用户的提现额度
111 112
 
112 113
     /**
113 114
      * @return mixed
@@ -1962,4 +1963,22 @@ class UserEntity extends DataEntity
1962 1963
         $this->identityUpTime = $identityUpTime;
1963 1964
         return $this;
1964 1965
     }
1966
+
1967
+    /**
1968
+     * @return mixed
1969
+     */
1970
+    public function getWithdrawalLimit()
1971
+    {
1972
+        return $this->withdrawalLimit;
1973
+    }
1974
+
1975
+    /**
1976
+     * @param mixed $withdrawalLimit
1977
+     * @return UserEntity
1978
+     */
1979
+    public function setWithdrawalLimit($withdrawalLimit): UserEntity
1980
+    {
1981
+        $this->withdrawalLimit = $withdrawalLimit;
1982
+        return $this;
1983
+    }
1965 1984
 }

+ 237 - 0
app/entity/data/user/UserWithdrawalLimitRecordEntity.php

@@ -0,0 +1,237 @@
1
+<?php
2
+
3
+namespace app\entity\data\user;
4
+
5
+use app\entity\data\DataEntity;
6
+
7
+class UserWithdrawalLimitRecordEntity extends DataEntity
8
+{
9
+    public $id = null;           // 记录ID
10
+    public $userId = null;       // 用户ID
11
+    public $pm = null;           // 0 = 支出 1 = 获得
12
+    public $number = null;       // 明细数字
13
+    public $balance = null;      // 剩余
14
+    public $status = null;       // 0 = 待确定 1 = 有效 -1 = 无效
15
+    public $typeShop = null;     // 0平台1多多进宝2唯品会3苏宁易购4网易考拉5淘宝客6京东联盟7饿了么8线上9话费
16
+    public $orderSn = null;      // 订单号
17
+    public $takeTime = null;     // 结算时间
18
+    public $remark = null;       // 备注
19
+    public $createTime = null;   // 添加时间
20
+    public $updateTime = null;   // 更新时间
21
+
22
+    /**
23
+     * @return mixed
24
+     */
25
+    public function getId()
26
+    {
27
+        return $this->id;
28
+    }
29
+
30
+    /**
31
+     * @param mixed $id
32
+     * @return UserWithdrawalLimitRecordEntity
33
+     */
34
+    public function setId($id): UserWithdrawalLimitRecordEntity
35
+    {
36
+        $this->id = $id;
37
+        return $this;
38
+    }
39
+
40
+    /**
41
+     * @return mixed
42
+     */
43
+    public function getUserId()
44
+    {
45
+        return $this->userId;
46
+    }
47
+
48
+    /**
49
+     * @param mixed $userId
50
+     * @return UserWithdrawalLimitRecordEntity
51
+     */
52
+    public function setUserId($userId): UserWithdrawalLimitRecordEntity
53
+    {
54
+        $this->userId = $userId;
55
+        return $this;
56
+    }
57
+
58
+    /**
59
+     * @return mixed
60
+     */
61
+    public function getPm()
62
+    {
63
+        return $this->pm;
64
+    }
65
+
66
+    /**
67
+     * @param mixed $pm
68
+     * @return UserWithdrawalLimitRecordEntity
69
+     */
70
+    public function setPm($pm): UserWithdrawalLimitRecordEntity
71
+    {
72
+        $this->pm = $pm;
73
+        return $this;
74
+    }
75
+
76
+    /**
77
+     * @return mixed
78
+     */
79
+    public function getNumber()
80
+    {
81
+        return $this->number;
82
+    }
83
+
84
+    /**
85
+     * @param mixed $number
86
+     * @return UserWithdrawalLimitRecordEntity
87
+     */
88
+    public function setNumber($number): UserWithdrawalLimitRecordEntity
89
+    {
90
+        $this->number = $number;
91
+        return $this;
92
+    }
93
+
94
+    /**
95
+     * @return mixed
96
+     */
97
+    public function getBalance()
98
+    {
99
+        return $this->balance;
100
+    }
101
+
102
+    /**
103
+     * @param mixed $balance
104
+     * @return UserWithdrawalLimitRecordEntity
105
+     */
106
+    public function setBalance($balance): UserWithdrawalLimitRecordEntity
107
+    {
108
+        $this->balance = $balance;
109
+        return $this;
110
+    }
111
+
112
+    /**
113
+     * @return mixed
114
+     */
115
+    public function getStatus()
116
+    {
117
+        return $this->status;
118
+    }
119
+
120
+    /**
121
+     * @param mixed $status
122
+     * @return UserWithdrawalLimitRecordEntity
123
+     */
124
+    public function setStatus($status): UserWithdrawalLimitRecordEntity
125
+    {
126
+        $this->status = $status;
127
+        return $this;
128
+    }
129
+
130
+    /**
131
+     * @return mixed
132
+     */
133
+    public function getTypeShop()
134
+    {
135
+        return $this->typeShop;
136
+    }
137
+
138
+    /**
139
+     * @param mixed $typeShop
140
+     * @return UserWithdrawalLimitRecordEntity
141
+     */
142
+    public function setTypeShop($typeShop): UserWithdrawalLimitRecordEntity
143
+    {
144
+        $this->typeShop = $typeShop;
145
+        return $this;
146
+    }
147
+
148
+    /**
149
+     * @return mixed
150
+     */
151
+    public function getOrderSn()
152
+    {
153
+        return $this->orderSn;
154
+    }
155
+
156
+    /**
157
+     * @param mixed $orderSn
158
+     * @return UserWithdrawalLimitRecordEntity
159
+     */
160
+    public function setOrderSn($orderSn): UserWithdrawalLimitRecordEntity
161
+    {
162
+        $this->orderSn = $orderSn;
163
+        return $this;
164
+    }
165
+
166
+    /**
167
+     * @return mixed
168
+     */
169
+    public function getTakeTime()
170
+    {
171
+        return $this->takeTime;
172
+    }
173
+
174
+    /**
175
+     * @param mixed $takeTime
176
+     * @return UserWithdrawalLimitRecordEntity
177
+     */
178
+    public function setTakeTime($takeTime): UserWithdrawalLimitRecordEntity
179
+    {
180
+        $this->takeTime = $takeTime;
181
+        return $this;
182
+    }
183
+
184
+    /**
185
+     * @return mixed
186
+     */
187
+    public function getRemark()
188
+    {
189
+        return $this->remark;
190
+    }
191
+
192
+    /**
193
+     * @param mixed $remark
194
+     * @return UserWithdrawalLimitRecordEntity
195
+     */
196
+    public function setRemark($remark): UserWithdrawalLimitRecordEntity
197
+    {
198
+        $this->remark = $remark;
199
+        return $this;
200
+    }
201
+
202
+    /**
203
+     * @return mixed
204
+     */
205
+    public function getCreateTime()
206
+    {
207
+        return $this->createTime;
208
+    }
209
+
210
+    /**
211
+     * @param mixed $createTime
212
+     * @return UserWithdrawalLimitRecordEntity
213
+     */
214
+    public function setCreateTime($createTime): UserWithdrawalLimitRecordEntity
215
+    {
216
+        $this->createTime = $createTime;
217
+        return $this;
218
+    }
219
+
220
+    /**
221
+     * @return mixed
222
+     */
223
+    public function getUpdateTime()
224
+    {
225
+        return $this->updateTime;
226
+    }
227
+
228
+    /**
229
+     * @param mixed $updateTime
230
+     * @return UserWithdrawalLimitRecordEntity
231
+     */
232
+    public function setUpdateTime($updateTime): UserWithdrawalLimitRecordEntity
233
+    {
234
+        $this->updateTime = $updateTime;
235
+        return $this;
236
+    }
237
+}