Kirin před 2 roky
rodič
revize
09da5e5c8c

+ 1 - 0
app/Request.php

@@ -17,6 +17,7 @@ use Spatie\Macroable\Macroable;
  * @method user()
  * @method uid()
  * @method store_id()
+ * @method isLogin()
  */
 class Request extends \think\Request
 {

+ 1 - 1
app/api/controller/PublicController.php

@@ -85,7 +85,7 @@ class PublicController
         $info['bastList'] = StoreProduct::getBestProduct('id,image,store_name,cate_id,price,ot_price,IFNULL(sales,0) + IFNULL(ficti,0) as sales,unit_name', (int)$bastNumber, $request->uid(), false, $request->store_id());//TODO 精品推荐个数
         $info['firstList'] = StoreProduct::getNewProduct('id,image,store_name,cate_id,price,unit_name,IFNULL(sales,0) + IFNULL(ficti,0) as sales', (int)$firstNumber, $request->uid(), false, $request->store_id());//TODO 首发新品个数
         $info['bastBanner'] = sys_data('routine_home_bast_banner') ?? [];//TODO 首页精品推荐图片
-        $benefit = StoreProduct::getBenefitProduct('id,image,store_name,cate_id,price,ot_price,stock,unit_name', $promotionNumber, $request->store_id());//TODO 首页促销单品
+        $benefit = StoreProduct::getBenefitProduct('id,image,store_name,cate_id,price,ot_price,stock,unit_name', $promotionNumber, $request->uid(), $request->store_id());//TODO 首页促销单品
         $lovely = sys_data('routine_home_new_banner') ?: [];//TODO 首发新品顶部图
         $likeInfo = StoreProduct::getHotProduct('id,image,store_name,cate_id,price,ot_price,unit_name', 3, $request->uid(), $request->store_id());//TODO 热门榜单 猜你喜欢
         $couponList = StoreCouponIssue::getIssueCouponList($request->uid(), 3);

+ 7 - 1
app/api/controller/store/CategoryController.php

@@ -3,13 +3,19 @@
 namespace app\api\controller\store;
 
 use app\models\store\StoreCategory;
+use app\models\user\User;
 use app\Request;
 
 class CategoryController
 {
     public function category(Request $request)
     {
-        $cateogry = StoreCategory::with('children')->where('is_show', 1)->order('sort desc,id desc')->where('pid', 0)->select();
+        $model = StoreCategory::with('children')->where('is_show', 1)->order('sort desc,id desc')->where('pid', 0);
+        $user = User::getUserInfo($request->uid());
+        if (!($user['admin_id'] ?? 0)) {
+            $model = $model->where('only_store_user', 0);
+        }
+        $cateogry = $model->select();
         return app('json')->success($cateogry->hidden(['add_time', 'is_show', 'sort', 'children.sort', 'children.add_time', 'children.pid', 'children.is_show'])->toArray());
     }
 }

+ 12 - 10
app/api/controller/store/StoreProductController.php

@@ -60,9 +60,9 @@ class StoreProductController
      */
     public function code(Request $request, $id)
     {
-        if (!$id || !($storeInfo = StoreProduct::getValidProduct($id, 'id'))) return app('json')->fail('商品不存在或已下架');
-        $userType = $request->get('user_type', 'wechat');
         $user = $request->user();
+        if (!$id || !($storeInfo = StoreProduct::getValidProduct($id, $user['admin_id'], 'id'))) return app('json')->fail('商品不存在或已下架');
+        $userType = $request->get('user_type', 'wechat');
         try {
             switch ($userType) {
                 case 'wechat':
@@ -125,13 +125,15 @@ class StoreProductController
      */
     public function detail(Request $request, $id, $type = 0)
     {
-        if (!$id || !($storeInfo = StoreProduct::getValidProduct($id))) return app('json')->fail('商品不存在或已下架');
+        $uid = $request->uid();
+        if ($request->isLogin())
+            $user = $request->user();
+        $data['uid'] = $uid;
+        if (!$id || !($storeInfo = StoreProduct::getValidProduct($id, $user['admin_id'] ?? 0))) return app('json')->fail('商品不存在或已下架');
         $siteUrl = sys_config('site_url');
         $storeInfo['image'] = set_file_url($storeInfo['image'], $siteUrl);
         $storeInfo['image_base'] = set_file_url($storeInfo['image'], $siteUrl);
         $storeInfo['code_base'] = QrcodeService::getWechatQrcodePath($id . '_product_detail_wap.jpg', '/detail/' . $id);
-        $uid = $request->uid();
-        $data['uid'] = $uid;
         $storeInfo['description'] = htmlspecialchars_decode(StoreDescription::getDescription($id));
         //替换windows服务器下正反斜杠问题导致图片无法显示
         $storeInfo['description'] = preg_replace_callback('#<img.*?src="([^"]*)"[^>]*>#i', function ($imagsSrc) {
@@ -142,7 +144,7 @@ class StoreProductController
         list($productAttr, $productValue) = StoreProductAttr::getProductAttrDetail($id, $uid, $type, 0, $request->store_id());
         StoreVisit::setView($uid, $id, $storeInfo['cate_id'], 'viwe');
         $data['storeInfo'] = StoreProduct::setLevelPrice($storeInfo, $uid, true);
-        $data['similarity'] = StoreProduct::cateIdBySimilarityProduct($storeInfo['cate_id'], 'id,store_name,image,price,sales,ficti', 4);
+        $data['similarity'] = StoreProduct::cateIdBySimilarityProduct($storeInfo['cate_id'], 'id,store_name,image,price,sales,ficti', 4, $uid);
         $data['productAttr'] = $productAttr;
         $data['productValue'] = $productValue;
         $data['priceName'] = 0;
@@ -174,7 +176,7 @@ class StoreProductController
         } else $data['replyChance'] = 0;
         $data['mer_id'] = $storeInfo['mer_id'];
         $data['system_store'] = ($res = SystemStore::getStoreDispose()) ? $res : [];
-        $data['good_list'] = StoreProduct::getGoodList(18, 'image,store_name,price,id,ot_price');
+        $data['good_list'] = StoreProduct::getGoodList(18, $user['admin_id'] ?? 0, 'image,store_name,price,id,ot_price');
         $data['mapKey'] = sys_config('tengxun_map_key');
         $data['store_self_mention'] = (int)sys_config('store_self_mention') ?? 0;//门店自提是否开启
         $data['activity'] = StoreProduct::activity($data['storeInfo']['id'], false);
@@ -197,7 +199,7 @@ class StoreProductController
             ['limit', 0]
         ], $request, true);
         if (!$limit) return app('json')->successful([]);
-        $productHot = StoreProduct::getHotProductLoading('id,image,store_name,cate_id,price,unit_name,ot_price', (int)$page, (int)$limit);
+        $productHot = StoreProduct::getHotProductLoading('id,image,store_name,cate_id,price,unit_name,ot_price', (int)$page, (int)$limit, $request->uid());
         if (!empty($productHot)) {
             foreach ($productHot as $k => $v) {
                 if ($request->store_id()) {
@@ -234,7 +236,7 @@ class StoreProductController
             $info['list'] = StoreProduct::getNewProduct('id,image,store_name,cate_id,price,ot_price,unit_name,sort,IFNULL(sales,0) + IFNULL(ficti,0) as sales', 0, $request->uid(), true, $request->store_id());//TODO 首发新品
         } else if ($type == 4) {//TODO 促销单品
             $info['banner'] = sys_data('routine_home_benefit_banner') ?: [];//TODO 促销单品推荐图片
-            $info['list'] = StoreProduct::getBenefitProduct('id,image,store_name,cate_id,price,ot_price,stock,unit_name,sort', 0, $request->store_id());//TODO 促销单品
+            $info['list'] = StoreProduct::getBenefitProduct('id,image,store_name,cate_id,price,ot_price,stock,unit_name,sort', 0, $request->uid(), $request->store_id());//TODO 促销单品
         }
         return app('json')->successful($info);
     }
@@ -278,7 +280,7 @@ class StoreProductController
         if (!$bargainId) return app('json')->fail('参数错误');
         $user = $request->user();
 //        var_dump($user);
-        $storeBargainInfo = StoreProduct::getValidProduct($bargainId);
+        $storeBargainInfo = StoreProduct::getValidProduct($bargainId, $user['admin_id']);
         $price = $storeBargainInfo['price'];//TODO 获取砍价剩余金额
         try {
             $siteUrl = sys_config('site_url');

+ 46 - 11
app/models/store/StoreProduct.php

@@ -10,6 +10,7 @@ namespace app\models\store;
 use app\admin\model\store\StoreProductAttrValue as StoreProductAttrValueModel;
 use app\admin\model\system\SystemStoreProductStock;
 use app\models\system\SystemUserLevel;
+use app\models\user\User;
 use app\models\user\UserLevel;
 use crmeb\basic\BaseModel;
 use crmeb\services\GroupDataService;
@@ -59,16 +60,20 @@ class StoreProduct extends BaseModel
         return htmlspecialchars_decode($value);
     }
 
-    public static function getValidProduct($productId, $field = 'add_time,browse,cate_id,code_path,cost,ficti,give_integral,id,image,is_sub,is_bargain,is_benefit,is_best,is_del,is_hot,is_new,is_postage,is_seckill,is_show,keyword,mer_id,mer_use,ot_price,postage,price,sales,slider_image,sort,stock,store_info,store_name,unit_name,vip_price,spec_type,IFNULL(sales,0) + IFNULL(ficti,0) as fsales,video_link')
+    public static function getValidProduct($productId, $store_user = 0, $field = 'add_time,browse,cate_id,code_path,cost,ficti,give_integral,id,image,is_sub,is_bargain,is_benefit,is_best,is_del,is_hot,is_new,is_postage,is_seckill,is_show,keyword,mer_id,mer_use,ot_price,postage,price,sales,slider_image,sort,stock,store_info,store_name,unit_name,vip_price,spec_type,IFNULL(sales,0) + IFNULL(ficti,0) as fsales,video_link')
     {
-        $Product = self::where('is_del', 0)->where('is_show', 1)->where('id', $productId)->field($field)->find();
+
+        $Product = self::where('is_del', 0)->where('is_show', 1)->where('id', $productId)->field($field);
+        if (!$store_user)
+            $Product = $Product->where('only_store_user', 0);
+        $Product = $Product->find();
         if ($Product) return $Product->toArray();
         else return false;
     }
 
-    public static function getGoodList($limit = 18, $field = '*')
+    public static function getGoodList($limit = 18, $store_user = 0, $field = '*')
     {
-        $list = self::validWhere()->where('is_good', 1)->order('sort desc,id desc')->limit($limit)->field($field)->select();
+        $list = self::validWhere($store_user)->where('is_good', 1)->order('sort desc,id desc')->limit($limit)->field($field)->select();
         $list = count($list) ? $list->toArray() : [];
         if (!empty($list)) {
             foreach ($list as $k => $v) {
@@ -78,13 +83,17 @@ class StoreProduct extends BaseModel
         return $list;
     }
 
-    public static function validWhere()
+    public static function validWhere($store_user = 0)
     {
-        return self::where('is_del', 0)->where('is_show', 1)->where('mer_id', 0);
+        $model = self::where('is_del', 0)->where('is_show', 1)->where('mer_id', 0);
+        if (!$store_user)
+            $model = $model->where('only_store_user', 0);
+        return $model;
     }
 
     public static function getProductList($data, $uid, $store_id = 0)
     {
+        $user = User::getUserInfo($uid);
         $sId = $data['sid'];
         $cId = $data['cid'];
         $keyword = $data['keyword'];
@@ -94,7 +103,7 @@ class StoreProduct extends BaseModel
         $page = $data['page'];
         $limit = $data['limit'];
         $type = $data['type']; // 某些模板需要购物车数量 1 = 需要查询,0 = 不需要
-        $model = self::validWhere();
+        $model = self::validWhere($user['admin_id'] ?? 0);
         if ($sId) {
             $model->whereIn('id', function ($query) use ($sId) {
                 $query->name('store_product_cate')->where('cate_id', $sId)->field('product_id')->select();
@@ -144,7 +153,8 @@ class StoreProduct extends BaseModel
      * */
     public static function getSearchStorePage($keyword, $page, $limit, $uid, $cutApart = [' ', ',', '-'])
     {
-        $model = self::validWhere();
+        $user = User::getUserInfo($uid);
+        $model = self::validWhere($user['admin_id'] ?? 0);
         $keyword = trim($keyword);
         if (strlen($keyword)) {
             $cut = false;
@@ -183,10 +193,15 @@ class StoreProduct extends BaseModel
      */
     public static function getNewProduct($field = '*', $limit = 0, $uid = 0, bool $bool = true, $store_id = 0)
     {
+
         if (!$limit && !$bool) return [];
         $model = self::where('is_new', 1)->where('is_del', 0)->where('mer_id', 0)
             ->where('stock', '>', 0)->where('is_show', 1)->field($field)
             ->order('sort DESC, id DESC');
+        $user = User::getUserInfo($uid);
+        if (!($user['admin_id'] ?? 0)) {
+            $model = $model->where('only_store_user', 0);
+        }
         if ($limit) $model->limit($limit);
         $list = $model->select();
         $list = count($list) ? $list->toArray() : [];
@@ -214,6 +229,10 @@ class StoreProduct extends BaseModel
         $model = self::where('is_hot', 1)->where('is_del', 0)->where('mer_id', 0)
             ->where('stock', '>', 0)->where('is_show', 1)->field($field)
             ->order('sort DESC, id DESC');
+        $user = User::getUserInfo($uid);
+        if (!($user['admin_id'] ?? 0)) {
+            $model = $model->where('only_store_user', 0);
+        }
         if ($limit) $model->limit($limit);
         $list = $model->select();
         $list = count($list) ? $list->toArray() : [];
@@ -240,12 +259,16 @@ class StoreProduct extends BaseModel
      * @throws \think\db\exception\ModelNotFoundException
      * @throws \think\exception\DbException
      */
-    public static function getHotProductLoading($field = '*', $page = 0, $limit = 0)
+    public static function getHotProductLoading($field = '*', $page = 0, $limit = 0, $uid = 0)
     {
         if (!$limit) return [];
         $model = self::where('is_hot', 1)->where('is_del', 0)->where('mer_id', 0)
             ->where('stock', '>', 0)->where('is_show', 1)->field($field)
             ->order('sort DESC, id DESC');
+        $user = User::getUserInfo($uid);
+        if (!($user['admin_id'] ?? 0)) {
+            $model = $model->where('only_store_user', 0);
+        }
         if ($page) $model->page($page, $limit);
         $list = $model->select();
         if (is_object($list)) return $list->toArray();
@@ -264,6 +287,10 @@ class StoreProduct extends BaseModel
         $model = self::where('is_best', 1)->where('is_del', 0)->where('mer_id', 0)
             ->where('stock', '>', 0)->where('is_show', 1)->field($field)
             ->order('sort DESC, id DESC');
+        $user = User::getUserInfo($uid);
+        if (!($user['admin_id'] ?? 0)) {
+            $model = $model->where('only_store_user', 0);
+        }
         if ($limit) $model->limit($limit);
         $list = $model->select();
         $list = count($list) ? $list->toArray() : [];
@@ -326,12 +353,16 @@ class StoreProduct extends BaseModel
      * @param int $limit
      * @return false|\PDOStatement|string|\think\Collection
      */
-    public static function getBenefitProduct($field = '*', $limit = 0, $store_id = 0)
+    public static function getBenefitProduct($field = '*', $limit = 0, $uid = 0, $store_id = 0)
     {
         $model = self::where('is_benefit', 1)
             ->where('is_del', 0)->where('mer_id', 0)->where('stock', '>', 0)
             ->where('is_show', 1)->field($field)
             ->order('sort DESC, id DESC');
+        $user = User::getUserInfo($uid);
+        if (!($user['admin_id'] ?? 0)) {
+            $model = $model->where('only_store_user', 0);
+        }
         if ($limit) $model->limit($limit);
         $data = $model->select();
         if (count($data) > 0) {
@@ -347,7 +378,7 @@ class StoreProduct extends BaseModel
         return $data;
     }
 
-    public static function cateIdBySimilarityProduct($cateId, $field = '*', $limit = 0)
+    public static function cateIdBySimilarityProduct($cateId, $field = '*', $limit = 0, $uid = 0)
     {
         $pid = StoreCategory::cateIdByPid($cateId) ?: $cateId;
         $cateList = StoreCategory::pidByCategory($pid, 'id') ?: [];
@@ -357,6 +388,10 @@ class StoreProduct extends BaseModel
         }
         $model = self::where('cate_id', 'IN', $cid)->where('is_show', 1)->where('is_del', 0)
             ->field($field)->order('sort DESC,id DESC');
+        $user = User::getUserInfo($uid);
+        if (!($user['admin_id'] ?? 0)) {
+            $model = $model->where('only_store_user', 0);
+        }
         if ($limit) $model->limit($limit);
         return $model->select();
     }