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.

210 lines
6.0 KiB

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