No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GuestbookAttribute.php 4.8KB

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