Ejemplo n.º 1
0
 /**
  * 合并页面请求,合并json和数据库内容,返回合并后的数组
  *
  * @param string $themename 模版名称
  * @param string $pagename 页面名称
  * @param string $jsondata 文件配置数据
  * @return array 合并后的数组
  */
 public function pagedata($pagename, $jsondata = array())
 {
     if ($this->type == 'pc') {
         $tpl_id = websiteInfo::where('cus_id', $this->cus_id)->pluck('pc_tpl_id');
     } else {
         $tpl_id = websiteInfo::where('cus_id', $this->cus_id)->pluck('mobile_tpl_id');
     }
     $website_confige = WebsiteConfig::where('cus_id', $this->cus_id)->where('key', $pagename)->where('type', 1)->where('template_id', $tpl_id)->pluck('value');
     $website_confige_value = unserialize($website_confige);
     //===对多图进行排序===
     if (is_array($website_confige_value)) {
         foreach ($website_confige_value as $key => &$value) {
             if ($key == 'slidepics') {
                 $slidepics_data = $value['value'];
                 if (is_array($slidepics_data)) {
                     foreach ($slidepics_data as $k => $v) {
                         if (isset($v['sort'])) {
                             $sort[$k] = is_numeric($v['sort']) ? $v['sort'] : 100;
                             $value['value'][$k]['sort'] = is_numeric($v['sort']) ? $v['sort'] : 100;
                         } else {
                             $sort[$k] = 100;
                             $value['value'][$k]['sort'] = 100;
                         }
                     }
                 }
                 array_multisort($sort, $slidepics_data);
                 $value['value'] = $slidepics_data;
             }
         }
     }
     //===对多图进行排序_end===
     if (count($jsondata)) {
         $json = isset($jsondata[$pagename . '.json']) ? $jsondata[$pagename . '.json'] : '{}';
     } else {
         $json_path = public_path('templates/' . $this->themename . '/json/' . $pagename . '.json');
         $json = file_exists($json_path) ? file_get_contents($json_path) : '{}';
     }
     if ($website_confige_value) {
         //===数据库中有模板数据===
         $default = json_decode(trim($json), TRUE);
         $result = $this->array_merge_recursive_new($default, $website_confige_value);
         $this->replaceUrl($result);
         $result = $this->dataDeal($result);
         foreach ($result as &$v) {
             if ($v['type'] == 'list') {
                 if (isset($v['config']['filter'])) {
                     if ($v['config']['filter'] == 'list') {
                         $v['config']['limit'] = isset($v['config']['limit']) ? $v['config']['limit'] : 20;
                     } else {
                         $v['config']['limit'] = isset($v['config']['limit']) ? $v['config']['limit'] : 20;
                     }
                 } else {
                     $v['config']['limit'] = isset($v['config']['limit']) ? $v['config']['limit'] : 20;
                 }
             } elseif ($v['type'] == 'navs') {
                 if (isset($v['config']['ids'])) {
                     $v['config']['ids'] = array_merge($v['config']['ids']);
                 }
             }
         }
     } else {
         //===数据库中无模板数据,从文件中读取===
         $result = json_decode(trim($json), TRUE);
         if ($result === NULL) {
             dd("{$pagename}.json文件错误");
         }
         $this->replaceUrl($result);
         $result = $this->dataDeal($result);
         $classify = new Classify();
         $templates = new TemplatesController();
         $c_arr = Classify::where('cus_id', $this->cus_id)->whereIn('type', array(1, 2, 3, 4, 5, 6, 9))->where($this->type . '_show', '=', 1)->get()->toArray();
         if (empty($c_arr)) {
             $c_arr = array();
         }
         foreach ($result as &$v) {
             switch ($v['type']) {
                 case 'list':
                     if (isset($v['config']['mustchild']) && $v['config']['mustchild'] == true) {
                         if (isset($v['config']['filter'])) {
                             if ($v['config']['filter'] == 'page') {
                                 $c_arr = $classify->toTree($c_arr);
                                 $templates->unsetFalseClassify($c_arr, array(4));
                                 $templates->unsetLastClassify($c_arr);
                                 $c_arr = array_merge($c_arr);
                             } elseif ($v['config']['filter'] == 'list') {
                                 $c_arr = $classify->toTree($c_arr);
                                 $templates->unsetFalseClassify($c_arr, array(1, 2, 3));
                                 $templates->unsetLastClassify($c_arr);
                                 if (is_array($c_arr)) {
                                     $c_arr = array_merge($c_arr);
                                 }
                                 $v['config']['limit'] = isset($v['config']['limit']) ? $v['config']['limit'] : 20;
                             } elseif ($v['config']['filter'] == 'feedback') {
                                 /* 20151021添加feeback filter */
                                 $c_arr = $classify->toTree($c_arr);
                                 $templates->unsetFalseClassify($c_arr, array(5, 9));
                                 $templates->unsetLastClassify($c_arr);
                                 $c_arr = array_merge($c_arr);
                             } elseif ($v['config']['filter'] == 'ALL') {
                                 $c_arr = $classify->toTree($c_arr);
                                 $templates->unsetFalseClassify($c_arr, array(1, 2, 3, 4, 5, 6));
                                 $templates->unsetLastClassify($c_arr);
                                 $c_arr = array_merge($c_arr);
                                 $v['config']['limit'] = isset($v['config']['limit']) ? $v['config']['limit'] : 20;
                             } else {
                                 $c_arr = $classify->toTree($c_arr);
                                 $templates->unsetFalseClassify($c_arr, array(1, 2, 3, 4));
                                 $templates->unsetLastClassify($c_arr);
                                 if (is_array($c_arr)) {
                                     $c_arr = array_merge($c_arr);
                                 }
                                 $v['config']['limit'] = isset($v['config']['limit']) ? $v['config']['limit'] : 20;
                             }
                         } else {
                             $c_arr = $classify->toTree($c_arr);
                             $templates->unsetFalseClassify($c_arr, array(1, 2, 3));
                             $templates->unsetLastClassify($c_arr);
                             $c_arr = array_merge($c_arr);
                             $v['config']['limit'] = isset($v['config']['limit']) ? $v['config']['limit'] : 20;
                         }
                         if (count($c_arr)) {
                             $v['config']['id'] = $c_arr[0]['id'];
                         }
                     } else {
                         if (isset($v['config']['filter'])) {
                             if ($v['config']['filter'] == 'page') {
                                 $v['config']['id'] = Classify::where('cus_id', $this->cus_id)->where('type', 4)->where($this->type . '_show', 1)->pluck('id');
                             } elseif ($v['config']['filter'] == 'list') {
                                 $v['config']['id'] = Classify::where('cus_id', $this->cus_id)->whereIn('type', array(1, 2, 3))->where($this->type . '_show', 1)->pluck('id');
                                 $v['config']['limit'] = isset($v['config']['limit']) ? $v['config']['limit'] : 20;
                             } elseif ($v['config']['filter'] == 'feedback') {
                                 /* 20151021添加feeback filter */
                                 $v['config']['id'] = Classify::where('cus_id', $this->cus_id)->whereIn('type', array(5, 9))->where($this->type . '_show', 1)->pluck('id');
                             } elseif ($v['config']['filter'] == 'ALL') {
                                 $v['config']['id'] = Classify::where('cus_id', $this->cus_id)->whereIn('type', array(1, 2, 3, 4, 5, 6))->where($this->type . '_show', 1)->pluck('id');
                                 $v['config']['limit'] = isset($v['config']['limit']) ? $v['config']['limit'] : 20;
                             } else {
                                 $v['config']['id'] = Classify::where('cus_id', $this->cus_id)->whereIn('type', array(1, 2, 3, 4))->where($this->type . '_show', 1)->pluck('id');
                                 $v['config']['limit'] = isset($v['config']['limit']) ? $v['config']['limit'] : 20;
                             }
                         } else {
                             $v['config']['id'] = Classify::where('cus_id', $this->cus_id)->whereIn('type', array(1, 2, 3))->where($this->type . '_show', 1)->pluck('id');
                             $v['config']['limit'] = isset($v['config']['limit']) ? $v['config']['limit'] : 20;
                         }
                     }
                     break;
                 case 'page':
                     if (isset($v['config']['mustchild']) && $v['config']['mustchild'] == true) {
                         $c_arr = Classify::where('cus_id', $this->cus_id)->where('type', 4)->where($this->type . '_show', 1)->get()->toArray();
                         $c_arr = $classify->toTree($c_arr);
                         $templates->unsetLastClassify($c_arr);
                         $c_arr = array_merge($c_arr);
                         if (count($c_arr)) {
                             $v['config']['id'] = $c_arr[0]['id'];
                         }
                     } else {
                         $v['config']['id'] = Classify::where('cus_id', $this->cus_id)->where('type', 4)->where($this->type . '_show', 1)->pluck('id');
                     }
                     break;
                 case 'navs':
                     if (isset($v['config']['mustchild']) && $v['config']['mustchild'] == true) {
                         if (isset($v['config']['filter'])) {
                             if ($v['config']['filter'] == 'page') {
                                 $c_arr = $classify->toTree($c_arr);
                                 $templates->unsetFalseClassify($c_arr, array(4));
                                 $templates->unsetLastClassify($c_arr);
                                 $c_arr = array_merge($c_arr);
                             } elseif ($v['config']['filter'] == 'list') {
                                 $c_arr = $classify->toTree($c_arr);
                                 $templates->unsetFalseClassify($c_arr, array(1, 2, 3));
                                 $templates->unsetLastClassify($c_arr);
                                 $c_arr = array_merge($c_arr);
                                 $v['config']['limit'] = isset($v['config']['limit']) ? $v['config']['limit'] : 20;
                             } elseif ($v['config']['filter'] == 'ALL') {
                                 $c_arr = $classify->toTree($c_arr);
                                 $templates->unsetFalseClassify($c_arr, array(1, 2, 3, 4, 6));
                                 $templates->unsetLastClassify($c_arr);
                                 $c_arr = array_merge($c_arr);
                                 $v['config']['limit'] = isset($v['config']['limit']) ? $v['config']['limit'] : 20;
                             } else {
                                 $c_arr = $classify->toTree($c_arr);
                                 $templates->unsetFalseClassify($c_arr, array(1, 2, 3, 4));
                                 $templates->unsetLastClassify($c_arr);
                                 $c_arr = array_merge($c_arr);
                                 $v['config']['limit'] = isset($v['config']['limit']) ? $v['config']['limit'] : 20;
                             }
                         } else {
                             $c_arr = $classify->toTree($c_arr);
                             $templates->unsetFalseClassify($c_arr, array(1, 2, 3));
                             $templates->unsetLastClassify($c_arr);
                             $c_arr = array_merge($c_arr);
                             $v['config']['limit'] = isset($v['config']['limit']) ? $v['config']['limit'] : 20;
                         }
                     } else {
                         if (isset($v['config']['filter'])) {
                             if ($v['config']['filter'] == 'page') {
                                 $c_arr[0]['id'] = Classify::where('cus_id', $this->cus_id)->where('type', 4)->where($this->type . '_show', 1)->pluck('id');
                             } elseif ($v['config']['filter'] == 'list') {
                                 $c_arr[0]['id'] = Classify::where('cus_id', $this->cus_id)->whereIn('type', array(1, 2, 3))->where($this->type . '_show', 1)->pluck('id');
                                 $v['config']['limit'] = isset($v['config']['limit']) ? $v['config']['limit'] : 20;
                             } elseif ($v['config']['filter'] == 'ALL') {
                                 $c_arr[0]['id'] = Classify::where('cus_id', $this->cus_id)->whereIn('type', array(1, 2, 3, 4, 6))->where($this->type . '_show', 1)->pluck('id');
                                 $v['config']['limit'] = isset($v['config']['limit']) ? $v['config']['limit'] : 20;
                             } else {
                                 $c_arr[0]['id'] = Classify::where('cus_id', $this->cus_id)->whereIn('type', array(1, 2, 3, 4))->where($this->type . '_show', 1)->pluck('id');
                                 $v['config']['limit'] = isset($v['config']['limit']) ? $v['config']['limit'] : 20;
                             }
                         } else {
                             $c_arr[0]['id'] = Classify::where('cus_id', $this->cus_id)->whereIn('type', array(1, 2, 3))->where($this->type . '_show', 1)->pluck('id');
                             $v['config']['limit'] = isset($v['config']['limit']) ? $v['config']['limit'] : 20;
                         }
                     }
                     $ids = "";
                     $num = $v['config']['limit'];
                     if (count($c_arr)) {
                         $ids = array();
                         for ($i = 0; $i < $num; $i++) {
                             $ids[$i] = $c_arr[0]['id'];
                         }
                     }
                     $v['config']['ids'] = $ids;
                     break;
                 case 'form':
                     //                        var_dump($v);
                     //                        exit;
                     break;
                 default:
                     break;
             }
         }
     }
     return $result;
 }
Ejemplo n.º 2
0
 /**
  * 合并页面请求,合并json和数据库内容,返回合并后的数组
  *
  * @param string $themename 模版名称
  * @param string $pagename 页面名称
  * @return array 合并后的数组
  */
 public function pagedata($pagename)
 {
     if ($this->type == 'pc') {
         $tpl_id = websiteInfo::where('id', $this->cus_id)->pluck('pc_tpl_id');
     } else {
         $tpl_id = websiteInfo::where('id', $this->cus_id)->pluck('mobile_tpl_id');
     }
     $website_confige = WebsiteConfig::where('cus_id', $this->cus_id)->where('key', $pagename)->where('type', 1)->where('template_id', $tpl_id)->pluck('value');
     $website_confige_value = unserialize($website_confige);
     $json_path = public_path('templates/' . $this->themename . '/json/' . $pagename . '.json');
     $json = file_exists($json_path) ? file_get_contents($json_path) : '{}';
     if ($website_confige_value) {
         $default = json_decode(trim($json), TRUE);
         $result = $this->array_merge_recursive_new($default, $website_confige_value);
         //$result = $website_confige_value;
         $this->replaceUrl($result);
         $result = $this->dataDeal($result);
         foreach ($result as &$v) {
             if ($v['type'] == 'list') {
                 if (isset($v['config']['filter'])) {
                     if ($v['config']['filter'] == 'list') {
                         $v['config']['limit'] = isset($v['config']['limit']) ? $v['config']['limit'] : 20;
                     } else {
                         $v['config']['limit'] = isset($v['config']['limit']) ? $v['config']['limit'] : 20;
                     }
                 } else {
                     $v['config']['limit'] = isset($v['config']['limit']) ? $v['config']['limit'] : 20;
                 }
             } elseif ($v['type'] == 'navs') {
                 $v['config']['ids'] = array_merge($v['config']['ids']);
             }
         }
     } else {
         $result = json_decode(trim($json), TRUE);
         if ($result === NULL) {
             dd("{$pagename}.json文件错误");
         }
         $this->replaceUrl($result);
         //dd($result);
         $result = $this->dataDeal($result);
         $classify = new Classify();
         $templates = new TemplatesController();
         $c_arr = Classify::where('cus_id', $this->cus_id)->whereIn('type', array(1, 2, 3, 4, 5, 6))->where('pc_show', '=', 1)->get()->toArray();
         foreach ($result as &$v) {
             if ($v['type'] == 'list') {
                 if (isset($v['config']['mustchild']) && $v['config']['mustchild'] == true) {
                     if (isset($v['config']['filter'])) {
                         if ($v['config']['filter'] == 'page') {
                             $c_arr = $classify->toTree($c_arr);
                             $templates->unsetFalseClassify($c_arr, array(4));
                             $templates->unsetLastClassify($c_arr);
                             $c_arr = array_merge($c_arr);
                         } elseif ($v['config']['filter'] == 'list') {
                             $c_arr = $classify->toTree($c_arr);
                             $templates->unsetFalseClassify($c_arr, array(1, 2, 3));
                             $templates->unsetLastClassify($c_arr);
                             $c_arr = array_merge($c_arr);
                             $v['config']['limit'] = isset($v['config']['limit']) ? $v['config']['limit'] : 20;
                         } elseif ($v['config']['filter'] == 'feedback') {
                             $c_arr = $classify->toTree($c_arr);
                             $templates->unsetFalseClassify($c_arr, array(5));
                             $templates->unsetLastClassify($c_arr);
                             $c_arr = array_merge($c_arr);
                         } elseif ($v['config']['filter'] == 'ALL') {
                             $c_arr = $classify->toTree($c_arr);
                             $templates->unsetFalseClassify($c_arr, array(1, 2, 3, 4, 5, 6));
                             $templates->unsetLastClassify($c_arr);
                             $c_arr = array_merge($c_arr);
                             $v['config']['limit'] = isset($v['config']['limit']) ? $v['config']['limit'] : 20;
                         } else {
                             $c_arr = $classify->toTree($c_arr);
                             $templates->unsetFalseClassify($c_arr, array(1, 2, 3, 4));
                             $templates->unsetLastClassify($c_arr);
                             $c_arr = array_merge($c_arr);
                             $v['config']['limit'] = isset($v['config']['limit']) ? $v['config']['limit'] : 20;
                         }
                     } else {
                         $c_arr = $classify->toTree($c_arr);
                         $templates->unsetFalseClassify($c_arr, array(1, 2, 3));
                         $templates->unsetLastClassify($c_arr);
                         $c_arr = array_merge($c_arr);
                         $v['config']['limit'] = isset($v['config']['limit']) ? $v['config']['limit'] : 20;
                     }
                     if (count($c_arr)) {
                         $v['config']['id'] = $c_arr[0]['id'];
                     }
                 } else {
                     if (isset($v['config']['filter'])) {
                         if ($v['config']['filter'] == 'page') {
                             $v['config']['id'] = Classify::where('cus_id', $this->cus_id)->where('type', 4)->where('pc_show', 1)->pluck('id');
                         } elseif ($v['config']['filter'] == 'list') {
                             $v['config']['id'] = Classify::where('cus_id', $this->cus_id)->whereIn('type', array(1, 2, 3))->where('pc_show', 1)->pluck('id');
                             $v['config']['limit'] = isset($v['config']['limit']) ? $v['config']['limit'] : 20;
                         } elseif ($v['config']['filter'] == 'feedback') {
                             $v['config']['id'] = Classify::where('cus_id', $this->cus_id)->whereIn('type', array(5))->where('pc_show', 1)->pluck('id');
                         } elseif ($v['config']['filter'] == 'ALL') {
                             $v['config']['id'] = Classify::where('cus_id', $this->cus_id)->whereIn('type', array(1, 2, 3, 4, 5, 6))->where('pc_show', 1)->pluck('id');
                             $v['config']['limit'] = isset($v['config']['limit']) ? $v['config']['limit'] : 20;
                         } else {
                             $v['config']['id'] = Classify::where('cus_id', $this->cus_id)->whereIn('type', array(1, 2, 3, 4))->where('pc_show', 1)->pluck('id');
                             $v['config']['limit'] = isset($v['config']['limit']) ? $v['config']['limit'] : 20;
                         }
                     } else {
                         $v['config']['id'] = Classify::where('cus_id', $this->cus_id)->whereIn('type', array(1, 2, 3))->where('pc_show', 1)->pluck('id');
                         $v['config']['limit'] = isset($v['config']['limit']) ? $v['config']['limit'] : 20;
                     }
                 }
             } elseif ($v['type'] == 'page') {
                 if (isset($v['config']['mustchild']) && $v['config']['mustchild'] == true) {
                     $c_arr = Classify::where('cus_id', $this->cus_id)->where('type', 4)->where('pc_show', 1)->get()->toArray();
                     $c_arr = $classify->toTree($c_arr);
                     $templates->unsetLastClassify($c_arr);
                     $c_arr = array_merge($c_arr);
                     if (count($c_arr)) {
                         $v['config']['id'] = $c_arr[0]['id'];
                     }
                 } else {
                     $v['config']['id'] = Classify::where('cus_id', $this->cus_id)->where('type', 4)->where('pc_show', 1)->pluck('id');
                 }
             } elseif ($v['type'] == 'navs') {
                 if (isset($v['config']['mustchild']) && $v['config']['mustchild'] == true) {
                     if (isset($v['config']['filter'])) {
                         if ($v['config']['filter'] == 'page') {
                             $c_arr = $classify->toTree($c_arr);
                             $templates->unsetFalseClassify($c_arr, array(4));
                             $templates->unsetLastClassify($c_arr);
                             $c_arr = array_merge($c_arr);
                         } elseif ($v['config']['filter'] == 'list') {
                             $c_arr = $classify->toTree($c_arr);
                             $templates->unsetFalseClassify($c_arr, array(1, 2, 3));
                             $templates->unsetLastClassify($c_arr);
                             $c_arr = array_merge($c_arr);
                             $v['config']['limit'] = isset($v['config']['limit']) ? $v['config']['limit'] : 20;
                         } elseif ($v['config']['filter'] == 'ALL') {
                             $c_arr = $classify->toTree($c_arr);
                             $templates->unsetFalseClassify($c_arr, array(1, 2, 3, 4, 6));
                             $templates->unsetLastClassify($c_arr);
                             $c_arr = array_merge($c_arr);
                             $v['config']['limit'] = isset($v['config']['limit']) ? $v['config']['limit'] : 20;
                         } else {
                             $c_arr = $classify->toTree($c_arr);
                             $templates->unsetFalseClassify($c_arr, array(1, 2, 3, 4));
                             $templates->unsetLastClassify($c_arr);
                             $c_arr = array_merge($c_arr);
                             $v['config']['limit'] = isset($v['config']['limit']) ? $v['config']['limit'] : 20;
                         }
                     } else {
                         $c_arr = $classify->toTree($c_arr);
                         $templates->unsetFalseClassify($c_arr, array(1, 2, 3));
                         $templates->unsetLastClassify($c_arr);
                         $c_arr = array_merge($c_arr);
                         $v['config']['limit'] = isset($v['config']['limit']) ? $v['config']['limit'] : 20;
                     }
                 } else {
                     if (isset($v['config']['filter'])) {
                         if ($v['config']['filter'] == 'page') {
                             $c_arr[0]['id'] = Classify::where('cus_id', $this->cus_id)->where('type', 4)->where('pc_show', 1)->pluck('id');
                         } elseif ($v['config']['filter'] == 'list') {
                             $c_arr[0]['id'] = Classify::where('cus_id', $this->cus_id)->whereIn('type', array(1, 2, 3))->where('pc_show', 1)->pluck('id');
                             $v['config']['limit'] = isset($v['config']['limit']) ? $v['config']['limit'] : 20;
                         } elseif ($v['config']['filter'] == 'ALL') {
                             $c_arr[0]['id'] = Classify::where('cus_id', $this->cus_id)->whereIn('type', array(1, 2, 3, 4, 6))->where('pc_show', 1)->pluck('id');
                             $v['config']['limit'] = isset($v['config']['limit']) ? $v['config']['limit'] : 20;
                         } else {
                             $c_arr[0]['id'] = Classify::where('cus_id', $this->cus_id)->whereIn('type', array(1, 2, 3, 4))->where('pc_show', 1)->pluck('id');
                             $v['config']['limit'] = isset($v['config']['limit']) ? $v['config']['limit'] : 20;
                         }
                     } else {
                         $c_arr[0]['id'] = Classify::where('cus_id', $this->cus_id)->whereIn('type', array(1, 2, 3))->where('pc_show', 1)->pluck('id');
                         $v['config']['limit'] = isset($v['config']['limit']) ? $v['config']['limit'] : 20;
                     }
                 }
                 $ids = "";
                 $num = $v['config']['limit'];
                 if (count($c_arr)) {
                     $ids = array();
                     for ($i = 0; $i < $num; $i++) {
                         $ids[$i] = $c_arr[0]['id'];
                     }
                 }
                 $v['config']['ids'] = $ids;
             }
         }
     }
     return $result;
 }