feat: 修改了商品订单逻辑和佣金计算逻辑
This commit is contained in:
parent
be8881b1ad
commit
20095c8085
@ -51,7 +51,7 @@ class StoreOrderCartInfoLists extends BaseAdminDataLists implements ListsSearchI
|
|||||||
public function lists(): array
|
public function lists(): array
|
||||||
{
|
{
|
||||||
return StoreOrderCartInfo::where($this->searchWhere)
|
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) {
|
->select()->each(function ($item) {
|
||||||
$find=StoreProduct::where('id',$item['product_id'])->field('image,unit,store_name,store_info')->find();
|
$find=StoreProduct::where('id',$item['product_id'])->field('image,unit,store_name,store_info')->find();
|
||||||
if($find){
|
if($find){
|
||||||
@ -75,6 +75,8 @@ class StoreOrderCartInfoLists extends BaseAdminDataLists implements ListsSearchI
|
|||||||
$item['store_info']=$find['store_info'];//商品规格
|
$item['store_info']=$find['store_info'];//商品规格
|
||||||
$item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name')??"";
|
$item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name')??"";
|
||||||
$item['cate_name'] = StoreCategory::where('id', $find['cate_id'])->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{
|
}else{
|
||||||
$item['image']='';//商品图片
|
$item['image']='';//商品图片
|
||||||
$item['unit_name']='';//商品图片
|
$item['unit_name']='';//商品图片
|
||||||
@ -83,6 +85,7 @@ class StoreOrderCartInfoLists extends BaseAdminDataLists implements ListsSearchI
|
|||||||
$item['store_info']='';//商品规格-(数据库叫商品简介)
|
$item['store_info']='';//商品规格-(数据库叫商品简介)
|
||||||
$item['nickname']='';
|
$item['nickname']='';
|
||||||
$item['system_store']='';
|
$item['system_store']='';
|
||||||
|
$item['cart_info']=[];
|
||||||
}
|
}
|
||||||
return $item; //返回处理后的数据。
|
return $item; //返回处理后的数据。
|
||||||
})
|
})
|
||||||
|
@ -118,6 +118,13 @@ class StoreOrderLogic extends BaseLogic
|
|||||||
public static function refund($detail, $params)
|
public static function refund($detail, $params)
|
||||||
{
|
{
|
||||||
if (isset($params['product_arr']) && count($params['product_arr']) > 0) {
|
if (isset($params['product_arr']) && count($params['product_arr']) > 0) {
|
||||||
|
//微信支付
|
||||||
|
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, $pay_price);
|
||||||
|
if ($refund) {
|
||||||
$refund_price = $params['refund_price'];
|
$refund_price = $params['refund_price'];
|
||||||
$refund_num = 0;
|
$refund_num = 0;
|
||||||
foreach ($params['product_arr'] as $k => $v) {
|
foreach ($params['product_arr'] as $k => $v) {
|
||||||
@ -145,15 +152,10 @@ class StoreOrderLogic extends BaseLogic
|
|||||||
$brigade_uid = StoreFinanceFlow::where('order_id', $detail['id'])->where('financial_type', 15)->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');
|
$transaction_id = StoreFinanceFlow::where('order_id', $detail['id'])->value('transaction_id');
|
||||||
StoreFinanceFlow::where('order_id', $detail['id'])->update(['delete_time' => time()]);
|
StoreFinanceFlow::where('order_id', $detail['id'])->update(['delete_time' => time()]);
|
||||||
|
$detail['refund_price']=$refund_price;
|
||||||
CommissionnLogic::setStore($detail, $village_uid, $brigade_uid, $transaction_id);
|
CommissionnLogic::setStore($detail, $village_uid, $brigade_uid, $transaction_id);
|
||||||
|
|
||||||
StoreOrder::where('id', $detail['oid'])->update(['refund_price' => $refund_price, 'refund_num' => $refund_num]);
|
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);
|
|
||||||
$refund = (new \app\common\logic\store_order\StoreOrderLogic())
|
|
||||||
->refund($params['order_id'], $money, $detail['pay_price']);
|
|
||||||
if ($refund) {
|
|
||||||
return '退款成功';
|
return '退款成功';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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_finance_flow_product\StoreFinanceFlowProduct;
|
||||||
use app\common\model\store_order_cart_info\StoreOrderCartInfo;
|
use app\common\model\store_order_cart_info\StoreOrderCartInfo;
|
||||||
use app\common\model\store_product\StoreProduct;
|
use app\common\model\store_product\StoreProduct;
|
||||||
|
use app\common\model\user\User;
|
||||||
use PDO;
|
use PDO;
|
||||||
use support\Log;
|
use support\Log;
|
||||||
|
|
||||||
@ -51,8 +52,8 @@ class CommissionProductLogic extends BaseLogic
|
|||||||
*/
|
*/
|
||||||
public function a($find, $order, $village_uid, $brigade_uid, $user_ship, $product)
|
public function a($find, $order, $village_uid, $brigade_uid, $user_ship, $product)
|
||||||
{
|
{
|
||||||
$total_price = bcmul($product['price'], $find['cart_num']);
|
$total_price = bcmul($product['price'], $find['cart_num'], 2);
|
||||||
$purchase_price = bcmul($product['purchase'], $find['cart_num']);
|
$purchase_price = bcmul($product['purchase'], $find['cart_num'], 2);
|
||||||
$price = $product['purchase'];
|
$price = $product['purchase'];
|
||||||
|
|
||||||
$brigade_number = bcmul($purchase_price, 0.02, 2); //队长
|
$brigade_number = bcmul($purchase_price, 0.02, 2); //队长
|
||||||
@ -69,15 +70,31 @@ class CommissionProductLogic extends BaseLogic
|
|||||||
$number4 = bcadd($attrition_number, $number2, 2);
|
$number4 = bcadd($attrition_number, $number2, 2);
|
||||||
|
|
||||||
//会员
|
//会员
|
||||||
if ($order['spread_uid'] > 0 || $user_ship > 0) {
|
$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])) {
|
if (in_array($user_ship, [2, 3])) {
|
||||||
$vip_number = bcmul($purchase_price, 0.05, 2); //会员利润
|
$vip_number = bcmul($purchase_price, 0.05, 2); //会员利润
|
||||||
$data[] = [
|
$data[] = [
|
||||||
'nickname' => '会员',
|
'nickname' => $nickname,
|
||||||
'store_id' => $order['store_id'],
|
'store_id' => $order['store_id'],
|
||||||
'product_id' => $find['product_id'],
|
'product_id' => $find['product_id'],
|
||||||
'price' => $price,
|
'price' => $price,
|
||||||
'other_uid' => $order['spread_uid'],
|
'other_uid' => $uid,
|
||||||
'total_price' => $purchase_price,
|
'total_price' => $purchase_price,
|
||||||
'cart_num' => $find['cart_num'],
|
'cart_num' => $find['cart_num'],
|
||||||
'rate' => 0.05,
|
'rate' => 0.05,
|
||||||
@ -85,15 +102,16 @@ class CommissionProductLogic extends BaseLogic
|
|||||||
'oid' => $order['id'],
|
'oid' => $order['id'],
|
||||||
'type' => 0,
|
'type' => 0,
|
||||||
'status' => 1,
|
'status' => 1,
|
||||||
|
'delete_time'=>$delete_time
|
||||||
];
|
];
|
||||||
$number4 = bcadd($number4, $vip_number, 2);
|
$number4 = bcadd($number4, $vip_number, 2);
|
||||||
} else {
|
} else {
|
||||||
$vip_number = bcmul($purchase_price, 0.07, 2); //会员利润
|
$vip_number = bcmul($purchase_price, 0.07, 2); //会员利润
|
||||||
$data[] = [
|
$data[] = [
|
||||||
'nickname' => '会员',
|
'nickname' => $nickname,
|
||||||
'store_id' => $order['store_id'],
|
'store_id' => $order['store_id'],
|
||||||
'product_id' => $find['product_id'],
|
'product_id' => $find['product_id'],
|
||||||
'other_uid' => $order['spread_uid'],
|
'other_uid' => $uid,
|
||||||
'price' => $price,
|
'price' => $price,
|
||||||
'total_price' => $purchase_price,
|
'total_price' => $purchase_price,
|
||||||
'cart_num' => $find['cart_num'],
|
'cart_num' => $find['cart_num'],
|
||||||
@ -102,10 +120,10 @@ class CommissionProductLogic extends BaseLogic
|
|||||||
'oid' => $order['id'],
|
'oid' => $order['id'],
|
||||||
'type' => 0,
|
'type' => 0,
|
||||||
'status' => 1,
|
'status' => 1,
|
||||||
|
'delete_time'=>$delete_time
|
||||||
];
|
];
|
||||||
$number4 = bcadd($number4, $vip_number, 2);
|
$number4 = bcadd($number4, $vip_number, 2);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
//门店利润
|
//门店利润
|
||||||
if ($number3 <= 0) {
|
if ($number3 <= 0) {
|
||||||
$store_number = 0;
|
$store_number = 0;
|
||||||
@ -202,8 +220,8 @@ class CommissionProductLogic extends BaseLogic
|
|||||||
*/
|
*/
|
||||||
public function b($find, $order, $product, $user_ship)
|
public function b($find, $order, $product, $user_ship)
|
||||||
{
|
{
|
||||||
$total_price = bcmul($product['price'], $find['cart_num']);
|
$total_price = bcmul($product['price'], $find['cart_num'], 2);
|
||||||
$purchase_price = bcmul($product['purchase'], $find['cart_num']);
|
$purchase_price = bcmul($product['purchase'], $find['cart_num'], 2);
|
||||||
$price = $product['purchase'];
|
$price = $product['purchase'];
|
||||||
|
|
||||||
$brigade_number = bcmul($purchase_price, 0.02, 2); //队长
|
$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)
|
public function c($find, $order, $village_uid, $brigade_uid, $user_ship, $product)
|
||||||
{
|
{
|
||||||
// $rose = bcdiv($product['rose'], 100, 2);
|
// $rose = bcdiv($product['rose'], 100, 2);
|
||||||
$total_price = bcmul($product['price'], $find['cart_num']);
|
$total_price = bcmul($product['price'], $find['cart_num'], 2);
|
||||||
$purchase_price = bcmul($product['purchase'], $find['cart_num']);
|
$purchase_price = bcmul($product['purchase'], $find['cart_num'], 2);
|
||||||
$price = $product['price'];
|
$price = $product['price'];
|
||||||
$brigade_number = bcmul($total_price, 0.02, 2); //队长
|
$brigade_number = bcmul($total_price, 0.02, 2); //队长
|
||||||
$village_number = bcmul($brigade_number, 0.1, 2); //村长
|
$village_number = bcmul($brigade_number, 0.1, 2); //村长
|
||||||
|
@ -106,7 +106,7 @@ class CommissionnLogic extends BaseLogic
|
|||||||
$financeLogic = new StoreFinanceFlowLogic();
|
$financeLogic = new StoreFinanceFlowLogic();
|
||||||
$financeLogic->order = $order;
|
$financeLogic->order = $order;
|
||||||
$financeLogic->user['uid'] = $order['uid'];
|
$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');
|
$number = StoreFinanceFlowProduct::where('oid', $order['id'])->sum('number');
|
||||||
$fees = bcsub($pay_price, $number, 2);
|
$fees = bcsub($pay_price, $number, 2);
|
||||||
if ($fees > 0) {
|
if ($fees > 0) {
|
||||||
@ -124,7 +124,7 @@ class CommissionnLogic extends BaseLogic
|
|||||||
$financeLogic->user['uid'] = $order['uid'];
|
$financeLogic->user['uid'] = $order['uid'];
|
||||||
$financeLogic->other_arr['vip_uid'] = $uid;
|
$financeLogic->other_arr['vip_uid'] = $uid;
|
||||||
$financeLogic->order = $order;
|
$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();
|
$money_limt = SystemStore::where('id', $order['store_id'])->field('paid_deposit,security_deposit')->find();
|
||||||
|
@ -250,12 +250,31 @@ class StoreOrderLogic extends BaseLogic
|
|||||||
if ($order['pay_type'] == 19){
|
if ($order['pay_type'] == 19){
|
||||||
$order['deduction_price'] = "0.00";
|
$order['deduction_price'] = "0.00";
|
||||||
}
|
}
|
||||||
|
$product=StoreOrderCartInfo::where(['oid'=>$order['id']])
|
||||||
$detail =StoreOrderCartInfo::where('oid',$order['id'])->find()->toArray();
|
->field('oid,uid,product_id,store_id,cart_num,price,total_price,create_time')
|
||||||
$vip =0;
|
->select()->each(function ($item) {
|
||||||
if(isset($detail['cart_info']['vip']) && $detail['cart_info']['vip'] == 1){
|
$find=StoreProduct::where('id',$item['product_id'])->field('image,unit,store_name,store_info')->find();
|
||||||
$vip = 1;
|
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;
|
||||||
$order['vip'] = $vip;
|
$order['vip'] = $vip;
|
||||||
return $order->toArray();
|
return $order->toArray();
|
||||||
}
|
}
|
||||||
@ -371,7 +390,7 @@ class StoreOrderLogic extends BaseLogic
|
|||||||
return false;
|
return false;
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
\support\Log::info($e->extra['message'] ?? $e->getMessage());
|
\support\Log::info($e->extra['message'] ?? $e->getMessage());
|
||||||
throw new BusinessException($e->getMessage());
|
throw new BusinessException($e->extra['message'] ?? $e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user