You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

382 lines
17 KiB

  1. <?php
  2. require_once __DIR__ . '/../HotelLib.php';
  3. /**
  4. * Created by PhpStorm.
  5. * User: luocj
  6. * Date: 2016/9/24
  7. * Time: 11:34
  8. */
  9. class HTOrderList extends HotelLib
  10. {
  11. //检测订单状态
  12. function checkStatus($order_id,$order_status){
  13. $sql = "select order_status from order_main where order_id = $order_id and cancel_flag = 0 limit 1";
  14. $tmp = $this->DBTool->queryBySql($sql);
  15. $now_status = $tmp['rowset'][0]['order_status'];
  16. $data = array();
  17. //修改订单与异常状态修改订单状态不区分
  18. if ($order_status==$now_status){
  19. $data['code'] = 0;
  20. $data['info'] = '';
  21. }else{
  22. $data['code'] = 10;
  23. $data['info'] = '请刷新页面后重试';
  24. }
  25. return $data;
  26. }
  27. //查询订单渠道
  28. function getOrgList()
  29. {
  30. $sql = "select a.id as org_id ,a.supplier_name as org_name from base_supplier a inner join base_supplier_sale b on a.id = b.supplier_id where a.cancel_flag = 0 and a.supplier_type = 301 and a.is_disabled = 0 and b.parent_type = 25";
  31. writeLog('sql= ' . $sql);
  32. $org_list = $this->DBTool->queryBySql($sql);
  33. $data['code'] = $org_list['code'];
  34. $data['info'] = $org_list['info'];
  35. $data['org_list'] = $org_list['rowset'];
  36. return $data;
  37. }
  38. //酒店订单列表,调用存储过程
  39. function getOrderList($para_date_type, $para_start_date, $para_end_date, $para_province, $para_city, $para_hotel_name, $para_order_status, $para_org_id, $para_more_search, $current, $page_size, $confirm_number ,$para_channel_order_status)
  40. {
  41. $sql = "CALL ht_test_order2 ('" . $para_date_type . "','" . $para_start_date . "','" . $para_end_date . "'," . $para_province . "," . $para_city . ",'" . $para_hotel_name . "','" . $para_order_status . "','" . $para_org_id . "','" . $para_more_search . "'," . $current . "," . $page_size . ",'" . $confirm_number . "','" . $para_channel_order_status . "')";
  42. //$sql = "CALL `ht_get_order_list`(0, '2016-09-19', '2016-09-20',0,0,' ',0,0,0,1,10)";
  43. writeLog(__FUNCTION__ . " sql= " . $sql);
  44. $data = array();
  45. $rowset = $this->DBTool->execProcedure($sql);
  46. if ($rowset['code'] != '0') return array('code'=>'1','info'=>'查询订单列表失败');
  47. $data['code'] = $rowset['code'];
  48. $data['info'] = $rowset['info'];
  49. $data['order_list'] = isset($rowset['rowset'][0]) ? $rowset['rowset'][0] : array();
  50. $data['current'] = isset($rowset['rowset'][1][0]['currpage']) ? $rowset['rowset'][1][0]['currpage'] : '1';
  51. $data['page_size'] = isset($rowset['rowset'][1][0]['pagesize']) ? $rowset['rowset'][1][0]['pagesize'] : '1';
  52. $data['total'] = isset($rowset['rowset'][1][0]['num']) ? $rowset['rowset'][1][0]['num'] : '0';
  53. $data['total_page'] = isset($rowset['rowset'][1][0]['pagecount']) ? $rowset['rowset'][1][0]['pagecount'] : '1';
  54. $data['wait_count'] = isset($rowset['rowset'][1][0]['wait_count']) ? $rowset['rowset'][1][0]['wait_count'] : "0";
  55. $data['cancel_count'] = isset($rowset['rowset'][1][0]['cancel_count']) ? $rowset['rowset'][1][0]['cancel_count'] : "0";
  56. $data['out_count'] = isset($rowset['rowset'][1][0]['out_count']) ? $rowset['rowset'][1][0]['out_count'] : "0";
  57. // $order_ary = [];
  58. // foreach ($data['order_list'] as $key => $value) {
  59. // $order_ary[] = $value['order_id'];
  60. // }
  61. //
  62. //
  63. //
  64. // foreach($order_ary as $k => $v){
  65. //
  66. // $sql = "select "
  67. //
  68. //
  69. //
  70. // }
  71. return $data;
  72. }
  73. /**
  74. * 获取user_id对应的真实姓名
  75. * @param $user_id
  76. * @return mixed
  77. *
  78. */
  79. function getUserTrueName($user_id)
  80. {
  81. // $sql = "select true_name from base_user where id={$user_id} AND CANCEL_FLAG=0 LIMIT 1";
  82. $sql = "select true_name from base_user where id={$user_id} LIMIT 1";
  83. $true_name = $this->DBTool->queryBySql($sql);
  84. writeLog(__FUNCTION__ . " sql= " . $sql);
  85. return $true_name['rowset'][0];
  86. }
  87. //导出订单信息
  88. function outOrderList($para_date_type, $para_start_date, $para_end_date, $para_province, $para_city, $para_hotel_name, $para_order_status, $para_org_id, $para_more_search, $current, $page_size)
  89. {
  90. $sql = "CALL ht_out_order_list ('" . $para_date_type . "','" . $para_start_date . "','" . $para_end_date . "'," . $para_province . "," . $para_city . ",'" . $para_hotel_name . "'," . $para_order_status . "," . $para_org_id . ",'" . $para_more_search . "'," . $current . "," . $page_size . ")";
  91. // $sql = "CALL `ht_get_order_list`(0, '2016-09-19', '2016-09-20',0,0,' ',0,0,0,1,10)";
  92. writeLog(__FUNCTION__ . " sql= " . $sql);
  93. $data = array();
  94. $rowset = $this->DBTool->execProcedure($sql);
  95. $data['code'] = $rowset['code'];
  96. $data['info'] = $rowset['info'];
  97. $data['order_list'] = isset($rowset['rowset'][0]) ? $rowset['rowset'][0] : array();
  98. $data['current'] = isset($rowset['rowset'][1][0]['currpage']) ? $rowset['rowset'][1][0]['currpage'] : '1';
  99. $data['page_size'] = isset($rowset['rowset'][1][0]['pagesize']) ? $rowset['rowset'][1][0]['pagesize'] : '1';
  100. $data['total'] = isset($rowset['rowset'][1][0]['num']) ? $rowset['rowset'][1][0]['num'] : '1';
  101. $data['total_page'] = isset($rowset['rowset'][1][0]['pagecount']) ? $rowset['rowset'][1][0]['pagecount'] : '1';
  102. return $data;
  103. }
  104. //酒店确认,内部确认不需要发rtx
  105. function getMakeSure($make_sure_order_id, $make_sure_num, $user_id, $outside = 0)
  106. {
  107. $today = date('Y-m-d H:i:s', time());
  108. $sql = "update order_main set order_status = 314,order_confirm_code = '$make_sure_num' where order_id = " . $make_sure_order_id . " or parent_order_id =" . $make_sure_order_id;
  109. writeLog('sql= ' . $sql);
  110. $rowset = $this->DBTool->execSql($sql);
  111. $data['code'] = $rowset['code'];
  112. $data['info'] = $rowset['info'];
  113. $sql = "insert into order_ht_status_log(order_id,order_status,before_status,cancel_flag,create_user_id,create_time,update_user_id,update_time) values ($make_sure_order_id,314,198,0,1,'$today',1,'$today')";
  114. writeLog('sql= ' . $sql);
  115. $rowset = $this->DBTool->execSql($sql);
  116. $data['make_sure_order_id'] = $make_sure_order_id;
  117. if ($rowset['code'] == "0") {
  118. $this->setMemcache($make_sure_order_id, 314);
  119. $supplier_name = $this->getSupplierName($make_sure_order_id);
  120. $outside ? $this->sendMessageToRTX("酒店确认通知", "$supplier_name \n已完成订单确认:$make_sure_order_id") : true;
  121. $model = array(
  122. "user_id" => $user_id,
  123. "log_type" => 3,
  124. "hotel_id" => 0,
  125. "room_type" => 0,
  126. "log_desc" => "订单号为" . $make_sure_order_id . "的状态由待确认变为已安排,确认号为" . $make_sure_num,
  127. "order_id" => $make_sure_order_id
  128. );
  129. $this->DBLog->insertLog($model, '变为已安排');
  130. }
  131. return $data;
  132. }
  133. //取消订单
  134. function getCancelOrder($cancel_order_id, $user_id, $cancel_order_status)
  135. {
  136. $today = date('Y-m-d H:i:s', time());
  137. $cancel_flag = 1;
  138. if ($cancel_order_status == 382) {
  139. //这里需要判断是修改的取消,还是直接取消
  140. //如果是修改的取消,修改后订单的状态值应该变为382,而如果是直接取消,应该直接变为383
  141. $cancel_flag = 4;
  142. }
  143. $sql = "select order_status from order_main where ORDER_ID = $cancel_order_id and cancel_flag = 0 and order_valid_status = 1";
  144. $res = $this->DBTool->queryBySql($sql);
  145. $before_status = 313; //待发单
  146. if ($res['code'] == 0 && !empty($res['rowset']))
  147. $before_status = $res['rowset'][0]['order_status'];
  148. //取消订单前判断该订单是否为已取消148 383
  149. if ($before_status == 148 ||$before_status==383){
  150. $data['code'] = '5';
  151. $data['info'] = '请刷新当前页面再尝试';
  152. return $data;
  153. }
  154. //end
  155. $sql = "CALL ht_cancel_order(" . $user_id . "," . $cancel_order_id . ",$cancel_flag)";
  156. writeLog(__FUNCTION__ . " sql= " . $sql);
  157. $data = array();
  158. $rowset = $this->DBTool->execProcedure($sql);
  159. $status_name = '';
  160. //已取消有2种状态,1、所有正常取消148,2、酒店已安排,我们异常处理并取消了订单383
  161. $sql = "select type_name from dict_type WHERE id = $before_status";
  162. $res = $this->DBTool->queryBySql($sql);
  163. if ($res['code'] == 0 && !empty($res['rowset']))
  164. $status_name = $res['rowset'][0]['type_name'];
  165. $sql = "insert into order_ht_status_log(order_id,order_status,before_status,cancel_flag,create_user_id,create_time,update_user_id,update_time) values ($cancel_order_id,$cancel_order_status,$before_status,0,$user_id,'{$today}',$user_id,'{$today}')";
  166. writeLog(__FUNCTION__ . " sql= " . $sql);
  167. $rowset = $this->DBTool->execSql($sql);
  168. $data['code'] = $rowset['code'];
  169. $data['info'] = $rowset['info'];
  170. //正常取消,清空memcache缓存;已安排 异常处理 取消订单 这种情况不清空
  171. if ($cancel_order_status == 382) {
  172. $this->setMemcache($cancel_order_id, 383);
  173. } else
  174. $this->resetMemcache($cancel_order_id);
  175. if ($rowset['code'] == "0") {
  176. $model = array(
  177. "user_id" => $user_id,
  178. "log_type" => 3,
  179. "hotel_id" => 0,
  180. "room_type" => 0,
  181. "log_desc" => "订单号为" . $cancel_order_id . "的状态由" . $status_name . "变为已取消",
  182. "order_id" => $cancel_order_id
  183. );
  184. $this->DBLog->insertLog($model, '变为已取消');
  185. }
  186. return $data;
  187. }
  188. //取消原因
  189. function getCancelReason($cancel_order_id, $cancel_reason, $user_id, $comment_type = 0)
  190. {
  191. $today = date('Y-m-d H:i:s', time());
  192. $sql = "insert into order_comment(order_id,comment_type,comment_txt,cancel_flag,create_user_id,create_time,update_user_id,update_time) values ($cancel_order_id,$comment_type,'{$cancel_reason}',0,$user_id,'{$today}',$user_id,'{$today}')";
  193. $rowset = $this->DBTool->execSql($sql);
  194. $data['code'] = $rowset['code'];
  195. $data['info'] = $rowset['info'];
  196. return $data;
  197. }
  198. /**
  199. * 发送确认单
  200. * User: Steven
  201. * @param $order_id 订单号
  202. * @param $user_id 操作人
  203. * @return mixed
  204. */
  205. public function getBilling($order_id, $user_id)
  206. {
  207. $today = date('Y-m-d H:i:s', time());
  208. $sql = "update order_main set order_status = 198,update_time ='$today', order_disable_type = 0 where order_id = " . $order_id . " or parent_order_id =" . $order_id;
  209. $rowset = $this->DBTool->execSql($sql);
  210. if ($rowset['code'] == "0") {
  211. $this->setMemcache($order_id, 198);
  212. $model = array(
  213. "user_id" => $user_id,
  214. "log_type" => 3,
  215. "hotel_id" => 0,
  216. "room_type" => 0,
  217. "log_desc" => "订单号为" . $order_id . "的状态由待发单变为待确认",
  218. "order_id" => $order_id
  219. );
  220. $this->DBLog->insertLog($model, '变为待确认');
  221. }
  222. $data['code'] = $rowset['code'];
  223. $data['info'] = $rowset['info'];
  224. $sql = "insert into order_ht_status_log(order_id,order_status,before_status,cancel_flag,create_user_id,create_time,update_user_id,update_time) values ($order_id,198,313,0,$user_id,'{$today}',$user_id,'{$today}')";
  225. writeLog(__FUNCTION__ . " sql= " . $sql);
  226. $rowset = $this->DBTool->execSql($sql);
  227. return $data;
  228. }
  229. function getHandleOrder($order_id, $user_id, $text_reason, $order_status, $order_status_name)
  230. {
  231. //382:酒店异常处理待发单 383已取消(区别于148) 待酒店确认退单
  232. $today = date('Y-m-d H:i:s', time());
  233. $new_status = 313;
  234. if ($order_status == 314) { //在酒店已经安排的情况下异常订单处理,应该把订单状态变更成异常处理代发单状态(区别于常规的代发单)
  235. $new_status = 382;
  236. }
  237. $sql = "update order_main set order_status = $new_status, is_up=0 , update_time ='$today' where order_id = " . $order_id . " or parent_order_id =" . $order_id;
  238. writeLog("update_order_main =" . $sql);
  239. $rowset = $this->DBTool->execSql($sql);
  240. $sql = "insert into order_comment(order_id,comment_type,comment_txt,cancel_flag,create_user_id,create_time,update_user_id,update_time) values ($order_id,2,'$text_reason',0,$user_id,'{$today}',$user_id,'{$today}')";
  241. writeLog("handleOrder =" . $sql);
  242. $rowset = $this->DBTool->execSql($sql);
  243. if ($rowset['code'] == "0") {
  244. $this->setMemcache($order_id, 313);
  245. $model = array(
  246. "user_id" => $user_id,
  247. "log_type" => 3,
  248. "hotel_id" => 0,
  249. "room_type" => 0,
  250. "log_desc" => "订单号为" . $order_id . "的状态由" . $order_status_name . "变为待发单",
  251. "order_id" => $order_id
  252. );
  253. $this->DBLog->insertLog($model, '异常订单处理');
  254. }
  255. $data['code'] = $rowset['code'];
  256. $data['info'] = $rowset['info'];
  257. $sql = "update order_ht_status_log set cancel_flag = 1 where order_id =" . $order_id;
  258. $rowset = $this->DBTool->execSql($sql);
  259. $sql = "insert into order_ht_status_log(order_id,order_status,before_status,cancel_flag,create_user_id,create_time,update_user_id,update_time) values ($order_id,313,$order_status,0,$user_id,'{$today}',$user_id,'{$today}')";
  260. $rowset = $this->DBTool->execSql($sql);
  261. return $data;
  262. }
  263. //下订单后 存入短信信息
  264. function makeMessage($order_id, $mobile, $message, $now, $user_id)
  265. {
  266. $sql = "insert into order_send_message (id,order_id,send_mobile,send_message,send_time,create_user_id,create_time,update_user_id,update_time)
  267. VALUES ((select max(b.id)+1 from order_send_message as b),'$order_id','$mobile','$message','$now','$user_id','$now','$user_id','$now')";
  268. writeLog(__FUNCTION__ . " sql= " . $sql);
  269. $rowset = $this->DBTool->execSql($sql);
  270. return $rowset;
  271. }
  272. //重发短信 查询所需的电话号码
  273. // function getMoble($order_id)
  274. // {
  275. // $sql = "select send_mobile from order_send_message WHERE order_id='$order_id'";
  276. // writeLog(__FUNCTION__ . " sql= " . $sql);
  277. // $rowset = $this->DBTool->queryBySql($sql);
  278. // return $rowset['rowset'];
  279. // }
  280. //查询已发短信条数和内容
  281. function getMessageInfo($order_id)
  282. {
  283. $sql = "select send_message from order_send_message WHERE order_id='$order_id'";
  284. $sqlt = "select count(order_id) from order_send_message WHERE order_id='$order_id'";
  285. $message = $this->DBTool->queryBySql($sql);
  286. $count = $this->DBTool->queryBySql($sqlt);
  287. $data['code'] = $message['code'];
  288. $data['message'] = $message['rowset'];
  289. $data['count'] = $count['rowset'][0];
  290. return $data;
  291. }
  292. //查询短信所需信息
  293. function getmessage($order_id)
  294. {
  295. $sql = "select customer_name,
  296. parent_prod_name,
  297. order_description,
  298. hotel_address,
  299. customer_mobile
  300. from order_main AS A
  301. LEFT JOIN opera_hotel AS B on A.parent_prod_name=B.hotel_name WHERE order_id='$order_id'
  302. AND A.cancel_flag=0";
  303. $rowset = $this->DBTool->queryBySql($sql);
  304. return $rowset['rowset'][0];
  305. }
  306. /**
  307. * 获取供应商的采购负责人
  308. * @param $supplier_id
  309. * @return mixed
  310. */
  311. public function getPurchaser($supplier_id)
  312. {
  313. $sql = "select id as purchaser_id,purchaser_name from base_supplier_purchase where supplier_id=$supplier_id and product_type=25 and cancel_flag=0";
  314. $rowset = $this->DBTool->queryBySql($sql);
  315. return $rowset['rowset'][0];
  316. }
  317. /**
  318. * 获取运营人员
  319. * @param $hotel_id
  320. * @return mixed
  321. */
  322. public function getPrincipal($hotel_name)
  323. {
  324. $hotel_name = trim($hotel_name);
  325. $sql = "select true_name from base_user where id in (select principal from opera_hotel where hotel_name = '$hotel_name')";
  326. $rowset = $this->DBTool->queryBySql($sql);
  327. $tmp = array();
  328. foreach ($rowset['rowset'] as $k => $v) {
  329. $tmp[] = $v['true_name'];
  330. }
  331. $data = implode(',',$tmp);
  332. return $data;
  333. }
  334. function getPrice($order_id)
  335. {
  336. $sql = "select count(*) as num ,prod_start_station_date,A.base_price*count(*) as base_price from order_main as A LEFT JOIN run_hotel as B
  337. on A.run_id=B.id
  338. WHERE A.cancel_flag = 0 and A.parent_order_id='$order_id' GROUP BY PROD_START_STATION_DATE";
  339. $rowset = $this->DBTool->queryBySql($sql);
  340. return $rowset['rowset'];
  341. }
  342. }
  343. //
  344. //$HTOrderList = new HTOrderList();
  345. //$data = $HTOrderList->getMessageInfo(474455);
  346. //
  347. ////////$data =$HTOrderList ->getOrgList();
  348. ////////$data =$HTOrderList ->getHandleOrder(4565465, 1, 'hehehehe',148);
  349. //echo json_encode($data);