init
This commit is contained in:
53
src/application/common/behavior/AppInitBehavior.php
Normal file
53
src/application/common/behavior/AppInitBehavior.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\behavior;
|
||||
|
||||
class AppInitBehavior {
|
||||
protected static $method;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// 行为扩展的执行入口必须是run
|
||||
public function run(&$params){
|
||||
self::$method = request()->method();
|
||||
$this->_initialize();
|
||||
}
|
||||
|
||||
private function _initialize() {
|
||||
$this->saveSqlmode();
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存mysql的sql-mode模式参数
|
||||
*/
|
||||
private function saveSqlmode(){
|
||||
/*在后台模块才执行,以便提高性能*/
|
||||
if (!stristr(request()->baseFile(), 'index.php')) {
|
||||
if ('GET' == self::$method) {
|
||||
$key = 'isset_saveSqlmode';
|
||||
$sessvalue = session($key);
|
||||
if(!empty($sessvalue))
|
||||
return true;
|
||||
session($key, 1);
|
||||
|
||||
$sql_mode = \think\Db::query("SELECT @@global.sql_mode AS sql_mode");
|
||||
$system_sql_mode = isset($sql_mode[0]['sql_mode']) ? $sql_mode[0]['sql_mode'] : '';
|
||||
/*多语言*/
|
||||
if (is_language()) {
|
||||
$langRow = \think\Db::name('language')->cache(true, EYOUCMS_CACHE_TIME, 'language')
|
||||
->order('id asc')->select();
|
||||
foreach ($langRow as $key => $val) {
|
||||
tpCache('system', ['system_sql_mode'=>$system_sql_mode], $val['mark']);
|
||||
}
|
||||
} else {
|
||||
tpCache('system', ['system_sql_mode'=>$system_sql_mode]);
|
||||
}
|
||||
/*--end*/
|
||||
}
|
||||
}
|
||||
/*--end*/
|
||||
}
|
||||
}
|
||||
31
src/application/common/behavior/InitHookBehavior.php
Normal file
31
src/application/common/behavior/InitHookBehavior.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\behavior;
|
||||
use think\Hook;
|
||||
|
||||
class InitHookBehavior {
|
||||
// 行为扩展的执行入口必须是run
|
||||
public function run(&$params){
|
||||
$data = cache('hooks');
|
||||
$hooks = M('hooks')->field('name,module')->where(array('status'=>1))->cache(true, EYOUCMS_CACHE_TIME, 'hooks')->select();
|
||||
if(empty($data) && !empty($hooks)){
|
||||
$exist = \think\Db::query('SHOW TABLES LIKE "'.config('database.prefix').'weapp"');
|
||||
if (!empty($exist)) {
|
||||
$weappRow = M('weapp')->field('code,status')->where(array('status'=>1))->getAllWithIndex('code');
|
||||
if (!empty($hooks)) {
|
||||
foreach ($hooks as $key => $val) {
|
||||
$module = $val['module'];
|
||||
if (isset($weappRow[$module]) && !empty($module)) {
|
||||
Hook::add($val['name'], get_weapp_class($module));
|
||||
}
|
||||
}
|
||||
cache('hooks', Hook::get());
|
||||
}
|
||||
}
|
||||
}else{
|
||||
if (!empty($data)) {
|
||||
Hook::import($data, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
130
src/application/common/controller/Common.php
Normal file
130
src/application/common/controller/Common.php
Normal file
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
|
||||
namespace app\common\controller;
|
||||
use think\Controller;
|
||||
use think\Session;
|
||||
use think\Db;
|
||||
class Common extends Controller {
|
||||
|
||||
public $session_id;
|
||||
public $theme_style = '';
|
||||
public $theme_style_path = '';
|
||||
public $view_suffix = 'html';
|
||||
public $eyou = array();
|
||||
|
||||
public $users_id = 0;
|
||||
public $users = array();
|
||||
|
||||
/**
|
||||
* 析构函数
|
||||
*/
|
||||
function __construct()
|
||||
{
|
||||
/*是否隐藏或显示应用入口index.php*/
|
||||
if (tpCache('seo.seo_inlet') == 0) {
|
||||
\think\Url::root('/index.php');
|
||||
} else {
|
||||
// \think\Url::root('/');
|
||||
}
|
||||
/*--end*/
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/*
|
||||
* 初始化操作
|
||||
*/
|
||||
public function _initialize()
|
||||
{
|
||||
session('admin_info'); // 传后台信息到前台,此处可视化用到
|
||||
if (!session_id()) {
|
||||
Session::start();
|
||||
}
|
||||
header("Cache-control: private"); // history.back返回后输入框值丢失问题
|
||||
$this->session_id = session_id(); // 当前的 session_id
|
||||
!defined('SESSION_ID') && define('SESSION_ID', $this->session_id); //将当前的session_id保存为常量,供其它方法调用
|
||||
|
||||
$global = tpCache('global');
|
||||
|
||||
/*关闭网站*/
|
||||
if (in_array(MODULE_NAME, ['home']) && !empty($global['web_status']) && $global['web_status'] == 1) {
|
||||
die("<div style='text-align:center; font-size:20px; font-weight:bold; margin:50px 0px;'>网站暂时关闭,维护中……</div>");
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
/*强制微信模式,仅允许微信端访问*/
|
||||
$shop_force_use_wechat = getUsersConfigData('shop.shop_force_use_wechat');
|
||||
if (!empty($shop_force_use_wechat) && 1 == $shop_force_use_wechat && !isWeixin()) {
|
||||
$html = "<div style='text-align:center; font-size:20px; font-weight:bold; margin:50px 0px;'>网站仅微信端可访问</div>";
|
||||
$WeChatLoginConfig = getUsersConfigData('wechat.wechat_login_config') ? unserialize(getUsersConfigData('wechat.wechat_login_config')) : [];
|
||||
if (!empty($WeChatLoginConfig['wechat_name'])) $html .= "<div style='text-align:center; font-size:20px; font-weight:bold; margin:50px 0px;'>关注微信公众号:".$WeChatLoginConfig['wechat_name']."</div>";
|
||||
if (!empty($WeChatLoginConfig['wechat_pic'])) $html .= "<div style='text-align:center; font-size:20px; font-weight:bold; margin:50px 0px;'><img style='width: 400px; height: 400px;' src='".$WeChatLoginConfig['wechat_pic']."'></div>";
|
||||
die($html);
|
||||
}
|
||||
/*END*/
|
||||
|
||||
$this->global_assign($global); // 获取网站全局变量值
|
||||
$this->view_suffix = config('template.view_suffix'); // 模板后缀htm
|
||||
$this->theme_style = THEME_STYLE; // 模板标识
|
||||
$this->theme_style_path = THEME_STYLE_PATH; // 模板目录
|
||||
//全局变量
|
||||
$this->eyou['global'] = $global;
|
||||
// 多语言变量
|
||||
try {
|
||||
$langArr = include_once APP_PATH."lang/{$this->home_lang}.php";
|
||||
} catch (\Exception $e) {
|
||||
$this->home_lang = $this->main_lang;
|
||||
$langCookieVar = \think\Config::get('global.home_lang');
|
||||
\think\Cookie::set($langCookieVar, $this->home_lang);
|
||||
$langArr = include_once APP_PATH."lang/{$this->home_lang}.php";
|
||||
}
|
||||
$this->eyou['lang'] = !empty($langArr) ? $langArr : [];
|
||||
/*电脑版与手机版的切换*/
|
||||
$v = I('param.v/s', 'pc');
|
||||
$v = trim($v, '/');
|
||||
$this->assign('v', $v);
|
||||
/*--end*/
|
||||
|
||||
/*多语言开关限制 - 不开某个语言情况下,报404 */
|
||||
if ($this->main_lang != $this->home_lang) {
|
||||
if (1 != $global['web_language_switch']) {
|
||||
abort(404,'页面不存在');
|
||||
} else {
|
||||
$langInfo = Db::name('language')->field('id')
|
||||
->where([
|
||||
'mark' => $this->home_lang,
|
||||
'status' => 1,
|
||||
])->find();
|
||||
if (empty($langInfo)) {
|
||||
abort(404,'页面不存在');
|
||||
}
|
||||
}
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
// 判断是否开启注册入口
|
||||
$users_open_register = getUsersConfigData('users.users_open_register');
|
||||
$this->assign('users_open_register', $users_open_register);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取系统内置变量
|
||||
*/
|
||||
public function global_assign($globalParams = [])
|
||||
{
|
||||
if (empty($globalParams)) {
|
||||
$globalParams = tpCache('global');
|
||||
}
|
||||
$this->assign('global', $globalParams);
|
||||
}
|
||||
}
|
||||
50
src/application/common/controller/Weapp.php
Normal file
50
src/application/common/controller/Weapp.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
|
||||
namespace app\common\controller;
|
||||
use think\Session;
|
||||
use think\WeappController;
|
||||
class Weapp extends WeappController {
|
||||
|
||||
/**
|
||||
* 析构函数
|
||||
*/
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/*
|
||||
* 初始化操作
|
||||
*/
|
||||
public function _initialize()
|
||||
{
|
||||
if (!session_id()) {
|
||||
Session::start();
|
||||
}
|
||||
header("Cache-control: private"); // history.back返回后输入框值丢失问题
|
||||
$this->session_id = session_id(); // 当前的 session_id
|
||||
!defined('SESSION_ID') && define('SESSION_ID', $this->session_id); //将当前的session_id保存为常量,供其它方法调用
|
||||
}
|
||||
|
||||
/**
|
||||
* 多语言功能操作权限
|
||||
*/
|
||||
public function language_access()
|
||||
{
|
||||
if (is_language() && $this->main_lang != $this->admin_lang) {
|
||||
$lang_title = model('Language')->where('mark',$this->main_lang)->value('title');
|
||||
$this->error('当前语言没有此功能,请切换到【'.$lang_title.'】语言');
|
||||
}
|
||||
}
|
||||
}
|
||||
427
src/application/common/logic/ArctypeLogic.php
Normal file
427
src/application/common/logic/ArctypeLogic.php
Normal file
@@ -0,0 +1,427 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
|
||||
namespace app\common\logic;
|
||||
|
||||
use think\Model;
|
||||
use think\Db;
|
||||
/**
|
||||
* 栏目逻辑定义
|
||||
* @package common\Logic
|
||||
*/
|
||||
class ArctypeLogic extends Model
|
||||
{
|
||||
|
||||
/**
|
||||
* 获得指定栏目下的子栏目的数组
|
||||
*
|
||||
* @access public
|
||||
* @param int $id 栏目的ID
|
||||
* @param int $selected 当前选中栏目的ID
|
||||
* @param boolean $re_type 返回的类型: 值为真时返回下拉列表,否则返回数组
|
||||
* @param int $level 限定返回的级数。为0时返回所有级数
|
||||
* @param array $map 查询条件
|
||||
* @return mix
|
||||
*/
|
||||
public function arctype_list($id = 0, $selected = 0, $re_type = true, $level = 0, $map = array(), $is_cache = true)
|
||||
{
|
||||
static $res = NULL;
|
||||
// $res = NULL;
|
||||
|
||||
if ($res === NULL)
|
||||
{
|
||||
$where = array(
|
||||
'status' => 1,
|
||||
);
|
||||
|
||||
/*权限控制 by 小虎哥*/
|
||||
$admin_info = session('admin_info');
|
||||
if (in_array(MODULE_NAME, ['admin']) && 0 < intval($admin_info['role_id'])) {
|
||||
$auth_role_info = $admin_info['auth_role_info'];
|
||||
if(! empty($auth_role_info)){
|
||||
if(! empty($auth_role_info['permission']['arctype'])){
|
||||
$where['id'] = array('IN', $auth_role_info['permission']['arctype']);
|
||||
}
|
||||
}
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
/*多语言 by 小虎哥*/
|
||||
if (empty($map['lang'])) {
|
||||
$where['lang'] = get_current_lang();
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
if (!empty($map)) {
|
||||
$where = array_merge($where, $map);
|
||||
}
|
||||
foreach ($where as $key => $val) {
|
||||
$key_tmp = 'c.'.$key;
|
||||
$where[$key_tmp] = $val;
|
||||
unset($where[$key]);
|
||||
}
|
||||
$fields = "c.*, c.id as typeid, count(s.id) as has_children, '' as children";
|
||||
$res = DB::name('arctype')
|
||||
->field($fields)
|
||||
->alias('c')
|
||||
->join('__ARCTYPE__ s','s.parent_id = c.id','LEFT')
|
||||
->where($where)
|
||||
->group('c.id')
|
||||
->order('c.parent_id asc, c.sort_order asc, c.id')
|
||||
->cache($is_cache,EYOUCMS_CACHE_TIME,"arctype")
|
||||
->select();
|
||||
}
|
||||
|
||||
if (empty($res) == true)
|
||||
{
|
||||
return $re_type ? '' : array();
|
||||
}
|
||||
|
||||
$options = $this->arctype_options($id, $res); // 获得指定栏目下的子栏目的数组
|
||||
|
||||
/* 截取到指定的缩减级别 */
|
||||
if ($level > 0)
|
||||
{
|
||||
if ($id == 0)
|
||||
{
|
||||
$end_level = $level;
|
||||
}
|
||||
else
|
||||
{
|
||||
$first_item = reset($options); // 获取第一个元素
|
||||
$end_level = $first_item['level'] + $level;
|
||||
}
|
||||
|
||||
/* 保留level小于end_level的部分 */
|
||||
foreach ($options AS $key => $val)
|
||||
{
|
||||
if ($val['level'] >= $end_level)
|
||||
{
|
||||
unset($options[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$pre_key = 0;
|
||||
foreach ($options AS $key => $value)
|
||||
{
|
||||
$options[$key]['has_children'] = 0;
|
||||
if ($pre_key > 0)
|
||||
{
|
||||
if ($options[$pre_key]['id'] == $options[$key]['parent_id'])
|
||||
{
|
||||
$options[$pre_key]['has_children'] = 1;
|
||||
}
|
||||
}
|
||||
$pre_key = $key;
|
||||
}
|
||||
|
||||
if ($re_type == true)
|
||||
{
|
||||
$select = '';
|
||||
foreach ($options AS $var)
|
||||
{
|
||||
$select .= '<option value="' . $var['id'] . '" ';
|
||||
$select .= ($selected == $var['id']) ? "selected='true'" : '';
|
||||
$select .= '>';
|
||||
if ($var['level'] > 0)
|
||||
{
|
||||
$select .= str_repeat(' ', $var['level'] * 4);
|
||||
}
|
||||
$select .= htmlspecialchars_decode(addslashes($var['typename'])) . '</option>';
|
||||
}
|
||||
|
||||
return $select;
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach ($options AS $key => $value)
|
||||
{
|
||||
///$options[$key]['url'] = build_uri('article_cat', array('acid' => $value['id']), $value['cat_name']);
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 过滤和排序所有文章栏目,返回一个带有缩进级别的数组
|
||||
*
|
||||
* @access private
|
||||
* @param int $id 上级栏目ID
|
||||
* @param array $arr 含有所有栏目的数组
|
||||
* @param int $level 级别
|
||||
* @return void
|
||||
*/
|
||||
public function arctype_options($spec_id, $arr)
|
||||
{
|
||||
static $cat_options = array();
|
||||
|
||||
// $cat_options = array();
|
||||
|
||||
if (isset($cat_options[$spec_id]))
|
||||
{
|
||||
return $cat_options[$spec_id];
|
||||
}
|
||||
|
||||
if (!isset($cat_options[0]))
|
||||
{
|
||||
$level = $last_id = 0;
|
||||
$options = $id_array = $level_array = array();
|
||||
while (!empty($arr))
|
||||
{
|
||||
foreach ($arr AS $key => $value)
|
||||
{
|
||||
$id = $value['id'];
|
||||
if ($level == 0 && $last_id == 0)
|
||||
{
|
||||
if ($value['parent_id'] > 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
$options[$id] = $value;
|
||||
$options[$id]['level'] = $level;
|
||||
$options[$id]['id'] = $id;
|
||||
$options[$id]['typename'] = htmlspecialchars_decode($value['typename']);
|
||||
unset($arr[$key]);
|
||||
|
||||
if ($value['has_children'] == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
$last_id = $id;
|
||||
$id_array = array($id);
|
||||
$level_array[$last_id] = ++$level;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($value['parent_id'] == $last_id)
|
||||
{
|
||||
$options[$id] = $value;
|
||||
$options[$id]['level'] = $level;
|
||||
$options[$id]['id'] = $id;
|
||||
$options[$id]['typename'] = htmlspecialchars_decode($value['typename']);
|
||||
unset($arr[$key]);
|
||||
|
||||
if ($value['has_children'] > 0)
|
||||
{
|
||||
if (end($id_array) != $last_id)
|
||||
{
|
||||
$id_array[] = $last_id;
|
||||
}
|
||||
$last_id = $id;
|
||||
$id_array[] = $id;
|
||||
$level_array[$last_id] = ++$level;
|
||||
}
|
||||
}
|
||||
elseif ($value['parent_id'] > $last_id)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$count = count($id_array);
|
||||
if ($count > 1)
|
||||
{
|
||||
$last_id = array_pop($id_array);
|
||||
}
|
||||
elseif ($count == 1)
|
||||
{
|
||||
if ($last_id != end($id_array))
|
||||
{
|
||||
$last_id = end($id_array);
|
||||
}
|
||||
else
|
||||
{
|
||||
$level = 0;
|
||||
$last_id = 0;
|
||||
$id_array = array();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if ($last_id && isset($level_array[$last_id]))
|
||||
{
|
||||
$level = $level_array[$last_id];
|
||||
}
|
||||
else
|
||||
{
|
||||
$level = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$cat_options[0] = $options;
|
||||
}
|
||||
else
|
||||
{
|
||||
$options = $cat_options[0];
|
||||
}
|
||||
|
||||
if (!$spec_id)
|
||||
{
|
||||
return $options;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (empty($options[$spec_id]))
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
$spec_id_level = $options[$spec_id]['level'];
|
||||
|
||||
foreach ($options AS $key => $value)
|
||||
{
|
||||
if ($key != $spec_id)
|
||||
{
|
||||
unset($options[$key]);
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$spec_id_array = array();
|
||||
foreach ($options AS $key => $value)
|
||||
{
|
||||
if (($spec_id_level == $value['level'] && $value['id'] != $spec_id) ||
|
||||
($spec_id_level > $value['level']))
|
||||
{
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
$spec_id_array[$key] = $value;
|
||||
}
|
||||
}
|
||||
$cat_options[$spec_id] = $spec_id_array;
|
||||
|
||||
return $spec_id_array;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步新增栏目ID到多语言的模板栏目变量里
|
||||
*/
|
||||
public function syn_add_language_attribute($typeid)
|
||||
{
|
||||
/*单语言情况下不执行多语言代码*/
|
||||
if (!is_language()) {
|
||||
return true;
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
$attr_group = 'arctype';
|
||||
$admin_lang = get_admin_lang();
|
||||
$main_lang = get_main_lang();
|
||||
$languageRow = Db::name('language')->field('mark')->order('id asc')->select();
|
||||
if (!empty($languageRow) && $admin_lang == $main_lang) { // 当前语言是主体语言,即语言列表最早新增的语言
|
||||
$arctypeRow = Db::name('arctype')->find($typeid);
|
||||
$attr_name = 'tid'.$typeid;
|
||||
$r = Db::name('language_attribute')->save([
|
||||
'attr_title' => $arctypeRow['typename'],
|
||||
'attr_name' => $attr_name,
|
||||
'attr_group' => $attr_group,
|
||||
'add_time' => getTime(),
|
||||
'update_time' => getTime(),
|
||||
]);
|
||||
if (false !== $r) {
|
||||
$data = [];
|
||||
foreach ($languageRow as $key => $val) {
|
||||
/*同步新栏目到其他语言栏目列表*/
|
||||
if ($val['mark'] != $admin_lang) {
|
||||
$addsaveData = $arctypeRow;
|
||||
$addsaveData['lang'] = $val['mark'];
|
||||
$addsaveData['typename'] = $val['mark'].$addsaveData['typename']; // 临时测试
|
||||
$parent_id = Db::name('language_attr')->where([
|
||||
'attr_name' => 'tid'.$arctypeRow['parent_id'],
|
||||
'lang' => $val['mark'],
|
||||
])->getField('attr_value');
|
||||
$addsaveData['parent_id'] = intval($parent_id);
|
||||
/*获取顶级栏目ID*/
|
||||
if (empty($parent_id)) {
|
||||
$topid = 0;
|
||||
} else {
|
||||
$parentInfo = M('arctype')->field('id,topid')->where('id', $parent_id)->find();
|
||||
$topid = !empty($parentInfo['topid']) ? $parentInfo['topid'] : $parentInfo['id'];
|
||||
}
|
||||
$addsaveData['topid'] = $topid;
|
||||
/*end*/
|
||||
unset($addsaveData['id']);
|
||||
$typeid = model('Arctype')->addData($addsaveData);
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
/*所有语言绑定在主语言的ID容器里*/
|
||||
$data[] = [
|
||||
'attr_name' => $attr_name,
|
||||
'attr_value' => $typeid,
|
||||
'lang' => $val['mark'],
|
||||
'attr_group' => $attr_group,
|
||||
'add_time' => getTime(),
|
||||
'update_time' => getTime(),
|
||||
];
|
||||
/*--end*/
|
||||
}
|
||||
if (!empty($data)) {
|
||||
model('LanguageAttr')->saveAll($data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取栏目的目录名称,确保唯一性
|
||||
*/
|
||||
public function get_dirname($typename = '', $dirname = '', $id = 0, $newDirnameArr = [])
|
||||
{
|
||||
$id = intval($id);
|
||||
if (!trim($dirname) || empty($dirname)) {
|
||||
$dirname = get_pinyin($typename);
|
||||
}
|
||||
if (strval(intval($dirname)) == strval($dirname)) {
|
||||
$dirname .= get_rand_str(3,0,2);
|
||||
}
|
||||
$dirname = preg_replace('/(\s)+/', '_', $dirname);
|
||||
if (!$this->dirname_unique($dirname, $id, $newDirnameArr)) {
|
||||
$nowDirname = $dirname.get_rand_str(3,0,2);
|
||||
return $this->get_dirname($typename, $nowDirname, $id, $newDirnameArr);
|
||||
}
|
||||
|
||||
return $dirname;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断目录名称的唯一性
|
||||
*/
|
||||
public function dirname_unique($dirname = '', $typeid = 0, $newDirnameArr = [])
|
||||
{
|
||||
$result = Db::name('arctype')->field('id,dirname')
|
||||
->where(['lang'=>get_admin_lang()])
|
||||
->getAllWithIndex('id');
|
||||
if (!empty($result)) {
|
||||
if (0 < $typeid) unset($result[$typeid]);
|
||||
!empty($result) && $result = get_arr_column($result, 'dirname');
|
||||
}
|
||||
empty($result) && $result = [];
|
||||
$langMarks = Db::name('language_mark')->column('mark'); // 多语言标识
|
||||
$disableDirname = config('global.disable_dirname');
|
||||
$disableDirname = array_merge($disableDirname, $langMarks, $result);
|
||||
!empty($newDirnameArr) && $disableDirname = array_merge($disableDirname, $newDirnameArr);
|
||||
if (in_array(strtolower($dirname), $disableDirname)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
290
src/application/common/logic/EmailLogic.php
Normal file
290
src/application/common/logic/EmailLogic.php
Normal file
@@ -0,0 +1,290 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
|
||||
namespace app\common\logic;
|
||||
|
||||
use think\Db;
|
||||
|
||||
/**
|
||||
* Description of SmsLogic
|
||||
*
|
||||
* 邮件类
|
||||
*/
|
||||
class EmailLogic
|
||||
{
|
||||
private $config;
|
||||
private $home_lang;
|
||||
|
||||
public function __construct($smtp_config = [])
|
||||
{
|
||||
$this->config = !empty($smtp_config) ? $smtp_config : tpCache('smtp');
|
||||
$this->home_lang = get_home_lang();
|
||||
}
|
||||
|
||||
/**
|
||||
* 置换邮件模版内容
|
||||
* @param intval $scene 应用场景
|
||||
*/
|
||||
private function replaceContent($scene = '', $params = '')
|
||||
{
|
||||
if (0 == intval($scene)) {
|
||||
$msg = $params;
|
||||
} else {
|
||||
$params_arr = [];
|
||||
$emailTemp = Db::name('smtp_tpl')->where([
|
||||
'send_scene'=> $scene,
|
||||
'lang' => $this->home_lang,
|
||||
])->find();
|
||||
if (!empty($emailTemp)) {
|
||||
$msg = $emailTemp['tpl_content'];
|
||||
preg_match_all('/\${([^\}]+)}/i', $msg, $matchs);
|
||||
if (!empty($matchs[1])) {
|
||||
foreach ($matchs[1] as $key => $val) {
|
||||
if (is_array($params)) {
|
||||
$params_arr[$val] = $params[$val];
|
||||
} else {
|
||||
$params_arr[$val] = $params;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//置换邮件模版内容
|
||||
foreach ($params_arr as $k => $v) {
|
||||
$msg = str_replace('${' . $k . '}', $v, $msg);
|
||||
}
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
return $msg;
|
||||
}
|
||||
|
||||
/**
|
||||
* 邮件发送
|
||||
* @param $to 接收人
|
||||
* @param string $subject 邮件标题
|
||||
* @param string|array $data 邮件内容(html模板渲染后的内容)
|
||||
* @param string $scene 使用场景
|
||||
* @throws Exception
|
||||
*/
|
||||
public function send_email($to='', $subject='', $data='', $scene=1, $library = 'phpmailer'){
|
||||
if (0 < intval($scene)) {
|
||||
$smtp_tpl_row = Db::name('smtp_tpl')->where([
|
||||
'send_scene'=> $scene,
|
||||
'lang' => $this->home_lang,
|
||||
])->find();
|
||||
if (empty($smtp_tpl_row)) {
|
||||
return ['code'=>0,'msg'=>'找不到相关邮件模板!'];
|
||||
} else if (empty($smtp_tpl_row['is_open'])) {
|
||||
return ['code'=>0,'msg'=>'该功能待开放,请先启用邮件模板('.$smtp_tpl_row['tpl_name'].')'];
|
||||
} else {
|
||||
empty($subject) && $subject = $smtp_tpl_row['tpl_title'];
|
||||
}
|
||||
}
|
||||
|
||||
switch ($library) {
|
||||
case 'phpmailer':
|
||||
return $this->send_phpmailer($to, $subject, $data, $scene);
|
||||
break;
|
||||
|
||||
case 'swiftmailer':
|
||||
return $this->send_swiftmailer($to, $subject, $data, $scene);
|
||||
break;
|
||||
|
||||
default:
|
||||
return $this->send_phpmailer($to, $subject, $data, $scene);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 邮件发送 - swiftmailer第三方库
|
||||
* @param $to 接收人
|
||||
* @param string $subject 邮件标题
|
||||
* @param string|array $data 邮件内容(html模板渲染后的内容)
|
||||
* @param string $scene 使用场景
|
||||
* @throws Exception
|
||||
*/
|
||||
private function send_swiftmailer($to='', $subject='', $data='', $scene=1){
|
||||
vendor('swiftmailer.lib.swift_required');
|
||||
// require_once 'vendor/swiftmailer/lib/swift_required.php';
|
||||
try {
|
||||
//判断openssl是否开启
|
||||
$openssl_funcs = get_extension_funcs('openssl');
|
||||
if(!$openssl_funcs){
|
||||
return array('code'=>0 , 'msg'=>'请先开启php的openssl扩展');
|
||||
}
|
||||
|
||||
//判断openssl是否开启
|
||||
// $sockets_funcs = get_extension_funcs('sockets');
|
||||
// if(!$sockets_funcs){
|
||||
// return array('code'=>0 , 'msg'=>'请先开启php的sockets扩展');
|
||||
// }
|
||||
|
||||
empty($to) && $to = $this->config['smtp_from_eamil'];
|
||||
$to = explode(',', $to);
|
||||
|
||||
//smtp服务器
|
||||
$host = $this->config['smtp_server'];
|
||||
//端口 - likely to be 25, 465 or 587
|
||||
$port = intval($this->config['smtp_port']);
|
||||
//用户名
|
||||
$user = $this->config['smtp_user'];
|
||||
//密码
|
||||
$pwd = $this->config['smtp_pwd'];
|
||||
//发送者
|
||||
$from = $this->config['smtp_user'];
|
||||
//发送者名称
|
||||
$from_name = $user;//tpCache('web.web_name');
|
||||
// 使用安全协议
|
||||
$encryption_type = null;
|
||||
switch ($port) {
|
||||
case 465:
|
||||
$encryption_type = 'ssl';
|
||||
break;
|
||||
|
||||
case 587:
|
||||
$encryption_type = 'tls';
|
||||
break;
|
||||
|
||||
default:
|
||||
# code...
|
||||
break;
|
||||
}
|
||||
//HTML内容转换
|
||||
$body = $this->replaceContent($scene, $data);
|
||||
|
||||
// Create the Transport
|
||||
$transport = (new \Swift_SmtpTransport($host, $port, $encryption_type))
|
||||
->setUsername($user)
|
||||
->setPassword($pwd);
|
||||
|
||||
// Create the Mailer using your created Transport
|
||||
$mailer = new \Swift_Mailer($transport);
|
||||
|
||||
// Create a message
|
||||
$message = (new \Swift_Message($subject))
|
||||
->setFrom([$from=>$from_name])
|
||||
// ->setTo([$to, '第二个接收者邮箱' => '别名'])
|
||||
->setTo($to)
|
||||
->setContentType("text/html")
|
||||
->setBody($body);
|
||||
|
||||
// Send the message
|
||||
$result = $mailer->send($message);
|
||||
if (!$result) {
|
||||
return array('code'=>0 , 'msg'=>'发送失败');
|
||||
} else {
|
||||
return array('code'=>1 , 'msg'=>'发送成功');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return array('code'=>0 , 'msg'=>'发送失败: '.$e->errorMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 邮件发送 - 第三方库phpmailer
|
||||
* @param $to 接收人
|
||||
* @param string $subject 邮件标题
|
||||
* @param string|array $data 邮件内容(html模板渲染后的内容)
|
||||
* @param string $scene 使用场景
|
||||
* @throws Exception
|
||||
*/
|
||||
private function send_phpmailer($to='', $subject='', $data='', $scene=1){
|
||||
vendor('phpmailer.PHPMailerAutoload');
|
||||
try {
|
||||
//判断openssl是否开启
|
||||
$openssl_funcs = get_extension_funcs('openssl');
|
||||
if(!$openssl_funcs){
|
||||
return array('code'=>0 , 'msg'=>'请先开启php的openssl扩展');
|
||||
}
|
||||
|
||||
//判断openssl是否开启
|
||||
// $sockets_funcs = get_extension_funcs('sockets');
|
||||
// if(!$sockets_funcs){
|
||||
// return array('code'=>0 , 'msg'=>'请先开启php的sockets扩展');
|
||||
// }
|
||||
|
||||
$mail = new \PHPMailer;
|
||||
$mail->CharSet = 'UTF-8'; //设定邮件编码,默认ISO-8859-1,如果发中文此项必须设置,否则乱码
|
||||
$mail->isSMTP();
|
||||
//Enable SMTP debugging
|
||||
// 0 = off (for production use)
|
||||
// 1 = client messages
|
||||
// 2 = client and server messages
|
||||
$mail->SMTPDebug = 0;
|
||||
//调试输出格式
|
||||
//$mail->Debugoutput = 'html';
|
||||
//接收者邮件
|
||||
empty($to) && $to = $this->config['smtp_from_eamil'];
|
||||
$to = explode(',', $to);
|
||||
//smtp服务器
|
||||
$mail->Host = $this->config['smtp_server'];
|
||||
//端口 - likely to be 25, 465 or 587
|
||||
$mail->Port = intval($this->config['smtp_port']);
|
||||
// 使用安全协议
|
||||
switch ($mail->Port) {
|
||||
case 465:
|
||||
$mail->SMTPSecure = 'ssl';
|
||||
break;
|
||||
|
||||
case 587:
|
||||
$mail->SMTPSecure = 'tls';
|
||||
break;
|
||||
|
||||
default:
|
||||
# code...
|
||||
break;
|
||||
}
|
||||
//Whether to use SMTP authentication
|
||||
$mail->SMTPAuth = true;
|
||||
//用户名
|
||||
$mail->Username = $this->config['smtp_user'];
|
||||
//密码
|
||||
$mail->Password = $this->config['smtp_pwd'];
|
||||
//Set who the message is to be sent from
|
||||
$mail->setFrom($this->config['smtp_user']);
|
||||
//回复地址
|
||||
//$mail->addReplyTo('replyto@example.com', 'First Last');
|
||||
//接收邮件方
|
||||
if(is_array($to)){
|
||||
foreach ($to as $v){
|
||||
$mail->addAddress($v);
|
||||
}
|
||||
}else{
|
||||
$mail->addAddress($to);
|
||||
}
|
||||
|
||||
$mail->isHTML(true);// send as HTML
|
||||
//标题
|
||||
$mail->Subject = $subject;
|
||||
//HTML内容转换
|
||||
$content = $this->replaceContent($scene, $data);
|
||||
$mail->msgHTML($content);
|
||||
//Replace the plain text body with one created manually
|
||||
//$mail->AltBody = 'This is a plain-text message body';
|
||||
//添加附件
|
||||
//$mail->addAttachment('images/phpmailer_mini.png');
|
||||
//send the message, check for errors
|
||||
$result = $mail->send();
|
||||
if (!$result) {
|
||||
return array('code'=>0 , 'msg'=>'发送失败:'.$mail->ErrorInfo);
|
||||
} else {
|
||||
return array('code'=>1 , 'msg'=>'发送成功');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return array('code'=>0 , 'msg'=>'发送失败: '.$e->errorMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
10
src/application/common/logic/FunctionLogic.php
Normal file
10
src/application/common/logic/FunctionLogic.php
Normal file
File diff suppressed because one or more lines are too long
150
src/application/common/logic/HtmlCacheLogic.php
Normal file
150
src/application/common/logic/HtmlCacheLogic.php
Normal file
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
|
||||
namespace app\common\logic;
|
||||
|
||||
use think\Db;
|
||||
|
||||
/**
|
||||
*
|
||||
* 页面缓存
|
||||
*/
|
||||
class HtmlCacheLogic
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除首页的页面缓存文件
|
||||
*/
|
||||
public function clear_index()
|
||||
{
|
||||
$web_cmsmode = tpCache('web.web_cmsmode');
|
||||
$html_cache_arr = config('HTML_CACHE_ARR');
|
||||
if (1 == intval($web_cmsmode)) { // 页面html静态永久缓存
|
||||
$fileList = glob(HTML_ROOT.'http*/'.$html_cache_arr['home_Index_index']['filename'].'/*_html/index*.html');
|
||||
if (!empty($fileList)) {
|
||||
foreach ($fileList as $k2 => $file) {
|
||||
if (file_exists($file) && preg_match('/index(_\d+)?\.html$/i', $file)) {
|
||||
@unlink($file);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else { // 页面cache自动过期缓存
|
||||
$fileList = glob(HTML_ROOT.'http*/'.$html_cache_arr['home_Index_index']['filename'].'/*_cache/index/*');
|
||||
if (!empty($fileList)) {
|
||||
foreach ($fileList as $k2 => $dir) {
|
||||
if (file_exists($dir) && is_dir($dir)) {
|
||||
delFile($dir, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除指定栏目的页面缓存文件
|
||||
* @param array $typeids 栏目ID数组
|
||||
*/
|
||||
public function clear_arctype($typeids = [])
|
||||
{
|
||||
$web_cmsmode = tpCache('web.web_cmsmode');
|
||||
$html_cache_arr = config('HTML_CACHE_ARR');
|
||||
if (!empty($typeids)) {
|
||||
foreach ($typeids as $key => $tid) {
|
||||
if (1 == intval($web_cmsmode)) { // 页面html静态永久缓存
|
||||
$fileList = glob(HTML_ROOT.'http*/'.$html_cache_arr['home_Lists_index']['filename'].'/*_html/'.$tid.'*.html');
|
||||
if (!empty($fileList)) {
|
||||
foreach ($fileList as $k2 => $file) {
|
||||
if (file_exists($file) && preg_match('/'.$tid.'(_\d+)?\.html$/i', $file)) {
|
||||
@unlink($file);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else { // 页面cache自动过期缓存
|
||||
$fileList = glob(HTML_ROOT.'http*/'.$html_cache_arr['home_Lists_index']['filename'].'/*_cache/'.$tid.'/*');
|
||||
if (!empty($fileList)) {
|
||||
foreach ($fileList as $k2 => $dir) {
|
||||
if (file_exists($dir) && is_dir($dir)) {
|
||||
delFile($dir, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else { // 清除全部的栏目页面缓存
|
||||
$fileList = glob(HTML_ROOT.'http*/'.$html_cache_arr['home_Lists_index']['filename'].'/*');
|
||||
if (!empty($fileList)) {
|
||||
foreach ($fileList as $k2 => $dir) {
|
||||
if (file_exists($dir) && is_dir($dir)) {
|
||||
delFile($dir, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->clear_index(); // 清除首页缓存
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除指定文档的页面缓存文件
|
||||
* @param array $aids 文档ID数组
|
||||
*/
|
||||
public function clear_archives($aids = [])
|
||||
{
|
||||
$web_cmsmode = tpCache('web.web_cmsmode');
|
||||
$html_cache_arr = config('HTML_CACHE_ARR');
|
||||
if (!empty($aids)) {
|
||||
$row = Db::name('archives')->field('aid,typeid')
|
||||
->where([
|
||||
'aid' => ['IN', $aids],
|
||||
])->select();
|
||||
foreach ($row as $key => $val) {
|
||||
$aid = $val['aid'];
|
||||
$typeid = $val['typeid'];
|
||||
if (1 == intval($web_cmsmode)) { // 页面html静态永久缓存
|
||||
$fileList = glob(HTML_ROOT.'http*/'.$html_cache_arr['home_View_index']['filename'].'/*_html/'.$aid.'*.html');
|
||||
if (!empty($fileList)) {
|
||||
foreach ($fileList as $k2 => $file) {
|
||||
if (preg_match('/'.$aid.'(_\d+)?\.html$/i', $file)) {
|
||||
@unlink($file);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else { // 页面cache自动过期缓存
|
||||
$fileList = glob(HTML_ROOT.'http*/'.$html_cache_arr['home_View_index']['filename'].'/*_cache/'.$aid.'/*');
|
||||
if (!empty($fileList)) {
|
||||
foreach ($fileList as $k2 => $dir) {
|
||||
if (file_exists($dir) && is_dir($dir)) {
|
||||
delFile($dir, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else { // 清除所有的文档页面缓存
|
||||
$fileList = glob(HTML_ROOT.'http*/'.$html_cache_arr['home_View_index']['filename'].'*');
|
||||
if (!empty($fileList)) {
|
||||
foreach ($fileList as $k2 => $dir) {
|
||||
if (file_exists($dir) && is_dir($dir)) {
|
||||
delFile($dir, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->clear_arctype(); // 清除所有的栏目
|
||||
}
|
||||
}
|
||||
233
src/application/common/logic/OssLogic.php
Normal file
233
src/application/common/logic/OssLogic.php
Normal file
@@ -0,0 +1,233 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 易而优团队 by 陈风任 <491085389@qq.com>
|
||||
* Date: 2020-04-09
|
||||
*/
|
||||
|
||||
namespace app\common\logic;
|
||||
|
||||
use OSS\OssClient;
|
||||
use OSS\Core\OssException;
|
||||
|
||||
require_once './vendor/aliyun-oss-php-sdk/autoload.php';
|
||||
|
||||
/**
|
||||
* Class OssLogic
|
||||
* 对象存储逻辑类
|
||||
*/
|
||||
class OssLogic
|
||||
{
|
||||
static private $initConfigFlag = false;
|
||||
static private $accessKeyId = '';
|
||||
static private $accessKeySecret = '';
|
||||
static private $endpoint = '';
|
||||
static private $bucket = '';
|
||||
|
||||
/** @var \OSS\OssClient */
|
||||
static private $ossClient = null;
|
||||
static private $errorMsg = '';
|
||||
|
||||
static private $waterPos = [
|
||||
1 => 'nw', //标识左上角水印
|
||||
2 => 'north', //标识上居中水印
|
||||
3 => 'ne', //标识右上角水印
|
||||
4 => 'west', //标识左居中水印
|
||||
5 => 'center', //标识居中水印
|
||||
6 => 'east', //标识右居中水印
|
||||
7 => 'sw', //标识左下角水印
|
||||
8 => 'south', //标识下居中水印
|
||||
9 => 'se', //标识右下角水印
|
||||
];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
self::initConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取错误信息,一旦其他接口返回false时,可调用此接口查看具体错误信息
|
||||
* @return type
|
||||
*/
|
||||
public function getError()
|
||||
{
|
||||
return self::$errorMsg;
|
||||
}
|
||||
|
||||
static private function initConfig()
|
||||
{
|
||||
if (self::$initConfigFlag) {
|
||||
return;
|
||||
}
|
||||
|
||||
$c = [];
|
||||
$where = [
|
||||
'name' => ['IN', ['oss_key_id', 'oss_key_secret', 'oss_endpoint','oss_bucket']],
|
||||
'lang' => get_admin_lang()
|
||||
];
|
||||
$config = M('config')->field('name, value')->where($where)->select();
|
||||
foreach ($config as $v) {
|
||||
$c[$v['name']] = $v['value'];
|
||||
}
|
||||
self::$accessKeyId = !empty($c['oss_key_id']) ? $c['oss_key_id'] : '';
|
||||
self::$accessKeySecret = !empty($c['oss_key_secret']) ? $c['oss_key_secret'] : '';
|
||||
self::$endpoint = !empty($c['oss_endpoint']) ? $c['oss_endpoint'] : '';
|
||||
self::$bucket = !empty($c['oss_bucket']) ? $c['oss_bucket'] : '';
|
||||
self::$initConfigFlag = true;
|
||||
}
|
||||
|
||||
static private function getOssClient()
|
||||
{
|
||||
if (!self::$ossClient) {
|
||||
self::initConfig();
|
||||
try {
|
||||
self::$ossClient = new OssClient(self::$accessKeyId, self::$accessKeySecret, self::$endpoint, false);
|
||||
} catch (OssException $e) {
|
||||
self::$errorMsg = "创建oss对象失败,".$e->getMessage();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return self::$ossClient;
|
||||
}
|
||||
|
||||
public function getSiteUrl()
|
||||
{
|
||||
$http = config('is_https') ? 'https://' : 'http://';
|
||||
$site_url = $http .self::$bucket . "." . self::$endpoint;
|
||||
|
||||
$ossConfig = tpCache('oss');
|
||||
$oss_domain = $ossConfig['oss_domain'];
|
||||
if ($oss_domain) {
|
||||
$site_url = $http . $oss_domain;
|
||||
}
|
||||
|
||||
return $site_url;
|
||||
}
|
||||
|
||||
public function uploadFile($filePath, $object = null)
|
||||
{
|
||||
$ossClient = self::getOssClient();
|
||||
if (!$ossClient) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (is_null($object)) {
|
||||
$object = $filePath;
|
||||
}
|
||||
|
||||
try {
|
||||
$ossClient->uploadFile(self::$bucket, $object, $filePath);
|
||||
} catch (OssException $e) {
|
||||
self::$errorMsg = "oss上传文件失败,".$e->getMessage();
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->getSiteUrl().'/'.$object;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取产品图片的url
|
||||
* @param type $originalImg
|
||||
* @param type $width
|
||||
* @param type $height
|
||||
* @param type $defaultImg
|
||||
* @return type
|
||||
*/
|
||||
public function getProductThumbImageUrl($originalImg, $width, $height, $defaultImg = '')
|
||||
{
|
||||
if (!$this->isOssUrl($originalImg)) {
|
||||
return $defaultImg;
|
||||
}
|
||||
|
||||
// 图片缩放(等比缩放)
|
||||
$url = $originalImg."?x-oss-process=image/resize,m_pad,h_$height,w_$width";
|
||||
|
||||
$water = tpCache('water');
|
||||
if ($water['is_mark']) {
|
||||
if ($width > $water['mark_width'] && $height > $water['mark_height']) {
|
||||
if ($water['mark_type'] == 'img') {
|
||||
if ($this->isOssUrl($water['mark_img'])) {
|
||||
$url = $this->withImageWaterUrl($url, $water['mark_img'], $water['mark_degree'], $water['mark_sel']);
|
||||
}
|
||||
} else {
|
||||
$url = $this->withTextWaterUrl($url, $water['mark_txt'], $water['mark_txt_size'], $water['mark_txt_color'], $water['mark_degree'], $water['mark_sel']);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取产品相册的url
|
||||
* @param type $originalImg
|
||||
* @param type $width
|
||||
* @param type $height
|
||||
* @param type $defaultImg
|
||||
* @return type
|
||||
*/
|
||||
public function getProductAlbumThumbUrl($originalImg, $width, $height, $defaultImg = '')
|
||||
{
|
||||
if (!($originalImg && strpos($originalImg, 'http') === 0 && strpos($originalImg, 'aliyuncs.com'))) {
|
||||
return $defaultImg;
|
||||
}
|
||||
|
||||
// 图片缩放(等比缩放)
|
||||
$url = $originalImg."?x-oss-process=image/resize,m_pad,h_$height,w_$width";
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* 链接加上文本水印参数(文字水印(方针黑体,黑色))
|
||||
* @param string $url
|
||||
* @param type $text
|
||||
* @param type $size
|
||||
* @param type $posSel
|
||||
* @return string
|
||||
*/
|
||||
private function withTextWaterUrl($url, $text, $size, $color, $transparency, $posSel)
|
||||
{
|
||||
$color = $color ?: '#000000';
|
||||
if (!preg_match('/^#[0-9a-fA-F]{6}$/', $color)) {
|
||||
$color = '#000000';
|
||||
}
|
||||
$color = ltrim($color, '#');
|
||||
$text_encode = urlsafe_b64encode($text);
|
||||
$url .= ",image/watermark,text_{$text_encode},type_ZmFuZ3poZW5naGVpdGk,color_{$color},size_{$size},t_{$transparency},g_" . self::$waterPos[$posSel];
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* 链接加上图片水印参数
|
||||
* @param string $url
|
||||
* @param type $image
|
||||
* @param type $transparency
|
||||
* @param type $posSel
|
||||
* @return string
|
||||
*/
|
||||
private function withImageWaterUrl($url, $image, $transparency, $posSel)
|
||||
{
|
||||
$image = ltrim(parse_url($image, PHP_URL_PATH), '/');
|
||||
$image_encode = urlsafe_b64encode($image);
|
||||
$url .= ",image/watermark,image_{$image_encode},t_{$transparency},g_" . self::$waterPos[$posSel];
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否是oss的链接
|
||||
* @param type $url
|
||||
* @return boolean
|
||||
*/
|
||||
public function isOssUrl($url)
|
||||
{
|
||||
if ($url && strpos($url, 'http') === 0 && strpos($url, 'aliyuncs.com')) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
132
src/application/common/logic/ShopCommonLogic.php
Normal file
132
src/application/common/logic/ShopCommonLogic.php
Normal file
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 易而优团队 by 陈风任 <491085389@qq.com>
|
||||
* Date: 2021-01-14
|
||||
*/
|
||||
|
||||
namespace app\common\logic;
|
||||
use think\Model;
|
||||
use think\Db;
|
||||
|
||||
/**
|
||||
* 商城公共逻辑业务层
|
||||
* @package common\Logic
|
||||
*/
|
||||
class ShopCommonLogic extends Model
|
||||
{
|
||||
/**
|
||||
* 初始化操作
|
||||
*/
|
||||
public function initialize() {
|
||||
parent::initialize();
|
||||
$this->users_db = Db::name('users'); // 会员数据表
|
||||
$this->users_money_db = Db::name('users_money'); // 会员余额明细表
|
||||
$this->shop_order_db = Db::name('shop_order'); // 订单主表
|
||||
$this->shop_order_details_db = Db::name('shop_order_details'); // 订单明细表
|
||||
}
|
||||
|
||||
public function GetOrderStatusIfno($Where = array())
|
||||
{
|
||||
// 查询订单信息
|
||||
if (empty($Where)) return '条件错误!';
|
||||
$OrderData = $this->shop_order_db->where($Where)->field('order_code, use_balance, use_point, order_status')->find();
|
||||
if (empty($OrderData)) return '订单不存在!';
|
||||
|
||||
// 返回处理
|
||||
switch ($OrderData['order_status']) {
|
||||
case '-1':
|
||||
return '订单已取消,不可取消订单!';
|
||||
break;
|
||||
|
||||
case '1':
|
||||
return '订单已支付,不可取消订单!';
|
||||
break;
|
||||
|
||||
case '2':
|
||||
return '订单已发货,不可取消订单!';
|
||||
break;
|
||||
|
||||
case '3':
|
||||
return '订单已完成,不可取消订单!';
|
||||
break;
|
||||
|
||||
case '4':
|
||||
return '订单已过期,不可取消订单!';
|
||||
break;
|
||||
|
||||
default:
|
||||
// 订单仅在未支付时返回数组
|
||||
return $OrderData;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function UpdateUsersProcess($GetOrder = array(), $GetUsers = array())
|
||||
{
|
||||
// 如果没有传入会员信息则获取session
|
||||
$Users = $GetUsers ? $GetUsers : session('users');
|
||||
// 若数据为空则返回false
|
||||
if (empty($Users) || empty($GetOrder)) return false;
|
||||
// 当前时间
|
||||
$time = getTime();
|
||||
|
||||
/*返还余额支付的金额*/
|
||||
if (!empty($GetOrder['use_balance']) && $GetOrder['use_balance'] > 0) {
|
||||
$UsersMoney['users_money'] = Db::raw('users_money+'.($GetOrder['use_balance']));
|
||||
$this->users_db->where('users_id', $Users['users_id'])->update($UsersMoney);
|
||||
|
||||
/*使用余额支付时,同时添加一条记录到金额明细表*/
|
||||
$AddMoneyData = [
|
||||
'users_id' => $Users['users_id'],
|
||||
'money' => $GetOrder['use_balance'],
|
||||
'users_old_money' => $Users['users_money'],
|
||||
'users_money' => $Users['users_money'] + $GetOrder['use_balance'],
|
||||
'cause' => '订单取消,退还使用余额,订单号:' . $GetOrder['order_code'],
|
||||
'cause_type' => 2,
|
||||
'status' => 3,
|
||||
'order_number' => $GetOrder['order_code'],
|
||||
'add_time' => $time,
|
||||
'update_time' => $time,
|
||||
];
|
||||
$this->users_money_db->add($AddMoneyData);
|
||||
/* END */
|
||||
}
|
||||
/* END */
|
||||
}
|
||||
|
||||
// 前后台通过,记录商品退换货服务单信息
|
||||
public function AddOrderServiceLog($param = [], $IsUsers = 1)
|
||||
{
|
||||
if (empty($param)) return false;
|
||||
if (2 == $param['status']) {
|
||||
$LogNote = '商家通过申请,等待会员将货物寄回商家!';
|
||||
} else if (3 == $param['status']) {
|
||||
$LogNote = '商家拒绝申请,请联系商家处理!';
|
||||
} else if (4 == $param['status']) {
|
||||
$LogNote = '会员已将货物发出,等待商家收货!';
|
||||
} else if (5 == $param['status']) {
|
||||
$LogNote = '商家已收到货物,待管理员进行退换货处理!';
|
||||
} else if (6 == $param['status']) {
|
||||
$LogNote = '商家已将新货物重新发出,换货完成,服务结束!';
|
||||
} else if (7 == $param['status']) {
|
||||
$LogNote = '商家已将金额、余额、积分退回,退款完成,服务结束!';
|
||||
} else if (8 == $param['status']) {
|
||||
$LogNote = '服务单被取消,服务结束!';
|
||||
}
|
||||
if (1 == $IsUsers) {
|
||||
$users_id = $param['users_id'];
|
||||
$admin_id = 0;
|
||||
} else {
|
||||
$admin_id = session('admin_id');
|
||||
$users_id = 0;
|
||||
}
|
||||
OrderServiceLog($param['service_id'], $param['order_id'], $users_id, $admin_id, $LogNote);
|
||||
}
|
||||
}
|
||||
255
src/application/common/logic/SmsLogic.php
Normal file
255
src/application/common/logic/SmsLogic.php
Normal file
@@ -0,0 +1,255 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 易而优团队 by 陈风任 <491085389@qq.com>
|
||||
* Date: 2020-03-31
|
||||
*/
|
||||
|
||||
namespace app\common\logic;
|
||||
|
||||
use think\Model;
|
||||
use think\Db;
|
||||
|
||||
/**
|
||||
* Description of SmsLogic
|
||||
*
|
||||
* 短信类
|
||||
*/
|
||||
class SmsLogic extends Model
|
||||
{
|
||||
private $config;
|
||||
|
||||
public function __construct($sms_config = [])
|
||||
{
|
||||
$this->config = !empty($sms_config) ? $sms_config : tpCache('sms');
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送短信逻辑
|
||||
* @param unknown $source
|
||||
*/
|
||||
public function sendSms($source = null, $sender = null, $params = [], $unique_id = 0)
|
||||
{
|
||||
$sms_config = $this->config;
|
||||
$sms_type = isset($sms_config['sms_type']) ? $sms_config['sms_type'] : 1;
|
||||
$smsTemp = M('sms_template')->where(["send_scene"=> $source,"sms_type"=> $sms_type])->find();
|
||||
if (empty($smsTemp) || empty($smsTemp['sms_sign']) || empty($smsTemp['sms_tpl_code'])|| empty($smsTemp['tpl_content'])){
|
||||
return $result = ['status' => -1, 'msg' => '尚未正确配置短信模板,请联系管理员!'];
|
||||
}
|
||||
if (0 == $smsTemp['is_open']) return $result = ['status' => -1, 'msg' => '模板类型已关闭,请先开启'];
|
||||
|
||||
$content = !empty($params['content']) ? $params['content'] : false;
|
||||
$code = !empty($params['code']) ? $params['code'] : $content;
|
||||
|
||||
if(empty($unique_id)){
|
||||
$session_id = session_id();
|
||||
}else{
|
||||
$session_id = $unique_id;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if ($sms_type == 1) {
|
||||
if (strpos($smsTemp['tpl_content'], 'code') !== false) {
|
||||
$smsParams = array(
|
||||
0 => "{\"code\":\"$code\"}",
|
||||
1 => "{\"code\":\"$code\"}",
|
||||
2 => "{\"code\":\"$code\"}",
|
||||
3 => "{\"code\":\"$code\"}",
|
||||
4 => "{\"code\":\"$code\"}",
|
||||
5 => "{\"code\":\"$code\"}",
|
||||
6 => "{\"code\":\"$code\"}",
|
||||
);
|
||||
} else if (strpos($smsTemp['tpl_content'], 'content') !== false) {
|
||||
$smsParams = array(
|
||||
0 => "{\"content\":\"$content\"}",
|
||||
1 => "{\"content\":\"$content\"}",
|
||||
2 => "{\"content\":\"$content\"}",
|
||||
3 => "{\"content\":\"$content\"}",
|
||||
4 => "{\"content\":\"$content\"}",
|
||||
5 => "{\"content\":\"$content\"}",
|
||||
6 => "{\"content\":\"$content\"}",
|
||||
);
|
||||
} else if (strpos($smsTemp['tpl_content'], 'name') !== false) {
|
||||
$smsParams = array(
|
||||
0 => "{\"name\":\"$name\"}",
|
||||
1 => "{\"name\":\"$name\"}",
|
||||
2 => "{\"name\":\"$name\"}",
|
||||
3 => "{\"name\":\"$name\"}",
|
||||
4 => "{\"name\":\"$name\"}",
|
||||
5 => "{\"name\":\"$name\"}",
|
||||
6 => "{\"name\":\"$name\"}",
|
||||
);
|
||||
}
|
||||
|
||||
$smsParam = $smsParams[$source];
|
||||
//提取发送短信内容
|
||||
$msg = $smsTemp['tpl_content'];
|
||||
$params_arr = json_decode($smsParam);
|
||||
|
||||
//提取发送短信内容
|
||||
$msg = $smsTemp['tpl_content'];
|
||||
$params_arr = json_decode($smsParam);
|
||||
foreach ($params_arr as $k => $v) {
|
||||
$msg = str_replace('${' . $k . '}', $v, $msg);
|
||||
}
|
||||
}else{
|
||||
|
||||
$params_arr = $smsParam = array_values($params);
|
||||
//提取发送短信内容
|
||||
$msg = $smsTemp['tpl_content'];
|
||||
foreach ($params_arr as $k => $v) {
|
||||
$index = $k+1;
|
||||
$msg = str_replace('{' . $index . '}', $v, $msg);
|
||||
}
|
||||
}
|
||||
|
||||
//发送记录存储数据库
|
||||
$log_id = M('sms_log')->insertGetId(array('source' => $source,'sms_type' => $sms_type, 'mobile' => $sender, 'code' => $code, 'add_time' => time(), 'status' => 0, 'msg' => $msg, 'is_use' => 0, 'error_msg'=>''));
|
||||
if ($sender != '' && check_mobile($sender)) {
|
||||
// 如果是正常的手机号码才发送
|
||||
try {
|
||||
$resp = $this->realSendSms($sender, $smsTemp['sms_sign'], $smsParam, $smsTemp['sms_tpl_code']);
|
||||
} catch (\Exception $e) {
|
||||
$resp = ['status' => -1, 'msg' => $e->getMessage()];
|
||||
}
|
||||
if ($resp['status'] == 1) {
|
||||
// 修改发送状态为成功
|
||||
M('sms_log')->where(array('id' => $log_id))->save(array('status' => 1));
|
||||
} else {
|
||||
// 发送失败, 将发送失败信息保存数据库
|
||||
M('sms_log')->where(array('id' => $log_id))->update(array('error_msg'=>$resp['msg']));
|
||||
}
|
||||
return $resp;
|
||||
} else {
|
||||
return $result = ['status' => -1, 'msg' => '接收手机号不正确['.$sender.']'];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function realSendSms($mobile, $smsSign, $smsParam, $templateCode)
|
||||
{
|
||||
if (config('sms_debug') == true) {
|
||||
return array('status' => 1, 'msg' => '专用于越过短信发送');
|
||||
}
|
||||
$param = input('param.');
|
||||
if (!isset($param['sms_type'])) {
|
||||
$type = (int)$this->config['sms_type'] ?: 1;
|
||||
}else{
|
||||
$type = $param['sms_type'];
|
||||
}
|
||||
|
||||
switch($type) {
|
||||
case 1:
|
||||
$result = $this->sendSmsByAliyun($mobile, $smsSign, $smsParam, $templateCode);
|
||||
break;
|
||||
case 2:
|
||||
$result = $this->sendSmsByTencentCloud($mobile, $smsSign, $smsParam, $templateCode);
|
||||
break;
|
||||
default:
|
||||
$result = ['status' => -1, 'msg' => '不支持的短信平台'];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送短信(阿里云短信)
|
||||
* @param $mobile 手机号码
|
||||
* @param $code 验证码
|
||||
* @return bool 短信发送成功返回true失败返回false
|
||||
*/
|
||||
private function sendSmsByAliyun($mobile, $smsSign, $smsParam, $templateCode)
|
||||
{
|
||||
include_once './vendor/aliyun-php-sdk-core/Config.php';
|
||||
include_once './vendor/Dysmsapi/Request/V20170525/SendSmsRequest.php';
|
||||
|
||||
$accessKeyId = $this->config['sms_appkey'];
|
||||
$accessKeySecret = $this->config['sms_secretkey'];
|
||||
if (empty($accessKeyId) || empty($accessKeySecret)){
|
||||
return array('status' => -1, 'msg' => '请设置短信平台appkey和secretKey');
|
||||
}
|
||||
//短信API产品名
|
||||
$product = "Dysmsapi";
|
||||
//短信API产品域名
|
||||
$domain = "dysmsapi.aliyuncs.com";
|
||||
//暂时不支持多Region
|
||||
$region = "cn-hangzhou";
|
||||
|
||||
//初始化访问的acsCleint
|
||||
$profile = \DefaultProfile::getProfile($region, $accessKeyId, $accessKeySecret);
|
||||
\DefaultProfile::addEndpoint("cn-hangzhou", "cn-hangzhou", $product, $domain);
|
||||
$acsClient= new \DefaultAcsClient($profile);
|
||||
|
||||
$request = new \Dysmsapi\Request\V20170525\SendSmsRequest;
|
||||
//必填-短信接收号码
|
||||
$request->setPhoneNumbers($mobile);
|
||||
//必填-短信签名
|
||||
$request->setSignName($smsSign);
|
||||
//必填-短信模板Code
|
||||
$request->setTemplateCode($templateCode);
|
||||
//选填-假如模板中存在变量需要替换则为必填(JSON格式)
|
||||
$request->setTemplateParam($smsParam);
|
||||
//选填-发送短信流水号
|
||||
//$request->setOutId("1234");
|
||||
|
||||
//发起访问请求
|
||||
$resp = $acsClient->getAcsResponse($request);
|
||||
|
||||
//短信发送成功返回True,失败返回false
|
||||
if ($resp && $resp->Code == 'OK') {
|
||||
return array('status' => 1, 'msg' => $resp->Code);
|
||||
} else {
|
||||
return array('status' => -1, 'msg' => $resp->Message . '. Code: ' . $resp->Code);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送短信(腾讯云短信)
|
||||
* @param $mobile 手机号码
|
||||
* @param $code 验证码
|
||||
* @return bool 短信发送成功返回true失败返回false
|
||||
*/
|
||||
private function sendSmsByTencentCloud($mobile, $smsSign, $smsParam, $templateCode)
|
||||
{
|
||||
// 短信应用SDK AppID 1400开头
|
||||
$appid = $this->config['sms_appid_tx'];
|
||||
|
||||
// 短信应用SDK AppKey
|
||||
$appkey = $this->config['sms_appkey_tx'];
|
||||
if (empty($appid) || empty($appkey)) {
|
||||
return array('status' => -1, 'msg' => '请设置短信平台appkid和appkey');
|
||||
}
|
||||
|
||||
// 需要发送短信的手机号码
|
||||
$phoneNumbers = $mobile;
|
||||
|
||||
// 短信模板ID,需要在短信应用中申请
|
||||
$templateId = $templateCode; // NOTE: 这里的模板ID`7839`只是一个示例,真实的模板ID需要在短信控制台中申请
|
||||
|
||||
// 签名
|
||||
$smsSign = $smsSign; // NOTE: 这里的签名只是示例,请使用真实的已申请的签名,签名参数使用的是`签名内容`,而不是`签名ID`
|
||||
// var_dump($smsParam);exit;
|
||||
|
||||
// 单发短信
|
||||
Vendor('tencentsms.SmsSingleSender');
|
||||
$ssender = new \SmsSingleSender($appid, $appkey);
|
||||
$params = $smsParam;//数组具体的元素个数和模板中变量个数必须一致,例如事例中 templateId:5678对应一个变量,参数数组中元素个数也必须是一个
|
||||
$result = $ssender->sendWithParam("86", $phoneNumbers, $templateId,
|
||||
$params, $smsSign, "", ""); // 签名参数未提供或者为空时,会使用默认签名发送短信
|
||||
$resp = json_decode($result,TRUE);
|
||||
|
||||
//短信发送成功返回True,失败返回false
|
||||
if ($resp && $resp['errmsg'] == 'OK') {
|
||||
return array('status' => 1, 'msg' => $resp['errmsg']);
|
||||
} else {
|
||||
return array('status' => -1, 'msg' => $resp['errmsg']);
|
||||
}
|
||||
}
|
||||
}
|
||||
1106
src/application/common/model/Arctype.php
Normal file
1106
src/application/common/model/Arctype.php
Normal file
File diff suppressed because it is too large
Load Diff
36
src/application/common/model/AskScoreLevel.php
Normal file
36
src/application/common/model/AskScoreLevel.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 陈风任 <491085389@qq.com>
|
||||
* Date: 2019-07-30
|
||||
*/
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 模型
|
||||
*/
|
||||
class AskScoreLevel extends Model
|
||||
{
|
||||
/**
|
||||
* 数据表名,不带前缀
|
||||
*/
|
||||
public $name = 'ask_score_level';
|
||||
|
||||
//初始化
|
||||
protected function initialize()
|
||||
{
|
||||
// 需要调用`Model`的`initialize`方法
|
||||
parent::initialize();
|
||||
}
|
||||
|
||||
}
|
||||
40
src/application/common/model/AskType.php
Normal file
40
src/application/common/model/AskType.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 陈风任 <491085389@qq.com>
|
||||
* Date: 2019-07-30
|
||||
*/
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 模型
|
||||
*/
|
||||
class AskType extends Model
|
||||
{
|
||||
/**
|
||||
* 数据表名,不带前缀
|
||||
*/
|
||||
public $name = 'ask_type';
|
||||
|
||||
/**
|
||||
* 插件标识
|
||||
*/
|
||||
public $code = 'Askr';
|
||||
|
||||
//初始化
|
||||
protected function initialize()
|
||||
{
|
||||
// 需要调用`Model`的`initialize`方法
|
||||
parent::initialize();
|
||||
}
|
||||
}
|
||||
70
src/application/common/model/Channelfield.php
Normal file
70
src/application/common/model/Channelfield.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* 模型自定义字段
|
||||
*/
|
||||
class Channelfield extends Model
|
||||
{
|
||||
//初始化
|
||||
protected function initialize()
|
||||
{
|
||||
// 需要调用`Model`的`initialize`方法
|
||||
parent::initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单条记录
|
||||
* @author 小虎哥 by 2018-4-16
|
||||
*/
|
||||
public function getInfo($id, $field = '*')
|
||||
{
|
||||
$result = Db::name('Channelfield')->field($field)->find($id);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单条记录
|
||||
* @author 小虎哥 by 2018-4-16
|
||||
*/
|
||||
public function getInfoByWhere($where, $field = '*')
|
||||
{
|
||||
$result = Db::name('Channelfield')->field($field)->where($where)->cache(true,EYOUCMS_CACHE_TIME,"channelfield")->find();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 默认模型字段
|
||||
* @author 小虎哥 by 2018-4-16
|
||||
*/
|
||||
public function getListByWhere($map = array(), $field = '*', $index_key = '')
|
||||
{
|
||||
$result = Db::name('Channelfield')->field($field)
|
||||
->where($map)
|
||||
->order('sort_order asc, channel_id desc, id desc')
|
||||
->select();
|
||||
|
||||
if (!empty($index_key)) {
|
||||
$result = convert_arr_key($result, $index_key);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
193
src/application/common/model/Channeltype.php
Normal file
193
src/application/common/model/Channeltype.php
Normal file
@@ -0,0 +1,193 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* 模型
|
||||
*/
|
||||
class Channeltype extends Model
|
||||
{
|
||||
//初始化
|
||||
protected function initialize()
|
||||
{
|
||||
// 需要调用`Model`的`initialize`方法
|
||||
parent::initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单条记录
|
||||
* @author 小虎哥 by 2018-4-16
|
||||
*/
|
||||
public function getInfo($id)
|
||||
{
|
||||
$result = M('channeltype')->field('*')->cache(true,EYOUCMS_CACHE_TIME,"channeltype")->find($id);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单条记录
|
||||
* @author 小虎哥 by 2018-4-16
|
||||
*/
|
||||
public function getInfoByWhere($where, $field = '*')
|
||||
{
|
||||
$result = M('channeltype')->field($field)->where($where)->find();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取多条记录
|
||||
* @author 小虎哥 by 2018-4-16
|
||||
*/
|
||||
public function getListByIds($ids, $field = '*')
|
||||
{
|
||||
$map = array(
|
||||
'id' => array('IN', $ids),
|
||||
);
|
||||
$result = Db::name('Channeltype')->field($field)
|
||||
->where($map)
|
||||
->order('sort_order asc')
|
||||
->select();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 默认获取全部
|
||||
* @author 小虎哥 by 2018-4-16
|
||||
*/
|
||||
public function getAll($field = '*', $map = array(), $index_key = '')
|
||||
{
|
||||
$cacheKey = array(
|
||||
'common',
|
||||
'model',
|
||||
'Channeltype',
|
||||
'getAll',
|
||||
$field,
|
||||
$map,
|
||||
$index_key
|
||||
);
|
||||
$cacheKey = json_encode($cacheKey);
|
||||
$result = cache($cacheKey);
|
||||
if (empty($result)) {
|
||||
$result = Db::name('channeltype')->field($field)
|
||||
->where($map)
|
||||
->order('sort_order asc, id asc')
|
||||
->select();
|
||||
|
||||
if (!empty($index_key)) {
|
||||
$result = convert_arr_key($result, $index_key);
|
||||
}
|
||||
|
||||
cache($cacheKey, $result, null, 'channeltype');
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取有栏目的模型列表
|
||||
* @param string $type yes表示存在栏目的模型列表,no表示不存在栏目的模型列表
|
||||
* @author 小虎哥 by 2018-4-16
|
||||
*/
|
||||
public function getArctypeChannel($type = 'yes')
|
||||
{
|
||||
if ($type == 'yes') {
|
||||
$map = array(
|
||||
'b.status' => 1,
|
||||
);
|
||||
$result = M('Channeltype')->field('b.*, a.*, b.id as typeid')
|
||||
->alias('a')
|
||||
->join('__ARCTYPE__ b', 'b.current_channel = a.id', 'LEFT')
|
||||
->where($map)
|
||||
->group('a.id')
|
||||
->cache(true,EYOUCMS_CACHE_TIME,"arctype")
|
||||
->getAllWithIndex('nid');
|
||||
|
||||
} else {
|
||||
$result = M('Channeltype')->field('b.*, a.*, b.id as typeid')
|
||||
->alias('a')
|
||||
->join('__ARCTYPE__ b', 'b.current_channel = a.id', 'LEFT')
|
||||
->group('a.id')
|
||||
->cache(true,EYOUCMS_CACHE_TIME,"arctype")
|
||||
->getAllWithIndex('nid');
|
||||
|
||||
if ($result) {
|
||||
foreach ($result as $key => $val) {
|
||||
if (intval($val['channeltype']) > 0) {
|
||||
unset($result[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据文档ID获取模型信息
|
||||
* @author 小虎哥 by 2018-4-16
|
||||
*/
|
||||
public function getInfoByAid($aid)
|
||||
{
|
||||
$result = array();
|
||||
$res1 = M('archives')->where(array('aid'=>$aid))->find();
|
||||
$res2 = M('Channeltype')->where(array('id'=>$res1['channel']))->find();
|
||||
|
||||
if (is_array($res1) && is_array($res2)) {
|
||||
$result = array_merge($res1, $res2);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据前端模板自动开启系统模型
|
||||
*/
|
||||
public function setChanneltypeStatus()
|
||||
{
|
||||
$planPath = 'template/'.TPL_THEME.'pc';
|
||||
$planPath = realpath($planPath);
|
||||
if (!file_exists($planPath)) {
|
||||
return true;
|
||||
}
|
||||
$ctl_name_arr = array();
|
||||
$dirRes = opendir($planPath);
|
||||
$view_suffix = config('template.view_suffix');
|
||||
while($filename = readdir($dirRes))
|
||||
{
|
||||
if(preg_match('/^(lists|view)?_/i', $filename) == 1)
|
||||
{
|
||||
$tplname = preg_replace('/([^_]+)?_([^\.]+)\.'.$view_suffix.'$/i', '${2}', $filename);
|
||||
$ctl_name_arr[] = ucwords($tplname);
|
||||
} elseif (preg_match('/\.'.$view_suffix.'$/i', $filename) == 1) {
|
||||
$tplname = preg_replace('/\.'.$view_suffix.'$/i', '', $filename);
|
||||
$ctl_name_arr[] = ucwords($tplname);
|
||||
}
|
||||
}
|
||||
$ctl_name_arr = array_unique($ctl_name_arr);
|
||||
|
||||
if (!empty($ctl_name_arr)) {
|
||||
\think\Db::name('Channeltype')->where('id > 0')->cache(true,null,"channeltype")->update(array('status'=>0, 'update_time'=>getTime()));
|
||||
$map = array(
|
||||
'ctl_name' => array('IN', $ctl_name_arr),
|
||||
);
|
||||
\think\Db::name('Channeltype')->where($map)->cache(true,null,"channeltype")->update(array('status'=>1, 'update_time'=>getTime()));
|
||||
}
|
||||
}
|
||||
}
|
||||
29
src/application/common/model/Config.php
Normal file
29
src/application/common/model/Config.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 全局配置
|
||||
*/
|
||||
class Config extends Model
|
||||
{
|
||||
//初始化
|
||||
protected function initialize()
|
||||
{
|
||||
// 需要调用`Model`的`initialize`方法
|
||||
parent::initialize();
|
||||
}
|
||||
}
|
||||
29
src/application/common/model/ConfigAttribute.php
Normal file
29
src/application/common/model/ConfigAttribute.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 全局自定义变量设置
|
||||
*/
|
||||
class ConfigAttribute extends Model
|
||||
{
|
||||
//初始化
|
||||
protected function initialize()
|
||||
{
|
||||
// 需要调用`Model`的`initialize`方法
|
||||
parent::initialize();
|
||||
}
|
||||
}
|
||||
78
src/application/common/model/EyouUsers.php
Normal file
78
src/application/common/model/EyouUsers.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 陈风任 <491085389@qq.com>
|
||||
* Date: 2019-1-25
|
||||
*/
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 公共会员模型
|
||||
*/
|
||||
class EyouUsers extends Model
|
||||
{
|
||||
//初始化
|
||||
protected function initialize()
|
||||
{
|
||||
// 需要调用`Model`的`initialize`方法
|
||||
parent::initialize();
|
||||
}
|
||||
|
||||
// 更新会员级别信息
|
||||
public function UpUsersLevelData($users_id = null)
|
||||
{
|
||||
$LevelData = [];
|
||||
/*查询系统初始的默认级别*/
|
||||
$LevelWhere = [
|
||||
'level_id' => 1,
|
||||
'is_system' => 1,
|
||||
'lang' => get_home_lang(),
|
||||
];
|
||||
$level = M('users_level')->where($LevelWhere)->field('level_id,level_name,level_value')->find();
|
||||
if (empty($level)) $level = ['level'=>1, 'level_name'=>'注册会员', 'level_value'=>10];
|
||||
/* END */
|
||||
|
||||
/*更新信息*/
|
||||
$LevelData = [
|
||||
'level' => $level['level_id'],
|
||||
'open_level_time' => 0,
|
||||
'level_maturity_days' => 0,
|
||||
'update_time' => getTime(),
|
||||
];
|
||||
$return = M('users')->where('users_id', $users_id)->update($LevelData);
|
||||
/* END */
|
||||
|
||||
if (!empty($return)) {
|
||||
$LevelData['level_name'] = $level['level_name'];
|
||||
$LevelData['level_value'] = $level['level_value'];
|
||||
return $LevelData;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
// 会员登录之后的业务逻辑
|
||||
public function loginAfter($users)
|
||||
{
|
||||
session('users', $users);
|
||||
session('users_id', $users['users_id']);
|
||||
cookie('users_id', $users['users_id']);
|
||||
|
||||
$data = [
|
||||
'last_ip' => clientIP(),
|
||||
'last_login' => getTime(),
|
||||
'login_count' => Db::raw('login_count+1'),
|
||||
];
|
||||
Db::name('users')->where('users_id', $users['users_id'])->update($data);
|
||||
}
|
||||
}
|
||||
716
src/application/common/model/Language.php
Normal file
716
src/application/common/model/Language.php
Normal file
@@ -0,0 +1,716 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* 模型
|
||||
*/
|
||||
class Language extends Model
|
||||
{
|
||||
//初始化
|
||||
protected function initialize()
|
||||
{
|
||||
// 需要调用`Model`的`initialize`方法
|
||||
parent::initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* 后置操作方法
|
||||
* 自定义的一个函数 用于数据新增之后做的相应处理操作, 使用时手动调用
|
||||
* @param int $aid 产品id
|
||||
* @param array $post post数据
|
||||
* @param string $opt 操作
|
||||
*/
|
||||
public function afterAdd($insertId = '', $post = [])
|
||||
{
|
||||
$mark = trim($post['mark']);
|
||||
|
||||
/*设置默认语言,只允许有一个是默认,其他取消*/
|
||||
if (1 == intval($post['is_home_default'])) {
|
||||
$this->where('id','NEQ',$insertId)->update([
|
||||
'is_home_default' => 0,
|
||||
'update_time' => getTime(),
|
||||
]);
|
||||
/*多语言 设置默认前台语言*/
|
||||
if (is_language()) {
|
||||
$langRow = \think\Db::name('language')->order('id asc')
|
||||
->cache(true, EYOUCMS_CACHE_TIME, 'language')
|
||||
->select();
|
||||
foreach ($langRow as $key => $val) {
|
||||
tpCache('system', ['system_home_default_lang'=>$mark], $val['mark']);
|
||||
}
|
||||
} else { // 单语言
|
||||
tpCache('system', ['system_home_default_lang'=>$mark]);
|
||||
}
|
||||
/*--end*/
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
/*复制栏目表以及关联数据*/
|
||||
$syn_status = $this->syn_arctype($mark, $post['copy_lang']);
|
||||
if (false === $syn_status) {
|
||||
return $syn_status;
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
/*复制阅读权限表数据*/
|
||||
$arcrank_db = Db::name('arcrank');
|
||||
$arcrankCount = $arcrank_db->where('lang',$mark)->count();
|
||||
if (empty($arcrankCount)) {
|
||||
$arcrankRow = $arcrank_db->field('id,lang',true)
|
||||
->where('lang', $post['copy_lang'])
|
||||
->order('id asc')
|
||||
->select();
|
||||
if (!empty($arcrankRow)) {
|
||||
foreach ($arcrankRow as $key => $val) {
|
||||
$arcrankRow[$key]['lang'] = $mark;
|
||||
}
|
||||
$insertNum = $arcrank_db->insertAll($arcrankRow);
|
||||
if ($insertNum != count($arcrankRow)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
/*复制网站配置表数据*/
|
||||
$config_db = Db::name('config');
|
||||
$configCount = $config_db->where('lang',$mark)->count();
|
||||
if (empty($configCount)) {
|
||||
$configRow = $config_db->field('id,lang',true)
|
||||
->where('lang', $post['copy_lang'])
|
||||
->order('id asc')
|
||||
->select();
|
||||
if (!empty($configRow)) {
|
||||
|
||||
/* 生成静态页面代码 */
|
||||
$markArr = Db::name('language')->field('mark')->order('id asc')->limit('1,1')->select();
|
||||
if (!empty($markArr)) {
|
||||
$seo_pseudo_lang = tpCache('seo.seo_pseudo', [], $markArr[0]['mark']);
|
||||
$seo_dynamic_format_lang = tpCache('seo.seo_dynamic_format', [], $markArr[0]['mark']);
|
||||
$seo_rewrite_format_lang = tpCache('seo.seo_rewrite_format', [], $markArr[0]['mark']);
|
||||
}
|
||||
$seo_pseudo_lang = !empty($seo_pseudo_lang) ? $seo_pseudo_lang : 1;
|
||||
$seo_dynamic_format_lang = !empty($seo_dynamic_format_lang) ? $seo_dynamic_format_lang : 1;
|
||||
$seo_rewrite_format_lang = !empty($seo_rewrite_format_lang) ? $seo_rewrite_format_lang : 1;
|
||||
/* end */
|
||||
|
||||
foreach ($configRow as $key => $val) {
|
||||
$configRow[$key]['lang'] = $mark;
|
||||
/*临时测试*/
|
||||
if ('web_name' == $val['name']) {
|
||||
$configRow[$key]['value'] = $mark.$val['value'];
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
/**
|
||||
* 生成静态页面代码
|
||||
* 新增语言的URL模式必须与第二个语言一致
|
||||
* 如果没有第二个语言,那么URL模式默认为动态
|
||||
*/
|
||||
if ('seo_pseudo' == $val['name']) {
|
||||
$configRow[$key]['value'] = $seo_pseudo_lang;
|
||||
} else if ('seo_dynamic_format' == $val['name']) {
|
||||
$configRow[$key]['value'] = $seo_dynamic_format_lang;
|
||||
} else if ('seo_rewrite_format' == $val['name']) {
|
||||
$configRow[$key]['value'] = $seo_rewrite_format_lang;
|
||||
}
|
||||
/* end */
|
||||
}
|
||||
$insertObject = model('Config')->saveAll($configRow);
|
||||
$insertNum = count($insertObject);
|
||||
if ($insertNum != count($configRow)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
/*复制自定义变量表数据*/
|
||||
$configattribute_db = Db::name('config_attribute');
|
||||
$configattributeCount = $configattribute_db->where('lang',$mark)->count();
|
||||
if (empty($configattributeCount)) {
|
||||
$configAttrRow = $configattribute_db->field('attr_id,lang',true)
|
||||
->where('lang', $post['copy_lang'])
|
||||
->order('attr_id asc')
|
||||
->select();
|
||||
if (!empty($configAttrRow)) {
|
||||
foreach ($configAttrRow as $key => $val) {
|
||||
$configAttrRow[$key]['lang'] = $mark;
|
||||
}
|
||||
$insertObject = model('ConfigAttribute')->saveAll($configAttrRow);
|
||||
$insertNum = count($insertObject);
|
||||
if ($insertNum != count($configAttrRow)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
/*复制广告位置表以及广告表数据*/
|
||||
$syn_status = $this->syn_ad_position($mark, $post['copy_lang']);
|
||||
if (false === $syn_status) {
|
||||
return $syn_status;
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
/*复制友情链接分组表以及友情链接表数据*/
|
||||
$syn_status = $this->syn_links_group($mark, $post['copy_lang']);
|
||||
if (false === $syn_status) {
|
||||
return $syn_status;
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
/*复制友情链接表数据*/
|
||||
/*$links_db = Db::name('links');
|
||||
$linksCount = $links_db->where('lang',$mark)->count();
|
||||
if (empty($linksCount)) {
|
||||
$linksRow = $links_db->field('id,lang',true)
|
||||
->where('lang', $post['copy_lang'])
|
||||
->order('id asc')
|
||||
->select();
|
||||
if (!empty($linksRow)) {
|
||||
foreach ($linksRow as $key => $val) {
|
||||
$linksRow[$key]['lang'] = $mark;
|
||||
$linksRow[$key]['title'] = $mark.$val['title']; // 临时测试
|
||||
}
|
||||
$insertObject = model('Links')->saveAll($linksRow);
|
||||
$insertNum = count($insertObject);
|
||||
if ($insertNum != count($linksRow)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
/*--end*/
|
||||
|
||||
/*复制邮件模板表数据*/
|
||||
$smtp_tpl_db = Db::name('smtp_tpl');
|
||||
$smtptplCount = $smtp_tpl_db->where('lang',$mark)->count();
|
||||
if (empty($smtptplCount)) {
|
||||
$smtptplRow = $smtp_tpl_db->field('tpl_id,lang',true)
|
||||
->where('lang', $post['copy_lang'])
|
||||
->order('tpl_id asc')
|
||||
->select();
|
||||
if (!empty($smtptplRow)) {
|
||||
foreach ($smtptplRow as $key => $val) {
|
||||
$smtptplRow[$key]['lang'] = $mark;
|
||||
}
|
||||
$insertObject = model('SmtpTpl')->saveAll($smtptplRow);
|
||||
$insertNum = count($insertObject);
|
||||
if ($insertNum != count($smtptplRow)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
/*复制模板语言包变量表数据*/
|
||||
$langpack_db = Db::name('language_pack');
|
||||
$langpackCount = $langpack_db->where('lang',$mark)->count();
|
||||
if (empty($langpackCount)) {
|
||||
$langpackRow = $langpack_db->field('id,lang',true)
|
||||
->where([
|
||||
'lang' => $post['copy_lang'],
|
||||
'is_syn' => 0,
|
||||
])
|
||||
->order('id asc')
|
||||
->select();
|
||||
if (!empty($langpackRow)) {
|
||||
foreach ($langpackRow as $key => $val) {
|
||||
$langpackRow[$key]['lang'] = $mark;
|
||||
}
|
||||
$insertObject = model('LanguagePack')->saveAll($langpackRow);
|
||||
$insertNum = count($insertObject);
|
||||
if ($insertNum != count($langpackRow)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
/*统计多语言数量*/
|
||||
$this->setLangNum();
|
||||
/*--end*/
|
||||
|
||||
\think\Cache::clear('language');
|
||||
delFile(RUNTIME_PATH.'cache'.DS.$mark, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 统计多语言数量
|
||||
*/
|
||||
public function setLangNum()
|
||||
{
|
||||
\think\Cache::clear('system_langnum');
|
||||
$languageRow = Db::name('language')->field('mark')->select();
|
||||
$system_langnum = count($languageRow);
|
||||
foreach ($languageRow as $key => $val) {
|
||||
tpCache('system', ['system_langnum'=>$system_langnum], $val['mark']);
|
||||
}
|
||||
|
||||
// 记录多语言启用数量
|
||||
$system_langnum = 1;
|
||||
$web_language_switch = tpCache('web.web_language_switch');
|
||||
if (!empty($web_language_switch)) {
|
||||
$system_langnum = Db::name('language')->where(['status'=>1])->count();
|
||||
}
|
||||
$tfile = DATA_PATH.'conf'.DS.'lang_enable_num.txt';
|
||||
$fp = @fopen($tfile,'w');
|
||||
if(!$fp) {
|
||||
@file_put_contents($tfile, $system_langnum);
|
||||
}
|
||||
else {
|
||||
fwrite($fp, $system_langnum);
|
||||
fclose($fp);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 后置操作方法
|
||||
* 自定义的一个函数 用于数据删除之后做的相应处理操作, 使用时手动调用
|
||||
* @param int $aid 产品id
|
||||
* @param array $post post数据
|
||||
* @param string $opt 操作
|
||||
*/
|
||||
public function afterDel($id_arr = [], $lang_list = [])
|
||||
{
|
||||
if (!empty($id_arr) && !empty($lang_list)) {
|
||||
\think\Cache::clear('language');
|
||||
foreach ($lang_list as $key => $lang) {
|
||||
delFile(RUNTIME_PATH.'cache'.DS.$lang, true);
|
||||
@unlink(APP_PATH."lang/{$lang}.php");
|
||||
}
|
||||
/*统计多语言数量*/
|
||||
$this->setLangNum();
|
||||
/*同步删除模板栏目绑定表数据*/
|
||||
Db::name('language_attr')->where("lang",'IN',$lang_list)->delete();
|
||||
/*同步删除模板语言变量表数据*/
|
||||
Db::name('language_pack')->where("lang",'IN',$lang_list)->delete();
|
||||
/*同步删除阅读权限表数据*/
|
||||
Db::name('arcrank')->where("lang",'IN',$lang_list)->delete();
|
||||
/*同步删除基础信息表数据*/
|
||||
Db::name('config')->where("lang",'IN',$lang_list)->delete();
|
||||
/*同步删除自定义变量表数据*/
|
||||
Db::name('config_attribute')->where("lang",'IN',$lang_list)->delete();
|
||||
/*同步删除栏目表以及文档表数据*/
|
||||
$typeids = Db::name('arctype')->where("lang",'IN',$lang_list)->column('id');
|
||||
//待删除栏目ID集合
|
||||
Db::name('arctype')->where("lang",'IN',$lang_list)->delete(); // 栏目表
|
||||
$aids = Db::name('archives')->where("typeid",'IN',$typeids)->column('aid');
|
||||
//待删除文档ID集合
|
||||
Db::name('archives')->where("aid",'IN',$aids)->delete(); // 文档主表
|
||||
Db::name('article_content')->where("aid",'IN',$aids)->delete(); // 文章内容表
|
||||
Db::name('download_content')->where("aid",'IN',$aids)->delete(); // 软件内容表
|
||||
Db::name('download_file')->where("aid",'IN',$aids)->delete(); // 软件附件表
|
||||
Db::name('guestbook')->where("aid",'IN',$aids)->delete(); // 留言主表
|
||||
Db::name('guestbook_attr')->where("aid",'IN',$aids)->delete(); // 留言内容表
|
||||
Db::name('images_content')->where("aid",'IN',$aids)->delete(); // 图集内容表
|
||||
Db::name('images_upload')->where("aid",'IN',$aids)->delete(); // 图集图片表
|
||||
Db::name('product_content')->where("aid",'IN',$aids)->delete(); // 产品内容表
|
||||
Db::name('product_img')->where("aid",'IN',$aids)->delete(); // 产品图集表
|
||||
Db::name('single_content')->where("aid",'IN',$aids)->delete(); // 单页内容表
|
||||
/*同步删除产品属性表数据*/
|
||||
Db::name('product_attribute')->where("lang",'IN',$lang_list)->delete();
|
||||
/*同步删除留言属性表数据*/
|
||||
Db::name('guestbook_attribute')->where("lang",'IN',$lang_list)->delete();
|
||||
/*同步删除广告表数据*/
|
||||
Db::name('ad')->where("lang",'IN',$lang_list)->delete();
|
||||
/*同步删除广告位置表数据*/
|
||||
Db::name('ad_position')->where("lang",'IN',$lang_list)->delete();
|
||||
/*同步删除友情链接表数据*/
|
||||
Db::name('links')->where("lang",'IN',$lang_list)->delete();
|
||||
/*同步删除友情链接分组表数据*/
|
||||
Db::name('links_group')->where("lang",'IN',$lang_list)->delete();
|
||||
/*同步删除可视化表数据*/
|
||||
Db::name('ui_config')->where("lang",'IN',$lang_list)->delete();
|
||||
/*同步删除Tag标签表数据*/
|
||||
Db::name('taglist')->where("lang",'IN',$lang_list)->delete();
|
||||
/*同步删除标签索引表数据*/
|
||||
Db::name('tagindex')->where("lang",'IN',$lang_list)->delete();
|
||||
/*同步删除邮件模板表数据*/
|
||||
Db::name('smtp_tpl')->where("lang",'IN',$lang_list)->delete();
|
||||
/*同步删除邮件发送记录表数据*/
|
||||
Db::name('smtp_record')->where("lang",'IN',$lang_list)->delete();
|
||||
/*同步删除短信模板表数据*/
|
||||
Db::name('sms_template')->where("lang",'IN',$lang_list)->delete();
|
||||
/*同步删除短信发送记录表数据*/
|
||||
Db::name('sms_log')->where("lang",'IN',$lang_list)->delete();
|
||||
/*同步删除站内信模板表数据*/
|
||||
Db::name('users_notice_tpl')->where("lang",'IN',$lang_list)->delete();
|
||||
/*同步删除站内信发送记录表数据*/
|
||||
Db::name('users_notice_tpl_content')->where("lang",'IN',$lang_list)->delete();
|
||||
/*会员中心移动端底部菜单表*/
|
||||
Db::name('users_bottom_menu')->where("lang",'IN',$lang_list)->delete();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建语言时,同步第一个语言的栏目到新语言里
|
||||
*
|
||||
* @param string $mark 新增语言
|
||||
* @param string $copy_lang 复制语言
|
||||
*/
|
||||
private function syn_arctype($mark = '', $copy_lang = 'cn')
|
||||
{
|
||||
$arctype_db = Db::name('arctype');
|
||||
|
||||
/*删除新增语言之前的多余数据*/
|
||||
$count = $arctype_db->where('lang',$mark)->count();
|
||||
if (!empty($count)) {
|
||||
$arctype_db->where("lang",$mark)->delete();
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
$bindArctypeArr = []; // 源栏目ID与目标栏目ID的对应数组
|
||||
$arctypeLogic = new \app\common\logic\ArctypeLogic;
|
||||
$arctypeList = $arctypeLogic->arctype_list(0, 0, false, 0, ['lang'=>$copy_lang]);
|
||||
|
||||
if (empty($mark) || empty($arctypeList)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*复制产品属性表数据*/
|
||||
$bindProductAttributeArr = []; // 源产品属性ID与目标产品属性ID的对应数组
|
||||
$product_attribute_db = Db::name('product_attribute');
|
||||
$productAttributeRow = $product_attribute_db->where('lang',$copy_lang)
|
||||
->order('attr_id asc')
|
||||
->select();
|
||||
$productAttributeRow = group_same_key($productAttributeRow, 'typeid');
|
||||
/*--end*/
|
||||
|
||||
/*复制留言属性表数据*/
|
||||
$bindgbookAttributeArr = []; // 源留言属性ID与目标留言属性ID的对应数组
|
||||
$guestbook_attribute_db = Db::name('guestbook_attribute');
|
||||
$gbookAttributeRow = $guestbook_attribute_db->where('lang',$copy_lang)
|
||||
->order('attr_id asc')
|
||||
->select();
|
||||
$gbookAttributeRow = group_same_key($gbookAttributeRow, 'typeid');
|
||||
/*--end*/
|
||||
|
||||
/*复制栏目表数据*/
|
||||
$arctype_M = model('Arctype');
|
||||
foreach ($arctypeList as $key => $val) {
|
||||
$data = $val;
|
||||
unset($data['id']);
|
||||
$data['lang'] = $mark;
|
||||
$data['typename'] = $mark.$data['typename']; // 临时测试
|
||||
$data['parent_id'] = !empty($bindArctypeArr[$val['parent_id']]) ? $bindArctypeArr[$val['parent_id']] : 0;
|
||||
$typeid = $arctype_M->addData($data);
|
||||
if (empty($typeid)) {
|
||||
return false; // 同步失败
|
||||
}
|
||||
$bindArctypeArr[$val['id']] = $typeid;
|
||||
/*复制产品属性表数据*/
|
||||
if (!empty($productAttributeRow[$val['id']])) {
|
||||
foreach ($productAttributeRow[$val['id']] as $k2 => $v2) {
|
||||
$proArr = $v2;
|
||||
$proArr['typeid'] = $typeid;
|
||||
$proArr['lang'] = $mark;
|
||||
unset($proArr['attr_id']);
|
||||
$proArr['attr_name'] = $mark.$proArr['attr_name']; // 临时测试
|
||||
$new_attr_id = $product_attribute_db->insertGetId($proArr);
|
||||
if (empty($new_attr_id)) {
|
||||
return false; // 同步失败
|
||||
}
|
||||
$bindProductAttributeArr[$v2['attr_id']] = $new_attr_id;
|
||||
}
|
||||
}
|
||||
/*--end*/
|
||||
/*复制留言属性表数据*/
|
||||
if (!empty($gbookAttributeRow[$val['id']])) {
|
||||
foreach ($gbookAttributeRow[$val['id']] as $k2 => $v2) {
|
||||
$gbArr = $v2;
|
||||
$gbArr['typeid'] = $typeid;
|
||||
$gbArr['lang'] = $mark;
|
||||
unset($gbArr['attr_id']);
|
||||
$gbArr['attr_name'] = $mark.$gbArr['attr_name']; // 临时测试
|
||||
$new_attr_id = $guestbook_attribute_db->insertGetId($gbArr);
|
||||
if (empty($new_attr_id)) {
|
||||
return false; // 同步失败
|
||||
}
|
||||
$bindgbookAttributeArr[$v2['attr_id']] = $new_attr_id;
|
||||
}
|
||||
}
|
||||
/*--end*/
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
$langAttrData = [];
|
||||
|
||||
/*新增栏目ID与源栏目ID的绑定*/
|
||||
foreach ($bindArctypeArr as $key => $val) {
|
||||
$langAttrData[] = [
|
||||
'attr_name' => 'tid'.$key,
|
||||
'attr_value' => $val,
|
||||
'lang' => $mark,
|
||||
'attr_group' => 'arctype',
|
||||
'add_time' => getTime(),
|
||||
'update_time' => getTime(),
|
||||
];
|
||||
}
|
||||
/*--end*/
|
||||
/*新增产品属性ID与源产品属性ID的绑定*/
|
||||
foreach ($bindProductAttributeArr as $key => $val) {
|
||||
$langAttrData[] = [
|
||||
'attr_name' => 'attr_'.$key,
|
||||
'attr_value' => $val,
|
||||
'lang' => $mark,
|
||||
'attr_group' => 'product_attribute',
|
||||
'add_time' => getTime(),
|
||||
'update_time' => getTime(),
|
||||
];
|
||||
}
|
||||
/*--end*/
|
||||
/*新增留言属性ID与源留言属性ID的绑定*/
|
||||
foreach ($bindgbookAttributeArr as $key => $val) {
|
||||
$langAttrData[] = [
|
||||
'attr_name' => 'attr_'.$key,
|
||||
'attr_value' => $val,
|
||||
'lang' => $mark,
|
||||
'attr_group' => 'guestbook_attribute',
|
||||
'add_time' => getTime(),
|
||||
'update_time' => getTime(),
|
||||
];
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
// 批量存储
|
||||
if (!empty($langAttrData)) {
|
||||
$insertObject = model('LanguageAttr')->saveAll($langAttrData);
|
||||
$insertNum = count($insertObject);
|
||||
if ($insertNum != count($langAttrData)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建语言时,同步广告位置以及广告数据,并进行多语言关联绑定
|
||||
*
|
||||
* @param string $mark 新增语言
|
||||
* @param string $copy_lang 复制语言
|
||||
*/
|
||||
private function syn_ad_position($mark = '', $copy_lang = 'cn')
|
||||
{
|
||||
$ad_position_db = Db::name('ad_position');
|
||||
|
||||
/*删除新增语言之前的多余数据*/
|
||||
$count = $ad_position_db->where('lang',$mark)->count();
|
||||
if (!empty($count)) {
|
||||
$ad_position_db->where("lang",$mark)->delete();
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
// 广告位置列表
|
||||
$bindAdpositionArr = []; // 源广告位置ID与目标广告位置ID的对应数组
|
||||
$adpositionList = $ad_position_db->where([
|
||||
'lang'=>$copy_lang
|
||||
])->order('id asc')
|
||||
->select();
|
||||
|
||||
if (empty($mark) || empty($adpositionList)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*复制广告表数据*/
|
||||
$bindAdArr = []; // 源广告ID与目标广告ID的对应数组
|
||||
$ad_db = Db::name('ad');
|
||||
$adRow = $ad_db->where('lang',$copy_lang)
|
||||
->order('id asc')
|
||||
->select();
|
||||
$adRow = group_same_key($adRow, 'pid');
|
||||
/*--end*/
|
||||
|
||||
/*复制广告位置表数据*/
|
||||
foreach ($adpositionList as $key => $val) {
|
||||
$data = $val;
|
||||
unset($data['id']);
|
||||
$data['lang'] = $mark;
|
||||
$data['title'] = $mark.$data['title']; // 临时测试
|
||||
$pid = $ad_position_db->insertGetId($data);
|
||||
if (empty($pid)) {
|
||||
return false; // 同步失败
|
||||
}
|
||||
$bindAdpositionArr[$val['id']] = $pid;
|
||||
/*复制广告表数据*/
|
||||
if (!empty($adRow[$val['id']])) {
|
||||
foreach ($adRow[$val['id']] as $k2 => $v2) {
|
||||
$adArr = $v2;
|
||||
$adArr['pid'] = $pid;
|
||||
$adArr['lang'] = $mark;
|
||||
unset($adArr['id']);
|
||||
$adArr['title'] = $mark.$adArr['title']; // 临时测试
|
||||
$new_ad_id = $ad_db->insertGetId($adArr);
|
||||
if (empty($new_ad_id)) {
|
||||
return false; // 同步失败
|
||||
}
|
||||
$bindAdArr[$v2['id']] = $new_ad_id;
|
||||
}
|
||||
}
|
||||
/*--end*/
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
$langAttrData = [];
|
||||
|
||||
/*新增广告位置ID与源广告位置ID的绑定*/
|
||||
foreach ($bindAdpositionArr as $key => $val) {
|
||||
$langAttrData[] = [
|
||||
'attr_name' => 'adp'.$key,
|
||||
'attr_value' => $val,
|
||||
'lang' => $mark,
|
||||
'attr_group' => 'ad_position',
|
||||
'add_time' => getTime(),
|
||||
'update_time' => getTime(),
|
||||
];
|
||||
}
|
||||
/*--end*/
|
||||
/*新增广告ID与源广告ID的绑定*/
|
||||
foreach ($bindAdArr as $key => $val) {
|
||||
$langAttrData[] = [
|
||||
'attr_name' => 'ad'.$key,
|
||||
'attr_value' => $val,
|
||||
'lang' => $mark,
|
||||
'attr_group' => 'ad',
|
||||
'add_time' => getTime(),
|
||||
'update_time' => getTime(),
|
||||
];
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
// 批量存储
|
||||
if (!empty($langAttrData)) {
|
||||
$insertObject = model('LanguageAttr')->saveAll($langAttrData);
|
||||
$insertNum = count($insertObject);
|
||||
if ($insertNum != count($langAttrData)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建语言时,同步友链分组以及友情链接数据,并进行多语言关联绑定
|
||||
*
|
||||
* @param string $mark 新增语言
|
||||
* @param string $copy_lang 复制语言
|
||||
*/
|
||||
private function syn_links_group($mark = '', $copy_lang = 'cn')
|
||||
{
|
||||
$links_group_db = Db::name('links_group');
|
||||
|
||||
/*删除新增语言之前的多余数据*/
|
||||
$count = $links_group_db->where('lang',$mark)->count();
|
||||
if (!empty($count)) {
|
||||
$links_group_db->where("lang",$mark)->delete();
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
// 友情链接分组列表
|
||||
$bindLinksGroupArr = []; // 源友情链接分组ID与目标友情链接分组ID的对应数组
|
||||
$linksGroupList = $links_group_db->where([
|
||||
'lang'=>$copy_lang
|
||||
])->order('id asc')
|
||||
->select();
|
||||
|
||||
if (empty($mark) || empty($linksGroupList)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*复制友情链接表数据*/
|
||||
$bindLinksArr = []; // 源友情链接ID与目标友情链接ID的对应数组
|
||||
$links_db = Db::name('links');
|
||||
$linksRow = $links_db->where('lang',$copy_lang)
|
||||
->order('id asc')
|
||||
->select();
|
||||
$linksRow = group_same_key($linksRow, 'groupid');
|
||||
/*--end*/
|
||||
|
||||
/*复制友情链接分组表数据*/
|
||||
foreach ($linksGroupList as $key => $val) {
|
||||
$data = $val;
|
||||
unset($data['id']);
|
||||
$data['lang'] = $mark;
|
||||
$data['group_name'] = $mark.$data['group_name']; // 临时测试
|
||||
$groupid = $links_group_db->insertGetId($data);
|
||||
if (empty($groupid)) {
|
||||
return false; // 同步失败
|
||||
}
|
||||
$bindLinksGroupArr[$val['id']] = $groupid;
|
||||
/*复制友情链接表数据*/
|
||||
if (!empty($linksRow[$val['id']])) {
|
||||
foreach ($linksRow[$val['id']] as $k2 => $v2) {
|
||||
$linksArr = $v2;
|
||||
$linksArr['groupid'] = $groupid;
|
||||
$linksArr['lang'] = $mark;
|
||||
unset($linksArr['id']);
|
||||
$linksArr['title'] = $mark.$linksArr['title']; // 临时测试
|
||||
$new_links_id = $links_db->insertGetId($linksArr);
|
||||
if (empty($new_links_id)) {
|
||||
return false; // 同步失败
|
||||
}
|
||||
$bindLinksArr[$v2['id']] = $new_links_id;
|
||||
}
|
||||
}
|
||||
/*--end*/
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
$langAttrData = [];
|
||||
|
||||
/*新增友情链接分组ID与源友情链接分组ID的绑定*/
|
||||
foreach ($bindLinksGroupArr as $key => $val) {
|
||||
$langAttrData[] = [
|
||||
'attr_name' => 'linkgroup'.$key,
|
||||
'attr_value' => $val,
|
||||
'lang' => $mark,
|
||||
'attr_group' => 'links_group',
|
||||
'add_time' => getTime(),
|
||||
'update_time' => getTime(),
|
||||
];
|
||||
}
|
||||
/*--end*/
|
||||
/*新增友情链接ID与源友情链接ID的绑定*/
|
||||
foreach ($bindLinksArr as $key => $val) {
|
||||
$langAttrData[] = [
|
||||
'attr_name' => 'links'.$key,
|
||||
'attr_value' => $val,
|
||||
'lang' => $mark,
|
||||
'attr_group' => 'links',
|
||||
'add_time' => getTime(),
|
||||
'update_time' => getTime(),
|
||||
];
|
||||
}
|
||||
/*--end*/
|
||||
|
||||
// 批量存储
|
||||
if (!empty($langAttrData)) {
|
||||
$insertObject = model('LanguageAttr')->saveAll($langAttrData);
|
||||
$insertNum = count($insertObject);
|
||||
if ($insertNum != count($langAttrData)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
239
src/application/common/model/LanguageAttr.php
Normal file
239
src/application/common/model/LanguageAttr.php
Normal file
@@ -0,0 +1,239 @@
|
||||
<?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
|
||||
{
|
||||
//初始化
|
||||
protected function initialize()
|
||||
{
|
||||
// 需要调用`Model`的`initialize`方法
|
||||
parent::initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取关联绑定的变量值
|
||||
* @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)) {
|
||||
$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 = '';
|
||||
} 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)) {
|
||||
$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;
|
||||
$bind_value = Db::name('language_attr')->where([
|
||||
'attr_name' => $attr_name,
|
||||
'lang' => $lang,
|
||||
'attr_group' => $attr_group,
|
||||
])->getField('attr_value');
|
||||
empty($bind_value) && $bind_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)) {
|
||||
$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;
|
||||
$bind_value = Db::name('language_attr')->where([
|
||||
'attr_name' => $attr_name,
|
||||
'lang' => $lang,
|
||||
'attr_group' => $attr_group,
|
||||
])->getField('attr_value');
|
||||
empty($bind_value) && $bind_value = '';
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'ad_position':
|
||||
{
|
||||
if (!is_array($bind_value)) {// 获取关联绑定的广告位置ID
|
||||
$attr_name = 'adp'.$bind_value;
|
||||
$bind_value = Db::name('language_attr')->where([
|
||||
'attr_name' => $attr_name,
|
||||
'lang' => $lang,
|
||||
'attr_group' => $attr_group,
|
||||
])->getField('attr_value');
|
||||
empty($bind_value) && $bind_value = '';
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'ad':
|
||||
{
|
||||
if (!is_array($bind_value)) {// 获取关联绑定的广告ID
|
||||
$attr_name = 'ad'.$bind_value;
|
||||
$bind_value = Db::name('language_attr')->where([
|
||||
'attr_name' => $attr_name,
|
||||
'lang' => $lang,
|
||||
'attr_group' => $attr_group,
|
||||
])->getField('attr_value');
|
||||
empty($bind_value) && $bind_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;
|
||||
}
|
||||
}
|
||||
29
src/application/common/model/LanguageAttribute.php
Normal file
29
src/application/common/model/LanguageAttribute.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 模型
|
||||
*/
|
||||
class LanguageAttribute extends Model
|
||||
{
|
||||
//初始化
|
||||
protected function initialize()
|
||||
{
|
||||
// 需要调用`Model`的`initialize`方法
|
||||
parent::initialize();
|
||||
}
|
||||
}
|
||||
29
src/application/common/model/LanguageMark.php
Normal file
29
src/application/common/model/LanguageMark.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 模型
|
||||
*/
|
||||
class LanguageMark extends Model
|
||||
{
|
||||
//初始化
|
||||
protected function initialize()
|
||||
{
|
||||
// 需要调用`Model`的`initialize`方法
|
||||
parent::initialize();
|
||||
}
|
||||
}
|
||||
29
src/application/common/model/LanguagePack.php
Normal file
29
src/application/common/model/LanguagePack.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 小虎哥 <1105415366@qq.com>
|
||||
* Date: 2018-4-3
|
||||
*/
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 模型
|
||||
*/
|
||||
class LanguagePack extends Model
|
||||
{
|
||||
//初始化
|
||||
protected function initialize()
|
||||
{
|
||||
// 需要调用`Model`的`initialize`方法
|
||||
parent::initialize();
|
||||
}
|
||||
}
|
||||
30
src/application/common/model/Recruit.php
Normal file
30
src/application/common/model/Recruit.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 陈风任 <491085389@qq.com>
|
||||
* Date: 2019-1-7
|
||||
*/
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 数据库模型
|
||||
*/
|
||||
class Recruit extends Model
|
||||
{
|
||||
//初始化
|
||||
protected function initialize()
|
||||
{
|
||||
// 需要调用`Model`的`initialize`方法
|
||||
parent::initialize();
|
||||
}
|
||||
}
|
||||
114
src/application/common/model/Region.php
Normal file
114
src/application/common/model/Region.php
Normal file
@@ -0,0 +1,114 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* 区域分类
|
||||
*/
|
||||
class Region extends Model
|
||||
{
|
||||
//初始化
|
||||
protected function initialize()
|
||||
{
|
||||
// 需要调用`Model`的`initialize`方法
|
||||
parent::initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单条地区
|
||||
* @author wengxianhu by 2017-7-26
|
||||
*/
|
||||
public function getInfo($id, $field = '*')
|
||||
{
|
||||
$result = Db::name('region')->field($field)->find($id);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取多个地区
|
||||
* @author wengxianhu by 2017-7-26
|
||||
*/
|
||||
public function getListByIds($ids = array(), $field = '*', $index_key = '')
|
||||
{
|
||||
$map = array(
|
||||
'id' => array('IN', $ids),
|
||||
);
|
||||
$result = Db::name('region')->field($field)
|
||||
->where($map)
|
||||
->select();
|
||||
|
||||
if (!empty($index_key)) {
|
||||
$result = convert_arr_key($result, $index_key);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取子地区
|
||||
* @author wengxianhu by 2017-7-26
|
||||
*/
|
||||
public function getList($parent_id = 0, $field = '*', $index_key = '')
|
||||
{
|
||||
$result = $this->getAll($parent_id, $field, $index_key);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取全部地区
|
||||
* @author wengxianhu by 2017-7-26
|
||||
*/
|
||||
public function getAll($parent_id = false, $field = '*', $index_key = '')
|
||||
{
|
||||
$map = array();
|
||||
if (false !== $parent_id) {
|
||||
$map['parent_id'] = $parent_id;
|
||||
}
|
||||
|
||||
$result = Db::name('region')->field($field)
|
||||
->where($map)
|
||||
->select();
|
||||
|
||||
if (!empty($index_key)) {
|
||||
$result = convert_arr_key($result, $index_key);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取级别的地区
|
||||
* @author wengxianhu by 2017-7-26
|
||||
*/
|
||||
public function getListByLevel($level = 1, $field = '*', $index_key = '')
|
||||
{
|
||||
$map = array(
|
||||
'level' => $level,
|
||||
);
|
||||
|
||||
$result = Db::name('region')->field($field)
|
||||
->where($map)
|
||||
->select();
|
||||
|
||||
if (!empty($index_key)) {
|
||||
$result = convert_arr_key($result, $index_key);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
30
src/application/common/model/Special.php
Normal file
30
src/application/common/model/Special.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/**
|
||||
* 易优CMS
|
||||
* ============================================================================
|
||||
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
||||
* 网站地址: http://www.eyoucms.com
|
||||
* ----------------------------------------------------------------------------
|
||||
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
||||
* ============================================================================
|
||||
* Author: 陈风任 <491085389@qq.com>
|
||||
* Date: 2019-1-7
|
||||
*/
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 数据库模型
|
||||
*/
|
||||
class Special extends Model
|
||||
{
|
||||
//初始化
|
||||
protected function initialize()
|
||||
{
|
||||
// 需要调用`Model`的`initialize`方法
|
||||
parent::initialize();
|
||||
}
|
||||
}
|
||||
305
src/application/common/model/Taglist.php
Normal file
305
src/application/common/model/Taglist.php
Normal file
@@ -0,0 +1,305 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* 文章Tag标签
|
||||
*/
|
||||
class Taglist extends Model
|
||||
{
|
||||
//初始化
|
||||
protected function initialize()
|
||||
{
|
||||
// 需要调用`Model`的`initialize`方法
|
||||
parent::initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单条记录
|
||||
* @author wengxianhu by 2017-7-26
|
||||
*/
|
||||
public function getInfo($tid, $field = '*')
|
||||
{
|
||||
$result = Db::name('Taglist')->field($field)->where('tid', $tid)->find();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单篇文章的标签
|
||||
* @author wengxianhu by 2017-7-26
|
||||
*/
|
||||
public function getListByAid($aid = '', $typeid = 0, $field = 'tid, tag')
|
||||
{
|
||||
$str = [
|
||||
'tag_arr' => '',
|
||||
'tid_arr' => '',
|
||||
];
|
||||
$result = Db::name('Taglist')->field($field)
|
||||
->where(array('aid'=>$aid, 'typeid'=>$typeid))
|
||||
->order('aid asc')
|
||||
->select();
|
||||
if ($result) {
|
||||
$tag_arr = get_arr_column($result, 'tag');
|
||||
$str['tag_arr'] = implode(',', $tag_arr);
|
||||
$id_arr = get_arr_column($result, 'tid');
|
||||
$str['tid_arr'] = implode(',', $id_arr);
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取多篇文章的标签
|
||||
* @author wengxianhu by 2017-7-26
|
||||
*/
|
||||
public function getListByAids($aids = array(), $field = '*')
|
||||
{
|
||||
$data = array();
|
||||
$result = Db::name('Taglist')->field($field)
|
||||
->where(array('aid'=>array('IN', $aids)))
|
||||
->order('aid asc')
|
||||
->select();
|
||||
if ($result) {
|
||||
foreach ($result as $key => $val) {
|
||||
if (!isset($data[$val['aid']])) $data[$val['aid']] = array();
|
||||
array_push($data[$val['aid']], $val);
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 插入Tags
|
||||
*
|
||||
* @access public
|
||||
* @param int $aid 文档AID
|
||||
* @param int $typeid 栏目ID
|
||||
* @param string $tag tag标签
|
||||
* @return void
|
||||
*/
|
||||
public function savetags($aid = 0, $typeid = 0, $tag = '', $arcrank = 0, $opt = 'add')
|
||||
{
|
||||
$tag = strip_tags(htmlspecialchars_decode($tag));
|
||||
|
||||
if ($opt == 'add') {
|
||||
$tag = str_replace(',', ',', $tag);
|
||||
$tags = explode(',', $tag);
|
||||
$tags = array_unique($tags);
|
||||
|
||||
foreach($tags as $tag)
|
||||
{
|
||||
$tag = trim($tag);
|
||||
if($tag != stripslashes($tag))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
$this->InsertOneTag($tag, $aid, $typeid,$arcrank);
|
||||
}
|
||||
} else if ($opt == 'edit') {
|
||||
$this->UpdateOneTag($aid, $typeid, $tag,$arcrank);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 插入一个tag
|
||||
*
|
||||
* @access public
|
||||
* @param string $tag 标签
|
||||
* @param int $aid 文档AID
|
||||
* @param int $typeid 栏目ID
|
||||
* @return void
|
||||
*/
|
||||
private function InsertOneTag($tag, $aid, $typeid = 0, $arcrank = 0)
|
||||
{
|
||||
$tag = trim($tag);
|
||||
if(empty($tag))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if(empty($typeid))
|
||||
{
|
||||
$typeid = 0;
|
||||
}
|
||||
$rs = false;
|
||||
$addtime = getTime();
|
||||
$row = Db::name('tagindex')->where([
|
||||
'tag' => $tag,
|
||||
'lang' => get_admin_lang(),
|
||||
])->find();
|
||||
if(empty($row))
|
||||
{
|
||||
$rs = $tid = Db::name('tagindex')->insertGetId([
|
||||
'tag' => $tag,
|
||||
'typeid' => $typeid,
|
||||
'seo_title' => '',
|
||||
'seo_keywords' => '',
|
||||
'seo_description' => '',
|
||||
'total' => 1,
|
||||
'weekup' => $addtime,
|
||||
'monthup' => $addtime,
|
||||
'lang' => get_admin_lang(),
|
||||
'add_time' => $addtime,
|
||||
'update_time'=> $addtime,
|
||||
]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$rs = Db::name('tagindex')->where([
|
||||
'tag' => $tag,
|
||||
'lang' => get_admin_lang(),
|
||||
])->update([
|
||||
'total' => Db::raw('total + 1'),
|
||||
'update_time' => $addtime,
|
||||
'lang' => get_admin_lang(),
|
||||
]);
|
||||
$tid = $row['id'];
|
||||
}
|
||||
|
||||
if($rs)
|
||||
{
|
||||
Db::name('taglist')->insert([
|
||||
'tid' => $tid,
|
||||
'aid' => $aid,
|
||||
'typeid' => $typeid,
|
||||
'tag' => $tag,
|
||||
'arcrank' => $arcrank,
|
||||
'lang' => get_admin_lang(),
|
||||
'add_time' => $addtime,
|
||||
'update_time'=> $addtime,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新Tag
|
||||
*
|
||||
* @access public
|
||||
* @param int $aid 文档ID
|
||||
* @param int $typeid 栏目ID
|
||||
* @param string $tags tag标签
|
||||
* @return string
|
||||
*/
|
||||
private function UpdateOneTag($aid, $typeid, $tags='', $arcrank = 0)
|
||||
{
|
||||
$lang = get_admin_lang();
|
||||
$oldtag = $this->GetTags($aid);
|
||||
$oldtags = explode(',', $oldtag);
|
||||
$tags = str_replace(',', ',', $tags);
|
||||
$new_tags = explode(',', $tags);
|
||||
if(!empty($tags) || !empty($oldtags))
|
||||
{
|
||||
foreach($new_tags as $tag)
|
||||
{
|
||||
$tag = trim($tag);
|
||||
if(empty($tag) || $tag != stripslashes($tag))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if(!in_array($tag, $oldtags))
|
||||
{
|
||||
$this->InsertOneTag($tag, $aid, $typeid,$arcrank);
|
||||
}
|
||||
}
|
||||
|
||||
$taglistRow = Db::name('taglist')->field('count(tid) as total, tag')->where([
|
||||
'tag' => ['IN', $oldtags],
|
||||
'lang' => $lang,
|
||||
])->group('tag')->select();
|
||||
foreach ($taglistRow as $key => $val) {
|
||||
$taglistRow[md5($val['tag'])] = $val;
|
||||
unset($taglistRow[$key]);
|
||||
}
|
||||
|
||||
foreach($oldtags as $tag)
|
||||
{
|
||||
if(!in_array($tag, $new_tags))
|
||||
{
|
||||
Db::name('taglist')->where(['aid'=>$aid,'tag'=>$tag])->delete();
|
||||
$total = !empty($taglistRow[md5($tag)]) ? $taglistRow[md5($tag)]['total'] - 1 : 0;
|
||||
if (0 < $total) {
|
||||
Db::name('tagindex')->where(['tag'=>$tag,'lang'=>$lang])->update([
|
||||
'total' => $total,
|
||||
'update_time' => getTime(),
|
||||
]);
|
||||
} else {
|
||||
Db::name('tagindex')->where(['tag'=>$tag,'lang'=>$lang])->delete();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Db::name('taglist')->where(['aid'=>$aid,'tag'=>$tag,'lang'=>$lang])->update([
|
||||
'typeid' => $typeid,
|
||||
'update_time' => getTime(),
|
||||
]);
|
||||
Db::name('taglist')->where(['aid'=>$aid])->update([
|
||||
'arcrank' => $arcrank,
|
||||
'update_time' => getTime(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得某文档的所有tag
|
||||
*
|
||||
* @param int $aid 文档id
|
||||
* @return string
|
||||
*/
|
||||
public function GetTags($aid)
|
||||
{
|
||||
$tags = '';
|
||||
$row = Db::name('taglist')->field('tag')->where(['aid'=>$aid])->select();
|
||||
foreach ($row as $key => $val) {
|
||||
$tags .= (empty($tags) ? $val['tag'] : ','.$val['tag']);
|
||||
}
|
||||
return $tags;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文章标签
|
||||
*/
|
||||
public function delByAids($aids = array())
|
||||
{
|
||||
if (!empty($aids)) {
|
||||
$tags = Db::name('taglist')->where(['aid'=>['IN', $aids]])->column('tag');
|
||||
if (!empty($tags)) {
|
||||
Db::name('taglist')->where(['aid'=>['IN', $aids]])->delete();
|
||||
$tagsgroup = Db::name('taglist')->field('tag')->where(['tag'=>['IN', $tags]])->group('tag')->getAllWithIndex('tag');
|
||||
// 更新标签的文档总数
|
||||
foreach ($tags as $key => $tag) {
|
||||
if (empty($tagsgroup[$tag])) {
|
||||
Db::name('tagindex')->where(['tag'=>$tag])->delete();
|
||||
} else {
|
||||
$total = Db::name('taglist')->where(['tag'=>$tag])->count();
|
||||
Db::name('tagindex')->where([
|
||||
'tag'=>$tag,
|
||||
'total'=>['gt', 0],
|
||||
'lang'=>get_admin_lang()
|
||||
])
|
||||
->update([
|
||||
'total' => $total,
|
||||
'update_time' => getTime(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
60
src/application/common/model/Weapp.php
Normal file
60
src/application/common/model/Weapp.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* 插件模型
|
||||
*/
|
||||
class Weapp extends Model
|
||||
{
|
||||
//初始化
|
||||
protected function initialize()
|
||||
{
|
||||
// 需要调用`Model`的`initialize`方法
|
||||
parent::initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取插件列表所有信息,方便系统其它地方使用
|
||||
*/
|
||||
public function getWeappList($code = '')
|
||||
{
|
||||
$result = extra_cache('common_weapp_getWeappList');
|
||||
if (empty($result)) {
|
||||
$result = Db::name('weapp')->getAllWithIndex('code');
|
||||
foreach ($result as $key => &$value) {
|
||||
try {
|
||||
if (!empty($value['data']) && $value['data']!="[]") {
|
||||
if (preg_match('/^{.*}$/', $value['data'])) { // json格式
|
||||
$value['data'] = json_decode($value['data'], true);
|
||||
} else {
|
||||
$value['data'] = unserialize($value['data']);
|
||||
}
|
||||
}
|
||||
if (!empty($value['config'])) {
|
||||
$value['config'] = json_decode($value['config'], true);
|
||||
}
|
||||
} catch (\Exception $e) {}
|
||||
}
|
||||
extra_cache('common_weapp_getWeappList', $result);
|
||||
}
|
||||
|
||||
!empty($code) && $result = $result[$code];
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
493
src/application/common/util/ChineseSpell.php
Normal file
493
src/application/common/util/ChineseSpell.php
Normal file
@@ -0,0 +1,493 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by Green Studio.
|
||||
* File: File.class.php
|
||||
* Date: 14-1-31
|
||||
* Time: 下午2:53
|
||||
*/
|
||||
|
||||
namespace app\common\util;
|
||||
class ChineseSpell {//注意仅支持:GBK,故传入参数前须转码
|
||||
/**
|
||||
* @var array $chineseSpellList 拼音编码对应表
|
||||
* @access private
|
||||
*/
|
||||
private $chineseSpellList = array(
|
||||
'a'=>-20319,
|
||||
'ai'=>-20317,
|
||||
'an'=>-20304,
|
||||
'ang'=>-20295,
|
||||
'ao'=>-20292,
|
||||
'ba'=>-20283,
|
||||
'bai'=>-20265,
|
||||
'ban'=>-20257,
|
||||
'bang'=>-20242,
|
||||
'bao'=>-20230,
|
||||
'bei'=>-20051,
|
||||
'ben'=>-20036,
|
||||
'beng'=>-20032,
|
||||
'bi'=>-20026,
|
||||
'bian'=>-20002,
|
||||
'biao'=>-19990,
|
||||
'bie'=>-19986,
|
||||
'bin'=>-19982,
|
||||
'bing'=>-19976,
|
||||
'bo'=>-19805,
|
||||
'bu'=>-19784,
|
||||
'ca'=>-19775,
|
||||
'cai'=>-19774,
|
||||
'can'=>-19763,
|
||||
'cang'=>-19756,
|
||||
'cao'=>-19751,
|
||||
'ce'=>-19746,
|
||||
'ceng'=>-19741,
|
||||
'cha'=>-19739,
|
||||
'chai'=>-19728,
|
||||
'chan'=>-19725,
|
||||
'chang'=>-19715,
|
||||
'chao'=>-19540,
|
||||
'che'=>-19531,
|
||||
'chen'=>-19525,
|
||||
'cheng'=>-19515,
|
||||
'chi'=>-19500,
|
||||
'chong'=>-19484,
|
||||
'chou'=>-19479,
|
||||
'chu'=>-19467,
|
||||
'chuai'=>-19289,
|
||||
'chuan'=>-19288,
|
||||
'chuang'=>-19281,
|
||||
'chui'=>-19275,
|
||||
'chun'=>-19270,
|
||||
'chuo'=>-19263,
|
||||
'ci'=>-19261,
|
||||
'cong'=>-19249,
|
||||
'cou'=>-19243,
|
||||
'cu'=>-19242,
|
||||
'cuan'=>-19238,
|
||||
'cui'=>-19235,
|
||||
'cun'=>-19227,
|
||||
'cuo'=>-19224,
|
||||
'da'=>-19218,
|
||||
'dai'=>-19212,
|
||||
'dan'=>-19038,
|
||||
'dang'=>-19023,
|
||||
'dao'=>-19018,
|
||||
'de'=>-19006,
|
||||
'deng'=>-19003,
|
||||
'di'=>-18996,
|
||||
'dian'=>-18977,
|
||||
'diao'=>-18961,
|
||||
'die'=>-18952,
|
||||
'ding'=>-18783,
|
||||
'diu'=>-18774,
|
||||
'dong'=>-18773,
|
||||
'dou'=>-18763,
|
||||
'du'=>-18756,
|
||||
'duan'=>-18741,
|
||||
'dui'=>-18735,
|
||||
'dun'=>-18731,
|
||||
'duo'=>-18722,
|
||||
'e'=>-18710,
|
||||
'en'=>-18697,
|
||||
'er'=>-18696,
|
||||
'fa'=>-18526,
|
||||
'fan'=>-18518,
|
||||
'fang'=>-18501,
|
||||
'fei'=>-18490,
|
||||
'fen'=>-18478,
|
||||
'feng'=>-18463,
|
||||
'fo'=>-18448,
|
||||
'fou'=>-18447,
|
||||
'fu'=>-18446,
|
||||
'ga'=>-18239,
|
||||
'gai'=>-18237,
|
||||
'gan'=>-18231,
|
||||
'gang'=>-18220,
|
||||
'gao'=>-18211,
|
||||
'ge'=>-18201,
|
||||
'gei'=>-18184,
|
||||
'gen'=>-18183,
|
||||
'geng'=>-18181,
|
||||
'gong'=>-18012,
|
||||
'gou'=>-17997,
|
||||
'gu'=>-17988,
|
||||
'gua'=>-17970,
|
||||
'guai'=>-17964,
|
||||
'guan'=>-17961,
|
||||
'guang'=>-17950,
|
||||
'gui'=>-17947,
|
||||
'gun'=>-17931,
|
||||
'guo'=>-17928,
|
||||
'ha'=>-17922,
|
||||
'hai'=>-17759,
|
||||
'han'=>-17752,
|
||||
'hang'=>-17733,
|
||||
'hao'=>-17730,
|
||||
'he'=>-17721,
|
||||
'hei'=>-17703,
|
||||
'hen'=>-17701,
|
||||
'heng'=>-17697,
|
||||
'hong'=>-17692,
|
||||
'hou'=>-17683,
|
||||
'hu'=>-17676,
|
||||
'hua'=>-17496,
|
||||
'huai'=>-17487,
|
||||
'huan'=>-17482,
|
||||
'huang'=>-17468,
|
||||
'hui'=>-17454,
|
||||
'hun'=>-17433,
|
||||
'huo'=>-17427,
|
||||
'ji'=>-17417,
|
||||
'jia'=>-17202,
|
||||
'jian'=>-17185,
|
||||
'jiang'=>-16983,
|
||||
'jiao'=>-16970,
|
||||
'jie'=>-16942,
|
||||
'jin'=>-16915,
|
||||
'jing'=>-16733,
|
||||
'jiong'=>-16708,
|
||||
'jiu'=>-16706,
|
||||
'ju'=>-16689,
|
||||
'juan'=>-16664,
|
||||
'jue'=>-16657,
|
||||
'jun'=>-16647,
|
||||
'ka'=>-16474,
|
||||
'kai'=>-16470,
|
||||
'kan'=>-16465,
|
||||
'kang'=>-16459,
|
||||
'kao'=>-16452,
|
||||
'ke'=>-16448,
|
||||
'ken'=>-16433,
|
||||
'keng'=>-16429,
|
||||
'kong'=>-16427,
|
||||
'kou'=>-16423,
|
||||
'ku'=>-16419,
|
||||
'kua'=>-16412,
|
||||
'kuai'=>-16407,
|
||||
'kuan'=>-16403,
|
||||
'kuang'=>-16401,
|
||||
'kui'=>-16393,
|
||||
'kun'=>-16220,
|
||||
'kuo'=>-16216,
|
||||
'la'=>-16212,
|
||||
'lai'=>-16205,
|
||||
'lan'=>-16202,
|
||||
'lang'=>-16187,
|
||||
'lao'=>-16180,
|
||||
'le'=>-16171,
|
||||
'lei'=>-16169,
|
||||
'leng'=>-16158,
|
||||
'li'=>-16155,
|
||||
'lia'=>-15959,
|
||||
'lian'=>-15958,
|
||||
'liang'=>-15944,
|
||||
'liao'=>-15933,
|
||||
'lie'=>-15920,
|
||||
'lin'=>-15915,
|
||||
'ling'=>-15903,
|
||||
'liu'=>-15889,
|
||||
'long'=>-15878,
|
||||
'lou'=>-15707,
|
||||
'lu'=>-15701,
|
||||
'lv'=>-15681,
|
||||
'luan'=>-15667,
|
||||
'lue'=>-15661,
|
||||
'lun'=>-15659,
|
||||
'luo'=>-15652,
|
||||
'ma'=>-15640,
|
||||
'mai'=>-15631,
|
||||
'man'=>-15625,
|
||||
'mang'=>-15454,
|
||||
'mao'=>-15448,
|
||||
'me'=>-15436,
|
||||
'mei'=>-15435,
|
||||
'men'=>-15419,
|
||||
'meng'=>-15416,
|
||||
'mi'=>-15408,
|
||||
'mian'=>-15394,
|
||||
'miao'=>-15385,
|
||||
'mie'=>-15377,
|
||||
'min'=>-15375,
|
||||
'ming'=>-15369,
|
||||
'miu'=>-15363,
|
||||
'mo'=>-15362,
|
||||
'mou'=>-15183,
|
||||
'mu'=>-15180,
|
||||
'na'=>-15165,
|
||||
'nai'=>-15158,
|
||||
'nan'=>-15153,
|
||||
'nang'=>-15150,
|
||||
'nao'=>-15149,
|
||||
'ne'=>-15144,
|
||||
'nei'=>-15143,
|
||||
'nen'=>-15141,
|
||||
'neng'=>-15140,
|
||||
'ni'=>-15139,
|
||||
'nian'=>-15128,
|
||||
'niang'=>-15121,
|
||||
'niao'=>-15119,
|
||||
'nie'=>-15117,
|
||||
'nin'=>-15110,
|
||||
'ning'=>-15109,
|
||||
'niu'=>-14941,
|
||||
'nong'=>-14937,
|
||||
'nu'=>-14933,
|
||||
'nv'=>-14930,
|
||||
'nuan'=>-14929,
|
||||
'nue'=>-14928,
|
||||
'nuo'=>-14926,
|
||||
'o'=>-14922,
|
||||
'ou'=>-14921,
|
||||
'pa'=>-14914,
|
||||
'pai'=>-14908,
|
||||
'pan'=>-14902,
|
||||
'pang'=>-14894,
|
||||
'pao'=>-14889,
|
||||
'pei'=>-14882,
|
||||
'pen'=>-14873,
|
||||
'peng'=>-14871,
|
||||
'pi'=>-14857,
|
||||
'pian'=>-14678,
|
||||
'piao'=>-14674,
|
||||
'pie'=>-14670,
|
||||
'pin'=>-14668,
|
||||
'ping'=>-14663,
|
||||
'po'=>-14654,
|
||||
'pu'=>-14645,
|
||||
'qi'=>-14630,
|
||||
'qia'=>-14594,
|
||||
'qian'=>-14429,
|
||||
'qiang'=>-14407,
|
||||
'qiao'=>-14399,
|
||||
'qie'=>-14384,
|
||||
'qin'=>-14379,
|
||||
'qing'=>-14368,
|
||||
'qiong'=>-14355,
|
||||
'qiu'=>-14353,
|
||||
'qu'=>-14345,
|
||||
'quan'=>-14170,
|
||||
'que'=>-14159,
|
||||
'qun'=>-14151,
|
||||
'ran'=>-14149,
|
||||
'rang'=>-14145,
|
||||
'rao'=>-14140,
|
||||
're'=>-14137,
|
||||
'ren'=>-14135,
|
||||
'reng'=>-14125,
|
||||
'ri'=>-14123,
|
||||
'rong'=>-14122,
|
||||
'rou'=>-14112,
|
||||
'ru'=>-14109,
|
||||
'ruan'=>-14099,
|
||||
'rui'=>-14097,
|
||||
'run'=>-14094,
|
||||
'ruo'=>-14092,
|
||||
'sa'=>-14090,
|
||||
'sai'=>-14087,
|
||||
'san'=>-14083,
|
||||
'sang'=>-13917,
|
||||
'sao'=>-13914,
|
||||
'se'=>-13910,
|
||||
'sen'=>-13907,
|
||||
'seng'=>-13906,
|
||||
'sha'=>-13905,
|
||||
'shai'=>-13896,
|
||||
'shan'=>-13894,
|
||||
'shang'=>-13878,
|
||||
'shao'=>-13870,
|
||||
'she'=>-13859,
|
||||
'shen'=>-13847,
|
||||
'sheng'=>-13831,
|
||||
'shi'=>-13658,
|
||||
'shou'=>-13611,
|
||||
'shu'=>-13601,
|
||||
'shua'=>-13406,
|
||||
'shuai'=>-13404,
|
||||
'shuan'=>-13400,
|
||||
'shuang'=>-13398,
|
||||
'shui'=>-13395,
|
||||
'shun'=>-13391,
|
||||
'shuo'=>-13387,
|
||||
'si'=>-13383,
|
||||
'song'=>-13367,
|
||||
'sou'=>-13359,
|
||||
'su'=>-13356,
|
||||
'suan'=>-13343,
|
||||
'sui'=>-13340,
|
||||
'sun'=>-13329,
|
||||
'suo'=>-13326,
|
||||
'ta'=>-13318,
|
||||
'tai'=>-13147,
|
||||
'tan'=>-13138,
|
||||
'tang'=>-13120,
|
||||
'tao'=>-13107,
|
||||
'te'=>-13096,
|
||||
'teng'=>-13095,
|
||||
'ti'=>-13091,
|
||||
'tian'=>-13076,
|
||||
'tiao'=>-13068,
|
||||
'tie'=>-13063,
|
||||
'ting'=>-13060,
|
||||
'tong'=>-12888,
|
||||
'tou'=>-12875,
|
||||
'tu'=>-12871,
|
||||
'tuan'=>-12860,
|
||||
'tui'=>-12858,
|
||||
'tun'=>-12852,
|
||||
'tuo'=>-12849,
|
||||
'wa'=>-12838,
|
||||
'wai'=>-12831,
|
||||
'wan'=>-12829,
|
||||
'wang'=>-12812,
|
||||
'wei'=>-12802,
|
||||
'wen'=>-12607,
|
||||
'weng'=>-12597,
|
||||
'wo'=>-12594,
|
||||
'wu'=>-12585,
|
||||
'xi'=>-12556,
|
||||
'xia'=>-12359,
|
||||
'xian'=>-12346,
|
||||
'xiang'=>-12320,
|
||||
'xiao'=>-12300,
|
||||
'xie'=>-12120,
|
||||
'xin'=>-12099,
|
||||
'xing'=>-12089,
|
||||
'xiong'=>-12074,
|
||||
'xiu'=>-12067,
|
||||
'xu'=>-12058,
|
||||
'xuan'=>-12039,
|
||||
'xue'=>-11867,
|
||||
'xun'=>-11861,
|
||||
'ya'=>-11847,
|
||||
'yan'=>-11831,
|
||||
'yang'=>-11798,
|
||||
'yao'=>-11781,
|
||||
'ye'=>-11604,
|
||||
'yi'=>-11589,
|
||||
'yin'=>-11536,
|
||||
'ying'=>-11358,
|
||||
'yo'=>-11340,
|
||||
'yong'=>-11339,
|
||||
'you'=>-11324,
|
||||
'yu'=>-11303,
|
||||
'yuan'=>-11097,
|
||||
'yue'=>-11077,
|
||||
'yun'=>-11067,
|
||||
'za'=>-11055,
|
||||
'zai'=>-11052,
|
||||
'zan'=>-11045,
|
||||
'zang'=>-11041,
|
||||
'zao'=>-11038,
|
||||
'ze'=>-11024,
|
||||
'zei'=>-11020,
|
||||
'zen'=>-11019,
|
||||
'zeng'=>-11018,
|
||||
'zha'=>-11014,
|
||||
'zhai'=>-10838,
|
||||
'zhan'=>-10832,
|
||||
'zhang'=>-10815,
|
||||
'zhao'=>-10800,
|
||||
'zhe'=>-10790,
|
||||
'zhen'=>-10780,
|
||||
'zheng'=>-10764,
|
||||
'zhi'=>-10587,
|
||||
'zhong'=>-10544,
|
||||
'zhou'=>-10533,
|
||||
'zhu'=>-10519,
|
||||
'zhua'=>-10331,
|
||||
'zhuai'=>-10329,
|
||||
'zhuan'=>-10328,
|
||||
'zhuang'=>-10322,
|
||||
'zhui'=>-10315,
|
||||
'zhun'=>-10309,
|
||||
'zhuo'=>-10307,
|
||||
'zi'=>-10296,
|
||||
'zong'=>-10281,
|
||||
'zou'=>-10274,
|
||||
'zu'=>-10270,
|
||||
'zuan'=>-10262,
|
||||
'zui'=>-10260,
|
||||
'zun'=>-10256,
|
||||
'zuo'=>-10254
|
||||
);
|
||||
|
||||
/**
|
||||
* 取汉字所有拼音
|
||||
* @param string $chinese 要转换的汉字
|
||||
* @param string $delimiter 分隔符
|
||||
* @param int $length 返回的长度
|
||||
* @return string
|
||||
*/
|
||||
public function getFullSpell($chinese, $delimiter = '', $length = 0){
|
||||
$spell = $this->getChineseSpells($chinese, $delimiter);
|
||||
if($length){
|
||||
$spell = substr($spell, 0, $length);
|
||||
}
|
||||
return $spell;
|
||||
}
|
||||
|
||||
/**
|
||||
* 取汉字第【一个】汉字完整拼音
|
||||
* @param string $chinese 要转换的汉字
|
||||
* @param int $length 返回的长度
|
||||
* @return string
|
||||
*/
|
||||
public function getFirstSpell($chinese, $length = 0){
|
||||
$spell = $this->getChineseSpells($chinese, ' ', 1);
|
||||
if($length){
|
||||
$spell = substr($spell, 0, $length);
|
||||
}
|
||||
return $spell;
|
||||
}
|
||||
|
||||
/**
|
||||
* 取一个汉字码对应的拼音
|
||||
* @param int $num 汉字码
|
||||
* @param string $blank 空白字符
|
||||
* @return string
|
||||
*/
|
||||
public function getChineseSpell ($num, $blank = ''){
|
||||
if($num>0 && $num<160){
|
||||
return chr($num);
|
||||
}
|
||||
elseif($num<-20319||$num>-10247){
|
||||
return $blank;
|
||||
}
|
||||
else{
|
||||
foreach ($this->chineseSpellList as $spell => $code){
|
||||
if ($code > $num) break;
|
||||
$result = $spell;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 取汉字拼音
|
||||
* @param string $chinese 要转换的汉字
|
||||
* @param string $delimiter 分隔符
|
||||
* @param int $first 是否只返回第一个
|
||||
* @return string
|
||||
*/
|
||||
public function getChineseSpells($chinese, $delimiter = '', $first=0){
|
||||
$result = array();
|
||||
for($i=0; $i<strlen($chinese); $i++){
|
||||
$p = ord(substr($chinese,$i,1));
|
||||
if($p>160){
|
||||
$q = ord(substr($chinese,++$i,1));
|
||||
$p = $p*256 + $q - 65536;
|
||||
}
|
||||
$result[] = $this->getChineseSpell($p);
|
||||
if($first){
|
||||
return $result[0];
|
||||
}
|
||||
}
|
||||
return implode($delimiter, $result);
|
||||
}
|
||||
}
|
||||
//$ok=new ChineseSpell();
|
||||
//$str='%^&《》:“{}AGDFasdfas===取汉字所有拼音';
|
||||
//echo $ok->getFullSpell($str);
|
||||
//echo '<p />';
|
||||
//echo $ok->getChineseSpells($str);
|
||||
|
||||
499
src/application/common/util/File.class.php
Normal file
499
src/application/common/util/File.class.php
Normal file
@@ -0,0 +1,499 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by Green Studio.
|
||||
* File: File.class.php
|
||||
* User: Timothy Zhang
|
||||
* Date: 14-1-31
|
||||
* Time: 下午2:53
|
||||
*/
|
||||
|
||||
namespace Common\Util;
|
||||
|
||||
use think\Storage;
|
||||
|
||||
|
||||
/**
|
||||
* Class File
|
||||
* @package Common\Util
|
||||
*/
|
||||
class File
|
||||
{
|
||||
|
||||
/**
|
||||
* 运行于 Sae 和 LAMP
|
||||
* @param $filename
|
||||
* @return bool
|
||||
*/
|
||||
public static function file_exists($filename)
|
||||
{
|
||||
$Storage = new Storage();
|
||||
$Storage::connect();
|
||||
return $Storage::has($filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* 运行于 Sae 和 LAMP
|
||||
* @param $bytes
|
||||
* @return string
|
||||
*/
|
||||
public static function byteFormat($bytes)
|
||||
{
|
||||
$size_text = array(" B", " KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB");
|
||||
return round($bytes / pow(1024, ($i = floor(log($bytes, 1024)))), 2) . $size_text[$i];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $filename
|
||||
* @return string
|
||||
*/
|
||||
static public function readFile($filename)
|
||||
{
|
||||
$content = '';
|
||||
$Storage = new Storage();
|
||||
$Storage::connect();
|
||||
@$content = $Storage::read($filename);
|
||||
return $content;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $filename
|
||||
* @param $writetext
|
||||
* @param string $openmod
|
||||
* @return bool
|
||||
*/
|
||||
public static function writeFile($filename, $writetext, $openmod = 'w')
|
||||
{
|
||||
if (@$fp = fopen($filename, $openmod)) {
|
||||
flock($fp, 2);
|
||||
fwrite($fp, $writetext);
|
||||
fclose($fp);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $filename
|
||||
* @return bool
|
||||
*/
|
||||
public static function delFile($filename)
|
||||
{
|
||||
$Storage = new Storage();
|
||||
$Storage::connect();
|
||||
return $Storage::unlink($filename);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $path
|
||||
* @param bool $delDir
|
||||
* @return bool
|
||||
*/
|
||||
public static function delAll($path, $delDir = false)
|
||||
{
|
||||
$handle = opendir($path);
|
||||
if ($handle) {
|
||||
while (false !== ($item = readdir($handle))) {
|
||||
if ($item != "." && $item != "..")
|
||||
is_dir("$path/$item") ? self::delAll("$path/$item", $delDir) : unlink("$path/$item");
|
||||
}
|
||||
closedir($handle);
|
||||
if ($delDir)
|
||||
return rmdir($path);
|
||||
} else {
|
||||
if (file_exists($path)) {
|
||||
return unlink($path);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $dirName
|
||||
* @return bool
|
||||
*/
|
||||
public static function delDir($dirName)
|
||||
{
|
||||
if (!file_exists($dirName)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$dir = opendir($dirName);
|
||||
while ($fileName = readdir($dir)) {
|
||||
$file = $dirName . '/' . $fileName;
|
||||
if ($fileName != '.' && $fileName != '..') {
|
||||
if (is_dir($file)) {
|
||||
self::delDir($file);
|
||||
} else {
|
||||
unlink($file);
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir($dir);
|
||||
return rmdir($dirName);
|
||||
}
|
||||
|
||||
public function delFile2($dir,$file_type='') {
|
||||
if(is_dir($dir)){
|
||||
$files = ey_scandir($dir);
|
||||
//打开目录 //列出目录中的所有文件并去掉 . 和 ..
|
||||
foreach($files as $filename){
|
||||
if($filename!='.' && $filename!='..'){
|
||||
if(!is_dir($dir.'/'.$filename)){
|
||||
if(empty($file_type)){
|
||||
unlink($dir.'/'.$filename);
|
||||
}else{
|
||||
if(is_array($file_type)){
|
||||
//正则匹配指定文件
|
||||
if(preg_match($file_type[0],$filename)){
|
||||
unlink($dir.'/'.$filename);
|
||||
}
|
||||
}else{
|
||||
//指定包含某些字符串的文件
|
||||
if(false!=stristr($filename,$file_type)){
|
||||
unlink($dir.'/'.$filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
}else{
|
||||
delFile($dir.'/'.$filename);
|
||||
rmdir($dir.'/'.$filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
}else{
|
||||
if(file_exists($dir)) unlink($dir);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @param $surDir
|
||||
* @param $toDir
|
||||
* @return bool
|
||||
*/
|
||||
public static function copyDir($surDir, $toDir)
|
||||
{
|
||||
$surDir = rtrim($surDir, '/') . '/';
|
||||
$toDir = rtrim($toDir, '/') . '/';
|
||||
if (!file_exists($surDir)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!file_exists($toDir)) {
|
||||
self::mkDir($toDir);
|
||||
}
|
||||
$file = opendir($surDir);
|
||||
while ($fileName = readdir($file)) {
|
||||
$file1 = $surDir . '/' . $fileName;
|
||||
$file2 = $toDir . '/' . $fileName;
|
||||
if ($fileName != '.' && $fileName != '..') {
|
||||
if (is_dir($file1)) {
|
||||
self::copyDir($file1, $file2);
|
||||
} else {
|
||||
copy($file1, $file2);
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir($file);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $dir
|
||||
* @return bool
|
||||
*/
|
||||
public static function mkDir($dir)
|
||||
{
|
||||
$dir = rtrim($dir, '/') . '/';
|
||||
if (!is_dir($dir)) {
|
||||
if (mkdir($dir, 0700) == false) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 遍历获取目录下的指定类型的文件
|
||||
* @param $path 路径
|
||||
* @param array $files
|
||||
* 文件类型数组
|
||||
*
|
||||
* @param string $preg
|
||||
* @return array 所有文件路径
|
||||
*/
|
||||
public static function getFiles($path, &$files = array(), $preg = "/\.(gif|jpeg|jpg|png|bmp|webp)$/i")
|
||||
{
|
||||
if (!is_dir($path))
|
||||
return null;
|
||||
|
||||
|
||||
$handle = opendir($path);
|
||||
while (false !== ($file = readdir($handle))) {
|
||||
if ($file != '.' && $file != '..') {
|
||||
$path2 = $path .'/' . $file; //'/' .
|
||||
|
||||
// dump($path2);
|
||||
|
||||
if (is_dir($path2)) {
|
||||
self::getFiles($path2, $files);
|
||||
} else {
|
||||
if (preg_match($preg, $file)) {
|
||||
$files [] = $path2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $files;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $dir
|
||||
* @param bool $doc
|
||||
* @return array
|
||||
*/
|
||||
public static function getDirs($dir, $doc = false)
|
||||
{
|
||||
$dir = rtrim($dir, '/') . '/';
|
||||
$dirArray [][] = null;
|
||||
if (false != ($handle = opendir($dir))) {
|
||||
$i = 0;
|
||||
$j = 0;
|
||||
while (false !== ($file = readdir($handle))) {
|
||||
if (is_dir($dir . $file)) { //判断是否文件夹
|
||||
if ($file[0] != '.') {
|
||||
$dirArray ['dir'] [$i] = $file;
|
||||
$i++;
|
||||
}
|
||||
|
||||
} else {
|
||||
if ($file[0] != '.') {
|
||||
$dirArray ['file'] [$j] = $file;
|
||||
$j++;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
closedir($handle);
|
||||
}
|
||||
return $dirArray;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $dir
|
||||
* @return int|string
|
||||
*/
|
||||
public static function dirSize($dir)
|
||||
{
|
||||
if (self::readable($dir)) {
|
||||
$dir_list = opendir($dir);
|
||||
$dir_size = 0;
|
||||
while (false !== ($folder_or_file = readdir($dir_list))) {
|
||||
if ($folder_or_file != "." && $folder_or_file != "..") {
|
||||
if (is_dir("$dir/$folder_or_file")) {
|
||||
$dir_size += self::dirSize("$dir/$folder_or_file");
|
||||
} else {
|
||||
$dir_size += filesize("$dir/$folder_or_file");
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir($dir_list);
|
||||
return $dir_size;
|
||||
} else {
|
||||
return "不存在";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $dir
|
||||
* @return string
|
||||
*/
|
||||
public static function realSize($dir = null)
|
||||
{
|
||||
if (self::readable($dir)) {
|
||||
if (is_file($dir)) { // 对文件的判断
|
||||
return self::byteFormat(filesize($dir));
|
||||
} else
|
||||
return self::byteFormat(self::dirSize($dir));
|
||||
|
||||
} else
|
||||
return "文件不存在";
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param null $dir
|
||||
* @return bool
|
||||
*/
|
||||
public static function readable($dir = null)
|
||||
{
|
||||
if (($frst = file_get_contents($dir)) && is_file($dir)) {
|
||||
return true; // 是文件,并且可读
|
||||
} else { // 是目录
|
||||
if (is_dir($dir) && ey_scandir($dir)) {
|
||||
return true; // 目录可读
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $dir
|
||||
* @return bool
|
||||
*/
|
||||
public static function writeable($dir = null)
|
||||
{
|
||||
if (is_file($dir)) { // 对文件的判断
|
||||
return is_writeable($dir);
|
||||
} elseif (is_dir($dir)) {
|
||||
// 开始写入测试;
|
||||
$file = '_______' . time() . rand() . '_______';
|
||||
$file = $dir . '/' . $file;
|
||||
if (file_put_contents($file, '//')) {
|
||||
unlink($file); // 删除测试文件
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $dir
|
||||
* @return bool
|
||||
*/
|
||||
public static function emptyDir($dir)
|
||||
{
|
||||
if (($files = @ey_scandir($dir)) && count($files) <= 2)
|
||||
return true;
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $path
|
||||
* @param int $property
|
||||
* @return bool
|
||||
*/
|
||||
public static function makeDir($path, $property = 0777)
|
||||
{
|
||||
return is_dir($path) or (self::makeDir(dirname($path), $property) and @mkdir($path, $property));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $dir
|
||||
* @param bool $file
|
||||
* @return array
|
||||
*/
|
||||
public static function scanDir($dir, $file = false)
|
||||
{
|
||||
if ($file == true) {
|
||||
$res = ey_scandir($dir);
|
||||
foreach ($res as $key => $value) {
|
||||
if (($res[$key][0]) == '.') {
|
||||
unset($res[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $res;
|
||||
|
||||
} else {
|
||||
$path = self::getDirs($dir);
|
||||
$dir = $path['dir'];
|
||||
foreach ($dir as $key => $value) {
|
||||
if (($dir[$key][0]) == '.') {
|
||||
unset($dir[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
return $dir;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 功能:生成zip压缩文件,存放都 WEB_CACHE_PATH 中
|
||||
*
|
||||
* @param $files array 需要压缩的文件
|
||||
* @param $filename string 压缩后的zip文件名 包括zip后缀
|
||||
* @param $path string 文件所在目录
|
||||
* @param $outDir string 输出目录
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function zip($files, $filename, $outDir = WEB_CACHE_PATH, $path = DB_Backup_PATH)
|
||||
{
|
||||
$zip = new \ZipArchive;
|
||||
|
||||
File::makeDir($outDir);
|
||||
|
||||
$res = $zip->open($outDir . "\\" . $filename, \ZipArchive::CREATE);
|
||||
|
||||
if ($res == true) {
|
||||
foreach ($files as $file) {
|
||||
if ($t = $zip->addFile($path . $file, str_replace('/', '', $file))) {
|
||||
$t = $zip->addFile($path . $file, str_replace('/', '', $file));
|
||||
}
|
||||
}
|
||||
$zip->close();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 功能:解压缩zip文件,存放都 DB_Backup_PATH 中
|
||||
*
|
||||
* @param $file string 需要压缩的文件
|
||||
* @param $outDir string 解压文件存放目录
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function unzip($file, $outDir = DB_Backup_PATH)
|
||||
{
|
||||
$zip = new \ZipArchive();
|
||||
if ($zip->open(DB_Backup_PATH . "Zip/" . $file) !== true)
|
||||
return false;
|
||||
$zip->extractTo($outDir);
|
||||
$zip->close();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public static function filemtime($file)
|
||||
{
|
||||
return filemtime($file);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static function filectime($file)
|
||||
{
|
||||
return filectime($file);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static function fileatime($file)
|
||||
{
|
||||
return fileatime($file);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
157
src/application/common/util/XML.php
Normal file
157
src/application/common/util/XML.php
Normal file
@@ -0,0 +1,157 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the overtrue/wechat.
|
||||
*
|
||||
* (c) overtrue <i@overtrue.me>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* XML.php.
|
||||
*
|
||||
* @author overtrue <i@overtrue.me>
|
||||
* @copyright 2015 overtrue <i@overtrue.me>
|
||||
*
|
||||
* @see https://github.com/overtrue
|
||||
* @see http://overtrue.me
|
||||
*/
|
||||
|
||||
//namespace EasyWeChat\Support;
|
||||
namespace app\common\util;
|
||||
|
||||
use SimpleXMLElement;
|
||||
|
||||
/**
|
||||
* Class XML.
|
||||
*/
|
||||
class XML
|
||||
{
|
||||
/**
|
||||
* XML to array.
|
||||
*
|
||||
* @param string $xml XML string
|
||||
*
|
||||
* @return array|\SimpleXMLElement
|
||||
*/
|
||||
public static function parse($xml)
|
||||
{
|
||||
return self::normalize(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA | LIBXML_NOBLANKS));
|
||||
}
|
||||
|
||||
/**
|
||||
* XML encode.
|
||||
*
|
||||
* @param mixed $data
|
||||
* @param string $root
|
||||
* @param string $item
|
||||
* @param string $attr
|
||||
* @param string $id
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function build(
|
||||
$data,
|
||||
$root = 'xml',
|
||||
$item = 'item',
|
||||
$attr = '',
|
||||
$id = 'id'
|
||||
) {
|
||||
if (is_array($attr)) {
|
||||
$_attr = array();
|
||||
|
||||
foreach ($attr as $key => $value) {
|
||||
$_attr[] = "{$key}=\"{$value}\"";
|
||||
}
|
||||
|
||||
$attr = implode(' ', $_attr);
|
||||
}
|
||||
|
||||
$attr = trim($attr);
|
||||
$attr = empty($attr) ? '' : " {$attr}";
|
||||
$xml = "<{$root}{$attr}>";
|
||||
$xml .= self::data2Xml($data, $item, $id);
|
||||
$xml .= "</{$root}>";
|
||||
|
||||
return $xml;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build CDATA.
|
||||
*
|
||||
* @param string $string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function cdata($string)
|
||||
{
|
||||
return sprintf('<![CDATA[%s]]>', $string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Object to array.
|
||||
*
|
||||
*
|
||||
* @param SimpleXMLElement $obj
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function normalize($obj)
|
||||
{
|
||||
$result = null;
|
||||
|
||||
if (is_object($obj)) {
|
||||
$obj = (array) $obj;
|
||||
}
|
||||
|
||||
if (is_array($obj)) {
|
||||
foreach ($obj as $key => $value) {
|
||||
$res = self::normalize($value);
|
||||
if (($key === '@attributes') && ($key)) {
|
||||
$result = $res;
|
||||
} else {
|
||||
$result[$key] = $res;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$result = $obj;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Array to XML.
|
||||
*
|
||||
* @param array $data
|
||||
* @param string $item
|
||||
* @param string $id
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected static function data2Xml($data, $item = 'item', $id = 'id')
|
||||
{
|
||||
$xml = $attr = '';
|
||||
|
||||
foreach ($data as $key => $val) {
|
||||
if (is_numeric($key)) {
|
||||
$id && $attr = " {$id}=\"{$key}\"";
|
||||
$key = $item;
|
||||
}
|
||||
|
||||
$xml .= "<{$key}{$attr}>";
|
||||
|
||||
if ((is_array($val) || is_object($val))) {
|
||||
$xml .= self::data2Xml((array) $val, $item, $id);
|
||||
} else {
|
||||
$xml .= is_numeric($val) ? $val : self::cdata($val);
|
||||
}
|
||||
|
||||
$xml .= "</{$key}>";
|
||||
}
|
||||
|
||||
return $xml;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user