You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

202 lines
5.8 KiB

7 years ago
7 years ago
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use App\Http\Controllers\Admin\CommonController;
  4. use DB;
  5. use App\Http\Model\WeixinMenu;
  6. use App\Common\WechatMenu;
  7. class WeixinMenuController extends CommonController
  8. {
  9. public function __construct()
  10. {
  11. parent::__construct();
  12. }
  13. public function index()
  14. {
  15. $catlist = WeixinMenu::getList(array('is_show'=>-1));
  16. $data['catlist'] = $catlist;
  17. return view('admin.WeixinMenu.index', $data);
  18. }
  19. public function add()
  20. {
  21. if(!empty($_GET["reid"]))
  22. {
  23. $id = $_GET["reid"];
  24. if(preg_match('/[0-9]*/',$id)){}else{exit;}
  25. if($id!=0)
  26. {
  27. $data['postone'] = object_to_array(DB::table("weixin_menu")->where('id', $id)->first(), 1);
  28. }
  29. $data['id'] = $id;
  30. }
  31. else
  32. {
  33. $data['id'] = 0;
  34. }
  35. return view('admin.WeixinMenu.add', $data);
  36. }
  37. public function doadd()
  38. {
  39. if(!empty($_POST["prid"])){if($_POST["prid"]=="top"){$_POST['pid']=0;}else{$_POST['pid'] = $_POST["prid"];}}//父级栏目id
  40. $_POST['addtime'] = time();//添加时间
  41. unset($_POST["prid"]);
  42. unset($_POST["_token"]);
  43. if(DB::table('weixin_menu')->insert($_POST))
  44. {
  45. success_jump('添加成功!');
  46. }
  47. else
  48. {
  49. error_jump('添加失败!请修改后重新添加');
  50. }
  51. }
  52. public function edit()
  53. {
  54. $id = $_GET["id"];if(preg_match('/[0-9]*/',$id)){}else{exit;}
  55. $data['id'] = $id;
  56. $post = object_to_array(DB::table('weixin_menu')->where('id', $id)->first(), 1);
  57. $reid = $post['pid'];
  58. if($reid!=0){$data['postone'] = object_to_array(DB::table('weixin_menu')->where('id', $reid)->first());}
  59. $data['post'] = $post;
  60. return view('admin.WeixinMenu.edit', $data);
  61. }
  62. public function doedit()
  63. {
  64. if(!empty($_POST["id"])){$id = $_POST["id"];unset($_POST["id"]);}else {$id="";exit;}
  65. $_POST['addtime'] = time(); //添加时间
  66. unset($_POST["_token"]);
  67. if(DB::table('weixin_menu')->where('id', $id)->update($_POST))
  68. {
  69. success_jump('修改成功!', route('admin_weixinmenu'));
  70. }
  71. else
  72. {
  73. error_jump('修改失败!请修改后重新添加');
  74. }
  75. }
  76. public function del()
  77. {
  78. if(!empty($_REQUEST["id"])){$id = $_REQUEST["id"];}else{error_jump('删除失败!请重新提交');} //if(preg_match('/[0-9]*/',$id)){}else{exit;}
  79. if(DB::table('weixin_menu')->where('pid', $id)->first())
  80. {
  81. error_jump('删除失败!请先删除子栏目');
  82. }
  83. else
  84. {
  85. if(DB::table('weixin_menu')->where('id', $id)->delete())
  86. {
  87. success_jump('删除成功');
  88. }
  89. else
  90. {
  91. error_jump('删除失败!请重新提交');
  92. }
  93. }
  94. }
  95. public function createmenu()
  96. {
  97. $catlist = WeixinMenu::getList(array('is_show'=>-1));
  98. $wechat_menu = new WechatMenu(sysconfig('CMS_WX_APPID'),sysconfig('CMS_WX_APPSECRET'));
  99. /* $menu = array(
  100. 'button'=>array();
  101. ); */
  102. $jsonmenu = '
  103. {
  104. "button":[
  105. {
  106. "name":"篮球",
  107. "sub_button":[
  108. {
  109. "type":"click",
  110. "name":"nba",
  111. "key":"V1001_NBA"
  112. },
  113. {
  114. "type":"click",
  115. "name":"cba",
  116. "key":"V1001_CBA"
  117. }
  118. ]
  119. },
  120. {
  121. "name":"体育",
  122. "sub_button":[
  123. {
  124. "type":"view",
  125. "name":"url",
  126. "url":"http://m.hao123.com/a/tianqi"
  127. },
  128. {
  129. "type":"click",
  130. "name":"排球",
  131. "key":"V1001_PAIQIU"
  132. },
  133. {
  134. "type":"click",
  135. "name":"网球",
  136. "key":"V1001_WANGQIU"
  137. },
  138. {
  139. "type":"click",
  140. "name":"乒乓球",
  141. "key":"V1001_PPQ"
  142. },
  143. {
  144. "type":"click",
  145. "name":"台球",
  146. "key":"V1001_TAIQIU"
  147. }
  148. ]
  149. },
  150. {
  151. "name":"新闻",
  152. "sub_button":[
  153. {
  154. "type":"click",
  155. "name":"国内新闻",
  156. "key":"V1001_GNNEWS"
  157. },
  158. {
  159. "type":"click",
  160. "name":"国际新闻",
  161. "key":"V1001_GJNEWS"
  162. },
  163. {
  164. "type":"click",
  165. "name":"地方新闻",
  166. "key":"V1001_AREANEWS"
  167. },
  168. {
  169. "type":"click",
  170. "name":"家庭新闻",
  171. "key":"V1001_HOMENEWS"
  172. }
  173. ]
  174. }
  175. ]
  176. }';
  177. $wechat_menu->create_menu($jsonmenu);
  178. success_jump('修改菜单,生成后,不会立即显示,有24小时的缓存,除非你取消关注,然后重新关注!', route('admin_weixinmenu'),5);
  179. }
  180. }