Nenhuma descrição
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

FormLogic.php 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. /**
  3. * 易优CMS
  4. * ============================================================================
  5. * 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
  6. * 网站地址: http://www.eyoucms.com
  7. * ----------------------------------------------------------------------------
  8. * 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
  9. * ============================================================================
  10. * Author: 小虎哥 <1105415366@qq.com>
  11. * Date: 2023-3-8
  12. */
  13. namespace app\admin\logic;
  14. use think\Model;
  15. use think\Db;
  16. class FormLogic extends Model
  17. {
  18. public $form_db;
  19. public $main_lang = 'cn';
  20. public $admin_lang = 'cn';
  21. /**
  22. * 初始化操作
  23. */
  24. public function initialize() {
  25. parent::initialize();
  26. $this->form_db = Db::name('form');
  27. $this->main_lang = get_main_lang();
  28. $this->admin_lang = get_admin_lang();
  29. }
  30. /**
  31. * 同步新增表单ID到多语言的模板变量里
  32. */
  33. public function syn_add_language_form($form_id)
  34. {
  35. /*单语言情况下不执行多语言代码*/
  36. if (!is_language() || tpCache('language.language_split')) {
  37. return true;
  38. }
  39. /*--end*/
  40. $attr_group = 'form';
  41. $languageRow = Db::name('language')->field('mark')->order('id asc')->select();
  42. if (!empty($languageRow) && $this->admin_lang == $this->main_lang) { // 当前语言是主体语言,即语言列表最早新增的语言
  43. $result = $this->form_db->find($form_id);
  44. $attr_name = 'form'.$form_id;
  45. $r = Db::name('language_attribute')->save([
  46. 'attr_title' => $result['form_name'],
  47. 'attr_name' => $attr_name,
  48. 'attr_group' => $attr_group,
  49. 'add_time' => getTime(),
  50. 'update_time' => getTime(),
  51. ]);
  52. if (false !== $r) {
  53. $data = [];
  54. foreach ($languageRow as $key => $val) {
  55. /*同步新分组到其他语言分组列表*/
  56. if ($val['mark'] != $this->admin_lang) {
  57. $addsaveData = $result;
  58. $addsaveData['lang'] = $val['mark'];
  59. $addsaveData['form_name'] = $val['mark'].$addsaveData['form_name'];
  60. unset($addsaveData['form_id']);
  61. $form_id = $this->form_db->insertGetId($addsaveData);
  62. }
  63. /*--end*/
  64. /*所有语言绑定在主语言的ID容器里*/
  65. $data[] = [
  66. 'attr_name' => $attr_name,
  67. 'attr_value' => $form_id,
  68. 'lang' => $val['mark'],
  69. 'attr_group' => $attr_group,
  70. 'add_time' => getTime(),
  71. 'update_time' => getTime(),
  72. ];
  73. /*--end*/
  74. }
  75. if (!empty($data)) {
  76. model('LanguageAttr')->saveAll($data);
  77. }
  78. }
  79. }
  80. }
  81. /**
  82. * 同步新增表单属性ID到多语言的模板变量里
  83. */
  84. public function syn_add_language_attribute($attr_id)
  85. {
  86. /*单语言情况下不执行多语言代码*/
  87. if (!is_language() || tpCache('language.language_split')) {
  88. return true;
  89. }
  90. /*--end*/
  91. $attr_group = 'form_attribute';
  92. $languageRow = Db::name('language')->field('mark')->order('id asc')->select();
  93. if (!empty($languageRow) && $this->admin_lang == $this->main_lang) { // 当前语言是主体语言,即语言列表最早新增的语言
  94. $result = Db::name('guestbook_attribute')->find($attr_id);
  95. $attr_name = 'attr_' . $attr_id;
  96. $r = Db::name('language_attribute')->save([
  97. 'attr_title' => $result['attr_name'],
  98. 'attr_name' => $attr_name,
  99. 'attr_group' => $attr_group,
  100. 'add_time' => getTime(),
  101. 'update_time' => getTime(),
  102. ]);
  103. if (false !== $r) {
  104. $data = [];
  105. foreach ($languageRow as $key => $val) {
  106. /*同步新留言属性到其他语言留言属性列表*/
  107. if ($val['mark'] != $this->admin_lang) {
  108. $addsaveData = $result;
  109. $addsaveData['lang'] = $val['mark'];
  110. $newTypeid = Db::name('language_attr')->where([
  111. 'attr_name' => 'form' . $result['typeid'],
  112. 'attr_group' => 'form',
  113. 'lang' => $val['mark'],
  114. ])->getField('attr_value');
  115. $addsaveData['typeid'] = $newTypeid;
  116. unset($addsaveData['attr_id']);
  117. $attr_id = Db::name('guestbook_attribute')->insertGetId($addsaveData);
  118. }
  119. /*--end*/
  120. /*所有语言绑定在主语言的ID容器里*/
  121. $data[] = [
  122. 'attr_name' => $attr_name,
  123. 'attr_value' => $attr_id,
  124. 'lang' => $val['mark'],
  125. 'attr_group' => $attr_group,
  126. 'add_time' => getTime(),
  127. 'update_time' => getTime(),
  128. ];
  129. /*--end*/
  130. }
  131. if (!empty($data)) {
  132. model('LanguageAttr')->saveAll($data);
  133. }
  134. }
  135. }
  136. }
  137. }