<?php
/**
* 企业小程序模块微站定义
*
* @author weixinmao
* @url
*/
defined('IN_IA') or exit('Access Denied');
class Weixinmao_carsModuleSite extends WeModuleSite {
public function doWebIntro() {
//这个操作被定义用来呈现 管理中心导航菜单
global $_W,$_GPC;
load()->func('tpl');
$operation = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
if ($operation == 'post') {
$id = intval($_GPC['id']);
if (checksubmit('submit')) {
$data = array(
'uniacid' => $_W['uniacid'],
'name'=>$_GPC['name'],
'city'=>$_GPC['city'],
'address'=>$_GPC['address'],
'tel'=>$_GPC['tel'],
'qq'=>$_GPC['qq'],
'email'=>$_GPC['email'],
'logo'=>$_GPC['logo'],
'name'=>$_GPC['name'],
'opentime'=>$_GPC['opentime'],
'lng'=>$_GPC['location']['lng'],
'lat'=>$_GPC['location']['lat'],
'content' => ihtmlspecialchars($_GPC['content']),
'createtime' => TIMESTAMP,
);
if (!empty($id)) {
unset($data['createtime']);
pdo_update('weixinmao_cars_intro', $data, array('id' => $id));
} else {
pdo_insert('weixinmao_cars_intro', $data);
$id = pdo_insertid();
}
message('更新成功!', $this->createWebUrl('intro', array('op' => 'display')), 'success');
}
if (empty($shop)) {
$shop['displayorder'] = 0;
$shop['enabled'] = 1;
}
}elseif($operation == 'display'){
$intro = pdo_fetch("select * from " . tablename('weixinmao_cars_intro') . " where uniacid=:uniacid limit 1", array(":uniacid" => $_W['uniacid']));
include $this->template('intro');
}
}
public function doWebCate() {
//这个操作被定义用来呈现 管理中心导航菜单
global $_GPC, $_W;
load()->func('tpl');
$operation = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
if ($operation == 'display') {
if (!empty($_GPC['displayorder'])) {
foreach ($_GPC['displayorder'] as $id => $displayorder) {
pdo_update('weixinmao_house_category', array('displayorder' => $displayorder), array('id' => $id, 'weid' => $_W['uniacid']));
}
message('分类排序更新成功!', $this->createWebUrl('category', array('op' => 'display')), 'success');
}
$children = array();
$category = pdo_fetchall("SELECT * FROM " . tablename('weixinmao_house_category') . " WHERE weid = '{$_W['uniacid']}' ORDER BY parentid ASC, displayorder DESC");
foreach ($category as $index => $row) {
if (!empty($row['parentid'])) {
$children[$row['parentid']][] = $row;
unset($category[$index]);
}
}
include $this->template('category');
} elseif ($operation == 'post') {
$parentid = intval($_GPC['parentid']);
$id = intval($_GPC['id']);
if (!empty($id)) {
$category = pdo_fetch("SELECT * FROM " . tablename('weixinmao_house_category') . " WHERE id = :id AND weid = :weid", array(':id' => $id, ':weid' => $_W['uniacid']));
} else {
$category = array(
'displayorder' => 0,
);
}
if (!empty($parentid)) {
$parent = pdo_fetch("SELECT id, name FROM " . tablename('weixinmao_house_category') . " WHERE id = '$parentid'");
if (empty($parent)) {
message('抱歉,上级分类不存在或是已经被删除!', $this->createWebUrl('post'), 'error');
}
}
if (checksubmit('submit')) {
if (empty($_GPC['catename'])) {
message('抱歉,请输入分类名称!');
}
$data = array(
'weid' => $_W['uniacid'],
'name' => $_GPC['catename'],
'enabled' => intval($_GPC['enabled']),
'displayorder' => intval($_GPC['displayorder']),
'isrecommand' => intval($_GPC['isrecommand']),
'model'=>intval($_GPC['model']),
'description' => $_GPC['description'],
'parentid' => intval($parentid),
'thumb' => $_GPC['thumb']
);
if (!empty($id)) {
unset($data['parentid']);
pdo_update('weixinmao_house_category', $data, array('id' => $id, 'weid' => $_W['uniacid']));
load()->func('file');
file_delete($_GPC['thumb_old']);
} else {
pdo_insert('weixinmao_house_category', $data);
$id = pdo_insertid();
}
message('更新分类成功!', $this->createWebUrl('cate', array('op' => 'display')), 'success');
}
include $this->template('category');
} elseif ($operation == 'delete') {
$id = intval($_GPC['id']);
$category = pdo_fetch("SELECT id, parentid FROM " . tablename('weixinmao_house_category') . " WHERE id = '$id'");
if (empty($category)) {
message('抱歉,分类不存在或是已经被删除!', $this->createWebUrl('weixinmao_house_category', array('op' => 'display')), 'error');
}
pdo_delete('weixinmao_house_category', array('id' => $id, 'parentid' => $id), 'OR');
message('分类删除成功!', $this->createWebUrl('cate', array('op' => 'display')), 'success');
}
}
public function doWebContent() {
//这个操作被定义用来呈现 管理中心导航菜单
global $_GPC, $_W;
load()->func('tpl');
$sql = 'SELECT * FROM ' . tablename('weixinmao_house_category') . ' WHERE `weid` = :weid ORDER BY `parentid`, `displayorder` DESC';
$category = pdo_fetchall($sql, array(':weid' => $_W['uniacid']), 'id');
$operation = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
if ($operation == 'post') {
$id = $_GPC['id'];
if (!empty($id)) {
$item = pdo_fetch("SELECT * FROM " . tablename('weixinmao_house_content') . " WHERE id = :id", array(':id' => $id));
}
$pid = $_GPC['category']['parentid'];
$sid = 0;
if (checksubmit('submit')) {
//print_r($_GPC);
//exit;
$data = array(
'uniacid' => $_W['uniacid'],
'title'=>$_GPC['title'],
'pid'=>$pid,
'sid'=>$sid,
'content' => ihtmlspecialchars($_GPC['content']),
'sort'=>$_GPC['sort'],
'thumb'=>$_GPC['thumb'],
'createtime' => TIMESTAMP,
);
if (!empty($id)) {
unset($data['createtime']);
pdo_update('weixinmao_house_content', $data, array('id' => $id));
} else {
pdo_insert('weixinmao_house_content', $data);
$id = pdo_insertid();
}
message('更新成功!', $this->createWebUrl('content', array('op' => 'display')), 'success');
}
} elseif ($operation == 'display') {
echo $_GPC['keyword'];
$pindex = max(1, intval($_GPC['page']));
$psize = 15;
$condition = ' WHERE `uniacid` = :uniacid ';
$params = array(':uniacid' => $_W['uniacid']);
if (!empty($_GPC['keyword'])) {
$condition .= ' AND `title` LIKE :title';
$params[':title'] = '%' . trim($_GPC['keyword']) . '%';
}
$sql = 'SELECT COUNT(*) FROM ' . tablename('weixinmao_house_content') .$condition ;
$total = pdo_fetchcolumn($sql, $params);
if (!empty($total)) {
$sql = 'SELECT * FROM ' . tablename('weixinmao_house_content') .$condition.' ORDER BY `sort` DESC LIMIT ' . ($pindex - 1) * $psize . ',' . $psize;
$list = pdo_fetchall($sql, $params);
$pager = pagination($total, $pindex, $psize);
}
foreach($list as $k=>$v)
{
$parent_info = pdo_fetch("SELECT name FROM " . tablename('weixinmao_house_category') . " WHERE id = :id", array(':id' => $v['pid']));
$children_info = pdo_fetch("SELECT name FROM " . tablename('weixinmao_house_category') . " WHERE id = :id", array(':id' => $