'edit'], [['min_cash', 'max_cash', 'day_max_cash', 'service_charge'], 'number'], ]; } public function attributeLabels() { return [ 'cx_mch_id' => '平台商户ID', 'scene' => '场景类型', 'cash_types' => '提现类型', 'min_cash' => '最低提现金额', 'max_cash' => '最高提现金额', 'day_max_cash' => '每日最高提现金额', 'service_charge' => '提现费率(百分比)', ]; } public function save() { if(!$this->validate()){ return $this->getModelError(); } $model = CashSetting::findOne([ 'cx_mch_id' => $this->cx_mch_id, 'scene' => $this->scene, ]); if($model == null){ $model = new CashSetting(); $model->cx_mch_id = $this->cx_mch_id; $model->scene = $this->scene; } if(!is_array($this->cash_types)) return Model::asReturnError("无效提现类型"); $cash_types = Cash::getCashTypes($this->cash_types); $model->cash_types = json_encode($cash_types,JSON_UNESCAPED_UNICODE); $this->min_cash = sprintf("%.2f",$this->min_cash); if($this->min_cash < 0) return Model::asReturnError("最低提现金额不能小于0"); $model->min_cash = $this->min_cash; $this->max_cash = sprintf("%.2f",$this->max_cash); if($this->max_cash < 0) return Model::asReturnError("最高提现金额不能小于0"); if($this->max_cash < $this->min_cash) return Model::asReturnError("最高提现金额不能小于最低提现金额"); $model->max_cash = $this->max_cash; $this->day_max_cash = sprintf("%.2f",$this->day_max_cash); if($this->day_max_cash < 0) return Model::asReturnError("每日最高提现金额不能小于0"); $model->day_max_cash = $this->day_max_cash; if($this->service_charge < 0) return Model::asReturnError("提现费率不能小于0"); if($this->service_charge > 100) return Model::asReturnError("提现费率不能大于100"); $model->service_charge = $this->service_charge; if(!$model->save()) return $this->getModelError($model); return Model::asReturnSuccess("保存成功"); } public function search() { if(!$this->validate()){ throw new \Exception(json_encode($this->getFirstErrors(),JSON_UNESCAPED_UNICODE)); } $model = CashSetting::findOne([ 'cx_mch_id' => $this->cx_mch_id, 'scene' => $this->scene, ]); if($model == null) $model = new CashSetting(); if(!$model->isNewRecord) $model->cash_types = json_decode($model->cash_types,true); if(empty($model->cash_types)) $model->cash_types = Cash::getCashTypeLabels(); return $model; } }