Browse Source

Merge branch 'phoenix' of http://120.24.33.109:11081/hyzjshwo/lanzu_api_hyperf into phoenix

master
Lemon 5 years ago
parent
commit
92c52fe25d
  1. 24
      app/Model/v3/Category.php
  2. 10
      app/Model/v3/GoodsCategory.php
  3. 3
      app/Service/v3/Implementations/SearchService.php

24
app/Model/v3/Category.php

@ -3,18 +3,27 @@
namespace App\Model\v3;
use App\Model\Model;
use App\Service\v3\Interfaces\AttachmentServiceInterface;
use Hyperf\Database\Model\Builder;
use Hyperf\Database\Model\SoftDeletes;
use Hyperf\Di\Annotation\Inject;
class Category extends Model
{
use SoftDeletes;
/**
* @Inject
* @var AttachmentServiceInterface
*/
protected $attachmentService;
protected $table = 'lanzu_category';
protected $appends = [
'goods_types',
'cover_url'
'cover_url',
'goods_category_ids',
];
protected function boot(): void
@ -30,14 +39,13 @@ class Category extends Model
return self::query()->where(['parent_id' => $this->attributes['id']])->orderBy('sort', 'desc')->get()->toArray();
}
public function getCoverUrlAttribute()
public function getGoodsCategoryIdsAttribute()
{
$url = $this->attributes['cover_img'];
if(strripos($url,"http") === false){
return config('alioss.img_host').'/'.$url;
}else{
return $url;
return GoodsCategory::query()->where(['category_id' => $this->attributes['id']])->orderBy('sort', 'desc')->pluck('id');
}
public function getCoverUrlAttribute()
{
return $this->attachmentService->switchImgToAliOss($this->attributes['cover_img']);
}
}

10
app/Model/v3/GoodsCategory.php

@ -0,0 +1,10 @@
<?php
namespace App\Model\v3;
use App\Model\Model;
class GoodsCategory extends Model
{
protected $table = 'lanzu_goods_category';
}

3
app/Service/v3/Implementations/SearchService.php

@ -22,7 +22,8 @@ class SearchService implements \App\Service\v3\Interfaces\SearchServiceInterface
->where('inventory', '>', 0);
if (isset($params['type_id']) && $params['type_id']) {
$builder->where(['category_id' => $params['type_id']]);
$typeIds = explode(',', $params['type_id']);
$builder->whereIn('goods_category_id', $typeIds);
}
if (isset($params['keyword']) && $params['keyword']) {

Loading…
Cancel
Save