|
@@ -7,6 +7,7 @@ use Dingo\Api\Http\Response;
|
|
|
use App\Models\CmsContentTemplate;
|
|
|
use App\Models\CmsContentTemplateSet;
|
|
|
use App\Models\CmsSubjectProduct;
|
|
|
+use Illuminate\Support\Facades\Cache;
|
|
|
use Symfony\Component\HttpKernel\Exception\HttpException;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
use Illuminate\Database\QueryException;
|
|
@@ -119,38 +120,40 @@ class CmsContentTemplateSetRepository {
|
|
|
$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();
|
|
|
+ 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();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- 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);
|
|
|
+ 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 {
|
|
|
- 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 (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, '添加失败');
|
|
|
}
|
|
@@ -292,6 +295,9 @@ class CmsContentTemplateSetRepository {
|
|
|
*/
|
|
|
public function release($request)
|
|
|
{
|
|
|
+ $group_key = config('constants.CMS_GROUP');
|
|
|
+ $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();
|
|
|
$where = [
|
|
@@ -347,6 +353,15 @@ class CmsContentTemplateSetRepository {
|
|
|
return Response::create();
|
|
|
}
|
|
|
}
|
|
|
+ if ($template->apply_type == 0){
|
|
|
+ if (Cache::has($group_key)) {
|
|
|
+ Cache::forget($group_key);
|
|
|
+ }
|
|
|
+ }elseif ($template->apply_type == 1){
|
|
|
+ if (Cache::has($market_key)) {
|
|
|
+ Cache::forget($market_key);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
@@ -378,8 +393,10 @@ class CmsContentTemplateSetRepository {
|
|
|
$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);
|
|
|
+ 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'] = 1;
|