wxapp.php 78 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390
  1. <?php
  2. /**
  3. * 志汇酒店营销版模块小程序接口定义
  4. *
  5. * @author 武汉志汇科技
  6. * @url http://bbs.we7.cc/
  7. */
  8. defined('IN_IA') or exit('Access Denied');
  9. require_once 'init.php';
  10. class Zh_jdgjbModuleWxapp extends WeModuleWxapp {
  11. public function __construct()
  12. {
  13. checkOrder();
  14. }
  15. public function doPageTest(){
  16. global $_GPC, $_W;
  17. $errno = 0;
  18. $message = '返回消息';
  19. $data = array();
  20. return $this->result($errno, $message, $data);
  21. }
  22. //登入
  23. public function doPageLogin(){
  24. global $_GPC, $_W;
  25. $openid=$_GPC['openid'];
  26. $res=pdo_get('zh_jdgjb_user',array('openid'=>$openid,'uniacid'=>$_W['uniacid']));
  27. if($res){
  28. $user_id=$res['id'];
  29. $data['openid']=$_GPC['openid'];
  30. $data['img']=$_GPC['img'];
  31. $data['name']=$_GPC['name'];
  32. $data['uniacid']=$_W['uniacid'];
  33. $res = pdo_update('zh_jdgjb_user', $data, array('id' =>$user_id));
  34. $sql="select a.*,b.name as level_name,b.discount from " . tablename("zh_jdgjb_user") ." a left join".tablename('zh_jdgjb_level')." b on a.level_id=b.id WHERE a.openid=:openid and a.uniacid=:uniacid";
  35. $user=pdo_fetch($sql,array(':openid'=>$openid ,'uniacid'=>$_W['uniacid']));
  36. if(empty($user['level_name'])){
  37. $user['level_name']='初始会员';
  38. }
  39. //$user=pdo_get('zhjd_user',array('openid'=>$openid));
  40. echo json_encode($user);
  41. }else{
  42. $data['openid']=$_GPC['openid'];
  43. $data['img']=$_GPC['img'];
  44. $data['name']=$_GPC['name'];
  45. $data['uniacid']=$_W['uniacid'];
  46. $data['join_time']=time();
  47. $data['type']=1;
  48. $res2=pdo_insert('zh_jdgjb_user',$data);
  49. $sql="select a.*,b.name as level_name,b.discount from " . tablename("zh_jdgjb_user") ." a left join".tablename('zh_jdgjb_level')." b on a.level_id=b.id WHERE a.openid=:openid and a.uniacid=:uniacid";
  50. $user=pdo_fetch($sql,array(':openid'=>$openid,'uniacid'=>$_W['uniacid'] ));
  51. if(empty($user['level_name'])){
  52. $user['level_name']='初始会员';;
  53. }
  54. echo json_encode($user);
  55. }
  56. }
  57. //图片路径(七牛)
  58. public function doPageAttachurl(){
  59. global $_W;
  60. echo $_W['attachurl'];
  61. }
  62. //获取url
  63. public function doPageUrl(){
  64. global $_W;
  65. echo $_W['siteroot'];
  66. }
  67. //获取openid
  68. public function doPageOpenid(){
  69. global $_W, $_GPC;
  70. $res=pdo_get('zh_jdgjb_system',array('uniacid'=>$_W['uniacid']));
  71. $code=$_GPC['code'];
  72. $appid=$res['appid'];
  73. $secret=$res['appsecret'];
  74. $url="https://api.weixin.qq.com/sns/jscode2session?appid=".$appid."&secret=".$secret."&js_code=".$code."&grant_type=authorization_code";
  75. function httpRequest($url,$data = null){
  76. $curl = curl_init();
  77. curl_setopt($curl, CURLOPT_URL, $url);
  78. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
  79. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
  80. if (!empty($data)){
  81. curl_setopt($curl, CURLOPT_POST, 1);
  82. curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
  83. }
  84. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  85. //执行
  86. $output = curl_exec($curl);
  87. curl_close($curl);
  88. return $output;
  89. }
  90. $res=httpRequest($url);
  91. print_r($res);
  92. }
  93. //系统设置
  94. public function doPageGetSystem(){
  95. global $_W, $_GPC;
  96. $res=pdo_get('zh_jdgjb_system',array('uniacid'=>$_W['uniacid']));
  97. echo json_encode($res);
  98. }
  99. //获取轮播图
  100. public function doPageGetAd(){
  101. global $_GPC, $_W;
  102. // $res=pdo_getall('zh_gjhdbm_ad',array('uniacid'=>$_W['uniacid'],'status'=>1,'type'=>$_GPC['type']));
  103. $where=" where uniacid=:uniacid and status=1 and type=:type ";
  104. $data[':uniacid']=$_W['uniacid'];
  105. $data[':type']=$_GPC['type'];
  106. $sql="select * from " . tablename("zh_jdgjb_ad") .$where." order by id desc ";
  107. $list=pdo_fetchall($sql,$data);
  108. echo json_encode($list);
  109. }
  110. //导航列表
  111. public function doPageGetNav(){
  112. global $_GPC, $_W;
  113. $res=pdo_getall('zh_jdgjb_nav',array('uniacid'=>$_W['uniacid'],'status'=>1),array(),'','orderby asc');
  114. echo json_encode($res);
  115. }
  116. //酒店入住
  117. public function doPageSaveHotelApply(){
  118. global $_GPC, $_W;
  119. $data['name']=$_GPC['name'];
  120. $data['star']=$_GPC['star'];
  121. $data['address']=$_GPC['address'];
  122. $data['coordinates']=$_GPC['coordinates'];
  123. $data['link_name']=$_GPC['link_name'];
  124. $data['link_tel']=$_GPC['link_tel'];
  125. $data['tel']=$_GPC['tel'];
  126. $data['user_id']=$_GPC['user_id'];
  127. $data['owner']=2;
  128. $data['state']=1;
  129. $data['sfz_img1']=$_GPC['sfz_img1'];
  130. $data['sfz_img2']=$_GPC['sfz_img2'];
  131. $data['yy_img']=$_GPC['yy_img'];
  132. $data['other']=$_GPC['other'];
  133. $data['sq_time']=time();
  134. $data['uniacid']=$_W['uniacid'];
  135. $rst=pdo_get('zh_jdgjb_seller',array('user_id'=>$_GPC['user_id'],'uniacid'=>$_W['uniacid']));
  136. if($rst){
  137. $res = pdo_update('zh_jdgjb_seller', $data, array('user_id' => $_GPC['user_id']));
  138. }else{
  139. $res=pdo_insert('zh_jdgjb_seller',$data);
  140. }
  141. if($res){
  142. echo '1';
  143. }else{
  144. echo '2';
  145. }
  146. }
  147. //查看是否入住
  148. public function doPageCheckRz(){
  149. global $_W, $_GPC;
  150. $res=pdo_get('zh_jdgjb_seller',array('user_id'=>$_GPC['user_id'],'uniacid'=>$_W['uniacid']),'state');
  151. echo json_encode($res);
  152. }
  153. //短信验证码
  154. public function doPageSms2(){
  155. global $_W, $_GPC;
  156. $res=pdo_get('zh_jdgjb_system',array('uniacid'=>$_W['uniacid']));
  157. if($res['item']==2){
  158. if($_GPC['type']==1){
  159. $tpl_id=$res['aliyun_id'];
  160. }else{
  161. $tpl_id=$res['aliyun_id2'];
  162. }
  163. var_dump($this->doPageAliyun($_GPC['tel'],$_GPC['code'],$tpl_id)) ;
  164. }else{
  165. if($_GPC['type']==1){
  166. $tpl_id=$res['tpl_id'];
  167. }else{
  168. $tpl_id=$res['tpl_id2'];
  169. }
  170. $tel=$_GPC['tel'];
  171. $code=$_GPC['code'];
  172. $key=$res['appkey'];
  173. $url = "http://v.juhe.cn/sms/send?mobile=".$tel."&tpl_id=".$tpl_id."&tpl_value=%23code%23%3D".$code."&key=".$key;
  174. $data=file_get_contents($url);
  175. print_r($data);
  176. }
  177. }
  178. //上传图片
  179. public function doPageUpload(){
  180. global $_W, $_GPC;
  181. $uptypes=array(
  182. 'image/jpg',
  183. 'image/jpeg',
  184. 'image/png',
  185. 'image/pjpeg',
  186. 'image/gif',
  187. 'image/bmp',
  188. 'image/x-png'
  189. );
  190. $max_file_size=2000000; //上传文件大小限制, 单位BYTE
  191. $destination_folder="../attachment/zh_gjjd/".date(Y)."/".date(m)."/".date(d)."/"; //上传文件路径
  192. if (!is_uploaded_file($_FILES["upfile"]['tmp_name']))
  193. //是否存在文件
  194. {
  195. echo "图片不存在!";
  196. exit;
  197. }
  198. $file = $_FILES["upfile"];
  199. if($max_file_size < $file["size"])
  200. //检查文件大小
  201. {
  202. echo "文件太大!";
  203. exit;
  204. }
  205. // if(!in_array($file["type"], $uptypes))
  206. // //检查文件类型
  207. // {
  208. // echo "文件类型不符!".$file["type"];
  209. // exit;
  210. // }
  211. if (!file_exists($destination_folder)){
  212. mkdir ($destination_folder,0777,true);
  213. }
  214. $filename=$file["tmp_name"];
  215. $image_size = getimagesize($filename);
  216. $pinfo=pathinfo($file["name"]);
  217. $ftype=$pinfo['extension'];
  218. $destination = $destination_folder.str_shuffle(time().rand(111111,999999)).".".$ftype;
  219. if (file_exists($destination) && $overwrite != true)
  220. {
  221. echo "同名文件已经存在了";
  222. exit;
  223. }
  224. if(!move_uploaded_file ($filename, $destination))
  225. {
  226. echo "移动文件出错";
  227. exit;
  228. }
  229. $pinfo=pathinfo($destination);
  230. $fname="zh_gjjd/".date(Y)."/".date(m)."/".date(d)."/".$pinfo['basename'];
  231. // var_dump($pinfo);die;
  232. echo $fname;
  233. @require_once (IA_ROOT . '/framework/function/file.func.php');
  234. @$filename=$fname;
  235. @file_remote_upload($filename);
  236. }
  237. //解密
  238. public function doPageJiemi(){
  239. global $_W, $_GPC;
  240. $res=pdo_get('zh_jdgjb_system',array('uniacid'=>$_W['uniacid']));
  241. include_once IA_ROOT . "/addons/zh_jdgjb/wxBizDataCrypt.php";
  242. $appid = $res['appid'];
  243. $sessionKey = $_GPC['sessionKey'];
  244. $encryptedData=$_GPC['data'];
  245. $iv = $_GPC['iv'];
  246. $pc = new WXBizDataCrypt($appid, $sessionKey);
  247. $errCode = $pc->decryptData($encryptedData, $iv, $data );
  248. if ($errCode == 0) {
  249. //echo json_encode($data);
  250. print($data . "\n");
  251. } else {
  252. print($errCode . "\n");
  253. }
  254. }
  255. //酒店列表
  256. public function doPageJdList(){
  257. global $_GPC, $_W;
  258. $pageindex = max(1, intval($_GPC['page']));
  259. $pagesize=$_GPC['pagesize']?:10;
  260. $data[':uniacid']=$_W['uniacid'];
  261. $item = pdo_fetch("SELECT openCity FROM ". tablename('zh_jdgjb_system') . " WHERE uniacid = :weid", array('weid' => $_W['uniacid']));
  262. $where=" where uniacid=:uniacid and state=2";
  263. if($_GPC['keywords']){
  264. $where.=" and name LIKE concat('%', :name,'%') ";
  265. $data[':name']=$_GPC['keywords'];
  266. }
  267. if($_GPC['cityName']&&$item['openCity']==1){
  268. $where.=" and cityName LIKE concat('%', :cityName,'%') ";
  269. $data[':cityName']=$_GPC['cityName'];
  270. }
  271. $sql="select * from " . tablename("zh_jdgjb_seller") .$where." order by scort asc ";
  272. $select_sql=$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
  273. $list=pdo_fetchall($select_sql,$data);
  274. echo json_encode($list);
  275. }
  276. //酒店详情
  277. public function doPagePjDetails(){
  278. global $_GPC, $_W;
  279. $res=pdo_get("zh_jdgjb_seller",array('id'=>$_GPC['seller_id']));
  280. pdo_update('zh_jdgjb_seller',array('ll_num +='=>1),array('id'=>$_GPC['seller_id']));
  281. echo json_encode($res);
  282. }
  283. //房型列表
  284. public function doPageRoomList(){
  285. global $_GPC, $_W;
  286. $pageindex = max(1, intval($_GPC['page']));
  287. $pagesize=50;
  288. $data[':uniacid']=$_W['uniacid'];
  289. $data[':seller_id']=$_GPC['seller_id'];
  290. $where=" where uniacid=:uniacid and seller_id=:seller_id ";
  291. $sql="select * from " . tablename("zh_jdgjb_room") .$where." order by sort asc ";
  292. $select_sql=$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
  293. $list=pdo_fetchall($select_sql,$data);
  294. echo json_encode($list);
  295. }
  296. //房间详情
  297. public function doPageRoomDetails(){
  298. global $_GPC, $_W;
  299. $res=pdo_get("zh_jdgjb_room",array('id'=>$_GPC['room_id']));
  300. echo json_encode($res);
  301. }
  302. //平台(所有)优惠券
  303. public function doPageGetSponsorCoupon(){
  304. global $_GPC, $_W;
  305. $pageindex = max(1, intval($_GPC['page']));
  306. $pagesize=10;
  307. $time=date("Y-m-d",time());
  308. $time=strtotime($time);
  309. $sql=" select * from".tablename('zh_jdgjb_coupons')." where uniacid=:uniacid and lq_num < number and unix_timestamp(end_time) >= $time
  310. and id not in (select coupons_id from".tablename('zh_jdgjb_usercoupons')." where user_id={$_GPC['user_id']} and uniacid={$_W['uniacid']}) order by id desc";
  311. //echo $sql;die;
  312. $select_sql=$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
  313. $list=pdo_fetchall($select_sql,array(':uniacid'=>$_W['uniacid']));
  314. echo json_encode($list);
  315. }
  316. // //商家优惠券
  317. // public function doPagegetSellerCoupon(){
  318. // global $_GPC, $_W;
  319. // $time=date("Y-m-d",time());
  320. // $time=strtotime($time);
  321. // $sql=" select * from".tablename('zh_jdgjb_coupons')." where uniacid=:uniacid and seller_id=:seller_id and lq_num < number and unix_timestamp(end_time) >= $time order by id desc";
  322. // $list=pdo_fetchall($sql,array(':uniacid'=>$_W['uniacid'],':seller_id'=>$_GPC['uniacid']));
  323. // echo json_encode($list);
  324. // }
  325. //优惠券详情
  326. public function doPageCouponDetails(){
  327. global $_GPC, $_W;
  328. $res=pdo_get("zh_jdgjb_coupons",array('id'=>$_GPC['coupon_id']));
  329. echo json_encode($res);
  330. }
  331. //领取优惠券
  332. public function doPageReceiveCoupons(){
  333. global $_GPC, $_W;
  334. $rst=pdo_get('zh_jdgjb_usercoupons',array('user_id'=>$_GPC['user_id'],'coupons_id'=>$_GPC['coupons_id'],'uniacid'=>$_W['uniacid']));
  335. if(!$rst){
  336. $data['user_id']=$_GPC['user_id'];
  337. $data['coupons_id']=$_GPC['coupons_id'];
  338. $data['state']=1;
  339. $data['time']=time();
  340. $data['uniacid']=$_W['uniacid'];
  341. $res=pdo_insert('zh_jdgjb_usercoupons',$data);
  342. if($res){
  343. //修改券的数量
  344. pdo_update('zh_jdgjb_coupons',array('lq_num +='=>1),array('id'=>$_GPC['coupons_id']));
  345. echo '1';
  346. }else{
  347. echo '2';
  348. }
  349. }else{
  350. echo '重复领取';
  351. }
  352. }
  353. public function doPageGetLevelInfo()
  354. {
  355. global $_W, $_GPC;
  356. $level = pdo_get('zh_jdgjb_level',array('uniacid' => $_W['uniacid']));
  357. echo json_encode($level);
  358. }
  359. //生成订单
  360. public function doPageAddVipOrder(){
  361. global $_W, $_GPC;
  362. $data['user_id']=$_GPC['user_id'];
  363. $data['level_id']=$_GPC['level_id'];
  364. $level = pdo_get('zh_jdgjb_level',array('id' => $_GPC['level_id']));
  365. if (!$level) {
  366. echo json_encode(['code'=> -1, 'msg' => '该等级不存在']);
  367. exit;
  368. }
  369. $user = pdo_get('zh_jdgjb_user',array('id' => $_GPC['user_id']));
  370. if ($user['type'] == 2) {
  371. echo json_encode(['code'=> -1, 'msg' => '您已是会员']);
  372. exit;
  373. }
  374. $data['order_no']='V' . date('YmdHis').rand(0,9999);
  375. $data['status']=1;
  376. $data['time']=time();
  377. $data['price']=$level['value'];
  378. $data['tel']=$_GPC['tel'];
  379. $data['name']=$_GPC['name'];
  380. $data['total_cost']=$level['value'];
  381. $data['uniacid']=$_W['uniacid'];
  382. $data['out_trade_no']='V' . time().rand(1000,9999).$_GPC['user_id'];
  383. // $data['out_trade_no']=$_GPC['out_trade_no'];//预定订单
  384. $data['from_id']=$_GPC['from_id'];
  385. $res=pdo_insert('zh_jdgjb_vip_order',$data);
  386. $order_id=pdo_insertid();
  387. echo json_encode(['code'=> 1, 'data' => $order_id]);
  388. }
  389. public function doPageAddRePayOrder(){
  390. global $_W, $_GPC;
  391. $data['user_id']=$_GPC['user_id'];
  392. $data['order_id']=$_GPC['order_id'];
  393. $level = pdo_get('zh_jdgjb_order',array('id' => $_GPC['order_id']));
  394. if (!$level) {
  395. echo json_encode(['code'=> -1, 'msg' => '该订单不存在']);
  396. exit;
  397. }
  398. if ($level['is_re_pay'] == 1) {
  399. echo json_encode(['code'=> -1, 'msg' => '该订单已支付']);
  400. exit;
  401. }
  402. $data['order_no']='R' . date('YmdHis').rand(0,9999);
  403. $data['status']=1;
  404. $data['time']=time();
  405. $data['price']=$level['value'];
  406. $data['tel']=$_GPC['tel'];
  407. $data['name']=$_GPC['name'];
  408. $data['total_cost']=$level['value'];
  409. $data['uniacid']=$_W['uniacid'];
  410. $data['out_trade_no']='R' . time().rand(1000,9999).$_GPC['user_id'];
  411. // $data['out_trade_no']=$_GPC['out_trade_no'];//预定订单
  412. $data['from_id']=$_GPC['from_id'];
  413. $res=pdo_insert('zh_jdgjb_re_order',$data);
  414. $order_id=pdo_insertid();
  415. echo json_encode(['code'=> 1, 'data' => $order_id]);
  416. }
  417. //生成订单
  418. public function doPageAddOrder(){
  419. global $_W, $_GPC;
  420. $data['user_id']=$_GPC['user_id'];
  421. $data['seller_id']=$_GPC['seller_id'];
  422. $data['coupons_id']=$_GPC['coupons_id'];
  423. $data['hb_id']=$_GPC['hb_id'];
  424. $data['room_id']=$_GPC['room_id'];
  425. $data['order_no']=date('YmdHis').rand(0,9999);
  426. $data['status']=1;
  427. $data['time']=time();
  428. $data['price']=$_GPC['price'];
  429. $data['seller_name']=$_GPC['seller_name'];
  430. $data['seller_address']=$_GPC['seller_address'];
  431. $data['coordinates']=$_GPC['coordinates'];
  432. $data['arrival_time']=$_GPC['arrival_time'];
  433. $data['departure_time']=$_GPC['departure_time'];
  434. $data['dd_time']=$_GPC['dd_time'];
  435. $data['tel']=$_GPC['tel'];
  436. $data['name']=$_GPC['name'];
  437. $data['room_type']=$_GPC['room_type'];
  438. $data['total_cost']=$_GPC['total_cost'];
  439. $data['num']=$_GPC['num'];
  440. $data['bed_type']=$_GPC['bed_type'];
  441. $data['uniacid']=$_W['uniacid'];
  442. $data['out_trade_no']=time().rand(1000,9999).$_GPC['user_id'];
  443. $data['days']=$_GPC['days'];
  444. $data['dis_cost']=$_GPC['dis_cost'];//折扣后的金额
  445. $data['yhq_cost']=$_GPC['yhq_cost'];
  446. $data['hb_cost']=$_GPC['hb_cost'];
  447. $data['yyzk_cost']=$_GPC['yyzk_cost'];
  448. $data['yj_cost']=$_GPC['yj_cost'];
  449. $data['room_logo']=$_GPC['room_logo'];
  450. // $data['out_trade_no']=$_GPC['out_trade_no'];//预定订单
  451. $data['from_id']=$_GPC['from_id'];
  452. $data['qr_fromid']=$_GPC['qr_fromid'];
  453. $data['classify']=$_GPC['classify'];
  454. $data['type']=$_GPC['type'];
  455. $data['code']=$_GPC['code'];
  456. $dt_start = strtotime($_GPC['arrival_time']);
  457. $dt_end = strtotime($_GPC['departure_time']);
  458. $rid=$_GPC['room_id'];
  459. $str='';
  460. $diffDay=$data['days'];
  461. $roomnum=$data['num'];
  462. while ($dt_start<$dt_end){
  463. $dateday=$dt_start;
  464. $res=pdo_get('zh_jdgjb_roomnum',array('rid'=>$rid,'dateday'=>$dateday));
  465. $surplus=$res['nums'];
  466. if(!$res['id']){
  467. $surplus=pdo_getcolumn('zh_jdgjb_room',array('id'=>$rid),'total_num');
  468. }
  469. if(($roomnum-$surplus>0)){
  470. if($surplus==0){
  471. $str.=date('m月d日',$dateday).'已经没有房间了!';
  472. }else{
  473. $str.=date('m月d日',$dateday).'只剩下'.$surplus.'间房';
  474. }
  475. }
  476. $dt_start = strtotime('+1 day',$dt_start);
  477. }
  478. if($str){
  479. echo $str;
  480. }else{
  481. if($_GPC['type']==3){//到店付
  482. $data['status']=1;
  483. file_get_contents("".$_W['siteroot']."app/index.php?i=".$_W['uniacid']."&c=entry&a=wxapp&do=Sms&m=zh_jdgjb&seller_id=".$_GPC['seller_id']);//短信
  484. }
  485. $res=pdo_insert('zh_jdgjb_order',$data);
  486. $order_id=pdo_insertid();
  487. if($_GPC['hb_id']){//使用积分红包
  488. pdo_update('zh_jdgjb_jfhb',array('state'=>2),array('id'=>$_GPC['hb_id']));
  489. }
  490. if($_GPC['type']==3){
  491. file_get_contents("".$_W['siteroot']."/app/index.php?i=".$_W['uniacid']."&c=entry&a=wxapp&do=print&m=zh_jdgjb&order_id=".$order_id);
  492. if($_GPC['coupons_id']){//使用优惠券
  493. pdo_update('zh_jdgjb_usercoupons',array('state'=>2,'sy_time'=>time()),array('coupons_id'=>$_GPC['coupons_id'],'user_id'=>$_GPC['user_id']));
  494. }
  495. }
  496. echo $order_id;
  497. }
  498. }
  499. //微信支付
  500. public function doPageVipPay(){
  501. global $_W, $_GPC;
  502. include IA_ROOT.'/addons/zh_jdgjb/wxpay.php';
  503. $res=pdo_get('zh_jdgjb_system',array('uniacid'=>$_W['uniacid']));
  504. $order=pdo_get('zh_jdgjb_vip_order',array('id'=>$_GPC['order_id']));
  505. $appid=$res['appid'];
  506. $openid=$_GPC['openid'];//oQKgL0ZKHwzAY-KhiyEEAsakW5Zg
  507. $mch_id=$res['mchid'];
  508. $key=$res['wxkey'];
  509. $out_trade_no = $order['out_trade_no'];
  510. $root=$_W['siteroot'];
  511. // pdo_update('zh_jdgjb_order',array('out_trade_no'=>$out_trade_no),array('id'=>$_GPC['order_id']));
  512. $total_fee =$order['total_cost'];
  513. if(empty($total_fee))
  514. {
  515. $body = "订单付款";
  516. $total_fee = floatval(99*100);
  517. }else{
  518. $body = "订单付款";
  519. $total_fee = floatval($total_fee*100);
  520. }
  521. $weixinpay = new WeixinPay($appid,$openid,$mch_id,$key,$out_trade_no,$body,$total_fee,$root);
  522. $return=$weixinpay->pay();
  523. echo json_encode($return);
  524. }
  525. public function doPageRePay(){
  526. global $_W, $_GPC;
  527. include IA_ROOT.'/addons/zh_jdgjb/wxpay.php';
  528. $res=pdo_get('zh_jdgjb_system',array('uniacid'=>$_W['uniacid']));
  529. $order=pdo_get('zh_jdgjb_re_order',array('id'=>$_GPC['order_id']));
  530. $appid=$res['appid'];
  531. $openid=$_GPC['openid'];//oQKgL0ZKHwzAY-KhiyEEAsakW5Zg
  532. $mch_id=$res['mchid'];
  533. $key=$res['wxkey'];
  534. $out_trade_no = $order['out_trade_no'];
  535. $root=$_W['siteroot'];
  536. // pdo_update('zh_jdgjb_order',array('out_trade_no'=>$out_trade_no),array('id'=>$_GPC['order_id']));
  537. $total_fee =$order['total_cost'];
  538. $body = "订单付款";
  539. $total_fee = floatval($total_fee*100);
  540. $weixinpay = new WeixinPay($appid,$openid,$mch_id,$key,$out_trade_no,$body,$total_fee,$root);
  541. $return=$weixinpay->pay();
  542. echo json_encode($return);
  543. }
  544. //微信支付
  545. public function doPagePay(){
  546. global $_W, $_GPC;
  547. include IA_ROOT.'/addons/zh_jdgjb/wxpay.php';
  548. $res=pdo_get('zh_jdgjb_system',array('uniacid'=>$_W['uniacid']));
  549. $order=pdo_get('zh_jdgjb_order',array('id'=>$_GPC['order_id']));
  550. $appid=$res['appid'];
  551. $openid=$_GPC['openid'];//oQKgL0ZKHwzAY-KhiyEEAsakW5Zg
  552. $mch_id=$res['mchid'];
  553. $key=$res['wxkey'];
  554. $out_trade_no = $order['out_trade_no'];
  555. $root=$_W['siteroot'];
  556. // pdo_update('zh_jdgjb_order',array('out_trade_no'=>$out_trade_no),array('id'=>$_GPC['order_id']));
  557. $total_fee =$order['total_cost'];
  558. if(empty($total_fee))
  559. {
  560. $body = "订单付款";
  561. $total_fee = floatval(99*100);
  562. }else{
  563. $body = "订单付款";
  564. $total_fee = floatval($total_fee*100);
  565. }
  566. $weixinpay = new WeixinPay($appid,$openid,$mch_id,$key,$out_trade_no,$body,$total_fee,$root);
  567. $return=$weixinpay->pay();
  568. echo json_encode($return);
  569. }
  570. //余额支付
  571. public function doPageYePay(){
  572. global $_W, $_GPC;
  573. $orderInfo=pdo_get('zh_jdgjb_order',array('id'=>$_GPC['order_id']));
  574. $data['user_id']=$orderInfo['user_id'];
  575. $data['cz_money']=$orderInfo['total_cost'];
  576. $data['note']='订单消费';
  577. $data['state']=2;
  578. $data['time']=time();
  579. $data['uniacid']=$_W['uniacid'];
  580. $res=pdo_insert('zh_jdgjb_recharge',$data);
  581. if($res){
  582. $dt_start = strtotime(substr($orderInfo['arrival_time'],0,10));
  583. $dt_end = strtotime(substr($orderInfo['departure_time'],0,10));
  584. while ($dt_start<$dt_end){
  585. $dateday=$dt_start;
  586. $res=pdo_get('zh_jdgjb_roomnum',array('rid'=>$orderInfo['room_id'],'dateday'=>$dateday));
  587. if($res['id']){
  588. $nums=$res['nums']-$orderInfo['num'];
  589. pdo_update('zh_jdgjb_roomnum',array('nums'=>$nums),array('rid'=>$orderInfo['room_id'],'dateday'=>$dateday));
  590. }else{
  591. $uniacid=$_W['uniacid'];
  592. $roomArr=pdo_get('zh_jdgjb_room',array('id'=>$orderInfo['room_id'],'uniacid'=>$orderInfo['uniacid']),array('total_num','id'));
  593. $nums=$roomArr['total_num']-$order['num'];
  594. pdo_insert('zh_jdgjb_roomnum',array('nums'=>$nums,'rid'=>$roomArr['id'],'dateday'=>$dateday));
  595. }
  596. $dt_start = strtotime('+1 day',$dt_start);
  597. }
  598. pdo_update('zh_jdgjb_order',array('status'=>2),array('id'=>$_GPC['order_id']));
  599. if($orderInfo['coupons_id']){//使用优惠券
  600. pdo_update('zh_jdgjb_usercoupons',array('state'=>2,'sy_time'=>time()),array('coupons_id'=>$orderInfo['coupons_id'],'user_id'=>$orderInfo['user_id']));
  601. }
  602. pdo_update('zh_jdgjb_user',array('balance -='=>$orderInfo['total_cost']),array('id'=>$orderInfo['user_id']));
  603. //echo "".$_W['siteroot']."/app/index.php?i=".$_W['uniacid']."&c=entry&a=wxapp&do=print&m=zh_jdgjb&order_id=".$_GPC['order_id'];die;
  604. echo file_get_contents("".$_W['siteroot']."/app/index.php?i=".$_W['uniacid']."&c=entry&a=wxapp&do=print&m=zh_jdgjb&order_id=".$_GPC['order_id']);//打印小票die;
  605. file_get_contents("".$_W['siteroot']."app/index.php?i=".$_W['uniacid']."&c=entry&a=wxapp&do=Sms&m=zh_jdgjb&seller_id=".$orderInfo['seller_id']);//短信
  606. echo '1';
  607. }else{
  608. echo '2';
  609. }
  610. }
  611. //我的优惠券
  612. public function doPageMyCoupons(){
  613. global $_W, $_GPC;
  614. $pageindex = max(1, intval($_GPC['page']));
  615. $pagesize=10;
  616. $data[':uniacid']=$_W['uniacid'];
  617. $data[':user_id']=$_GPC['user_id'];
  618. $where=" where a.uniacid=:uniacid and a.user_id=:user_id ";
  619. $sql="select b.*,a.id as lq_id,a.state from " . tablename("zh_jdgjb_usercoupons")." a left join".tablename('zh_jdgjb_coupons')." b on a.coupons_id=b.id" .$where." order by id desc ";
  620. $select_sql=$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
  621. $list=pdo_fetchall($select_sql,$data);
  622. echo json_encode($list);
  623. }
  624. //保存评价
  625. public function doPageSaveAssess(){
  626. global $_W, $_GPC;
  627. $res2=pdo_get('zh_jdgjb_system',array('uniacid'=>$_W['uniacid']));
  628. $data['seller_id']=$_GPC['seller_id'];
  629. $data['score']=$_GPC['score'];
  630. $data['content']=html_entity_decode($_GPC['content']);
  631. $data['img']=$_GPC['img'];
  632. $data['user_id']=$_GPC['user_id'];
  633. $data['status']=1;
  634. $data['time']=time();
  635. $data['uniacid']=$_W['uniacid'];
  636. $res=pdo_insert('zh_jdgjb_assess',$data);
  637. $assess_id=pdo_insertid();
  638. if($res){
  639. echo '1';
  640. //完成订单
  641. pdo_update('zh_jdgjb_order',array('status'=>4),array('id'=>$_GPC['order_id']));
  642. $data2['user_id']=$_GPC['user_id'];
  643. $data2['assess_id']=$assess_id;
  644. $data2['score']=$res2['pl_score'];
  645. $data2['note']='评论所得';
  646. $data2['time']=time();
  647. $data2['uniacid']=$_W['uniacid'];
  648. pdo_insert('zh_jdgjb_score',$data2);
  649. pdo_update('zh_jdgjb_user',array('score +='=>$res2['pl_score']),array('id'=>$_GPC['user_id']));
  650. }else{
  651. echo '2';
  652. }
  653. }
  654. //评价列表
  655. public function doPageAssessList(){
  656. global $_GPC, $_W;
  657. $pageindex = max(1, intval($_GPC['page']));
  658. $pagesize=10;
  659. $sql=" select a.*,b.name,b.img as logo from".tablename('zh_jdgjb_assess')." a left join ".tablename('zh_jdgjb_user')." b on a.user_id=b.id where a.uniacid=:uniacid and a.seller_id=:seller_id order by a.id desc";
  660. //echo $sql;die;
  661. $select_sql=$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
  662. $list=pdo_fetchall($select_sql,array(':uniacid'=>$_W['uniacid'],':seller_id'=>$_GPC['seller_id']));
  663. echo json_encode($list);
  664. }
  665. //打印机
  666. public function doPagePrint(){
  667. global $_W, $_GPC;
  668. include IA_ROOT.'/addons/zh_jdgjb/print/dyj.php';
  669. $orderInfo=pdo_get('zh_jdgjb_order',array('id'=>$_GPC['order_id']));
  670. $dyj=pdo_get('zh_jdgjb_dyj',array('seller_id'=>$orderInfo['seller_id']));
  671. $yh_money=$orderInfo['yhq_cost']+$orderInfo['yyzk_cost']+$orderInfo['hb_cost'];
  672. if($orderInfo['type']==1){
  673. $type='微信支付';
  674. }
  675. if($orderInfo['type']==2){
  676. $type='余额支付';
  677. }
  678. if($orderInfo['type']==3){
  679. $type='到店支付';
  680. }
  681. if($dyj['state']==1){//打印机开启
  682. if($dyj['type']==3){
  683. $content = "<BR><BR>";
  684. $content .= " ".$dyj['dyj_title']."<BR>";
  685. $content .= "--------------------------------<BR>";
  686. $content .="酒店名称: ". $orderInfo['seller_name']."<BR>";
  687. $content .="酒店地址: ". $orderInfo['seller_address']."<BR>";
  688. $content .="房型: ". $orderInfo['room_type']."<BR>";
  689. $content .="房间价格: ". $orderInfo['dis_cost']."<BR>";
  690. $content .="押金: ". $orderInfo['yj_cost']."<BR>";
  691. $content .="优惠金额: ". $yh_money."<BR>";
  692. $content .="房间数量: ". $orderInfo['num']."<BR>";
  693. $content .="入住时间: ". substr($orderInfo['arrival_time'],0,10)."<BR>";
  694. $content .="离店时间: ". substr($orderInfo['departure_time'],0,10)."<BR>";
  695. $content .="到店时间: ". $orderInfo['dd_time']."<BR>";
  696. $content .="入住天数: ". $orderInfo['days']."<BR>";
  697. $content .="入住人姓名: ". $orderInfo['name']."<BR>";
  698. $content .="入住人电话: ". $orderInfo['tel']."<BR>";
  699. $content .="支付方式: ". $type."<BR>";
  700. $content .= "<BR><BR>";
  701. }else{
  702. $content = "\n\n\n";
  703. $content .= " ".$dyj['dyj_title']."\n\n";
  704. $content .= "--------------------------------\n\n";
  705. $content .="酒店名称: ". $orderInfo['seller_name']."\n\n";
  706. $content .="酒店地址: ". $orderInfo['seller_address']."\n\n";
  707. $content .="房型: ". $orderInfo['room_type']."\n\n";
  708. $content .="房间价格: ". $orderInfo['dis_cost']."\n\n";
  709. $content .="押金: ". $orderInfo['yj_cost']."\n\n";
  710. $content .="优惠金额: ". $yh_money."\n\n";
  711. $content .="房间数量: ". $orderInfo['num']."\n\n";
  712. $content .="入住时间: ". substr($orderInfo['arrival_time'],0,10)."\n\n";
  713. $content .="离店时间: ". substr($orderInfo['departure_time'],0,10)."\n\n";
  714. $content .="到店时间: ". $orderInfo['dd_time']."\n\n";
  715. $content .="入住天数: ". $orderInfo['days']."\n\n";
  716. $content .="入住人姓名: ". $orderInfo['name']."\n\n";
  717. $content .="入住人电话: ". $orderInfo['tel']."\n\n";
  718. $content .="支付方式: ". $type."\n";
  719. $content .= "\n\n\n";
  720. }
  721. if($dyj['type']==1){//365
  722. $rst=Dyj::dy($dyj['dyj_id'],$content,$dyj['dyj_key']);
  723. }
  724. if($dyj['type']==2){//易联云
  725. $rst=Dyj::ylydy($dyj['api'],$dyj['token'],$dyj['yy_id'],$dyj['mid'],$content);
  726. }
  727. if($dyj['type']==3){//飞蛾
  728. $rst=Dyj::fedy($dyj['fezh'],$dyj['fe_ukey'],$dyj['fe_dycode'],$content);
  729. }
  730. }
  731. }
  732. //短信通知
  733. public function doPageSms(){
  734. global $_W, $_GPC;
  735. $res=pdo_get('zh_jdgjb_notice',array('uniacid'=>$_W['uniacid'],'seller_id'=>$_GPC['seller_id']));
  736. if($res['item']==2){
  737. $tpl_id=$res['aliyun_id2'];
  738. var_dump( $this->doPageAliyun2($res['js_tel'],$res['aliyun_appkey'],$res['aliyun_appsecret'],$res['aliyun_sign'],$res['aliyun_id'])) ;
  739. }else{
  740. $tpl_id=$res['tpl_id'];
  741. $tel=$res['js_tel'];
  742. $key=$res['appkey'];
  743. $url = "http://v.juhe.cn/sms/send?mobile=".$tel."&tpl_id=".$tpl_id."&tpl_value=%23code%23%3D654654&key=".$key;
  744. $data=file_get_contents($url);
  745. print_r($data);
  746. }
  747. }
  748. //我的订单
  749. public function doPageMyOrder(){
  750. global $_GPC, $_W;
  751. $pageindex = max(1, intval($_GPC['page']));
  752. $pagesize=10;
  753. $data[':uniacid']=$_W['uniacid'];
  754. $data[':user_id']=$_GPC['user_id'];
  755. $where=" where uniacid=:uniacid and user_id=:user_id ";
  756. if($_GPC['status']){
  757. $where.=" and status=:status and is_out_time = :is_out_time";
  758. $data[':status']=$_GPC['status'];
  759. $data[':is_out_time'] = 0;
  760. }
  761. $sql="select * from " . tablename("zh_jdgjb_order") .$where." order by id desc ";
  762. $select_sql=$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
  763. $list=pdo_fetchall($select_sql,$data);
  764. foreach($list as $key=>$val){
  765. $list[$key]['count']=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_jdgjb_order') .$where.' and id<='.$val['id'].' and user_id='.$val['user_id'] ,$data)?:0;
  766. }
  767. echo json_encode($list);
  768. }
  769. //我的订单
  770. public function doPageMyOverdueOrder(){
  771. global $_GPC, $_W;
  772. $pageindex = max(1, intval($_GPC['page']));
  773. $pagesize=10;
  774. $data[':uniacid']=$_W['uniacid'];
  775. $data[':user_id']=$_GPC['user_id'];
  776. $where=" where uniacid=:uniacid and user_id=:user_id ";
  777. if($_GPC['status']){
  778. $where.=" and status = :status and is_out_time = :is_out_time";
  779. $data[':status'] = 10;
  780. $data[':is_out_time'] = 1;
  781. }
  782. $sql="select * from " . tablename("zh_jdgjb_order") .$where." order by id desc ";
  783. $select_sql=$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
  784. $list=pdo_fetchall($select_sql,$data);
  785. foreach($list as $key=>$val){
  786. $list[$key]['count']=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_jdgjb_order') .$where.' and id<='.$val['id'].' and user_id='.$val['user_id'] ,$data)?:0;
  787. $conf = pdo_get('zh_jdgjb_seller',array('id'=>$val['seller_id']));
  788. $list[$key]['re_pay_money'] = $conf['re_pay_money'];
  789. }
  790. echo json_encode($list);
  791. }
  792. //订单详情
  793. public function doPageOrderDetails(){
  794. global $_GPC, $_W;
  795. $res=pdo_get('zh_jdgjb_order',array('id'=>$_GPC['order_id']));
  796. echo json_encode($res);
  797. }
  798. //取消订单
  799. public function doPageCancelOrder(){
  800. global $_GPC, $_W;
  801. $res=pdo_update('zh_jdgjb_order',array('status'=>3),array('id'=>$_GPC['order_id']));
  802. if($res){
  803. if($_GPC['hb_id']){//使用积分红包
  804. pdo_update('zh_jdgjb_jfhb',array('state'=>1),array('id'=>$_GPC['hb_id']));
  805. }
  806. echo '1';
  807. }else{
  808. echo '2';
  809. }
  810. }
  811. //申请退款
  812. public function doPageApplyOrder(){
  813. global $_GPC, $_W;
  814. $res=pdo_update('zh_jdgjb_order',array('status'=>6),array('id'=>$_GPC['order_id']));
  815. if($res){
  816. echo '1';
  817. }else{
  818. echo '2';
  819. }
  820. }
  821. //获取实时房价
  822. public function doPageGetRoomCost(){
  823. global $_W, $_GPC;
  824. $rid=$_GPC['room_id'];
  825. $dt_start = strtotime($_GPC['start']);
  826. $dt_end = strtotime($_GPC['end']);
  827. $pricelist=array();
  828. $i=0;
  829. while ($dt_start<$dt_end){
  830. $dateday=$dt_start;
  831. $res1=pdo_get('zh_jdgjb_roomprice',array('rid'=>$rid,'dateday'=>$dateday));
  832. $pricelist[$i]['dateday']=date('m月d日',$dateday);
  833. if($res1['mprice']){
  834. $pricelist[$i]['mprice']=$res1['mprice'];
  835. }else{
  836. $mprice=pdo_getcolumn('zh_jdgjb_room',array('id'=>$rid),'price');
  837. $pricelist[$i]['mprice']=$mprice;
  838. }
  839. $dt_start = strtotime('+1 day',$dt_start);
  840. $i++;
  841. }
  842. echo json_encode($pricelist);
  843. }
  844. //微信支付退款
  845. public function doPageRefund(){
  846. global $_W, $_GPC;
  847. include_once IA_ROOT . '/addons/zh_jdgjb/cert/WxPay.Api.php';
  848. load()->model('account');
  849. load()->func('communication');
  850. $refund_order =pdo_get('zh_jdgjb_order',array('id'=>$_GPC['order_id']));
  851. $WxPayApi = new WxPayApi();
  852. $input = new WxPayRefund();
  853. $path_cert = IA_ROOT . "/addons/zh_jdgjb/cert/".'apiclient_cert_' .$_W['uniacid'] . '.pem';
  854. $path_key = IA_ROOT . "/addons/zh_jdgjb/cert/".'apiclient_key_' . $_W['uniacid'] . '.pem';
  855. $account_info = $_W['account'];
  856. $res=pdo_get('zh_jdgjb_system',array('uniacid'=>$_W['uniacid']));
  857. $appid=$res['appid'];
  858. $key=$res['wxkey'];
  859. $mchid=$res['mchid'];
  860. $out_trade_no=$refund_order['out_trade_no'];
  861. $fee = $refund_order['total_cost'] * 100;
  862. $input->SetAppid($appid);
  863. $input->SetMch_id($mchid);
  864. $input->SetOp_user_id($mchid);
  865. $input->SetRefund_fee($fee);
  866. $input->SetTotal_fee($fee);
  867. // $input->SetTransaction_id($refundid);
  868. $input->SetOut_refund_no($refund_order['order_no']);
  869. $input->SetOut_trade_no($out_trade_no);
  870. $result = $WxPayApi->refund($input, 6, $path_cert, $path_key, $key);
  871. if ($result['result_code'] == 'SUCCESS') {//退款成功
  872. //更改订单操作
  873. pdo_update('zh_jdgjb_order',array('status'=>7),array('id'=>$_GPC['order_id']));
  874. echo '1';
  875. }else{
  876. echo $result['err_code_des'];
  877. }
  878. }
  879. public function doPageRefund2(){
  880. global $_W, $_GPC;
  881. include_once IA_ROOT . '/addons/zh_jdgjb/cert/WxPay.Api.php';
  882. load()->model('account');
  883. load()->func('communication');
  884. $refund_order =pdo_get('zh_jdgjb_order',array('id'=>$_GPC['order_id']));
  885. $WxPayApi = new WxPayApi();
  886. $input = new WxPayRefund();
  887. $path_cert = IA_ROOT . "/addons/zh_jdgjb/cert/".'apiclient_cert_' .$_W['uniacid'] . '.pem';
  888. $path_key = IA_ROOT . "/addons/zh_jdgjb/cert/".'apiclient_key_' . $_W['uniacid'] . '.pem';
  889. $account_info = $_W['account'];
  890. $res=pdo_get('zh_jdgjb_system',array('uniacid'=>$_W['uniacid']));
  891. $appid=$res['appid'];
  892. $key=$res['wxkey'];
  893. $mchid=$res['mchid'];
  894. $out_trade_no=$refund_order['out_trade_no'];
  895. $fee = $_GPC['total_cost'] * 100;
  896. $input->SetAppid($appid);
  897. $input->SetMch_id($mchid);
  898. $input->SetOp_user_id($mchid);
  899. $input->SetRefund_fee($fee);
  900. $input->SetTotal_fee($fee);
  901. // $input->SetTransaction_id($refundid);
  902. $input->SetOut_refund_no($refund_order['order_no']);
  903. $input->SetOut_trade_no($out_trade_no);
  904. $result = $WxPayApi->refund($input, 6, $path_cert, $path_key, $key);
  905. if ($result['result_code'] == 'SUCCESS') {//退款成功
  906. //更改订单操作
  907. pdo_update('zh_jdgjb_order',array('status'=>7),array('id'=>$_GPC['order_id']));
  908. echo '1';
  909. }else{
  910. echo $result['err_code_des'];
  911. }
  912. }
  913. //余额退款
  914. public function doPageYeRefund(){
  915. global $_W, $_GPC;
  916. $orderInfo=pdo_get('zh_jdgjb_order',array('id'=>$_GPC['order_id']));
  917. $data['user_id']=$orderInfo['user_id'];
  918. $data['cz_money']=$orderInfo['total_cost'];
  919. $data['note']='订单退款';
  920. $data['state']=2;
  921. $data['time']=time();
  922. $data['uniacid']=$_W['uniacid'];
  923. $res=pdo_insert('zh_jdgjb_recharge',$data);
  924. if($res){
  925. pdo_update('zh_jdgjb_order',array('status'=>7),array('id'=>$_GPC['order_id']));
  926. pdo_update('zh_jdgjb_user',array('balance +='=>$orderInfo['total_cost']),array('id'=>$orderInfo['user_id']));
  927. echo '1';
  928. }
  929. }
  930. //订房成功模板消息
  931. public function doPageMessage(){
  932. global $_W, $_GPC;
  933. function getaccess_token($_W){
  934. $res=pdo_get('zh_jdgjb_system',array('uniacid'=>$_W['uniacid']));
  935. $appid=$res['appid'];
  936. $secret=$res['appsecret'];
  937. $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret."";
  938. $ch = curl_init();
  939. curl_setopt($ch, CURLOPT_URL,$url);
  940. curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
  941. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
  942. $data = curl_exec($ch);
  943. curl_close($ch);
  944. $data = json_decode($data,true);
  945. return $data['access_token'];
  946. }
  947. //设置与发送模板信息
  948. function set_msg($_W){
  949. $access_token = getaccess_token($_W);
  950. $res=pdo_get('zh_jdgjb_system',array('uniacid'=>$_W['uniacid']));
  951. $sql="select * from " . tablename("zh_jdgjb_order")." WHERE id=:order_id ";
  952. $list=pdo_fetch($sql,array(':order_id'=>$_GET['order_id']));
  953. $time=date('Y-m-d H:i',$list['time']);
  954. $time1=substr($list['arrival_time'],0,10);
  955. $time2=substr($list['departure_time'],0,10);
  956. //下面是要填充模板的信息
  957. $formwork ='{
  958. "touser": "'.$_GET["openid"].'",
  959. "template_id": "'.$res["tid1"].'",
  960. "form_id":"'.$_GET['form_id'].'",
  961. "data": {
  962. "keyword1": {
  963. "value": "'.$list['seller_name'].'",
  964. "color": "#173177"
  965. },
  966. "keyword2": {
  967. "value": "'. $time.'",
  968. "color": "#173177"
  969. },
  970. "keyword3": {
  971. "value": "'.$list['dis_cost'].'",
  972. "color": "#173177"
  973. },
  974. "keyword4": {
  975. "value": "'.$list['seller_address'].'",
  976. "color": "#173177"
  977. },
  978. "keyword5": {
  979. "value": "'.$list['order_no'].'",
  980. "color": "#173177"
  981. },
  982. "keyword6": {
  983. "value": "'.$time1.'",
  984. "color": "#173177"
  985. },
  986. "keyword7": {
  987. "value": "'.$time2.'",
  988. "color": "#173177"
  989. },
  990. "keyword8": {
  991. "value": "'.$list['name'].'",
  992. "color": "#173177"
  993. },
  994. "keyword9": {
  995. "value": "'.$list['room_type'].'",
  996. "color": "#173177"
  997. }
  998. }
  999. }';
  1000. $url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=".$access_token."";
  1001. $ch = curl_init();
  1002. curl_setopt($ch, CURLOPT_URL,$url);
  1003. curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
  1004. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
  1005. curl_setopt($ch, CURLOPT_POST,1);
  1006. curl_setopt($ch, CURLOPT_POSTFIELDS,$formwork);
  1007. $data = curl_exec($ch);
  1008. curl_close($ch);
  1009. return $data;
  1010. }
  1011. echo set_msg($_W);
  1012. }
  1013. ////////////////////以下积分商城///////////////////////////
  1014. //分类列表
  1015. public function doPageJfTypeList(){
  1016. global $_W, $_GPC;
  1017. $res=pdo_getall('zh_jdgjb_jftype',array('uniacid'=>$_W['uniacid']),array(),'','num asc');
  1018. echo json_encode($res);
  1019. }
  1020. //商品列表
  1021. public function doPageJfGoodsList(){
  1022. global $_GPC, $_W;
  1023. $pageindex = max(1, intval($_GPC['page']));
  1024. $pagesize=10;
  1025. $data[':uniacid']=$_W['uniacid'];
  1026. $where=" where uniacid=:uniacid ";
  1027. if($_GPC['type_id']){
  1028. $where.=" and type_id=:type_id ";
  1029. $data[':type_id']=$_GPC['type_id'];
  1030. }
  1031. $sql="select * from " . tablename("zh_jdgjb_jfgoods") .$where." order by num asc ";
  1032. $select_sql=$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
  1033. $list=pdo_fetchall($select_sql,$data);
  1034. echo json_encode($list);
  1035. }
  1036. //商品详情
  1037. public function doPageGoodsDetails(){
  1038. global $_W, $_GPC;
  1039. $res=pdo_get('zh_jdgjb_jfgoods',array('id'=>$_GPC['id']));
  1040. echo json_encode($res);
  1041. }
  1042. //兑换商品
  1043. public function doPageExchange(){
  1044. global $_W, $_GPC;
  1045. $data['user_id']=$_GPC['user_id'];//用户id
  1046. $data['good_id']=$_GPC['good_id'];//商品id
  1047. $data['user_name']=$_GPC['user_name'];//用户名称
  1048. $data['user_tel']=$_GPC['user_tel'];//用户电话
  1049. $data['address']=$_GPC['address'];//地址
  1050. $data['integral']=$_GPC['integral'];//积分
  1051. $data['good_name']=$_GPC['good_name'];//商品名称
  1052. $data['good_img']=$_GPC['good_img'];//商品图片
  1053. $data['time']=date("Y-m-d H:i:s");
  1054. if($_GPC['type']==1){
  1055. $data['state']=2;
  1056. }else{
  1057. $data['state']=1;
  1058. }
  1059. $res=pdo_insert('zh_jdgjb_jfrecord',$data);
  1060. if($res){
  1061. pdo_update('zh_jdgjb_jfgoods',array('number -='=>1),array('id'=>$_GPC['good_id']));
  1062. if($_GPC['type']==1){//虚拟红包
  1063. $data2['money']=$_GPC['hb_money'];
  1064. $data2['user_id']=$_GPC['user_id'];
  1065. $data2['goods_id']=$_GPC['good_id'];;
  1066. $data2['time']=date('Y-m-d H:i:s');
  1067. $data2['uniacid']=$_W['uniacid'];
  1068. pdo_insert('zh_jdgjb_jfhb',$data2);
  1069. }
  1070. $data3['user_id']=$_GPC['user_id'];
  1071. $data3['goods_id']=$_GPC['good_id'];
  1072. $data3['score']=$_GPC['integral'];
  1073. $data3['note']='兑换商品';
  1074. $data3['type']=2;
  1075. $data3['time']=time();
  1076. $data3['uniacid']=$_W['uniacid'];
  1077. pdo_insert('zh_jdgjb_score',$data3);
  1078. pdo_update('zh_jdgjb_user',array('score -='=>$_GPC['integral']),array('id'=>$_GPC['user_id']));
  1079. echo '1';
  1080. }else{
  1081. echo '2';
  1082. }
  1083. }
  1084. //兑换明细
  1085. public function doPageDhmx(){
  1086. global $_W, $_GPC;
  1087. $pageindex = max(1, intval($_GPC['page']));
  1088. $pagesize=10;
  1089. $data[':user_id']=$_GPC['user_id'];
  1090. $where=" where user_id=:user_id ";
  1091. $sql="select * from " . tablename("zh_jdgjb_jfrecord") .$where." order by id desc ";
  1092. $select_sql=$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
  1093. $list=pdo_fetchall($select_sql,$data);
  1094. echo json_encode($list);
  1095. }
  1096. //我的积分明细
  1097. public function doPageMyScoreDetails(){
  1098. global $_GPC, $_W;
  1099. $pageindex = max(1, intval($_GPC['page']));
  1100. $pagesize=20;
  1101. $data[':uniacid']=$_W['uniacid'];
  1102. $data[':user_id']=$_GPC['user_id'];
  1103. $where=" where uniacid=:uniacid and user_id=:user_id ";
  1104. $sql="select * from " . tablename("zh_jdgjb_score") .$where." order by id desc ";
  1105. $select_sql=$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
  1106. $list=pdo_fetchall($select_sql,$data);
  1107. echo json_encode($list);
  1108. }
  1109. //我的可用红包
  1110. public function doPageMyHb(){
  1111. global $_GPC, $_W;
  1112. $pageindex = max(1, intval($_GPC['page']));
  1113. $pagesize=10;
  1114. $data[':uniacid']=$_W['uniacid'];
  1115. $data[':user_id']=$_GPC['user_id'];
  1116. $where=" where uniacid=:uniacid and user_id=:user_id and state=1";
  1117. $sql="select * from " . tablename("zh_jdgjb_jfhb") .$where." order by id desc ";
  1118. $select_sql=$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
  1119. $list=pdo_fetchall($select_sql,$data);
  1120. echo json_encode($list);
  1121. }
  1122. //获取实时房间数量
  1123. public function doPageGetRoomNum(){
  1124. global $_W, $_GPC;
  1125. $rid=$_GPC['room_id'];
  1126. $dt_start = strtotime($_GPC['start']);
  1127. $dt_end = strtotime($_GPC['end']);
  1128. $pricelist=array();
  1129. $i=0;
  1130. while ($dt_start<$dt_end){
  1131. $dateday=$dt_start;
  1132. $res1=pdo_get('zh_jdgjb_roomnum',array('rid'=>$rid,'dateday'=>$dateday));
  1133. $pricelist[$i]['dateday']=date('m月d日',$dateday);
  1134. if($res1){
  1135. $pricelist[$i]['nums']=$res1['nums'];
  1136. }else{
  1137. $mprice=pdo_getcolumn('zh_jdgjb_room',array('id'=>$rid),'total_num');
  1138. $pricelist[$i]['nums']=$mprice;
  1139. }
  1140. $dt_start = strtotime('+1 day',$dt_start);
  1141. $i++;
  1142. }
  1143. echo json_encode($pricelist);
  1144. }
  1145. //会员等级列表
  1146. public function doPageMemberList(){
  1147. global $_W, $_GPC;
  1148. $res=pdo_getall('zh_jdgjb_level',array('uniacid'=>$_W['uniacid']),array(),'','value asc');
  1149. echo json_encode($res);
  1150. }
  1151. /////////////////////////以下后台操作
  1152. ///
  1153. public function doPageHtLogin(){
  1154. global $_GPC, $_W;
  1155. load()->model('user');
  1156. $time=strtotime(date("Y-m-d"));
  1157. $mttime=strtotime(date("Y-m-d",strtotime("+1 day")));
  1158. $zttime=strtotime(date("Y-m-d",strtotime("-1 day")));
  1159. $month=strtotime(date("Y-m"));
  1160. $member = array();
  1161. $summary=array();
  1162. $member['username'] =$_GPC['username'];
  1163. $member['password'] = $_GPC['password'];
  1164. $record = user_single($member);
  1165. if(!empty($record)) {
  1166. $account = pdo_fetch("SELECT * FROM " . tablename("zh_jdgjb_account") . " WHERE status=2 AND uid=:uid ORDER BY id DESC LIMIT 1", array(':uid' => $record['uid']));
  1167. if (!empty($account)) {
  1168. $storeid = $account['storeid'];
  1169. $data[':uniacid']=$_W['uniacid'];
  1170. $data[':seller_id']=$storeid;
  1171. //获取酒店信息
  1172. $sellerInfo=pdo_get('zh_jdgjb_seller',array('id'=>$storeid),array('name','ewm_logo','ll_num'));
  1173. //今日订单
  1174. $order=" select count(id) as total from".tablename('zh_jdgjb_order')." where uniacid=:uniacid and seller_id=:seller_id and time>=".$time." and time<".$mttime."";
  1175. $total=pdo_fetch($order,$data);
  1176. //今日销售额
  1177. $moneysql=" select sum(total_cost) as total_money, sum(ytyj_cost) as yj_money from".tablename('zh_jdgjb_order')." where uniacid=:uniacid and seller_id=:seller_id and status in (2,4,5,6,8) and time>=".$time." and time<".$mttime."";
  1178. $jrmoney=pdo_fetch($moneysql,$data);
  1179. //本月销售额
  1180. $bysql=" select sum(total_cost) as total_money, sum(ytyj_cost) as yj_money from".tablename('zh_jdgjb_order')." where uniacid=:uniacid and seller_id=:seller_id and status in (2,4,5,6,8) and time>=".$month;
  1181. $bymoney=pdo_fetch($bysql,$data);
  1182. //订单统计
  1183. $sql2="select count( case when status=2 then 1 end) as dzf, count( case when status=4 then 1 end) as ywc, count( case when status=6 then 1 end) as ytk from ".tablename('zh_jdgjb_order')." where uniacid=:uniacid and seller_id=:seller_id ";
  1184. $tjorder=pdo_fetch($sql2,$data);
  1185. //昨日营业额
  1186. $zrsql=" select sum(total_cost) as total_money, sum(ytyj_cost) as yj_money from".tablename('zh_jdgjb_order')." where uniacid=:uniacid and seller_id=:seller_id and status in (2,4,5,6,8) and time>=".$zttime." and time<".$time."";
  1187. $zrmoney=pdo_fetch($zrsql,$data);
  1188. //总营业额
  1189. $totalsql=" select sum(total_cost) as total_money, sum(ytyj_cost) as yj_money from".tablename('zh_jdgjb_order')." where uniacid=:uniacid and seller_id=:seller_id and status in (2,4,5,6,8) ";
  1190. $totalmoney=pdo_fetch($totalsql,$data);
  1191. //var_dump($totalmoney['yj_money']);die;
  1192. $summary['seller_id']=$storeid;
  1193. $summary['seller_name']=$sellerInfo['name'];
  1194. $summary['seller_logo']=$sellerInfo['ewm_logo'];
  1195. $summary['ll_num']=$sellerInfo['ll_num'];
  1196. $summary['jrdd']=$total['total'];
  1197. $summary['jrxse']=$jrmoney['total_money']-$jrmoney['yj_money'];
  1198. $summary['byxse']=$bymoney['total_money']-$bymoney['yj_money'];
  1199. $summary['dzf']=$tjorder['dzf'];
  1200. $summary['ywc']=$tjorder['ywc'];
  1201. $summary['ytk']=$tjorder['ytk'];
  1202. $summary['zrxse']=$zrmoney['total_money']-$zrmoney['yj_money'];
  1203. $summary['zxse']=$totalmoney['total_money']-$totalmoney['yj_money'];
  1204. echo json_encode($summary);
  1205. } else {
  1206. echo '您的账号正在审核或是已经被系统禁止,请联系网站管理员解决!!!';
  1207. }
  1208. }else{
  1209. echo '账号或密码错误';
  1210. }
  1211. }
  1212. //商家微信登录
  1213. public function doPageStoreWxLogin(){
  1214. global $_GPC, $_W;
  1215. $res=pdo_get('zh_jdgjb_seller',array('user_id'=>$_GPC['user_id'],'state'=>2));
  1216. if($res){
  1217. $storeid=$res['id'];
  1218. $time=strtotime(date("Y-m-d"));
  1219. $mttime=strtotime(date("Y-m-d",strtotime("+1 day")));
  1220. $zttime=strtotime(date("Y-m-d",strtotime("-1 day")));
  1221. $month=strtotime(date("Y-m"));
  1222. $summary=array();
  1223. $data[':uniacid']=$_W['uniacid'];
  1224. $data[':seller_id']=$storeid;
  1225. //获取酒店信息
  1226. $sellerInfo=pdo_get('zh_jdgjb_seller',array('id'=>$storeid),array('name','ewm_logo','ll_num'));
  1227. //今日订单
  1228. $order=" select count(id) as total from".tablename('zh_jdgjb_order')." where uniacid=:uniacid and seller_id=:seller_id and time>=".$time." and time<".$mttime."";
  1229. $total=pdo_fetch($order,$data);
  1230. //今日销售额
  1231. $moneysql=" select sum(total_cost) as total_money, sum(ytyj_cost) as yj_money from".tablename('zh_jdgjb_order')." where uniacid=:uniacid and seller_id=:seller_id and status in (2,4,5,6,8) and time>=".$time." and time<".$mttime."";
  1232. $jrmoney=pdo_fetch($moneysql,$data);
  1233. //本月销售额
  1234. $bysql=" select sum(total_cost) as total_money, sum(ytyj_cost) as yj_money from".tablename('zh_jdgjb_order')." where uniacid=:uniacid and seller_id=:seller_id and status in (2,4,5,6,8) and time>=".$month;
  1235. $bymoney=pdo_fetch($bysql,$data);
  1236. //订单统计
  1237. $sql2="select count( case when status=2 then 1 end) as dzf, count( case when status=4 then 1 end) as ywc, count( case when status=6 then 1 end) as ytk from ".tablename('zh_jdgjb_order')." where uniacid=:uniacid and seller_id=:seller_id ";
  1238. $tjorder=pdo_fetch($sql2,$data);
  1239. //昨日营业额
  1240. $zrsql=" select sum(total_cost) as total_money, sum(ytyj_cost) as yj_money from".tablename('zh_jdgjb_order')." where uniacid=:uniacid and seller_id=:seller_id and status in (2,4,5,6,8) and time>=".$zttime." and time<".$time."";
  1241. $zrmoney=pdo_fetch($zrsql,$data);
  1242. //总营业额
  1243. $totalsql=" select sum(total_cost) as total_money, sum(ytyj_cost) as yj_money from".tablename('zh_jdgjb_order')." where uniacid=:uniacid and seller_id=:seller_id and status in (2,4,5,6,8) ";
  1244. $totalmoney=pdo_fetch($totalsql,$data);
  1245. //var_dump($totalmoney['yj_money']);die;
  1246. $summary['seller_id']=$storeid;
  1247. $summary['seller_name']=$sellerInfo['name'];
  1248. $summary['seller_logo']=$sellerInfo['ewm_logo'];
  1249. $summary['ll_num']=$sellerInfo['ll_num'];
  1250. $summary['jrdd']=$total['total'];
  1251. $summary['jrxse']=$jrmoney['total_money']-$jrmoney['yj_money'];
  1252. $summary['byxse']=$bymoney['total_money']-$bymoney['yj_money'];
  1253. $summary['dzf']=$tjorder['dzf'];
  1254. $summary['ywc']=$tjorder['ywc'];
  1255. $summary['ytk']=$tjorder['ytk'];
  1256. $summary['zrxse']=$zrmoney['total_money']-$zrmoney['yj_money'];
  1257. $summary['zxse']=$totalmoney['total_money']-$totalmoney['yj_money'];
  1258. echo json_encode($summary);
  1259. }else{
  1260. echo '您还不是管理员或在审核中';
  1261. }
  1262. }
  1263. //订单列表
  1264. public function doPageSellerOrderList(){
  1265. global $_GPC, $_W;
  1266. $pageindex = max(1, intval($_GPC['page']));
  1267. $pagesize=10;
  1268. $data[':uniacid']=$_W['uniacid'];
  1269. $data[':seller_id']=$_GPC['seller_id'];
  1270. $where=" where uniacid=:uniacid and seller_id=:seller_id ";
  1271. if($_GPC['status']){
  1272. $where.=" and status=:status ";
  1273. $data[':status']=$_GPC['status'];
  1274. }
  1275. if($_GPC['keywords']){
  1276. $where.=" and order_no LIKE concat('%', :order_no,'%') ";
  1277. $data[':order_no']=$_GPC['keywords'];
  1278. }
  1279. $sql="select * from " . tablename("zh_jdgjb_order") .$where." order by id desc ";
  1280. $select_sql=$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
  1281. $list=pdo_fetchall($select_sql,$data);
  1282. foreach($list as $key=>$val){
  1283. $list[$key]['count']=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_jdgjb_order') .$where.' and id<='.$val['id'].' and user_id='.$val['user_id'] ,$data)?:0;
  1284. }
  1285. echo json_encode($list);
  1286. }
  1287. //确认入住,拒绝退款
  1288. public function doPageChangeOrder(){
  1289. global $_W, $_GPC;
  1290. $res=pdo_update('zh_jdgjb_order',array('status'=>$_GPC['status']),array('id'=>$_GPC['order_id']));
  1291. if($res){
  1292. if($_GPC['status']==5){
  1293. $rst=file_get_contents("".$_W['siteroot']."/app/index.php?i=".$_W['uniacid']."&c=entry&a=wxapp&do=UpdRz&m=zh_jdgjb&id=".$_GPC['order_id']);
  1294. }
  1295. echo '1';
  1296. }else{
  1297. echo'2';
  1298. }
  1299. }
  1300. //编辑房间
  1301. public function doPageEditRoom(){
  1302. global $_GPC, $_W;
  1303. $data['name']=$_GPC['name'];
  1304. $data['price']=$_GPC['price'];
  1305. $data['img']=$_GPC['img'];
  1306. $data['floor']=$_GPC['floor'];
  1307. $data['people']=$_GPC['people'];
  1308. $data['logo']=$_GPC['logo'];
  1309. $data['yj_cost']=$_GPC['yj_cost'];
  1310. $data['state']=$_GPC['state'];
  1311. //var_dump($data);die;
  1312. $res = pdo_update('zh_jdgjb_room', $data, array('id' =>$_GPC['room_id']));
  1313. if($res){
  1314. echo '1';
  1315. }else{
  1316. echo '2';
  1317. }
  1318. }
  1319. //获取15天放价
  1320. public function doPageGetMonthCost(){
  1321. global $_W, $_GPC;
  1322. $rid=$_GPC['room_id'];
  1323. $dt_start = strtotime(date('Y-m-d'));
  1324. $dt_end = strtotime(date("Y-m-d",strtotime("+15 day")));
  1325. $pricelist=array();
  1326. $i=0;
  1327. while ($dt_start<$dt_end){
  1328. $dateday=$dt_start;
  1329. $res1=pdo_get('zh_jdgjb_roomprice',array('rid'=>$rid,'dateday'=>$dateday));
  1330. $pricelist[$i]['dateday']=date('m月d日',$dateday);
  1331. if($res1['mprice']){
  1332. $pricelist[$i]['mprice']=$res1['mprice'];
  1333. }else{
  1334. $mprice=pdo_getcolumn('zh_jdgjb_room',array('id'=>$rid),'price');
  1335. $pricelist[$i]['mprice']=$mprice;
  1336. }
  1337. $dt_start = strtotime('+1 day',$dt_start);
  1338. $i++;
  1339. }
  1340. echo json_encode($pricelist);
  1341. }
  1342. //获取15天房量
  1343. public function doPageGetMonthNum(){
  1344. global $_W, $_GPC;
  1345. $rid=$_GPC['room_id'];
  1346. $dt_start = strtotime(date('Y-m-d'));
  1347. $dt_end = strtotime(date("Y-m-d",strtotime("+15 day")));
  1348. $numlist=array();
  1349. $i=0;
  1350. while ($dt_start<$dt_end){
  1351. $dateday=$dt_start;
  1352. $res1=pdo_get('zh_jdgjb_roomnum',array('rid'=>$rid,'dateday'=>$dateday));
  1353. $numlist[$i]['dateday']=date('m月d日',$dateday);
  1354. if($res1){
  1355. $numlist[$i]['nums']=$res1['nums'];
  1356. }else{
  1357. $mprice=pdo_getcolumn('zh_jdgjb_room',array('id'=>$rid),'total_num');
  1358. $numlist[$i]['nums']=$mprice;
  1359. }
  1360. $dt_start = strtotime('+1 day',$dt_start);
  1361. $i++;
  1362. }
  1363. echo json_encode($numlist);
  1364. }
  1365. //删除房间
  1366. public function doPageDeleteRoom(){
  1367. global $_W, $_GPC;
  1368. $res=pdo_delete('zh_jdgjb_room',array('id'=>$_GPC['room_id']));
  1369. if($res){
  1370. echo '1';
  1371. }else{
  1372. echo'2';
  1373. }
  1374. }
  1375. //房间上下架
  1376. public function doPageChangeRoom(){
  1377. global $_W, $_GPC;
  1378. $res=pdo_update('zh_jdgjb_room',array('state'=>$_GPC['state']),array('id'=>$_GPC['room_id']));
  1379. if($res){
  1380. echo '1';
  1381. }else{
  1382. echo'2';
  1383. }
  1384. }
  1385. //修改价格
  1386. public function doPageEditRoomPrice(){
  1387. global $_W, $_GPC;
  1388. $data['dateday']=strtotime(trim($_GPC['dateday']));
  1389. $data['mprice']=trim($_GPC['price']);
  1390. $data['rid']=trim($_GPC['room_id']);
  1391. $res=pdo_get('zh_jdgjb_roomprice',array('rid'=>$data['rid'],'dateday'=>$data['dateday']));
  1392. if(!$res['id']){
  1393. $rst=pdo_insert('zh_jdgjb_roomprice',$data);
  1394. }else{
  1395. $rst=pdo_update('zh_jdgjb_roomprice',array('mprice'=>$data['mprice']),array('id'=>$res['id']));
  1396. }
  1397. if($rst){
  1398. echo '1';
  1399. }else{
  1400. echo '2';
  1401. }
  1402. }
  1403. //修改数量
  1404. public function doPageEditRoomNum(){
  1405. global $_W, $_GPC;
  1406. $data['dateday']=strtotime(trim($_GPC['dateday']));
  1407. $data['nums']=trim($_GPC['nums']);
  1408. $data['rid']=trim($_GPC['room_id']);
  1409. $res=pdo_get('zh_jdgjb_roomnum',array('rid'=>$data['rid'],'dateday'=>$data['dateday']));
  1410. if(!$res['id']){
  1411. $rst=pdo_insert('zh_jdgjb_roomnum',$data);
  1412. }else{
  1413. $rst=pdo_update('zh_jdgjb_roomnum',array('nums'=>$data['nums']),array('id'=>$res['id']));
  1414. }
  1415. if($rst){
  1416. echo '1';
  1417. }else{
  1418. echo '2';
  1419. }
  1420. }
  1421. //可提现金额
  1422. public function doPageTxMoney(){
  1423. global $_W, $_GPC;
  1424. $data2[':seller_id']=$_GPC['seller_id'];
  1425. $data2[':uniacid']=$_W['uniacid'];
  1426. //总营业额
  1427. $totalsql=" select sum(total_cost) as total_money, sum(ytyj_cost) as yj_money from".tablename('zh_jdgjb_order')." where uniacid=:uniacid and seller_id=:seller_id and status in (4,5,8) and type !=3 ";
  1428. $totalmoney=pdo_fetch($totalsql,$data2);
  1429. $sql2 = "select sum(tx_cost) as total from " . tablename("zh_jdgjb_withdrawal")." WHERE seller_id=:seller_id and state in (1,2) and uniacid=:uniacid ";
  1430. $total2 = pdo_fetch($sql2,$data2);//已提现金额
  1431. $ktxcost=$totalmoney['total_money']-$totalmoney['yj_money']-$total2['total'];
  1432. echo $ktxcost;
  1433. }
  1434. //保存提现申请
  1435. public function doPageSaveTxApply(){
  1436. global $_W, $_GPC;
  1437. $data2[':seller_id']=$_GPC['seller_id'];
  1438. $data2[':uniacid']=$_W['uniacid'];
  1439. //总营业额
  1440. $totalsql=" select sum(total_cost) as total_money, sum(ytyj_cost) as yj_money from".tablename('zh_jdgjb_order')." where uniacid=:uniacid and seller_id=:seller_id and status in (4,5,8) and type !=3 ";
  1441. $totalmoney=pdo_fetch($totalsql,$data2);
  1442. $sql2 = "select sum(tx_cost) as total from " . tablename("zh_jdgjb_withdrawal")." WHERE seller_id=:seller_id and state in (1,2) and uniacid=:uniacid ";
  1443. $total2 = pdo_fetch($sql2,$data2);//已提现金额
  1444. $ktxcost=$totalmoney['total_money']-$totalmoney['yj_money']-$total2['total'];
  1445. if($_GPC['tx_cost']>$ktxcost){
  1446. echo 2;exit();
  1447. }
  1448. $data['sj_cost']=$_GPC['sj_cost'];
  1449. $data['seller_id']=$_GPC['seller_id'];
  1450. $data['name']=$_GPC['name'];
  1451. $data['username']=$_GPC['username'];
  1452. $data['state']=1;
  1453. $data['tx_cost']=$_GPC['tx_cost'];
  1454. $data['uniacid']=$_W['uniacid'];
  1455. $data['time']=date("Y-m-d H:i:s");
  1456. $res=pdo_insert('zh_jdgjb_withdrawal',$data);
  1457. if($res){
  1458. echo '1';
  1459. }else{
  1460. echo '2';
  1461. }
  1462. }
  1463. //商家提现记录
  1464. public function doPageSellerTxList(){
  1465. global $_GPC, $_W;
  1466. $pageindex = max(1, intval($_GPC['page']));
  1467. $pagesize=10;
  1468. $data[':uniacid']=$_W['uniacid'];
  1469. $data[':seller_id']=$_GPC['seller_id'];
  1470. $where=' WHERE uniacid=:uniacid and seller_id=:seller_id and is_delete=1';
  1471. $sql="SELECT * FROM ".tablename('zh_jdgjb_withdrawal') . $where." ORDER BY time DESC";
  1472. $select_sql=$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
  1473. $list=pdo_fetchall($select_sql,$data);
  1474. echo json_encode($list);
  1475. }
  1476. //回复评价
  1477. public function doPageReplyAssess(){
  1478. global $_W, $_GPC;
  1479. $data['reply']=$_GPC['reply'];
  1480. $data['status']=2;
  1481. $data['reply_time']=time();
  1482. $res=pdo_update('zh_jdgjb_assess',$data,array('id'=>$_GPC['assess_id']));
  1483. if($res){
  1484. echo '1';
  1485. }else{
  1486. echo '2';
  1487. }
  1488. }
  1489. ///////////////////以下分销
  1490. //分销设置
  1491. public function doPageGetFxSet(){
  1492. global $_W, $_GPC;
  1493. $res=pdo_get('zh_jdgjb_fxset',array('uniacid'=>$_W['uniacid']));
  1494. echo json_encode($res);
  1495. }
  1496. //申请分销商
  1497. public function doPageDistribution(){
  1498. global $_W, $_GPC;
  1499. pdo_delete('zh_jdgjb_distribution',array('user_id'=>$_GPC['user_id']));
  1500. $set=pdo_get('zh_jdgjb_fxset',array('uniacid'=>$_W['uniacid']));
  1501. $data['user_id']=$_GPC['user_id'];
  1502. $data['user_name']=$_GPC['user_name'];
  1503. $data['user_tel']=$_GPC['user_tel'];
  1504. $data['time']=time();
  1505. if($set['is_fx']==1){
  1506. $data['state']=1;
  1507. }else{
  1508. $data['state']=2;
  1509. }
  1510. $data['uniacid']=$_W['uniacid'];
  1511. $res=pdo_insert('zh_jdgjb_distribution',$data);
  1512. $sq_id=pdo_insertid();
  1513. if($res){
  1514. $fx=pdo_get('zh_jdgjb_fxuser',array('fx_user'=>$_GPC['user_id']));
  1515. if($set['is_fx']==1 and !$fx){
  1516. pdo_insert("zh_jdgjb_fxuser",array('user_id'=>0,'fx_user'=>$_GPC['user_id'],'time'=>time()));
  1517. }
  1518. echo $sq_id;
  1519. }else{
  1520. echo '申请失败!';
  1521. }
  1522. }
  1523. //查看我的上线
  1524. public function doPageMySx(){
  1525. global $_W, $_GPC;
  1526. $sql="select a.* ,b.name from " . tablename("zh_jdgjb_fxuser") . " a" . " left join " . tablename("zh_jdgjb_user") . " b on b.id=a.user_id WHERE a.fx_user=:fx_user ";
  1527. $res=pdo_fetch($sql,array(':fx_user'=>$_GPC['user_id']));
  1528. echo json_encode($res);
  1529. }
  1530. //查看我的申请
  1531. public function doPageMyDistribution(){
  1532. global $_W, $_GPC;
  1533. $res=pdo_get('zh_jdgjb_distribution',array('user_id'=>$_GPC['user_id']));
  1534. echo json_encode($res);
  1535. }
  1536. //绑定分销商
  1537. public function doPageBinding(){
  1538. global $_W, $_GPC;
  1539. $res=pdo_get('zh_jdgjb_fxuser',array('fx_user'=>$_GPC['fx_user']));//已绑定
  1540. $res2=pdo_get('zh_jdgjb_fxuser',array('user_id'=>$_GPC['fx_user'],'fx_user'=>$_GPC['user_id']));//已绑定成下线
  1541. if($_GPC['user_id']==$_GPC['fx_user']){
  1542. echo '自己不能绑定自己';
  1543. }elseif($res || $res2){
  1544. echo '不能重复绑定';
  1545. }else{
  1546. $res3=pdo_insert('zh_jdgjb_fxuser',array('user_id'=>$_GPC['user_id'],'fx_user'=>$_GPC['fx_user'],'time'=>time()));
  1547. if($res3){
  1548. echo '1';
  1549. }else{
  1550. echo '2';
  1551. }
  1552. }
  1553. }
  1554. //我的二维码
  1555. public function doPageMyCode(){
  1556. global $_W, $_GPC;
  1557. function getCoade($user_id){
  1558. function getaccess_token(){
  1559. global $_W, $_GPC;
  1560. $res=pdo_get('zh_jdgjb_system',array('uniacid' => $_W['uniacid']));
  1561. $appid=$res['appid'];
  1562. $secret=$res['appsecret'];
  1563. // $appid="wx80fa1d36c435231a";
  1564. // $secret="9bb4735bd092f092477049bfd7e183f8";
  1565. $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret."";
  1566. $ch = curl_init();
  1567. curl_setopt($ch, CURLOPT_URL,$url);
  1568. curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
  1569. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
  1570. $data = curl_exec($ch);
  1571. curl_close($ch);
  1572. $data = json_decode($data,true);
  1573. return $data['access_token'];
  1574. }
  1575. function set_msg($user_id){
  1576. $access_token = getaccess_token();
  1577. $data2=array(
  1578. "scene"=>$user_id,
  1579. // /"page"=>"zh_dianc/pages/info/info",
  1580. "width"=>100
  1581. );
  1582. $data2 = json_encode($data2);
  1583. $url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=".$access_token."";
  1584. $ch = curl_init();
  1585. curl_setopt($ch, CURLOPT_URL,$url);
  1586. curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
  1587. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
  1588. curl_setopt($ch, CURLOPT_POST,1);
  1589. curl_setopt($ch, CURLOPT_POSTFIELDS,$data2);
  1590. $data = curl_exec($ch);
  1591. curl_close($ch);
  1592. return $data;
  1593. }
  1594. $img=set_msg($user_id);
  1595. $img=base64_encode($img);
  1596. return $img;
  1597. }
  1598. $base64_image_content = "data:image/jpeg;base64," . getCoade($_GPC['user_id']);
  1599. if (preg_match('/^(data:\s*image\/(\w+);base64,)/', $base64_image_content, $result)) {
  1600. $type = $result[2];
  1601. $new_file = IA_ROOT . "/addons/zh_jdgjb/img/";
  1602. if (!file_exists($new_file)) {
  1603. //检查是否有该文件夹,如果没有就创建,并给予最高权限
  1604. mkdir($new_file, 0777);
  1605. }
  1606. $wname = "{$_GPC['user_id']}" . ".{$type}";
  1607. //$wname="1511.jpeg";
  1608. $new_file = $new_file . $wname;
  1609. file_put_contents($new_file, base64_decode(str_replace($result[1], '', $base64_image_content)));
  1610. }
  1611. echo $_W['siteroot'] . "addons/zh_jdgjb/img/" . $wname;
  1612. }
  1613. //查看我的团队
  1614. public function doPageMyTeam(){
  1615. global $_W, $_GPC;
  1616. $sql="select a.* ,b.name ,b.img from " . tablename("zh_jdgjb_fxuser") . " a" . " left join " . tablename("zh_jdgjb_user") . " b on b.id=a.fx_user WHERE a.user_id=:user_id order by id DESC";
  1617. $res=pdo_fetchall($sql,array(':user_id'=>$_GPC['user_id']));
  1618. $res2=array();
  1619. for($i=0;$i<count($res);$i++){
  1620. $sql2="select a.* ,b.name ,b.img from " . tablename("zh_jdgjb_fxuser") . " a" . " left join " . tablename("zh_jdgjb_user") . " b on b.id=a.fx_user WHERE a.user_id=:user_id order by id DESC";
  1621. $res3=pdo_fetchall($sql2,array(':user_id'=>$res[$i]['fx_user']));
  1622. $res2[]=$res3;
  1623. }
  1624. $res4=array();
  1625. for($k=0;$k<count($res2);$k++){
  1626. for($j=0;$j<count($res2[$k]);$j++){
  1627. $res4[]=$res2[$k][$j];
  1628. }
  1629. }
  1630. $data['one']=$res;
  1631. $data['two']=$res4;
  1632. echo json_encode($data);
  1633. }
  1634. //佣金统计
  1635. public function doPageCountCommission(){
  1636. global $_W, $_GPC;
  1637. $sql2="select sum(case when state=1 then money else 0 end ) as dj ,sum( case when state=2 then money else 0 end ) as yx from ".tablename('zh_jdgjb_earnings')." where uniacid=:uniacid and user_id=:user_id ";
  1638. $money=pdo_fetch($sql2,array('uniacid'=>$_W['uniacid'],':user_id'=>$_GPC['user_id']));
  1639. $sql3=" select ifnull(sum(tx_cost),0) as tx_money from ".tablename('zh_jdgjb_commission_withdrawal')." where user_id=:user_id and state in (1,2)";
  1640. $ytx_money=pdo_fetch($sql3,array(':user_id'=>$_GPC['user_id']));
  1641. $commission['ktx']= number_format($money['yx']-$ytx_money['tx_money'],2);
  1642. $commission['dj']= number_format($money['dj'],2);
  1643. $commission['ytx']= number_format($ytx_money['tx_money'],2);
  1644. $commission['lj']= number_format($money['yx']+$commission['dj'],2);
  1645. echo json_encode($commission);
  1646. }
  1647. //佣金明细
  1648. public function doPageYjlist(){
  1649. global $_GPC, $_W;
  1650. $pageindex = max(1, intval($_GPC['page']));
  1651. $pagesize=30;
  1652. $data[':user_id']=$_GPC['user_id'];
  1653. $sql=" select id,money,note,time from ".tablename('zh_jdgjb_earnings')." where user_id=:user_id and state=2 union all select id,tx_cost as money ,note,time from".tablename('zh_jdgjb_commission_withdrawal')." where user_id=:user_id order by time desc";
  1654. $select_sql=$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
  1655. $list=pdo_fetchall($sql,$data);
  1656. echo json_encode($list);
  1657. }
  1658. //佣金提现设置
  1659. public function doPageGetYjTxSet(){
  1660. global $_GPC, $_W;
  1661. $res=pdo_get('zh_jdgjb_fxtxset',array('uniacid'=>$_W['uniacid']));
  1662. echo json_encode($res);
  1663. }
  1664. //佣金提现
  1665. public function doPageYjtx(){
  1666. global $_W, $_GPC;
  1667. $data['tx_cost']=$_GPC['tx_cost'];
  1668. $data['sj_cost']=$_GPC['sj_cost'];
  1669. $data['account']=$_GPC['account'];
  1670. $data['user_name']=$_GPC['user_name'];
  1671. $data['state']=1;
  1672. $data['time']=time();
  1673. $data['uniacid']=$_W['uniacid'];
  1674. $data['user_id']=$_GPC['user_id'];
  1675. $data['note']='提现';
  1676. $res=pdo_insert('zh_jdgjb_commission_withdrawal',$data);
  1677. if($res){
  1678. echo '1';
  1679. }else{
  1680. echo '2';
  1681. }
  1682. }
  1683. //完善信息
  1684. public function doPageRenewUser(){
  1685. global $_W, $_GPC;
  1686. $data['tel']=$_GPC['tel'];
  1687. $data['zs_name']=$_GPC['zs_name'];
  1688. $data['type']=2;
  1689. $data['number']=substr("00000000".$_GPC['user_id'], -8);
  1690. $res=pdo_update('zh_jdgjb_user',$data,array('id'=>$_GPC['user_id']));
  1691. if($res){
  1692. echo '1';
  1693. }else{
  1694. echo '2';
  1695. }
  1696. }
  1697. //累计消费
  1698. public function doPageMyCost(){
  1699. global $_W, $_GPC;
  1700. $total=pdo_get('zh_jdgjb_order', array('user_id'=>$_GPC['user_id'],'status '=>array(4,5,8)), array('sum(total_cost) as total_money','sum(ytyj_cost) as yt_money'));
  1701. echo json_encode($total['total_money']-$total['yt_money']);
  1702. }
  1703. //订单二维码
  1704. public function doPageOrderCode(){
  1705. global $_W, $_GPC;
  1706. function getCoade($order_id){
  1707. function getaccess_token(){
  1708. global $_W, $_GPC;
  1709. $res=pdo_get('zh_jdgjb_system',array('uniacid' => $_W['uniacid']));
  1710. $appid=$res['appid'];
  1711. $secret=$res['appsecret'];
  1712. // $appid="wx80fa1d36c435231a";
  1713. // $secret="9bb4735bd092f092477049bfd7e183f8";
  1714. $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret."";
  1715. $ch = curl_init();
  1716. curl_setopt($ch, CURLOPT_URL,$url);
  1717. curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
  1718. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
  1719. $data = curl_exec($ch);
  1720. curl_close($ch);
  1721. $data = json_decode($data,true);
  1722. return $data['access_token'];
  1723. }
  1724. function set_msg($order_id){
  1725. $access_token = getaccess_token();
  1726. $data2=array(
  1727. "scene"=>$order_id,
  1728. "page"=>"zh_jdgjb/pages/logs/Workbench",
  1729. "width"=>100
  1730. );
  1731. $data2 = json_encode($data2);
  1732. $url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=".$access_token."";
  1733. $ch = curl_init();
  1734. curl_setopt($ch, CURLOPT_URL,$url);
  1735. curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
  1736. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
  1737. curl_setopt($ch, CURLOPT_POST,1);
  1738. curl_setopt($ch, CURLOPT_POSTFIELDS,$data2);
  1739. $data = curl_exec($ch);
  1740. curl_close($ch);
  1741. return $data;
  1742. }
  1743. $img=set_msg($order_id);
  1744. $img=base64_encode($img);
  1745. return $img;
  1746. }
  1747. echo getCoade($_GPC['order_id']);
  1748. }
  1749. //二维码确认入住
  1750. public function doPageSmRz(){
  1751. global $_W, $_GPC;
  1752. $orderInfo=pdo_get('zh_jdgjb_order',array('id'=>$_GPC['order_id']),'seller_id');
  1753. if($orderInfo['seller_id']==$_GPC['seller_id']){
  1754. $res=pdo_update('zh_jdgjb_order',array('status'=>5),array('id'=>$_GPC['order_id']));
  1755. if($res){
  1756. echo '1';
  1757. }else{
  1758. echo'2';
  1759. }
  1760. }else{
  1761. echo '没有核销权限';
  1762. }
  1763. }
  1764. //押金退款
  1765. public function doPageYjRefund(){
  1766. global $_W, $_GPC;
  1767. $money=$_GPC['money']*100;//退款金额
  1768. $order_id=$_GPC['order_id'];
  1769. include_once IA_ROOT . '/addons/zh_jdgjb/cert/WxPay.Api.php';
  1770. load()->model('account');
  1771. load()->func('communication');
  1772. $refund_order =pdo_get('zh_jdgjb_order',array('id'=>$order_id));
  1773. $WxPayApi = new WxPayApi();
  1774. $input = new WxPayRefund();
  1775. $path_cert = IA_ROOT . "/addons/zh_jdgjb/cert/".'apiclient_cert_' .$_W['uniacid'] . '.pem';
  1776. $path_key = IA_ROOT . "/addons/zh_jdgjb/cert/".'apiclient_key_' . $_W['uniacid'] . '.pem';
  1777. $account_info = $_W['account'];
  1778. $res=pdo_get('zh_jdgjb_system',array('uniacid'=>$_W['uniacid']));
  1779. $appid=$res['appid'];
  1780. $key=$res['wxkey'];
  1781. $mchid=$res['mchid'];
  1782. $out_trade_no=$refund_order['out_trade_no'];
  1783. $fee = $refund_order['total_cost'] * 100;
  1784. $input->SetAppid($appid);
  1785. $input->SetMch_id($mchid);
  1786. $input->SetOp_user_id($mchid);
  1787. $input->SetRefund_fee($money);
  1788. $input->SetTotal_fee($fee);
  1789. // $input->SetTransaction_id($refundid);
  1790. $input->SetOut_refund_no($refund_order['order_no']);
  1791. $input->SetOut_trade_no($out_trade_no);
  1792. $result = $WxPayApi->refund($input, 6, $path_cert, $path_key, $key);
  1793. if ($result['result_code'] == 'SUCCESS') {//退款成功
  1794. //更改订单操作
  1795. pdo_update('zh_jdgjb_order',array('ytyj_cost +='=>($money/100)),array('id'=>$order_id));
  1796. return '1';
  1797. }else{
  1798. return '2';
  1799. }
  1800. }
  1801. //充值活动
  1802. public function doPageCzhd(){
  1803. global $_W, $_GPC;
  1804. $res=pdo_getall('zh_jdgjb_czhd',array('uniacid'=>$_W['uniacid']),array(),'','full DESC');
  1805. echo json_encode($res);
  1806. }
  1807. //充值支付
  1808. public function doPagePay2(){
  1809. global $_W, $_GPC;
  1810. include IA_ROOT.'/addons/zh_jdgjb/wxpay.php';
  1811. $res=pdo_get('zh_jdgjb_system',array('uniacid'=>$_W['uniacid']));
  1812. $order=pdo_get('zh_jdgjb_recharge',array('id'=>$_GPC['cz_id']));
  1813. $appid=$res['appid'];
  1814. $openid=$_GPC['openid'];//oQKgL0ZKHwzAY-KhiyEEAsakW5Zg
  1815. $mch_id=$res['mchid'];
  1816. $key=$res['wxkey'];
  1817. $out_trade_no = $order['out_trade_no'];
  1818. $root=$_W['siteroot'];
  1819. //pdo_update('zh_jdgjb_recharge',array('out_trade_no'=>$out_trade_no),array('id'=>$_GPC['cz_id']));
  1820. $total_fee =$order['cz_money'];
  1821. if(empty($total_fee))
  1822. {
  1823. $body = "订单付款";
  1824. $total_fee = floatval(99*100);
  1825. }else{
  1826. $body = "订单付款";
  1827. $total_fee = floatval($total_fee*100);
  1828. }
  1829. $weixinpay = new WeixinPay($appid,$openid,$mch_id,$key,$out_trade_no,$body,$total_fee,$root);
  1830. $return=$weixinpay->pay();
  1831. echo json_encode($return);
  1832. }
  1833. //充值
  1834. public function doPageSaveRecharge(){
  1835. global $_W, $_GPC;
  1836. $data['cz_money']=$_GPC['cz_money'];
  1837. $data['zs_money']=$_GPC['zs_money'];
  1838. $data['out_trade_no']=time().rand(1000,9999).$_GPC['user_id'];
  1839. $data['user_id']=$_GPC['user_id'];
  1840. $data['state']=1;
  1841. $data['note']='在线充值';
  1842. $data['time']=time();
  1843. $data['uniacid']=$_W['uniacid'];
  1844. $res2=pdo_insert('zh_jdgjb_recharge',$data);
  1845. $cz_id=pdo_insertid();
  1846. if($res2){
  1847. echo $cz_id;
  1848. }else{
  1849. echo '2';
  1850. }
  1851. }
  1852. //余额明细
  1853. public function doPageYelist(){
  1854. global $_GPC, $_W;
  1855. $pageindex = max(1, intval($_GPC['page']));
  1856. $pagesize=30;
  1857. $data[':user_id']=$_GPC['user_id'];
  1858. $sql=" select id,cz_money,zs_money,note,time from ".tablename('zh_jdgjb_recharge')." where user_id=:user_id and state=2 ";
  1859. $select_sql=$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
  1860. $list=pdo_fetchall($sql,$data);
  1861. echo json_encode($list);
  1862. }
  1863. //入住改变
  1864. public function doPageUpdRz(){
  1865. global $_GPC, $_W;
  1866. function getLevel($members,$count){
  1867. for($i=0;$i<count($members);$i++){
  1868. if($count['count']>=$members[$i]['value']){
  1869. return $members[$i]['id'];
  1870. }
  1871. if($count['count']<$members[$i]['value']&&$count['count']>$members[$i+1]['value']){
  1872. return $members[$i+1]['id'];
  1873. }
  1874. }
  1875. }
  1876. function getScore($order_id){
  1877. global $_W, $_GPC;
  1878. $orderInfo=pdo_get('zh_jdgjb_order',array('id'=>$order_id));
  1879. $scoreInfo=pdo_get('zh_jdgjb_system',array('uniacid'=>$_W['uniacid']));
  1880. $score= floor($orderInfo['dis_cost']*$scoreInfo['xf_score']);
  1881. return $score;
  1882. }
  1883. function saveScore($order_id,$user_id,$score){
  1884. global $_W, $_GPC;
  1885. $data['user_id']=$user_id;
  1886. $data['order_id']=$order_id;
  1887. $data['score']=$score;
  1888. $data['note']='购物所得';
  1889. $data['time']=time();
  1890. $data['uniacid']=$_W['uniacid'];
  1891. $rst=pdo_insert('zh_jdgjb_score',$data);
  1892. return $rst;
  1893. }
  1894. function roomNum($order_id){
  1895. global $_W, $_GPC;
  1896. $order=pdo_get('zh_jdgjb_order',array('id'=>$order_id));
  1897. //修改房间数量
  1898. $dt_start = strtotime(substr($order['arrival_time'],0,10));
  1899. $dt_end = strtotime(substr($order['departure_time'],0,10));
  1900. while ($dt_start<$dt_end){
  1901. $dateday=$dt_start;
  1902. $res=pdo_get('zh_jdgjb_roomnum',array('rid'=>$order['room_id'],'dateday'=>$dateday));
  1903. if($res['id']){
  1904. $nums=$res['nums']-$order['num'];
  1905. pdo_update('zh_jdgjb_roomnum',array('nums'=>$nums),array('rid'=>$order['room_id'],'dateday'=>$dateday));
  1906. }else{
  1907. $uniacid=$_W['uniacid'];
  1908. $roomArr=pdo_get('zh_jdgjb_room',array('id'=>$order['room_id'],'uniacid'=>$order['uniacid']),array('total_num','id'));
  1909. $nums=$roomArr['total_num']-$order['num'];
  1910. pdo_insert('zh_jdgjb_roomnum',array('nums'=>$nums,'rid'=>$roomArr['id'],'dateday'=>$dateday));
  1911. }
  1912. $dt_start = strtotime('+1 day',$dt_start);
  1913. }
  1914. }
  1915. $type=pdo_get('zh_jdgjb_system',array('uniacid'=>$_W['uniacid']),'open_member');
  1916. $order=pdo_get('zh_jdgjb_order',array('id'=>$_GPC['id']));
  1917. if($type['open_member']==1){
  1918. //获取用户消费金额
  1919. $count=pdo_get('zh_jdgjb_order', array('user_id'=>$order['user_id'],'status'=>5), array('sum(dis_cost) as count'));
  1920. $members=pdo_getall('zh_jdgjb_level',array('uniacid'=>$_W['uniacid']),array() , '' , 'value DESC');
  1921. $level_id= getLevel($members,$count);
  1922. }
  1923. $score=getScore($_GPC['id']);
  1924. $rst=saveScore($_GPC['id'],$order['user_id'],$score);
  1925. if($rst){
  1926. pdo_update('zh_jdgjb_user',array('score +='=>$score),array('id'=>$order['user_id']));
  1927. }
  1928. if($level_id){
  1929. //更改会员等级
  1930. pdo_update('zh_jdgjb_user',array('level_id'=>$level_id,'type'=>2),array('id'=>$order['user_id']));
  1931. //echo $level_id;
  1932. }
  1933. if($order['type']==3){
  1934. roomNum($_GPC['id']);
  1935. }
  1936. //更改拥金
  1937. pdo_update('zh_jdgjb_earnings',array('state'=>2),array('order_id'=>$_GPC['id']));
  1938. }
  1939. public function doPageAliyun($phone,$code,$tpl_id) {
  1940. global $_W, $_GPC;
  1941. require_once dirname(__DIR__) . "/zh_jdgjb/SignatureHelper.php";
  1942. $sms=pdo_get('zh_jdgjb_system',array('uniacid'=>$_W['uniacid']));
  1943. // echo $code;die;
  1944. $params = array ();
  1945. // *** 需用户填写部分 ***
  1946. // fixme 必填:是否启用https
  1947. $security = false;
  1948. // fixme 必填: 请参阅 https://ak-console.aliyun.com/ 取得您的AK信息
  1949. $accessKeyId = $sms['aliyun_appkey'];
  1950. $accessKeySecret = $sms['aliyun_appsecret'];
  1951. // fixme 必填: 短信接收号码
  1952. $params["PhoneNumbers"] = $phone;
  1953. // fixme 必填: 短信签名,应严格按"签名名称"填写,请参考: https://dysms.console.aliyun.com/dysms.htm#/develop/sign
  1954. $params["SignName"] = $sms['aliyun_sign'];
  1955. // fixme 必填: 短信模板Code,应严格按"模板CODE"填写, 请参考: https://dysms.console.aliyun.com/dysms.htm#/develop/template
  1956. $params["TemplateCode"] =$tpl_id;
  1957. // fixme 可选: 设置模板参数, 假如模板中存在变量需要替换则为必填项
  1958. $params['TemplateParam'] = Array (
  1959. "code" => $code,
  1960. );
  1961. // *** 需用户填写部分结束, 以下代码若无必要无需更改 ***
  1962. if(!empty($params["TemplateParam"]) && is_array($params["TemplateParam"])) {
  1963. $params["TemplateParam"] = json_encode($params["TemplateParam"], JSON_UNESCAPED_UNICODE);
  1964. }
  1965. // 初始化SignatureHelper实例用于设置参数,签名以及发送请求
  1966. $helper = new SignatureHelper();
  1967. // 此处可能会抛出异常,注意catch
  1968. $content = $helper->request(
  1969. $accessKeyId,
  1970. $accessKeySecret,
  1971. "dysmsapi.aliyuncs.com",
  1972. array_merge($params, array(
  1973. "RegionId" => "cn-hangzhou",
  1974. "Action" => "SendSms",
  1975. "Version" => "2017-05-25",
  1976. )),
  1977. $security
  1978. );
  1979. return $content;
  1980. }
  1981. public function doPageAliyun2($tel,$aliyun_appkey,$aliyun_appsecret,$aliyun_sign,$tpl_id) {
  1982. global $_W, $_GPC;
  1983. require_once dirname(__DIR__) . "/zh_jdgjb/SignatureHelper.php";
  1984. // echo $code;die;
  1985. $params = array ();
  1986. // *** 需用户填写部分 ***
  1987. // fixme 必填:是否启用https
  1988. $security = false;
  1989. // fixme 必填: 请参阅 https://ak-console.aliyun.com/ 取得您的AK信息
  1990. $accessKeyId = $aliyun_appkey;
  1991. $accessKeySecret = $aliyun_appsecret;
  1992. // fixme 必填: 短信接收号码
  1993. $params["PhoneNumbers"] = $tel;
  1994. // fixme 必填: 短信签名,应严格按"签名名称"填写,请参考: https://dysms.console.aliyun.com/dysms.htm#/develop/sign
  1995. $params["SignName"] =$aliyun_sign;
  1996. // fixme 必填: 短信模板Code,应严格按"模板CODE"填写, 请参考: https://dysms.console.aliyun.com/dysms.htm#/develop/template
  1997. $params["TemplateCode"] = $tpl_id;
  1998. // fixme 可选: 设置模板参数, 假如模板中存在变量需要替换则为必填项
  1999. // *** 需用户填写部分结束, 以下代码若无必要无需更改 ***
  2000. if(!empty($params["TemplateParam"]) && is_array($params["TemplateParam"])) {
  2001. $params["TemplateParam"] = json_encode($params["TemplateParam"], JSON_UNESCAPED_UNICODE);
  2002. }
  2003. // 初始化SignatureHelper实例用于设置参数,签名以及发送请求
  2004. $helper = new SignatureHelper();
  2005. // 此处可能会抛出异常,注意catch
  2006. $content = $helper->request(
  2007. $accessKeyId,
  2008. $accessKeySecret,
  2009. "dysmsapi.aliyuncs.com",
  2010. array_merge($params, array(
  2011. "RegionId" => "cn-hangzhou",
  2012. "Action" => "SendSms",
  2013. "Version" => "2017-05-25",
  2014. )),
  2015. $security
  2016. );
  2017. return $content;
  2018. }
  2019. function base64EncodeImage ($image_file) {
  2020. $base64_image = '';
  2021. $image_info = getimagesize($image_file);
  2022. $image_data = fread(fopen($image_file, 'r'), filesize($image_file));
  2023. $base64_image = chunk_split(base64_encode($image_data));
  2024. return $base64_image;
  2025. }
  2026. public function doPageTest2(){
  2027. global $_GPC, $_W;
  2028. require_once dirname(__DIR__) . "/zh_jdgjb/baiduSdk/AipFace.php";
  2029. $appId='16809002';
  2030. $apiKey='NkQDRqjKs7oH01rrqTuQez25';
  2031. $secretKey='B6lqYgOiew485z6kT7YctVggHRGHiePF';
  2032. $image=$this->base64EncodeImage(dirname(__DIR__) . "/zh_jdgjb/img/7.jpg");
  2033. $imageType='BASE64';
  2034. $data=[
  2035. [
  2036. 'image'=>'7020ad3c0fc764b00a760fcf91c6ce7b',
  2037. 'image_type'=>'FACE_TOKEN'
  2038. ],
  2039. [
  2040. 'image'=>$image,
  2041. 'image_type'=>$imageType
  2042. ]
  2043. ];
  2044. $client= new AipFace($appId,$apiKey,$secretKey);
  2045. $arr=$client->match($data);
  2046. return json_encode($arr);
  2047. $errno = 5;
  2048. $message = '返回消息';
  2049. $data = array();
  2050. return $this->result($errno, $message, $data);
  2051. }
  2052. public function doPageTest3(){
  2053. global $_GPC, $_W;
  2054. require_once dirname(__DIR__) . "/zh_jdgjb/distance/distance.php";
  2055. $circle =['center'=>['lng'=>'117.26714358070373','lat'=>'31.933753273109424'],'radius'=>'5'*1000];
  2056. $arr=[
  2057. ['category'=>1,
  2058. 'radius'=>2.00,
  2059. 'fee'=>5,
  2060. 'vertexes'=>[
  2061. 'lat'=>'31.934336',
  2062. 'lng'=>'117.26503'
  2063. ]
  2064. ],
  2065. ['category'=>1,
  2066. 'radius'=>15.00,
  2067. 'fee'=>10,
  2068. 'vertexes'=>[
  2069. 'lat'=>'31.934336',
  2070. 'lng'=>'117.26503'
  2071. ]
  2072. ],
  2073. ['category'=>2,
  2074. 'radius'=>0.00,
  2075. 'fee'=>20,
  2076. 'vertexes'=>[
  2077. [
  2078. 'lat'=>'31.901419208343',
  2079. 'lng'=>'117.26503'
  2080. ],
  2081. [
  2082. 'lat'=>'31.95502',
  2083. 'lng'=>'117.283'
  2084. ],
  2085. [
  2086. 'lat'=>'31.95502',
  2087. 'lng'=>'117.24706'
  2088. ],
  2089. [
  2090. 'lat'=>'31.99448561994',
  2091. 'lng'=>'117.18766516358'
  2092. ],
  2093. [
  2094. 'lat'=>'32.008318599485',
  2095. 'lng'=>'117.10080450684'
  2096. ],
  2097. [
  2098. 'lat'=>'31.891508803575',
  2099. 'lng'=>'117.23195379883'
  2100. ],
  2101. ]
  2102. ],
  2103. ];
  2104. $convert= new Convert();
  2105. foreach ($arr as $key => $value) {
  2106. if($value['category']==1){
  2107. $rst=$convert -> is_point_in_circle($value['vertexes'], $circle);
  2108. if($rst){
  2109. echo $value['fee'];die;
  2110. }
  2111. continue;
  2112. }
  2113. if($value['category']==2){
  2114. $rst=$convert -> is_point_in_polygon($circle['center'], $value['vertexes']);
  2115. if($rst){
  2116. echo $value['fee'];die;
  2117. }
  2118. continue;
  2119. }
  2120. echo '不在配送范围';die;
  2121. }
  2122. echo 6789;die;
  2123. /* $pts = [
  2124. ['lng'=>117.29673291016, 'lat'=>31.901419208343],
  2125. ['lng'=>117.283, 'lat'=>31.95502],
  2126. ['lng'=>117.24706, 'lat'=>31.95502],
  2127. ['lng'=>117.10080450684, 'lat'=>32.008318599485],
  2128. ['lng'=>117.23195379883, 'lat'=>31.891508803575],
  2129. ];*/
  2130. $point = ['lng'=>117.18766516358,'lat'=>31.99448561994];
  2131. $bool = $convert -> is_point_in_polygon($point,$pts);
  2132. var_dump($bool);die;
  2133. }
  2134. }