|
@@ -8,6 +8,8 @@ use App\Models\CmsContentTemplate;
|
|
|
use App\Models\CmsContentTemplateSet;
|
|
|
use App\Models\CmsSubjectProduct;
|
|
|
use Symfony\Component\HttpKernel\Exception\HttpException;
|
|
|
+use Illuminate\Support\Facades\DB;
|
|
|
+use Illuminate\Database\QueryException;
|
|
|
|
|
|
class CmsContentTemplateSetRepository {
|
|
|
public function __construct(CmsContentTemplateSet $cmsContentTemplateSet,CmsContentTemplate $cmsContentTemplate,CmsSubjectProduct $cmsSubjectProduct,CmsSubject $cmsSubject) {
|
|
@@ -18,31 +20,98 @@ class CmsContentTemplateSetRepository {
|
|
|
$this->cmsSubject = $cmsSubject;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 点击内容配置
|
|
|
+ */
|
|
|
+ public function set($request)
|
|
|
+ {
|
|
|
+ $template = $this->cmsContentTemplate->where('id',$request['tpl_id'])->first();
|
|
|
+ $templates = $template->toArray();
|
|
|
+
|
|
|
+ $request = [];
|
|
|
+ if ($templates['is_open'] == 0){
|
|
|
+ $request['type'] = $templates['apply_type'];
|
|
|
+ $request['tpl_id'] = $templates['id'];
|
|
|
+ return $this->preview($request);
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($templates['is_open'] == 1){
|
|
|
+ $new_template = [
|
|
|
+ 'title' => $templates['title'],
|
|
|
+ 'city_id' => $templates['city_id'],
|
|
|
+ 'city_name' => $templates['city_name'],
|
|
|
+ 'apply_type' => $templates['apply_type'],
|
|
|
+ 'is_open' => 0,
|
|
|
+ ];
|
|
|
+ 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, '生成模板内容失败');
|
|
|
+ }
|
|
|
+ $request['type'] = $res->apply_type;
|
|
|
+ $request['tpl_id'] = $result->tpl_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
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* banner配置
|
|
|
*/
|
|
|
public function bannerSet($request)
|
|
|
{
|
|
|
- $rules = json_decode($request['rule'],true);
|
|
|
+ $banner_id = $request['id']??'';
|
|
|
+ $rules = $request['rule'];
|
|
|
if (is_array($rules)){
|
|
|
if (count($rules)>10) {
|
|
|
throw new HttpException(500, '最多只能添加10个banner海报');
|
|
|
}
|
|
|
- $decode_floor = json_decode($request['rule'], true);
|
|
|
- $count = count($decode_floor);
|
|
|
- if ($count > 0) {
|
|
|
- for ($i = 0; $i < $count; $i++) {
|
|
|
$subject = [
|
|
|
- 'rule' => json_encode($decode_floor[$i]),
|
|
|
+ '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 (!$this->cmsContentTemplateSet->create($subject)) {
|
|
|
- throw new HttpException(500, '添加失败');
|
|
|
+ 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, '添加失败');
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- }
|
|
|
}else{
|
|
|
throw new HttpException(500, '参数格式有误');
|
|
|
}
|
|
@@ -54,17 +123,26 @@ class CmsContentTemplateSetRepository {
|
|
|
*/
|
|
|
public function advertisementSet($request)
|
|
|
{
|
|
|
+ $advertisement_id = $request['id'] ?? '';
|
|
|
$subject = [
|
|
|
'tpl_id' => $request['tpl_id'],
|
|
|
- 'rule' => $request['rule'],
|
|
|
+ '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 (!$this->cmsContentTemplateSet->create($subject)) {
|
|
|
- throw new HttpException(500, '添加失败');
|
|
|
+ if (empty($advertisement_id)){
|
|
|
+ if (!$this->cmsContentTemplateSet->create($subject)) {
|
|
|
+ throw new HttpException(500, '添加失败');
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ $advertisement_ids = $this->cmsContentTemplateSet->where('id',$advertisement_id)->update($subject);
|
|
|
+ if (!$advertisement_ids) {
|
|
|
+ throw new HttpException(500, '更新失败');
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -72,16 +150,26 @@ class CmsContentTemplateSetRepository {
|
|
|
*/
|
|
|
public function floorSet($request)
|
|
|
{
|
|
|
+ $floor_id = $request['id'] ?? '';
|
|
|
$subject = [
|
|
|
'tpl_id' => $request['tpl_id'],
|
|
|
- 'rule' => $request['rule'],
|
|
|
+ '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 (!$this->cmsContentTemplateSet->create($subject)) {
|
|
|
throw new HttpException(500, '添加失败');
|
|
|
}
|
|
|
+ }else {
|
|
|
+ $floor_ids = $this->cmsContentTemplateSet->where('id',$floor_id)->update($subject);
|
|
|
+ if (!$floor_ids) {
|
|
|
+ throw new HttpException(500, '更新失败');
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
@@ -90,16 +178,26 @@ class CmsContentTemplateSetRepository {
|
|
|
*/
|
|
|
public function categorySet($request)
|
|
|
{
|
|
|
+ $category_id = $request['id'] ?? '';
|
|
|
$subject = [
|
|
|
'tpl_id' => $request['tpl_id'],
|
|
|
- 'rule' => $request['rule'],
|
|
|
+ '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 (!$this->cmsContentTemplateSet->create($subject)) {
|
|
|
throw new HttpException(500, '添加失败');
|
|
|
}
|
|
|
+ }else {
|
|
|
+ $category_ids = $this->cmsContentTemplateSet->where('id',$category_id)->update($subject);
|
|
|
+ if (!$category_ids) {
|
|
|
+ throw new HttpException(500, '更新失败');
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
@@ -157,17 +255,15 @@ class CmsContentTemplateSetRepository {
|
|
|
$group_array['content'] =[];
|
|
|
}
|
|
|
|
|
|
- $group_array['content'][0]['area_type'] ="banner";
|
|
|
- $banner_rule = $this->cmsContentTemplateSet->select('id','rule')->where(['tpl_id'=>$request['tpl_id'],'area_type'=>0])->get();
|
|
|
+ $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){
|
|
|
$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'] ="special";
|
|
|
+ $group_array['content'][1]['area_type'] = 1;
|
|
|
$subject_rule = $this->cmsContentTemplateSet->select('id','rule')->where(['tpl_id'=>$request['tpl_id'],'area_type'=>1])->get();
|
|
|
|
|
|
$new_rule = [];
|
|
@@ -177,7 +273,7 @@ class CmsContentTemplateSetRepository {
|
|
|
}
|
|
|
$group_array['content'][1]['rule'] = $new_rule;
|
|
|
|
|
|
- $group_array['content'][2]['area_type'] ="floor";
|
|
|
+ $group_array['content'][2]['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){
|
|
@@ -187,8 +283,9 @@ class CmsContentTemplateSetRepository {
|
|
|
foreach ($new_rule as $k=>$v){
|
|
|
if ($v){
|
|
|
$rules = $v['rule'];
|
|
|
+ $show_num = intval($rules['show_num']);
|
|
|
$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();
|
|
|
+ $product = $this->cmsSubjectProduct->where('subject_id', $rules['link_url'])->orderBy('sort', 'asc')->limit($show_num)->get();
|
|
|
$pro_array = $product->toArray();
|
|
|
$res_id = implode(",", array_column($pro_array, 'product_id'));
|
|
|
$new_rule[$k]['product_id'] = $res_id;
|
|
@@ -203,7 +300,7 @@ class CmsContentTemplateSetRepository {
|
|
|
$group_array['content'][2]['rule'] = $new_rule;
|
|
|
|
|
|
if ($request['type'] == 1){
|
|
|
- $group_array['content'][3]['area_type'] ="category";
|
|
|
+ $group_array['content'][3]['area_type'] = 3;
|
|
|
$category_rule = $this->cmsContentTemplateSet->select('id','rule')->where(['tpl_id'=>$request['tpl_id'],'area_type'=>3])->get();
|
|
|
$new_rule = [];
|
|
|
foreach ($category_rule->toArray() as $k=>$v){
|
|
@@ -212,14 +309,12 @@ class CmsContentTemplateSetRepository {
|
|
|
}
|
|
|
$group_array['content'][3]['rule'] = $new_rule;
|
|
|
}
|
|
|
-
|
|
|
return $group_array;
|
|
|
-
|
|
|
}
|
|
|
|
|
|
public function getTemplate($cityId)
|
|
|
{
|
|
|
- return $this->cmsContentTemplate->select('title','apply_type')->where(['city_id'=>$cityId,'is_open'=>1])->orderBy('apply_type','asc')->get();
|
|
|
+ return $this->cmsContentTemplate->select('id','title','apply_type')->where(['city_id'=>$cityId,'is_open'=>1])->orderBy('apply_type','asc')->get();
|
|
|
|
|
|
}
|
|
|
|