['save'] ], [ [ 'code', 'name', 'mobile' ], 'string' ], [ [ 'status', 'store_id' ], 'integer' ], [ ['id'], 'required', 'on' => [ 'item', 'del' ] ], [ ['id'], 'integer', 'on' => [ 'item' ] ], [ ['id'], 'isArray', 'on' => [ 'del' ] ], [['start_time','end_time'],'string'] ]; } /** * 自定义数组验证规则 * @param $attribute * @param $params * @author: hankaige * @Time: 2024/3/22 15:53 */ public function isArray($attribute, $params) { if(!is_array($this->$attribute) || count($this->$attribute) <= 0){ $this->addError($attribute,'删除数据为空'); } } public function getList() { $query = MdGroupDriver::find()->where([ 'store_id' => $this->store_id, 'is_delete' => 0, ]); if($this->status > 0){ $query->andWhere(['status'=>$this->status]); } if(!empty($this->keywords)) { $query->andWhere(['or',['like', 'name', $this->keywords],['like', 'code', $this->keywords],['like', 'mobile', $this->keywords]]); } if (!empty($this->start_time)) { $query->andWhere([ '>=', 'created_at', strtotime($this->start_time) ]); } if (!empty($this->end_time)) { $query->andWhere([ '<=', 'created_at', strtotime($this->end_time) ]); } $result = pagination_make($query, TRUE, 'created_at'); foreach ($result['list'] as &$item) { $item['created_at'] = date('Y-m-d H:i:s', $item['created_at']); $item['status'] = (int)$item['status']; } return ['code'=>0,'data'=>$result]; } public function createItem() { if (!$this->validate()) { return [ 'code' => 1, 'msg' => $this->getErrorSummary(FALSE)[0] ]; } $model = MdGroupDriver::findOne($this->id); if (empty($model)) { $model = new MdGroupDriver(); } if(MdGroupDriver::find()->where(['code'=>$this->code])->andWhere(['!=','id',$this->id])->count() > 0){ return ['code'=>1,'msg'=>'司机编号已存在']; } $model->store_id = $this->store_id; $model->code = $this->code; $model->name = $this->name; $model->mobile = $this->mobile; $model->status = $this->status; if ($model->save()) { return [ 'code' => 0, 'msg' => '操作成功' ]; } return [ 'code' => 1, 'msg' => $model->getErrors() ]; } public function delItem() { if (!$this->validate()) { return [ 'code' => 1, 'msg' => $this->getErrorSummary(FALSE)[0] ]; } $res = MdGroupDriver::updateAll(['is_delete'=>1],['id'=>$this->id,'store_id'=>$this->store_id]); if ($res > 0) { return [ 'code'=>0, 'msg' => '删除成功' ]; } return [ 'code' => 1, 'msg' => '操作失败' ]; } }