From c391e89e30ef29635b82d02f8a8f24a1d28c3b47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E4=B8=80=E5=B3=B0?= <1feng.0595@gmail.com> Date: Fri, 29 Sep 2017 00:03:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=88=91=E7=9A=84=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Common/ReturnCode.php | 10 ++++++ .../Controllers/Api/UserAddressController.php | 9 +++-- .../Api/UserGoodsHistoryController.php | 2 +- .../Controllers/Weixin/UserController.php | 34 +++++++++++++++++++ app/Http/Model/Goods.php | 7 ++-- app/Http/Model/UserAddress.php | 34 +++++++++---------- public/js/weixin/mobile.js | 18 +++++++++- .../weixin/user/userGoodsHistory.blade.php | 8 +++-- routes/web.php | 8 +++-- 9 files changed, 99 insertions(+), 31 deletions(-) create mode 100644 app/Common/ReturnCode.php diff --git a/app/Common/ReturnCode.php b/app/Common/ReturnCode.php new file mode 100644 index 0000000..5557175 --- /dev/null +++ b/app/Common/ReturnCode.php @@ -0,0 +1,10 @@ +input('limit', 10); $data['offset'] = $request->input('offset', 0); + $data['user_id'] = Token::$uid; $res = UserAddress::getList($data); if(!$res) @@ -36,7 +37,7 @@ class UserAddressController extends CommonController //参数 $id = $request->input('id',null); - $res = UserAddress::getOne($id); + $res = UserAddress::getOne(Token::$uid,$id); if(!$res) { return ReturnData::create(ReturnData::SYSTEM_FAIL); @@ -51,7 +52,7 @@ class UserAddressController extends CommonController //参数 $id = $request->input('id',null); - $res = UserAddress::setDefault($id); + $res = UserAddress::setDefault($id,Token::$uid); if(!$res) { return ReturnData::create(ReturnData::SYSTEM_FAIL); @@ -64,6 +65,7 @@ class UserAddressController extends CommonController public function userAddressAdd(Request $request) { //参数 + $data['user_id'] = Token::$uid; $data['name'] = $request->input('name',null); $data['mobile'] = $request->input('mobile',null); $data['country'] = $request->input('country',null); @@ -95,6 +97,7 @@ class UserAddressController extends CommonController public function userAddressUpdate(Request $request) { //参数 + $data['user_id'] = Token::$uid; $data['id'] = $request->input('id',null); $data['name'] = $request->input('name',null); $data['mobile'] = $request->input('mobile',null); @@ -129,7 +132,7 @@ class UserAddressController extends CommonController //参数 $id = $request->input('id',null); - $res = UserAddress::remove($id); + $res = UserAddress::remove($id,Token::$uid); if(!$res) { return ReturnData::create(ReturnData::SYSTEM_FAIL); diff --git a/app/Http/Controllers/Api/UserGoodsHistoryController.php b/app/Http/Controllers/Api/UserGoodsHistoryController.php index 8fae967..7caff9b 100644 --- a/app/Http/Controllers/Api/UserGoodsHistoryController.php +++ b/app/Http/Controllers/Api/UserGoodsHistoryController.php @@ -75,7 +75,7 @@ class UserGoodsHistoryController extends CommonController //参数 $user_id = Token::$uid; - $res = UserGoodsHistory::remove($user_id); + $res = UserGoodsHistory::clear($user_id); if($res === false) { return ReturnData::create(ReturnData::SYSTEM_FAIL); diff --git a/app/Http/Controllers/Weixin/UserController.php b/app/Http/Controllers/Weixin/UserController.php index b2cfded..803f0fd 100644 --- a/app/Http/Controllers/Weixin/UserController.php +++ b/app/Http/Controllers/Weixin/UserController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers\Weixin; use App\Http\Controllers\Weixin\CommonController; use Illuminate\Http\Request; +use App\Common\ReturnCode; class UserController extends CommonController { @@ -50,4 +51,37 @@ class UserController extends CommonController return view('weixin.user.userGoodsHistory', $data); } + + //浏览记录删除 + public function userGoodsHistoryDelete(Request $request) + { + $id = $request->input('id',''); + + if($id == ''){$this->error_jump(ReturnData::PARAMS_ERROR);} + + $postdata = array( + 'id' => $id, + 'access_token' => $_SESSION['weixin_user_info']['access_token'] + ); + $url = env('APP_API_URL')."/user_goods_history_delete"; + $res = curl_request($url,$postdata,'POST'); + + if($res['code'] != ReturnCode::SUCCESS_CODE){$this->error_jump(ReturnCode::FAIL);} + + $this->success_jump(ReturnCode::SUCCESS); + } + + //浏览记录清空 + public function userGoodsHistoryClear(Request $request) + { + $postdata = array( + 'access_token' => $_SESSION['weixin_user_info']['access_token'] + ); + $url = env('APP_API_URL')."/user_goods_history_clear"; + $res = curl_request($url,$postdata,'POST'); + + if($res['code'] != ReturnCode::SUCCESS_CODE){$this->error_jump(ReturnCode::FAIL);} + + $this->success_jump(ReturnCode::SUCCESS); + } } \ No newline at end of file diff --git a/app/Http/Model/Goods.php b/app/Http/Model/Goods.php index 1266d72..994eb66 100644 --- a/app/Http/Model/Goods.php +++ b/app/Http/Model/Goods.php @@ -123,8 +123,11 @@ class Goods extends BaseModel $goods = $model->first(); - $goods['goods_detail_url'] = route('weixin_goods_detail',array('id'=>$goods->id)); - $goods['price'] = self::get_final_price($id); + if($goods) + { + $goods['goods_detail_url'] = route('weixin_goods_detail',array('id'=>$goods->id)); + $goods['price'] = self::get_final_price($id); + } return $goods; } diff --git a/app/Http/Model/UserAddress.php b/app/Http/Model/UserAddress.php index 3a90649..84cba78 100644 --- a/app/Http/Model/UserAddress.php +++ b/app/Http/Model/UserAddress.php @@ -1,8 +1,6 @@ count(); $res['list'] = array(); @@ -56,7 +54,7 @@ class UserAddress extends BaseModel } //获取一条记录,不传address_id表示获取默认地址 - public static function getOne($address_id='') + public static function getOne($user_id,$address_id='') { $arr = ''; @@ -75,11 +73,11 @@ class UserAddress extends BaseModel return $arr; } - if (Token::$uid > 0) + if ($user_id > 0) { // 取默认地址 $arr = self::join('user','user_address.id', '=', 'user.address_id') - ->where('user.id',Token::$uid)->select('user_address.id','user_address.name','country','province','city','district','address','user_address.mobile','zipcode','best_time') + ->where('user.id',$user_id)->select('user_address.id','user_address.name','country','province','city','district','address','user_address.mobile','zipcode','best_time') ->first(); if($arr) @@ -99,7 +97,7 @@ class UserAddress extends BaseModel extract($param); $model = new UserAddress; - $model->user_id = Token::$uid; + $model->user_id = $user_id; $model->name = $name; $model->email = isset($email) ? $email : ''; $model->country = isset($country) ? $country : 0; @@ -116,7 +114,7 @@ class UserAddress extends BaseModel if ($model->save()) { - $user = User::where('id', Token::$uid)->first(); + $user = User::where('id', $user_id)->first(); if (!UserAddress::where('id', $user->address_id)->first() || $model->is_default!=0) { @@ -133,9 +131,9 @@ class UserAddress extends BaseModel { extract($param); - if ($model = UserAddress::where('id', $id)->where('user_id', Token::$uid)->first()) + if ($model = UserAddress::where('id', $id)->where('user_id', $user_id)->first()) { - $model->user_id = Token::$uid; + $model->user_id = $user_id; $model->name = $name; $model->email = isset($email) ? $email : ''; $model->country = isset($country) ? $country : 0; @@ -165,13 +163,13 @@ class UserAddress extends BaseModel } //删除一条记录 - public static function remove($id) + public static function remove($id,$user_id) { - if (UserAddress::where('id', $id)->where('user_id', Token::$uid)->delete()) + if (UserAddress::where('id', $id)->where('user_id', $user_id)->delete()) { - if ($address = UserAddress::where('user_id', Token::$uid)->first()) + if ($address = UserAddress::where('user_id', $user_id)->first()) { - $user = User::where('id', Token::$uid)->first(); + $user = User::where('id', $user_id)->first(); if($user->address_id == $id) { @@ -185,16 +183,16 @@ class UserAddress extends BaseModel } //设为默认地址 - public static function setDefault($address_id) + public static function setDefault($address_id,$user_id) { - if ($user_address = UserAddress::where('id', $address_id)->where('user_id', Token::$uid)->first()) + if ($user_address = UserAddress::where('id', $address_id)->where('user_id', $user_id)->first()) { $user_address->is_default = 1; $user_address->save(); - UserAddress::where('user_id', Token::$uid)->where('id', '<>', $address_id)->update(['is_default'=>0]); + UserAddress::where('user_id', $user_id)->where('id', '<>', $address_id)->update(['is_default'=>0]); - if($user = User::where('id', Token::$uid)->first()) + if($user = User::where('id', $user_id)->first()) { $user->address_id = $address_id; $user->save(); diff --git a/public/js/weixin/mobile.js b/public/js/weixin/mobile.js index e5e0c19..8f4ce0f 100644 --- a/public/js/weixin/mobile.js +++ b/public/js/weixin/mobile.js @@ -8,4 +8,20 @@ $(function(){ $('.classlist ul li').click(function(){ $(this).addClass('red').siblings().removeClass('red'); }); -}) \ No newline at end of file +}); + +//删除确认框 +function delconfirm(url,des) +{ + if(!des){des='确定要删除吗?';} + + //询问框 + layer.open({ + content: des + ,btn: ['确定', '取消'] + ,yes: function(index){ + location.href= url; + layer.close(index); + } + }); +} \ No newline at end of file diff --git a/resources/views/weixin/user/userGoodsHistory.blade.php b/resources/views/weixin/user/userGoodsHistory.blade.php index 311dbb8..3a285aa 100644 --- a/resources/views/weixin/user/userGoodsHistory.blade.php +++ b/resources/views/weixin/user/userGoodsHistory.blade.php @@ -1,20 +1,22 @@