作者 liyuhang

Merge branch 'dev' of http://47.244.231.31:8099/zhl/globalso-v6 into dev

... ... @@ -8,6 +8,7 @@ use App\Helper\Arr;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\Product\ProductLogic;
use App\Http\Requests\Bside\Product\ProductRequest;
use App\Models\Product\CategoryRelated;
use App\Rules\Ids;
use Illuminate\Http\Request;
... ... @@ -26,11 +27,18 @@ class ProductController extends BaseController
if(!empty($this->param['search'])){
$map[] = ['title', 'like', "%{$this->param['search']}%"];
}
if(!empty($this->param['created_at'])){
if(!empty($this->param['created_at'][0]) && !empty($this->param['created_at'][1])){
$map[] = ['created_at', 'between', $this->param['created_at']];
}
if(!empty($this->param['category_id'])){
$ids = CategoryRelated::where('cate_id', $this->param['category_id'])->pluck('product_id')->toArray();
$map[] = ['id', 'in', $ids];
}
if(!empty($this->param['status'])){
$map[] = ['status', $this->param['status']];
}
$sort = ['id' => 'desc'];
$data = $logic->getList($map, $sort, ['id', 'title', 'thumb', 'category_id', 'keywords', 'status', 'created_at', 'updated_at']);
$data = $logic->getList($map, $sort, ['id', 'title', 'thumb', 'category_id', 'keywords', 'status', 'created_uid', 'created_at', 'updated_at']);
return $this->success($data);
}
... ... @@ -42,7 +50,7 @@ class ProductController extends BaseController
]);
$data = $logic->getInfo($this->param['id']);
return $this->success(Arr::twoKeepKeys($data, ['id', 'title', 'gallery', 'attrs', 'category_id', 'keywords', 'intro', 'content',
'describe', 'seo_mate', 'related_product_id', 'status']));
'describe', 'seo_mate', 'related_product_id', 'status', 'category_id_text', 'status_text', 'created_uid', 'created_uid_text']));
}
public function save(ProductRequest $request, ProductLogic $logic)
... ...
... ... @@ -4,6 +4,7 @@ namespace App\Http\Logic\Bside\Product;
use App\Helper\Arr;
use App\Http\Logic\Bside\BaseLogic;
use App\Http\Logic\Bside\User\UserLogic;
use App\Models\Product\CategoryRelated;
use App\Models\Product\Product;
use App\Models\RouteMap;
... ... @@ -24,6 +25,32 @@ class ProductLogic extends BaseLogic
$this->model = new Product();
}
public function getList(array $map = [], array $sort = ['id' => 'desc'], array $columns = ['*'], int $limit = 20)
{
$data = parent::getList($map, $sort, $columns, $limit);
foreach ($data['list'] as &$v){
foreach ($v['category_id'] as $category_id){
$v['category_id_text'][] =(new CategoryLogic())->getCacheInfo($category_id)['title']??'';
}
$v['category_id_text'] = Arr::arrToSet($v['category_id_text'], 'trim');
$v['status_text'] = Product::statusMap()[$v['status']] ?? '';
$v['created_uid_text'] = (new UserLogic())->getCacheInfo($v['created_uid'])['name'] ?? '';
}
return $this->success($data);
}
public function getInfo($id)
{
$info = parent::getInfo($id);
foreach ($info['category_id'] as $category_id) {
$info['category_id_text'][] = (new CategoryLogic())->getCacheInfo($category_id)['title'] ?? '';
}
$info['category_id_text'] = Arr::arrToSet($info['category_id_text'], 'trim');
$info['status_text'] = Product::statusMap()[$info['status']] ?? '';
$info['created_uid_text'] = (new UserLogic())->getCacheInfo($info['created_uid'])['name'] ?? '';
return $this->success($info);
}
public function save($param){
//封面取第一个图片
$param['thumb'] = $param['gallery'][0] ?? '';
... ... @@ -31,6 +58,7 @@ class ProductLogic extends BaseLogic
try {
$data = $param;
unset($data['route']);
$data['created_uid'] = $this->user['id'];
$res = parent::save($data);
//关联分类
CategoryRelated::saveRelated($res['id'], $data['category_id']);
... ...
... ... @@ -43,7 +43,7 @@ class ProductRequest extends FormRequest
if (empty($v['url'])) {
$fail('图片链接不能为空');
}
if (Str::contains($v['url'], env('APP_URL'))) {
if (!Str::contains($v['url'], env('UPLOAD_LOCAL_URL') ?: env('APP_URL'))) {
$fail('图片链接不正确');
}
}
... ...
... ... @@ -16,14 +16,14 @@ class Product extends Base
const STATUS_DRAFT = 0;
const STATUS_ON = 1;
const STATUS_OFF = 2;
const STATUS_RECYCLE = 2;
public static function statusMap(){
return [
self::STATUS_DRAFT => '草稿',
self::STATUS_ON => '已上架',
self::STATUS_OFF => '未上架',
self::STATUS_ON => '已发布',
self::STATUS_RECYCLE => '回收站',
];
}
... ...