|
@@ -17,6 +17,7 @@ use app\admin\model\shopro\user\Coupon;
|
|
|
use app\admin\model\shopro\user\Address as UserAddress;
|
|
|
use app\admin\model\shopro\user\Invoice as UserInvoice;
|
|
|
use addons\shopro\service\StockSale;
|
|
|
+use app\common\model\Wallet;
|
|
|
|
|
|
class OrderCreate
|
|
|
{
|
|
@@ -74,6 +75,11 @@ class OrderCreate
|
|
|
protected $money = 0;
|
|
|
|
|
|
/**
|
|
|
+ * 善豆抵扣(余额和 微信|支付宝,混合支付时使用了)
|
|
|
+ */
|
|
|
+ protected $bean = 0;
|
|
|
+
|
|
|
+ /**
|
|
|
* 发票配置
|
|
|
*/
|
|
|
protected $invoiceConfig = [];
|
|
@@ -101,6 +107,7 @@ class OrderCreate
|
|
|
'goods_original_amount' => '0', // 商品原始总价
|
|
|
'goods_old_amount' => '0', // 商品不参与活动时的总价
|
|
|
'goods_amount' => '0', // 商品总价
|
|
|
+ 'goods_bean_amount' => '0', // 商品善豆可抵扣总价
|
|
|
'coupon_discount_fee' => '0', // 优惠券优惠金额
|
|
|
'promo_discount_fee' => 0, // 当前促销优惠总金额 (包含满包邮的邮费)
|
|
|
'total_discount_fee' => 0, // 当前订单,总优惠金额(优惠券 + 活动优惠)
|
|
@@ -156,6 +163,7 @@ class OrderCreate
|
|
|
$this->remark = $params['remark'] ?? '';
|
|
|
|
|
|
$this->money = (isset($params['money']) && $params['money'] > 0) ? $params['money'] : 0;
|
|
|
+ $this->bean = (isset($params['bean']) && $params['bean'] > 0) ? $params['bean'] : 0;
|
|
|
|
|
|
// 获取商品信息
|
|
|
$this->goodsListInit();
|
|
@@ -289,10 +297,13 @@ class OrderCreate
|
|
|
*/
|
|
|
public function calcAmount()
|
|
|
{
|
|
|
+ //dump($this->goodsList);
|
|
|
// 计算商品金额
|
|
|
foreach ($this->goodsList as $key => &$buyInfo) {
|
|
|
$goods = $buyInfo['goods'];
|
|
|
|
|
|
+ //dd(json_decode(json_encode($buyInfo),true));
|
|
|
+
|
|
|
// 当前商品原始总价
|
|
|
$current_goods_original_amount = bcmul($goods->original_price, $buyInfo['goods_num'], 2);
|
|
|
$this->orderData['goods_original_amount'] = bcadd($this->orderData['goods_original_amount'], $current_goods_original_amount, 2);
|
|
@@ -301,6 +312,16 @@ class OrderCreate
|
|
|
$current_goods_amount = bcmul($buyInfo['current_sku_price']->price, $buyInfo['goods_num'], 2);
|
|
|
$this->orderData['goods_amount'] = bcadd($this->orderData['goods_amount'], $current_goods_amount, 2);
|
|
|
|
|
|
+ //当前商品的善豆抵扣价,商品没有就拿分类
|
|
|
+ $bean_rate = floatval($goods->bean_rate) > 0 ? $goods->bean_rate : 0;
|
|
|
+ if($bean_rate == 0){
|
|
|
+ $bean_rate = Db::name('shopro_category')->where('id',$goods->category_ids)->value('bean_rate');
|
|
|
+ $bean_rate = floatval($bean_rate) > 0 ? $bean_rate : 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ $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);
|
|
|
+
|
|
|
// 当有活动时,计算作为普通商品时的商品总金额
|
|
|
$current_goods_old_amount = $current_goods_amount;
|
|
|
if ($this->activity['activity']) {
|
|
@@ -315,12 +336,14 @@ class OrderCreate
|
|
|
$this->orderData['score_amount'] = $this->orderData['score_amount'] + $current_score_amount;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
// 当前商品总重量
|
|
|
$current_weight = bcmul($buyInfo['current_sku_price']->weight, $buyInfo['goods_num'], 2);
|
|
|
|
|
|
// 将计算好的属性记录下来,插入订单 item 表使用
|
|
|
$buyInfo['goods_original_amount'] = $current_goods_original_amount; // 当前商品原始总金额(原价 * 数量)
|
|
|
$buyInfo['goods_amount'] = $current_goods_amount; // 当前商品总金额(价格 * 数量)
|
|
|
+ $buyInfo['goods_bean_amount'] = $current_goods_bean_amount; // 当前商品可抵扣最高总金额(当前商品总金额 * 比例)
|
|
|
$buyInfo['score_amount'] = $current_score_amount; // 商品所需积分(积分商城)
|
|
|
$buyInfo['weight'] = $current_weight; // 当前商品总重量
|
|
|
$buyInfo['original_dispatch_amount'] = 0; // 当前商品运费(未判断活动的,并且也未合并相同运费模板商品的原始运费)
|
|
@@ -949,12 +972,24 @@ class OrderCreate
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- $temp_remain_pay_fee = bcsub($this->orderData['pay_fee'], $this->money, 2);
|
|
|
+ //善豆抵扣不能高于善豆余额
|
|
|
+ $user_bean = (new Wallet())->getWalletBak($this->user->id,'bean');
|
|
|
+ $this->orderData['goods_bean_amount'] = $this->orderData['goods_bean_amount'] > $user_bean ? $user_bean : $this->orderData['goods_bean_amount'];
|
|
|
+
|
|
|
+ //$temp_remain_pay_fee = bcsub($this->orderData['pay_fee'], $this->money, 2);
|
|
|
+
|
|
|
+ $this->bean = $this->bean > $this->orderData['goods_bean_amount'] ? $this->orderData['goods_bean_amount'] : $this->bean;
|
|
|
+ $temp_remain_pay_fee = bcsub($this->orderData['pay_fee'], $this->bean, 2);
|
|
|
|
|
|
$result = [
|
|
|
'goods_original_amount' => $this->orderData['goods_original_amount'],
|
|
|
'goods_old_amount' => $this->orderData['goods_old_amount'],
|
|
|
'goods_amount' => $this->orderData['goods_amount'],
|
|
|
+
|
|
|
+ 'goods_bean_amount' => $this->orderData['goods_bean_amount'], //最大可抵扣善豆
|
|
|
+ 'user_bean_amount' => $user_bean, //用户善豆余额
|
|
|
+ 'min_bean_amount' => config('site.shopro_min_bean_amount'), //最小可使用善豆数量
|
|
|
+
|
|
|
'dispatch_amount' => $this->orderData['dispatch_amount'],
|
|
|
'real_dispatch_amount' => $this->orderData['real_dispatch_amount'],
|
|
|
'order_amount' => $this->orderData['order_amount'],
|
|
@@ -964,6 +999,7 @@ class OrderCreate
|
|
|
'coupon_discount_fee' => $this->orderData['coupon_discount_fee'],
|
|
|
'promo_discount_fee' => $this->orderData['promo_discount_fee'], // 包含包邮的运费优惠
|
|
|
'money' => $this->money, // 余额支付部分
|
|
|
+ 'bean' => $this->bean, // 善豆支付部分
|
|
|
"invoice_amount" => $this->orderData[$this->invoiceConfig['amount_type']] // 可开票金额
|
|
|
];
|
|
|
|
|
@@ -1093,6 +1129,7 @@ class OrderCreate
|
|
|
$orderData['promo_types'] = join(',', $result['promo_types']);
|
|
|
$orderData['goods_original_amount'] = $result['goods_original_amount'];
|
|
|
$orderData['goods_amount'] = $result['goods_amount'];
|
|
|
+ $orderData['goods_bean_amount'] = $result['goods_bean_amount'];
|
|
|
$orderData['dispatch_amount'] = $result['dispatch_amount'];
|
|
|
$orderData['remark'] = $this->remark;
|
|
|
$orderData['order_amount'] = $result['order_amount'];
|