给商户记账

lszyh
lqmac 4 months ago
parent 9d7737a32a
commit 82aa506e2d
  1. 51
      app/api/service/order/PaySuccess.php
  2. 5
      app/common/model/MerchantPay.php
  3. 2
      app/common/service/qrcode/InviteUser.php

@ -344,27 +344,36 @@ class PaySuccess extends BaseService
// 当前订单信息
$orderInfo = $this->getOrderInfo();
// 余额支付
if ($this->method == PaymentMethodEnum::BALANCE) {
// 更新用户余额
UserModel::setDecBalance((int)$orderInfo['user_id'], (float)$orderInfo['pay_price']);
// 新增余额变动记录
BalanceLogModel::add(SceneEnum::CONSUME, [
'user_id' => (int)$orderInfo['user_id'],
'money' => -$orderInfo['pay_price'],
], ['order_no' => $orderInfo['order_no']]);
// //增加商户支付详情
// $model = \app\store\model\Merchant::detail($orderInfo['merchant_id']);
// $precent = 1;
// if ($model['commission_ratio']) {
// $precent = (1 - $model['commission_ratio'] / 1000);
// }
// $precentPrice = round($precent * $orderInfo['pay_price'], 2);
// (new merchantPayModel())->addDetail($orderInfo, $precentPrice);
// //累计商户余额支付金额
// merchantModel::setIncTotal($orderInfo['merchant_id'], $precentPrice);
if ($this->method == PaymentMethodEnum::BALANCE || $this->method == PaymentMethodEnum::HUIFU) {
if ($this->method == PaymentMethodEnum::BALANCE) {
// 更新用户余额
UserModel::setDecBalance((int)$orderInfo['user_id'], (float)$orderInfo['pay_price']);
// 新增余额变动记录
BalanceLogModel::add(SceneEnum::CONSUME, [
'user_id' => (int)$orderInfo['user_id'],
'money' => -$orderInfo['pay_price'],
], ['order_no' => $orderInfo['order_no']]);
}
if ($orderInfo['merchant_id']) {
//增加商户支付详情
$model = \app\store\model\Merchant::detail($orderInfo['merchant_id']);
if ($model) {
$precent = 1;
if ($model['commission_ratio']) {
$precent = (1 - $model['commission_ratio'] / 1000);
}
$precentPrice = round($precent * $orderInfo['pay_price'], 2);
(new merchantPayModel())->addDetail($orderInfo, $precentPrice, $this->method == PaymentMethodEnum::HUIFU ? 1 : 0);
//累计商户余额支付金额
merchantModel::setIncTotal($orderInfo['merchant_id'], $precentPrice);
}
}
}
// 将第三方交易记录更新为已支付状态
if (in_array($this->method, [PaymentMethodEnum::WECHAT, PaymentMethodEnum::ALIPAY, PaymentMethodEnum::HUIFU])) {

@ -34,14 +34,15 @@ class MerchantPay extends BaseModel
* @param float $money
* @return mixed
*/
public function addDetail($orderInfo, $precentPrice)
public function addDetail($orderInfo, $precentPrice, $source = 0)
{
if (!empty($orderInfo['merchant_id'])) {
$data = [
'order_id' => $orderInfo['order_id'],
//'store_id' => $orderInfo['store_id'],
'store_id' => $orderInfo['store_id'],
'merchant_id' => $orderInfo['merchant_id'],
'total_amount' => $precentPrice,
'source' => $source,
];
return $this->save($this->createData($data));
}

@ -61,7 +61,7 @@ class InviteUser extends BaseQRcode
// 小程序码参数
$scene = "refereeId:" . ($this->userInfo['user_id'] ?: '');
// 下载小程序码
$page = 'pages/index/index';
$page = 'pages/login/index';
$qrcode = $this->getQrcode($storeId, $scene, $page, $this->channel);
//获取图片名称
$arr = explode('/', $qrcode);

Loading…
Cancel
Save