|
@@ -4,7 +4,7 @@ namespace app\api\controller;
|
|
|
|
|
|
use app\common\model\Address as AddressModel;
|
|
|
use app\common\model\Area;
|
|
|
-
|
|
|
+use app\common\Enum\StatusEnum;
|
|
|
/**
|
|
|
* 地址
|
|
|
*/
|
|
@@ -38,7 +38,7 @@ class Address extends Base
|
|
|
*/
|
|
|
public function def_address()
|
|
|
{
|
|
|
- $row = AddressModel::where('user_id', $this->auth->id)->where('isdefault', 1)->find();
|
|
|
+ $row = AddressModel::where('user_id', $this->auth->id)->where('is_default', 1)->find();
|
|
|
if (!$row) {
|
|
|
$this->error('未找到记录');
|
|
|
}
|
|
@@ -51,9 +51,25 @@ class Address extends Base
|
|
|
$id = $this->request->post('id');
|
|
|
$address = $this->request->post('address');
|
|
|
$area_id = $this->request->post('area_id');
|
|
|
- $isdefault = $this->request->post('isdefault');
|
|
|
+ $isdefault = $this->request->post('is_default');
|
|
|
$mobile = $this->request->post('mobile');
|
|
|
$receiver = $this->request->post('receiver');
|
|
|
+
|
|
|
+ // 增加 验证器
|
|
|
+ $validate = new \app\api\validate\Address();
|
|
|
+ $data_to_validate = [
|
|
|
+ 'receiver' => $receiver,
|
|
|
+ 'mobile' => $mobile,
|
|
|
+ 'address' => $address,
|
|
|
+ 'area_id' => $area_id,
|
|
|
+ 'is_default' => $isdefault,
|
|
|
+ ];
|
|
|
+
|
|
|
+ // 验证数据
|
|
|
+ $scene = $id ? 'edit' : 'add';
|
|
|
+ if (!$validate->scene($scene)->check($data_to_validate)) {
|
|
|
+ $this->error($validate->getError());
|
|
|
+ }
|
|
|
$area = Area::field('a.id,a.zipcode,c.id as city_id,p.id as province_id')
|
|
|
->alias('a')
|
|
|
->join('shop_area c', 'a.pid=c.id')
|
|
@@ -70,7 +86,7 @@ class Address extends Base
|
|
|
|
|
|
$data = [
|
|
|
'address' => $address,
|
|
|
- 'isdefault' => $isdefault,
|
|
|
+ 'is_default' => $isdefault,
|
|
|
'mobile' => $mobile,
|
|
|
'receiver' => $receiver,
|
|
|
'area_id' => $area_id,
|
|
@@ -78,10 +94,12 @@ class Address extends Base
|
|
|
'city_id' => $area['city_id'],
|
|
|
'province_id' => $area['province_id'],
|
|
|
'zipcode' => $area['zipcode'],
|
|
|
- 'status' => 'normal'
|
|
|
+ 'status' => StatusEnum::ENABLED
|
|
|
];
|
|
|
if ($id) { //编辑
|
|
|
- $row = AddressModel::where('id', $id)->where('user_id', $this->auth->id)->find();
|
|
|
+ $row = AddressModel::where('id', $id)
|
|
|
+ ->where('user_id', $this->auth->id)
|
|
|
+ ->find();
|
|
|
if (!$row) {
|
|
|
$this->error('未找到记录');
|
|
|
}
|