diff --git a/app/admin/controller/Goods.php b/app/admin/controller/Goods.php index aa057294..e161e755 100644 --- a/app/admin/controller/Goods.php +++ b/app/admin/controller/Goods.php @@ -231,7 +231,7 @@ class Goods extends Controller $categoryIds = $model->dealCategory($categoryIds); \app\store\model\GoodsCategoryRel::updates($goodsId, $categoryIds); } - $model->whereIn('goods_id', $goodsIds)->update(['cate_status'=>1]); + $model->whereIn('goods_id', $goodsIds)->update(['cate_status'=>1,'update_time' => time()]); return $this->renderSuccess('操作成功'); } /** diff --git a/app/admin/controller/goods/Import.php b/app/admin/controller/goods/Import.php index 9437a517..ba31bc5a 100644 --- a/app/admin/controller/goods/Import.php +++ b/app/admin/controller/goods/Import.php @@ -35,7 +35,7 @@ class Import extends Controller $params['store_id'] = 0; $model = new ImportModel; $platform = $this->getUserPlatform(); - $params['channels'] = $platform ? array_column($platform->toArray(), "code") : []; + $params['channels'] = $this->admin['user']['role'] == 0 ? [] : ($platform ? array_column($platform->toArray(), "code") : []); $list = $model->getList($params); return $this->renderSuccess(compact('list')); } diff --git a/app/api/controller/Controller.php b/app/api/controller/Controller.php index 277a53b9..6a8965ee 100644 --- a/app/api/controller/Controller.php +++ b/app/api/controller/Controller.php @@ -32,6 +32,10 @@ class Controller extends BaseController // 当前商城ID protected int $storeId; + protected $storeInfo; + + protected $user; + // 当前商户ID protected int $merchantId = 0; @@ -50,7 +54,7 @@ class Controller extends BaseController $this->checkStore(); // 验证当前客户端状态 $this->checkClient(); - //$user = $this->getLoginUser(); + $this->user = $this->getLoginUser(false); // if ($user) { // if ($user->user_type == 0 || $user->status == 0) { // throwError('很抱歉,您没有权限进入系统'); @@ -95,6 +99,7 @@ class Controller extends BaseController if ($store['is_recycle'] || $store['is_delete']) { throwError('很抱歉,当前商城已删除'); } + $this->storeInfo = $store; } /** diff --git a/app/api/controller/Goods.php b/app/api/controller/Goods.php index de318ad0..c1fe2ced 100644 --- a/app/api/controller/Goods.php +++ b/app/api/controller/Goods.php @@ -24,6 +24,7 @@ use cores\exception\BaseException; use think\db\exception\DbException; use think\response\Json; use app\common\enum\goods\GoodsDeliveryTime; +use think\facade\Cache; /** * 商品控制器 * Class Goods @@ -38,9 +39,14 @@ class Goods extends Controller */ public function list(): Json { + // 获取列表数据 $model = new GoodsModel; $param = $this->request->param(); + //限制过滤条件-渠道 + $param['channels'] = $this->storeInfo['open_channel'] ? array_merge(['zy'], explode(",", $this->storeInfo['open_channel'])) : []; + //分类利润-利润率 + $param['fliter_condition'] = $this->storeInfo['fliter_condition']; $list = $model->getList($param); return $this->renderSuccess(compact('list')); } @@ -142,7 +148,7 @@ class Goods extends Controller ]; break; default: - if ($goods->stock_total > ($value['num'] ?? 1)) { + if ($goods->stock_total >= ($value['num'] ?? 1)) { $res = "有货"; } $data = [ @@ -288,13 +294,13 @@ class Goods extends Controller public function recommended(): Json { $service = new GoodsService; -// $cache_key = "goods_recommended".$this->storeId; -// if(Cache::has($cache_key)) { -// $goodsList = Cache::get($cache_key); -// return $this->renderSuccess(compact('goodsList')); -// } + $cache_key = "goods_recommended".$this->storeId.($this->user ? $this->user->user_type : 0); + if(Cache::has($cache_key)) { + $goodsList = Cache::get($cache_key); + return $this->renderSuccess(compact('goodsList')); + } $goodsList = $service->recommended(); -// Cache::set($cache_key, $goodsList, 60*60); + Cache::set($cache_key, $goodsList, 60*60); return $this->renderSuccess(compact('goodsList')); } @@ -405,7 +411,7 @@ class Goods extends Controller $wxConfig = WxappSettingModel::getConfigBasic($store_id); // 请求api获取短连接 $link_obj = new ShortLink($wxConfig['app_id'], $wxConfig['app_secret']); - $url = $link_obj->shortUrl($page_url, $page_title); + $url = $link_obj->shortUrl($page_url, ""); return $this->renderSuccess(['url' => $url]); } diff --git a/app/api/model/Goods.php b/app/api/model/Goods.php index 7094877f..d60de044 100644 --- a/app/api/model/Goods.php +++ b/app/api/model/Goods.php @@ -583,12 +583,25 @@ class Goods extends GoodsModel * @return \app\common\model\GoodsSku|array|null * @throws BaseException */ - public static function getSkuInfo($goodsInfo, string $goodsSkuId, bool $enableGradeMoney = true) + public static function getSkuInfo($goods, string $goodsSkuId, bool $enableGradeMoney = true) { - $goodsInfo['skuInfo'] = GoodsService::getSkuInfo($goodsInfo['goods_id'], $goodsSkuId); + $goods['skuInfo'] = GoodsService::getSkuInfo($goods['goods_id'], $goodsSkuId); //$enableGradeMoney && (new static)->setGoodsGradeMoney($goodsInfo); - (new static)->setGoodsMoney($goodsInfo); - return $goodsInfo['skuInfo']; + + $catService = new GoodsCategoryRel(); + $catIds = $catService->where(['goods_id' => $goods->goods_id])->column('category_id'); + if ($goods->getAttr('skuInfo')) { + if (UserService::isPlusMember()) { + $goods['skuInfo']['goods_price'] = \app\common\model\PriceSet::membershipPrice($goods['skuInfo']['goods_price'], $goods['skuInfo']['cost_price'], $catIds); + + } elseif (UserService::isDealerMember()) { + $priceArr = \app\common\model\PriceSet::distributionPrice($goods['skuInfo']['goods_price'], $goods['skuInfo']['cost_price'], $catIds); + $goods['skuInfo']['goods_price'] = $priceArr['distributionPrice']; + } + + } + //(new static)->setGoodsMoney($goodsInfo); + return $goods['skuInfo']; } /** diff --git a/app/api/model/Order.php b/app/api/model/Order.php index a6f6c54c..2eb0b14e 100644 --- a/app/api/model/Order.php +++ b/app/api/model/Order.php @@ -80,9 +80,13 @@ class Order extends OrderModel // 获取商品列表 $model = new GoodsModel; $goodsList = $model->setEnableGradeMoney(false)->getListByIdsFromApi([$goodsId]); + if ($goodsList->isEmpty()) { throwError('未找到商品信息'); } + // echo "
";
+        // print_r($goodsList->toArray());
+        // exit();
         // 隐藏冗余的属性
         $goodsList->hidden(GoodsModel::getHidden(['content', 'goods_images', 'images']));
         foreach ($goodsList as &$item) {
@@ -92,7 +96,7 @@ class Order extends OrderModel
             $item['goods_image'] = $item['skuInfo']['goods_image'] ?: $item['goods_image'];
 
             // 商品单价
-            $item['goods_price'] = \app\api\service\Goods::getGoodsPrice($item['goods_id'], $item['skuInfo']['goods_price'], $item['skuInfo']['cost_price']);
+            $item['goods_price'] = $item['skuInfo']['goods_price'];//\app\api\service\Goods::getGoodsPrice($item['goods_id'], $item['skuInfo']['goods_price'], $item['skuInfo']['cost_price']);
             // 商品购买数量
             $item['total_num'] = $goodsNum;
             // 商品SKU索引
@@ -100,6 +104,9 @@ class Order extends OrderModel
             // 商品购买总金额
             $item['total_price'] = helper::bcmul($item['goods_price'], $goodsNum);
         }
+        // echo "
";
+        // print_r($goodsList->toArray());
+        // exit();
         return $goodsList;
     }
 
diff --git a/app/api/model/dealer/Order.php b/app/api/model/dealer/Order.php
index 43ebd092..2f0d1a92 100644
--- a/app/api/model/dealer/Order.php
+++ b/app/api/model/dealer/Order.php
@@ -12,17 +12,17 @@ declare (strict_types=1);
 
 namespace app\api\model\dealer;
 
+use app\api\model\Order as OrderApiModel;
+use app\api\model\User as UserApiModel;
 use app\api\service\User as UserService;
 use app\common\enum\dealer\DealerUserEnum;
+use app\common\enum\order\PayStatus as PayStatusEnum;
 use app\common\enum\ServerEnum;
-use app\common\model\Order as OrderModel;
+use app\common\enum\user\UserTypeEnum;
 use app\common\model\dealer\Order as DealerOrderModel;
-use app\api\model\Order as OrderApiModel;
-use app\common\enum\order\PayStatus as PayStatusEnum;
+use app\common\model\Order as OrderModel;
 use app\common\model\UserAddress as UserAddessModel;
 use cores\exception\BaseException;
-use app\api\model\User as UserApiModel;
-use app\common\enum\user\UserTypeEnum;
 
 
 /**
@@ -64,11 +64,11 @@ class Order extends DealerOrderModel
             ->paginate(15);
         // 数据整理
         foreach ($list as &$item) {
-            $with = ['goods' => ['image'],'user','address'];
+            $with = ['goods' => ['image'], 'user', 'address'];
             $where = ['order_id' => $item['order_id']];
             // 查询订单记录
             $order_goods = OrderApiModel::detail($where, $with);
-            $address = UserAddessModel::where('address_id',$item['user']->address_id)->find();
+            $address = UserAddessModel::where('address_id', $item['user']->address_id)->find();
             // 我的佣金
             $money = [
                 $item['first_user_id'] => $item['first_money'],
@@ -76,7 +76,7 @@ class Order extends DealerOrderModel
                 $item['third_user_id'] => $item['third_money'],
             ];
             $item['goods'] = $order_goods['goods'] ?? [];
-            $item['address_name'] =$address['name'];
+            $item['address_name'] = $address['name'];
             $item['order_no'] = $item['order']['order_no'] ?? "";
             $item['my_money'] = $money[$userId];
         }
@@ -126,11 +126,13 @@ class Order extends DealerOrderModel
             return false;
         }
         //如果上级已经不是分销商
-        if(!User::isDealerUser($dealerUser['first_user_id'])){
+        if (!User::isDealerUser($dealerUser['first_user_id'])) {
             return false;
         }
         //如果上级已经不是分销商
-        if(!UserApiModel::where('user_id',$dealerUser['first_user_id'])->value('user_type') !== UserTypeEnum::DEALER){
+        $userModel = new UserApiModel;
+        $user_type = $userModel->where('user_id', $dealerUser['first_user_id'])->value('user_type');
+        if ($user_type && $user_type != UserTypeEnum::DEALER) {
             return false;
         }
         // 计算订单分销佣金
diff --git a/app/api/service/Cart.php b/app/api/service/Cart.php
index 89770cbc..2f8475f2 100644
--- a/app/api/service/Cart.php
+++ b/app/api/service/Cart.php
@@ -80,7 +80,7 @@ class Cart extends BaseService
             // 商品记录
             $goods = $item['goods'];
             // 商品单价
-            $goods['goods_price'] = \app\api\service\Goods::getGoodsPrice($item['goods_id'], $goods['skuInfo']['goods_price'], $goods['skuInfo']['cost_price']);
+            $goods['goods_price'] = $goods['skuInfo']['goods_price'];//\app\api\service\Goods::getGoodsPrice($item['goods_id'], $goods['skuInfo']['goods_price'], $goods['skuInfo']['cost_price']);
             //$goods['goods_price'] = $goods['skuInfo']['goods_price'];
             // 商品购买数量
             $goods['total_num'] = $item['goods_num'];
diff --git a/app/common/model/Goods.php b/app/common/model/Goods.php
index 885a6835..64873222 100644
--- a/app/common/model/Goods.php
+++ b/app/common/model/Goods.php
@@ -329,13 +329,36 @@ class Goods extends BaseModel
                 $query = $query->whereRaw('goods_name like ? or goods_no like ?', ["%{$val}%", "%{$val}%"]);
             }
         }
-        // 执行查询
-        $list = $query->with(['images.file'])
-            ->alias($this->name)
-            ->field($field)
-            ->where('is_delete', '=', 0)
-            ->order($sort)
-            ->paginate($listRows);
+        if (isset($param['fliter_condition']) && $param['fliter_condition']) {
+            $fliter_condition = json_decode($param['fliter_condition'], true);
+            
+            $str = "";
+            foreach ($fliter_condition as $value) {
+                $strConditon = "(";
+                $strConditon .= "goods_category_rel.category_id in (".implode(",", $value['category']).")";
+                $strConditon .= " and goods.profit >= ".$value['profit'];
+                $strConditon .= " and goods.profit_rate >= ".$value['profit_rate'] . ") or ";
+                $str .= $strConditon;
+            }
+            $str = trim($str, "or ");
+            // 执行查询
+            $list = $query->with(['images.file'])
+                ->alias($this->name)
+                ->field($field)
+                ->where('is_delete', '=', 0)
+                ->where($str)
+                ->order($sort)
+                ->paginate($listRows);
+        } else {
+            // 执行查询
+            $list = $query->with(['images.file'])
+                ->alias($this->name)
+                ->field($field)
+                ->where('is_delete', '=', 0)
+                ->order($sort)
+                ->paginate($listRows);
+        }
+          
 
         // 整理列表数据并返回
         return $this->setGoodsListData($list);
@@ -532,6 +555,7 @@ class Goods extends BaseModel
         if (isset($param['is_has_detail']) && $param['is_has_detail'] !== '') {
             $filter[] = ['goods.is_has_detail', '=', $params['is_has_detail']];
         }
+
         // 实例化新查询对象
         return $query->where($filter);
     }
@@ -566,7 +590,7 @@ class Goods extends BaseModel
     protected function setGoodsData($goodsInfo, callable $callback = null)
     {
         $channel = Channel::withoutGlobalScope()->where('code', $goodsInfo['channel'])->find();
-        $goodsInfo['channel_name'] = $channel['name'] ?? "";
+        $goodsInfo['channel_name'] = $channel['alias'] ?? "";
 
         $goodsInfo['goods_images'] = helper::getArrayColumn($goodsInfo['images'], 'file');
         // 商品主图
diff --git a/app/job/service/goods/AdminImport.php b/app/job/service/goods/AdminImport.php
index a4c769bc..784cda48 100644
--- a/app/job/service/goods/AdminImport.php
+++ b/app/job/service/goods/AdminImport.php
@@ -110,7 +110,10 @@ class AdminImport extends BaseService
                 continue;
             }
         	$data = $this->createData($item, $storeId);
-        	$service->single($item['D'], $data, $storeId);
+        	$ret = $service->single($item['D'], $data, $storeId);
+            if ($ret == false) {
+                continue;
+            }
             // 记录导入成功
             $this->successCount++;
         }
diff --git a/app/job/service/goods/Collector.php b/app/job/service/goods/Collector.php
index 0760b7d6..b59078f1 100644
--- a/app/job/service/goods/Collector.php
+++ b/app/job/service/goods/Collector.php
@@ -145,6 +145,7 @@ class Collector extends BaseService
     {
        
         try {
+            //var_dump($url);
             // 采集第三方商品数据
             $original = $this->collector($url, $storeId);
             if ($original['spec_type'] == 20) {
diff --git a/app/job/service/goods/GoodsStoreImport.php b/app/job/service/goods/GoodsStoreImport.php
index 5e79308c..d8e9dd38 100644
--- a/app/job/service/goods/GoodsStoreImport.php
+++ b/app/job/service/goods/GoodsStoreImport.php
@@ -110,7 +110,10 @@ class GoodsStoreImport extends BaseService
                 continue;
             }
         	$data = $this->createData($item, $storeId);
-        	$service->single($item['D'], $data, $storeId);
+        	$ret = $service->single($item['D'], $data, $storeId);
+            if ($ret == false) {
+                continue;
+            }
             // 记录导入成功
             $this->successCount++;
         }
@@ -201,9 +204,6 @@ class GoodsStoreImport extends BaseService
      */
     public function createData(array $original, int $storeId): array
     {
-
-        //$channel = Channel::where('name', $original["B"])->find();
-
         //批量导入销售区域处理
         $region = [];
         $region_text = [];
@@ -227,7 +227,8 @@ class GoodsStoreImport extends BaseService
             foreach ($regions as $key => $value) {
                 $regionsnew[$value['pid']][] = $value;
             }
-            
+            // echo "
";
+            // print_r($regionsnew);
             foreach ($regionsnew as $pid => $value) {
                 $privince = Region::withoutGlobalScope()->where('id', $pid)->find();
                 $region_text[$pid]['name'] = $privince['name'] ?? "";
@@ -239,11 +240,19 @@ class GoodsStoreImport extends BaseService
                 }
                 $region_text[$pid]['citys'] = $citys;
             }
+            unset($pid);
+
+            foreach ($region_text as $pid => &$item) {
+                //如果传入的是整个省份
+                if (count($item['citys']) == Region::withoutGlobalScope()->whereIn('pid', $pid)->count()) {
+                    $item['citys'] = [];
+                }
+            }
         }
-         // echo "
";
-         //    print_r($region_text);
-         //    print_r($region);
-         //    exit();
+        // echo "
";
+        //     print_r($region_text);
+        //     print_r($region);
+        //     exit();
         // 整理商品数据
         $data = [
             'cmmdty_model' => $original["A"],
diff --git a/app/store/controller/Goods.php b/app/store/controller/Goods.php
index 0d820833..850a5f9d 100644
--- a/app/store/controller/Goods.php
+++ b/app/store/controller/Goods.php
@@ -25,6 +25,7 @@ use app\common\model\GoodsCategoryRel;
  */
 class Goods extends Controller
 {
+    private static $show_content = "***";
     /**
      * 商品列表
      * @return Json
@@ -35,9 +36,26 @@ class Goods extends Controller
         // 获取列表记录
         $model = new GoodsModel;
         $params = $this->request->param();
-        $params['channel'] = 'zy';
+        //$params['channel'] = 'zy';
         $params['merchantId'] = $this->merchantId;
-        $list= $model->getList($params, (int)$this->request->param('pageSize', 15));
+        $list = $model->getList($params, (int)$this->request->param('pageSize', 15));
+        if ($list->isEmpty()) {
+            return $this->renderSuccess(compact('list'));
+        }
+        $list = $list->toArray();
+
+        foreach ($list['data'] as &$value) {
+            if (!in_array($value['channel'], ['zy'])) {
+                $value['goods_price_min'] = self::$show_content;
+                $value['goods_price_max'] = self::$show_content;
+                $value['line_price_max'] = self::$show_content;
+                $value['line_price_min'] = self::$show_content;
+                $value['cost_price_min'] = self::$show_content;
+                $value['goods_no'] = self::$show_content;
+            }
+
+        }
+
         return $this->renderSuccess(compact('list'));
     }
 
@@ -68,6 +86,19 @@ class Goods extends Controller
         // 获取商品详情
         $model = new GoodsModel;
         $goodsInfo = $model->getDetail($goodsId);
+        if (!in_array($goodsInfo['channel'], ['zy'])) {
+            $goodsInfo['goods_price_min'] = self::$show_content;
+            $goodsInfo['goods_price_max'] = self::$show_content;
+            $goodsInfo['line_price_max'] = self::$show_content;
+            $goodsInfo['line_price_min'] = self::$show_content;
+            $goodsInfo['cost_price_min'] = self::$show_content;
+            $goodsInfo['goods_no'] = self::$show_content;
+            foreach ($goodsInfo['skuList'] as $key => &$value) {
+                $value['goods_price'] = self::$show_content;
+                $value['cost_price'] = self::$show_content;
+            }
+
+        }
         return $this->renderSuccess(compact('goodsInfo'));
     }
 
@@ -120,8 +151,22 @@ class Goods extends Controller
     {
         // 商品详情
         $model = GoodsModel::detail($goodsId);
+        $params = $this->postForm();
+        if ($model->isEmpty()) {
+            return $this->renderError("该商品已不存在!");
+        }
+        if (!in_array($model->channel, ['zy'])) {
+            $params['goods_price'] = $model->goods_price_min;
+            $params['cost_price'] = $model->cost_price_min;
+            $params['goods_no'] = $model->goods_no;
+        }
+
+        // echo "
";
+        // print_r($params);
+        // print_r($model->toArray());
+        // exit();
         // 更新记录
-        if ($model->edit($this->postForm())) {
+        if ($model->edit($params)) {
             return $this->renderSuccess('更新成功');
         }
         return $this->renderError($model->getError() ?: '更新失败');
diff --git a/app/store/model/Goods.php b/app/store/model/Goods.php
index c6086968..09a2e1b2 100644
--- a/app/store/model/Goods.php
+++ b/app/store/model/Goods.php
@@ -183,7 +183,7 @@ class Goods extends GoodsModel
     public function setIsPool(array $goodsIds, int $is_pool): bool
     {
         // 批量更新记录
-        return static::updateBase(['is_pool' => $is_pool], [['goods_id', 'in', $goodsIds]]);
+        return static::updateBase(['is_pool' => $is_pool,'update_time' => time(),'sale_time' => time()], [['goods_id', 'in', $goodsIds]]);
     }
     /**
      * 修改商品状态
@@ -194,7 +194,7 @@ class Goods extends GoodsModel
     public function setIsSale(array $goodsIds, int $is_sale): bool
     {
         // 批量更新记录
-        return static::updateBase(['is_sale' => $is_sale], [['goods_id', 'in', $goodsIds]]);
+        return static::updateBase(['is_sale' => $is_sale,'update_time' => time(),'sale_time' => time()], [['goods_id', 'in', $goodsIds]]);
     }
     /**
      * 修改商品状态
diff --git a/app/store/model/Store.php b/app/store/model/Store.php
index 3891ae32..32fcc630 100644
--- a/app/store/model/Store.php
+++ b/app/store/model/Store.php
@@ -30,6 +30,7 @@ class Store extends StoreModel
     {
         // 是否删除图片
         !isset($data['logo_image_id']) && $data['logo_image_id'] = 0;
+        $data['fliter_condition'] = isset($data['fliter_condition']) ? json_encode($data['fliter_condition'], JSON_UNESCAPED_UNICODE) : "";
         return $this->save($data) !== false;
     }
 }
diff --git a/config/allowapi.php b/config/allowapi.php
new file mode 100644
index 00000000..babc3798
--- /dev/null
+++ b/config/allowapi.php
@@ -0,0 +1,4 @@
+