474 lines
17 KiB
PHP
474 lines
17 KiB
PHP
<?php
|
||
|
||
defined('IN_MET') or exit('No permission');
|
||
|
||
load::sys_class('admin');
|
||
load::own_func('appcmp');
|
||
load::own_class('../traits/appcmp');
|
||
|
||
//后台类
|
||
class appadmin extends admin
|
||
{
|
||
|
||
# URL上c的值
|
||
public $u_urlc;
|
||
# URL上a的值
|
||
public $u_urla;
|
||
# URL上的参数
|
||
public $u_para;
|
||
|
||
# 管理员权限
|
||
public $adop = ['met' => false, 'add' => false, 'del' => false];
|
||
|
||
// 调用类
|
||
public $tsql;
|
||
public $cloud;
|
||
|
||
# 初始化
|
||
public function __construct()
|
||
{
|
||
global $_M, $_YW;
|
||
parent::__construct();
|
||
|
||
//调试使用
|
||
ini_set("display_errors", "On");
|
||
error_reporting(E_ERROR);
|
||
|
||
$this->tsql = load::own_class('tsql', 'new');
|
||
self::cmp_load();
|
||
self::adminop();
|
||
$this->cloud = load::own_class('cloud', 'new');
|
||
}
|
||
|
||
use appcmp;
|
||
|
||
//调试使用
|
||
public function bug()
|
||
{
|
||
$this->destruct = false;
|
||
}
|
||
|
||
# 后台导航
|
||
/*
|
||
* @$select string 最终菜单选项
|
||
* @$title string 当前页面标题
|
||
*/
|
||
public function appnav($select = '', $title = '')
|
||
{
|
||
global $_M, $_YW;
|
||
if (is_array($select)) list($select, $title) = $select;
|
||
//当前的CA组合
|
||
$select = empty($select) ? $_M['form']['c'] . '__' . $_M['form']['a'] : $select;
|
||
//导航公用参数
|
||
$glpara = [
|
||
'navon' => $_M['form']['navon'],
|
||
];
|
||
|
||
/*
|
||
* 导航规则
|
||
*/
|
||
//key 为c值和a值组成,可实现自动选择
|
||
//val 第一位是导航名称,第二位为传递的参数(array) 若第三位跳转的外链
|
||
$nav = [
|
||
'dzadsod__dodzadsod' => [
|
||
['统计中心'],
|
||
[
|
||
'dzadsod__dodzadsod' => ['总计界面'],
|
||
'table_on__dovillages' => ['场所统计'],
|
||
'table_on__doelevators' => ['广告位统计'],
|
||
'table_on__doschedule' => ['排期查询'],
|
||
]
|
||
],
|
||
'table_on__docontract' => [
|
||
['运营中心'],
|
||
[
|
||
|
||
'table_on__docontract' => ['订单管理'],
|
||
'table_on__dolaunch' => ['投放计划'],
|
||
// 'info_on__douplaunch' => ['调整投放'],
|
||
'table_on__docustomer' => ['合作企业'],
|
||
'table_on__doworkers' => ['企业联系人'],
|
||
'table_on__dokeylist' => ['巡查人员'],
|
||
]
|
||
],
|
||
|
||
'table_on__doelevator' => [
|
||
['资源管理'],
|
||
[
|
||
'table_on__doelevator' => ['广告位'],
|
||
'table_on__dovillage' => ['合作场所']
|
||
]
|
||
],
|
||
|
||
'table_on__dopara' => [
|
||
['配置参数'],
|
||
[
|
||
'config__doindex' => ['基础配置'],
|
||
'table_on__dopara' => ['参数列表']
|
||
]
|
||
],
|
||
'index__doindex' => [
|
||
['更新检测', ['check' => 1]]
|
||
]
|
||
];
|
||
|
||
$i = 0;
|
||
foreach ($nav as $key => $val) {
|
||
list($info, $sub) = $val;
|
||
//判断是否执行当前二级目录
|
||
$li = '';
|
||
if (is_array($info) && ($select == $key || array_key_exists($select, $sub))) {
|
||
//执行二级目录的操作
|
||
$sub = array_merge([$key => $info], $sub);
|
||
foreach ($sub as $skey => $sval) {
|
||
if ($key == $skey) $sval = array_replace($info, $sval);
|
||
//执行一级目录的操作
|
||
list($sname, $surl) = self::nav_para($skey, $sval, $glpara);
|
||
//二级选项和页面title
|
||
$active = '';
|
||
if ($select == $skey) {
|
||
$select = $key;
|
||
$active = 'active';
|
||
$this->input['met_title'] = empty($title) ? $sname : $title;
|
||
}
|
||
//二级导航HTML
|
||
$li .= "<li class='nav-item'><a class='nav-link {$active}' href='{$surl}'>{$sname}</a></li>";
|
||
}
|
||
$this->input['nav_sub'] = empty($li) ? '' : '<div class="m-t-10 app-sub-nav"><ul class="p-b-10 nav nav-tabs nav-tabs-line">' . $li . '</ul></div>';
|
||
}
|
||
|
||
//执行一级目录的操作
|
||
if (!is_array($info)) $info = $val;
|
||
list($name, $url) = self::nav_para($key, $info, $glpara);
|
||
//填充HTML
|
||
nav::set_nav($i, $name, $url);
|
||
$select_nav[ $key ] = $i;
|
||
|
||
//页面title
|
||
if ($select == $key && empty($this->input['met_title'])) $this->input['met_title'] = empty($title) ? $name : $title;
|
||
$i++;
|
||
}
|
||
|
||
//指定当前方法属于哪个主导航
|
||
if (array_key_exists($select, $nav)) nav::select_nav($select_nav[ $select ]);
|
||
}
|
||
|
||
//导航NAME和URL
|
||
private function nav_para($key, $info, $glpara)
|
||
{
|
||
global $_M, $_YW;
|
||
//合并c和a
|
||
list($c, $a) = stringto_array($key, '__');
|
||
//合并默认参数值
|
||
$arr = array_merge(['c' => $c, 'a' => $a], $glpara);
|
||
list($name, $para, $links) = $info;
|
||
//判断是否有设置单独的参数,有则增加
|
||
if (is_array($para)) $arr = array_merge($arr, $para);
|
||
//生成URL
|
||
$url = empty($links) ? $_M['url']['own_name'] : $links;
|
||
return [$name, self::http_build_query($url, $arr)];
|
||
}
|
||
|
||
#URL上c的值 a的值
|
||
#$appshow 全局模板文件,指整个文件的模板
|
||
public function point($c, $a, $appshow = '')
|
||
{
|
||
global $_M, $_YW;
|
||
$this->u_urlc = $c;
|
||
$this->u_urla = $a;
|
||
if (!empty($appshow)) $this->appshow = 'app/' . $appshow;
|
||
}
|
||
|
||
#URL处理
|
||
#$appshow 单独定义模板 某个方法内定义
|
||
public function appurl($tname = '', $query = [], $appshow = '')
|
||
{
|
||
global $_M, $_YW;
|
||
//数据库表简写
|
||
$this->tname = empty($tname) ? self::tname() : $tname;
|
||
//URL参数
|
||
if (!is_array($query)) $query = [$query];
|
||
$query['tname'] = $this->tname;
|
||
$this->u_para = '&' . http_build_query($query);
|
||
//URL
|
||
$this->input['url'] = [
|
||
'action' => $_M['url']['own_name'] . "c={$this->u_urlc}&a={$this->u_urla}" . $this->u_para, // 表单提交URL
|
||
'ajaxurl' => $_M['url']['own_name'] . "c=table_ajax&a={$this->u_urla}" . $this->u_para, // table数据获取URL
|
||
'addlist' => $_M['url']['own_name'] . 'c=table_ajax&a=do_table_add_list' . $this->u_para, // table新增行URL
|
||
'backup' => $_M['url']['own_name'] . 'c=backups&a=doindex' . $this->u_para, // table备份URL
|
||
'select' => $_M['url']['own_name'] . 'c=select&a=doselect' // 下拉选择器
|
||
];
|
||
$this->input['tname'] = $this->tname;
|
||
$_YW['url'] = $this->input['url'];
|
||
if (!empty($appshow)) $this->appshow = 'app/' . $appshow;
|
||
}
|
||
|
||
//权限
|
||
private function adminop()
|
||
{
|
||
global $_M, $_YW;
|
||
$admin_op = background_privilege();
|
||
$adminop = array_filter(explode('-', $admin_op['admin_op']));
|
||
//1查看 【不勾选任何的操作即可实现】
|
||
//2编辑 不含删除 【不勾选删除权限即可实现】
|
||
//3不限制权限 【全部勾选即可】
|
||
if (in_array('metinfo', $adminop)) {
|
||
$this->adop = ['met' => true, 'add' => true, 'del' => true];
|
||
} else {
|
||
if (in_array('add', $adminop) || in_array('editor', $adminop)) {
|
||
$this->adop['add'] = true;
|
||
}
|
||
if (in_array('del', $adminop)) {
|
||
$this->adop['del'] = true;
|
||
}
|
||
if ($this->adop['add'] && $this->adop['del']) {
|
||
$this->adop['met'] = true;
|
||
}
|
||
}
|
||
$_YW['aop'] = $this->adop;
|
||
}
|
||
|
||
//添加设置参数HTML
|
||
public function setparahtml($ptype = 0, &$html)
|
||
{
|
||
global $_M, $_YW;
|
||
$addparaurl = $_M['url']['own_name'] . 'c=table_on&a=dopara&p_type=' . $ptype;
|
||
$html .= '<span class="text-help m-l-10"><a target="_blank" href="' . $addparaurl . '">设置选项</a></span>';
|
||
}
|
||
|
||
//参数单选组成
|
||
public function para_radio($para, $name, $checked, &$html, $exists = false)
|
||
{
|
||
global $_M, $_YW;
|
||
$html = '';
|
||
$first = 'data-checked="' . $checked . '" required data-fv-notEmpty-message="不能为空"';
|
||
foreach ($para as $key => $val) {
|
||
if ($exists) {
|
||
list($p_name, $p_value, $p_text) = $val;
|
||
} else {
|
||
extract($val);
|
||
}
|
||
$html .= '<div class="radio-custom radio-primary radio-inline">
|
||
<input type="radio" id="' . $name . $key . '" name="' . $name . '" value="' . $p_value . '" ' . $first . ' />
|
||
<label for="' . $name . $key . '">' . $p_name . '</label>
|
||
<span class="text-help m-l-10">' . $p_text . '</span>
|
||
</div>';
|
||
$first = '';
|
||
}
|
||
return $this;
|
||
}
|
||
|
||
//参数多选组成
|
||
public function para_checkbox($para, $name, $checked, &$html, $exists = false)
|
||
{
|
||
global $_M, $_YW;
|
||
$html = '';
|
||
$first = 'data-checked="' . $checked . '" required data-fv-notEmpty-message="不能为空" '; // data-delimiter="," 因为暂时无效
|
||
foreach ($para as $key => $val) {
|
||
if ($exists) {
|
||
list($p_name, $p_value, $p_text) = $val;
|
||
} else {
|
||
extract($val);
|
||
}
|
||
$html .= '<div class="checkbox-custom checkbox-primary checkbox-inline">
|
||
<input type="checkbox" id="' . $name . $key . '" name="' . $name . '" value="' . $p_value . '" ' . $first . ' />
|
||
<label for="' . $name . $key . '">' . $p_name . '</label>
|
||
<span class="text-help m-l-10">' . $p_text . '</span>
|
||
</div>';
|
||
$first = '';
|
||
}
|
||
return $this;
|
||
}
|
||
|
||
//参数处理
|
||
public function translate($p_type = 0)
|
||
{
|
||
global $_M, $_YW;
|
||
$para = self::paralist($p_type);
|
||
return array_combine(array_column($para, 'p_value'), array_column($para, 'p_name'));
|
||
}
|
||
|
||
//场所名称
|
||
public function villagelist($id, $key = 'v_name')
|
||
{
|
||
global $_M, $_YW;
|
||
$village = $this->tsql->table('village')->where(['id' => $id])->one();
|
||
return $village[ $key ];
|
||
}
|
||
|
||
//公司名称
|
||
public function customerlist($id, $key = 'c_allname')
|
||
{
|
||
global $_M, $_YW;
|
||
$customer = $this->tsql->table('customer')->where(['id' => $id])->one();
|
||
return $customer[ $key ];
|
||
}
|
||
|
||
//相关人员
|
||
public function workerslist($id, $key = 'w_name')
|
||
{
|
||
global $_M, $_YW;
|
||
$workers = $this->tsql->table('workers')->where(['id' => $id])->one();
|
||
return $key == false ? $workers : $workers[ $key ];
|
||
}
|
||
|
||
//返回广告位对照地址
|
||
public function e_address($elevator)
|
||
{
|
||
global $_M, $_YW;
|
||
//门口方位
|
||
$e_bno = self::paralist(['p_type' => 3, 'p_value' => $elevator['e_bno']]);
|
||
//广告位置
|
||
$e_aps = self::paralist(['p_type' => 0, 'p_value' => $elevator['e_aps']]);
|
||
//场所
|
||
$e_vid = self::villagelist($elevator['e_vid']);
|
||
return "({$elevator['e_number']})" . $e_vid . $e_bno['p_name'] . $e_aps['p_name'];
|
||
}
|
||
|
||
//字段颜色
|
||
public function state_color($state, $array = [])
|
||
{
|
||
global $_M, $_YW;
|
||
$color = ['red-600', 'green-600', 'purple-600'];
|
||
$str = count($array) > 0 ? $array : ['无效', '有效'];
|
||
return '<font class="' . $color[ $state ] . '">' . $str[ $state ] . '</font>';
|
||
}
|
||
|
||
//字体颜色
|
||
public function str_color($state, $str, $weight = 'unset')
|
||
{
|
||
global $_M, $_YW;
|
||
$color = ['red-600', 'green-600', 'cyan-600', 'blue-600','orange-600','purple-600'];
|
||
return '<font class="' . $color[ $state ] . ' font-weight-' . $weight . '">' . $str . '</font>';
|
||
}
|
||
|
||
//标签形式的分割显示
|
||
public function tab_tokenfield($ver, $type = 0, $decollator = ',', $length = 0)
|
||
{
|
||
global $_M, $_YW;
|
||
$class = ['tag-default', 'tag-primary', 'tag-warning'];
|
||
$array = stringto_array($ver, $decollator);
|
||
$i = 0;
|
||
foreach ($array as $val) {
|
||
$html .= '<span class="tag tag-sm ' . $class[ $type ] . '">' . $val . '</span> ';
|
||
$i++;
|
||
if ($length > 0 && $length == $i) break;
|
||
}
|
||
return $html;
|
||
}
|
||
|
||
//广告位的合同编号
|
||
public function e_state($title)
|
||
{
|
||
global $_M, $_YW;
|
||
$class = ['tag-danger', 'tag-primary'];
|
||
$title = $title > 0 ? '已租赁' : '空置';
|
||
$type = $title > 0 ? 1 : 0;
|
||
return '<span class="tag tag-sm ' . $class[ $type ] . '">' . $title . '</span> ';
|
||
}
|
||
|
||
//参数的对应值获取
|
||
public function paralist($p_type = 0)
|
||
{
|
||
global $_M, $_YW;
|
||
$this->tsql->table('para')
|
||
->where(is_array($p_type) ? $p_type : ['p_type' => $p_type])
|
||
->order('p_order DESC');
|
||
|
||
return is_array($p_type) ? $this->tsql->one() : $this->tsql->all();
|
||
}
|
||
|
||
//转化字符串形式
|
||
public function strchange($strarr = [])
|
||
{
|
||
global $_M, $_YW;
|
||
foreach ($strarr as $val) {
|
||
if ($val != null) $idstr[] = "'{$val}'";
|
||
}
|
||
return arrayto_string($idstr, ',');
|
||
}
|
||
|
||
//广告位状态变更
|
||
public function type_onoff($field, $value, $id, $array = ['无效', '有效'])
|
||
{
|
||
global $_M, $_YW;
|
||
$color = ['tag-danger', 'tag-success'];
|
||
$url = $_M['url']['own_name'] . "c=table_off&a=doindex&submit_type=typeonoff&field={$field}&all_id={$id}&tname={$this->tname}&method=ajax";
|
||
return '<span data-href="' . $url . '" class="btn-cursor-pointer tag tag-sm tag-outline ' . $color[ $value ] . '" >' . $array[ $value ] . '</span>';
|
||
}
|
||
|
||
//处理多选的ID
|
||
public function where_id(&$where)
|
||
{
|
||
global $_M, $_YW;
|
||
$allid = array_filter(stringto_array($_M['form']['all_id'], ','));
|
||
if ($allid) {
|
||
if ($where) $where .= " AND ";
|
||
$idstr = self::strchange($allid);
|
||
switch ($this->tname) {
|
||
case 'elevators':
|
||
$where .= " el.e_number IN({$idstr}) ";
|
||
break;
|
||
case 'villages':
|
||
$where .= " vi.id IN({$idstr}) ";
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
// 对现有广告位进行裂变,已经不再需要
|
||
public function fission()
|
||
{
|
||
global $_M, $_YW;
|
||
//获取所有广告位
|
||
$elevator = $this->tsql->table('elevator')->all();
|
||
//划定什么位置裂变成什么 1裂变出2
|
||
$e_aps = [
|
||
'1' => 4,
|
||
'2' => 5,
|
||
'3' => 6,
|
||
];
|
||
|
||
//拼装数据
|
||
foreach ($elevator as $val) {
|
||
//计算广告位编号
|
||
$neweaps = $e_aps[ $val['e_aps'] ];
|
||
self::e_number($val['e_number'], $neweaps);
|
||
$field = [
|
||
'e_number' => $val['e_number'],
|
||
'e_vid' => $val['e_vid'],
|
||
'e_bno' => $val['e_bno'],
|
||
'e_aps' => $neweaps,
|
||
'e_size' => $val['e_size'],
|
||
'e_enable' => $val['e_enable'],
|
||
'e_label' => $val['e_label'],
|
||
'e_text' => $val['e_text']
|
||
];
|
||
|
||
$this->tsql->table('elevator')
|
||
->field($field)
|
||
->add();
|
||
}
|
||
}
|
||
|
||
//对字符串处理
|
||
public function e_number(&$num, $neweaps, $type = false)
|
||
{
|
||
global $_M, $_YW;
|
||
if ($type) $neweaps++;
|
||
//新的编号
|
||
$enum = $num . $neweaps;
|
||
//验证
|
||
$elevator = $this->tsql->table('elevator')->where(['e_number' => $enum])->one();
|
||
if ($elevator == false) {
|
||
$num = $enum;
|
||
} else {
|
||
self::e_number($num, $neweaps, true);
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
?>
|