• 基于PHP的餐厅微信点餐支付小程序设计与实现(任务书+开题+lunwen+前后台源码)


    目 录
    摘 要 I
    Abstract II
    1绪论 1
    1.1研究背景及意义 1
    1.3研究内容 2
    2微信小程序开发相关技术介绍 3
    2.1微信小程序介绍 3
    2.1.1微信介绍 3
    2.1.2微信小程序简介 3
    2.1.3微信小程序基本功能 4
    2.2微信点餐小程序开发技术的介绍 5
    2.2.1 PHP 5
    2.2.2 JSON 6
    2.2.3 XML 6
    2.2.4 HTML 7
    3需求分析 8
    3.1需求综述 8
    3.1.1用户需求 8
    3.1.2 功能需求 9
    3.2 详细需求分析 9
    3.2.1 系统参与者 9
    3.2.2系统用例 10
    3.2.3具体用例分析 12
    3.3领域类图 17
    4概要设计 18
    4.1 技术选型 18
    4.2 功能模块划分 18
    4.2.1 用户功能模块 18
    4.2.2 系统管理员功能模块 20
    4.2.2 微信用户功能模块 20
    4.3 系统架构 21
    4.4 包图 22
    4.5 类图 23
    4.6 数据库设计与实现 25
    4.6.1 数据库E-R图 25
    4.6.2 数据库设计 27
    4.6.3 数据逻辑结构设计 28
    4.7 部署图 34
    5详细设计 35
    5.1微信点餐小程序整体流程 35
    5.2微信点餐小程序前端 36
    5.2.1首页 36
    5.2.2在线预定 37
    5.2.3外卖点餐 39
    5.2.4扫码点餐 42
    5.2.5个人中心 45
    5.3微信点餐小程序后端 46
    5.3.1桌台信息 48
    5.3.2我的预约 50
    5.3.3扫码点餐 51
    5.3.4查看外卖 52
    5.3.5设置 53
    6安装测试 54
    6.1 运行环境简介 54
    6.2 测试计划 54
    6.3 测试过程与结果 55
    6.3.1 注册功能测试 55
    6.3.2 登录功能测试 56
    6.3.3 查看菜品分类功能测试 57
    6.3.4 点餐下单功能测试 59
    总 结 61
    致 谢 62
    参考文献 63
    1.3研究内容
    本论文将从点餐小程序和微信小程序的基本介绍切入,通过对微信小程序的优势、点餐小程序的行业环境、微信对点餐小程序的影响几个方面进行分析,从而得到启示,进而分析得到我们所搭建的信息服务平台需要满足的一些需求。最终利用微信小程序提供的API接口以及 PHP 开发框架,开发出一个提供给企业和商家使用的信息服务系统平台。最终将通过本系统帮助企业和商家利用微信平台进行快速、低成本的营销推广活动。
    根据我们的研究内容,设计论文的内容结构如下:
    (1)绪论:主要介绍本篇论文研究的背景,意义和内容。
    (2)移动手机支付平台环境下点餐系统的现状分析:本章主要介绍了在移动手机支付平台环境下点餐系统的特点,对当前国内外移动手机支付平台环境下点餐系统的现状和微信给移动手机支付平台环境下点餐系统带来的影响进行分析。
    (3)微信小程序开发相关技术介绍:本部分主要是对微信小程序的各项功能和微信小程序开发所需要的各项技术做了一个基本的介绍。
    (4)基于微信点餐小程序功能模块设计:本章主要阐述基于微信点餐小程序需求的分析和功能模块的设计。
    (5)基于微信点餐小程序开发与实现:本章主要了介绍微信小程序的开发模式,以及微信小程序消息接口。并重点介绍了通过PHP开发框架实现基于微信点餐小程序各个核心模块的方法。
    (6)基于微信点餐小程序功能测试:在本部分主要是对系统测试的环境,测试流程和测试结果的叙述。
    (7)总结与展望:本部分主要是对毕业设计工作的总结和未来工作的展望。
    (8)最后就是论文的致谢部分和参考文献部分,主要是表达对论文撰写过程中对我提供了帮助的导师和同学朋友们的一个感谢,以及注明在本论文中参考和借鉴过的参考文献。
    3需求分析
    3.1需求综述
    本微信点餐小程序是一个基于时下最热的IM软件微信为平台的点餐系统,利用微信庞大的用户群体作为系统入口。结合当下移动互联网热潮以及O2O模式,利用该微信点餐小程序,能够更好地提高餐饮服务的标准以及信息化程度,为客户带来更好的点餐体验,结合微信本身的营销推广特征,更好得为餐厅推广以及节约成本提高盈收。
    本系统的设计与实现与时下流行的社交软件—微信进行交互的点餐系统,提高餐饮行业的信息化管理,节省人力、控制成本、提升工作效率的特点。为餐饮行业商家提供了高效的餐饮信息化服务,营销服务。
    3.1.1用户需求
    该系统的用户主要有2类,一类用户是餐厅商家,一类用户是去到餐厅使用微信扫码点餐的用户。
    针对餐厅商家这类用户类说,使用微信扫码点餐,他们能够减少员工的数量,只需少部分引导人员将顾客引导到座位上。座位上需要帖个2微码,让用户扫描关注商家微信号,就可以使用微信进行点餐。顾客将直接在手机上面进行菜单浏览以及下单,成功下单后服务员过来确认下单。这无疑给一些生意很火爆,但人手不足的餐厅带来很大的方便。而且使用传统的菜单,一旦某个菜的价格改变或在菜单改变,都需要重新印制大量的菜单,使用微信扫码点餐,只需要在后台进行修改就可以更换菜单。而且当顾客关注了商家的微信小程序后,以后商家可以再公众号与顾客进行互动,相当于免费的短信平台,一旦出了新品或者优惠活动,可以迅速推送给顾客。
    对于来到餐厅消费的用户来说,他们希望能够有一种体验好,不用排队等候,并且新颖的点餐方式。他们只需要去到餐厅座位,不需要等候服务员过来点餐,而只需要掏出手机扫一扫二维码,关注后进入点餐页面就可以方便地点餐。而且这种新颖的方式也会吸引到他们。下单后,服务员在后台看到订单打印出来后拿给顾客确认,即完成了点餐流程。后来还可以加入在线支付功能,用户甚至不需要带钱包,只要绑定了微信支付或者支付宝,直接下单即可完成支付。但顾客想预订位置,且想事先点好菜,以往只能是去到餐厅才能点餐,而是用微信扫码点餐,顾客可以随后随地得用微信扫码点餐下单预订位置。收到顾客预订后,服务员通过顾客留下的联系方式进行确认。以及事先准备好顾客的订单(提前在线支付)。
    3.1.2 功能需求
    该系统功能模块包括:
    1)微信小程序基本回复模块:该模块可以设置用户微信小程序文本回复,图文回复,关注回复,语音回复等;
    2)微信小程序微网站模块:该模块用于展示商家微信号官方微站给微信用户,可设置微站内容分类,微站首页滑动幻灯片,微站模板等;
    3)微信扫码点餐模块:该模块用于关注商家微信公众账号的用户在商家微信号上进行点餐操作,是该系统的核心功能。
    4)营销推广模块:该模块主要有刮刮卡、转盘、优惠劵等抽奖模块。这些模块通过让微信用户在关注商家微信号后,在微信端参与商家的活动,从而提高用户粘度以及体验性;
    5)会员卡模块:该模块主要用于让商家的客户领取微信会员卡,以及商家微信会员的消费积分设置,本文转载自http://www.biyezuopin.vip/onews.asp?id=11101以及会员权限,优惠折扣等。
    6)营业统计模块:该模块主要用于统计微信订餐营业的数据,以及微信用户在微信会员卡积分消费的情况。
    3.2 详细需求分析
    3.2.1 系统参与者
    a) 用户(餐厅商家)
    餐厅商家,商家通过注册登录使用该微信扫码点餐管理系统,可以实现添加微信小程序并绑定连通好该订餐系统,设置微信小程序消息回复功能,微信订餐功能以及开通营销推广模块(抽奖游戏)、微信会员卡功能。

    b)微信用户
    关注该商家微信小程序的用户,可以实现查看该商家公众号官网、了解最新信息、订餐、订位、参加活动抽奖以及领取会员卡、签到领取积分功能

    c) 订餐系统管理员
    该系统是一个多用户的微信扫码点餐管理系统。系统管理员具有审核用户注册,管理每一个用户(商家)是否具有开通微站、订餐、会员卡、抽奖模块的权限。

    <?php
    /**
     * 点餐小程序模块小程序接口定义
     *
     * @author cmszs
     * @url 
     */
    defined('IN_IA') or exit('Access Denied');
    require_once IA_ROOT . '/addons/deam_food/common/defines.php';
    require DM_ROOT. '/common/functions.php';
    class Deam_foodModuleWxapp extends WeModuleWxapp {
    	public function doPageSettings(){
    		global $_GPC, $_W;
    		$operation = trim($_GPC['op']);
    		$getfields = array();
    		if($operation!='all'){
    			$getfields = array("id",'uniacid','name','type','bg_color','fg_color','share_title','area_limit','tencent_map_apikey','single_storeid','store_blogo','copyright','wxapp_scan','wxapp_scan_name','wxapp_scan_color','wxapp_scan_intro','wxapp_scan_logo','wxapp_takeout','wxapp_takeout_name','wxapp_takeout_color','wxapp_takeout_intro','wxapp_takeout_logo','wxapp_getself','wxapp_getself_name','wxapp_getself_color','wxapp_getself_intro','wxapp_getself_logo','deliver_dada_status','bell_settings');
    		}
    		$settings = pdo_get("deamx_food_settings",array('uniacid'=>$_W['uniacid']),$getfields);
    		$settings['tencent_map_apikey'] = empty($settings['tencent_map_apikey']) ? "DOKBZ-4HHRX-JVR4Q-ZROIE-INAP3-7UFG3" : $settings['tencent_map_apikey'];
    		$settings['store_blogo'] = empty($settings['store_blogo']) ? '' : tomedia($settings['store_blogo']);
    		if(empty($settings['single_storeid'])){
    			$settings['single_storeid'] = pdo_fetchcolumn("select id from ".tablename('deamx_food_store')." where uniacid=:uniacid and status='1' order by id asc",array(':uniacid'=>$_W['uniacid']));
    		}
    		$settings['wxapp_scan_logo'] = !empty($settings['wxapp_scan_logo']) ? tomedia($settings['wxapp_scan_logo']) : "";
    		$settings['wxapp_takeout_logo'] = !empty($settings['wxapp_takeout_logo']) ? tomedia($settings['wxapp_takeout_logo']) : "";
    		$settings['wxapp_getself_logo'] = !empty($settings['wxapp_getself_logo']) ? tomedia($settings['wxapp_getself_logo']) : "";
    		if($operation == 'storeInfo'){
    			$storeid = intval($_GPC['store_id']);
    			$settings['storeinfo'] = pdo_get("deamx_food_store",array('uniacid'=>$_W['uniacid'],'id'=>$storeid));
    		}
    		if(empty($settings['bg_color'])){
    			$settings['bg_color'] = "#ff9c37";
    		}
    		if(empty($settings['fg_color'])){
    			$settings['fg_color'] = "#ffffff";
    		}
    		$settings['bell_settings'] = @json_decode($settings['bell_settings'],true);
    		$settings['call_waiter'] = intval($settings['bell_settings']['call_waiter']);
    		unset($settings['bell_settings']);
    		show_json(1,$settings);
    	}
    	public function doPageData(){
    		global $_GPC, $_W;
    		$uniacid = $_W['uniacid'];
    		$operation = trim($_GPC['op']);
    		if($operation == 'index'){
    			//adv
    			$adv = pdo_getall("deamx_food_adv",array('uniacid'=>$_W['uniacid'],'adv_isshow'=>"1"),array('id','adv_title','adv_img','adv_url'),'',"sortid desc,id desc");
    			foreach($adv as &$row){
    				$row['adv_img'] = tomedia($row['adv_img']);
    			}
    			if(!empty($adv[0]['adv_img'])){
    				$adv_img = trim($adv[0]['adv_img']);
    				$parsed = parse_url($adv_img);
    				if (isset($parsed['scheme']) && strtolower($parsed['scheme']) == 'https') {
    				  $adv_img = 'http://'.substr($adv_img,8);
    				}
    				$advStyle = getimagesize($adv_img);
    			}
    			unset($row);
    			show_json(1,array('adv'=>$adv,'adv_width'=>$advStyle[0],'adv_height'=>$advStyle[1]));
    		}elseif($operation == 'storelist'){
    			$store_type = trim($_GPC['store_type']);
    			$latitude = trim($_GPC['latitude']);
    			$longitude = trim($_GPC['longitude']);
    			$pagesize = 7;
    			$page = intval($_GPC['page']);
    			$settings = pdo_get("deamx_food_settings",array('uniacid'=>$_W['uniacid']));
    			$area_limit = intval($settings['area_limit']);
    			$limit = "";
    			if($area_limit>0){
    				$limit = " HAVING distance <=".$area_limit;
    			}
    			if($store_type == 'takeout'){
    				$condition .= " and is_takeout = 1";
    			}else{
    				$condition .= " and is_getself = 1";
    			}
    			$list = pdo_fetchall("select id,province,city,district,address,name,ROUND(6378.138*2*ASIN(SQRT(POW(SIN(( ".$latitude." * PI()/180-latitude*PI()/180)/2),2)+COS( ".$latitude." *PI()/180)*COS(latitude*PI()/180)*POW(SIN(( ".$longitude." * PI()/180-longitude*PI()/180)/2),2)))*1000) AS distance FROM ".tablename('deamx_food_store')." WHERE 1 ".$condition." and uniacid=:uniacid and status='1' ".$limit." ORDER BY distance ASC,id desc LIMIT " . ($page - 1) * $pagesize . ',' . $pagesize,array(':uniacid'=>$uniacid));
    			foreach ($list as &$row) {
    				$row['distance'] = @number_format($row['distance']/1000,2,".","");
    			}
    			$total = pdo_fetchcolumn("SELECT COUNT(*),ROUND(6378.138*2*ASIN(SQRT(POW(SIN(( ".$latitude." * PI()/180-latitude*PI()/180)/2),2)+COS( ".$latitude." *PI()/180)*COS(latitude*PI()/180)*POW(SIN(( ".$longitude." * PI()/180-longitude*PI()/180)/2),2)))*1000) AS distance FROM ".tablename('deamx_food_store')." WHERE uniacid=:uniacid and status='1' ".$condition.$limit." ORDER BY id DESC",array(':uniacid'=>$_W['uniacid']));
    			$result['pagesize'] = $pagesize;
    			$result['list'] = $list;
    			$result['total'] = $total;
    			show_json(1,$result);
    		}elseif($operation == "storeinfo"){
    			$storeid = intval($_GPC['storeid']);
    			$storeinfo = pdo_get("deamx_food_store",array('uniacid'=>$uniacid,'id'=>$storeid));
    			empty($storeinfo) && show_json(0,"该门店不存在!");
    			if(empty($storeinfo['status'])){
    				$storeinfo['statusText'] = "门店已关闭";
    				$storeinfo['storeStatus'] = "0";
    			}else{
    
    				if($storeinfo['starttime'] != "00:00" || $storeinfo['endtime'] != "00:00"){
    					
    					$starttime = strtotime($storeinfo['starttime']);
    					$endtime = strtotime($storeinfo['endtime']);
    
    					if($starttime > $endtime){
    						$endtime = strtotime("+1 day",$endtime);
    						$storeinfo['timeText'] = "次日";
    					}
    					if(TIMESTAMP >= $starttime && TIMESTAMP <= $endtime){
    						$storeinfo['statusText'] = "正常营业中";
    						$storeinfo['storeStatus'] = "1";
    					}else{
    						$storeinfo['statusText'] = "商家休息中...";
    						$storeinfo['close_reason'] = "营业时间 ".$storeinfo['starttime']."-".$storeinfo['timeText'].$storeinfo['endtime'];
    						$storeinfo['storeStatus'] = "2";
    					}
    				}
    			}
    			$deskid = intval($_GPC['deskid']);
    			if(!empty($deskid)){
    				$deskinfo = pdo_get("deamx_food_desknumber",array('uniacid'=>$_W['uniacid'],'store_id'=>$storeid,'id'=>$deskid),array('id','name'));
    				if(!empty($deskinfo['name'])){
    					$deskinfo['name'] ="当前位置:".$deskinfo['name'];
    				}
    			}
    			$classlist = pdo_getall("deamx_food_class",array('uniacid'=>$_W['uniacid'],'enabled'=>"1",'store_id'=>$storeid),array('id','classname'),'',"sortid desc,id desc");
    			foreach ($classlist as $key => $classItem) {
    				$goodslist[$key] = pdo_getall("deamx_food_goods",array('uniacid'=>$_W['uniacid'],'status'=>"1",'store_id'=>$storeid,'class_id'=>$classItem['id']),array('id','name','intro','price','img','hasoption','unit','is_pbox','pbox_price'),'',"displayorder desc,id desc");
    				foreach ($goodslist[$key] as &$row) {
    					$row['img'] = tomedia($row['img']);
    					$row['unit'] = empty($row['unit']) ? '份' : $row['unit'];
    				}
    				unset($row);
    			}
    			empty($goodslist) && $goodslist = array();
    			show_json(1,array('storeinfo'=>$storeinfo,'classlist'=>$classlist,'goodslist'=>$goodslist,'deskinfo'=>$deskinfo));
    
    		}elseif($operation == "goodsinfo"){
    			$goodsid = intval($_GPC['goodsid']);
    			$storeid = intval($_GPC['storeid']);
    			$goods = pdo_get("deamx_food_goods",array('uniacid'=>$_W['uniacid'],'status'=>"1",'store_id'=>$storeid,'id'=>$goodsid),array('id','name','intro','price','img','hasoption'));
    			if (!(empty($goods)) && $goods['hasoption']) {
    				$specs = pdo_fetchall('select * from ' . tablename('deamx_food_goods_spec') . ' where goodsid=:goodsid and uniacid=:uniacid order by displayorder asc', array(':goodsid' => $goodsid, ':uniacid' => $_W['uniacid']));
    				foreach ($specs as &$spec ){
    					$spec['items'] = pdo_fetchall('select * from ' . tablename('deamx_food_goods_spec_item') . ' where specid=:specid and `show`=1 order by displayorder asc', array(':specid' => $spec['id']));
    				}
    				unset($spec);
    				$options = pdo_fetchall('select * from ' . tablename('deamx_food_goods_option') . ' where goodsid=:goodsid and uniacid=:uniacid order by displayorder asc', array(':goodsid' => $goodsid, ':uniacid' => $_W['uniacid']));
    			}
    			show_json(1, array('goods' => $goods, 'specs' => $specs, 'options' => $options));
    		}elseif($operation == 'orderlist'){
    			$pagesize = 10;
    			$page = intval($_GPC['page']);
    			$member_id = intval($_GPC['member_id']);
    			$list = pdo_fetchall("SELECT o.id,o.ordersn,o.goods_list,o.count,o.price,o.pay_price,o.status,o.paytime,o.order_type,s.name as store_name FROM ".tablename('deamx_food_order')." o INNER JOIN ".tablename('deamx_food_store')." s ON o.store_id=s.id WHERE 1 ".$condition." and o.uniacid=:uniacid and o.status > '0' and o.openid=:openid ORDER BY id DESC LIMIT " . ($page - 1) * $pagesize . ',' . $pagesize,array(':uniacid'=>$uniacid,':openid'=>$_W['openid']));
    			foreach ($list as &$row) {
    				$row['paytime'] = date("Y-m-d H:i:s",$row['paytime']);
    				//状态和样式
    				if($row['order_type'] == '1'){
    					if($row['status'] == '0'){
    						$row['status_text'] = "待付款";
    					}elseif($row['status'] == '1'){
    						$row['status_text'] = "等待接单";
    					}elseif($row['status'] == '2'){
    						$row['status_text'] = "制作中";
    					}elseif($row['status'] == '3'){
    						$row['status_text'] = "已完成";
    					}elseif($row['status'] == '5'){
    						$row['status_text'] = "已关闭";
    					}
    				}elseif($row['order_type'] == '2'){
    					if($row['status'] == '0'){
    						$row['status_text'] = "待付款";
    					}elseif($row['status'] == '1'){
    						$row['status_text'] = "等待接单";
    					}elseif($row['status'] == '2'){
    						$row['status_text'] = "等待配送";
    					}elseif($row['status'] == '3'){
    						$row['status_text'] = "已完成";
    					}elseif($row['status'] == '4'){
    						$row['status_text'] = "正在配送";
    					}elseif($row['status'] == '5'){
    						$row['status_text'] = "已关闭";
    					}
    				}
    			}
    			$total = pdo_fetchcolumn("SELECT COUNT(*) FROM ".tablename('deamx_food_order')." o WHERE o.uniacid=:uniacid and o.status > '0' and o.openid=:openid ".$condition." ORDER BY id DESC",array(':uniacid'=>$_W['uniacid'],':openid'=>$_W['openid']));
    			$result['pagesize'] = $pagesize;
    			$result['list'] = $list;
    			$result['total'] = $total;
    			show_json(1,$result);
    		}elseif($operation == 'orderinfo'){
    			$order_id = intval($_GPC['order_id']);
    			$member_id = intval($_GPC['member_id']);
    			$orderInfo = pdo_get("deamx_food_order",array('uniacid'=>$_W['uniacid'],'id'=>$order_id,'status >'=>'0','openid'=>$_W['openid']),array('id','goods_list','count','price','pay_price','status','remark','paytime','order_number','createtime','ordersn','store_id','order_type','pbox_fee','send_fee','use_coupon','coupon_price','need_send_coupon','is_send_coupon','enoughdeduct','getfood_time'));
    			empty($orderInfo) && show_json(0,'订单不存在或状态异常!');
    			$orderInfo['ticket_remark'] = "请留意服务员叫号";
    			$orderInfo['paytime'] = date("Y-m-d H:i:s",$orderInfo['paytime']);
    			$orderInfo['store'] = pdo_get("deamx_food_store",array('uniacid'=>$_W['uniacid'],'id'=>$orderInfo['store_id']),array('id','name'));
    			$orderInfo['getfood_time'] = str_replace("取餐", "", $orderInfo['getfood_time']);
    			if($orderInfo['order_type'] == '2'){
    				if($orderInfo['status'] == '0'){
    					$orderInfo['takeout_status_text'] = STORE_STATUS0;
    				}elseif($orderInfo['status'] == '1'){
    					$orderInfo['takeout_status_text'] = STORE_STATUS1;
    				}elseif($orderInfo['status'] == '2'){
    					$orderInfo['takeout_status_text'] = STORE_STATUS2;
    				}elseif($orderInfo['status'] == '3'){
    					$orderInfo['takeout_status_text'] = STORE_STATUS3;
    				}elseif($orderInfo['status'] == '4'){
    					$orderInfo['takeout_status_text'] = STORE_STATUS4;
    				}elseif($orderInfo['status'] == '5'){
    					$orderInfo['takeout_status_text'] = STORE_STATUS5;
    				}
    				
    			}
    			//更新卡券显示
    			if($orderInfo['need_send_coupon'] > 0 && $orderInfo['is_send_coupon'] == 0){
    				pdo_update("deamx_food_order",array('is_send_coupon'=>'1'),array('id'=>$order_id));
    			}
    			show_json(1,$orderInfo);
    		}elseif($operation == 'address'){
    			$pagesize = 10;
    			$page = intval($_GPC['page']);
    			$member_id = intval($_GPC['member_id']);
    			$list = pdo_fetchall("SELECT * FROM ".tablename('deamx_food_address')." WHERE uniacid=:uniacid AND openid=:openid ORDER BY id DESC LIMIT " . ($page - 1) * $pagesize . ',' . $pagesize,array(':uniacid'=>$uniacid,':openid'=>$_W['openid']));
    			$total = pdo_fetchcolumn("SELECT * FROM ".tablename('deamx_food_address')." WHERE uniacid=:uniacid AND openid=:openid ORDER BY id DESC",array(':uniacid'=>$uniacid,':openid'=>$_W['openid']));
    			$result['pagesize'] = $pagesize;
    			$result['list'] = $list;
    			$result['total'] = $total;
    			show_json(1,$result);
    		}elseif($operation == 'addr_detail'){
    			$member_id = intval($_GPC['member_id']);
    			$addressid = intval($_GPC['addressid']);
    			$address = pdo_get("deamx_food_address",array('uniacid'=>$_W['uniacid'],'openid'=>$_W['openid'],'id'=>$addressid));
    			if (!empty($address)) {
    				show_json(1,$address);
    			}else{
    				show_json(0,'地址不存在,无法编辑!');
    			}
    		}elseif($operation == 'couponlist'){
    			$settings = pdo_get("deamx_food_settings",array('uniacid'=>$_W['uniacid']), array('template_status', 'template_id','sms_status','sms_type','sms_params','takeout_template_id','coupon_uniacid'));
    			$memberInfo = pdo_get("mc_mapping_fans",array('uniacid'=>$_W['uniacid'],'openid'=>$_W['openid']));
    			$pagesize = 10;
    			$page = intval($_GPC['page']);
    			$member_id = intval($_GPC['member_id']);
    			$status = intval($_GPC['status']);
    			switch ($status){
    				case '0':
    				$result['tips'] = "您还没有未使用的优惠券~";
    				$condition .= " AND r.status='1' AND r.endtime>=".TIMESTAMP;
    				break;
    				case '1':
    				$result['tips'] = "您还没有已使用的优惠券~";
    				$condition .= " AND r.status='3'";
    				break;
    				case '2':
    				$result['tips'] = "您还没有已过期的优惠券~";
    				$condition .= " AND r.status='1' AND r.endtime<".TIMESTAMP;
    				break;
    			}
    			$list = pdo_fetchall("SELECT r.*,c.title,c.least_cost,c.reduce_cost FROM ".tablename('deamx_food_coupon_record')." r LEFT JOIN ".tablename('deamx_food_coupon')." c ON r.card_id=c.card_id AND r.uniacid=c.coupon_uniacid WHERE r.uniacid=:uniacid AND r.unionid=:unionid ".$condition." ORDER BY endtime ASC,id ASC LIMIT " . ($page - 1) * $pagesize . ',' . $pagesize,array(':uniacid'=>$settings['coupon_uniacid'],':unionid'=>$memberInfo['unionid']));
    			foreach ($list as $key => &$row) {
    				$row['reduce_cost'] = $row['reduce_cost']/100;
    				$row['least_cost'] = $row['least_cost']/100;
    				$row['starttime'] = date("Y.m.d",$row['starttime']);
    				$row['endtime'] = date("Y.m.d",$row['endtime']);
    
    			}
    			$total = pdo_fetchcolumn("SELECT * FROM ".tablename('deamx_food_coupon_record')." r WHERE r.uniacid=:uniacid AND r.unionid=:unionid ".$condition." ORDER BY id DESC",array(':uniacid'=>$settings['coupon_uniacid'],':unionid'=>$memberInfo['unionid']));
    			$result['pagesize'] = $pagesize;
    			$result['list'] = $list;
    			$result['total'] = intval($total);
    			show_json(1,$result);
    		}elseif ($operation == 'first_addr') {
    			$member_id = intval($_GPC['member_id']);
    			$latitude = trim($_GPC['latitude']);
    			$longitude = trim($_GPC['longitude']);
    			$store_id = intval($_GPC['store_id']);
    			$storeinfo = pdo_get("deamx_food_store",array('uniacid'=>$uniacid,'id'=>$store_id),array('send_limit','longitude','latitude'));
    
    			if($storeinfo['send_limit']>0){
    				$limit = " HAVING distance <=".($storeinfo['send_limit'] * 1000);
    			}
    			$list = pdo_fetch("SELECT id,realname,telphone,address,address_road,number,ROUND(6378.138*2*ASIN(SQRT(POW(SIN(( ".$storeinfo['latitude']." * PI()/180-latitude*PI()/180)/2),2)+COS( ".$storeinfo['latitude']." *PI()/180)*COS(latitude*PI()/180)*POW(SIN(( ".$storeinfo['longitude']." * PI()/180-longitude*PI()/180)/2),2)))*1000) AS distance,ROUND(6378.138*2*ASIN(SQRT(POW(SIN(( ".$latitude." * PI()/180-latitude*PI()/180)/2),2)+COS( ".$latitude." *PI()/180)*COS(latitude*PI()/180)*POW(SIN(( ".$longitude." * PI()/180-longitude*PI()/180)/2),2)))*1000) AS mydistance,latitude,longitude FROM ".tablename('deamx_food_address')." WHERE 1 ".$condition." and uniacid=:uniacid and openid=:openid ".$limit." ORDER BY mydistance ASC, distance ASC,id desc",array(':uniacid'=>$uniacid,':openid'=>$_W['openid']));
    			if(!empty($list)){
    				show_json(1,$list);
    			}else{
    				show_json(0);
    			}
    		}elseif($operation == 'select_addr'){
    			$member_id = intval($_GPC['member_id']);
    			$store_id = intval($_GPC['store_id']);
    			$storeinfo = pdo_get("deamx_food_store",array('uniacid'=>$uniacid,'id'=>$store_id),array('send_limit','longitude','latitude'));
    			if($storeinfo['send_limit']>0){
    				$true_limit = " HAVING distance <=".($storeinfo['send_limit'] * 1000);
    				$false_limit = " HAVING distance >".($storeinfo['send_limit'] * 1000);
    			}
    			$truelist = pdo_fetchall("SELECT id,realname,telphone,address,address_road,number,ROUND(6378.138*2*ASIN(SQRT(POW(SIN(( ".$storeinfo['latitude']." * PI()/180-latitude*PI()/180)/2),2)+COS( ".$storeinfo['latitude']." *PI()/180)*COS(latitude*PI()/180)*POW(SIN(( ".$storeinfo['longitude']." * PI()/180-longitude*PI()/180)/2),2)))*1000) AS distance,latitude,longitude FROM ".tablename('deamx_food_address')." WHERE 1 ".$condition." and uniacid=:uniacid and openid=:openid ".$true_limit." ORDER BY id desc",array(':uniacid'=>$uniacid,':openid'=>$_W['openid']));
    			$falselist = pdo_fetchall("SELECT id,realname,telphone,address,address_road,number,ROUND(6378.138*2*ASIN(SQRT(POW(SIN(( ".$storeinfo['latitude']." * PI()/180-latitude*PI()/180)/2),2)+COS( ".$storeinfo['latitude']." *PI()/180)*COS(latitude*PI()/180)*POW(SIN(( ".$storeinfo['longitude']." * PI()/180-longitude*PI()/180)/2),2)))*1000) AS distance,latitude,longitude FROM ".tablename('deamx_food_address')." WHERE 1 ".$condition." and uniacid=:uniacid and openid=:openid ".$false_limit." ORDER BY id desc",array(':uniacid'=>$uniacid,':openid'=>$_W['openid']));
    			$total = pdo_fetchcolumn("SELECT * FROM ".tablename('deamx_food_address')." WHERE uniacid=:uniacid AND openid=:openid ORDER BY id DESC",array(':uniacid'=>$uniacid,':openid'=>$_W['openid']));
    			$result['truelist'] = $truelist;
    			$result['truecount'] = count($truelist);
    			$result['falsecount'] = count($falselist);
    			$result['falselist'] = $falselist;
    			$result['total'] = $total;
    			show_json(1,$result);
    		}elseif ($operation == 'check_addr') {
    			$member_id = intval($_GPC['member_id']);
    			$address_id = intval($_GPC['address_id']);
    			$address = pdo_get("deamx_food_address",array('uniacid'=>$uniacid,'openid'=>$_W['openid'],'id'=>$address_id));
    			if(empty($address)){
    				show_json(0);
    			}else{
    				show_json(1);
    			}
    		}elseif($operation == 'adv_info'){
    			$adv_id = intval($_GPC['id']);
    			$adv = pdo_get("deamx_food_adv",array('uniacid'=>$_W['uniacid'],'id'=>$adv_id),array('adv_title','adv_url'));
    			if(!empty($adv)){
    				show_json(1,$adv);
    			}
    			show_json(0);
    		}elseif($operation == 'auth_setting'){
    			$settings = pdo_get("deamx_food_settings",array('uniacid'=>$_W['uniacid']),array('auth_setting','name'));
    			$settings['auth_setting'] = iunserializer($settings['auth_setting']);
    			if(empty($settings['auth_setting']['name'])){
    				$settings['auth_setting']['name'] = $settings['name'];
    			}
    			if(empty($settings['auth_setting']['logo'])){
    				$settings['auth_setting']['logo'] = $_W['current_module']['logo'];
    			}else{
    				$settings['auth_setting']['logo'] = tomedia($settings['auth_setting']['logo']);
    			}
    			if(empty($settings['auth_setting']['intro'])){
    				$settings['auth_setting']['intro'] = "暂无简介";
    			}
    			show_json(1,$settings);
    		}elseif($operation == 'getfood_time'){
    			$store_id = intval($_GPC['store_id']);
    			$storeinfo = pdo_get("deamx_food_store",array('uniacid'=>$_W['uniacid'],'id'=>$store_id));
    			
    			if($storeinfo['starttime'] != "00:00" || $storeinfo['endtime'] != "00:00"){
    					
    				$starttime = strtotime($storeinfo['starttime']);
    				$endtime = strtotime($storeinfo['endtime']);
    
    				if($starttime > $endtime){
    					$endtime = strtotime("+1 day",$endtime);
    				}
    				if(TIMESTAMP+1200 <= $endtime){//20分钟后还在营业
    					$getstratTime = TIMESTAMP+1200;
    					for ($i=0; $i <= 300; $i++) { 
    						if((TIMESTAMP+1200+$i)%300<60){
    							$getstratTime = TIMESTAMP+1200+$i;
    							break;
    						}
    					}
    					$chooseTime = array();
    						$chooseTime[] = '立即取餐';
    					for ($j=$getstratTime; $j < $endtime;$j = $j+300) {
    						$chooseTime[] = date('H:i',$j);
    					}
    					show_json(1,array('getfood_time'=>$chooseTime));
    				}else{
    					show_json(1,array('getfood_time'=>array('立即取餐')));
    				}
    			}
    
    		}
    	}
    	public function doPageApi(){
    		global $_GPC, $_W;
    		$operation = trim($_GPC['op']);
    		load()->func('communication');
    		if($operation == 'getaddr'){
    			$settings = pdo_get("deamx_food_settings",array('uniacid'=>$_W['uniacid']));
    			$settings['tencent_map_apikey'] = empty($settings['tencent_map_apikey']) ? "DOKBZ-4HHRX-JVR4Q-ZROIE-INAP3-7UFG3" : $settings['tencent_map_apikey'];
    			$latitude = trim($_GPC['latitude']);
    			$longitude = trim($_GPC['longitude']);
    			$url = "http://apis.map.qq.com/ws/geocoder/v1/?location=".$latitude.",".$longitude."&key=".$settings['tencent_map_apikey'];
    			$result = ihttp_get($url);
    			$return = json_decode($result['content'],true);
    			$address = $return['result']['address'];
    			show_json(1,array('address'=>$address));
    		}
    	}
    	public function doPageDeampost(){
    		global $_GPC, $_W;
    		$openid = $_W['openid'];
    		$operation = trim($_GPC['op']);
    		if($operation == 'submitorder'){
    			if(empty($_W['openid'])){
    				show_json(0,'未获取到用户信息,无法提交订单!');
    			}
    			$address_info = htmlspecialchars_decode($_GPC['address']);
    			$_GPC['cart'] = str_replace("null,", "", $_GPC['cart']);
    			$cart = htmlspecialchars_decode($_GPC['cart']);
    			$count = intval($_GPC['cartCount']);
    			$totalPrice = @number_format($_GPC['cartPrice'],2,".","");
    			$coupon_price = @number_format($_GPC['coupon_price'],2,".","");
    			$enoughdeduct = @number_format($_GPC['enoughdeduct'],2,".","");
    			$member_id = intval($_GPC['member_id']);
    			$store_id = intval($_GPC['store_id']);
    			$desk_id = intval($_GPC['desk_id']);
    			$paySetting = uni_setting($_W['uniacid'], array('payment'));
    			$storeinfo = pdo_get("deamx_food_store",array('uniacid'=>$_W['uniacid'],'id'=>$store_id), array('name'));
    			//删除之前未支付订单
    			pdo_delete("deamx_food_order",array('uniacid'=>$_W['uniacid'],'openid'=>$_W['openid'],'status'=>'0'));
    			//创建订单
    			$orderno = "DM".sprintf("%03d",$_W['uniacid']).date("YmdHis").mt_rand(1000,9999);
    			$insertArr = array(
    				'uniacid'		=>	$_W['uniacid'],
    				'member_id'		=>	$member_id,
    				'openid'		=>	$_W['openid'],
    				'ordersn'		=>	$orderno,
    				'store_id'		=>	$store_id,
    				'desk_id'		=>	$desk_id,
    				'goods_list'	=>	$cart,
    				'count'			=>	$count,
    				'price'			=>	$totalPrice + $coupon_price + $enoughdeduct,
    				'enoughdeduct'	=>	@number_format($_GPC['enoughdeduct'],2,".",""),
    				'use_coupon'	=>	intval($_GPC['use_coupon']),
    				'coupon_price'	=>	$coupon_price,
    				'status'		=>	'0',
    				'remark'		=>	trim($_GPC['remark']),
    				'createtime'	=>	TIMESTAMP,
    				'is_prompt'		=>	'0',
    				'pbox_fee'		=>	@number_format($_GPC['pbox_fee'],2,".",""),
    				'order_type'	=>	trim($_GPC['order_type']) == 'takeout' ? '2' : '1',
    				'send_fee'		=>	@number_format($_GPC['send_fee'],2,".",""),
    				'address_info'	=>	$address_info,
    				'getfood_time'	=>	trim($_GPC['getfood_time']),
    			);
    			$result = pdo_insert("deamx_food_order",$insertArr);
    			$orderId = pdo_insertid();
    			if($orderId){
    				/*创建微信订单开始*/
    				$orderPrice = $totalPrice * 100;
    				$unifiedorder_url = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
    				$input['appid'] = $_W['account']['key'];
    				$input['mch_id'] = $paySetting['payment']['wechat']['mchid'];
    				$input['nonce_str'] = random(32);
    				$input['body'] = $storeinfo['name'].'-小程序点餐';
    				$input['out_trade_no'] = $orderno;
    				$input['total_fee'] = intval($orderPrice);
    				$input['spbill_create_ip'] = CLIENT_IP;
    				$input['attach'] = $_W['uniacid'];
    				$input['notify_url'] = MODULE_URL.'payment/wechat/notify.php';
    				$input['trade_type'] = 'JSAPI';
    				$input['openid'] = $_W['openid'];
    				$unSignParaStr = formatQueryParaMap($input,false);
    				$signStr = $unSignParaStr."&key=".$paySetting['payment']['wechat']['signkey'];
    				$input['sign'] = strtoupper(md5($signStr));
    				$orderinfo = simplexml_load_string(curl_post($unifiedorder_url,arrayToXml($input)),'SimpleXMLElement', LIBXML_NOCDATA);
    				$orderinfo = json_decode(json_encode($orderinfo),true);
    				if($orderinfo['result_code']=='FAIL'){
    					//
    					pdo_update("deamx_food_order",array('orderno'=>"DM".sprintf("%03d",$_W['uniacid']).date("YmdHis").mt_rand(1000,9999)),array('uniacid'=>$_W['uniacid'],'id'=>$orderId));
    					show_json(0,array('message'=>"订单状态异常!请重新发起支付!"));
    				}
    				//保存prepay_id用来下发模板消息
    				pdo_update("deamx_food_order",array('prepay_id'=>$orderinfo['prepay_id']),array('id'=>$orderId));
    				$wOpt['appId'] = $orderinfo['appid'];
    				$wOpt['timeStamp'] = TIMESTAMP;
    				$wOpt['nonceStr'] = random(32);
    				$wOpt['package'] = 'prepay_id='.$orderinfo['prepay_id'];
    				$wOpt['signType'] = 'MD5';
    				$paySignParaStr = formatQueryParaMap($wOpt,false);
    				$paysignStr = $paySignParaStr."&key=".$paySetting['payment']['wechat']['signkey'];
    				$wOpt['order_id'] = $orderId;
    				$wOpt['paySign'] = strtoupper(md5($paysignStr));
    				$wOpt['success'] = true;
    				$wOpt['weixin'] = true;
    				$wOpt['jie'] = 0;
    				$wOpt['order_id'] = $orderId;
    				show_json(1,$wOpt);
    			}else{
    				show_json(0,array('message'=>"创建订单失败,请重试!"));
    			}
    		}elseif($operation == 'submitaddr'){
    			if(empty($_W['openid'])){
    				show_json(0,'未获取到用户信息,无法提交信息');
    			}
    			$member_id = intval($_GPC['member_id']);
    			$addr_id = intval($_GPC['addressid']);
    			$realname = trim($_GPC['realname']);
    			$telphone = trim($_GPC['telphone']);
    			$address = trim($_GPC['address']);
    			$name = trim($_GPC['name']);
    			$latitude = trim($_GPC['latitude']);
    			$longitude = trim($_GPC['longitude']);
    			$addrnumber = trim($_GPC['addrnumber']);
    			$postArr = array(
    				'uniacid'		=>	$_W['uniacid'],
    				'member_id'		=>	$member_id,
    				'openid'		=>	$_W['openid'],
    				'realname'		=>	$realname,
    				'telphone'		=>	$telphone,
    				'address'		=>	$name,
    				'address_road'	=>	$address,
    				'latitude'		=>	$latitude,
    				'longitude'		=>	$longitude,
    				'number'		=>	$addrnumber,
    				'is_default'	=>	0,
    				'createtime'	=>	TIMESTAMP
    			);
    			if(empty($addr_id)){
    				$result = pdo_insert("deamx_food_address",$postArr);
    			}else{
    				unset($postArr['createtime']);
    				$result = pdo_update("deamx_food_address",$postArr,array('id'=>$addr_id));
    			}
    			if(empty($result)){
    				show_json(0,array('message'=>empty($addr_id) ? '添加失败' : '更新失败'));
    			}else{
    				show_json(1,array('message'=>empty($addr_id) ? '添加成功' : '更新成功'));
    			}
    
    		}elseif($operation == 'delteaddr'){
    			if(empty($_W['openid'])){
    				show_json(0,'未获取到用户信息,无法删除!');
    			}
    			$member_id = intval($_GPC['member_id']);
    			$addr_id = intval($_GPC['addressid']);
    			$result = pdo_delete("deamx_food_address",array('uniacid'=>$_W['uniacid'],'id'=>$addr_id,'openid'=>$_W['openid']));
    			if(empty($result)){
    				show_json(0,array('message'=>'删除失败'));
    			}else{
    				show_json(1,array('message'=>'删除成功'));
    			}
    		}elseif($operation == 'call_waiter') {
    			$desk_id = intval($_GPC['desk_id']);
    			$store_id = intval($_GPC['store_id']);
    			if(!empty($desk_id)){
    				$deskinfo = pdo_get("deamx_food_desknumber",array('uniacid'=>$_W['uniacid'],'id'=>$desk_id),array('id','name'));
    				//$deskinfo['name']
    				$settings = pdo_get("deamx_food_settings",array('uniacid'=>$_W['uniacid']),array('bell_settings'));
    				$settings['bell_settings'] = json_decode($settings['bell_settings'],true);
    				require_once DM_ROOT.'/vendor/aipSpeech/AipSpeech.php';
    				$APP_ID = $settings['bell_settings']['appid'];
    				$API_KEY = $settings['bell_settings']['apikey'];
    				$SECRET_KEY = $settings['bell_settings']['secretkey'];
    				if(empty($APP_ID) || empty($API_KEY) || empty($SECRET_KEY)){
    					show_json(0,"呼叫功能尚未配置,请到总后台进行配置!");
    				}
    				$client = new AipSpeech($APP_ID, $API_KEY, $SECRET_KEY);
    				$text = $settings['bell_settings']['getwaiter_front'].$deskinfo['name'].$settings['bell_settings']['getwaiter_behind'];
    				$result = $client->synthesis($text, 'zh', 1, array(
    				    'vol' => 15,
    				    'per' => 0,
    				    'spd' => 3,
    				));
    				if(!is_array($result)){
    					$audio_name = "CALL_".md5($text).".mp3";
    					$audio_dir = MODULE_ROOT."/data/audios/foodBell/{$_W['uniacid']}";
    					if (!file_exists($audio_dir)){
    					    @mkdir($audio_dir,0777,true);
    					}
    					$audio_status = @file_put_contents($audio_dir."/".$audio_name, $result);
    					if(!empty($audio_status)){
    						//show_json(1,"../addons/deam_food/data/audios/foodBell/{$_W['uniacid']}/{$audio_name}");
    						$insertArr = array(
    							'uniacid'		=>	$_W['uniacid'],
    							'from_openid'	=>	$_W['openid'],
    							'store_id'		=>	$store_id,
    							'type'			=>	'1',
    							'title'			=>	"桌号[{$deskinfo['name']}]呼叫服务员",
    							'content'		=>	"audios/foodBell/{$_W['uniacid']}/{$audio_name}",
    							'status'		=>	'0',
    							'createtime'	=>	TIMESTAMP
    						);
    						pdo_insert("deamx_food_notice",$insertArr);
    						show_json(1);
    					}else{
    						show_json(0,"文件保存失败,请检查目录".MODULE_ROOT."/data是否为可写(777)状态");
    					}
    				}else{
    					show_json(0,$result['err_msg']);
    				}
    
    			}else{
    				show_json(0,"扫描桌号二维码点餐才能呼叫服务员");
    			}
    			echo $_W['openid'];
    		}
    	}
    	public function doPageCoupon(){
    		global $_GPC, $_W;
    		$operation = trim($_GPC['op']);
    		load()->func('communication');
    		load()->classs('wxapp.account');
    		$accObj= WxappAccount::create($_W['uniacid']);
    		$access_token = $accObj->getAccessToken();
    		if($operation == 'test'){
    			$cardId = "pGYIaxPRyaTooH1AVegRtmloiqzM";
    			load()->classs('coupon');
    			$coupon_api = new coupon('3');
    			$cardTicket = $coupon_api->getCardTicket();
    			$time = TIMESTAMP;
    			$sign = array($cardId, $time);
    			$signature = $coupon_api->SignatureCard($sign);
    			//show_json(1,array('cardid'=>$cardId,'timestamp' => $time, 'signature' => $signature));
    		}elseif($operation == 'choose'){
    			$store_id = intval($_GPC['store_id']);
    			$price = intval($_GPC['price']*100);//分
    			$store_type = trim($_GPC['store_type']);
    			$couponList = pdo_fetchall("SELECT r.*,COUNT(r.id) AS coupon_count,c.title,c.least_cost,c.reduce_cost FROM ".tablename("deamx_food_coupon_record")." r LEFT JOIN ".tablename('deamx_food_coupon')." c ON r.card_id=c.card_id AND r.uniacid=c.coupon_uniacid WHERE c.least_cost<=:least_cost AND r.starttime<=:time AND r.endtime>=:time AND c.title!='' AND c.uniacid=:uniacid AND r.unionid=:unionid AND r.status=:status GROUP BY r.card_id ORDER BY r.id DESC",array(':uniacid'=>$_W['uniacid'],':unionid'=>$_W['fans']['unionid'],':least_cost'=>$price,':time'=>TIMESTAMP,':status'=>'1'));
    			foreach ($couponList as $key => &$row) {
    				$row['max_use'] = intval($price / $row['least_cost']) >= $row['coupon_count'] ? $row['coupon_count'] : intval($price / $row['least_cost']);
    				$row['total_reduce_cost'] = $row['max_use'] * $row['reduce_cost']/100;
    				$row['reduce_cost'] = $row['reduce_cost']/100;
    				$row['least_cost'] = $row['least_cost']/100;
    				$row['starttime'] = date("Y.m.d",$row['starttime']);
    				$row['endtime'] = date("Y.m.d",$row['endtime']);
    
    			}
    			show_json(count($couponList),array('list'=>$couponList));
    		}elseif($operation == 'upload_wechat'){
    			$settings = pdo_get("deamx_food_settings",array('uniacid'=>$_W['uniacid']), array('template_status', 'template_id','sms_status','sms_type','sms_params','takeout_template_id','coupon_uniacid'));
    			$couponid = intval($_GPC['couponid']);
    			$couponinfo = pdo_get("deamx_food_coupon_record",array('uniacid'=>$settings['coupon_uniacid'],'id'=>$couponid));
    			load()->classs('coupon');
    			$coupon_api = new coupon($settings['coupon_uniacid']);
    			$cardTicket = $coupon_api->getCardTicket();
    			$time = TIMESTAMP;
    			$sign = array($couponinfo['card_id'], $time);
    			$signature = $coupon_api->SignatureCard($sign);
    			show_json(1,array('cardid'=>$couponinfo['card_id'],'timestamp' => $time, 'signature' => $signature,'outer_str'=>$couponid));
    		}
    	}
    	public function doPageSandbox(){
    		global $_GPC, $_W;
    		$operation = trim($_GPC['op']);
    		if($operation == 'topay'){
    			$paySetting = uni_setting($_W['uniacid'], array('payment'));
    			$orderNo = 'DMT'.date("YmdHis").mt_rand(1000,9999);
    			$getsignkey_url = "https://api.mch.weixin.qq.com/sandboxnew/pay/getsignkey";
    			$input['mch_id'] = $paySetting['payment']['wechat']['mchid'];
    			$input['nonce_str'] = random(32);
    			$unSignParaStr = formatQueryParaMap($input,false);
    			$signStr = $unSignParaStr."&key=".$paySetting['payment']['wechat']['signkey'];
    			$input['sign'] = strtoupper(md5($signStr));
    			$signkeyinfo = simplexml_load_string(curl_post($getsignkey_url,arrayToXml($input)),'SimpleXMLElement', LIBXML_NOCDATA);
    			$signkeyinfo = json_decode(json_encode($signkeyinfo),true);
    
    			unset($input);
    			$unifiedorder_url = 'https://api.mch.weixin.qq.com/sandboxnew/pay/unifiedorder';
    			$input['appid'] = $_W['account']['key'];
    			$input['mch_id'] = $paySetting['payment']['wechat']['mchid'];
    			$input['nonce_str'] = random(32);
    			$input['body'] = '点沐-开通免充值代金券';
    			$input['out_trade_no'] = $orderNo;
    			$input['total_fee'] = '551';
    			$input['spbill_create_ip'] = CLIENT_IP;
    			$input['attach'] = $_W['uniacid'];
    			$input['notify_url'] = MODULE_URL.'payment/wechat/notify_sandbox.php';
    			$input['trade_type'] = 'JSAPI';
    			//$input['openid'] = $_W['openid'];
    			$input['openid'] = "";
    			$unSignParaStr = formatQueryParaMap($input,false);
    			$signStr = $unSignParaStr."&key=".$signkeyinfo['sandbox_signkey'];
    			$input['sign'] = strtoupper(md5($signStr));
    			$orderinfo = simplexml_load_string(curl_post($unifiedorder_url,arrayToXml($input)),'SimpleXMLElement', LIBXML_NOCDATA);
    			$orderinfo = json_decode(json_encode($orderinfo),true);
    			
    			if($orderinfo['result_code']=='FAIL'){
    				//
    				
    			}
    
    
    			$orderquery_url = "https://api.mch.weixin.qq.com/sandboxnew/orderquery";
    			$input = array();
    			$input['appid'] = $_W['account']['key'];
    			$input['mch_id'] = $paySetting['payment']['wechat']['mchid'];
    			$input['out_trade_no'] = $orderNo;
    			$input['nonce_str'] = random(32);
    			
    			$unSignParaStr = formatQueryParaMap($input,false);
    			$signStr = $unSignParaStr."&key=".$signkeyinfo['sandbox_signkey'];
    			$input['sign'] = strtoupper(md5($signStr));
    			
    			$orderQueryInfo = simplexml_load_string(curl_post($orderquery_url,arrayToXml($input)),'SimpleXMLElement', LIBXML_NOCDATA);//红包预下单返回信息
    			$orderQueryInfo = json_decode(json_encode($orderQueryInfo),true);
    
    
    			//1004
    			$orderNo = 'DMT'.date("YmdHis").mt_rand(1000,9999);
    			$getsignkey_url = "https://api.mch.weixin.qq.com/sandboxnew/pay/getsignkey";
    			$input['mch_id'] = $paySetting['payment']['wechat']['mchid'];
    			$input['nonce_str'] = random(32);
    			$unSignParaStr = formatQueryParaMap($input,false);
    			$signStr = $unSignParaStr."&key=".$paySetting['payment']['wechat']['signkey'];
    			$input['sign'] = strtoupper(md5($signStr));
    			$signkeyinfo = simplexml_load_string(curl_post($getsignkey_url,arrayToXml($input)),'SimpleXMLElement', LIBXML_NOCDATA);
    			$signkeyinfo = json_decode(json_encode($signkeyinfo),true);
    
    			unset($input);
    			$unifiedorder_url = 'https://api.mch.weixin.qq.com/sandboxnew/pay/unifiedorder';
    			$input['appid'] = $_W['account']['key'];
    			$input['mch_id'] = $paySetting['payment']['wechat']['mchid'];
    			$input['nonce_str'] = random(32);
    			$input['body'] = '点沐-开通免充值代金券';
    			$input['out_trade_no'] = $orderNo;
    			$input['total_fee'] = '552';
    			$input['spbill_create_ip'] = CLIENT_IP;
    			$input['attach'] = $_W['uniacid'];
    			$input['notify_url'] = MODULE_URL.'payment/wechat/notify_sandbox.php';
    			$input['trade_type'] = 'JSAPI';
    			//$input['openid'] = $_W['openid'];
    			$input['openid'] = "";
    			$unSignParaStr = formatQueryParaMap($input,false);
    			$signStr = $unSignParaStr."&key=".$signkeyinfo['sandbox_signkey'];
    			$input['sign'] = strtoupper(md5($signStr));
    			$orderinfo = simplexml_load_string(curl_post($unifiedorder_url,arrayToXml($input)),'SimpleXMLElement', LIBXML_NOCDATA);
    			$orderinfo = json_decode(json_encode($orderinfo),true);
    			
    			if($orderinfo['result_code']=='FAIL'){
    				//
    				
    			}
    
    
    			$orderquery_url = "https://api.mch.weixin.qq.com/sandboxnew/orderquery";
    			$input = array();
    			$input['appid'] = $_W['account']['key'];
    			$input['mch_id'] = $paySetting['payment']['wechat']['mchid'];
    			$input['out_trade_no'] = $orderNo;
    			$input['nonce_str'] = random(32);
    			
    			$unSignParaStr = formatQueryParaMap($input,false);
    			$signStr = $unSignParaStr."&key=".$signkeyinfo['sandbox_signkey'];
    			$input['sign'] = strtoupper(md5($signStr));
    			
    			$orderQueryInfo = simplexml_load_string(curl_post($orderquery_url,arrayToXml($input)),'SimpleXMLElement', LIBXML_NOCDATA);//红包预下单返回信息
    			$orderQueryInfo = json_decode(json_encode($orderQueryInfo),true);
    
    			$refund_url = "https://api.mch.weixin.qq.com/sandboxnew/secapi/pay/refund";
    
    			$setting = uni_setting_load('payment', $_W['uniacid']);
    			$pay_setting = $setting['payment'];
    			$cert =  authcode($pay_setting['wechat_refund']['cert'], 'DECODE');
    			$key =  authcode($pay_setting['wechat_refund']['key'], 'DECODE');
    			$cert_dir = MODULE_ROOT."/data/cert/{$_W['uniacid']}";
    			if (!file_exists($cert_dir)){
    			    @mkdir($cert_dir,0777,true);
    			}
    			$cert_name = md5(TIMESTAMP)."_cert.pem";
    			$key_name = md5(TIMESTAMP)."_key.pem";
    			$cert_status = @file_put_contents($cert_dir."/".$cert_name, $cert);
    			$key_status = @file_put_contents($cert_dir."/".$key_name, $key);
    			if(empty($cert_status) || empty($key_status) || empty($cert) || empty($key)){
    				show_json(0,array('message'=>"证书异常!请检查支付证书是否已上传!"));
    			}
    			//退款操作
    			$refundsn = "RFT".sprintf("%03d",$_W['uniacid']).date("YmdHis").mt_rand(1000,9999);
    			$refund_param = array(
    				'appid' => $_W['account']['key'],
    				'mch_id' => $paySetting['payment']['wechat']['mchid'],
    				'out_trade_no' => $orderNo,
    				'out_refund_no' => $refundsn,
    				'total_fee' => '552',
    				'refund_fee' => '552',
    				'nonce_str' => random(8),
    				'refund_desc' => $refund_reason
    			);
    			$unSignParaStr = formatQueryParaMap($refund_param,false);
    			$signStr = $unSignParaStr."&key=".$signkeyinfo['sandbox_signkey'];
    			$refund_param['sign'] = strtoupper(md5($signStr));
    			$refundinfo = simplexml_load_string(curl_post_ssl($refund_url,arrayToXml($refund_param),$cert_dir."/".$cert_name,$cert_dir."/".$key_name),'SimpleXMLElement', LIBXML_NOCDATA);
    			$refundinfo = json_decode(json_encode($refundinfo),true);
    			//print_r($refundinfo);
    
    			$refundquery_url = "https://api.mch.weixin.qq.com/sandboxnew/pay/refundquery";
    			$input = array();
    			$input['appid'] = $_W['account']['key'];
    			$input['mch_id'] = $paySetting['payment']['wechat']['mchid'];
    			$input['out_trade_no'] = $orderNo;
    			$input['nonce_str'] = random(32);
    			
    			$unSignParaStr = formatQueryParaMap($input,false);
    			$signStr = $unSignParaStr."&key=".$signkeyinfo['sandbox_signkey'];
    			$input['sign'] = strtoupper(md5($signStr));
    			
    			$refundqueryInfo = simplexml_load_string(curl_post($refundquery_url,arrayToXml($input)),'SimpleXMLElement', LIBXML_NOCDATA);//红包预下单返回信息
    			$refundqueryInfo = json_decode(json_encode($refundqueryInfo),true);
    			//print_r($refundqueryInfo);
    
    			$downloadbill_url = "https://api.mch.weixin.qq.com/sandboxnew/pay/downloadbill";
    			$input = array();
    			$input['appid'] = $_W['account']['key'];
    			$input['mch_id'] = $paySetting['payment']['wechat']['mchid'];
    			$input['nonce_str'] = random(32);
    			$input['bill_type'] = "SUCCESS";
    			$unSignParaStr = formatQueryParaMap($input,false);
    			$signStr = $unSignParaStr."&key=".$signkeyinfo['sandbox_signkey'];
    			$input['sign'] = strtoupper(md5($signStr));
    			
    			$downloadbillInfo = curl_post($downloadbill_url,arrayToXml($input));//红包预下单返回信息
    			//print_r($downloadbillInfo);
    			show_json(0,array('message'=>"开通成功!"));
    			// $wOpt['appId'] = $orderinfo['appid'];
    			// $wOpt['timeStamp'] = TIMESTAMP;
    			// $wOpt['nonceStr'] = random(32);
    			// $wOpt['package'] = 'prepay_id='.$orderinfo['prepay_id'];
    			// $wOpt['signType'] = 'MD5';
    			// $paySignParaStr = formatQueryParaMap($wOpt,false);
    			// $paysignStr = $paySignParaStr."&key=".$paySetting['payment']['wechat']['signkey'];
    			// $wOpt['order_id'] = $orderId;
    			// $wOpt['paySign'] = strtoupper(md5($paysignStr));
    			// $wOpt['success'] = true;
    			// $wOpt['weixin'] = true;
    			// $wOpt['jie'] = 0;
    			// $wOpt['order_id'] = $orderId;
    			// show_json(1,$wOpt);
    		}
    	}
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186
    • 187
    • 188
    • 189
    • 190
    • 191
    • 192
    • 193
    • 194
    • 195
    • 196
    • 197
    • 198
    • 199
    • 200
    • 201
    • 202
    • 203
    • 204
    • 205
    • 206
    • 207
    • 208
    • 209
    • 210
    • 211
    • 212
    • 213
    • 214
    • 215
    • 216
    • 217
    • 218
    • 219
    • 220
    • 221
    • 222
    • 223
    • 224
    • 225
    • 226
    • 227
    • 228
    • 229
    • 230
    • 231
    • 232
    • 233
    • 234
    • 235
    • 236
    • 237
    • 238
    • 239
    • 240
    • 241
    • 242
    • 243
    • 244
    • 245
    • 246
    • 247
    • 248
    • 249
    • 250
    • 251
    • 252
    • 253
    • 254
    • 255
    • 256
    • 257
    • 258
    • 259
    • 260
    • 261
    • 262
    • 263
    • 264
    • 265
    • 266
    • 267
    • 268
    • 269
    • 270
    • 271
    • 272
    • 273
    • 274
    • 275
    • 276
    • 277
    • 278
    • 279
    • 280
    • 281
    • 282
    • 283
    • 284
    • 285
    • 286
    • 287
    • 288
    • 289
    • 290
    • 291
    • 292
    • 293
    • 294
    • 295
    • 296
    • 297
    • 298
    • 299
    • 300
    • 301
    • 302
    • 303
    • 304
    • 305
    • 306
    • 307
    • 308
    • 309
    • 310
    • 311
    • 312
    • 313
    • 314
    • 315
    • 316
    • 317
    • 318
    • 319
    • 320
    • 321
    • 322
    • 323
    • 324
    • 325
    • 326
    • 327
    • 328
    • 329
    • 330
    • 331
    • 332
    • 333
    • 334
    • 335
    • 336
    • 337
    • 338
    • 339
    • 340
    • 341
    • 342
    • 343
    • 344
    • 345
    • 346
    • 347
    • 348
    • 349
    • 350
    • 351
    • 352
    • 353
    • 354
    • 355
    • 356
    • 357
    • 358
    • 359
    • 360
    • 361
    • 362
    • 363
    • 364
    • 365
    • 366
    • 367
    • 368
    • 369
    • 370
    • 371
    • 372
    • 373
    • 374
    • 375
    • 376
    • 377
    • 378
    • 379
    • 380
    • 381
    • 382
    • 383
    • 384
    • 385
    • 386
    • 387
    • 388
    • 389
    • 390
    • 391
    • 392
    • 393
    • 394
    • 395
    • 396
    • 397
    • 398
    • 399
    • 400
    • 401
    • 402
    • 403
    • 404
    • 405
    • 406
    • 407
    • 408
    • 409
    • 410
    • 411
    • 412
    • 413
    • 414
    • 415
    • 416
    • 417
    • 418
    • 419
    • 420
    • 421
    • 422
    • 423
    • 424
    • 425
    • 426
    • 427
    • 428
    • 429
    • 430
    • 431
    • 432
    • 433
    • 434
    • 435
    • 436
    • 437
    • 438
    • 439
    • 440
    • 441
    • 442
    • 443
    • 444
    • 445
    • 446
    • 447
    • 448
    • 449
    • 450
    • 451
    • 452
    • 453
    • 454
    • 455
    • 456
    • 457
    • 458
    • 459
    • 460
    • 461
    • 462
    • 463
    • 464
    • 465
    • 466
    • 467
    • 468
    • 469
    • 470
    • 471
    • 472
    • 473
    • 474
    • 475
    • 476
    • 477
    • 478
    • 479
    • 480
    • 481
    • 482
    • 483
    • 484
    • 485
    • 486
    • 487
    • 488
    • 489
    • 490
    • 491
    • 492
    • 493
    • 494
    • 495
    • 496
    • 497
    • 498
    • 499
    • 500
    • 501
    • 502
    • 503
    • 504
    • 505
    • 506
    • 507
    • 508
    • 509
    • 510
    • 511
    • 512
    • 513
    • 514
    • 515
    • 516
    • 517
    • 518
    • 519
    • 520
    • 521
    • 522
    • 523
    • 524
    • 525
    • 526
    • 527
    • 528
    • 529
    • 530
    • 531
    • 532
    • 533
    • 534
    • 535
    • 536
    • 537
    • 538
    • 539
    • 540
    • 541
    • 542
    • 543
    • 544
    • 545
    • 546
    • 547
    • 548
    • 549
    • 550
    • 551
    • 552
    • 553
    • 554
    • 555
    • 556
    • 557
    • 558
    • 559
    • 560
    • 561
    • 562
    • 563
    • 564
    • 565
    • 566
    • 567
    • 568
    • 569
    • 570
    • 571
    • 572
    • 573
    • 574
    • 575
    • 576
    • 577
    • 578
    • 579
    • 580
    • 581
    • 582
    • 583
    • 584
    • 585
    • 586
    • 587
    • 588
    • 589
    • 590
    • 591
    • 592
    • 593
    • 594
    • 595
    • 596
    • 597
    • 598
    • 599
    • 600
    • 601
    • 602
    • 603
    • 604
    • 605
    • 606
    • 607
    • 608
    • 609
    • 610
    • 611
    • 612
    • 613
    • 614
    • 615
    • 616
    • 617
    • 618
    • 619
    • 620
    • 621
    • 622
    • 623
    • 624
    • 625
    • 626
    • 627
    • 628
    • 629
    • 630
    • 631
    • 632
    • 633
    • 634
    • 635
    • 636
    • 637
    • 638
    • 639
    • 640
    • 641
    • 642
    • 643
    • 644
    • 645
    • 646
    • 647
    • 648
    • 649
    • 650
    • 651
    • 652
    • 653
    • 654
    • 655
    • 656
    • 657
    • 658
    • 659
    • 660
    • 661
    • 662
    • 663
    • 664
    • 665
    • 666
    • 667
    • 668
    • 669
    • 670
    • 671
    • 672
    • 673
    • 674
    • 675
    • 676
    • 677
    • 678
    • 679
    • 680
    • 681
    • 682
    • 683
    • 684
    • 685
    • 686
    • 687
    • 688
    • 689
    • 690
    • 691
    • 692
    • 693
    • 694
    • 695
    • 696
    • 697
    • 698
    • 699
    • 700
    • 701
    • 702
    • 703
    • 704
    • 705
    • 706
    • 707
    • 708
    • 709
    • 710
    • 711
    • 712
    • 713
    • 714
    • 715
    • 716
    • 717
    • 718
    • 719
    • 720
    • 721
    • 722
    • 723
    • 724
    • 725
    • 726
    • 727
    • 728
    • 729
    • 730
    • 731
    • 732
    • 733
    • 734
    • 735
    • 736
    • 737
    • 738
    • 739
    • 740
    • 741
    • 742
    • 743
    • 744
    • 745
    • 746
    • 747
    • 748
    • 749
    • 750
    • 751
    • 752
    • 753
    • 754
    • 755
    • 756
    • 757
    • 758
    • 759
    • 760
    • 761
    • 762
    • 763
    • 764
    • 765
    • 766
    • 767
    • 768
    • 769
    • 770
    • 771
    • 772
    • 773
    • 774
    • 775
    • 776
    • 777
    • 778
    • 779
    • 780
    • 781
    • 782
    • 783
    • 784
    • 785
    • 786
    • 787
    • 788
    • 789
    • 790
    • 791
    • 792
    • 793
    • 794
    • 795
    • 796
    • 797
    • 798
    • 799
    • 800
    • 801
    • 802
    • 803
    • 804
    • 805
    • 806
    • 807
    • 808
    • 809
    • 810
    • 811
    • 812
    • 813
    • 814
    • 815
    • 816
    • 817

    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述

  • 相关阅读:
    [MAUI程序设计] 用Handler实现自定义跨平台控件
    KCP协议:从TCP到UDP家族QUIC/KCP/ENET
    尚品汇项目2
    初识C++(二)
    leetcode top100(10) 和为 K 的子数组
    YOLOv5 onnx \tensorrt 推理
    Part3_理解MATSIM_第50章 运动波的排队表示
    基于SpringBoot的篮球竞赛预约平台
    850. 矩形面积 II
    Python3 - Docker部署Libre Office Online在线文件转换
  • 原文地址:https://blog.csdn.net/newlw/article/details/127767903