dzadsod/admin/ajax.class.php

256 lines
10 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::own_class('appadmin');
/*
* 配置
* 包含其他功能初始化
*/
class ajax extends appadmin
{
public function __construct()
{
global $_M, $_YW;
parent::__construct();
}
//own.JS lang语言数组调用
public function doajaxcl()
{
global $_M, $_YW;
parent::loadp('cmp_a,cmp_ac');
unset($_YW['aop']);
unset($_YW['c']['ac_cache']);
echo parent::jsoncallback($_YW);
}
//将相同区域的信息全部查出
public function doallmap()
{
global $_M, $_YW;
$where = " 1 = 1 AND v_maplng IS NOT NULL AND v_maplat IS NOT NULL ";
if (!empty($_M['form']['id'])) $where .= " AND id != '{$_M['form']['id']}' ";
// 省市区
if (!empty($_M['form']['province'])) $where .= " AND v_province= '{$_M['form']['province']}' ";
if (!empty($_M['form']['city'])) $where .= " AND v_city= '{$_M['form']['city']}' ";
if (!empty($_M['form']['district'])) $where .= " AND v_district= '{$_M['form']['district']}'";
// 其他条件
if (!empty($_M['form']['vtype']) || $_M['form']['vtype'] === '0' || $_M['form']['vtype'] === 0) {
$vtype = stringto_array($_M['form']['vtype'], ',');
// 社区类型,分类
$where .= " AND " . $this->tsql->where_arr(['v_type' => $vtype]);
}
$qfield = $_M['form']['allinfo'] === 'all' ? '*' : 'id,v_maplng,v_maplat';
$array = $this->tsql->table('village')
->qfield($qfield)
->where($where)
->all();
echo parent::jsoncallback($array);
}
//城市选择
public function docitys()
{
global $_M, $_YW;
$this->cloud->citydata();
}
//查询广告位编号是否重复
public function doenumber()
{
global $_M, $_YW;
$array = $this->tsql->table('elevator')->where(['e_number' => $_M['form']['e_number']])->one();
$result['valid'] = $array == false ? true : ($array['id'] == $_M['form']['id'] ? true : false);
//再判断一个排期内是否存在此编号
echo parent::jsoncallback($result);
}
//查询广告位编号是否重复
public function dohnumber()
{
global $_M, $_YW;
$array = $this->tsql->table('contract')->where(['h_number' => $_M['form']['h_number']])->one();
$result['valid'] = $array == false ? true : ($array['id'] == $_M['form']['id'] ? true : false);
echo parent::jsoncallback($result);
}
//查询投放标题
public function dolatitle()
{
global $_M, $_YW;
$ids = stringto_array($_M['form']['ids'], ',');
if (count($ids)) {
$url = $_M['url']['own_name'] . 'c=table_on&a=doschedule&s_lid=';
$strid = arrayto_string($ids, ',');
$launch = $this->tsql->table('launch')->where(" id IN({$strid}) ")->all('id');
list($eid, $nid) = $ids;
$eslid = $eid ? '<a href="' . $url . $eid . '" title="查看排期">' . $launch[ $eid ]['l_title'] . '</a>' : '';
$ntslid = $nid ? '<a href="' . $url . $nid . '" title="查看排期">' . $launch[ $nid ]['l_title'] . '</a>' : '';
}
echo parent::jsoncallback(['eslid' => $eslid, 'ntslid' => $ntslid]);
}
//广告位排期入库【重要】
public function doapplan()
{
global $_M, $_YW;
$form = $_M['form'];
$ap_enumber = $_M['form']['ap_enumber'];
$slid = $form['slid'];
//检查投放订单是否存在
$retarray = ['code' => false, 'text' => '投放计划不存在!'];
$launch = $this->tsql->table('launch')
->where(['id' => $slid])
->one();
if ($launch == false) {
echo parent::jsoncallback($retarray);
exit;
}
//检查广告位排期时间是否可用,是否合法
$l_starttime = strtotime($form['l_starttime']);
$l_endtime = strtotime($form['l_endtime']);
$daystr = strtotime(date('Y-m-d', time()));
if ($l_starttime > $l_endtime && (empty($l_starttime) || empty($l_endtime))) {
$retarray['text'] = "{$ap_enumber}】投放结束时间({$form['l_starttime']})不能小于开始时间({$form['l_endtime']})";
echo parent::jsoncallback($retarray);
exit;
}
//根据广告位编号查询对应广告位信息 e_enable
$elevator = $this->tsql->table('elevator')
->where(['e_number' => $ap_enumber])
->one();
$elstr = $error = $sqlupd = false;
// 判断广告位是否存在
if ($elevator != false) {
//进行排期处理
$field = [
's_lid' => $slid,
's_enumber' => $ap_enumber,
's_hnumber' => $form['l_hnumber'],
's_starttime' => $form['l_starttime'],
's_endtime' => $form['l_endtime'],
];
// 不可通过唯一索引新增和更新数据,因为他会先触发新增的触发器
// 先查询是否存在相应的广告位排期,存在则修改,相反为新增
$enum = $this->tsql->table('schedule')
->qfield('id')
->where(['s_lid' => $slid, 's_enumber' => $ap_enumber])
->one();
if ($enum == false) {
//判断广告位是否停用
if ($elevator['e_enable']) {
//新增
$field['id'] = 'UUID()';
$this->tsql->table('schedule')
->special('UUID()')
->field($field)
->add();
} else {
//表示广告位已停用
$elstr = '已禁用';
}
} else {
//修改
$this->tsql->table('schedule')
->field($field)
->where(['id' => $enum['id']])
->upd();
$sqlupd = true;
}
//获取sql执行结果查看是否存在错误
$error = $this->tsql->error();
if ($error) {
$elstr = $error;
// 清楚掉已存在,但修改后无法达到要求的广告位
if ($sqlupd) {
$this->tsql->table('schedule')
->where(['id' => $enum['id']])
->del();
}
}
//广告位地址
$e_address = parent::e_address($elevator);
} else {
// 删除此广告位之前保存的排期记录
$this->tsql->table('schedule')
->where(['s_enumber' => $ap_enumber])
->del();
// 记录不存在的广告位,保留到最后删除掉相关的选择广告位
$session = load::sys_class('session', 'new');
$senumber = $session->get('schedule_eid' . $slid);
$senumber[] = $ap_enumber;
$session->set('schedule_eid' . $slid, $senumber);
$e_address = "{$ap_enumber}";
$elstr = '广告位不存在或者已删除,';
}
$array = $elstr
? ['code' => false, 'text' => "{$e_address}{$elstr}排期失败。", 'eid' => $ap_enumber, $enum, $field, $senumber]
: ['code' => true, 'text' => "{$e_address},排期成功。", 'eid' => $ap_enumber, $senumber];
echo parent::jsoncallback($array);
exit;
}
//选中排期的成功广告位保存
public function dolenumber()
{
global $_M, $_YW;
$slid = $_M['form']['slid'];
// 删除不存在的已选择广告位
$session = load::sys_class('session', 'new');
$schedule_eid = $session->get('schedule_eid' . $slid) ?: [];
$session->del('schedule_eid');
$session->del('schedule_eid' . $slid);
$launch = $this->tsql->table('launch')
->where(['id' => $slid])
->one();
$l_selectenum = arrayto_string(array_unique(array_diff(stringto_array($launch['l_selectenum'], ','), $schedule_eid)), ',');
// 排期保存
//查询出所有的
$schedule = $this->tsql->table('schedule')
->where(['s_lid' => $slid])
->all();
$idarr = array_column($schedule, 's_enumber');
$idstr = arrayto_string($idarr, ',');
$this->tsql->table('launch')
->field(['l_selectenum' => $l_selectenum, 'l_enumber' => $idstr])
->where(['id' => $slid])
->upd();
$error = $this->tsql->error();
$num = count($idarr);
$array = $error
? ['code' => false, 'text' => "选中广告位保存失败,导致排期失败!", 'idstr' => $idstr, $schedule_eid]
: ['code' => true, 'text' => "选中的({$num})个广告位排期记录保存成功。", 'idstr' => $idstr, $schedule_eid];
echo parent::jsoncallback($array);
}
//处理序列表,让他始终大于广告位的总个数
public function dosequence()
{
global $_M, $_YW;
$counta = $this->tsql->table('elevator')->count();
$countb = $this->tsql->table('sequence')->count();
$count = $counta + 10 - $countb;
if ($count > 0) {
for ($i = 0; $i < $count; $i++) {
$this->tsql->table('sequence')->field(['seq' => null])->add();
}
}
echo parent::jsoncallback([$counta, $countb, $count]);
}
}
?>