0], [['name', 'question', 'dateTime'], 'string', 'max' => 255], ]; } public function attributeLabels() { return [ 'name' => '名称' ]; } public function search() { $query = QAndAQuestionTemplate::find()->alias('ro')->where([ 'ro.is_delete' => 0, 'ro.store_id' => $this->store_id, ])->leftJoin(['c' => QAndACat::tableName()], 'ro.cat_id = c.id') ->orderBy('ro.id DESC'); if ($this->state >= 0) { $query->andWhere(['ro.state' => $this->state]); } if ($this->cat_id > 0) { $query->andWhere(['ro.cat_id' => $this->cat_id]); } if ($this->name) { $query->andWhere(['like', 'ro.name', $this->name]); } if ($this->dateTime) { $query->andWhere(['>=', 'ro.created_at', strtotime($this->dateTime[0])]); $query->andWhere(['<=', 'ro.created_at', strtotime($this->dateTime[1])]); } $query->select('ro.*, c.name cat_name'); $data = pagination_make($query); foreach ($data['list'] as &$item) { $item['created_at'] = date('Y-m-d H:i:s', $item['created_at']); } return [ 'code' => 0, 'data' => [ 'data' => $data['list'], 'pageNo' => $data['pageNo'], 'totalCount' => $data['totalCount'] ], 'sql' => $query->createCommand()->getRawSql(), ]; } public function save() { if (!$this->validate()) { return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0], ]; } $cloud = QAndAQuestionTemplate::findOne($this->id) ?: new QAndAQuestionTemplate(); $cloud->store_id = get_store_id(); $cloud->cat_id = $this->cat_id; $cloud->name = $this->name; $cloud->question = $this->question; $cloud->is_hot = $this->is_hot; $cloud->state = $this->state; if ($cloud->save()) { return [ 'code' => 0, 'msg' => '保存成功' ]; } else { return [ 'code' => 1, 'msg' => '保存失败', 'err' => $cloud->errors ]; } } }