| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- <?php
- namespace addons\Community\api\modules\v1\controllers;
- use addons\Community\common\service\HeadService;
- use api\controllers\OnAuthController;
- use common\models\common\Region;
- use Yii;
- class SettingController extends OnAuthController
- {
- public $modelClass = '';
- /**
- * 不用进行登录验证的方法
- *
- * 例如: ['index', 'update', 'create', 'view', 'delete']
- * 默认全部需要验证
- *
- * @var array
- */
- protected $authOptional = [];
- public function actionEdit()
- {
- $data = Yii::$app->request->post();
- $valid = Yii::$app->services->validate->validate($data, [
- [['intro', 'street', 'name', 'logo', 'license_img'], 'string'],
- [['province_id', 'city_id', 'district_id', 'contact_phone'], 'integer'],
- [['lng', 'lat'], 'number'],
- [['contact_phone', 'intro', 'street', 'province_id', 'city_id', 'district_id', 'lng', 'lat', 'name'], 'required'],
- [['id_card_img'], 'safe']
- ], [
- 'contact_phone' => '手机号码',
- 'intro' => '自提点介绍',
- 'name' => '自提点名称',
- 'province_id' => '省份',
- 'city_id' => '城市',
- 'district_id' => '区县',
- 'lng' => '经度',
- 'lat' => '纬度',
- 'license_img' => '营业执照',
- 'street' => '详细地址',
- 'logo' => 'Logo',
- 'id_card_img' => '证件照片'
- ]);
- if ($valid === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- if (empty($data['id_card_img'])) return $this->error('证件照片不能为空');
- if (!is_array($data['id_card_img'])) return $this->error('证件照片格式错误');
- if (count($data['id_card_img']) != 2) return $this->error('证件照片数量错误');
- $regions = Region::find()->where(['in', 'id', [$data['province_id'], $data['city_id'], $data['district_id']]])
- ->select('name,id,parent_id,level')->orderBy('id asc')->asArray()->all();
- if (count($regions) != 3) return $this->error('地区错误');
- $regions = array_reduce($regions, function (&$regions, $val) {
- $regions[$val['id']] = $val;
- return $regions;
- });
- $province = $regions[$data['province_id']] ?? '';
- if (empty($province)) return $this->error('省份不存在');
- $city = $regions[$data['city_id']] ?? '';
- if (empty($city)) return $this->error('城市不存在');
- $district = $regions[$data['district_id']] ?? '';
- if (empty($district)) return $this->error('区县不存在');
- $data['street'] = "{$province['name']}{$city['name']}{$district['name']}{$data['street']}";
- $ret = (new HeadService())->update($this->mall_id, $data, $this->user_id);
- return is_string($ret) ? $this->error($ret) : $this->success('修改成功');
- }
- /**
- * 获取详情
- * @return mixed|null
- */
- public function actionDetail()
- {
- $ret = (new HeadService())->detail($this->mall_id, $this->user_id);
- return is_string($ret) ? $this->error($ret) : $this->success('获取成功', $ret);
- }
-
- }
|