hrjy 2 vuotta sitten
vanhempi
commit
bd0d217623

+ 46 - 38
app/admin/model/system/SystemUserTask.php

@@ -41,22 +41,22 @@ class SystemUserTask extends BaseModel
      * @var array
      */
     protected static $TaskType = [
-        [
-            'type' => 'SatisfactionIntegral',
-            'name' => '满足积分{$num}',
-            'real_name' => '积分数',
-            'max_number' => 0,
-            'min_number' => 0,
-            'unit' => '分'
-        ],
-        [
-            'type' => 'ConsumptionAmount',
-            'name' => '消费满{$num}',
-            'real_name' => '消费金额',
-            'max_number' => 0,
-            'min_number' => 0,
-            'unit' => '元'
-        ],
+//        [
+//            'type' => 'SatisfactionIntegral',
+//            'name' => '满足积分{$num}',
+//            'real_name' => '积分数',
+//            'max_number' => 0,
+//            'min_number' => 0,
+//            'unit' => '分'
+//        ],
+//        [
+//            'type' => 'ConsumptionAmount',
+//            'name' => '消费满{$num}',
+//            'real_name' => '消费金额',
+//            'max_number' => 0,
+//            'min_number' => 0,
+//            'unit' => '元'
+//        ],
         [
             'type' => 'ConsumptionFrequency',
             'name' => '消费{$num}',
@@ -65,29 +65,37 @@ class SystemUserTask extends BaseModel
             'min_number' => 0,
             'unit' => '次'
         ],
+//        [
+//            'type' => 'CumulativeAttendance',
+//            'name' => '累计签到{$num}',
+//            'real_name' => '累计签到',
+//            'max_number' => 365,
+//            'min_number' => 1,
+//            'unit' => '天'
+//        ],
+//        [
+//            'type' => 'InviteGoodFriends',
+//            'name' => '邀请好友{$num}成为下线',
+//            'real_name' => '邀请好友成为下线',
+//            'max_number' => 1000,
+//            'min_number' => 1,
+//            'unit' => '人'
+//        ],
+//        [
+//            'type' => 'InviteGoodFriendsLevel',
+//            'name' => '邀请好友{$num}成为会员',
+//            'real_name' => '邀请好友成为会员',
+//            'max_number' => 1000,
+//            'min_number' => 1,
+//            'unit' => '人'
+//        ],
         [
-            'type' => 'CumulativeAttendance',
-            'name' => '累计签到{$num}',
-            'real_name' => '累计签到',
-            'max_number' => 365,
-            'min_number' => 1,
-            'unit' => '天'
-        ],
-        [
-            'type' => 'InviteGoodFriends',
-            'name' => '邀请好友{$num}成为下线',
-            'real_name' => '邀请好友成为下线',
-            'max_number' => 1000,
-            'min_number' => 1,
-            'unit' => '人'
-        ],
-        [
-            'type' => 'InviteGoodFriendsLevel',
-            'name' => '邀请好友{$num}成为会员',
-            'real_name' => '邀请好友成为会员',
-            'max_number' => 1000,
-            'min_number' => 1,
-            'unit' => '人'
+            'type' => 'ShareLevel',
+            'name' => '分享单数{$num}',
+            'real_name' => '分享单数',
+            'max_number' => 0,
+            'min_number' => 0,
+            'unit' => '个'
         ],
     ];
 

+ 1 - 1
app/admin/view/index/index.php

@@ -5,7 +5,7 @@
     <meta name="viewport" content="width=device-width, initial-scale=1.0">
     <meta name="renderer" content="webkit">
     <meta http-equiv="Cache-Control" content="no-siteapp" />
-    <title>Liuniu管理系统</title>
+    <title>管理系统</title>
     <!--[if lt IE 9]>
     <meta http-equiv="refresh" content="0;ie.html" />
     <![endif]-->

+ 8 - 8
app/api/controller/AuthController.php

@@ -41,8 +41,8 @@ class AuthController
         if ($user) {
             if ($user->pwd !== md5($request->param('password')))
                 return app('json')->fail('账号或密码错误');
-            if ($user->pwd === md5(123456))
-                return app('json')->fail('请修改您的初始密码,再尝试登陆!');
+//            if ($user->pwd === md5(123456))
+//                return app('json')->fail('请修改您的初始密码,再尝试登陆!');
         } else {
             return app('json')->fail('账号或密码错误');
         }
@@ -197,14 +197,14 @@ class AuthController
             return app('json')->fail($e->getError());
         }
         $verifyCode = CacheService::get('code_' . $account);
-        if (!$verifyCode)
-            return app('json')->fail('请先获取验证码');
-        $verifyCode = substr($verifyCode, 0, 6);
-        if ($verifyCode != $captcha)
-            return app('json')->fail('验证码错误');
+//        if (!$verifyCode)
+//            return app('json')->fail('请先获取验证码');
+//        $verifyCode = substr($verifyCode, 0, 6);
+//        if ($verifyCode != $captcha)
+//            return app('json')->fail('验证码错误');
         if (strlen(trim($password)) < 6 || strlen(trim($password)) > 16)
             return app('json')->fail('密码必须是在6到16位之间');
-        if ($password == '123456') return app('json')->fail('密码太过简单,请输入较为复杂的密码');
+//        if ($password == '123456') return app('json')->fail('密码太过简单,请输入较为复杂的密码');
         $registerStatus = User::register($account, $password, $spread);
         if ($registerStatus) return app('json')->success('注册成功');
         return app('json')->fail(User::getErrorInfo('注册失败'));

+ 90 - 0
app/api/controller/user/UserController.php

@@ -4,6 +4,7 @@ namespace app\api\controller\user;
 
 use app\http\validates\user\AddressValidate;
 use app\models\system\SystemCity;
+use app\models\user\UserSingleAward;
 use app\models\user\UserVisit;
 use think\db\exception\DataNotFoundException;
 use think\db\exception\DbException;
@@ -611,4 +612,93 @@ class UserController
         $puid = $request->post('puid/d', 0);
         return app('json')->success(User::setSpread($puid, $request->uid()));
     }
+
+    /**
+     * 加权奖励
+     * @param Request $request
+     * @return void
+     * @throws DataNotFoundException
+     * @throws DbException
+     * @throws ModelNotFoundException
+     */
+    public function weighting(Request $request)
+    {
+        $start = strtotime('yesterday');
+        $end = strtotime('today');
+        $money = StoreOrder::where('paid', 1)->whereBetweenTime('add_time',  $start, $end)->sum('pay_price'); // 全网业绩
+
+        $partner = sys_config('partner')/100;//合伙人比列
+        $shareholder = sys_config('shareholder')/100;//股东比列
+        $director = sys_config('director')/100;//董事比列
+        $user = User::where('level', '>=', 2)->select()->toArray();
+        if (!empty($user)) {
+            foreach ($user as $vo) {
+                $jl = 0;
+                if ($vo['level'] == 2) {
+                    //合伙人
+                    $jl += $money * $partner;// 合伙人加权奖励
+                    $sp_jl = $money * $partner;// 合伙人上级奖励
+                } elseif ($vo['level'] == 3) {
+                    //股东
+                    $jl += $money * $partner;// 合伙人加权奖励
+                    $jl += $money * $shareholder;// 股东加权奖励
+                } elseif ($vo['level'] == 4) {
+                    //股东
+                    $jl += $money * $partner;// 合伙人加权奖励
+                    $jl += $money * $shareholder;// 股东加权奖励
+                    $jl += $money * $director;// 董事加权奖励
+                }
+                $model = new UserSingleAward();
+                $award = $model->where('uid', $vo['uid'])->where('status', 0)->select()->toArray();
+                if ($award) {
+                    $bdjl = 0; // 爆单剩余奖励
+                    foreach ($award as &$item) {
+                        $surplus = $item['money'] - $item['grant'];
+                        if ($surplus < $jl) {
+                            $bdjl += $surplus;
+                            $jl -= $surplus;
+                            $item['status'] = 1;
+                            $item['grant'] = $item['money'];
+                        } else {
+                            $bdjl += $jl;
+                            $item['grant'] += $jl;
+                        }
+                    }
+                    $model->saveAll($award);
+                    UserBill::income('佣金', $vo['uid'], 'now_money', 'brokerage', $bdjl, '', $vo['brokerage_price'] + $bdjl, '加权佣金奖励');
+                    User::where('uid', $vo['uid'])->inc('brokerage_price', $bdjl)->update();
+
+                    if ($vo['level'] == 2){
+                        // 如果是合伙人
+                        if ($vo['spread_uid']){
+                            $spread = User::where('uid', $vo['spread_uid'])->where('level', '>=', 1)->find();
+                            if ($spread){
+                                $model = new UserSingleAward();
+                                $award = $model->where('uid', $spread['uid'])->where('status', 0)->select()->toArray();
+                                if ($award){
+                                    $bdjl = 0; // 爆单剩余奖励
+                                    foreach ($award as &$item){
+                                        $surplus = $item['money'] - $item['grant'];
+                                        if ($surplus < $sp_jl){
+                                            $bdjl += $surplus;
+                                            $sp_jl -= $surplus;
+                                            $item['status'] = 1;
+                                            $item['grant'] = $item['money'];
+                                        }else{
+                                            $bdjl += $sp_jl;
+                                            $item['grant'] += $sp_jl;
+                                        }
+                                    }
+                                    $model->saveAll($award);
+                                    UserBill::income('佣金', $spread['uid'], 'now_money', 'brokerage', $bdjl, '', $spread['brokerage_price']+$bdjl, '领导奖励');
+                                    User::where('uid', $spread['uid'])->inc('brokerage_price', $bdjl)->update();
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        echo '发放成功';
+    }
 }

+ 44 - 0
app/common.php

@@ -593,4 +593,48 @@ if (!function_exists('do_request')) {
         curl_close($curl);
         return $result;
     }
+
+
+    if (!function_exists('pr')) {
+        function pr($var, $int = '')
+        {
+            $template = PHP_SAPI !== 'cli' ? '<pre>%s</pre>' : "\n%s\n";
+            printf($template, print_r($var, true));
+            if (!empty($int)) {
+                exit($int);
+            }
+
+        }
+    }
+
+    if (!function_exists('getParents')){
+        //获取指定级别的所有上级
+        function getParents($p_id,$array) {
+            $subs=array();
+            foreach($array as $item){
+                if($item['uid'] == $p_id){
+                    $subs[]=$item['uid'];//这里自己看着办,我是获取用户名
+                    $subs=array_merge($subs,getParents($item['spread_uid'],$array));
+                }
+
+            }
+            return $subs;
+        }
+    }
+
+
+    if (!function_exists('getParents')){
+        //获取指定级别的所有上级
+        function getParentsCate($p_id,$array) {
+            $subs=array();
+            foreach($array as $item){
+                if($item['id'] == $p_id){
+                    $subs[]=$item['id'];//这里自己看着办,我是获取用户名
+                    $subs=array_merge($subs,getParents($item['pid'],$array));
+                }
+
+            }
+            return $subs;
+        }
+    }
 }

+ 65 - 1
app/models/store/StoreOrder.php

@@ -18,7 +18,7 @@ use crmeb\traits\ModelTrait;
 use think\facade\Log;
 use app\models\system\SystemStore;
 use app\models\routine\RoutineTemplate;
-use app\models\user\{User, UserAddress, UserBill, UserSpread, WechatUser};
+use app\models\user\{User, UserAddress, UserBill, UserSingleAward, UserSpread, WechatUser};
 use crmeb\services\{
     SystemConfigService, WechatTemplateService, workerman\ChannelService
 };
@@ -316,7 +316,10 @@ class StoreOrder extends BaseModel
             $cartIds = [];
             $totalNum = 0;
             $gainIntegral = 0;
+            $is_explosion_order = 0;
             foreach ($cartInfo as $cart) {
+                $product = StoreProduct::where('id', $cart['product_id'])->find();
+                if (strstr(2,$product['cate_id'])) $is_explosion_order = 1;
                 $cartIds[] = $cart['id'];
                 $totalNum += $cart['cart_num'];
                 if (!$seckill_id) $seckill_id = $cart['seckill_id'];
@@ -450,6 +453,7 @@ class StoreOrder extends BaseModel
                 'add_time' => time(),
                 'unique' => $key,
                 'shipping_type' => $shipping_type,
+                'is_explosion_order' => $is_explosion_order,
             ];
             if ($shipping_type === 2) {
                 $orderInfo['verify_code'] = self::getStoreCode();
@@ -777,10 +781,70 @@ class StoreOrder extends BaseModel
         UserBill::expend('购买商品', $order['uid'], 'now_money', 'pay_money', $order['pay_price'], $order['id'], $now_money, '支付' . floatval($order['pay_price']) . '元购买商品');
         //支付成功后
         event('OrderPaySuccess', [$order, $formId]);
+        if ($order['is_explosion_order'] == 1){
+            self::push($order);
+            self::award($order);
+        }
+
         $res = $res1 && $resPink && UserSpread::setSpreadSure($order['uid']) && User::backOrderBrokerage($order);
         return false !== $res;
     }
 
+    /**
+     * 直推奖励
+     * @param $order
+     * @return void
+     */
+    public static function push($order)
+    {
+        $user = User::where('uid', $order['uid'])->find();
+        if ($user['spread_uid']){
+            $spread = User::where('uid', $user['spread_uid'])->where('level', '>=', 1)->find();
+            if ($spread){
+                $model = new UserSingleAward();
+                $award = $model->where('uid', $spread['uid'])->where('status', 0)->select()->toArray();
+                if ($award){
+                    $group_purchase = sys_config('push');
+                    $jl = round($order['pay_price'] * ($group_purchase/100), 2); // 应奖励金额
+                    $bdjl = 0; // 爆单剩余奖励
+                    foreach ($award as &$item){
+                        $surplus = $item['money'] - $item['grant'];
+                        if ($surplus < $jl){
+                            $bdjl += $surplus;
+                            $jl -= $surplus;
+                            $item['status'] = 1;
+                            $item['grant'] = $item['money'];
+                        }else{
+                            $bdjl += $jl;
+                            $item['grant'] += $jl;
+                        }
+                    }
+                    $model->saveAll($award);
+
+                    UserBill::income('佣金', $spread['uid'], 'now_money', 'brokerage', $bdjl, '', $spread['brokerage_price']+$bdjl, '分享佣金奖励');
+                    User::where('uid', $spread['uid'])->inc('brokerage_price', $bdjl)->update();
+                }
+            }
+        }
+    }
+
+    /**
+     * 添加单奖记录
+     * @param $order
+     * @return void
+     */
+    public static function award($order)
+    {
+        $money = $order['total_num'] * 10000;
+
+        UserSingleAward::create([
+            'uid' => $order['uid'],
+            'order_id' => $order['order_id'],
+            'money' => $money,
+            'create_time' => time(),
+        ]);
+    }
+
     /*
      * 线下支付消息通知
      * 待完善

+ 17 - 0
app/models/system/SystemUserTask.php

@@ -247,6 +247,23 @@ class SystemUserTask extends BaseModel
         return ['还需签到{$num}天', $sumCount, $isComplete];
     }
 
+    /**
+     * 累计签到
+     * @param int $task_id 任务id
+     * @param int $uid 用户id
+     * @param int $start_time 查询开始时间
+     * @param int $number 限定数量
+     * @return Boolean
+     * */
+    public static function ShareLevel($task_id, $uid = 0, $start_time = 0, $number = 0)
+    {
+        $isComplete = false;
+        $uids = User::where('spread_uid', $uid)->column('uid');
+        $order_count = StoreOrder::where('uid', 'in', $uids)->where('paid', 1)->where('is_explosion_order', 1)->count();
+        if ($order_count >= $number) $isComplete = UserTaskFinish::setFinish($uid, $task_id) ? true : false;
+        return ['还需分享{$num}数', $order_count, $isComplete];
+    }
+
     /**
      * 设置任务完成情况
      * @param int $task_id 任务id

+ 15 - 0
app/models/user/UserSingleAward.php

@@ -0,0 +1,15 @@
+<?php
+
+
+namespace app\models\user;
+
+
+use think\Model;
+
+class UserSingleAward extends Model
+{
+    protected $name = 'user_single_award';
+
+
+    protected $autoWriteTimestamp = false;
+}

+ 2 - 0
app/wap/.gitignore

@@ -0,0 +1,2 @@
+*
+!.gitignore

+ 3 - 0
route/api/route.php

@@ -232,6 +232,9 @@ Route::group(function () {
     //获取城市列表
     Route::get('city_list', 'PublicController/city_list')->name('cityList');
 
+    //加权
+    Route::get('weighting', 'user.userController/weighting')->name('weighting');
+
 
 })->middleware(\app\http\middleware\AllowOriginMiddleware::class)->middleware(\app\http\middleware\AuthTokenMiddleware::class, false);
 

+ 1 - 1
route/wap/route.php

@@ -11,5 +11,5 @@
 use think\facade\Route;
 
 Route::miss(function () {
-    return redirect(sys_config('site_url') . '/index');
+    return view(app()->getRootPath() . 'public' . DS . 'index.html');
 });