Explorar el Código

计算佣金、分红奖励

family hace 1 año
padre
commit
72ad428179
Se han modificado 1 ficheros con 141 adiciones y 201 borrados
  1. 141 201
      app/common/repositories/movie/MovieRepository.php

+ 141 - 201
app/common/repositories/movie/MovieRepository.php

@@ -448,8 +448,8 @@ class MovieRepository extends BaseRepository
448 448
         if ($res) {
449 449
             $confirmOrder = DouHuoMallFilmApiRequest::confirmOrder($orderinfo['order_sn'], $orderinfo['price']);
450 450
             if (!empty($confirmOrder) && isset($confirmOrder['code']) && ($confirmOrder['code'] == ApiResponseService::DEFAULT_SUCCESS_CODE)) {
451
-                // 计算佣金分红奖励
452
-                $this->calculationCommissionDividendAward();
451
+                // 计算佣金分红奖励
452
+                $this->calculationCommissionDividendAward($orderinfo);
453 453
                 // 提交事务
454 454
                 Db::commit();
455 455
             } else {
@@ -464,218 +464,158 @@ class MovieRepository extends BaseRepository
464 464
         }
465 465
     }
466 466
 
467
-    private function calculationCommissionDividendAward()
467
+    /**
468
+     * 计算佣金、分红奖励
469
+     * @param $orderinfo
470
+     * @return void
471
+     * @throws \think\db\exception\DataNotFoundException
472
+     * @throws \think\db\exception\DbException
473
+     * @throws \think\db\exception\ModelNotFoundException
474
+     */
475
+    private function calculationCommissionDividendAward($orderinfo)
468 476
     {
469
-        //商家让利部分的拆分
470
-        $ylj_pri = bcmul($concession_pri, 0.3, 2); // 让利部分30%给消费者做养老金
471
-        $pv = bcmul($concession_pri, 0.35, 2); // 35%做业绩PV分配
472
-
473
-        //分配养老金给消费者
474
-        $ylj_amount_mine = $user_data['annuity'] + $ylj_pri;
475
-        //分配积分和贡献值给消费者
476
-        $con = $user_data['contribute'] + $pv;
477
-        $score = $user_data['score'] + $pv;
478
-
479
-        // 让利部分30%给消费者做养老金{$ylj_pri}
480
-        $this->bill_user_log($user_data['uid'], $ylj_pri, $store_order_data['order_id'], 5, $group_order['group_order_sn'], '购买商贸区商品获得养老金' . $ylj_pri, $store_order_data['mer_id'], 0);
481
-        // @todo 消费者购买商品赠送PV等值的积分和贡献值
482
-        // 贡献值
483
-//                $this->con_log($user_data['uid'], $pv, $store_order_data['order_id'], 12, "购买商贸区商品赠送贡献值");
477
+        /** @var StoreOrderRepository $storeOrderRepository */
478
+        $storeOrderRepository = app()->make(StoreOrderRepository::class);
479
+
480
+        // 电影分佣比例配置
481
+        $movie_commission_rate_config = Db::name('system_config_value')->where('config_key', 'movie_commission_rate_config')->find();
482
+        // 让利金额
483
+        $concession_pri = bcmul((string)$orderinfo['price'], $movie_commission_rate_config['premium_rate'], 2);
484
+        // 养老金
485
+        $ylj_pri = bcmul($concession_pri, $movie_commission_rate_config['consumer_yanglaojin_rate'], 2);
486
+        // 业绩PV
487
+        $pv = bcmul($concession_pri, $movie_commission_rate_config['pv_rate'], 2);
488
+
489
+        //-------------------消费者收益---------------------
490
+        // PV值
491
+        $storeOrderRepository->con_log_pv($orderinfo['uid'], $pv, $orderinfo['order_id'], 13, "购买电影票赠送PV值");
492
+        // 养老金
493
+        $this->distributionAnnuityEarnings($orderinfo['uid'], $ylj_pri, $orderinfo['order_id'], 5, $orderinfo['order_sn'], '购买电影票获得养老金' . $ylj_pri, 0, 0);
494
+        // 消费者 - 红包 - 老用户发红包奖励
495
+        $user = Db::name("user")->where('uid', $orderinfo["uid"])->find();
496
+        if ($user['is_old'] == 1) {
497
+            $storeOrderRepository->giveHongBao($orderinfo["uid"], $pv, $orderinfo['order_id'], '购买电影票赠送红包');
498
+        }
484 499
         // 积分
485
-        $this->score_log($user_data['uid'], $pv, $store_order_data['order_id'], 12, "购买商贸区商品赠送积分");
486
-
487
-        // @todo ------------PV业绩100%分配如下------------------
488
-        if ($user_data['spread_uid'] != 0) {
489
-            //查询下单用户上级
490
-            $spread_data = Db::name('user')->where('uid', $user_data['spread_uid'])->find();
491
-
492
-            $rate = static::getUserGroupRate($spread_data['user_group']);
500
+        $storeOrderRepository->score_log($orderinfo['uid'], $pv, $orderinfo['order_id'], 13, "购买电影票赠送积分");
501
+        // 贡献值
502
+        $storeOrderRepository->con_log($orderinfo['uid'], $pv, $orderinfo['order_id'], 13, "购买电影票赠送贡献值");
503
+        //-------------------消费者收益---------------------
504
+
505
+        // 推广者
506
+        if ($user['spread_uid'] != 0) {
507
+            //查询{下单用户}的上级
508
+            $spread_data = Db::name('user')->where('uid', $user['spread_uid'])->find();
509
+            $rate = $storeOrderRepository->getUserGroupRate($spread_data['user_group']);
510
+
511
+            //养老金
512
+            $spread_yanglaojin = bcmul($pv, $movie_commission_rate_config['spread_yanglaojin_rate'], 2);
513
+            $this->distributionAnnuityEarnings(
514
+                $spread_data['uid'], $spread_yanglaojin, $orderinfo['order_id'], 5, $orderinfo['order_sn'], '电影票-推广者获得养老金' . $spread_yanglaojin, 0, 0
515
+            );
516
+
517
+            // 直推佣金
518
+            $yj_amount_90 = round(bcmul($pv, $rate, 2) * $movie_commission_rate_config['commission_directthrust_rate'], 2);
519
+            $this->distributionAnnuityEarnings(
520
+                $spread_data['uid'], $yj_amount_90, $orderinfo['order_id'], 3, $orderinfo['order_sn'], '电影票-推广者获得直推佣金' . $yj_amount_90,
521
+                0, 0
522
+            );
523
+
524
+            // 复购金-推广者的佣金抽10%到个人复购金
525
+            $fgj_amount_10 = round(bcmul($pv, $rate, 2) * $movie_commission_rate_config['repurchase_directthrust_rate'], 2);
526
+            $storeOrderRepository->fugou_user_log($spread_data['uid'], $fgj_amount_10, $orderinfo['order_id'], 1);
527
+
528
+            // 积分
529
+            $score = bcmul($pv, $rate, 2);
530
+            $storeOrderRepository->score_log($spread_data['uid'], $score, $orderinfo['order_id'], 13, "电影票-推广者获得赠送积分");
531
+
532
+            // 业务员及以上身份
493 533
             if ($spread_data['user_group'] > 1) {
494
-                $ssf = 0;//变量
495
-                $yj_amount_90 = 0;//90%的佣金
496
-                // 业务员
497
-                if ($spread_data['user_group'] == 2) {
498
-                    $ssf = bcmul($pv, $rate, 2);
499
-                    $con = $spread_data['contribute'] + bcmul($pv, $rate, 2);
500
-                    $score = $spread_data['score'] + bcmul($pv, $rate, 2);
501
-
502
-
503
-                    $yj_amount_90 = bcmul($pv, $rate, 2) * 0.9;
504
-                    $fgj_amount_10 = bcmul($pv, $rate, 2) * 0.1;//推广者的佣金抽10%到个人复购金
505
-
506
-                    $yj_amount = $spread_data['brokerage_price'] + $yj_amount_90;
507
-                    $fgj_amount = $spread_data['fugou'] + $fgj_amount_10;
508
-                    $this->fugou_user_log($spread_data['uid'], $fgj_amount_10, $store_order_data['order_id'], 1);
509
-                } else if ($spread_data['user_group'] == 3) {
510
-                    $ssf = bcmul($pv, $rate, 2);
511
-                    $con = $spread_data['contribute'] + bcmul($pv, $rate, 2);
512
-                    $score = $spread_data['score'] + bcmul($pv, $rate, 2);
513
-
514
-                    $yj_amount_90 = bcmul($pv, $rate, 2) * 0.9;
515
-                    $fgj_amount_10 = bcmul($pv, $rate, 2) * 0.1;//推广者的佣金抽10%到个人复购金
516
-
517
-                    $yj_amount = $spread_data['brokerage_price'] + $yj_amount_90;
518
-                    $fgj_amount = $spread_data['fugou'] + $fgj_amount_10;
519
-                    $this->fugou_user_log($spread_data['uid'], $fgj_amount_10, $store_order_data['order_id'], 1);
520
-
521
-                    // Db::name('user')->where('uid',$spread_data['uid'])->update(['contribute'=> $con,'score'=> $score,'brokerage_price'=> $yj_amount,'annuity'=>$ylj_amount,'fugou'=>$fgj_amount]);
522
-                } else if ($spread_data['user_group'] == 4) {
523
-                    $ssf = bcmul($pv, $rate, 2);
524
-                    $con = $spread_data['contribute'] + bcmul($pv, $rate, 2);
525
-                    $score = $spread_data['score'] + bcmul($pv, $rate, 2);
526
-
527
-                    $yj_amount_90 = bcmul($pv, $rate, 2) * 0.9;
528
-                    $fgj_amount_10 = bcmul($pv, $rate, 2) * 0.1;//推广者的佣金抽10%到个人复购金
529
-
530
-                    $yj_amount = $spread_data['brokerage_price'] + $yj_amount_90;
531
-                    $fgj_amount = $spread_data['fugou'] + $fgj_amount_10;
532
-                    $this->fugou_user_log($spread_data['uid'], $fgj_amount_10, $store_order_data['order_id'], 1);
533
-
534
-                    //Db::name('user')->where('uid',$spread_data['uid'])->update(['contribute'=> $con,'score'=> $score,'brokerage_price'=> $yj_amount,'annuity'=>$ylj_amount,'fugou'=>$fgj_amount]);
535
-                } else if ($spread_data['user_group'] == 5) {
536
-                    $ssf = bcmul($pv, $rate, 2);
537
-                    $con = $spread_data['contribute'] + bcmul($pv, $rate, 2);
538
-                    $score = $spread_data['score'] + bcmul($pv, $rate, 2);
539
-                    // $yj_amount = $spread_data['brokerage_price'] + round($pv * $rate,2);
540
-
541
-                    $yj_amount_90 = bcmul($pv, $rate, 2) * 0.9;
542
-                    $fgj_amount_10 = bcmul($pv, $rate, 2) * 0.1;//推广者的佣金抽10%到个人复购金
543
-
544
-                    $yj_amount = $spread_data['brokerage_price'] + $yj_amount_90;
545
-                    $fgj_amount = $spread_data['fugou'] + $fgj_amount_10;
546
-                    $this->fugou_user_log($spread_data['uid'], $fgj_amount_10, $store_order_data['order_id'], 1);
547
-
548
-                    // Db::name('user')->where('uid',$spread_data['uid'])->update(['contribute'=> $con,'score'=> $score,'brokerage_price'=> $yj_amount,'annuity'=>$ylj_amount,'fugou'=>$fgj_amount]);
549
-                } else if ($spread_data['user_group'] == 6) {
550
-                    $ssf = bcmul($pv, $rate, 2);
551
-                    $con = $spread_data['contribute'] + bcmul($pv, $rate, 2);
552
-                    $score = $spread_data['score'] + bcmul($pv, $rate, 2);
553
-
554
-                    $yj_amount_90 = bcmul($pv, $rate, 2) * 0.9;
555
-                    $fgj_amount_10 = bcmul($pv, $rate, 2) * 0.1;//推广者的佣金抽10%到个人复购金
556
-
557
-                    $yj_amount = $spread_data['brokerage_price'] + $yj_amount_90;
558
-                    $fgj_amount = $spread_data['fugou'] + $fgj_amount_10;
559
-                    $this->fugou_user_log($spread_data['uid'], $fgj_amount_10, $store_order_data['order_id'], 1);
560
-
561
-                    // Db::name('user')->where('uid',$spread_data['uid'])->update(['contribute'=> $con,'score'=> $score,'brokerage_price'=> $yj_amount,'annuity'=>$ylj_amount,'fugou'=>$fgj_amount]);
562
-                } else if ($spread_data['user_group'] == 7) {
563
-                    $ssf = bcmul($pv, $rate, 2);
564
-                    $con = $spread_data['contribute'] + bcmul($pv, $rate, 2);
565
-                    $score = $spread_data['score'] + bcmul($pv, $rate, 2);
566
-
567
-
568
-                    $yj_amount_90 = bcmul($pv, $rate, 2) * 0.9;
569
-                    $fgj_amount_10 = bcmul($pv, $rate, 2) * 0.1;//推广者的佣金抽10%到个人复购金
570
-
571
-                    $yj_amount = $spread_data['brokerage_price'] + $yj_amount_90;
572
-                    $fgj_amount = $spread_data['fugou'] + $fgj_amount_10;
573
-                    $this->fugou_user_log($spread_data['uid'], $fgj_amount_10, $store_order_data['order_id'], 1);
574
-
575
-                    // Db::name('user')->where('uid',$spread_data['uid'])->update(['contribute'=> $con,'score'=> $score,'brokerage_price'=> $yj_amount,'annuity'=>$ylj_amount,'fugou'=>$fgj_amount]);
576
-                }
577
-
578
-                //贡献值
579
-                $this->con_log($spread_data['uid'], $pv, $store_order_data['order_id'], 12, "商贸区商品赠送贡献值");
580
-                //积分
581
-                $this->score_log($spread_data['uid'], $ssf, $store_order_data['order_id'], 12, "商贸区商品赠送积分");
582
-                //推广佣金
583
-                $this->bill_user_log($spread_data['uid'], $yj_amount_90, $store_order_data['order_id'], 3, $group_order['group_order_sn'], '推广获得佣金' . $yj_amount_90, $store_order_data['mer_id'], 0);
584
-                //养老金
585
-                $this->bill_user_log($spread_data['uid'], bcmul($pv, 0.05, 2), $store_order_data['order_id'], 5, $group_order['group_order_sn'], '推广获得养老金' . round($pv * 0.05, 2), $store_order_data['mer_id'], 0);
534
+                // 贡献值
535
+                $storeOrderRepository->con_log($spread_data['uid'], $pv, $orderinfo['order_id'], 13, "电影票-推广者获得赠送贡献值");
586 536
             }
587 537
 
588
-            //普通用户推广人
538
+            // 普通用户推广人
589 539
             if ($spread_data['user_group'] == 1) {
590
-                //给推广者分配佣金
591
-
592
-                $yj_amount_90 = bcmul($pv, $rate, 2) * 0.9;
593
-                $fgj_amount_10 = bcmul($pv, $rate, 2) * 0.1;//推广者的佣金抽10%到个人复购金
594
-
595
-                $yj_amount = $spread_data['brokerage_price'] + $yj_amount_90;
596
-                $fgj_amount = $spread_data['fugou'] + $fgj_amount_10;
597
-                $this->fugou_user_log($spread_data['uid'], $fgj_amount_10, $store_order_data['order_id'], 1);
598
-
599
-                //Db::name('user')->where('uid',$spread_data['uid'])->update(['brokerage_price'=>$yj_amount,'fugou'=>$fgj_amount]);
600
-
601
-                $con = $spread_data['contribute'] + bcmul($pv, $rate, 2);
602
-                $score = $spread_data['score'] + bcmul($pv, $rate, 2);
603
-
604
-                //贡献值和积分
605
-                // Db::name('user')->where('uid',$spread_data['uid'])->update(["contribute"=>$con,"score"=>$score]);
606
-
607
-                //推广佣金
608
-                $this->bill_user_log($spread_data['uid'], $yj_amount_90, $store_order_data['order_id'], 3, $group_order['group_order_sn'], '推广获得佣金' . $yj_amount_90, $store_order_data['mer_id'], 0);
609 540
                 // 贡献值
610
-                $this->con_log($spread_data['uid'], $pv, $store_order_data['order_id'], 12, "推广商贸区商品赠送贡献值");
611
-                // 积分
612
-                $this->score_log($spread_data['uid'], bcmul($pv, $rate, 2), $store_order_data['order_id'], 12, "推广商贸区商品赠送积分");
541
+                $gongxianValue = bcmul($pv, $movie_commission_rate_config['contributionvalue_spread_user_rate'], 2);
542
+                $storeOrderRepository->con_log($spread_data['uid'], $gongxianValue, $orderinfo['order_id'], 13, "电影票-推广者用户身份获得赠送贡献值");
613 543
             }
614 544
         }
615 545
 
616
-        //锁客收益
617
-        if ($user_data['mer_id'] != 0) {
618
-            $merchant_data = Db::name('merchant')->where('mer_id', $user_data['mer_id'])->find();
619
-            $merchant_user_data = Db::name('user')->where('uid', $merchant_data['uid'])->find();
620
-            if (!empty($merchant_user_data)) {
621
-                //给推广者分配佣金
622
-                $yj_amount_90 = bcmul($pv, 0.05, 2) * 0.9;
623
-                $fgj_amount_10 = bcmul($pv, 0.05, 2) * 0.1;//推广者的佣金抽10%到个人复购金
624
-
625
-                $yj_amount = $merchant_user_data['brokerage_price'] + $yj_amount_90;
626
-                $fgj_amount = $merchant_user_data['fugou'] + $fgj_amount_10;
627
-                $this->fugou_user_log($merchant_data['uid'], $fgj_amount_10, $store_order_data['order_id'], 1);
628
-
629
-                //推广佣金
630
-                $this->bill_user_log($merchant_data['uid'], $yj_amount_90, $store_order_data['order_id'], 3, $group_order['group_order_sn'], '推广获得佣金' . $yj_amount_90, $store_order_data['mer_id'], 0);
631
-            }
632
-            /** @var OrderMerchantRepository $orderMerchantRepository */
633
-            $orderMerchantRepository = app()->make(OrderMerchantRepository::class);
634
-            $jdAndGonxianConfig = $orderMerchantRepository->getMerchantContribution($store_order_data['extension_two']);
635
-
636
-            //商户获得贡献值
637
-            if ($concession_pri >= 0.01) {
638
-                $gonxian = bcmul($concession_pri, $jdAndGonxianConfig['gonxian'], 2);
639
-                $gongxian_data = [
640
-                    "uid" => $merchant_data["uid"],
641
-                    "mer_id" => $user_data['mer_id'],
642
-                    "pv" => $pv,
643
-                    "number" => $gonxian,
644
-                    "addtime" => time(),
645
-                    "status" => -1,
646
-                    "order_type" => 2,
647
-                    "order_id" => $store_order_data['order_id'],
648
-                    "mark" => "锁客商家获得贡献值",
649
-                    "desc" => '',
650
-                    "surplus" => $gonxian,
651
-                    "type" => 1
652
-                ];
653
-                Db::name("user_sign_gongxian")->insert($gongxian_data);//添加记录
654
-            } else {
655
-                Db::name('log')->insert(['data' => '订单号:' . $store_order_data['order_id'] . '付款额度较低或 商家、平台设置的返佣比例较低,贡献值低于0.01无法入库 特此记录!']);
546
+        // 锁客收益
547
+        if ($user['mer_id'] != 0) {
548
+            $merchant_uid = Db::name('merchant')->where('mer_id', $user['mer_id'])->value('uid');
549
+            $merchant_user = Db::name('user')->where('uid', $merchant_uid)->find();
550
+            if (!empty($merchant_user)) {
551
+                // 锁客佣金
552
+                $yj_amount_90 = round(bcmul($pv, $movie_commission_rate_config['commission_lockpassenger_merid_rate'], 2) * $movie_commission_rate_config['commission_lockpassenger_rate'], 2);
553
+                $this->distributionAnnuityEarnings(
554
+                    $merchant_uid, $yj_amount_90, $orderinfo['order_id'], 3, $orderinfo['order_sn'], '电影票-商户锁定用户获得佣金' . $yj_amount_90,
555
+                    $user['mer_id'], 0
556
+                );
557
+
558
+                // 锁客复购金
559
+                $fgj_amount_10 = round(bcmul($pv, $movie_commission_rate_config['repurchase_lockpassenger_merid_rate'], 2) * $movie_commission_rate_config['repurchase_lockpassenger_rate'], 2);
560
+                $storeOrderRepository->fugou_user_log($merchant_uid, $fgj_amount_10, $orderinfo['order_id'], 1);
656 561
             }
562
+        }
563
+    }
657 564
 
658
-            //商户获得京豆
659
-            if ($concession_pri >= 0.01) {
660
-                $jd = bcmul($concession_pri, $jdAndGonxianConfig['jd'], 2);
661
-                $jd_data = [
662
-                    "uid" => $merchant_data["uid"],
663
-                    "mer_id" => $user_data['mer_id'],
664
-                    "number" => $jd,
665
-                    "addtime" => time(),
666
-                    "status" => -1,
667
-                    "order_type" => 2,
668
-                    "order_id" => $store_order_data['order_id'],
669
-                    "mark" => "锁客商家获得京豆",
670
-                    "desc" => '',
671
-                    "surplus" => $jd,
672
-                    "type" => 1
673
-                ];
674
-                Db::name("user_sign_jingdou")->insert($jd_data);//添加记录
675
-            } else {
676
-                Db::name('log')->insert(['data' => '订单号:' . $store_order_data['order_id'] . '付款额度较低或 商家、平台设置的返佣比例较低,京豆低于0.01无法入库 特此记录!']);
677
-            }
565
+    /**
566
+     * 直推奖、养老金
567
+     *
568
+     * @param $uid
569
+     * @param $num
570
+     * @param $order_id
571
+     * @param $comm_order_type
572
+     * @param $order_sn
573
+     * @param $mark
574
+     * @param $merid
575
+     * @param $ds
576
+     * @return void
577
+     */
578
+    private function distributionAnnuityEarnings($uid, $num, $order_id, $comm_order_type, $order_sn, $mark, $merid, $ds = 0)
579
+    {
580
+        $name = '';
581
+
582
+        if ($comm_order_type == 3) {
583
+            $name = '直推奖';
584
+
585
+        } else if ($comm_order_type == 5) {
586
+            $name = '养老金';
678 587
         }
588
+
589
+        $bill = [
590
+            'uid' => $uid,
591
+            'link_id' => $order_id,//关联订单id
592
+            'pm' => 1,//0:支出,1:获得
593
+            'title' => $name,//账单标题
594
+            'category' => 'now_money',//明细种类
595
+            'type' => 'commission',//明细类型
596
+            'number' => $num,//明细数字
597
+            'balance' => 0,//剩余
598
+            'mark' => $mark,//备注
599
+            'create_time' => date('Y-m-d H:i:s'),//添加时间
600
+            'status' => $ds,//0待确定,1有效,-1无效
601
+            'commission_type' => $comm_order_type,//佣金类型 1代理费 2 消费佣金 3直推奖√ 4辖区佣金\r\n5 养老金√ 6 广告费
602
+            //7 跨店奖励√ 8平台奖励 9渠道商\r\n10 推荐创客收益√ 11分红奖金√ 12代理区域收益√ 13消费循环佣金
603
+            //14-推荐代理收益√ 15邀请小区团长升级√ 16大v分享奖√ 17创客合伙人√ 18积分奖励√ 19创客补贴√’
604
+            'order_sn' => $order_sn,//订单号
605
+            'tripartite' => 0,//
606
+            'type_shop' => 0,//0平台1多多进宝2唯品会3苏宁易购4网易考拉5淘宝客6京东联盟7饿了么8线上
607
+            'mer_id' => $merid,//商户id
608
+            'source' => 0,//1线下 0线上
609
+            'order_type' => 1,//1自营  2 第三方  订单类型
610
+            'is_red_brokerage' => 0,//1红积分对冲佣金 0正常佣金
611
+            'gzc' => 0,//养老金是否已进入公证处log表0:未进入。1:已进入
612
+            'take_time' => '',//结算时间
613
+            'district_id' => '',//
614
+            'street_id' => '',//
615
+            'month' => '',//月份
616
+        ];
617
+
618
+        Db::name('user_bill')->insert($bill);
679 619
     }
680 620
 
681 621
     /**