<?php
/**
* 砍价宝模块小程序接口定义
*
* @author ypuk
* @url
*/
defined('IN_IA') or exit('Access Denied');
define("YPUK_FFYD", "ypuk_ffyd");
define("YPUK_FFYD_RES", "../addons/" . YPUK_FFYD . "/");
require_once IA_ROOT . "/addons/" . YPUK_FFYD . "/dbconfig.class.php";
class Ypuk_ffydModuleWxapp extends WeModuleWxapp
{
public $Setting;
public $attachment_root;
public static $SERVER_VERSION = '4.9.0';
public function doPageRecommendList()
{
global $_GPC, $_W;
$message = '成功';
$close_ios_pay = $this->checkCloseIosPay($_GPC['version'], $_GPC['appos']);
$list = pdo_fetchall("SELECT * FROM " . tablename(DBCONFIG::$TABLE_FFYD_ARTICLE) . " WHERE weid='{$_W['acid']}' AND recommend='1' AND status=1 ORDER BY sort ASC, id DESC ");
foreach ($list as $key => $val) {
if ($close_ios_pay == 1) {
$list[$key]['price'] = 0;
}
$list[$key]['thumb'] = tomedia($val['thumb']);
$list[$key]['createtime'] = date('Y-m-d H:i', $val['createtime']);
}
return $this->result(0, $message, $list);
}
public function doPageRecommendPackage()
{
global $_GPC, $_W;
$message = '成功';
$list = pdo_fetchall("SELECT * FROM " . tablename(DBCONFIG::$TABLE_FFYD_PACKAGE) . " WHERE weid='{$_W['acid']}' AND recommend='1' AND status=1 ORDER BY createtime DESC, id DESC ");
foreach ($list as $key => $val) {
$list[$key]['thumb'] = tomedia($val['thumb']);
$list[$key]['createtime'] = date('Y-m-d H:i', $val['createtime']);
$list[$key]['updatenum'] = pdo_fetchcolumn("SELECT COUNT(*) FROM" . tablename(DBCONFIG::$TABLE_FFYD_PACKAGE_BIND) . "WHERE weid='{$_W['acid']}' AND pid = {$val['id']}");
$intro = str_replace(' ', '', $val['intro']);
if (mb_strlen($intro, 'utf-8') > 10) {
$list[$key]['intro'] = mb_substr($intro, 0, 10, 'utf-8') . '...';
} else {
$list[$key]['intro'] = $intro;
}
}
return $this->result(0, $message, $list);
}
public function doPageList()
{
global $_GPC, $_W;
$message = '成功';
$pindex = max(1, intval($_GPC['page']));
$psize = 20;
$order = $_GPC['order'];
$close_ios_pay = $this->checkCloseIosPay($_GPC['version'], $_GPC['appos']);
if ($order == 'new') {
$orderby = 'ORDER BY sort ASC, createtime DESC';
} else {
$orderby = 'ORDER BY sort ASC, viewnum DESC';
}
$list = pdo_fetchall("SELECT * FROM " . tablename(DBCONFIG::$TABLE_FFYD_ARTICLE) . " WHERE weid='{$_W['acid']}' AND status=1 " . $orderby . " LIMIT " . ($pindex - 1) * $psize . ',' . $psize);
foreach ($list as $key => $val) {
if ($close_ios_pay == 1) {
$list[$key]['price'] = 0;
}
$list[$key]['thumb'] = tomedia($val['thumb']);
$list[$key]['createtime'] = date('Y-m-d H:i', $val['createtime']);
if ($val['type'] == 'pic') {
$articlecontent = pdo_fetch("SELECT * FROM" . tablename(DBCONFIG::$TABLE_FFYD_PIC_CONTENT) . "WHERE weid='{$_W['acid']}' AND articleid='{$val['id']}'");
$articlecontent['pic'] = unserialize($articlecontent['piclist']);
$list[$key]['picnum'] = count($articlecontent['pic']);
}
}
return $this->result(0, $message, $list);
}
public function doPagePackageList()
{
global $_GPC, $_W;
$message = '成功';
$pindex = max(1, intval($_GPC['page']));
$psize = 20;
$close_ios_pay = $this->checkCloseIosPay($_GPC['version'], $_GPC['appos']);
$order = $_GPC['order'];
if ($order == 'new' || empty($order)) {
$orderby = 'ORDER BY sort DESC, id DESC';
} else {
$orderby = 'ORDER BY buynum DESC';
}
$where = ' AND status=1 ';
if (!empty($_GPC['recommend']) && $_GPC['recommend'] == 1) {
$where .= ' AND recommend=1 ';
$psize = 3;
}
$list = pdo_fetchall("SELECT * FROM " . tablename(DBCONFIG::$TABLE_FFYD_PACKAGE) . " WHERE weid='{$_W['acid']}' " . $where . " " . $orderby . " LIMIT " . ($pindex - 1) * $psize . ',' . $psize);
foreach ($list as $key => $val) {
if ($close_ios_pay == 1) {
$list[$key]['price'] = 0;
}
$list[$key]['thumb'] = tomedia($val['thumb']);
$list[$key]['createtime'] = date('Y-m-d H:i', $val['createtime']);
$list[$key]['updatenum'] = pdo_fetchcolumn("SELECT COUNT(*) FROM" . tablename(DBCONFIG::$TABLE_FFYD_PACKAGE_BIND) . "WHERE weid='{$_W['acid']}' AND pid = {$val['id']}");
$intro = str_replace(' ', '', $val['intro']);
if (mb_strlen($intro, 'utf-8') > 10) {
$list[$key]['intro'] = mb_substr($intro, 0, 10, 'utf-8') . '...';
} else {
$list[$key]['intro'] = $intro;
}
$list[$key]['updatenum'] = pdo_fetchcolumn("SELECT COUNT(*) FROM" . tablename(DBCONFIG::$TABLE_FFYD_PACKAGE_BIND) . "WHERE weid='{$_W['acid']}' AND pid = {$val['id']}");
if (!empty($list[$key]['buynum_min']) && $list[$key]['buynum_min'] != 0) {
$list[$key]['buynum'] = $list[$key]['buynum_min'] + $list[$key]['buynum'];
}
if ($list[$key]['buynum'] > 999) {
$list[$key]['buynum'] = '999+';
}
}
return $this->result(0, $message, $list);
}
public function doPageGetIndexMoreSetting()
{
global $_GPC, $_W;
$setting = pdo_fetch("SELECT * FROM " . tablename(DBCONFIG::$TABLE_FFYD_SETTING) . " WHERE weid='{$_W['acid']}'");
$catnum = pdo_fetchcolumn("SELECT COUNT(*) FROM" . tablename(DBCONFIG::$TABLE_FFYD_CATEGORY) . "WHERE weid='{$_W['acid']}' AND parentid = 0");
$result['navtype'] = $setting['navtype'];
if ($catnum < 5) {
$result['scstyle'] = 'padding-left:18px;';
} else {
$result['scstyle'] = '';
}
/*--Swiper---*/
if (!empty($setting['swiper'])) {
$swiper = unserialize($setting['swiper']);
foreach ($swiper as $key => $val) {
$swiper[$key]['swiper_image'] = tomedia($val['swiper_image']);
$sorts[$key] = $val['swiper_sort'];
}
array_multisort($sorts, SORT_ASC, $swiper);
} else {
$swiper = '';
}
$topBarItems = array(0 => array('id' => 'new', 'name' => '新鲜的', 'selected' => true), 1 => array('id' => 'view', 'name' => '热门的', 'selected' => false));
if (!empty($setting['index_new_text'])) {
$topBarItems[0]['name'] = $setting['index_new_text'];
}
if (!empty($setting['index_view_text'])) {
$topBarItems[1]['name'] = $setting['index_view_text'];
}
$result['topBarItems'] = $topBarItems;
$result['swiper'] = $swiper;
return $this->result(0, '成功', $result);
}
public function doPageNavSetting()
{
global $_GPC, $_W;
$message = '成功';
$setting = pdo_fetch("SELECT * FROM " . tablename(DBCONFIG::$TABLE_FFYD_SETTING) . " WHERE weid='{$_W['acid']}'");
$catnum = pdo_fetchcolumn("SELECT COUNT(*) FROM" . tablename(DBCONFIG::$TABLE_FFYD_CATEGORY) . "WHERE weid='{$_W['acid']}' AND parentid = 0");
$result['navtype'] = $setting['navtype'];
if ($catnum < 5) {
$result['scstyle'] = 'padding-left:18px;';
} else {
$result['scstyle'] = '';
}
return $this->result(0, $message, $result);
}
public function doPageCategoryList()
{
global $_GPC, $_W;
$message = '成功';
$data = array();
$topcat = pdo_fetchall("SELECT *