[1,2]], [['cx_mch_id', 'user_id', 'scene'], 'required'], [['integral', 'type', 'remark', 'operator_name'], 'required', 'on' => 'recharge'], [['integral', 'pay_type',], 'required', 'on' => 'auto_recharge'], ]; } public function attributeLabels(){ return [ 'operator_name' => '操作用户', 'type' => '类型', 'integral' => '积分', 'remark' => '备注', 'receipt' => '回执', ]; } //后台充值 public function recharge() { if(!$this->validate()){ return $this->getModelError(); } if($this->type == 1 && $this->integral <= 0){ return $this->apiReturnError('充值金额不能小于0'); } $res = Integral::initIntegral($this->user_id, $this->scene, $this->cx_mch_id); if($res['code'] != 0) return $res; $integral_model = Integral::findOne(['user_id' => $this->user_id, 'scene' => $this->scene, 'cx_mch_id' => $this->cx_mch_id, 'is_delete' => 0]); if($integral_model == null){ return $this->apiReturnError('系统内部错误'); } if($this->type == 2 && $this->integral > $integral_model->account_integral){ return $this->apiReturnError('账户积分不足'); } $type_cn = $this->type == 1 ? '充值' : '扣除'; $desc = $this->operator_name . "操作后台" . $type_cn . $this->integral."积分"; $order_no = UniqueOrderNo::generate(UniqueOrderNo::ORDER_TYPE_MANUAL_RECHARGE_INTEGRAL_ORDER); $order_type = UniqueOrderNo::getOrderTypeByOrderNo($order_no); $ext = [ 'remark' => $this->remark, 'receipt' => $this->receipt ]; $ext = json_encode($ext,JSON_UNESCAPED_UNICODE); $t = \Yii::$app->db->beginTransaction(); $res = Integral::logger($this->user_id, $this->type, $this->integral, $desc, $order_type, $order_no, $this->scene, $ext, $this->cx_mch_id); if($res['code'] != 0){ $t->rollBack(); return $res; } $t->commit(); return $this->apiReturnSuccess("操作成功"); } }