<?php
/**
* 旺铺点餐模块小程序接口定义
* @author 阿莫之家社区
* @url http://www.0766city.com/
*/
defined('IN_IA') or exit('Access Denied');
class Zh_diancModuleWxapp extends WeModuleWxapp {
//系统信息
public function doPageSystem() {
global $_W, $_GPC;
$res = pdo_get('wpdc_system', array('uniacid' => $_W['uniacid']));
echo json_encode($res);
}
//获取openid
public function doPageOpenid() {
global $_W, $_GPC;
$res = pdo_get('wpdc_system', array('uniacid' => $_W['uniacid']));
$code = $_GPC['code'];
$appid = $res['appid'];
$secret = $res['appsecret'];
// echo $appid;die;
$url = "https://api.weixin.qq.com/sns/jscode2session?appid=" . $appid . "&secret=" . $secret . "&js_code=" . $code . "&grant_type=authorization_code";
function httpRequest($url, $data = null) {
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
if (!empty($data)) {
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
}
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
//执行
$output = curl_exec($curl);
curl_close($curl);
return $output;
}
$res = httpRequest($url);
print_r($res);
}
//商家登录
public function doPageStoreLogin() {
global $_W, $_GPC;
$user = $_GPC['user'];
$password = md5($_GPC['password']);
$res = pdo_get('wpdc_seller', array('account' => $user, 'pwd' => $password, 'uniacid' => $_W['uniacid']));
if ($res) {
echo json_encode($res);
} else {
echo '2';
}
}
//商家信息
public function doPageStore() {
global $_W, $_GPC;
if ($_GPC['user_id']) {
$data['user_id'] = $_GPC['user_id'];
$data['store_id'] = $_GPC['id'];
$data['time'] = date("Y-m-d");
$list = pdo_get('wpdc_traffic', $data);
if (!$list) {
pdo_insert('wpdc_traffic', $data);
}
}
$res = pdo_get('wpdc_store', array('uniacid' => $_W['uniacid'], 'id' => $_GPC['id']));
if ($res['img']) {
if (strlen($res['img']) > 51) {
$res['img'] = explode(',', $res['img']);
} else {
$res['img'] = array(0 => $res['img']);
}
}
if ($res['yyzz']) {
if (strlen($res['yyzz']) > 51) {
$res['yyzz'] = explode(',', $res['yyzz']);
} else {
$res['yyzz'] = array(0 => $res['yyzz']);
}
}
if ($res['environment']) {
if (strlen($res['environment']) > 51) {
$res['environment'] = explode(',', $res['environment']);
} else {
$res['environment'] = array(0 => $res['environment']);
}
}
function video($video) {
$vid = trim(strrchr($video, '/'), '/');
$vid = substr($vid, 0, -5);
$json = file_get_contents("http://vv.video.qq.com/getinfo?vids=" . $vid . "&platform=101001&charge=0&otype=json");
// echo $json;die;
$json = substr($json, 13);
$json = substr($json, 0, -1);
$a = json_decode(html_entity_decode($json));
$sz = json_decode(json_encode($a), true);
// print_R($sz);die;
$url = $sz['vl']['vi']['0']['ul']['ui']['3']['url'];
$fn = $sz['vl']['vi']['0']['fn'];
$fvkey = $sz['vl']['vi']['0']['fvkey'];
$url = $url . $fn . '?vkey=' . $fvkey;
return $url;
}
$res['store_video'] = video($res['store_video']);
echo json_encode($res);
}
//登录用户信息
public function doPageLogin() {
global $_GPC, $_W;
$openid = $_GPC['openid'];
$res = pdo_get('wpdc_user', array('openid' => $openid, 'uniacid' => $_W['uniacid']));
if ($res) {
$user_id = $res['id'];
$data['openid'] = $_GPC['openid'];
if ($_GPC['img']) {
$data['img'] = $_GPC['img'];
$data['name'] = $_GPC['name'];
}
$res = pdo_update('wpdc_user', $data, array('id' => $user_id));
$user = pdo_get('wpdc_user', array('openid' => $openid, 'uniacid' => $_W['uniacid']));
echo json_encode($user);
} else {
$data['openid'] = $_GPC['openid'];
$data['img'] = $_GPC['img'];
$data['name'] = $_GPC['name'];
$data['uniacid'] = $_W['uniacid'];
$data['join_time'] = time();
$res2 = pdo_insert('wpdc_user', $data);
$user = pdo_get('wpdc_user', array('openid' => $openid, 'uniacid' => $_W['uniacid']));
echo json_encode($user);
}
}
//菜品列表
public function doPageDishes() {
global $_W, $_GPC;
// $_GPC['dishes_type']=1;
$type = pdo_getall('wpdc_type', array('uniacid' => $_W['uniacid'], 'store_id' => $_GPC['id'], 'is_open' => 1), array(), '', 'order_by ASC');
$list = pdo_getall('wpdc_dishes', array('uniacid' => $_W['uniacid'], 'is_shelves' => 1, 'dishes_type !=' => $_GPC['dishes_type'], 'store_id' => $_GPC['id']), array(), '', 'sorting ASC');
$data2 = array();
for ($i = 0;$i < count($type);$i++) {
$data = array();
for ($k = 0;$k < count($list);$k++) {
if ($type[$i]['id'] == $list[$k]['type_id']) {
$data[] = array('id' => $list[$k]['id'], 'name' => $list[$k]['name'], 'img' => $list[$k]['img'], 'num' => $list[$k]['num'], 'money' => $list[$k]['money'], 'one' => $list[$k]['one'], 'signature' => $list[$k]['signature'], 'dishes_type' => $list[$k]['dishes_type'], 'xs_num' => $list[$k]['xs_num'], 'sit_ys_num' => $list[$k]['sit_ys_num'], 'wm_money' => $list[$k]['wm_money'], 'details' => $list[$k]['details'], 'box_fee' => $list[$k]['box_fee']);
}
}
$data2[] = array('id' => $type[$i]['id'], 'type_name' => $type[$i]['type_name'], 'goods' => $data);
}
echo json_encode($data2);
}
//菜品规格
public function doPageDishesGg() {
global $_W, $_GPC;
$res = pdo_getall('wpdc_spec', array('goods_id' => $_GPC['dishes_id']));
echo json_encode($res);
}
//菜品详情
public function doPageDishesInfo() {
global $_GPC, $_W;
$res = pdo_get('wpdc_dishes', array('id' => $_GPC['id']));
$res2 = pdo_getall('wpdc_spec', array('goods_id' => $_GPC['id']));
$data['dishes'] = $res;
$data['spec'] = $res2;
echo json_encode($data);
}
//url(七牛)
public function doPageUrl() {
global $_GPC, $_W;
echo $_W['attachurl'];
}
public function doPageUrl2() {
global $_GPC, $_W;
echo $_W['siteroot'];
}
//下订单
public function doPageAddOrder() {
global $_W, $_GPC;
if ($_GPC['type'] == 1) { //外卖
$data['user_id'] = $_GPC['user_id'];
$data['order_num'] = date('YmdHis', time()) . rand(1111, 9999);
$data['state'] = 1;
$data['time'] = date("Y-m-d H:i:s", time());
$data['time2'] = time();
$data['money'] = $_GPC['money'];
$data['preferential'] = $_GPC['preferential'];
$data['tel'] = $_GPC['tel'];
$data['name'] = $_GPC['name'];
$data['note'] = $_GPC['note']; //备注
$data['address'] = $_GPC['address'];
$data['type'] = $_GPC['type'];
$data['area'] = $_GPC['area'];
$data['lat'] = $_GPC['lat'];