|
@@ -12,8 +12,10 @@ use Symfony\Component\HttpKernel\Exception\HttpException;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Database\QueryException;
|
|
use Illuminate\Database\QueryException;
|
|
|
|
|
|
-class CmsContentTemplateSetRepository {
|
|
|
|
- public function __construct(CmsContentTemplateSet $cmsContentTemplateSet,CmsContentTemplate $cmsContentTemplate,CmsSubjectProduct $cmsSubjectProduct,CmsSubject $cmsSubject) {
|
|
|
|
|
|
+class CmsContentTemplateSetRepository
|
|
|
|
+{
|
|
|
|
+ public function __construct(CmsContentTemplateSet $cmsContentTemplateSet, CmsContentTemplate $cmsContentTemplate, CmsSubjectProduct $cmsSubjectProduct, CmsSubject $cmsSubject)
|
|
|
|
+ {
|
|
|
|
|
|
$this->cmsContentTemplateSet = $cmsContentTemplateSet;
|
|
$this->cmsContentTemplateSet = $cmsContentTemplateSet;
|
|
$this->cmsContentTemplate = $cmsContentTemplate;
|
|
$this->cmsContentTemplate = $cmsContentTemplate;
|
|
@@ -26,17 +28,16 @@ class CmsContentTemplateSetRepository {
|
|
*/
|
|
*/
|
|
public function set($request)
|
|
public function set($request)
|
|
{
|
|
{
|
|
- $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();
|
|
$templates = $template->toArray();
|
|
$templates = $template->toArray();
|
|
-// var_dump($templates);die;
|
|
|
|
$where = [
|
|
$where = [
|
|
- 'city_id'=>$templates['city_id'],
|
|
|
|
- 'apply_type'=>$templates['apply_type'],
|
|
|
|
|
|
+ 'city_id' => $templates['city_id'],
|
|
|
|
+ '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;
|
|
$request['type'] = $v['apply_type'];
|
|
$request['type'] = $v['apply_type'];
|
|
@@ -45,55 +46,57 @@ class CmsContentTemplateSetRepository {
|
|
return $this->preview($request);
|
|
return $this->preview($request);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- if ($need_create) {
|
|
|
|
- $new_template = [
|
|
|
|
- 'title' => $templates['title'],
|
|
|
|
- 'city_id' => $templates['city_id'],
|
|
|
|
- 'city_name' => $templates['city_name'],
|
|
|
|
- 'apply_type' => $templates['apply_type'],
|
|
|
|
- 'status' => 0,
|
|
|
|
- 'is_open' => $templates['is_open'],
|
|
|
|
- ];
|
|
|
|
- DB::beginTransaction();
|
|
|
|
- try {
|
|
|
|
- $res = $this->cmsContentTemplate->create($new_template);
|
|
|
|
- if (!$res) {
|
|
|
|
- throw new HttpException(500, '添加草稿模板失败');
|
|
|
|
- }
|
|
|
|
|
|
+ if ($need_create) {
|
|
|
|
+ $new_template = [
|
|
|
|
+ 'title' => $templates['title'],
|
|
|
|
+ 'city_id' => $templates['city_id'],
|
|
|
|
+ 'city_name' => $templates['city_name'],
|
|
|
|
+ 'apply_type' => $templates['apply_type'],
|
|
|
|
+ 'status' => 0,
|
|
|
|
+ 'is_open' => $templates['is_open'],
|
|
|
|
+ ];
|
|
|
|
+ DB::beginTransaction();
|
|
|
|
+ try {
|
|
|
|
+ $res = $this->cmsContentTemplate->create($new_template);
|
|
|
|
+ if (!$res) {
|
|
|
|
+ throw new HttpException(500, '添加草稿模板失败');
|
|
|
|
+ }
|
|
|
|
|
|
- $template_set = $this->cmsContentTemplateSet->where('tpl_id', $templates['id'])->get();
|
|
|
|
- if (count($template_set) > 0) {
|
|
|
|
- foreach ($template_set->toArray() as $key => $val) {
|
|
|
|
- $copy_template = [
|
|
|
|
- 'rule' => $val['rule'],
|
|
|
|
- 'tpl_id' => $res->id,
|
|
|
|
- 'area_type' => $val['area_type'],
|
|
|
|
- 'status' => $val['status'],
|
|
|
|
- ];
|
|
|
|
- $result = $this->cmsContentTemplateSet->create($copy_template);
|
|
|
|
- if (!$result) {
|
|
|
|
- throw new HttpException(500, '生成模板内容失败');
|
|
|
|
- }
|
|
|
|
|
|
+ $template_set = $this->cmsContentTemplateSet->where('tpl_id', $templates['id'])->get();
|
|
|
|
+ if (count($template_set) > 0) {
|
|
|
|
+ foreach ($template_set->toArray() as $key => $val) {
|
|
|
|
+ $copy_template = [
|
|
|
|
+ 'rule' => $val['rule'],
|
|
|
|
+ 'tpl_id' => $res->id,
|
|
|
|
+ 'area_type' => $val['area_type'],
|
|
|
|
+ 'status' => $val['status'],
|
|
|
|
+ 'sort' => $val['sort'],
|
|
|
|
+ 'name' => $val['name'],
|
|
|
|
+ ];
|
|
|
|
+ $result = $this->cmsContentTemplateSet->create($copy_template);
|
|
|
|
+ if (!$result) {
|
|
|
|
+ throw new HttpException(500, '生成模板内容失败');
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|
|
- $request['type'] = $res->apply_type;
|
|
|
|
- $request['tpl_id'] = $res->id;
|
|
|
|
- $request['city_id'] = $res->city_id;
|
|
|
|
- DB::commit();
|
|
|
|
-
|
|
|
|
- return $this->preview($request);
|
|
|
|
- //return Response::create();
|
|
|
|
-
|
|
|
|
- } catch (QueryException $exception) {
|
|
|
|
- DB::rollBack();
|
|
|
|
- return Response::create([
|
|
|
|
- 'message' => '生成模板内容失败,请重试',
|
|
|
|
- 'error' => $exception->getMessage(),
|
|
|
|
- 'status_code' => 500
|
|
|
|
- ]);
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
+ $request['type'] = $res->apply_type;
|
|
|
|
+ $request['tpl_id'] = $res->id;
|
|
|
|
+ $request['city_id'] = $res->city_id;
|
|
|
|
+ DB::commit();
|
|
|
|
+
|
|
|
|
+ return $this->preview($request);
|
|
|
|
+ //return Response::create();
|
|
|
|
+
|
|
|
|
+ } catch (QueryException $exception) {
|
|
|
|
+ DB::rollBack();
|
|
|
|
+ return Response::create([
|
|
|
|
+ 'message' => '生成模板内容失败,请重试',
|
|
|
|
+ 'error' => $exception->getMessage(),
|
|
|
|
+ 'status_code' => 500
|
|
|
|
+ ]);
|
|
}
|
|
}
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -108,11 +111,20 @@ class CmsContentTemplateSetRepository {
|
|
if (count($rules) > 10) {
|
|
if (count($rules) > 10) {
|
|
throw new HttpException(500, '最多只能添加10个banner海报');
|
|
throw new HttpException(500, '最多只能添加10个banner海报');
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ foreach ($rules as $k => $v) {
|
|
|
|
+ if (isset($v['link_type'])) {
|
|
|
|
+ $rules[$k]['link_type'] = intval($v['link_type']);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
$subject = [
|
|
$subject = [
|
|
'rule' => json_encode($rules),
|
|
'rule' => json_encode($rules),
|
|
'tpl_id' => $request['tpl_id'],
|
|
'tpl_id' => $request['tpl_id'],
|
|
'area_type' => $request['area_type'],
|
|
'area_type' => $request['area_type'],
|
|
'status' => 0,
|
|
'status' => 0,
|
|
|
|
+ 'sort' => isset($request['sort']) ? $request['sort'] : 999,
|
|
|
|
+ 'name' => isset($request['name']) ? $request['name'] : '',
|
|
'created_at' => date('Y-m-d H:i:s'),
|
|
'created_at' => date('Y-m-d H:i:s'),
|
|
'updated_at' => date('Y-m-d H:i:s')
|
|
'updated_at' => date('Y-m-d H:i:s')
|
|
];
|
|
];
|
|
@@ -120,7 +132,7 @@ class CmsContentTemplateSetRepository {
|
|
$old_subject_id = $this->cmsContentTemplateSet->select('rule')->find($banner_id);
|
|
$old_subject_id = $this->cmsContentTemplateSet->select('rule')->find($banner_id);
|
|
$subject_id_array = json_decode($old_subject_id['rule'], true);
|
|
$subject_id_array = json_decode($old_subject_id['rule'], true);
|
|
$request_rule = $request['rule'];
|
|
$request_rule = $request['rule'];
|
|
- if (count($request_rule)>0){
|
|
|
|
|
|
+ if (count($request_rule) > 0) {
|
|
foreach ($request_rule as $k => $v) {
|
|
foreach ($request_rule as $k => $v) {
|
|
if (isset($v['link_type']) && $v['link_type'] == 1) {
|
|
if (isset($v['link_type']) && $v['link_type'] == 1) {
|
|
$templates = $this->cmsSubject->where('id', intval($v['link_url']))->first();
|
|
$templates = $this->cmsSubject->where('id', intval($v['link_url']))->first();
|
|
@@ -129,7 +141,7 @@ class CmsContentTemplateSetRepository {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- if (count($subject_id_array)>0) {
|
|
|
|
|
|
+ if (count($subject_id_array) > 0) {
|
|
foreach ($subject_id_array as $val) {
|
|
foreach ($subject_id_array as $val) {
|
|
if (isset($val['link_type']) && $val['link_type'] == 1) {
|
|
if (isset($val['link_type']) && $val['link_type'] == 1) {
|
|
$templates = $this->cmsSubject->where('id', intval($val['link_url']))->first();
|
|
$templates = $this->cmsSubject->where('id', intval($val['link_url']))->first();
|
|
@@ -145,7 +157,7 @@ class CmsContentTemplateSetRepository {
|
|
throw new HttpException(500, '更新失败');
|
|
throw new HttpException(500, '更新失败');
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- if (count($request['rule'])>0) {
|
|
|
|
|
|
+ if (count($request['rule']) > 0) {
|
|
foreach ($request['rule'] as $v) {
|
|
foreach ($request['rule'] as $v) {
|
|
if (isset($v['link_type']) && $v['link_type'] == 1) {
|
|
if (isset($v['link_type']) && $v['link_type'] == 1) {
|
|
$templates = $this->cmsSubject->where('id', intval($v['link_url']))->first();
|
|
$templates = $this->cmsSubject->where('id', intval($v['link_url']))->first();
|
|
@@ -158,8 +170,8 @@ class CmsContentTemplateSetRepository {
|
|
throw new HttpException(500, '添加失败');
|
|
throw new HttpException(500, '添加失败');
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- }else{
|
|
|
|
- throw new HttpException(500, '参数格式有误');
|
|
|
|
|
|
+ } else {
|
|
|
|
+ throw new HttpException(500, '参数格式有误');
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -167,28 +179,28 @@ class CmsContentTemplateSetRepository {
|
|
function update_subject($request)
|
|
function update_subject($request)
|
|
{
|
|
{
|
|
$old_subject_id = $this->cmsContentTemplateSet->select('rule')->find($request['id']);
|
|
$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();
|
|
|
|
|
|
+ $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 = [
|
|
$update_template = [
|
|
- $templates->used_count -=1
|
|
|
|
|
|
+ $templates->used_count -= 1
|
|
];
|
|
];
|
|
$templates->update($update_template);
|
|
$templates->update($update_template);
|
|
|
|
|
|
- $templates = $this->cmsSubject->where('id',intval($request['rule']['link_url']))->first();
|
|
|
|
- $templates->used_count +=1;
|
|
|
|
|
|
+ $templates = $this->cmsSubject->where('id', intval($request['rule']['link_url']))->first();
|
|
|
|
+ $templates->used_count += 1;
|
|
$templates->save();
|
|
$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();
|
|
|
|
|
|
+ } 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 = [
|
|
$update_template = [
|
|
- $templates->used_count -=1
|
|
|
|
|
|
+ $templates->used_count -= 1
|
|
];
|
|
];
|
|
$templates->update($update_template);
|
|
$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;
|
|
|
|
|
|
+ } 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();
|
|
$templates->save();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -201,32 +213,32 @@ class CmsContentTemplateSetRepository {
|
|
public function advertisementSet($request)
|
|
public function advertisementSet($request)
|
|
{
|
|
{
|
|
$advertisement_id = $request['id'] ?? '';
|
|
$advertisement_id = $request['id'] ?? '';
|
|
- $subject = [
|
|
|
|
- 'tpl_id' => $request['tpl_id'],
|
|
|
|
- 'rule' => json_encode($request['rule']),
|
|
|
|
- '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')
|
|
|
|
- ];
|
|
|
|
|
|
+ $subject = [
|
|
|
|
+ 'tpl_id' => $request['tpl_id'],
|
|
|
|
+ 'rule' => json_encode($request['rule']),
|
|
|
|
+ '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 (empty($advertisement_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)) {
|
|
|
|
- throw new HttpException(500, '添加失败');
|
|
|
|
- }
|
|
|
|
- }else{
|
|
|
|
- $this->update_subject($request);
|
|
|
|
|
|
+ if (empty($advertisement_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)) {
|
|
|
|
+ throw new HttpException(500, '添加失败');
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ $this->update_subject($request);
|
|
|
|
|
|
- $advertisement_ids = $this->cmsContentTemplateSet->where('id',$advertisement_id)->update($subject);
|
|
|
|
- if (!$advertisement_ids) {
|
|
|
|
- throw new HttpException(500, '更新失败');
|
|
|
|
- }
|
|
|
|
|
|
+ $advertisement_ids = $this->cmsContentTemplateSet->where('id', $advertisement_id)->update($subject);
|
|
|
|
+ if (!$advertisement_ids) {
|
|
|
|
+ throw new HttpException(500, '更新失败');
|
|
}
|
|
}
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -235,27 +247,35 @@ class CmsContentTemplateSetRepository {
|
|
public function floorSet($request)
|
|
public function floorSet($request)
|
|
{
|
|
{
|
|
$floor_id = $request['id'] ?? '';
|
|
$floor_id = $request['id'] ?? '';
|
|
- $subject = [
|
|
|
|
- 'tpl_id' => $request['tpl_id'],
|
|
|
|
- 'rule' => json_encode($request['rule']),
|
|
|
|
- '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 (empty($floor_id)){
|
|
|
|
- if ($request['rule']['link_type'] == 1){
|
|
|
|
- $templates = $this->cmsSubject->where('id',intval($request['rule']['link_url']))->first();
|
|
|
|
- $templates->used_count +=1;
|
|
|
|
|
|
+ if (isset($request['rule']['link_type'])) {
|
|
|
|
+ $request['rule']['link_type'] = intval($request['rule']['link_type']);
|
|
|
|
+ }
|
|
|
|
+ if (isset($request['rule']['show_num'])) {
|
|
|
|
+ $request['rule']['show_num'] = intval($request['rule']['show_num']);
|
|
|
|
+ }
|
|
|
|
+ $subject = [
|
|
|
|
+ 'tpl_id' => $request['tpl_id'],
|
|
|
|
+ 'rule' => json_encode($request['rule']),
|
|
|
|
+ 'area_type' => $request['area_type'],
|
|
|
|
+ 'status' => 0,
|
|
|
|
+ 'sort' => isset($request['sort']) ? $request['sort'] : 999,
|
|
|
|
+ 'name' => isset($request['name']) ? $request['name'] : '',
|
|
|
|
+ 'created_at' => date('Y-m-d H:i:s'),
|
|
|
|
+ 'updated_at' => date('Y-m-d H:i:s')
|
|
|
|
+ ];
|
|
|
|
+ if (empty($floor_id)) {
|
|
|
|
+ if ($request['rule']['link_type'] == 1) {
|
|
|
|
+ $templates = $this->cmsSubject->where('id', intval($request['rule']['link_url']))->first();
|
|
|
|
+ $templates->used_count += 1;
|
|
$templates->save();
|
|
$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);
|
|
$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, '更新失败');
|
|
}
|
|
}
|
|
@@ -270,18 +290,18 @@ class CmsContentTemplateSetRepository {
|
|
public function categorySet($request)
|
|
public function categorySet($request)
|
|
{
|
|
{
|
|
$category_id = $request['id'] ?? '';
|
|
$category_id = $request['id'] ?? '';
|
|
- $subject = [
|
|
|
|
- 'tpl_id' => $request['tpl_id'],
|
|
|
|
- 'rule' => json_encode($request['rule']),
|
|
|
|
- '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 (empty($category_id)){
|
|
|
|
- if ($request['rule']['link_type'] == 1){
|
|
|
|
- $templates = $this->cmsSubject->where('id',intval($request['rule']['link_url']))->first();
|
|
|
|
- $templates->used_count +=1;
|
|
|
|
|
|
+ $subject = [
|
|
|
|
+ 'tpl_id' => $request['tpl_id'],
|
|
|
|
+ 'rule' => json_encode($request['rule']),
|
|
|
|
+ '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 (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();
|
|
$templates->save();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -291,7 +311,7 @@ class CmsContentTemplateSetRepository {
|
|
} else {
|
|
} else {
|
|
$this->update_subject($request);
|
|
$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, '更新失败');
|
|
}
|
|
}
|
|
@@ -309,23 +329,23 @@ class CmsContentTemplateSetRepository {
|
|
$market_key = config('constants.CMS_MARKET');
|
|
$market_key = config('constants.CMS_MARKET');
|
|
|
|
|
|
//同一个城市同一个模板(团购/菜市场) 只能有一种状态(草稿/发布),已发布的一旦被编辑把之前的直接删掉
|
|
//同一个城市同一个模板(团购/菜市场) 只能有一种状态(草稿/发布),已发布的一旦被编辑把之前的直接删掉
|
|
- $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();
|
|
$where = [
|
|
$where = [
|
|
- 'city_id'=>$template->city_id,
|
|
|
|
- 'title'=>$template->title,
|
|
|
|
- 'apply_type'=>$template->apply_type,
|
|
|
|
|
|
+ 'city_id' => $template->city_id,
|
|
|
|
+ 'title' => $template->title,
|
|
|
|
+ 'apply_type' => $template->apply_type,
|
|
];
|
|
];
|
|
$templates = $this->cmsContentTemplate->where($where)->get();
|
|
$templates = $this->cmsContentTemplate->where($where)->get();
|
|
- $update_is_open_ids=[];
|
|
|
|
- foreach ($templates->toArray() as $k=>$v) {
|
|
|
|
|
|
+ $update_is_open_ids = [];
|
|
|
|
+ foreach ($templates->toArray() as $k => $v) {
|
|
if ($v['status'] == 1) {
|
|
if ($v['status'] == 1) {
|
|
- $update_is_open_ids[]=$v['id'];
|
|
|
|
|
|
+ $update_is_open_ids[] = $v['id'];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- if ($update_is_open_ids){
|
|
|
|
|
|
+ if ($update_is_open_ids) {
|
|
$delete_open_ids = $this->cmsContentTemplate->whereIn('id', $update_is_open_ids)->get();
|
|
$delete_open_ids = $this->cmsContentTemplate->whereIn('id', $update_is_open_ids)->get();
|
|
- if (count($delete_open_ids)>0){
|
|
|
|
|
|
+ if (count($delete_open_ids) > 0) {
|
|
$result = $this->cmsContentTemplate->whereIn('id', $update_is_open_ids)->delete();
|
|
$result = $this->cmsContentTemplate->whereIn('id', $update_is_open_ids)->delete();
|
|
if (!$result) {
|
|
if (!$result) {
|
|
throw new HttpException(500, '删除失败,请重试');
|
|
throw new HttpException(500, '删除失败,请重试');
|
|
@@ -333,7 +353,7 @@ class CmsContentTemplateSetRepository {
|
|
}
|
|
}
|
|
|
|
|
|
$update_open_ids = $this->cmsContentTemplateSet->whereIn('tpl_id', $update_is_open_ids)->get();
|
|
$update_open_ids = $this->cmsContentTemplateSet->whereIn('tpl_id', $update_is_open_ids)->get();
|
|
- if (count($update_open_ids)>0){
|
|
|
|
|
|
+ if (count($update_open_ids) > 0) {
|
|
$res = $this->cmsContentTemplateSet->whereIn('tpl_id', $update_is_open_ids)->update(['status' => 0]);
|
|
$res = $this->cmsContentTemplateSet->whereIn('tpl_id', $update_is_open_ids)->update(['status' => 0]);
|
|
if (!$res) {
|
|
if (!$res) {
|
|
throw new HttpException(500, '修改失败,请重试');
|
|
throw new HttpException(500, '修改失败,请重试');
|
|
@@ -342,32 +362,32 @@ class CmsContentTemplateSetRepository {
|
|
}
|
|
}
|
|
|
|
|
|
$update_tpl = $this->cmsContentTemplate->where('id', $request['tpl_id'])->first();
|
|
$update_tpl = $this->cmsContentTemplate->where('id', $request['tpl_id'])->first();
|
|
- if ($update_tpl){
|
|
|
|
|
|
+ if ($update_tpl) {
|
|
$result = $this->cmsContentTemplate->where('id', $request['tpl_id'])->update(['status' => 1]);
|
|
$result = $this->cmsContentTemplate->where('id', $request['tpl_id'])->update(['status' => 1]);
|
|
if (!$result) {
|
|
if (!$result) {
|
|
throw new HttpException(500, '修改失败,请重试');
|
|
throw new HttpException(500, '修改失败,请重试');
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- $template_id = $this->cmsContentTemplateSet->where('tpl_id',$request['tpl_id'])->get();
|
|
|
|
- if (count($template_id)>0){
|
|
|
|
- $res = $this->cmsContentTemplateSet->where('tpl_id',$request['tpl_id'])->update(['status'=>1]);
|
|
|
|
- if (!$res){
|
|
|
|
|
|
+ $template_id = $this->cmsContentTemplateSet->where('tpl_id', $request['tpl_id'])->get();
|
|
|
|
+ if (count($template_id) > 0) {
|
|
|
|
+ $res = $this->cmsContentTemplateSet->where('tpl_id', $request['tpl_id'])->update(['status' => 1]);
|
|
|
|
+ if (!$res) {
|
|
throw new HttpException(500, '修改失败,请重试');
|
|
throw new HttpException(500, '修改失败,请重试');
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- foreach ($templates->toArray() as $k=>$v) {
|
|
|
|
- $result = $this->cmsContentTemplateSet->where(['status'=>0,'tpl_id'=>$v['id']])->delete();
|
|
|
|
|
|
+ foreach ($templates->toArray() as $k => $v) {
|
|
|
|
+ $result = $this->cmsContentTemplateSet->where(['status' => 0, 'tpl_id' => $v['id']])->delete();
|
|
if ($result) {
|
|
if ($result) {
|
|
return Response::create();
|
|
return Response::create();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- if ($template->apply_type == 0){
|
|
|
|
|
|
+ if ($template->apply_type == 0) {
|
|
if (Cache::has($group_key)) {
|
|
if (Cache::has($group_key)) {
|
|
Cache::forget($group_key);
|
|
Cache::forget($group_key);
|
|
}
|
|
}
|
|
- }elseif ($template->apply_type == 1){
|
|
|
|
|
|
+ } elseif ($template->apply_type == 1) {
|
|
if (Cache::has($market_key)) {
|
|
if (Cache::has($market_key)) {
|
|
Cache::forget($market_key);
|
|
Cache::forget($market_key);
|
|
}
|
|
}
|
|
@@ -380,54 +400,54 @@ class CmsContentTemplateSetRepository {
|
|
*/
|
|
*/
|
|
public function preview($request)
|
|
public function preview($request)
|
|
{
|
|
{
|
|
- $temalates = $this->cmsContentTemplate->select('title')->where(['id'=>$request['tpl_id']])->first();
|
|
|
|
- if (!$temalates){
|
|
|
|
|
|
+ $temalates = $this->cmsContentTemplate->select('title')->where(['id' => $request['tpl_id']])->first();
|
|
|
|
+ if (!$temalates) {
|
|
throw new HttpException(500, '没有找到对应模板');
|
|
throw new HttpException(500, '没有找到对应模板');
|
|
}
|
|
}
|
|
|
|
|
|
//团购首页
|
|
//团购首页
|
|
$group_array = [];
|
|
$group_array = [];
|
|
- if ($request['type'] == 0){
|
|
|
|
|
|
+ if ($request['type'] == 0) {
|
|
$group_array['apply_type'] = 0;
|
|
$group_array['apply_type'] = 0;
|
|
$group_array['tpl_id'] = $request['tpl_id'];
|
|
$group_array['tpl_id'] = $request['tpl_id'];
|
|
$group_array['title'] = $temalates->title;
|
|
$group_array['title'] = $temalates->title;
|
|
- $group_array['content'] =[];
|
|
|
|
- }else{//菜市场首页
|
|
|
|
|
|
+ $group_array['content'] = [];
|
|
|
|
+ } else {//菜市场首页
|
|
$group_array['apply_type'] = 1;
|
|
$group_array['apply_type'] = 1;
|
|
$group_array['tpl_id'] = $request['tpl_id'];
|
|
$group_array['tpl_id'] = $request['tpl_id'];
|
|
$group_array['title'] = $temalates->title;
|
|
$group_array['title'] = $temalates->title;
|
|
- $group_array['content'] =[];
|
|
|
|
|
|
+ $group_array['content'] = [];
|
|
}
|
|
}
|
|
|
|
|
|
$group_array['content'][0]['area_type'] = 0;
|
|
$group_array['content'][0]['area_type'] = 0;
|
|
- $banner_rule = $this->cmsContentTemplateSet->select('id','rule')->where(['tpl_id'=>$request['tpl_id'],'area_type'=>0])->orderBy('id', 'desc')->limit(1)->get();
|
|
|
|
|
|
+ $banner_rule = $this->cmsContentTemplateSet->select('id', 'rule')->where(['tpl_id' => $request['tpl_id'], 'area_type' => 0])->orderBy('id', 'desc')->limit(1)->get();
|
|
$new_rule = [];
|
|
$new_rule = [];
|
|
- foreach ($banner_rule->toArray() as $k=>$v){
|
|
|
|
- if (count(json_decode($v['rule']))>0){
|
|
|
|
|
|
+ foreach ($banner_rule->toArray() as $k => $v) {
|
|
|
|
+ if (count(json_decode($v['rule'])) > 0) {
|
|
$new_rule[$k]['id'] = $v['id'];
|
|
$new_rule[$k]['id'] = $v['id'];
|
|
- $new_rule[$k]['rule'] = json_decode($v['rule'],true);
|
|
|
|
|
|
+ $new_rule[$k]['rule'] = json_decode($v['rule'], true);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
$group_array['content'][0]['rule'] = $new_rule;
|
|
$group_array['content'][0]['rule'] = $new_rule;
|
|
$group_array['content'][1]['area_type'] = 1;
|
|
$group_array['content'][1]['area_type'] = 1;
|
|
- $subject_rule = $this->cmsContentTemplateSet->select('id','rule')->where(['tpl_id'=>$request['tpl_id'],'area_type'=>1])->get();
|
|
|
|
|
|
+ $subject_rule = $this->cmsContentTemplateSet->select('id', 'rule')->where(['tpl_id' => $request['tpl_id'], 'area_type' => 1])->get();
|
|
|
|
|
|
$new_rule = [];
|
|
$new_rule = [];
|
|
- foreach ($subject_rule->toArray() as $k=>$v){
|
|
|
|
|
|
+ foreach ($subject_rule->toArray() as $k => $v) {
|
|
$new_rule[$k]['id'] = $v['id'];
|
|
$new_rule[$k]['id'] = $v['id'];
|
|
- $new_rule[$k]['rule'] = json_decode($v['rule'],true);
|
|
|
|
|
|
+ $new_rule[$k]['rule'] = json_decode($v['rule'], true);
|
|
}
|
|
}
|
|
$group_array['content'][1]['rule'] = $new_rule;
|
|
$group_array['content'][1]['rule'] = $new_rule;
|
|
|
|
|
|
$group_array['content'][2]['area_type'] = 2;
|
|
$group_array['content'][2]['area_type'] = 2;
|
|
- $floor_rule = $this->cmsContentTemplateSet->select('id','rule')->where(['tpl_id'=>$request['tpl_id'],'area_type'=>2])->get();
|
|
|
|
|
|
+ $floor_rule = $this->cmsContentTemplateSet->select('id', 'rule')->where(['tpl_id' => $request['tpl_id'], 'area_type' => 2])->get();
|
|
$new_rule = [];
|
|
$new_rule = [];
|
|
- foreach ($floor_rule->toArray() as $k=>$v){
|
|
|
|
|
|
+ foreach ($floor_rule->toArray() as $k => $v) {
|
|
$new_rule[$k]['id'] = $v['id'];
|
|
$new_rule[$k]['id'] = $v['id'];
|
|
- $new_rule[$k]['rule'] = json_decode($v['rule'],true);
|
|
|
|
|
|
+ $new_rule[$k]['rule'] = json_decode($v['rule'], true);
|
|
}
|
|
}
|
|
- foreach ($new_rule as $k=>$v){
|
|
|
|
- if ($v){
|
|
|
|
|
|
+ foreach ($new_rule as $k => $v) {
|
|
|
|
+ if ($v) {
|
|
$rules = $v['rule'];
|
|
$rules = $v['rule'];
|
|
$show_num = intval($rules['show_num']);
|
|
$show_num = intval($rules['show_num']);
|
|
$show_type = $this->cmsSubject->select('show_type')->where('id', $rules['link_url'])->first();
|
|
$show_type = $this->cmsSubject->select('show_type')->where('id', $rules['link_url'])->first();
|
|
@@ -443,15 +463,15 @@ class CmsContentTemplateSetRepository {
|
|
unset($v['link_type']);
|
|
unset($v['link_type']);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- $group_array['content'][2]['rule'] = $new_rule;
|
|
|
|
|
|
+ $group_array['content'][2]['rule'] = $new_rule;
|
|
|
|
|
|
- if ($request['type'] == 1){
|
|
|
|
|
|
+ if ($request['type'] == 1) {
|
|
$group_array['content'][3]['area_type'] = 3;
|
|
$group_array['content'][3]['area_type'] = 3;
|
|
- $category_rule = $this->cmsContentTemplateSet->select('id','rule')->where(['tpl_id'=>$request['tpl_id'],'area_type'=>3])->get();
|
|
|
|
|
|
+ $category_rule = $this->cmsContentTemplateSet->select('id', 'rule')->where(['tpl_id' => $request['tpl_id'], 'area_type' => 3])->get();
|
|
$new_rule = [];
|
|
$new_rule = [];
|
|
- foreach ($category_rule->toArray() as $k=>$v){
|
|
|
|
|
|
+ foreach ($category_rule->toArray() as $k => $v) {
|
|
$new_rule[$k]['id'] = $v['id'];
|
|
$new_rule[$k]['id'] = $v['id'];
|
|
- $new_rule[$k]['rule'] = json_decode($v['rule'],true);
|
|
|
|
|
|
+ $new_rule[$k]['rule'] = json_decode($v['rule'], true);
|
|
}
|
|
}
|
|
$group_array['content'][3]['rule'] = $new_rule;
|
|
$group_array['content'][3]['rule'] = $new_rule;
|
|
}
|
|
}
|
|
@@ -460,25 +480,25 @@ class CmsContentTemplateSetRepository {
|
|
|
|
|
|
public function getTemplate($cityId)
|
|
public function getTemplate($cityId)
|
|
{
|
|
{
|
|
- $group = $this->cmsContentTemplate->select('id','status','title','apply_type')->where(['city_id'=>$cityId,'deleted_at'=>null,'apply_type'=>0])->get();
|
|
|
|
|
|
+ $group = $this->cmsContentTemplate->select('id', 'status', 'title', 'apply_type')->where(['city_id' => $cityId, 'deleted_at' => null, 'apply_type' => 0])->get();
|
|
$groups = $group->toArray();
|
|
$groups = $group->toArray();
|
|
- if (count($groups)>1){
|
|
|
|
- foreach($groups as $key => $val) {
|
|
|
|
|
|
+ if (count($groups) > 1) {
|
|
|
|
+ foreach ($groups as $key => $val) {
|
|
if ($val['status'] == 1) {
|
|
if ($val['status'] == 1) {
|
|
unset($groups[$key]);
|
|
unset($groups[$key]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- $market = $this->cmsContentTemplate->select('id','status','title','apply_type')->where(['city_id'=>$cityId,'deleted_at'=>null,'apply_type'=>1])->get();
|
|
|
|
|
|
+ $market = $this->cmsContentTemplate->select('id', 'status', 'title', 'apply_type')->where(['city_id' => $cityId, 'deleted_at' => null, 'apply_type' => 1])->get();
|
|
$markets = $market->toArray();
|
|
$markets = $market->toArray();
|
|
- if (count($markets)>1){
|
|
|
|
- foreach($markets as $key => $val) {
|
|
|
|
|
|
+ if (count($markets) > 1) {
|
|
|
|
+ foreach ($markets as $key => $val) {
|
|
if ($val['status'] == 1) {
|
|
if ($val['status'] == 1) {
|
|
unset($markets[$key]);
|
|
unset($markets[$key]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- $templates['cms_content_templates'] = array_merge($groups,$markets);
|
|
|
|
|
|
+ $templates['cms_content_templates'] = array_merge($groups, $markets);
|
|
return $templates;
|
|
return $templates;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -486,10 +506,10 @@ class CmsContentTemplateSetRepository {
|
|
{
|
|
{
|
|
$advertisement = $this->cmsContentTemplateSet->where('id', $request['id'])->first();
|
|
$advertisement = $this->cmsContentTemplateSet->where('id', $request['id'])->first();
|
|
$res = $advertisement->delete();
|
|
$res = $advertisement->delete();
|
|
- if (!$res){
|
|
|
|
|
|
+ if (!$res) {
|
|
return Response::create([
|
|
return Response::create([
|
|
- 'message' => '删除失败,请重试',
|
|
|
|
- 'status_code' => 500
|
|
|
|
|
|
+ 'message' => '删除失败,请重试',
|
|
|
|
+ 'status_code' => 500
|
|
]);
|
|
]);
|
|
}
|
|
}
|
|
}
|
|
}
|