|
|
@@ -63,12 +63,17 @@ class ShopGoodsService
|
|
|
$where['menu_id'] = $menuId;
|
|
|
}
|
|
|
|
|
|
+ $goodsType = isset($map['goods_type'])? intval($map['goods_type']) : 0;
|
|
|
+ if ($goodsType>0){
|
|
|
+ $where['goods_type'] = $goodsType;
|
|
|
+ }
|
|
|
+
|
|
|
$keywords = isset($map['keywords'])? trim($map['keywords']) : '';
|
|
|
if (!empty($keywords)) {
|
|
|
$where['goods_name|hot_keywords'] = "%{$map['keywords']}%";
|
|
|
}
|
|
|
|
|
|
- $field = $field? $field : 'sort,category,goods_sn,goods_name,goods_img,min_original_price as original_price,min_price as price,rebate_score,sales_volume,inventory,attension_count,restrictions_num';
|
|
|
+ $field = $field? $field : 'sort,category,goods_sn,goods_name,goods_type,goods_img,min_original_price as original_price,min_price as price,rebate_score,sales_volume,inventory,attension_count,restrictions_num';
|
|
|
$order = isset($map['sort']) && $map['sort']? $map['sort'] : 'sort desc,goods_id desc';
|
|
|
$list = $this->model->where($where)
|
|
|
->where(function($query) use($map){
|
|
|
@@ -77,6 +82,9 @@ class ShopGoodsService
|
|
|
$query->where('give_vip','>', 0);
|
|
|
}
|
|
|
})
|
|
|
+ ->withAttr('goods_img',function($value){
|
|
|
+ return getPreviewUrl($value);
|
|
|
+ })
|
|
|
->field($field)
|
|
|
->order($order)
|
|
|
->paginate($pageSize);
|
|
|
@@ -89,6 +97,34 @@ class ShopGoodsService
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 获取随机商品
|
|
|
+ * @param int $num
|
|
|
+ * @return array|mixed
|
|
|
+ */
|
|
|
+ public function getRandomGoods($num=12)
|
|
|
+ {
|
|
|
+ $cacheKey = "caches:goods:random:{$num}";
|
|
|
+ $data = RedisCache::get($cacheKey);
|
|
|
+ if($data){
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+ $data = $this->model->where('on_sale', 1)
|
|
|
+ ->withAttr('box_pic',function ($value){
|
|
|
+ return getPreviewUrl($value);
|
|
|
+ })
|
|
|
+ ->orderRaw("rand() , goods_id DESC")
|
|
|
+ ->field('goods_id,box_pic,goods_sn')
|
|
|
+ ->limit($num)
|
|
|
+ ->select()
|
|
|
+ ->toArray();
|
|
|
+ if($data){
|
|
|
+ RedisCache::set($cacheKey, $data, rand(5, 10));
|
|
|
+ }
|
|
|
+
|
|
|
+ return $data?$data : [];
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 获取开奖福袋商品
|
|
|
* @param int $num
|
|
|
* @return array|mixed
|
|
|
@@ -107,6 +143,9 @@ class ShopGoodsService
|
|
|
$data = $this->model->where('box_type', $boxType)
|
|
|
->where('goods_type', 2)
|
|
|
->where('can_open', $canOpen)
|
|
|
+ ->withAttr('goods_img', function($value){
|
|
|
+ return getPreviewUrl($value);
|
|
|
+ })
|
|
|
->field('goods_id,box_type,goods_img,price,goods_name')
|
|
|
->limit($num)
|
|
|
->select();
|
|
|
@@ -143,13 +182,22 @@ class ShopGoodsService
|
|
|
$info = RedisCache::get($cacheKey);
|
|
|
if(empty($info)){
|
|
|
$field = 'menu_id,spec_name,goods_id,category,goods_sn,goods_name,goods_img,goods_img_banner,goods_remark,min_original_price as original_price,min_price as price,note,inventory,rebate_score,sales_volume,restrictions,rush_buy,buynote_template as buyNote,post_template_id,restrictions_num';
|
|
|
- $info = $this->model->where($where)->field($field)->withAttr('goods_img_banner', function ($value) {
|
|
|
- return json_decode($value, true) ?: [];
|
|
|
- })->withAttr('goods_remark', function ($value) {
|
|
|
- return htmlspecialchars_decode($value);
|
|
|
- })->withAttr('buyNote', function ($value) {
|
|
|
- return htmlspecialchars_decode($value);
|
|
|
- })->findOrEmpty()->toArray();
|
|
|
+ $info = $this->model->where($where)->field($field)
|
|
|
+ ->withAttr('goods_img_banner', function ($value) {
|
|
|
+ $banners = $value? json_decode($value, true) : [];
|
|
|
+ if($banners){
|
|
|
+ foreach ($banners as &$v){
|
|
|
+ $v = getPreviewUrl($v);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return $banners;
|
|
|
+ })->withAttr('goods_img', function ($value) {
|
|
|
+ return getPreviewUrl($value);
|
|
|
+ })->withAttr('goods_remark', function ($value) {
|
|
|
+ return getContent(htmlspecialchars_decode($value));
|
|
|
+ })->withAttr('buyNote', function ($value) {
|
|
|
+ return htmlspecialchars_decode($value);
|
|
|
+ })->findOrEmpty()->toArray();
|
|
|
}else{
|
|
|
$isCache = true;
|
|
|
}
|
|
|
@@ -304,6 +352,9 @@ class ShopGoodsService
|
|
|
$info = $this->model->alias('a')
|
|
|
->leftJoin('shop_supplier s','s.id = a.supplier')
|
|
|
->where(['a.goods_sn'=> $goodsSn])
|
|
|
+ ->withAttr('goods_img', function ($value) {
|
|
|
+ return getPreviewUrl($value);
|
|
|
+ })
|
|
|
->field($field)
|
|
|
->find();
|
|
|
$info = $info? $info->toArray() : [];
|
|
|
@@ -335,6 +386,9 @@ class ShopGoodsService
|
|
|
$info = $this->model->alias('a')
|
|
|
->leftJoin('shop_supplier s','s.id = a.supplier')
|
|
|
->where(['a.goods_id'=> $goodsId])
|
|
|
+ ->withAttr('goods_img', function ($value) {
|
|
|
+ return getPreviewUrl($value);
|
|
|
+ })
|
|
|
->field($field)
|
|
|
->find();
|
|
|
$info = $info? $info->toArray() : [];
|
|
|
@@ -359,7 +413,10 @@ class ShopGoodsService
|
|
|
return $data;
|
|
|
}
|
|
|
$field = $field? $field : 'goods_type';
|
|
|
- $data = $this->model->whereIn('goods_sn', $snArr)->field($field)->findOrEmpty();
|
|
|
+ $data = $this->model->whereIn('goods_sn', $snArr)->field($field)
|
|
|
+ ->withAttr('goods_img', function ($value) {
|
|
|
+ return getPreviewUrl($value);
|
|
|
+ })->findOrEmpty();
|
|
|
if($data){
|
|
|
$data = $data->toArray();
|
|
|
RedisCache::set($cacheKey, $data, rand(5, 10));
|
|
|
@@ -393,10 +450,13 @@ class ShopGoodsService
|
|
|
$query->whereIn('box_type', [10,20,30,40]);
|
|
|
}
|
|
|
})
|
|
|
- ->withAttr('box_img', function ($val, $data) {
|
|
|
- return getWebUrl() . '.' . $val;
|
|
|
+ ->withAttr('box_pic', function ($value) {
|
|
|
+ return getPreviewUrl($value);
|
|
|
+ })
|
|
|
+ ->withAttr('goods_img', function ($value) {
|
|
|
+ return getPreviewUrl($value);
|
|
|
})
|
|
|
- ->field('goods_id,box_type,goods_img,price,goods_name,goods_sn')
|
|
|
+ ->field('goods_id,box_type,box_pic,goods_img,price,goods_name,goods_sn')
|
|
|
->order('box_type', 'desc')
|
|
|
->paginate($pageSize)
|
|
|
->toArray();
|