diff --git a/app/Http/Controllers/Api/BonusController.php b/app/Http/Controllers/Api/BonusController.php index ce56abf..103c709 100644 --- a/app/Http/Controllers/Api/BonusController.php +++ b/app/Http/Controllers/Api/BonusController.php @@ -21,7 +21,6 @@ class BonusController extends CommonController //参数 $data['limit'] = $request->input('limit', 10); $data['offset'] = $request->input('offset', 0); - $data['user_id'] = Token::$uid; $res = Bonus::getList($data); if(!$res) diff --git a/app/Http/Controllers/Api/UserController.php b/app/Http/Controllers/Api/UserController.php index dea75d2..b9b89a4 100644 --- a/app/Http/Controllers/Api/UserController.php +++ b/app/Http/Controllers/Api/UserController.php @@ -105,6 +105,10 @@ class UserController extends CommonController $data['limit'] = $request->input('limit', 10); $data['offset'] = $request->input('offset', 0); + if($request->input('parent_id', '')!=''){$data['parent_id'] = $request->input('parent_id');} + if($request->input('group_id', '')!=''){$data['group_id'] = $request->input('group_id');} + if($request->input('sex', '')!=''){$data['sex'] = $request->input('sex');} + $res = User::getList($data); if(!$res) { diff --git a/app/Http/Controllers/Weixin/BonusController.php b/app/Http/Controllers/Weixin/BonusController.php index 8bbe22c..d15f92a 100644 --- a/app/Http/Controllers/Weixin/BonusController.php +++ b/app/Http/Controllers/Weixin/BonusController.php @@ -20,8 +20,7 @@ class BonusController extends CommonController $postdata = array( 'limit' => $pagesize, - 'offset' => $offset, - 'access_token' => $_SESSION['weixin_user_info']['access_token'] + 'offset' => $offset ); $url = env('APP_API_URL')."/bonus_list"; $res = curl_request($url,$postdata,'GET'); diff --git a/app/Http/Controllers/Weixin/UserController.php b/app/Http/Controllers/Weixin/UserController.php index 35b2df9..5455cf7 100644 --- a/app/Http/Controllers/Weixin/UserController.php +++ b/app/Http/Controllers/Weixin/UserController.php @@ -46,6 +46,56 @@ class UserController extends CommonController return view('weixin.user.userinfo', $data); } + //我的分销 + public function userDistribution(Request $request) + { + //获取会员信息 + $postdata = array( + 'access_token' => $_SESSION['weixin_user_info']['access_token'] + ); + $url = env('APP_API_URL')."/user_info"; + $res = curl_request($url,$postdata,'GET'); + $data['user_info'] = $res['data']; + + //获取直属下级会员列表 + $pagesize = 10; + $offset = 0; + if(isset($_REQUEST['page'])){$offset = ($_REQUEST['page']-1)*$pagesize;} + + $postdata = array( + 'limit' => $pagesize, + 'offset' => $offset, + 'parent_id' => $_SESSION['weixin_user_info']['id'], + 'access_token' => $_SESSION['weixin_user_info']['access_token'] + ); + $url = env('APP_API_URL')."/user_list"; + $res = curl_request($url,$postdata,'GET'); + $data['list'] = $res['data']['list']; + + $data['totalpage'] = ceil($res['data']['count']/$pagesize); + + if(isset($_REQUEST['page_ajax']) && $_REQUEST['page_ajax']==1) + { + $html = ''; + + if($res['data']['list']) + { + foreach($res['data']['list'] as $k => $v) + { + $html .= '
  • '.$v['user_name'].''; + $html .= '

    '.$v['user_name'].'

    '; + $html .= '

    佣金:'.$v['commission'].'

    '; + $html .= '

    注册时间:'.date('Y-m-d',$v['add_time']).'

    '; + $html .= '
  • '; + } + } + + exit(json_encode($html)); + } + + return view('weixin.user.userDistribution', $data); + } + //资金管理 public function userAccount(Request $request) { @@ -260,7 +310,7 @@ class UserController extends CommonController public function userBonusList(Request $request) { //商品列表 - $pagesize = 1; + $pagesize = 10; $offset = 0; if(isset($_REQUEST['page'])){$offset = ($_REQUEST['page']-1)*$pagesize;} diff --git a/app/Http/Model/Bonus.php b/app/Http/Model/Bonus.php index d1feb6e..d78cae8 100644 --- a/app/Http/Model/Bonus.php +++ b/app/Http/Model/Bonus.php @@ -30,16 +30,20 @@ class Bonus extends BaseModel $model = $model->where($where); + $model = $model->where(function ($query) { + $query->where('num', '=', -1)->orWhere('num', '>', 0); + }); + + $model = $model->where(function ($query) { + $query->where('start_time', '<', date('Y-m-d H:i:s'))->where('end_time', '>', date('Y-m-d H:i:s')); + }); + $res['count'] = $model->count(); $res['list'] = array(); if($res['count']>0) { - $res['list'] = $model->skip($offset)->take($limit)->orderBy('id','desc')->get()->toArray(); - } - else - { - return false; + $res['list'] = $model->skip($offset)->take($limit)->orderBy('money','desc')->get(); } return $res; @@ -47,7 +51,7 @@ class Bonus extends BaseModel public static function getOne($id) { - return self::where('id', $id)->first()->toArray(); + return self::where('id', $id)->first(); } public static function add(array $data) diff --git a/app/Http/Model/User.php b/app/Http/Model/User.php index f5a47c4..9152165 100644 --- a/app/Http/Model/User.php +++ b/app/Http/Model/User.php @@ -50,25 +50,27 @@ class User extends BaseModel { extract($param); //参数:limit,offset - $where = ''; $limit = isset($limit) ? $limit : 10; $offset = isset($offset) ? $offset : 0; $model = new User; if(isset($group_id)){$where['group_id'] = $group_id;} + if(isset($parent_id)){$where['parent_id'] = $parent_id;} - if($where != '') - { - $model = $model->where($where); - } + if(isset($where)){$model = $model->where($where);} $res['count'] = $model->count(); $res['list'] = array(); if($res['count']>0) { - $res['list'] = $model->select('id','user_name','email','sex','money','point','mobile','nickname','add_time')->skip($offset)->take($limit)->orderBy('id','desc')->get()->toArray(); + $res['list'] = $model->select('id','user_name','email','sex','money','commission','point','mobile','nickname','head_img','add_time')->skip($offset)->take($limit)->orderBy('id','desc')->get(); + + foreach($res['list'] as $k=>$v) + { + $res['list'][$k]['user_name'] = !empty($res['list'][$k]['mobile']) ? $res['list'][$k]['mobile'] : $res['list'][$k]['user_name']; + } } else { diff --git a/app/Http/Model/UserBonus.php b/app/Http/Model/UserBonus.php index 6696ad2..c91dc16 100644 --- a/app/Http/Model/UserBonus.php +++ b/app/Http/Model/UserBonus.php @@ -63,7 +63,10 @@ class UserBonus extends BaseModel public static function add(array $data) { - if(!Bonus::where(['id'=>$data['bonus_id']])->where('num',-1)->first() && !Bonus::where(['id'=>$data['bonus_id']])->where('num','>',0)->first()) + $bonus1 = Bonus::where(['id'=>$data['bonus_id']])->where('num',-1)->first(); + $bonus2 = Bonus::where(['id'=>$data['bonus_id']])->where('num','>',0)->first(); + + if(!$bonus1 && !$bonus2) { return ReturnData::create(ReturnData::PARAMS_ERROR,null,'亲,您来晚了啦,已被抢光了'); } @@ -73,7 +76,7 @@ class UserBonus extends BaseModel $data['get_time'] = time(); //优惠券获取时间 if ($id = self::insertGetId($data)) { - DB::table('bonus')->where(array('id'=>$data['bonus_id']))->decrement('num', 1); + if(!$bonus1){DB::table('bonus')->where(array('id'=>$data['bonus_id']))->decrement('num', 1);} return ReturnData::create(ReturnData::SUCCESS,$id); } diff --git a/resources/views/weixin/bonus/bonusList.blade.php b/resources/views/weixin/bonus/bonusList.blade.php index af522b3..06277f7 100644 --- a/resources/views/weixin/bonus/bonusList.blade.php +++ b/resources/views/weixin/bonus/bonusList.blade.php @@ -6,6 +6,7 @@
    返回
    领券中心
    +
    @@ -19,11 +20,13 @@
    $v){ ?> +
    -

    -

    有效期至 可用

    +

    +

    有效期至 可用

    +
    暂无记录
    @@ -87,6 +90,48 @@ $(function(){ } }); }); + +function getbonus(bonus_id) +{ + var url = ''; + var access_token = ''; + if(access_token=='') + { + //提示 + layer.open({ + content: '请先登录' + ,skin: 'msg' + ,time: 2 //2秒后自动关闭 + }); + + setTimeout("location.href = 'route('weixin_bonus_list'))); ?>'",1000); + + return false; + } + + $.post(url,{bonus_id:bonus_id,access_token:access_token},function(res) + { + if(res.code==0) + { + //提示 + layer.open({ + content: '获取成功' + ,skin: 'msg' + ,time: 2 //2秒后自动关闭 + }); + + location.href = ''; + } + else + { + layer.open({ + content: res.msg + ,skin: 'msg' + ,time: 2 //2秒后自动关闭 + }); + } + },'json'); +} @include('weixin.common.footer') diff --git a/resources/views/weixin/user/index.blade.php b/resources/views/weixin/user/index.blade.php index 310475e..72bdfc0 100644 --- a/resources/views/weixin/user/index.blade.php +++ b/resources/views/weixin/user/index.blade.php @@ -137,22 +137,22 @@
    -
    -
    - -
    -
    - - 我的分销 -
    -
    - -
    +
    -
    +
    +
    -
    +
    - +
    diff --git a/resources/views/weixin/user/userBonusList.blade.php b/resources/views/weixin/user/userBonusList.blade.php index a804e90..18935aa 100644 --- a/resources/views/weixin/user/userBonusList.blade.php +++ b/resources/views/weixin/user/userBonusList.blade.php @@ -6,6 +6,7 @@
    返回
    我的优惠券
    +
    diff --git a/resources/views/weixin/user/userDistribution.blade.php b/resources/views/weixin/user/userDistribution.blade.php new file mode 100644 index 0000000..5adb57f --- /dev/null +++ b/resources/views/weixin/user/userDistribution.blade.php @@ -0,0 +1,103 @@ + +我的分销 + + + + +
    +
    返回
    +
    我的分销
    +
    + + + + +
    + + +
      + $v){ ?> +
    • <?php echo $v['user_name']; ?> +

      +

      佣金:

      +

      注册时间:

      +
    • + +
    + +
    暂无记录
    + +
    + + +@include('weixin.common.footer') + \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index 9beea3d..bedf367 100644 --- a/routes/web.php +++ b/routes/web.php @@ -87,6 +87,7 @@ Route::group(['prefix' => 'weixin', 'namespace' => 'Weixin', 'middleware' => ['w Route::get('/user_money_list', 'UserController@userMoneyList')->name('weixin_user_money_list'); Route::get('/user_point_list', 'UserController@userPointList')->name('weixin_user_point_list'); Route::get('/user_message_list', 'UserController@userMessageList')->name('weixin_user_message_list'); + Route::get('/user_distribution', 'UserController@userDistribution')->name('weixin_user_distribution'); //用户充值 Route::get('/user_recharge', 'UserController@userRecharge')->name('weixin_user_recharge'); Route::get('/user_recharge_order', 'UserController@userRechargeOrder')->name('weixin_user_recharge_order'); @@ -145,6 +146,8 @@ Route::group(['prefix' => 'dataapi', 'namespace' => 'Api', 'middleware' => ['web Route::post('/wx_register', 'UserController@wxRegister'); //注册 Route::post('/wx_login', 'UserController@wxLogin'); //登录 Route::post('/wx_oauth_register', 'UserController@wxOauthRegister'); //微信授权注册登录 + //可用的优惠券列表 + Route::get('/bonus_list', 'BonusController@bonusList'); //可用获取的优惠券列表 }); //API接口路由,需token验证 @@ -200,7 +203,6 @@ Route::group(['prefix' => 'dataapi', 'namespace' => 'Api', 'middleware' => ['web Route::get('/user_available_bonus_list', 'UserBonusController@userAvailableBonusList'); //用户结算时获取可用优惠券列表 Route::get('/user_bonus_list', 'UserBonusController@userBonusList'); //用户优惠券列表 Route::post('/user_bonus_add', 'UserBonusController@userBonusAdd'); //用户获取优惠券 - Route::get('/bonus_list', 'BonusController@bonusList'); //可用获取的优惠券列表 Route::post('/bonus_add', 'BonusController@bonusAdd'); //添加优惠券 Route::post('/bonus_update', 'BonusController@bonusUpdate'); //修改优惠券 Route::post('/bonus_delete', 'BonusController@bonusDelete'); //删除优惠券