0], [['status'], 'in', 'range' => [0, 1]], [['model', 'config', 'name', 'pay_type',], 'required'], ]; } public function attributeLabels() { return [ 'cx_mch_id' => '平台商户ID', 'name' => '名称', 'pay_type' => '支付类型', 'status' => '状态:0=停用,1=启用', 'config' => '配置', 'remark' => '备注', ]; } public function save() { if(!$this->validate()){ return $this->getModelError(); } if($this->model->isNewRecord){ $this->model->cx_mch_id = $this->cx_mch_id; $this->model->status = $this->status; } $this->model->name = $this->name; $pay_types = $this->getPayTypes(); if(!in_array($this->pay_type, array_column($pay_types, 'short_name'))){ return $this->apiReturnError('无效支付类型'); } $this->model->pay_type = $this->pay_type; $this->model->remark = $this->remark; $form = new CommonPaymentConfigForm(); $form->scenario = $this->pay_type; $form->attributes = $this->config; $res = $form->save(); if($res['code'] != 0){ return $res; } $this->model->config = $res['data']['data']; if(!$this->model->save()){ return $this->getModelError($this->model); } return $this->apiReturnSuccess('保存成功'); } private function getPayTypes() { $form = new CommonPaymentSettingForm(); $form->cx_mch_id = $this->cx_mch_id; $data = $form->search(); return $data['pay_types']; } }