Browse Source

收货地址修改

master
林一峰 7 years ago
parent
commit
b19fe97388
  1. 3
      app/Common/ReturnCode.php
  2. 34
      app/Http/Controllers/Weixin/AddressController.php
  3. 12
      app/Http/Model/UserAddress.php
  4. 17
      public/js/weixin/mobile.js
  5. 2
      resources/views/weixin/address/index.blade.php
  6. 68
      resources/views/weixin/address/userAddressAdd.blade.php
  7. 269
      resources/views/weixin/address/userAddressUpdate.blade.php

3
app/Common/ReturnCode.php

@ -6,5 +6,6 @@ class ReturnCode
//通用
const SUCCESS = '操作成功'; //操作成功
const FAIL = '操作失败'; //操作失败
const SUCCESS_CODE = 0;
const NO_FOUND = '您访问的页面不存在';
const SUCCESS_CODE = 0;
}

34
app/Http/Controllers/Weixin/AddressController.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 AddressController extends CommonController
{
@ -48,7 +49,7 @@ class AddressController extends CommonController
$html .= '<p class="f-h-adr-title"><label>'.$v['name'].'</label><span class="ect-colory">'.$v['mobile'].'</span></p>';
}
$html .= '<p class="f-h-adr-con">'.$v['province'].$v['city'].$v['district'].' '.$v['address'].'</p>';
$html .= '<p class="f-h-adr-con">'.$v['province_name'].$v['city_name'].$v['district_name'].' '.$v['address'].'</p>';
$html .= '<div class="adr-edit-del"><a href="'.route('weixin_user_address_update',array('id'=>$v['id'])).'"><i class="iconfont icon-bianji"></i>编辑</a><a href="javascript:del('.$v['id'].');"><i class="iconfont icon-xiao10"></i>删除</a></div>';
$html .= '</div>';
}
@ -63,25 +64,24 @@ class AddressController extends CommonController
//收货地址添加
public function userAddressAdd(Request $request)
{
if($request->input('typeid', '') != ''){$data['typeid'] = $request->input('typeid');}
if($request->input('tuijian', '') != ''){$data['tuijian'] = $request->input('tuijian');}
if($request->input('keyword', '') != ''){$data['keyword'] = $request->input('keyword');}
if($request->input('status', '') != ''){$data['status'] = $request->input('status');}
if($request->input('is_promote', '') != ''){$data['is_promote'] = $request->input('is_promote');}
if($request->input('orderby', '') != ''){$data['orderby'] = $request->input('orderby');}
if($request->input('max_price', '') != ''){$data['max_price'] = $request->input('max_price');}else{$data['max_price'] = 99999;}
if($request->input('min_price', '') != ''){$data['min_price'] = $request->input('min_price');}else{$data['min_price'] = 0;}
return view('weixin.address.userAddressAdd');
}
//收货地址修改
public function userAddressUpdate(Request $request)
{
$id = $request->input('id','');
if($id == ''){$this->error_jump(ReturnCode::NO_FOUND,route('weixin'),3);}
//商品列表
$postdata = array(
'access_token' => $_SESSION['weixin_user_info']['access_token'],
'limit' => 10,
'offset' => 0
'id' => $_REQUEST['id'],
'access_token' => $_SESSION['weixin_user_info']['access_token']
);
$url = env('APP_API_URL')."/user_address_list";
$goods_list = curl_request($url,$postdata,'GET');
$data['user_address_list'] = $goods_list['data']['list'];
$url = env('APP_API_URL')."/user_address_detail";
$res = curl_request($url,$postdata,'GET');
$data['post'] = $res['data'];
return view('weixin.address.userAddressAdd', $data);
return view('weixin.address.userAddressUpdate',$data);
}
}

12
app/Http/Model/UserAddress.php

@ -36,13 +36,13 @@ class UserAddress extends BaseModel
if($res['list'])
{
/* foreach($res['list'] as $k=>$v)
foreach($res['list'] as $k=>$v)
{
$res['list'][$k]['country_name'] = Region::getRegionName($v['country']);
$res['list'][$k]['province_name'] = Region::getRegionName($v['province']);
$res['list'][$k]['city_name'] = Region::getRegionName($v['city']);
$res['list'][$k]['district_name'] = Region::getRegionName($v['district']);
} */
}
}
}
else
@ -62,13 +62,13 @@ class UserAddress extends BaseModel
{
$arr = self::where('id',$address_id)->first();
/* if($arr)
if($arr)
{
$arr->country_name = Region::getRegionName($arr->country);
$arr->province_name = Region::getRegionName($arr->province);
$arr->city_name = Region::getRegionName($arr->city);
$arr->district_name = Region::getRegionName($arr->district);
} */
}
return $arr;
}
@ -80,13 +80,13 @@ class UserAddress extends BaseModel
->where('user.id',$user_id)->select('user_address.id','user_address.name','country','province','city','district','address','user_address.mobile','zipcode')
->first();
/* if($arr)
if($arr)
{
$arr->country_name = Region::getRegionName($arr->country);
$arr->province_name = Region::getRegionName($arr->province);
$arr->city_name = Region::getRegionName($arr->city);
$arr->district_name = Region::getRegionName($arr->district);
} */
}
}
return $arr;

17
public/js/weixin/mobile.js

@ -24,4 +24,21 @@ function delconfirm(url,des)
layer.close(index);
}
});
}
//手机号验证
function validatemobile(mobile)
{
if(mobile.length == 0 || mobile.length != 11)
{
return false;
}
var reg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
if(!reg.test(mobile))
{
return false;
}
return true;
}

2
resources/views/weixin/address/index.blade.php

@ -37,7 +37,7 @@
<?php if($list){foreach($list as $k=>$v){ ?>
<div class="flow-have-adr">
<p class="f-h-adr-title"><label><?php echo $v['name']; ?></label><span class="ect-colory"><?php echo $v['mobile']; ?></span><?php if($v['is_default']==1){ ?><span class="fr">默认</span><?php } ?></p>
<p class="f-h-adr-con"><?php echo $v['province'].$v['city'].$v['district'].' '.$v['address']; ?></p>
<p class="f-h-adr-con"><?php echo $v['province_name'].$v['city_name'].$v['district_name'].' '.$v['address']; ?></p>
<div class="adr-edit-del"><a href="<?php echo route('weixin_user_address_update',array('id'=>$v['id'])); ?>"><i class="iconfont icon-bianji"></i>编辑</a><a href="javascript:del(<?php echo $v['id']; ?>);"><i class="iconfont icon-xiao10"></i>删除</a></div>
</div>
<?php }} ?>

68
resources/views/weixin/address/userAddressAdd.blade.php

@ -22,22 +22,10 @@
<style>
.adr_add{margin:0 10px;}
.adr-form-group{margin-top:10px;}
.adr-form-group input[type=text],.adr-form-group textarea{
display: block;
width: 100%;
font-size:16px;
padding:10px;
color: #777;
vertical-align: middle;
background-color: #fff;
background-image: none;
border: 1px solid #ddd;
border-radius: 0;box-sizing:border-box;
}
.adr-form-group input[type=text],.adr-form-group textarea{display: block;width: 100%;font-size:16px;padding:10px;color: #777;vertical-align: middle;background-color: #fff;background-image: none;border: 1px solid #ddd;border-radius: 0;box-sizing:border-box;}
.adr-form-group select{padding:5px;margin-right:10px;}
.bottoma{display:block;font-size:18px;padding:10px;color:white;background-color: #f23030;text-align:center;}
</style>
<div class="adr_add">
<div class="adr-form-group">
<label for="doc-ipt-email-1">收货人</label>
@ -195,13 +183,61 @@ function adr_dosubmit()
var mobile = $("#mobile").val();
var address = $("#address").val();
var province = '福建';
var city = '厦门';
var district = '湖里';
var province = $("#sheng").val();
var city = $("#shi").val();
var district = $("#qu").val();
var is_default = 0;
if(document.getElementById("is_default").checked){is_default = 1;}
if(name == '')
{
//提示
layer.open({
content: '姓名不能为空'
,skin: 'msg'
,time: 2 //2秒后自动关闭
});
return false;
}
if(mobile == '')
{
//提示
layer.open({
content: '手机号不能为空'
,skin: 'msg'
,time: 2 //2秒后自动关闭
});
return false;
}
if(validatemobile(mobile) == false)
{
//提示
layer.open({
content: '手机号格式不正确'
,skin: 'msg'
,time: 2 //2秒后自动关闭
});
return false;
}
if(address == '')
{
//提示
layer.open({
content: '地址不能为空'
,skin: 'msg'
,time: 2 //2秒后自动关闭
});
return false;
}
$.post(url,{access_token:access_token,name:name,mobile:mobile,address:address,province:province,city:city,district:district,is_default:is_default},function(res)
{
if(res.code==0)

269
resources/views/weixin/address/userAddressUpdate.blade.php

@ -0,0 +1,269 @@
<!DOCTYPE html><html><head><meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<title>收货地址编辑</title><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>
<script type="text/javascript" src="<?php echo env('APP_URL'); ?>/js/weixin/mobile.js"></script>
<meta name="keywords" content="关键词"><meta name="description" content="描述"></head><body style="background-color:#f1f1f1;">
<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);"><img src="<?php echo env('APP_URL'); ?>/images/weixin/class1.png" alt="菜单"></a></div>
</div>
<div class="flool tpnavf cl">
<div class="nav_list">
<ul>
<a href="index.html"><li><img src="<?php echo env('APP_URL'); ?>/images/weixin/home_icon.png"><p>首页</p></li></a>
<a href="/Weixin/index.php?m=Store&amp;a=index"><li><img src="<?php echo env('APP_URL'); ?>/images/weixin/brand_icon.png"><p>分类</p></li></a>
<a href="/Weixin/index.php?m=Cart&amp;a=index"><li><img src="<?php echo env('APP_URL'); ?>/images/weixin/car_icon.png"><p>购物车</p></li></a>
<a href="/Weixin/index.php?m=User&amp;a=index"><li><img src="<?php echo env('APP_URL'); ?>/images/weixin/center_icon.png"><p>个人中心</p></li></a></ul>
<div class="cl"></div>
</div>
</div>
<style>
.adr_add{margin:0 10px;}
.adr-form-group{margin-top:10px;}
.adr-form-group input[type=text],.adr-form-group textarea{display: block;width: 100%;font-size:16px;padding:10px;color: #777;vertical-align: middle;background-color: #fff;background-image: none;border: 1px solid #ddd;border-radius: 0;box-sizing:border-box;}
.adr-form-group select{padding:5px;margin-right:10px;}
.bottoma{display:block;font-size:18px;padding:10px;color:white;background-color: #f23030;text-align:center;}
</style>
<div class="adr_add">
<div class="adr-form-group">
<label for="doc-ipt-email-1">收货人</label>
<input name="name" type="text" class="" id="name" placeholder="输入姓名" value="<?php echo $post['name']; ?>">
</div>
<div class="adr-form-group">
<label for="doc-ipt-email-1">手机号码</label>
<input type="text" name="mobile" class="" id="mobile" placeholder="输入手机号码" value="<?php echo $post['mobile']; ?>">
</div>
<div class="adr-form-group">
地区: <select id='sheng'></select><select id='shi'></select><select id='qu'></select>
<script>
// JavaScript Document
$(document).ready(function(e) {
//加载省的数据
LoadSheng(86,<?php echo $post['province']; ?>);
//加载市的数据
LoadShi(<?php echo $post['province']; ?>,<?php echo $post['city']; ?>);
//加载区的数据
LoadQu(<?php echo $post['city']; ?>,<?php echo $post['district']; ?>);
//给省的下拉加点击事件
$("#sheng").change(function(){
//重新加载市
LoadShi();
//重新加载区
LoadQu();
});
//给市的下拉加点击事件
$("#shi").change(function(){
//重新加载区
LoadQu();
});
});
//加载省份的方法
function LoadSheng(parent_id,select_id)
{
//省的父级代号
parent_id = parent_id || '86';
select_id = select_id || 0;
$.ajax({
async:false,
url:'<?php echo env('APP_API_URL')."/region_list"; ?>',
data:{id:parent_id},
type:"GET",
dataType:"json",
success: function(res){
var hang = res.data;
var str = "";
for(var i=0;i<hang.length;i++)
{
if(select_id != 0 && select_id == hang[i].id)
{
str = str+"<option selected='selected' value='"+hang[i].id+"'>"+hang[i].name+"</option>";
}
else
{
str = str+"<option value='"+hang[i].id+"'>"+hang[i].name+"</option>";
}
}
$("#sheng").html(str);
}
});
}
//加载市的方法
function LoadShi(parent_id,select_id)
{
//找市的父级代号
parent_id = parent_id || $("#sheng").val();
select_id = select_id || 0;
$.ajax({
async:false,
url:'<?php echo env('APP_API_URL')."/region_list"; ?>',
data:{id:parent_id},
type:"GET",
dataType:"json",
success: function(res){
var hang = res.data;
var str = "";
for(var i=0;i<hang.length;i++)
{
if(select_id != 0 && select_id == hang[i].id)
{
str = str+"<option selected='selected' value='"+hang[i].id+"'>"+hang[i].name+"</option>";
}
else
{
str = str+"<option value='"+hang[i].id+"'>"+hang[i].name+"</option>";
}
}
$("#shi").html(str);
}
});
}
//加载区的方法
function LoadQu(parent_id,select_id)
{
//找区的父级代号
parent_id = parent_id || $("#shi").val();
select_id = select_id || 0;
$.ajax({
url:'<?php echo env('APP_API_URL')."/region_list"; ?>',
data:{id:parent_id},
type:"GET",
dataType:"json",
success: function(res){
var hang = res.data;
var str = "";
for(var i=0;i<hang.length;i++)
{
if(select_id != 0 && select_id == hang[i].id)
{
str = str+"<option selected='selected' value='"+hang[i].id+"'>"+hang[i].name+"</option>";
}
else
{
str = str+"<option value='"+hang[i].id+"'>"+hang[i].name+"</option>";
}
}
$("#qu").html(str);
}
});
}
</script>
</div>
<div class="adr-form-group">
<label for="doc-ta-1">详细地址</label>
<textarea name="address" class="" rows="3" id="address"><?php echo $post['address']; ?></textarea>
</div>
<div class="adr-form-group">
<label>
<input type="checkbox" name="is_default" id="is_default" <?php if($post['is_default']==1){echo 'checked="checked"';} ?>> 设为默认
</label>
</div>
</div>
<a style="margin:10px;" class="bottoma" href="javascript:adr_dosubmit();">提交</a>
<script type="text/javascript" src="<?php echo env('APP_URL'); ?>/js/layer/mobile/layer.js"></script>
<script>
function adr_dosubmit()
{
var access_token = '<?php echo $_SESSION['weixin_user_info']['access_token']; ?>';
var url = '<?php echo env('APP_API_URL').'/user_address_add'; ?>';
var name = $("#name").val();
var mobile = $("#mobile").val();
var address = $("#address").val();
var province = $("#sheng").val();
var city = $("#shi").val();
var district = $("#qu").val();
var is_default = 0;
if(document.getElementById("is_default").checked){is_default = 1;}
if(name == '')
{
//提示
layer.open({
content: '姓名不能为空'
,skin: 'msg'
,time: 2 //2秒后自动关闭
});
return false;
}
if(mobile == '')
{
//提示
layer.open({
content: '手机号不能为空'
,skin: 'msg'
,time: 2 //2秒后自动关闭
});
return false;
}
if(validatemobile(mobile) == false)
{
//提示
layer.open({
content: '手机号格式不正确'
,skin: 'msg'
,time: 2 //2秒后自动关闭
});
return false;
}
if(address == '')
{
//提示
layer.open({
content: '地址不能为空'
,skin: 'msg'
,time: 2 //2秒后自动关闭
});
return false;
}
$.post(url,{access_token:access_token,name:name,mobile:mobile,address:address,province:province,city:city,district:district,is_default:is_default},function(res)
{
if(res.code==0)
{
//提示
layer.open({
content: res.msg
,skin: 'msg'
,time: 2 //2秒后自动关闭
});
window.history.back();
}
else
{
//提示
layer.open({
content: res.msg
,skin: 'msg'
,time: 2 //2秒后自动关闭
});
var url = "http://www.baidu.com";
location.href = url;
}
},'json');
}
</script>
</body></html>
Loading…
Cancel
Save