123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- <?php
- namespace App\Http\Controllers\Api;
- use App\Models\WxIcon;
- use App\Models\WxPage;
- use Illuminate\Http\Request;
- class PageController extends BaseController{
- /** tabs页面模板
- * @param Request $request
- */
- public function tabs(Request $request){
- $id = $request->id;
- if(_empty_($id)){
- return $this->fail(200001);
- }
- $page = WxPage::find($id);
- if(_empty_($page)){
- return $this->fail(200003);
- }
- if(!in_array($page->type, [0, 1])){
- return $this->fail(200008);
- }
- $right = $page->right;
- $config = $page->config;
- $result = [
- 'style' => $page->type,
- 'header' => [
- 'left' => [],
- 'center' => $page->title,
- 'right' => []
- ],
- 'config' => [
- ]
- ];
- if($right){
- $right = json_decode($right, true);
- if($right){
- $result['header']['right'] = WxIcon::find($right[0]);
- }
- }
- $tabs = [];
- $tab_pages = [];
- if($config){
- $config_arr = json_decode($config, true);
- $i = 0;
- foreach ($config_arr as $tab){
- $tabs[] = [
- 'title' => $tab['name']
- ];
- $icon_ids = $tab['tab'];
- $tab_pages[$i] = [];
- if($icon_ids){
- $icon_ids = explode(',', $icon_ids);
- foreach ($icon_ids as $icon){
- $icon_obj = WxIcon::find($icon);
- $tab_pages[$i][] = $icon_obj;
- }
- }
- $i++;
- }
- }
- $result['config']['tabs'] = $tabs;
- $result['config']['tab_pages'] = $tab_pages;
- return $this->success($result);
- }
- /** qrcodes页面模板
- * @param Request $request
- */
- public function qrcodes(Request $request){
- $id = $request->id;
- if(_empty_($id)){
- return $this->fail(200001);
- }
- $page = WxPage::find($id);
- if(_empty_($page)){
- return $this->fail(200003);
- }
- if(!in_array($page->type, [3])){
- return $this->fail(200008);
- }
- $right = $page->right;
- $config = $page->config;
- $result = [
- 'style' => $page->type,
- 'header' => [
- 'left' => [],
- 'center' => $page->title,
- 'right' => []
- ],
- 'config' => [
- ]
- ];
- if($right){
- $right = json_decode($right, true);
- if($right){
- $result['header']['right'] = WxIcon::find($right[0]);
- }
- }
- $menus = [];
- if($config){
- $config = json_decode($config, true);
- if($config['tabs']){
- if(is_string($config['tabs'])){
- $config['tabs'] = json_decode($config['tabs'], true);
- }
- }else{
- $config['tabs'] = [];
- }
- $result['config'] = $config;
- }
- return $this->success($result);
- }
- /** menus页面模板
- * @param Request $request
- */
- public function menus(Request $request){
- $id = $request->id;
- if(_empty_($id)){
- return $this->fail(200001);
- }
- $page = WxPage::find($id);
- if(_empty_($page)){
- return $this->fail(200003);
- }
- if(!in_array($page->type, [2])){
- return $this->fail(200008);
- }
- $right = $page->right;
- $config = $page->config;
- $result = [
- 'style' => $page->type,
- 'header' => [
- 'left' => [],
- 'center' => $page->title,
- 'right' => []
- ],
- 'config' => [
- ]
- ];
- if($right){
- $right = json_decode($right, true);
- if($right){
- $result['header']['right'] = WxIcon::find($right[0]);
- }
- }
- $menus = [];
- if($config){
- $config_arr = explode(',', $config);
- $i = 0;
- foreach ($config_arr as $icon_id){
- $menus[] = WxIcon::find($icon_id);
- $i++;
- }
- }
- $result['config']['menus'] = $menus;
- return $this->success($result);
- }
- }
|