代币优化

This commit is contained in:
Dev
2026-10-27 18:30:40 +08:00
parent f53c142a56
commit 25804d500e
11 changed files with 66 additions and 27 deletions
@@ -11,6 +11,7 @@ return [
'Files' => '附件',
'Desc' => '需求详情',
'Contact' => '联系方式',
'Pay_platform' => '发布终端',
'Budget_amount' => '预算(元)',
'Limit_time' => '工期(天)',
'Weigh' => '排序',
@@ -8,6 +8,7 @@ use app\common\service\ContractService;
use app\common\service\DemandBiddingService;
use app\common\service\DemandService;
use app\common\service\OrderShipService;
use app\common\service\VirtualPayService;
use think\exception\HttpResponseException;
use think\Lang;
use think\Validate;
@@ -273,6 +274,9 @@ class Demand extends Api
try {
$demandId = $this->request->param('demandId', 0);
$info = ContractService::getWinBiddingContract($demandId);
$demand = DemandService::getOne(['id' => $demandId]);
$platform = $demand ? VirtualPayService::normalizePayPlatform($demand->pay_platform) : '';
$info->pay_platform = $platform !== '' ? $platform : 'android';
if (empty($info->data_json['customData']) && ($firstContract = ContractService::getFirstContract($demandId))) {
$data_json = $info->data_json;
$data_json['customData'] = $firstContract->data_json['customData'] ?? [];
@@ -151,6 +151,8 @@ class DemandService
'files' => $data['files'] ?? [],
'budget_amount' => $data['budget_amount'] ?? 0,
'limit_time' => $data['limit_time'] ?? 0,
// 客户发布需求时的手机系统,报价预估按这个终端。真正付款可能换设备,以支付记录为准
'pay_platform' => VirtualPayService::normalizePayPlatform($data['pay_platform'] ?? '') ?: 'android',
'publish_status' => CommonService::ONGOING,
'status' => self::STATUS_NO
];
@@ -481,8 +481,9 @@ class VirtualPayService
}
/**
* 代币数量,保留两位小数。1元=1代币时,0.01元对应 0.01 个代币
* @param float|string $amountYuan
* @return int
* @return float
* @throws \Exception
*/
private static function coinQuantity($amountYuan)
@@ -495,11 +496,9 @@ class VirtualPayService
if ($coinPerYuan < 1) {
$coinPerYuan = 1;
}
if (($fen * $coinPerYuan) % 100 !== 0) {
throw new \Exception('订单金额须为整数元才能按1元=1代币支付');
}
$quantity = bcdiv(bcmul((string)$fen, (string)$coinPerYuan, 0), '100', 2);
return intdiv($fen * $coinPerYuan, 100);
return (float)$quantity;
}
/**
+1 -1
View File
@@ -40,7 +40,7 @@ return [
'transfer_authorization_notify_url' => Env::get('app.url') . '/api/account/transferAuthorizationNotify',
],
// 小程序虚拟支付(类目不支持普通微信支付时使用)
// 代币比例须与 MP「虚拟支付-代币配置」一致:1元=1代币。buyQuantity 只能是整数,订单金额须为整数元
// 代币比例须与 MP「虚拟支付-代币配置」一致:1元=1代币。数量保留两位小数,0.01元=0.01代币
'virtual_pay' => [
'offer_id' => Env::get('wechat.vp_offer_id', ''),
'app_key' => Env::get('wechat.vp_app_key', ''), // 现网 AppKey,env=0