Explorar o código

Merge branch 'master' into huangfamily

family hai 1 ano
pai
achega
caa4f6132b

+ 31 - 0
app/command/PensionTasks.php

@@ -12,6 +12,7 @@ use app\common\repositories\merchant\order\OrderMerchantRepository;
12 12
 use app\common\repositories\store\order\StoreOrderStatusRepository;
13 13
 use app\common\repositories\store\product\ProductRepository;
14 14
 use app\common\repositories\user\UserBillRepository;
15
+use app\common\repositories\user\UserRepository;
15 16
 use app\traits\GzcApiRequest;
16 17
 use Carbon\Carbon;
17 18
 use think\console\Command;
@@ -524,6 +525,9 @@ class PensionTasks extends Command
524 525
                             'status'          => 1,
525 526
                             'settlement_time' => date('Y-m-d H:i:s')
526 527
                         ]);
528
+                    /** @var UserRepository $userRepository */
529
+                    $userRepository = app()->make(UserRepository::class);
530
+                    $userRepository->setUserIdentity($user_sign_gongxian['uid']);
527 531
                 }
528 532
 
529 533
             });
@@ -772,6 +776,33 @@ class PensionTasks extends Command
772 776
                             'status'          => 1,
773 777
                             'settlement_time' => date('Y-m-d H:i:s')
774 778
                         ]);
779
+                    /** @var UserRepository $userRepository */
780
+                    $userRepository = app()->make(UserRepository::class);
781
+                    $userRepository->setUserIdentity($user_sign_gongxian['uid']);
782
+                }
783
+
784
+                // 结算PV值
785
+                $user_pv_list = Db::name('user_pv_log')
786
+                    ->where('status', -1)
787
+                    ->where('order_id', $online['order_id'])
788
+                    ->whereIn('type', [1, 2])
789
+                    ->select()
790
+                    ->toArray();
791
+                if($user_pv_list) {
792
+                    foreach ($user_pv_list as $user_pv) {
793
+                        // 修改pv
794
+                        Db::name('user')
795
+                            ->where('uid', $user_pv['uid'])
796
+                            ->inc('pv', (float)$user_pv['pv'])
797
+                            ->update();
798
+                        Db::name('user_pv_log')
799
+                            ->where('status', -1)
800
+                            ->where('id', $user_pv['id'])
801
+                            ->update([
802
+                                'status'          => 1,
803
+                                'settlement_time' => date('Y-m-d H:i:s')
804
+                            ]);
805
+                    }
775 806
                 }
776 807
 
777 808
                 

+ 43 - 0
app/command/TaskDividendCommand.php

@@ -0,0 +1,43 @@
1
+<?php
2
+
3
+namespace app\command;
4
+
5
+use app\controller\api\store\merchant\Taskorderguquan;
6
+use app\controller\api\store\merchant\Taskorderlianc;
7
+use app\controller\api\store\merchant\TaskPartnerProfits;
8
+use think\console\Command;
9
+use think\console\Input;
10
+use think\console\Output;
11
+
12
+class TaskDividendCommand extends Command
13
+{
14
+    protected function configure()
15
+    {
16
+        // 配置命令名称及描述
17
+        $this->setName('TaskDividendCommand')
18
+            ->setDescription('分红任务');
19
+    }
20
+
21
+    protected function execute(Input $input, Output $output)
22
+    {
23
+        // 在这里执行任务的具体内容
24
+        $output->writeln('定时任务执行中...');
25
+
26
+        // 合伙人分红
27
+        /** @var TaskPartnerProfits $taskPartnerProfits */
28
+        $taskPartnerProfits = app()->make(TaskPartnerProfits::class);
29
+        $taskPartnerProfits->partnerProfits();
30
+
31
+        // 股份分红
32
+        /** @var Taskorderguquan $taskorderguquan */
33
+        $taskorderguquan = app()->make(Taskorderguquan::class);
34
+        $taskorderguquan->lst6();
35
+
36
+        // 联创分红
37
+        /** @var Taskorderlianc $taskorderlianc */
38
+        $taskorderlianc = app()->make(Taskorderlianc::class);
39
+        $taskorderlianc->lst2();
40
+
41
+        $output->writeln('定时任务执行完成');
42
+    }
43
+}

+ 48 - 0
app/common/dao/user/UserIdentityDao.php

@@ -0,0 +1,48 @@
1
+<?php
2
+/**
3
+ * @package merchant
4
+ *
5
+ * @author xaboy
6
+ * @day 2020-05-07
7
+ *
8
+ * 
9
+ */
10
+
11
+namespace app\common\dao\user;
12
+
13
+
14
+use app\common\dao\BaseDao;
15
+use app\common\model\BaseModel;
16
+use app\common\model\user\UserIdentity;
17
+use think\db\BaseQuery;
18
+
19
+/**
20
+ * Class UserIdentityDao
21
+ * @package app\common\dao\user
22
+ */
23
+class UserIdentityDao extends BaseDao
24
+{
25
+
26
+    /**
27
+     * @return BaseModel
28
+     * @author xaboy
29
+     * @day 2020-03-30
30
+     */
31
+    protected function getModel(): string
32
+    {
33
+        return UserIdentity::class;
34
+    }
35
+
36
+
37
+    /**
38
+     * @param array $where
39
+     * @return BaseQuery
40
+     * @author xaboy
41
+     * @day 2020-05-06
42
+     */
43
+    public function search(array $where = [])
44
+    {
45
+        return UserIdentity::getDB();
46
+    }
47
+
48
+}

+ 38 - 0
app/common/model/user/UserIdentity.php

@@ -0,0 +1,38 @@
1
+<?php
2
+/**
3
+ * @package merchant
4
+ *
5
+ * @author xaboy
6
+ * @day 2020-05-07
7
+ *
8
+ * 
9
+ */
10
+
11
+namespace app\common\model\user;
12
+
13
+
14
+use app\common\model\BaseModel;
15
+
16
+class UserIdentity extends BaseModel
17
+{
18
+
19
+    /**
20
+     * @return string
21
+     * @author xaboy
22
+     * @day 2020-03-30
23
+     */
24
+    public static function tablePk(): string
25
+    {
26
+        return 'user_group_id';
27
+    }
28
+
29
+    /**
30
+     * @return string
31
+     * @author xaboy
32
+     * @day 2020-03-30
33
+     */
34
+    public static function tableName(): string
35
+    {
36
+        return 'user_identity';
37
+    }
38
+}

+ 59 - 10
app/common/repositories/store/order/StoreOrderRepository.php

@@ -694,7 +694,7 @@ class StoreOrderRepository extends BaseRepository
694 694
 //                         $mer_money += $moneys - $total_extension_one - $souxufees;
695 695
 //                         if ($cartInfo['mer_id'] == 290) {
696 696
 //                             $moneys = bcsub($moneys, $souxufees, 3);
697
-//                             $moneys = round($moneys, 2); 
697
+//                             $moneys = round($moneys, 2);
698 698
 //                             $total_extension_one = bcmul($moneys, '0.52', 3);
699 699
 //                             $total_extension_one = round($total_extension_one, 2);
700 700
 //                             $mer_money = bcmul($moneys, '0.40', 3);
@@ -3804,6 +3804,9 @@ class StoreOrderRepository extends BaseRepository
3804 3804
                 $yongjinbili = 17;
3805 3805
             }
3806 3806
 
3807
+            $yongjin = $pvfee * $yongjinbili / 100;
3808
+            // 佣金百分之90进入佣金池
3809
+            // $tuiguanyongjin = round($yongjin * 0.9, 2);
3807 3810
             $tuiguanyongjin = bcmul($pvfee, $yongjinbili / 100, 2);
3808 3811
 
3809 3812
 
@@ -3819,6 +3822,21 @@ class StoreOrderRepository extends BaseRepository
3819 3822
                 Db::name('log')->insert(['data' => '订单号:' . $order_sn . '付款额度较低或 商家、平台设置的返佣比例较低,佣金低于0.01无法入库 特此记录!']);
3820 3823
             }
3821 3824
 
3825
+            if($yongjin >= 0.1){
3826
+                // 佣金百分之10进入复购金
3827
+                $orderThird = app()->make(UserThirdRepository::class);
3828
+                //复购金
3829
+                $orderThird->yuguFugou(
3830
+                    $yongjin,
3831
+                    $sprerdUser["uid"],
3832
+                    $order_sn,
3833
+                    $order["type_shop"]
3834
+                );
3835
+            } else {
3836
+                Db::name('log')->insert(['data' => '订单号:' . $order_sn . '付款额度较低或 商家、平台设置的返佣比例较低,复购金低于0.01无法入库 特此记录!']);
3837
+            }
3838
+
3839
+
3822 3840
         }
3823 3841
         //end存养老金
3824 3842
 
@@ -6715,7 +6733,7 @@ class StoreOrderRepository extends BaseRepository
6715 6733
                         $data['status'] = 2;
6716 6734
                     } else {
6717 6735
                         $data['status'] = $value['status'];
6718
-                    }  
6736
+                    }
6719 6737
                     Db::name('store_order')->where('order_sn', $value['order_sn'])->update($data);
6720 6738
                     $s = [
6721 6739
                         'order_id' => $value['order_id'],
@@ -7440,9 +7458,13 @@ class StoreOrderRepository extends BaseRepository
7440 7458
                 ->whereIn('status', [0, 1, 2, 3])
7441 7459
                 ->sum('pay_price');
7442 7460
 //            if ($pay_price >= 365) {
7443
-            Db::name('user')->where('uid', $uid)->whereNotIn('user_group', [3, 4, 5, 6])->update([
7444
-                'user_group' => 2
7445
-            ]);
7461
+//            Db::name('user')->where('uid', $uid)->whereNotIn('user_group', [3, 4, 5, 6])->update([
7462
+//                'user_group' => 2
7463
+//            ]);
7464
+            // 设置用户 身份
7465
+            /** @var UserRepository $userRepository */
7466
+            $userRepository = app()->make(UserRepository::class);
7467
+            $userRepository->setUserIdentity($uid);
7446 7468
         }
7447 7469
 
7448 7470
         $shouxufei = systemConfig('online_yanglao');
@@ -7471,9 +7493,12 @@ class StoreOrderRepository extends BaseRepository
7471 7493
         }
7472 7494
 
7473 7495
         if ($product_id == 15323) {
7474
-            Db::name('user')->where('uid', $uid)->whereNotIn('user_group', [3, 4, 5, 6])->update([
7475
-                'user_group' => 4//升級創客
7476
-            ]);
7496
+//            Db::name('user')->where('uid', $uid)->whereNotIn('user_group', [3, 4, 5, 6])->update([
7497
+//                'user_group' => 4//升級創客
7498
+//            ]);
7499
+            /** @var UserRepository $userRepository */
7500
+            $userRepository = app()->make(UserRepository::class);
7501
+            $userRepository->setUserIdentity($uid);
7477 7502
         }
7478 7503
 
7479 7504
         Db::name('store_order')->where('order_id', $order_id)
@@ -9228,6 +9253,20 @@ class StoreOrderRepository extends BaseRepository
9228 9253
         return $group;
9229 9254
     }
9230 9255
 
9256
+    public function con_log_pv($uid, $num, $order_id, $order_type, $mark, $status = -1)
9257
+    {
9258
+        // 添加pv记录
9259
+        $pv_data = [
9260
+            "uid" => $uid,
9261
+            "pv" => $num,
9262
+            "addtime" => time(),
9263
+            "status" => $status,
9264
+            "order_type" => $order_type,
9265
+            "order_id" => $order_id,
9266
+            "mark" => str_replace('贡献值', 'PV', $mark),
9267
+        ];
9268
+        Db::name("user_pv_log")->insert($pv_data);//添加pv记录
9269
+    }
9231 9270
 
9232 9271
     //添加贡献值日志
9233 9272
     public function con_log($uid, $num, $order_id, $order_type, $mark, $status = -1, $pv = 0)
@@ -9559,6 +9598,7 @@ class StoreOrderRepository extends BaseRepository
9559 9598
                 $this->bill_user_log($user_data['uid'], $ylj_pri, $store_order_data['order_id'], 5, $store_order_data['order_sn'], '消费获得养老金' . $ylj_pri, $store_order_data['mer_id'], 0);
9560 9599
                 // 贡献值
9561 9600
                 $this->con_log($user_data['uid'], $pv, $store_order_data['order_id'], 11, "购买精彩生活商品赠送贡献值");
9601
+                $this->con_log_pv($user_data['uid'], $pv, $store_order_data['order_id'], 11, "购买精彩生活商品赠送贡献值");
9562 9602
                 // 积分
9563 9603
                 $this->score_log($user_data['uid'], $pv, $store_order_data['order_id'], 11, "购买精彩生活商品赠送积分");
9564 9604
 
@@ -9779,6 +9819,9 @@ class StoreOrderRepository extends BaseRepository
9779 9819
 
9780 9820
             $this->bill_user_log($user_data['uid'], bcmul($pv, 0.035, 2), $store_order_data['order_id'], 5, $store_order_data['order_sn'], '消费获得养老金' . bcmul($pv, 0.035, 2), $store_order_data['mer_id']);
9781 9821
             $this->con_log($user_data['uid'], $gx_jf, $store_order_data['order_id'], 11, "购买会员专区商品赠送贡献值", 1, $gx_jf);
9822
+            // $this->bill_user_log($user_data['uid'], round($pv * 0.035, 2), $store_order_data['order_id'], 5, $store_order_data['order_sn'], '消费获得养老金' . round($pv * 0.035, 2), $store_order_data['mer_id']);
9823
+            $this->con_log_pv($user_data['uid'], $gx_jf, $store_order_data['order_id'], 11, "购买会员专区商品赠送贡献值", 1);
9824
+            // $this->con_log($user_data['uid'], $gx_jf, $store_order_data['order_id'], 11, "购买会员专区商品赠送贡献值", 1);
9782 9825
             $this->score_log($user_data['uid'], $gx_jf, $store_order_data['order_id'], 11, "购买会员专区商品赠送积分", 1);
9783 9826
 
9784 9827
             //查询下单用户上级身份(2.0新表用户)
@@ -10052,12 +10095,18 @@ class StoreOrderRepository extends BaseRepository
10052 10095
             if ($totalPayPrice >= 1180 && $totalPayPrice < 11800) {
10053 10096
 
10054 10097
                 if ($userdata['user_group'] <= 1) {
10055
-                    Db::name("user")->where("uid", $store_order_data['uid'])->update(["user_group" => 2]);
10098
+//                    Db::name("user")->where("uid", $store_order_data['uid'])->update(["user_group" => 2]);
10099
+                    /** @var UserRepository $userRepository */
10100
+                    $userRepository = app()->make(UserRepository::class);
10101
+                    $userRepository->setUserIdentity($store_order_data['uid']);
10056 10102
                 }
10057 10103
 
10058 10104
             } else if ($totalPayPrice >= 11800) {
10059 10105
                 if ($userdata['user_group'] <= 2) {
10060
-                    Db::name("user")->where("uid", $store_order_data['uid'])->update(["user_group" => 3]);
10106
+//                    Db::name("user")->where("uid", $store_order_data['uid'])->update(["user_group" => 3]);
10107
+                    /** @var UserRepository $userRepository */
10108
+                    $userRepository = app()->make(UserRepository::class);
10109
+                    $userRepository->setUserIdentity($store_order_data['uid']);
10061 10110
                 }
10062 10111
             }
10063 10112
 

+ 53 - 0
app/common/repositories/store/order/StoreRefundOrderRepository.php

@@ -1516,4 +1516,57 @@ class StoreRefundOrderRepository extends BaseRepository
1516 1516
         });
1517 1517
         return true;
1518 1518
     }
1519
+
1520
+    /**
1521
+     * 取消订单福利
1522
+     * @param $id
1523
+     * @throws \think\db\exception\DbException
1524
+     */
1525
+    public function cancelOrderBonus($id)
1526
+    {
1527
+
1528
+        // //分配逻辑
1529
+        // $store_order_data = Db::name('store_order')->where('group_order_id',$group_order_id)->find();
1530
+        //
1531
+        // //找到对应的商品id(product_id)
1532
+        // $store_order_product_data = Db::name('store_order_product')->where('order_id',$store_order_data['order_id'])->find();
1533
+        // //找到对应的商品让利金额或比例
1534
+        // $store_product_data = Db::name('store_product')->where('product_id',$store_order_product_data['product_id'])->find();
1535
+        // //下单用户
1536
+        // $user_data = Db::name('user')->where('uid',$store_order_data['uid'])->find();
1537
+        // $concession_pri =  $store_order_data['con_pri'];
1538
+
1539
+
1540
+        $refundOrder = $this -> dao -> getWhere(['refund_order_id' => $id]);
1541
+        if(!$refundOrder){
1542
+            return ['code'=>-6,'message'=>'找不到退款订单'];
1543
+        }
1544
+        $refundOrder = $refundOrder -> toArray();
1545
+        $orderId = $refundOrder['order_id'];
1546
+
1547
+        Db::name("user_bill")
1548
+            ->where('link_id', $orderId)
1549
+            ->where('status', 0)
1550
+            ->update(['status' => -1]);
1551
+
1552
+        Db::name("user_sign_fugou")
1553
+            ->where('order_id', $orderId)
1554
+            ->where('status', -1)
1555
+            ->update(['status' => 0]);
1556
+
1557
+        Db::name("user_sign_score")
1558
+            ->where('order_id', $orderId)
1559
+            ->where('status', -1)
1560
+            ->update(['status' => 0]);
1561
+
1562
+        Db::name("user_sign_gongxian")
1563
+            ->where('order_id', $orderId)
1564
+            ->where('status', -1)
1565
+            ->update(['status' => 0]);
1566
+
1567
+        Db::name("user_pv_log")
1568
+            ->where('order_id', $orderId)
1569
+            ->where('status', -1)
1570
+            ->update(['status' => 0]);
1571
+    }
1519 1572
 }

+ 45 - 2
app/common/repositories/store/product/ProductReplyRepository.php

@@ -256,8 +256,51 @@ class ProductReplyRepository extends BaseRepository
256 256
 
257 257
     /*用户评价列表*/
258 258
     public function  getReplyList($where=[],$page=1, $limit=10){
259
-        $count =  Db::name("store_product_reply")->where($where)->count();
260
-        $list = Db::name("store_product_reply")->page($page, $limit)->where($where)->select();
259
+        $count = Db::name("store_product_reply")
260
+            ->where($where)
261
+            ->count();
262
+        $list = Db::name("store_product_reply")
263
+            //            ->alias('spr')  // 给主表起个别名
264
+            //            ->join('store_order_product rsop', 'spr.order_product_id = rsop.order_product_id', 'LEFT')  // 左连接
265
+            //            ->field('spr.*, rsop.*')
266
+            ->where($where)
267
+            ->page($page, $limit)
268
+            ->select()
269
+            ->toArray();
270
+
271
+        $order_product_id_list = array_column($list,'order_product_id');
272
+        $order_product_info_list = Db::name("store_order_product")
273
+            ->whereIn('order_product_id',$order_product_id_list)
274
+            ->select()
275
+            ->toArray();
276
+        $order_product_info_map = array_column($order_product_info_list, null, 'order_product_id');
277
+
278
+        $mer_id_list = array_column($list,'mer_id');
279
+        $mer_info_list = Db::name("merchant")
280
+            ->whereIn('mer_id',$mer_id_list)
281
+            ->select()
282
+            ->toArray();
283
+        $mer_info_map = array_column($mer_info_list, null, 'mer_id');
284
+
285
+        foreach ($list as &$item) {
286
+            if (!empty($order_product_info_map[$item['order_product_id']])) {
287
+                if (!empty($order_product_info_map[$item['order_product_id']]['cart_info'])) {
288
+                    $cart_info = json_decode($order_product_info_map[$item['order_product_id']]['cart_info']);
289
+                    if (json_last_error() == JSON_ERROR_NONE) {
290
+                        $order_product_info_map[$item['order_product_id']]['cart_info'] = $cart_info;
291
+                    }
292
+                }
293
+                $item['order_product_info'] = $order_product_info_map[$item['order_product_id']];
294
+            } else {
295
+                $item['order_product_info'] = new \stdClass();
296
+            }
297
+
298
+            if (!empty($mer_info_map[$item['mer_id']])) {
299
+                $item['mer_info'] = $mer_info_map[$item['mer_id']];
300
+            } else {
301
+                $item['mer_info'] = new \stdClass();
302
+            }
303
+        }
261 304
         return compact('count', 'list');
262 305
     }
263 306
 }

+ 110 - 0
app/common/repositories/user/UserIdentityRepository.php

@@ -0,0 +1,110 @@
1
+<?php
2
+/**
3
+ * @package merchant
4
+ *
5
+ * @author xaboy
6
+ * @day 2020-05-07
7
+ *
8
+ * 
9
+ */
10
+
11
+namespace app\common\repositories\user;
12
+
13
+
14
+use app\common\dao\user\UserIdentityDao;
15
+use app\common\repositories\BaseRepository;
16
+use FormBuilder\Exception\FormBuilderException;
17
+use FormBuilder\Factory\Elm;
18
+use FormBuilder\Form;
19
+use think\db\exception\DataNotFoundException;
20
+use think\db\exception\DbException;
21
+use think\db\exception\ModelNotFoundException;
22
+use think\facade\Route;
23
+
24
+/**
25
+ * Class UserIdentityRepository
26
+ * @package app\common\repositories\user
27
+ * @author xaboy
28
+ * @day 2020-05-07
29
+ * @mixin UserIdentityDao
30
+ */
31
+class UserIdentityRepository extends BaseRepository
32
+{
33
+    /**
34
+     * @var UserIdentityDao
35
+     */
36
+    protected $dao;
37
+
38
+    /**
39
+     * UserGroupRepository constructor.
40
+     * @param UserIdentityDao $dao
41
+     */
42
+    public function __construct(UserIdentityDao $dao)
43
+    {
44
+        $this->dao = $dao;
45
+    }
46
+
47
+    /**
48
+     * @param array $where
49
+     * @param $page
50
+     * @param $limit
51
+     * @return array
52
+     * @throws DataNotFoundException
53
+     * @throws DbException
54
+     * @throws ModelNotFoundException
55
+     * @author xaboy
56
+     * @day 2020-05-07
57
+     */
58
+    public function getList(array $where, $page, $limit)
59
+    {
60
+        $query = $this->dao->search($where);
61
+        $count = $query->count($this->dao->getPk());
62
+        $list = $query->page($page, $limit)->select();
63
+        return compact('count', 'list');
64
+    }
65
+
66
+    /**
67
+     * @param null $id
68
+     * @param array $formData
69
+     * @return Form
70
+     * @throws FormBuilderException
71
+     * @author xaboy
72
+     * @day 2020-05-07
73
+     */
74
+    public function form($id = null, array $formData = [])
75
+    {
76
+        $action = Route::buildUrl('configIdentityUpdate' , compact('id'))->build();
77
+        return Elm::createForm($action, [
78
+            Elm::number('arrive_num_own', '个人达标贡献值')->min(0)->size('large'),
79
+            Elm::number('arrive_num_team', '团队达标贡献值')->min(0)->size('large')
80
+        ])->setTitle('业务员升级设置')->formData($formData);
81
+    }
82
+
83
+    /**
84
+     * @param $id
85
+     * @return Form
86
+     * @throws FormBuilderException
87
+     * @throws DataNotFoundException
88
+     * @throws DbException
89
+     * @throws ModelNotFoundException
90
+     * @author xaboy
91
+     * @day 2020-05-07
92
+     */
93
+    public function updateForm($id)
94
+    {
95
+        return $this->form($id, $this->dao->get($id)->toArray());
96
+    }
97
+
98
+    /**
99
+     * @param array $where
100
+     * @return array
101
+     * @throws DataNotFoundException
102
+     * @throws DbException
103
+     * @throws ModelNotFoundException
104
+     */
105
+    public function getIdentityList(array $where = [])
106
+    {
107
+        $query = $this->dao->search($where);
108
+        return $query->select()->toArray();
109
+    }
110
+}

+ 202 - 0
app/common/repositories/user/UserRepository.php

@@ -3225,4 +3225,206 @@ class UserRepository extends BaseRepository
3225 3225
         $resultArray = array_diff($originalArray, [$uid]);
3226 3226
         return $resultArray;
3227 3227
     }
3228
+
3229
+
3230
+    /**
3231
+     * 设置用户 身份
3232
+     * @param $uid
3233
+     * @param $identityId
3234
+     * @return int|mixed|null
3235
+     * @throws DbException
3236
+     */
3237
+    public function setUserIdentity($uid, $identityId = null)
3238
+    {
3239
+        $result = null;
3240
+        if (empty($identityId)) {
3241
+            $identityId = $this->getUserIdentity($uid);
3242
+        }
3243
+        $this->dao->update($uid, ['user_group' => $identityId]);
3244
+        return $identityId;
3245
+    }
3246
+
3247
+    /**
3248
+     * 获取用户 身份
3249
+     * @param $uid
3250
+     * @return int|mixed
3251
+     * @throws DataNotFoundException
3252
+     * @throws DbException
3253
+     * @throws ModelNotFoundException
3254
+     */
3255
+    public function getUserIdentity($uid)
3256
+    {
3257
+        // 1、获取所有等级信息
3258
+        /** @var UserIdentityRepository $identityRepository */
3259
+        $identityRepository = app()->make(UserIdentityRepository::class);
3260
+        $identityList = $identityRepository->getIdentityList();
3261
+
3262
+        // 2、获取身份需要的最深等级
3263
+        $lowerLevelNumList = array_column($identityList, 'lower_level_num');
3264
+        $lowerLevelNumMax = max($lowerLevelNumList);
3265
+        $lowerLevelNumMin = min($lowerLevelNumList);
3266
+        $needLower = $lowerLevelNumMax;
3267
+        if($lowerLevelNumMin == 0) {
3268
+            $needLower = $lowerLevelNumMin;
3269
+        }
3270
+
3271
+        // 3、获取下级用户 贡献值
3272
+        $userContributionSumMap = [];
3273
+        $uidContributeList = $this->getUidContributeListBySpreadUidList([$uid]);
3274
+        foreach ($uidContributeList as $uidContribute) {
3275
+            $userContributionSumMap[$uidContribute['uid']] = $this->getContributionSumByLevel([$uidContribute['uid']], $needLower);
3276
+            $userContributionSumMap[$uidContribute['uid']][0] = $uidContribute['contribute'];
3277
+        }
3278
+
3279
+        // 4、获取个人贡献值
3280
+        $userData = $this->dao->get($uid)->toArray();
3281
+
3282
+        // 5、当前用户等级
3283
+        $identityId = 0;
3284
+        usort($identityList, function ($a, $b) {
3285
+            return $b['user_group_id'] <=> $a['user_group_id'];  // 反转顺序,倒序排列
3286
+        });
3287
+        foreach ($identityList as $item) {
3288
+            $lowerLevelNum = $item['lower_level_num']??0;
3289
+
3290
+            $arriveNumOwn = $userData['contribute'];
3291
+            $arriveNumTeam = 0;
3292
+            $subordinateContribution = [];
3293
+
3294
+            foreach ($userContributionSumMap as $key => $value) {
3295
+                $subordinateContribution[$key] = 0;
3296
+                if ($lowerLevelNum != 0) {
3297
+                    foreach ($value as $k => $v) {
3298
+                        if ($k <= $lowerLevelNum) {
3299
+                            $subordinateContribution[$key] += $v;
3300
+                        } else {
3301
+                            break;
3302
+                        }
3303
+                    }
3304
+                } else {
3305
+                    $subordinateContribution[$key] = array_sum($value);
3306
+                }
3307
+            }
3308
+            if (!empty($subordinateContribution)) {
3309
+                // 大区业绩
3310
+                $dqYj = max($subordinateContribution);
3311
+                // 总业绩
3312
+                $zYj = array_sum($subordinateContribution);
3313
+                // 小区团体业绩
3314
+                $arriveNumTeam = bcsub($zYj, $dqYj, 2);
3315
+            }
3316
+            if ($item['arrive_num_own'] <= $arriveNumOwn && $item['arrive_num_team'] <= $arriveNumTeam) {
3317
+                $identityId = $item['user_group_id'];
3318
+                break;
3319
+            }
3320
+        }
3321
+        return $identityId;
3322
+    }
3323
+
3324
+    /**
3325
+     * 获取该会员的所有下级会员
3326
+     */
3327
+    public function getUidContributeListBySpreadUidList(array $uidList)
3328
+    {
3329
+        return Db::name("user")
3330
+            ->whereIn("spread_uid", $uidList)
3331
+            ->field("uid, contribute, spread_uid")
3332
+            ->select()
3333
+            ->toArray();
3334
+    }
3335
+
3336
+    /**
3337
+     * 计算指定用户下属每一层级的总贡献值。
3338
+     *
3339
+     * @param array $initialUserIds 初始用户ID列表 (视为第0层)。
3340
+     * @param int $maxDepth 需要查询的最大深度(相对于初始列表)。
3341
+     *                      0 表示查询所有层级直到末端。
3342
+     *                      1 表示只计算第1层(直接下级)的总贡献。
3343
+     *                      N 表示计算到第 N 层(包含第N层)的总贡献。
3344
+     * @return array 返回一个数组,键是层级号(从1开始),值是该层级所有用户的贡献值总和。
3345
+     *               例如:[ 1 => 600, 2 => 1300 ]
3346
+     */
3347
+    public function getContributionSumByLevel(array $initialUserIds, int $maxDepth = 0): array
3348
+    {
3349
+        $levelContributions = []; // 结果数组 [level => total_contribution]
3350
+        if (empty($initialUserIds)) {
3351
+            return $levelContributions;
3352
+        }
3353
+
3354
+        $currentLevelIds = $initialUserIds; // 当前层级的用户ID (初始为第0层)
3355
+        $currentLevel = 0; // 当前层级号
3356
+
3357
+        // 使用一个集合跟踪所有已处理过的下级用户ID,防止重复计算和循环
3358
+        $processedSubordinateIds = [];
3359
+
3360
+        while (!empty($currentLevelIds)) {
3361
+            // 计算下一层级的编号
3362
+            $nextLevel = $currentLevel + 1;
3363
+
3364
+            // 检查是否达到最大深度限制
3365
+            if ($maxDepth > 0 && $nextLevel > $maxDepth) {
3366
+                break; // 停止查询更深的层级
3367
+            }
3368
+
3369
+            // 批量查询当前层级用户的直接下级
3370
+            // 使用 array_chunk 防止 WHERE IN 子句过长 (根据数据库限制调整 chunkSize)
3371
+            $chunkSize = 500;
3372
+            $subordinatesOfCurrentLevel = [];
3373
+            foreach(array_chunk($currentLevelIds, $chunkSize) as $chunk) {
3374
+                $subordinatesChunk = Db::name('user')
3375
+                    ->field('uid, contribute') // 只需要下级的uid和贡献值
3376
+                    ->whereIn('spread_uid', $chunk) // spread_uid 在当前层级用户块中
3377
+                    ->select()
3378
+                    ->toArray();
3379
+                $subordinatesOfCurrentLevel = array_merge($subordinatesOfCurrentLevel, $subordinatesChunk);
3380
+            }
3381
+
3382
+            // 如果没有找到任何下级,结束循环
3383
+            if (empty($subordinatesOfCurrentLevel)) {
3384
+                break;
3385
+            }
3386
+
3387
+            $nextLevelTotalContribution = 0;
3388
+            $nextLevelIds = []; // 存储下一轮需要查询的用户ID
3389
+
3390
+            // 遍历找到的所有下级
3391
+            foreach ($subordinatesOfCurrentLevel as $subordinate) {
3392
+                $subordinateId = $subordinate['uid'];
3393
+                $subordinateContribution = $subordinate['contribute'] ?? 0; // 安全获取,默认为0
3394
+
3395
+                // 累加下一层级的总贡献值
3396
+                // 注意:这里简单累加,如果一个下级同时被当前层多个用户推荐,其贡献会被计算多次
3397
+                // 如果要求每个下级只贡献一次(即使有多个上级),需要调整逻辑,
3398
+                // 例如在累加前检查 $processedSubordinateIds
3399
+
3400
+                // --- 修改点:确保每个下级贡献只被计算一次 ---
3401
+                // if (!isset($processedSubordinateIds[$subordinateId])) { // 如果这个下级还没被处理过
3402
+                $nextLevelTotalContribution += (float)$subordinateContribution;
3403
+                // }
3404
+                // 注释掉上面的检查,因为用户描述似乎是按层级直接累加,不管这个下级是否被上层处理过。
3405
+                // 如果A1和A2都属于第1层,他们各自的下级B1和B2都属于第2层,B1和B2的贡献值直接加到第2层的总和里。
3406
+                // 如果需要严格按“人”计算,即使一个人出现在多层或被多人推荐也只算一次,则需要解开注释并调整
3407
+
3408
+                // 收集下一轮需要查询的用户ID,同样需要防止重复处理
3409
+                if (!isset($processedSubordinateIds[$subordinateId])) {
3410
+                    $nextLevelIds[] = $subordinateId;
3411
+                    // 标记这个下级ID已处理过,避免在更深层级中再次将其加入查询队列
3412
+                    $processedSubordinateIds[$subordinateId] = true;
3413
+                }
3414
+
3415
+            }
3416
+
3417
+            // 存储下一层级的总贡献值 (只有当贡献值大于0或你想记录空层级时)
3418
+            // 根据例子,我们只记录有贡献的层级,或者至少有用户的层级
3419
+            if (!empty($subordinatesOfCurrentLevel)) { // 只要找到了下级就记录该层
3420
+                $levelContributions[$nextLevel] = $nextLevelTotalContribution;
3421
+            }
3422
+
3423
+            // 准备下一轮迭代
3424
+            $currentLevelIds = array_unique($nextLevelIds); // 去重下一层的用户ID
3425
+            $currentLevel = $nextLevel; // 更新当前层级
3426
+        }
3427
+
3428
+        return $levelContributions;
3429
+    }
3228 3430
 }

+ 12 - 0
app/common/repositories/user/UserThirdRepository.php

@@ -865,6 +865,18 @@ class UserThirdRepository extends BaseRepository
865 865
             Db::name("user_sign_gongxian")->insert($gongxian_data);//添加贡献记录
866 866
             log::info("===添加完积分和贡献值");
867 867
 
868
+            // 添加pv记录
869
+            $pv_data = [
870
+                "uid"           =>$user_id,
871
+                "pv"            =>$gongxian,
872
+                "addtime"       =>time(),
873
+                "status"        =>-1,
874
+                "order_type"    =>$type_shop,
875
+                "order_id"      =>$order_sn,
876
+                "mark"          =>"购买{$make}商品获得的PV",
877
+            ];
878
+            Db::name("user_pv_log")->insert($pv_data);//添加pv记录
879
+
868 880
             //判断是否是老用户  is_old=1是1.0的用户,1.0的用户要总pv*45%的红包
869 881
             if($user["is_old"]==1){
870 882
                 //添加红包

+ 94 - 0
app/controller/admin/system/config/Identity.php

@@ -0,0 +1,94 @@
1
+<?php
2
+/**
3
+ * @package merchant
4
+ *
5
+ * @author xaboy
6
+ * @day 2020-03-24
7
+ *
8
+ * 
9
+ */
10
+
11
+namespace app\controller\admin\system\config;
12
+
13
+
14
+use crmeb\basic\BaseController;
15
+use app\common\repositories\user\UserIdentityRepository;
16
+use FormBuilder\Exception\FormBuilderException;
17
+use think\App;
18
+use think\db\exception\DataNotFoundException;
19
+use think\db\exception\DbException;
20
+use think\db\exception\ModelNotFoundException;
21
+
22
+/**
23
+ * Class Config
24
+ * @package app\controller\admin\system\config
25
+ * @author xaboy
26
+ * @day 2020-03-27
27
+ */
28
+class Identity extends BaseController
29
+{
30
+    /**
31
+     * @var UserIdentityRepository
32
+     */
33
+    protected $repository;
34
+
35
+    /**
36
+     * Config constructor.
37
+     * @param App $app
38
+     * @param UserIdentityRepository $repository
39
+     */
40
+    public function __construct(App $app, UserIdentityRepository $repository)
41
+    {
42
+        parent::__construct($app);
43
+        $this->repository = $repository;
44
+    }
45
+
46
+    /**
47
+     * @return mixed
48
+     * @throws DataNotFoundException
49
+     * @throws DbException
50
+     * @throws ModelNotFoundException
51
+     * @author xaboy
52
+     * @day 2020-03-31
53
+     */
54
+    public function lst()
55
+    {
56
+        $where = $this->request->params(['keyword']);
57
+        [$page, $limit] = $this->getPage();
58
+        $lst = $this->repository->getList($where, $page, $limit);
59
+
60
+        return app('json')->success($lst);
61
+    }
62
+
63
+    /**
64
+     * @param int $id
65
+     * @return mixed
66
+     * @throws DataNotFoundException
67
+     * @throws DbException
68
+     * @throws ModelNotFoundException
69
+     * @throws FormBuilderException
70
+     * @author xaboy
71
+     * @day 2020-03-31
72
+     */
73
+    public function updateTable($id)
74
+    {
75
+        if (!$this->repository->exists($id)) app('json')->fail('数据不存在');
76
+        $form = $this->repository->updateForm($id);
77
+        return app('json')->success(formToData($form));
78
+    }
79
+
80
+    /**
81
+     * @param int $id
82
+     * @return mixed
83
+     * @throws DbException
84
+     * @author xaboy
85
+     * @day 2020-03-27
86
+     */
87
+    public function update($id)
88
+    {
89
+        $data = $this->request->params(['arrive_num_own', 'arrive_num_team']);
90
+        $this->repository->update($id, $data);
91
+        return app('json')->success('修改成功');
92
+    }
93
+
94
+}

+ 6 - 5
app/controller/api/Auth.php

@@ -1899,11 +1899,12 @@ class Auth extends BaseController
1899 1899
             if(empty($sessionKey['sessionKey'])||empty($encryptedData['encryptedData'])||empty($iv['iv'])){
1900 1900
                 return app('json')->fail('参数不正确');
1901 1901
             }
1902
-            $appid = 'wx82986c4471ce7efc';
1903
-            if($this->source=='yhc'){
1904
-                $appid = 'wx82986c4471ce7efc';
1905
-            }
1906
-            $appid = 'wx7b4d857deb0447f3';
1902
+//            $appid = 'wx82986c4471ce7efc';
1903
+//            if($this->source=='yhc'){
1904
+//                $appid = 'wx82986c4471ce7efc';
1905
+//            }
1906
+//            $appid = 'wx7b4d857deb0447f3';
1907
+            $appid = 'wx9082e5ac2fdb513f';
1907 1908
             $sessionKey =str_replace(' ','+', $sessionKey['sessionKey']);
1908 1909
 
1909 1910
             $encryptedData=str_replace(' ','+',$encryptedData['encryptedData']);

+ 41 - 17
app/controller/api/Notify.php

@@ -4,6 +4,7 @@ namespace app\controller\api;
4 4
 use AdaPaySdk\AdapayTools;
5 5
 use app\common\repositories\movie\MovieRepository;
6 6
 use app\common\repositories\store\order\StoreRefundOrderRepository;
7
+use app\common\repositories\user\UserRepository;
7 8
 use app\controller\api\merchant\sxy\Access;
8 9
 use app\controller\api\store\service\Huafei;
9 10
 use think\facade\Db;
@@ -169,7 +170,7 @@ class Notify
169 170
                                     //if($job_par['note'] == "现金"){
170 171
                                     //普通消费者
171 172
                                     $ylj_pri = bcmul($concession_pri, 0.3,2);
172
-                                    $pv = bcmul($concession_pri, 0.35,2);  
173
+                                    $pv = bcmul($concession_pri, 0.35,2);
173 174
 
174 175
                                     //分配养老金给消费者
175 176
                                     $ylj_amount_mine = $user_data['annuity'] + $ylj_pri;
@@ -180,6 +181,7 @@ class Notify
180 181
                                     //Db::name('user')->where('uid',$user_data['uid'])->update(['annuity'=>$ylj_amount_mine,"contribute"=>$con,"score"=>$score]);
181 182
 
182 183
                                     $this->bill_user_log($user_data['uid'],$ylj_pri,$store_order_data['order_id'],5,$store_order_data['order_sn'],'消费获得养老金'.$ylj_pri,$store_order_data['mer_id'],0);
184
+                                    $this->con_log_pv($user_data['uid'],$pv,$store_order_data['order_id'],11,"购买精彩生活商品赠送贡献值");
183 185
                                     $this->con_log($user_data['uid'],$pv,$store_order_data['order_id'],11,"购买精彩生活商品赠送贡献值");
184 186
                                     $this->score_log($user_data['uid'],$pv,$store_order_data['order_id'],11,"购买精彩生活商品赠送积分");
185 187
 
@@ -301,8 +303,10 @@ class Notify
301 303
                                         if($spread_data['user_group'] == 1){
302 304
                                             //给推广者分配佣金
303 305
                                             // $ylj_amount = $spread_data['annuity'] + round($pv * 0.3,2);
304
-                                            $yj_amount_90 = bcmul($pv, 0.21,2) * 0.9;
305
-                                            $fgj_amount_10 = bcmul($pv, 0.21,2) * 0.1;//推广者的佣金抽10%到个人复购金
306
+                                            // $yj_amount_90 = round($pv * 0.21,2) * 0.9;
307
+                                            $yj_amount_90 = bcmul($pv, 0.3,2) * 0.9;
308
+                                            // $fgj_amount_10 = round($pv * 0.21,2) * 0.1;//推广者的佣金抽10%到个人复购金
309
+                                            $fgj_amount_10 = bcmul($pv, 0.3,2) * 0.1;//推广者的佣金抽10%到个人复购金
306 310
 
307 311
                                             $yj_amount = $spread_data['brokerage_price'] + $yj_amount_90;
308 312
                                             $fgj_amount = $spread_data['fugou'] + $fgj_amount_10;
@@ -310,8 +314,8 @@ class Notify
310 314
 
311 315
                                             //Db::name('user')->where('uid',$spread_data['uid'])->update(['brokerage_price'=>$yj_amount,'fugou'=>$fgj_amount]);
312 316
 
313
-                                            $con = $spread_data['contribute'] + bcmul($pv, 0.21,2);
314
-                                            $score = $spread_data['score'] + bcmul($pv, 0.21,2);
317
+                                            $con = $spread_data['contribute'] + bcmul($pv, 0.3,2);
318
+                                            $score = $spread_data['score'] + bcmul($pv, 0.3,2);
315 319
 
316 320
                                             //贡献值和积分
317 321
                                             //Db::name('user')->where('uid',$spread_data['uid'])->update(["contribute"=>$con,"score"=>$score]);
@@ -320,8 +324,8 @@ class Notify
320 324
 
321 325
                                             //推广佣金
322 326
                                             $this->bill_user_log($spread_data['uid'],$yj_amount_90,$store_order_data['order_id'],3,$store_order_data['order_sn'],'推广获得佣金'.$yj_amount_90,$store_order_data['mer_id'],0);
323
-                                            $this->con_log($spread_data['uid'],round($pv * 0.21,2),$store_order_data['order_id'],11,"推广精彩生活区商品赠送贡献值");
324
-                                            $this->score_log($spread_data['uid'],round($pv * 0.21,2),$store_order_data['order_id'],11,"推广精彩生活区商品赠送积分");
327
+                                            $this->con_log($spread_data['uid'],round($pv * 0.3,2),$store_order_data['order_id'],11,"推广精彩生活区商品赠送贡献值");
328
+                                            $this->score_log($spread_data['uid'],round($pv * 0.3,2),$store_order_data['order_id'],11,"推广精彩生活区商品赠送积分");
325 329
 
326 330
 
327 331
 
@@ -413,6 +417,8 @@ class Notify
413 417
  
414 418
                                 $this->bill_user_log($user_data['uid'],round($pv * 0.035,2),$store_order_data['order_id'],5,$store_order_data['order_sn'],'消费获得养老金'.round($pv * 0.035,2),$store_order_data['mer_id']);
415 419
  
420
+                                $this->con_log_pv($user_data['uid'],$gx_jf,$store_order_data['order_id'],11,"购买会员专区商品赠送贡献值",1);
421
+                                // $this->con_log($user_data['uid'],$gx_jf,$store_order_data['order_id'],11,"购买会员专区商品赠送贡献值",1);
416 422
                                 $this->con_log($user_data['uid'],$gx_jf,$store_order_data['order_id'],11,"购买会员专区商品赠送贡献值",1, $gx_jf);
417 423
                                 $this->score_log($user_data['uid'],$gx_jf,$store_order_data['order_id'],11,"购买会员专区商品赠送积分",1);
418 424
 
@@ -550,7 +556,7 @@ class Notify
550 556
                                         // $this->bill_user_log($user_data['spread_uid'],round($pv * 0.01,2),$store_order_data['order_id'],3,$group_order['group_order_sn'],'推广获得佣金'.round($pv * 0.01,2),$store_order_data['mer_id']);
551 557
 
552 558
                                         //获取贡献值和积分和佣金
553
-                                        $gx_jf = $spread_data['contribute'] + bcmul($pv, 0.21,2);
559
+                                        $gx_jf = $spread_data['contribute'] + bcmul($pv, 0.3,2);
554 560
 
555 561
                                         //$yj111 = $spread_data['brokerage_price'] + $yj1;
556 562
 
@@ -563,8 +569,8 @@ class Notify
563 569
 
564 570
 
565 571
                                         //Db::name('user')->where('uid',$spread_data['uid'])->update(['contribute'=> $gx_jf,'score'=> $gx_jf,'brokerage_price'=> $yj_amount,'fugou'=>$fgj_amount]);
566
-                                        $this->con_log($spread_data['uid'],round($pv * 0.21,2),$store_order_data['order_id'],11,"推广会员专区商品赠送贡献值",1, round($pv * 0.21,2));
567
-                                        $this->score_log($spread_data['uid'],round($pv * 0.21,2),$store_order_data['order_id'],11,"推广会员专区商品赠送积分",1);
572
+                                        $this->con_log($spread_data['uid'],round($pv * 0.3,2),$store_order_data['order_id'],11,"推广会员专区商品赠送贡献值",1, round($pv * 0.21,2));
573
+                                        $this->score_log($spread_data['uid'],round($pv * 0.3,2),$store_order_data['order_id'],11,"推广会员专区商品赠送积分",1);
568 574
                                         //推广佣金
569 575
                                         $this->bill_user_log($spread_data['uid'],$yj_amount_90,$store_order_data['order_id'],3,$store_order_data['order_sn'],'推广获得佣金'.$yj_amount_90,$store_order_data['mer_id']);
570 576
                                     }
@@ -1398,8 +1404,20 @@ class Notify
1398 1404
         return $newList;
1399 1405
     }
1400 1406
 
1401
-
1402
-
1407
+    public function con_log_pv($uid, $num, $order_id, $order_type, $mark, $status = -1)
1408
+    {
1409
+        // 添加pv记录
1410
+        $pv_data = [
1411
+            "uid" => $uid,
1412
+            "pv" => $num,
1413
+            "addtime" => time(),
1414
+            "status" => $status,
1415
+            "order_type" => $order_type,
1416
+            "order_id" => $order_id,
1417
+            "mark" => str_replace('贡献值', 'PV', $mark),
1418
+        ];
1419
+        Db::name("user_pv_log")->insert($pv_data);//添加pv记录
1420
+    }
1403 1421
 
1404 1422
     //添加贡献值日志
1405 1423
     public function con_log($uid,$num,$order_id,$order_type,$mark,$status = -1, $pv = 0){
@@ -1416,6 +1434,9 @@ class Notify
1416 1434
 
1417 1435
                 if (strpos($mark, "购买") !== false) {
1418 1436
                     Db::name('user')->where("uid",$uid)->update(['contribute'=>$con_data['contribute'] + $num]);
1437
+                    /** @var UserRepository $userRepository */
1438
+                    $userRepository = app()->make(UserRepository::class);
1439
+                    $userRepository->setUserIdentity($uid);
1419 1440
                 }
1420 1441
 
1421 1442
                 if (strpos($mark, "推广") !== false) {
@@ -1425,7 +1446,7 @@ class Notify
1425 1446
                 if($pv > 0){
1426 1447
                     Db::name('user')->where("uid", $uid)->update(['pv' => $con_data['pv'] + $pv]);
1427 1448
                 }
1428
-             
1449
+
1429 1450
                 //if(count($spread_data) > 0){
1430 1451
                     // $all_ids = [];
1431 1452
                     // foreach($spread_data as $k=>$v){
@@ -1473,10 +1494,13 @@ class Notify
1473 1494
             //     //     echo "字符串1包含'推广'\n";
1474 1495
             //     // }
1475 1496
 
1476
-            //     // 检查是否包含“购买”
1477
-            //     if (strpos($mark, "购买") !== false) {
1478
-            //         Db::name('user')->where("uid",$uid)->update(['contribute'=>$con_data['contribute'] + $num]);
1479
-            //     }
1497
+                // 检查是否包含“购买”
1498
+                if (strpos($mark, "购买") !== false) {
1499
+                    Db::name('user')->where("uid",$uid)->update(['contribute'=>$con_data['contribute'] + $num]);
1500
+                    /** @var UserRepository $userRepository */
1501
+                    $userRepository = app()->make(UserRepository::class);
1502
+                    $userRepository->setUserIdentity($uid);
1503
+                }
1480 1504
 
1481 1505
                  
1482 1506
                

+ 707 - 0
app/controller/api/store/merchant/TaskPartnerProfits.php

@@ -0,0 +1,707 @@
1
+<?php
2
+
3
+
4
+namespace app\controller\api\store\merchant;
5
+
6
+
7
+use think\facade\Db;
8
+
9
+class TaskPartnerProfits
10
+{
11
+    public function getTime($timePeriod)
12
+    {
13
+        // 定义时间区间
14
+        $now = time();
15
+        $startTime = '';
16
+        $endTime = '';
17
+        if ($timePeriod == 'last_week') {
18
+            // 上周的时间区间
19
+            $startTime = date('Y-m-d', strtotime('monday last week', $now)); // 上周星期一的开始时间
20
+            $endTime = date('Y-m-d', strtotime('sunday last week', $now)); // 上周星期日的结束时间
21
+        } elseif ($timePeriod == 'this_week') {
22
+            // 这周的时间区间
23
+            $startTime = date('Y-m-d', strtotime('monday this week', $now)); // 这周星期一的开始时间
24
+            $endTime = date('Y-m-d', strtotime('sunday this week', $now)); // 这周星期日的结束时间
25
+        }
26
+//        return ['startTime' => '2025-03-10', 'endTime' => '2025-03-23'];
27
+        return ['startTime' => $startTime, 'endTime' => $endTime];
28
+    }
29
+
30
+    public function getTeamPvByTime($timePeriod = 'last_week', $removeUserIdList = [])
31
+    {
32
+        $timeMap = $this->getTime($timePeriod);
33
+        $startTime = $timeMap['startTime'];
34
+        $endTime = $timeMap['endTime'];
35
+
36
+        // 查询指定时间区间内的所有订单,并排除 pay_time 为 NULL 的订单
37
+        $orders = Db::name("store_order")
38
+            ->where('mer_id', 496)
39
+            ->whereNotIn('uid', $removeUserIdList)
40
+            ->whereIn('status', [0, 1, 2, 3])
41
+            ->whereIn("total_price", [1180, 11800, 10620, 2360, 9440])
42
+            ->whereBetween("pay_time", [$startTime . ' 00:00:00', $endTime . ' 23:59:59'])
43
+            ->whereNotNull("pay_time") // 排除 pay_time 为 NULL 的订单
44
+            ->select();
45
+
46
+        // 计算总业绩
47
+        $totalPv = 0;
48
+        foreach ($orders as $order) {
49
+            switch ($order['total_price']) {
50
+                case 1180:
51
+                    $totalPv += 700;
52
+                    break;
53
+                case 11800:
54
+                    $totalPv += 7000;
55
+                    break;
56
+                case 10620:
57
+                    $totalPv += 6300;
58
+                    break;
59
+                case 2360:
60
+                    $totalPv += 1400;
61
+                    break;
62
+                case 9440:
63
+                    $totalPv += 5600;
64
+                    break;
65
+            }
66
+        }
67
+
68
+        return $totalPv;
69
+    }
70
+
71
+    public function getRedEnvelopeByTime($timePeriod = 'last_week', $removeUserIdList = [])
72
+    {
73
+        $timeMap = $this->getTime($timePeriod);
74
+        $startTime = $timeMap['startTime'];
75
+        $endTime = $timeMap['endTime'];
76
+
77
+        // 查询指定时间区间内的所有订单,并排除 pay_time 为 NULL 的订单
78
+        $redEnvelopeList = Db::name("user_sign_hongbao")
79
+            ->whereNotIn('uid', $removeUserIdList)
80
+            ->where('status', 1)
81
+            ->whereBetween("settlement_time", [$startTime . ' 00:00:00', $endTime . ' 23:59:59'])
82
+            ->select()
83
+            ->toArray();
84
+        return floor(array_sum(array_column($redEnvelopeList, 'number')) * 100) / 100;
85
+    }
86
+
87
+    public function partnerProfits()
88
+    {
89
+        // 查询测试人员账号信息
90
+        //18973958920
91
+        //15186694339
92
+        //18833633835
93
+        //19525470098
94
+        //17756507016
95
+        //18226705337
96
+        $testAccount = ['18973958920', '15186694339', '18833633835', '19525470098', '17756507016', '18226705337'];
97
+        $removeUserList = Db::name("user")
98
+            ->whereIn('account', $testAccount)
99
+            ->where("status", "<>", 0)
100
+            ->where('is_del', '<>', 1)
101
+            ->select()
102
+            ->toArray();
103
+        $removeUserIdList = array_column($removeUserList, 'uid');
104
+        // 定义分红金额
105
+        $weekRecord = $this->getTeamPvByTime('last_week', $removeUserIdList);
106
+        // 分红金额 - 红包金额
107
+        $redEnvelope = $this->getRedEnvelopeByTime('last_week', $removeUserIdList);
108
+
109
+        $weekRecord -= $redEnvelope;
110
+        if ($weekRecord <= 0) {
111
+            return json('无效分红金额');
112
+        }
113
+
114
+
115
+        // 1、获取用户星级信息
116
+        //$star_list = Db::name("user_star")->order("statement_all_num desc")->select()->toArray();//旧星级等级
117
+        $starList = Db::name("old_user_starlevel")
118
+            ->whereIn('title', ['初级', '中级', '高级'])
119
+            ->order("statement_all_num desc")
120
+            ->select()
121
+            ->toArray();//星级等级
122
+
123
+        // 2、循环星级信息 并分组归类
124
+        $salesArr = array_column($starList, null, 'title');
125
+
126
+        // 3、获取 分红用户 信息 (`user_group` tinyint(1) DEFAULT '1' COMMENT '1消费者 2,推广业务员 3,业务经理 4初级合伙人5中级合伙人 6高级合伙人 7.懂事',)
127
+        $list = Db::name("user")
128
+//            ->whereNotIn('uid', $removeUserIdList)
129
+            ->where("user_group", "IN", [4, 5, 6])
130
+            ->where("status", "<>", 0)
131
+            ->where('is_del', '<>', 1)
132
+            ->select()
133
+            ->toArray();
134
+
135
+        // 4、将用户装载到 星级等级 分红数据中
136
+        foreach ($list as $key => $value) {
137
+            if ($value['user_group'] == 4) {
138
+                $salesArr['初级']['divider_people'][] = $value['uid'];
139
+            } else if ($value['user_group'] == 5) {
140
+                $salesArr['中级']['divider_people'][] = $value['uid'];
141
+            } else if ($value['user_group'] == 6) {
142
+                $salesArr['高级']['divider_people'][] = $value['uid'];
143
+            }
144
+        }
145
+
146
+        // 5、移除特定人员
147
+        // 要移动的ID数组
148
+//        $ids_to_remove_from_junior = array(12, 69, 144); // 从初级中移除的ID
149
+//        $ids_to_remove_from_intermediate = array(49); // 从中级中移除的ID
150
+//        // 查找初级并获取其divider_people
151
+//        $junior = &$salesArr['初级']['divider_people']; // 使用引用,以便直接修改数组
152
+//        // 查找中级并获取其divider_people
153
+//        $intermediate = &$salesArr['中级']['divider_people']; // 使用引用,以便直接修改数组
154
+//        // 从初级的divider_people中移除特定的ID
155
+//        foreach ($ids_to_remove_from_junior as $id) {
156
+//            $key = array_search($id, $junior);
157
+//            if ($key !== false) {
158
+//                unset($junior[$key]); // 移除初级中的特定ID
159
+//            }
160
+//        }
161
+//        // 从中级的divider_people中移除特定的ID
162
+//        foreach ($ids_to_remove_from_intermediate as $id) {
163
+//            $key = array_search($id, $intermediate);
164
+//            if ($key !== false) {
165
+//                unset($intermediate[$key]); // 移除中级中的特定ID
166
+//            }
167
+//        }
168
+//        // 重置数组的索引,因为unset会留下空位
169
+//        $salesArr['初级']['divider_people'] = array_values($junior);
170
+//        $salesArr['中级']['divider_people'] = array_values($intermediate);
171
+
172
+
173
+        // 6、执行分开发放
174
+        $partnerProfitsPvListByUid = [];
175
+        foreach ($salesArr as $key => $value) {
176
+            // 6.1 计算可分红金额
177
+            //比如这个周的总业绩是 8400
178
+            //周总业绩(8400) * 合伙人级别的分佣比例(15%) = 可分红的佣金(1260)
179
+//            $salesArr[$key]['fs_money_nums'] = round($weekRecord * $value['profit_rate'], 2);
180
+            $salesArr[$key]['fs_money_nums'] = floor(($weekRecord * ($value['profit_rate'] / 100)) * 100) / 100;
181
+            //可分红的业绩(分为两半,各50%,一部分是分给双联盟比例,一部分是小业绩比例)
182
+            //把本周的业绩(8400) * 合伙人级别的分佣比例(15%) * 0.5 = 630(可分红佣金的 50%)
183
+//            $salesArr[$key]['fs_money'] = round($salesArr[$key]['fs_money_nums'] / 2, 2);
184
+            $salesArr[$key]['fs_money'] = floor(($salesArr[$key]['fs_money_nums'] / 2) * 100) / 100;
185
+
186
+            // 6.2 计算所有人的 PV值
187
+            $salesArr[$key]['maxValueAll'] = 0;
188
+            $salesArr[$key]['sumOfOthersAll'] = 0;
189
+            $salesArr[$key]['dividerPeoplePv'] = [];
190
+            foreach ($value['divider_people'] as $k => $v) {
191
+                // 6.2.1 查出分红人的所有部门 即 下级用户
192
+                $spreadUserUidList = $this->getSpreadUserUidListByUidList([$v]);
193
+                if (empty($spreadUserUidList[$v])) {
194
+                    continue;
195
+                }
196
+
197
+                // 6.2.2 获取当前分红人的所有部门 内的下级成员,递归获取至最低一级
198
+                $subordinatesBatch = $this->getSubordinatesBatch($spreadUserUidList[$v]);
199
+                // 6.2.3 获取所有部门(下线)的PV值
200
+                foreach ($subordinatesBatch as $k1 => $v1) {
201
+                    // 获取当前下线的PV值, 忽略测试人员的账号
202
+                    $pv = $this->getPv(array_merge($v1, [$k1]), $removeUserIdList);
203
+                    if (!empty($pv)) {
204
+                        $partnerProfitsPvListByUid[$v][$k1] = $pv;
205
+                    }
206
+                }
207
+
208
+                // 6.2.4 将PV值进行记录 以便后续计算
209
+                if (!empty($partnerProfitsPvListByUid[$v])) {
210
+                    // 获取数组中的最大值
211
+                    $maxValue = max($partnerProfitsPvListByUid[$v]);
212
+                    // 计算总和
213
+                    $totalSum = array_sum($partnerProfitsPvListByUid[$v]);
214
+                    // 计算除最大值外其余值的和
215
+                    $sumOfOthers = $totalSum - $maxValue;
216
+
217
+                    $salesArr[$key]['dividerPeoplePv'][$v]['maxValue'] = $maxValue;
218
+                    $salesArr[$key]['dividerPeoplePv'][$v]['sumOfOthers'] = $sumOfOthers;
219
+                    $salesArr[$key]['maxValueAll'] += $maxValue;
220
+                    $salesArr[$key]['sumOfOthersAll'] += $sumOfOthers;
221
+                }
222
+            }
223
+        }
224
+
225
+        // 7、执行分红
226
+        $testRecord = [];
227
+        foreach ($salesArr as $key => $value) {
228
+            $amount = $value['fs_money'];//可分红的总佣金,分红佣金的一半,中级合伙61.95
229
+            $fsMoneyNums = $value['fs_money_nums'];//中级合伙人级别,可分红的总佣金
230
+            $maxValueAll = $value['maxValueAll'];//当前级别合伙人下面所有的双联盟业绩
231
+            $sumOfOthersAll = $value['sumOfOthersAll'];//当前级别合伙人下面所有的小区(业绩小的部分)总业绩
232
+
233
+            if (count($value['divider_people']) <= 0) {
234
+                continue;
235
+            }
236
+            //每人分红金额
237
+            foreach ($value['divider_people'] as $v) {
238
+
239
+                //个人小区(佣金少的一部分) 权重 计算权重
240
+                //返回是数组,下标0是最小的值(业绩小的),下标1是最大的值(业绩大的)
241
+                $userPvSmallNum = $value['dividerPeoplePv'][$v]['sumOfOthers'] ?? 0;
242
+//                $myMixMoney = round($amount * ($userPvSmallNum / $sumOfOthersAll), 2);
243
+                $myMixMoney = floor(($amount * (floor(($userPvSmallNum / $sumOfOthersAll) * 100) / 100)) * 100) / 100;
244
+
245
+                //个人双区总佣金 权重 计算
246
+                $myBill = $value['dividerPeoplePv'][$v]['maxValue'] ?? 0;
247
+                //中级合伙人。userid=17可以分到双区可分红的金额
248
+                //可分红的佣金 * (中级合伙人个人的双区总业绩 / 当前等级所有合伙人的双联盟业绩) = 当前用户可以获取到的分红佣金(双区联盟总业绩加权佣金),287742 * (61.95/431032)=41.36
249
+//                $myWeightMoney = round($amount * ($myBill / $maxValueAll), 2);
250
+                $myWeightMoney = floor(($amount * (floor((($myBill + $userPvSmallNum) / ($maxValueAll + $sumOfOthersAll)) * 100) / 100)) * 100) / 100;
251
+
252
+
253
+                $salesArr[$key]['dividerPeoplePv'][$v]['myWeightMoney'] = $myWeightMoney;
254
+                $salesArr[$key]['dividerPeoplePv'][$v]['myMixMoney'] = $myMixMoney;
255
+                $salesArr[$key]['dividerPeoplePv'][$v]['maxValueAll'] = $maxValueAll;
256
+                $salesArr[$key]['dividerPeoplePv'][$v]['sumOfOthersAll'] = $sumOfOthersAll;
257
+                $salesArr[$key]['dividerPeoplePv'][$v]['weekRecord'] = $weekRecord;
258
+
259
+                # code...
260
+                $allAward = $myWeightMoney + $myMixMoney;
261
+
262
+                //90%给佣金,10给复购金
263
+                $yj_90 = $allAward * 0.9;
264
+                $fg_10 = $allAward * 0.1;
265
+
266
+
267
+                $userdatassss = db::name("old_user_jbp")->where("id", $v)->find();
268
+                $datas_log = [
269
+                    'note' => "名称:" . $userdatassss['nick_name'] . " 用户:" . $v . " 双联盟总业绩:" . $maxValueAll . " 我的双区业绩:" . $myBill . " 小区总业绩:" . $sumOfOthersAll . " 我的业绩小的:" . $userPvSmallNum[0] . "  可分红佣金:" . $amount . "  可分红总佣金:" . $fsMoneyNums . "  小区业绩可分红:" . $myMixMoney . " 大区业绩可分红:" . $myWeightMoney . " 实际分得:" . $yj_90,
270
+                    'create_time' => date('Y-m-d H:i:s')
271
+                ];
272
+                $con_data = Db::name('test_log')->insert($datas_log);   //数据存到2.0数据表中
273
+
274
+                # code...
275
+                $res = Db::name("user")->where("uid", $v)->inc("total_amount_old", $yj_90)->save();
276
+
277
+                Db::name("user")->where("uid", $v)->inc("amount_old", $yj_90)->save();//不用冻结金额和提现额度来限制佣金发放
278
+                Db::name("user")->where("uid", $v)->inc("brokerage_price", $yj_90)->save();
279
+
280
+                Db::name("user")->where("uid", $v)->inc("fugou", $fg_10)->save();
281
+
282
+
283
+                //if($res) {
284
+                $this->change_user_log($v, 'amount_old', 1, $yj_90, "member_award", "星级分红入账" . "-" . $value['title']);//释放佣金
285
+                //入账星级分红记录表
286
+                $week_data = [];
287
+                $week_data['user_id'] = $v;
288
+                $week_data['user_star_id'] = $key;
289
+                $week_data['award_num'] = $myWeightMoney;
290
+                $week_data['award_num_sm'] = $myMixMoney;
291
+                $week_data['remark'] = "星级分红主动执行:" . $yj_90;
292
+                $week_data['week_record'] = $weekRecord;
293
+                $week_data['all_amount'] = $fsMoneyNums;
294
+                $week_data['radio'] = 2;
295
+                $week_data['owner_bill'] = $maxValueAll;  //总流水金额
296
+                $week_data['my_bill'] = $myBill;  //我的流水
297
+                $week_data['create_time'] = time();
298
+
299
+                Db::name("old_user_weekaward")->insert($week_data);
300
+
301
+                $this->bill_user_log111111($v, "合伙人分佣", $yj_90, "合伙人分佣明细入账", 11);//联创分佣明细2.0系统
302
+                $this->fugou_user_log($v, $fg_10, 16, 1, 1);//复购金明细入账
303
+            }
304
+
305
+        }
306
+        return json($salesArr);
307
+    }
308
+
309
+    /**
310
+     * 获取该会员的所有下级会员
311
+     */
312
+    public function getSpreadUserUidListByUidList(array $uidList)
313
+    {
314
+        $son_ids = Db::name("user")
315
+            ->whereIn("spread_uid", $uidList)
316
+            ->field("uid,spread_uid")
317
+            ->select()
318
+            ->toArray();
319
+        $new_array_ids = [];
320
+        foreach ($son_ids as $key => $value) {
321
+            $new_array_ids[$value['spread_uid']][] = $value['uid'];
322
+        }
323
+        return $new_array_ids;
324
+    }
325
+
326
+    /**
327
+     * 递归查询下级用户并分组
328
+     *
329
+     * @param array $uids 初始用户ID数组
330
+     * @return array 分组后的下级用户ID数组
331
+     */
332
+    public function getSubordinates(array $uids): array
333
+    {
334
+        $result = [];
335
+
336
+        foreach ($uids as $uid) {
337
+            $result[$uid] = $this->getSubordinatesRecursively($uid);
338
+        }
339
+
340
+        return $result;
341
+    }
342
+
343
+    /**
344
+     * 获取该会员的所有下级会员
345
+     */
346
+    public function getSpreadUserUidAccountListByUidList($uid, $account = '')
347
+    {
348
+        $son_ids = Db::name("user")
349
+            ->where("spread_uid", $uid)
350
+            ->field("uid,spread_uid,account")
351
+            ->select()
352
+            ->toArray();
353
+        $new_array_ids = [];
354
+        foreach ($son_ids as $key => $value) {
355
+            $childList = $this->getSpreadUserUidAccountListByUidList($value['uid'], $value['account']);
356
+            $new_array_ids[] = [
357
+                '当前用户ID' => $value['uid'],
358
+                '当前用户的上级用户ID' => $value['spread_uid'],
359
+                '用户账号(手机号)' => $value['account'],
360
+                '当前用户的下级用户列表' => $childList
361
+            ];
362
+        }
363
+        return $new_array_ids;
364
+    }
365
+
366
+    /**
367
+     * 递归查询单个用户的下级用户
368
+     *
369
+     * @param int $uid 用户ID
370
+     * @param array $subordinates 用于存储下级用户ID的数组(内部使用, 递归传递)
371
+     * @return array 下级用户ID数组
372
+     */
373
+    private function getSubordinatesRecursively(int $uid, array &$subordinates = []): array
374
+    {
375
+        $subUidList = Db::name("user")
376
+            ->where("spread_uid", $uid)  // 直接使用 $uid, 不需要 whereIn
377
+            ->field("uid") //只需要查询uid
378
+            ->select()
379
+            ->toArray();
380
+
381
+        if (!empty($subUidList)) {
382
+            foreach ($subUidList as $subUser) {
383
+                $subUid = $subUser['uid'];
384
+                $subordinates[] = $subUid; // 添加到下级用户数组
385
+                $this->getSubordinatesRecursively($subUid, $subordinates); // 递归查询下级的下级
386
+            }
387
+        }
388
+        return $subordinates;
389
+    }
390
+
391
+    /**
392
+     * 递归获取所有下级ID(不分组)
393
+     * @param int $uid
394
+     * @param array $allSubordinates
395
+     * @return array
396
+     */
397
+    public function getAllSubordinates(int $uid, array &$allSubordinates = []): array
398
+    {
399
+        $subUidList = Db::name("user")
400
+            ->where("spread_uid", $uid)
401
+            ->column("uid");  // 使用 column 方法直接获取 uid 数组
402
+
403
+        if (!empty($subUidList)) {
404
+            foreach ($subUidList as $subUid) {
405
+                $allSubordinates[] = $subUid;
406
+                $this->getAllSubordinates($subUid, $allSubordinates);
407
+            }
408
+        }
409
+
410
+        return $allSubordinates;
411
+    }
412
+
413
+    /**
414
+     *  更高效的获取所有下级 (使用循环代替递归, 避免栈溢出)
415
+     * @param array $uids
416
+     * @return array
417
+     */
418
+    public function getAllSubordinatesIterative(array $uids): array
419
+    {
420
+        $result = [];
421
+
422
+        foreach ($uids as $uid) {
423
+            $result[$uid] = [];
424
+            $queue = [$uid];  // 使用队列来存储待处理的 UID
425
+            $processed = []; // 记录已经处理过的
426
+
427
+            while (!empty($queue)) {
428
+                $currentUid = array_shift($queue); // 从队列头部取出 UID
429
+                if (in_array($currentUid, $processed)) {
430
+                    continue; // 已经处理过
431
+                }
432
+                $processed[] = $currentUid;
433
+                $subUidList = Db::name("user")
434
+                    ->where("spread_uid", $currentUid)
435
+                    ->column("uid");
436
+
437
+                if (!empty($subUidList)) {
438
+                    $result[$uid] = array_merge($result[$uid], $subUidList); //合并
439
+                    $queue = array_merge($queue, $subUidList);  // 将新找到的下级 UID 加入队列尾部
440
+                }
441
+            }
442
+            $result[$uid] = array_unique($result[$uid]);//去重
443
+        }
444
+        return $result;
445
+    }
446
+
447
+    /**
448
+     * 获取多个用户的所有下级,  返回分组后的数组.  (更高效, 使用循环, 减少数据库查询次数)
449
+     * @param array $uids
450
+     * @return array 形如 ['A1' => [A11, A12, ...], 'A2' => [...]]
451
+     */
452
+    public function getSubordinatesBatch(array $uids): array
453
+    {
454
+        $result = [];
455
+        $allSubordinates = [];
456
+        $queue = $uids;
457
+        $processed = [];
458
+        //1. 找出所有的下级ID (不去重)
459
+        while (!empty($queue)) {
460
+            $currentUids = array_splice($queue, 0, 500); // 一次最多处理500个,防止in太多.  可以根据实际情况调整.
461
+            $currentUids = array_diff($currentUids, $processed); //去除已经查询过的
462
+            if (empty($currentUids)) continue;  //没有新的需要处理的
463
+            $processed = array_merge($processed, $currentUids);//记录
464
+            $subUidList = Db::name("user")
465
+                ->whereIn("spread_uid", $currentUids)
466
+                ->field("uid,spread_uid") // 需要查询 spread_uid 用于后续分组
467
+                ->select()
468
+                ->toArray();
469
+
470
+            if (!empty($subUidList)) {
471
+                $allSubordinates = array_merge($allSubordinates, $subUidList); //所有下级
472
+                $nextLevelUids = array_column($subUidList, 'uid');
473
+                $queue = array_merge($queue, $nextLevelUids);  //放到队列中
474
+            }
475
+        }
476
+        //2. 分组
477
+        foreach ($uids as $uid) {
478
+            $result[$uid] = []; // 初始化每个用户的下级数组
479
+        }
480
+        $allSubordinatesMap = [];
481
+        foreach ($allSubordinates as $item) {
482
+            $allSubordinatesMap[$item['spread_uid']][] = $item['uid'];
483
+        }
484
+
485
+        //3. 递归的将查到的下级进行分组
486
+        $group = function ($spreadUid) use (&$group, &$allSubordinatesMap, &$result) {
487
+            if (isset($allSubordinatesMap[$spreadUid])) {
488
+                foreach ($allSubordinatesMap[$spreadUid] as $subUid) {
489
+                    if (isset($result[$spreadUid])) {
490
+                        $result[$spreadUid][] = $subUid; //直接添加到结果中
491
+                    } else { //不属于直接上级, 查找上级的上级
492
+                        foreach ($result as $rootUid => &$subordinates) {
493
+                            if (in_array($spreadUid, $subordinates) || $rootUid == $spreadUid) {
494
+                                $subordinates[] = $subUid;
495
+                                break;
496
+                            }
497
+                        }
498
+                    }
499
+                    $group($subUid); //递归下一层
500
+                }
501
+            }
502
+        };
503
+        foreach ($uids as $uid) {
504
+            $group($uid);
505
+        }
506
+
507
+        // 4. 去重 (如果需要)
508
+        foreach ($result as $key => $value) {
509
+            $result[$key] = array_values(array_unique($value));
510
+        }
511
+        return $result;
512
+    }
513
+
514
+    // 获取用户PV值
515
+    public function getPv($userIdList, $removeUserIdList = [])
516
+    {
517
+        if (!empty($removeUserIdList)) {
518
+            $userIdList = array_values(array_diff($userIdList, $removeUserIdList));
519
+        }
520
+        // 基础查询构建器
521
+        $user_team_amount = Db::name("old_user_of_goods")
522
+            ->whereIn("user_id", $userIdList)
523
+            ->where('status', 1)
524
+            ->where('money', 1180)
525
+            ->select();
526
+        //$money1180Records = $this->old_user_of_goods->where('status', 1)->where('money', 1180)->select();
527
+        // 计算 status 为 1 且 money 为 1180 的记录总和(减去相应值后)
528
+        $money1180Sum = 0;
529
+        foreach ($user_team_amount as $record) {
530
+            $money1180Sum += $record['money'] - 300 - 180;
531
+        }
532
+
533
+        // 获取 status 为 1 且 money 为 11800 的记录集合
534
+        $money11800Records = Db::name("old_user_of_goods")
535
+            ->whereIn("user_id", $userIdList)
536
+            ->where('status', 1)
537
+            ->where('money', 11800)
538
+            ->select();
539
+        // 计算 status 为 1 且 money 为 11800 的记录总和(减去相应值后)
540
+        $money11800Sum = 0;
541
+        foreach ($money11800Records as $record) {
542
+            $money11800Sum += $record['money'] - 3000 - 1800;
543
+        }
544
+
545
+        $money10620Records = Db::name("old_user_of_goods")
546
+            ->whereIn("user_id", $userIdList)
547
+            ->where('status', 1)
548
+            ->where('money', 10620)
549
+            ->select();
550
+        // 计算 status 为 1 且 money 为 10620 的记录总和(减去相应值后)
551
+        $money10620Sum = 0;
552
+        foreach ($money10620Records as $record) {
553
+            $money10620Sum += $record['money'] - 2700 - 1620;
554
+        }
555
+
556
+
557
+        $money9440Records = Db::name("old_user_of_goods")
558
+            ->whereIn("user_id", $userIdList)
559
+            ->where('status', 1)
560
+            ->where('money', 9440)
561
+            ->select();
562
+        // 计算 status 为 1 且 money 为 9440 的记录总和(减去相应值后)
563
+        $money9440Sum = 0;
564
+        foreach ($money9440Records as $record) {
565
+            $money9440Sum += $record['money'] - 2400 - 1440;
566
+        }
567
+
568
+        $money2360Records = Db::name("old_user_of_goods")
569
+            ->whereIn("user_id", $userIdList)
570
+            ->where('status', 1)
571
+            ->where('money', 2360)
572
+            ->select();
573
+        // 计算 status 为 1 且 money 为 2360 的记录总和(减去相应值后)
574
+        $money2360Sum = 0;
575
+        foreach ($money2360Records as $record) {
576
+            $money2360Sum += $record['money'] - 600 - 360;
577
+        }
578
+
579
+        // 计算除去特定值后的总和
580
+        $otherMoneyRecords = [];
581
+//        $otherMoneyRecords = Db::name("old_user_of_goods")
582
+//            ->whereIn("user_id", $userIdList)
583
+//            ->whereNotIn('money', [1180, 11800, 10620, 9440, 2360])
584
+//            ->select();
585
+        $otherMoneySum = 0;
586
+        foreach ($otherMoneyRecords as $record) {
587
+            $otherMoneySum += $record['money'];
588
+        }
589
+        return $money1180Sum + $money11800Sum + $money10620Sum + $money9440Sum + $money2360Sum + (floor($otherMoneySum * 70) / 100);
590
+    }
591
+
592
+    //发放佣金 示例: $this->change_user_log($v,'amount',1,$all_award,"member_award","星级分红入账"."-".$value['title']);//释放佣金
593
+    function change_user_log($user_id, $type, $change_status, $money, $routine, $remark = "", $is_admin = 1, $appoint_money = 0)
594
+    {
595
+        $transition = [
596
+            'pv' => 1,
597
+            "gb" => 2,
598
+            "df" => 3,
599
+            "vr" => 4,
600
+            "bt" => 5,
601
+            "withdraw_quota_old" => 6,//提现
602
+            "unsettled_pension" => 7,
603
+            "amount_old" => 8//发放佣金
604
+        ];
605
+        $routineInfo = Db::name("old_routine_log_of_key")->where("key", $routine)->find();
606
+        if (empty($routineInfo)) {
607
+            return false;
608
+        }
609
+        $key_id = isset($routineInfo['id']) ? $routineInfo['id'] : 0;
610
+
611
+        if ($appoint_money > 0) {
612
+            $alter_money = $appoint_money;
613
+        } else {
614
+            //再去查询变更前的 金额
615
+            $alter_money = Db::name("user")->where('uid', $user_id)->value($type);
616
+        }
617
+        if ($change_status == 1) {
618
+            //新增前
619
+            $alter_money = $alter_money - $money;
620
+        } else if ($change_status == 2) {
621
+            //减少前
622
+            $alter_money = $alter_money + $money;
623
+        }
624
+        if ($alter_money < 0) {
625
+            $alter_money = 0;
626
+        }
627
+        $inser_data = [];
628
+        $inser_data['user_id'] = $user_id;
629
+        $inser_data['type'] = $transition[$type];
630
+        $inser_data['change_status'] = $change_status;
631
+        $inser_data['money'] = $money;
632
+        $inser_data['routine_log_of_key_id'] = $key_id;
633
+        $inser_data['remark'] = $remark;
634
+        $inser_data['is_admin'] = $is_admin;
635
+        $inser_data['create_time'] = time();
636
+        $inser_data['alter_money'] = isset($alter_money) ? $alter_money : 0;
637
+        Db::name("old_user_log")->insert($inser_data);
638
+    }
639
+
640
+    //添加平台分佣2.0系统收益明细日志(养老金金额)
641
+    public function bill_user_log111111($uid, $name, $num, $mark, $comm)
642
+    {
643
+
644
+        $con_data = Db::name('user')->where("uid", $uid)->find();
645
+        //如果是会员专区就即刻到账
646
+
647
+        // Db::name('user')->where("uid",$con_data['uid'])->update(['brokerage_price'=> $con_data['brokerage_price'] + $num]);
648
+
649
+
650
+        $bill = [
651
+            'uid' => $uid,
652
+            'link_id' => 0,//关联订单id
653
+            'pm' => 1,//0:支出,1:获得
654
+            'title' => $name,//账单标题
655
+            'category' => 'now_money',//明细种类
656
+            'type' => 'commission',//明细类型
657
+            'number' => $num,//明细数字
658
+            'balance' => 0,//剩余
659
+            'mark' => $mark,//备注
660
+            'create_time' => date('Y-m-d H:i:s'),//添加时间
661
+            'status' => 1,//0待确定,1有效,-1无效
662
+            'commission_type' => $comm,//佣金类型 1代理费 2 消费佣金 3直推奖√ 4辖区佣金\r\n5 养老金√ 6 广告费
663
+            //7 跨店奖励√ 8平台奖励 9渠道商\r\n10 推荐创客收益√ 11分红奖金√ 12代理区域收益√ 13消费循环佣金
664
+            //14-推荐代理收益√ 15邀请小区团长升级√ 16大v分享奖√ 17创客合伙人√ 18积分奖励√ 19创客补贴√’
665
+            'order_sn' => 0,//订单号
666
+            'tripartite' => 0,//
667
+            'type_shop' => 0,//0平台1多多进宝2唯品会3苏宁易购4网易考拉5淘宝客6京东联盟7饿了么8线上
668
+            'mer_id' => 0,//商户id
669
+            'source' => 0,//1线下 0线上
670
+            'order_type' => 1,//1自营  2 第三方  订单类型
671
+            'is_red_brokerage' => 0,//1红积分对冲佣金 0正常佣金
672
+            'gzc' => 3,//养老金是否已进入公证处log表0:未进入。1:已进入
673
+            'take_time' => '',//结算时间
674
+            'district_id' => '',//
675
+            'street_id' => '',//
676
+            'month' => '',//月份
677
+
678
+
679
+        ];
680
+
681
+        Db::name('user_bill')->insert($bill);
682
+    }
683
+
684
+    //添加复购金
685
+    public function fugou_user_log($uid, $num, $order_id, $type_inc_des, $status = -1)
686
+    {
687
+
688
+        $fugou_data = Db::name('user')->where("uid", $uid)->find();
689
+
690
+
691
+        $bill = [
692
+            'uid' => $uid,
693
+            'number' => $num,//数量
694
+            'status' => $status,//复购金状态1-有效 0-失效 -1待确认
695
+            'mark' => "复购金",//备注
696
+            'desc' => "10%复购金",//描述
697
+            'order_id' => $order_id,//订单id
698
+            'surplus' => 0,//剩余
699
+            'order_type' => 11,//关联订单ID
700
+            'type' => $type_inc_des,//复购金类型 :1赠送,2消耗
701
+            'settlement_time' => date('Y-m-d H:i:s'),//添加时间,
702
+            'addtime' => time(),
703
+        ];
704
+
705
+        Db::name('user_sign_fugou')->insert($bill);
706
+    }
707
+}

+ 16 - 16
app/controller/api/store/merchant/Taskorder.php

@@ -72,8 +72,8 @@ class Taskorder extends BaseController
72 72
     public function lst1()
73 73
     {
74 74
 
75
-       return;
76
-   
75
+        return;
76
+
77 77
         // $user_datas = Db::name("user")->select();//星级等级
78 78
         // foreach($user_datas as $k=>$v){
79 79
         //     if($v['user_level_id_old']==2){
@@ -83,28 +83,28 @@ class Taskorder extends BaseController
83 83
         //     }
84 84
         // }
85 85
 
86
-         // 查询当前用户及其子级的所有订单
86
+        // 查询当前用户及其子级的所有订单
87 87
         //$totalPv = $this->getTeamPvByTime('this_week');
88 88
 
89
-    
90
-    //    var_dump($totalPv);return;    
91
-    
89
+
90
+        //    var_dump($totalPv);return;
91
+
92 92
         // $sf = $this->getStarLevel(221);
93
- 
93
+
94 94
         //$ss = $this->getbig_samll_datas(17);//222
95 95
         //var_dump($ss);
96
-          //$ff = $this->getPerformanceOf(221);
97
-         // var_dump($ff);
98
-    //var_dump($ss);   
99
-          // return;
100
-      
101
-     
96
+        //$ff = $this->getPerformanceOf(221);
97
+        // var_dump($ff);
98
+        //var_dump($ss);
99
+        // return;
100
+
101
+
102 102
         // $store_product_datas = Db::name('old_user_of_goods_old')->select();
103
-       
103
+
104 104
         //$week_record = 45500 + 1400 + 60000; //20250218
105 105
         //$week_record =23800 + 60000; //20250222
106
-       // $week_record = 64400; //20250301
107
-        
106
+        // $week_record = 64400; //20250301
107
+    }
108 108
 
109 109
     //添加复购金
110 110
     public function fugou_user_log($uid,$num,$order_id,$type_inc_des,$status=-1){

+ 230 - 78
app/controller/api/store/merchant/Taskorderguquan.php

@@ -4,6 +4,7 @@
4 4
  * @Author: Qinii
5 5
  * @Date: 2020/5/28
6 6
  */
7
+
7 8
 namespace app\controller\api\store\merchant;
8 9
 
9 10
 use think\App;
@@ -17,87 +18,165 @@ class Taskorderguquan extends BaseController
17 18
 {
18 19
 
19 20
 
20
-
21
-
22 21
     public function lst6()
23 22
     {
24 23
 
25
-       return;
26
-
27
-        // return;
28
-
29
-        // $store_product_datas = Db::name('old_user_of_goods_old')->select();
30
-
31
-        //$week_record = 45500 + 60000 + 1400;
32
-
33
-        //$week_record = 23800 + 60000;//20250222
34
-
35
-       // $week_record = 64400;//20250303
36
-
37
-       
38
-
39
-
24
+        $week_record = 10500 + 50000; //20250310
25
+
26
+        // 查询测试人员账号信息
27
+        //18973958920
28
+        //15186694339
29
+        //18833633835
30
+        //19525470098
31
+        //17756507016
32
+        //18226705337
33
+        $testAccount = ['18973958920', '15186694339', '18833633835', '19525470098', '17756507016', '18226705337'];
34
+        $removeUserList = Db::name("user")
35
+            ->whereIn('account', $testAccount)
36
+            ->where("status", "<>", 0)
37
+            ->where('is_del', '<>', 1)
38
+            ->select()
39
+            ->toArray();
40
+        $removeUserIdList = array_column($removeUserList, 'uid');
41
+        // 定义分红金额
42
+        $week_record = $this->getTeamPvByTime('last_week', $removeUserIdList);
43
+        // 分红金额 - 红包金额
44
+        $redEnvelope = $this->getRedEnvelopeByTime('last_week', $removeUserIdList);
45
+
46
+        $week_record -= $redEnvelope;
47
+
48
+
49
+        $stock_comm = round($week_record * 0.05 ,2);
50
+
51
+
52
+        //获取股权分红的人
53
+
54
+        $GetAllUserPackNum = db::name("old_user_stock")->sum("pack");//计算所有用户的份数总和
55
+
56
+        $stockuserdatas = db::name("old_user_stock")->select();//获取所有用户
57
+
58
+        if(count($stockuserdatas) > 0){
59
+            $one_pack_comm_data = round($stock_comm / $GetAllUserPackNum,2);//获取每份的单佣金
60
+
61
+            foreach ($stockuserdatas as &$v) {
62
+                $v['getcomm'] = $v['pack'] * $one_pack_comm_data;
63
+                $v['allgetcomm'] =  $v['allgetcomm'] + $v['getcomm'];
64
+                $v['update_time'] = time();
65
+
66
+                $yj_90 = $v['getcomm'] * 0.9;
67
+                $fg_10 = $v['getcomm'] * 0.1;
68
+
69
+                // // 更新 user_stock 表中的记录
70
+                $res = db::name("old_user_stock")->where("id", $v['id'])->update([
71
+                    'getcomm' => $v['getcomm'],
72
+                    'allgetcomm' => $v['allgetcomm'],
73
+                    'update_time' => $v['update_time']
74
+                ]);
75
+
76
+                Db::name("user")->where("uid",$v['user_id'])->inc("brokerage_price", $yj_90)->save();
77
+                $res1 = Db::name("user")->where("uid",$v['user_id'])->inc("total_amount_old", $yj_90)->save();
78
+                $res2 = Db::name("user")->where("uid",$v['user_id'])->inc("amount_old", $yj_90)->save();
79
+
80
+                $res3 = Db::name("user")->where("uid",$v['user_id'])->inc("fugou", $fg_10)->save();
81
+
82
+                $res =true;
83
+                if($res){
84
+                    $das = $this->change_user_log($v['user_id'],'amount_old',1, $yj_90,"member_award_stock","股权分红入账"."-".$v['pack']);//释放佣金
85
+
86
+                    //入账星级分红记录表
87
+                    $week_data = [];
88
+                    $week_data['user_id'] =  $v['user_id'];
89
+                    $week_data['user_star_id'] =  0;
90
+                    $week_data['award_num'] =  0;
91
+                    $week_data['award_num_sm'] =  0;
92
+                    $week_data['remark'] =  "股权分红主动执行" . $yj_90;
93
+                    $week_data['week_record'] =  $week_record;
94
+                    $week_data['all_amount'] =  $stock_comm;
95
+                    $week_data['radio'] =  2;
96
+                    $week_data['owner_bill'] =  0;  //总流水金额
97
+                    $week_data['my_bill'] = 0;  //我的流水
98
+                    $week_data['create_time'] = time();
99
+
100
+
101
+                    Db::name("old_user_weekaward")->insert($week_data);
102
+
103
+                    $userdatassss = db::name("old_user_jbp")->where("id",$v['user_id'])->find();
104
+                    $datas_log = [
105
+                        'note'=>"名称:".  $userdatassss['nick_name']  . " 用户:".  $v['user_id'] . " 新增股权佣金:" .  $yj_90,
106
+                        'create_time'=>date('Y-m-d H:i:s')
107
+                    ];
108
+                    $con_data = Db::name('test_log')->insert($datas_log);   //数据存到2.0数据表中
109
+
110
+                    $this->bill_user_log111111($v['user_id'],"股权分佣",  $yj_90,"股权明细入账",13);//股权分佣明细2.0系统
111
+
112
+                    $this->fugou_user_log($v['user_id'],$fg_10,16,1,1);//复购金明细入账
113
+                }
114
+            }
115
+        }
116
+        //股权分红 end
40 117
     }
41 118
 
42
-       //添加复购金
43
-       public function fugou_user_log($uid,$num,$order_id,$type_inc_des,$status=-1){
119
+    //添加复购金
120
+    public function fugou_user_log($uid, $num, $order_id, $type_inc_des, $status = -1)
121
+    {
122
+
123
+        $fugou_data = Db::name('user')->where("uid", $uid)->find();
44 124
 
45
-        $fugou_data = Db::name('user')->where("uid",$uid)->find();
46
-       
47 125
 
48 126
         $bill = [
49
-            'uid'=>$uid,
50
-            'number'=>$num,//数量
51
-            'status'=>$status,//复购金状态1-有效 0-失效 -1待确认
52
-            'mark'=>"复购金",//备注
53
-            'desc'=>"10%作为复购金",//描述
54
-            'order_id'=>$order_id,//订单id
55
-            'surplus'=>0,//剩余
56
-            'order_type'=>11,//关联订单ID
57
-            'type'=>$type_inc_des,//复购金类型 :1赠送,2消耗
58
-            'settlement_time'=>date('Y-m-d H:i:s'),//添加时间,
59
-            'addtime'=>time(),
127
+            'uid' => $uid,
128
+            'number' => $num,//数量
129
+            'status' => $status,//复购金状态1-有效 0-失效 -1待确认
130
+            'mark' => "复购金",//备注
131
+            'desc' => "10%作为复购金",//描述
132
+            'order_id' => $order_id,//订单id
133
+            'surplus' => 0,//剩余
134
+            'order_type' => 11,//关联订单ID
135
+            'type' => $type_inc_des,//复购金类型 :1赠送,2消耗
136
+            'settlement_time' => date('Y-m-d H:i:s'),//添加时间,
137
+            'addtime' => time(),
60 138
         ];
61 139
 
62 140
         Db::name('user_sign_fugou')->insert($bill);
63 141
     }
64 142
 
65 143
     //添加平台分佣2.0系统收益明细日志(养老金金额)
66
-    public function bill_user_log111111($uid,$name,$num,$mark,$comm){
144
+    public function bill_user_log111111($uid, $name, $num, $mark, $comm)
145
+    {
67 146
 
68
-        $con_data = Db::name('user')->where("uid",$uid)->find();
147
+        $con_data = Db::name('user')->where("uid", $uid)->find();
69 148
         //如果是会员专区就即刻到账
70 149
 
71 150
         // Db::name('user')->where("uid",$con_data['uid'])->update(['brokerage_price'=> $con_data['brokerage_price'] + $num]);
72 151
 
73 152
 
74 153
         $bill = [
75
-            'uid'=>$uid,
76
-            'link_id'=>0,//关联订单id
77
-            'pm'=>1,//0:支出,1:获得
78
-            'title'=>$name,//账单标题
79
-            'category'=>'now_money',//明细种类
80
-            'type'=>'commission',//明细类型
81
-            'number'=>$num,//明细数字
82
-            'balance'=>0,//剩余
83
-            'mark'=>$mark,//备注
84
-            'create_time'=>date('Y-m-d H:i:s'),//添加时间
85
-            'status'=>1,//0待确定,1有效,-1无效
86
-            'commission_type'=>$comm,//佣金类型 1代理费 2 消费佣金 3直推奖√ 4辖区佣金\r\n5 养老金√ 6 广告费
154
+            'uid' => $uid,
155
+            'link_id' => 0,//关联订单id
156
+            'pm' => 1,//0:支出,1:获得
157
+            'title' => $name,//账单标题
158
+            'category' => 'now_money',//明细种类
159
+            'type' => 'commission',//明细类型
160
+            'number' => $num,//明细数字
161
+            'balance' => 0,//剩余
162
+            'mark' => $mark,//备注
163
+            'create_time' => date('Y-m-d H:i:s'),//添加时间
164
+            'status' => 1,//0待确定,1有效,-1无效
165
+            'commission_type' => $comm,//佣金类型 1代理费 2 消费佣金 3直推奖√ 4辖区佣金\r\n5 养老金√ 6 广告费
87 166
             //7 跨店奖励√ 8平台奖励 9渠道商\r\n10 推荐创客收益√ 11分红奖金√ 12代理区域收益√ 13消费循环佣金
88 167
             //14-推荐代理收益√ 15邀请小区团长升级√ 16大v分享奖√ 17创客合伙人√ 18积分奖励√ 19创客补贴√’
89
-            'order_sn'=>0,//订单号
90
-            'tripartite'=>0,//
91
-            'type_shop'=>0,//0平台1多多进宝2唯品会3苏宁易购4网易考拉5淘宝客6京东联盟7饿了么8线上
92
-            'mer_id'=>0,//商户id
93
-            'source'=>0,//1线下 0线上
94
-            'order_type'=>1,//1自营  2 第三方  订单类型
95
-            'is_red_brokerage'=>0,//1红积分对冲佣金 0正常佣金
96
-            'gzc'=>3,//养老金是否已进入公证处log表0:未进入。1:已进入
97
-            'take_time'=>'',//结算时间
98
-            'district_id'=>'',//
99
-            'street_id'=>'',//
100
-            'month'=>'',//月份
168
+            'order_sn' => 0,//订单号
169
+            'tripartite' => 0,//
170
+            'type_shop' => 0,//0平台1多多进宝2唯品会3苏宁易购4网易考拉5淘宝客6京东联盟7饿了么8线上
171
+            'mer_id' => 0,//商户id
172
+            'source' => 0,//1线下 0线上
173
+            'order_type' => 1,//1自营  2 第三方  订单类型
174
+            'is_red_brokerage' => 0,//1红积分对冲佣金 0正常佣金
175
+            'gzc' => 3,//养老金是否已进入公证处log表0:未进入。1:已进入
176
+            'take_time' => '',//结算时间
177
+            'district_id' => '',//
178
+            'street_id' => '',//
179
+            'month' => '',//月份
101 180
 
102 181
 
103 182
         ];
@@ -105,41 +184,41 @@ class Taskorderguquan extends BaseController
105 184
         Db::name('user_bill')->insert($bill);
106 185
     }
107 186
 
108
-    
187
+
109 188
     //发放佣金 示例: $this->change_user_log($v,'amount',1,$all_award,"member_award","星级分红入账"."-".$value['title']);//释放佣金
110
-    function change_user_log($user_id,$type,$change_status,$money,$routine,$remark="",$is_admin=1,$appoint_money = 0)
189
+    function change_user_log($user_id, $type, $change_status, $money, $routine, $remark = "", $is_admin = 1, $appoint_money = 0)
111 190
     {
112 191
         $transition = [
113
-            'pv'=>1,
114
-            "gb"=>2,
115
-            "df"=>3,
116
-            "vr"=>4,
117
-            "bt"=>5,
118
-            "withdraw_quota_old"=>6,//提现
119
-            "unsettled_pension"=>7,
120
-            "amount_old"=>8//发放佣金
192
+            'pv' => 1,
193
+            "gb" => 2,
194
+            "df" => 3,
195
+            "vr" => 4,
196
+            "bt" => 5,
197
+            "withdraw_quota_old" => 6,//提现
198
+            "unsettled_pension" => 7,
199
+            "amount_old" => 8//发放佣金
121 200
         ];
122
-        $routineInfo = Db::name("old_routine_log_of_key")->where("key",$routine)->find();
123
-        if(empty($routineInfo)) {
201
+        $routineInfo = Db::name("old_routine_log_of_key")->where("key", $routine)->find();
202
+        if (empty($routineInfo)) {
124 203
             return false;
125 204
         }
126 205
         $key_id = isset($routineInfo['id']) ? $routineInfo['id'] : 0;
127 206
 
128
-        if($appoint_money > 0) {
207
+        if ($appoint_money > 0) {
129 208
             $alter_money = $appoint_money;
130
-        }else{
209
+        } else {
131 210
             //再去查询变更前的 金额
132
-            $alter_money = Db::name("user")->where('uid',$user_id)->value($type);
211
+            $alter_money = Db::name("user")->where('uid', $user_id)->value($type);
133 212
         }
134
-        if($change_status == 1) {
213
+        if ($change_status == 1) {
135 214
             //新增前
136
-            $alter_money = $alter_money-$money;
137
-        }else if($change_status == 2){
215
+            $alter_money = $alter_money - $money;
216
+        } else if ($change_status == 2) {
138 217
             //减少前
139 218
             $alter_money = $alter_money + $money;
140 219
         }
141
-        if($alter_money < 0) {
142
-            $alter_money =0;
220
+        if ($alter_money < 0) {
221
+            $alter_money = 0;
143 222
         }
144 223
         $inser_data = [];
145 224
         $inser_data['user_id'] = $user_id;
@@ -154,6 +233,79 @@ class Taskorderguquan extends BaseController
154 233
         Db::name("old_user_log")->insert($inser_data);
155 234
     }
156 235
 
236
+    public function getTime($timePeriod)
237
+    {
238
+        // 定义时间区间
239
+        $now = time();
240
+        $startTime = '';
241
+        $endTime = '';
242
+        if ($timePeriod == 'last_week') {
243
+            // 上周的时间区间
244
+            $startTime = date('Y-m-d', strtotime('monday last week', $now)); // 上周星期一的开始时间
245
+            $endTime = date('Y-m-d', strtotime('sunday last week', $now)); // 上周星期日的结束时间
246
+        } elseif ($timePeriod == 'this_week') {
247
+            // 这周的时间区间
248
+            $startTime = date('Y-m-d', strtotime('monday this week', $now)); // 这周星期一的开始时间
249
+            $endTime = date('Y-m-d', strtotime('sunday this week', $now)); // 这周星期日的结束时间
250
+        }
251
+        //        return ['startTime' => '2025-03-10', 'endTime' => '2025-03-23'];
252
+        return ['startTime' => $startTime, 'endTime' => $endTime];
253
+    }
254
+
255
+    public function getTeamPvByTime($timePeriod = 'last_week', $removeUserIdList = [])
256
+    {
257
+        $timeMap = $this->getTime($timePeriod);
258
+        $startTime = $timeMap['startTime'];
259
+        $endTime = $timeMap['endTime'];
260
+
261
+        // 查询指定时间区间内的所有订单,并排除 pay_time 为 NULL 的订单
262
+        $orders = Db::name("store_order")
263
+            ->where('mer_id', 496)
264
+            ->whereNotIn('uid', $removeUserIdList)
265
+            ->whereIn('status', [0, 1, 2, 3])
266
+            ->whereIn("total_price", [1180, 11800, 10620, 2360, 9440])
267
+            ->whereBetween("pay_time", [$startTime . ' 00:00:00', $endTime . ' 23:59:59'])
268
+            ->whereNotNull("pay_time") // 排除 pay_time 为 NULL 的订单
269
+            ->select();
270
+
271
+        // 计算总业绩
272
+        $totalPv = 0;
273
+        foreach ($orders as $order) {
274
+            switch ($order['total_price']) {
275
+                case 1180:
276
+                    $totalPv += 700;
277
+                    break;
278
+                case 11800:
279
+                    $totalPv += 7000;
280
+                    break;
281
+                case 10620:
282
+                    $totalPv += 6300;
283
+                    break;
284
+                case 2360:
285
+                    $totalPv += 1400;
286
+                    break;
287
+                case 9440:
288
+                    $totalPv += 5600;
289
+                    break;
290
+            }
291
+        }
157 292
 
293
+        return $totalPv;
294
+    }
158 295
 
296
+    public function getRedEnvelopeByTime($timePeriod = 'last_week', $removeUserIdList = [])
297
+    {
298
+        $timeMap = $this->getTime($timePeriod);
299
+        $startTime = $timeMap['startTime'];
300
+        $endTime = $timeMap['endTime'];
301
+
302
+        // 查询指定时间区间内的所有订单,并排除 pay_time 为 NULL 的订单
303
+        $redEnvelopeList = Db::name("user_sign_hongbao")
304
+            ->whereNotIn('uid', $removeUserIdList)
305
+            ->where('status', 1)
306
+            ->whereBetween("settlement_time", [$startTime . ' 00:00:00', $endTime . ' 23:59:59'])
307
+            ->select()
308
+            ->toArray();
309
+        return floor(array_sum(array_column($redEnvelopeList, 'number')) * 100) / 100;
310
+    }
159 311
 }

+ 355 - 178
app/controller/api/store/merchant/Taskorderlianc.php

@@ -4,6 +4,7 @@
4 4
  * @Author: Qinii
5 5
  * @Date: 2020/5/28
6 6
  */
7
+
7 8
 namespace app\controller\api\store\merchant;
8 9
 
9 10
 use think\App;
@@ -19,14 +20,14 @@ class Taskorderlianc extends BaseController
19 20
     /**
20 21
      * 会员升级
21 22
      */
22
-    public function member_update($orderInfo,$goods_of_info,$user_id)
23
+    public function member_update($orderInfo, $goods_of_info, $user_id)
23 24
     {
24 25
         //
25 26
         //$user_id = $userInfo['id'];
26 27
         $order_id = $orderInfo['id'];
27 28
 
28 29
         //code...
29
-        $pay_gb =  round($orderInfo['num'] * $orderInfo['gb_num'],2);
30
+        $pay_gb = round($orderInfo['num'] * $orderInfo['gb_num'], 2);
30 31
         //$pay_vr =  round($orderInfo['num'] * $orderInfo['vr_num'],2);
31 32
         //付款按照700的VR付款 start
32 33
         $vr_num = 0;
@@ -36,14 +37,13 @@ class Taskorderlianc extends BaseController
36 37
             $vr_num = 7000;
37 38
         } elseif ($orderInfo['price'] == 11800) {
38 39
             $vr_num = 2100;
39
-        }elseif($orderInfo['price'] == 10620){
40
+        } elseif ($orderInfo['price'] == 10620) {
40 41
             $vr_num = 6300;
41 42
         }
42 43
 
43 44
 
44
-
45 45
         $pay_gb1 = $vr_num;
46
-        $pay_vr1 =$orderInfo['price'];//记录VR值
46
+        $pay_vr1 = $orderInfo['price'];//记录VR值
47 47
 
48 48
 
49 49
         // $result = Db::name("old_user_jbp")->where("id",$user_id)->dec("vr",$orderInfo['price'])->save();//1.0jbp旧表
@@ -51,43 +51,41 @@ class Taskorderlianc extends BaseController
51 51
 
52 52
 
53 53
         $result = true;
54
-        if($result) {
54
+        if ($result) {
55 55
             $invite_id = $goods_of_info['spread_id'];
56 56
 
57 57
 
58 58
             $zs_ylj = 0; //养老金赋值
59 59
 
60 60
 
61
-            if($goods_of_info['money'] == 1180){
61
+            if ($goods_of_info['money'] == 1180) {
62 62
                 //修改订单到账状态
63
-                $zs_ylj = round(700 * 0.05,2);//计算的养老金 金额
64
-            }elseif($goods_of_info['money'] == 11800){
65
-                $zs_ylj = round(7000 * 0.05,2);//计算的养老金 金额
66
-            }elseif($goods_of_info['money'] == 3540){
67
-                $zs_ylj = round(2100 * 0.05,2);//计算的养老金 金额
68
-            }elseif($goods_of_info['money'] == 10620){
69
-                $zs_ylj = round(6300 * 0.05,2);//计算的养老金 金额
70
-            }elseif($goods_of_info['money'] == 9440){
71
-                $zs_ylj = round(5600 * 0.05,2);//八单计算的养老金 金额
72
-            }elseif($goods_of_info['money'] == 2360){
73
-                $zs_ylj = round(1400 * 0.05,2);//两单计算的养老金 金额
63
+                $zs_ylj = round(700 * 0.05, 2);//计算的养老金 金额
64
+            } elseif ($goods_of_info['money'] == 11800) {
65
+                $zs_ylj = round(7000 * 0.05, 2);//计算的养老金 金额
66
+            } elseif ($goods_of_info['money'] == 3540) {
67
+                $zs_ylj = round(2100 * 0.05, 2);//计算的养老金 金额
68
+            } elseif ($goods_of_info['money'] == 10620) {
69
+                $zs_ylj = round(6300 * 0.05, 2);//计算的养老金 金额
70
+            } elseif ($goods_of_info['money'] == 9440) {
71
+                $zs_ylj = round(5600 * 0.05, 2);//八单计算的养老金 金额
72
+            } elseif ($goods_of_info['money'] == 2360) {
73
+                $zs_ylj = round(1400 * 0.05, 2);//两单计算的养老金 金额
74 74
             }
75 75
 
76 76
 
77
-
78
-
79 77
             $uid = $user_id;
80 78
             $new_user_id = $uid;
81
-            if(empty($new_user_id)) {
82
-                abort(0,"当前绑定会员查询错误");
79
+            if (empty($new_user_id)) {
80
+                abort(0, "当前绑定会员查询错误");
83 81
             }
84 82
 
85
-            $new_nums =Db::name("old_user_of_goods")->where("user_id", $uid)->sum("money");
83
+            $new_nums = Db::name("old_user_of_goods")->where("user_id", $uid)->sum("money");
86 84
 
87 85
             //增加过后权益对比 获取当前权益等级
88
-            $old_level_id = Db::name("old_user_jbp")->where("id",$uid)->find();
86
+            $old_level_id = Db::name("old_user_jbp")->where("id", $uid)->find();
89 87
 
90
-            $old_level_info = Db::name("old_user_level")->where("id",$old_level_id['user_level_id'])->find();
88
+            $old_level_info = Db::name("old_user_level")->where("id", $old_level_id['user_level_id'])->find();
91 89
 
92 90
 
93 91
             $level_info = [];
@@ -97,8 +95,8 @@ class Taskorderlianc extends BaseController
97 95
             //计算会员等级 升级
98 96
             foreach ($level_list as $key => $value) {
99 97
                 # code...
100
-                if($new_nums>=$value['money']) {
101
-                    $level_info =  $value;
98
+                if ($new_nums >= $value['money']) {
99
+                    $level_info = $value;
102 100
                     break;
103 101
                 }
104 102
             }
@@ -107,21 +105,20 @@ class Taskorderlianc extends BaseController
107 105
             $zs_withdraw_quota = $orderInfo['price'];
108 106
 
109 107
 
110
-            if($old_level_info['id'] == $level_info['id']) {
108
+            if ($old_level_info['id'] == $level_info['id']) {
111 109
                 //未到达升级权益 不改变用户等级
112 110
                 $update_status = false;
113
-            }else{
111
+            } else {
114 112
                 $update_status = true;
115 113
                 $user_level = $level_info['id'];
116 114
                 //var_dump( $user_level);
117
-                Db::name("old_user_jbp")->where("id",$new_user_id)->save(['user_level_id'=>$user_level]);//1.0jbp旧表
118
-                Db::name("user")->where("uid",$new_user_id)->save(['user_level_id_old'=>$user_level]);//2.0新表
115
+                Db::name("old_user_jbp")->where("id", $new_user_id)->save(['user_level_id' => $user_level]);//1.0jbp旧表
116
+                Db::name("user")->where("uid", $new_user_id)->save(['user_level_id_old' => $user_level]);//2.0新表
119 117
 
120 118
                 // todo 同时改变他的权益
121 119
             }
122 120
 
123 121
 
124
-
125 122
             // Db::name("old_user_jbp")->where("id",$new_user_id)->inc("withdraw_quota",$zs_withdraw_quota)->save();//1.0jbp旧表
126 123
             // Db::name("user")->where("uid",$new_user_id)->save(['withdraw_quota_old'=>$zs_withdraw_quota]);//2.0新表
127 124
 
@@ -135,55 +132,54 @@ class Taskorderlianc extends BaseController
135 132
 
136 133
 
137 134
             //检查是不是订单价格是1180或者11800,更改VR
138
-            if($goods_of_info['money'] == 1180 || $goods_of_info['money'] == 11800 || $goods_of_info['money'] == 3540 || $goods_of_info['money'] == 10620 || $goods_of_info['money'] == 9440  || $goods_of_info['money'] == 2360){
135
+            if ($goods_of_info['money'] == 1180 || $goods_of_info['money'] == 11800 || $goods_of_info['money'] == 3540 || $goods_of_info['money'] == 10620 || $goods_of_info['money'] == 9440 || $goods_of_info['money'] == 2360) {
139 136
                 //修改订单到账状态
140 137
 
141 138
 
142
-                Db::name("old_user_of_goods")->where("order_id",$goods_of_info1['id'])->save(['status'=>1,'pay_gb'=>0,'pay_vr'=>$pay_vr1,'pay_bt'=>0,'create_time'=>time()]);
139
+                Db::name("old_user_of_goods")->where("order_id", $goods_of_info1['id'])->save(['status' => 1, 'pay_gb' => 0, 'pay_vr' => $pay_vr1, 'pay_bt' => 0, 'create_time' => time()]);
143 140
 
144 141
 
145 142
             }
146 143
         }
147 144
 
148 145
 
149
-
150
-        if($result) {
146
+        if ($result) {
151 147
             //更改订单状态
152 148
 
153 149
             Db::commit();
154
-            $new_user_name = Db::name("old_user_jbp")->where("id",$new_user_id)->value("user_name");
150
+            $new_user_name = Db::name("old_user_jbp")->where("id", $new_user_id)->value("user_name");
155 151
             $new_user_name = empty($new_user_name) ? "" : $new_user_name;
156 152
 
157 153
             //记录日志信息
158 154
 
159
-            if($user_id == $invite_id) {
155
+            if ($user_id == $invite_id) {
160 156
                 //报单中心=推荐人 GB记录日志有问题需要传入指定参数去计算
161 157
                 //$money = Db::name("old_user_jbp")->where("id",$user_id)->value("gb");
162 158
                 //$appoint_money = $money - $zs_invite_gb;
163 159
 
164
-                if($goods_of_info['money'] == 1180 || $goods_of_info['money'] == 11800 || $goods_of_info['money'] == 3540 || $goods_of_info['money'] == 10620 || $goods_of_info['money'] == 9440  || $goods_of_info['money'] == 2360){
160
+                if ($goods_of_info['money'] == 1180 || $goods_of_info['money'] == 11800 || $goods_of_info['money'] == 3540 || $goods_of_info['money'] == 10620 || $goods_of_info['money'] == 9440 || $goods_of_info['money'] == 2360) {
165 161
 
166 162
 
167
-                    $this->change_user_log66($user_id,"vr",2,$pay_vr1,"declare_expend",'权益消费VR-'.$new_user_name);
163
+                    $this->change_user_log66($user_id, "vr", 2, $pay_vr1, "declare_expend", '权益消费VR-' . $new_user_name);
168 164
 
169 165
                 }
170
-            }else{
166
+            } else {
171 167
 
172
-                if($goods_of_info['money'] == 1180 || $goods_of_info['money'] == 11800 || $goods_of_info['money'] == 3540 || $goods_of_info['money'] == 10620 || $goods_of_info['money'] == 9440  || $goods_of_info['money'] == 2360){
168
+                if ($goods_of_info['money'] == 1180 || $goods_of_info['money'] == 11800 || $goods_of_info['money'] == 3540 || $goods_of_info['money'] == 10620 || $goods_of_info['money'] == 9440 || $goods_of_info['money'] == 2360) {
173 169
 
174 170
 
175
-                    $this->change_user_log66($user_id,"vr",2,$pay_vr1,"declare_expend",'权益消费VR-'.$new_user_name);
171
+                    $this->change_user_log66($user_id, "vr", 2, $pay_vr1, "declare_expend", '权益消费VR-' . $new_user_name);
176 172
 
177 173
                 }
178 174
             }
179 175
             // $this->change_user_log66($new_user_id,'gb',1,$zs_gb,"levle_update_zs","权益升级达标赠送");
180
-            $this->change_user_log66($new_user_id,'withdraw_quota_old',1,$zs_withdraw_quota,"levle_update_zs","权益升级达标赠送");
176
+            $this->change_user_log66($new_user_id, 'withdraw_quota_old', 1, $zs_withdraw_quota, "levle_update_zs", "权益升级达标赠送");
181 177
             // $this->change_user_log66($invite_id,'gb',1,$zs_invite_gb,"levle_update_zs","邀请-".$new_user_name);
182 178
             // echo 123;return;
183 179
             //处理查看是否有待发放佣金
184 180
             // $zs_withdraw_quota
185
-            Db::name("old_user_jbp")->where("id",$new_user_id)->inc("total_withdraw_quota",$zs_withdraw_quota)->save();//1.0jbp旧表
186
-            Db::name("user")->where("uid",$new_user_id)->inc("total_withdraw_quota_old",$zs_withdraw_quota)->save();
181
+            Db::name("old_user_jbp")->where("id", $new_user_id)->inc("total_withdraw_quota", $zs_withdraw_quota)->save();//1.0jbp旧表
182
+            Db::name("user")->where("uid", $new_user_id)->inc("total_withdraw_quota_old", $zs_withdraw_quota)->save();
187 183
             // $this->releaseTobeAmount($new_user_id,$zs_withdraw_quota);
188 184
             // $this->success("支付成功",['is_cash'=>0]);
189 185
         }
@@ -191,34 +187,34 @@ class Taskorderlianc extends BaseController
191 187
         // $this->error("操作失败");
192 188
     }
193 189
 
194
-    function change_user_log66($user_id,$type,$change_status,$money,$routine,$remark="",$is_admin=1,$appoint_money = 0)
190
+    function change_user_log66($user_id, $type, $change_status, $money, $routine, $remark = "", $is_admin = 1, $appoint_money = 0)
195 191
     {
196 192
         $transition = [
197
-            'pv'=>1,
198
-            "gb"=>2,
199
-            "df"=>3,
200
-            "vr"=>4,
201
-            "bt"=>5,
202
-            "withdraw_quota_old"=>6,
203
-            "unsettled_pension"=>7,
204
-            "amount_old"=>8
193
+            'pv' => 1,
194
+            "gb" => 2,
195
+            "df" => 3,
196
+            "vr" => 4,
197
+            "bt" => 5,
198
+            "withdraw_quota_old" => 6,
199
+            "unsettled_pension" => 7,
200
+            "amount_old" => 8
205 201
         ];
206
-        $routineInfo = Db::name("old_routine_log_of_key")->where("key",$routine)->find();
207
-        if(empty($routineInfo)) {
202
+        $routineInfo = Db::name("old_routine_log_of_key")->where("key", $routine)->find();
203
+        if (empty($routineInfo)) {
208 204
             return false;
209 205
         }
210 206
         $key_id = isset($routineInfo['id']) ? $routineInfo['id'] : 0;
211 207
         //再去查询变更前的 金额
212
-        if($appoint_money > 0) {
208
+        if ($appoint_money > 0) {
213 209
             $alter_money = $appoint_money;
214
-        }else{
210
+        } else {
215 211
             //再去查询变更前的 金额
216
-            $alter_money = Db::name("user")->where('uid',$user_id)->value($type);
212
+            $alter_money = Db::name("user")->where('uid', $user_id)->value($type);
217 213
         }
218
-        if($change_status == 1) {
214
+        if ($change_status == 1) {
219 215
             //新增前
220
-            $alter_money = $alter_money-$money;
221
-        }else if($change_status == 2){
216
+            $alter_money = $alter_money - $money;
217
+        } else if ($change_status == 2) {
222 218
             //减少前
223 219
             $alter_money = $alter_money + $money;
224 220
         }
@@ -231,46 +227,47 @@ class Taskorderlianc extends BaseController
231 227
         $inser_data['remark'] = $remark;
232 228
         $inser_data['is_admin'] = $is_admin;
233 229
         $inser_data['create_time'] = time();
234
-        $inser_data['alter_money'] =  isset($alter_money) ? $alter_money : 0;
230
+        $inser_data['alter_money'] = isset($alter_money) ? $alter_money : 0;
235 231
         Db::name("old_user_log")->insert($inser_data);
236 232
     }
237 233
 
238 234
     //添加推广佣金/养老金日志(养老金金额)
239
-    public function bill_user_log($uid,$name,$num,$mark){
235
+    public function bill_user_log($uid, $name, $num, $mark)
236
+    {
240 237
 
241
-        $con_data = Db::name('user')->where("uid",$uid)->find();
238
+        $con_data = Db::name('user')->where("uid", $uid)->find();
242 239
         //如果是会员专区就即刻到账
243 240
 
244
-        Db::name('user')->where("uid",$con_data['uid'])->update(['brokerage_price'=> $con_data['brokerage_price'] + $num]);
241
+        Db::name('user')->where("uid", $con_data['uid'])->update(['brokerage_price' => $con_data['brokerage_price'] + $num]);
245 242
 
246 243
 
247 244
         $bill = [
248
-            'uid'=>$uid,
249
-            'link_id'=>0,//关联订单id
250
-            'pm'=>1,//0:支出,1:获得
251
-            'title'=>$name,//账单标题
252
-            'category'=>'now_money',//明细种类
253
-            'type'=>'commission',//明细类型
254
-            'number'=>$num,//明细数字
255
-            'balance'=>0,//剩余
256
-            'mark'=>$mark,//备注
257
-            'create_time'=>date('Y-m-d H:i:s'),//添加时间
258
-            'status'=>1,//0待确定,1有效,-1无效
259
-            'commission_type'=>8,//佣金类型 1代理费 2 消费佣金 3直推奖√ 4辖区佣金\r\n5 养老金√ 6 广告费
245
+            'uid' => $uid,
246
+            'link_id' => 0,//关联订单id
247
+            'pm' => 1,//0:支出,1:获得
248
+            'title' => $name,//账单标题
249
+            'category' => 'now_money',//明细种类
250
+            'type' => 'commission',//明细类型
251
+            'number' => $num,//明细数字
252
+            'balance' => 0,//剩余
253
+            'mark' => $mark,//备注
254
+            'create_time' => date('Y-m-d H:i:s'),//添加时间
255
+            'status' => 1,//0待确定,1有效,-1无效
256
+            'commission_type' => 8,//佣金类型 1代理费 2 消费佣金 3直推奖√ 4辖区佣金\r\n5 养老金√ 6 广告费
260 257
             //7 跨店奖励√ 8平台奖励 9渠道商\r\n10 推荐创客收益√ 11分红奖金√ 12代理区域收益√ 13消费循环佣金
261 258
             //14-推荐代理收益√ 15邀请小区团长升级√ 16大v分享奖√ 17创客合伙人√ 18积分奖励√ 19创客补贴√’
262
-            'order_sn'=>0,//订单号
263
-            'tripartite'=>0,//
264
-            'type_shop'=>0,//0平台1多多进宝2唯品会3苏宁易购4网易考拉5淘宝客6京东联盟7饿了么8线上
265
-            'mer_id'=>0,//商户id
266
-            'source'=>0,//1线下 0线上
267
-            'order_type'=>1,//1自营  2 第三方  订单类型
268
-            'is_red_brokerage'=>0,//1红积分对冲佣金 0正常佣金
269
-            'gzc'=>3,//养老金是否已进入公证处log表0:未进入。1:已进入
270
-            'take_time'=>'',//结算时间
271
-            'district_id'=>'',//
272
-            'street_id'=>'',//
273
-            'month'=>'',//月份
259
+            'order_sn' => 0,//订单号
260
+            'tripartite' => 0,//
261
+            'type_shop' => 0,//0平台1多多进宝2唯品会3苏宁易购4网易考拉5淘宝客6京东联盟7饿了么8线上
262
+            'mer_id' => 0,//商户id
263
+            'source' => 0,//1线下 0线上
264
+            'order_type' => 1,//1自营  2 第三方  订单类型
265
+            'is_red_brokerage' => 0,//1红积分对冲佣金 0正常佣金
266
+            'gzc' => 3,//养老金是否已进入公证处log表0:未进入。1:已进入
267
+            'take_time' => '',//结算时间
268
+            'district_id' => '',//
269
+            'street_id' => '',//
270
+            'month' => '',//月份
274 271
 
275 272
 
276 273
         ];
@@ -279,77 +276,192 @@ class Taskorderlianc extends BaseController
279 276
     }
280 277
 
281 278
 
279
+    public function lst2()
280
+    {
281
+
282 282
 
283
+        $week_record = 10500 + 50000; //20250310
283 284
 
284
-    public function lst2(){
285
+        // 查询测试人员账号信息
286
+        //18973958920
287
+        //15186694339
288
+        //18833633835
289
+        //19525470098
290
+        //17756507016
291
+        //18226705337
292
+        $testAccount = ['18973958920', '15186694339', '18833633835', '19525470098', '17756507016', '18226705337'];
293
+        $removeUserList = Db::name("user")
294
+            ->whereIn('account', $testAccount)
295
+            ->where("status", "<>", 0)
296
+            ->where('is_del', '<>', 1)
297
+            ->select()
298
+            ->toArray();
299
+        $removeUserIdList = array_column($removeUserList, 'uid');
300
+        // 定义分红金额
301
+        $week_record = $this->getTeamPvByTime('last_week', $removeUserIdList);
302
+        // 分红金额 - 红包金额
303
+        $redEnvelope = $this->getRedEnvelopeByTime('last_week', $removeUserIdList);
285 304
 
305
+        $week_record -= $redEnvelope;
286 306
 
287 307
 
308
+        $originator_award = round(($week_record * 0.05), 2);
288 309
 
310
+        $list = Db::name("user")->where("originator_id_old", ">", 0)->where("status", 1)->field("uid,originator_id_old")->select()->toArray();
289 311
 
312
+        // foreach($list as $k=>$v){
313
+        //     var_dump($v);
314
+        // }
290 315
 
316
+        // return;
291 317
 
292
-    }
318
+        $sum_money = Db::name("old_user_lianc")->sum("number");
319
+
320
+        $lianc_list = Db::name("old_user_lianc")->order("id desc")->field("id,number,title")->select()->toArray();
321
+        $user_arr = [];
322
+
323
+        $lianc_list_arr = [];
324
+        foreach ($lianc_list as $key => $value) {
325
+            # code...
326
+            $lianc_list_arr[$value['id']] = $value;
327
+        }
293 328
 
294
-        //添加复购金
295
-        public function fugou_user_log($uid,$num,$order_id,$type_inc_des,$status=-1){
296
-
297
-            $fugou_data = Db::name('user')->where("uid",$uid)->find();
298
-           
299
-    
300
-            $bill = [
301
-                'uid'=>$uid,
302
-                'number'=>$num,//数量
303
-                'status'=>$status,//复购金状态1-有效 0-失效 -1待确认
304
-                'mark'=>"复购金",//备注
305
-                'desc'=>"10%作为复购金",//描述
306
-                'order_id'=>$order_id,//订单id
307
-                'surplus'=>0,//剩余
308
-                'order_type'=>11,//关联订单ID
309
-                'type'=>$type_inc_des,//复购金类型 :1赠送,2消耗
310
-                'settlement_time'=>date('Y-m-d H:i:s'),//添加时间,
311
-                'addtime'=>time(),
312
-            ];
313
-    
314
-            Db::name('user_sign_fugou')->insert($bill);
329
+        foreach ($list as $key => $value) {
330
+            # code...
331
+            $user_arr[$value['originator_id_old']]['people'][] = $value['uid'];
332
+            $user_arr[$value['originator_id_old']]['money'] = $lianc_list_arr[$value['originator_id_old']]['number'];
333
+            $user_arr[$value['originator_id_old']]['title'] = $lianc_list_arr[$value['originator_id_old']]['title'];
334
+            $user_arr[$value['originator_id_old']]['id'] = $lianc_list_arr[$value['originator_id_old']]['id'];
315 335
         }
316 336
 
337
+
338
+        //处理计算权重 和平均分配的金额
339
+        $total_num = 0;
340
+        $count_num = 0;
341
+        foreach ($user_arr as $key => $value) {
342
+            # code...
343
+            $total_num += round($value['money'] * count($value['people']) / 1000, 2);
344
+            $count_num += count($value['people']);
345
+        }
346
+        foreach ($user_arr as $key => $value) {
347
+            # code...
348
+            $rate = round((count($value['people']) * $value['money']) / $total_num, 2) / 1000;
349
+            $user_arr[$key]['rate'] = $rate;
350
+            $distribution_money = round($originator_award * $rate, 2);
351
+            $user_arr[$key]['distribution_money'] = $distribution_money;
352
+            $user_arr[$key]['people_award'] = round($distribution_money / count($value['people']), 2);//可分配佣金
353
+        }
354
+
355
+        $count = 0;
356
+        foreach ($user_arr as $key => $value) {
357
+            $distribution_money = $value['distribution_money'];
358
+            # code...
359
+            foreach ($value['people'] as $k => $v) {
360
+                # code...
361
+                $award = $value['people_award'];
362
+
363
+                //90给佣金,10给复购金
364
+                $yj_90 = $award * 0.9;
365
+                $fg_10 = $award * 0.1;
366
+
367
+                Db::name("user")->where("uid", $v)->inc("brokerage_price", $yj_90)->save();
368
+                $res = Db::name("user")->where("uid", $v)->inc("total_amount_old", $yj_90)->save();
369
+                Db::name("user")->where("uid", $v)->inc("amount_old", $yj_90)->save();//不用冻结金额和提现额度来限制佣金发放
370
+                $res3 = Db::name("user")->where("uid", $v)->inc("fugou", $fg_10)->save();
371
+
372
+                $res = true;
373
+                if ($res) {
374
+                    $$count = $count + 1;
375
+                    $this->change_user_log($v, 'amount_old', 1, $yj_90, "relation_profits", "联创分红入账" . "-" . $value['title']);
376
+                    //入账
377
+                    $week_data = [];
378
+                    $week_data['user_id'] = $v;
379
+                    $week_data['user_lianc_id'] = $value['id'];
380
+                    $week_data['money'] = $yj_90;
381
+                    $week_data['remark'] = "联创分红入账主动执行" . $yj_90;
382
+                    $week_data['all_record'] = $originator_award;
383
+                    $week_data['all_amount'] = $distribution_money;
384
+                    $week_data['create_time'] = time();
385
+                    Db::name("old_user_originator")->insert($week_data);
386
+
387
+                    $userdatassss = db::name("user")->where("uid", $v)->find();
388
+                    $datas_log = [
389
+                        'note' => "名称:" . $userdatassss['nickname'] . " 用户:" . $v . " 新增联创佣金:" . $yj_90,
390
+                        'create_time' => date('Y-m-d H:i:s')
391
+                    ];
392
+                    Db::name('test_log')->insert($datas_log);   //数据存到2.0数据表中
393
+                    $this->bill_user_log111111($v, "联创分佣", $yj_90, "联创明细入账", 12);//股权分佣明细2.0系统
394
+
395
+                    $this->fugou_user_log($v, $fg_10, 16, 1, 1);//复购金明细入账
396
+
397
+                } else {
398
+                    // ..
399
+                }
400
+            }
401
+        }
402
+    }
403
+
404
+    //添加复购金
405
+    public function fugou_user_log($uid, $num, $order_id, $type_inc_des, $status = -1)
406
+    {
407
+
408
+        $fugou_data = Db::name('user')->where("uid", $uid)->find();
409
+
410
+
411
+        $bill = [
412
+            'uid' => $uid,
413
+            'number' => $num,//数量
414
+            'status' => $status,//复购金状态1-有效 0-失效 -1待确认
415
+            'mark' => "复购金",//备注
416
+            'desc' => "10%作为复购金",//描述
417
+            'order_id' => $order_id,//订单id
418
+            'surplus' => 0,//剩余
419
+            'order_type' => 11,//关联订单ID
420
+            'type' => $type_inc_des,//复购金类型 :1赠送,2消耗
421
+            'settlement_time' => date('Y-m-d H:i:s'),//添加时间,
422
+            'addtime' => time(),
423
+        ];
424
+
425
+        Db::name('user_sign_fugou')->insert($bill);
426
+    }
427
+
317 428
     //添加平台分佣2.0系统收益明细日志(养老金金额)
318
-    public function bill_user_log111111($uid,$name,$num,$mark,$comm){
429
+    public function bill_user_log111111($uid, $name, $num, $mark, $comm)
430
+    {
319 431
 
320
-        $con_data = Db::name('user')->where("uid",$uid)->find();
432
+        $con_data = Db::name('user')->where("uid", $uid)->find();
321 433
         //如果是会员专区就即刻到账
322 434
 
323 435
         // Db::name('user')->where("uid",$con_data['uid'])->update(['brokerage_price'=> $con_data['brokerage_price'] + $num]);
324 436
 
325 437
 
326 438
         $bill = [
327
-            'uid'=>$uid,
328
-            'link_id'=>0,//关联订单id
329
-            'pm'=>1,//0:支出,1:获得
330
-            'title'=>$name,//账单标题
331
-            'category'=>'now_money',//明细种类
332
-            'type'=>'commission',//明细类型
333
-            'number'=>$num,//明细数字
334
-            'balance'=>0,//剩余
335
-            'mark'=>$mark,//备注
336
-            'create_time'=>date('Y-m-d H:i:s'),//添加时间
337
-            'status'=>1,//0待确定,1有效,-1无效
338
-            'commission_type'=>$comm,//佣金类型 1代理费 2 消费佣金 3直推奖√ 4辖区佣金\r\n5 养老金√ 6 广告费
439
+            'uid' => $uid,
440
+            'link_id' => 0,//关联订单id
441
+            'pm' => 1,//0:支出,1:获得
442
+            'title' => $name,//账单标题
443
+            'category' => 'now_money',//明细种类
444
+            'type' => 'commission',//明细类型
445
+            'number' => $num,//明细数字
446
+            'balance' => 0,//剩余
447
+            'mark' => $mark,//备注
448
+            'create_time' => date('Y-m-d H:i:s'),//添加时间
449
+            'status' => 1,//0待确定,1有效,-1无效
450
+            'commission_type' => $comm,//佣金类型 1代理费 2 消费佣金 3直推奖√ 4辖区佣金\r\n5 养老金√ 6 广告费
339 451
             //7 跨店奖励√ 8平台奖励 9渠道商\r\n10 推荐创客收益√ 11分红奖金√ 12代理区域收益√ 13消费循环佣金
340 452
             //14-推荐代理收益√ 15邀请小区团长升级√ 16大v分享奖√ 17创客合伙人√ 18积分奖励√ 19创客补贴√’
341
-            'order_sn'=>0,//订单号
342
-            'tripartite'=>0,//
343
-            'type_shop'=>0,//0平台1多多进宝2唯品会3苏宁易购4网易考拉5淘宝客6京东联盟7饿了么8线上
344
-            'mer_id'=>0,//商户id
345
-            'source'=>0,//1线下 0线上
346
-            'order_type'=>1,//1自营  2 第三方  订单类型
347
-            'is_red_brokerage'=>0,//1红积分对冲佣金 0正常佣金
348
-            'gzc'=>3,//养老金是否已进入公证处log表0:未进入。1:已进入
349
-            'take_time'=>'',//结算时间
350
-            'district_id'=>'',//
351
-            'street_id'=>'',//
352
-            'month'=>'',//月份
453
+            'order_sn' => 0,//订单号
454
+            'tripartite' => 0,//
455
+            'type_shop' => 0,//0平台1多多进宝2唯品会3苏宁易购4网易考拉5淘宝客6京东联盟7饿了么8线上
456
+            'mer_id' => 0,//商户id
457
+            'source' => 0,//1线下 0线上
458
+            'order_type' => 1,//1自营  2 第三方  订单类型
459
+            'is_red_brokerage' => 0,//1红积分对冲佣金 0正常佣金
460
+            'gzc' => 3,//养老金是否已进入公证处log表0:未进入。1:已进入
461
+            'take_time' => '',//结算时间
462
+            'district_id' => '',//
463
+            'street_id' => '',//
464
+            'month' => '',//月份
353 465
 
354 466
 
355 467
         ];
@@ -392,39 +504,39 @@ class Taskorderlianc extends BaseController
392 504
     // }
393 505
 
394 506
 
395
-    public function change_user_log($user_id,$type,$change_status,$money,$routine,$remark="",$is_admin=1,$appoint_money = 0)
507
+    public function change_user_log($user_id, $type, $change_status, $money, $routine, $remark = "", $is_admin = 1, $appoint_money = 0)
396 508
     {
397 509
         $transition = [
398
-            'pv'=>1,
399
-            "gb"=>2,
400
-            "df"=>3,
401
-            "vr"=>4,
402
-            "bt"=>5,
403
-            "withdraw_quota"=>6,
404
-            "unsettled_pension"=>7,
405
-            "amount_old"=>8
510
+            'pv' => 1,
511
+            "gb" => 2,
512
+            "df" => 3,
513
+            "vr" => 4,
514
+            "bt" => 5,
515
+            "withdraw_quota" => 6,
516
+            "unsettled_pension" => 7,
517
+            "amount_old" => 8
406 518
         ];
407
-        $routineInfo = Db::name("old_routine_log_of_key")->where("key",$routine)->find();
408
-        if(empty($routineInfo)) {
519
+        $routineInfo = Db::name("old_routine_log_of_key")->where("key", $routine)->find();
520
+        if (empty($routineInfo)) {
409 521
             return false;
410 522
         }
411 523
         $key_id = isset($routineInfo['id']) ? $routineInfo['id'] : 0;
412 524
 
413
-        if($appoint_money > 0) {
525
+        if ($appoint_money > 0) {
414 526
             $alter_money = $appoint_money;
415
-        }else{
527
+        } else {
416 528
             //再去查询变更前的 金额
417
-            $alter_money = Db::name("user")->where('uid',$user_id)->value($type);
529
+            $alter_money = Db::name("user")->where('uid', $user_id)->value($type);
418 530
         }
419
-        if($change_status == 1) {
531
+        if ($change_status == 1) {
420 532
             //新增前
421
-            $alter_money = $alter_money-$money;
422
-        }else if($change_status == 2){
533
+            $alter_money = $alter_money - $money;
534
+        } else if ($change_status == 2) {
423 535
             //减少前
424 536
             $alter_money = $alter_money + $money;
425 537
         }
426
-        if($alter_money < 0) {
427
-            $alter_money =0;
538
+        if ($alter_money < 0) {
539
+            $alter_money = 0;
428 540
         }
429 541
         $inser_data = [];
430 542
         $inser_data['user_id'] = $user_id;
@@ -440,60 +552,125 @@ class Taskorderlianc extends BaseController
440 552
     }
441 553
 
442 554
 
443
-
444 555
     /**
445 556
      * 释放待发放佣金
446 557
      */
447
-    public function releaseTobeAmount($user_id,$amount,$output)
558
+    public function releaseTobeAmount($user_id, $amount, $output)
448 559
     {
449 560
         $userInfo = Db::name("user")->find($user_id);
450
-        if(empty($userInfo)) {
561
+        if (empty($userInfo)) {
451 562
             return false;
452 563
         }
453 564
         $withdraw_quota = empty($userInfo['withdraw_quota_old']) ? 0 : $userInfo['withdraw_quota_old'];
454 565
         $old_amount = empty($userInfo['tobe_amount_old']) ? 0 : $userInfo['tobe_amount_old'];
455
-        Db::name("user")->where("uid",$user_id)->save(['tobe_amount_old'=>0]);
566
+        Db::name("user")->where("uid", $user_id)->save(['tobe_amount_old' => 0]);
456 567
         $amount += $old_amount;
457 568
         $inc_amount = 0;
458 569
         $inc_tobe_amount = 0;
459 570
         $dec_withdraw_quota = 0;
460 571
 
461
-        if(($amount - $withdraw_quota) > 0) {
572
+        if (($amount - $withdraw_quota) > 0) {
462 573
             $diff_money = $amount - $withdraw_quota;
463 574
             $inc_amount = $withdraw_quota;
464 575
             $dec_withdraw_quota = $withdraw_quota;
465 576
             $inc_tobe_amount = $diff_money;
466
-        }elseif(($amount - $withdraw_quota)==0){
577
+        } elseif (($amount - $withdraw_quota) == 0) {
467 578
             $inc_amount = $withdraw_quota;
468 579
             $dec_withdraw_quota = $withdraw_quota;
469
-        }else {
580
+        } else {
470 581
             // <0的情况
471 582
             $diff_money = $withdraw_quota - $amount;
472 583
             $inc_amount = $amount;
473 584
             $dec_withdraw_quota = $amount;
474 585
         }
475
-        if($inc_tobe_amount != 0 ) {
586
+        if ($inc_tobe_amount != 0) {
476 587
 
477
-            $res = Db::name("user")->where("uid",$user_id)->inc("tobe_amount_old",$inc_tobe_amount)->fetchSql()->inc("amount",$inc_amount)->dec("withdraw_quota_old",$dec_withdraw_quota)->save();
588
+            $res = Db::name("user")->where("uid", $user_id)->inc("tobe_amount_old", $inc_tobe_amount)->fetchSql()->inc("amount", $inc_amount)->dec("withdraw_quota_old", $dec_withdraw_quota)->save();
478 589
 
479 590
 
480
-
481
-        }else {
482
-            $res = Db::name("user")->where("uid",$user_id)->inc("amount_old",$inc_amount)->fetchSql()->dec("withdraw_quota_old",$dec_withdraw_quota)->save();
591
+        } else {
592
+            $res = Db::name("user")->where("uid", $user_id)->inc("amount_old", $inc_amount)->fetchSql()->dec("withdraw_quota_old", $dec_withdraw_quota)->save();
483 593
 
484 594
         }
485 595
         //记录日志 提现额度消费
486
-        if($dec_withdraw_quota > 0) {
487
-            $this->change_user_log($user_id,'withdraw_quota',2,$dec_withdraw_quota,"conversion_tobe_amount","佣金额度兑换佣金");
596
+        if ($dec_withdraw_quota > 0) {
597
+            $this->change_user_log($user_id, 'withdraw_quota', 2, $dec_withdraw_quota, "conversion_tobe_amount", "佣金额度兑换佣金");
488 598
         }
489 599
     }
490 600
 
601
+    public function getTime($timePeriod)
602
+    {
603
+        // 定义时间区间
604
+        $now = time();
605
+        $startTime = '';
606
+        $endTime = '';
607
+        if ($timePeriod == 'last_week') {
608
+            // 上周的时间区间
609
+            $startTime = date('Y-m-d', strtotime('monday last week', $now)); // 上周星期一的开始时间
610
+            $endTime = date('Y-m-d', strtotime('sunday last week', $now)); // 上周星期日的结束时间
611
+        } elseif ($timePeriod == 'this_week') {
612
+            // 这周的时间区间
613
+            $startTime = date('Y-m-d', strtotime('monday this week', $now)); // 这周星期一的开始时间
614
+            $endTime = date('Y-m-d', strtotime('sunday this week', $now)); // 这周星期日的结束时间
615
+        }
616
+        //        return ['startTime' => '2025-03-10', 'endTime' => '2025-03-23'];
617
+        return ['startTime' => $startTime, 'endTime' => $endTime];
618
+    }
491 619
 
620
+    public function getTeamPvByTime($timePeriod = 'last_week', $removeUserIdList = [])
621
+    {
622
+        $timeMap = $this->getTime($timePeriod);
623
+        $startTime = $timeMap['startTime'];
624
+        $endTime = $timeMap['endTime'];
625
+
626
+        // 查询指定时间区间内的所有订单,并排除 pay_time 为 NULL 的订单
627
+        $orders = Db::name("store_order")
628
+            ->where('mer_id', 496)
629
+            ->whereNotIn('uid', $removeUserIdList)
630
+            ->whereIn('status', [0, 1, 2, 3])
631
+            ->whereIn("total_price", [1180, 11800, 10620, 2360, 9440])
632
+            ->whereBetween("pay_time", [$startTime . ' 00:00:00', $endTime . ' 23:59:59'])
633
+            ->whereNotNull("pay_time") // 排除 pay_time 为 NULL 的订单
634
+            ->select();
635
+
636
+        // 计算总业绩
637
+        $totalPv = 0;
638
+        foreach ($orders as $order) {
639
+            switch ($order['total_price']) {
640
+                case 1180:
641
+                    $totalPv += 700;
642
+                    break;
643
+                case 11800:
644
+                    $totalPv += 7000;
645
+                    break;
646
+                case 10620:
647
+                    $totalPv += 6300;
648
+                    break;
649
+                case 2360:
650
+                    $totalPv += 1400;
651
+                    break;
652
+                case 9440:
653
+                    $totalPv += 5600;
654
+                    break;
655
+            }
656
+        }
492 657
 
658
+        return $totalPv;
659
+    }
493 660
 
494
-
495
-
496
-
497
-
498
-
661
+    public function getRedEnvelopeByTime($timePeriod = 'last_week', $removeUserIdList = [])
662
+    {
663
+        $timeMap = $this->getTime($timePeriod);
664
+        $startTime = $timeMap['startTime'];
665
+        $endTime = $timeMap['endTime'];
666
+
667
+        // 查询指定时间区间内的所有订单,并排除 pay_time 为 NULL 的订单
668
+        $redEnvelopeList = Db::name("user_sign_hongbao")
669
+            ->whereNotIn('uid', $removeUserIdList)
670
+            ->where('status', 1)
671
+            ->whereBetween("settlement_time", [$startTime . ' 00:00:00', $endTime . ' 23:59:59'])
672
+            ->select()
673
+            ->toArray();
674
+        return floor(array_sum(array_column($redEnvelopeList, 'number')) * 100) / 100;
675
+    }
499 676
 }

+ 4 - 2
app/controller/api/store/product/Su.php

@@ -26,8 +26,10 @@ class Su extends BaseController
26 26
     {
27 27
 
28 28
         parent::__construct($app);
29
-        $this->appKey = '8349fdf89e7c46ff8ba28752093dfd09';
30
-        $this->secretKey = '7c386c01da509065febddde9f87d4821';
29
+//        $this->appKey = '8349fdf89e7c46ff8ba28752093dfd09';
30
+//        $this->secretKey = '7c386c01da509065febddde9f87d4821';
31
+        $this->appKey = '7031e4de1179b326a904b9c2eec68eb1';
32
+        $this->secretKey = 'bf0c498b244aaca811c19742602c2d4d';
31 33
         $this->channel = '';
32 34
         $this->userThird = app()->make(UserThirdRepository::class);
33 35
     }

+ 3 - 3
app/controller/api/user/User.php

@@ -219,10 +219,10 @@ class User extends BaseController
219 219
 
220 220
         if ($pm==0){
221 221
 
222
-            $data = DB::name('user_sign_hongbao')->where($where)->where('type', 1)->field('id,mark,number,type,addtime,order_id')->page($page, $limit)->order("id desc")->select();
222
+            $data = DB::name('user_sign_hongbao')->where($where)->where(['type' => 1,'status' => 1])->field('id,mark,number,type,addtime,order_id')->page($page, $limit)->order("id desc")->select();
223 223
         }
224 224
         if($pm==1){
225
-            $data = DB::name('user_sign_hongbao')->where($where)->where('type', 2)->field('id,mark,number,type,addtime,order_id')->page($page, $limit)->order("id desc")->select();
225
+            $data = DB::name('user_sign_hongbao')->where($where)->where(['type' => 2,'status' => 1])->field('id,mark,number,type,addtime,order_id')->page($page, $limit)->order("id desc")->select();
226 226
 
227 227
         }
228 228
         if($pm==2){
@@ -1580,7 +1580,7 @@ class User extends BaseController
1580 1580
         $common_list = [];//小部门数据
1581 1581
         if(count($child_nums_Tree) && isset($child_nums_Tree[0]['children']) && count($child_nums_Tree[0]['children'])){
1582 1582
             //获取大部门的key
1583
-            $maxBalanceIndex = array_search(max(array_column($child_nums_Tree[0]['children'], 'total_pv')), array_column($child_nums_Tree, 'total_pv'));
1583
+            $maxBalanceIndex = array_search(max(array_column($child_nums_Tree[0]['children'], 'total_pv')), array_column($child_nums_Tree[0]['children'], 'total_pv'));
1584 1584
             foreach($child_nums_Tree[0]['children'] as $k=>$v){
1585 1585
                 if($k == $maxBalanceIndex){
1586 1586
                     $person_list[] = [

+ 9 - 4
app/controller/api/user/UserMp.php

@@ -36,8 +36,11 @@ class UserMp extends BaseController
36 36
         //点餐小程序
37 37
         // $this->appid = 'wx10669a2eca032216';
38 38
         // $this->secret = '0e71d5c636fdb9bf1c79c403db70f739';
39
-        $this->appid = 'wx7b4d857deb0447f3';
40
-        $this->secret = '643efbd7f3cd6398df1e7adb441afceb';
39
+//        $this->appid = 'wx7b4d857deb0447f3';
40
+//        $this->secret = '643efbd7f3cd6398df1e7adb441afceb';
41
+
42
+        $this->appid = 'wx9082e5ac2fdb513f';
43
+        $this->secret = 'e334c41e1c4aa962f65d1882092fbda6';
41 44
     }
42 45
 
43 46
     public function getUserUnionid(){
@@ -46,8 +49,10 @@ class UserMp extends BaseController
46 49
         if(!$data['code'] || $data['code'] == '' || $data['code'] =='undefined') {
47 50
             return app('json')->fail("异常操作");
48 51
         }
49
-        $appid = 'wx7b4d857deb0447f3';
50
-        $secret = '643efbd7f3cd6398df1e7adb441afceb';
52
+//        $appid = 'wx7b4d857deb0447f3';
53
+//        $secret = '643efbd7f3cd6398df1e7adb441afceb';
54
+        $appid = 'wx9082e5ac2fdb513f';
55
+        $secret = 'e334c41e1c4aa962f65d1882092fbda6';
51 56
         $url = "https://api.weixin.qq.com/sns/jscode2session?appid=".$appid."&secret=".$secret."&js_code=".$data['code']."&grant_type=authorization_code";
52 57
         $get = curlGet($url);
53 58
         if(!$get){

+ 2 - 0
app/controller/merchant/store/order/RefundOrder.php

@@ -120,6 +120,8 @@ class RefundOrder extends BaseController
120 120
             $data['status'] = $status;
121 121
             $this->repository->agree($id,$data,$this->request->adminId(),1);
122 122
 
123
+            // 取消 订单所发放的福利
124
+            $this->repository->cancelOrderBonus($id);
123 125
         }else{
124 126
             $fail_message = $this->request->param('fail_message','');
125 127
             if($status == -1 && empty($fail_message)){

+ 3 - 1
app/controller/merchant/store/shipping/ShippingTemplate.php

@@ -47,7 +47,9 @@ class ShippingTemplate extends BaseController
47 47
      */
48 48
     public function getList()
49 49
     {
50
-        return app('json')->success($this->repository->getList($this->request->merId()));
50
+//        return app('json')->success($this->repository->getList($this->request->merId()));
51
+        // 目前只包邮
52
+        return app('json')->success($this->repository->getList(0));
51 53
     }
52 54
 
53 55
     /**

+ 1 - 0
cc.txt

@@ -0,0 +1 @@
1
+12

+ 6 - 0
route/admin.php

@@ -86,6 +86,12 @@ Route::group(config('admin.api_admin_prefix') . '/', function () {
86 86
             Route::delete('delete/:id', '/delete')->name('configSettingDelete');
87 87
             Route::post('upload_file/:field', '/upload')->name('configUpload');
88 88
         })->prefix('admin.system.config.Config');
89
+        //用户身份升级配置
90
+        Route::group('config/identity', function () {
91
+            Route::post('update/:id', '/update')->name('configIdentityUpdate');
92
+            Route::get('update/table/:id', '/updateTable')->name('configIdentityUpdateForm');
93
+            Route::get('lst', '/lst')->name('configIdentityLst');
94
+        })->prefix('admin.system.config.Identity');
89 95
 
90 96
         Route::group('config/others', function () {
91 97
             Route::get('lst', 'ConfigOthers/lst')->name('configOthersSettingLst');

+ 4 - 0
route/api.php

@@ -1291,6 +1291,10 @@ Route::group('api/', function () {
1291 1291
     ->middleware(\app\common\middleware\AllowOriginMiddleware::class)
1292 1292
     ->middleware(\app\common\middleware\InstallMiddleware::class)
1293 1293
     ->middleware(\app\common\middleware\CheckSiteOpenMiddleware::class);
1294
+//Route::get('/sxb_test', 'api.store.merchant.TaskPartnerProfits/partnerProfits');
1295
+Route::get('sxb_test', function () {
1296
+    return 'hello,ThinkPHP6!';
1297
+});
1294 1298
 Route::any('/share', function () {
1295 1299
     return view(app()->getRootPath() . 'public/share/register.html');
1296 1300
 });