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

PDD-订单奖励-未完成

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

+ 23 - 0
app/common/dao/user/UserBillDao.php

@@ -242,6 +242,29 @@ class UserBillDao extends BaseDao
242 242
     }
243 243
 
244 244
     /**
245
+     * @param string $typeShop
246
+     * @param string $orderSn
247
+     * @return UserBillEntity
248
+     */
249
+    public function getUserBillEntityByTypeShopAndOrderSn(string $typeShop, string $orderSn): UserBillEntity
250
+    {
251
+        $entity = UserBillEntity::newInstance();
252
+        try {
253
+            $dataRes = UserBill::getDB()
254
+                ->where('type_shop', '=', $typeShop)
255
+                ->where('order_sn', '=', $orderSn)
256
+                ->find()
257
+                ->toArray();
258
+            if (!empty($dataRes)) {
259
+                $entity = UserBillEntity::newInstance($dataRes);
260
+            }
261
+        } catch (DataNotFoundException|ModelNotFoundException|DbException $e) {
262
+
263
+        }
264
+        return $entity;
265
+    }
266
+
267
+    /**
245 268
      * 批量更新
246 269
      * @param $dataList
247 270
      * @return array

+ 24 - 2
app/common/enum/CommonEnum.php

@@ -23,7 +23,7 @@ class CommonEnum
23 23
     // 订单类型:根据业务需要进一步扩展
24 24
     const ORDER_TYPE = [
25 25
         'Platform' => ['code' => 0, 'name' => '平台'],
26
-        'DuoduoJinbao' => ['code' => 1, 'name' => '多多进宝'],
26
+        'DuoduoJinbao' => ['code' => 1, 'name' => '多多'],
27 27
         'Vipshop' => ['code' => 2, 'name' => '唯品会'],
28 28
         'SuningYigou' => ['code' => 3, 'name' => '苏宁易购'],
29 29
         'NetEaseKaola' => ['code' => 4, 'name' => '网易考拉'],
@@ -278,7 +278,29 @@ class CommonEnum
278 278
             ],
279 279
             'Thank' => ['code' => 0.1, 'name' => '感恩奖分配比例,10%'],
280 280
             'Hierarchy' => ['code' => 5, 'name' => '会员层级,5层'],
281
-        ]
281
+        ],
282
+        'Pdd' => [
283
+            'CommissionDistributionRatio' => [
284
+                'Ratio' => ['code' => 1, 'name' => '拼多多的佣金分配比例']
285
+            ],
286
+            'Pv' => [
287
+                'Ratio' => ['code' => 0.7, 'name' => '将订单利润的70%作为PV值']
288
+            ],
289
+            'Self' => [
290
+                'YangLaoJin' => [
291
+                    'Ratio' => ['code' => 0.3, 'name' => '将订单利润的30%,当做养老金分配给下单人']
292
+                ]
293
+            ],
294
+            'Spread' => [
295
+                'YangLaoJin' => [
296
+                    'Ratio' => ['code' => 0.05, 'name' => '将订单PV的百分之5,当做养老金分配给推荐人']
297
+                ], 'BrokeragePrice' => [
298
+                    'Ratio' => ['code' => 0.9, 'name' => '将商品利润中 用户身份对应分配比例 的推荐人可分配利润中 90% ,直推奖励的佣金部分'],
299
+                ], 'Fugou' => [
300
+                    'Ratio' => ['code' => 0.1, 'name' => '将商品利润中 用户身份对应分配比例 的推荐人可分配利润中 10% ,直推奖励的复购部分'],
301
+                ]
302
+            ]
303
+        ],
282 304
     ];
283 305
 
284 306
 }

+ 12 - 2
app/common/repositories/user/UserBillRepository.php

@@ -397,12 +397,12 @@ class UserBillRepository extends BaseRepository
397 397
      * @param int $orderId
398 398
      * @param string $mark
399 399
      * @param string $title
400
+     * @param string $orderSn
400 401
      * @return UserBillEntity
401 402
      */
402
-    public function addUserBill(int $uid, int $commissionType, int $pm, float $number, string $category, string $type, string $source, int $orderType, int $typeShop = 0, int $orderId = 0, string $mark = '', string $title = ''): UserBillEntity
403
+    public function addUserBill(int $uid, int $commissionType, int $pm, float $number, string $category, string $type, string $source, int $orderType, int $typeShop = 0, int $orderId = 0, string $mark = '', string $title = '', string $orderSn = ''): UserBillEntity
403 404
     {
404 405
 
405
-        $orderSn = '';
406 406
         $merId = 0;
407 407
         if ($typeShop == UserBillEnum::TYPE_SHOP['Platform']['code']) {
408 408
             /** @var StoreOrderRepository $storeOrderRepository */
@@ -493,6 +493,16 @@ class UserBillRepository extends BaseRepository
493 493
     }
494 494
 
495 495
     /**
496
+     * @param string $typeShop
497
+     * @param string $orderSn
498
+     * @return UserBillEntity
499
+     */
500
+    public function getUserBillEntityByTypeShopAndOrderSn(string $typeShop, string $orderSn): UserBillEntity
501
+    {
502
+        return $this->dao->getUserBillEntityByTypeShopAndOrderSn($typeShop, $orderSn);
503
+    }
504
+
505
+    /**
496 506
      * @param $dataList
497 507
      * @return array
498 508
      */

+ 152 - 0
app/controller/api/store/product/TaoKe.php

@@ -2,9 +2,17 @@
2 2
 
3 3
 namespace app\controller\api\store\product;
4 4
 
5
+use app\common\enum\CommonEnum;
6
+use app\common\enum\user\UserBillEnum;
7
+use app\common\enum\user\UserEnum;
8
+use app\common\enum\user\UserSignFugouEnum;
5 9
 use app\common\model\user\UserThird;
10
+use app\common\repositories\shared\SharedProsperityUserRepository;
11
+use app\common\repositories\store\order\StoreOrderRepository;
6 12
 use app\common\repositories\store\product\ProductRepository;
13
+use app\common\repositories\user\UserBillRepository;
7 14
 use app\common\repositories\user\UserRepository;
15
+use app\common\repositories\user\UserSignFugouRepository;
8 16
 use app\common\repositories\user\UserThirdRepository;
9 17
 use app\model\common\PddOrderModel;
10 18
 use crmeb\services\JwtTokenService;
@@ -896,6 +904,7 @@ class TaoKe extends BaseController
896 904
 
897 905
     public function operatePinOrder($orderLists)
898 906
     {
907
+        /** @var UserThirdRepository $orderThird */
899 908
         $orderThird = app()->make(UserThirdRepository::class);
900 909
         foreach ($orderLists as $k => $order) {
901 910
             if (empty($order)) continue;
@@ -957,6 +966,149 @@ class TaoKe extends BaseController
957 966
         }
958 967
     }
959 968
 
969
+    public function operatePinOrderNew($orderLists)
970
+    {
971
+        foreach ($orderLists as $order) {
972
+            if (empty($order)) continue;
973
+            $localOrder = PddOrderModel::getInstance()->getOne(['order_sn' => $order['order_sn']]);
974
+            if (empty($localOrder)) {
975
+                /** @var UserRepository $userRepository */
976
+                $userRepository = app()->make(UserRepository::class);
977
+                $userEntity = $userRepository->getUserEntityByUid($order['uid']);
978
+                if (empty($userEntity->getUid())) {
979
+                    Db::name('log')->insert(['data' => '拼多多订单号:' . $order['order_sn'] . ',未查询到相应用户信息:' . $order['uid']]);
980
+                    continue;
981
+                }
982
+                /** @var SharedProsperityUserRepository $sharedProsperityUserRepository */
983
+                $sharedProsperityUserRepository = app()->make(SharedProsperityUserRepository::class);
984
+                $sharedProsperityUserEntity = $sharedProsperityUserRepository->getSharedProsperityUserEntityByUserId($userEntity->getUid());
985
+
986
+                $localOrder = PddOrderModel::create($order);
987
+
988
+                // 发放养老金
989
+                // 收益
990
+                $commission = $localOrder['commission'] ?? 0.00;
991
+                // 手续费
992
+                $huifuCommissionCharge = bcmul((string)$commission, (string)CommonEnum::HUIFU_COMMISSION_CHARGE, CommonEnum::CALCULATE_THE_NUMBER_OF_DECIMAL_PLACES);
993
+                // 可支配金额
994
+                $profit = bcsub((string)$commission, $huifuCommissionCharge, CommonEnum::CALCULATE_THE_NUMBER_OF_DECIMAL_PLACES);
995
+                $profit = bcmul($profit, CommonEnum::ORDER_EARNING_ALLOCATION['Pdd']['CommissionDistributionRatio']['Ratio']['code'], CommonEnum::CALCULATE_THE_NUMBER_OF_DECIMAL_PLACES);
996
+
997
+                $pv = bcmul((string)$commission, (string)CommonEnum::ORDER_EARNING_ALLOCATION['Pdd']['Pv']['Ratio']['code'], CommonEnum::DECIMAL_PLACES_OF_THE_AMOUNT);
998
+
999
+                // 为消费者 发放养老金
1000
+                /** @var UserBillRepository $userBillRepository */
1001
+                $userBillRepository = app()->make(UserBillRepository::class);
1002
+                $yanglaojin = bcmul((string)$commission, CommonEnum::ORDER_EARNING_ALLOCATION['Pdd']['Self']['YangLaoJin']['Ratio']['code'], CommonEnum::DECIMAL_PLACES_OF_THE_AMOUNT);
1003
+                if ($yanglaojin >= 0.01) {
1004
+                    $userBillRepository->addUserBill(
1005
+                        $userEntity->getUid(),
1006
+                        UserBillEnum::COMMISSION_TYPE['PENSION']['code'],
1007
+                        UserBillEnum::PM['INCOME']['code'],
1008
+                        $yanglaojin,
1009
+                        UserBillEnum::CATEGORY['NowMoney']['code'],
1010
+                        UserBillEnum::TYPE['Commission']['code'],
1011
+                        UserBillEnum::SOURCE['ONLINE']['code'],
1012
+                        UserBillEnum::ORDER_TYPE['THIRD_PARTY']['code'],
1013
+                        UserBillEnum::TYPE_SHOP['DuoduoJinbao']['code'],
1014
+                        $localOrder['order_pdd_id'],
1015
+                        CommonEnum::ORDER_TYPE['DuoduoJinbao']['name'] . '消费获得养老金' . $yanglaojin,
1016
+                        '',
1017
+                        $localOrder['order_sn']
1018
+                    );
1019
+                } else {
1020
+                    Db::name('log')->insert(['data' => '订单号:' . $localOrder['order_sn'] . '付款额度较低或 商家、平台设置的返佣比例较低,养老金低于0.01无法入库 特此记录!']);
1021
+                }
1022
+
1023
+                $spreadUid = $userEntity->getSpreadUid();
1024
+                // 判断推广者 如果推广者 是共富体系会员
1025
+                if (!empty($sharedProsperityUserEntity->getId())) {
1026
+                    $spreadUid = $sharedProsperityUserEntity->getParentId();
1027
+                }
1028
+                if (!empty($spreadUid)) {
1029
+                    $userEntityBySpreadUid = $userRepository->getUserEntityByUid($spreadUid);
1030
+                    if (!empty($userEntityBySpreadUid->getUid()) && $userEntityBySpreadUid->getIsDel() == UserEnum::IS_DEL['No']['code']) {
1031
+                        // 发放养老金
1032
+                        // 如果用户的身份 不是 普通用户 (高于普通用户) 则发放养老金
1033
+                        if ($userEntityBySpreadUid->getUserGroup() != CommonEnum::USER_GROUP['RegularUser']['code']) {
1034
+                            $yanglaojinBySpreadUid = bcmul($pv, CommonEnum::ORDER_EARNING_ALLOCATION['Pdd']['Spread']['YangLaoJin']['Ratio']['code'], CommonEnum::DECIMAL_PLACES_OF_THE_AMOUNT);
1035
+                            if ($yanglaojin >= 0.01) {
1036
+                                /** @var UserBillRepository $userBillRepository */
1037
+                                $userBillRepository = app()->make(UserBillRepository::class);
1038
+                                $userBillRepository->addUserBill(
1039
+                                    $userEntityBySpreadUid->getUid(),
1040
+                                    UserBillEnum::COMMISSION_TYPE['PENSION']['code'],
1041
+                                    UserBillEnum::PM['INCOME']['code'],
1042
+                                    $yanglaojinBySpreadUid,
1043
+                                    UserBillEnum::CATEGORY['NowMoney']['code'],
1044
+                                    UserBillEnum::TYPE['Commission']['code'],
1045
+                                    UserBillEnum::SOURCE['ONLINE']['code'],
1046
+                                    UserBillEnum::ORDER_TYPE['THIRD_PARTY']['code'],
1047
+                                    UserBillEnum::TYPE_SHOP['DuoduoJinbao']['code'],
1048
+                                    $localOrder['order_pdd_id'],
1049
+                                    "推荐消费获得养老金" . $yanglaojinBySpreadUid,
1050
+                                    '',
1051
+                                    $localOrder['order_sn']
1052
+                                );
1053
+                            } else {
1054
+                                Db::name('log')->insert(['data' => '订单号:' . $localOrder['order_sn'] . '付款额度较低,推荐养老金低于0.01无法入库 特此记录!']);
1055
+                            }
1056
+                        }
1057
+
1058
+                        // 后台设置中 可以设置 推荐人 直推收益 的比例
1059
+                        $rate = StoreOrderRepository::getUserGroupRate($userEntityBySpreadUid->getUserGroup());
1060
+                        // 推荐 奖金 目前需要将 奖金按比例 分成佣金和复购金
1061
+                        $directReferralBonus = bcmul($pv, $rate, CommonEnum::CALCULATE_THE_NUMBER_OF_DECIMAL_PLACES);
1062
+
1063
+                        // 计算 复购金
1064
+                        $fugouBySpreadUid = bcmul($directReferralBonus, CommonEnum::ORDER_EARNING_ALLOCATION['Pdd']['Spread']['Fugou']['Ratio']['code'], CommonEnum::DECIMAL_PLACES_OF_THE_AMOUNT);
1065
+                        if ($fugouBySpreadUid >= 0.01) {
1066
+                            // 添加复购金记录
1067
+                            /** @var UserSignFugouRepository $userSignFugouRepository */
1068
+                            $userSignFugouRepository = app()->make(UserSignFugouRepository::class);
1069
+                            $userSignFugouRepository->addUserSingFugou(
1070
+                                $userEntityBySpreadUid->getUid(),
1071
+                                UserSignFugouEnum::TYPE['Give']['code'],
1072
+                                $fugouBySpreadUid,
1073
+                                UserSignFugouEnum::COMMISSION_TYPE['DIRECT_REFERRAL']['code'],
1074
+                                '推荐消费' . CommonEnum::ORDER_TYPE['DuoduoJinbao']['name'] . '商品赠送复购金',
1075
+                                UserSignFugouEnum::ORDER_TYPE['DuoduoJinbao']['code'],
1076
+                                $localOrder['order_pdd_id']
1077
+                            );
1078
+                        } else {
1079
+                            Db::name('log')->insert(['data' => '订单号:' .  $localOrder['order_sn'] . '付款额度较低或 商家、平台设置的返佣比例较低,复购金低于0.01无法入库 特此记录!']);
1080
+                        }
1081
+
1082
+                        // 计算 佣金
1083
+                        $brokeragePriceBySpreadUid = bcmul($directReferralBonus, CommonEnum::ORDER_EARNING_ALLOCATION['Pdd']['Spread']['BrokeragePrice']['Ratio']['code'], CommonEnum::DECIMAL_PLACES_OF_THE_AMOUNT);
1084
+                        if ($brokeragePriceBySpreadUid >= 0.01) {
1085
+                            // 添加佣金记录
1086
+                            /** @var UserBillRepository $userBillRepository */
1087
+                            $userBillRepository = app()->make(UserBillRepository::class);
1088
+                            $userBillRepository->addUserBill(
1089
+                                $userEntityBySpreadUid->getUid(),
1090
+                                UserBillEnum::COMMISSION_TYPE['DIRECT_REFERRAL']['code'],
1091
+                                UserBillEnum::PM['INCOME']['code'],
1092
+                                $brokeragePriceBySpreadUid,
1093
+                                UserBillEnum::CATEGORY['NowMoney']['code'],
1094
+                                UserBillEnum::TYPE['Commission']['code'],
1095
+                                UserBillEnum::SOURCE['ONLINE']['code'],
1096
+                                UserBillEnum::ORDER_TYPE['THIRD_PARTY']['code'],
1097
+                                UserBillEnum::TYPE_SHOP['DuoduoJinbao']['code'],
1098
+                                $localOrder['order_pdd_id'],
1099
+                                '推荐消费获得佣金' . $brokeragePriceBySpreadUid,
1100
+                                '',
1101
+                                $localOrder['order_sn']
1102
+                            );
1103
+                        } else {
1104
+                            Db::name('log')->insert(['data' => '订单号:' . $localOrder['order_sn'] . '付款额度较低或 商家、平台设置的返佣比例较低,佣金低于0.01无法入库 特此记录!']);
1105
+                        }
1106
+                    }
1107
+                }
1108
+            }
1109
+        }
1110
+    }
1111
+
960 1112
 
961 1113
     //将拼多多订单列表中的订单写入第三方平台订单表
962 1114
     public function operatePinOrderOld($orderLists)