From 6f7921636ef69c4a8e732397ec9e416dddf3dc46 Mon Sep 17 00:00:00 2001 From: lqmac Date: Fri, 5 Jul 2024 01:29:22 +0800 Subject: [PATCH] 1 --- app/admin/controller/Goods.php | 2 ++ app/admin/controller/Store.php | 18 +++++++++---- app/api/controller/Goods.php | 47 ++++++++++++++++++++++++++-------- app/common.php | 3 ++- app/common/model/PriceSet.php | 6 +++-- app/common/service/Jd.php | 3 ++- config/module.php | 1 + 7 files changed, 60 insertions(+), 20 deletions(-) diff --git a/app/admin/controller/Goods.php b/app/admin/controller/Goods.php index 57c2b046..310cbda3 100644 --- a/app/admin/controller/Goods.php +++ b/app/admin/controller/Goods.php @@ -174,6 +174,8 @@ class Goods extends Controller 'goods_source' => $goods_sku->goods_source, 'is_check' => $goods_sku->is_check, 'delivery_time' => $goods_sku->delivery_time, + 'is_use_jd_stock' => $goods_sku->is_use_jd_stock, + 'is_jd_remove' => $goods_sku->is_jd_remove, // 'is_pool' => $goods_sku->is_pool, // 'is_sale' => $goods_sku->is_sale, 'update_time' => time(), diff --git a/app/admin/controller/Store.php b/app/admin/controller/Store.php index 4801d48c..d0285f5f 100644 --- a/app/admin/controller/Store.php +++ b/app/admin/controller/Store.php @@ -374,7 +374,7 @@ class Store extends Controller */ public function deleteGoods(int $storeId): Json { - ini_set('memory_limit', '2024M'); + ini_set('memory_limit', '1024M'); set_time_limit(0); $model = StoreModel::detail($storeId); if (!$model || $storeId <= 0) { @@ -389,9 +389,16 @@ class Store extends Controller // GoodsModel::where('store_id', $storeId)->delete(); $page = 1; while (TRUE) { - $goods_list = GoodsModel::where('store_id', $storeId)->where('channel','<>', 'zy')->field('goods_id')->page($page)->limit(2000)->select(); + //echo $page.PHP_EOL; + $goods_list = GoodsModel::where('store_id', $storeId) + ->where('channel','<>', 'zy') + ->field('goods_id') + ->order("goods_id desc") + ->page($page) + ->limit(2000) + ->select(); if ($goods_list->isEmpty()) { - return $this->renderSuccess(); + break; } $goods_ids = array_column($goods_list->toArray(), "goods_id"); //删除商品sku @@ -400,10 +407,11 @@ class Store extends Controller GoodsImage::whereIn('goods_id', $goods_ids)->delete(); //删除商品规格 GoodsSpecRel::whereIn('goods_id', $goods_ids)->delete(); - //删除商品 - GoodsModel::whereIn('goods_id', $goods_ids)->delete(); + $page++; } + //删除商品 + GoodsModel::where('store_id', $storeId)->where('channel','<>', 'zy')->delete(); return $this->renderSuccess(); } diff --git a/app/api/controller/Goods.php b/app/api/controller/Goods.php index 648c2ea0..0dcf213f 100644 --- a/app/api/controller/Goods.php +++ b/app/api/controller/Goods.php @@ -124,9 +124,7 @@ class Goods extends Controller case 'jd': case 'jd1': case 'jd2': - case 'zy': $province = Region::withoutGlobalScope()->where('name', $params['province'])->where('level', 1)->find(); - //$city = Region::withoutGlobalScope()->where('name', $params['city'])->where('level', 2)->find(); $district = Region::withoutGlobalScope()->where('name', $params['district'])->where('level', 3)->find(); $jd = new \app\common\service\Jd(); $arr = []; @@ -152,16 +150,43 @@ class Goods extends Controller ]; break; default: - - if ($goods->stock_total >= ($value['num'] ?? 1)) { - $res = "有货"; + if ($goods->is_use_jd_stock) {//是否使用京东库存 + $province = Region::withoutGlobalScope()->where('name', $params['province'])->where('level', 1)->find(); + $district = Region::withoutGlobalScope()->where('name', $params['district'])->where('level', 3)->find(); + $jd = new \app\common\service\Jd(); + $arr = []; + + $ret = $jd->getGoodsStock($province->jd_code, $city->jd_code, $district->jd_code, $goods['goods_no'], $value['num'] ?? 1); + // echo "
";
+                        // print_r($ret);
+                        //var_dump($ret);
+                        if ($ret) {
+                            $res = $ret['stockResp']['desc'] ?? "无货";
+                            if (strpos($res, "无货") !== false) {
+                                $res = "无货";
+                            } elseif (strpos($res, "有货") == false) {
+                                $res = "有货";
+                            }
+                        }
+                        $data = [
+                            'state' => $res,
+                            'goods_name' => $goods['goods_name'],
+                            'goods_id' => $goods['goods_id'],
+                            //'promise_info' => $ret['promiseInfo'] ?? "预计72小时内发货",
+                            'promise_info' => "预计48小时内发货",
+                        ];
+                    } else {
+                        if ($goods->stock_total >= ($value['num'] ?? 1)) {
+                            $res = "有货";
+                        }
+                        $data = [
+                            'state' => $res,
+                            'goods_name' => $goods['goods_name'],
+                            'goods_id' => $goods['goods_id'],
+                            'promise_info' => "预计".(GoodsDeliveryTime::data()[$goods['delivery_time']]['name'] ?? "72小时")."内发货",
+                        ];
                     }
-                    $data = [
-                        'state' => $res,
-                        'goods_name' => $goods['goods_name'],
-                        'goods_id' => $goods['goods_id'],
-                        'promise_info' => "预计".(GoodsDeliveryTime::data()[$goods['delivery_time']]['name'] ?? "72小时")."内发货",
-                    ];
+                    
 
                     break;
             }
diff --git a/app/common.php b/app/common.php
index 9020079b..d5b786ea 100644
--- a/app/common.php
+++ b/app/common.php
@@ -621,7 +621,8 @@ function getGoodsCostAndProfitAndProfitRate($net_price, $cost_price, $rate){
  */
 function getJdGoodsBySku($skus){
     $sku = implode(",", $skus);
-    $url = "http://47.98.251.206:8811/api/skus/info?skus=".$sku;
+    //$url = "http://47.98.251.206:8811/api/skus/info?skus=".$sku;
+    $url = "http://8.130.98.31:8811/api/skus/info?skus=".$sku;
     $data = httpRequest($url, "GET", null, [], false, 30);
     
     if ($data['code'] != 0 || !$data['data']) {
diff --git a/app/common/model/PriceSet.php b/app/common/model/PriceSet.php
index 75d9fc2a..b8ec05a6 100644
--- a/app/common/model/PriceSet.php
+++ b/app/common/model/PriceSet.php
@@ -43,7 +43,8 @@ class PriceSet extends BaseModel
             //return sprintf("%.2f", $market_price);
             return round($market_price);
         }
-        $membershipPrice = $cost_price * (1 + $addPriceRate * 0.01);
+        //$membershipPrice = $cost_price * (1 + $addPriceRate * 0.01);
+        $membershipPrice = $cost_price / (1 - $addPriceRate * 0.01);
         //当加价率生效后,会员价高于市场价
         if ($membershipPrice > $market_price) {
             $membershipPrice = ($market_price - $cost_price) * $addPriceRate * 0.01 + $cost_price;
@@ -74,7 +75,8 @@ class PriceSet extends BaseModel
             $arr['distributionPrice'] = round($market_price);
             return $arr;
         }
-        $distributionPrice = $cost_price * (1 + $addPriceRate * 0.01);
+        //$distributionPrice = $cost_price * (1 + $addPriceRate * 0.01);
+        $distributionPrice = $cost_price / (1 - $addPriceRate * 0.01);
         $price = $distributionPrice;
         //当加价率生效后,分销价高于市场价
         if ($distributionPrice > $market_price) {
diff --git a/app/common/service/Jd.php b/app/common/service/Jd.php
index 44c2e0ee..46bc9a8b 100644
--- a/app/common/service/Jd.php
+++ b/app/common/service/Jd.php
@@ -65,7 +65,8 @@ class Jd extends BaseService {
      * @return [type]        [description]
      */
     public function getGoodsMainImageAndDetail($skuId){
-        $url = "http://47.98.251.206:8811/api/goods/info/v2?sku=".$skuId."&areaId=";
+        //$url = "http://47.98.251.206:8811/api/goods/info/v2?sku=".$skuId."&areaId=";
+        $url = "http://8.130.98.31:8811/api/goods/info/v2?sku=".$skuId."&areaId=";
         $res = httpRequest($url);
         if ($res && $res['code'] == 0 && isset($res['data'])) {
             return $res['data'];
diff --git a/config/module.php b/config/module.php
index 17abbe46..bcbf457e 100755
--- a/config/module.php
+++ b/config/module.php
@@ -32,6 +32,7 @@ return [
         'children' => [
             'merchant' => ['name' => '商户管理', 'enable' => true],
             'merchant-manage' => ['name' => '商户列表', 'enable' => true],
+            'merchant-cate' => ['name' => '商户分类', 'enable' => true],
         ]
     ],
     'goods' => [