Sfoglia il codice sorgente

临时存储,有赞转单校验活动相关字段和注释

wufeng 2 anni fa
parent
commit
c85413eea1
2 ha cambiato i file con 74 aggiunte e 29 eliminazioni
  1. 34 29
      app/command/handleYzOrderData.php
  2. 40 0
      app/common.php

+ 34 - 29
app/command/handleYzOrderData.php

@@ -144,14 +144,15 @@ class handleYzOrderData extends Command
 //                        ->find();
 //
 //                    if ($stock == false || $stock['usable_stock'] < $good_num) throw new Exception('库存数量不足');
-                        $stock_num = Db::name("good_stock")->alias("a")
-			            ->leftJoin("warehouse_info b", "a.wsm_code=b.wsm_code")
-			            ->leftJoin("good_stock_info c", "a.id=c.stockid and c.balance_num>0")
-			            ->where(["spuCode" => $spuCode, "a.is_del" => 0, "a.status" => 1, "b.wsm_type" => 5, "b.companyNo" =>$supplierNo])
-			            ->sum('balance_num');
-			            if($stock_num < $good_num){
-			                 throw new Exception('bn库存数量不足');
-			            }
+                    $stock_num = Db::name("good_stock")
+                        ->alias("a")
+                        ->leftJoin("warehouse_info b", "a.wsm_code=b.wsm_code")
+                        ->leftJoin("good_stock_info c", "a.id=c.stockid and c.balance_num>0")
+                        ->where(["spuCode" => $spuCode, "a.is_del" => 0, "a.status" => 1, "b.wsm_type" => 5, "b.companyNo" => $supplierNo])
+                        ->sum('balance_num');
+                    if ($stock_num < $good_num) {
+                        throw new Exception('bn库存数量不足');
+                    }
                     $origin_price = 0;
 
                 } else {
@@ -168,30 +169,34 @@ class handleYzOrderData extends Command
 
 
                 //活动相关信息
-                $act = Db::name('activity_info')
-                    ->alias('ai')
-                    ->field('ai.id,ai.activity_stock,ai.moq_num,ai.activity_stock')
-                    ->join('good_activity ga', 'ga.activity_code=ai.activity_code')
-                    ->where([
-                        'ai.skuCode' => $skuCode,
-                        'ai.spuCode' => $spuCode,
-                        'ai.is_del' => 0,
-                        'ai.status' => 1,
-                        'ga.status' => 6,
-                        'ga.is_del' => 0,
-                        'ga.platform_code' => $platform_id,
-                        'ga.is_stock' => $is_stock
-                    ])
-                    ->where(function ($query) {
-                        return $query->where('ga.start', '<=', date('Y-m-d H:i:s'))->where('ga.end', '>=', date('Y-m-d H:i:s'));
-                    })
-                    ->find();
+//                $act = Db::name('activity_info')
+//                    ->alias('ai')
+//                    ->field('ai.id,ai.activity_stock,ai.moq_num,ai.activity_stock')
+//                    ->join('good_activity ga', 'ga.activity_code=ai.activity_code')
+//                    ->where([
+//                        'ai.skuCode' => $skuCode,
+//                        'ai.spuCode' => $spuCode,
+//                        'ai.is_del' => 0,
+//                        'ai.status' => 1,
+//                        'ga.status' => 6,
+//                        'ga.is_del' => 0,
+//                        'ga.platform_code' => $platform_id,
+//                        'ga.is_stock' => $is_stock
+//                    ])
+//                    ->where(function ($query) {
+//                        return $query->where('ga.start', '<=', date('Y-m-d H:i:s'))->where('ga.end', '>=', date('Y-m-d H:i:s'));
+//                    })
+//                    ->find();
+                //如果是泰行销的单子,要取原始价格(即优惠前的价格)
+                $sale_price = $c_data['discount_price'];
 
+                $act = check_activity($spuCode, $skuCode, $platform_id, $is_stock, $sale_price, $good_num);
                 $is_activity = 0;
                 if (!empty($act)) {
                     $is_activity = 1;
-                    if ($act['moq_num'] > $good_num) throw new Exception('商品不满足活动价起订量' . $act['moq_num']);
-                    if ($act['activity_stock'] < $good_num) throw new Exception('商品活动库存剩余' . $act['activity_stock']);
+                    $sale_price = $act['final_price'];//取活动的相关价格
+//                    if ($act['moq_num'] > $good_num) throw new Exception('商品不满足活动价起订量' . $act['moq_num']);
+//                    if ($act['activity_stock'] < $good_num) throw new Exception('商品活动库存剩余' . $act['activity_stock']);
                 }
 
 //                $is_activity = (int)(!empty($act));
@@ -209,7 +214,7 @@ class handleYzOrderData extends Command
 //                }
 
 
-                $sale_price = $c_data['discount_price'];
+
 
 //                if ($goodtype == 1) {
 //                    $good = Db::name("good_ladder")

+ 40 - 0
app/common.php

@@ -1403,4 +1403,44 @@ if(function_exists("cgd_sale_return")){
 		->find()->isExists();
 		return $order;
 	}
+}
+
+//检查是否有符合条件的活动
+//@param $spuCode string 商品成本编号
+//@param $skuCode string 商品上线编号
+//@param $platform_id int 上线平台id
+//@param $is_stock int 是否库存品
+//@param $price float 售价
+//@param $good_num int 商品数量
+if (!function_exists('check_activity')) {
+    function check_activity(string $spuCode = '', string $skuCode = '', int $platform_id = 0, int $is_stock = 0, float $price = 0.00, int $good_num = 0)
+    {
+        $act = Db::name('activity_info')
+            ->alias('ai')
+            ->field('ai.id,ai.activity_stock,ai.moq_num,ai.activity_stock,ai.activity_price,ai.is_activity,ai.settle_price')
+            ->join('good_activity ga', 'ga.activity_code=ai.activity_code')
+            ->where([
+                'ai.spuCode' => $spuCode,
+                'ai.skuCode' => $skuCode,
+                'ai.is_del' => 0,
+                'ai.status' => 1,
+                'ga.status' => 6,
+                'ga.is_del' => 0,
+                'ga.platform_code' => $platform_id,
+                'ga.is_stock' => $is_stock
+            ])
+            ->where(function ($query) {
+                return $query->where('ga.start', '<=', date('Y-m-d H:i:s'))->where('ga.end', '>=', date('Y-m-d H:i:s'));
+            })
+            ->findOrEmpty();
+
+        if (empty($act)) return $act;//没有符合条件的活动
+        else {
+            if ($act['moq_num'] > $good_num) throw new \think\Exception('商品不满足活动价起订量' . $act['moq_num']);
+            if ($act['activity_stock'] < $good_num) throw new \think\Exception('商品活动库存剩余' . $act['activity_stock']);
+            if ($price < $act['activity_price']) throw new \think\Exception('售价低于活动价' . $act['activity_price']);
+
+            return $act['is_activity'] == 1 ? ['final_price' => $act['activity_price']] : ['final_price' => $act['settle_price']];
+        }
+    }
 }