order.inc.php 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <?php
  2. global $_GPC, $_W;
  3. // $action = 'ad';
  4. // $title = $this->actions_titles[$action];
  5. $GLOBALS['frames'] = $this->getMainMenu();
  6. $operation = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
  7. $type=isset($_GPC['type'])?$_GPC['type']:'all';
  8. $status=$_GPC['status'];
  9. load()->func('tpl');
  10. $pageindex = max(1, intval($_GPC['page']));
  11. $pagesize=10;
  12. $where=' WHERE uniacid=:uniacid and is_delete=0 ';
  13. if($_GPC['keywords']){
  14. $where.=" and (seller_name LIKE concat('%', :order_no,'%') or name LIKE concat('%', :order_no,'%') or tel LIKE concat('%', :order_no,'%'))";
  15. $data[':order_no']=$_GPC['keywords'];
  16. }
  17. if($type!='all'){
  18. if ($type == 'overdue') {
  19. $where.= " and is_out_time = 1";
  20. } else {
  21. $where.= " and status = $status";
  22. }
  23. }
  24. if(!empty($_GPC['time'])){
  25. $start=strtotime($_GPC['time']['start']);
  26. $end=strtotime($_GPC['time']['end']);
  27. $where.=" and time >={$start} and time<={$end}";
  28. }
  29. $sql="SELECT * FROM ".tablename('zh_jdgjb_order') .$where." ORDER BY id DESC";
  30. $data[':uniacid']=$_W['uniacid'];
  31. $total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_jdgjb_order') .$where,$data);
  32. $select_sql =$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
  33. $list=pdo_fetchall($select_sql,$data);
  34. foreach($list as $key=>$val){
  35. $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;
  36. }
  37. //var_dump($list);die;
  38. $pager = pagination($total, $pageindex, $pagesize);
  39. if($operation=='delete'){
  40. $res=pdo_update('zh_jdgjb_order',array('is_delete'=>1),array('id'=>$_GPC['id']));
  41. if($res){
  42. message('删除成功',$this->createWebUrl('order',array()),'success');
  43. }else{
  44. message('删除失败','','error');
  45. }
  46. }
  47. if($operation=='rz'){
  48. $res=pdo_update('zh_jdgjb_order',array('status'=>5),array('id'=>$_GPC['id']));
  49. if($res){
  50. $type=pdo_get('zh_jdgjb_system',array('uniacid'=>$_W['uniacid']),array('open_member','is_score'));
  51. $order=pdo_get('zh_jdgjb_order',array('id'=>$_GPC['id']));
  52. if($type['open_member']==1){
  53. //获取用户消费金额
  54. $userInfo=pdo_get('zh_jdgjb_user',array('id'=>$order['user_id']),array('level_id','dj_money'));
  55. $xf_money=$userInfo['dj_money']+$order['dis_cost'];
  56. $members=pdo_getall('zh_jdgjb_level',array('uniacid'=>$_W['uniacid'],'id >'=>$userInfo['level_id']),array() , '' , 'value DESC');
  57. $level_id= $this->getLevel($members,$xf_money);
  58. pdo_update('zh_jdgjb_user',array('dj_money +='=>$order['dis_cost']),array('id'=>$order['user_id']));
  59. }
  60. if($type['is_score']==1){
  61. $score=$this->getScore($_GPC['id']);
  62. $rst=$this->saveScore($_GPC['id'],$order['user_id'],$score);
  63. if($rst){
  64. pdo_update('zh_jdgjb_user',array('score +='=>$score),array('id'=>$order['user_id']));
  65. }
  66. }
  67. $this->rzMessage($_GPC['id']);
  68. if($level_id){
  69. //更改会员等级
  70. $level=pdo_get('zh_jdgjb_level',array('id'=>$level_id),array('value'));
  71. pdo_update('zh_jdgjb_user',array('level_id'=>$level_id,'type'=>2,'dj_money -='=>$level['value']),array('id'=>$order['user_id']));
  72. //echo $level_id;
  73. }
  74. if($order['type']==3){
  75. $this->roomNum($_GPC['id']);
  76. }
  77. //更改拥金
  78. pdo_update('zh_jdgjb_earnings',array('state'=>2),array('order_id'=>$_GPC['id']));
  79. message('操作成功',$this->createWebUrl('order',array()),'success');
  80. }else{
  81. message('操作失败','','error');
  82. }
  83. }
  84. if($operation=='jjrz'){
  85. $orderInfo=pdo_get('zh_jdgjb_order',array('id'=>$_GPC['order_id']));
  86. $this->jjrzMessage($_GPC['order_id']);
  87. if($orderInfo['type']==1){
  88. $result=$this->wxrefund($_GPC['order_id']);
  89. if ($result['result_code'] == 'SUCCESS') {//退款成功
  90. //更改订单操作
  91. pdo_update('zh_jdgjb_order',array('status'=>9,'jj_time'=>time()),array('id'=>$_GPC['order_id']));
  92. $order=pdo_get('zh_jdgjb_order',array('id'=>$_GPC['order_id']));
  93. //修改房间数量
  94. $dt_start = strtotime(substr($order['arrival_time'],0,10));
  95. $dt_end = strtotime(substr($order['departure_time'],0,10));
  96. while ($dt_start<$dt_end){
  97. $dateday=$dt_start;
  98. $res=pdo_get('zh_jdgjb_roomnum',array('rid'=>$order['room_id'],'dateday'=>$dateday));
  99. if($res['id']){
  100. $nums=$res['nums']+$order['num'];
  101. pdo_update('zh_jdgjb_roomnum',array('nums'=>$nums),array('rid'=>$order['room_id'],'dateday'=>$dateday));
  102. }
  103. $dt_start = strtotime('+1 day',$dt_start);
  104. }
  105. pdo_update('zh_jdgjb_earnings',array('state'=>3),array('order_id'=>$_GPC['order_id']));
  106. message('拒绝入住成功',$this->createWebUrl('order',array()),'success');
  107. }else{
  108. message($result['err_code_des'],'','error');
  109. }
  110. }
  111. //余额支付
  112. if($orderInfo['type']==2){
  113. $result=$this->saveRecharge($_GPC['order_id']);
  114. if($result==1){
  115. pdo_update('zh_jdgjb_order',array('status'=>9,'jj_time'=>time()),array('id'=>$_GPC['order_id']));
  116. pdo_update('zh_jdgjb_user',array('balance +='=>$orderInfo['total_cost']),array('id'=>$orderInfo['user_id']));
  117. message('拒绝入住成功',$this->createWebUrl('order',array()),'success');
  118. }
  119. }
  120. //到店付款
  121. if($orderInfo['type']==3){
  122. pdo_update('zh_jdgjb_order',array('status'=>9,'jj_time'=>time()),array('id'=>$_GPC['order_id']));
  123. message('拒绝入住成功',$this->createWebUrl('order',array()),'success');
  124. }
  125. }
  126. if($operation=='refund'){
  127. $orderInfo=pdo_get('zh_jdgjb_order',array('id'=>$_GPC['order_id']));
  128. if($orderInfo['type']==1){
  129. $result=$this->wxrefund($_GPC['order_id']);
  130. if ($result['result_code'] == 'SUCCESS') {//退款成功
  131. //更改订单操作
  132. pdo_update('zh_jdgjb_order',array('status'=>7),array('id'=>$_GPC['order_id']));
  133. $order=pdo_get('zh_jdgjb_order',array('id'=>$_GPC['order_id']));
  134. //修改房间数量
  135. $dt_start = strtotime(substr($order['arrival_time'],0,10));
  136. $dt_end = strtotime(substr($order['departure_time'],0,10));
  137. while ($dt_start<$dt_end){
  138. $dateday=$dt_start;
  139. $res=pdo_get('zh_jdgjb_roomnum',array('rid'=>$order['room_id'],'dateday'=>$dateday));
  140. if($res['id']){
  141. $nums=$res['nums']+$order['num'];
  142. pdo_update('zh_jdgjb_roomnum',array('nums'=>$nums),array('rid'=>$order['room_id'],'dateday'=>$dateday));
  143. }
  144. $dt_start = strtotime('+1 day',$dt_start);
  145. }
  146. pdo_update('zh_jdgjb_earnings',array('state'=>3),array('order_id'=>$_GPC['order_id']));
  147. message('退款成功',$this->createWebUrl('order',array()),'success');
  148. }else{
  149. message($result['err_code_des'],'','error');
  150. }
  151. }
  152. //余额支付
  153. if($orderInfo['type']==2){
  154. $result=$this->saveRecharge($_GPC['order_id']);
  155. if($result==1){
  156. pdo_update('zh_jdgjb_order',array('status'=>7),array('id'=>$_GPC['order_id']));
  157. pdo_update('zh_jdgjb_user',array('balance +='=>$orderInfo['total_cost']),array('id'=>$orderInfo['user_id']));
  158. message('退款成功',$this->createWebUrl('order',array()),'success');
  159. }
  160. }
  161. }
  162. if($operation=='reject'){
  163. $res=pdo_update('zh_jdgjb_order',array('status'=>8),array('id'=>$_GPC['order_id']));
  164. if($res){
  165. //更改拥金
  166. pdo_update('zh_jdgjb_earnings',array('state'=>2),array('order_id'=>$_GPC['order_id']));
  167. message('拒绝成功',$this->createWebUrl('order',array()),'success');
  168. }else{
  169. message('拒绝失败','','error');
  170. }
  171. }
  172. if($operation=='close'){
  173. $res=pdo_update('zh_jdgjb_order',array('voice'=>2),array('id'=>$_GPC['order_id']));
  174. if($res){
  175. message('操作成功',$this->createWebUrl('order',array()),'success');
  176. }else{
  177. message('操作失败','','error');
  178. }
  179. }
  180. if($operation=='complete'){
  181. $res=pdo_update('zh_jdgjb_order',array('status'=>4),array('id'=>$_GPC['order_id']));
  182. if($res){
  183. message('操作成功',$this->createWebUrl('order',array()),'success');
  184. }else{
  185. message('操作失败','','error');
  186. }
  187. }
  188. if($operation=='query'){
  189. $res=pdo_update('zh_jdgjb_order',array('status'=>10),array('id'=>$_GPC['order_id']));
  190. if($res){
  191. $this->queryOrderMessage($_GPC['order_id']);
  192. message('确认成功',$this->createWebUrl('order',array()),'success');
  193. }else{
  194. message('确认失败','','error');
  195. }
  196. }
  197. if($operation=='jjorder'){
  198. $orderInfo=pdo_get('zh_jdgjb_order',array('id'=>$_GPC['order_id']));
  199. $this->rejectOrderMessage($_GPC['order_id']);
  200. if($orderInfo['type']==1){
  201. $result=$this->wxrefund($_GPC['order_id']);
  202. if ($result['result_code'] == 'SUCCESS') {//退款成功
  203. //更改订单操作
  204. pdo_update('zh_jdgjb_order',array('status'=>9,'jj_time'=>time()),array('id'=>$_GPC['order_id']));
  205. $order=pdo_get('zh_jdgjb_order',array('id'=>$_GPC['order_id']));
  206. //修改房间数量
  207. $dt_start = strtotime(substr($order['arrival_time'],0,10));
  208. $dt_end = strtotime(substr($order['departure_time'],0,10));
  209. while ($dt_start<$dt_end){
  210. $dateday=$dt_start;
  211. $res=pdo_get('zh_jdgjb_roomnum',array('rid'=>$order['room_id'],'dateday'=>$dateday));
  212. if($res['id']){
  213. $nums=$res['nums']+$order['num'];
  214. pdo_update('zh_jdgjb_roomnum',array('nums'=>$nums),array('rid'=>$order['room_id'],'dateday'=>$dateday));
  215. }
  216. $dt_start = strtotime('+1 day',$dt_start);
  217. }
  218. pdo_update('zh_jdgjb_earnings',array('state'=>3),array('order_id'=>$_GPC['order_id']));
  219. message('拒绝成功',$this->createWebUrl('order',array()),'success');
  220. }else{
  221. message($result['err_code_des'],'','error');
  222. }
  223. }
  224. //余额支付
  225. if($orderInfo['type']==2){
  226. $result=$this->saveRecharge($_GPC['order_id']);
  227. if($result==1){
  228. pdo_update('zh_jdgjb_order',array('status'=>9,'jj_time'=>time()),array('id'=>$_GPC['order_id']));
  229. pdo_update('zh_jdgjb_user',array('balance +='=>$orderInfo['total_cost']),array('id'=>$orderInfo['user_id']));
  230. message('拒绝成功',$this->createWebUrl('order',array()),'success');
  231. }
  232. }
  233. //到店付款
  234. if($orderInfo['type']==3){
  235. pdo_update('zh_jdgjb_order',array('status'=>9,'jj_time'=>time()),array('id'=>$_GPC['order_id']));
  236. message('拒绝成功',$this->createWebUrl('order',array()),'success');
  237. }
  238. }
  239. include $this->template('web/order');