123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- <?php
- namespace App\Repositories;
- use Dingo\Api\Http\Response;
- use App\Models\CmsContentTemplate;
- use App\Models\CmsContentTemplateSet;
- use Symfony\Component\HttpKernel\Exception\HttpException;
- class CmsContentTemplateSetRepository {
- public function __construct(CmsContentTemplateSet $cmsContentTemplateSet,CmsContentTemplate $cmsContentTemplate) {
- $this->cmsContentTemplateSet = $cmsContentTemplateSet;
- $this->cmsContentTemplate = $cmsContentTemplate;
- }
- /**
- * banner配置
- */
- public function bannerSet($request)
- {
- $rules = json_decode($request['rule'],true);
- if (is_array($rules)){
- if (count($rules)>10) {
- throw new HttpException(500, '最多只能添加10个banner海报');
- }
- $subject = [
- 'tpl_id' => $request['tpl_id'],
- 'rule' => $request['rule'],
- 'area_type' => $request['area_type'],
- 'status' => 0,
- ];
- if (!$this->cmsContentTemplateSet->create($subject)) {
- throw new HttpException(500, '添加失败');
- }
- }else{
- throw new HttpException(500, '参数格式有误');
- }
- }
- /**
- * 专题广告配置
- */
- public function advertisementSet($request)
- {
- $rules = json_decode($request['rule'],true);
- if (is_array($rules)){
- $subject = [
- 'tpl_id' => $request['tpl_id'],
- 'rule' => $request['rule'],
- 'area_type' => $request['area_type'],
- 'status' => 0,
- ];
- if (!$this->cmsContentTemplateSet->create($subject)) {
- throw new HttpException(500, '添加失败');
- }
- }else{
- throw new HttpException(500, '参数格式有误');
- }
- }
- /**
- * 商品楼层配置
- */
- public function floorSet($request)
- {
- $rules = json_decode($request['rule'],true);
- if (is_array($rules)){
- $subject = [
- 'tpl_id' => $request['tpl_id'],
- 'rule' => $request['rule'],
- 'area_type' => $request['area_type'],
- 'status' => 0,
- ];
- if (!$this->cmsContentTemplateSet->create($subject)) {
- throw new HttpException(500, '添加失败');
- }
- }else{
- throw new HttpException(500, '参数格式有误');
- }
- }
- /**
- * 分类专题配置
- */
- public function categorySet($request)
- {
- $rules = json_decode($request['rule'],true);
- if (is_array($rules)){
- $subject = [
- 'tpl_id' => $request['tpl_id'],
- 'rule' => $request['rule'],
- 'area_type' => $request['area_type'],
- 'status' => 0,
- ];
- if (!$this->cmsContentTemplateSet->create($subject)) {
- throw new HttpException(500, '添加失败');
- }
- }else{
- throw new HttpException(500, '参数格式有误');
- }
- }
- /**
- * 内容发布
- */
- public function release($request)
- {
- //同一个城市同一个模板(团购/菜市场) 只能有一种状态(草稿/发布),已发布的一旦被编辑把之前的直接删掉
- $templateSet = $this->cmsContentTemplateSet->where('tpl_id',$request['tpl_id'])->select('id','status')->get();
- $tem_array = $templateSet->toArray();
- foreach ($tem_array as $k=>$v) {
- if ($v['status'] == 1) {
- $result = $this->cmsContentTemplateSet->where('id', $v['id'])->delete();
- if (!$result) {
- return Response::create([
- 'message' => '删除失败,请重试',
- 'status_code' => 500
- ]);
- }
- }
- }
- $res = $this->cmsContentTemplateSet->where('tpl_id',$request['tpl_id'])->update(['status'=>1]);
- if (!$res){
- return Response::create([
- 'message' => '修改失败,请重试',
- 'status_code' => 500
- ]);
- }
- }
- }
|