Browse Source

我的地址

master
林一峰 7 years ago
parent
commit
c391e89e30
  1. 10
      app/Common/ReturnCode.php
  2. 9
      app/Http/Controllers/Api/UserAddressController.php
  3. 2
      app/Http/Controllers/Api/UserGoodsHistoryController.php
  4. 34
      app/Http/Controllers/Weixin/UserController.php
  5. 7
      app/Http/Model/Goods.php
  6. 34
      app/Http/Model/UserAddress.php
  7. 18
      public/js/weixin/mobile.js
  8. 8
      resources/views/weixin/user/userGoodsHistory.blade.php
  9. 8
      routes/web.php

10
app/Common/ReturnCode.php

@ -0,0 +1,10 @@
<?php
namespace App\Common;
class ReturnCode
{
//通用
const SUCCESS = '操作成功'; //操作成功
const FAIL = '操作失败'; //操作失败
const SUCCESS_CODE = 0;
}

9
app/Http/Controllers/Api/UserAddressController.php

@ -20,6 +20,7 @@ class UserAddressController extends CommonController
//参数
$data['limit'] = $request->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);

2
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);

34
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);
}
}

7
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;
}

34
app/Http/Model/UserAddress.php

@ -1,8 +1,6 @@
<?php
namespace App\Http\Model;
use App\Common\Token;
class UserAddress extends BaseModel
{
//用户收货地址
@ -27,7 +25,7 @@ class UserAddress extends BaseModel
$limit = isset($limit) ? $limit : 10;
$offset = isset($offset) ? $offset : 0;
$model = self::where('user_id', Token::$uid);
$model = self::where('user_id', $user_id);
$res['count'] = $model->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();

18
public/js/weixin/mobile.js

@ -8,4 +8,20 @@ $(function(){
$('.classlist ul li').click(function(){
$(this).addClass('red').siblings().removeClass('red');
});
})
});
//删除确认框
function delconfirm(url,des)
{
if(!des){des='确定要删除吗?';}
//询问框
layer.open({
content: des
,btn: ['确定', '取消']
,yes: function(index){
location.href= url;
layer.close(index);
}
});
}

8
resources/views/weixin/user/userGoodsHistory.blade.php

@ -1,20 +1,22 @@
<!DOCTYPE html><html><head><meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<title>我的足迹</title><meta name="keywords" content="关键词"><meta name="description" content="描述"><meta content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport">
<link href="<?php echo env('APP_URL'); ?>/css/weixin/style.css" type="text/css" rel="stylesheet">
<script type="text/javascript" src="<?php echo env('APP_URL'); ?>/js/jquery.min.js"></script></head><body>
<script type="text/javascript" src="<?php echo env('APP_URL'); ?>/js/jquery.min.js"></script>
<script type="text/javascript" src="<?php echo env('APP_URL'); ?>/js/weixin/mobile.js"></script></head><body>
<div class="classreturn loginsignup">
<div class="ds-in-bl return"><a href="javascript:history.back(-1);"><img src="<?php echo env('APP_URL'); ?>/images/weixin/return.png" alt="返回"></a></div>
<div class="ds-in-bl tit center"><span>我的足迹</span></div>
<div class="ds-in-bl nav_menu"><a href="javascript:void(0);" style="color:#999;" id="clear_history">清空</a></div>
<div class="ds-in-bl nav_menu"><a href="javascript:void(0);" style="color:#999;" id="clear_history" onclick="delconfirm('<?php echo route('weixin_user_goods_history_clear'); ?>','确定要清空吗?')">清空</a></div>
</div>
<script type="text/javascript" src="<?php echo env('APP_URL'); ?>/js/layer/mobile/layer.js"></script>
<div class="floor">
<ul class="goods_list_s cl">
<?php if($user_goods_history){foreach($user_goods_history as $k=>$v){ ?>
<li><a href="<?php echo $v['goods']['goods_detail_url']; ?>"><span class="goods_thumb"><img alt="<?php echo $v['goods']['title']; ?>" src="<?php echo env('APP_URL'); ?><?php echo $v['goods']['litpic']; ?>"></span></a>
<div class="goods_info"><p class="goods_tit"><?php echo $v['goods']['title']; ?></p>
<p class="goods_price"><b><?php echo $v['goods']['price']; ?></b></p>
<p class="goods_des fr"><span id="del_history">删除</span></p>
<p class="goods_des fr"><span id="del_history" onclick="delconfirm('<?php echo route('weixin_user_goods_history_delete',array('id'=>$v['id'])); ?>')">删除</span></p>
</div></li>
<?php }} ?>
</ul>

8
routes/web.php

@ -66,10 +66,12 @@ Route::group(['prefix' => 'weixin', 'namespace' => 'Weixin'], function () {
Route::get('/user', 'UserController@index')->name('weixin_user');
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');
Route::get('/user_goods_history_clear', 'UserController@userGoodsHistoryClear')->name('weixin_user_goods_history_clear');
Route::get('/cart', 'CartController@index')->name('weixin_cart');
Route::get('/user_address_list', 'AddressController@index')->name('weixin_user_address_list');
Route::get('/user_address', 'AddressController@index')->name('weixin_user_address_list');
//页面跳转
Route::get('/jump', 'IndexController@jump')->name('weixin_jump');
@ -236,8 +238,8 @@ Route::group(['prefix' => 'dataapi', 'namespace' => 'Api', 'middleware' => ['web
Route::post('/user_money_add', 'UserMoneyController@userMoneyAdd'); //添加余额明细
//浏览记录
Route::get('/user_goods_history_list', 'UserGoodsHistoryController@userGoodsHistoryList'); //我的足迹列表
Route::get('/user_goods_history_delete', 'UserGoodsHistoryController@userGoodsHistoryDelete'); //我的足迹删除一条
Route::get('/user_goods_history_clear', 'UserGoodsHistoryController@userGoodsHistoryClear'); //我的足迹清空
Route::post('/user_goods_history_delete', 'UserGoodsHistoryController@userGoodsHistoryDelete'); //我的足迹删除一条
Route::post('/user_goods_history_clear', 'UserGoodsHistoryController@userGoodsHistoryClear'); //我的足迹清空
//商品评价
Route::get('/goods_comment_list', 'CommentController@goodsCommentList'); //商品评价列表

Loading…
Cancel
Save