ConfigController.php 4.4 KB

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