|
|
@@ -14,13 +14,13 @@ use Illuminate\Support\Facades\Log;
|
|
|
use App\Services\Payment\QianBaoService;
|
|
|
use App\Services\Payment\SanJinService;
|
|
|
|
|
|
-use App\Services\WalletService;
|
|
|
-use App\Services\BalanceLogService;
|
|
|
+use App\Services\WalletService;
|
|
|
+use App\Services\BalanceLogService;
|
|
|
|
|
|
/**
|
|
|
* 投注
|
|
|
-*/
|
|
|
-class PaymentOrderService extends BaseService
|
|
|
+ */
|
|
|
+class PaymentOrderService extends BaseService
|
|
|
{
|
|
|
const TYPE_PAY = 1; // 代收
|
|
|
const TYPE_PAYOUT = 2; // 代付
|
|
|
@@ -33,8 +33,8 @@ class PaymentOrderService extends BaseService
|
|
|
/**
|
|
|
* @description: 模型
|
|
|
* @return {string}
|
|
|
- */
|
|
|
- public static function model() :string
|
|
|
+ */
|
|
|
+ public static function model(): string
|
|
|
{
|
|
|
return PaymentOrder::class;
|
|
|
}
|
|
|
@@ -42,8 +42,8 @@ class PaymentOrderService extends BaseService
|
|
|
/**
|
|
|
* @description: 枚举
|
|
|
* @return {*}
|
|
|
- */
|
|
|
- public static function enum() :string
|
|
|
+ */
|
|
|
+ public static function enum(): string
|
|
|
{
|
|
|
return '';
|
|
|
}
|
|
|
@@ -52,32 +52,32 @@ class PaymentOrderService extends BaseService
|
|
|
* @description: 获取查询条件
|
|
|
* @param {array} $search 查询内容
|
|
|
* @return {array}
|
|
|
- */
|
|
|
- public static function getWhere(array $search = []) :array
|
|
|
+ */
|
|
|
+ public static function getWhere(array $search = []): array
|
|
|
{
|
|
|
$where = [];
|
|
|
- if(isset($search['member_id']) && !empty($search['member_id'])){
|
|
|
+ if (isset($search['member_id']) && !empty($search['member_id'])) {
|
|
|
$where[] = ['member_id', '=', $search['member_id']];
|
|
|
}
|
|
|
- if(isset($search['type']) && !empty($search['type'])){
|
|
|
+ if (isset($search['type']) && !empty($search['type'])) {
|
|
|
$where[] = ['type', '=', $search['type']];
|
|
|
}
|
|
|
- if(isset($search['channel']) && !empty($search['channel'])){
|
|
|
+ if (isset($search['channel']) && !empty($search['channel'])) {
|
|
|
$where[] = ['channel', '=', $search['channel']];
|
|
|
}
|
|
|
- if(isset($search['order_no']) && !empty($search['order_no'])){
|
|
|
+ if (isset($search['order_no']) && !empty($search['order_no'])) {
|
|
|
$where[] = ['order_no', '=', $search['order_no']];
|
|
|
}
|
|
|
- if(isset($search['id']) && !empty($search['id'])){
|
|
|
+ if (isset($search['id']) && !empty($search['id'])) {
|
|
|
$where[] = ['id', '=', $search['id']];
|
|
|
}
|
|
|
- if(isset($search['status']) && $search['status'] != ''){
|
|
|
+ if (isset($search['status']) && $search['status'] != '') {
|
|
|
$where[] = ['status', '=', $search['status']];
|
|
|
}
|
|
|
return $where;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
+ /**
|
|
|
* @description: 查询单条数据
|
|
|
* @param array $search
|
|
|
* @return \App\Models\Coin|null
|
|
|
@@ -104,29 +104,31 @@ class PaymentOrderService extends BaseService
|
|
|
*/
|
|
|
public static function paginate(array $search = [])
|
|
|
{
|
|
|
- $limit = isset($search['limit'])?$search['limit']:15;
|
|
|
- $paginator = self::model()::where(self::getWhere($search))->paginate($limit);
|
|
|
+ $limit = isset($search['limit']) ? $search['limit'] : 15;
|
|
|
+ $paginator = self::model()::where(self::getWhere($search))
|
|
|
+ ->with(['user'])
|
|
|
+ ->paginate($limit);
|
|
|
return ['total' => $paginator->total(), 'data' => $paginator->items()];
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @description:
|
|
|
+ * @description:
|
|
|
* @param {*} $params
|
|
|
* @return {*}
|
|
|
- */
|
|
|
+ */
|
|
|
public static function submit($params = [])
|
|
|
{
|
|
|
$result = false;
|
|
|
$msg['code'] = self::NOT;
|
|
|
$msg['msg'] = '';
|
|
|
-
|
|
|
+
|
|
|
// 2. 判断是否是更新
|
|
|
if (!empty($params['id'])) {
|
|
|
// 更新
|
|
|
- $info = self::findOne(['id'=>$params['id']] );
|
|
|
+ $info = self::findOne(['id' => $params['id']]);
|
|
|
if (!$info) {
|
|
|
$msg['msg'] = '数据不存在!';
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
$result = $info->update($params);
|
|
|
$id = $params['id'];
|
|
|
}
|
|
|
@@ -135,14 +137,14 @@ class PaymentOrderService extends BaseService
|
|
|
$result = $info = self::model()::create($params);
|
|
|
$id = $result->id;
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- if($result){
|
|
|
- $msg['code'] = self::YES;
|
|
|
- $msg['msg'] = '设置成功';
|
|
|
- $msg['key'] = $id;
|
|
|
- }else{
|
|
|
- $msg['msg'] = empty($msg['msg']) ?'操作失败':$msg['msg'];
|
|
|
+
|
|
|
+
|
|
|
+ if ($result) {
|
|
|
+ $msg['code'] = self::YES;
|
|
|
+ $msg['msg'] = '设置成功';
|
|
|
+ $msg['key'] = $id;
|
|
|
+ } else {
|
|
|
+ $msg['msg'] = empty($msg['msg']) ? '操作失败' : $msg['msg'];
|
|
|
}
|
|
|
|
|
|
return $msg;
|
|
|
@@ -154,8 +156,8 @@ class PaymentOrderService extends BaseService
|
|
|
* @param {*} $amount
|
|
|
* @param {*} $paymentType 支付类型:支付宝、数字人民币
|
|
|
* @return {*}
|
|
|
- */
|
|
|
- public static function createPay($memberId,$amount,$paymentType)
|
|
|
+ */
|
|
|
+ public static function createPay($memberId, $amount, $paymentType)
|
|
|
{
|
|
|
$result = [];
|
|
|
$result['chat_id'] = $memberId;
|
|
|
@@ -164,33 +166,33 @@ class PaymentOrderService extends BaseService
|
|
|
$max = 0;
|
|
|
$min = 0;
|
|
|
$rate = 0;
|
|
|
- foreach($product as $k => $v){
|
|
|
- if($v['type'] == $paymentType){
|
|
|
- if($amount >= $v['min'] && $amount <= $v['max']){
|
|
|
+ foreach ($product as $k => $v) {
|
|
|
+ if ($v['type'] == $paymentType) {
|
|
|
+ if ($amount >= $v['min'] && $amount <= $v['max']) {
|
|
|
$channel = $k;
|
|
|
$rate = $v['rate'];
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
- if($min == 0){
|
|
|
+ if ($min == 0) {
|
|
|
$min = $v['min'];
|
|
|
}
|
|
|
- if($max == 0){
|
|
|
+ if ($max == 0) {
|
|
|
$max = $v['max'];
|
|
|
}
|
|
|
- if($min > $v['min']){
|
|
|
+ if ($min > $v['min']) {
|
|
|
$min = $v['min'];
|
|
|
}
|
|
|
- if($max < $v['max']){
|
|
|
+ if ($max < $v['max']) {
|
|
|
$max = $v['max'];
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 没有找到支付通道
|
|
|
- if(empty($channel)){
|
|
|
+ if (empty($channel)) {
|
|
|
$text = "发起充值失败 \n";
|
|
|
- $text .= "最低充值:".$min." \n";
|
|
|
- $text .= "最高充值:".$max." \n";
|
|
|
+ $text .= "最低充值:" . $min . " \n";
|
|
|
+ $text .= "最高充值:" . $max . " \n";
|
|
|
$text .= "请重新填写充值的金额!";
|
|
|
$result['text'] = $text;
|
|
|
return $result;
|
|
|
@@ -202,13 +204,13 @@ class PaymentOrderService extends BaseService
|
|
|
$data['amount'] = $amount;
|
|
|
$data['channel'] = $channel;
|
|
|
$data['fee'] = $amount * $rate;
|
|
|
- $order_no = self::createOrderNo('sj'.$data['type'].'_', $memberId);
|
|
|
+ $order_no = self::createOrderNo('sj' . $data['type'] . '_', $memberId);
|
|
|
$data['order_no'] = $order_no;
|
|
|
$data['callback_url'] = SanJinService::getNotifyUrl();
|
|
|
- $data['remark'] = '充值费率:'.$rate;
|
|
|
+ $data['remark'] = '充值费率:' . $rate;
|
|
|
$data['status'] = self::STATUS_STAY;
|
|
|
- $ret = SanJinService::pay(($amount*100), $order_no, $channel);
|
|
|
- if($ret['code'] == 0){
|
|
|
+ $ret = SanJinService::pay(($amount * 100), $order_no, $channel);
|
|
|
+ if ($ret['code'] == 0) {
|
|
|
|
|
|
$qrCode = asset(self::createPaymentQrCode($ret['data']['payUrl']));
|
|
|
$result['image'] = $qrCode;
|
|
|
@@ -216,15 +218,15 @@ class PaymentOrderService extends BaseService
|
|
|
$data['status'] = self::STATUS_PROCESS;
|
|
|
$data['pay_no'] = $item['tradeNo'];
|
|
|
$data['pay_url'] = $item['payUrl'];
|
|
|
- $data['pay_data'] = json_encode($ret,JSON_UNESCAPED_UNICODE);
|
|
|
+ $data['pay_data'] = json_encode($ret, JSON_UNESCAPED_UNICODE);
|
|
|
$info = self::model()::create($data);
|
|
|
$text = "✅ 支付提示 \n";
|
|
|
$text .= "请扫码支付 \n";
|
|
|
- $text .= "支付金额:".$amount." RMB \n";
|
|
|
+ $text .= "支付金额:" . $amount . " RMB \n";
|
|
|
$text .= "请按实际支付金额进行付款,否则影响到账 \n";
|
|
|
$text .= "支付完成后请耐心等待,支付到账会第一时间通知您! \n";
|
|
|
$result['text'] = $text;
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
$result['text'] = $ret['message'];
|
|
|
}
|
|
|
return $result;
|
|
|
@@ -234,45 +236,45 @@ class PaymentOrderService extends BaseService
|
|
|
* @description: 接收支付的通知
|
|
|
* @param {*} $params
|
|
|
* @return {*}
|
|
|
- */
|
|
|
+ */
|
|
|
public static function receivePay($params)
|
|
|
{
|
|
|
// 判断商户号
|
|
|
- if($params['mchId'] == SanJinService::getMerchantId()){
|
|
|
- $must = ['mchId','productId','tradeNo','outTradeNo','amount','payAmount','state','createTime','payTime'];
|
|
|
-
|
|
|
+ if ($params['mchId'] == SanJinService::getMerchantId()) {
|
|
|
+ $must = ['mchId', 'productId', 'tradeNo', 'outTradeNo', 'amount', 'payAmount', 'state', 'createTime', 'payTime'];
|
|
|
+
|
|
|
|
|
|
$info = self::findOne(['order_no' => $params['outTradeNo']]);
|
|
|
- if($info){
|
|
|
+ if ($info) {
|
|
|
// 平台以分计算转成元
|
|
|
$payAmount = $params['payAmount'] / 100;
|
|
|
// 判断金额是不是正确认
|
|
|
- if($info->amount != $payAmount){
|
|
|
+ if ($info->amount != $payAmount) {
|
|
|
$text = '❌ 支付失败提醒 \n';
|
|
|
$text .= "订单金额:{$info->amount} \n";
|
|
|
$text .= "实际支付:{$payAmount} \n";
|
|
|
$text .= "订单号:{$params['outTradeNo']} \n";
|
|
|
$text .= "失败原因:支付金额与订单金额不一致 \n";
|
|
|
$text .= "请联系客服处理!";
|
|
|
- self::sendMessage($info->member_id,$text);
|
|
|
+ self::sendMessage($info->member_id, $text);
|
|
|
return false;
|
|
|
}
|
|
|
-
|
|
|
- if($params['sign'] != SanJinService::signature($params,$must)){
|
|
|
+
|
|
|
+ if ($params['sign'] != SanJinService::signature($params, $must)) {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- if($info->status != self::STATUS_PROCESS){
|
|
|
+ if ($info->status != self::STATUS_PROCESS) {
|
|
|
return false;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 付款
|
|
|
- if($info->type == self::TYPE_PAY){
|
|
|
- if($params['state'] == 1){
|
|
|
+ if ($info->type == self::TYPE_PAY) {
|
|
|
+ if ($params['state'] == 1) {
|
|
|
$info->status = self::STATUS_SUCCESS;
|
|
|
$wallet = WalletService::findOne(['member_id' => $info->member_id]);
|
|
|
$balance = $wallet->available_balance;
|
|
|
- $available_balance = bcadd($balance,$payAmount,10);
|
|
|
+ $available_balance = bcadd($balance, $payAmount, 10);
|
|
|
$wallet->available_balance = $available_balance;
|
|
|
$wallet->save();
|
|
|
|
|
|
@@ -291,8 +293,8 @@ class PaymentOrderService extends BaseService
|
|
|
$text .= "充值金额:{$payAmount} RMB \n";
|
|
|
$text .= "订单号:{$params['outTradeNo']} \n";
|
|
|
$text .= "您充值的金额已到账,请注意查收!";
|
|
|
- self::sendMessage($info->member_id,$text);
|
|
|
- }else{
|
|
|
+ self::sendMessage($info->member_id, $text);
|
|
|
+ } else {
|
|
|
$info->status = self::STATUS_FAIL;
|
|
|
$text = "❌ 支付失败 \n";
|
|
|
$text .= "充值金额:{$payAmount} RMB \n";
|
|
|
@@ -314,32 +316,32 @@ class PaymentOrderService extends BaseService
|
|
|
* @param {*} $account 姓名
|
|
|
* @param {*} $card_no 银行卡号/支付宝账号
|
|
|
* @return {*}
|
|
|
- */
|
|
|
+ */
|
|
|
public static function createPayout($memberId, $amount, $channel, $bank_name, $account, $card_no)
|
|
|
{
|
|
|
$default_amount = $amount;
|
|
|
$result = [];
|
|
|
$result['chat_id'] = $memberId;
|
|
|
|
|
|
- if($amount < 100){
|
|
|
+ if ($amount < 100) {
|
|
|
$result['text'] = '提现金额最少100';
|
|
|
return $result;
|
|
|
}
|
|
|
- if($amount > 49999){
|
|
|
+ if ($amount > 49999) {
|
|
|
$result['text'] = '提现金额最多49999';
|
|
|
return $result;
|
|
|
}
|
|
|
|
|
|
// 在调用三方支付前开始事务
|
|
|
DB::beginTransaction();
|
|
|
-
|
|
|
+
|
|
|
try {
|
|
|
$wallet = WalletService::findOne(['member_id' => $memberId]);
|
|
|
if (!$wallet) {
|
|
|
$result['text'] = '钱包不存在!';
|
|
|
return $result;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
$balance = $wallet->available_balance;
|
|
|
if (bccomp($balance, $amount, 2) < 0) {
|
|
|
$result['text'] = '您的钱包余额不足!';
|
|
|
@@ -350,7 +352,7 @@ class PaymentOrderService extends BaseService
|
|
|
|
|
|
$data = [];
|
|
|
$data['type'] = self::TYPE_PAYOUT;
|
|
|
- $order_no = self::createOrderNo('sj'.$data['type'].'_', $memberId);
|
|
|
+ $order_no = self::createOrderNo('sj' . $data['type'] . '_', $memberId);
|
|
|
$data['order_no'] = $order_no;
|
|
|
$data['member_id'] = $memberId;
|
|
|
$data['fee'] = $amount * 0.002 + 2;
|
|
|
@@ -418,7 +420,7 @@ class PaymentOrderService extends BaseService
|
|
|
$text .= "⌛️请等待系统处理, 到账时间可能需要几分钟!\n";
|
|
|
|
|
|
$result['text'] = $text;
|
|
|
-
|
|
|
+
|
|
|
} catch (\Exception $e) {
|
|
|
DB::rollBack();
|
|
|
// 状态更新失败,但资金已扣款且三方支付已成功
|
|
|
@@ -429,7 +431,7 @@ class PaymentOrderService extends BaseService
|
|
|
]);
|
|
|
$result['text'] = '提现申请已提交,系统处理中...';
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
} else {
|
|
|
// 三方支付失败,需要回滚之前的预扣款
|
|
|
DB::beginTransaction();
|
|
|
@@ -437,12 +439,12 @@ class PaymentOrderService extends BaseService
|
|
|
// 恢复钱包余额
|
|
|
$wallet->available_balance = $balance;
|
|
|
$wallet->save();
|
|
|
-
|
|
|
+
|
|
|
// 更新提现记录状态为失败
|
|
|
$info->status = self::STATUS_FAIL;
|
|
|
$info->remark = $ret['msg'];
|
|
|
$info->save();
|
|
|
-
|
|
|
+
|
|
|
// 记录退款日志
|
|
|
BalanceLogService::addLog(
|
|
|
$memberId,
|
|
|
@@ -453,10 +455,10 @@ class PaymentOrderService extends BaseService
|
|
|
$id,
|
|
|
'提现失败退款'
|
|
|
);
|
|
|
-
|
|
|
+
|
|
|
DB::commit();
|
|
|
$result['text'] = $ret['msg'];
|
|
|
-
|
|
|
+
|
|
|
} catch (\Exception $e) {
|
|
|
DB::rollBack();
|
|
|
// 回滚失败,需要记录告警,人工干预
|
|
|
@@ -476,57 +478,57 @@ class PaymentOrderService extends BaseService
|
|
|
* @description: 接收三方订单
|
|
|
* @param {*} $params
|
|
|
* @return {*}
|
|
|
- */
|
|
|
+ */
|
|
|
public static function receiveOrder($params)
|
|
|
{
|
|
|
// 判断商户号是否一致
|
|
|
- if($params['merchantNum'] == QianBaoService::getMerchantId()){
|
|
|
+ if ($params['merchantNum'] == QianBaoService::getMerchantId()) {
|
|
|
|
|
|
$info = self::findOne(['order_no' => $params['orderNo']]);
|
|
|
- if($info){
|
|
|
+ if ($info) {
|
|
|
// 判断金额是不是正确认
|
|
|
- if($info->amount != $params['amount']){
|
|
|
+ if ($info->amount != $params['amount']) {
|
|
|
return false;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 验证签名
|
|
|
- $sign = QianBaoService::verifyNotifySign($params['state'],$params['orderNo'],$params['amount']);
|
|
|
- if($params['sign'] != $sign){
|
|
|
+ $sign = QianBaoService::verifyNotifySign($params['state'], $params['orderNo'], $params['amount']);
|
|
|
+ if ($params['sign'] != $sign) {
|
|
|
return false;
|
|
|
}
|
|
|
// 代付
|
|
|
- if($info->type == self::TYPE_PAYOUT){
|
|
|
- self::onSubmitPayout($params,$info);
|
|
|
+ if ($info->type == self::TYPE_PAYOUT) {
|
|
|
+ self::onSubmitPayout($params, $info);
|
|
|
}
|
|
|
// 代收
|
|
|
- if($info->type == self::TYPE_PAY){
|
|
|
+ if ($info->type == self::TYPE_PAY) {
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @description: 处理代付订单
|
|
|
* @param {*} $params
|
|
|
* @return {*}
|
|
|
- */
|
|
|
- public static function onSubmitPayout($params,$info)
|
|
|
+ */
|
|
|
+ public static function onSubmitPayout($params, $info)
|
|
|
{
|
|
|
$memberId = $info->member_id;
|
|
|
$amount = $params['amount'];
|
|
|
$data = [];
|
|
|
$result = [];
|
|
|
$chat_id = $info->member_id;
|
|
|
- $data['callback_data'] =json_encode($params,JSON_UNESCAPED_UNICODE);
|
|
|
+ $data['callback_data'] = json_encode($params, JSON_UNESCAPED_UNICODE);
|
|
|
DB::beginTransaction();
|
|
|
- try{
|
|
|
- if($params['state'] == 1){
|
|
|
+ try {
|
|
|
+ if ($params['state'] == 1) {
|
|
|
$data['status'] = self::STATUS_SUCCESS;
|
|
|
$res = self::model()::where(['order_no' => $params['orderNo']])->update($data);
|
|
|
- if($res){
|
|
|
+ if ($res) {
|
|
|
DB::commit();
|
|
|
$text = "✅ 提现通知 \n";
|
|
|
$text .= "提现平台:{$info->bank_name} \n";
|
|
|
@@ -534,16 +536,16 @@ class PaymentOrderService extends BaseService
|
|
|
$text .= "收款卡号:{$info->card_no} \n";
|
|
|
$text .= "提现金额:{$info->amount} \n";
|
|
|
$text .= "提现成功,金额已到账,请注意查收!";
|
|
|
- self::sendMessage($chat_id,$text);
|
|
|
+ self::sendMessage($chat_id, $text);
|
|
|
}
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
$data['status'] = self::STATUS_FAIL;
|
|
|
$res = self::model()::where(['order_no' => $params['orderNo']])->update($data);
|
|
|
|
|
|
$wallet = WalletService::findOne(['member_id' => $info->member_id]);
|
|
|
|
|
|
$balance = $wallet->available_balance; // 钱包当前余额
|
|
|
-
|
|
|
+
|
|
|
$available_balance = bcadd($balance, $params['amount'], 10);
|
|
|
$wallet->available_balance = $available_balance;
|
|
|
$wallet->save();
|
|
|
@@ -557,7 +559,7 @@ class PaymentOrderService extends BaseService
|
|
|
$info->id,
|
|
|
'提现失败退款'
|
|
|
);
|
|
|
- if($res){
|
|
|
+ if ($res) {
|
|
|
DB::commit();
|
|
|
$text = "❌ 提现通知 \n";
|
|
|
$text .= "提现平台:{$info->bank_name} \n";
|
|
|
@@ -565,17 +567,16 @@ class PaymentOrderService extends BaseService
|
|
|
$text .= "收款卡号:{$info->card_no} \n";
|
|
|
$text .= "提现金额:{$info->amount} \n";
|
|
|
$text .= "提现失败,金额已返回钱包,请注意查收!";
|
|
|
- self::sendMessage($chat_id,$text);
|
|
|
+ self::sendMessage($chat_id, $text);
|
|
|
}
|
|
|
}
|
|
|
- }catch(\Exception $e){
|
|
|
+ } catch (\Exception $e) {
|
|
|
DB::rollBack();
|
|
|
// 回滚失败,需要记录告警,人工干预
|
|
|
Log::error('提现失败回滚异常: ' . $e->getMessage(), $params);
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
}
|
|
|
|
|
|
}
|