|
@@ -108,6 +108,7 @@ class OrderCreate
|
|
|
'goods_old_amount' => '0', // 商品不参与活动时的总价
|
|
|
'goods_amount' => '0', // 商品总价
|
|
|
'goods_bean_amount' => '0', // 商品善豆可抵扣总价
|
|
|
+ 'goods_back_amount' => '0', // 商品可让利总价
|
|
|
'coupon_discount_fee' => '0', // 优惠券优惠金额
|
|
|
'promo_discount_fee' => 0, // 当前促销优惠总金额 (包含满包邮的邮费)
|
|
|
'total_discount_fee' => 0, // 当前订单,总优惠金额(优惠券 + 活动优惠)
|
|
@@ -322,6 +323,12 @@ class OrderCreate
|
|
|
$current_goods_bean_amount = bcdiv(bcmul($current_goods_amount,$bean_rate,2),100,2);
|
|
|
$this->orderData['goods_bean_amount'] = bcadd($this->orderData['goods_bean_amount'],$current_goods_bean_amount,2);
|
|
|
|
|
|
+ //能让利百分比
|
|
|
+ $back_rate = floatval($goods->back_rate) > 0 ? $goods->back_rate : 0;
|
|
|
+
|
|
|
+ $current_goods_back_amount = bcdiv(bcmul($current_goods_amount,$back_rate,2),100,2);
|
|
|
+ $this->orderData['goods_back_amount'] = bcadd($this->orderData['goods_back_amount'],$current_goods_back_amount,2);
|
|
|
+
|
|
|
// 当有活动时,计算作为普通商品时的商品总金额
|
|
|
$current_goods_old_amount = $current_goods_amount;
|
|
|
if ($this->activity['activity']) {
|
|
@@ -344,6 +351,7 @@ class OrderCreate
|
|
|
$buyInfo['goods_original_amount'] = $current_goods_original_amount; // 当前商品原始总金额(原价 * 数量)
|
|
|
$buyInfo['goods_amount'] = $current_goods_amount; // 当前商品总金额(价格 * 数量)
|
|
|
$buyInfo['goods_bean_amount'] = $current_goods_bean_amount; // 当前商品可抵扣最高总金额(当前商品总金额 * 比例)
|
|
|
+ $buyInfo['goods_back_amount'] = $current_goods_back_amount; // 当前商品让利总金额(当前商品总金额 * 比例)
|
|
|
$buyInfo['score_amount'] = $current_score_amount; // 商品所需积分(积分商城)
|
|
|
$buyInfo['weight'] = $current_weight; // 当前商品总重量
|
|
|
$buyInfo['original_dispatch_amount'] = 0; // 当前商品运费(未判断活动的,并且也未合并相同运费模板商品的原始运费)
|
|
@@ -987,6 +995,7 @@ class OrderCreate
|
|
|
'goods_amount' => $this->orderData['goods_amount'],
|
|
|
|
|
|
'goods_bean_amount' => $this->orderData['goods_bean_amount'], //最大可抵扣善豆
|
|
|
+ 'goods_back_amount' => $this->orderData['goods_back_amount'], //让利金额
|
|
|
'user_bean_amount' => $user_bean, //用户善豆余额
|
|
|
'min_bean_amount' => config('site.shopro_min_bean_amount'), //最小可使用善豆数量
|
|
|
|
|
@@ -1130,6 +1139,7 @@ class OrderCreate
|
|
|
$orderData['goods_original_amount'] = $result['goods_original_amount'];
|
|
|
$orderData['goods_amount'] = $result['goods_amount'];
|
|
|
$orderData['goods_bean_amount'] = $result['goods_bean_amount'];
|
|
|
+ $orderData['goods_back_amount'] = $result['goods_back_amount'];
|
|
|
$orderData['dispatch_amount'] = $result['dispatch_amount'];
|
|
|
$orderData['remark'] = $this->remark;
|
|
|
$orderData['order_amount'] = $result['order_amount'];
|
|
@@ -1194,6 +1204,9 @@ class OrderCreate
|
|
|
$order = new Order();
|
|
|
$order->save($orderData);
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
// 添加收货地址信息
|
|
|
if ($result['user_address']) {
|
|
|
$this->createOrderAddress($order, $result);
|
|
@@ -1211,9 +1224,13 @@ class OrderCreate
|
|
|
$result['coupon']->allowField(true)->save();
|
|
|
}
|
|
|
|
|
|
+ //bill表args
|
|
|
+ $bill_args = [];
|
|
|
+
|
|
|
// 添加 订单 item
|
|
|
foreach ($result['goods_list'] as $key => $buyInfo) {
|
|
|
$goods = $buyInfo['goods'];
|
|
|
+
|
|
|
$current_sku_price = $buyInfo['current_sku_price'];
|
|
|
|
|
|
$orderItem = new OrderItem();
|
|
@@ -1248,6 +1265,9 @@ class OrderCreate
|
|
|
$orderItem->comment_status = 0;
|
|
|
$orderItem->refund_status = 0;
|
|
|
|
|
|
+ $orderItem->back_rate = floatval($goods->back_rate) > 0 ? $goods->back_rate : 0; //让利比例
|
|
|
+ $orderItem->goods_back_amount = $buyInfo['goods_back_amount']; //让利总额
|
|
|
+
|
|
|
$orderItem->room_id = $orderData['room_id'];
|
|
|
$orderItem->room_log_id = $orderData['room_log_id'];
|
|
|
|
|
@@ -1263,10 +1283,24 @@ class OrderCreate
|
|
|
$ext['is_commission'] = $buyInfo['is_commission'];
|
|
|
}
|
|
|
|
|
|
+ //bill表args
|
|
|
+ $bill_args[] = [
|
|
|
+ 'goods_sku_price_id' => $orderItem->goods_sku_price_id,
|
|
|
+ 'goods_title' => $orderItem->goods_title,
|
|
|
+ 'goods_image' => $orderItem->goods_image,
|
|
|
+ 'goods_price' => $orderItem->goods_price,
|
|
|
+ 'goods_num' => $orderItem->goods_num,
|
|
|
+ 'goods_sku_text' => $orderItem->goods_sku_text,
|
|
|
+ 'goods_amount' => $buyInfo['goods_amount'],
|
|
|
+ ];
|
|
|
+
|
|
|
$orderItem->ext = $ext;
|
|
|
$orderItem->save();
|
|
|
}
|
|
|
|
|
|
+ //冗余到bill
|
|
|
+ $this->createBill($order->id,$orderData,$bill_args);
|
|
|
+
|
|
|
// 订单创建后
|
|
|
$hookData = [
|
|
|
'order' => $order,
|
|
@@ -1280,6 +1314,31 @@ class OrderCreate
|
|
|
return $order;
|
|
|
}
|
|
|
|
|
|
+ //冗余到bill表
|
|
|
+ public function createBill($order_id,$orderData,$bill_args){
|
|
|
+
|
|
|
+ $num_sum = array_sum(array_column($bill_args,'goods_num'));
|
|
|
+
|
|
|
+ $bill = [
|
|
|
+ 'user_id' => $orderData['user_id'],
|
|
|
+ 'order_no' => $orderData['order_sn'],
|
|
|
+ 'num' => $num_sum,
|
|
|
+ 'pay_amount' => $orderData['pay_fee'],
|
|
|
+ 'table_id' => $order_id,
|
|
|
+ 'table_name' => 'shopro_order',
|
|
|
+
|
|
|
+ 'shop_name' => '商城',
|
|
|
+ 'shop_logo' => '',
|
|
|
+ 'args' => json_encode($bill_args,JSON_UNESCAPED_UNICODE),
|
|
|
+ 'total_amount' => $orderData['order_amount'],
|
|
|
+
|
|
|
+ 'back_amount' => $orderData['goods_back_amount'], //因为一个订单有多个商品,所以直接从订单拿就好
|
|
|
+ 'createtime' => time(),
|
|
|
+ ];
|
|
|
+
|
|
|
+ Db::name('bill')->insertGetId($bill);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 添加收货地址信息
|