修改:进货订单生成后 品牌额度处理独立到订单生成成功事件中心处理,不在主流程公共方法中处理

This commit is contained in:
wuhui_zzw 2024-07-02 17:26:47 +08:00
parent cb3732b958
commit 239be9a568
2 changed files with 65 additions and 1543 deletions

View File

@ -1,11 +1,12 @@
<?php
namespace app\listener\exchangeQuota;
use app\common\model\store\product\Product;
use app\common\model\system\merchant\MerchantQuotaRecord;
use app\common\model\user\ExchangeIntegralRecord;
use app\common\model\user\ExchangeQuotaRecord;
use app\common\model\user\User;
use app\common\repositories\store\order\StoreOrderRepository;
use app\common\repositories\system\merchant\MerchantQuotaRepository;
use app\common\repositories\user\ExchangeQuotaRepository;
use think\facade\Log;
@ -20,11 +21,11 @@ class OrderCreateEvent{
switch((int)$this->groupOrder->activity_type){
// 酒道馆和小酒馆兑换订单
case 36:$this->quotaAndIntegralHandle();break;
// 进货订单
case 35:$this->merQuotaHandle();break;
}
}catch(\Exception $e){
$data = [
'uid' => $this->groupOrder->uid,
@ -55,7 +56,7 @@ class OrderCreateEvent{
// 酒道馆和小酒馆兑换订单生成前处理
private function quotaAndIntegralHandle(){
// 获取订单列表
$orderField = 'order_id,group_order_id,uid,mer_id,quota_integral,quota_integral_price,quota_integral_diff,quota_integral_diff_money';
$orderField = 'order_id,group_order_id,uid,mer_id';
$orderProductField = [
'uid',
'order_product_id',
@ -176,7 +177,67 @@ class OrderCreateEvent{
return true;
}
// 进货订单处理
private function merQuotaHandle(){
if((int)$this->groupOrder->with_goods_mer_id <= 0) return true;
// 获取订单列表
$orderField = 'order_id,group_order_id,uid,mer_id,mer_quota_title,mer_quota_other,with_goods_mer_id';
$orderProductField = [
'uid',
'order_product_id',
'order_id',
'product_id',
'total_price',
'mer_quota_title',
'mer_quota_other'
];
$orderList = $this->getOrderList($orderField, $orderProductField);
// 循环处理
$quotaHoldInfo = app()->make(MerchantQuotaRepository::class)->getQuotaInfo($this->groupOrder->with_goods_mer_id);
$quotaRecordInsertData = [];
foreach($orderList as $orderInfo){
// 判断:是否存在冠名品牌额度
if((float)$orderInfo['mer_quota_title'] > 0){
// 变更持有信息
$changeFront = (float)sprintf("%.2f", $quotaHoldInfo->title_brand_limit - $quotaHoldInfo->title_brand_used);
$quotaHoldInfo->title_brand_used += (float)$orderInfo['mer_quota_title'];
$quotaHoldInfo->title_brand_total += (float)$orderInfo['mer_quota_title'];
//变更记录
$quotaRecordInsertData[] = [
'mer_id' => $orderInfo['with_goods_mer_id'],
'change_type' => (int)0,
'change_front' => $changeFront,
'change_quantity' => (float)$orderInfo['mer_quota_title'],
'change_after' => (float)sprintf("%.2f", $quotaHoldInfo->title_brand_limit - $quotaHoldInfo->title_brand_used),
'source' => 1,
'order_id' => $orderInfo['order_id'],
'quota_type' => 2
];
}
// 判断:是否存在其他品牌额度
if((float)$orderInfo['mer_quota_other'] > 0){
// 变更持有信息
$changeFront = (float)sprintf("%.2f", $quotaHoldInfo->other_brand_limit - $quotaHoldInfo->other_brand_used);
$quotaHoldInfo->other_brand_used += (float)$orderInfo['mer_quota_other'];
$quotaHoldInfo->other_brand_total += (float)$orderInfo['mer_quota_other'];
//变更记录
$quotaRecordInsertData[] = [
'mer_id' => $orderInfo['with_goods_mer_id'],
'change_type' => (int)0,
'change_front' => $changeFront,
'change_quantity' => (float)$orderInfo['mer_quota_title'],
'change_after' => (float)sprintf("%.2f", $quotaHoldInfo->other_brand_limit - $quotaHoldInfo->other_brand_used),
'source' => 1,
'order_id' => $orderInfo['order_id'],
'quota_type' => 3
];
}
}
$quotaHoldInfo->save();
if(count($quotaRecordInsertData) > 0) MerchantQuotaRecord::insertAll($quotaRecordInsertData);
return true;
}