6
0
Fork 0

修复奖励BUG

release
李静 2022-01-07 11:17:50 +08:00
parent a48071aac6
commit acb960a952
5 changed files with 22 additions and 19 deletions

View File

@ -2,7 +2,6 @@
namespace App\Console\Commands\Distribution;
use App\Exceptions\BizException;
use App\Models\DistributionPreIncome;
use App\Models\DistributionPreIncomeJob;
use App\Models\MerchantMessage;
@ -48,13 +47,6 @@ class PreIncomeJobCommand extends Command
DB::rollBack();
report($e);
if ($e instanceof BizException) {
$job->update([
'status' => DistributionPreIncomeJob::STATUS_FAILED,
'failed_reason' => $e->getMessage(),
]);
}
}
//发送商家端预收益进帐消息

View File

@ -34,8 +34,11 @@ class OrderSettleCommand extends Command
public function handle()
{
// 只查询可结算的订单,并且没有处理中的售后单
// 检查订单是否有未执行的分销任务
Order::whereDoesntHave('afterSales', function ($query) {
return $query->processing();
})->whereDoesntHave('distributionPreIncomeJobs', function ($query) {
return $query->pending();
})->settlable()->chunkById(200, function ($orders) {
$orders->load(['user', 'afterSales']);

View File

@ -213,6 +213,14 @@ class Order extends Model
return $this->hasMany(AfterSale::class, 'order_id');
}
/**
* 属于此订单的预收益任务
*/
public function distributionPreIncomeJobs()
{
return $this->morphMany(DistributionPreIncomeJob::class, 'jobable');
}
/**
* 此订单是否待付款
*

View File

@ -358,7 +358,7 @@ class AfterSaleService
if (in_array($afterSale->type, [AfterSale::TYPE_REFUND_AND_RETURN, AfterSale::TYPE_REFUND])) {
if ($afterSaleProduct->total_amount > 0) {
// 总销售值
$totalSalesValue = bcmul($afterSaleProduct->sales_value, $afterSaleProduct->quantity);
$totalSalesValue = bcmul($afterSaleProduct->sales_value, $afterSaleProduct->quantity, 2);
// 售后变更金额
$amount = $afterSale->amount;
@ -459,11 +459,16 @@ class AfterSaleService
'remarks' => $remarks,
]);
if (! $afterSaleProduct->isGift() && in_array($afterSale->type, [
AfterSale::TYPE_REFUND_AND_RETURN,
AfterSale::TYPE_REFUND,
AfterSale::TYPE_CHANGE,
])) {
// 订单未结算
// 非赠品售后单,且售后单类型是换货、退款、退款退货
if (! $order->is_settle
&& ! $afterSaleProduct->isGift()
&& in_array($afterSale->type, [
AfterSale::TYPE_REFUND_AND_RETURN,
AfterSale::TYPE_REFUND,
AfterSale::TYPE_CHANGE,
])
) {
DistributionPreIncomeJob::create([
'jobable_id' => $afterSale->id,
'jobable_type' => $afterSale->getMorphClass(),

View File

@ -2,7 +2,6 @@
namespace App\Services;
use App\Exceptions\BizException;
use App\Models\AfterSale;
use App\Models\DistributionPreIncome;
use App\Models\DistributionPreIncomeJob;
@ -37,10 +36,6 @@ class DistributionPreIncomeJobService
case AfterSale::class:
$this->runOrderAfterSaleJob($job);
break;
default:
throw new BizException('任务类型不支持');
break;
}
$job->update([