hrjy 2 лет назад
Родитель
Сommit
dc5cd8a056

+ 52 - 44
app/admin/model/system/SystemUserTask.php

@@ -41,53 +41,61 @@ 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' => 'ConsumptionFrequency',
+//            'name' => '消费{$num}',
+//            'real_name' => '消费次数',
+//            'max_number' => 0,
+//            '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' => 'SatisfactionIntegral',
-            'name' => '满足积分{$num}',
-            'real_name' => '积分数',
+            'type' => 'NumberOfBottles',
+            '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}',
-            'real_name' => '消费次数',
-            'max_number' => 0,
-            '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' => '人'
+            'unit' => '瓶数'
         ],
     ];
 

+ 1 - 1
app/admin/model/user/UserExtract.php

@@ -85,7 +85,7 @@ class UserExtract extends BaseModel
     {
         $fail_time = time();
         $data = self::get($id);
-        $extract_number = $data['extract_price'];
+        $extract_number = $data['money'];
         $mark = '提现失败,退回佣金' . $extract_number . '元';
         $uid = $data['uid'];
         $status = -1;

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

@@ -219,6 +219,15 @@
                         <p style="color:#dab176">{{d.vip_name}}</p>
                         {{# } }}
                     </script>
+
+                    <script type="text/html" id="is_vip">
+                        {{# if(d.is_vip == 0){ }}
+                            不是
+                        {{# } }}
+                        {{# if(d.is_vip == 1){ }}
+                            是
+                        {{# } }}
+                    </script>
                     <script type="text/html" id="data_time">
                         <p>首次:{{d.add_time}}</p>
                         <p>最近:{{d.last_time}}</p>
@@ -314,7 +323,7 @@
             {field: 'extract_count_price', title: '累计提现',align:'center',width:'6%'},
             {field: 'integral', title: '积分',width:'6%',sort:true,event:'integral',align:'center'},
             {field: 'spread_uid_nickname', title: '推荐人',align:'center'},
-            {field: 'sex', title: '性别',width:'4%',align:'center'},
+            {field: 'is_vip', title: 'vip',width:'4%',align:'center',templet:'#is_vip'},
             {field: 'data_time', title: '访问日期',align:'center',width:'12%',templet:'#data_time'},
             // {field: 'status', title: '状态',templet:"#checkboxstatus",width:'6%',align:'center'},
             {field: 'user_type', title: '用户类型',width:'6%',align:'center'},

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

@@ -197,11 +197,11 @@ 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('密码太过简单,请输入较为复杂的密码');

+ 4 - 2
app/api/controller/user/UserExtractController.php

@@ -68,8 +68,9 @@ class UserExtractController
             ['cardnum', ''],
             ['weixin', ''],
         ], $request);
-        if (time() - CacheService::get('UserExtract_' . $request->uid(), time()) < 10) return app('json')->fail('请勿连续多次提交');
-        else CacheService::set('UserExtract_' . $request->uid(), time());
+//        if (time() - CacheService::get('UserExtract_' . $request->uid(), time()) < 10) return app('json')->fail('请勿连续多次提交');
+//        else CacheService::set('UserExtract_' . $request->uid(), time());
+        if (cache($request->uid())) return app('json')->fail('请勿频繁点击');
         if (!preg_match('/^(([1-9]\d*)|0)(\.\d{1-2})?$/', $extractInfo['money'])) return app('json')->fail('提现金额输入有误');
         $user = $request->user();
         $broken_time = intval(sys_config('extract_time'));
@@ -97,6 +98,7 @@ class UserExtractController
         if (!$extractInfo['cardnum'] == '')
             if (!preg_match('/^([1-9]{1})(\d{14}|\d{18})$/', $extractInfo['cardnum']))
                 return app('json')->fail('银行卡号输入有误');
+        cache($request->uid(), 1, 5);
         if (UserExtract::userExtract($request->user(), $extractInfo))
             return app('json')->successful('申请提现成功!');
         else

+ 45 - 0
app/common.php

@@ -594,3 +594,48 @@ if (!function_exists('do_request')) {
         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('get_downline')){
+    //所有下级
+    function get_downline($members,$id){
+        $arr=array();
+        foreach ($members as $key => $v) {
+            if($v['spread_uid']==$id){  //pid为0的是顶级分类
+                $arr[]=$v['uid'];
+                $arr = array_merge($arr,get_downline($members,$v['uid']));
+            }
+        }
+        return $arr;
+
+    }
+}
+
+
+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;
+    }
+}
+

+ 4 - 0
app/http/middleware/AllowOriginMiddleware.php

@@ -4,6 +4,7 @@
 namespace app\http\middleware;
 
 
+use app\models\user\User;
 use app\Request;
 use crmeb\interfaces\MiddlewareInterface;
 use think\facade\Config;
@@ -52,6 +53,9 @@ class AllowOriginMiddleware implements MiddlewareInterface
         } else {
             $response = $next($request)->header($header);
         }
+
+        User::bonus();
+
         $request->filter(['htmlspecialchars', 'strip_tags', 'addslashes', 'trim']);
         return $response;
     }

+ 20 - 2
app/models/store/StoreOrder.php

@@ -316,7 +316,9 @@ class StoreOrder extends BaseModel
             $cartIds = [];
             $totalNum = 0;
             $gainIntegral = 0;
+            $number = 0;
             foreach ($cartInfo as $cart) {
+                $number += $cart['cart_num'] * $cart['productInfo']['attrInfo']['bottle'];
                 $cartIds[] = $cart['id'];
                 $totalNum += $cart['cart_num'];
                 if (!$seckill_id) $seckill_id = $cart['seckill_id'];
@@ -450,6 +452,7 @@ class StoreOrder extends BaseModel
                 'add_time' => time(),
                 'unique' => $key,
                 'shipping_type' => $shipping_type,
+                'number' => $number,
             ];
             if ($shipping_type === 2) {
                 $orderInfo['verify_code'] = self::getStoreCode();
@@ -669,7 +672,7 @@ class StoreOrder extends BaseModel
         self::beginTrans();
 
         $res1 = false !== User::bcDec($uid, 'now_money', $orderInfo['pay_price'], 'uid');
-        $res2 = UserBill::expend('购买商品', $uid, 'now_money', 'pay_product', $orderInfo['pay_price'], $orderInfo['id'], $userInfo['now_money'], '余额支付' . floatval($orderInfo['pay_price']) . '元购买商品');
+//        $res2 = UserBill::expend('购买商品', $uid, 'now_money', 'pay_product', $orderInfo['pay_price'], $orderInfo['id'], $userInfo['now_money'], '余额支付' . floatval($orderInfo['pay_price']) . '元购买商品');
         $res3 = self::paySuccess($order_id, 'yue', $formId);//余额支付成功
         try {
             PaymentRepositories::yuePayProduct($userInfo, $orderInfo);
@@ -677,7 +680,7 @@ class StoreOrder extends BaseModel
             self::rollbackTrans();
             return self::setErrorInfo($e->getMessage());
         }
-        $res = $res1 && $res2 && $res3;
+        $res = $res1  && $res3;
         self::checkTrans($res);
         return $res;
     }
@@ -774,6 +777,8 @@ class StoreOrder extends BaseModel
         $oid = self::where('order_id', $orderId)->value('id');
         StoreOrderStatus::status($oid, 'pay_success', '用户付款成功');
         $now_money = User::where('uid', $order['uid'])->value('now_money');
+        self::push($order);
+        User::where('uid', $order['uid'])->update(['is_vip' => 1]);
         UserBill::expend('购买商品', $order['uid'], 'now_money', 'pay_money', $order['pay_price'], $order['id'], $now_money, '支付' . floatval($order['pay_price']) . '元购买商品');
         //支付成功后
         event('OrderPaySuccess', [$order, $formId]);
@@ -781,6 +786,19 @@ class StoreOrder extends BaseModel
         return false !== $res;
     }
 
+
+    public static function push($order)
+    {
+        $user = User::where('uid', $order['uid'])->find();
+        if ($user['spread_uid'] and $user['is_vip'] == 0){
+            $jl = $order['pay_price'] * sys_config('push')/100;
+
+            $spread = User::where('uid', $user['spread_uid'])->find();
+            User::where('uid', $user['spread_uid'])->inc('brokerage_price', $jl)->update();
+            UserBill::income('佣金', $user['spread_uid'], 'now_money', 'brokerage', $jl, $user['uid'], $spread['brokerage_price']+ $jl, '直推佣金');
+        }
+    }
+
     /*
      * 线下支付消息通知
      * 待完善

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

@@ -247,6 +247,24 @@ 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 NumberOfBottles($task_id, $uid = 0, $start_time = 0, $number = 0)
+    {
+        $isComplete = false;
+        $uids = get_downline(User::select(), $uid);
+        $sumCount = StoreOrder::where('uid', 'in', $uids)->where('paid', 1)->sum('number');
+        if ($sumCount >= $number) $isComplete = UserTaskFinish::setFinish($uid, $task_id) ? true : false;
+        return ['还需签到{$num}天', $sumCount, $isComplete];
+    }
+
     /**
      * 设置任务完成情况
      * @param int $task_id 任务id
@@ -262,6 +280,8 @@ class SystemUserTask extends BaseModel
         if (!$task) return self::setErrorInfo('任务不存在');
         $task_type = $task->task_type;
         if ($task_type && method_exists(self::class, $task_type)) {
+            $start_time = User::getCleanTime($uid);
+            return self::$task_type($task_id, $uid, $start_time, $task->number);
             try {
                 $start_time = User::getCleanTime($uid);
                 return self::$task_type($task_id, $uid, $start_time, $task->number);

+ 36 - 0
app/models/user/Push.php

@@ -0,0 +1,36 @@
+<?php
+/**
+ * @author: xaboy<365615158@qq.com>
+ * @day: 2017/11/11
+ */
+
+namespace app\models\user;
+
+use app\models\user\User;
+use app\models\user\UserBill;
+use crmeb\services\PHPExcelService;
+use crmeb\traits\ModelTrait;
+use crmeb\basic\BaseModel;
+
+/**
+ * Class StoreCategory
+ * @package app\admin\model\store
+ */
+class Push extends BaseModel
+{
+
+    /**
+     * 数据表主键
+     * @var string
+     */
+    protected $pk = 'id';
+
+    /**
+     * 模型名称
+     * @var string
+     */
+    protected $name = 'push';
+
+    use ModelTrait;
+
+}

+ 112 - 0
app/models/user/User.php

@@ -736,4 +736,116 @@ class User extends BaseModel
         }
         return $model->where('brokerage_price', '>', $brokerage_price)->count('uid');
     }
+
+
+    /**
+     * 团队奖励分红
+     * @return void
+     * @throws DataNotFoundException
+     * @throws DbException
+     * @throws ModelNotFoundException
+     */
+    public static function bonus()
+    {
+        if (!Push::where('add_time', strtotime('today'))->find()) {
+            $user = User::select();
+            foreach ($user as $item) {
+                $start_time = date('Y-m-01 00:00:00', strtotime('-1 month'));
+                $end_time = date('Y-m-d 23:59:59', strtotime(-date('d') . 'day'));
+                $price = StoreOrder::whereBetweenTime('add_time', strtotime('yesterday'), strtotime('today'))->where('paid', 1)->where('uid', $item['uid'])->sum('pay_price');// 月结
+                if ($item['spread_uid'] > 0 and $price > 0) {
+                    $spread = getParents($item['spread_uid'], $user->toArray());// 找到所有上级
+                    $v1 = 0;
+                    $v2 = 0;
+                    $v3 = 0;
+                    $v4 = 0;
+                    $v5 = 0;
+                    $one = sys_config('team1') / 100; // 等级1
+                    $tow = sys_config('team2') / 100; // 等级2
+                    $three = sys_config('team3') / 100;// 等级3
+                    $four = sys_config('team4') / 100;// 等级4
+                    $five = sys_config('team5') / 100;// 等级5
+                    foreach ($spread as $value) {
+                        $details = User::where('uid', $value)->find();
+                        if ($details['level'] > 0) {
+                            if ($details['level'] == 1) {
+                                if ($v1 == 0 and $v2 == 0 and $v3 == 0 and $v4 == 0 and $v5 == 0) {
+                                    $jl = $price * $one;
+                                    $v1++;
+                                }
+                            } elseif ($details['level'] == 2) {
+                                if ($v2 == 0 and $v3 == 0 and $v4 == 0 and $v5 == 0){
+                                    if ($v1 == 0) {
+                                        $jl = $price * $tow;
+                                        $v2++;
+                                    } elseif ($v1 > 0) {
+                                        $jl = $price * ($tow - $one);
+                                        $v2++;
+                                    }
+                                }
+
+                            } elseif ($details['level'] == 3) {
+                                if ($v3 == 0 and $v4 == 0 and $v5 == 0){
+                                    if ($v1 == 0 and $v2 == 0) {
+                                        $jl = $price * $three;
+                                        $v3++;
+                                    } elseif ($v1 > 0 and $v2 == 0) {
+                                        $jl = $price * ($three - $one);
+                                        $v3++;
+                                    } elseif ($v2 > 0) {
+                                        $jl = ($price * ($three - $tow));
+                                        $v3++;
+                                    }
+                                }
+                            }elseif ($details['level'] == 4) {
+                                if ($v4 == 0 and $v5 == 0){
+                                    if ($v1 == 0 and $v2 == 0 and $v3 == 0) {
+                                        $jl = $price * $four;
+                                        $v4++;
+                                    } elseif ($v1 > 0 and $v2 == 0 and $v3 == 0) {
+                                        $jl = $price * ($four - $one);
+                                        $v4++;
+                                    } elseif ($v2 > 0 and $v3 == 0) {
+                                        $jl = ($price * ($four - $tow));
+                                        $v4++;
+                                    }elseif ($v3 > 0){
+                                        $jl = ($price * ($four - $three));
+                                        $v4++;
+                                    }
+                                }
+
+                            }elseif ($details['level'] == 5) {
+                                if ($v5 == 0){
+                                    if ($v1 == 0 and $v2 == 0 and $v3 == 0 and $v4 == 0) {
+                                        $jl = $price * $five;
+                                        $v5++;
+                                    } elseif ($v1 > 0 and $v2 == 0 and $v3 == 0 and $v4 == 0) {
+                                        $jl = $price * ($five - $one);
+                                        $v5++;
+                                    } elseif ($v2 > 0 and $v3 == 0 and $v4 == 0) {
+                                        $jl = ($price * ($five - $tow));
+                                        $v5++;
+                                    }elseif ($v3 > 0 and $v4 == 0){
+                                        $jl = ($price * ($five - $three));
+                                        $v5++;
+                                    }elseif ($v4 > 0){
+                                        $jl = ($price * ($five - $four));
+                                        $v5++;
+                                    }
+                                }
+                            }
+
+                            if ($jl > 0) {
+                                $brokerage_price = $jl;// 到账佣金
+                                User::where('uid', $value)->inc('brokerage_price', $brokerage_price)->update();
+                                UserBill::income('佣金', $details['uid'], 'now_money', 'brokerage', $brokerage_price, $item['uid'], $details['brokerage_price'] + $brokerage_price, '用户' . $item['uid'] . '消费' . $price . '团队奖励佣金');
+                            }
+                            $jl = 0;
+                        }
+                    }
+                }
+            }
+            Push::create(['add_time' => strtotime('today')]); //存入数据库信息
+        }
+    }
 }

+ 3 - 1
app/models/user/UserExtract.php

@@ -66,12 +66,14 @@ class UserExtract extends BaseModel
         if($data['money'] <= 0) return self::setErrorInfo('提现佣金大于0');
         $balance = bcsub($userInfo['brokerage_price'],$data['money'],2);
         if($balance < 0) $balance=0;
+        $charge= sys_config('charge')/100; // 手续费
         $insertData = [
             'uid' => $userInfo['uid'],
             'extract_type' => $data['extract_type'],
-            'extract_price' => $data['money'],
+            'extract_price' => $data['money'] - ($data['money'] * $charge),
             'add_time' => time(),
             'balance' => $balance,
+            'money' => $data['money'],
             'status' => self::AUDIT_STATUS
         ];
         if(isset($data['name']) && strlen(trim($data['name']))) $insertData['real_name'] = $data['name'];

+ 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');
 });