|
...
|
...
|
@@ -8,8 +8,12 @@ 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\Category;
|
|
|
|
use App\Models\Product\CategoryRelated;
|
|
|
|
use App\Models\Product\Keyword;
|
|
|
|
use App\Models\Product\KeywordRelated;
|
|
|
|
use App\Models\Product\Product;
|
|
|
|
use App\Models\User\User;
|
|
|
|
use App\Rules\Ids;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
...
|
...
|
@@ -23,43 +27,65 @@ use Illuminate\Support\Facades\DB; |
|
|
|
class ProductController extends BaseController
|
|
|
|
{
|
|
|
|
|
|
|
|
public function index(ProductLogic $logic)
|
|
|
|
public function index(Product $product)
|
|
|
|
{
|
|
|
|
$map = [];
|
|
|
|
if(!empty($this->param['search'])){
|
|
|
|
$map[] = ['title', 'like', "%{$this->param['search']}%"];
|
|
|
|
}
|
|
|
|
if(!empty($this->param['created_at'][0])){
|
|
|
|
$this->param['created_at'][0] .= ' 00:00:00';
|
|
|
|
}
|
|
|
|
if(!empty($this->param['created_at'][1])){
|
|
|
|
$this->param['created_at'][1] .= ' 23:59:59';
|
|
|
|
}
|
|
|
|
if(empty($this->param['created_at'][0]) && !empty($this->param['created_at'][1])){
|
|
|
|
$map[] = ['created_at', '>=', $this->param['created_at'][0]];
|
|
|
|
}
|
|
|
|
if(!empty($this->param['created_at'][0]) && empty($this->param['created_at'][1])){
|
|
|
|
$map[] = ['created_at', '<=', $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['keyword_id'])){
|
|
|
|
$ids = KeywordRelated::where('keyword_id', $this->param['keyword_id'])->pluck('product_id')->toArray();
|
|
|
|
$map[] = ['id', 'in', $ids];
|
|
|
|
}
|
|
|
|
if(isset($this->param['status'])){
|
|
|
|
$map[] = ['status', $this->param['status']];
|
|
|
|
}
|
|
|
|
$sort = ['id' => 'desc'];
|
|
|
|
$data = $logic->getList($map, $sort, ['id', 'project_id', 'title', 'thumb', 'product_type' , 'route' ,'category_id', 'keyword_id', 'status', 'created_uid', 'created_at', 'updated_at'],$this->row);
|
|
|
|
return $this->response('success',Code::SUCCESS,$data);
|
|
|
|
// $map = [];
|
|
|
|
// if(!empty($this->param['search'])){
|
|
|
|
// $map[] = ['title', 'like', "%{$this->param['search']}%"];
|
|
|
|
// }
|
|
|
|
// if(!empty($this->param['created_at'][0])){
|
|
|
|
// $this->param['created_at'][0] .= ' 00:00:00';
|
|
|
|
// }
|
|
|
|
// if(!empty($this->param['created_at'][1])){
|
|
|
|
// $this->param['created_at'][1] .= ' 23:59:59';
|
|
|
|
// }
|
|
|
|
// if(empty($this->param['created_at'][0]) && !empty($this->param['created_at'][1])){
|
|
|
|
// $map[] = ['created_at', '>=', $this->param['created_at'][0]];
|
|
|
|
// }
|
|
|
|
// if(!empty($this->param['created_at'][0]) && empty($this->param['created_at'][1])){
|
|
|
|
// $map[] = ['created_at', '<=', $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['keyword_id'])){
|
|
|
|
// $ids = KeywordRelated::where('keyword_id', $this->param['keyword_id'])->pluck('product_id')->toArray();
|
|
|
|
// $map[] = ['id', 'in', $ids];
|
|
|
|
// }
|
|
|
|
// if(isset($this->param['status'])){
|
|
|
|
// $map[] = ['status', $this->param['status']];
|
|
|
|
// }
|
|
|
|
// $sort = ['id' => 'desc'];
|
|
|
|
$filed = ['id', 'project_id', 'title', 'thumb', 'product_type' , 'route' ,'category_id', 'keyword_id', 'status', 'created_uid', 'created_at', 'updated_at'];
|
|
|
|
$lists = $product->lists($this->map,$this->page,$this->row,$this->order,$filed);
|
|
|
|
if(!empty($lists['list'])){
|
|
|
|
foreach ($lists['list'] as &$v){
|
|
|
|
$v['thumb']['image_link'] = getImageUrl($v['thumb']['url']);//图片统一
|
|
|
|
$v['category_id_text'] = '';
|
|
|
|
$v['keyword_id_text'] = '';
|
|
|
|
if(!empty($v['category_id'])){
|
|
|
|
$category_arr = explode(',',$v['category_id']);
|
|
|
|
$categoryModel = new Category();
|
|
|
|
$category_data = $categoryModel->list(['id'=>['in',$category_arr]]);
|
|
|
|
}
|
|
|
|
if(!empty($v['keyword_id'])){
|
|
|
|
$keyword_arr = explode(',',$v['keyword_id']);
|
|
|
|
$keywordModel = new Keyword();
|
|
|
|
$keyword_data = $keywordModel->list(['id'=>['in',$keyword_arr]]);
|
|
|
|
}
|
|
|
|
$v['status_text'] = Product::statusMap()[$info['status']] ?? '';
|
|
|
|
$v['created_uid_text'] = (new User())->read(['id'=>$v['created_uid']])['name'] ?? '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $this->response('success',Code::SUCCESS,$lists);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function info(Request $request, ProductLogic $logic){
|
|
|
|
$request->validate([
|
|
|
|
'id'=>'required'
|
...
|
...
|
|