ConfigController.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <?php
  2. namespace app\admin\controller;
  3. use think\exception\ValidateException;
  4. use app\model\Config;
  5. use app\model\MemberAuthGroup;
  6. use app\model\OrderStatus;
  7. use app\samos\wechat\SubscribeMessage;
  8. use app\samos\wechat\Messagetpl;
  9. class ConfigController extends Base
  10. {
  11. public function update()
  12. {
  13. $config = $this->request->post();
  14. $mo = $config['mo'];
  15. if (empty($mo)) {
  16. $mo = 'common';
  17. }
  18. if ($mo == 'common') {
  19. if (!empty($config['keyword'])) {
  20. $config['keyword'] = implode(',', $config['keyword']);
  21. }
  22. }
  23. if ($mo == 'collect') {
  24. if (!empty($config['collect_type'])) {
  25. $config['collect_type'] = implode(',', $config['collect_type']);
  26. }
  27. }
  28. if ($mo == 'miniprogram') {
  29. if ($config['app_id'] == $config['techapp_id']) {
  30. throw new ValidateException("用户端小程序AppId和师傅端AppId不能相同!");
  31. }
  32. }
  33. $configstr = serialize($config);
  34. if (empty($config['id'])) {
  35. $data["weid"] = weid();
  36. $data["module"] = $mo;
  37. $data["status"] = 1;
  38. $data["settings"] = $configstr;
  39. Config::create($data);
  40. } else {
  41. Config::update(['settings' => $configstr], ['id' => $config['id']]);
  42. }
  43. return $this->json(['msg' => '操作成功']);
  44. }
  45. function getInfo()
  46. {
  47. $mo = input('post.mo', '', 'serach_in');
  48. if (empty($mo)) {
  49. $mo = 'common';
  50. }
  51. $res = Config::getconfig($mo);
  52. $res['mo'] = $mo;
  53. if ($mo == 'common') {
  54. $res['logo'] = toimg($res['logo']);
  55. if (!empty($res['keyword'])) {
  56. $res['keyword'] = explode(',', $res['keyword']);
  57. }
  58. $res['autoapi'] = gethost() . scriptPath() . '/public/index.php/index/auto?i=' . weid();
  59. }
  60. if ($mo == 'mp') {
  61. $res['h5url'] = gethost() . scriptPath() . "/h5/?i=" . weid();
  62. }
  63. if ($mo == 'messagetpl') {
  64. $res['ordertploption'] = getordertploption();
  65. }
  66. if ($mo == 'collect') {
  67. if (empty($res['collect_type'])) {
  68. $res['collect_type'] = ['bank'];
  69. } else {
  70. if (!empty($res['collect_type'])) {
  71. $res['collect_type'] = explode(',', $res['collect_type']);
  72. }
  73. }
  74. }
  75. return $this->json(['data' => $res]);
  76. }
  77. function getField()
  78. {
  79. $data['member_auth_group'] = MemberAuthGroup::getpcarray();
  80. $data['collect_typearray'] = getcollect_type();
  81. return $this->json(['data' => $data]);
  82. }
  83. public function getsubscribemessage()
  84. {
  85. $tpl = input('post.tpl', '', 'serach_in');
  86. $mo = 'subscribemessage';
  87. $res = Config::getconfig($mo);
  88. $res['mo'] = $mo;
  89. $app = \app\samos\wechat\MiniProgram::makemini();
  90. $sm = SubscribeMessage::addparam($tpl);
  91. $Templates = $app->subscribe_message->getTemplates();
  92. foreach ($Templates['data'] as $vo) {
  93. if ($vo['title'] == $sm['title']) {
  94. $res[$tpl] = $vo['priTmplId'];
  95. break;
  96. }
  97. }
  98. if (empty($res[$tpl])) {
  99. $result = $app->subscribe_message->addTemplate($sm['tid'], $sm['kidList'], $sm['sceneDesc']);
  100. if ($result['errmsg'] == 'ok') {
  101. $res[$tpl] = $result['priTmplId'];
  102. } else {
  103. throw new ValidateException("获取失败!" . $result['errcode']);
  104. }
  105. }
  106. if (empty($res['id'])) {
  107. $data["weid"] = weid();
  108. $data["module"] = $mo;
  109. $data["status"] = 1;
  110. $data["settings"] = serialize($res);
  111. Config::create($data);
  112. } else {
  113. Config::update(['settings' => serialize($res)], ['id' => $res['id']]);
  114. }
  115. $res = Config::getconfig($mo);
  116. return $this->json(['data' => $res]);
  117. }
  118. public function getmessagetpl()
  119. {
  120. $tpl = input('post.tpl', '', 'serach_in');
  121. $mo = 'messagetpl';
  122. $res = Config::getconfig($mo);
  123. $res['mo'] = $mo;
  124. $app = Messagetpl::maketpl();
  125. $sm = Messagetpl::addparam($tpl);
  126. $Templates = $app->getAllPrivateTemplate();
  127. //var_dump($Templates);
  128. $is_oldtpl = true;
  129. foreach ($Templates['template_list'] as $vo) {
  130. if ($vo['title'] == $sm['title']) {
  131. $res[$tpl] = $vo['template_id'];
  132. $is_oldtpl = false;
  133. break;
  134. }
  135. }
  136. if ($is_oldtpl) {
  137. $result = $app->addTemplate($sm['tid'], $sm['keyword_name_list']);
  138. if ($result['errmsg'] == 'ok') {
  139. $res[$tpl] = $result['template_id'];
  140. } else {
  141. throw new ValidateException("获取失败!" . $result['errcode']);
  142. }
  143. }
  144. if (empty($res['id'])) {
  145. $data["weid"] = weid();
  146. $data["module"] = $mo;
  147. $data["status"] = 1;
  148. $data["settings"] = serialize($res);
  149. Config::create($data);
  150. } else {
  151. Config::update(['settings' => serialize($res)], ['id' => $res['id']]);
  152. }
  153. $res = Config::getconfig($mo);
  154. return $this->json(['data' => $res]);
  155. }
  156. }