From 54764fe7f26efbcd631dc9bc8c98e767ef913d9d Mon Sep 17 00:00:00 2001 From: devil Date: Mon, 21 Sep 2020 16:03:38 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=9C=B0=E5=9D=80=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=9C=8D=E5=8A=A1=E5=B1=82=E5=88=86=E7=A6=BB=EF=BC=8C?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=99=BE=E5=BA=A6=E5=B0=8F=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?=E5=9C=B0=E5=9D=80=E5=AF=BC=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/api/controller/Useraddress.php | 26 +- application/index/controller/Buy.php | 3 +- application/index/controller/Useraddress.php | 12 +- application/service/BuyService.php | 3 +- application/service/GoodsService.php | 40 +- application/service/UserAddressService.php | 590 ++++++++++++++++++ application/service/UserService.php | 350 ----------- sourcecode/alipay/app.js | 2 +- sourcecode/baidu/app.js | 2 +- .../baidu/pages/user-address/user-address.css | 8 + .../baidu/pages/user-address/user-address.js | 45 +- .../pages/user-address/user-address.swan | 13 +- sourcecode/qq/app.js | 2 +- sourcecode/toutiao/app.js | 2 +- sourcecode/weixin/app.js | 2 +- 15 files changed, 719 insertions(+), 381 deletions(-) create mode 100644 application/service/UserAddressService.php diff --git a/application/api/controller/Useraddress.php b/application/api/controller/Useraddress.php index d3452f44d..fb63eb5a0 100755 --- a/application/api/controller/Useraddress.php +++ b/application/api/controller/Useraddress.php @@ -10,7 +10,7 @@ // +---------------------------------------------------------------------- namespace app\api\controller; -use app\service\UserService; +use app\service\UserAddressService; use app\service\ConfigService; /** @@ -50,7 +50,7 @@ class UserAddress extends Common { $params = $this->data_post; $params['user'] = $this->user; - return UserService::UserAddressRow($params); + return UserAddressService::UserAddressRow($params); } /** @@ -63,7 +63,7 @@ class UserAddress extends Common */ public function Index() { - return UserService::UserAddressList(['user'=>$this->user]); + return UserAddressService::UserAddressList(['user'=>$this->user]); } @@ -79,7 +79,7 @@ class UserAddress extends Common { $params = $this->data_post; $params['user'] = $this->user; - return UserService::UserAddressSave($params); + return UserAddressService::UserAddressSave($params); } /** @@ -94,7 +94,7 @@ class UserAddress extends Common { $params = $this->data_post; $params['user'] = $this->user; - return UserService::UserAddressDelete($params); + return UserAddressService::UserAddressDelete($params); } /** @@ -109,7 +109,7 @@ class UserAddress extends Common { $params = $this->data_post; $params['user'] = $this->user; - return UserService::UserAddressDefault($params); + return UserAddressService::UserAddressDefault($params); } /** @@ -125,5 +125,19 @@ class UserAddress extends Common return ConfigService::SiteTypeExtractionAddressList(); } + /** + * 外部系统地址添加 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2020-09-21 + * @desc description + */ + public function OutSystemAdd() + { + $params = $this->data_post; + $params['user'] = $this->user; + return UserAddressService::OutSystemUserAddressAdd($params); + } } ?> \ No newline at end of file diff --git a/application/index/controller/Buy.php b/application/index/controller/Buy.php index e3cd8a2b1..315787489 100755 --- a/application/index/controller/Buy.php +++ b/application/index/controller/Buy.php @@ -13,6 +13,7 @@ namespace app\index\controller; use think\facade\Hook; use app\service\GoodsService; use app\service\UserService; +use app\service\UserAddressService; use app\service\PaymentService; use app\service\BuyService; @@ -83,7 +84,7 @@ class Buy extends Common $buy_goods = $buy_ret['data']['goods']; // 用户地址 - $address = UserService::UserAddressList(['user'=>$this->user]); + $address = UserAddressService::UserAddressList(['user'=>$this->user]); $this->assign('user_address_list', $address['data']); // 支付方式 diff --git a/application/index/controller/Useraddress.php b/application/index/controller/Useraddress.php index df3cf9c7b..f17b11d4d 100755 --- a/application/index/controller/Useraddress.php +++ b/application/index/controller/Useraddress.php @@ -11,7 +11,7 @@ namespace app\index\controller; use app\service\SeoService; -use app\service\UserService; +use app\service\UserAddressService; /** * 用户地址管理 @@ -48,7 +48,7 @@ class UserAddress extends Common public function Index() { // 用户地址列表 - $data = UserService::UserAddressList(['user'=>$this->user]); + $data = UserAddressService::UserAddressList(['user'=>$this->user]); $this->assign('user_address_list', $data['data']); // 浏览器名称 @@ -74,7 +74,7 @@ class UserAddress extends Common { $params = $this->data_request; $params['user'] = $this->user; - $ret = UserService::UserAddressRow($params); + $ret = UserAddressService::UserAddressRow($params); $data = $ret['data']; } @@ -95,7 +95,7 @@ class UserAddress extends Common { $params = input('post.'); $params['user'] = $this->user; - return UserService::UserAddressSave($params); + return UserAddressService::UserAddressSave($params); } /** @@ -110,7 +110,7 @@ class UserAddress extends Common { $params = $_POST; $params['user'] = $this->user; - return UserService::UserAddressDelete($params); + return UserAddressService::UserAddressDelete($params); } /** @@ -125,7 +125,7 @@ class UserAddress extends Common { $params = $_POST; $params['user'] = $this->user; - return UserService::UserAddressDefault($params); + return UserAddressService::UserAddressDefault($params); } } ?> \ No newline at end of file diff --git a/application/service/BuyService.php b/application/service/BuyService.php index 2da652605..a574e169d 100755 --- a/application/service/BuyService.php +++ b/application/service/BuyService.php @@ -14,6 +14,7 @@ use think\Db; use think\facade\Hook; use app\service\GoodsService; use app\service\UserService; +use app\service\UserAddressService; use app\service\ResourcesService; use app\service\PaymentService; use app\service\ConfigService; @@ -723,7 +724,7 @@ class BuyService { $address_params['where'] = ['id' => $params['address_id']]; } - $ads = UserService::UserDefaultAddress($address_params); + $ads = UserAddressService::UserDefaultAddress($address_params); if(!empty($ads['data'])) { $address = $ads['data']; diff --git a/application/service/GoodsService.php b/application/service/GoodsService.php index cd5afbfcc..f75f9005c 100755 --- a/application/service/GoodsService.php +++ b/application/service/GoodsService.php @@ -1007,6 +1007,7 @@ class GoodsService } // 是否成功 + $status = false; if(isset($goods_id) && $goods_id > 0) { // 分类 @@ -1063,13 +1064,33 @@ class GoodsService return $ret; } - // 提交事务 - Db::commit(); - return DataReturn('操作成功', 0); + // 操作成功 + $status = true; } - // 回滚事务 - Db::rollback(); + // 事务处理 + if($status) + { + Db::commit(); + } else { + Db::rollback(); + } + + // 商品保存后钩子 + $hook_name = 'plugins_service_goods_save_end'; + Hook::listen($hook_name, [ + 'hook_name' => $hook_name, + 'is_backend' => true, + 'params' => $params, + 'data' => $data, + 'goods_id' => $goods_id, + ]); + + // 返回信息 + if($status) + { + return DataReturn('操作成功', 0); + } return DataReturn('操作失败', -100); } @@ -1687,6 +1708,15 @@ class GoodsService return DataReturn('相册删除失败', -100); } + // 商品删除钩子 + $hook_name = 'plugins_service_goods_delete'; + Hook::listen($hook_name, [ + 'hook_name' => $hook_name, + 'is_backend' => true, + 'params' => $params, + 'data_ids' => $params['ids'], + ]); + // 提交事务 Db::commit(); return DataReturn('删除成功', 0); diff --git a/application/service/UserAddressService.php b/application/service/UserAddressService.php new file mode 100644 index 000000000..c785a5915 --- /dev/null +++ b/application/service/UserAddressService.php @@ -0,0 +1,590 @@ + 'empty', + 'key_name' => 'user', + 'error_msg' => '用户信息有误', + ], + ]; + $ret = ParamsChecked($params, $p); + if($ret !== true) + { + return DataReturn($ret, -1); + } + + $where = (!empty($params['where']) && is_array($params['where'])) ? $params['where'] : []; + $where['user_id'] = $params['user']['id']; + $where['is_delete_time'] = 0; + + // 获取用户地址 + $field = 'id,alias,name,tel,province,city,county,address,lng,lat,is_default'; + $data = Db::name('UserAddress')->where($where)->field($field)->order('id desc')->select(); + if(!empty($data)) + { + $is_default = false; + foreach($data as &$v) + { + // 地区 + $v['province_name'] = RegionService::RegionName($v['province']); + $v['city_name'] = RegionService::RegionName($v['city']); + $v['county_name'] = RegionService::RegionName($v['county']); + + // 是否有默认地址 + if($is_default === false && $v['is_default'] == 1) + { + $is_default = true; + } + } + + // 是否处理默认地址,没有默认地址将第一个设置为默认地址 + $is_default_handle = isset($params['is_default_handle']) ? intval($params['is_default_handle']) : 1; + if($is_default === false && $is_default_handle == 1) + { + $data[0]['is_default'] = true; + } + } + + // 用户地址列表钩子 + $hook_name = 'plugins_service_user_address_list'; + Hook::listen($hook_name, [ + 'hook_name' => $hook_name, + 'is_backend' => true, + 'params' => $params, + 'data' => &$data, + 'user_id' => $params['user']['id'], + ]); + + return DataReturn('操作成功', 0, $data); + } + + /** + * 获取地址详情 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2018-08-29 + * @desc description + * @param [array] $params [输入参数] + */ + public static function UserAddressRow($params = []) + { + // 请求参数 + $p = [ + [ + 'checked_type' => 'empty', + 'key_name' => 'id', + 'error_msg' => '地址id不能为空', + ], + [ + 'checked_type' => 'empty', + 'key_name' => 'user', + 'error_msg' => '用户信息有误', + ], + ]; + $ret = ParamsChecked($params, $p); + if($ret !== true) + { + return DataReturn($ret, -1); + } + + // 获取用户地址 + $params['where'] = [ + 'id' => intval($params['id']), + ]; + $params['is_default_handle'] = 0; + $ret = self::UserAddressList($params); + if(!empty($ret['data'][0])) + { + $ret['data'] = $ret['data'][0]; + } + return $ret; + } + + /** + * 用户默认地址 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2018-08-29 + * @desc description + * @param [array] $params [输入参数] + */ + public static function UserDefaultAddress($params = []) + { + // 请求参数 + $p = [ + [ + 'checked_type' => 'empty', + 'key_name' => 'user', + 'error_msg' => '用户信息有误', + ], + ]; + $ret = ParamsChecked($params, $p); + if($ret !== true) + { + return DataReturn($ret, -1); + } + + // 获取用户地址 + $params['where'] = empty($params['where']) ? ['is_default'=>1] : $params['where']; + $ret = self::UserAddressList($params); + $data = []; + if(!empty($ret['data'][0])) + { + $data = $ret['data'][0]; + } else { + // 没有默认地址则读取第一条作为默认地址 + unset($params['where']); + $ret = self::UserAddressList($params); + if(!empty($ret['data'][0])) + { + $data = $ret['data'][0]; + } + } + + // 用户默认地址钩子 + $hook_name = 'plugins_service_user_address_default_row'; + Hook::listen($hook_name, [ + 'hook_name' => $hook_name, + 'is_backend' => true, + 'params' => $params, + 'data' => &$data, + 'user_id' => $params['user']['id'], + ]); + + return DataReturn('获取成功', 0, $data); + } + + /** + * 用户地址保存 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2018-08-29 + * @desc description + * @param [array] $params [输入参数] + */ + public static function UserAddressSave($params = []) + { + // 参数校验 + $ret = self::UserAddressSaveParamsCheck($params); + if($ret['code'] != 0) + { + return $ret; + } + + if(!empty($params['id'])) + { + $where = ['user_id' => $params['user']['id'], 'id'=>$params['id']]; + $temp = Db::name('UserAddress')->where($where)->find(); + } + + // 操作数据 + $is_default = isset($params['is_default']) ? intval($params['is_default']) : 0; + $data = [ + 'name' => $params['name'], + 'tel' => $params['tel'], + 'province' => $params['province'], + 'city' => $params['city'], + 'county' => $params['county'], + 'address' => $params['address'], + 'is_default' => $is_default, + ]; + if(!empty($params['alias'])) + { + $data['alias'] = $params['alias']; + } + if(!empty($params['lng'])) + { + $data['lng'] = floatval($params['lng']); + } + if(!empty($params['lat'])) + { + $data['lat'] = floatval($params['lat']); + } + + // 用户地址保存前钩子 + $hook_name = 'plugins_service_user_address_save_begin'; + $ret = HookReturnHandle(Hook::listen($hook_name, [ + 'hook_name' => $hook_name, + 'is_backend' => true, + 'params' => $params, + 'data' => &$data, + 'user_id' => $params['user']['id'], + ])); + if(isset($ret['code']) && $ret['code'] != 0) + { + return $ret; + } + + Db::startTrans(); + + // 默认地址处理 + if($is_default == 1) + { + Db::name('UserAddress')->where(['user_id'=>$params['user']['id'], 'is_default'=>1])->update(['is_default'=>0]); + } + + // 添加/更新数据 + $status = false; + $msg = '操作失败'; + if(empty($temp)) + { + $data['user_id'] = $params['user']['id']; + $data['add_time'] = time(); + if(Db::name('UserAddress')->insertGetId($data) > 0) + { + $status = true; + $msg = '新增成功'; + } else { + $msg = '新增失败'; + } + } else { + $data['upd_time'] = time(); + if(Db::name('UserAddress')->where($where)->update($data)) + { + $status = true; + $msg = '更新成功'; + } else { + $msg = '更新失败'; + } + } + + // 事务处理 + if($status) + { + Db::commit(); + } else { + Db::rollback(); + } + + // 用户地址保存后钩子 + $hook_name = 'plugins_service_user_address_save_end'; + Hook::listen($hook_name, [ + 'hook_name' => $hook_name, + 'is_backend' => true, + 'params' => $params, + 'data' => $data, + 'user_id' => $params['user']['id'], + ]); + + return DataReturn($msg, $status ? 0 : -100); + } + + /** + * 地址保存参数校验 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2020-09-21 + * @desc description + * @param [array] $params [输入参数] + */ + private static function UserAddressSaveParamsCheck($params = []) + { + // 请求参数 + $p = [ + [ + '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' => '详细地址不能为空', + ], + [ + 'checked_type' => 'empty', + 'key_name' => 'user', + 'error_msg' => '用户信息有误', + ], + ]; + $ret = ParamsChecked($params, $p); + if($ret !== true) + { + return DataReturn($ret, -1); + } + return DataReturn('success', 0); + } + + /** + * 用户地址删除 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2018-08-29 + * @desc description + * @param [array] $params [输入参数] + */ + public static function UserAddressDelete($params = []) + { + // 请求参数 + $p = [ + [ + 'checked_type' => 'empty', + 'key_name' => 'id', + 'error_msg' => '地址id不能为空', + ], + [ + 'checked_type' => 'empty', + 'key_name' => 'user', + 'error_msg' => '用户信息有误', + ], + ]; + $ret = ParamsChecked($params, $p); + if($ret !== true) + { + return DataReturn($ret, -1); + } + + // 软删除数据 + $where = ['user_id' => $params['user']['id'], 'id'=>$params['id']]; + $data = ['is_delete_time' => time()]; + if(Db::name('UserAddress')->where($where)->update($data)) + { + // 用户地址删除钩子 + $hook_name = 'plugins_service_user_address_delete'; + Hook::listen($hook_name, [ + 'hook_name' => $hook_name, + 'is_backend' => true, + 'params' => $params, + 'data_id' => $params['id'], + 'user_id' => $params['user']['id'], + ]); + + return DataReturn('删除成功', 0); + } else { + return DataReturn('删除失败或资源不存在', -100); + } + } + + /** + * 用户地址设置默认地址 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2018-09-25 + * @desc description + * @param [array] $params [输入参数] + */ + public static function UserAddressDefault($params = []) + { + // 请求参数 + $p = [ + [ + 'checked_type' => 'empty', + 'key_name' => 'id', + 'error_msg' => '地址id不能为空', + ], + [ + 'checked_type' => 'empty', + 'key_name' => 'user', + 'error_msg' => '用户信息有误', + ], + ]; + $ret = ParamsChecked($params, $p); + if($ret !== true) + { + return DataReturn($ret, -1); + } + + // 开启事务 + Db::startTrans(); + + // 先全部设置为0 再将当前设置为1 + $all_status = Db::name('UserAddress')->where(['user_id' => $params['user']['id']])->update(['is_default'=>0]); + $my_status = Db::name('UserAddress')->where(['user_id' => $params['user']['id'], 'id'=>$params['id']])->update(['is_default'=>1]); + if($all_status !== false && $my_status) + { + // 用户地址删除钩子 + $hook_name = 'plugins_service_user_address_default'; + Hook::listen($hook_name, [ + 'hook_name' => $hook_name, + 'is_backend' => true, + 'params' => $params, + 'data_id' => $params['id'], + 'user_id' => $params['user']['id'], + ]); + + // 提交事务 + Db::commit(); + return DataReturn('设置成功', 0); + } else { + // 回滚事务 + Db::rollback(); + return DataReturn('设置失败', -100); + } + } + + /** + * 外部系统地址添加 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2020-09-21 + * @desc description + * @param [array] $params [输入参数] + */ + public static function OutSystemUserAddressAdd($params = []) + { + // 参数校验 + $ret = self::UserAddressSaveParamsCheck($params); + if($ret['code'] != 0) + { + return $ret; + } + + // 省市区解析 + $province_name = $params['province']; + $city_name = $params['city']; + $county_name = $params['county']; + $town_name = isset($params['town']) ? $params['town'] : ''; + + // 开始匹配地址 + $field = 'id,name,level'; + + // 省匹配 + $search = ['市', '区']; + $where = [ + ['pid', '=', 0], + ['level', '=', 1], + ['name', 'like', str_replace($search, '', $province_name).'%'], + ]; + $province = Db::name('Region')->where($where)->field($field)->find(); + if(empty($province)) + { + return DataReturn('省匹配失败', -1); + } + + // 市匹配 + $where = [ + ['pid', '=', $province['id']], + ['level', '=', 2], + ]; + $search = ['自治州', '自治县', '特别行政区', '地区', '市', '县', '区']; + $where1 = $where; + $where1[] = ['name', 'like', str_replace($search, '', $city_name).'%']; + $city = Db::name('Region')->where($where1)->field($field)->find(); + if(empty($city)) + { + // 没查询到则使用县字段查询 + $where2 = $where; + $where2[] = ['name', 'like', str_replace($search, '', $county_name).'%']; + $city = Db::name('Region')->where($where2)->field($field)->find(); + if(empty($city)) + { + return DataReturn('市匹配失败', -1); + } + } + + // 区/县匹配 + $where = [ + ['pid', '=', $city['id']], + ['level', '=', 3], + ]; + $search = ['街道', '县', '镇']; + $where1 = $where; + $where1[] = ['name', 'like', str_replace($search, '', $county_name).'%']; + $county = Db::name('Region')->where($where1)->field($field)->find(); + if(empty($county) && !empty($town_name)) + { + // 没查询到则使用街道字段查询 + $where2 = $where; + $where2[] = ['name', 'like', str_replace($search, '', $town_name).'%']; + $county = Db::name('Region')->where($where2)->field($field)->find(); + } + if(empty($county)) + { + return DataReturn('区/县匹配失败', -1); + } + + // 地区id赋值 + $params['province'] = $province['id']; + $params['city'] = $city['id']; + $params['county'] = $county['id']; + + // 存在街道字段数据则拼接到详细地址前面 + if(!empty($town_name)) + { + $params['address'] = $town_name.$params['address']; + } + + // 地址存在则不重复添加 + $where = [ + 'name' => $params['name'], + 'tel' => $params['tel'], + 'province' => $params['province'], + 'city' => $params['city'], + 'county' => $params['county'], + 'address' => $params['address'], + 'user_id' => $params['user']['id'], + ]; + $address = Db::name('UserAddress')->where($where)->find(); + if(!empty($address)) + { + return DataReturn('地址已存在', -1); + } + + // 地址保存 + return self::UserAddressSave($params); + } +} +?> \ No newline at end of file diff --git a/application/service/UserService.php b/application/service/UserService.php index 9333e2f57..4c780b346 100755 --- a/application/service/UserService.php +++ b/application/service/UserService.php @@ -381,356 +381,6 @@ class UserService return DataReturn('删除失败', -100); } - /** - * 用户地址列表列表 - * @author Devil - * @blog http://gong.gg/ - * @version 1.0.0 - * @date 2018-08-29 - * @desc description - * @param [array] $params [输入参数] - */ - public static function UserAddressList($params = []) - { - // 请求参数 - $p = [ - [ - 'checked_type' => 'empty', - 'key_name' => 'user', - 'error_msg' => '用户信息有误', - ], - ]; - $ret = ParamsChecked($params, $p); - if($ret !== true) - { - return DataReturn($ret, -1); - } - - $where = (!empty($params['where']) && is_array($params['where'])) ? $params['where'] : []; - $where['user_id'] = $params['user']['id']; - $where['is_delete_time'] = 0; - - // 获取用户地址 - $field = 'id,alias,name,tel,province,city,county,address,lng,lat,is_default'; - $data = Db::name('UserAddress')->where($where)->field($field)->order('id desc')->select(); - if(!empty($data)) - { - $is_default = false; - foreach($data as &$v) - { - // 地区 - $v['province_name'] = RegionService::RegionName($v['province']); - $v['city_name'] = RegionService::RegionName($v['city']); - $v['county_name'] = RegionService::RegionName($v['county']); - - // 是否有默认地址 - if($is_default === false && $v['is_default'] == 1) - { - $is_default = true; - } - } - - // 是否处理默认地址,没有默认地址将第一个设置为默认地址 - $is_default_handle = isset($params['is_default_handle']) ? intval($params['is_default_handle']) : 1; - if($is_default === false && $is_default_handle == 1) - { - $data[0]['is_default'] = true; - } - } - return DataReturn('操作成功', 0, $data); - } - - /** - * [UserAddressRow 获取地址详情] - * @author Devil - * @blog http://gong.gg/ - * @version 1.0.0 - * @datetime 2018-09-23T23:19:25+0800 - * @param [array] $params [输入参数] - */ - public static function UserAddressRow($params = []) - { - // 请求参数 - $p = [ - [ - 'checked_type' => 'empty', - 'key_name' => 'id', - 'error_msg' => '地址id不能为空', - ], - [ - 'checked_type' => 'empty', - 'key_name' => 'user', - 'error_msg' => '用户信息有误', - ], - ]; - $ret = ParamsChecked($params, $p); - if($ret !== true) - { - return DataReturn($ret, -1); - } - - // 获取用户地址 - $params['where'] = [ - 'id' => intval($params['id']), - ]; - $params['is_default_handle'] = 0; - $ret = self::UserAddressList($params); - if(!empty($ret['data'][0])) - { - $ret['data'] = $ret['data'][0]; - } - return $ret; - } - - /** - * 用户默认地址 - * @author Devil - * @blog http://gong.gg/ - * @version 1.0.0 - * @date 2018-08-29 - * @desc description - * @param [array] $params [输入参数] - */ - public static function UserDefaultAddress($params = []) - { - // 请求参数 - $p = [ - [ - 'checked_type' => 'empty', - 'key_name' => 'user', - 'error_msg' => '用户信息有误', - ], - ]; - $ret = ParamsChecked($params, $p); - if($ret !== true) - { - return DataReturn($ret, -1); - } - - // 获取用户地址 - $params['where'] = empty($params['where']) ? ['is_default'=>1] : $params['where']; - $ret = self::UserAddressList($params); - if(!empty($ret['data'][0])) - { - $ret['data'] = $ret['data'][0]; - } else { - // 没有默认地址则读取第一条作为默认地址 - unset($params['where']); - $ret = self::UserAddressList($params); - if(!empty($ret['data'][0])) - { - $ret['data'] = $ret['data'][0]; - } - } - return $ret; - } - - /** - * [UserAddressSave 用户地址保存] - * @author Devil - * @blog http://gong.gg/ - * @version 1.0.0 - * @datetime 2018-09-23T22:28:31+0800 - * @param [array] $params [输入参数] - */ - public static function UserAddressSave($params = []) - { - // 请求参数 - $p = [ - [ - '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' => '详细地址不能为空', - ], - [ - 'checked_type' => 'empty', - 'key_name' => 'user', - 'error_msg' => '用户信息有误', - ], - ]; - $ret = ParamsChecked($params, $p); - if($ret !== true) - { - return DataReturn($ret, -1); - } - - if(!empty($params['id'])) - { - $where = ['user_id' => $params['user']['id'], 'id'=>$params['id']]; - $temp = Db::name('UserAddress')->where($where)->find(); - } - - // 操作数据 - $is_default = isset($params['is_default']) ? intval($params['is_default']) : 0; - $data = [ - 'name' => $params['name'], - 'tel' => $params['tel'], - 'province' => $params['province'], - 'city' => $params['city'], - 'county' => $params['county'], - 'address' => $params['address'], - 'is_default' => $is_default, - ]; - if(!empty($params['alias'])) - { - $data['alias'] = $params['alias']; - } - if(!empty($params['lng'])) - { - $data['lng'] = floatval($params['lng']); - } - if(!empty($params['lat'])) - { - $data['lat'] = floatval($params['lat']); - } - - Db::startTrans(); - - // 默认地址处理 - if($is_default == 1) - { - Db::name('UserAddress')->where(['user_id'=>$params['user']['id'], 'is_default'=>1])->update(['is_default'=>0]); - } - - // 添加/更新数据 - if(empty($temp)) - { - $data['user_id'] = $params['user']['id']; - $data['add_time'] = time(); - if(Db::name('UserAddress')->insertGetId($data) > 0) - { - Db::commit(); - return DataReturn('新增成功', 0); - } else { - Db::rollback(); - return DataReturn('新增失败'); - } - } else { - $data['upd_time'] = time(); - if(Db::name('UserAddress')->where($where)->update($data)) - { - Db::commit(); - return DataReturn('更新成功', 0); - } else { - Db::rollback(); - return DataReturn('更新失败'); - } - } - } - - /** - * [UserAddressDelete 用户地址删除] - * @author Devil - * @blog http://gong.gg/ - * @version 1.0.0 - * @datetime 2018-09-23T23:55:51+0800 - * @param [array] $params [输入参数] - */ - public static function UserAddressDelete($params = []) - { - // 请求参数 - $p = [ - [ - 'checked_type' => 'empty', - 'key_name' => 'id', - 'error_msg' => '地址id不能为空', - ], - [ - 'checked_type' => 'empty', - 'key_name' => 'user', - 'error_msg' => '用户信息有误', - ], - ]; - $ret = ParamsChecked($params, $p); - if($ret !== true) - { - return DataReturn($ret, -1); - } - - // 软删除数据 - $where = ['user_id' => $params['user']['id'], 'id'=>$params['id']]; - $data = ['is_delete_time' => time()]; - if(Db::name('UserAddress')->where($where)->update($data)) - { - return DataReturn('删除成功', 0); - } else { - return DataReturn('删除失败或资源不存在', -100); - } - } - - /** - * 用户地址设置默认地址 - * @author Devil - * @blog http://gong.gg/ - * @version 1.0.0 - * @date 2018-09-25 - * @desc description - * @param [array] $params [输入参数] - */ - public static function UserAddressDefault($params = []) - { - // 请求参数 - $p = [ - [ - 'checked_type' => 'empty', - 'key_name' => 'id', - 'error_msg' => '地址id不能为空', - ], - [ - 'checked_type' => 'empty', - 'key_name' => 'user', - 'error_msg' => '用户信息有误', - ], - ]; - $ret = ParamsChecked($params, $p); - if($ret !== true) - { - return DataReturn($ret, -1); - } - - // 开启事务 - Db::startTrans(); - - // 先全部设置为0 再将当前设置为1 - $all_status = Db::name('UserAddress')->where(['user_id' => $params['user']['id']])->update(['is_default'=>0]); - $my_status = Db::name('UserAddress')->where(['user_id' => $params['user']['id'], 'id'=>$params['id']])->update(['is_default'=>1]); - if($all_status !== false && $my_status) - { - // 提交事务 - Db::commit(); - return DataReturn('设置成功', 0); - } else { - // 回滚事务 - Db::rollback(); - return DataReturn('设置失败', -100); - } - } - /** * [UserLoginRecord 用户登录记录] * @author Devil diff --git a/sourcecode/alipay/app.js b/sourcecode/alipay/app.js index 21be504a1..ea53a6ec1 100644 --- a/sourcecode/alipay/app.js +++ b/sourcecode/alipay/app.js @@ -46,7 +46,7 @@ App({ "goods_search": "商品搜索", "goods_detail": "商品详情", "user_address": "我的地址", - "user_address_save_add": "新增地址", + "user_address_save_add": "添加地址", "user_address_save_edit": "编辑地址", "buy": "订单确认", "user_order": "我的订单", diff --git a/sourcecode/baidu/app.js b/sourcecode/baidu/app.js index 7d50aa906..8c96a1d01 100755 --- a/sourcecode/baidu/app.js +++ b/sourcecode/baidu/app.js @@ -46,7 +46,7 @@ App({ "goods_search": "商品搜索", "goods_detail": "商品详情", "user_address": "我的地址", - "user_address_save_add": "新增地址", + "user_address_save_add": "添加地址", "user_address_save_edit": "编辑地址", "buy": "订单确认", "user_order": "我的订单", diff --git a/sourcecode/baidu/pages/user-address/user-address.css b/sourcecode/baidu/pages/user-address/user-address.css index 38c61d6be..8cba6cfbe 100755 --- a/sourcecode/baidu/pages/user-address/user-address.css +++ b/sourcecode/baidu/pages/user-address/user-address.css @@ -33,4 +33,12 @@ } .page { padding-bottom: 85rpx; +} +.submit-list button { + width: 50%; +} +.submit-list .import-system-address-submit { + background: #07c160 !important; + right: 0; + left: auto; } \ No newline at end of file diff --git a/sourcecode/baidu/pages/user-address/user-address.js b/sourcecode/baidu/pages/user-address/user-address.js index a2c717206..f1ec1131b 100755 --- a/sourcecode/baidu/pages/user-address/user-address.js +++ b/sourcecode/baidu/pages/user-address/user-address.js @@ -209,7 +209,6 @@ Page({ }, fail: () => { swan.hideLoading(); - app.showToast("服务器请求出错"); } }); @@ -226,6 +225,48 @@ Page({ }); swan.navigateBack(); } - } + }, + + // 获取系统地址 + choose_system_address_event(e) { + var detail = e.detail; + var data = { + "name": detail.userName || '', + "tel": detail.telNumber || '', + "province": detail.provinceName || '', + "city": detail.cityName || '', + "county": detail.countyName || '', + "town": detail.townName || '', + "address": detail.detailInfo || '', + }; + + // 加载loding + swan.showLoading({ title: "处理中..." }); + + // 获取数据 + swan.request({ + url: app.get_request_url("outsystemadd", "useraddress"), + method: "POST", + data: data, + dataType: "json", + success: res => { + swan.hideLoading(); + if (res.data.code == 0) { + this.get_data_list(); + app.showToast(res.data.msg, "success"); + } else { + if (app.is_login_check(res.data)) { + app.showToast(res.data.msg); + } else { + app.showToast('提交失败,请重试!'); + } + } + }, + fail: () => { + swan.hideLoading(); + app.showToast("服务器请求出错"); + } + }); + }, }); \ No newline at end of file diff --git a/sourcecode/baidu/pages/user-address/user-address.swan b/sourcecode/baidu/pages/user-address/user-address.swan index 2395dd895..2b2c86342 100755 --- a/sourcecode/baidu/pages/user-address/user-address.swan +++ b/sourcecode/baidu/pages/user-address/user-address.swan @@ -30,11 +30,14 @@ - + - - - - + + + + + + + \ No newline at end of file diff --git a/sourcecode/qq/app.js b/sourcecode/qq/app.js index 7530d1984..eb61f50b1 100755 --- a/sourcecode/qq/app.js +++ b/sourcecode/qq/app.js @@ -46,7 +46,7 @@ App({ "goods_search": "商品搜索", "goods_detail": "商品详情", "user_address": "我的地址", - "user_address_save_add": "新增地址", + "user_address_save_add": "添加地址", "user_address_save_edit": "编辑地址", "buy": "订单确认", "user_order": "我的订单", diff --git a/sourcecode/toutiao/app.js b/sourcecode/toutiao/app.js index 1712fb2f6..8c073441e 100755 --- a/sourcecode/toutiao/app.js +++ b/sourcecode/toutiao/app.js @@ -46,7 +46,7 @@ App({ "goods_search": "商品搜索", "goods_detail": "商品详情", "user_address": "我的地址", - "user_address_save_add": "新增地址", + "user_address_save_add": "添加地址", "user_address_save_edit": "编辑地址", "buy": "订单确认", "user_order": "我的订单", diff --git a/sourcecode/weixin/app.js b/sourcecode/weixin/app.js index 0036ea296..481a271b6 100755 --- a/sourcecode/weixin/app.js +++ b/sourcecode/weixin/app.js @@ -46,7 +46,7 @@ App({ "goods_search": "商品搜索", "goods_detail": "商品详情", "user_address": "我的地址", - "user_address_save_add": "新增地址", + "user_address_save_add": "添加地址", "user_address_save_edit": "编辑地址", "buy": "订单确认", "user_order": "我的订单",