123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- <?php
- namespace App\Http\Controllers;
- use App\Models\CmsSubject;
- use App\Repositories\CmsContentTemplateSetRepository;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\Validator;
- /**
- * Created by PhpStorm.
- * User: qinyaer
- * Date: 2019/5/5
- * Time: 上午9:30
- */
- class CmsContentTemplateSetController extends BaseController
- {
- public function __construct(CmsContentTemplateSetRepository $cmsContentTemplateSetRepository)
- {
- $this->cmsContentSetTemplate = $cmsContentTemplateSetRepository;
- }
- //内容预览
- public function preview(Request $request)
- {
- $validator = Validator::make($request->all(), [
- 'city_id' => 'required|integer',
- 'type' => 'required|integer',
- ]);
- if ($validator->fails()) {
- return $this->jsonError($validator->errors()->first());
- }
- return $this->jsonSuccess($this->cmsContentSetTemplate->preview($request->all()));
- }
- //兑换商城首页预览
- public function exchangeMall(Request $request)
- {
- return $this->jsonSuccess($this->cmsContentSetTemplate->exchangeMall($request->all()));
- }
- /**
- * 获取城市模板名称及类型
- * @param Request $request
- * @return array
- */
- public function template(Request $request){
- $validator = Validator::make($request->all(), [
- 'city_id' => 'required|integer'
- ]);
- if ($validator->fails()) {
- return $this->jsonError($validator->errors()->first());
- }
- return $this->jsonSuccess($this->cmsContentSetTemplate->getTemplate($request->only('city_id')));
- }
- //获取商品列表
- public function productList(Request $request)
- {
- $validator = Validator::make($request->all(), [
- 'subject_id' => 'required|integer',
- ]);
- if ($validator->fails()) {
- return $this->jsonError($validator->errors()->first());
- }
- $product_list = $this->cmsContentSetTemplate->productList($request->all());
- if ($product_list){
- return $this->jsonSuccess($product_list);
- }else{
- return $this->jsonError('没有找到对应商品');
- }
- }
- //获取某专题下的列表
- public function getProducts(Request $request)
- {
- $validator = Validator::make($request->all(), [
- 'subject_id' => 'required|integer',
- ]);
- if ($validator->fails()) {
- return $this->jsonError($validator->errors()->first());
- }
- $get_subject = CmsSubject::select('title', 'subject_img')->where('id', $request['subject_id'])->first();
- if (!$get_subject) {
- return $this->jsonError('专题ID不正确');
- }
- $product_list = $this->cmsContentSetTemplate->getProducts($request->all());
- if (count($product_list) > 0) {
- foreach ($product_list->toArray() as $k => $v) {
- $product_list[$k]['subject_title'] = $get_subject->title ?? '';
- $product_list[$k]['subject_img'] = $get_subject->subject_img ?? '';
- }
- return $this->jsonSuccess($product_list);
- } else {
- return $this->jsonError('没有找到对应商品');
- }
- }
- }
|