|
@@ -49,7 +49,7 @@ class CmsContentTemplateSetRepository
|
|
|
if ($v['apply_type'] == 2) {
|
|
|
return $this->exchangeMall($request);
|
|
|
}
|
|
|
- if ($v['apply_type'] == 0 || $v['apply_type'] == 1){
|
|
|
+ if ($v['apply_type'] == 0 || $v['apply_type'] == 1) {
|
|
|
return $this->preview($request);
|
|
|
}
|
|
|
}
|
|
@@ -97,7 +97,7 @@ class CmsContentTemplateSetRepository
|
|
|
if ($res->apply_type == 2) {
|
|
|
return $this->exchangeMall($request);
|
|
|
}
|
|
|
- if ($res->apply_type == 0 || $res->apply_type == 1){
|
|
|
+ if ($res->apply_type == 0 || $res->apply_type == 1) {
|
|
|
return $this->preview($request);
|
|
|
}
|
|
|
//return Response::create();
|
|
@@ -131,27 +131,37 @@ class CmsContentTemplateSetRepository
|
|
|
'name' => isset($request['name']) ? $request['name'] : '',
|
|
|
'floor_img' => isset($request['floor_img']) ? $request['floor_img'] : '',
|
|
|
];
|
|
|
+ $template_id = $this->cmsContentTemplate->select('apply_type')->where('id', $request['tpl_id'])->first();
|
|
|
+
|
|
|
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 (count($rules) > 0) {
|
|
|
+ foreach ($rules 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();
|
|
|
+ $subject = $this->cmsSubject->where('id', intval($v['link_url']))->first();
|
|
|
+
|
|
|
+ if ($template_id->apply_type == 2) {
|
|
|
+ if (!$subject || $subject->is_open != 1 || $subject->used_mall != 0) {
|
|
|
+ throw new HttpException(500, '所填专题已关闭或不是兑换商城专题');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $subject->used_count += 1;
|
|
|
+ $subject->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);
|
|
|
+ $subject = $this->cmsSubject->where('id', intval($val['link_url']))->first();
|
|
|
+ if ($subject) {
|
|
|
+ $update_subject = [
|
|
|
+ $subject->used_count -= 1
|
|
|
+ ];
|
|
|
+ $subject->update($update_subject);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -160,12 +170,17 @@ class CmsContentTemplateSetRepository
|
|
|
throw new HttpException(500, '更新失败');
|
|
|
}
|
|
|
} else {
|
|
|
- if (count($request['rule']) > 0) {
|
|
|
- foreach ($request['rule'] as $v) {
|
|
|
+ if (count($rules) > 0) {
|
|
|
+ foreach ($rules 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();
|
|
|
+ $subject = $this->cmsSubject->where('id', intval($v['link_url']))->first();
|
|
|
+ if ($template_id->apply_type == 2) {
|
|
|
+ if (!$subject || $subject->is_open != 1 || $subject->used_mall != 0) {
|
|
|
+ throw new HttpException(500, '所填专题已关闭或不是兑换商城专题');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $subject->used_count += 1;
|
|
|
+ $subject->save();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -183,26 +198,40 @@ class CmsContentTemplateSetRepository
|
|
|
$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);
|
|
|
+ $subject = $this->cmsSubject->where('id', intval($subject_id_array['link_url']))->first();
|
|
|
+ if ($subject) {
|
|
|
+ $update_subject = [
|
|
|
+ $subject->used_count -= 1
|
|
|
+ ];
|
|
|
+ $subject->update($update_subject);
|
|
|
+ }
|
|
|
|
|
|
- $templates = $this->cmsSubject->where('id', intval($request['rule']['link_url']))->first();
|
|
|
- $templates->used_count += 1;
|
|
|
- $templates->save();
|
|
|
+ $subject = $this->cmsSubject->where('id', intval($request['rule']['link_url']))->first();
|
|
|
+ if ($request['apply_type'] == 2) {
|
|
|
+ if (!$subject || $subject->is_open != 1 || $subject->used_mall != 0) {
|
|
|
+ throw new HttpException(500, '所填专题已关闭或不是兑换商城专题');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $subject->used_count += 1;
|
|
|
+ $subject->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);
|
|
|
+ $subject = $this->cmsSubject->where('id', intval($subject_id_array['link_url']))->first();
|
|
|
+ if ($subject) {
|
|
|
+ $update_subject = [
|
|
|
+ $subject->used_count -= 1
|
|
|
+ ];
|
|
|
+ $subject->update($update_subject);
|
|
|
+ }
|
|
|
} 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();
|
|
|
+ $subject = $this->cmsSubject->where('id', intval($request['rule']['link_url']))->first();
|
|
|
+ if ($request['apply_type'] == 2) {
|
|
|
+ if (!$subject || $subject->is_open != 1 || $subject->used_mall != 0) {
|
|
|
+ throw new HttpException(500, '所填专题已关闭或不是兑换商城专题');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $subject->used_count += 1;
|
|
|
+ $subject->save();
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -238,6 +267,7 @@ class CmsContentTemplateSetRepository
|
|
|
'area_type' => $request['area_type'],
|
|
|
'status' => 0,
|
|
|
];
|
|
|
+ $template_id = $this->cmsContentTemplate->select('apply_type')->where('id', $request['tpl_id'])->first();
|
|
|
|
|
|
if (empty($advertisement_id)) {
|
|
|
if ($request['rule']['link_type'] == 1) {
|
|
@@ -249,6 +279,7 @@ class CmsContentTemplateSetRepository
|
|
|
throw new HttpException(500, '添加失败');
|
|
|
}
|
|
|
} else {
|
|
|
+ $request['apply_type'] = $template_id->apply_type;
|
|
|
$this->update_subject($request);
|
|
|
|
|
|
$advertisement_ids = $this->cmsContentTemplateSet->where('id', $advertisement_id)->update($subject);
|
|
@@ -270,7 +301,7 @@ class CmsContentTemplateSetRepository
|
|
|
if (isset($request['rule']['show_num'])) {
|
|
|
$request['rule']['show_num'] = intval($request['rule']['show_num']);
|
|
|
}
|
|
|
- $subject = [
|
|
|
+ $templateSet = [
|
|
|
'tpl_id' => $request['tpl_id'],
|
|
|
'rule' => json_encode($request['rule']),
|
|
|
'area_type' => $request['area_type'],
|
|
@@ -279,19 +310,28 @@ class CmsContentTemplateSetRepository
|
|
|
'name' => isset($request['name']) ? $request['name'] : '',
|
|
|
'floor_img' => isset($request['floor_img']) ? $request['floor_img'] : '',
|
|
|
];
|
|
|
+ $template_id = $this->cmsContentTemplate->select('apply_type')->where('id', $request['tpl_id'])->first();
|
|
|
+
|
|
|
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();
|
|
|
+ $subject = $this->cmsSubject->where('id', intval($request['rule']['link_url']))->first();
|
|
|
+ if ($template_id->apply_type == 2) {
|
|
|
+ if (!$subject || $subject->is_open != 1 || $subject->used_mall != 0) {
|
|
|
+ throw new HttpException(500, '所填专题已关闭或不是兑换商城专题');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $subject->used_count += 1;
|
|
|
+ $subject->save();
|
|
|
}
|
|
|
- if (!$this->cmsContentTemplateSet->create($subject)) {
|
|
|
+ if (!$this->cmsContentTemplateSet->create($templateSet)) {
|
|
|
throw new HttpException(500, '添加失败');
|
|
|
}
|
|
|
} else {
|
|
|
+ $request['apply_type'] = $template_id->apply_type;
|
|
|
$this->update_subject($request);
|
|
|
|
|
|
- $floor_ids = $this->cmsContentTemplateSet->where('id', $floor_id)->update($subject);
|
|
|
+ $floor_ids = $this->cmsContentTemplateSet->where('id', $floor_id)->update($templateSet);
|
|
|
if (!$floor_ids) {
|
|
|
throw new HttpException(500, '更新失败');
|
|
|
}
|
|
@@ -312,10 +352,15 @@ class CmsContentTemplateSetRepository
|
|
|
'area_type' => $request['area_type'],
|
|
|
'status' => 0,
|
|
|
];
|
|
|
+ $template_id = $this->cmsContentTemplate->select('apply_type')->where('id', $request['tpl_id'])->first();
|
|
|
+
|
|
|
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;
|
|
|
+ if ($templates == null) {
|
|
|
+ $templates = new CmsSubject();
|
|
|
+ $templates->used_count += 1;
|
|
|
+ }
|
|
|
$templates->save();
|
|
|
}
|
|
|
|
|
@@ -323,6 +368,7 @@ class CmsContentTemplateSetRepository
|
|
|
throw new HttpException(500, '添加失败');
|
|
|
}
|
|
|
} else {
|
|
|
+ $request['apply_type'] = $template_id->apply_type;
|
|
|
$this->update_subject($request);
|
|
|
|
|
|
$category_ids = $this->cmsContentTemplateSet->where('id', $category_id)->update($subject);
|
|
@@ -601,10 +647,10 @@ class CmsContentTemplateSetRepository
|
|
|
$new_rule[$k]['rule']['rule'] = json_decode($v['rule'], true);
|
|
|
// }
|
|
|
}
|
|
|
- foreach ($new_rule as $k => $v) {
|
|
|
- $group_array['content'][$k + 1]['area_type'] = $new_rule[$k]['area_type'];
|
|
|
- $group_array['content'][$k + 1]['rule'] = array($new_rule[$k]['rule']);
|
|
|
- }
|
|
|
+ foreach ($new_rule as $k => $v) {
|
|
|
+ $group_array['content'][$k + 1]['area_type'] = $new_rule[$k]['area_type'];
|
|
|
+ $group_array['content'][$k + 1]['rule'] = array($new_rule[$k]['rule']);
|
|
|
+ }
|
|
|
|
|
|
$floor_rule = $this->cmsContentTemplateSet->select('id', 'rule', 'floor_img')->where(['tpl_id' => $request['tpl_id'], 'area_type' => 2])->orderBy('id', 'asc')->get();
|
|
|
$new_rule = [];
|
|
@@ -628,8 +674,8 @@ class CmsContentTemplateSetRepository
|
|
|
unset($v['link_type']);
|
|
|
}
|
|
|
}
|
|
|
- $group_array['content'][$count + 1]['area_type'] = 2;
|
|
|
- $group_array['content'][$count + 1]['rule'] = $new_rule;
|
|
|
+ $group_array['content'][$count + 1]['area_type'] = 2;
|
|
|
+ $group_array['content'][$count + 1]['rule'] = $new_rule;
|
|
|
|
|
|
return $group_array;
|
|
|
}
|