validate()){ return $this->getModelError(); } if(is_array($this->cat_id)){ foreach ($this->cat_id as $cat_id){ $model = Cat2::findOne([ 'cx_mch_id' => $this->cx_mch_id, 'id' => $cat_id, 'is_delete' => 0, 'type' => $this->type ]); if($model == null) continue; $model->is_delete = 1; $model->deleted_at = time(); if(!$model->save()){ return $this->getModelError($model); } } } else { $model = Cat2::findOne([ 'cx_mch_id' => $this->cx_mch_id, 'id' => $this->cat_id, 'is_delete' => 0, 'type' => $this->type ]); if($model == null) return $this->apiReturnError('分类不存在或已经删除'); $model->is_delete = 1; $model->deleted_at = time(); if(!$model->save()){ return $this->getModelError($model); } } return $this->apiReturnSuccess('操作成功'); } public function open() { if(!$this->validate()){ return $this->getModelError(); } if(is_array($this->cat_id)){ foreach ($this->cat_id as $cat_id){ $model = Cat2::findOne([ 'cx_mch_id' => $this->cx_mch_id, 'id' => $cat_id, 'is_delete' => 0, 'type' => $this->type, 'status' => 0 ]); if($model == null) continue; $model->status = 1; if(!$model->save()){ return $this->getModelError($model); } } } else { $model = Cat2::findOne([ 'cx_mch_id' => $this->cx_mch_id, 'id' => $this->cat_id, 'is_delete' => 0, 'type' => $this->type, 'status' => 0 ]); if($model == null) return $this->apiReturnError('分类不存在或已经删除'); $model->status = 1; if(!$model->save()){ return $this->getModelError($model); } } return $this->apiReturnSuccess('操作成功'); } public function close() { if(!$this->validate()){ return $this->getModelError(); } if(is_array($this->cat_id)){ foreach ($this->cat_id as $cat_id){ $model = Cat2::findOne([ 'cx_mch_id' => $this->cx_mch_id, 'id' => $cat_id, 'is_delete' => 0, 'type' => $this->type, 'status' => 1 ]); if($model == null) continue; $model->status = 0; if(!$model->save()){ return $this->getModelError($model); } } } else { $model = Cat2::findOne([ 'cx_mch_id' => $this->cx_mch_id, 'id' => $this->cat_id, 'is_delete' => 0, 'type' => $this->type, 'status' => 1 ]); if($model == null) return $this->apiReturnError('分类不存在或已经删除'); $model->status = 0; if(!$model->save()){ return $this->getModelError($model); } } return $this->apiReturnSuccess('操作成功'); } public function show() { if(!$this->validate()){ return $this->getModelError(); } if(is_array($this->cat_id)){ foreach ($this->cat_id as $cat_id){ $model = Cat2::findOne([ 'cx_mch_id' => $this->cx_mch_id, 'id' => $cat_id, 'is_delete' => 0, 'type' => $this->type, 'is_hide' => 1 ]); if($model == null) continue; $model->is_hide = 0; if(!$model->save()){ return $this->getModelError($model); } } } else { $model = Cat2::findOne([ 'cx_mch_id' => $this->cx_mch_id, 'id' => $this->cat_id, 'is_delete' => 0, 'type' => $this->type, 'is_hide' => 1 ]); if($model == null) return $this->apiReturnError('分类不存在或已经删除'); $model->is_hide = 0; if(!$model->save()){ return $this->getModelError($model); } } return $this->apiReturnSuccess('操作成功'); } public function hide() { if(!$this->validate()){ return $this->getModelError(); } if(is_array($this->cat_id)){ foreach ($this->cat_id as $cat_id){ $model = Cat2::findOne([ 'cx_mch_id' => $this->cx_mch_id, 'id' => $cat_id, 'is_delete' => 0, 'type' => $this->type, 'is_hide' => 0 ]); if($model == null) continue; $model->is_hide = 1; if(!$model->save()){ return $this->getModelError($model); } } } else { $model = Cat2::findOne([ 'cx_mch_id' => $this->cx_mch_id, 'id' => $this->cat_id, 'is_delete' => 0, 'type' => $this->type, 'is_hide' => 0 ]); if($model == null) return $this->apiReturnError('分类不存在或已经删除'); $model->is_hide = 1; if(!$model->save()){ return $this->getModelError($model); } } return $this->apiReturnSuccess('操作成功'); } }