100], [['is_hide'], 'default', 'value' => 0], [['status'], 'default', 'value' => 1], [['model'], 'safe'], [['type', 'parent_id', 'cx_mch_id', 'name', ], 'required'], ]; } public function attributeLabels() { return [ 'cx_mch_id' => '平台商户ID', 'type' => '类型', 'name' => '名称', 'desc' => '描述', 'img_url' => '图片', 'parent_id' => '父ID', 'sort' => '排序,默认100,升序', 'status' => '是否启用,0=否,1=是', 'is_hide' => '是否隐藏,0=否,1=是', 'big_img_url' => '大图', 'advert_pic' => '广告图', 'advert_url' => '广告链接', 'advert_url_type' => '广告链接类型', 'advert_open_params' => '广告链接打开参数', ]; } public function save() { if(!$this->validate()){ return $this->getModelError(); } if($this->model->isNewRecord){ $this->model->is_delete = 0; $this->model->cx_mch_id = $this->cx_mch_id; $this->model->type = $this->type; $this->model->created_at = time(); } if(!empty($this->parent_id)){ //父节点是否存在 $temp = Cat::findOne([ 'id' => $this->parent_id, 'type' => $this->type, 'cx_mch_id' => $this->cx_mch_id, 'is_delete' => 0 ]); if($temp == null){ return $this->apiReturnError('父节点不存在'); } if(!$this->model->isNewRecord && $this->model->id == $temp->id){ return $this->apiReturnError('父节点不能为本身'); } } else { $this->parent_id = 0; } $this->model->name = $this->name; $this->model->img_url = $this->img_url; $this->model->desc = $this->desc == null ? $this->name : $this->desc; $this->model->parent_id = $this->parent_id; $this->model->sort = $this->sort; $this->model->status = $this->status; $this->model->is_hide = $this->is_hide; $this->model->big_img_url = $this->big_img_url; $this->model->advert_pic = $this->advert_pic; $this->model->advert_url = $this->advert_url; $this->model->advert_url_type = $this->advert_url_type; $this->model->advert_open_params = $this->advert_open_params; if(!$this->model->save()){ return $this->getModelError($this->model); } return $this->apiReturnSuccess('保存成功'); } }