dzadsod/include/class/appweb.class.php

359 lines
12 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
defined('IN_MET') or exit('No permission');
load::sys_class('web');
load::own_class('../traits/appcmp');
//前台类
class appweb extends web {
//开始时间
public $time;
public $datetime;
// 调用类
public $tsql;
public $cloud;
public $href;
public $sign = true;
//微信通知参数
public $webase;
public $postdata = [];
public $tem_id = '';
public function __construct() {
global $_M, $_YW;
parent::__construct();
self::cmp_load();
self::loadp('cmp_a,cmp_ac');
//开始时间
$this->time = time();
$this->datetime = self::data_time($this->time);
$this->tsql = load::own_class('tsql','new');
$this->cloud = load::own_class('cloud','new');
// self::basics();
ini_set("display_errors", "On");
error_reporting(E_ERROR);
}
use appcmp;
//生成CSS
public function metcss() {
global $_M,$_YW;
$metcss = PATH_APP_FILE.'web/templates/met/css/metinfo.css';
if(!file_exists($metcss)) self::merge_css();
}
//前台常用信息
protected function basics() {
global $_M,$_YW;
$this->input['appcore'] .= ' data-m_name="'.$this->m_name.'" ';
$this->input['appcore'] .= ' data-own_name="'.$_M['url']['own_name'].'" ';
}
//合同内容
public function postdata($type,$arr) {
global $_M, $_YW;
//清理缓存
$this->postdata = [];
$this->tem_id = '';
//微信模板
switch ($type) {
case 1:
//预约到期提醒
//模板ID
$this->tem_id = $_YW['c']['tem_ida'];
//内容
$this->postdata = [
//开头 提醒的内容
'first' => ['value' => $arr['first']['value'], 'color' => $arr['first']['color'] ],
// 合同开始日期
'keyword1' => ['value' => $arr['h_starttime'] ],
// 合同结束日期
'keyword2' => ['value' => $arr['h_endtime'] ],
//结尾
'remark' => ['value' =>
"合同编号:{$arr['h_number']}".PHP_EOL
."签定企业:{$arr['c_allname']}".PHP_EOL
."相关人员:{$arr['wnamestr']}".PHP_EOL
."提醒时间:{$this->datetime}"
],
];
break;
case 2:
//合同到期提醒
//模板ID
$this->tem_id = $_YW['c']['tem_idb'];
//内容
$this->postdata = [
//开头 提醒的内容
'first' => ['value' => $arr['first']['value'], 'color' => $arr['first']['color'] ],
// 合同编号
'keyword1' => ['value' => $arr['h_number'] ],
// 合同开始日期
'keyword2' => ['value' => $arr['h_starttime'] ],
// 合同结束日期
'keyword3' => ['value' => $arr['h_endtime'] ],
//结尾
'remark' => ['value' =>
"签定企业:{$arr['c_allname']}".PHP_EOL
."相关人员:{$arr['wnamestr']}".PHP_EOL
."通知时间:{$this->datetime}"
],
];
break;
case 3:
//汇总数据通知
//模板ID
$this->tem_id = $_YW['c']['tem_idc'];
//内容
$this->postdata = [
//开头 提醒的内容
'first' => ['value' => '合同提醒汇总结果,请登录后台查看详情', 'color' => '#BDBDBD'],
// 合同编号
'keyword1' => ['value' => '山东梯美广告有限公司' ],
// 合同开始日期
'keyword2' => ['value' => $this->datetime ],
// 合同结束日期
'keyword3' => ['value' => array_sum($arr) ],
//结尾
'remark' => ['value' =>
"定时提醒:{$arr['daya']}".PHP_EOL
."三天到期:{$arr['dayb']}".PHP_EOL
."今天到期:{$arr['dayc']}".PHP_EOL
."今天投放开始总数:{$arr['dayd']}"
],
];
break;
default:
break;
}
return $this;
}
//微信模板消息发送wesend
public function openid($openid = '')
{
global $_M, $_YW;
$openid .= ','.$_YW['c']['openid'];
$openid = stringto_array($openid,',');
foreach ($openid as $id) {
if($id) self::temmsg($id);
}
return $this;
}
//微信合同到期提醒
private function temmsg($openid)
{
global $_M, $_YW;
$return = ['errcode' => -1, 'errmsg' => "系统错误用户openid{$openid}消息模板Tem_id{$this->tem_id}"];
if($openid && $this->tem_id){
$return = $this->webase->post_template_msg($openid, $this->tem_id, '', $this->postdata);
}
$json = is_array($return)?json_encode($return,JSON_UNESCAPED_UNICODE):$return;
//发送记录
$field = [
'openid' => $openid,
'text' => $this->postdata['first']['value'],
'content' => json_encode($this->postdata,JSON_UNESCAPED_UNICODE),
'returntext' => $json,
'state' => $return['errcode'] == 0?1:0,
'exetime' => $this->datetime,
'addtime' => $this->datetime
];
$this->tsql->table('welog')->field($field)->add();
return $return;
}
//参数处理
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'];
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);
}
}
}
?>