From ba6e179988ee0d8db1a879af72ab4549d54ced47 Mon Sep 17 00:00:00 2001 From: devil_gong Date: Mon, 8 Apr 2019 15:19:46 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A2=E5=8D=95=E6=8F=90=E4=BA=A4=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E5=9C=B0=E5=9D=80=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/service/UserService.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/application/service/UserService.php b/application/service/UserService.php index 67133384a..e814ea9ca 100755 --- a/application/service/UserService.php +++ b/application/service/UserService.php @@ -390,11 +390,24 @@ class UserService $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; + } + } + + // 没有默认地址将第一个设置为默认地址 + if($is_default === false) + { + $data[0]['is_default'] = true; } } return DataReturn('操作成功', 0, $data); @@ -472,6 +485,14 @@ class UserService 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; }