|
@@ -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) {
|
|
@@ -19,9 +21,67 @@ class CmsContentTemplateSetRepository {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 点击配置
|
|
|
+ * 点击内容配置
|
|
|
*/
|
|
|
-
|
|
|
+ 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配置
|
|
@@ -29,7 +89,6 @@ class CmsContentTemplateSetRepository {
|
|
|
public function bannerSet($request)
|
|
|
{
|
|
|
$banner_id = $request['id']??'';
|
|
|
-// $rules = json_decode($request['rule'],true);
|
|
|
$rules = $request['rule'];
|
|
|
if (is_array($rules)){
|
|
|
if (count($rules)>10) {
|
|
@@ -242,9 +301,7 @@ class CmsContentTemplateSetRepository {
|
|
|
}
|
|
|
$group_array['content'][3]['rule'] = $new_rule;
|
|
|
}
|
|
|
-
|
|
|
return $group_array;
|
|
|
-
|
|
|
}
|
|
|
|
|
|
public function getTemplate($cityId)
|