diff --git a/service/Application/Home/Controller/UserAddressController.class.php b/service/Application/Home/Controller/UserAddressController.class.php index 7529ade9e..ed4202155 100644 --- a/service/Application/Home/Controller/UserAddressController.class.php +++ b/service/Application/Home/Controller/UserAddressController.class.php @@ -3,6 +3,7 @@ namespace Home\Controller; use Service\BuyService; +use Service\UserService; /** * 用户地址管理 @@ -67,13 +68,88 @@ class UserAddressController extends CommonController { $data = array(); } else { - $data = M('Article')->find(I('id')); + $params = $_REQUEST; + $params['user'] = $this->user; + $data = UserService::UserAddressRow($params); } - $this->assign('data', $data); - - // 地区 - + $this->assign('data', $data['data']); $this->display('SaveInfo'); } + + /** + * [Save 用户地址保存] + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @datetime 2018-09-23T22:36:18+0800 + */ + public function Save() + { + $params = $_POST; + $params['user'] = $this->user; + $ret = UserService::UserAddressSave($params); + $this->ajaxReturn($ret['msg'], $ret['code'], $ret['data']); + } + + /** + * 删除地址 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2018-07-18 + * @desc description + */ + public function Delete() + { + $params = $_POST; + $params['user'] = $this->user; + $ret = UserService::UserAddressDelete($params); + $this->ajaxReturn($ret['msg'], $ret['code'], $ret['data']); + } + + /** + * 默认地址设置 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2018-07-18 + * @desc description + */ + public function SetDefault() + { + // 请求参数 + $params = [ + [ + 'checked_type' => 'empty', + 'key_name' => 'address_id', + 'error_msg' => '地址ID不能为空', + ] + ]; + $ret = params_checked($_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'=>$_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); + } + } } ?> \ No newline at end of file diff --git a/service/Application/Home/View/Default/Buy/Index.html b/service/Application/Home/View/Default/Buy/Index.html index ad9073353..51babbb34 100644 --- a/service/Application/Home/View/Default/Buy/Index.html +++ b/service/Application/Home/View/Default/Buy/Index.html @@ -25,7 +25,7 @@