创建订单计算成本和利润

This commit is contained in:
liu 2024-06-08 16:24:34 +08:00
parent 8644e3d571
commit b6aa59e1b8
2 changed files with 143 additions and 122 deletions

View File

@ -39,6 +39,8 @@ use Yansongda\Pay\Event\PayEnd;
class OrderLogic extends BaseLogic class OrderLogic extends BaseLogic
{ {
public static $total; public static $total;
public static $cost;
public static $profit;
/** /**
* @notes 获取购物车商品信息 * @notes 获取购物车商品信息
@ -56,16 +58,24 @@ class OrderLogic extends BaseLogic
} }
try { try {
self::$total = 0; self::$total = 0;
self::$cost = 0;//成本
self::$profit = 0;//利润
/** 计算价格 */ /** 计算价格 */
$check = DictType::where('type','activities')->find(); $check = DictType::where('type', 'activities')->find();
foreach ($cart_select as $k => $v) { foreach ($cart_select as $k => $v) {
$find = StoreBranchProduct::where(['id' => $v['goods']])->field('store_name,image,unit,price,product_id')->find(); $find = StoreBranchProduct::where(['id' => $v['goods']])->field('store_name,image,unit,price,product_id')->find();
if (!$find) { if (!$find) {
continue; continue;
} }
if(isset($check) && $check['status'] == 1){ $productBase = StoreProduct::where('id', $find['product_id'])->withTrashed()->field('price,ot_price,cost')->find();
$find['price'] = StoreProduct::where('id',$find['product_id'])->withTrashed()->value('ot_price'); if (isset($check) && $check['status'] == 1) {
$find['price'] = $productBase['ot_price'];
} }
//利润
$onePrice = bcsub($productBase['price'], $productBase['ot_price'], 2);
$cart_select[$k]['profit'] = bcmul($v['cart_num'], $onePrice, 2);//利润
$cart_select[$k]['cost'] = bcmul($v['cart_num'], $productBase['cost'], 2) ?? 0;
$cart_select[$k]['total'] = bcmul($v['cart_num'], $find['price'], 2);//钱 $cart_select[$k]['total'] = bcmul($v['cart_num'], $find['price'], 2);//钱
$cart_select[$k]['price'] = $find['price']; $cart_select[$k]['price'] = $find['price'];
$cart_select[$k]['product_id'] = $v['goods']; $cart_select[$k]['product_id'] = $v['goods'];
@ -77,63 +87,69 @@ class OrderLogic extends BaseLogic
$cartInfo['image'] = $find['image']; $cartInfo['image'] = $find['image'];
//计算好vip价格 //计算好vip价格
$vipPrice = self::dealVip($find['price']); $vipPrice = self::dealVip($find['price']);
if($vipPrice){ if ($vipPrice) {
$cartInfo['price'] = $vipPrice; $cartInfo['price'] = $vipPrice;
} }
$cartInfo['vip_price'] = $cart_select[$k]['total'] - $vipPrice??0; $cartInfo['vip_price'] = $cart_select[$k]['total'] - $vipPrice ?? 0;
$cart_select[$k]['cart_info'] = json_encode($cartInfo); $cart_select[$k]['cart_info'] = json_encode($cartInfo);
//理论上每笔都是拆分了 //理论上每笔都是拆分了
$cart_select[$k]['name'] = $find['store_name']; $cart_select[$k]['name'] = $find['store_name'];
$cart_select[$k]['imgs'] = $find['image']; $cart_select[$k]['imgs'] = $find['image'];
$cart_select[$k]['unit_name'] = StoreProductUnit::where(['id' => $find['unit']])->value('name'); $cart_select[$k]['unit_name'] = StoreProductUnit::where(['id' => $find['unit']])->value('name');
self::$total = bcadd(self::$total, $cart_select[$k]['total'], 2); self::$total = bcadd(self::$total, $cart_select[$k]['total'], 2);
self::$cost = bcadd(self::$cost, $cart_select[$k]['cost'], 2);
self::$profit = bcadd(self::$profit, $cart_select[$k]['profit'], 2);
} }
//TODO 收单打9.9折 会员按照比例打折 等级按照充值去升级 //TODO 收单打9.9折 会员按照比例打折 等级按照充值去升级
$pay_price = self::$total; $pay_price = self::$total;
// $check = StoreOrder::where('uid',\request()->userId)->count();//首单逻辑 // $check = StoreOrder::where('uid',\request()->userId)->count();//首单逻辑
$vipPrice = 0; $vipPrice = 0;
if(isset($check) && $check['status'] == 1){ if (isset($check) && $check['status'] == 1) {
// $discountRate = '0.99';//首单逻辑 // $discountRate = '0.99';//首单逻辑
// $pay_price 是价格 // $pay_price 是价格
$discountRate = $check['remark'];//折扣 $discountRate = $check['remark'];//折扣
$discountRate = bcdiv($discountRate, '10', 2); $discountRate = bcdiv($discountRate, '10', 2);
$pay_price = bcdiv(bcmul($pay_price, $discountRate, 4), '1', 2); $pay_price = bcdiv(bcmul($pay_price, $discountRate, 4), '1', 2);
}else{ } else {
$userVip = User::where('id',\request()->userId)->value('user_ship'); $userVip = User::where('id', \request()->userId)->value('user_ship');
if($userVip){ if ($userVip) {
switch ($userVip){ switch ($userVip) {
case UserShipEnum::VIP1: case UserShipEnum::VIP1:
$discountRate = UserShip::where('id',UserShipEnum::VIP1)->value('discount'); $discountRate = UserShip::where('id', UserShipEnum::VIP1)->value('discount');
break; break;
case UserShipEnum::VIP2: case UserShipEnum::VIP2:
$discountRate = UserShip::where('id',UserShipEnum::VIP2)->value('discount'); $discountRate = UserShip::where('id', UserShipEnum::VIP2)->value('discount');
break; break;
case UserShipEnum::VIP3: case UserShipEnum::VIP3:
$discountRate = UserShip::where('id',UserShipEnum::VIP3)->value('discount'); $discountRate = UserShip::where('id', UserShipEnum::VIP3)->value('discount');
break; break;
case UserShipEnum::VIP4: case UserShipEnum::VIP4:
$discountRate = UserShip::where('id',UserShipEnum::VIP4)->value('discount'); $discountRate = UserShip::where('id', UserShipEnum::VIP4)->value('discount');
break; break;
case UserShipEnum::VIP5: case UserShipEnum::VIP5:
$discountRate = UserShip::where('id',UserShipEnum::VIP5)->value('discount'); $discountRate = UserShip::where('id', UserShipEnum::VIP5)->value('discount');
break; break;
default: default:
$discountRate = 1; $discountRate = 1;
} }
$discountRate = bcdiv($discountRate, '100', 2); $discountRate = bcdiv($discountRate, '100', 2);
$pay_price = bcdiv(bcmul($pay_price, $discountRate, 4), '1', 2); $pay_price = bcdiv(bcmul($pay_price, $discountRate, 4), '1', 2);
} }
} }
if(!empty(self::$total) && !empty($pay_price)){ if (!empty(self::$total) && !empty($pay_price)) {
bcscale(2); bcscale(2);
$vipPrice = bcsub(self::$total, $pay_price, 2); $vipPrice = bcsub(self::$total, $pay_price, 2);
} }
//成本价 收益
$order = [ $order = [
'create_time' => time(), 'create_time' => time(),
'order_id' => getNewOrderId('PF'), 'order_id' => getNewOrderId('PF'),
'total_price' => self::$total,//总价 'total_price' => self::$total,//总价
'cost' => self::$cost,//成本价
'profit' => self::$profit,//利润
'pay_price' => $pay_price,//后期可能有降价抵扣 'pay_price' => $pay_price,//后期可能有降价抵扣
'vip_price'=>$vipPrice, 'vip_price' => $vipPrice,
'total_num' => count($cart_select),//总数 'total_num' => count($cart_select),//总数
'pay_type' => $params['pay_type'] ?? 0, 'pay_type' => $params['pay_type'] ?? 0,
'reservation_time' => $params['reservation_time'] ?? '', 'reservation_time' => $params['reservation_time'] ?? '',
@ -168,6 +184,7 @@ class OrderLogic extends BaseLogic
$_order['mobile'] = $user['mobile']; $_order['mobile'] = $user['mobile'];
$_order['pay_type'] = $orderInfo['order']['pay_type']; $_order['pay_type'] = $orderInfo['order']['pay_type'];
$_order['verify_code'] = $verify_code; $_order['verify_code'] = $verify_code;
$_order['reservation_time'] = null;
if (isset($params['reservation_time'])) { if (isset($params['reservation_time'])) {
$_order['reservation_time'] = $params['reservation_time']; $_order['reservation_time'] = $params['reservation_time'];
$_order['reservation'] = YesNoEnum::YES; $_order['reservation'] = YesNoEnum::YES;
@ -453,11 +470,11 @@ class OrderLogic extends BaseLogic
//取消售后 //取消售后
public static function cancelSell($where) public static function cancelSell($where)
{ {
return StoreOrder::where($where)->update( return StoreOrder::where($where)->update(
[ [
'refund_status'=>OrderEnum::CANCEL_SALE, 'refund_status' => OrderEnum::CANCEL_SALE,
'status'=>OrderEnum::CANCEL_ORDER, 'status' => OrderEnum::CANCEL_ORDER,
'refund_cancle_time'=>date('Y-m-d H:i:s',time()) 'refund_cancle_time' => date('Y-m-d H:i:s', time())
] ]
); );
@ -512,149 +529,151 @@ class OrderLogic extends BaseLogic
} }
public static function write_count($info,$params) public static function write_count($info, $params)
{ {
$store_id = SystemStoreStaff::where('phone',$info['mobile'])->value('store_id'); $store_id = SystemStoreStaff::where('phone', $info['mobile'])->value('store_id');
if(empty($store_id)){ if (empty($store_id)) {
throw new \Exception('该用户未绑定店铺请查看'); throw new \Exception('该用户未绑定店铺请查看');
} }
$query = StoreOrderCartInfo::alias('o') $query = StoreOrderCartInfo::alias('o')
->leftJoin('store_branch_product p','p.id = o.product_id') ->leftJoin('store_branch_product p', 'p.id = o.product_id')
->leftJoin('store_order s','s.id = o.oid') ->leftJoin('store_order s', 's.id = o.oid')
->field('o.oid,p.store_name,s.order_id') ->field('o.oid,p.store_name,s.order_id')
->where('o.store_id',$store_id); ->where('o.store_id', $store_id);
if(isset($params['name']) && $params['name']){ if (isset($params['name']) && $params['name']) {
if($params['name'] && preg_match('/[\x{4e00}-\x{9fff}]+/u', $params['name'])==1){ if ($params['name'] && preg_match('/[\x{4e00}-\x{9fff}]+/u', $params['name']) == 1) {
$query->where('p.store_name','like','%'.$params['name'].'%'); $query->where('p.store_name', 'like', '%' . $params['name'] . '%');
}else{ } else {
$query->where('s.order_id',$params['name']); $query->where('s.order_id', $params['name']);
} }
} }
$product = $query->select(); $product = $query->select();
if(empty($product)){ if (empty($product)) {
return [ return [
'no_send'=>0, 'no_send' => 0,
'send'=>0 'send' => 0
]; ];
} }
$oids = array_column($product->toArray(), 'oid'); $oids = array_column($product->toArray(), 'oid');
$uniqueOids = array_unique($oids); $uniqueOids = array_unique($oids);
$no_send = StoreOrder::whereIn('id',$uniqueOids) $no_send = StoreOrder::whereIn('id', $uniqueOids)
->where('status',1)->count(); ->where('status', 1)->count();
$send = StoreOrder::whereIn('id',$uniqueOids) $send = StoreOrder::whereIn('id', $uniqueOids)
->where('status',2)->count(); ->where('status', 2)->count();
return [ return [
'no_send'=>$no_send, 'no_send' => $no_send,
'send'=>$send 'send' => $send
]; ];
} }
public static function getOne($code) public static function getOne($code)
{ {
return StoreOrder::with(['store'])->where('verify_code',$code) return StoreOrder::with(['store'])->where('verify_code', $code)
->select()->each(function ($item) { ->select()->each(function ($item) {
$item['goods_list']=StoreOrderCartInfo::where('oid',$item['id'])->with('goodsName')->field('product_id,cart_num,verify_code,is_writeoff,writeoff_time')->limit(3)->select(); $item['goods_list'] = StoreOrderCartInfo::where('oid', $item['id'])->with('goodsName')->field('product_id,cart_num,verify_code,is_writeoff,writeoff_time')->limit(3)->select();
$item['goods_count']=count(explode(',',$item['cart_id'])); $item['goods_count'] = count(explode(',', $item['cart_id']));
return $item; //返回处理后的数据。 return $item; //返回处理后的数据。
}) })
->toArray(); ->toArray();
} }
public static function write_list($info,$status,$params) public static function write_list($info, $status, $params)
{ {
$store_id = SystemStoreStaff::where('phone',$info['mobile'])->value('store_id'); $store_id = SystemStoreStaff::where('phone', $info['mobile'])->value('store_id');
if(empty($store_id)){ if (empty($store_id)) {
throw new \Exception('该用户未绑定店铺请查看'); throw new \Exception('该用户未绑定店铺请查看');
} }
//先查商品相似 //先查商品相似
$query = StoreOrderCartInfo::alias('o') $query = StoreOrderCartInfo::alias('o')
->leftJoin('store_branch_product p','p.id = o.product_id') ->leftJoin('store_branch_product p', 'p.id = o.product_id')
->leftJoin('store_order s','s.id = o.oid') ->leftJoin('store_order s', 's.id = o.oid')
->field('o.oid,p.store_name,s.order_id') ->field('o.oid,p.store_name,s.order_id')
->where('o.store_id',$store_id); ->where('o.store_id', $store_id);
if(isset($params['name']) && $params['name']){ if (isset($params['name']) && $params['name']) {
if($params['name'] && preg_match('/[\x{4e00}-\x{9fff}]+/u', $params['name'])==1){ if ($params['name'] && preg_match('/[\x{4e00}-\x{9fff}]+/u', $params['name']) == 1) {
$query->where('p.store_name','like','%'.$params['name'].'%'); $query->where('p.store_name', 'like', '%' . $params['name'] . '%');
}else{ } else {
$query->where('s.order_id',$params['name']); $query->where('s.order_id', $params['name']);
} }
} }
$product = $query->select(); $product = $query->select();
if(empty($product)){ if (empty($product)) {
return [ return [
'list'=>[], 'list' => [],
'count'=>0 'count' => 0
]; ];
} }
$oids = array_column($product->toArray(), 'oid'); $oids = array_column($product->toArray(), 'oid');
$uniqueOids = array_unique($oids); $uniqueOids = array_unique($oids);
$query = StoreOrder::with(['store']) $query = StoreOrder::with(['store'])
->whereIn('id',$uniqueOids) ->whereIn('id', $uniqueOids)
->where('status',$status); ->where('status', $status);
$count = $query->count(); $count = $query->count();
$list = $query $list = $query
->page($params['page_no'], $params['page_size']) ->page($params['page_no'], $params['page_size'])
->order(['id' => 'desc']) ->order(['id' => 'desc'])
->select() ->select()
->each(function($item){ ->each(function ($item) {
$item['goods_list']=StoreOrderCartInfo::where('oid',$item['id'])->with('goodsName')->field('product_id,cart_num,verify_code,is_writeoff,writeoff_time')->limit(3)->select(); $item['goods_list'] = StoreOrderCartInfo::where('oid', $item['id'])->with('goodsName')->field('product_id,cart_num,verify_code,is_writeoff,writeoff_time')->limit(3)->select();
$item['goods_count']=count(explode(',',$item['cart_id'])); $item['goods_count'] = count(explode(',', $item['cart_id']));
}) })
->toArray(); ->toArray();
return [ return [
'list'=>$list, 'list' => $list,
'count'=>$count 'count' => $count
]; ];
} }
public static function dealRefund($uid,$params) public static function dealRefund($uid, $params)
{ {
//todo 单子不是完成的不允许退款 //todo 单子不是完成的不允许退款
//单笔不拆单子直接修改状态 //单笔不拆单子直接修改状态
$order = StoreOrder::where('id',$params['id'])->withTrashed()->findOrEmpty(); $order = StoreOrder::where('id', $params['id'])->withTrashed()->findOrEmpty();
if(count($params['old_cart_id']) ==1){ $params['refund_num'] = 1;//todo 拿实际数量
if (count($params['old_cart_id']) == 1) {
$order->refund_status = OrderEnum::REFUND_STATUS_YES; $order->refund_status = OrderEnum::REFUND_STATUS_YES;
$order->status = OrderEnum::ALREADY_REFUND; $order->status = OrderEnum::ALREADY_REFUND;
$order->refund_reason_wap_explain =$params['refund_message']??''; $order->refund_reason_wap_explain = $params['refund_message'] ?? '';
$order->refund_num = $params['refund_num']; $order->mark = $params['mark'] ?? '';
$refund_price_cart = StoreOrderCartInfo::where('oid',$params['id']) $order->refund_num = $params['refund_num'] ?? 1;
$refund_price_cart = StoreOrderCartInfo::where('oid', $params['id'])
->field('id,oid,cart_info') ->field('id,oid,cart_info')
->find()->toArray(); ->find()->toArray();
$vipPrice = $order['vip_price']; $vipPrice = $order['vip_price'];
$price = $refund_price_cart['cart_info']['price'] * $params['refund_num']; $price = $refund_price_cart['cart_info']['price'] * $params['refund_num'];
$onePrice = 0; $onePrice = 0;
bcscale(2); bcscale(2);
if($vipPrice){ if ($vipPrice) {
//每单的vip价格 //每单的vip价格
$onePrice = bcdiv($vipPrice, $refund_price_cart['cart_info']['cart_num']); $onePrice = bcdiv($vipPrice, $refund_price_cart['cart_info']['cart_num']);
} }
if($price > $onePrice){ if ($price > $onePrice) {
$price =bcsub($price, $onePrice); $price = bcsub($price, $onePrice);
} }
$order->refund_price = $price; $order->refund_price = $price;
$order->refund_type = $params['refund_type']; $order->refund_type = $params['refund_type'];
$order->save(); $order->save();
}else{ } else {
// 多单的情况 拆主订单为新的2单 修改新的2单的核销码 修改cart_info的核销码 和订单id 退款直接退一单的钱 // 多单的情况 拆主订单为新的2单 修改新的2单的核销码 修改cart_info的核销码 和订单id 退款直接退一单的钱
$order->delete_time = time(); $order->delete_time = time();
$order->save(); $order->save();
Db::startTrans(); Db::startTrans();
try { try {
$order = $order->toArray(); $order = $order->toArray();
$cart_info = StoreOrderCartInfo::where('oid',$params['id']) $cart_info = StoreOrderCartInfo::where('oid', $params['id'])
->whereNotIn('old_cart_id',$params['old_cart_id']) ->whereNotIn('old_cart_id', $params['old_cart_id'])
->select()->toArray(); ->select()->toArray();
if($cart_info){ if ($cart_info) {
$leftOrder = self::dealCreateLeftOrder($order,$cart_info,$params); $leftOrder = self::dealCreateLeftOrder($order, $cart_info, $params);
self::dealChangeCartInfo($leftOrder); self::dealChangeCartInfo($leftOrder);
} }
$refundOrder = self::dealCreateRefundOrder($order,$params); $refundOrder = self::dealCreateRefundOrder($order, $params);
self::dealChangeCartInfo($refundOrder); self::dealChangeCartInfo($refundOrder);
// d($leftOrder,$refundOrder); // d($leftOrder,$refundOrder);
Db::commit(); Db::commit();
@ -675,28 +694,27 @@ class OrderLogic extends BaseLogic
$code = $leftOrder->verify_code; $code = $leftOrder->verify_code;
$new_oid = $leftOrder->id; $new_oid = $leftOrder->id;
$old_id = $leftOrder->pid; $old_id = $leftOrder->pid;
$car_id = explode(',',$leftOrder->cart_id); $car_id = explode(',', $leftOrder->cart_id);
return StoreOrderCartInfo::where('oid',$old_id) return StoreOrderCartInfo::where('oid', $old_id)
->whereIn('old_cart_id',$car_id) ->whereIn('old_cart_id', $car_id)
->update([ ->update([
'oid'=>$new_oid, 'oid' => $new_oid,
'verify_code'=>$code 'verify_code' => $code
]); ]);
} }
public static function dealCreateLeftOrder($order,$cart_info,$params) public static function dealCreateLeftOrder($order, $cart_info, $params)
{ {
//查出不在这个退货中的数据 //查出不在这个退货中的数据
$order['order_id'] = $order['order_id'].'-2'; $order['order_id'] = $order['order_id'] . '-2';
$order['pid'] = $order['id']; $order['pid'] = $order['id'];
unset($order['id']); unset($order['id']);
$allOldCartIds =[]; $allOldCartIds = [];
$totalTotal = 0; $totalTotal = 0;
$totalPrice = 0; $totalPrice = 0;
$totalVipPrice = 0; $totalVipPrice = 0;
foreach ($cart_info as $value){ foreach ($cart_info as $value) {
if (isset($value['old_cart_id'])) { if (isset($value['old_cart_id'])) {
$allOldCartIds[] = $value['old_cart_id']; $allOldCartIds[] = $value['old_cart_id'];
} }
@ -712,7 +730,7 @@ class OrderLogic extends BaseLogic
} }
} }
} }
$order['cart_id'] = implode(',',$allOldCartIds); $order['cart_id'] = implode(',', $allOldCartIds);
$order['total_num'] = count($cart_info); $order['total_num'] = count($cart_info);
$order['refund_type'] = $params['refund_type']; $order['refund_type'] = $params['refund_type'];
$order['total_price'] = number_format($totalTotal, 2); $order['total_price'] = number_format($totalTotal, 2);
@ -722,24 +740,24 @@ class OrderLogic extends BaseLogic
$order['create_time'] = time(); $order['create_time'] = time();
$order['update_time'] = null; $order['update_time'] = null;
$order['delete_time'] = null; $order['delete_time'] = null;
return StoreOrder::create($order); return StoreOrder::create($order);
} }
public static function dealCreateRefundOrder($order, $params)
public static function dealCreateRefundOrder($order,$params)
{ {
$order['order_id'] = $order['order_id'].'-1'; $order['order_id'] = $order['order_id'] . '-1';
$order['pid'] = $order['id']; $order['pid'] = $order['id'];
unset($order['id']); unset($order['id']);
$order['cart_id'] = implode(',',$params['old_cart_id']); $order['cart_id'] = implode(',', $params['old_cart_id']);
$order['refund_status'] = OrderEnum::REFUND_STATUS_YES; $order['refund_status'] = OrderEnum::REFUND_STATUS_YES;
$order['status'] = OrderEnum::ALREADY_REFUND; $order['status'] = OrderEnum::ALREADY_REFUND;
$order['refund_num'] = $params['refund_num'];//按数量整单退剩余的 $order['refund_num'] = $params['refund_num'];//按数量整单退剩余的
$order['refund_reason_wap_explain'] = $params['refund_message']??''; $order['refund_reason_wap_explain'] = $params['refund_message'] ?? '';
$order['mark'] = $params['mark'] ?? '';
$order['total_num'] = count($params['old_cart_id']); $order['total_num'] = count($params['old_cart_id']);
$refund_price_cart = StoreOrderCartInfo::whereIn('old_cart_id',$params['old_cart_id']) $refund_price_cart = StoreOrderCartInfo::whereIn('old_cart_id', $params['old_cart_id'])
->field('id,oid,cart_info') ->field('id,oid,cart_info')
->select()->toArray(); ->select()->toArray();
$totalTotals = array_column(array_column($refund_price_cart, 'cart_info'), 'total'); $totalTotals = array_column(array_column($refund_price_cart, 'cart_info'), 'total');
@ -759,49 +777,49 @@ class OrderLogic extends BaseLogic
$order['total_price'] = number_format($totalTotal, 2); $order['total_price'] = number_format($totalTotal, 2);
$order['pay_price'] = number_format($totalPrice, 2); $order['pay_price'] = number_format($totalPrice, 2);
$order['vip_price'] = number_format($totalVipPrices, 2); $order['vip_price'] = number_format($totalVipPrices, 2);
$order['refund_price'] = number_format($totalPrice, 2); $order['refund_price'] = number_format($totalPrice, 2);
$order['verify_code'] = verificationCode(); $order['verify_code'] = verificationCode();
$order['refund_reason_time'] = time(); $order['refund_reason_time'] = time();
$order['create_time'] = time()+1; $order['create_time'] = time() + 1;
$order['update_time'] = null; $order['update_time'] = null;
$order['delete_time'] = null; $order['delete_time'] = null;
return StoreOrder::create($order); return StoreOrder::create($order);
} }
public static function dealVip($pay_price) public static function dealVip($pay_price)
{ {
$check = DictType::where('type','activities')->find(); $check = DictType::where('type', 'activities')->find();
if(isset($check) && $check['status'] == 1){ if (isset($check) && $check['status'] == 1) {
// $discountRate = '0.99';//首单逻辑 // $discountRate = '0.99';//首单逻辑
$discountRate = $check['remark']; $discountRate = $check['remark'];
$discountRate = bcdiv($discountRate, '100', 2); $discountRate = bcdiv($discountRate, '100', 2);
$pay_price = bcdiv(bcmul($pay_price, $discountRate, 4), '1', 2); $pay_price = bcdiv(bcmul($pay_price, $discountRate, 4), '1', 2);
}else{ } else {
$userVip = User::where('id',\request()->userId)->value('user_ship'); $userVip = User::where('id', \request()->userId)->value('user_ship');
if($userVip){ if ($userVip) {
switch ($userVip){ switch ($userVip) {
case UserShipEnum::VIP1: case UserShipEnum::VIP1:
$discountRate = UserShip::where('id',UserShipEnum::VIP1)->value('discount'); $discountRate = UserShip::where('id', UserShipEnum::VIP1)->value('discount');
break; break;
case UserShipEnum::VIP2: case UserShipEnum::VIP2:
$discountRate = UserShip::where('id',UserShipEnum::VIP2)->value('discount'); $discountRate = UserShip::where('id', UserShipEnum::VIP2)->value('discount');
break; break;
case UserShipEnum::VIP3: case UserShipEnum::VIP3:
$discountRate = UserShip::where('id',UserShipEnum::VIP3)->value('discount'); $discountRate = UserShip::where('id', UserShipEnum::VIP3)->value('discount');
break; break;
case UserShipEnum::VIP4: case UserShipEnum::VIP4:
$discountRate = UserShip::where('id',UserShipEnum::VIP4)->value('discount'); $discountRate = UserShip::where('id', UserShipEnum::VIP4)->value('discount');
break; break;
case UserShipEnum::VIP5: case UserShipEnum::VIP5:
$discountRate = UserShip::where('id',UserShipEnum::VIP5)->value('discount'); $discountRate = UserShip::where('id', UserShipEnum::VIP5)->value('discount');
break; break;
default: default:
$discountRate = 1; $discountRate = 1;
} }
$discountRate = bcdiv($discountRate, '100', 2); $discountRate = bcdiv($discountRate, '100', 2);
$pay_price = bcdiv(bcmul($pay_price, $discountRate, 4), '1', 2); $pay_price = bcdiv(bcmul($pay_price, $discountRate, 4), '1', 2);
} }
} }
return $pay_price; return $pay_price;

View File

@ -18,6 +18,7 @@ class OrderEnum
* @SUPPLIER_ORDER_OBTAINS 供应链订单获得 * @SUPPLIER_ORDER_OBTAINS 供应链订单获得
* @PLATFORM_ORDER_PAY 平台订单支付 * @PLATFORM_ORDER_PAY 平台订单支付
* @SYSTEM_SET 系统设置 * @SYSTEM_SET 系统设置
* @OWN_GET 平台收入
*/ */
const USER_ORDER_PAY = 1; const USER_ORDER_PAY = 1;
const MERCHANT_ORDER_OBTAINS = 2; const MERCHANT_ORDER_OBTAINS = 2;
@ -30,6 +31,8 @@ class OrderEnum
const CASHIER_ORDER_PAY = 9; const CASHIER_ORDER_PAY = 9;
const CASHIER_CASH_ORDER_PAY = 10; const CASHIER_CASH_ORDER_PAY = 10;
const OWN_GET = 3;
/** /**
* 收入支出类型 * 收入支出类型