|
@@ -29,12 +29,11 @@ class CmsContentTemplateSetRepository {
|
|
$templates = $template->toArray();
|
|
$templates = $template->toArray();
|
|
$where = [
|
|
$where = [
|
|
'city_id'=>$templates['city_id'],
|
|
'city_id'=>$templates['city_id'],
|
|
- 'title'=>$templates['title'],
|
|
|
|
'apply_type'=>$templates['apply_type'],
|
|
'apply_type'=>$templates['apply_type'],
|
|
];
|
|
];
|
|
$copys_template = $this->cmsContentTemplate->where($where)->get();
|
|
$copys_template = $this->cmsContentTemplate->where($where)->get();
|
|
$request = [];
|
|
$request = [];
|
|
- $need_create=true;
|
|
|
|
|
|
+ $need_create = true;
|
|
foreach ($copys_template as $k=>$v) {
|
|
foreach ($copys_template as $k=>$v) {
|
|
if ($v['status'] == 0) {
|
|
if ($v['status'] == 0) {
|
|
$need_create = false;
|
|
$need_create = false;
|
|
@@ -98,35 +97,95 @@ class CmsContentTemplateSetRepository {
|
|
public function bannerSet($request)
|
|
public function bannerSet($request)
|
|
{
|
|
{
|
|
$banner_id = $request['id'] ?? '';
|
|
$banner_id = $request['id'] ?? '';
|
|
- $rules = $request['rule'];
|
|
|
|
- if (is_array($rules)){
|
|
|
|
- if (count($rules)>10) {
|
|
|
|
- throw new HttpException(500, '最多只能添加10个banner海报');
|
|
|
|
|
|
+ $rules = $request['rule'];
|
|
|
|
+ if (is_array($rules)) {
|
|
|
|
+ if (count($rules) > 10) {
|
|
|
|
+ throw new HttpException(500, '最多只能添加10个banner海报');
|
|
|
|
+ }
|
|
|
|
+ $subject = [
|
|
|
|
+ 'rule' => json_encode($rules),
|
|
|
|
+ 'tpl_id' => $request['tpl_id'],
|
|
|
|
+ 'area_type' => $request['area_type'],
|
|
|
|
+ 'status' => 0,
|
|
|
|
+ 'created_at' => date('Y-m-d H:i:s'),
|
|
|
|
+ 'updated_at' => date('Y-m-d H:i:s')
|
|
|
|
+ ];
|
|
|
|
+ if ($banner_id) {
|
|
|
|
+ $old_subject_id = $this->cmsContentTemplateSet->select('rule')->find($banner_id);
|
|
|
|
+ $subject_id_array = json_decode($old_subject_id['rule'], true);
|
|
|
|
+ $request_rule = $request['rule'];
|
|
|
|
+
|
|
|
|
+ foreach ($request_rule as $k => $v) {
|
|
|
|
+ if ($v['link_type'] == 1) {
|
|
|
|
+ $templates = $this->cmsSubject->where('id', intval($v['link_url']))->first();
|
|
|
|
+ $templates->used_count += 1;
|
|
|
|
+ $templates->save();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- $subject = [
|
|
|
|
- 'rule' => json_encode($rules),
|
|
|
|
- 'tpl_id' => $request['tpl_id'],
|
|
|
|
- 'area_type' => $request['area_type'],
|
|
|
|
- 'status' => 0,
|
|
|
|
- 'created_at' => date('Y-m-d H:i:s'),
|
|
|
|
- 'updated_at' => date('Y-m-d H:i:s')
|
|
|
|
- ];
|
|
|
|
- if ($banner_id){
|
|
|
|
- $banners = $this->cmsContentTemplateSet->where('id',$banner_id)->update($subject);
|
|
|
|
- if (!$banners) {
|
|
|
|
- throw new HttpException(500, '更新失败');
|
|
|
|
- }
|
|
|
|
- }else{
|
|
|
|
- if (!$this->cmsContentTemplateSet->create($subject)) {
|
|
|
|
- throw new HttpException(500, '添加失败');
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
|
|
+ foreach ($subject_id_array as $val) {
|
|
|
|
+ if ($val['link_type'] == 1) {
|
|
|
|
+ $templates = $this->cmsSubject->where('id', intval($val['link_url']))->first();
|
|
|
|
+ $update_template = [
|
|
|
|
+ $templates->used_count -= 1
|
|
|
|
+ ];
|
|
|
|
+ $templates->update($update_template);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $banners = $this->cmsContentTemplateSet->where('id', $banner_id)->update($subject);
|
|
|
|
+ if (!$banners) {
|
|
|
|
+ throw new HttpException(500, '更新失败');
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ foreach ($request['rule'] as $v) {
|
|
|
|
+ if ($v['link_type'] == 1) {
|
|
|
|
+ $templates = $this->cmsSubject->where('id', intval($v['link_url']))->first();
|
|
|
|
+ $templates->used_count += 1;
|
|
|
|
+ $templates->save();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!$this->cmsContentTemplateSet->create($subject)) {
|
|
|
|
+ throw new HttpException(500, '添加失败');
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}else{
|
|
}else{
|
|
throw new HttpException(500, '参数格式有误');
|
|
throw new HttpException(500, '参数格式有误');
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ //专题被使用计数
|
|
|
|
+ function update_subject($request)
|
|
|
|
+ {
|
|
|
|
+ $old_subject_id = $this->cmsContentTemplateSet->select('rule')->find($request['id']);
|
|
|
|
+ $subject_id_array = json_decode($old_subject_id['rule'],true);
|
|
|
|
+ if ($subject_id_array['link_type'] == 1 && $request['rule']['link_type'] == 1){//链接方式都为专题
|
|
|
|
+ if ($subject_id_array['link_url'] != $request['rule']['link_url']){
|
|
|
|
+ $templates = $this->cmsSubject->where('id',intval($subject_id_array['link_url']))->first();
|
|
|
|
+ $update_template = [
|
|
|
|
+ $templates->used_count -=1
|
|
|
|
+ ];
|
|
|
|
+ $templates->update($update_template);
|
|
|
|
+
|
|
|
|
+ $templates = $this->cmsSubject->where('id',intval($request['rule']['link_url']))->first();
|
|
|
|
+ $templates->used_count +=1;
|
|
|
|
+ $templates->save();
|
|
|
|
+ }
|
|
|
|
+ }elseif ($subject_id_array['link_type'] == 1 && $request['rule']['link_type'] != 1){
|
|
|
|
+ $templates = $this->cmsSubject->where('id',intval($subject_id_array['link_url']))->first();
|
|
|
|
+ $update_template = [
|
|
|
|
+ $templates->used_count -=1
|
|
|
|
+ ];
|
|
|
|
+ $templates->update($update_template);
|
|
|
|
+ }elseif ($subject_id_array['link_type'] != 1 && $request['rule']['link_type'] == 1){
|
|
|
|
+ $templates = $this->cmsSubject->where('id',intval($request['rule']['link_url']))->first();
|
|
|
|
+ $templates->used_count +=1;
|
|
|
|
+ $templates->save();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 专题广告配置
|
|
* 专题广告配置
|
|
*/
|
|
*/
|
|
@@ -147,6 +206,8 @@ class CmsContentTemplateSetRepository {
|
|
throw new HttpException(500, '添加失败');
|
|
throw new HttpException(500, '添加失败');
|
|
}
|
|
}
|
|
}else{
|
|
}else{
|
|
|
|
+ $this->update_subject($request);
|
|
|
|
+
|
|
$advertisement_ids = $this->cmsContentTemplateSet->where('id',$advertisement_id)->update($subject);
|
|
$advertisement_ids = $this->cmsContentTemplateSet->where('id',$advertisement_id)->update($subject);
|
|
if (!$advertisement_ids) {
|
|
if (!$advertisement_ids) {
|
|
throw new HttpException(500, '更新失败');
|
|
throw new HttpException(500, '更新失败');
|
|
@@ -173,6 +234,8 @@ class CmsContentTemplateSetRepository {
|
|
throw new HttpException(500, '添加失败');
|
|
throw new HttpException(500, '添加失败');
|
|
}
|
|
}
|
|
}else {
|
|
}else {
|
|
|
|
+ $this->update_subject($request);
|
|
|
|
+
|
|
$floor_ids = $this->cmsContentTemplateSet->where('id',$floor_id)->update($subject);
|
|
$floor_ids = $this->cmsContentTemplateSet->where('id',$floor_id)->update($subject);
|
|
if (!$floor_ids) {
|
|
if (!$floor_ids) {
|
|
throw new HttpException(500, '更新失败');
|
|
throw new HttpException(500, '更新失败');
|
|
@@ -197,15 +260,22 @@ class CmsContentTemplateSetRepository {
|
|
'updated_at' => date('Y-m-d H:i:s')
|
|
'updated_at' => date('Y-m-d H:i:s')
|
|
];
|
|
];
|
|
if (empty($category_id)){
|
|
if (empty($category_id)){
|
|
|
|
+ if ($request['rule']['link_type'] == 1){
|
|
|
|
+ $templates = $this->cmsSubject->where('id',intval($request['rule']['link_url']))->first();
|
|
|
|
+ $templates->used_count +=1;
|
|
|
|
+ $templates->save();
|
|
|
|
+ }
|
|
|
|
+
|
|
if (!$this->cmsContentTemplateSet->create($subject)) {
|
|
if (!$this->cmsContentTemplateSet->create($subject)) {
|
|
throw new HttpException(500, '添加失败');
|
|
throw new HttpException(500, '添加失败');
|
|
}
|
|
}
|
|
- }else {
|
|
|
|
|
|
+ } else {
|
|
|
|
+ $this->update_subject($request);
|
|
|
|
+
|
|
$category_ids = $this->cmsContentTemplateSet->where('id',$category_id)->update($subject);
|
|
$category_ids = $this->cmsContentTemplateSet->where('id',$category_id)->update($subject);
|
|
if (!$category_ids) {
|
|
if (!$category_ids) {
|
|
throw new HttpException(500, '更新失败');
|
|
throw new HttpException(500, '更新失败');
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
@@ -217,12 +287,7 @@ class CmsContentTemplateSetRepository {
|
|
public function release($request)
|
|
public function release($request)
|
|
{
|
|
{
|
|
//同一个城市同一个模板(团购/菜市场) 只能有一种状态(草稿/发布),已发布的一旦被编辑把之前的直接删掉
|
|
//同一个城市同一个模板(团购/菜市场) 只能有一种状态(草稿/发布),已发布的一旦被编辑把之前的直接删掉
|
|
- $templateSet = $this->cmsContentTemplateSet->where('tpl_id',$request['tpl_id'])->select('id','status')->get();
|
|
|
|
- $tem_array = $templateSet->toArray();
|
|
|
|
$template = $this->cmsContentTemplate->select('id','city_name','city_id','title','apply_type','is_open','status')->where('id',$request['tpl_id'])->first();
|
|
$template = $this->cmsContentTemplate->select('id','city_name','city_id','title','apply_type','is_open','status')->where('id',$request['tpl_id'])->first();
|
|
-// if ($template->is_open == 0){
|
|
|
|
-// throw new HttpException(500, '请先将状态开启之后再发布');
|
|
|
|
-// }
|
|
|
|
$where = [
|
|
$where = [
|
|
'city_id'=>$template->city_id,
|
|
'city_id'=>$template->city_id,
|
|
'title'=>$template->title,
|
|
'title'=>$template->title,
|
|
@@ -247,7 +312,6 @@ class CmsContentTemplateSetRepository {
|
|
if (!$update_open) {
|
|
if (!$update_open) {
|
|
throw new HttpException(500, '修改失败,请重试');
|
|
throw new HttpException(500, '修改失败,请重试');
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
$update_tpl = $this->cmsContentTemplate->where('id', $request['tpl_id'])->update(['status' => 1]);
|
|
$update_tpl = $this->cmsContentTemplate->where('id', $request['tpl_id'])->update(['status' => 1]);
|
|
@@ -255,7 +319,6 @@ class CmsContentTemplateSetRepository {
|
|
throw new HttpException(500, '修改失败,请重试');
|
|
throw new HttpException(500, '修改失败,请重试');
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
$res = $this->cmsContentTemplateSet->where('tpl_id',$request['tpl_id'])->update(['status'=>1]);
|
|
$res = $this->cmsContentTemplateSet->where('tpl_id',$request['tpl_id'])->update(['status'=>1]);
|
|
|
|
|
|
if (!$res){
|
|
if (!$res){
|
|
@@ -354,7 +417,7 @@ class CmsContentTemplateSetRepository {
|
|
|
|
|
|
public function getTemplate($cityId)
|
|
public function getTemplate($cityId)
|
|
{
|
|
{
|
|
- return $this->cmsContentTemplate->select('id','title','apply_type')->where(['city_id'=>$cityId])->where('deleted_at', null)->orderBy('apply_type','asc')->get();
|
|
|
|
|
|
+ return $this->cmsContentTemplate->select('id','title','apply_type')->where(['city_id'=>$cityId])->where('deleted_at', null)->groupBy('title')->orderBy('apply_type','asc')->get();
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|