diff --git a/.gitignore b/.gitignore
index 379c3a4..ab03834 100644
--- a/.gitignore
+++ b/.gitignore
@@ -10,3 +10,6 @@ Homestead.json
Homestead.yaml
npm-debug.log
.env
+/.svn
+/build
+/.project
\ No newline at end of file
diff --git a/app/Http/Controllers/Api/BonusController.php b/app/Http/Controllers/Api/BonusController.php
index 94df844..ce56abf 100644
--- a/app/Http/Controllers/Api/BonusController.php
+++ b/app/Http/Controllers/Api/BonusController.php
@@ -118,41 +118,4 @@ class BonusController extends CommonController
return ReturnData::create(ReturnData::SUCCESS,$res);
}
-
- //用户获取优惠券
- public function userGetBonus(Request $request)
- {
- //参数
- $data['bonus_id'] = $request->input('bonus_id',null);
- if($data['bonus_id']===null)
- {
- return ReturnData::create(ReturnData::PARAMS_ERROR);
- }
-
- $data['user_id'] = Token::$uid;
-
- $res = UserBonus::add($data);
- if($res !== true)
- {
- return ReturnData::create(ReturnData::SYSTEM_FAIL,null,$res);
- }
-
- return ReturnData::create(ReturnData::SUCCESS,$res);
- }
-
- //用户优惠券列表
- public function userBonusList(Request $request)
- {
- //参数
- $data['used_time'] = 0;
- $data['user_id'] = Token::$uid;
-
- $res = UserBonus::getList($data);
- if(!$res)
- {
- return ReturnData::create(ReturnData::SYSTEM_FAIL,null,$res);
- }
-
- return ReturnData::create(ReturnData::SUCCESS,$res);
- }
}
\ No newline at end of file
diff --git a/app/Http/Controllers/Api/UserBonusController.php b/app/Http/Controllers/Api/UserBonusController.php
new file mode 100644
index 0000000..3a7f8f1
--- /dev/null
+++ b/app/Http/Controllers/Api/UserBonusController.php
@@ -0,0 +1,73 @@
+input('limit', 10);
+ $data['offset'] = $request->input('offset', 0);
+ if($request->input('status', '') != ''){$data['status'] = $request->input('status');}
+ $data['user_id'] = Token::$uid;
+
+ $res = UserBonus::getList($data);
+ if($res == false)
+ {
+ return ReturnData::create(ReturnData::SYSTEM_FAIL);
+ }
+
+ return ReturnData::create(ReturnData::SUCCESS,$res);
+ }
+
+ //用户获取优惠券
+ public function userBonusAdd(Request $request)
+ {
+ //参数
+ $data['bonus_id'] = $request->input('bonus_id','');
+ $data['get_time'] = time();
+ $data['user_id'] = Token::$uid;
+
+ if($data['bonus_id']=='')
+ {
+ return ReturnData::create(ReturnData::PARAMS_ERROR);
+ }
+
+ $res = UserBonus::add($data);
+ if($res == false)
+ {
+ return ReturnData::create(ReturnData::SYSTEM_FAIL);
+ }
+
+ return ReturnData::create(ReturnData::SUCCESS,$res);
+ }
+
+ //用户删除优惠券
+ public function userBonusDelete(Request $request)
+ {
+ $id = $request->input('id','');
+ if($id=='')
+ {
+ return ReturnData::create(ReturnData::PARAMS_ERROR);
+ }
+
+ $res = UserBonus::remove($id);
+ if($res == false)
+ {
+ return ReturnData::create(ReturnData::SYSTEM_FAIL,null,$res);
+ }
+
+ return ReturnData::create(ReturnData::SUCCESS,$res);
+ }
+}
\ No newline at end of file
diff --git a/app/Http/Controllers/Weixin/UserController.php b/app/Http/Controllers/Weixin/UserController.php
index 9defcc1..7232f7f 100644
--- a/app/Http/Controllers/Weixin/UserController.php
+++ b/app/Http/Controllers/Weixin/UserController.php
@@ -149,6 +149,48 @@ class UserController extends CommonController
return view('weixin.user.userPointList', $data);
}
+ //用户优惠券列表
+ public function userBonusList(Request $request)
+ {
+ //商品列表
+ $pagesize = 1;
+ $offset = 0;
+ if(isset($_REQUEST['page'])){$offset = ($_REQUEST['page']-1)*$pagesize;}
+
+ $postdata = array(
+ 'limit' => $pagesize,
+ 'offset' => $offset,
+ 'status' => 0,
+ 'access_token' => $_SESSION['weixin_user_info']['access_token']
+ );
+ $url = env('APP_API_URL')."/user_bonus_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 .= '
';
+ $html .= '
'.$v['bonus']['name'].'¥'.$v['bonus']['money'].'
';
+ $html .= '
有效期至'.$v['bonus']['end_time'].' 满'.$v['bonus']['min_amount'].'可用
';
+ //$html .= '
说明
';
+ $html .= '
';
+ }
+ }
+
+ exit(json_encode($html));
+ }
+
+ return view('weixin.user.userBonusList', $data);
+ }
+
//浏览记录
public function userGoodsHistory(Request $request)
{
diff --git a/app/Http/Model/User.php b/app/Http/Model/User.php
index 521d03b..4e82032 100644
--- a/app/Http/Model/User.php
+++ b/app/Http/Model/User.php
@@ -134,7 +134,8 @@ class User extends BaseModel
if(!$user){return false;}
$user->reciever_address = UserAddress::getOne($user->address_id);
$user->collect_goods_count = CollectGoods::where('user_id', $user_id)->count();
-
+ $user->bonus_count = UserBonus::where(array('user_id'=>$user_id,'status'=>0))->count();
+
$userinfo = $user->makeVisible(array('pay_password'))->toArray();
$user->pay_password = 0;
if($userinfo['pay_password']){$user->pay_password = 1;}
diff --git a/app/Http/Model/UserBonus.php b/app/Http/Model/UserBonus.php
index 672b18f..1cfecd9 100644
--- a/app/Http/Model/UserBonus.php
+++ b/app/Http/Model/UserBonus.php
@@ -26,7 +26,7 @@ class UserBonus extends BaseModel
$model = new UserBonus;
- if(isset($used_time)){$where['used_time'] = $used_time;}
+ if(isset($status)){$where['status'] = $status;}
$model = $model->where($where);
@@ -35,7 +35,13 @@ class UserBonus extends BaseModel
if($res['count']>0)
{
- $res['list'] = $model->skip($offset)->take($limit)->orderBy('id','desc')->get()->toArray();
+ $bonus_list = $model->skip($offset)->take($limit)->orderBy('id','desc')->get();
+ foreach($bonus_list as $k=>$v)
+ {
+ $bonus_list[$k]->bonus = Bonus::where('id',$v->bonus_id)->first();
+ }
+
+ $res['list'] = $bonus_list;
}
else
{
@@ -45,18 +51,21 @@ class UserBonus extends BaseModel
return $res;
}
- public static function getOne($id)
+ public static function getOne($where)
{
- return self::where('id', $id)->first()->toArray();
+ $res = self::where($where)->first();
+ if($res){$res->bonus = Bonus::where('id',$res->bonus_id)->first();}
+
+ return $res;
}
public static function add(array $data)
{
- if(self::where($data)->first()){return '亲,您已获取!';}
+ if(self::where(['bonus_id'=>$data['bonus_id'],'user_id'=>$data['user_id']])->first()){return '亲,您已获取!';}
if ($id = self::insertGetId($data))
{
- return true;
+ return $id;
}
return false;
diff --git a/resources/views/weixin/common/footer.blade.php b/resources/views/weixin/common/footer.blade.php
index 9a2fefb..1bc2fc2 100644
--- a/resources/views/weixin/common/footer.blade.php
+++ b/resources/views/weixin/common/footer.blade.php
@@ -4,7 +4,7 @@
diff --git a/resources/views/weixin/goods/goodsDetail.blade.php b/resources/views/weixin/goods/goodsDetail.blade.php
index 63e157c..943acb0 100644
--- a/resources/views/weixin/goods/goodsDetail.blade.php
+++ b/resources/views/weixin/goods/goodsDetail.blade.php
@@ -13,9 +13,9 @@
diff --git a/resources/views/weixin/user/index.blade.php b/resources/views/weixin/user/index.blade.php
index bc9745e..7604a98 100644
--- a/resources/views/weixin/user/index.blade.php
+++ b/resources/views/weixin/user/index.blade.php
@@ -121,8 +121,8 @@
-
- 0
+
+
优惠券
diff --git a/resources/views/weixin/user/userBonusList.blade.php b/resources/views/weixin/user/userBonusList.blade.php
new file mode 100644
index 0000000..b9ab29e
--- /dev/null
+++ b/resources/views/weixin/user/userBonusList.blade.php
@@ -0,0 +1,91 @@
+
+我的优惠券
+
+
+
+
+
+
+
+
+
+
+
+@include('weixin.common.footer')
+
\ No newline at end of file
diff --git a/routes/web.php b/routes/web.php
index f8c43f3..8cfe60a 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -75,13 +75,15 @@ Route::group(['prefix' => 'weixin', 'namespace' => 'Weixin'], function () {
//微信路由,需登录,全局
Route::group(['prefix' => 'weixin', 'namespace' => 'Weixin', 'middleware' => ['web','wxlogin']], function () {
-
+ Route::get('/category', 'CartController@index')->name('weixin_category');
//个人中心
Route::get('/user', 'UserController@index')->name('weixin_user');
Route::get('/userinfo', 'UserController@userinfo')->name('weixin_userinfo');
Route::get('/user_account', 'UserController@userAccount')->name('weixin_user_account');
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_bonus_list', 'UserController@userBonusList')->name('weixin_user_bonus_list');
//浏览记录
Route::get('/user_goods_history', 'UserController@userGoodsHistory')->name('weixin_user_goods_history');
Route::get('/user_goods_history_delete', 'UserController@userGoodsHistoryDelete')->name('weixin_user_goods_history_delete');
@@ -164,8 +166,8 @@ Route::group(['prefix' => 'dataapi', 'namespace' => 'Api', 'middleware' => ['web
Route::get('/user_point_list', 'UserPointController@userPointList'); //用户积分列表
Route::post('/user_point_add', 'UserPointController@userPointAdd');
//优惠券
- Route::get('/user_bonus_list', 'BonusController@userBonusList'); //用户优惠券列表
- Route::post('/user_get_bonus', 'BonusController@userGetBonus'); //用户获取优惠券
+ 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'); //修改优惠券