feat(commission): 优化分润计算逻辑,移除冗余代码,提高可读性和性能

This commit is contained in:
mkm 2024-08-26 23:09:35 +08:00
parent df9ed597fc
commit 63c90c8bbf

View File

@ -677,53 +677,16 @@ class PayNotifyLogic extends BaseLogic
} }
$info = StoreOrderCartInfo::where('oid', $order['id'])->field('store_id,product_id,cart_num')->select(); $info = StoreOrderCartInfo::where('oid', $order['id'])->field('store_id,product_id,cart_num')->select();
$comm = new CommissionProductLogic(); $comm = new CommissionProductLogic();
foreach ($info as $k => $v) {
$comm->calculate_product_flow($v, $order, $village_uid, $brigade_uid, $user_ship);
}
CommissionnLogic::setStore($order, $village_uid, $brigade_uid, $transaction_id);
return true;
if (isset($user) && $order['store_id'] == getenv('ACTIVITY_STORE_ID') && !in_array($user['user_ship'], [4, 6, 7])) {
try { try {
$info = StoreOrderCartInfo::where('oid', $order['id'])->field('store_id,product_id,cart_num')->select();
$comm = new CommissionProductLogic();
foreach ($info as $k => $v) { foreach ($info as $k => $v) {
$comm->calculate_product_flow($v, $order, $village_uid, $brigade_uid, $user_ship); $comm->calculate_product_flow($v, $order, $village_uid, $brigade_uid, $user_ship);
} }
CommissionnLogic::setStore($order, $village_uid, $brigade_uid, $transaction_id); CommissionnLogic::setStore($order, $village_uid, $brigade_uid, $transaction_id);
return true; } catch (\Throwable $e) {
} catch (\Exception $e) { Log::error('分润报错' . $e->getMessage());
Log::error('活动分润报错' . $e->getMessage());
return false; return false;
} }
}
switch ($user_ship) {
case 1: // 厨师
//case 4: // 商户
//case 5: // 种养殖
// case 6: // 酒店
// case 7: // 食堂
case 8: // 一条龙
CommissionLogic::setCook($order, $village_uid, $brigade_uid, $transaction_id);
break;
case 2: // 村长
CommissionLogic::setVillage($order, $village_uid, $brigade_uid, $transaction_id);
break;
case 3: // 队长
CommissionLogic::setBrigade($order, $village_uid, $brigade_uid, $transaction_id);
break;
default:
CommissionLogic::setStore($order, $transaction_id);
break;
}
} else { } else {
$info = StoreOrderCartInfo::where('oid', $order['id'])->field('store_id,product_id,cart_num')->select();
$comm = new CommissionProductLogic();
foreach ($info as $k => $v) {
$comm->calculate_product_flow($v, $order, $village_uid, $brigade_uid, $user_ship);
}
CommissionnLogic::setStore($order, $village_uid, $brigade_uid, $transaction_id);
return true;
if (isset($user) && $order['store_id'] == getenv('ACTIVITY_STORE_ID') && !in_array($user['user_ship'], [4, 6, 7])) {
try { try {
$info = StoreOrderCartInfo::where('oid', $order['id'])->field('store_id,product_id,cart_num')->select(); $info = StoreOrderCartInfo::where('oid', $order['id'])->field('store_id,product_id,cart_num')->select();
$comm = new CommissionProductLogic(); $comm = new CommissionProductLogic();
@ -731,13 +694,11 @@ class PayNotifyLogic extends BaseLogic
$comm->calculate_product_flow($v, $order, $village_uid, $brigade_uid, $user_ship); $comm->calculate_product_flow($v, $order, $village_uid, $brigade_uid, $user_ship);
} }
CommissionnLogic::setStore($order, $village_uid, $brigade_uid, $transaction_id); CommissionnLogic::setStore($order, $village_uid, $brigade_uid, $transaction_id);
return true; } catch (\Throwable $e) {
} catch (\Exception $e) { Log::error('分润报错' . $e->getMessage());
Log::error('活动分润报错' . $e->getMessage());
return false; return false;
} }
} return true;
CommissionLogic::setStore($order, $transaction_id);
} }
} }