控制台应用,yzncms本身基于tp5.1框架,里面的队列用不了,bug,坑
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

Formguide.php 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Yzncms [ 御宅男工作室 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2018 http://yzncms.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: 御宅男 <530765310@qq.com>
  10. // +----------------------------------------------------------------------
  11. // +----------------------------------------------------------------------
  12. // | 表单前台管理
  13. // +----------------------------------------------------------------------
  14. namespace app\index\controller;
  15. use addons\formguide\library\Service;
  16. use addons\formguide\model\Formguide as FormguideModel;
  17. use app\member\controller\MemberBase;
  18. use think\Db;
  19. use think\Validate;
  20. class Formguide extends MemberBase
  21. {
  22. //当前表单ID
  23. public $formid;
  24. //表单模型缓存
  25. protected $tableName;
  26. //模型信息
  27. protected $modelInfo = [];
  28. //配置
  29. protected $setting = [];
  30. protected $noNeedLogin = ['*'];
  31. protected $noNeedRight = [];
  32. protected function initialize()
  33. {
  34. parent::initialize();
  35. $this->formid = $this->request->param('id/d', 0);
  36. //模型
  37. $this->modelInfo = Db::name('model')->where('id', $this->formid)->where('module', 'formguide')->find();
  38. if (empty($this->modelInfo)) {
  39. $this->error('该表单不存在或者已经关闭!');
  40. }
  41. if (!empty($this->formid)) {
  42. $model_cache = cache("Model");
  43. $this->tableName = $model_cache[$this->formid]['tablename'];
  44. }
  45. //配置
  46. $this->modelInfo['setting'] = $this->setting = unserialize($this->modelInfo['setting']);
  47. $this->FormguideModel = new FormguideModel;
  48. $this->assign('id', $this->formid);
  49. }
  50. //显示表单
  51. public function index()
  52. {
  53. //模板
  54. $show_template = $this->setting['show_template'] ? $this->setting['show_template'] : "show";
  55. $modelid = $this->request->param('id/d', 0);
  56. $fieldList = Service::getFieldList($modelid);
  57. $seo = [];
  58. $seo['site_title'] = $this->modelInfo['name'] . "_自定义表单";
  59. $seo['keyword'] = "";
  60. $seo['description'] = $this->modelInfo['description'];
  61. $this->assign([
  62. 'SEO' => $seo,
  63. 'modelInfo' => $this->modelInfo,
  64. 'fieldList' => $fieldList,
  65. ]);
  66. return $this->fetch("{$show_template}");
  67. }
  68. //表单提交
  69. public function post()
  70. {
  71. $token = $this->request->post('__token__');
  72. //验证Token
  73. if (!Validate::make()->check(['__token__' => $token], ['__token__' => 'require|token'])) {
  74. $this->error('令牌错误!', null, ['__token__' => $this->request->token()]);
  75. }
  76. //验证权限
  77. $this->competence();
  78. //提交间隔
  79. if ($this->setting['interval']) {
  80. $formguide = cookie('formguide_' . $this->formid);
  81. if ($formguide) {
  82. $this->error("操作过快,请歇息后再次提交!", null, ['__token__' => $this->request->token()]);
  83. }
  84. }
  85. $data = $this->request->post();
  86. //开启验证码
  87. if ($this->setting['isverify']) {
  88. // 验证码
  89. if (!captcha_check($data['captcha'])) {
  90. $this->error('验证码错误或失效', null, ['__token__' => $this->request->token()]);
  91. }
  92. }
  93. try {
  94. $this->FormguideModel->addFormguideData($this->formid, $data['modelField']);
  95. } catch (\Exception $ex) {
  96. $this->error($ex->getMessage(), null, ['__token__' => $this->request->token()]);
  97. }
  98. if ($this->setting['interval']) {
  99. cookie('formguide_' . $this->formid, 1, $this->setting['interval']);
  100. }
  101. //发送邮件
  102. if ($this->setting['mails']) {
  103. //$ems['email'] = explode(",", $this->setting['mails']);
  104. $ems['email'] = $this->setting['mails'];
  105. $ems['title'] = "[" . $this->modelInfo['name'] . "]表单消息提醒!";
  106. $ems['msg'] = "刚刚有人在[" . $this->modelInfo['name'] . "]中提交了新的信息,请进入后台查看!";
  107. $result = hook('ems_notice', $ems, true, true);
  108. }
  109. //跳转地址
  110. $forward = $this->setting['forward'] ? ((strpos($this->setting['forward'], '://') !== false) ? $this->setting['forward'] : url($this->setting['forward'])) : '';
  111. $this->success('提交成功!', $forward);
  112. }
  113. //验证提交权限
  114. protected function competence()
  115. {
  116. //是否允许游客提交
  117. if ((int) $this->setting['allowunreg'] == 0) {
  118. //判断是否登陆
  119. if (!$this->auth->isLogin()) {
  120. $this->error('该表单不允许游客提交,请登陆后操作!', url('member/Index/login'), null, ['__token__' => $this->request->token()]);
  121. }
  122. }
  123. //是否允许同一IP多次提交
  124. if ((int) $this->setting['allowmultisubmit'] == 0) {
  125. $ip = $this->request->ip();
  126. $count = Db::name($this->tableName)->where("ip", $ip)->count();
  127. if ($count) {
  128. $this->error('你已经提交过了!', null, ['__token__' => $this->request->token()]);
  129. }
  130. }
  131. }
  132. }