50], [['phone'], 'string', 'max' => 20], [['ratio'], 'integer', 'min' => 0,'max' => 100], [['province', 'city', 'region','begin_time', 'end_time',], 'string', 'max' => 20], [['location_detail'], 'string', 'max' => 255], [['name', 'province_id', 'city_id', 'region_id', 'location_detail', 'begin_time', 'end_time','area','phone'], 'required'], ]; } public function attributeLabels() { return [ 'id' => 'ID', 'name' => '门店名称', 'province' => '省', 'province_id' => '省ID', 'city' => '市', 'city_id' => '市ID', 'region' => '区', 'region_id' => '区ID', 'location_detail' => '门店具体位置', 'begin_time' => '营业开始时间', 'end_time' => '营业结束时间', 'status' => '1-营业 0-停业', 'sort' => '排序', 'created_at' => '添加时间', 'updated_at' => '修改时间', 'is_delete' => '是否删除,0=否,1=是', 'deleted_at' => '删除时间', 'ratio' => '收益比例', 'area' => '区域坐标', 'phone' => '客服电话', ]; } public function edit() { if(!$this->validate()){ return $this->getModelError(); } if($this->model->isNewRecord){ $this->model->is_delete = 0; $this->model->deleted_at = 0; $this->model->sort = '100'; $this->model->created_at = time(); } $this->model->name = $this->name; $this->model->location_detail = $this->location_detail; $this->model->begin_time = $this->begin_time; $this->model->end_time = $this->end_time; $this->model->updated_at = time(); $province = District::findOne($this->province_id); if(empty($province)){ return Model::asReturnError('用户所在省级行政区未找到'); } $city = District::findOne($this->city_id); if(empty($city)){ return Model::asReturnError('用户所在市级行政区未找到'); } $region = District::findOne($this->region_id); if(empty($region)){ return Model::asReturnError('用户所在区/县级行政区未找到'); } $area_json = []; $area_arr = json_decode($this->area,true); foreach ($area_arr as $index => $item){ $area_json[$item['area_type']] = $item; } $this->model->province = $province->name; $this->model->city = $city->name; $this->model->region = $region->name; $this->model->province_id = $province->id; $this->model->city_id = $city->id; $this->model->region_id = $region->id; $this->model->ratio = $this->ratio; $this->model->area = json_encode($area_json,JSON_UNESCAPED_UNICODE); $this->model->lat = strval($area_json['store']['paths'][0]['lat']); $this->model->lng = strval($area_json['store']['paths'][0]['lng']); $this->model->phone = $this->phone; if(!$this->model->save()){ return $this->getModelError($this->model); } // 存入数据表 $redis_name = \Yii::$app->params['cacheKeyPrefix'].":api:store:zset"; try{ \Yii::$app->redis->geoadd($redis_name,$this->model->lat,$this->model->lng,$this->model->id); }catch (\Exception $e){ } // 删除城市缓存 $obj = new StoreCityForm(); $cache_name = $obj->getCacheName(); FlashStorage::deleteCache($cache_name); return $this->apiReturnSuccess('保存成功'); } }