1, 'type_flag' => WechatShare::RECEIVE_PERSONAL_OPENID, ], [ 'type' => 2, 'type_flag' => WechatShare::RECEIVE_MERCHANT_ID, ], [ 'type' => 3, 'type_flag' => WechatShare::RECEIVE_PERSONAL_SUB_OPENID, ] ]; public function rules() { return [ [['type'], 'integer'], [['name', 'description', 'account', 'id'], 'string', 'max' => 255], [['name', 'description', 'account'], 'trim'], ]; } /** * @return array * @throws \yii\db\Exception */ public function save() { if (!$this->validate()) { return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0] ]; } if (!in_array($this->type, array_column(self::$valid_type, 'type'))) { return [ 'code' => 1, 'msg' => '接收方类型错误' ]; } $model = ProfitSharingReceiver::findOne($this->id); if (!$model) { $model = new ProfitSharingReceiver(); $model->created_at = time(); $model->store_id = get_store_id(); } $model->type = $this->type; $model->account = $this->account; $model->name = $this->name; $model->max_amount = $this->max_amount; $model->ratio = $this->ratio; $model->description = $this->description; if (!$model->save()) { return [ 'code' => 1, 'msg' => $model->errors[0] ]; } return [ 'code' => 0, 'msg' => '保存成功' ]; } public function search() { $query = ProfitSharingReceiver::find()->where(['store_id' => get_store_id(), 'is_delete' => 0]); if (!empty($this->search_key)) { $query->andWhere(['like', 'name', $this->search_key]); } $list = pagination_make($query); foreach ($list['list'] as &$val) { $val['type'] = intval($val['type']); $val['created_at'] = date('Y-m-d H:i:s', $val['created_at']); $val['updated_at'] = date('Y-m-d H:i:s', $val['updated_at']); } return [ 'code' => 0, 'msg' => 'success', 'data' => [ 'data' => $list['list'], 'pageNo' => $list['pageNo'], 'totalCount' => $list['totalCount'], 'type' => self::$valid_type ] ]; } }