123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338 |
- <?php
- /**
- * 易优CMS
- * ============================================================================
- * 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
- * 网站地址: http://www.eyoucms.com
- * ----------------------------------------------------------------------------
- * 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
- * ============================================================================
- * Author: 小虎哥 <1105415366@qq.com>
- * Date: 2018-4-3
- */
-
- namespace app\common\model;
-
- use think\Db;
- use think\Model;
- use think\Request;
-
- /**
- * 模型
- */
- class LanguageAttr extends Model
- {
- public $language_split = 0;
-
- //初始化
- protected function initialize()
- {
- // 需要调用`Model`的`initialize`方法
- parent::initialize();
- $this->language_split = tpCache('language.language_split');
- }
-
- /**
- * 获取关联绑定的变量值
- * @param string|array $bind_value 绑定之前的值,或者绑定之后的值
- * @param string $group 分组
- */
- public function getBindValue($bind_value = '', $attr_group = 'arctype', $langvar = '')
- {
- /*单语言情况下不执行多语言代码*/
- if (!is_language()) {
- return $bind_value;
- }
- /*--end*/
-
- // 主语言
- $main_lang = get_main_lang();
- // 当前语言
- $lang = $main_lang;
- if ('admin' == request()->module()) {
- $lang = get_admin_lang();
- } else {
- $lang = get_home_lang();
- }
-
- if (!empty($bind_value) && $main_lang != $lang) {
- switch ($attr_group) {
- case 'arctype':
- {
- if (!is_array($bind_value)) { // 获取关联绑定的栏目ID
- $typeidArr = explode(',', $bind_value);
- $row = Db::name('language_attr')->field('attr_name')
- ->where([
- 'attr_value' => ['IN', $typeidArr],
- 'attr_group' => $attr_group,
- ])->select();
- if (!empty($row) && empty($this->language_split)) {
- $row2 = Db::name('language_attr')->field('attr_name,attr_value')
- ->where([
- 'attr_name' => ['IN', get_arr_column($row, 'attr_name')],
- 'lang' => $lang,
- 'attr_group' => $attr_group,
- ])->select();
- if (1 < count($typeidArr)) {
- $bind_value = implode(',', get_arr_column($row2, 'attr_value'));
- } else {
- if(empty($row2)) {
- $bind_value = empty($this->language_split) ? '' : $bind_value;
- } else {
- $bind_value = $row2[0]['attr_value'];
- }
- }
- }
- }
- }
- break;
-
- case 'product_attribute':
- {
- if (is_array($bind_value)) {
- !empty($langvar) && $lang = $langvar;
- $row = Db::name('language_attr')->field('attr_name, attr_value')
- ->where([
- 'attr_value' => ['IN', get_arr_column($bind_value, 'attr_id')],
- 'attr_group' => $attr_group,
- ])->getAllWithIndex('attr_value');
- if (!empty($row) && empty($this->language_split)) {
- $row2 = Db::name('language_attr')->field('attr_name, attr_value')
- ->where([
- 'attr_name' => ['IN', get_arr_column($row, 'attr_name')],
- 'lang' => $lang,
- 'attr_group' => $attr_group,
- ])->getAllWithIndex('attr_name');
- if (!empty($row2)) {
- foreach ($bind_value as $key => $val) {
- if (!empty($row[$val['attr_id']])) {
- $val['attr_id'] = $row2[$row[$val['attr_id']]['attr_name']]['attr_value'];
- }
- $bind_value[$key] = $val;
- }
- }
- }
- } else { // 获取关联绑定的产品属性ID
- $attr_name = 'attr_'.$bind_value;
- $attr_value = Db::name('language_attr')->where([
- 'attr_name' => $attr_name,
- 'lang' => $lang,
- 'attr_group' => $attr_group,
- ])->getField('attr_value');
- if (empty($this->language_split)) {
- $bind_value = empty($attr_value) ? '' : $attr_value;
- } else {
- // $bind_value = empty($attr_value) ? $bind_value : $attr_value;
- }
- }
- }
- break;
-
- case 'guestbook_attribute':
- {
- if (is_array($bind_value)) {
- !empty($langvar) && $lang = $langvar;
- $row = Db::name('language_attr')->field('attr_name, attr_value')
- ->where([
- 'attr_value' => ['IN', get_arr_column($bind_value, 'attr_id')],
- 'attr_group' => $attr_group,
- ])->getAllWithIndex('attr_value');
-
- if (!empty($row) && empty($this->language_split)) {
- $row2 = Db::name('language_attr')->field('attr_name, attr_value')
- ->where([
- 'attr_name' => ['IN', get_arr_column($row, 'attr_name')],
- 'lang' => $lang,
- 'attr_group' => $attr_group,
- ])->getAllWithIndex('attr_name');
- if (!empty($row2)) {
- foreach ($bind_value as $key => $val) {
- if (!empty($row[$val['attr_id']])) {
- $val['attr_id'] = $row2[$row[$val['attr_id']]['attr_name']]['attr_value'];
- }
- $bind_value[$key] = $val;
- }
- }
- }
- } else { // 获取关联绑定的留言属性ID
- $attr_name = 'attr_'.$bind_value;
- $attr_value = Db::name('language_attr')->where([
- 'attr_name' => $attr_name,
- 'lang' => $lang,
- 'attr_group' => $attr_group,
- ])->getField('attr_value');
- if (empty($this->language_split)) {
- $bind_value = empty($attr_value) ? '' : $attr_value;
- } else {
- // $bind_value = empty($attr_value) ? $bind_value : $attr_value;
- }
- }
- }
- break;
-
- case 'ad_position':
- {
- if (!is_array($bind_value)) {// 获取关联绑定的广告位置ID
- $attr_name = 'adp'.$bind_value;
- $attr_value = Db::name('language_attr')->where([
- 'attr_name' => $attr_name,
- 'lang' => $lang,
- 'attr_group' => $attr_group,
- ])->getField('attr_value');
- if (empty($this->language_split)) {
- $bind_value = empty($attr_value) ? '' : $attr_value;
- } else {
- // $bind_value = empty($attr_value) ? $bind_value : $attr_value;
- }
- }
- }
- break;
-
- case 'ad':
- {
- if (!is_array($bind_value)) {// 获取关联绑定的广告ID
- $attr_name = 'ad'.$bind_value;
- $attr_value = Db::name('language_attr')->where([
- 'attr_name' => $attr_name,
- 'lang' => $lang,
- 'attr_group' => $attr_group,
- ])->getField('attr_value');
- if (empty($this->language_split)) {
- $bind_value = empty($attr_value) ? '' : $attr_value;
- } else {
- // $bind_value = empty($attr_value) ? $bind_value : $attr_value;
- }
- }
- }
- break;
-
- case 'links_group':
- {
- if (!is_array($bind_value)) {// 获取关联绑定的广告位置ID
- $attr_name = 'linksgroup'.$bind_value;
- $attr_value = Db::name('language_attr')->where([
- 'attr_name' => $attr_name,
- 'lang' => $lang,
- 'attr_group' => $attr_group,
- ])->getField('attr_value');
- if (empty($this->language_split)) {
- $bind_value = empty($attr_value) ? '' : $attr_value;
- } else {
- // $bind_value = empty($attr_value) ? $bind_value : $attr_value;
- }
- }
- }
- break;
-
- case 'form':
- {
- if (!is_array($bind_value)) {// 获取关联绑定的表单ID
- $attr_name = 'form'.$bind_value;
- $attr_value = Db::name('language_attr')->where([
- 'attr_name' => $attr_name,
- 'lang' => $lang,
- 'attr_group' => $attr_group,
- ])->getField('attr_value');
- if (empty($this->language_split)) {
- $bind_value = empty($attr_value) ? '' : $attr_value;
- } else {
- // $bind_value = empty($attr_value) ? $bind_value : $attr_value;
- }
- }
- }
- break;
-
- case 'form_attribute':
- {
- if (is_array($bind_value)) {
- !empty($langvar) && $lang = $langvar;
- $row = Db::name('language_attr')->field('attr_name, attr_value')
- ->where([
- 'attr_value' => ['IN', get_arr_column($bind_value, 'attr_id')],
- 'attr_group' => $attr_group,
- ])->getAllWithIndex('attr_value');
-
- if (!empty($row) && empty($this->language_split)) {
- $row2 = Db::name('language_attr')->field('attr_name, attr_value')
- ->where([
- 'attr_name' => ['IN', get_arr_column($row, 'attr_name')],
- 'lang' => $lang,
- 'attr_group' => $attr_group,
- ])->getAllWithIndex('attr_name');
- if (!empty($row2)) {
- foreach ($bind_value as $key => $val) {
- if (!empty($row[$val['attr_id']])) {
- $val['attr_id'] = $row2[$row[$val['attr_id']]['attr_name']]['attr_value'];
- }
- $bind_value[$key] = $val;
- }
- }
- }
- } else { // 获取关联绑定的表单属性ID
- $attr_name = 'attr_'.$bind_value;
- $attr_value = Db::name('language_attr')->where([
- 'attr_name' => $attr_name,
- 'lang' => $lang,
- 'attr_group' => $attr_group,
- ])->getField('attr_value');
- if (empty($this->language_split)) {
- $bind_value = empty($attr_value) ? '' : $attr_value;
- } else {
- // $bind_value = empty($attr_value) ? $bind_value : $attr_value;
- }
- }
- }
- break;
-
- default:
- # code...
- break;
- }
- }
-
- return $bind_value;
- }
-
- /**
- * 获取关联绑定的主语言的变量值
- * @param string|array $bind_value 绑定之前的值,或者绑定之后的值
- * @param string $group 分组
- */
- public function getBindMainValue($bind_value = '', $attr_group = 'arctype')
- {
- /*单语言情况下不执行多语言代码*/
- if (!is_language()) {
- return $bind_value;
- }
- /*--end*/
-
- $main_lang = get_main_lang();
-
- if (!empty($bind_value)) {
- switch ($attr_group) {
- case 'ad':
- {
- if (!is_array($bind_value)) {// 获取关联绑定的广告ID
- $attr_name = Db::name('language_attr')->where([
- 'attr_value' => $bind_value,
- 'attr_group' => $attr_group,
- ])->getField('attr_name');
- $attr_value = Db::name('language_attr')->where([
- 'attr_name' => $attr_name,
- 'lang' => $main_lang,
- 'attr_group' => $attr_group,
- ])->getField('attr_value');
- !empty($attr_value) && $bind_value = $attr_value;
- }
- }
- break;
-
- default:
- # code...
- break;
- }
- }
-
- return $bind_value;
- }
- }
|