user_id . ",UPDATE_TIME=NOW() WHERE BUS_ID in (" . $bus_id . ")"; zzcsUtils::writeLog($sql); $result = $this->exec($sql); if ($result === false) { $json["code"] = "1"; $json["info"] = "车辆删除失败!"; return $json; } else { $json["code"] = "0"; $json["info"] = "车辆删除成功!"; return $json; } } } /** * @return array * 品牌列表 */ public function brandList() { $sql = "SELECT res_name,res_id FROM base_resource where RES_TYPE_ID=134 AND CANCEL_FLAG=0"; $brand_list = $this->query($sql); if ($brand_list === false) { $json = array(); $json["code"] = "1"; $json["info"] = "数据库错误"; return $json; } else { $json = array(); $json["code"] = "0"; $json["info"] = "品牌信息"; $json["data"] = $brand_list; return $json; } } /** * @param $web_data * @return array * 车辆列表 */ public function carList($web_data) { #region 获取渠道权限 $user_id = $this->user_id; $opera_org_id_sql = "select opera_org_id from base_user where id = " . $user_id . " and cancel_flag = 0"; $opera_org_id_result = $this->query($opera_org_id_sql); $opera_org_id = $opera_org_id_result[0]['opera_org_id']; if ($opera_org_id == '') { $and_sql = ''; } else { $and_sql = " and org_id in (" . $opera_org_id . ") "; } #endregion $brand_id = isset($web_data["brand_id"]) ? trim($web_data["brand_id"]) : false; $car_number = isset($web_data["car_number"]) ? trim($web_data["car_number"]) : false; $current_page = isset($web_data["current_page"]) ? trim($web_data["current_page"]) : false; $page_size = isset($web_data["page_size"]) ? trim($web_data["page_size"]) : false; if ($brand_id === false || $car_number === false || $current_page === false || $page_size === false) { $json = array(); $json["code"] = "2"; $json["info"] = "缺少必要参数"; return $json; } else { $size = ($current_page - 1) * $page_size; if ($brand_id == 0) { //没有选择品牌 $sql = "select bus_id,bus_no,seat_desc, IFNULL((SELECT res_name FROM base_resource where base_bus.BRAND_ID = base_resource.res_id and res_type_id = 134 and cancel_flag = 0),'' )AS bus_brand, IFNULL((SELECT type_name FROM dict_type where base_bus.bus_state=dict_type.id),'' )AS bus_state, IFNULL((SELECT supplier_name FROM base_supplier where base_bus.org_id=base_supplier.id and cancel_flag = 0),'') as company FROM base_bus WHERE bus_no LIKE '%" . $car_number . "%' AND cancel_flag=0 " . $and_sql . " LIMIT " . $size . "," . $page_size; $car_list = $this->query($sql); $sql_count = "select count(*) as count from (select bus_id,bus_no,seat_desc, IFNULL((SELECT res_name FROM base_resource where base_bus.BRAND_ID = base_resource.res_id and res_type_id = 134 and cancel_flag = 0),'' )AS bus_brand, IFNULL( (SELECT type_name FROM dict_type where base_bus.bus_state=dict_type.id),'' )AS bus_state,IFNULL( (SELECT supplier_name FROM base_supplier where base_bus.org_id=base_supplier.id and cancel_flag = 0),'') as company FROM base_bus WHERE bus_no LIKE '%" . $car_number . "%' AND cancel_flag=0 " . $and_sql . ") AS a"; $page_answer = $this->query($sql_count); $total = $page_answer[0]['count']; $total_page = ceil($total / $page_size); if ($car_list === false) { $json = array(); $json["code"] = "1"; $json["info"] = "车辆列表获取失败"; return $json; } else { $json = array(); $json["code"] = "0"; $json["info"] = "车辆列表获取成功"; $json["data"] = $car_list; $page = array(); $page["current_page"] = $current_page; $page["page_size"] = $page_size; $page["total_count"] = $total; $page["total_page"] = $total_page; $json["page"] = $page; return $json; } } else { $sql = "select bus_id,bus_no,seat_desc, IFNULL((SELECT res_name FROM base_resource where base_bus.BRAND_ID = base_resource.res_id and res_type_id = 134 and cancel_flag = 0),'' )AS bus_brand, IFNULL( (SELECT type_name FROM dict_type where base_bus.bus_state=dict_type.id),'' )AS bus_state,IFNULL( (SELECT supplier_name FROM base_supplier where base_bus.org_id=base_supplier.id and cancel_flag = 0),'') as company FROM base_bus WHERE bus_no LIKE '%" . $car_number . "%' AND brand_id=" . $brand_id . " AND cancel_flag=0 " . $and_sql . " LIMIT " . $size . "," . $page_size; $car_list = $this->query($sql); $sql_count = "select count(*) as count from (select bus_id,bus_no,seat_desc, IFNULL((SELECT res_name FROM base_resource where base_bus.BRAND_ID = base_resource.res_id and res_type_id = 134 and cancel_flag = 0),'' )AS bus_brand, IFNULL( (SELECT type_name FROM dict_type where base_bus.bus_state=dict_type.id),'' )AS bus_state,IFNULL( (SELECT supplier_name FROM base_supplier where base_bus.org_id=base_supplier.id and cancel_flag = 0),'') as company FROM base_bus WHERE bus_no LIKE '%" . $car_number . "%' AND brand_id=" . $brand_id . " AND cancel_flag=0 " . $and_sql . ") as a"; $page_answer = $this->query($sql_count); $total = $page_answer[0]['count']; $total_page = ceil($total / $page_size); if ($car_list === false) { $json = array(); $json["code"] = "1"; $json["info"] = "车辆列表获取失败"; return $json; } else { $json = array(); $json["code"] = "0"; $json["info"] = "车辆列表获取成功"; $json["data"] = $car_list; $page = array(); $page["current_page"] = $current_page; $page["page_size"] = $page_size; $page["total_count"] = $total; $page["total_page"] = $total_page; $json["page"] = $page; return $json; } } } } /** * @return array *所属车队列表 * */ public function orgList() { #region 获取渠道权限 $user_id = $this->user_id; $opera_org_id_sql = "select opera_org_id from base_user where id = " . $user_id . " and cancel_flag = 0"; $opera_org_id_result = $this->query($opera_org_id_sql); $opera_org_id = $opera_org_id_result[0]['opera_org_id']; if ($opera_org_id == '') { $and_sql = ''; } else { $and_sql = " and s.id in (" . $opera_org_id . ") "; } #endregion //$sql = "select res_name,res_id from base_resource where res_type_id=18"; //$sql = "SELECT DISTINCT supplier_id,(SELECT supplier_name FROM base_supplier where supplier_id=base_supplier.ID) as bus_team FROM base_supplier_purchase WHERE PRODUCT_TYPE =259 AND CANCEL_FLAG=0"; $sql = "select s.id as supplier_id,s.supplier_name as bus_team from base_supplier as s,base_supplier_purchase as p where s.cancel_flag = 0 and s.supplier_type = 187 " . $and_sql . " and p.cancel_flag = 0 and p.product_type = 259 group by s.id"; $orgList = $this->query($sql); if ($orgList === false) { $json = array(); $json["code"] = "1"; $json["info"] = "数据库错误"; return $json; } else { $json = array(); $json["code"] = "0"; $json["info"] = "公司信息"; $json["data"] = $orgList; return $json; } } /** * @param $web_data * @return array * 增加车辆信息 */ public function addCar($web_data) { $imgMeta = zzcsUtils::uploadMultiple('bus_img'); $imgType = ''; $imgPath = ''; if ($imgMeta) { $imgType = $imgMeta['type']; $imgPath = $imgMeta['path']; } $bus_number = isset($web_data["bus_number"]) ? trim($web_data["bus_number"]) : false;//车牌号 $bus_team = isset($web_data["bus_team"]) ? trim($web_data["bus_team"]) : false;//车队 $bus_brand = isset($web_data["bus_brand"]) ? trim($web_data["bus_brand"]) : false;//品牌 $bus_version = isset($web_data["bus_version"]) ? trim($web_data["bus_version"]) : false;//型号 $buy_date = isset($web_data["buy_date"]) ? trim($web_data["buy_date"]) : false;//购买日期 $seat_type = isset($web_data["seat_type"]) ? trim($web_data["seat_type"]) : false;//座位类型 $seat_number = isset($web_data["seat_number"]) ? trim($web_data["seat_number"]) : false;//座位数量 $driver = isset($web_data["driver"]) ? trim($web_data["driver"]) : false;//司机 $guider = isset($web_data["guider"]) ? trim($web_data["guider"]) : false;//导游 $auxiliary_seat = isset($web_data["auxiliary_seat"]) ? trim($web_data["auxiliary_seat"]) : false;//辅座 $consumption = isset($web_data["consumption"]) ? trim($web_data["consumption"]) : false;//油耗 $day_cost = isset($web_data["day_cost"]) ? trim($web_data["day_cost"]) : false;//成本 $status_select = isset($web_data["status_select"]) ? trim($web_data["status_select"]) : false;//状态 $bus_color = isset($web_data["bus_color"]) ? trim($web_data["bus_color"]) : false;//颜色 $bus_desc = isset($web_data["bus_desc"]) ? trim($web_data["bus_desc"]) : false;//车型描述 if ($bus_number === false || $bus_team === false || $bus_brand === false || $bus_version === false || $buy_date === false || $seat_type === false || $seat_number === false || $driver === false || $guider === false || $auxiliary_seat === false || $consumption === false || $day_cost === false || $status_select === false || $bus_color === false || $bus_desc === false) { $json = array(); $json["code"] = "2"; $json["info"] = "缺少必要参数"; return $json; } else { //座位数量前台没有传入具体数值 $seat_count = preg_replace('/[^\d]/', '', $bus_desc); if (empty($driver)) { $driver = ''; } if (empty($guider)) { $guider = ''; } if (empty($auxiliary_seat)) { $auxiliary_seat = ''; } if (empty($consumption)) { $consumption = ''; } if (empty($day_cost)) { $day_cost = ''; } if (empty($bus_color)) { $bus_color = 0; } $sql = "SELECT bus_id FROM base_bus WHERE 1=1 ORDER BY(bus_id) ASC"; $temp = $this->query($sql); if (!empty($temp)) { $bus_id = $temp[count($temp) - 1]["bus_id"] + 1; } $tmpArray = explode(',', $imgPath); $newArray = array_reverse($tmpArray); $imgPath = implode(',', $newArray); $tmpArray = explode(',', $imgType); $newArray = array_reverse($tmpArray); $imgType = implode(',', $newArray); $sql = "INSERT INTO base_bus (BUS_ID,CREATE_USER_ID,CREATE_TIME,UPDATE_USER_ID,UPDATE_TIME,CANCEL_FLAG,BUS_NO,BUS_TYPE_RES_ID,SEAT_COUNT,BRAND_ID,ORG_ID,SEAT_DESC,BUY_DATE,BUS_LICENSE,DRIVER_COUNT,TOUR_COUNT,EXTRA_COUNT,MPG,COST,BUS_STATE,SEAT_TYPE,BUS_COLOR,BUS_IMG_PATH, BUS_IMG_TYPE) VALUES (" . $bus_id . "," . $this->user_id . ",NOW()," . $this->user_id . ",NOW(),0,' " . $bus_number . " '," . $seat_number . "," . $seat_count . "," . $bus_brand . "," . $bus_team . ",'" . $bus_desc . "','" . $buy_date . "','" . $bus_version . "','" . $driver . "','" . $guider . "','" . $auxiliary_seat . "','" . $consumption . "','" . $day_cost . "'," . $status_select . "," . $seat_type . ",'" . $bus_color . "','" . $imgPath . "','" . $imgType . "')"; zzcsUtils::writeLog($sql); $res = $this->exec($sql); if ($res === false) { $json = array(); $json["code"] = "1"; $json["info"] = "新增车辆失败!"; return $json; } else { //网络原因,图片有可能会上传失败,但是车辆信息应该保存;返回的状态有区别 $json = array(); $json["code"] = "0"; $json["info"] = "新增车辆成功!"; return $json; } } } /** * @return array * 获取颜色列表 */ public function getColorList() { $sql = "SELECT res_name AS color,res_id FROM base_resource where RES_TYPE_ID =338 AND CANCEL_FLAG=0"; $res = $this->query($sql); if ($res === false) { $json = array(); $json["code"] = "1"; $json["info"] = "获取颜色列表失败!"; return $json; } else { $json = array(); $json["code"] = "0"; $json["info"] = "获取颜色列表成功!"; $json["data"] = $res; return $json; } } /** * @return array * 得到车辆当前状态 */ public function getSeatType() { //add by qius on 2016.11.09 $normal_seat_array = array(); $normal_seat_array[] = array("id" => 72, "seat_type" => "普通座"); $json = array(); $json["code"] = "0"; $json["info"] = "获取车辆状态成功!"; $json["data"] = $normal_seat_array; return $json; //end of add by qius on 2016.11.09 $sql = "SELECT type_name AS seat_type,id FROM dict_type where PARENT_ID =71"; $res = $this->query($sql); if ($res === false) { $json = array(); $json["code"] = "1"; $json["info"] = "获取座位类型失败!"; return $json; } else { $json = array(); $json["code"] = "0"; $json["info"] = "获取座位类型成功!"; $json["data"] = $res; return $json; } } /** * @return array * 得到车辆座位数类型 */ public function getSeatNumber() { $sql = "SELECT res_id,res_name AS seat_number FROM base_resource WHERE RES_TYPE_ID = 69 AND CANCEL_FLAG=0 ORDER BY res_name"; $res = $this->query($sql); if ($res === false) { $json = array(); $json["code"] = "1"; $json["info"] = "获取座位数量失败!"; return $json; } else { $json = array(); $json["code"] = "0"; $json["info"] = "获取座位数量成功!"; usort($res, 'my_sort'); $json["data"] = $res; return $json; } } /** * @return array * 得到车辆当前状态 */ public function getCarStatus() { $sql = "SELECT id,type_name AS bus_status FROM dict_type WHERE PARENT_ID =339"; $res = $this->query($sql); if ($res === false) { $json = array(); $json["code"] = "1"; $json["info"] = "获取车辆状态失败!"; return $json; } else { $json = array(); $json["code"] = "0"; $json["info"] = "获取车辆状态成功!"; $json["data"] = $res; return $json; } } /** * @return array * 得到车辆图片类型数组 */ public function getImgType() { $sql = "SELECT id,type_name AS img_status FROM dict_type WHERE PARENT_ID =360"; $res = $this->query($sql); if ($res === false) { $json = array(); $json["code"] = "1"; $json["info"] = "获取图片类型失败!"; return $json; } else { $json = array(); $json["code"] = "0"; $json["info"] = "获取图片类型成功!"; $json["data"] = $res; return $json; } } /** * @param $web_data * @return array * 修改车辆信息 */ public function reviseCar($web_data) { $bus_id = isset($web_data["bus_id"]) ? trim($web_data["bus_id"]) : false;//车牌号 $bus_number = isset($web_data["bus_number"]) ? trim($web_data["bus_number"]) : false;//车牌号 $bus_team = isset($web_data["bus_team"]) ? trim($web_data["bus_team"]) : false;//车队 $bus_brand = isset($web_data["bus_brand"]) ? trim($web_data["bus_brand"]) : false;//品牌 $bus_version = isset($web_data["bus_version"]) ? trim($web_data["bus_version"]) : false;//型号 $buy_date = isset($web_data["buy_date"]) ? trim($web_data["buy_date"]) : false;//购买日期 $seat_type = isset($web_data["seat_type"]) ? trim($web_data["seat_type"]) : false;//座位类型 $seat_number = isset($web_data["seat_number"]) ? trim($web_data["seat_number"]) : false;//座位数量 $driver = isset($web_data["driver"]) ? trim($web_data["driver"]) : false;//司机 $guider = isset($web_data["guider"]) ? trim($web_data["guider"]) : false;//导游 $auxiliary_seat = isset($web_data["auxiliary_seat"]) ? trim($web_data["auxiliary_seat"]) : false;//辅座 $consumption = isset($web_data["consumption"]) ? trim($web_data["consumption"]) : false;//油耗 $day_cost = isset($web_data["day_cost"]) ? trim($web_data["day_cost"]) : false;//成本 $status_select = isset($web_data["status_select"]) ? trim($web_data["status_select"]) : false;//状态 $bus_color = isset($web_data["bus_color"]) ? trim($web_data["bus_color"]) : false;//颜色 $bus_desc = isset($web_data["bus_desc"]) ? trim($web_data["bus_desc"]) : false;//车型描述 $old_path = ''; $old_type = ''; if (isset($web_data['bus_img_path_old'])) { foreach ($web_data['bus_img_path_old'] as $key => $item) { if ($item != '' || $web_data['bus_img_type_old'][$key] != '') { $type = $web_data['bus_img_type_old'][$key]; if ($old_path == '') { $old_path .= $item; $old_type .= $type; } else { $old_path .= ',' . $item; $old_type .= ',' . $type; } } } } if ($bus_id === false || $bus_number === false || $bus_team === false || $bus_brand === false || $bus_version === false || $buy_date === false || $seat_type === false || $seat_number === false || $driver === false || $guider === false || $auxiliary_seat === false || $consumption === false || $day_cost === false || $status_select === false || $bus_color === false || $bus_desc === false) { $json = array(); $json["code"] = "2"; $json["info"] = "缺少必要参数"; return $json; } else { //座位数量前台没有传入具体数值 $seat_count = preg_replace('/[^\d]/', '', $bus_desc); //更新操作 if (empty($driver)) { $driver = ''; } if (empty($guider)) { $guider = ''; } if (empty($auxiliary_seat)) { $auxiliary_seat = ''; } if (empty($consumption)) { $consumption = ''; } if (empty($day_cost)) { $day_cost = ''; } if (empty($bus_color)) { $bus_color = 0; } $imgType = ''; $imgPath = ''; $imgMeta = zzcsUtils::uploadMultiple('bus_img'); if ($imgMeta) { $imgType = $imgMeta['type']; $imgPath = $imgMeta['path']; } $imgPath = $old_path == '' ? $imgPath : $old_path . ($imgPath != '' ? (',' . $imgPath) : ''); $imgType = $old_type == '' ? $imgType : $old_type . ($imgType != '' ? (',' . $imgType) : ''); $tmpArray = explode(',', $imgPath); $newArray = array_reverse($tmpArray); $imgPath = implode(',', $newArray); $tmpArray = explode(',', $imgType); $newArray = array_reverse($tmpArray); $imgType = implode(',', $newArray); //删除旧图片 zzcsUtils::deleteFiles($web_data['bus_img_allpath_old'], $imgPath); $sql = "UPDATE base_bus set UPDATE_USER_ID=" . $this->user_id . ",UPDATE_TIME=NOW(),BUS_NO='" . $bus_number . "',BUS_TYPE_RES_ID=" . $seat_number . "',SEAT_COUNT=" . $seat_count . ",BRAND_ID=" . $bus_brand . ",ORG_ID=" . $bus_team . ",SEAT_DESC='" . $bus_desc . "',BUY_DATE='" . $buy_date . "', BUS_LICENSE='" . $bus_version . "',DRIVER_COUNT='" . $driver . "',TOUR_COUNT='" . $guider . "',EXTRA_COUNT='" . $auxiliary_seat . "',MPG='" . $consumption . "',COST='" . $day_cost . "',BUS_STATE=" . $status_select . ",SEAT_TYPE=" . $seat_type . ",BUS_COLOR=" . $bus_color . ",BUS_IMG_PATH='" . $imgPath . "',BUS_IMG_TYPE='" . $imgType . "' WHERE bus_id=" . $bus_id; zzcsUtils::writeLog($sql); $res = $this->exec($sql); if ($res === false) { $json = array(); $json["code"] = "1"; $json["info"] = "更新车辆信息失败!"; return $json; } else { $json = array(); $json["code"] = "0"; $json["info"] = "更新车辆信息成功!"; return $json; } } } /** * @param $web_data * @return array * 得到车辆详细信息 */ public function getBusInfo($web_data) { //得到基本信息 $bus_id = isset($web_data["bus_id"]) ? trim($web_data["bus_id"]) : false;//得到bus_id if ($bus_id === false) { $json = array(); $json["code"] = "1"; $json["info"] = "获取车辆信息失败!"; return $json; } else { $sql = "SELECT bus_type_res_id, brand_id,bus_id ,bus_no,org_id,buy_date,bus_license,driver_count,tour_count,extra_count,mpg,cost,bus_state,seat_type,bus_color, bus_img_path, bus_img_type FROM base_bus WHERE bus_id = " . $bus_id . " AND cancel_flag = 0"; $res = $this->query($sql); if ($res === false) { $json = array(); $json["code"] = "1"; $json["info"] = "获取车辆信息失败!"; return $json; } else { $json = array(); $json["code"] = "0"; $json["info"] = "获取车辆信息成功!"; $temp = $res[0]['buy_date']; $temp_arr = explode('-', $temp); $res[0]['buy_year'] = $temp_arr[0]; $res[0]['buy_month'] = $temp_arr[1]; $json["data"] = $res; return $json; } } } } /** * @param $a * @param $b * @return int * 自定义比较函数 */ function my_sort($a, $b) { $a_number = (int)mb_substr($a["seat_number"], 0, mb_strlen($a["seat_number"]) - 1); $b_number = (int)mb_substr($b["seat_number"], 0, mb_strlen($b["seat_number"]) - 1); if ($a_number == $b_number) { return 0; } return $a_number > $b_number ? +1 : -1; }