|
|
@@ -52,6 +52,8 @@ use app\common\repositories\merchant\order\OrderMerchantRepository;
|
|
52
|
52
|
use app\common\repositories\BaseRepository;
|
|
53
|
53
|
use app\common\repositories\product\ProductSeckillRepository;
|
|
54
|
54
|
use app\common\repositories\product\ShareRepository;
|
|
|
55
|
+use app\common\repositories\shared\SharedProsperityRecommendConfigRepository;
|
|
|
56
|
+use app\common\repositories\shared\SharedProsperityUserRepository;
|
|
55
|
57
|
use app\common\repositories\store\coupon\StoreCouponProductRepository;
|
|
56
|
58
|
use app\common\repositories\store\coupon\StoreCouponRepository;
|
|
57
|
59
|
use app\common\repositories\store\coupon\StoreCouponUserRepository;
|
|
|
@@ -88,6 +90,7 @@ use app\controller\api\user\Volunteer;
|
|
88
|
90
|
use app\entity\data\merchant\MerchantEntity;
|
|
89
|
91
|
use app\entity\data\product\ProductSeckillEntity;
|
|
90
|
92
|
use app\entity\data\product\ShareEntity;
|
|
|
93
|
+use app\entity\data\shared\SharedProsperityUserEntity;
|
|
91
|
94
|
use app\entity\data\store\CartEntity;
|
|
92
|
95
|
use app\entity\data\store\StoreProductAttrValueEntity;
|
|
93
|
96
|
use app\entity\data\store\StoreProductEntity;
|
|
|
@@ -11513,6 +11516,98 @@ class StoreOrderRepository extends BaseRepository
|
|
11513
|
11516
|
}
|
|
11514
|
11517
|
}
|
|
11515
|
11518
|
}
|
|
|
11519
|
+ } else if ($storeOrderEntity->getMerId() == CommonEnum::DESIGN_MERCHANT_ID['SharedProsperity']['code']) {
|
|
|
11520
|
+ /** @var SharedProsperityUserRepository $sharedProsperityUserRepository */
|
|
|
11521
|
+ $sharedProsperityUserRepository = app()->make(SharedProsperityUserRepository::class);
|
|
|
11522
|
+ $sharedProsperityUserEntity = $sharedProsperityUserRepository->getSharedProsperityUserEntityByUserId($userEntity->getUid());
|
|
|
11523
|
+ // 如果当前 共富体系内 没有该用户信息,则需要为其创建 共富体系用户数据
|
|
|
11524
|
+ if (empty($sharedProsperityUserEntity->getId())) {
|
|
|
11525
|
+ // 生成 共富体系用户实体
|
|
|
11526
|
+ $sharedProsperityUserEntityByNewCreate = SharedProsperityUserEntity::newInstance()
|
|
|
11527
|
+ ->setUserId($userEntity->getUid());
|
|
|
11528
|
+ // 查看分享人是否为 共富体系会员 如果是,则绑定共富体系的推荐关系,如果没有,则当前消费者则为 共富体系内的自然消费者,上级绑定为平台(因为文档内说明了,推荐人只能是共富会员)
|
|
|
11529
|
+ if (!empty($storeOrderEntity->getShareUid())) {
|
|
|
11530
|
+ $sharedProsperityUserEntityByShareUid = $sharedProsperityUserRepository->getSharedProsperityUserEntityByUserId($storeOrderEntity->getShareUid());
|
|
|
11531
|
+ if (!empty($sharedProsperityUserEntityByShareUid->getId())) {
|
|
|
11532
|
+ $sharedProsperityUserEntityByNewCreate->setParentId($sharedProsperityUserEntityByShareUid->getUserId());
|
|
|
11533
|
+ }
|
|
|
11534
|
+ }
|
|
|
11535
|
+ $sharedProsperityUserEntity = $sharedProsperityUserRepository->createByEntity($sharedProsperityUserEntityByNewCreate);
|
|
|
11536
|
+ }
|
|
|
11537
|
+
|
|
|
11538
|
+ if (empty($sharedProsperityUserEntity->getId())) {
|
|
|
11539
|
+ Db::name('log')->insert(['data' => '共富区奖励发放,用户创建失败,订单ID:' . $storeOrderEntity->getOrderId()]);
|
|
|
11540
|
+ return;
|
|
|
11541
|
+ }
|
|
|
11542
|
+
|
|
|
11543
|
+ // 为消费者 初始化 添加养老金记录
|
|
|
11544
|
+ $yanglaojin = bcmul($storeOrderEntity->getConPri(), CommonEnum::ORDER_EARNING_ALLOCATION['SharedProsperity']['Self']['YangLaoJin']['Ratio']['code'], CommonEnum::DECIMAL_PLACES_OF_THE_AMOUNT);
|
|
|
11545
|
+ /** @var UserBillRepository $userBillRepository */
|
|
|
11546
|
+ $userBillRepository = app()->make(UserBillRepository::class);
|
|
|
11547
|
+ $userBillRepository->addUserBill(
|
|
|
11548
|
+ $sharedProsperityUserEntity->getUserId(),
|
|
|
11549
|
+ UserBillEnum::COMMISSION_TYPE['PENSION']['code'],
|
|
|
11550
|
+ UserBillEnum::PM['INCOME']['code'],
|
|
|
11551
|
+ $yanglaojin,
|
|
|
11552
|
+ UserBillEnum::CATEGORY['NowMoney']['code'],
|
|
|
11553
|
+ UserBillEnum::TYPE['Commission']['code'],
|
|
|
11554
|
+ UserBillEnum::SOURCE['ONLINE']['code'],
|
|
|
11555
|
+ UserBillEnum::ORDER_TYPE['SELF_OPERATED']['code'],
|
|
|
11556
|
+ UserBillEnum::TYPE_SHOP['Platform']['code'],
|
|
|
11557
|
+ $storeOrderEntity->getOrderId(),
|
|
|
11558
|
+ '购买共富区商品获得养老金'
|
|
|
11559
|
+ );
|
|
|
11560
|
+
|
|
|
11561
|
+ // 消费股 TODO 该做这里了
|
|
|
11562
|
+
|
|
|
11563
|
+ if (!empty($sharedProsperityUserEntity->getParentId())) {
|
|
|
11564
|
+ // 如果 共富区推荐人 不是平台,则为 推荐人发放 推荐奖励
|
|
|
11565
|
+ $sharedProsperityUserEntityByParent = $sharedProsperityUserRepository->getSharedProsperityUserEntityByUserId($sharedProsperityUserEntity->getParentId());
|
|
|
11566
|
+ if (!empty($sharedProsperityUserEntityByParent->getId())) {
|
|
|
11567
|
+ // 为 共富体系推荐人 发放养老金
|
|
|
11568
|
+ $yanglaojinBySpreadUid = bcmul($storeOrderEntity->getConPri(), CommonEnum::ORDER_EARNING_ALLOCATION['SharedProsperity']['Spread']['YangLaoJin']['Ratio']['code'], CommonEnum::DECIMAL_PLACES_OF_THE_AMOUNT);
|
|
|
11569
|
+ /** @var UserBillRepository $userBillRepository */
|
|
|
11570
|
+ $userBillRepository = app()->make(UserBillRepository::class);
|
|
|
11571
|
+ $userBillRepository->addUserBill(
|
|
|
11572
|
+ $sharedProsperityUserEntityByParent->getUserId(),
|
|
|
11573
|
+ UserBillEnum::COMMISSION_TYPE['PENSION']['code'],
|
|
|
11574
|
+ UserBillEnum::PM['INCOME']['code'],
|
|
|
11575
|
+ $yanglaojinBySpreadUid,
|
|
|
11576
|
+ UserBillEnum::CATEGORY['NowMoney']['code'],
|
|
|
11577
|
+ UserBillEnum::TYPE['Commission']['code'],
|
|
|
11578
|
+ UserBillEnum::SOURCE['ONLINE']['code'],
|
|
|
11579
|
+ UserBillEnum::ORDER_TYPE['SELF_OPERATED']['code'],
|
|
|
11580
|
+ UserBillEnum::TYPE_SHOP['Platform']['code'],
|
|
|
11581
|
+ $storeOrderEntity->getOrderId(),
|
|
|
11582
|
+ '推广共富区会员消费获得养老金'
|
|
|
11583
|
+ );
|
|
|
11584
|
+
|
|
|
11585
|
+ // 计算 推广佣金
|
|
|
11586
|
+ /** @var SharedProsperityRecommendConfigRepository $sharedProsperityRecommendConfigRepository */
|
|
|
11587
|
+ $sharedProsperityRecommendConfigRepository = app()->make(SharedProsperityRecommendConfigRepository::class);
|
|
|
11588
|
+ $sharedProsperityRecommendConfigEntityByParentPartnerLevel = $sharedProsperityRecommendConfigRepository->getSharedProsperityRecommendConfigEntityByLevel($sharedProsperityUserEntityByParent->getPartnerLevel());
|
|
|
11589
|
+ if (!empty($sharedProsperityRecommendConfigEntityByParentPartnerLevel->getId())) {
|
|
|
11590
|
+ $rewardRatio = bcdiv($sharedProsperityRecommendConfigEntityByParentPartnerLevel->getRewardRatio(), 100, 2);
|
|
|
11591
|
+ $brokeragePriceBySpreadUid = bcmul($storeOrderEntity->getConPri(), $rewardRatio, CommonEnum::DECIMAL_PLACES_OF_THE_AMOUNT);
|
|
|
11592
|
+ // 添加佣金记录
|
|
|
11593
|
+ /** @var UserBillRepository $userBillRepository */
|
|
|
11594
|
+ $userBillRepository = app()->make(UserBillRepository::class);
|
|
|
11595
|
+ $userBillRepository->addUserBill(
|
|
|
11596
|
+ $sharedProsperityUserEntityByParent->getUid(),
|
|
|
11597
|
+ UserBillEnum::COMMISSION_TYPE['DIRECT_REFERRAL']['code'],
|
|
|
11598
|
+ UserBillEnum::PM['INCOME']['code'],
|
|
|
11599
|
+ $brokeragePriceBySpreadUid,
|
|
|
11600
|
+ UserBillEnum::CATEGORY['NowMoney']['code'],
|
|
|
11601
|
+ UserBillEnum::TYPE['Commission']['code'],
|
|
|
11602
|
+ UserBillEnum::SOURCE['ONLINE']['code'],
|
|
|
11603
|
+ UserBillEnum::ORDER_TYPE['SELF_OPERATED']['code'],
|
|
|
11604
|
+ UserBillEnum::TYPE_SHOP['Platform']['code'],
|
|
|
11605
|
+ $storeOrderEntity->getOrderId(),
|
|
|
11606
|
+ '推广共富区商品获得佣金'
|
|
|
11607
|
+ );
|
|
|
11608
|
+ }
|
|
|
11609
|
+ }
|
|
|
11610
|
+ }
|
|
11516
|
11611
|
} else {
|
|
11517
|
11612
|
/** @var MerchantRepository $merchantRepository */
|
|
11518
|
11613
|
$merchantRepository = app()->make(MerchantRepository::class);
|