处理转账订单的错误

This commit is contained in:
luofei 2024-03-07 15:15:37 +08:00
parent 1c6517ee20
commit 92ed3cef19
3 changed files with 84 additions and 1 deletions

View File

@ -793,7 +793,7 @@ class StoreOrderRepository extends BaseRepository
// ], $order->mer_id);
}
$promoterCommission = FinancialRecord::where('order_id', $order['id'])
$promoterCommission = FinancialRecord::where('order_id', $order['order_id'])
->where('financial_type', 'promoter_commission')
->column('user_id,number');
if (!empty($promoterCommission)) {

View File

@ -13,10 +13,15 @@ namespace app\common\repositories\store\order;
use app\common\dao\store\order\StoreOrderOtherDao;
use app\common\dao\system\financial\FinancialDao;
use app\common\model\store\order\StoreGroupOrder;
use app\common\model\store\order\StoreGroupOrderOther;
use app\common\model\store\order\StoreOrder;
use app\common\model\store\order\StoreOrderInterestOther;
use app\common\model\store\order\StoreOrderOther;
use app\common\model\store\order\StoreRefundOrder;
use app\common\model\store\order\StoreRefundOrderOther;
use app\common\model\system\merchant\FinancialRecord;
use app\common\model\system\merchant\Merchant;
use app\common\model\user\User;
use app\common\repositories\BaseRepository;
use app\common\repositories\store\product\ProductRepository;
@ -520,14 +525,34 @@ class StoreOtherOrderRepository extends BaseRepository
public function takeAfter(StoreOrderOther $order, ?User $user)
{
Db::transaction(function () use ($user, $order) {
if ($user && $order->pay_type != StoreGroupOrder::PAY_TYPE_CREDIT_BUY) {
$this->computed($order, $user);
}
Queue::push(SendSmsJob::class, ['tempId' => 'ORDER_TAKE_SUCCESS', 'id' => $order->order_id]);
Queue::push(SendSmsJob::class, ['tempId' => 'ADMIN_TAKE_DELIVERY_CODE', 'id' => $order->order_id]);
if ($order->pay_type != StoreGroupOrder::PAY_TYPE_CREDIT_BUY) {
app()->make(MerchantRepository::class)->computedSupplyLockMoney($order);
}
if (!empty($order->interest) && $order->interest->status == StoreOrderInterestOther::STATUS_UNSETTLED) {
$order->interest->start_time = date('Y-m-d H:i:s', strtotime("+{$order->interest->settle_cycle} days"));
$order->interest->save();
}
$order->save();
if ($order->uid != $order->merchant->uid && !$order->orderProduct[0]->product->isPlatformCard()) {
$refundPrice = StoreRefundOrderOther::where('order_id', $order['order_id'])->where('status', '<>', -1)->sum('refund_price');
$money = bcsub($order->total_price, bcadd($order['extension_one'], $order['extension_two'], 3), 2);
$money = bcsub($money, $refundPrice, 2);
//订单确认收货,增加商户销售金额
Merchant::where('mer_id', $order->mer_id)->update(['sale_amount' => Db::raw('sale_amount+' . $money)]);
//订单确认收货,增加商户采购金额
$merId = Merchant::where('uid', $order->uid)->value('mer_id');
if (!empty($merId)) {
Merchant::where('mer_id', $merId)->update(['purchase_amount' => Db::raw('purchase_amount+' . $money)]);
}
}
});
}
@ -1874,4 +1899,26 @@ class StoreOtherOrderRepository extends BaseRepository
throw new Exception($e->getMessage());
}
}
public function computed(StoreOrderOther $order, User $user)
{
/** @var UserBillRepository $userBillRepository */
$userBillRepository = app()->make(UserBillRepository::class);
$promoterCommission = FinancialRecord::where('order_id', $order['order_id'])
->where('financial_type', 'promoter_commission')
->column('user_id,number');
if (!empty($promoterCommission)) {
$userBillRepository->incBill($promoterCommission['user_id'], 'brokerage', 'order_one', [
'link_id' => $order['order_id'],
'status' => 0,
'title' => '获得推广佣金',
'number' => $promoterCommission['number'],
'mark' => $order->merchant['mer_name'] . '成功销售' . floatval($order['pay_price']) . '元,奖励推广佣金' . floatval($promoterCommission['number']),
'balance' => 0
]);
$balance = bcadd($user->now_money, $promoterCommission['number'], 2);
$user->save(['now_money' => $balance]);
}
}
}

View File

@ -603,6 +603,42 @@ class MerchantRepository extends BaseRepository
});
}
public function computedSupplyLockMoney($order)
{
Db::transaction(function () use ($order) {
$money = 0;
/** @var UserBillRepository $make */
$make = app()->make(UserBillRepository::class);
$bills = $make->search(['mer_id' => $order['mer_id'], 'category' => 'mer_lock_money', 'type' => 'order', 'link_id' => '1' . $order->order_id, 'status' => 0])->select();
foreach ($bills as $bill) {
if ($bill) {
$money = bcsub($bill->number, $make->refundMerchantMoney($bill->link_id, $bill->type, $bill->mer_id), 2);
if ($order->presellOrder) {
$presellBill = $make->search(['category' => 'mer_lock_money', 'type' => 'presell', 'link_id' => '2' . $order->presellOrder->presell_order_id, 'status' => 0])->find();
if ($presellBill) {
$money = bcadd($money, bcsub($presellBill->number, $make->refundMerchantMoney($presellBill->link_id, $presellBill->type, $presellBill->mer_id), 2), 2);
$presellBill->status = 1;
$presellBill->save();
}
}
$bill->status = 1;
$bill->save();
}
if ($money > 0) {
app()->make(UserBillRepository::class)->incBill($bill->uid, 'mer_computed_money', 'order', [
'link_id' => $order->order_id,
'mer_id' => $bill->mer_id,
'status' => 0,
'title' => '商户待解冻余额',
'number' => $money,
'mark' => '交易完成,商户待解冻余额' . floatval($money) . '元',
'balance' => 0
]);
}
}
});
}
public function checkMargin($merId, $typeId)
{
$merchant = $this->dao->get($merId);