|
|
@@ -10,12 +10,14 @@ namespace app\common\repositories\movie;
|
|
10
|
10
|
use app\common\dao\movie\order\MovieOrderDao;
|
|
11
|
11
|
use app\common\model\movie\order\MovieOrder;
|
|
12
|
12
|
use app\common\repositories\BaseRepository;
|
|
|
13
|
+use app\common\repositories\merchant\order\OrderMerchantRepository;
|
|
13
|
14
|
use app\common\repositories\store\order\StoreOrderRepository;
|
|
14
|
15
|
use app\traits\HuiPay;
|
|
15
|
16
|
use crmeb\services\ApiResponseService;
|
|
16
|
17
|
use think\exception\ValidateException;
|
|
17
|
18
|
use think\facade\Db;
|
|
18
|
19
|
use think\facade\Log;
|
|
|
20
|
+use function Symfony\Component\String\b;
|
|
19
|
21
|
|
|
20
|
22
|
/**
|
|
21
|
23
|
* Class MovieRepository
|
|
|
@@ -431,6 +433,8 @@ class MovieRepository extends BaseRepository
|
|
431
|
433
|
if ($res) {
|
|
432
|
434
|
$confirmOrder = DouHuoMallFilmApiRequest::confirmOrder($orderinfo['order_sn'], $orderinfo['price']);
|
|
433
|
435
|
if (!empty($confirmOrder) && isset($confirmOrder['code']) && ($confirmOrder['code'] == ApiResponseService::DEFAULT_SUCCESS_CODE)) {
|
|
|
436
|
+ // 计算佣金分红奖励
|
|
|
437
|
+ $this->calculationCommissionDividendAward();
|
|
434
|
438
|
// 提交事务
|
|
435
|
439
|
Db::commit();
|
|
436
|
440
|
} else {
|
|
|
@@ -444,4 +448,265 @@ class MovieRepository extends BaseRepository
|
|
444
|
448
|
Db::rollback();
|
|
445
|
449
|
}
|
|
446
|
450
|
}
|
|
|
451
|
+
|
|
|
452
|
+ private function calculationCommissionDividendAward()
|
|
|
453
|
+ {
|
|
|
454
|
+ //商家让利部分的拆分
|
|
|
455
|
+ $ylj_pri = bcmul($concession_pri, 0.3, 2); // 让利部分30%给消费者做养老金
|
|
|
456
|
+ $pv = bcmul($concession_pri, 0.35, 2); // 35%做业绩PV分配
|
|
|
457
|
+
|
|
|
458
|
+ //分配养老金给消费者
|
|
|
459
|
+ $ylj_amount_mine = $user_data['annuity'] + $ylj_pri;
|
|
|
460
|
+ //分配积分和贡献值给消费者
|
|
|
461
|
+ $con = $user_data['contribute'] + $pv;
|
|
|
462
|
+ $score = $user_data['score'] + $pv;
|
|
|
463
|
+
|
|
|
464
|
+ // 让利部分30%给消费者做养老金{$ylj_pri}
|
|
|
465
|
+ $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);
|
|
|
466
|
+ // @todo 消费者购买商品赠送PV等值的积分和贡献值
|
|
|
467
|
+ // 贡献值
|
|
|
468
|
+// $this->con_log($user_data['uid'], $pv, $store_order_data['order_id'], 12, "购买商贸区商品赠送贡献值");
|
|
|
469
|
+ // 积分
|
|
|
470
|
+ $this->score_log($user_data['uid'], $pv, $store_order_data['order_id'], 12, "购买商贸区商品赠送积分");
|
|
|
471
|
+
|
|
|
472
|
+ // @todo ------------PV业绩100%分配如下------------------
|
|
|
473
|
+ if ($user_data['spread_uid'] != 0) {
|
|
|
474
|
+ //查询下单用户上级
|
|
|
475
|
+ $spread_data = Db::name('user')->where('uid', $user_data['spread_uid'])->find();
|
|
|
476
|
+
|
|
|
477
|
+ $rate = static::getUserGroupRate($spread_data['user_group']);
|
|
|
478
|
+ if ($spread_data['user_group'] > 1) {
|
|
|
479
|
+ $ssf = 0;//变量
|
|
|
480
|
+ $yj_amount_90 = 0;//90%的佣金
|
|
|
481
|
+ // 业务员
|
|
|
482
|
+ if ($spread_data['user_group'] == 2) {
|
|
|
483
|
+ $ssf = bcmul($pv, $rate, 2);
|
|
|
484
|
+ $con = $spread_data['contribute'] + bcmul($pv, $rate, 2);
|
|
|
485
|
+ $score = $spread_data['score'] + bcmul($pv, $rate, 2);
|
|
|
486
|
+
|
|
|
487
|
+
|
|
|
488
|
+ $yj_amount_90 = bcmul($pv, $rate, 2) * 0.9;
|
|
|
489
|
+ $fgj_amount_10 = bcmul($pv, $rate, 2) * 0.1;//推广者的佣金抽10%到个人复购金
|
|
|
490
|
+
|
|
|
491
|
+ $yj_amount = $spread_data['brokerage_price'] + $yj_amount_90;
|
|
|
492
|
+ $fgj_amount = $spread_data['fugou'] + $fgj_amount_10;
|
|
|
493
|
+ $this->fugou_user_log($spread_data['uid'], $fgj_amount_10, $store_order_data['order_id'], 1);
|
|
|
494
|
+ } else if ($spread_data['user_group'] == 3) {
|
|
|
495
|
+ $ssf = bcmul($pv, $rate, 2);
|
|
|
496
|
+ $con = $spread_data['contribute'] + bcmul($pv, $rate, 2);
|
|
|
497
|
+ $score = $spread_data['score'] + bcmul($pv, $rate, 2);
|
|
|
498
|
+
|
|
|
499
|
+ $yj_amount_90 = bcmul($pv, $rate, 2) * 0.9;
|
|
|
500
|
+ $fgj_amount_10 = bcmul($pv, $rate, 2) * 0.1;//推广者的佣金抽10%到个人复购金
|
|
|
501
|
+
|
|
|
502
|
+ $yj_amount = $spread_data['brokerage_price'] + $yj_amount_90;
|
|
|
503
|
+ $fgj_amount = $spread_data['fugou'] + $fgj_amount_10;
|
|
|
504
|
+ $this->fugou_user_log($spread_data['uid'], $fgj_amount_10, $store_order_data['order_id'], 1);
|
|
|
505
|
+
|
|
|
506
|
+ // Db::name('user')->where('uid',$spread_data['uid'])->update(['contribute'=> $con,'score'=> $score,'brokerage_price'=> $yj_amount,'annuity'=>$ylj_amount,'fugou'=>$fgj_amount]);
|
|
|
507
|
+ } else if ($spread_data['user_group'] == 4) {
|
|
|
508
|
+ $ssf = bcmul($pv, $rate, 2);
|
|
|
509
|
+ $con = $spread_data['contribute'] + bcmul($pv, $rate, 2);
|
|
|
510
|
+ $score = $spread_data['score'] + bcmul($pv, $rate, 2);
|
|
|
511
|
+
|
|
|
512
|
+ $yj_amount_90 = bcmul($pv, $rate, 2) * 0.9;
|
|
|
513
|
+ $fgj_amount_10 = bcmul($pv, $rate, 2) * 0.1;//推广者的佣金抽10%到个人复购金
|
|
|
514
|
+
|
|
|
515
|
+ $yj_amount = $spread_data['brokerage_price'] + $yj_amount_90;
|
|
|
516
|
+ $fgj_amount = $spread_data['fugou'] + $fgj_amount_10;
|
|
|
517
|
+ $this->fugou_user_log($spread_data['uid'], $fgj_amount_10, $store_order_data['order_id'], 1);
|
|
|
518
|
+
|
|
|
519
|
+ //Db::name('user')->where('uid',$spread_data['uid'])->update(['contribute'=> $con,'score'=> $score,'brokerage_price'=> $yj_amount,'annuity'=>$ylj_amount,'fugou'=>$fgj_amount]);
|
|
|
520
|
+ } else if ($spread_data['user_group'] == 5) {
|
|
|
521
|
+ $ssf = bcmul($pv, $rate, 2);
|
|
|
522
|
+ $con = $spread_data['contribute'] + bcmul($pv, $rate, 2);
|
|
|
523
|
+ $score = $spread_data['score'] + bcmul($pv, $rate, 2);
|
|
|
524
|
+ // $yj_amount = $spread_data['brokerage_price'] + round($pv * $rate,2);
|
|
|
525
|
+
|
|
|
526
|
+ $yj_amount_90 = bcmul($pv, $rate, 2) * 0.9;
|
|
|
527
|
+ $fgj_amount_10 = bcmul($pv, $rate, 2) * 0.1;//推广者的佣金抽10%到个人复购金
|
|
|
528
|
+
|
|
|
529
|
+ $yj_amount = $spread_data['brokerage_price'] + $yj_amount_90;
|
|
|
530
|
+ $fgj_amount = $spread_data['fugou'] + $fgj_amount_10;
|
|
|
531
|
+ $this->fugou_user_log($spread_data['uid'], $fgj_amount_10, $store_order_data['order_id'], 1);
|
|
|
532
|
+
|
|
|
533
|
+ // Db::name('user')->where('uid',$spread_data['uid'])->update(['contribute'=> $con,'score'=> $score,'brokerage_price'=> $yj_amount,'annuity'=>$ylj_amount,'fugou'=>$fgj_amount]);
|
|
|
534
|
+ } else if ($spread_data['user_group'] == 6) {
|
|
|
535
|
+ $ssf = bcmul($pv, $rate, 2);
|
|
|
536
|
+ $con = $spread_data['contribute'] + bcmul($pv, $rate, 2);
|
|
|
537
|
+ $score = $spread_data['score'] + bcmul($pv, $rate, 2);
|
|
|
538
|
+
|
|
|
539
|
+ $yj_amount_90 = bcmul($pv, $rate, 2) * 0.9;
|
|
|
540
|
+ $fgj_amount_10 = bcmul($pv, $rate, 2) * 0.1;//推广者的佣金抽10%到个人复购金
|
|
|
541
|
+
|
|
|
542
|
+ $yj_amount = $spread_data['brokerage_price'] + $yj_amount_90;
|
|
|
543
|
+ $fgj_amount = $spread_data['fugou'] + $fgj_amount_10;
|
|
|
544
|
+ $this->fugou_user_log($spread_data['uid'], $fgj_amount_10, $store_order_data['order_id'], 1);
|
|
|
545
|
+
|
|
|
546
|
+ // Db::name('user')->where('uid',$spread_data['uid'])->update(['contribute'=> $con,'score'=> $score,'brokerage_price'=> $yj_amount,'annuity'=>$ylj_amount,'fugou'=>$fgj_amount]);
|
|
|
547
|
+ } else if ($spread_data['user_group'] == 7) {
|
|
|
548
|
+ $ssf = bcmul($pv, $rate, 2);
|
|
|
549
|
+ $con = $spread_data['contribute'] + bcmul($pv, $rate, 2);
|
|
|
550
|
+ $score = $spread_data['score'] + bcmul($pv, $rate, 2);
|
|
|
551
|
+
|
|
|
552
|
+
|
|
|
553
|
+ $yj_amount_90 = bcmul($pv, $rate, 2) * 0.9;
|
|
|
554
|
+ $fgj_amount_10 = bcmul($pv, $rate, 2) * 0.1;//推广者的佣金抽10%到个人复购金
|
|
|
555
|
+
|
|
|
556
|
+ $yj_amount = $spread_data['brokerage_price'] + $yj_amount_90;
|
|
|
557
|
+ $fgj_amount = $spread_data['fugou'] + $fgj_amount_10;
|
|
|
558
|
+ $this->fugou_user_log($spread_data['uid'], $fgj_amount_10, $store_order_data['order_id'], 1);
|
|
|
559
|
+
|
|
|
560
|
+ // Db::name('user')->where('uid',$spread_data['uid'])->update(['contribute'=> $con,'score'=> $score,'brokerage_price'=> $yj_amount,'annuity'=>$ylj_amount,'fugou'=>$fgj_amount]);
|
|
|
561
|
+ }
|
|
|
562
|
+
|
|
|
563
|
+ //贡献值
|
|
|
564
|
+ $this->con_log($spread_data['uid'], $pv, $store_order_data['order_id'], 12, "商贸区商品赠送贡献值");
|
|
|
565
|
+ //积分
|
|
|
566
|
+ $this->score_log($spread_data['uid'], $ssf, $store_order_data['order_id'], 12, "商贸区商品赠送积分");
|
|
|
567
|
+ //推广佣金
|
|
|
568
|
+ $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);
|
|
|
569
|
+ //养老金
|
|
|
570
|
+ $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);
|
|
|
571
|
+ }
|
|
|
572
|
+
|
|
|
573
|
+ //普通用户推广人
|
|
|
574
|
+ if ($spread_data['user_group'] == 1) {
|
|
|
575
|
+ //给推广者分配佣金
|
|
|
576
|
+
|
|
|
577
|
+ $yj_amount_90 = bcmul($pv, $rate, 2) * 0.9;
|
|
|
578
|
+ $fgj_amount_10 = bcmul($pv, $rate, 2) * 0.1;//推广者的佣金抽10%到个人复购金
|
|
|
579
|
+
|
|
|
580
|
+ $yj_amount = $spread_data['brokerage_price'] + $yj_amount_90;
|
|
|
581
|
+ $fgj_amount = $spread_data['fugou'] + $fgj_amount_10;
|
|
|
582
|
+ $this->fugou_user_log($spread_data['uid'], $fgj_amount_10, $store_order_data['order_id'], 1);
|
|
|
583
|
+
|
|
|
584
|
+ //Db::name('user')->where('uid',$spread_data['uid'])->update(['brokerage_price'=>$yj_amount,'fugou'=>$fgj_amount]);
|
|
|
585
|
+
|
|
|
586
|
+ $con = $spread_data['contribute'] + bcmul($pv, $rate, 2);
|
|
|
587
|
+ $score = $spread_data['score'] + bcmul($pv, $rate, 2);
|
|
|
588
|
+
|
|
|
589
|
+ //贡献值和积分
|
|
|
590
|
+ // Db::name('user')->where('uid',$spread_data['uid'])->update(["contribute"=>$con,"score"=>$score]);
|
|
|
591
|
+
|
|
|
592
|
+ //推广佣金
|
|
|
593
|
+ $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);
|
|
|
594
|
+ // 贡献值
|
|
|
595
|
+ $this->con_log($spread_data['uid'], $pv, $store_order_data['order_id'], 12, "推广商贸区商品赠送贡献值");
|
|
|
596
|
+ // 积分
|
|
|
597
|
+ $this->score_log($spread_data['uid'], bcmul($pv, $rate, 2), $store_order_data['order_id'], 12, "推广商贸区商品赠送积分");
|
|
|
598
|
+ }
|
|
|
599
|
+ }
|
|
|
600
|
+
|
|
|
601
|
+ //锁客收益
|
|
|
602
|
+ if ($user_data['mer_id'] != 0) {
|
|
|
603
|
+ $merchant_data = Db::name('merchant')->where('mer_id', $user_data['mer_id'])->find();
|
|
|
604
|
+ $merchant_user_data = Db::name('user')->where('uid', $merchant_data['uid'])->find();
|
|
|
605
|
+ if (!empty($merchant_user_data)) {
|
|
|
606
|
+ //给推广者分配佣金
|
|
|
607
|
+ $yj_amount_90 = bcmul($pv, 0.05, 2) * 0.9;
|
|
|
608
|
+ $fgj_amount_10 = bcmul($pv, 0.05, 2) * 0.1;//推广者的佣金抽10%到个人复购金
|
|
|
609
|
+
|
|
|
610
|
+ $yj_amount = $merchant_user_data['brokerage_price'] + $yj_amount_90;
|
|
|
611
|
+ $fgj_amount = $merchant_user_data['fugou'] + $fgj_amount_10;
|
|
|
612
|
+ $this->fugou_user_log($merchant_data['uid'], $fgj_amount_10, $store_order_data['order_id'], 1);
|
|
|
613
|
+
|
|
|
614
|
+ //推广佣金
|
|
|
615
|
+ $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);
|
|
|
616
|
+ }
|
|
|
617
|
+ /** @var OrderMerchantRepository $orderMerchantRepository */
|
|
|
618
|
+ $orderMerchantRepository = app()->make(OrderMerchantRepository::class);
|
|
|
619
|
+ $jdAndGonxianConfig = $orderMerchantRepository->getMerchantContribution($store_order_data['extension_two']);
|
|
|
620
|
+
|
|
|
621
|
+ //商户获得贡献值
|
|
|
622
|
+ if ($concession_pri >= 0.01) {
|
|
|
623
|
+ $gonxian = bcmul($concession_pri, $jdAndGonxianConfig['gonxian'], 2);
|
|
|
624
|
+ $gongxian_data = [
|
|
|
625
|
+ "uid" => $merchant_data["uid"],
|
|
|
626
|
+ "mer_id" => $user_data['mer_id'],
|
|
|
627
|
+ "pv" => $pv,
|
|
|
628
|
+ "number" => $gonxian,
|
|
|
629
|
+ "addtime" => time(),
|
|
|
630
|
+ "status" => -1,
|
|
|
631
|
+ "order_type" => 2,
|
|
|
632
|
+ "order_id" => $store_order_data['order_id'],
|
|
|
633
|
+ "mark" => "锁客商家获得贡献值",
|
|
|
634
|
+ "desc" => '',
|
|
|
635
|
+ "surplus" => $gonxian,
|
|
|
636
|
+ "type" => 1
|
|
|
637
|
+ ];
|
|
|
638
|
+ Db::name("user_sign_gongxian")->insert($gongxian_data);//添加记录
|
|
|
639
|
+ } else {
|
|
|
640
|
+ Db::name('log')->insert(['data' => '订单号:' . $store_order_data['order_id'] . '付款额度较低或 商家、平台设置的返佣比例较低,贡献值低于0.01无法入库 特此记录!']);
|
|
|
641
|
+ }
|
|
|
642
|
+
|
|
|
643
|
+ //商户获得京豆
|
|
|
644
|
+ if ($concession_pri >= 0.01) {
|
|
|
645
|
+ $jd = bcmul($concession_pri, $jdAndGonxianConfig['jd'], 2);
|
|
|
646
|
+ $jd_data = [
|
|
|
647
|
+ "uid" => $merchant_data["uid"],
|
|
|
648
|
+ "mer_id" => $user_data['mer_id'],
|
|
|
649
|
+ "number" => $jd,
|
|
|
650
|
+ "addtime" => time(),
|
|
|
651
|
+ "status" => -1,
|
|
|
652
|
+ "order_type" => 2,
|
|
|
653
|
+ "order_id" => $store_order_data['order_id'],
|
|
|
654
|
+ "mark" => "锁客商家获得京豆",
|
|
|
655
|
+ "desc" => '',
|
|
|
656
|
+ "surplus" => $jd,
|
|
|
657
|
+ "type" => 1
|
|
|
658
|
+ ];
|
|
|
659
|
+ Db::name("user_sign_jingdou")->insert($jd_data);//添加记录
|
|
|
660
|
+ } else {
|
|
|
661
|
+ Db::name('log')->insert(['data' => '订单号:' . $store_order_data['order_id'] . '付款额度较低或 商家、平台设置的返佣比例较低,京豆低于0.01无法入库 特此记录!']);
|
|
|
662
|
+ }
|
|
|
663
|
+ }
|
|
|
664
|
+ }
|
|
|
665
|
+
|
|
|
666
|
+ /**
|
|
|
667
|
+ * 订单列表
|
|
|
668
|
+ *
|
|
|
669
|
+ * @param $userinfo
|
|
|
670
|
+ * @param $page
|
|
|
671
|
+ * @param $limit
|
|
|
672
|
+ * @param $type
|
|
|
673
|
+ * @return array
|
|
|
674
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
675
|
+ * @throws \think\db\exception\DbException
|
|
|
676
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
677
|
+ */
|
|
|
678
|
+ public function getOrderList($userinfo, $page, $limit, $type = -1)
|
|
|
679
|
+ {
|
|
|
680
|
+ $where['uid'] = $userinfo['uid'];
|
|
|
681
|
+ switch ($type) {
|
|
|
682
|
+ case 0:
|
|
|
683
|
+ $where['status'] = [0];
|
|
|
684
|
+ break;
|
|
|
685
|
+ case 1:
|
|
|
686
|
+ case 4:
|
|
|
687
|
+ $where['status'] = [1, 4];
|
|
|
688
|
+ break;
|
|
|
689
|
+ case 2:
|
|
|
690
|
+ case 3:
|
|
|
691
|
+ $where['status'] = [2, 3];
|
|
|
692
|
+ break;
|
|
|
693
|
+ default:
|
|
|
694
|
+ break;
|
|
|
695
|
+ }
|
|
|
696
|
+
|
|
|
697
|
+ $field = 'order_sn,order_price,city_name,area_name,cinema_name,address,hall_name,film_sign,film_name,show_date,show_time,sched_seat,number,status,create_time';
|
|
|
698
|
+ $movie_order = $this->dao->search($where)
|
|
|
699
|
+ ->when($page && $limit, function ($query) use ($page, $limit) {
|
|
|
700
|
+ $query->page($page, $limit);
|
|
|
701
|
+ })->order('order_id desc')->field([$field])->select()->toArray();
|
|
|
702
|
+ foreach ($movie_order as $key => $value) {
|
|
|
703
|
+ $movie_order[$key]['show_date'] = date('Y-m-d', $value['show_date']);
|
|
|
704
|
+ $movie_order[$key]['sched_seat'] = json_decode($value['sched_seat'], true);
|
|
|
705
|
+ $movie_order[$key]['cover_img'] = Db::name('movie_film')->where('film_sign', $value['film_sign'])->value('cover_img');
|
|
|
706
|
+ }
|
|
|
707
|
+
|
|
|
708
|
+ $count = $this->dao->search($where)->count();
|
|
|
709
|
+
|
|
|
710
|
+ return compact('movie_order', 'count');
|
|
|
711
|
+ }
|
|
447
|
712
|
}
|