作者 郭文星

123

1 <?php 1 <?php
2 2
  3 +/**
  4 + * 首字母排序A-Z(含汉字)
  5 + */
  6 +if (!function_exists('getFirstChar')) {
  7 + function getFirstChar($s)
  8 + {
  9 + $s0 = mb_substr($s, 0, 1); //获取名字的姓
  10 + $s = iconv('UTF-8', 'gb2312', $s0); //将UTF-8转换成GB2312编码
  11 +//var_dump(ord($s0));
  12 +// var_dump(ord($s));
  13 + if (ord($s0) > 128) { //汉字开头,汉字没有以U、V开头的
  14 +
  15 + $asc = ord($s{0}) * 256 + ord($s{1}) - 65536;
  16 + if ($asc >= -20319 and $asc <= -20284) return "A";
  17 + if ($asc >= -20283 and $asc <= -19776) return "B";
  18 + if ($asc >= -19775 and $asc <= -19219) return "C";
  19 + if ($asc >= -19218 and $asc <= -18711) return "D";
  20 + if ($asc >= -18710 and $asc <= -18527) return "E";
  21 + if ($asc >= -18526 and $asc <= -18240) return "F";
  22 + if ($asc >= -18239 and $asc <= -17760) return "G";
  23 + if ($asc >= -17759 and $asc <= -17248) return "H";
  24 + if ($asc >= -17247 and $asc <= -17418) return "I";
  25 + if ($asc >= -17417 and $asc <= -16475) return "J";
  26 + if ($asc >= -16474 and $asc <= -16213) return "K";
  27 + if ($asc >= -16212 and $asc <= -15641) return "L";
  28 + if ($asc >= -15640 and $asc <= -15166) return "M";
  29 + if ($asc >= -15165 and $asc <= -14923) return "N";
  30 + if ($asc >= -14922 and $asc <= -14915) return "O";
  31 + if ($asc >= -14914 and $asc <= -14631) return "P";
  32 + if ($asc >= -14630 and $asc <= -14150) return "Q";
  33 + if ($asc >= -14149 and $asc <= -14091) return "R";
  34 + if ($asc >= -14090 and $asc <= -13319) return "S";
  35 + if ($asc >= -13318 and $asc <= -12839) return "T";
  36 + if ($asc >= -12838 and $asc <= -12557) return "W";
  37 + if ($asc >= -12556 and $asc <= -11848) return "X";
  38 + if ($asc >= -11847 and $asc <= -11056) return "Y";
  39 + if ($asc >= -11055 and $asc <= -10247) return "Z";
  40 + } else if (ord($s) >= 48 && ord($s) <= 57) {//数字开头
  41 + $aa = @iconv_substr($s, 0, 1, 'utf-8');
  42 + switch ($aa) {
  43 + case 1:
  44 + return "Y";
  45 + case 2:
  46 + return "E";
  47 + case 3:
  48 + return "S";
  49 + case 4:
  50 + return "S";
  51 + case 5:
  52 + return "W";
  53 + case 6:
  54 + return "L";
  55 + case 7:
  56 + return "Q";
  57 + case 8:
  58 + return "B";
  59 + case 9:
  60 + return "J";
  61 + case 0:
  62 + return "L";
  63 + }
  64 + } else if (ord($s) >= 65 && ord($s) <= 90) { //大写英文开头
  65 + return substr($s, 0, 1);
  66 + } else if (ord($s) >= 97 && ord($s) <= 122) { //小写英文开头
  67 + return strtoupper(substr($s, 0, 1));
  68 + } else {
  69 + return iconv_substr($s0, 0, 1, 'utf-8');
  70 +//中英混合的词语,不适合上面的各种情况,因此直接提取首个字符即可
  71 + }
  72 + }
  73 +}
3 if (!function_exists('http_request')) { 74 if (!function_exists('http_request')) {
4 // curl请求 75 // curl请求
5 function http_request($url, $timeout = 30, $header = array()) 76 function http_request($url, $timeout = 30, $header = array())
@@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
3 namespace app\api\controller; 3 namespace app\api\controller;
4 4
5 use app\api\controller\inspection\Task; 5 use app\api\controller\inspection\Task;
  6 +use app\api\controller\tencentim\Openim;
6 use app\api\controller\v1\Base; 7 use app\api\controller\v1\Base;
7 use app\common\controller\Api; 8 use app\common\controller\Api;
8 use think\Db; 9 use think\Db;
@@ -1105,4 +1106,95 @@ class Car extends Base @@ -1105,4 +1106,95 @@ class Car extends Base
1105 $data=["data"=>$res,"amount"=>$amount]; 1106 $data=["data"=>$res,"amount"=>$amount];
1106 return $this->success("请求成功",$data); 1107 return $this->success("请求成功",$data);
1107 } 1108 }
  1109 +
  1110 + /**
  1111 + * 从蒙自出发
  1112 + * @return void
  1113 + */
  1114 + public function set_out(){
  1115 + $where = ["start_address"=>"蒙自"];
  1116 + $indexList = [];
  1117 + $itemArr = [];
  1118 + $list = Db::name("route")->where($where)
  1119 + ->select();
  1120 + $charArray = [];
  1121 + $back_data = [];
  1122 + if (!empty($list)) {
  1123 + $count = count($list);
  1124 + $addnum = 500;//因为即时通讯人员状态每次限制查500人;所以得分开查
  1125 + for ($i = 0; $i < $count; $i = $i + $addnum) {
  1126 + if ($count - $i > 0) {
  1127 + $j = $i - 1 > 0 ? $i : 0;
  1128 + $data = array_slice($list, $j, $addnum);
  1129 +
  1130 +
  1131 + }
  1132 + }
  1133 + $staff_names = array_column($list, 'end_address');
  1134 + array_multisort($staff_names, SORT_ASC, $list);
  1135 +
  1136 + foreach ($list as $k => $v) {
  1137 + $char = getFirstChar($v['end_address']);
  1138 + $nameArray = array();
  1139 + if (@count($charArray[$char]) != 0) {
  1140 + $nameArray = $charArray[$char];
  1141 + }
  1142 + array_push($nameArray, $v);
  1143 + $charArray[$char] = $nameArray;
  1144 + }
  1145 + ksort($charArray);
  1146 +
  1147 + $indexList = array_keys($charArray);
  1148 + $itemArr = array_values($charArray);
  1149 + }
  1150 +
  1151 + array_unshift($indexList, "*");
  1152 + $this->success("数据获取成功", ["indexList" => $indexList, "itemArr" => $itemArr]);
  1153 +
  1154 + }
  1155 +
  1156 +
  1157 + /**
  1158 + * 到达蒙自
  1159 + * @return void
  1160 + */
  1161 + public function reach(){
  1162 + $where = ["end_address"=>"蒙自"];
  1163 + $indexList = [];
  1164 + $itemArr = [];
  1165 + $list = Db::name("route")->where($where)
  1166 + ->select();
  1167 + $charArray = [];
  1168 + $back_data = [];
  1169 + if (!empty($list)) {
  1170 + $count = count($list);
  1171 + $addnum = 500;//因为即时通讯人员状态每次限制查500人;所以得分开查
  1172 + for ($i = 0; $i < $count; $i = $i + $addnum) {
  1173 + if ($count - $i > 0) {
  1174 + $j = $i - 1 > 0 ? $i : 0;
  1175 + $data = array_slice($list, $j, $addnum);
  1176 + }
  1177 + }
  1178 + $staff_names = array_column($list, 'start_address');
  1179 + array_multisort($staff_names, SORT_ASC, $list);
  1180 +
  1181 + foreach ($list as $k => $v) {
  1182 + $char = getFirstChar($v['start_address']);
  1183 + $nameArray = array();
  1184 + if (@count($charArray[$char]) != 0) {
  1185 + $nameArray = $charArray[$char];
  1186 + }
  1187 + array_push($nameArray, $v);
  1188 + $charArray[$char] = $nameArray;
  1189 + }
  1190 + ksort($charArray);
  1191 +
  1192 + $indexList = array_keys($charArray);
  1193 + $itemArr = array_values($charArray);
  1194 + }
  1195 +
  1196 + array_unshift($indexList, "*");
  1197 + $this->success("数据获取成功", ["indexList" => $indexList, "itemArr" => $itemArr]);
  1198 +
  1199 + }
1108 } 1200 }