@ -7,11 +7,7 @@ use app\model\PaymentCodeLogModel;
use app\model\PaymentListModel;
use app\model\RechargeApplyModel;
use app\model\StockMarketModel;
use app\model\UserModel;
use app\model\UserWithdrawalModel;
use app\model\WalletListModel;
use think\facade\Db;
use think\facade\Log;
/**
* 处理团队佣金业务
@ -38,230 +34,254 @@ class PayService extends BaseHomeService
}
/**
* 用户充值申请入库1
* 用户充值申请入库
* @param array $data
* @return array
*/
public function insertRechargeApply(array $data): array
{
$channel = PaymentListModel::getPaymentInfo([
'id' => $data['recharge_channel']
]);
if (empty($channel)) {
return $this->toData('100110', 'The system is busy. Please try again later.1', []);
// 判断支付方式,目前只有两种方式:1-支付码方式充值; 2-数字币方式充值
if (!in_array($data['recharge_type'], [1, 2])) {
return $this->toData('500', 'Parameter recharge_type is incorrect');
}
if (empty($data['country'])) {
return $this->toData('100120', 'The system is busy. Please try again later.2', []);
// 必要参数检测
if (!isset($data['account_type'])) {
return $this->toData('500', 'Parameter account_type is incorrect');
}
if (empty($data['recharge_num']) || $data['recharge_num'] < = 0) {
return $this->toData('100130', 'The system is busy. Please try again later.3', []);
// 生成订单号
$data['order_no'] = $this->generateOrderNumber();
// 2-支付码方式充值
if ($data['recharge_type'] == 2) {
// 如果是支付码方式充值,需要上传该参数,该参数值是payment_code_config表的主键ID
if (empty($data['payment_code_config_log_id'])) {
return $this->toData('500', 'Parameter payment_code_config_id is messing');
}
// 创建订单
$orderData = RechargeApplyModel::create([
'user_id' => $data['user_id'],
'account_type' => $data['account_type'],
'recharge_type' => $data['recharge_type'],
'recharge_num' => $data['recharge_num'],
'status' => 0,
'order_no' => $data['order_no'],
'create_time' => date('Y-m-d H:i:s'),
'update_time' => date('Y-m-d H:i:s'),
'is_online' => 1,
'is_check' => 0,
'real_amount' => 0,
]);
// 修改支付码预下单记录表,将实际充值的订单号关联到用户充值上一步的预下单记录中
PaymentCodeLogModel::where('id', $data['payment_code_config_log_id'])->update([
'recharge_apply_id' => $orderData->id,
'recharge_amount' => $data['recharge_num']
]);
return $this->toData('0', 'successful');
}
if($channel['type']==9){
//1USD=1USDT
$currency_rate = 1;
if($data['product']=='TRC20Buy'){
switch ($data['extra']){
case 'GBP':
$gpx_rate=StockMarketModel::where('stock_market_type',14)->value('rate');
$currency_rate=$gpx_rate/100;
break;
case "EUR":
$eur_rate=StockMarketModel::where('stock_market_type',15)->value('rate');
$currency_rate=$eur_rate*1;
break;
// 1-数字币方式充值
if ($data['recharge_type'] == 1) {
$channel = PaymentListModel::getPaymentInfo([
'id' => $data['recharge_channel']
]);
if (empty($channel)) {
return $this->toData('500', 'channel error');
}
if (empty($data['recharge_num']) || $data['recharge_num'] < = 0) {
return $this->toData('100130', 'recharge_num error');
}
if($channel['type']==9){
$currency_rate = 1;
if($data['product']=='TRC20Buy'){
switch ($data['extra']){
case 'GBP':
$gpx_rate=StockMarketModel::where('stock_market_type',14)->value('rate');
$currency_rate=$gpx_rate/100;
break;
case "EUR":
$eur_rate=StockMarketModel::where('stock_market_type',15)->value('rate');
$currency_rate=$eur_rate*1;
break;
}
}
}else{
$currency_rate = $channel['exchange_rate'];
}
}else{
$currency_rate = $channel['exchange_rate'];
}
//$currency_rate=(new StockMarketModel)->getRate(4);
if ($data['account_type'] > 2 & & ($data['account_type'] != 8)) {
$market_rate = (new StockMarketModel)->getRate($data['account_type']);
} else {
$market_rate = 1;
}
$market_amount = $data['recharge_num'] * $market_rate;
$market_amount = round($market_amount, 2);
if ($channel['pay_type'] == 1) {
$fee = $data['recharge_num'] * $currency_rate * $channel['service_rate'];
$server_fee = $market_amount * $channel['service_rate'];
} else {
$fee = $currency_rate * $channel['service_rate'];
$server_fee = $market_rate * $channel['service_rate'];
}
$total_amount = $data['recharge_num'] * $currency_rate + $fee;
$total_amount = round($total_amount, 2);
if ($data['account_type'] > 2 & & ($data['account_type'] != 8)) {
$market_rate = (new StockMarketModel)->getRate($data['account_type']);
} else {
$market_rate = 1;
}
$market_amount = $data['recharge_num'] * $market_rate;
$market_amount = round($market_amount, 2);
if ($data['is_online'] == 1 & & $total_amount > 100000) {
return $this->toData('101900', 'Online payment scope: 100 - 100000');
}
$data['service_fee'] = $server_fee;//手续费用
$data['market_amount'] = $market_amount; //换算的市场金额
$data['total_amount'] = $total_amount; //要支付的渠道货币金额
$data['currency_rate'] = $currency_rate;
if ($channel['channel_type'] == 'Bank') {
$data['recharge_type'] = 2;
// p2新增,如果是银行卡充值需要添加支付码配置的充值记录
if (empty($data['amount_range'])) {
return $this->toData('500', '缺少充值金额范围参数');
if ($channel['pay_type'] == 1) {
$fee = $data['recharge_num'] * $currency_rate * $channel['service_rate'];
$server_fee = $market_amount * $channel['service_rate'];
} else {
$fee = $currency_rate * $channel['service_rate'];
$server_fee = $market_rate * $channel['service_rate'];
}
} else {
$data['recharge_type'] = 1;
}
$total_amount = $data['recharge_num'] * $currency_rate + $fee;
$total_amount = round($total_amount, 2);
$data['order_no'] = $this->generateOrderNumber();
if ($data['is_online'] == 1 & & $total_amount > 100000) {
return $this->toData('101900', 'Online payment scope: 100 - 100000');
}
$order_id = RechargeApplyModel::InsertUserRecharge($data);
if ($order_id) {
// p2新增功能,如果是银行卡充值,添加支付码充值记录
$data['service_fee'] = $server_fee;//手续费用
$data['market_amount'] = $market_amount; //换算的市场金额
$data['total_amount'] = $total_amount; //要支付的渠道货币金额
$data['currency_rate'] = $currency_rate;
if ($channel['channel_type'] == 'Bank') {
Db::table("bot_payment_code_log")->insert([
'recharge_apply_id' => $order_id,
'user_id' => $data['user_id'],
'amount_range' => $data['amount_range'],
'recharge_amount' => $data['recharge_num'],
'payment_status' => 0,
]);
$data['recharge_type'] = 2;
} else {
$data['recharge_type'] = 1;
}
switch ($channel['type']) {
case 2:
$result = (new IndPayService())->indPay($data['order_no'], $data['total_amount']);
if ($result['status'] == 'SUCCESS') {
RechargeApplyModel::where('order_no', $data['order_no'])->update([
'order_idx' => $result['order_no'],
'pay_url' => $result['order_data'],
]);
return $this->toData(0, 'Request successful.', [
'type' => 'bank_pay',
'pay_url' => $result['order_data'],
'order_no' => $result['mer_order_no'],
]);
} else {
return $this->toData('100900', 'The system is busy. Please try again later.4', [$result['err_msg'], $result['err_code']]);
}
break;
case 3:
$result = (new MoPayService())->create_order($data['order_no'], $data['total_amount']);
if ($result['status'] == 'SUCCESS') {
RechargeApplyModel::where('order_no', $data['order_no'])->update([
'pay_url' => $result['data']['pay_url'],
]);
return $this->toData(0, 'Request successful.', [
'type' => 'bank_pay',
'pay_url' => $result['data']['pay_url'],
'order_no' => $data['order_no'],
]);
} else {
return $this->toData('100600', 'The system is busy. Please try again later.5', [$result['err_msg'], $result['err_code']]);
}
break;
case 4:
$result = (new HTPayService())->qrPay($data['order_no'], round($data['total_amount']));
if ($result['status'] == 1) {
RechargeApplyModel::where('order_no', $data['order_no'])->update([
'order_idx' => $result['orderNo'],
'pay_url' => $result['payUrl'],
'total_amount' => $result['oriAmount']
]);
return $this->toData(0, 'Request successful.', [
'type' => 'bank_pay',
'pay_url' => $result['payUrl'],
'order_no' => $data['order_no'],
]);
$order_id = RechargeApplyModel::InsertUserRecharge($data);
if ($order_id) {
switch ($channel['type']) {
case 2:
$result = (new IndPayService())->indPay($data['order_no'], $data['total_amount']);
if ($result['status'] == 'SUCCESS') {
RechargeApplyModel::where('order_no', $data['order_no'])->update([
'order_idx' => $result['order_no'],
'pay_url' => $result['order_data'],
]);
return $this->toData(0, 'Request successful.', [
'type' => 'bank_pay',
'pay_url' => $result['order_data'],
'order_no' => $result['mer_order_no'],
]);
} else {
return $this->toData('100900', 'The system is busy. Please try again later.4', [$result['err_msg'], $result['err_code']]);
}
break;
case 3:
$result = (new MoPayService())->create_order($data['order_no'], $data['total_amount']);
if ($result['status'] == 'SUCCESS') {
RechargeApplyModel::where('order_no', $data['order_no'])->update([
'pay_url' => $result['data']['pay_url'],
]);
return $this->toData(0, 'Request successful.', [
'type' => 'bank_pay',
'pay_url' => $result['data']['pay_url'],
'order_no' => $data['order_no'],
]);
} else {
return $this->toData('100600', 'The system is busy. Please try again later.5', [$result['err_msg'], $result['err_code']]);
}
break;
case 4:
$result = (new HTPayService())->qrPay($data['order_no'], round($data['total_amount']));
if ($result['status'] == 1) {
RechargeApplyModel::where('order_no', $data['order_no'])->update([
'order_idx' => $result['orderNo'],
'pay_url' => $result['payUrl'],
'total_amount' => $result['oriAmount']
]);
return $this->toData(0, 'Request successful.', [
'type' => 'bank_pay',
'pay_url' => $result['payUrl'],
'order_no' => $data['order_no'],
]);
} else {
return $this->toData('101900', 'The system is busy. Please try again later.6', [$result['status'], $result['message']]);
}
break;
case 5:
$result = (new XdPayService())->create_order($data['order_no'], $data['total_amount']);
if ($result['code'] == 200) {
RechargeApplyModel::where('order_no', $data['order_no'])->update([
'pay_url' => $result['data']['url'],
]);
return $this->toData(0, 'Request successful.', [
'type' => 'bank_pay',
'pay_url' => $result['data']['url'],
'order_no' => $data['order_no'],
]);
} else {
return $this->toData('101900', 'The system is busy. Please try again later.7', [$result['code'], $result['msg']]);
}
break;
case 6:
$result = (new QeaePayService())->create_order($data['order_no'], $data['total_amount']);
if ($result['respCode'] == 'SUCCESS') {
RechargeApplyModel::where('order_no', $data['order_no'])->update([
'pay_url' => $result['payInfo'],
]);
return $this->toData(0, 'Request successful.', [
'type' => 'bank_pay',
'pay_url' => $result['payInfo'],
'order_no' => $data['order_no'],
]);
} else {
return $this->toData('101900', 'The system is busy. Please try again later.8', [$result['respCode'], $result['tradeMsg']]);
}
break;
case 7:
$result = (new NicePayService())->create_order($data['order_no'], $data['total_amount']);
if ($result['err'] == 0 & & !empty($result)) {
RechargeApplyModel::where('order_no', $data['order_no'])->update([
'pay_url' => $result['url'],
]);
return $this->toData(0, 'Request successful.', [
'type' => 'bank_pay',
'pay_url' => $result['url'],
'order_no' => $data['order_no'],
]);
} else {
return $this->toData('101900', 'The system is busy. Please try again later.9', [$result['err'], $result['err_msg']]);
}
break;
case 8:
$result = (new ClickPayService())->create_order($data['order_no'], $data['total_amount']);
if (strtoupper($result['platRespCode']) == 'SUCCESS') {
RechargeApplyModel::where('order_no', $data['order_no'])->update([
'order_idx' => $result['platOrderNum'],
]);
return $this->toData(0, 'Request successful.', [
'type' => 'bank_pay',
'pay_url' => $result['payData'],
'order_no' => $data['order_no'],
]);
} else {
return $this->toData('101900', 'The system is busy. Please try again later.10');
}
break;
case 9:
if(in_array(trim($data['product']),['TRC20H5','TRC20Buy'])){
$result = (new StarPayService())->create_order($data['order_no'], $data['total_amount'],$data['product'],$data['extra']);
} else {
return $this->toData('101900', 'The system is busy. Please try again later.6', [$result['status'], $result['message']]);
}
break;
case 5:
$result = (new XdPayService())->create_order($data['order_no'], $data['total_amount']);
if ($result['code'] == 200) {
$respon=json_decode($result['params'],true);
RechargeApplyModel::where('order_no', $data['order_no'])->update([
'pay_url' => $respon['pay url'],
'pay_url' => $result['data']['url'],
]);
return $this->toData(0, 'Request successful.', [
'type' => 'bank_pay',
'pay_url' => $respon['pay url'],
'pay_url' => $result['data']['url'],
'order_no' => $data['order_no'],
]);
} else {
return $this->toData('100600', 'The system is busy. Please try again later.5', $result );
return $this->toData('101900', 'The system is busy. Please try again later.7', [$result['code'], $result['msg']]);
}
}else{
return $this->toData('102000', 'The system is busy. Please try again later.20');
}
break;
default:
return $this->toData(0, 'Request successful.', []);
break;
break;
case 6:
$result = (new QeaePayService())->create_order($data['order_no'], $data['total_amount']);
if ($result['respCode'] == 'SUCCESS') {
RechargeApplyModel::where('order_no', $data['order_no'])->update([
'pay_url' => $result['payInfo'],
]);
return $this->toData(0, 'Request successful.', [
'type' => 'bank_pay',
'pay_url' => $result['payInfo'],
'order_no' => $data['order_no'],
]);
} else {
return $this->toData('101900', 'The system is busy. Please try again later.8', [$result['respCode'], $result['tradeMsg']]);
}
break;
case 7:
$result = (new NicePayService())->create_order($data['order_no'], $data['total_amount']);
if ($result['err'] == 0 & & !empty($result)) {
RechargeApplyModel::where('order_no', $data['order_no'])->update([
'pay_url' => $result['url'],
]);
return $this->toData(0, 'Request successful.', [
'type' => 'bank_pay',
'pay_url' => $result['url'],
'order_no' => $data['order_no'],
]);
} else {
return $this->toData('101900', 'The system is busy. Please try again later.9', [$result['err'], $result['err_msg']]);
}
break;
case 8:
$result = (new ClickPayService())->create_order($data['order_no'], $data['total_amount']);
if (strtoupper($result['platRespCode']) == 'SUCCESS') {
RechargeApplyModel::where('order_no', $data['order_no'])->update([
'order_idx' => $result['platOrderNum'],
]);
return $this->toData(0, 'Request successful.', [
'type' => 'bank_pay',
'pay_url' => $result['payData'],
'order_no' => $data['order_no'],
]);
} else {
return $this->toData('101900', 'The system is busy. Please try again later.10');
}
break;
case 9:
if(in_array(trim($data['product']),['TRC20H5','TRC20Buy'])){
$result = (new StarPayService())->create_order($data['order_no'], $data['total_amount'],$data['product'],$data['extra']);
if ($result['code'] == 200) {
$respon=json_decode($result['params'],true);
RechargeApplyModel::where('order_no', $data['order_no'])->update([
'pay_url' => $respon['payurl'],
]);
return $this->toData(0, 'Request successful.', [
'type' => 'bank_pay',
'pay_url' => $respon['payurl'],
'order_no' => $data['order_no'],
]);
} else {
return $this->toData('100600', 'The system is busy. Please try again later.5', $result);
}
}else{
return $this->toData('102000', 'The system is busy. Please try again later.20');
}
break;
default:
return $this->toData(0, 'Request successful.', []);
}
} else {
return $this->toData(500, lang('system_busy'));
}
} else {
return $this->toData(500, lang('system_busy'));
}
// 没有匹配到支付方式,异常错误
return $this->toData('500', 'system_busy');
}
// 获取支付码配置列表
@ -275,6 +295,51 @@ class PayService extends BaseHomeService
}
}
// 创建用户支付码配置下单记录
public function AddUserPaymentCodeLog($userID, $param)
{
try {
if (empty($param['amount_range'])) {
return $this->toData('400', '参错错误');
}
Db::table("bot_payment_code_log")->insert([
'recharge_apply_id' => 0,
'user_id' => $userID,
'amount_range' => $param['amount_range'],
'payment_status' => 0,
]);
return $this->toData('0', 'SUCCESS', []);
} catch (\Exception $e) {
return $this->toData(500, lang('system_busy'), [$e->getMessage(), $e->getTrace()]);
}
}
// 前端通过轮询查询用户最近一次提交的冲值范围订单信息‘
public function GetLatestUserPaymentCodeLog($userID, $param)
{
try {
if (empty($param['amount_range'])) {
return $this->toData('400', '参错错误');
}
$info = PaymentCodeLogModel::where(['user_id'=>$userID,'amount_range'=>$param['amount_range']])->order("id", "desc")->find();
if (empty($info)) {
return $this->toData('500', '数据不存在');
}
$info = $info->toArray();
$info['qr_code'] = '';
if (!empty($info['payment_code_config_id'])) {
$paymentCodeConfig = PaymentCodeConfigModel::where(['id'=>$info['payment_code_config_id']])->find();
if (!empty($paymentCodeConfig)) {
$info['qr_code'] = $paymentCodeConfig->qr_code;
}
}
return $this->toData('0', 'SUCCESS', $info);
} catch (\Exception $e) {
return $this->toData(500, lang('system_busy'), [$e->getMessage(), $e->getTrace()]);
}
}
// 获取用户的支付码配置下单记录
public function getUserPaymentCodeLog($userID, $param)
{