Index.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | A3Mall
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2020 http://www.a3-mall.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Author: xzncit <158373108@qq.com>
  8. // +----------------------------------------------------------------------
  9. namespace app\admin\controller\wechat;
  10. use app\admin\controller\Auth;
  11. use app\common\library\wechat\mp\Menu as WechatMenu;
  12. use think\facade\Request;
  13. use mall\response\Response;
  14. use think\facade\View;
  15. use app\common\models\Setting as SettingModel;
  16. use app\common\models\wechat\WechatKeys as WechatKeysModel;
  17. class Index extends Auth {
  18. /**
  19. * 接口设置
  20. * @return string|\think\response\Json
  21. * @throws \think\db\exception\DataNotFoundException
  22. * @throws \think\db\exception\DbException
  23. * @throws \think\db\exception\ModelNotFoundException
  24. */
  25. public function api(){
  26. if(Request::isAjax()) {
  27. SettingModel::saveData("wechat",Request::param());
  28. return Response::returnArray("操作成功!");
  29. }
  30. $data = SettingModel::getArrayData("wechat");
  31. $data["ip"] = gethostbyname(Request::host());
  32. $data["url"] = createUrl("api/wechat.index/",[],false,true);
  33. return View::fetch("",[ "data"=>$data ]);
  34. }
  35. /**
  36. * 支付设置
  37. * @return string|\think\response\Json
  38. * @throws \think\db\exception\DataNotFoundException
  39. * @throws \think\db\exception\DbException
  40. * @throws \think\db\exception\ModelNotFoundException
  41. */
  42. public function pay(){
  43. if(Request::isAjax()){
  44. SettingModel::saveData("wepay",Request::post());
  45. return Response::returnArray("操作成功!");
  46. }
  47. return View::fetch("",[ "data"=>SettingModel::getArrayData("wepay") ]);
  48. }
  49. /**
  50. * 设置公众号菜单
  51. * @return string|\think\response\Json
  52. * @throws \think\db\exception\DataNotFoundException
  53. * @throws \think\db\exception\DbException
  54. * @throws \think\db\exception\ModelNotFoundException
  55. */
  56. public function menu(){
  57. if(Request::isAjax()){
  58. try {
  59. $post = Request::post("post");
  60. SettingModel::saveData("wechat_menu",$post);
  61. WechatMenu::save($post);
  62. }catch (\Exception $e){
  63. return Response::returnArray($e->getMessage(),0);
  64. }
  65. return Response::returnArray("操作成功");
  66. }
  67. return View::fetch("",[
  68. "data"=>SettingModel::getStringData("wechat_menu"),
  69. "keys"=>WechatKeysModel::where("keys","not in","default,subscribe")->select()->toArray()
  70. ]);
  71. }
  72. }