feat: 修改了商品订单逻辑和佣金计算逻辑

This commit is contained in:
mkm 2024-09-11 15:15:07 +08:00
parent be8881b1ad
commit 20095c8085
5 changed files with 123 additions and 81 deletions

View File

@ -51,7 +51,7 @@ class StoreOrderCartInfoLists extends BaseAdminDataLists implements ListsSearchI
public function lists(): array
{
return StoreOrderCartInfo::where($this->searchWhere)
->field('oid,uid,cart_info,product_id,store_id,cart_num,price,total_price,create_time')->limit($this->limitOffset, $this->limitLength)
->field('oid,uid,product_id,store_id,cart_num,price,total_price,create_time')->limit($this->limitOffset, $this->limitLength)
->select()->each(function ($item) {
$find=StoreProduct::where('id',$item['product_id'])->field('image,unit,store_name,store_info')->find();
if($find){
@ -75,6 +75,8 @@ class StoreOrderCartInfoLists extends BaseAdminDataLists implements ListsSearchI
$item['store_info']=$find['store_info'];//商品规格
$item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name')??"";
$item['cate_name'] = StoreCategory::where('id', $find['cate_id'])->value('name')??"";
$item['pay_price'] =$item['total_price'];
$item['cart_info'] = $item->toArray()??[];
}else{
$item['image']='';//商品图片
$item['unit_name']='';//商品图片
@ -83,6 +85,7 @@ class StoreOrderCartInfoLists extends BaseAdminDataLists implements ListsSearchI
$item['store_info']='';//商品规格-(数据库叫商品简介)
$item['nickname']='';
$item['system_store']='';
$item['cart_info']=[];
}
return $item; //返回处理后的数据。
})

View File

@ -118,42 +118,44 @@ class StoreOrderLogic extends BaseLogic
public static function refund($detail, $params)
{
if (isset($params['product_arr']) && count($params['product_arr']) > 0) {
$refund_price = $params['refund_price'];
$refund_num = 0;
foreach ($params['product_arr'] as $k => $v) {
$find = StoreOrderCartInfo::where('oid', $detail['id'])->where('product_id', $v['product_id'])->find();
if ($find) {
$refund_num += $v['cart_num'];
$cart_num = bcsub($find['cart_num'], $v['cart_num']);
$total_price = bcmul($find['price'], $cart_num);
$data = ['cart_num' => $cart_num, 'total_price' => $total_price];
StoreOrderCartInfo::where('id', $find['id'])->update($data);
$arr = StoreFinanceFlowProduct::where('oid', $detail['id'])->where('product_id', $v['product_id'])->select()->toArray();
foreach ($arr as $key => $value) {
$value['cart_num'] = $cart_num;
$value['total_price'] = bcmul($cart_num, $value['price'], 2);
$value['number'] = bcmul($value['total_price'], $value['rate'], 2);
StoreFinanceFlowProduct::where('id', $value['id'])->update(['delete_time' => time()]);
unset($value['id']);
$value['create_time'] = strtotime($value['create_time']);
$value['update_time'] = strtotime($value['update_time']);
StoreFinanceFlowProduct::create($value);
}
}
}
$village_uid = StoreFinanceFlow::where('order_id', $detail['id'])->where('financial_type', 14)->value('other_uid');
$brigade_uid = StoreFinanceFlow::where('order_id', $detail['id'])->where('financial_type', 15)->value('other_uid');
$transaction_id = StoreFinanceFlow::where('order_id', $detail['id'])->value('transaction_id');
StoreFinanceFlow::where('order_id', $detail['id'])->update(['delete_time' => time()]);
CommissionnLogic::setStore($detail, $village_uid, $brigade_uid, $transaction_id);
StoreOrder::where('id', $detail['oid'])->update(['refund_price' => $refund_price, 'refund_num' => $refund_num]);
//微信支付
if (in_array($detail['pay_type'], [PayEnum::WECHAT_PAY_MINI, PayEnum::WECHAT_PAY_BARCODE])) {
$money = (int)bcmul($params['refund_price'], 100);
$pay_price = (int)bcmul($detail['pay_price'], 100);
$refund = (new \app\common\logic\store_order\StoreOrderLogic())
->refund($params['order_id'], $money, $detail['pay_price']);
->refund($params['order_id'], $money, $pay_price);
if ($refund) {
$refund_price = $params['refund_price'];
$refund_num = 0;
foreach ($params['product_arr'] as $k => $v) {
$find = StoreOrderCartInfo::where('oid', $detail['id'])->where('product_id', $v['product_id'])->find();
if ($find) {
$refund_num += $v['cart_num'];
$cart_num = bcsub($find['cart_num'], $v['cart_num']);
$total_price = bcmul($find['price'], $cart_num);
$data = ['cart_num' => $cart_num, 'total_price' => $total_price];
StoreOrderCartInfo::where('id', $find['id'])->update($data);
$arr = StoreFinanceFlowProduct::where('oid', $detail['id'])->where('product_id', $v['product_id'])->select()->toArray();
foreach ($arr as $key => $value) {
$value['cart_num'] = $cart_num;
$value['total_price'] = bcmul($cart_num, $value['price'], 2);
$value['number'] = bcmul($value['total_price'], $value['rate'], 2);
StoreFinanceFlowProduct::where('id', $value['id'])->update(['delete_time' => time()]);
unset($value['id']);
$value['create_time'] = strtotime($value['create_time']);
$value['update_time'] = strtotime($value['update_time']);
StoreFinanceFlowProduct::create($value);
}
}
}
$village_uid = StoreFinanceFlow::where('order_id', $detail['id'])->where('financial_type', 14)->value('other_uid');
$brigade_uid = StoreFinanceFlow::where('order_id', $detail['id'])->where('financial_type', 15)->value('other_uid');
$transaction_id = StoreFinanceFlow::where('order_id', $detail['id'])->value('transaction_id');
StoreFinanceFlow::where('order_id', $detail['id'])->update(['delete_time' => time()]);
$detail['refund_price']=$refund_price;
CommissionnLogic::setStore($detail, $village_uid, $brigade_uid, $transaction_id);
StoreOrder::where('id', $detail['oid'])->update(['refund_price' => $refund_price, 'refund_num' => $refund_num]);
return '退款成功';
}
}

View File

@ -7,6 +7,7 @@ use app\common\model\store_branch_product\StoreBranchProduct;
use app\common\model\store_finance_flow_product\StoreFinanceFlowProduct;
use app\common\model\store_order_cart_info\StoreOrderCartInfo;
use app\common\model\store_product\StoreProduct;
use app\common\model\user\User;
use PDO;
use support\Log;
@ -51,8 +52,8 @@ class CommissionProductLogic extends BaseLogic
*/
public function a($find, $order, $village_uid, $brigade_uid, $user_ship, $product)
{
$total_price = bcmul($product['price'], $find['cart_num']);
$purchase_price = bcmul($product['purchase'], $find['cart_num']);
$total_price = bcmul($product['price'], $find['cart_num'], 2);
$purchase_price = bcmul($product['purchase'], $find['cart_num'], 2);
$price = $product['purchase'];
$brigade_number = bcmul($purchase_price, 0.02, 2); //队长
@ -69,43 +70,60 @@ class CommissionProductLogic extends BaseLogic
$number4 = bcadd($attrition_number, $number2, 2);
//会员
if ($order['spread_uid'] > 0 || $user_ship > 0) {
if (in_array($user_ship, [2, 3])) {
$vip_number = bcmul($purchase_price, 0.05, 2); //会员利润
$data[] = [
'nickname' => '会员',
'store_id' => $order['store_id'],
'product_id' => $find['product_id'],
'price' => $price,
'other_uid' => $order['spread_uid'],
'total_price' => $purchase_price,
'cart_num' => $find['cart_num'],
'rate' => 0.05,
'number' => $vip_number,
'oid' => $order['id'],
'type' => 0,
'status' => 1,
];
$number4=bcadd($number4, $vip_number, 2);
} else {
$vip_number = bcmul($purchase_price, 0.07, 2); //会员利润
$data[] = [
'nickname' => '会员',
'store_id' => $order['store_id'],
'product_id' => $find['product_id'],
'other_uid' => $order['spread_uid'],
'price' => $price,
'total_price' => $purchase_price,
'cart_num' => $find['cart_num'],
'rate' => 0.07,
'number' => $vip_number,
'oid' => $order['id'],
'type' => 0,
'status' => 1,
];
$number4=bcadd($number4, $vip_number, 2);
$uid = 0;
if ($order['spread_uid'] > 0) {
$uid = $order['spread_uid'];
}
if ($order['uid'] > 0) {
$uid = $order['uid'];
}
$user = User::where('id', $uid)->find();
$delete_time=null;
$nickname='会员';
if ($user) {
$moeny = bcsub($user['total_recharge_amount'], $user['purchase_funds'], 2);
if ($moeny < $user['first_purchase_funds']) {
$delete_time=1;
$nickname='首充没用完,会员不分配';
}
}
if (in_array($user_ship, [2, 3])) {
$vip_number = bcmul($purchase_price, 0.05, 2); //会员利润
$data[] = [
'nickname' => $nickname,
'store_id' => $order['store_id'],
'product_id' => $find['product_id'],
'price' => $price,
'other_uid' => $uid,
'total_price' => $purchase_price,
'cart_num' => $find['cart_num'],
'rate' => 0.05,
'number' => $vip_number,
'oid' => $order['id'],
'type' => 0,
'status' => 1,
'delete_time'=>$delete_time
];
$number4 = bcadd($number4, $vip_number, 2);
} else {
$vip_number = bcmul($purchase_price, 0.07, 2); //会员利润
$data[] = [
'nickname' => $nickname,
'store_id' => $order['store_id'],
'product_id' => $find['product_id'],
'other_uid' => $uid,
'price' => $price,
'total_price' => $purchase_price,
'cart_num' => $find['cart_num'],
'rate' => 0.07,
'number' => $vip_number,
'oid' => $order['id'],
'type' => 0,
'status' => 1,
'delete_time'=>$delete_time
];
$number4 = bcadd($number4, $vip_number, 2);
}
//门店利润
if ($number3 <= 0) {
$store_number = 0;
@ -202,8 +220,8 @@ class CommissionProductLogic extends BaseLogic
*/
public function b($find, $order, $product, $user_ship)
{
$total_price = bcmul($product['price'], $find['cart_num']);
$purchase_price = bcmul($product['purchase'], $find['cart_num']);
$total_price = bcmul($product['price'], $find['cart_num'], 2);
$purchase_price = bcmul($product['purchase'], $find['cart_num'], 2);
$price = $product['purchase'];
$brigade_number = bcmul($purchase_price, 0.02, 2); //队长
@ -312,8 +330,8 @@ class CommissionProductLogic extends BaseLogic
public function c($find, $order, $village_uid, $brigade_uid, $user_ship, $product)
{
// $rose = bcdiv($product['rose'], 100, 2);
$total_price = bcmul($product['price'], $find['cart_num']);
$purchase_price = bcmul($product['purchase'], $find['cart_num']);
$total_price = bcmul($product['price'], $find['cart_num'], 2);
$purchase_price = bcmul($product['purchase'], $find['cart_num'], 2);
$price = $product['price'];
$brigade_number = bcmul($total_price, 0.02, 2); //队长
$village_number = bcmul($brigade_number, 0.1, 2); //村长

View File

@ -106,7 +106,7 @@ class CommissionnLogic extends BaseLogic
$financeLogic = new StoreFinanceFlowLogic();
$financeLogic->order = $order;
$financeLogic->user['uid'] = $order['uid'];
$pay_price = $order['pay_price'];
$pay_price=bcsub($order['pay_price'],$order['refund_price'],2);
$number = StoreFinanceFlowProduct::where('oid', $order['id'])->sum('number');
$fees = bcsub($pay_price, $number, 2);
if ($fees > 0) {
@ -124,7 +124,7 @@ class CommissionnLogic extends BaseLogic
$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']); //用户订单支付
$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();

View File

@ -250,12 +250,31 @@ class StoreOrderLogic extends BaseLogic
if ($order['pay_type'] == 19){
$order['deduction_price'] = "0.00";
}
$detail =StoreOrderCartInfo::where('oid',$order['id'])->find()->toArray();
$product=StoreOrderCartInfo::where(['oid'=>$order['id']])
->field('oid,uid,product_id,store_id,cart_num,price,total_price,create_time')
->select()->each(function ($item) {
$find=StoreProduct::where('id',$item['product_id'])->field('image,unit,store_name,store_info')->find();
if($find){
$item['image']=$find['image'];//商品图片
$item['name']=$find['store_name'];//商品名称
$item['store_info']=$find['store_info'];//商品规格
$item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name')??"";
$item['pay_price'] =$item['total_price'];
$item['cart_info'] = $item->toArray()??[];
}else{
$item['image']='';//商品图片
$item['unit_name']='';//商品图片
$item['cate_name']='';//商品图片
$item['store_name']='';//商品名称
$item['store_info']='';//商品规格-(数据库叫商品简介)
$item['nickname']='';
$item['system_store']='';
$item['cart_info']=[];
}
return $item; //返回处理后的数据。
});
$order['product']=$product;
$vip =0;
if(isset($detail['cart_info']['vip']) && $detail['cart_info']['vip'] == 1){
$vip = 1;
}
$order['vip'] = $vip;
return $order->toArray();
}
@ -371,7 +390,7 @@ class StoreOrderLogic extends BaseLogic
return false;
} catch (Exception $e) {
\support\Log::info($e->extra['message'] ?? $e->getMessage());
throw new BusinessException($e->getMessage());
throw new BusinessException($e->extra['message'] ?? $e->getMessage());
}
}