feat/task1-c-wallet
parent
712cc5c3e6
commit
9bd62fc3b4
|
|
@ -5,7 +5,6 @@ Page({
|
|||
province_list: [],
|
||||
city_list: [],
|
||||
county_list: [],
|
||||
|
||||
province_id: null,
|
||||
city_id: null,
|
||||
county_id: null,
|
||||
|
|
@ -22,7 +21,7 @@ Page({
|
|||
},
|
||||
|
||||
onShow() {
|
||||
if((this.data.params.address_id || null) == null)
|
||||
if((this.data.params.id || null) == null)
|
||||
{
|
||||
var title = app.data.common_pages_title.user_address_save_add;
|
||||
} else {
|
||||
|
|
@ -43,7 +42,7 @@ Page({
|
|||
return false;
|
||||
} else {
|
||||
// 获取地址数据
|
||||
if((this.data.params.address_id || null) != null)
|
||||
if((this.data.params.id || null) != null)
|
||||
{
|
||||
this.get_user_address();
|
||||
}
|
||||
|
|
@ -61,7 +60,7 @@ Page({
|
|||
my.showLoading({ content: "加载中..." });
|
||||
|
||||
my.httpRequest({
|
||||
url: app.get_request_url("GetDetail", "UserAddress"),
|
||||
url: app.get_request_url("Detail", "UserAddress"),
|
||||
method: "POST",
|
||||
data: self.data.params,
|
||||
dataType: "json",
|
||||
|
|
@ -276,14 +275,14 @@ Page({
|
|||
form_data["province"] = data.province_id;
|
||||
form_data["city"] = data.city_id;
|
||||
form_data["county"] = data.county_id;
|
||||
form_data["address_id"] = self.data.params.address_id || 0;
|
||||
form_data["id"] = self.data.params.id || 0;
|
||||
|
||||
if (app.fields_check(form_data, validation)) {
|
||||
// 加载loding
|
||||
my.showLoading({ content: "处理中..." });
|
||||
|
||||
my.httpRequest({
|
||||
url: app.get_request_url("Edit", "UserAddress"),
|
||||
url: app.get_request_url("Save", "UserAddress"),
|
||||
method: "POST",
|
||||
data: form_data,
|
||||
dataType: "json",
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
<text>设为默认地址</text>
|
||||
</view>
|
||||
<button class="fr cr-666 delete-submit" type="default" size="mini" onTap="address_delete_event" data-index="{{index}}" data-value="{{item.id}}" hover-class="none">删除</button>
|
||||
<navigator url="/pages/user-address-save/user-address-save?address_id={{item.id}}" open-type="navigate" hover-class="none">
|
||||
<navigator url="/pages/user-address-save/user-address-save?id={{item.id}}" open-type="navigate" hover-class="none">
|
||||
<button class="fr cr-666" type="default" size="mini" onTap="address_edit_event" hover-class="none">编辑</button>
|
||||
</navigator>
|
||||
</view>
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ Page({
|
|||
|
||||
// 获取数据
|
||||
my.httpRequest({
|
||||
url: app.get_request_url("GetList", "UserAddress"),
|
||||
url: app.get_request_url("Index", "UserAddress"),
|
||||
method: "POST",
|
||||
data: {},
|
||||
dataType: "json",
|
||||
|
|
@ -134,7 +134,7 @@ Page({
|
|||
my.httpRequest({
|
||||
url: app.get_request_url("Delete", "UserAddress"),
|
||||
method: "POST",
|
||||
data: {address_id: value},
|
||||
data: {id: value},
|
||||
dataType: "json",
|
||||
success: res => {
|
||||
my.hideLoading();
|
||||
|
|
@ -202,7 +202,7 @@ Page({
|
|||
my.httpRequest({
|
||||
url: app.get_request_url("SetDefault", "UserAddress"),
|
||||
method: "POST",
|
||||
data: {address_id: value},
|
||||
data: {id: value},
|
||||
dataType: "json",
|
||||
success: res => {
|
||||
my.hideLoading();
|
||||
|
|
|
|||
|
|
@ -43,34 +43,12 @@ class UserAddressController extends CommonController
|
|||
* @date 2018-07-18
|
||||
* @desc description
|
||||
*/
|
||||
public function GetDetail()
|
||||
public function Detail()
|
||||
{
|
||||
// 请求参数
|
||||
$params = [
|
||||
[
|
||||
'checked_type' => 'empty',
|
||||
'key_name' => 'address_id',
|
||||
'error_msg' => '地址ID不能为空',
|
||||
]
|
||||
];
|
||||
$ret = params_checked($this->data_post, $params);
|
||||
if($ret !== true)
|
||||
{
|
||||
$this->ajaxReturn($ret);
|
||||
}
|
||||
|
||||
// 获取数据
|
||||
$field = 'id,alias,name,tel,province,city,county,address,lng,lat,is_default';
|
||||
$where = ['user_id'=>$this->user['id'], 'is_delete_time'=>0, 'id'=>intval($this->data_post['address_id'])];
|
||||
$data = M('UserAddress')->where($where)->field($field)->find();
|
||||
if(!empty($address))
|
||||
{
|
||||
$data['province_name'] = ResourcesService::RegionName($data['province']);
|
||||
$data['city_name'] = ResourcesService::RegionName($data['city']);
|
||||
$data['county_name'] = ResourcesService::RegionName($data['county']);
|
||||
}
|
||||
|
||||
$this->ajaxReturn(L('common_operation_success'), 0, $data);
|
||||
$params = $this->data_post;
|
||||
$params['user'] = $this->user;
|
||||
$ret = UserService::UserAddressRow($params);
|
||||
$this->ajaxReturn($ret['msg'], $ret['code'], $ret['data']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -81,106 +59,26 @@ class UserAddressController extends CommonController
|
|||
* @date 2018-07-18
|
||||
* @desc description
|
||||
*/
|
||||
public function GetList()
|
||||
public function Index()
|
||||
{
|
||||
$field = 'id,alias,name,tel,province,city,county,address,lng,lat,is_default';
|
||||
$where = ['user_id'=>$this->user['id'], 'is_delete_time'=>0];
|
||||
$data = M('UserAddress')->where($where)->field($field)->order('id desc')->select();
|
||||
if(!empty($data))
|
||||
{
|
||||
foreach($data as &$v)
|
||||
{
|
||||
$v['province_name'] = ResourcesService::RegionName($v['province']);
|
||||
$v['city_name'] = ResourcesService::RegionName($v['city']);
|
||||
$v['county_name'] = ResourcesService::RegionName($v['county']);
|
||||
}
|
||||
}
|
||||
$this->ajaxReturn(L('common_operation_success'), 0, $data);
|
||||
$data = UserService::UserAddressList(['user'=>$this->user]);
|
||||
$this->ajaxReturn(L('common_operation_success'), 0, $data['data']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户地址编辑
|
||||
* 用户地址保存
|
||||
* @author Devil
|
||||
* @blog http://gong.gg/
|
||||
* @version 1.0.0
|
||||
* @date 2018-07-18
|
||||
* @desc description
|
||||
*/
|
||||
public function Edit()
|
||||
public function Save()
|
||||
{
|
||||
// 请求参数
|
||||
$params = [
|
||||
[
|
||||
'checked_type' => 'empty',
|
||||
'key_name' => 'name',
|
||||
'error_msg' => '姓名不能为空',
|
||||
],
|
||||
[
|
||||
'checked_type' => 'empty',
|
||||
'key_name' => 'tel',
|
||||
'error_msg' => '联系电话不能为空',
|
||||
],
|
||||
[
|
||||
'checked_type' => 'empty',
|
||||
'key_name' => 'province',
|
||||
'error_msg' => '省不能为空',
|
||||
],
|
||||
[
|
||||
'checked_type' => 'empty',
|
||||
'key_name' => 'city',
|
||||
'error_msg' => '城市不能为空',
|
||||
],
|
||||
[
|
||||
'checked_type' => 'empty',
|
||||
'key_name' => 'county',
|
||||
'error_msg' => '区/县不能为空',
|
||||
],
|
||||
[
|
||||
'checked_type' => 'empty',
|
||||
'key_name' => 'address',
|
||||
'error_msg' => '详细地址不能为空',
|
||||
]
|
||||
];
|
||||
$ret = params_checked($this->data_post, $params);
|
||||
if($ret !== true)
|
||||
{
|
||||
$this->ajaxReturn($ret);
|
||||
}
|
||||
|
||||
$m = M('UserAddress');
|
||||
if(!empty($this->data_post['address_id']))
|
||||
{
|
||||
$where = ['user_id' => $this->user['id'], 'id'=>$this->data_post['address_id']];
|
||||
$temp = $m->where($where)->find();
|
||||
}
|
||||
|
||||
$data = [
|
||||
'name' => I('name'),
|
||||
'tel' => I('tel'),
|
||||
'province' => I('province'),
|
||||
'city' => I('city'),
|
||||
'county' => I('county'),
|
||||
'address' => I('address'),
|
||||
];
|
||||
if(empty($temp))
|
||||
{
|
||||
$data['user_id'] = $this->user['id'];
|
||||
$data['add_time'] = time();
|
||||
if($m->add($data) > 0)
|
||||
{
|
||||
$this->ajaxReturn(L('common_operation_add_success'), 0);
|
||||
} else {
|
||||
$this->ajaxReturn(L('common_operation_add_error'));
|
||||
}
|
||||
} else {
|
||||
$data['upd_time'] = time();
|
||||
if($m->where($where)->save($data))
|
||||
{
|
||||
$this->ajaxReturn(L('common_operation_update_success'), 0);
|
||||
} else {
|
||||
$this->ajaxReturn(L('common_operation_update_error'));
|
||||
}
|
||||
}
|
||||
$params = $this->data_post;
|
||||
$params['user'] = $this->user;
|
||||
$ret = UserService::UserAddressSave($params);
|
||||
$this->ajaxReturn($ret['msg'], $ret['code'], $ret['data']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -193,29 +91,10 @@ class UserAddressController extends CommonController
|
|||
*/
|
||||
public function Delete()
|
||||
{
|
||||
// 请求参数
|
||||
$params = [
|
||||
[
|
||||
'checked_type' => 'empty',
|
||||
'key_name' => 'address_id',
|
||||
'error_msg' => '地址ID不能为空',
|
||||
]
|
||||
];
|
||||
$ret = params_checked($this->data_post, $params);
|
||||
if($ret !== true)
|
||||
{
|
||||
$this->ajaxReturn($ret);
|
||||
}
|
||||
|
||||
// 软删除数据
|
||||
$where = ['user_id' => $this->user['id'], 'id'=>$this->data_post['address_id']];
|
||||
$data = ['is_delete_time' => time()];
|
||||
if(M('UserAddress')->where($where)->save($data))
|
||||
{
|
||||
$this->ajaxReturn(L('common_operation_delete_success'), 0);
|
||||
} else {
|
||||
$this->ajaxReturn(L('common_operation_delete_error'), -100);
|
||||
}
|
||||
$params = $this->data_post;
|
||||
$params['user'] = $this->user;
|
||||
$ret = UserService::UserAddressDelete($params);
|
||||
$this->ajaxReturn($ret['msg'], $ret['code'], $ret['data']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -228,39 +107,10 @@ class UserAddressController extends CommonController
|
|||
*/
|
||||
public function SetDefault()
|
||||
{
|
||||
// 请求参数
|
||||
$params = [
|
||||
[
|
||||
'checked_type' => 'empty',
|
||||
'key_name' => 'address_id',
|
||||
'error_msg' => '地址ID不能为空',
|
||||
]
|
||||
];
|
||||
$ret = params_checked($this->data_post, $params);
|
||||
if($ret !== true)
|
||||
{
|
||||
$this->ajaxReturn($ret);
|
||||
}
|
||||
|
||||
// 模型
|
||||
$m = M('UserAddress');
|
||||
|
||||
// 开启事务
|
||||
$m->startTrans();
|
||||
|
||||
// 先全部设置为0 再将当前设置为1
|
||||
$all_status = $m->where(['user_id' => $this->user['id']])->save(['is_default'=>0]);
|
||||
$my_status = $m->where(['user_id' => $this->user['id'], 'id'=>$this->data_post['address_id']])->save(['is_default'=>1]);
|
||||
if($all_status && $my_status)
|
||||
{
|
||||
// 提交事务
|
||||
$m->commit();
|
||||
$this->ajaxReturn(L('common_operation_set_success'), 0);
|
||||
} else {
|
||||
// 回滚事务
|
||||
$m->rollback();
|
||||
$this->ajaxReturn(L('common_operation_delete_error'), -100);
|
||||
}
|
||||
$params = $this->data_post;
|
||||
$params['user'] = $this->user;
|
||||
$ret = UserService::UserAddressDefault($params);
|
||||
$this->ajaxReturn($ret['msg'], $ret['code'], $ret['data']);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue