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.
 
 
 
 

415 lines
20 KiB

  1. <?php
  2. //author:fuhc
  3. //date:20161027
  4. //车次调度类
  5. class singleDispatch extends base
  6. {
  7. private $company_list; //公司列表
  8. // 得到车次调度列表
  9. public function getRunList($web_data)
  10. {
  11. $user_id = $this->user_id;
  12. $dispatch_status = isset($web_data['dispatch_status']) ? $web_data['dispatch_status'] : 0;
  13. $sort_id = isset($web_data['sort_id']) ? $web_data['sort_id'] : 0;
  14. $current_page = isset($web_data['current_page']) ? $web_data['current_page'] : 1;
  15. $page_size = isset($web_data['page_size']) ? $web_data['page_size'] : 10;
  16. $start_area = isset($web_data['start_area']) ? $web_data['start_area'] : '';
  17. $end_area = isset($web_data['end_area']) ? $web_data['end_area'] : '';
  18. $line = isset($web_data['line']) ? $web_data['line'] : '';
  19. $start_date = isset($web_data['start_date']) ? $web_data['start_date'] : '';
  20. $end_date = isset($web_data['end_date']) ? $web_data['end_date'] : '';
  21. $bus_type = isset($web_data['bus_type']) ? $web_data['bus_type'] : '0';
  22. //得到车次调度列表
  23. $sql = "CALL SP_GET_RUN_NO_LIST_XM({$user_id},{$current_page},{$page_size},'{$start_area}','{$end_area}','{$line}','{$start_date}','{$end_date}',{$dispatch_status},{$bus_type},{$sort_id})";
  24. zzcsUtils::writeLog($sql);
  25. $result = $this->procQuery($sql);
  26. $data = array();
  27. if ($result === false) {
  28. $data['code'] = '500';
  29. $data['info'] = '数据库存储过程错误';
  30. return $data;
  31. }
  32. $data['code'] = "0";
  33. $data['info'] = '获得车次调度列表成功';
  34. if ($result['code'] != "0") {
  35. $data['code'] = $result['code'];
  36. $data['info'] = $result['info'];
  37. return $data;
  38. }
  39. $data['page']['current_page'] = $result['data'][0][0]['currpage'];
  40. $data['page']['page_size'] = $result['data'][0][0]['page_size'];
  41. $data['page']['total_page'] = $result['data'][0][0]['total_page'];
  42. $data['page']['total_count'] = $result['data'][0][0]['total'];
  43. foreach ($result['data'][1] as $k => $v) {
  44. $tv = (string)$v['send_status'];
  45. $data['status_count'][$tv] = $v['count'];
  46. }
  47. // 线路类型
  48. $data['bus_group_list'] = array(
  49. array('group_id' => '1', 'group_name' => '苏州线A'),
  50. array('group_id' => '2', 'group_name' => '苏州线B'),
  51. array('group_id' => '3', 'group_name' => '周庄线'),
  52. array('group_id' => '4', 'group_name' => '杭州线')
  53. );
  54. $data['run_list'] = isset($result['data'][2]) ? $result['data'][2] : array();
  55. return $data;
  56. }
  57. //根据车牌号和公司查询车辆
  58. public function getVehicleList($param)
  59. {
  60. #region 获取渠道权限
  61. $user_id = $this->user_id;
  62. $opera_org_id_sql = "select opera_org_id from base_user where id = " . $user_id . " and cancel_flag = 0";
  63. $opera_org_id_result = $this->query($opera_org_id_sql);
  64. $opera_org_id = $opera_org_id_result[0]['opera_org_id'];
  65. if($opera_org_id == ''){
  66. $and_sql = '';
  67. }else{
  68. $and_sql = " and org_id in (" . $opera_org_id . ") ";
  69. }
  70. #endregion
  71. $keyword = isset($param['keyword']) ? "'" . $param['keyword'] . "'" : "''";
  72. $company = isset($param['company']) ? (empty($param['company']) ? "0" : $param['company']) : "0";
  73. $salecount = isset($param['salecount']) ? (empty($param['salecount']) ? "0" : $param['salecount']) : "0";
  74. $run_date = isset($param['run_date']) ? (empty($param['run_date']) ? "" : $param['run_date']) : "";
  75. $run_time = isset($param['run_time']) ? (empty($param['run_time']) ? "" : $param['run_time']) : "";
  76. if (date('Y-m-d', strtotime($run_date)) == date('Y-m-d', time())) { //派今天的车
  77. $sql_car_list = "select bus_id as res_id,
  78. bus_no as vihicle_number,
  79. ifnull((select res_name from base_resource where res_id = base_bus.brand_id and res_type_id = 134 and cancel_flag =0),'') as vihicle_brand,
  80. seat_desc as vihicle_seat,
  81. ifnull((select supplier_name as res_name from base_supplier where id = base_bus.org_id and cancel_flag =0),'') as company_name,
  82. seat_count,
  83. bus_state as bus_status
  84. from base_bus
  85. where bus_state = 336 and cancel_flag = 0
  86. and bus_id not in ( select b.send_bus_res_id
  87. from run_main m, run_bus b
  88. where m.run_id = b.run_id
  89. and m.run_date = '{$run_date}'
  90. and b.run_bus_status in (138,139,140)
  91. and b.send_bus_res_id > 0
  92. )
  93. and seat_count >= $salecount
  94. " . $and_sql . "
  95. and if(length(trim({$keyword}))=0,0=0,bus_no like concat('%',{$keyword},'%'))
  96. and if({$company}<=0,0=0,org_id = {$company})
  97. order by seat_count desc;";
  98. } else {
  99. $sql_car_list = "select bus_id as res_id,
  100. bus_no as vihicle_number,
  101. ifnull((select res_name from base_resource where res_id = a.brand_id and res_type_id = 134 and cancel_flag =0),'') as vihicle_brand,
  102. seat_desc as vihicle_seat,
  103. ifnull((select res_name from base_resource where res_id = a.org_id and res_type_id = 18 and cancel_flag =0),'') as company_name,
  104. seat_count,
  105. bus_state as bus_status
  106. from base_bus a
  107. where a.bus_state = 336 and a.cancel_flag = 0
  108. and a.bus_id not in ( select b.send_bus_res_id
  109. from run_main m, run_bus b, run_station s
  110. where m.run_id = b.run_id
  111. and m.run_id = s.RUN_ID
  112. and m.prod_id = s.prod_id
  113. and m.run_date = '{$run_date}'
  114. and m.prod_id > 0
  115. and b.send_bus_res_id > 0
  116. group by m.run_id,b.send_bus_res_id
  117. having max(START_MINUTES) > (select min(prod_start_station_time_minutes)
  118. from order_main
  119. where parent_order_id = 0 and prod_start_station_date = '{$run_date}'
  120. and parent_prod_id in (select line_id from opera_line where line_type = 316 and cancel_flag = 0) and order_valid_status = 1 and cancel_flag = 0)
  121. )
  122. and seat_count >= $salecount
  123. " . $and_sql . "
  124. and if(length(trim({$keyword}))=0,0=0,bus_no like concat('%',{$keyword},'%'))
  125. and if({$company}<=0,0=0,org_id = {$company})
  126. order by seat_count desc;";
  127. }
  128. zzcsUtils::writeLog($sql_car_list);
  129. $result = $this->query($sql_car_list);
  130. if (false === $result) {
  131. $json['code'] = '1';
  132. $json['info'] = '数据库错误';
  133. } else {
  134. $json['code'] = '0';
  135. $json['info'] = '返回数据成功';
  136. $json['vehicle_list'] = $result;
  137. }
  138. return $json;
  139. }
  140. //根据司机姓名手机号和公司查询司机
  141. public function getDriverList($param)
  142. {
  143. #region 获取渠道权限
  144. $user_id = $this->user_id;
  145. $opera_org_id_sql = "select opera_org_id from base_user where id = " . $user_id . " and cancel_flag = 0";
  146. $opera_org_id_result = $this->query($opera_org_id_sql);
  147. $opera_org_id = $opera_org_id_result[0]['opera_org_id'];
  148. if($opera_org_id == ''){
  149. $and_sql = '';
  150. }else{
  151. $and_sql = " and org_id in (" . $opera_org_id . ") ";
  152. }
  153. #endregion
  154. $keyword = isset($param['keyword']) ? "'" . $param['keyword'] . "'" : "''";
  155. $company = isset($param['company']) ? (empty($param['company']) ? '0' : $param['company']) : '0';
  156. $run_date = isset($param['run_date']) ? (empty($param['run_date']) ? "" : $param['run_date']) : "";
  157. $run_time = isset($param['run_time']) ? (empty($param['run_time']) ? "" : $param['run_time']) : "";
  158. if ($run_date == '' && $run_time == '') {
  159. $driver_status = "'0' as driver_status";
  160. } else {
  161. $driver_status = "(select count(id) FROM run_bus WHERE SEND_BUS_DRIVER_RES_ID = base_driver.driver_id AND CANCEL_FLAG = 0 AND RUN_ID in(SELECT run_id FROM RUN_MAIN WHERE RUN_DATE = '" . $run_date . "' AND RUN_TIME <= '" . $run_time . "') LIMIT 1) as driver_status";
  162. }
  163. $sql = "select
  164. driver_id as res_id,
  165. driver_name,
  166. driver_number,
  167. ifnull(phone_no,'') as driver_phone,
  168. (select supplier_name from base_supplier where id = base_driver.org_id) as company_name,
  169. " . $driver_status . "
  170. from base_driver
  171. where cancel_flag = 0
  172. " . $and_sql . "
  173. AND IF(length(trim(" . $keyword . "))<=0,0=0,(driver_name LIKE CONCAT('%'," . $keyword . ",'%') OR phone_no LIKE CONCAT('%'," . $keyword . ",'%')))
  174. AND IF(" . $company . "<=0,0=0,org_id=" . $company . ")";
  175. zzcsUtils::writeLog($sql);
  176. $result = $this->query($sql);
  177. if (false === $result) {
  178. $json['code'] = '1';
  179. $json['info'] = '数据库错误';
  180. } else {
  181. $json['code'] = '0';
  182. $json['info'] = '返回数据成功';
  183. $json['driver_list'] = $result;
  184. }
  185. return $json;
  186. }
  187. //根据导游姓名手机号和公司查询导游
  188. public function getGuideList($param)
  189. {
  190. #region 获取渠道权限
  191. $user_id = $this->user_id;
  192. $opera_org_id_sql = "select opera_org_id from base_user where id = " . $user_id . " and cancel_flag = 0";
  193. $opera_org_id_result = $this->query($opera_org_id_sql);
  194. $opera_org_id = $opera_org_id_result[0]['opera_org_id'];
  195. if($opera_org_id == ''){
  196. $and_sql = '';
  197. }else{
  198. $and_sql = " and org_id in (" . $opera_org_id . ") ";
  199. }
  200. #endregion
  201. $keyword = isset($param['keyword']) ? "'" . $param['keyword'] . "'" : "''";
  202. $company = isset($param['company']) ? (empty($param['company']) ? '0' : $param['company']) : '0';
  203. $run_date = isset($param['run_date']) ? (empty($param['run_date']) ? "" : $param['run_date']) : "";
  204. $run_time = isset($param['run_time']) ? (empty($param['run_time']) ? "" : $param['run_time']) : "";
  205. if ($run_date == '' && $run_time == '') {
  206. $guide_status = "'0' as guide_status";
  207. } else {
  208. $guide_status = "(select count(id) FROM run_bus WHERE SEND_TOUR_GUIDE_RES_ID = base_guide.guide_id AND CANCEL_FLAG = 0 AND RUN_ID in(SELECT run_id FROM RUN_MAIN WHERE RUN_DATE = '" . $run_date . "' AND RUN_TIME <= '" . $run_time . "') LIMIT 1) as guide_status";
  209. }
  210. $sql = "select
  211. guide_id as res_id,
  212. guide_name,
  213. phone_no as guide_phone,
  214. (select supplier_name from base_supplier where id = base_guide.org_id) as company_name,
  215. " . $guide_status . "
  216. from base_guide
  217. where cancel_flag = 0
  218. " . $and_sql . "
  219. AND IF(length(trim(" . $keyword . "))<=0,0=0,(guide_name LIKE CONCAT('%'," . $keyword . ",'%') OR phone_no LIKE CONCAT('%'," . $keyword . ",'%')))
  220. AND IF(" . $company . "<=0,0=0,org_id=" . $company . ")";
  221. zzcsUtils::writeLog($sql);
  222. $result = $this->query($sql);
  223. if (false === $result) {
  224. $json['code'] = '1';
  225. $json['info'] = '数据库错误';
  226. } else {
  227. $json['code'] = '0';
  228. $json['info'] = '返回数据成功';
  229. $json['guide_list'] = $result;
  230. }
  231. return $json;
  232. }
  233. //得到公司列表
  234. public function getCompanyList()
  235. {
  236. #region 获取渠道权限
  237. $user_id = $this->user_id;
  238. $opera_org_id_sql = "select opera_org_id from base_user where id = " . $user_id . " and cancel_flag = 0";
  239. $opera_org_id_result = $this->query($opera_org_id_sql);
  240. $opera_org_id = $opera_org_id_result[0]['opera_org_id'];
  241. if($opera_org_id == ''){
  242. $and_sql = '';
  243. }else{
  244. $and_sql = " and s.id in (" . $opera_org_id . ") ";
  245. }
  246. #endregion
  247. if (!$this->company_list) {
  248. $sql = "SELECT
  249. s.id as res_id,
  250. s.supplier_name as res_name
  251. from base_supplier as s,
  252. base_supplier_purchase as p
  253. WHERE
  254. s.id = p.supplier_id
  255. and s.cancel_flag = 0
  256. and p.cancel_flag = 0
  257. and p.product_type = 259
  258. " . $and_sql . "
  259. group by s.id";
  260. $result = $this->query($sql);
  261. $data = array();
  262. $data['code'] = '0';
  263. $data['info'] = '';
  264. $data['company_list'] = array();
  265. if ($result === false) {
  266. $data['code'] = '1';
  267. $data['info'] = '获取公司列表失败';
  268. } else {
  269. $data['code'] = '0';
  270. $data['info'] = '获取公司列表成功';
  271. $data['company_list'] = $result;
  272. }
  273. }
  274. if ($data['code'] != '0') {
  275. $this->company_list = array();
  276. } else {
  277. $this->company_list = $data;
  278. }
  279. return $this->company_list;
  280. }
  281. /*
  282. * 车辆派遣
  283. * @bus_id run_bus表中的id,参数名称有点乱
  284. * @res_id bus_base表中的bus_id
  285. * @user_id user_id
  286. */
  287. public function vehicleDispatch($param)
  288. {
  289. $user_id = $this->user_id;
  290. $bus_id = isset($param['bus_id']) ? (empty($param['bus_id']) ? '' : $param['bus_id']) : '';//这里的bus_id是run_bus表里的第一列唯一ID值
  291. $res_id = isset($param['res_id']) ? (empty($param['res_id']) ? '' : $param['res_id']) : '';
  292. if ('' == $bus_id || '' == $res_id) {
  293. $data['code'] = '1';
  294. $data['info'] = '缺少必要参数';
  295. return $data;
  296. }
  297. //这里加一个判断,判断该bus_id的车次已售座位数是否小于等于 所拍车的座位数--如果是,则返回错误信息---温依莅
  298. $sql="select ((select seat_count from base_bus where bus_id=$res_id limit 1)-(select SALED_COUNT from run_bus where id=$bus_id limit 1)) as diff_num;";
  299. $res = $this->query($sql);
  300. if(false===$res){
  301. $data['code'] = '1';
  302. $data['info'] = '获取数据失败';
  303. return $data;
  304. }
  305. $diff_num=$res[0]['diff_num'];//表示 所选车的座位数-所选车次的已售人数;如果该数值小于0,则不可派该车。
  306. if($diff_num<0){
  307. $data['code'] = '2';
  308. $data['info'] = '所选车座位数小于该车次已售人数,请选择其他车辆';
  309. return $data;
  310. }
  311. //----//
  312. $sql = "CALL SP_VEHICLE_DISPATCH($user_id,$bus_id,$res_id)";
  313. zzcsUtils::writeLog($sql);
  314. $result = $this->procQuery($sql);
  315. $data = array();
  316. if ($result === false) {
  317. $data['code'] = '500';
  318. $data['info'] = '数据库存储过程错误';
  319. return $data;
  320. }
  321. $data['code'] = isset($result['data'][0][0]['errorcode']) ? $result['data'][0][0]['errorcode'] : '1';
  322. $data['info'] = isset($result['data'][0][0]['errorinfo']) ? $result['data'][0][0]['errorinfo'] : '未从数据库获得返回值';
  323. return $data;
  324. }
  325. //司机派遣
  326. public function driverDispatch($param)
  327. {
  328. $user_id = $this->user_id;
  329. $bus_id = isset($param['bus_id']) ? (empty($param['bus_id']) ? '' : $param['bus_id']) : '';
  330. $res_id = isset($param['res_id']) ? (empty($param['res_id']) ? '' : $param['res_id']) : '';
  331. if ('' == $bus_id || '' == $res_id) {
  332. $data['code'] = '1';
  333. $data['info'] = '缺少必要参数';
  334. return $data;
  335. }
  336. $sql = "CALL SP_DRIVER_DISPATCH($user_id,$bus_id,$res_id)";
  337. zzcsUtils::writeLog($sql);
  338. $result = $this->procQuery($sql);
  339. $data = array();
  340. if ($result === false) {
  341. $data['code'] = '500';
  342. $data['info'] = '数据库存储过程错误';
  343. return $data;
  344. }
  345. $data['code'] = isset($result['data'][0][0]['errorcode']) ? $result['data'][0][0]['errorcode'] : '1';
  346. $data['info'] = isset($result['data'][0][0]['errorinfo']) ? $result['data'][0][0]['errorinfo'] : '未从数据库获得返回值';
  347. return $data;
  348. }
  349. //导游派遣
  350. public function guideDispatch($param)
  351. {
  352. $user_id = $this->user_id;
  353. $bus_id = isset($param['bus_id']) ? (empty($param['bus_id']) ? '' : $param['bus_id']) : '';
  354. $res_id = isset($param['res_id']) ? (empty($param['res_id']) ? '' : $param['res_id']) : '';
  355. if ('' == $bus_id || '' == $res_id) {
  356. $data['code'] = '1';
  357. $data['info'] = '缺少必要参数';
  358. return $data;
  359. }
  360. $sql = "CALL SP_GUIDE_DISPATCH($user_id,$bus_id,$res_id)";
  361. zzcsUtils::writeLog($sql);
  362. $result = $this->procQuery($sql);
  363. $data = array();
  364. if ($result === false) {
  365. $data['code'] = '500';
  366. $data['info'] = '数据库存储过程错误';
  367. return $data;
  368. }
  369. $data['code'] = isset($result['data'][0][0]['errorcode']) ? $result['data'][0][0]['errorcode'] : '1';
  370. $data['info'] = isset($result['data'][0][0]['errorinfo']) ? $result['data'][0][0]['errorinfo'] : '未从数据库获得返回值';
  371. return $data;
  372. }
  373. //重置车辆-司机-导游的派遣
  374. public function resetDispatch($param)
  375. {
  376. $user_id = $this->user_id;
  377. $idstr = isset($param['idstr']) ? $param['idstr'] : '';
  378. if ('' == $idstr) {
  379. $data['code'] = '1';
  380. $data['info'] = '缺少必要参数';
  381. return $data;
  382. }
  383. $sql = "CALL sp_update_run_dispatch_xm(" . $user_id . ",'" . $idstr . "')";
  384. zzcsUtils::writeLog($sql);
  385. $result = $this->procQuery($sql);
  386. $data = array();
  387. if ($result === false) {
  388. $data['code'] = '500';
  389. $data['info'] = '数据库存储过程错误';
  390. return $data;
  391. }
  392. $data['code'] = isset($result['data'][0][0]['errorcode']) ? $result['data'][0][0]['errorcode'] : '1';
  393. $data['info'] = isset($result['data'][0][0]['errorinfo']) ? $result['data'][0][0]['errorinfo'] : '未从数据库获得返回值';
  394. return $data;
  395. }
  396. }