创建订单计算成本和利润
This commit is contained in:
parent
8644e3d571
commit
b6aa59e1b8
@ -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,6 +58,9 @@ 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) {
|
||||||
@ -63,9 +68,14 @@ class OrderLogic extends BaseLogic
|
|||||||
if (!$find) {
|
if (!$find) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
$productBase = StoreProduct::where('id', $find['product_id'])->withTrashed()->field('price,ot_price,cost')->find();
|
||||||
if (isset($check) && $check['status'] == 1) {
|
if (isset($check) && $check['status'] == 1) {
|
||||||
$find['price'] = StoreProduct::where('id',$find['product_id'])->withTrashed()->value('ot_price');
|
$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'];
|
||||||
@ -87,6 +97,8 @@ class OrderLogic extends BaseLogic
|
|||||||
$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;
|
||||||
@ -128,10 +140,14 @@ class OrderLogic extends BaseLogic
|
|||||||
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),//总数
|
||||||
@ -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;
|
||||||
@ -618,11 +635,13 @@ class OrderLogic extends BaseLogic
|
|||||||
//todo 单子不是完成的不允许退款
|
//todo 单子不是完成的不允许退款
|
||||||
//单笔不拆单子直接修改状态
|
//单笔不拆单子直接修改状态
|
||||||
$order = StoreOrder::where('id', $params['id'])->withTrashed()->findOrEmpty();
|
$order = StoreOrder::where('id', $params['id'])->withTrashed()->findOrEmpty();
|
||||||
|
$params['refund_num'] = 1;//todo 拿实际数量
|
||||||
if (count($params['old_cart_id']) == 1) {
|
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'] ?? '';
|
||||||
|
$order->refund_num = $params['refund_num'] ?? 1;
|
||||||
$refund_price_cart = StoreOrderCartInfo::where('oid', $params['id'])
|
$refund_price_cart = StoreOrderCartInfo::where('oid', $params['id'])
|
||||||
->field('id,oid,cart_info')
|
->field('id,oid,cart_info')
|
||||||
->find()->toArray();
|
->find()->toArray();
|
||||||
@ -685,7 +704,6 @@ class OrderLogic extends BaseLogic
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static function dealCreateLeftOrder($order, $cart_info, $params)
|
public static function dealCreateLeftOrder($order, $cart_info, $params)
|
||||||
{
|
{
|
||||||
//查出不在这个退货中的数据
|
//查出不在这个退货中的数据
|
||||||
@ -726,7 +744,6 @@ class OrderLogic extends BaseLogic
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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';
|
||||||
@ -738,6 +755,7 @@ class OrderLogic extends BaseLogic
|
|||||||
$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')
|
||||||
|
@ -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;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 收入支出类型
|
* 收入支出类型
|
||||||
|
Loading…
x
Reference in New Issue
Block a user