255], ]; } public function attributeLabels() { return [ 'name' => '名称' ]; } public function search() { $query = QAndACat::find()->alias('ro')->where([ 'ro.is_delete' => 0, 'ro.store_id' => $this->store_id, ])->orderBy('ro.id DESC'); if ($this->name) { $query->andWhere(['like', 'ro.name', $this->name]); } if ($this->state >= 0) { $query->andWhere(['ro.state' => $this->state]); } if ($this->dateTime) { $query->andWhere(['>=', 'ro.created_at', strtotime($this->dateTime[0])]); $query->andWhere(['<=', 'ro.created_at', strtotime($this->dateTime[1])]); } if ($this->type) { $data = [ 'list' => $query->asArray()->all(), 'pageNo' => 0, 'totalCount' => 0 ]; } else { $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 = QAndACat::findOne($this->id) ?: new QAndACat(); $cloud->store_id = get_store_id(); $cloud->name = $this->name; $cloud->state = $this->state; $cloud->sort = $this->sort; if ($cloud->save()) { return [ 'code' => 0, 'msg' => '保存成功' ]; } else { return [ 'code' => 1, 'msg' => '保存失败', 'err' => $cloud->errors ]; } } }