<?php
|
|
namespace app\api\model\plus\regactivity;
|
|
use app\common\enum\order\OrderPayTypeEnum;
|
use app\common\model\plus\regactivity\User as regUserModel;
|
use app\api\model\plus\regactivity\Activity as ActivityModel;
|
use app\api\service\order\paysuccess\type\RegactivitySuccessService;
|
use app\api\service\order\PaymentService;
|
use app\common\enum\order\OrderTypeEnum;
|
|
|
|
/**
|
* 用户模型
|
*/
|
|
class User extends regUserModel
|
{
|
// 订单模型
|
public $model;
|
/**
|
* 隐藏字段
|
*/
|
protected $hidden = [
|
'create_time',
|
'update_time',
|
];
|
|
|
/**
|
* 添加报名用户
|
*/
|
public function addUser($user, $param)
|
{
|
$detail = ActivityModel::detail($param["activity_id"]);
|
//活动未开启/报名未开启/报名时间未到/活动已结束
|
if($detail["activity_status"] == 0 || $detail["register_status"] == 0 || $detail["status_text"]["reg_status"] != 1 || $detail["status_text"]["status"] == 2){
|
$this->error = '报名通道未开启';
|
return false;
|
}
|
if($detail["limit_num"] > 0 && $detail["reg_num"]>=$detail["limit_num"]){
|
$this->error = '报名名额已满';
|
return false;
|
}
|
if($detail['activity_fee']>0 && empty($param['pay_type'])){
|
$this->error = '请选择支付方式';
|
return false;
|
}
|
//生成记录
|
$record = [
|
'user_id' => $user['user_id'],
|
'order_no' => $this->orderNo(),
|
'activity_id' => $detail['activity_id'],
|
'activity_fee' => $detail['activity_fee'],
|
'pay_price' => $detail['activity_fee'],
|
'user_name' => $param['user_name'] ,
|
'mobile' => $param['mobile'],
|
'status' => $detail['activity_fee']>0 ? 0 : 1,//报名状态,没有费用则报名成功
|
'pay_type' => $param['pay_type'],
|
'app_id' => self::$app_id,
|
];
|
$status = $this->save($record);
|
/*if ($detail['activity_fee'] > 0) {
|
$param['pay_type'] = OrderPayTypeEnum::BALANCE;
|
}*/
|
// 余额支付标记订单已支付
|
if ($status && $param['pay_type'] == OrderPayTypeEnum::BALANCE) {
|
if ($user['balance'] < $detail['activity_fee']) {
|
$this->error = '用户余额不足,无法使用余额支付';
|
return false;
|
}
|
$this->onPaymentByBalance($record['order_no']);
|
}
|
return $this['order_id'];
|
}
|
/**
|
* 余额支付标记订单已支付
|
*/
|
public function onPaymentByBalance($orderNo)
|
{
|
// 获取订单详情
|
$PaySuccess = new RegactivitySuccessService($orderNo);
|
// 发起余额支付
|
return $PaySuccess->onPaySuccess(OrderPayTypeEnum::BALANCE);
|
}
|
|
/**
|
* 构建支付请求的参数
|
*/
|
public static function onOrderPayment($user, $order, $payType, $pay_source)
|
{
|
//如果来源是h5,首次不处理,payH5再处理
|
if ($pay_source == 'h5') {
|
return [];
|
}
|
if ($payType == OrderPayTypeEnum::WECHAT) {
|
return self::onPaymentByWechat($user, $order, $pay_source);
|
}
|
return [];
|
}
|
|
/**
|
* 构建微信支付请求
|
*/
|
protected static function onPaymentByWechat($user, $order, $pay_source)
|
{
|
return PaymentService::wechat(
|
$user,
|
[$order],
|
OrderTypeEnum::REGACTIVITY,
|
$pay_source
|
);
|
}
|
|
}
|