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 ]); } } }