diff --git a/app/api/logic/order/OrderLogic.php b/app/api/logic/order/OrderLogic.php index 856c5b75a..ecd3643f6 100644 --- a/app/api/logic/order/OrderLogic.php +++ b/app/api/logic/order/OrderLogic.php @@ -8,6 +8,7 @@ use app\common\enum\UserShipEnum; use app\common\enum\YesNoEnum; use app\common\logic\BaseLogic; use app\common\logic\CapitalFlowLogic; +use app\common\logic\CommissionnLogic; use app\common\logic\PayNotifyLogic; use app\common\logic\StoreFinanceFlowLogic; use app\common\logic\UserSignLogic; @@ -566,8 +567,7 @@ class OrderLogic extends BaseLogic 'store_id' => $params['store_id'], 'staff_id' => $params['staff_id'] ?? 0, ], ['id' => $order['id']]); - //修改商品统计记录标识 - (new StoreProductLog())->where('oid', $order['id'])->update(['store_id' => $params['store_id']]); + (new StoreOrderCartInfo())->update([ 'verify_code' => $params['verify_code'] . '-1', 'writeoff_time' => time(), diff --git a/app/common/logic/CommissionProductLogic.php b/app/common/logic/CommissionProductLogic.php index 13584e2a7..5f23c58a6 100644 --- a/app/common/logic/CommissionProductLogic.php +++ b/app/common/logic/CommissionProductLogic.php @@ -123,9 +123,11 @@ class CommissionProductLogic extends BaseLogic if($order['pay_type']==18 && bcsub($user['total_recharge_amount'],$user['purchase_funds'],2)<$user['first_purchase_funds']){ }else{ - $vip_number = bcmul($total_price, 0.06, 2); //会员利润 - $data[] = $this->vip_user('零售会员', $order, $find, $uid, $price, $total_price, $vip_number,0.06); - $number1 = bcadd($number1, $vip_number, 2); + if($rose>=9){ + $vip_number = bcmul($total_price, 0.06, 2); //会员利润 + $data[] = $this->vip_user('零售会员', $order, $find, $uid, $price, $total_price, $vip_number,0.06); + $number1 = bcadd($number1, $vip_number, 2); + } } if ($rose >= 12 && $village_uid>0) { $village_number = bcmul($total_price, 0.01, 2); //村长利润 diff --git a/app/common/logic/CommissionnLogic.php b/app/common/logic/CommissionnLogic.php index 44b9ae9b1..d070ea47a 100644 --- a/app/common/logic/CommissionnLogic.php +++ b/app/common/logic/CommissionnLogic.php @@ -77,26 +77,35 @@ class CommissionnLogic extends BaseLogic $financeLogic->in($transaction_id, bcsub($order['pay_price'],$order['refund_price'],2), OrderEnum::USER_ORDER_PAY, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); //用户订单支付 //缴纳齐全了就加商户没有就加到平台 + //查询保证金额度 和已交保证金 $money_limt = SystemStore::where('id', $order['store_id'])->field('paid_deposit,security_deposit')->find(); - $deposit = bcsub($money_limt['security_deposit'], $money_limt['paid_deposit'], 2); //保证金剩余额度 + //保证金剩余额度 + $deposit = bcsub($money_limt['security_deposit'], $money_limt['paid_deposit'], 2); + //门店利润 $store_profit = StoreFinanceFlowProduct::where('oid', $order['id'])->where('type', $type)->sum('number'); if ($deposit > 0) { + //如果保证金大于利润就全部扣除利润到保证金中 if ($deposit > $store_profit) { if ($store_profit > 0) { + //添加到门店保证中 $financeLogic->out($transaction_id, $store_profit, OrderEnum::ORDER_MARGIN, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); + //添加到门店余额中 $financeLogic->in($transaction_id, 0, OrderEnum::MERCHANT_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); //平台手续费 } } else { + //利润减去保证金 $money = bcsub($store_profit, $deposit, 2); if ($deposit > 0) { $financeLogic->out($transaction_id, $deposit, OrderEnum::ORDER_MARGIN, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); } if ($money) { + //添加到门店余额中 $financeLogic->in($transaction_id, $money, OrderEnum::MERCHANT_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); //平台手续费 } } } else { if ($store_profit > 0) { + //添加到门店余额中 $financeLogic->in($transaction_id, $store_profit, OrderEnum::MERCHANT_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); //平台手续费 } } diff --git a/app/common/logic/StoreFinanceFlowLogic.php b/app/common/logic/StoreFinanceFlowLogic.php index 98b3131be..1a2e06f8a 100644 --- a/app/common/logic/StoreFinanceFlowLogic.php +++ b/app/common/logic/StoreFinanceFlowLogic.php @@ -146,13 +146,20 @@ 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]); $store = SystemStore::where('id', $store_id)->find(); $capitalFlowDao = new CapitalFlowLogic($store, 'store'); if ($money > 0) { - $capitalFlowDao->storeIncome('store_money_add', 'order', $order_id, $money,'','store_money'); - SystemStore::where('id', $store_id)->inc('store_money', $money)->update(); + //判断是否是押金 + if($store['paid_deposit']<$store['security_deposit']){ + StoreFinanceFlow::where(['order_id' => $order_id, 'financial_type' => 11])->update(['status' => 1,'number'=>$money]); + StoreFinanceFlow::where(['order_id' => $order_id, 'financial_type' => 2])->update(['status' => 1,'number'=>0]); + + $capitalFlowDao->storeIncome('store_paid_deposit_add', 'order', $order_id, $money,'','paid_deposit'); + SystemStore::where('id', $store_id)->inc('paid_deposit', $money)->update(); + }else{ + $capitalFlowDao->storeIncome('store_money_add', 'order', $order_id, $money,'','store_money'); + SystemStore::where('id', $store_id)->inc('store_money', $money)->update(); + } } if ($deposit > 0) { $capitalFlowDao->storeIncome('store_paid_deposit_add', 'order', $order_id, $deposit,'','paid_deposit'); diff --git a/app/common/model/store_finance_flow/StoreFinanceFlow.php b/app/common/model/store_finance_flow/StoreFinanceFlow.php index 38f79b90c..c1e701280 100644 --- a/app/common/model/store_finance_flow/StoreFinanceFlow.php +++ b/app/common/model/store_finance_flow/StoreFinanceFlow.php @@ -36,10 +36,22 @@ class StoreFinanceFlow extends BaseModel { return $this->hasOne(SystemStoreStaff::class, 'id', 'staff_id')->bind(['staff_name']); } - + public static function onBeforeWrite($data) + { + try { + $where = $data->getWhere(); + if($data){ + $find = self::where($where)->field(array_keys($data->toArray()))->find(); + if($find){ + channelLog(array_merge($find->toArray(),$where),'store_finance_flow','更新前'); + } + } + } catch (Throwable $e) { + Log::error('store_finance_flow:' . $e->getMessage()); + } + } public static function onAfterWrite($data){ try{ - channelLog($data->getOrigin(),'store_finance_flow','更新前'); channelLog($data->toArray(),'store_finance_flow','更新后'); }catch(Throwable $e){ Log::error('store_finance_flow:'.$e->getMessage()); diff --git a/app/common/model/store_finance_flow_product/StoreFinanceFlowProduct.php b/app/common/model/store_finance_flow_product/StoreFinanceFlowProduct.php index bea36cb01..daa72cf84 100644 --- a/app/common/model/store_finance_flow_product/StoreFinanceFlowProduct.php +++ b/app/common/model/store_finance_flow_product/StoreFinanceFlowProduct.php @@ -18,13 +18,4 @@ class StoreFinanceFlowProduct extends BaseModel use SoftDelete; protected $name = 'store_finance_flow_product'; protected $deleteTime = 'delete_time'; - - public static function onAfterWrite($data){ - try{ - channelLog($data->getOrigin(),'store_finance_flow_product','更新前'); - channelLog($data->toArray(),'store_finance_flow_product','更新后'); - }catch(Throwable $e){ - Log::error('store_finance_flow_product:'.$e->getMessage()); - } - } } \ No newline at end of file diff --git a/app/common/model/system_store/SystemStore.php b/app/common/model/system_store/SystemStore.php index ff209e545..320d93f30 100644 --- a/app/common/model/system_store/SystemStore.php +++ b/app/common/model/system_store/SystemStore.php @@ -19,9 +19,23 @@ class SystemStore extends BaseModel protected $name = 'system_store'; protected $deleteTime = 'delete_time'; + public static function onBeforeWrite($data) + { + try { + $where = $data->getWhere(); + if($data){ + $find = self::where($where)->field(array_keys($data->toArray()))->find(); + if($find){ + channelLog(array_merge($find->toArray(),$where),'system_store','更新前'); + } + } + } catch (Throwable $e) { + Log::error('system_store:' . $e->getMessage()); + } + } + public static function onAfterWrite($data){ try{ - channelLog($data->getOrigin(),'system_store','更新前'); channelLog($data->toArray(),'system_store','更新后'); }catch(Throwable $e){ Log::error('system_store:'.$e->getMessage());