|
@@ -29,6 +29,9 @@ 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();
|
|
|
|
+ if (!$template) {
|
|
|
|
+ throw new HttpException(500, '没有找到对应模板');
|
|
|
|
+ }
|
|
$templates = $template->toArray();
|
|
$templates = $template->toArray();
|
|
$where = [
|
|
$where = [
|
|
'city_id' => $templates['city_id'],
|
|
'city_id' => $templates['city_id'],
|
|
@@ -43,7 +46,11 @@ class CmsContentTemplateSetRepository
|
|
$request['type'] = $v['apply_type'];
|
|
$request['type'] = $v['apply_type'];
|
|
$request['tpl_id'] = $v['id'];
|
|
$request['tpl_id'] = $v['id'];
|
|
$request['city_id'] = $v['city_id'];
|
|
$request['city_id'] = $v['city_id'];
|
|
- return $this->preview($request);
|
|
|
|
|
|
+ if ($v['apply_type'] == 2){
|
|
|
|
+ return $this->exchangeMall($request);
|
|
|
|
+ }else{
|
|
|
|
+ return $this->preview($request);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if ($need_create) {
|
|
if ($need_create) {
|
|
@@ -85,7 +92,11 @@ class CmsContentTemplateSetRepository
|
|
$request['city_id'] = $res->city_id;
|
|
$request['city_id'] = $res->city_id;
|
|
DB::commit();
|
|
DB::commit();
|
|
|
|
|
|
- return $this->preview($request);
|
|
|
|
|
|
+ if ($res->apply_type == 2){
|
|
|
|
+ return $this->exchangeMall($request);
|
|
|
|
+ }else{
|
|
|
|
+ return $this->preview($request);
|
|
|
|
+ }
|
|
//return Response::create();
|
|
//return Response::create();
|
|
|
|
|
|
} catch (QueryException $exception) {
|
|
} catch (QueryException $exception) {
|
|
@@ -99,78 +110,66 @@ class CmsContentTemplateSetRepository
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * banner配置
|
|
|
|
- */
|
|
|
|
- public function bannerSet($request)
|
|
|
|
|
|
+ //banner、左一右二、上一下三配置-数据处理
|
|
|
|
+ function request_data($request,$id,$rules)
|
|
{
|
|
{
|
|
- $banner_id = $request['id'] ?? '';
|
|
|
|
- $rules = $request['rule'];
|
|
|
|
- if (is_array($rules)) {
|
|
|
|
- if (count($rules) > 10) {
|
|
|
|
- throw new HttpException(500, '最多只能添加10个banner海报');
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- foreach ($rules as $k => $v) {
|
|
|
|
- if (isset($v['link_type'])) {
|
|
|
|
- $rules[$k]['link_type'] = intval($v['link_type']);
|
|
|
|
- }
|
|
|
|
|
|
+ foreach ($rules as $k => $v) {
|
|
|
|
+ if (isset($v['link_type'])) {
|
|
|
|
+ $rules[$k]['link_type'] = intval($v['link_type']);
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
|
|
- $subject = [
|
|
|
|
- 'rule' => json_encode($rules),
|
|
|
|
- 'tpl_id' => $request['tpl_id'],
|
|
|
|
- 'area_type' => $request['area_type'],
|
|
|
|
- 'status' => 0,
|
|
|
|
- 'sort' => isset($request['sort']) ? $request['sort'] : 999,
|
|
|
|
- 'name' => isset($request['name']) ? $request['name'] : '',
|
|
|
|
- ];
|
|
|
|
- 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'];
|
|
|
|
- if (count($request_rule) > 0) {
|
|
|
|
- foreach ($request_rule as $k => $v) {
|
|
|
|
- if (isset($v['link_type']) && $v['link_type'] == 1) {
|
|
|
|
- $templates = $this->cmsSubject->where('id', intval($v['link_url']))->first();
|
|
|
|
- $templates->used_count += 1;
|
|
|
|
- $templates->save();
|
|
|
|
- }
|
|
|
|
|
|
+ $templateSet = [
|
|
|
|
+ 'rule' => json_encode($rules),
|
|
|
|
+ 'tpl_id' => $request['tpl_id'],
|
|
|
|
+ 'area_type' => $request['area_type'],
|
|
|
|
+ 'status' => 0,
|
|
|
|
+ 'sort' => isset($request['sort']) ? $request['sort'] : 999,
|
|
|
|
+ 'name' => isset($request['name']) ? $request['name'] : '',
|
|
|
|
+ ];
|
|
|
|
+ if ($id) {
|
|
|
|
+ $old_subject_id = $this->cmsContentTemplateSet->select('rule')->find($id);
|
|
|
|
+ $subject_id_array = json_decode($old_subject_id['rule'], true);
|
|
|
|
+ $request_rule = $request['rule'];
|
|
|
|
+ if (count($request_rule) > 0) {
|
|
|
|
+ foreach ($request_rule as $k => $v) {
|
|
|
|
+ if (isset($v['link_type']) && $v['link_type'] == 1) {
|
|
|
|
+ $templates = $this->cmsSubject->where('id', intval($v['link_url']))->first();
|
|
|
|
+ $templates->used_count += 1;
|
|
|
|
+ $templates->save();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- if (count($subject_id_array) > 0) {
|
|
|
|
- foreach ($subject_id_array as $val) {
|
|
|
|
- if (isset($val['link_type']) && $val['link_type'] == 1) {
|
|
|
|
- $templates = $this->cmsSubject->where('id', intval($val['link_url']))->first();
|
|
|
|
- $update_template = [
|
|
|
|
- $templates->used_count -= 1
|
|
|
|
- ];
|
|
|
|
- $templates->update($update_template);
|
|
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
+ if (count($subject_id_array) > 0) {
|
|
|
|
+ foreach ($subject_id_array as $val) {
|
|
|
|
+ if (isset($val['link_type']) && $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 {
|
|
|
|
- if (count($request['rule']) > 0) {
|
|
|
|
- foreach ($request['rule'] as $v) {
|
|
|
|
- if (isset($v['link_type']) && $v['link_type'] == 1) {
|
|
|
|
- $templates = $this->cmsSubject->where('id', intval($v['link_url']))->first();
|
|
|
|
- $templates->used_count += 1;
|
|
|
|
- $templates->save();
|
|
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
+ $update_templates = $this->cmsContentTemplateSet->where('id', $id)->update($templateSet);
|
|
|
|
+ if (!$update_templates) {
|
|
|
|
+ throw new HttpException(500, '更新失败');
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ if (count($request['rule']) > 0) {
|
|
|
|
+ foreach ($request['rule'] as $v) {
|
|
|
|
+ if (isset($v['link_type']) && $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 {
|
|
|
|
- throw new HttpException(500, '参数格式有误');
|
|
|
|
|
|
+ if (!$this->cmsContentTemplateSet->create($templateSet)) {
|
|
|
|
+ throw new HttpException(500, '添加失败');
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
//专题被使用计数
|
|
//专题被使用计数
|
|
@@ -204,6 +203,24 @@ class CmsContentTemplateSetRepository
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * banner配置
|
|
|
|
+ */
|
|
|
|
+ public function bannerSet($request)
|
|
|
|
+ {
|
|
|
|
+ $id = $request['id'] ?? '';
|
|
|
|
+ $rules = $request['rule'];
|
|
|
|
+ if (is_array($rules)) {
|
|
|
|
+ if (count($rules) > 10) {
|
|
|
|
+ throw new HttpException(500, '最多只能添加10个banner海报');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $this->request_data($request,$id,$rules);
|
|
|
|
+
|
|
|
|
+ } else {
|
|
|
|
+ throw new HttpException(500, '参数格式有误');
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
/**
|
|
* 专题广告配置
|
|
* 专题广告配置
|
|
@@ -216,8 +233,6 @@ class CmsContentTemplateSetRepository
|
|
'rule' => json_encode($request['rule']),
|
|
'rule' => json_encode($request['rule']),
|
|
'area_type' => $request['area_type'],
|
|
'area_type' => $request['area_type'],
|
|
'status' => 0,
|
|
'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 (empty($advertisement_id)) {
|
|
@@ -291,8 +306,6 @@ class CmsContentTemplateSetRepository
|
|
'rule' => json_encode($request['rule']),
|
|
'rule' => json_encode($request['rule']),
|
|
'area_type' => $request['area_type'],
|
|
'area_type' => $request['area_type'],
|
|
'status' => 0,
|
|
'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 (empty($category_id)) {
|
|
if ($request['rule']['link_type'] == 1) {
|
|
if ($request['rule']['link_type'] == 1) {
|
|
@@ -315,6 +328,22 @@ class CmsContentTemplateSetRepository
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ //左一右二配置
|
|
|
|
+ public function subjectOne($request)
|
|
|
|
+ {
|
|
|
|
+ $id = $request['id'] ?? '';
|
|
|
|
+ $rules = $request['rule'];
|
|
|
|
+ $this->request_data($request, $id, $rules);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //上一下三配置
|
|
|
|
+ public function subjectTwo($request)
|
|
|
|
+ {
|
|
|
|
+ $id = $request['id'] ?? '';
|
|
|
|
+ $rules = $request['rule'];
|
|
|
|
+ $this->request_data($request, $id, $rules);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
/**
|
|
/**
|
|
* 内容发布
|
|
* 内容发布
|
|
@@ -509,4 +538,114 @@ class CmsContentTemplateSetRepository
|
|
]);
|
|
]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * v0.3兑换商城内容预览
|
|
|
|
+ */
|
|
|
|
+ public function exchangeMall($request)
|
|
|
|
+ {
|
|
|
|
+ $temalates = $this->cmsContentTemplate->select('title')->where(['id' => $request['tpl_id']])->first();
|
|
|
|
+ if (!$temalates) {
|
|
|
|
+ throw new HttpException(500, '没有找到对应模板');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $group_array = [];
|
|
|
|
+ $group_array['apply_type'] = 2;
|
|
|
|
+ $group_array['tpl_id'] = intval($request['tpl_id']);
|
|
|
|
+ $group_array['title'] = $temalates->title;
|
|
|
|
+ $group_array['content'] = [];
|
|
|
|
+
|
|
|
|
+ $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();
|
|
|
|
+ $new_rule = [];
|
|
|
|
+ foreach ($banner_rule->toArray() as $k => $v) {
|
|
|
|
+ if (count(json_decode($v['rule'])) > 0) {
|
|
|
|
+ $new_rule[$k]['id'] = $v['id'];
|
|
|
|
+ $new_rule[$k]['rule'] = json_decode($v['rule'], true);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ $group_array['content'][0]['rule'] = $new_rule;
|
|
|
|
+
|
|
|
|
+ $group_array['content'][1]['area_type'] = 2;
|
|
|
|
+ $floor_rule = $this->cmsContentTemplateSet->select('id', 'rule')->where(['tpl_id' => $request['tpl_id'], 'area_type' => 2])->get();
|
|
|
|
+ $new_rule = [];
|
|
|
|
+ foreach ($floor_rule->toArray() as $k => $v) {
|
|
|
|
+ $new_rule[$k]['id'] = $v['id'];
|
|
|
|
+ $new_rule[$k]['rule'] = json_decode($v['rule'], true);
|
|
|
|
+ }
|
|
|
|
+ foreach ($new_rule as $k => $v) {
|
|
|
|
+ if ($v) {
|
|
|
|
+ $rules = $v['rule'];
|
|
|
|
+ $show_type = $this->cmsSubject->select('show_type')->where('id', $rules['link_url'])->first();
|
|
|
|
+ $product = $this->cmsSubjectProduct->where('subject_id', $rules['link_url'])->orderBy('sort', 'asc')->get();
|
|
|
|
+ $pro_array = $product->toArray();
|
|
|
|
+ $res_id = implode(",", array_column($pro_array, 'product_id'));
|
|
|
|
+ $new_rule[$k]['product_id'] = $res_id;
|
|
|
|
+ $new_rule[$k]['subject_id'] = intval($rules['link_url']);
|
|
|
|
+ $new_rule[$k]['show_type'] = $show_type->show_type ?? '';
|
|
|
|
+ unset($v['url']);
|
|
|
|
+ unset($rules['link_url']);
|
|
|
|
+ unset($v['link_type']);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ $group_array['content'][1]['rule'] = $new_rule;
|
|
|
|
+
|
|
|
|
+ $subject_one = $this->cmsContentTemplateSet->select('id', 'rule','sort','name')->where(['tpl_id' => $request['tpl_id'], 'area_type' => 4])->orderBy('id', 'desc')->limit(1)->get();
|
|
|
|
+ $subject_two = $this->cmsContentTemplateSet->select('id', 'rule','sort','name')->where(['tpl_id' => $request['tpl_id'], 'area_type' => 5])->limit(1)->get();
|
|
|
|
+
|
|
|
|
+ $subject_one_sort = implode(',',array_column($subject_one->toArray(), 'sort'));
|
|
|
|
+ $subject_two_sort = implode(',',array_column($subject_two->toArray(), 'sort'));
|
|
|
|
+
|
|
|
|
+ if (intval($subject_one_sort) <= intval($subject_two_sort)){
|
|
|
|
+ $group_array['content'][2]['area_type'] = 4;
|
|
|
|
+ $new_rule = [];
|
|
|
|
+ foreach ($subject_one->toArray() as $k => $v) {
|
|
|
|
+ if (count(json_decode($v['rule'])) > 0) {
|
|
|
|
+ $new_rule[$k]['id'] = $v['id'];
|
|
|
|
+ $new_rule[$k]['name'] = $v['name'];
|
|
|
|
+ $new_rule[$k]['rule'] = json_decode($v['rule'], true);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ $group_array['content'][2]['rule'] = $new_rule;
|
|
|
|
+
|
|
|
|
+ $group_array['content'][3]['area_type'] = 5;
|
|
|
|
+ $new_rule = [];
|
|
|
|
+ foreach ($subject_two->toArray() as $k => $v) {
|
|
|
|
+ if (count(json_decode($v['rule'])) > 0) {
|
|
|
|
+ $new_rule[$k]['id'] = $v['id'];
|
|
|
|
+ $new_rule[$k]['name'] = $v['name'];
|
|
|
|
+ $new_rule[$k]['rule'] = json_decode($v['rule'], true);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ $group_array['content'][3]['rule'] = $new_rule;
|
|
|
|
+ }else{
|
|
|
|
+ $group_array['content'][2]['area_type'] = 5;
|
|
|
|
+ $new_rule = [];
|
|
|
|
+ foreach ($subject_two->toArray() as $k => $v) {
|
|
|
|
+ if (count(json_decode($v['rule'])) > 0) {
|
|
|
|
+ $new_rule[$k]['id'] = $v['id'];
|
|
|
|
+ $new_rule[$k]['name'] = $v['name'];
|
|
|
|
+ $new_rule[$k]['rule'] = json_decode($v['rule'], true);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ $group_array['content'][2]['rule'] = $new_rule;
|
|
|
|
+
|
|
|
|
+ $group_array['content'][3]['area_type'] = 4;
|
|
|
|
+ $new_rule = [];
|
|
|
|
+ foreach ($subject_one->toArray() as $k => $v) {
|
|
|
|
+ if (count(json_decode($v['rule'])) > 0) {
|
|
|
|
+ $new_rule[$k]['id'] = $v['id'];
|
|
|
|
+ $new_rule[$k]['name'] = $v['name'];
|
|
|
|
+ $new_rule[$k]['rule'] = json_decode($v['rule'], true);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ $group_array['content'][3]['rule'] = $new_rule;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ return $group_array;
|
|
|
|
+ }
|
|
}
|
|
}
|