添加:商品绑定省公司后下单流程特殊处理

添加:省公司门店及供应商提成处理
This commit is contained in:
wuhui_zzw 2024-04-19 16:42:37 +08:00
parent 9a4634b038
commit 8fcd978be1
6 changed files with 183 additions and 39 deletions

View File

@ -1028,6 +1028,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository{
// 数据补齐 总平台商品订单可能存在部分数据不存在 // 数据补齐 总平台商品订单可能存在部分数据不存在
$merchantCart['commission_rate'] = $merchantCart['commission_rate'] ?? 0; $merchantCart['commission_rate'] = $merchantCart['commission_rate'] ?? 0;
$cost = 0; $cost = 0;
$total_extension_one = 0; $total_extension_one = 0;
$total_extension_two = 0; $total_extension_two = 0;
@ -1152,7 +1153,6 @@ class StoreOrderCreateRepository extends StoreOrderRepository{
'point_id' => $merchantCart['take']['id'] ?? 0, 'point_id' => $merchantCart['take']['id'] ?? 0,
]; ];
$allUseCoupon = array_merge($allUseCoupon,$merchantCart['order']['useCouponIds']); $allUseCoupon = array_merge($allUseCoupon,$merchantCart['order']['useCouponIds']);
$orderList[] = $_order; $orderList[] = $_order;
$totalPostage = bcadd($totalPostage,$_order['total_postage'],2); $totalPostage = bcadd($totalPostage,$_order['total_postage'],2);
@ -1449,6 +1449,9 @@ class StoreOrderCreateRepository extends StoreOrderRepository{
'exchange_integral_price' => $cart['exchange_integral_price'] ?? 0, 'exchange_integral_price' => $cart['exchange_integral_price'] ?? 0,
'wine_diff_money' => $cart['wine_diff_money'] ?? 0, 'wine_diff_money' => $cart['wine_diff_money'] ?? 0,
'wine_diff_money_price' => $cart['wine_diff_money_price'] ?? 0, 'wine_diff_money_price' => $cart['wine_diff_money_price'] ?? 0,
// 特殊商品 代理及省公司门店,供应商提成处理
'province_here_id' => $cart['province_here_id'] ?? 0,
'province_send_id' => $cart['province_send_id'] ?? 0,
]; ];
} }
$userMerchantRepository->getInfo($uid,$order['mer_id']); $userMerchantRepository->getInfo($uid,$order['mer_id']);

View File

@ -311,12 +311,47 @@ class StoreOrderRepository extends BaseRepository
'user_type' => $storeOrderStatusRepository::U_TYPE_USER, 'user_type' => $storeOrderStatusRepository::U_TYPE_USER,
]; ];
//TODO 成为推广员 // 循环商品处理
foreach ($order->orderProduct as $product) { foreach ($order->orderProduct as $product) {
$product->append(['product']);
//TODO 成为推广员
if ($flag && $product['cart_info']['product']['is_gift_bag']) { if ($flag && $product['cart_info']['product']['is_gift_bag']) {
app()->make(UserRepository::class)->promoter($order->uid); app()->make(UserRepository::class)->promoter($order->uid);
$flag = false; $flag = false;
} }
// 判断:是否存在 province_here_id当前所在地址绑定商户id
if((int)$product['province_here_id'] > 0 && (float)$product['product']['agent_two_money'] > 0){
$finance[] = [
'order_id' => $order->order_id,
'order_sn' => $order->order_sn,
'user_info' => $groupOrder->user->nickname,
'user_id' => $uid,
'financial_type' => 'province_mer',// 省公司门店提成
'financial_pm' => 1,
'type' => 1,
'number' => (float)sprintf("%.2f",(float)$product['product']['agent_two_money'] * (int)$product['product_num']),
'mer_id' => (int)$product['province_here_id'],
'financial_record_sn' => $financeSn. ($i++),
'status' => 0,
];
}
// 判断:是否存在 供应商提成
if((float)$product['product']['supplier_money'] > 0 && (int)$product['product']['supplier_mer_id'] > 0){
$finance[] = [
'order_id' => $order->order_id,
'order_sn' => $order->order_sn,
'user_info' => $groupOrder->user->nickname,
'user_id' => $uid,
'financial_type' => 'supplier_mer',// 供应商提成
'financial_pm' => 1,
'type' => 1,
'number' => (float)sprintf("%.2f",(float)$product['product']['supplier_money'] * (int)$product['product_num']),
'mer_id' => (int)(int)$product['product']['supplier_mer_id'],
'financial_record_sn' => $financeSn. ($i++),
'status' => 0,
];
}
} }
$finance[] = [ $finance[] = [
@ -329,7 +364,8 @@ class StoreOrderRepository extends BaseRepository
'type' => $presell ? 2 : 1, 'type' => $presell ? 2 : 1,
'number' => $order->pay_price, 'number' => $order->pay_price,
'mer_id' => $order->mer_id, 'mer_id' => $order->mer_id,
'financial_record_sn' => $financeSn . ($i++) 'financial_record_sn' => $financeSn . ($i++),
'status' => 1,
]; ];
$_payPrice = bcsub($order->pay_price, bcadd($order['extension_one'], $order['extension_two'], 3), 2); $_payPrice = bcsub($order->pay_price, bcadd($order['extension_one'], $order['extension_two'], 3), 2);
@ -363,7 +399,8 @@ class StoreOrderRepository extends BaseRepository
'type' => 1, 'type' => 1,
'number' => $order['extension_one'], 'number' => $order['extension_one'],
'mer_id' => $order->mer_id, 'mer_id' => $order->mer_id,
'financial_record_sn' => $financeSn . ($i++) 'financial_record_sn' => $financeSn . ($i++),
'status' => 1,
]; ];
} }
@ -378,7 +415,8 @@ class StoreOrderRepository extends BaseRepository
'type' => 1, 'type' => 1,
'number' => $order['extension_two'], 'number' => $order['extension_two'],
'mer_id' => $order->mer_id, 'mer_id' => $order->mer_id,
'financial_record_sn' => $financeSn . ($i++) 'financial_record_sn' => $financeSn . ($i++),
'status' => 1,
]; ];
} }
if ($order['commission_rate'] > 0) { if ($order['commission_rate'] > 0) {
@ -392,7 +430,8 @@ class StoreOrderRepository extends BaseRepository
'type' => 1, 'type' => 1,
'number' => $_order_rate, 'number' => $_order_rate,
'mer_id' => $order->mer_id, 'mer_id' => $order->mer_id,
'financial_record_sn' => $financeSn . ($i++) 'financial_record_sn' => $financeSn . ($i++),
'status' => 1,
]; ];
} }
$finance[] = [ $finance[] = [
@ -405,7 +444,8 @@ class StoreOrderRepository extends BaseRepository
'type' => 2, 'type' => 2,
'number' => $_payPrice, 'number' => $_payPrice,
'mer_id' => $order->mer_id, 'mer_id' => $order->mer_id,
'financial_record_sn' => $financeSn . ($i++) 'financial_record_sn' => $financeSn . ($i++),
'status' => 1,
]; ];
if ($order->platform_coupon_price > 0) { if ($order->platform_coupon_price > 0) {
$finance[] = [ $finance[] = [
@ -418,7 +458,8 @@ class StoreOrderRepository extends BaseRepository
'type' => 1, 'type' => 1,
'number' => $order->platform_coupon_price, 'number' => $order->platform_coupon_price,
'mer_id' => $order->mer_id, 'mer_id' => $order->mer_id,
'financial_record_sn' => $financeSn . ($i++) 'financial_record_sn' => $financeSn . ($i++),
'status' => 1,
]; ];
$_payPrice = bcadd($_payPrice, $order->platform_coupon_price, 2); $_payPrice = bcadd($_payPrice, $order->platform_coupon_price, 2);
} }
@ -465,8 +506,7 @@ class StoreOrderRepository extends BaseRepository
$financialRecordRepository->insertAll($finance); $financialRecordRepository->insertAll($finance);
$storeOrderStatusRepository->batchCreateLog($orderStatus); $storeOrderStatusRepository->batchCreateLog($orderStatus);
if (count($groupOrder['give_coupon_ids']) > 0) if (count($groupOrder['give_coupon_ids']) > 0) $groupOrder['give_coupon_ids'] = app()->make(StoreCouponRepository::class)->getGiveCoupon($groupOrder['give_coupon_ids'])->column('coupon_id');
$groupOrder['give_coupon_ids'] = app()->make(StoreCouponRepository::class)->getGiveCoupon($groupOrder['give_coupon_ids'])->column('coupon_id');
$groupOrder->save(); $groupOrder->save();
}); });

View File

@ -4,6 +4,7 @@
namespace app\common\repositories\store\product; namespace app\common\repositories\store\product;
use app\common\model\marketing\Agent;
use app\common\model\store\product\Product; use app\common\model\store\product\Product;
use app\common\model\store\product\ProductLabel; use app\common\model\store\product\ProductLabel;
use app\common\model\system\merchant\Merchant; use app\common\model\system\merchant\Merchant;
@ -1316,7 +1317,7 @@ class ProductRepository extends BaseRepository
public function apiProductDetail($where,int $productType, ?int $activityId, $userInfo = null) public function apiProductDetail($where,int $productType, ?int $activityId, $userInfo = null)
{ {
$field = 'is_show,product_id,mer_id,image,slider_image,store_name,store_info,unit_name,price,cost,ot_price,stock,sales,video_link,product_type,extension_type,old_product_id,rate,guarantee_template_id,temp_id,once_max_count,pay_limit,once_min_count,integral_rate,delivery_way,delivery_free,type,cate_id,svip_price_type,svip_price,mer_svip_status'; $field = 'is_show,product_id,mer_id,image,slider_image,store_name,store_info,unit_name,price,cost,ot_price,stock,sales,video_link,product_type,extension_type,old_product_id,rate,guarantee_template_id,temp_id,once_max_count,pay_limit,once_min_count,integral_rate,delivery_way,delivery_free,type,cate_id,svip_price_type,svip_price,mer_svip_status,agent_two_ids,copy_product_id,supplier_mer_id';
$with = [ $with = [
'attr', 'attr',
'attrValue', 'attrValue',
@ -1390,6 +1391,40 @@ class ProductRepository extends BaseRepository
$product['attr'] = $attr; $product['attr'] = $attr;
$product['sku'] = $sku; $product['sku'] = $sku;
$product['isRelation'] = $isRelation; $product['isRelation'] = $isRelation;
// 商品绑定代理相关处理
$product['province_list'] = [];// 当前商品绑定的全部存在地区信息的省公司发起人
$product['province_has_list'] = [];// 存在当前商品库存的省公司门店
if($product['agent_two_ids'] && $product['copy_product_id'] > 0 && $product['supplier_mer_id'] > 0){
$product['province_list'] = Agent::getDB()
->field('id,province_id,mer_id')
->whereIn('id',$product['agent_two_ids'])
->where('province_id','>',0)
->where('mer_id','>',0)
->with([
'province' => function($query){
$query->field('id,name as province_name,code as province_code')
->bind(['province_name','province_code']);
},
])
->group('province_id')
->select()
->toArray();
$hasProvinceMer = Product::getDB()
->alias('a')
->join('merchant m', 'a.mer_id = m.mer_id', 'LEFT')
->whereIn('m.mer_id', array_filter(array_column($product['province_list'], 'mer_id')))
->where('m.status',1)
->where('m.mer_state',1)
->where('m.is_del',0)
->where('a.copy_product_id',$product['copy_product_id'])
->where('a.supplier_mer_id',$product['supplier_mer_id'])
->group('m.mer_id')
->column('m.mer_id');
$product['province_has_list'] = array_values(array_filter(array_map(function($item) use ($hasProvinceMer){
if(in_array($item['mer_id'],$hasProvinceMer)) return (int)$item['mer_id'];
},$product['province_list'])));
}
return $product; return $product;
} }

View File

@ -223,7 +223,17 @@ class StoreCart extends BaseController
*/ */
public function checkParams(validate $validate) public function checkParams(validate $validate)
{ {
$data = $this->request->params(['product_id','product_attr_unique','cart_num','is_new',['product_type',0],['group_buying_id',0],['spread_id',0]]); $data = $this->request->params([
'product_id',
'product_attr_unique',
'cart_num',
'is_new',
['product_type',0],
['group_buying_id',0],
['spread_id',0],
['province_here_id',0],
['province_send_id',0]
]);
$validate->check($data); $validate->check($data);
if ($data['spread_id']) { if ($data['spread_id']) {
if ($data['spread_id'] !== $this->request->userInfo()->uid){ if ($data['spread_id'] !== $this->request->userInfo()->uid){

View File

@ -3,11 +3,11 @@
namespace app\listener\exchangeQuota; namespace app\listener\exchangeQuota;
use app\common\model\user\ExchangeQuota;
use app\common\model\user\ExchangeQuotaRecord;
use app\common\repositories\store\product\WineProductRepository; use app\common\repositories\store\product\WineProductRepository;
use app\common\repositories\system\merchant\MerchantRepository;
use app\common\repositories\user\ExchangeQuotaRecordRepository; use app\common\repositories\user\ExchangeQuotaRecordRepository;
use app\common\repositories\user\ExchangeQuotaRepository; use app\common\repositories\user\ExchangeQuotaRepository;
use app\common\model\system\merchant\FinancialRecord;
use think\facade\Log; use think\facade\Log;
@ -33,27 +33,13 @@ class OrderTakeEvent{
// 'activity_type' => $order->activity_type // 'activity_type' => $order->activity_type
// ],1)); // ],1));
// 其他商品 // 其他商品
# 获取变更记录 条件order_id=当前订单id、变更类型=增加
$sum = (float)app()->make(ExchangeQuotaRecordRepository::class) // 酒卡额度解冻
->searchModel([ $this->quotaThawing($order);
'order_id' => $order->order_id, // 商户佣金结算
'change_type' => 1, $this->merMoneyHandle($order->order_id);
'source' => 0,// 仅查询购买赠送 进行解冻
])->sum('change_quantity');
$refundSum = (float)app()->make(ExchangeQuotaRecordRepository::class)
->searchModel([
'order_id' => $order->order_id,
'change_type' => 0,
'source' => 1,// 仅查询订单退款 减少内容
])->sum('change_quantity');
// 剩余数量 解冻
$surplusQuota = (float)sprintf("%.2f",$sum - $refundSum);
if($surplusQuota > 0){
$hold = app()->make(ExchangeQuotaRepository::class)->searchModel(['uid'=>$order->uid])->findOrEmpty();
$freezeQuota = sprintf("%.2f",$hold->freeze_quota - $surplusQuota);
$hold->freeze_quota = $freezeQuota < 0 ? 0 : $freezeQuota;
$hold->save();
}
} }
}catch(\Exception $e){ }catch(\Exception $e){
if($order->activity_type == 35){ if($order->activity_type == 35){
@ -64,6 +50,56 @@ class OrderTakeEvent{
} }
} }
// 酒卡额度解冻
private function quotaThawing($order){
# 获取变更记录 条件order_id=当前订单id、变更类型=增加
$sum = (float)app()->make(ExchangeQuotaRecordRepository::class)
->searchModel([
'order_id' => $order->order_id,
'change_type' => 1,
'source' => 0,// 仅查询购买赠送 进行解冻
])->sum('change_quantity');
$refundSum = (float)app()->make(ExchangeQuotaRecordRepository::class)
->searchModel([
'order_id' => $order->order_id,
'change_type' => 0,
'source' => 1,// 仅查询订单退款 减少内容
])->sum('change_quantity');
// 剩余数量 解冻
$surplusQuota = (float)sprintf("%.2f",$sum - $refundSum);
if($surplusQuota > 0){
$hold = app()->make(ExchangeQuotaRepository::class)->searchModel(['uid'=>$order->uid])->findOrEmpty();
$freezeQuota = sprintf("%.2f",$hold->freeze_quota - $surplusQuota);
$hold->freeze_quota = $freezeQuota < 0 ? 0 : $freezeQuota;
$hold->save();
}
}
// 商户佣金结算
private function merMoneyHandle($order_id){
$list = FinancialRecord::getDB()
->where('order_id',$order_id)
->where('status',0)
->where('number','>',0)
->where('financial_pm', 1)
->select()
->toArray();
if($list){
foreach($list as $financialInfo){
app()->make(MerchantRepository::class)->addLockMoney((int)$financialInfo['mer_id'], 'order', (int)$order_id, (float)$financialInfo['number']);
}
// 修改状态
$ids = array_column($list,'financial_record_id');
FinancialRecord::whereIn('financial_record_id',$ids)->update([
'status' => 1
]);
}
}
} }

View File

@ -4,9 +4,11 @@ namespace app\listener\exchangeQuota;
use app\common\model\store\order\StoreOrder; use app\common\model\store\order\StoreOrder;
use app\common\model\system\merchant\FinancialRecord;
use app\common\model\user\ExchangeQuota; use app\common\model\user\ExchangeQuota;
use app\common\model\user\ExchangeQuotaRecord; use app\common\model\user\ExchangeQuotaRecord;
use app\common\repositories\store\order\StoreOrderRepository; use app\common\repositories\store\order\StoreOrderRepository;
use app\common\repositories\system\merchant\MerchantRepository;
use app\common\repositories\user\ExchangeQuotaRecordRepository; use app\common\repositories\user\ExchangeQuotaRecordRepository;
use app\common\repositories\user\ExchangeQuotaRepository; use app\common\repositories\user\ExchangeQuotaRepository;
use think\facade\Log; use think\facade\Log;
@ -25,7 +27,8 @@ class OrderVerifyEvent{
$this->wineCard($orderId, $order); $this->wineCard($orderId, $order);
// 菜卡额度解冻 // 菜卡额度解冻
$this->dish($orderId, $order); $this->dish($orderId, $order);
// 商户佣金结算
$this->merMoneyHandle($orderId);
} }
@ -43,8 +46,6 @@ class OrderVerifyEvent{
$query->where('order_id',$orderId)->whereOr('main_id',$orderId); $query->where('order_id',$orderId)->whereOr('main_id',$orderId);
})->sum('total_num'); })->sum('total_num');
} }
// 酒水卡额度解冻 // 酒水卡额度解冻
public function wineCard($orderId, $order){ public function wineCard($orderId, $order){
try{ try{
@ -113,7 +114,26 @@ class OrderVerifyEvent{
Log::info('订单核销 - 菜卡额度相关处理 - 错误: '.$e->getMessage()); Log::info('订单核销 - 菜卡额度相关处理 - 错误: '.$e->getMessage());
} }
} }
// 商户佣金结算
private function merMoneyHandle($order_id){
$list = FinancialRecord::getDB()
->where('order_id',$order_id)
->where('status',0)
->where('number','>',0)
->where('financial_pm', 1)
->select()
->toArray();
if($list){
foreach($list as $financialInfo){
app()->make(MerchantRepository::class)->addLockMoney((int)$financialInfo['mer_id'], 'order', (int)$order_id, (float)$financialInfo['number']);
}
// 修改状态
$ids = array_column($list,'financial_record_id');
FinancialRecord::whereIn('financial_record_id',$ids)->update([
'status' => 1
]);
}
}