diff --git a/app/admin/controller/Goods.php b/app/admin/controller/Goods.php index 3f667e33..2e549818 100644 --- a/app/admin/controller/Goods.php +++ b/app/admin/controller/Goods.php @@ -359,6 +359,7 @@ class Goods extends Controller ['is_check'=>'是否审单(是填1 否填0)'], ['is_use_jd_stock'=>'是否使用京东库存(是填1 否填0)'], ['video_id'=>'是否覆盖商品(是填1 否填0)'], + ['video_id'=>'商品分类ID集'], ]; downLoadExcel('导出数据-'.date('Y-m-d', time()),$titles,$data['data']); diff --git a/app/api/controller/Goods.php b/app/api/controller/Goods.php index 1b2cf4a2..29963878 100644 --- a/app/api/controller/Goods.php +++ b/app/api/controller/Goods.php @@ -40,6 +40,7 @@ class Goods extends Controller $param = $this->request->param(); //限制过滤条件-渠道 $param['channels'] = $this->storeInfo['open_channel'] ? array_merge(['zy'], explode(",", $this->storeInfo['open_channel'])) : []; + $param['p_store_id'] = $this->storeInfo->p_store_id; //分类利润-利润率 $param['fliter_condition'] = $this->storeInfo['fliter_condition']; if (isset($param['keyword']) && $param['keyword']) { diff --git a/app/api/controller/GoodsNew.php b/app/api/controller/GoodsNew.php index 4b1414a3..be14951f 100644 --- a/app/api/controller/GoodsNew.php +++ b/app/api/controller/GoodsNew.php @@ -25,7 +25,7 @@ class GoodsNew extends Controller $param['channels'] = $this->storeInfo['open_channel'] ? array_merge(['zy'], explode(",", $this->storeInfo['open_channel'])) : []; $param['fliter_condition'] = $this->storeInfo['fliter_condition']; $param['status'] = 10; - $param['store_id'] = $this->storeId; + $param['store_id'] = 10038;//$this->storeId; $goodsService = new GoodsCateEs(); $data = $goodsService->list($param, $page, $pageSize); diff --git a/app/api/model/Goods.php b/app/api/model/Goods.php index d13ef327..11f746a0 100644 --- a/app/api/model/Goods.php +++ b/app/api/model/Goods.php @@ -715,21 +715,21 @@ class Goods extends GoodsModel $catService = new GoodsCategoryRel(); $catIds = $catService->where(['goods_id' => $goods->goods_id])->column('category_id'); $goods['line_price_min'] = $goods['goods_price_min'];//划线价格等于市场价 - //$goods['discount'] = 0.0; + $goods['discount'] = 0.0; //价格判断 if (UserService::isstore()) { $priceArr = \app\common\model\PriceSet::distributionPrice($goods['goods_price_min'], $goods['cost_price_min'], $catIds); $goods['goods_price_min_plus'] = $priceArr['membershipPrice']; $goods['goods_price_min_dealer'] = $priceArr['distributionPrice']; $goods['goods_price_min'] = $goods['goods_price_min_plus'];//$goods['cost_price_min'];//店长售价,展示为成本价 - + $goods['discount'] = bcdiv((string)($priceArr['distributionPrice'] * 10), (string)$goods['goods_price_min'], 1); } elseif (UserService::isPlusMember()) { $membershipPrice = \app\common\model\PriceSet::membershipPrice($goods['goods_price_min'], $goods['cost_price_min'], $catIds); - //$goods['discount'] = bcdiv((string)($membershipPrice * 10), (string)$goods['goods_price_min'], 1); + $goods['discount'] = bcdiv((string)($membershipPrice * 10), (string)$goods['goods_price_min'], 1); $goods['goods_price_min'] = $membershipPrice; } elseif (UserService::isDealerMember()) { $priceArr = \app\common\model\PriceSet::distributionPrice($goods['goods_price_min'], $goods['cost_price_min'], $catIds); - //$goods['discount'] = bcdiv((string)($priceArr['distributionPrice'] * 10), (string)$goods['goods_price_min'], 1); + $goods['discount'] = bcdiv((string)($priceArr['distributionPrice'] * 10), (string)$goods['goods_price_min'], 1); //$goods['goods_price_min'] = $membershipPrice; $goods['goods_price_min'] = $priceArr['distributionPrice']; } @@ -738,9 +738,9 @@ class Goods extends GoodsModel $goods['goods_price_min'] = $goods['seckill_price']; } - // if ($goods['discount'] == 10) { - // $goods['discount'] = 0.0; - // } + if ($goods['discount'] == 10) { + $goods['discount'] = 0.0; + } // 会员折扣价: 商品sku列表 if ($goods->getRelation('skuList') || $goods->getRelation('skuList1')) { diff --git a/app/api/service/Cart.php b/app/api/service/Cart.php index fb9fa190..a3630708 100644 --- a/app/api/service/Cart.php +++ b/app/api/service/Cart.php @@ -50,17 +50,18 @@ class Cart extends BaseService foreach ($cartList as $cartIdx => $item) { // 查找商品, 商品不存在则删除该购物车记录 $result = $this->findGoods($goodsList, $item, $enableGradeMoney); - //商户信息处理 - if ($result['merchant_id'] && !in_array($result['channel'], config('app.not_show_merchant'))) { - $merchant = \app\common\model\Merchant::detail($result['merchant_id'], $result['store_id']); - $result['merchant'] = $merchant; - } else { - $result['merchant_id'] = 0; - $result['merchant'] = null; - } - + if ($result !== false) { $cartList[$cartIdx]['goods'] = $result; + //商户信息处理 + if ($result['merchant_id'] && !in_array($result['channel'], config('app.not_show_merchant'))) { + $merchant = \app\common\model\Merchant::detail($result['merchant_id'], $result['store_id']); + $result['merchant'] = $merchant; + } else { + $result['merchant_id'] = 0; + $result['merchant'] = null; + } + } else { $this->clear([$item['id']]); unset($cartList[$cartIdx]); diff --git a/app/common/model/Goods.php b/app/common/model/Goods.php index b5000273..2b77209a 100644 --- a/app/common/model/Goods.php +++ b/app/common/model/Goods.php @@ -279,7 +279,10 @@ class Goods extends BaseModel */ public function getList(array $param = [], int $listRows = 15) { - + $storeId = self::$storeId; + //去掉where条件store_id + self::$storeId = 0; + app()->request->setStoreId(0); // 筛选条件 $query = $this->getQueryFilter($param); // 设置显示的销量 goods_sales @@ -319,6 +322,10 @@ class Goods extends BaseModel $query = $query->whereRaw('goods_name like ? or goods_no like ?', ["%{$val}%", "%{$val}%"]); } } + $storeIds = [$storeId]; + if (isset($param['p_store_id']) && $param['p_store_id']) { + $storeIds[] = $param['p_store_id']; + } //数据渠道过滤特殊处理 if (isset($param['fliter_condition']) && $param['fliter_condition']) { $fliter_condition = json_decode($param['fliter_condition'], true); @@ -340,6 +347,7 @@ class Goods extends BaseModel $list = $query->with(['images.file']) ->alias($this->name) ->field($field) + ->whereIn('goods.store_id', $storeIds) ->where('is_delete', '=', 0) ->where($str) ->group("goods.goods_id") @@ -350,6 +358,7 @@ class Goods extends BaseModel $list = $query->with(['images.file']) ->alias($this->name) ->field($field) + ->whereIn('goods.store_id', $storeIds) ->where('is_delete', '=', 0) ->group("goods.goods_id") ->order($sort) @@ -361,6 +370,7 @@ class Goods extends BaseModel $list = $query->with(['images.file']) ->alias($this->name) ->field($field) + ->whereIn('goods.store_id', $storeIds) ->where('is_delete', '=', 0) ->group("goods.goods_id") ->order($sort) @@ -475,7 +485,11 @@ class Goods extends BaseModel $filter[] = ['goods.goods_id', 'in', explode(",", $param['goodsIds'])]; } // 商品名称 - !empty($params['goodsName']) && $filter[] = ['goods_name', 'like', "%{$params['goodsName']}%"]; + if (!empty($params['goodsName'])) { + $goods_name = str_replace(" ", "", $params['goodsName']); + $query->where("REPLACE(`goods_name`, ' ', '') LIKE '%". $goods_name . "%'"); + //$filter[] = ["REPLACE(`goods_name`, ' ', '')", 'like', "%{$goods_name}%"]; + } // 商品编码 !empty($params['goodsNo']) && $filter[] = ['goods_no', 'like', "%{$params['goodsNo']}%"]; diff --git a/app/common/service/GoodsCateEs.php b/app/common/service/GoodsCateEs.php index f6d66c32..95938b6e 100644 --- a/app/common/service/GoodsCateEs.php +++ b/app/common/service/GoodsCateEs.php @@ -42,10 +42,14 @@ class GoodsCateEs $equal[] = ['is_delete' => 0]; //等于查询 if (isset($params['status']) && $params['status']) { - $equal[] = ['status' => $params['status'] ?? 0]; + $equal[] = ['status' => $params['status']]; } if (isset($params['store_id']) && $params['store_id']) { - $equal[] = ['store_id' => $params['store_id'] ?? 0]; + $storeIds = [$params['store_id']]; + if (isset($params['p_store_id']) && $params['p_store_id']) { + $storeIds[] = $params['p_store_id']; + } + $ins[] = ['store_id' => $storeIds]; } if (isset($params['merchantId']) && $params['merchantId']) { $equal[] = ['merchant_id' => $params['merchantId'] ?? 0]; diff --git a/app/job/controller/goods/StoreGoodsDelete.php b/app/job/controller/goods/StoreGoodsDelete.php new file mode 100644 index 00000000..e24b9eaa --- /dev/null +++ b/app/job/controller/goods/StoreGoodsDelete.php @@ -0,0 +1,41 @@ +batch($data['list']); + } +} \ No newline at end of file diff --git a/app/job/controller/goods/StoreGoodsOffline.php b/app/job/controller/goods/StoreGoodsOffline.php new file mode 100644 index 00000000..655e88d0 --- /dev/null +++ b/app/job/controller/goods/StoreGoodsOffline.php @@ -0,0 +1,40 @@ +batch($data['list']); + } +} \ No newline at end of file diff --git a/app/job/controller/goods/StoreGoodsOnline.php b/app/job/controller/goods/StoreGoodsOnline.php new file mode 100644 index 00000000..19af7ef0 --- /dev/null +++ b/app/job/controller/goods/StoreGoodsOnline.php @@ -0,0 +1,40 @@ +batch($data['list']); + } +} \ No newline at end of file diff --git a/app/job/service/goods/Collector.php b/app/job/service/goods/Collector.php index 0a270501..2ac958b6 100644 --- a/app/job/service/goods/Collector.php +++ b/app/job/service/goods/Collector.php @@ -14,7 +14,7 @@ use app\store\model\GoodsImage as GoodsImageModel1; use app\common\model\store\Setting as SettingModel; use app\common\model\GoodsSpecRel as GoodsSpecRelModel; use app\common\model\goods\Collector as GoodsCollectorModel; -use app\common\model\GoodsCategoryRel as GoodsCategoryRelModel; +use app\store\model\GoodsCategoryRel as GoodsCategoryRelModel; use app\common\enum\Setting as SettingEnum; use app\common\enum\file\FileType as FileTypeEnum; use app\common\enum\goods\SpecType as GoodsSpecTypeEnum; @@ -253,7 +253,7 @@ class Collector extends BaseService $model->transaction(function () use ($model, $data, $storeId) { // 添加商品 $model->save($data); - $model->where('goods_id', (int)$model['goods_id'])->update(['spu_id' => (int)$model['goods_id']]); + //$model->where('goods_id', (int)$model['goods_id'])->update(['spu_id' => (int)$model['goods_id']]); // 新增商品与分类关联 GoodsCategoryRelModel::increased((int)$model['goods_id'], $data['categoryIds'], $storeId); // 新增商品与图片关联 @@ -326,8 +326,12 @@ class Collector extends BaseService // exit; tre($e->getTraceAsString()); $errorLog = ['goodsSn' => $form['goods_id'], 'message' => trim($url).$e->getMessage()]; - return [true, $errorLog]; + return [false, $errorLog]; + } catch (\Exception $e){ + $errorLog = ['goodsSn' => $form['goods_id'], 'message' => trim($url).$e->getMessage()]; + return [false, $errorLog]; } + // if ($original['goods_price'] == 0) { // return false; // } @@ -337,6 +341,12 @@ class Collector extends BaseService $data['content'] = $original['content']; + if ($original['content']) { + $data['is_has_detail'] = 1; + } + if ($original['imagesIds']) { + $data['is_has_banner'] = 1; + } //重新计算利润和利润率 $data['goods_source'] = $form['goods_source']; @@ -344,6 +354,8 @@ class Collector extends BaseService $data['delivery_time'] = $form['delivery_time']; $data['is_check'] = $form['is_check']; $data['is_use_jd_stock'] = $form['is_use_jd_stock']; + $data['categoryIds'] = $form['categoryIds']; + $data['cate_status'] = $form['categoryIds'] ? 1 : 0; $data['goods_price_min'] = $original['goods_price']; $data['goods_price_max'] = $original['goods_price']; $data['line_price_min'] = $original['goods_price']; @@ -388,11 +400,16 @@ class Collector extends BaseService // var_dump($data); // var_dump($goodsSku); // exit(); - $model->transaction(function () use ($form, $data, $original, $goodsSku) { + $model->transaction(function () use ($goods, $form, $data, $original, $goodsSku) { $data['update_time'] = time(); $data['import_time'] = time(); + //$data['goods_id'] = $form['goods_id']; // 添加商品 - GoodsModel::where('goods_id', $form['goods_id'])->update($data); + $goods->save($data); + //GoodsModel::where('goods_id', $form['goods_id'])->update($data); + + // 新增商品与分类关联 + GoodsCategoryRelModel::updates((int)$form['goods_id'], $data['categoryIds']); // 新增商品与图片关联 GoodsImageModel1::updates((int)$form['goods_id'], $original['imagesIds']); //更新sku信息 @@ -568,6 +585,7 @@ class Collector extends BaseService 'status' => $form['goods_status'], 'imagesIds' => $original['imagesIds'], 'categoryIds' => $form['categoryIds'], + 'cate_status' => $form['categoryIds'] ? 1 : 0, // 下面是默认数据, 没有会报错 'alone_grade_equity' => [], 'newSpecList' => [], diff --git a/app/job/service/goods/GoodsOfflineStore.php b/app/job/service/goods/GoodsOfflineStore.php new file mode 100644 index 00000000..8040c556 --- /dev/null +++ b/app/job/service/goods/GoodsOfflineStore.php @@ -0,0 +1,54 @@ +where('is_delete',0) + ->where(function($query){ + $query->where('is_pool',2)->whereOr('is_sale',0); + }) + ->field(['goods_id','is_sale','is_pool']) + ->select(); + if ($goods_list->isEmpty()) { + return true; + } + $goodsIds = array_column($goods_list->toArray(), "goods_id"); + //GoodsModel::whereIn('origin_goods_id', $goodsIds)->update(['status' => 20, 'is_jd_remove' => 1, 'update_time' => time()]); + GoodsModel::whereIn('origin_goods_id', $goodsIds)->update(['is_delete' => 1, 'update_time' => time()]); + + //下架批发商城的商品 + return true; + } + + +} \ No newline at end of file diff --git a/app/job/service/goods/GoodsUpdateImport.php b/app/job/service/goods/GoodsUpdateImport.php index 98f2a2c0..fdf869ef 100644 --- a/app/job/service/goods/GoodsUpdateImport.php +++ b/app/job/service/goods/GoodsUpdateImport.php @@ -134,8 +134,15 @@ class GoodsUpdateImport extends BaseService 'is_check' => $original['L'] ?? 0, 'is_use_jd_stock' => $original['M'] ?? 0, 'is_cover' => $original['N'] ?? 0,//是否覆盖 + 'categoryIds' => $this->ids2array($original["O"]), ]; + + $data['categoryIds'] = CategoryModel::filterCategoryIds($data['categoryIds'], $storeId); + + //处理分类,设置最后一级一直往上查找 + $model = new \app\store\model\Goods(); + $data['categoryIds'] = $model->dealCategory($data['categoryIds']); return $data; } diff --git a/app/job/service/goods/StoreGoodsDelete.php b/app/job/service/goods/StoreGoodsDelete.php new file mode 100644 index 00000000..a659352a --- /dev/null +++ b/app/job/service/goods/StoreGoodsDelete.php @@ -0,0 +1,50 @@ +where('is_delete',1) + ->field(['goods_id','is_sale','is_pool']) + ->select(); + if ($goods_list->isEmpty()) { + return true; + } + $goodsIds = array_column($goods_list->toArray(), "goods_id"); + GoodsModel::whereIn('origin_goods_id', $goodsIds)->update(['is_delete' => 1, 'update_time' => time()]); + + //删除批发商城的商品 + return true; + } + + +} \ No newline at end of file diff --git a/app/job/service/goods/StoreGoodsOnline.php b/app/job/service/goods/StoreGoodsOnline.php new file mode 100644 index 00000000..0829f403 --- /dev/null +++ b/app/job/service/goods/StoreGoodsOnline.php @@ -0,0 +1,52 @@ +where('is_delete',0) + ->where('is_sale',1) + ->where('is_pool',1) + ->field(['goods_id','is_sale','is_pool']) + ->select(); + if ($goods_list->isEmpty()) { + return true; + } + $goodsIds = array_column($goods_list->toArray(), "goods_id"); + GoodsModel::whereIn('origin_goods_id', $goodsIds)->update(['status' => 10, 'is_jd_remove' => 0, 'update_time' => time(), 'is_delete' => 0]); + + //上架批发商城的商品 + return true; + } + + +} \ No newline at end of file diff --git a/app/store/controller/Controller.php b/app/store/controller/Controller.php index 01014260..b50d0573 100644 --- a/app/store/controller/Controller.php +++ b/app/store/controller/Controller.php @@ -33,7 +33,7 @@ class Controller extends BaseController // 当前商城ID protected int $storeId; - // protected $storeInfo; + protected $storeInfo; // 当前商户ID protected int $merchantId = 0; @@ -88,7 +88,7 @@ class Controller extends BaseController $this->getMerchantId(); // 验证当前商城状态 - // $this->checkStore(); + $this->checkStore(); } /** @@ -194,26 +194,29 @@ class Controller extends BaseController throwError('illegal request method'); } - // /** - // * 验证当前商城状态 - // * @return void - // * @throws BaseException - // */ - // private function checkStore(): void - // { - // // 获取当前商城信息 - // $store = StoreModel::detail($this->storeId); - // if (empty($store)) { - // throwError('很抱歉,当前商城信息不存在'); - // } - // if ($store['is_recycle'] || $store['is_delete']) { - // throwError('很抱歉,当前商城已删除'); - // } - // if($store['effective_time']storeInfo = $store; - // } + /** + * 验证当前商城状态 + * @return void + * @throws BaseException + */ + private function checkStore(): void + { + if (!$this->storeId) { + return; + } + // 获取当前商城信息 + $store = StoreModel::detail($this->storeId); + if (empty($store)) { + throwError('很抱歉,当前商城信息不存在'); + } + if ($store['is_recycle'] || $store['is_delete']) { + throwError('很抱歉,当前商城已删除'); + } + if($store['effective_time']storeInfo = $store; + } } diff --git a/app/store/controller/Goods.php b/app/store/controller/Goods.php index 82400775..acb26bc1 100644 --- a/app/store/controller/Goods.php +++ b/app/store/controller/Goods.php @@ -40,6 +40,10 @@ class Goods extends Controller if (!isset($params['merchant_id']) || !$params['merchant_id']) { $params['merchant_id'] = $this->merchantId; } + $params['p_store_id'] = $this->storeInfo->p_store_id; + // echo "
";
+        // print_r($this->storeInfo->p_store_id);
+        // exit();
         $list = $model->getList($params, (int)$this->request->param('pageSize', 15));
         if ($list->isEmpty()) {
             return $this->renderSuccess(compact('list'));
diff --git a/app/store/model/Category.php b/app/store/model/Category.php
index f1f2fde6..11e4b695 100644
--- a/app/store/model/Category.php
+++ b/app/store/model/Category.php
@@ -44,17 +44,19 @@ class Category extends CategoryModel
      */
     public function edit($data): bool
     {
+        ini_set('memory_limit', '1024M');
+        set_time_limit(0);
         // 判断上级分类是否为当前子级
         if ($data['parent_id'] > 0) {
             // 获取所有上级id集
             $parentIds = $this->getTopCategoryIds($data['parent_id']);
+            
             if (in_array($this['category_id'], $parentIds)) {
                 $this->error = '上级分类不允许设置为当前子分类';
                 return false;
             }
             $cate = $this->where('category_id', $data['parent_id'])->find();
-            // var_dump($cate['level']);
-            // exit();
+            
             $data['level'] = $cate ? $cate['level'] + 1 : 1;
         }
 
diff --git a/app/store/model/Goods.php b/app/store/model/Goods.php
index 34464c93..834c9d13 100644
--- a/app/store/model/Goods.php
+++ b/app/store/model/Goods.php
@@ -155,7 +155,11 @@ class Goods extends GoodsModel
             if ($data['spec_type'] == GoodsSpecTypeEnum::MULTI) {
                 $data['spu_id'] = $this['goods_id'];
                 //取消之前所有的商品组商品
+            } else {
+                $data['spu_id'] = 0;
             }
+
+            
             // 更新商品
             $this->save($data);
             // 更新商品与分类关联
@@ -415,8 +419,21 @@ class Goods extends GoodsModel
         }
         if ($data['categoryIds']) {
             $data['cate_status'] = 1;
+        } else {
+            $data['cate_status'] = 0;
         }
-         
+        
+        if ($data['content']) {
+            $data['is_has_detail'] = 1;
+        } else {
+            $data['is_has_detail'] = 0;
+        }
+        if ($data['imagesIds']) {
+            $data['is_has_banner'] = 1;
+        } else {
+            $data['is_has_banner'] = 0;
+        }
+            
         return $data;
     }