1557492053 преди 3 години
родител
ревизия
9e117b98cc
променени са 4 файла, в които са добавени 67 реда и са изтрити 4 реда
  1. 54 1
      app/api/service/OrderService.php
  2. 6 3
      app/api/service/ProductService.php
  3. 6 0
      app/common/model/CustomerZueCoinModel.php
  4. 1 0
      app/common/model/PaymentChannelModel.php

+ 54 - 1
app/api/service/OrderService.php

@@ -9,6 +9,7 @@ use app\common\model\AdminModel;
 use app\common\model\ConfigModel;
 use app\common\model\CreditCardConfigModel;
 use app\common\model\CustomerModel;
+use app\common\model\CustomerZueCoinModel;
 use app\common\model\OrderAnnualFeeModel;
 use app\common\model\OrderModel;
 use app\common\model\OrderPaymentModel;
@@ -36,6 +37,7 @@ class OrderService extends \app\BaseService
     private $customerModel;
     private $paymentChannelModel;
     private $creditCardModel;
+    private $zueCoinModel;
 
     public function __construct()
     {
@@ -53,6 +55,7 @@ class OrderService extends \app\BaseService
         $this->customerModel = new CustomerModel();
         $this->paymentChannelModel = new PaymentChannelModel();
         $this->creditCardModel = new CreditCardConfigModel();
+        $this->zueCoinModel = new CustomerZueCoinModel();
     }
 
     /**
@@ -277,6 +280,7 @@ class OrderService extends \app\BaseService
                 $item['fee'] = $channel->fee;
                 // TODO: 御龙币需求未明确
                 array_push($order_payments, $item);
+                $zue_coin += $channel->fee;
             } else {
                 for ($j = 0; $j < count($channel->credit_card); $j++) {
                     $credit_card = $channel->credit_card[$j];
@@ -326,6 +330,51 @@ class OrderService extends \app\BaseService
         $total_service_charge_amount = ($order->service_charge_amount + $service_charge);
         // 总共需要收取这么多费用; (商品的价格 + 商品税费 + 年费 + 信用卡手续费) - 御龙币抵扣的费用
         $imposed_amount = fixed2Float($order->product_amount + $order->total_sales_tax + $order->total_annual_fee + $total_service_charge_amount);
+
+
+        $order_use_zue_coin = $order->zue_coin;
+        $order_use_zue_coin_amount = $order->zue_coin_amount;
+
+        if($zue_coin > 0) {
+            $zue_coin_model = $this->zueCoinModel->findByCustomerId($customer->id);
+            if ($zue_coin > $zue_coin_model->zue_coin)
+                return $this->fail("当前客户御龙币账户余额:{$zue_coin_model->zue_coin}");
+            $zue_coin_config = $fmt_pay_channels['11'];
+            if(!$zue_coin_config)
+                return $this->fail("御龙币设置不存在!");
+            $zue_coin_exchange_rate = $zue_coin_config['zue_coin_exchange_rate'] ?? 0; // 兑换比例
+            $zue_coin_consume_rate = $zue_coin_config['zue_coin_consume_rate'] ?? 0; // 报销比例
+            if($zue_coin_exchange_rate == 0 || $zue_coin_consume_rate == 0) {
+                return $this->fail("该笔订单不支持御龙币支付");
+            }
+
+            // 1.计算出该订单能使用多少御龙币
+            // 2.结合之前已使用的御龙币 算出还能使用多少御龙币
+            // 3.判断当前御龙币是否符合兑换数额
+            // 4.进行扣除并记录
+
+            // 总共能报销这么多钱
+            $total_consume_amount = fixed2Float($imposed_amount * ($zue_coin_consume_rate / 100));
+            // 总共能消耗这么多御龙币
+            $total_can_zue_coin = fixed2Float($total_consume_amount / $zue_coin_exchange_rate);
+            // 还能使用多少御龙币
+            $now_can_consume_zue_coin = $total_can_zue_coin - $order_use_zue_coin;
+            // 判断当前还能使用
+            if ($now_can_consume_zue_coin - $zue_coin < 0)
+                return $this->fail("
+                    当前已使用御龙币数额: {$order_use_zue_coin}/{$total_can_zue_coin},
+                    当前已兑换金额: {$order_use_zue_coin_amount}/{$total_consume_amount},
+                    御龙币兑换比例: {$zue_coin_exchange_rate},
+                    御龙币报销比例:{$zue_coin_consume_rate}
+                ");
+            // 总共使用了这么多御龙币
+            $order_use_zue_coin += $zue_coin;
+            // 总共兑换了这么多钱
+            $order_use_zue_coin_amount = fixed2Float($order_use_zue_coin * $zue_coin_exchange_rate);
+        }
+        // 总计费用 - 御龙币抵消费用;
+        $imposed_amount -= $order_use_zue_coin_amount;
+
         // 总计实收金额
         $receive_amount = fixed2Float($order->receive_amount + $total_fee);
         if (round($receive_amount) > round($imposed_amount)) return $this->fail("实收金额大于待收金额! 应该支付 {$imposed_amount} (商品总价:{$order->product_amount} + 商品总消费税:{$order->total_sales_tax} + 第一年年费:{$order->total_annual_fee} + 信用卡总手续费:{$total_service_charge_amount})");
@@ -369,15 +418,19 @@ class OrderService extends \app\BaseService
                 }
             }
         }
+        return $this->ok(true);
 
         Db::startTrans();
         try {
             $update_order = [
-                'rental_amount' => $imposed_amount,
+                'rental_amount' => $imposed_amount + $order_use_zue_coin_amount,
                 'receivable_amount' => $imposed_amount,
                 'receive_amount'    =>  $receive_amount,
                 'imposed_amount'    =>  $imposed_amount - $receive_amount,
                 'service_charge_amount' =>  $order->service_charge_amount + $service_charge,
+                'zue_coin'      =>  $order_use_zue_coin,
+                'zue_coin_amount' => $order_use_zue_coin_amount,
+                'remarks'   =>  $params['remarks']
             ];
             if (round($receive_amount) == round($imposed_amount)) { // 支付满了
                 $update_order['type'] = 1;

+ 6 - 3
app/api/service/ProductService.php

@@ -46,15 +46,18 @@ class ProductService extends BaseService
                 return $aProduct['product_id'] == $item['product_id'];
             });
             $res = compare($item['product']['real_price'] ?? 0, $aProducts);
-            $item['product']['real_price'] = fixed2Float($res['min_num']);
+            $item['product']['activity_price'] = fixed2Float($res['min_num']);
             $item['activity'] = $res['item'];
             $sales_tax_rate = $item['product']['sales_tax_rate'] > 0 ? $item['product']['sales_tax_rate'] : $config->sales_tax_rate;
-            $sales_tax = fixed2Float($sales_tax_rate > 0 && $item['product']['real_price'] > 0 ? ($item['product']['real_price'] * ($sales_tax_rate / 100)) : 0);
             $item['product']['sales_tax_rate'] = $sales_tax_rate;
-            $item['product']['sales_tax'] = $sales_tax;
+            $item['product']['sales_tax'] = fixed2Float($sales_tax_rate > 0 && $item['product']['activity_price'] > 0 ? ($item['product']['activity_price'] * ($sales_tax_rate / 100)) : 0);
         }
         return [$items, $storeProducts->total()];
     }
 
+    // 订单总额 = 商品价格 + 商品年费 + 商品消费税
+    // 应收金额 = 商品的活动价 + 商品年费 + 商品消费税
+    // 优惠金额 = 订单总额 - 应收金额 + 商品消费税
+    // 消费税 = 商品的消费税
 
 }

+ 6 - 0
app/common/model/CustomerZueCoinModel.php

@@ -49,6 +49,12 @@ class CustomerZueCoinModel extends BaseModel
         ])->with(['customer', 'record'])->find();
     }
 
+    public function findByCustomerId($c_id) {
+        return $this->where([
+            ['is_delete', '=', 0],
+            ['lose_time', '<=', time()],
+        ])->order('lose_time', 'Asc')->find();
+    }
 
 }
 

+ 1 - 0
app/common/model/PaymentChannelModel.php

@@ -39,4 +39,5 @@ class PaymentChannelModel extends BaseModel
             ])->find();
     }
 
+
 }