family 1 год назад
Родитель
Сommit
5114997c47

+ 5 - 59
app/common/dao/movie/order/MovieOrderDao.php

@@ -42,78 +42,24 @@ class MovieOrderDao extends BaseDao
42 42
      * @author xaboyCRMEB
43 43
      * @day 2020/6/16
44 44
      */
45
-    public function search(array $where, $sysDel = 0)
45
+    public function search(array $where)
46 46
     {
47 47
         return MovieOrder::getDB()
48
-            ->when(($sysDel !== null), function ($query) use ($sysDel) {
49
-                $query->where('is_system_del', $sysDel);
50
-            })
51 48
             ->when(isset($where['pay_type']) && $where['pay_type'] != -1 && $where['pay_type'] >= 0, function ($query) use ($where) {
52 49
                 $query->where('pay_type', $where['pay_type']);
53 50
             })
54
-            ->when(isset($where['order_type']) && $where['order_type'] && $where['order_type'] >= 0, function ($query) use ($where) {
55
-                $query->where('order_type', $where['order_type']);
56
-            })
57
-            ->when(isset($where['distribution_mode']) && $where['distribution_mode'] && $where['distribution_mode'] >= 0, function ($query) use ($where) {
58
-                $query->where('distribution_mode', $where['distribution_mode']);
59
-            })
60
-            ->when(isset($where['status']) && $where['status'] !== '', function ($query) use ($where) {
61
-                if ($where['status'] == -2)
62
-                    $query->where('paid', 1);
63
-                else
64
-                    $query->where('status', $where['status']);
65
-            })
66 51
             ->when(isset($where['uid']) && $where['uid'] !== '', function ($query) use ($where) {
67 52
                 $query->where('uid', $where['uid']);
68 53
             })
69
-            ->when(isset($where['take_order']), function ($query) use ($where) {
70
-                $query->where('order_type', 1)->where('status', '>=', 2);
71
-            })
72
-            ->when(isset($where['mer_id']) && $where['mer_id'] !== '', function ($query) use ($where) {
73
-                $query->where('mer_id', $where['mer_id']);
74
-            })
75
-            ->when(isset($where['date']) && $where['date'] !== '', function ($query) use ($where) {
76
-                getModelTime($query, $where['date']);
77
-            })
78
-            ->when(isset($where['verify_date']) && $where['verify_date'] !== '', function ($query) use ($where) {
79
-                getModelTime($query, $where['verify_date']);
54
+            ->when(isset($where['status']) && $where['status'] !== '', function ($query) use ($where) {
55
+                $query->whereIn('status', $where['status']);
80 56
             })
81 57
             ->when(isset($where['order_sn']) && $where['order_sn'] !== '', function ($query) use ($where) {
82
-                $query->where('order_sn', 'like', '%' . $where['order_sn'] . '%');
58
+                $query->where('order_sn', '=', $where['order_sn']);
83 59
             })
84 60
             ->when(isset($where['paid']) && $where['paid'] !== '', function ($query) use ($where) {
85 61
                 $query->where('paid', $where['paid']);
86
-            })
87
-            ->when(isset($where['is_del']) && $where['is_del'] !== '', function ($query) use ($where) {
88
-                $query->where('is_del', $where['is_del']);
89
-            })
90
-            ->when(isset($where['service_id']) && $where['service_id'] !== '', function ($query) use ($where) {
91
-                $query->where('service_id', $where['service_id']);
92
-            })
93
-            ->when(isset($where['username']) && $where['username'] !== '', function ($query) use ($where) {
94
-                $uid = User::where('nickname', 'like', "%{$where['username']}%")
95
-                    ->whereOr('phone', 'like', "%{$where['username']}%")
96
-                    ->column('uid');
97
-                $query->where('uid', 'in', $uid);
98
-            })
99
-            ->when(isset($where['gzc']) && $where['gzc'] !== '', function ($query) use ($where) {
100
-                $query->where('gzc', $where['gzc']);
101
-            })
102
-            ->when(isset($where['keywords']) && $where['keywords'] !== '', function ($query) use ($where) {
103
-                $query->where(function ($query) use ($where) {
104
-                    $query->where('real_name', 'like', "%" . $where['keywords'] . "%")
105
-                        ->whereOr('user_phone', 'like', "%{$where['keywords']}%")
106
-                        ->whereOr('order_sn', 'like', '%' . $where['keywords'] . '%')
107
-                        ->whereOr('verify_code', 'like', '%' . $where['keywords'] . '%');
108
-                });
109
-            })
110
-            ->when(isset($where['reconciliation_type']) && $where['reconciliation_type'] !== '', function ($query) use ($where) {
111
-                $query->when($where['reconciliation_type'], function ($query) use ($where) {
112
-                    $query->where('reconciliation_id', '<>', 0);
113
-                }, function ($query) use ($where) {
114
-                    $query->where('reconciliation_id', 0);
115
-                });
116
-            })->order('create_time DESC');
62
+            });
117 63
     }
118 64
 
119 65
     /**

+ 265 - 0
app/common/repositories/movie/MovieRepository.php

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

+ 13 - 0
app/controller/api/movie/Movie.php

@@ -214,6 +214,19 @@ class Movie extends BaseController
214 214
     }
215 215
 
216 216
     /**
217
+     * 订单列表
218
+     *
219
+     * @return mixed
220
+     */
221
+    public function getOrderList()
222
+    {
223
+        [$page, $limit] = $this->getPage();
224
+        $type = $this->request->param('type', -1);//订单状态:-1:全部,0 待支付 1 已支付 2已超时 3已取消 4已成功
225
+
226
+        return app('json')->success($this->repository->getOrderList($this->request->userInfo(), $page, $limit, $type));
227
+    }
228
+
229
+    /**
217 230
      * 查询订单信息
218 231
      *
219 232
      * @return mixed

+ 1 - 0
route/api.php

@@ -1279,6 +1279,7 @@ Route::group('api/', function () {
1279 1279
         Route::get('film_sched', '/getFilmSched'); // 根据影片排片日期查询排片影院
1280 1280
         Route::get('cinemafilm_sched', '/getCinemaFilmSched'); // 根据影院影片场次日期查询场次列表
1281 1281
         Route::get('sched_seat', '/getSchedSeat'); // 获取场次座位
1282
+        Route::get('order_list', '/getOrderList'); // 订单列表
1282 1283
     })->prefix('api.movie.Movie');
1283 1284
 
1284 1285
     //电影 - 下单业务