@@ -39,10 +39,12 @@ class Address extends Base
public function def_address()
{
$row = AddressModel::where('user_id', $this->auth->id)->where('is_default', 1)->find();
- if (!$row) {
- $this->error('未找到记录');
+ $arrReturn = [];
+ if ($row) {
+ $arrReturn = $row->toArray();
}
- $this->success('获取成功', $row);
+
+ $this->success('获取成功', $arrReturn);
//添加(编辑)地址
@@ -41,7 +41,19 @@ class Address extends Model
$info->save();
- //$row['address'] = $row->address_full;
+ //新增时 第一个地址 默认地址
+ if (empty($row['id'])) {
+ $count = self::where('user_id', $row['user_id'])->count();
+ if ($count == 0) {
+ $row->is_default = 1;
+ }
+ } else {
+ // 编辑时,如果只有一个地址,强制设为默认
+ if ($count == 1) {
});
public function getCityAttr($value, $data)