validate()){ return $this->getModelError(); } if(is_array($this->faq_id)){ foreach ($this->faq_id as $faq_id){ $model = Faq::findOne([ 'id' => $faq_id, 'is_delete' => 0, 'status' => Faq::STATUS_TRASH, 'cx_mch_id' => $this->cx_mch_id ]); if($model == null) continue; $model->is_delete = 1; if(!$model->save()){ return $this->getModelError($model); } } } else { $model = Faq::findOne([ 'id' => $this->faq_id, 'is_delete' => 0, 'status' => Faq::STATUS_TRASH, 'cx_mch_id' => $this->cx_mch_id ]); if($model == null){ return $this->apiReturnError('帮助不存在或已经删除'); } $model->is_delete = 1; if(!$model->save()){ return $this->getModelError($model); } } return $this->apiReturnSuccess("删除成功"); } public function publish() { if(!$this->validate()){ return $this->getModelError(); } if(is_array($this->faq_id)){ foreach ($this->faq_id as $faq_id){ $model = Faq::findOne([ 'id' => $faq_id, 'is_delete' => 0, 'status' => Faq::STATUS_DRAFT, 'cx_mch_id' => $this->cx_mch_id ]); if($model == null) continue; $model->status = Faq::STATUS_PUBLISHED; if(empty($model->published_at)){ $model->published_at = time(); } if(!$model->save()){ return $this->getModelError($model); } } } else { $model = Faq::findOne([ 'id' => $this->faq_id, 'is_delete' => 0, 'status' => Faq::STATUS_DRAFT, 'cx_mch_id' => $this->cx_mch_id ]); if($model == null){ return $this->apiReturnError('帮助不存在或已经删除'); } $model->status = Faq::STATUS_PUBLISHED; if(empty($model->published_at)){ $model->published_at = time(); } if(!$model->save()){ return $this->getModelError($model); } } return $this->apiReturnSuccess("发布成功"); } public function trash() { if(!$this->validate()){ return $this->getModelError(); } if(is_array($this->faq_id)){ foreach ($this->faq_id as $faq_id){ $model = Faq::findOne([ 'id' => $faq_id, 'is_delete' => 0, 'status' => [Faq::STATUS_DRAFT, Faq::STATUS_PUBLISHED], 'cx_mch_id' => $this->cx_mch_id ]); if($model == null) continue; $model->status = Faq::STATUS_TRASH; if(!$model->save()){ return $this->getModelError($model); } } } else { $model = Faq::findOne([ 'id' => $this->faq_id, 'is_delete' => 0, 'status' => [Faq::STATUS_DRAFT, Faq::STATUS_PUBLISHED], 'cx_mch_id' => $this->cx_mch_id ]); if($model == null){ return $this->apiReturnError('帮助不存在或已经删除'); } $model->status = Faq::STATUS_TRASH; if(!$model->save()){ return $this->getModelError($model); } } return $this->apiReturnSuccess("操作成功"); } public function cancel_trash() { if(!$this->validate()){ return $this->getModelError(); } if(is_array($this->faq_id)){ foreach ($this->faq_id as $faq_id){ $model = Faq::findOne([ 'id' => $faq_id, 'is_delete' => 0, 'status' => Faq::STATUS_TRASH, 'cx_mch_id' => $this->cx_mch_id ]); if($model == null) continue; $model->status = Faq::STATUS_DRAFT; if(!$model->save()){ return $this->getModelError($model); } } } else { $model = Faq::findOne([ 'id' => $this->faq_id, 'is_delete' => 0, 'status' => Faq::STATUS_TRASH, 'cx_mch_id' => $this->cx_mch_id ]); if($model == null){ return $this->apiReturnError('帮助不存在或已经删除'); } $model->status = Faq::STATUS_DRAFT; if(!$model->save()){ return $this->getModelError($model); } } return $this->apiReturnSuccess("操作成功"); } public function hot() { if(!$this->validate()){ return $this->getModelError(); } if(is_array($this->faq_id)){ foreach ($this->faq_id as $faq_id){ $model = Faq::findOne([ 'id' => $faq_id, 'is_delete' => 0, 'is_hot' => 0, 'cx_mch_id' => $this->cx_mch_id ]); if($model == null) continue; $model->is_hot = 1; if(!$model->save()){ return $this->getModelError($model); } } } else { $model = Faq::findOne([ 'id' => $this->faq_id, 'is_delete' => 0, 'is_hot' => 0, 'cx_mch_id' => $this->cx_mch_id ]); if($model == null){ return $this->apiReturnError('帮助不存在或已经删除'); } $model->is_hot = 1; if(!$model->save()){ return $this->getModelError($model); } } return $this->apiReturnSuccess("设置成功"); } public function cancel_hot() { if(!$this->validate()){ return $this->getModelError(); } if(is_array($this->faq_id)){ foreach ($this->faq_id as $faq_id){ $model = Faq::findOne([ 'id' => $faq_id, 'is_delete' => 0, 'is_hot' => 1, 'cx_mch_id' => $this->cx_mch_id ]); if($model == null) continue; $model->is_hot = 0; if(!$model->save()){ return $this->getModelError($model); } } } else { $model = Faq::findOne([ 'id' => $this->faq_id, 'is_delete' => 0, 'is_hot' => 1, 'cx_mch_id' => $this->cx_mch_id ]); if($model == null){ return $this->apiReturnError('帮助不存在或已经删除'); } $model->is_hot = 0; if(!$model->save()){ return $this->getModelError($model); } } return $this->apiReturnSuccess("设置成功"); } public function detail() { if(!$this->validate()){ return $this->getModelError(); } $form = new CommonFaqListForm(); $form->scenario = 'detail'; $form->faq_id = $this->faq_id; $form->cx_mch_id = $this->cx_mch_id; $form->status = Faq::STATUS_PUBLISHED; $res = $form->search(); if($res['code'] != 0) return $res; if(count($res['data']) == 0) return $this->apiReturnError('帮助详情不存在'); Faq::setViewedNum($this->faq_id, $this->cx_mch_id); $data = $res['data'][0]; return $this->apiReturnSuccess('ok',$data); } }