优化分润逻辑与财务流水处理

This commit is contained in:
mkm 2024-06-29 10:19:08 +08:00
parent cf0ac14419
commit 090955158f
4 changed files with 115 additions and 76 deletions

View File

@ -29,7 +29,7 @@ class UserProductStorageLists extends BaseAdminDataLists implements ListsSearchI
{
return [
'=' => ['uid', 'oid', 'product_id'],
'between_time' => ['create_time'],
'between_time' => 'create_time',
];
}

View File

@ -12,63 +12,62 @@ class CommissionLogic extends BaseLogic
/**
* 走村长分润
*/
public static function setVillage($order,$village_uid=0,$brigade_uid=0, $transaction_id=0)
public static function setVillage($order, $village_uid = 0, $brigade_uid = 0, $transaction_id = 0)
{
$user_1=self::user($order, 0.05, $transaction_id,$village_uid,14);//村长
$user_2=self::user($order, 0.03, $transaction_id,0,12);//会员、厨师
$user_3=self::user($order, 0.01, $transaction_id,$brigade_uid,15);//队长
$user_1 = self::user($order, 0.05, $transaction_id, $village_uid, 14); //村长
$user_2 = self::user($order, 0.03, $transaction_id, 0, 12); //会员、厨师
$user_3 = self::user($order, 0.01, $transaction_id, $brigade_uid, 15); //队长
$platform=self::platform($order, 0.02, $transaction_id);//平台
$store=self::store($order, 0.05, $transaction_id,0);//门店
$user_4=self::user($order, 0.02, $transaction_id,0,16);//其他
$platform = self::platform($order, 0.02, $transaction_id); //平台
$store = self::store($order, 0.05, $transaction_id, 0); //门店
$attrition = self::attrition($order, 0.02,$transaction_id,16); //损耗
$moeny=bcadd(bcadd(bcadd(bcadd($user_1,$user_2,2),$user_3,2),$platform,2),bcadd($store,$user_4,2),2);
$moeny = bcadd(bcadd(bcadd(bcadd($user_1, $user_2, 2), $user_3, 2), $platform, 2), bcadd($store, $attrition, 2), 2);
self::suppliter($order, $moeny, $transaction_id);
}
/**
* 走队长分润
*/
public static function setBrigade($order,$village_uid=0,$brigade_uid=0, $transaction_id=0)
public static function setBrigade($order, $village_uid = 0, $brigade_uid = 0, $transaction_id = 0)
{
$user_1=self::user($order, 0.05, $transaction_id,$brigade_uid,14);//队长
$user_2=self::user($order, 0.03, $transaction_id,0,12);////会员、厨师
$user_3=self::user($order, 0.01, $transaction_id,$village_uid,15);//村长
$user_1 = self::user($order, 0.05, $transaction_id, $brigade_uid, 14); //队长
$user_2 = self::user($order, 0.03, $transaction_id, 0, 12); ////会员、厨师
$user_3 = self::user($order, 0.01, $transaction_id, $village_uid, 15); //村长
$platform=self::platform($order, 0.02, $transaction_id);//平台
$store=self::store($order, 0.05, $transaction_id,0);//门店
$user_4=self::user($order, 0.02, $transaction_id,0,16);//其他
$platform = self::platform($order, 0.02, $transaction_id); //平台
$store = self::store($order, 0.05, $transaction_id, 0); //门店
$attrition = self::attrition($order, 0.02,$transaction_id,16); //损耗
$moeny=bcadd(bcadd(bcadd(bcadd($user_1,$user_2,2),$user_3,2),$platform,2),bcadd($store,$user_4,2),2);
$moeny = bcadd(bcadd(bcadd(bcadd($user_1, $user_2, 2), $user_3, 2), $platform, 2), bcadd($store, $attrition, 2), 2);
self::suppliter($order, $moeny, $transaction_id);
}
/**
* 走厨师分润
*/
public static function setCook($order,$village_uid=0,$brigade_uid=0, $transaction_id=0)
public static function setCook($order, $village_uid = 0, $brigade_uid = 0, $transaction_id = 0)
{
$user_1=self::user($order, 0.07, $transaction_id,0,12);//会员、厨师
$user_2=self::user($order, 0.01, $transaction_id,$village_uid,14);//村长
$user_3=self::user($order, 0.01, $transaction_id,$brigade_uid,15);//队长
$user_1 = self::user($order, 0.07, $transaction_id, 0, 12); //会员、厨师
$user_2 = self::user($order, 0.01, $transaction_id, $village_uid, 14); //村长
$user_3 = self::user($order, 0.01, $transaction_id, $brigade_uid, 15); //队长
$platform=self::platform($order, 0.02, $transaction_id);//平台
$store=self::store($order, 0.05, $transaction_id,0);//门店
$user_4=self::user($order, 0.02, $transaction_id,0,16);//其他
$platform = self::platform($order, 0.02, $transaction_id); //平台
$store = self::store($order, 0.05, $transaction_id, 0); //门店
$attrition = self::attrition($order, 0.02,$transaction_id,16); //损耗
$moeny=bcadd(bcadd(bcadd(bcadd($user_1,$user_2,2),$user_3,2),$platform,2),bcadd($store,$user_4,2),2);
$moeny = bcadd(bcadd(bcadd(bcadd($user_1, $user_2, 2), $user_3, 2), $platform, 2), bcadd($store, $attrition, 2), 2);
self::suppliter($order, $moeny, $transaction_id);
}
/**
* 走线下分润
*/
public static function setStore($order, $transaction_id=0)
public static function setStore($order, $transaction_id = 0)
{
$platform= self::platform($order, 0.05, $transaction_id);//平台
$store= self::store($order, 0.02, $transaction_id,0);//门店
$user= self::user($order, 0.01, $transaction_id,0,16);//其他
$moeny=bcadd(bcadd($platform,$store,2),$user,2);
self::suppliter($order, $moeny, $transaction_id);
$platform = self::platform($order, 0.05, $transaction_id); //平台
$store = self::store($order, 0.02, $transaction_id, 0); //门店
$attrition = self::attrition($order, 0.01,$transaction_id,16); //损耗
$moeny = bcadd(bcadd($platform, $store, 2), $attrition, 2);
self::suppliter($order, $moeny, $transaction_id);
}
@ -78,8 +77,8 @@ class CommissionLogic extends BaseLogic
public static function platform($order, $platformRate, $transaction_id)
{
$financeLogic = new StoreFinanceFlowLogic();
$financeLogic->order=$order;
$financeLogic->user['uid']=$order['uid'];
$financeLogic->order = $order;
$financeLogic->user['uid'] = $order['uid'];
$fees = bcdiv(bcmul($order['pay_price'], $platformRate, 2), 1, 2);
if ($fees > 0) {
$financeLogic->in($transaction_id, $fees, OrderEnum::ORDER_HANDLING_FEES, $order['store_id'], 0, 0, $order['pay_type']); //平台手续费
@ -94,9 +93,9 @@ class CommissionLogic extends BaseLogic
public static function suppliter($order, $platformRate, $transaction_id)
{
$financeLogic = new StoreFinanceFlowLogic();
$financeLogic->order=$order;
$financeLogic->user['uid']=$order['uid'];
$fees = bcsub($order['pay_price'], $platformRate,2);
$financeLogic->order = $order;
$financeLogic->user['uid'] = $order['uid'];
$fees = bcsub($order['pay_price'], $platformRate, 2);
if ($fees > 0) {
$financeLogic->in($transaction_id, $fees, OrderEnum::SUPPLIER_ORDER_OBTAINS, $order['store_id'], 0, 0, $order['pay_type']);
$financeLogic->out($transaction_id, $fees, OrderEnum::SUPPLIER_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 0, $order['pay_type']);
@ -106,12 +105,12 @@ class CommissionLogic extends BaseLogic
/**
* 门店分润
*/
public static function store($order, $platformRate, $transaction_id,$uid)
public static function store($order, $platformRate, $transaction_id, $uid)
{
$financeLogic = new StoreFinanceFlowLogic();
$financeLogic->user['uid']=$order['uid'];
$financeLogic->other_arr['vip_uid']=$uid;
$financeLogic->order=$order;
$financeLogic->user['uid'] = $order['uid'];
$financeLogic->other_arr['vip_uid'] = $uid;
$financeLogic->order = $order;
$financeLogic->in($transaction_id, $order['pay_price'], OrderEnum::USER_ORDER_PAY, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); //用户订单支付
//缴纳齐全了就加商户没有就加到平台
@ -149,7 +148,7 @@ class CommissionLogic extends BaseLogic
/**
* 分给用户
*/
public static function user($order, $userRate, $transaction_id,$uid=0,$enum = 0)
public static function user($order, $userRate, $transaction_id, $uid = 0, $enum = 0)
{
$financeLogic = new StoreFinanceFlowLogic();
$fees = bcmul($order['pay_price'], $userRate, 2);
@ -160,13 +159,30 @@ class CommissionLogic extends BaseLogic
$capitalFlowDao = new CapitalFlowLogic($GiveUser);
$capitalFlowDao->userIncome('system_balance_add', 'order', $order['id'], $fees);
}
$financeLogic->user['uid']=$order['uid'];
$financeLogic->other_arr['vip_uid']=$uid;
$financeLogic->order=$order;
$financeLogic->user['uid'] = $order['uid'];
$financeLogic->other_arr['vip_uid'] = $uid;
$financeLogic->order = $order;
$financeLogic->in($transaction_id, $fees, $enum, $order['store_id'], 0, 0, $order['pay_type']);
$financeLogic->out($transaction_id, $fees, $enum, $order['store_id'], $order['staff_id'], 0, $order['pay_type']);
$financeLogic->save();
}
return $fees;
}
/**
* 损耗金
*/
public static function attrition($order, $userRate, $transaction_id, $enum)
{
$financeLogic = new StoreFinanceFlowLogic();
$financeLogic->order = $order;
$financeLogic->user['uid'] = $order['uid'];
$fees = bcmul($order['pay_price'], $userRate, 2);
if ($fees > 0) {
SystemStore::where('id', $order['store_id'])->inc('attrition', $fees)->update();
$financeLogic->in($transaction_id, $fees, $enum, $order['store_id'], $order['staff_id'], 0, $order['pay_type']);
$financeLogic->out($transaction_id, $fees, $enum, $order['store_id'], $order['staff_id'], 0, $order['pay_type']);
}
return $fees;
}
}

View File

@ -452,7 +452,7 @@ class PayNotifyLogic extends BaseLogic
$deal_money = bcdiv($extra['amount']['refund'], 100, 2);
$check_user_sing = UserSign::where('order_id', $order['order_id'])->count();
if (in_array($order['pay_type'], [PayEnum::BALANCE_PAY, PayEnum::PURCHASE_FUNDS])) {
if ($order['pay_type'] == PayEnum::BALANCE_PAY) { //用户余额
if ($order['pay_type'] == PayEnum::BALANCE_PAY) { //用户余额支付
$user->now_money = bcadd($user->now_money, $deal_money, 2);
$user->save();
//增加数量
@ -460,7 +460,7 @@ class PayNotifyLogic extends BaseLogic
//退款
$capitalFlowDao->userIncome('system_balance_back', 'system_back', $order['id'], $deal_money);
}
if ($order['pay_type'] == PayEnum::PURCHASE_FUNDS) { //采购款
if ($order['pay_type'] == PayEnum::PURCHASE_FUNDS) { //采购款支付
$user->purchase_funds = bcadd($user->purchase_funds, $deal_money, 2);
$user->save();
//增加数量
@ -480,7 +480,7 @@ class PayNotifyLogic extends BaseLogic
//微信日志 user_order_refund
$capitalFlowDao->userIncome('user_order_refund', 'system_back', $order['id'], $deal_money, '', 1);
//处理财务流水退还
self::store_finance_back($orderSn);
(new StoreFinanceFlowLogic())->store_finance_back($orderSn);
self::addStock($order['id']); //微信
return true;
// self::afterPay($order,$extra['transaction_id']);
@ -521,28 +521,7 @@ class PayNotifyLogic extends BaseLogic
/**
* 财务退还金额相关
* @param $orderSn
* @return void
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function store_finance_back($orderSn)
{
$data = StoreFinanceFlow::where('order_sn', $orderSn)
->where(['financial_pm' => 1])
->select()->toArray();
foreach ($data as &$value) {
unset($value['id']);
$value['financial_record_sn'] = (new StoreFinanceFlowLogic)->getSn();
$value['financial_pm'] = 0;
$value['financial_type'] = OrderEnum::PAY_BACK;
$value['create_time'] = time();
}
(new StoreFinanceFlow)->saveAll($data);
}
/**
* 现金退款相关

View File

@ -70,6 +70,7 @@ class StoreFinanceFlowLogic extends BaseLogic
switch ($financialType) {
case OrderEnum::MERCHANT_ORDER_OBTAINS: // 商户
case OrderEnum::ORDER_MARGIN: // 商户保证金
case OrderEnum::OTHER_ORDER_OBTAINS: // 损耗
$data['type'] = OrderEnum::MERCHANT;
break;
case OrderEnum::PLATFORM_ORDER_OBTAINS: // 平台
@ -144,20 +145,63 @@ class StoreFinanceFlowLogic extends BaseLogic
*/
public function updateStatusStore($order_id, $store_id, $money, $deposit)
{
StoreFinanceFlow::where(['order_id' => $order_id,'financial_type' => 11])->update(['status' => 1]);
StoreFinanceFlow::where(['order_id' => $order_id,'financial_type' => 2])->update(['status' => 1]);
if ($money>0) {
StoreFinanceFlow::where(['order_id' => $order_id, 'financial_type' => 11])->update(['status' => 1]);
StoreFinanceFlow::where(['order_id' => $order_id, 'financial_type' => 2])->update(['status' => 1]);
if ($money > 0) {
SystemStore::where('id', $store_id)->inc('store_money', $money)->update();
}
if ($deposit>0) {
if ($deposit > 0) {
SystemStore::where('id', $store_id)->inc('paid_deposit', $deposit)->update();
}
$find = StoreFinanceFlow::where(['order_id' => $order_id, 'financial_pm' => 1, 'financial_type' => 16,'status'=>0])->find();
StoreFinanceFlow::where(['order_id' => $order_id,'financial_type' => 16])->update(['status' => 1]);
$find = StoreFinanceFlow::where(['order_id' => $order_id, 'financial_pm' => 1, 'financial_type' => 16, 'status' => 0])->find();
StoreFinanceFlow::where(['order_id' => $order_id, 'financial_type' => 16])->update(['status' => 1]);
if ($find) {
if ($find['number'] > 0) {
SystemStore::where('id', $store_id)->inc('attrition', $find['number'])->update();
}
}
}
/**
* 财务退还金额相关
* @param $orderSn
* @return void
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function store_finance_back($orderSn)
{
$data = StoreFinanceFlow::where('order_sn', $orderSn)
->where(['financial_pm' => 1])
->select()->toArray();
foreach ($data as &$value) {
unset($value['id']);
$value['financial_record_sn'] = (new StoreFinanceFlowLogic)->getSn();
$value['financial_pm'] = 0;
$value['financial_type'] = OrderEnum::PAY_BACK;
$value['create_time'] = time();
if ($value['status'] == 1) {
switch ($value['type']) {
case 0:
$user = User::where('id', $value['other_uid'])->findOrEmpty();
$capitalFlowDao = new CapitalFlowLogic($user);
$capitalFlowDao->userExpense('system_now_money_back', 'system_back', $value['order_id'], $value['number']);
break;
case 1:
if ($value['number'] > 0 &&$value['financial_type']==2) {
SystemStore::where('id', $value['store_id'])->dec('store_money',$value['number'])->update();
}
if ($value['number'] > 0 &&$value['financial_type']==11) {
SystemStore::where('id', $value['store_id'])->dec('paid_deposit',$value['number'])->update();
}
if ($value['number'] > 0 &&$value['financial_type']==16) {
SystemStore::where('id', $value['store_id'])->dec('attrition',$value['number'])->update();
}
break;
}
}
}
(new StoreFinanceFlow)->saveAll($data);
}
}