|
@@ -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();
|
|
|
}
|