wxapp.php 78 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394
  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']=$_GPC['money'];
  406. $data['tel']=$_GPC['tel'];
  407. $data['name']=$_GPC['name'];
  408. $data['total_cost']=$_GPC['money'];
  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. $where.=" and is_out_time = :is_out_time";
  778. $data[':is_out_time'] = 1;
  779. $sql="select * from " . tablename("zh_jdgjb_order") .$where." order by id desc ";
  780. $select_sql=$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
  781. $list=pdo_fetchall($select_sql,$data);
  782. foreach($list as $key => $val){
  783. $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;
  784. $conf = pdo_get('zh_jdgjb_seller',array('id'=>$val['seller_id']));
  785. $list[$key]['re_pay_money'] = $conf['re_pay_money'];
  786. }
  787. echo json_encode($list);
  788. }
  789. //订单详情
  790. public function doPageOrderDetails(){
  791. global $_GPC, $_W;
  792. $res=pdo_get('zh_jdgjb_order',array('id'=>$_GPC['order_id']));
  793. if (time() > (strtotime($res['arrival_time']) - 43200)) {
  794. $res['can_refund'] = 0;
  795. } else {
  796. $res['can_refund'] = 1;
  797. }
  798. echo json_encode($res);
  799. }
  800. //取消订单
  801. public function doPageCancelOrder(){
  802. global $_GPC, $_W;
  803. $res=pdo_update('zh_jdgjb_order',array('status'=>3),array('id'=>$_GPC['order_id']));
  804. if($res){
  805. if($_GPC['hb_id']){//使用积分红包
  806. pdo_update('zh_jdgjb_jfhb',array('state'=>1),array('id'=>$_GPC['hb_id']));
  807. }
  808. echo '1';
  809. }else{
  810. echo '2';
  811. }
  812. }
  813. //申请退款
  814. public function doPageApplyOrder(){
  815. global $_GPC, $_W;
  816. $res=pdo_update('zh_jdgjb_order',array('status'=>6),array('id'=>$_GPC['order_id']));
  817. if($res){
  818. echo '1';
  819. }else{
  820. echo '2';
  821. }
  822. }
  823. //获取实时房价
  824. public function doPageGetRoomCost(){
  825. global $_W, $_GPC;
  826. $rid=$_GPC['room_id'];
  827. $dt_start = strtotime($_GPC['start']);
  828. $dt_end = strtotime($_GPC['end']);
  829. $pricelist=array();
  830. $i=0;
  831. while ($dt_start<$dt_end){
  832. $dateday=$dt_start;
  833. $res1=pdo_get('zh_jdgjb_roomprice',array('rid'=>$rid,'dateday'=>$dateday));
  834. $pricelist[$i]['dateday']=date('m月d日',$dateday);
  835. if($res1['mprice']){
  836. $pricelist[$i]['mprice']=$res1['mprice'];
  837. }else{
  838. $mprice=pdo_getcolumn('zh_jdgjb_room',array('id'=>$rid),'price');
  839. $pricelist[$i]['mprice']=$mprice;
  840. }
  841. $dt_start = strtotime('+1 day',$dt_start);
  842. $i++;
  843. }
  844. echo json_encode($pricelist);
  845. }
  846. //微信支付退款
  847. public function doPageRefund(){
  848. global $_W, $_GPC;
  849. include_once IA_ROOT . '/addons/zh_jdgjb/cert/WxPay.Api.php';
  850. load()->model('account');
  851. load()->func('communication');
  852. $refund_order =pdo_get('zh_jdgjb_order',array('id'=>$_GPC['order_id']));
  853. $WxPayApi = new WxPayApi();
  854. $input = new WxPayRefund();
  855. $path_cert = IA_ROOT . "/addons/zh_jdgjb/cert/".'apiclient_cert_' .$_W['uniacid'] . '.pem';
  856. $path_key = IA_ROOT . "/addons/zh_jdgjb/cert/".'apiclient_key_' . $_W['uniacid'] . '.pem';
  857. $account_info = $_W['account'];
  858. $res=pdo_get('zh_jdgjb_system',array('uniacid'=>$_W['uniacid']));
  859. $appid=$res['appid'];
  860. $key=$res['wxkey'];
  861. $mchid=$res['mchid'];
  862. $out_trade_no=$refund_order['out_trade_no'];
  863. $fee = $refund_order['total_cost'] * 100;
  864. $input->SetAppid($appid);
  865. $input->SetMch_id($mchid);
  866. $input->SetOp_user_id($mchid);
  867. $input->SetRefund_fee($fee);
  868. $input->SetTotal_fee($fee);
  869. // $input->SetTransaction_id($refundid);
  870. $input->SetOut_refund_no($refund_order['order_no']);
  871. $input->SetOut_trade_no($out_trade_no);
  872. $result = $WxPayApi->refund($input, 6, $path_cert, $path_key, $key);
  873. if ($result['result_code'] == 'SUCCESS') {//退款成功
  874. //更改订单操作
  875. pdo_update('zh_jdgjb_order',array('status'=>7),array('id'=>$_GPC['order_id']));
  876. echo '1';
  877. }else{
  878. echo $result['err_code_des'];
  879. }
  880. }
  881. public function doPageRefund2(){
  882. global $_W, $_GPC;
  883. include_once IA_ROOT . '/addons/zh_jdgjb/cert/WxPay.Api.php';
  884. load()->model('account');
  885. load()->func('communication');
  886. $refund_order =pdo_get('zh_jdgjb_order',array('id'=>$_GPC['order_id']));
  887. $WxPayApi = new WxPayApi();
  888. $input = new WxPayRefund();
  889. $path_cert = IA_ROOT . "/addons/zh_jdgjb/cert/".'apiclient_cert_' .$_W['uniacid'] . '.pem';
  890. $path_key = IA_ROOT . "/addons/zh_jdgjb/cert/".'apiclient_key_' . $_W['uniacid'] . '.pem';
  891. $account_info = $_W['account'];
  892. $res=pdo_get('zh_jdgjb_system',array('uniacid'=>$_W['uniacid']));
  893. $appid=$res['appid'];
  894. $key=$res['wxkey'];
  895. $mchid=$res['mchid'];
  896. $out_trade_no=$refund_order['out_trade_no'];
  897. $fee = $_GPC['total_cost'] * 100;
  898. $input->SetAppid($appid);
  899. $input->SetMch_id($mchid);
  900. $input->SetOp_user_id($mchid);
  901. $input->SetRefund_fee($fee);
  902. $input->SetTotal_fee($fee);
  903. // $input->SetTransaction_id($refundid);
  904. $input->SetOut_refund_no($refund_order['order_no']);
  905. $input->SetOut_trade_no($out_trade_no);
  906. $result = $WxPayApi->refund($input, 6, $path_cert, $path_key, $key);
  907. if ($result['result_code'] == 'SUCCESS') {//退款成功
  908. //更改订单操作
  909. pdo_update('zh_jdgjb_order',array('status'=>7),array('id'=>$_GPC['order_id']));
  910. echo '1';
  911. }else{
  912. echo $result['err_code_des'];
  913. }
  914. }
  915. //余额退款
  916. public function doPageYeRefund(){
  917. global $_W, $_GPC;
  918. $orderInfo=pdo_get('zh_jdgjb_order',array('id'=>$_GPC['order_id']));
  919. $data['user_id']=$orderInfo['user_id'];
  920. $data['cz_money']=$orderInfo['total_cost'];
  921. $data['note']='订单退款';
  922. $data['state']=2;
  923. $data['time']=time();
  924. $data['uniacid']=$_W['uniacid'];
  925. $res=pdo_insert('zh_jdgjb_recharge',$data);
  926. if($res){
  927. pdo_update('zh_jdgjb_order',array('status'=>7),array('id'=>$_GPC['order_id']));
  928. pdo_update('zh_jdgjb_user',array('balance +='=>$orderInfo['total_cost']),array('id'=>$orderInfo['user_id']));
  929. echo '1';
  930. }
  931. }
  932. //订房成功模板消息
  933. public function doPageMessage(){
  934. global $_W, $_GPC;
  935. function getaccess_token($_W){
  936. $res=pdo_get('zh_jdgjb_system',array('uniacid'=>$_W['uniacid']));
  937. $appid=$res['appid'];
  938. $secret=$res['appsecret'];
  939. $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret."";
  940. $ch = curl_init();
  941. curl_setopt($ch, CURLOPT_URL,$url);
  942. curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
  943. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
  944. $data = curl_exec($ch);
  945. curl_close($ch);
  946. $data = json_decode($data,true);
  947. return $data['access_token'];
  948. }
  949. //设置与发送模板信息
  950. function set_msg($_W){
  951. $access_token = getaccess_token($_W);
  952. $res=pdo_get('zh_jdgjb_system',array('uniacid'=>$_W['uniacid']));
  953. $sql="select * from " . tablename("zh_jdgjb_order")." WHERE id=:order_id ";
  954. $list=pdo_fetch($sql,array(':order_id'=>$_GET['order_id']));
  955. $time=date('Y-m-d H:i',$list['time']);
  956. $time1=substr($list['arrival_time'],0,10);
  957. $time2=substr($list['departure_time'],0,10);
  958. //下面是要填充模板的信息
  959. $formwork ='{
  960. "touser": "'.$_GET["openid"].'",
  961. "template_id": "'.$res["tid1"].'",
  962. "form_id":"'.$_GET['form_id'].'",
  963. "data": {
  964. "keyword1": {
  965. "value": "'.$list['seller_name'].'",
  966. "color": "#173177"
  967. },
  968. "keyword2": {
  969. "value": "'. $time.'",
  970. "color": "#173177"
  971. },
  972. "keyword3": {
  973. "value": "'.$list['dis_cost'].'",
  974. "color": "#173177"
  975. },
  976. "keyword4": {
  977. "value": "'.$list['seller_address'].'",
  978. "color": "#173177"
  979. },
  980. "keyword5": {
  981. "value": "'.$list['order_no'].'",
  982. "color": "#173177"
  983. },
  984. "keyword6": {
  985. "value": "'.$time1.'",
  986. "color": "#173177"
  987. },
  988. "keyword7": {
  989. "value": "'.$time2.'",
  990. "color": "#173177"
  991. },
  992. "keyword8": {
  993. "value": "'.$list['name'].'",
  994. "color": "#173177"
  995. },
  996. "keyword9": {
  997. "value": "'.$list['room_type'].'",
  998. "color": "#173177"
  999. }
  1000. }
  1001. }';
  1002. $url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=".$access_token."";
  1003. $ch = curl_init();
  1004. curl_setopt($ch, CURLOPT_URL,$url);
  1005. curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
  1006. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
  1007. curl_setopt($ch, CURLOPT_POST,1);
  1008. curl_setopt($ch, CURLOPT_POSTFIELDS,$formwork);
  1009. $data = curl_exec($ch);
  1010. curl_close($ch);
  1011. return $data;
  1012. }
  1013. echo set_msg($_W);
  1014. }
  1015. ////////////////////以下积分商城///////////////////////////
  1016. //分类列表
  1017. public function doPageJfTypeList(){
  1018. global $_W, $_GPC;
  1019. $res=pdo_getall('zh_jdgjb_jftype',array('uniacid'=>$_W['uniacid']),array(),'','num asc');
  1020. echo json_encode($res);
  1021. }
  1022. //商品列表
  1023. public function doPageJfGoodsList(){
  1024. global $_GPC, $_W;
  1025. $pageindex = max(1, intval($_GPC['page']));
  1026. $pagesize=10;
  1027. $data[':uniacid']=$_W['uniacid'];
  1028. $where=" where uniacid=:uniacid ";
  1029. if($_GPC['type_id']){
  1030. $where.=" and type_id=:type_id ";
  1031. $data[':type_id']=$_GPC['type_id'];
  1032. }
  1033. $sql="select * from " . tablename("zh_jdgjb_jfgoods") .$where." order by num asc ";
  1034. $select_sql=$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
  1035. $list=pdo_fetchall($select_sql,$data);
  1036. echo json_encode($list);
  1037. }
  1038. //商品详情
  1039. public function doPageGoodsDetails(){
  1040. global $_W, $_GPC;
  1041. $res=pdo_get('zh_jdgjb_jfgoods',array('id'=>$_GPC['id']));
  1042. echo json_encode($res);
  1043. }
  1044. //兑换商品
  1045. public function doPageExchange(){
  1046. global $_W, $_GPC;
  1047. $data['user_id']=$_GPC['user_id'];//用户id
  1048. $data['good_id']=$_GPC['good_id'];//商品id
  1049. $data['user_name']=$_GPC['user_name'];//用户名称
  1050. $data['user_tel']=$_GPC['user_tel'];//用户电话
  1051. $data['address']=$_GPC['address'];//地址
  1052. $data['integral']=$_GPC['integral'];//积分
  1053. $data['good_name']=$_GPC['good_name'];//商品名称
  1054. $data['good_img']=$_GPC['good_img'];//商品图片
  1055. $data['time']=date("Y-m-d H:i:s");
  1056. if($_GPC['type']==1){
  1057. $data['state']=2;
  1058. }else{
  1059. $data['state']=1;
  1060. }
  1061. $res=pdo_insert('zh_jdgjb_jfrecord',$data);
  1062. if($res){
  1063. pdo_update('zh_jdgjb_jfgoods',array('number -='=>1),array('id'=>$_GPC['good_id']));
  1064. if($_GPC['type']==1){//虚拟红包
  1065. $data2['money']=$_GPC['hb_money'];
  1066. $data2['user_id']=$_GPC['user_id'];
  1067. $data2['goods_id']=$_GPC['good_id'];;
  1068. $data2['time']=date('Y-m-d H:i:s');
  1069. $data2['uniacid']=$_W['uniacid'];
  1070. pdo_insert('zh_jdgjb_jfhb',$data2);
  1071. }
  1072. $data3['user_id']=$_GPC['user_id'];
  1073. $data3['goods_id']=$_GPC['good_id'];
  1074. $data3['score']=$_GPC['integral'];
  1075. $data3['note']='兑换商品';
  1076. $data3['type']=2;
  1077. $data3['time']=time();
  1078. $data3['uniacid']=$_W['uniacid'];
  1079. pdo_insert('zh_jdgjb_score',$data3);
  1080. pdo_update('zh_jdgjb_user',array('score -='=>$_GPC['integral']),array('id'=>$_GPC['user_id']));
  1081. echo '1';
  1082. }else{
  1083. echo '2';
  1084. }
  1085. }
  1086. //兑换明细
  1087. public function doPageDhmx(){
  1088. global $_W, $_GPC;
  1089. $pageindex = max(1, intval($_GPC['page']));
  1090. $pagesize=10;
  1091. $data[':user_id']=$_GPC['user_id'];
  1092. $where=" where user_id=:user_id ";
  1093. $sql="select * from " . tablename("zh_jdgjb_jfrecord") .$where." order by id desc ";
  1094. $select_sql=$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
  1095. $list=pdo_fetchall($select_sql,$data);
  1096. echo json_encode($list);
  1097. }
  1098. //我的积分明细
  1099. public function doPageMyScoreDetails(){
  1100. global $_GPC, $_W;
  1101. $pageindex = max(1, intval($_GPC['page']));
  1102. $pagesize=20;
  1103. $data[':uniacid']=$_W['uniacid'];
  1104. $data[':user_id']=$_GPC['user_id'];
  1105. $where=" where uniacid=:uniacid and user_id=:user_id ";
  1106. $sql="select * from " . tablename("zh_jdgjb_score") .$where." order by id desc ";
  1107. $select_sql=$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
  1108. $list=pdo_fetchall($select_sql,$data);
  1109. echo json_encode($list);
  1110. }
  1111. //我的可用红包
  1112. public function doPageMyHb(){
  1113. global $_GPC, $_W;
  1114. $pageindex = max(1, intval($_GPC['page']));
  1115. $pagesize=10;
  1116. $data[':uniacid']=$_W['uniacid'];
  1117. $data[':user_id']=$_GPC['user_id'];
  1118. $where=" where uniacid=:uniacid and user_id=:user_id and state=1";
  1119. $sql="select * from " . tablename("zh_jdgjb_jfhb") .$where." order by id desc ";
  1120. $select_sql=$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
  1121. $list=pdo_fetchall($select_sql,$data);
  1122. echo json_encode($list);
  1123. }
  1124. //获取实时房间数量
  1125. public function doPageGetRoomNum(){
  1126. global $_W, $_GPC;
  1127. $rid=$_GPC['room_id'];
  1128. $dt_start = strtotime($_GPC['start']);
  1129. $dt_end = strtotime($_GPC['end']);
  1130. $pricelist=array();
  1131. $i=0;
  1132. while ($dt_start<$dt_end){
  1133. $dateday=$dt_start;
  1134. $res1=pdo_get('zh_jdgjb_roomnum',array('rid'=>$rid,'dateday'=>$dateday));
  1135. $pricelist[$i]['dateday']=date('m月d日',$dateday);
  1136. if($res1){
  1137. $pricelist[$i]['nums']=$res1['nums'];
  1138. }else{
  1139. $mprice=pdo_getcolumn('zh_jdgjb_room',array('id'=>$rid),'total_num');
  1140. $pricelist[$i]['nums']=$mprice;
  1141. }
  1142. $dt_start = strtotime('+1 day',$dt_start);
  1143. $i++;
  1144. }
  1145. echo json_encode($pricelist);
  1146. }
  1147. //会员等级列表
  1148. public function doPageMemberList(){
  1149. global $_W, $_GPC;
  1150. $res=pdo_getall('zh_jdgjb_level',array('uniacid'=>$_W['uniacid']),array(),'','value asc');
  1151. echo json_encode($res);
  1152. }
  1153. /////////////////////////以下后台操作
  1154. ///
  1155. public function doPageHtLogin(){
  1156. global $_GPC, $_W;
  1157. load()->model('user');
  1158. $time=strtotime(date("Y-m-d"));
  1159. $mttime=strtotime(date("Y-m-d",strtotime("+1 day")));
  1160. $zttime=strtotime(date("Y-m-d",strtotime("-1 day")));
  1161. $month=strtotime(date("Y-m"));
  1162. $member = array();
  1163. $summary=array();
  1164. $member['username'] =$_GPC['username'];
  1165. $member['password'] = $_GPC['password'];
  1166. $record = user_single($member);
  1167. if(!empty($record)) {
  1168. $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']));
  1169. if (!empty($account)) {
  1170. $storeid = $account['storeid'];
  1171. $data[':uniacid']=$_W['uniacid'];
  1172. $data[':seller_id']=$storeid;
  1173. //获取酒店信息
  1174. $sellerInfo=pdo_get('zh_jdgjb_seller',array('id'=>$storeid),array('name','ewm_logo','ll_num'));
  1175. //今日订单
  1176. $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."";
  1177. $total=pdo_fetch($order,$data);
  1178. //今日销售额
  1179. $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."";
  1180. $jrmoney=pdo_fetch($moneysql,$data);
  1181. //本月销售额
  1182. $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;
  1183. $bymoney=pdo_fetch($bysql,$data);
  1184. //订单统计
  1185. $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 ";
  1186. $tjorder=pdo_fetch($sql2,$data);
  1187. //昨日营业额
  1188. $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."";
  1189. $zrmoney=pdo_fetch($zrsql,$data);
  1190. //总营业额
  1191. $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) ";
  1192. $totalmoney=pdo_fetch($totalsql,$data);
  1193. //var_dump($totalmoney['yj_money']);die;
  1194. $summary['seller_id']=$storeid;
  1195. $summary['seller_name']=$sellerInfo['name'];
  1196. $summary['seller_logo']=$sellerInfo['ewm_logo'];
  1197. $summary['ll_num']=$sellerInfo['ll_num'];
  1198. $summary['jrdd']=$total['total'];
  1199. $summary['jrxse']=$jrmoney['total_money']-$jrmoney['yj_money'];
  1200. $summary['byxse']=$bymoney['total_money']-$bymoney['yj_money'];
  1201. $summary['dzf']=$tjorder['dzf'];
  1202. $summary['ywc']=$tjorder['ywc'];
  1203. $summary['ytk']=$tjorder['ytk'];
  1204. $summary['zrxse']=$zrmoney['total_money']-$zrmoney['yj_money'];
  1205. $summary['zxse']=$totalmoney['total_money']-$totalmoney['yj_money'];
  1206. echo json_encode($summary);
  1207. } else {
  1208. echo '您的账号正在审核或是已经被系统禁止,请联系网站管理员解决!!!';
  1209. }
  1210. }else{
  1211. echo '账号或密码错误';
  1212. }
  1213. }
  1214. //商家微信登录
  1215. public function doPageStoreWxLogin(){
  1216. global $_GPC, $_W;
  1217. $res=pdo_get('zh_jdgjb_seller',array('user_id'=>$_GPC['user_id'],'state'=>2));
  1218. if($res){
  1219. $storeid=$res['id'];
  1220. $time=strtotime(date("Y-m-d"));
  1221. $mttime=strtotime(date("Y-m-d",strtotime("+1 day")));
  1222. $zttime=strtotime(date("Y-m-d",strtotime("-1 day")));
  1223. $month=strtotime(date("Y-m"));
  1224. $summary=array();
  1225. $data[':uniacid']=$_W['uniacid'];
  1226. $data[':seller_id']=$storeid;
  1227. //获取酒店信息
  1228. $sellerInfo=pdo_get('zh_jdgjb_seller',array('id'=>$storeid),array('name','ewm_logo','ll_num'));
  1229. //今日订单
  1230. $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."";
  1231. $total=pdo_fetch($order,$data);
  1232. //今日销售额
  1233. $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."";
  1234. $jrmoney=pdo_fetch($moneysql,$data);
  1235. //本月销售额
  1236. $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;
  1237. $bymoney=pdo_fetch($bysql,$data);
  1238. //订单统计
  1239. $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 ";
  1240. $tjorder=pdo_fetch($sql2,$data);
  1241. //昨日营业额
  1242. $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."";
  1243. $zrmoney=pdo_fetch($zrsql,$data);
  1244. //总营业额
  1245. $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) ";
  1246. $totalmoney=pdo_fetch($totalsql,$data);
  1247. //var_dump($totalmoney['yj_money']);die;
  1248. $summary['seller_id']=$storeid;
  1249. $summary['seller_name']=$sellerInfo['name'];
  1250. $summary['seller_logo']=$sellerInfo['ewm_logo'];
  1251. $summary['ll_num']=$sellerInfo['ll_num'];
  1252. $summary['jrdd']=$total['total'];
  1253. $summary['jrxse']=$jrmoney['total_money']-$jrmoney['yj_money'];
  1254. $summary['byxse']=$bymoney['total_money']-$bymoney['yj_money'];
  1255. $summary['dzf']=$tjorder['dzf'];
  1256. $summary['ywc']=$tjorder['ywc'];
  1257. $summary['ytk']=$tjorder['ytk'];
  1258. $summary['zrxse']=$zrmoney['total_money']-$zrmoney['yj_money'];
  1259. $summary['zxse']=$totalmoney['total_money']-$totalmoney['yj_money'];
  1260. echo json_encode($summary);
  1261. }else{
  1262. echo '您还不是管理员或在审核中';
  1263. }
  1264. }
  1265. //订单列表
  1266. public function doPageSellerOrderList(){
  1267. global $_GPC, $_W;
  1268. $pageindex = max(1, intval($_GPC['page']));
  1269. $pagesize=10;
  1270. $data[':uniacid']=$_W['uniacid'];
  1271. $data[':seller_id']=$_GPC['seller_id'];
  1272. $where=" where uniacid=:uniacid and seller_id=:seller_id ";
  1273. if($_GPC['status']){
  1274. $where.=" and status=:status ";
  1275. $data[':status']=$_GPC['status'];
  1276. }
  1277. if($_GPC['keywords']){
  1278. $where.=" and order_no LIKE concat('%', :order_no,'%') ";
  1279. $data[':order_no']=$_GPC['keywords'];
  1280. }
  1281. $sql="select * from " . tablename("zh_jdgjb_order") .$where." order by id desc ";
  1282. $select_sql=$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
  1283. $list=pdo_fetchall($select_sql,$data);
  1284. foreach($list as $key=>$val){
  1285. $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;
  1286. }
  1287. echo json_encode($list);
  1288. }
  1289. //确认入住,拒绝退款
  1290. public function doPageChangeOrder(){
  1291. global $_W, $_GPC;
  1292. $res=pdo_update('zh_jdgjb_order',array('status'=>$_GPC['status']),array('id'=>$_GPC['order_id']));
  1293. if($res){
  1294. if($_GPC['status']==5){
  1295. $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']);
  1296. }
  1297. echo '1';
  1298. }else{
  1299. echo'2';
  1300. }
  1301. }
  1302. //编辑房间
  1303. public function doPageEditRoom(){
  1304. global $_GPC, $_W;
  1305. $data['name']=$_GPC['name'];
  1306. $data['price']=$_GPC['price'];
  1307. $data['img']=$_GPC['img'];
  1308. $data['floor']=$_GPC['floor'];
  1309. $data['people']=$_GPC['people'];
  1310. $data['logo']=$_GPC['logo'];
  1311. $data['yj_cost']=$_GPC['yj_cost'];
  1312. $data['state']=$_GPC['state'];
  1313. //var_dump($data);die;
  1314. $res = pdo_update('zh_jdgjb_room', $data, array('id' =>$_GPC['room_id']));
  1315. if($res){
  1316. echo '1';
  1317. }else{
  1318. echo '2';
  1319. }
  1320. }
  1321. //获取15天放价
  1322. public function doPageGetMonthCost(){
  1323. global $_W, $_GPC;
  1324. $rid=$_GPC['room_id'];
  1325. $dt_start = strtotime(date('Y-m-d'));
  1326. $dt_end = strtotime(date("Y-m-d",strtotime("+15 day")));
  1327. $pricelist=array();
  1328. $i=0;
  1329. while ($dt_start<$dt_end){
  1330. $dateday=$dt_start;
  1331. $res1=pdo_get('zh_jdgjb_roomprice',array('rid'=>$rid,'dateday'=>$dateday));
  1332. $pricelist[$i]['dateday']=date('m月d日',$dateday);
  1333. if($res1['mprice']){
  1334. $pricelist[$i]['mprice']=$res1['mprice'];
  1335. }else{
  1336. $mprice=pdo_getcolumn('zh_jdgjb_room',array('id'=>$rid),'price');
  1337. $pricelist[$i]['mprice']=$mprice;
  1338. }
  1339. $dt_start = strtotime('+1 day',$dt_start);
  1340. $i++;
  1341. }
  1342. echo json_encode($pricelist);
  1343. }
  1344. //获取15天房量
  1345. public function doPageGetMonthNum(){
  1346. global $_W, $_GPC;
  1347. $rid=$_GPC['room_id'];
  1348. $dt_start = strtotime(date('Y-m-d'));
  1349. $dt_end = strtotime(date("Y-m-d",strtotime("+15 day")));
  1350. $numlist=array();
  1351. $i=0;
  1352. while ($dt_start<$dt_end){
  1353. $dateday=$dt_start;
  1354. $res1=pdo_get('zh_jdgjb_roomnum',array('rid'=>$rid,'dateday'=>$dateday));
  1355. $numlist[$i]['dateday']=date('m月d日',$dateday);
  1356. if($res1){
  1357. $numlist[$i]['nums']=$res1['nums'];
  1358. }else{
  1359. $mprice=pdo_getcolumn('zh_jdgjb_room',array('id'=>$rid),'total_num');
  1360. $numlist[$i]['nums']=$mprice;
  1361. }
  1362. $dt_start = strtotime('+1 day',$dt_start);
  1363. $i++;
  1364. }
  1365. echo json_encode($numlist);
  1366. }
  1367. //删除房间
  1368. public function doPageDeleteRoom(){
  1369. global $_W, $_GPC;
  1370. $res=pdo_delete('zh_jdgjb_room',array('id'=>$_GPC['room_id']));
  1371. if($res){
  1372. echo '1';
  1373. }else{
  1374. echo'2';
  1375. }
  1376. }
  1377. //房间上下架
  1378. public function doPageChangeRoom(){
  1379. global $_W, $_GPC;
  1380. $res=pdo_update('zh_jdgjb_room',array('state'=>$_GPC['state']),array('id'=>$_GPC['room_id']));
  1381. if($res){
  1382. echo '1';
  1383. }else{
  1384. echo'2';
  1385. }
  1386. }
  1387. //修改价格
  1388. public function doPageEditRoomPrice(){
  1389. global $_W, $_GPC;
  1390. $data['dateday']=strtotime(trim($_GPC['dateday']));
  1391. $data['mprice']=trim($_GPC['price']);
  1392. $data['rid']=trim($_GPC['room_id']);
  1393. $res=pdo_get('zh_jdgjb_roomprice',array('rid'=>$data['rid'],'dateday'=>$data['dateday']));
  1394. if(!$res['id']){
  1395. $rst=pdo_insert('zh_jdgjb_roomprice',$data);
  1396. }else{
  1397. $rst=pdo_update('zh_jdgjb_roomprice',array('mprice'=>$data['mprice']),array('id'=>$res['id']));
  1398. }
  1399. if($rst){
  1400. echo '1';
  1401. }else{
  1402. echo '2';
  1403. }
  1404. }
  1405. //修改数量
  1406. public function doPageEditRoomNum(){
  1407. global $_W, $_GPC;
  1408. $data['dateday']=strtotime(trim($_GPC['dateday']));
  1409. $data['nums']=trim($_GPC['nums']);
  1410. $data['rid']=trim($_GPC['room_id']);
  1411. $res=pdo_get('zh_jdgjb_roomnum',array('rid'=>$data['rid'],'dateday'=>$data['dateday']));
  1412. if(!$res['id']){
  1413. $rst=pdo_insert('zh_jdgjb_roomnum',$data);
  1414. }else{
  1415. $rst=pdo_update('zh_jdgjb_roomnum',array('nums'=>$data['nums']),array('id'=>$res['id']));
  1416. }
  1417. if($rst){
  1418. echo '1';
  1419. }else{
  1420. echo '2';
  1421. }
  1422. }
  1423. //可提现金额
  1424. public function doPageTxMoney(){
  1425. global $_W, $_GPC;
  1426. $data2[':seller_id']=$_GPC['seller_id'];
  1427. $data2[':uniacid']=$_W['uniacid'];
  1428. //总营业额
  1429. $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 ";
  1430. $totalmoney=pdo_fetch($totalsql,$data2);
  1431. $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 ";
  1432. $total2 = pdo_fetch($sql2,$data2);//已提现金额
  1433. $ktxcost=$totalmoney['total_money']-$totalmoney['yj_money']-$total2['total'];
  1434. echo $ktxcost;
  1435. }
  1436. //保存提现申请
  1437. public function doPageSaveTxApply(){
  1438. global $_W, $_GPC;
  1439. $data2[':seller_id']=$_GPC['seller_id'];
  1440. $data2[':uniacid']=$_W['uniacid'];
  1441. //总营业额
  1442. $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 ";
  1443. $totalmoney=pdo_fetch($totalsql,$data2);
  1444. $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 ";
  1445. $total2 = pdo_fetch($sql2,$data2);//已提现金额
  1446. $ktxcost=$totalmoney['total_money']-$totalmoney['yj_money']-$total2['total'];
  1447. if($_GPC['tx_cost']>$ktxcost){
  1448. echo 2;exit();
  1449. }
  1450. $data['sj_cost']=$_GPC['sj_cost'];
  1451. $data['seller_id']=$_GPC['seller_id'];
  1452. $data['name']=$_GPC['name'];
  1453. $data['username']=$_GPC['username'];
  1454. $data['state']=1;
  1455. $data['tx_cost']=$_GPC['tx_cost'];
  1456. $data['uniacid']=$_W['uniacid'];
  1457. $data['time']=date("Y-m-d H:i:s");
  1458. $res=pdo_insert('zh_jdgjb_withdrawal',$data);
  1459. if($res){
  1460. echo '1';
  1461. }else{
  1462. echo '2';
  1463. }
  1464. }
  1465. //商家提现记录
  1466. public function doPageSellerTxList(){
  1467. global $_GPC, $_W;
  1468. $pageindex = max(1, intval($_GPC['page']));
  1469. $pagesize=10;
  1470. $data[':uniacid']=$_W['uniacid'];
  1471. $data[':seller_id']=$_GPC['seller_id'];
  1472. $where=' WHERE uniacid=:uniacid and seller_id=:seller_id and is_delete=1';
  1473. $sql="SELECT * FROM ".tablename('zh_jdgjb_withdrawal') . $where." ORDER BY time DESC";
  1474. $select_sql=$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
  1475. $list=pdo_fetchall($select_sql,$data);
  1476. echo json_encode($list);
  1477. }
  1478. //回复评价
  1479. public function doPageReplyAssess(){
  1480. global $_W, $_GPC;
  1481. $data['reply']=$_GPC['reply'];
  1482. $data['status']=2;
  1483. $data['reply_time']=time();
  1484. $res=pdo_update('zh_jdgjb_assess',$data,array('id'=>$_GPC['assess_id']));
  1485. if($res){
  1486. echo '1';
  1487. }else{
  1488. echo '2';
  1489. }
  1490. }
  1491. ///////////////////以下分销
  1492. //分销设置
  1493. public function doPageGetFxSet(){
  1494. global $_W, $_GPC;
  1495. $res=pdo_get('zh_jdgjb_fxset',array('uniacid'=>$_W['uniacid']));
  1496. echo json_encode($res);
  1497. }
  1498. //申请分销商
  1499. public function doPageDistribution(){
  1500. global $_W, $_GPC;
  1501. pdo_delete('zh_jdgjb_distribution',array('user_id'=>$_GPC['user_id']));
  1502. $set=pdo_get('zh_jdgjb_fxset',array('uniacid'=>$_W['uniacid']));
  1503. $data['user_id']=$_GPC['user_id'];
  1504. $data['user_name']=$_GPC['user_name'];
  1505. $data['user_tel']=$_GPC['user_tel'];
  1506. $data['time']=time();
  1507. if($set['is_fx']==1){
  1508. $data['state']=1;
  1509. }else{
  1510. $data['state']=2;
  1511. }
  1512. $data['uniacid']=$_W['uniacid'];
  1513. $res=pdo_insert('zh_jdgjb_distribution',$data);
  1514. $sq_id=pdo_insertid();
  1515. if($res){
  1516. $fx=pdo_get('zh_jdgjb_fxuser',array('fx_user'=>$_GPC['user_id']));
  1517. if($set['is_fx']==1 and !$fx){
  1518. pdo_insert("zh_jdgjb_fxuser",array('user_id'=>0,'fx_user'=>$_GPC['user_id'],'time'=>time()));
  1519. }
  1520. echo $sq_id;
  1521. }else{
  1522. echo '申请失败!';
  1523. }
  1524. }
  1525. //查看我的上线
  1526. public function doPageMySx(){
  1527. global $_W, $_GPC;
  1528. $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 ";
  1529. $res=pdo_fetch($sql,array(':fx_user'=>$_GPC['user_id']));
  1530. echo json_encode($res);
  1531. }
  1532. //查看我的申请
  1533. public function doPageMyDistribution(){
  1534. global $_W, $_GPC;
  1535. $res=pdo_get('zh_jdgjb_distribution',array('user_id'=>$_GPC['user_id']));
  1536. echo json_encode($res);
  1537. }
  1538. //绑定分销商
  1539. public function doPageBinding(){
  1540. global $_W, $_GPC;
  1541. $res=pdo_get('zh_jdgjb_fxuser',array('fx_user'=>$_GPC['fx_user']));//已绑定
  1542. $res2=pdo_get('zh_jdgjb_fxuser',array('user_id'=>$_GPC['fx_user'],'fx_user'=>$_GPC['user_id']));//已绑定成下线
  1543. if($_GPC['user_id']==$_GPC['fx_user']){
  1544. echo '自己不能绑定自己';
  1545. }elseif($res || $res2){
  1546. echo '不能重复绑定';
  1547. }else{
  1548. $res3=pdo_insert('zh_jdgjb_fxuser',array('user_id'=>$_GPC['user_id'],'fx_user'=>$_GPC['fx_user'],'time'=>time()));
  1549. if($res3){
  1550. echo '1';
  1551. }else{
  1552. echo '2';
  1553. }
  1554. }
  1555. }
  1556. //我的二维码
  1557. public function doPageMyCode(){
  1558. global $_W, $_GPC;
  1559. function getCoade($user_id){
  1560. function getaccess_token(){
  1561. global $_W, $_GPC;
  1562. $res=pdo_get('zh_jdgjb_system',array('uniacid' => $_W['uniacid']));
  1563. $appid=$res['appid'];
  1564. $secret=$res['appsecret'];
  1565. // $appid="wx80fa1d36c435231a";
  1566. // $secret="9bb4735bd092f092477049bfd7e183f8";
  1567. $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret."";
  1568. $ch = curl_init();
  1569. curl_setopt($ch, CURLOPT_URL,$url);
  1570. curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
  1571. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
  1572. $data = curl_exec($ch);
  1573. curl_close($ch);
  1574. $data = json_decode($data,true);
  1575. return $data['access_token'];
  1576. }
  1577. function set_msg($user_id){
  1578. $access_token = getaccess_token();
  1579. $data2=array(
  1580. "scene"=>$user_id,
  1581. // /"page"=>"zh_dianc/pages/info/info",
  1582. "width"=>100
  1583. );
  1584. $data2 = json_encode($data2);
  1585. $url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=".$access_token."";
  1586. $ch = curl_init();
  1587. curl_setopt($ch, CURLOPT_URL,$url);
  1588. curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
  1589. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
  1590. curl_setopt($ch, CURLOPT_POST,1);
  1591. curl_setopt($ch, CURLOPT_POSTFIELDS,$data2);
  1592. $data = curl_exec($ch);
  1593. curl_close($ch);
  1594. return $data;
  1595. }
  1596. $img=set_msg($user_id);
  1597. $img=base64_encode($img);
  1598. return $img;
  1599. }
  1600. $base64_image_content = "data:image/jpeg;base64," . getCoade($_GPC['user_id']);
  1601. if (preg_match('/^(data:\s*image\/(\w+);base64,)/', $base64_image_content, $result)) {
  1602. $type = $result[2];
  1603. $new_file = IA_ROOT . "/addons/zh_jdgjb/img/";
  1604. if (!file_exists($new_file)) {
  1605. //检查是否有该文件夹,如果没有就创建,并给予最高权限
  1606. mkdir($new_file, 0777);
  1607. }
  1608. $wname = "{$_GPC['user_id']}" . ".{$type}";
  1609. //$wname="1511.jpeg";
  1610. $new_file = $new_file . $wname;
  1611. file_put_contents($new_file, base64_decode(str_replace($result[1], '', $base64_image_content)));
  1612. }
  1613. echo $_W['siteroot'] . "addons/zh_jdgjb/img/" . $wname;
  1614. }
  1615. //查看我的团队
  1616. public function doPageMyTeam(){
  1617. global $_W, $_GPC;
  1618. $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";
  1619. $res=pdo_fetchall($sql,array(':user_id'=>$_GPC['user_id']));
  1620. $res2=array();
  1621. for($i=0;$i<count($res);$i++){
  1622. $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";
  1623. $res3=pdo_fetchall($sql2,array(':user_id'=>$res[$i]['fx_user']));
  1624. $res2[]=$res3;
  1625. }
  1626. $res4=array();
  1627. for($k=0;$k<count($res2);$k++){
  1628. for($j=0;$j<count($res2[$k]);$j++){
  1629. $res4[]=$res2[$k][$j];
  1630. }
  1631. }
  1632. $data['one']=$res;
  1633. $data['two']=$res4;
  1634. echo json_encode($data);
  1635. }
  1636. //佣金统计
  1637. public function doPageCountCommission(){
  1638. global $_W, $_GPC;
  1639. $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 ";
  1640. $money=pdo_fetch($sql2,array('uniacid'=>$_W['uniacid'],':user_id'=>$_GPC['user_id']));
  1641. $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)";
  1642. $ytx_money=pdo_fetch($sql3,array(':user_id'=>$_GPC['user_id']));
  1643. $commission['ktx']= number_format($money['yx']-$ytx_money['tx_money'],2);
  1644. $commission['dj']= number_format($money['dj'],2);
  1645. $commission['ytx']= number_format($ytx_money['tx_money'],2);
  1646. $commission['lj']= number_format($money['yx']+$commission['dj'],2);
  1647. echo json_encode($commission);
  1648. }
  1649. //佣金明细
  1650. public function doPageYjlist(){
  1651. global $_GPC, $_W;
  1652. $pageindex = max(1, intval($_GPC['page']));
  1653. $pagesize=30;
  1654. $data[':user_id']=$_GPC['user_id'];
  1655. $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";
  1656. $select_sql=$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
  1657. $list=pdo_fetchall($sql,$data);
  1658. echo json_encode($list);
  1659. }
  1660. //佣金提现设置
  1661. public function doPageGetYjTxSet(){
  1662. global $_GPC, $_W;
  1663. $res=pdo_get('zh_jdgjb_fxtxset',array('uniacid'=>$_W['uniacid']));
  1664. echo json_encode($res);
  1665. }
  1666. //佣金提现
  1667. public function doPageYjtx(){
  1668. global $_W, $_GPC;
  1669. $data['tx_cost']=$_GPC['tx_cost'];
  1670. $data['sj_cost']=$_GPC['sj_cost'];
  1671. $data['account']=$_GPC['account'];
  1672. $data['user_name']=$_GPC['user_name'];
  1673. $data['state']=1;
  1674. $data['time']=time();
  1675. $data['uniacid']=$_W['uniacid'];
  1676. $data['user_id']=$_GPC['user_id'];
  1677. $data['note']='提现';
  1678. $res=pdo_insert('zh_jdgjb_commission_withdrawal',$data);
  1679. if($res){
  1680. echo '1';
  1681. }else{
  1682. echo '2';
  1683. }
  1684. }
  1685. //完善信息
  1686. public function doPageRenewUser(){
  1687. global $_W, $_GPC;
  1688. $data['tel']=$_GPC['tel'];
  1689. $data['zs_name']=$_GPC['zs_name'];
  1690. $data['type']=2;
  1691. $data['number']=substr("00000000".$_GPC['user_id'], -8);
  1692. $res=pdo_update('zh_jdgjb_user',$data,array('id'=>$_GPC['user_id']));
  1693. if($res){
  1694. echo '1';
  1695. }else{
  1696. echo '2';
  1697. }
  1698. }
  1699. //累计消费
  1700. public function doPageMyCost(){
  1701. global $_W, $_GPC;
  1702. $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'));
  1703. echo json_encode($total['total_money']-$total['yt_money']);
  1704. }
  1705. //订单二维码
  1706. public function doPageOrderCode(){
  1707. global $_W, $_GPC;
  1708. function getCoade($order_id){
  1709. function getaccess_token(){
  1710. global $_W, $_GPC;
  1711. $res=pdo_get('zh_jdgjb_system',array('uniacid' => $_W['uniacid']));
  1712. $appid=$res['appid'];
  1713. $secret=$res['appsecret'];
  1714. // $appid="wx80fa1d36c435231a";
  1715. // $secret="9bb4735bd092f092477049bfd7e183f8";
  1716. $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret."";
  1717. $ch = curl_init();
  1718. curl_setopt($ch, CURLOPT_URL,$url);
  1719. curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
  1720. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
  1721. $data = curl_exec($ch);
  1722. curl_close($ch);
  1723. $data = json_decode($data,true);
  1724. return $data['access_token'];
  1725. }
  1726. function set_msg($order_id){
  1727. $access_token = getaccess_token();
  1728. $data2=array(
  1729. "scene"=>$order_id,
  1730. "page"=>"zh_jdgjb/pages/logs/Workbench",
  1731. "width"=>100
  1732. );
  1733. $data2 = json_encode($data2);
  1734. $url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=".$access_token."";
  1735. $ch = curl_init();
  1736. curl_setopt($ch, CURLOPT_URL,$url);
  1737. curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
  1738. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
  1739. curl_setopt($ch, CURLOPT_POST,1);
  1740. curl_setopt($ch, CURLOPT_POSTFIELDS,$data2);
  1741. $data = curl_exec($ch);
  1742. curl_close($ch);
  1743. return $data;
  1744. }
  1745. $img=set_msg($order_id);
  1746. $img=base64_encode($img);
  1747. return $img;
  1748. }
  1749. echo getCoade($_GPC['order_id']);
  1750. }
  1751. //二维码确认入住
  1752. public function doPageSmRz(){
  1753. global $_W, $_GPC;
  1754. $orderInfo=pdo_get('zh_jdgjb_order',array('id'=>$_GPC['order_id']),'seller_id');
  1755. if($orderInfo['seller_id']==$_GPC['seller_id']){
  1756. $res=pdo_update('zh_jdgjb_order',array('status'=>5),array('id'=>$_GPC['order_id']));
  1757. if($res){
  1758. echo '1';
  1759. }else{
  1760. echo'2';
  1761. }
  1762. }else{
  1763. echo '没有核销权限';
  1764. }
  1765. }
  1766. //押金退款
  1767. public function doPageYjRefund(){
  1768. global $_W, $_GPC;
  1769. $money=$_GPC['money']*100;//退款金额
  1770. $order_id=$_GPC['order_id'];
  1771. include_once IA_ROOT . '/addons/zh_jdgjb/cert/WxPay.Api.php';
  1772. load()->model('account');
  1773. load()->func('communication');
  1774. $refund_order =pdo_get('zh_jdgjb_order',array('id'=>$order_id));
  1775. $WxPayApi = new WxPayApi();
  1776. $input = new WxPayRefund();
  1777. $path_cert = IA_ROOT . "/addons/zh_jdgjb/cert/".'apiclient_cert_' .$_W['uniacid'] . '.pem';
  1778. $path_key = IA_ROOT . "/addons/zh_jdgjb/cert/".'apiclient_key_' . $_W['uniacid'] . '.pem';
  1779. $account_info = $_W['account'];
  1780. $res=pdo_get('zh_jdgjb_system',array('uniacid'=>$_W['uniacid']));
  1781. $appid=$res['appid'];
  1782. $key=$res['wxkey'];
  1783. $mchid=$res['mchid'];
  1784. $out_trade_no=$refund_order['out_trade_no'];
  1785. $fee = $refund_order['total_cost'] * 100;
  1786. $input->SetAppid($appid);
  1787. $input->SetMch_id($mchid);
  1788. $input->SetOp_user_id($mchid);
  1789. $input->SetRefund_fee($money);
  1790. $input->SetTotal_fee($fee);
  1791. // $input->SetTransaction_id($refundid);
  1792. $input->SetOut_refund_no($refund_order['order_no']);
  1793. $input->SetOut_trade_no($out_trade_no);
  1794. $result = $WxPayApi->refund($input, 6, $path_cert, $path_key, $key);
  1795. if ($result['result_code'] == 'SUCCESS') {//退款成功
  1796. //更改订单操作
  1797. pdo_update('zh_jdgjb_order',array('ytyj_cost +='=>($money/100)),array('id'=>$order_id));
  1798. return '1';
  1799. }else{
  1800. return '2';
  1801. }
  1802. }
  1803. //充值活动
  1804. public function doPageCzhd(){
  1805. global $_W, $_GPC;
  1806. $res=pdo_getall('zh_jdgjb_czhd',array('uniacid'=>$_W['uniacid']),array(),'','full DESC');
  1807. echo json_encode($res);
  1808. }
  1809. //充值支付
  1810. public function doPagePay2(){
  1811. global $_W, $_GPC;
  1812. include IA_ROOT.'/addons/zh_jdgjb/wxpay.php';
  1813. $res=pdo_get('zh_jdgjb_system',array('uniacid'=>$_W['uniacid']));
  1814. $order=pdo_get('zh_jdgjb_recharge',array('id'=>$_GPC['cz_id']));
  1815. $appid=$res['appid'];
  1816. $openid=$_GPC['openid'];//oQKgL0ZKHwzAY-KhiyEEAsakW5Zg
  1817. $mch_id=$res['mchid'];
  1818. $key=$res['wxkey'];
  1819. $out_trade_no = $order['out_trade_no'];
  1820. $root=$_W['siteroot'];
  1821. //pdo_update('zh_jdgjb_recharge',array('out_trade_no'=>$out_trade_no),array('id'=>$_GPC['cz_id']));
  1822. $total_fee =$order['cz_money'];
  1823. if(empty($total_fee))
  1824. {
  1825. $body = "订单付款";
  1826. $total_fee = floatval(99*100);
  1827. }else{
  1828. $body = "订单付款";
  1829. $total_fee = floatval($total_fee*100);
  1830. }
  1831. $weixinpay = new WeixinPay($appid,$openid,$mch_id,$key,$out_trade_no,$body,$total_fee,$root);
  1832. $return=$weixinpay->pay();
  1833. echo json_encode($return);
  1834. }
  1835. //充值
  1836. public function doPageSaveRecharge(){
  1837. global $_W, $_GPC;
  1838. $data['cz_money']=$_GPC['cz_money'];
  1839. $data['zs_money']=$_GPC['zs_money'];
  1840. $data['out_trade_no']=time().rand(1000,9999).$_GPC['user_id'];
  1841. $data['user_id']=$_GPC['user_id'];
  1842. $data['state']=1;
  1843. $data['note']='在线充值';
  1844. $data['time']=time();
  1845. $data['uniacid']=$_W['uniacid'];
  1846. $res2=pdo_insert('zh_jdgjb_recharge',$data);
  1847. $cz_id=pdo_insertid();
  1848. if($res2){
  1849. echo $cz_id;
  1850. }else{
  1851. echo '2';
  1852. }
  1853. }
  1854. //余额明细
  1855. public function doPageYelist(){
  1856. global $_GPC, $_W;
  1857. $pageindex = max(1, intval($_GPC['page']));
  1858. $pagesize=30;
  1859. $data[':user_id']=$_GPC['user_id'];
  1860. $sql=" select id,cz_money,zs_money,note,time from ".tablename('zh_jdgjb_recharge')." where user_id=:user_id and state=2 ";
  1861. $select_sql=$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
  1862. $list=pdo_fetchall($sql,$data);
  1863. echo json_encode($list);
  1864. }
  1865. //入住改变
  1866. public function doPageUpdRz(){
  1867. global $_GPC, $_W;
  1868. function getLevel($members,$count){
  1869. for($i=0;$i<count($members);$i++){
  1870. if($count['count']>=$members[$i]['value']){
  1871. return $members[$i]['id'];
  1872. }
  1873. if($count['count']<$members[$i]['value']&&$count['count']>$members[$i+1]['value']){
  1874. return $members[$i+1]['id'];
  1875. }
  1876. }
  1877. }
  1878. function getScore($order_id){
  1879. global $_W, $_GPC;
  1880. $orderInfo=pdo_get('zh_jdgjb_order',array('id'=>$order_id));
  1881. $scoreInfo=pdo_get('zh_jdgjb_system',array('uniacid'=>$_W['uniacid']));
  1882. $score= floor($orderInfo['dis_cost']*$scoreInfo['xf_score']);
  1883. return $score;
  1884. }
  1885. function saveScore($order_id,$user_id,$score){
  1886. global $_W, $_GPC;
  1887. $data['user_id']=$user_id;
  1888. $data['order_id']=$order_id;
  1889. $data['score']=$score;
  1890. $data['note']='购物所得';
  1891. $data['time']=time();
  1892. $data['uniacid']=$_W['uniacid'];
  1893. $rst=pdo_insert('zh_jdgjb_score',$data);
  1894. return $rst;
  1895. }
  1896. function roomNum($order_id){
  1897. global $_W, $_GPC;
  1898. $order=pdo_get('zh_jdgjb_order',array('id'=>$order_id));
  1899. //修改房间数量
  1900. $dt_start = strtotime(substr($order['arrival_time'],0,10));
  1901. $dt_end = strtotime(substr($order['departure_time'],0,10));
  1902. while ($dt_start<$dt_end){
  1903. $dateday=$dt_start;
  1904. $res=pdo_get('zh_jdgjb_roomnum',array('rid'=>$order['room_id'],'dateday'=>$dateday));
  1905. if($res['id']){
  1906. $nums=$res['nums']-$order['num'];
  1907. pdo_update('zh_jdgjb_roomnum',array('nums'=>$nums),array('rid'=>$order['room_id'],'dateday'=>$dateday));
  1908. }else{
  1909. $uniacid=$_W['uniacid'];
  1910. $roomArr=pdo_get('zh_jdgjb_room',array('id'=>$order['room_id'],'uniacid'=>$order['uniacid']),array('total_num','id'));
  1911. $nums=$roomArr['total_num']-$order['num'];
  1912. pdo_insert('zh_jdgjb_roomnum',array('nums'=>$nums,'rid'=>$roomArr['id'],'dateday'=>$dateday));
  1913. }
  1914. $dt_start = strtotime('+1 day',$dt_start);
  1915. }
  1916. }
  1917. $type=pdo_get('zh_jdgjb_system',array('uniacid'=>$_W['uniacid']),'open_member');
  1918. $order=pdo_get('zh_jdgjb_order',array('id'=>$_GPC['id']));
  1919. if($type['open_member']==1){
  1920. //获取用户消费金额
  1921. $count=pdo_get('zh_jdgjb_order', array('user_id'=>$order['user_id'],'status'=>5), array('sum(dis_cost) as count'));
  1922. $members=pdo_getall('zh_jdgjb_level',array('uniacid'=>$_W['uniacid']),array() , '' , 'value DESC');
  1923. $level_id= getLevel($members,$count);
  1924. }
  1925. $score=getScore($_GPC['id']);
  1926. $rst=saveScore($_GPC['id'],$order['user_id'],$score);
  1927. if($rst){
  1928. pdo_update('zh_jdgjb_user',array('score +='=>$score),array('id'=>$order['user_id']));
  1929. }
  1930. if($level_id){
  1931. //更改会员等级
  1932. pdo_update('zh_jdgjb_user',array('level_id'=>$level_id,'type'=>2),array('id'=>$order['user_id']));
  1933. //echo $level_id;
  1934. }
  1935. if($order['type']==3){
  1936. roomNum($_GPC['id']);
  1937. }
  1938. //更改拥金
  1939. pdo_update('zh_jdgjb_earnings',array('state'=>2),array('order_id'=>$_GPC['id']));
  1940. }
  1941. public function doPageAliyun($phone,$code,$tpl_id) {
  1942. global $_W, $_GPC;
  1943. require_once dirname(__DIR__) . "/zh_jdgjb/SignatureHelper.php";
  1944. $sms=pdo_get('zh_jdgjb_system',array('uniacid'=>$_W['uniacid']));
  1945. // echo $code;die;
  1946. $params = array ();
  1947. // *** 需用户填写部分 ***
  1948. // fixme 必填:是否启用https
  1949. $security = false;
  1950. // fixme 必填: 请参阅 https://ak-console.aliyun.com/ 取得您的AK信息
  1951. $accessKeyId = $sms['aliyun_appkey'];
  1952. $accessKeySecret = $sms['aliyun_appsecret'];
  1953. // fixme 必填: 短信接收号码
  1954. $params["PhoneNumbers"] = $phone;
  1955. // fixme 必填: 短信签名,应严格按"签名名称"填写,请参考: https://dysms.console.aliyun.com/dysms.htm#/develop/sign
  1956. $params["SignName"] = $sms['aliyun_sign'];
  1957. // fixme 必填: 短信模板Code,应严格按"模板CODE"填写, 请参考: https://dysms.console.aliyun.com/dysms.htm#/develop/template
  1958. $params["TemplateCode"] =$tpl_id;
  1959. // fixme 可选: 设置模板参数, 假如模板中存在变量需要替换则为必填项
  1960. $params['TemplateParam'] = Array (
  1961. "code" => $code,
  1962. );
  1963. // *** 需用户填写部分结束, 以下代码若无必要无需更改 ***
  1964. if(!empty($params["TemplateParam"]) && is_array($params["TemplateParam"])) {
  1965. $params["TemplateParam"] = json_encode($params["TemplateParam"], JSON_UNESCAPED_UNICODE);
  1966. }
  1967. // 初始化SignatureHelper实例用于设置参数,签名以及发送请求
  1968. $helper = new SignatureHelper();
  1969. // 此处可能会抛出异常,注意catch
  1970. $content = $helper->request(
  1971. $accessKeyId,
  1972. $accessKeySecret,
  1973. "dysmsapi.aliyuncs.com",
  1974. array_merge($params, array(
  1975. "RegionId" => "cn-hangzhou",
  1976. "Action" => "SendSms",
  1977. "Version" => "2017-05-25",
  1978. )),
  1979. $security
  1980. );
  1981. return $content;
  1982. }
  1983. public function doPageAliyun2($tel,$aliyun_appkey,$aliyun_appsecret,$aliyun_sign,$tpl_id) {
  1984. global $_W, $_GPC;
  1985. require_once dirname(__DIR__) . "/zh_jdgjb/SignatureHelper.php";
  1986. // echo $code;die;
  1987. $params = array ();
  1988. // *** 需用户填写部分 ***
  1989. // fixme 必填:是否启用https
  1990. $security = false;
  1991. // fixme 必填: 请参阅 https://ak-console.aliyun.com/ 取得您的AK信息
  1992. $accessKeyId = $aliyun_appkey;
  1993. $accessKeySecret = $aliyun_appsecret;
  1994. // fixme 必填: 短信接收号码
  1995. $params["PhoneNumbers"] = $tel;
  1996. // fixme 必填: 短信签名,应严格按"签名名称"填写,请参考: https://dysms.console.aliyun.com/dysms.htm#/develop/sign
  1997. $params["SignName"] =$aliyun_sign;
  1998. // fixme 必填: 短信模板Code,应严格按"模板CODE"填写, 请参考: https://dysms.console.aliyun.com/dysms.htm#/develop/template
  1999. $params["TemplateCode"] = $tpl_id;
  2000. // fixme 可选: 设置模板参数, 假如模板中存在变量需要替换则为必填项
  2001. // *** 需用户填写部分结束, 以下代码若无必要无需更改 ***
  2002. if(!empty($params["TemplateParam"]) && is_array($params["TemplateParam"])) {
  2003. $params["TemplateParam"] = json_encode($params["TemplateParam"], JSON_UNESCAPED_UNICODE);
  2004. }
  2005. // 初始化SignatureHelper实例用于设置参数,签名以及发送请求
  2006. $helper = new SignatureHelper();
  2007. // 此处可能会抛出异常,注意catch
  2008. $content = $helper->request(
  2009. $accessKeyId,
  2010. $accessKeySecret,
  2011. "dysmsapi.aliyuncs.com",
  2012. array_merge($params, array(
  2013. "RegionId" => "cn-hangzhou",
  2014. "Action" => "SendSms",
  2015. "Version" => "2017-05-25",
  2016. )),
  2017. $security
  2018. );
  2019. return $content;
  2020. }
  2021. function base64EncodeImage ($image_file) {
  2022. $base64_image = '';
  2023. $image_info = getimagesize($image_file);
  2024. $image_data = fread(fopen($image_file, 'r'), filesize($image_file));
  2025. $base64_image = chunk_split(base64_encode($image_data));
  2026. return $base64_image;
  2027. }
  2028. public function doPageTest2(){
  2029. global $_GPC, $_W;
  2030. require_once dirname(__DIR__) . "/zh_jdgjb/baiduSdk/AipFace.php";
  2031. $appId='16809002';
  2032. $apiKey='NkQDRqjKs7oH01rrqTuQez25';
  2033. $secretKey='B6lqYgOiew485z6kT7YctVggHRGHiePF';
  2034. $image=$this->base64EncodeImage(dirname(__DIR__) . "/zh_jdgjb/img/7.jpg");
  2035. $imageType='BASE64';
  2036. $data=[
  2037. [
  2038. 'image'=>'7020ad3c0fc764b00a760fcf91c6ce7b',
  2039. 'image_type'=>'FACE_TOKEN'
  2040. ],
  2041. [
  2042. 'image'=>$image,
  2043. 'image_type'=>$imageType
  2044. ]
  2045. ];
  2046. $client= new AipFace($appId,$apiKey,$secretKey);
  2047. $arr=$client->match($data);
  2048. return json_encode($arr);
  2049. $errno = 5;
  2050. $message = '返回消息';
  2051. $data = array();
  2052. return $this->result($errno, $message, $data);
  2053. }
  2054. public function doPageTest3(){
  2055. global $_GPC, $_W;
  2056. require_once dirname(__DIR__) . "/zh_jdgjb/distance/distance.php";
  2057. $circle =['center'=>['lng'=>'117.26714358070373','lat'=>'31.933753273109424'],'radius'=>'5'*1000];
  2058. $arr=[
  2059. ['category'=>1,
  2060. 'radius'=>2.00,
  2061. 'fee'=>5,
  2062. 'vertexes'=>[
  2063. 'lat'=>'31.934336',
  2064. 'lng'=>'117.26503'
  2065. ]
  2066. ],
  2067. ['category'=>1,
  2068. 'radius'=>15.00,
  2069. 'fee'=>10,
  2070. 'vertexes'=>[
  2071. 'lat'=>'31.934336',
  2072. 'lng'=>'117.26503'
  2073. ]
  2074. ],
  2075. ['category'=>2,
  2076. 'radius'=>0.00,
  2077. 'fee'=>20,
  2078. 'vertexes'=>[
  2079. [
  2080. 'lat'=>'31.901419208343',
  2081. 'lng'=>'117.26503'
  2082. ],
  2083. [
  2084. 'lat'=>'31.95502',
  2085. 'lng'=>'117.283'
  2086. ],
  2087. [
  2088. 'lat'=>'31.95502',
  2089. 'lng'=>'117.24706'
  2090. ],
  2091. [
  2092. 'lat'=>'31.99448561994',
  2093. 'lng'=>'117.18766516358'
  2094. ],
  2095. [
  2096. 'lat'=>'32.008318599485',
  2097. 'lng'=>'117.10080450684'
  2098. ],
  2099. [
  2100. 'lat'=>'31.891508803575',
  2101. 'lng'=>'117.23195379883'
  2102. ],
  2103. ]
  2104. ],
  2105. ];
  2106. $convert= new Convert();
  2107. foreach ($arr as $key => $value) {
  2108. if($value['category']==1){
  2109. $rst=$convert -> is_point_in_circle($value['vertexes'], $circle);
  2110. if($rst){
  2111. echo $value['fee'];die;
  2112. }
  2113. continue;
  2114. }
  2115. if($value['category']==2){
  2116. $rst=$convert -> is_point_in_polygon($circle['center'], $value['vertexes']);
  2117. if($rst){
  2118. echo $value['fee'];die;
  2119. }
  2120. continue;
  2121. }
  2122. echo '不在配送范围';die;
  2123. }
  2124. echo 6789;die;
  2125. /* $pts = [
  2126. ['lng'=>117.29673291016, 'lat'=>31.901419208343],
  2127. ['lng'=>117.283, 'lat'=>31.95502],
  2128. ['lng'=>117.24706, 'lat'=>31.95502],
  2129. ['lng'=>117.10080450684, 'lat'=>32.008318599485],
  2130. ['lng'=>117.23195379883, 'lat'=>31.891508803575],
  2131. ];*/
  2132. $point = ['lng'=>117.18766516358,'lat'=>31.99448561994];
  2133. $bool = $convert -> is_point_in_polygon($point,$pts);
  2134. var_dump($bool);die;
  2135. }
  2136. }