|
|
@@ -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)
|