Orders.php 106 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\model\Config;
  4. use Overtrue\Pinyin\Pinyin;
  5. use think\App;
  6. use think\Db;
  7. use think\Exception;
  8. class Orders extends Auth {
  9. public function __construct(App $app = null) {
  10. parent::__construct($app);
  11. $this->model = new \app\common\model\Orders();
  12. $this->table = $this->model->table;
  13. }
  14. //用户订单列表
  15. public function selfIndex() {
  16. $mode = input('mode', 1);
  17. if (request()->isAjax()) {
  18. //分页参数
  19. $length = input('rows', 10, 'intval'); //每页条数
  20. $page = input('page', 1, 'intval'); //第几页
  21. $start = ($page - 1) * $length; //分页开始位置
  22. //排序
  23. $sortRow = input('sidx', 'a.id', 'trim'); //排序列
  24. $sort = input('sord', 'desc', 'trim'); //排序方式
  25. $order = $sortRow . ' ' . $sort;
  26. $map[] = ['a.del', '=', 0];
  27. $map[] = ['a.org_id', '=', $this->orgId];
  28. $order_mode = input('order_mode', '', 'trim');
  29. if ($order_mode != '') {
  30. $map[] = ['a.order_mode', '=', $order_mode];
  31. }
  32. if($mode >0){
  33. $map[] = ['a.work_type_mode', '=', $mode];
  34. }else{
  35. $map[] = ['a.source_type', '=', 4];
  36. }
  37. $sn = input('sn', '', 'trim');
  38. if ($sn) {
  39. $map[] = ['a.sn', 'like', '%' . $sn . '%'];
  40. }
  41. if (!is_admin($this->userId)) {
  42. $map[] = ['a.user_id', '=', $this->userId];
  43. }
  44. $priority = input('priority', '', 'trim');
  45. if($priority !=''){
  46. $map[] = ['b.priority', '=',$priority];
  47. }
  48. $map = empty($map) ? true : $map;
  49. //数据查询
  50. $lists = db($this->table)
  51. ->alias('a')
  52. ->leftJoin('order_convey b','a.id=b.order_id')
  53. ->where($map)
  54. ->field('a.*,b.priority')
  55. ->limit($start, $length)
  56. ->order($order)
  57. ->select();
  58. foreach ($lists as $k => $v) {
  59. $lists[$k] = $this->model->formatOrder($v);
  60. $lists[$k]['priority'] = isset($this->model->priority[$v['priority']])?$this->model->priority[$v['priority']]:"";
  61. }
  62. //数据返回
  63. $totalCount = db($this->table)
  64. ->alias('a')
  65. ->leftJoin('order_convey b','a.id=b.order_id')
  66. ->where($map)->count();
  67. $totalPage = ceil($totalCount / $length);
  68. $result['page'] = $page;
  69. $result['total'] = $totalPage;
  70. $result['records'] = $totalCount;
  71. $result['rows'] = $lists;
  72. return json($result);
  73. }
  74. else {
  75. $mode_name = $this->getTableField('work_type_mode', ['id' => $mode], 'name');
  76. if($mode==4){
  77. $mode_name = '应急';
  78. }
  79. $this->assign('m_name', $mode_name);
  80. $this->assign('mode', $mode);
  81. $this->assign('priority', model("Orders")->priority);
  82. $order_mode = Db::name('order_mode')->select();
  83. $this->assign('order_mode_list', $order_mode);
  84. $tsDh = model('Config')->getConfig('org_config_ts',$this->orgId);
  85. $this->assign('tsDh',$tsDh);
  86. if ($mode == 1) {
  87. return $this->fetch('selfIndex1');
  88. }
  89. else {
  90. if ($mode == 3) {
  91. return $this->fetch('selfIndex3');
  92. }
  93. else {
  94. return $this->fetch('selfIndex');
  95. }
  96. }
  97. }
  98. }
  99. //用户添加订单
  100. public function selfAdd($mode = 1) {
  101. if (request()->isPost()) {
  102. $data = request()->post();
  103. $data['user_id'] = $this->userId;
  104. $data['org_id'] = $this->orgId;
  105. $data['work_type_mode'] = $mode;
  106. $data['images'] = isset($data['images']) && !empty($data['images']) ? implode(',', $data['images']) : '';
  107. $res = $this->model->addSave($data);
  108. if ($res) {
  109. $this->success('操作成功');
  110. }
  111. else {
  112. $this->error($this->model->getError());
  113. }
  114. }
  115. else {
  116. $dep = $this->getTableField('user_dep', ['user_id' => $this->userId], 'dep_id');
  117. $depList = (new \app\common\model\Dep())->getList();
  118. $this->assign('dep_id', $dep);
  119. $this->assign('dep_list', $depList);
  120. $this->assign('mode', $mode);
  121. if ($mode == 3) {
  122. $address = (new \app\common\model\Address())->getListByType(2);
  123. $conveyCate = (new \app\common\model\ConveyCate());
  124. $priority = $conveyCate->priority;
  125. $order_convey = $conveyCate->getList();
  126. $order_device = (new \app\common\model\ConveyDevice())->getList();
  127. $this->assign('address', $address);
  128. $this->assign('priority', $priority);
  129. $this->assign('order_convey_type', $order_convey);
  130. $this->assign('order_device', $order_device);
  131. }
  132. $user = Db::name('user')
  133. ->where('id',$this->userId)
  134. ->find();
  135. $this->assign('user',$user);
  136. $tsDh = model('Config')->getConfig('org_config_ts',$this->orgId);
  137. $this->assign('tsDh',$tsDh);
  138. if ($mode == 3) {
  139. return $this->fetch('self_add3');
  140. }
  141. else {
  142. return $this->fetch('self_add');
  143. }
  144. }
  145. }
  146. public function getAddr(){
  147. $id = input('id/d',0);
  148. $info = Db::name('convey_cate')
  149. ->where('id',$id)
  150. ->find();
  151. if(!empty($info['starts'])){
  152. $st = explode(',',$info['starts']);
  153. $s = (new \app\common\model\Address())->getListByTypes($st,2);
  154. }else{
  155. $s = (new \app\common\model\Address())->getListByType(2);
  156. }
  157. if(!empty($info['ends'])){
  158. $ent = explode(',',$info['ends']);
  159. $en = (new \app\common\model\Address())->getListByTypes($ent,2);
  160. }else{
  161. $en = (new \app\common\model\Address())->getListByType(2);
  162. }
  163. $a = [
  164. 's'=>$s,
  165. 'e'=>$en,
  166. ];
  167. $this->success('','',$a);
  168. }
  169. //用户取消订单
  170. public function cancel($id) {
  171. $res = $this->model->cancel($id, $this->userId);
  172. if (!$res) {
  173. $this->error($this->model->getError());
  174. }
  175. $this->success('取消成功');
  176. }
  177. //调度取消订单
  178. public function disCancel($id) {
  179. if (request()->isGet()) {
  180. $this->assign('id', $id);
  181. return $this->fetch();
  182. }
  183. else {
  184. $reason = input('cancel_reason');
  185. $res = $this->model->cancel($id, $this->userId, 2, $reason);
  186. if (!$res) {
  187. $this->error($this->model->getError());
  188. }
  189. $this->success('取消成功');
  190. }
  191. }
  192. //延迟订单
  193. public function batchdelay($id) {
  194. if (request()->isGet()) {
  195. $delay_reason = Db::name('delay_reason')
  196. ->where('org_id', $this->orgId)
  197. ->where('enable', 1)
  198. ->where('del', 0)
  199. ->select();
  200. $this->assign('delay_reason', $delay_reason);
  201. $this->assign('id', $id);
  202. return $this->fetch();
  203. }
  204. else {
  205. $delay_reason_id = input('delay_reason_id');
  206. if (empty($delay_reason_id)) {
  207. $this->error('请选择延迟原因');
  208. }
  209. $res = $this->model->delay_reason($id, $delay_reason_id);
  210. if (!$res) {
  211. $this->error($this->model->getError());
  212. }
  213. $this->success('延迟成功');
  214. }
  215. }
  216. //取消延迟订单
  217. public function batchcanceldelay($id) {
  218. if (request()->isGet()) {
  219. $this->assign('id', $id);
  220. return $this->fetch();
  221. }
  222. else {
  223. $res = $this->model->batchcanceldelay($id);
  224. if (!$res) {
  225. $this->error($this->model->getError());
  226. }
  227. $this->success('延迟成功');
  228. }
  229. }
  230. //用户查看订单详情
  231. public function detail($id) {
  232. if (!$id) {
  233. $this->error('参数错误');
  234. }
  235. $order = Db::name('orders')->where(['id' => $id])->find();
  236. $order = $this->model->formatOrder($order, 1);
  237. $order['images'] = !empty($order['images']) ? explode(',', $order['images']) : '';
  238. if($order['work_type_mode'] == 3){
  239. // 地点路径
  240. $conveyends = Db::name('order_convey_end')
  241. ->alias('a')
  242. ->join('address b','b.id = a.addr')
  243. ->where('a.order_id',$id)
  244. ->order('a.id asc')
  245. ->field('a.*,b.title')
  246. ->select();
  247. $order['ends'] = $conveyends?$conveyends:[];
  248. }
  249. $this->assign('info', $order);
  250. $workTypeName = $this->getTableField('work_type_mode', ['id' => $order['work_type_mode']], 'name');
  251. $this->assign('meta_title', $workTypeName . '订单详情');
  252. return $this->fetch();
  253. }
  254. //调度订单列表
  255. public function index() {
  256. $mode = input('mode', 0);
  257. $quality_type = input('quality_type','');
  258. $level1 = check_is_dispatch($this->userId);
  259. $level2 = check_two_dispatch($this->userId);
  260. $turnoff = two_dispatch_off($this->orgId);
  261. if (request()->isAjax()) {
  262. //分页参数
  263. $length = input('rows', 10, 'intval'); //每页条数
  264. $page = input('page', 1, 'intval'); //第几页
  265. $start = ($page - 1) * $length; //分页开始位置
  266. //排序
  267. $sortRow = input('sidx', 'a.id', 'trim'); //排序列
  268. $sort = input('sord', 'desc', 'trim'); //排序方式
  269. $order = $sortRow . ' ' . $sort;
  270. $content = input('content', '', 'trim');
  271. if ($content) {
  272. $map[] = ['a.content', 'like', '%' . $content . '%'];
  273. }
  274. $dep_id = input('dep_id', '', 'trim');
  275. if ($dep_id != '') {
  276. $map[] = ['a.dep_id', '=', $dep_id];
  277. }
  278. $dep_cate = input('dep_cate', '', 'trim');
  279. if ($dep_cate != '') {
  280. $depIds = Db::name('dep')
  281. ->where('org_id',$this->orgId)
  282. ->where('cate_id',$dep_cate)
  283. ->where('del',0)
  284. ->column('id');
  285. if(!empty($depIds)){
  286. $map[] = ['a.dep_id', 'in', $depIds];
  287. }else{
  288. $map[] = ['a.dep_id', '=', -1];
  289. }
  290. }
  291. $order_mode = input('order_mode', '', 'trim');
  292. $map6 = [];
  293. if ($order_mode != '') {
  294. if($level1 && $turnoff && $mode != 15){ // 一级调度且二级调度开关开着,品质整改例外
  295. if ($order_mode == 1) {
  296. $map[] = ['a.is_deal', '=', 0];
  297. }else if ($order_mode == 4) {
  298. $map6[] = ['a.is_deal', '=', 1];
  299. }
  300. }
  301. if($order_mode==100){//已挂起
  302. $gq = Db::name('todo')
  303. ->where('work_type_mode',1)
  304. ->where('todo_mode',2)
  305. ->where('pause',1)
  306. ->column('order_id');
  307. if(empty($gq)){
  308. $map[] = ['a.id', '=', -1];
  309. }else{
  310. $map[] = ['a.id', 'in', $gq];
  311. }
  312. }else{
  313. $map[] = ['a.order_mode', '=', $order_mode];
  314. }
  315. }
  316. $b = input('start', '', 'trim');
  317. $e = input('end', '', 'trim');
  318. if ($b) {
  319. // $b = date('Ymd', strtotime($b));
  320. // $map[] = ['a.create_yyyymmdd', '>=', $b];
  321. $map[] = ['a.create_time', '>=', $b];
  322. }
  323. if ($e) {
  324. // $e = date('Ymd', strtotime($e));
  325. // $map[] = ['a.create_yyyymmdd', '<=', $e];
  326. $map[] = ['a.create_time', '<=', $e];
  327. }
  328. $map[] = ['a.del', '=', 0];
  329. $map[] = ['a.org_id', '=', $this->orgId];
  330. if($mode==-1){
  331. $map[] = ['a.source_type', '=', 4];
  332. }
  333. $type = input('type', '', 'trim');
  334. $oids = [];
  335. if ($type != '') {
  336. $map1[] = ['parent_id', '=', $type];
  337. $type_id = Db::name('order_type')
  338. ->where($map1)
  339. ->where('org_id', $this->orgId)
  340. ->where('enable', 1)
  341. ->column('id');
  342. if (!empty($type_id)) {
  343. $map3[] = ['type_id', 'in', $type_id];
  344. $ids = Db::name('order_repair')
  345. ->where($map3)
  346. ->column('order_id');
  347. if (!empty($ids)) {
  348. $oids = $ids;
  349. }
  350. else {
  351. $oids = [];
  352. }
  353. }
  354. else {
  355. $oids = [];
  356. }
  357. }
  358. $typeName = input('typeName', '', 'trim');
  359. if ($typeName != '') {
  360. $map_11[] = ['a.title', 'like', '%'.$typeName.'%'];
  361. $typeNameId = Db::name('convey_cate')
  362. ->alias('a')
  363. ->join('order_convey b','a.id=b.type')
  364. ->where($map_11)
  365. ->where('a.org_id', $this->orgId)
  366. ->where('a.enable', 1)
  367. ->where('a.del', 0)
  368. ->column('b.order_id');
  369. if (!empty($typeNameId)) {
  370. $map[] = ['a.id', 'in', $typeNameId];
  371. }
  372. else {
  373. $map[] = ['a.id', '=', -1];
  374. }
  375. }
  376. if($level2 && $turnoff){ // 二级调度
  377. $roles_id = Db::name('user_roles')
  378. ->where('user_id', $this->userId)
  379. ->value('roles_id');
  380. $ids = Db::name('dispatch_log')
  381. ->where('roles_id', $roles_id)
  382. ->whereOr('to_user_id', $this->userId)
  383. ->column('order_id');
  384. if (empty($ids)) {
  385. $map[] = ['a.id', '=', -1];
  386. } else {
  387. if($type != ''){
  388. $oids = array_intersect($oids,$ids);
  389. if($oids){
  390. $map[] = ['a.id', 'in', $oids];
  391. }else{
  392. $map[] = ['a.id', '=', -1];
  393. }
  394. }else{
  395. $map[] = ['a.id', 'in', $ids];
  396. }
  397. }
  398. }else{
  399. if($type != ''){
  400. if($oids){
  401. $map[] = ['a.id', 'in', $oids];
  402. }else{
  403. $map[] = ['a.id', '=', 0];
  404. }
  405. }
  406. }
  407. if($mode == 15){ // 品质检查,单独处理
  408. $map[] = ['a.work_type_mode','=',$mode];
  409. if($quality_type!=''){
  410. $map[] = ['a.quality_type','=',$quality_type];
  411. }
  412. }else{
  413. $work_type_mode = input('work_type_mode','','trim');
  414. if(!is_admin($this->userId)){
  415. $auth = get_dispatch_auth($this->userId);
  416. if($auth){
  417. $map[] = ['a.work_type_mode', 'in', $auth];
  418. if($mode > 0){
  419. $map[] = ['a.work_type_mode', '=', $mode];
  420. }else{
  421. if($work_type_mode!=''){
  422. $map[] = ['a.work_type_mode','=',$work_type_mode];
  423. }
  424. }
  425. }else{
  426. $map[] = ['a.work_type_mode', '=', -1];
  427. }
  428. }else{
  429. if($mode > 0){
  430. $map[] = ['a.work_type_mode', '=', $mode];
  431. }else{
  432. if($work_type_mode!=''){
  433. $map[] = ['a.work_type_mode','=',$work_type_mode];
  434. }
  435. }
  436. }
  437. }
  438. $sn = input('sn', '', 'trim');
  439. if ($sn) {
  440. $map[] = ['a.sn', 'like', '%' . $sn . '%'];
  441. }
  442. $from = input('from', '', 'trim');
  443. if ($from) {
  444. if($from >3){
  445. $map[] = ['a.from','=',0];
  446. $map[] = ['a.work_type_mode','=',$from-3];
  447. }else{
  448. $map[] = ['a.from','=',$from];
  449. }
  450. }
  451. $priority = input('priority', '', 'trim');
  452. if($priority !=''){
  453. $map[] = ['b.priority', '=',$priority];
  454. }
  455. $sddr = input('saddr','','trim');
  456. if($sddr !=''){
  457. $map[] = ['b.start','=',$sddr];
  458. }
  459. $eddr = input('eaddr','','trim');
  460. if($eddr !=''){
  461. $map[] = ['b.end','=',$eddr];
  462. }
  463. $map = empty($map) ? true : $map;
  464. //数据查询
  465. $lists = db($this->table)->where($map)
  466. ->alias('a')
  467. ->leftJoin('order_convey b','a.id=b.order_id')
  468. ->field('a.*,b.priority')
  469. ->whereOr($map6)
  470. ->limit($start, $length)->order($order)->select();
  471. foreach ($lists as $k => $v) {
  472. $lists[$k] = $this->model->formatOrder($v);
  473. $lists[$k]['priority'] = isset($this->model->priority[$v['priority']])?$this->model->priority[$v['priority']]:"";
  474. if ($turnoff && $level1 && $v['order_mode'] == 1 && $v['is_deal'] == 1) {
  475. $lists[$k]['order_mode_text'] = '已派发';
  476. }
  477. $lists[$k]['bh_nums'] = Db::name('todo')->where('order_id',$v['id'])->where('del',0)->where('todo_mode',4)->count();
  478. $gq = Db::name('todo')
  479. ->where('order_id',$v['id'])
  480. ->where('work_type_mode',1)
  481. ->where('todo_mode',2)
  482. ->where('pause',1)
  483. ->find();
  484. $lists[$k]['gq'] = $gq?'存在挂起':'';
  485. }
  486. //数据返回
  487. $totalCount = db($this->table)
  488. ->alias('a')
  489. ->leftJoin('order_convey b','a.id=b.order_id')
  490. ->where($map)->count();
  491. $totalPage = ceil($totalCount / $length);
  492. $result['page'] = $page;
  493. $result['total'] = $totalPage;
  494. $result['records'] = $totalCount;
  495. $result['rows'] = $lists;
  496. return json($result);
  497. }
  498. else {
  499. if($mode >0){
  500. $mode_name = $this->getTableField('work_type_mode', ['id' => $mode], 'name');
  501. }else{
  502. $mode_name = '';
  503. }
  504. if($mode==4){
  505. $mode_name = '应急';
  506. }
  507. $auths = [1,2,3,4,15,0];
  508. if(!is_admin($this->userId)){
  509. $auth = get_dispatch_auth($this->userId);
  510. if($auth){
  511. $auths = array_intersect($auths,$auth);
  512. if($mode > 0){
  513. $auths = array_intersect($auths,[$mode]);
  514. }
  515. }else{
  516. $auths = [];
  517. }
  518. }
  519. $this->assign('auths',$auths);
  520. $this->assign('priority', model("Orders")->priority);
  521. $dep_list = (new \app\common\model\Dep())->getList();
  522. $order_type = (new \app\common\model\OrderType())->list();
  523. $order_mode = Db::name('order_mode')
  524. ->select();
  525. $this->assign('dep_list', $dep_list);
  526. $this->assign('order_type_list', $order_type);
  527. $this->assign('m_name', $mode_name);
  528. $this->assign('mode', $mode);
  529. $this->assign('order_mode_list', $order_mode);
  530. $this->assign('dispatch_type', check_two_dispatch($this->userId));
  531. $this->assign('quality_type',$quality_type);
  532. $dep_cate = model('DepCate')->getList();
  533. $this->assign('dep_cate',$dep_cate);
  534. $addrList = (new \app\common\model\Address())->getListByTypes([],2,$this->orgId);
  535. $this->assign('addrList',$addrList);
  536. //抢单开关
  537. $this->assign('org_grab_order',(new \app\common\model\Config())
  538. ->getConfig('org_grab_order1',$this->orgId));
  539. $is = 0;
  540. if(!isset($_GET['quality_type']) && $mode==15){
  541. $is = 1;
  542. }
  543. $this->assign('is',$is);
  544. if ($mode == 1) {
  545. return $this->fetch('index1');
  546. }
  547. else {
  548. if ($mode == 3) {
  549. return $this->fetch('index3');
  550. }else if (in_array($mode,[0,-1])) {
  551. return $this->fetch('index0');
  552. }
  553. else {
  554. return $this->fetch('index');
  555. }
  556. }
  557. }
  558. }
  559. //调度删除订单
  560. public function del($id = 0) {
  561. if (!$id) {
  562. $this->error('参数错误');
  563. }
  564. $model = (new \app\common\model\Orders());
  565. $res = $model->del($id, $this->userId);
  566. if (!$res) {
  567. $this->error($model->getError());
  568. }
  569. $this->success('删除成功');
  570. }
  571. //调度添加订单
  572. public function dispatchAdd($mode = 1) {
  573. $id = input('id', 0);
  574. if (request()->isPost()) {
  575. $data = request()->post();
  576. $data['user_id'] = $this->userId;
  577. $data['org_id'] = $this->orgId;
  578. $data['work_type_mode'] = isset($data['work_type_mode'])?$data['work_type_mode']:$mode;
  579. $data['images'] = isset($data['images']) && !empty($data['images']) ? implode(',', $data['images']) : '';
  580. if ($id > 0) {
  581. // $phoneInfo = Db::name('phone_monitor_record')
  582. // ->where('id', $id)
  583. // ->find();
  584. $data['id'] = $id;
  585. $data['user_id'] = $this->userId;
  586. }
  587. $res = $this->model->addSave($data, 1);
  588. if ($res) {
  589. $this->success('操作成功');
  590. }
  591. else {
  592. $this->error($this->model->getError());
  593. }
  594. }
  595. else {
  596. $tsDh = model('Config')->getConfig('org_config_ts',$this->orgId);
  597. $this->assign('tsDh',$tsDh);
  598. $user = Db::name('user')
  599. ->where('id',$this->userId)
  600. ->find();
  601. $this->assign('user',$user);
  602. if($mode==0){//创建一键呼叫
  603. $dep = $this->getTableField('user_dep', ['user_id' => $this->userId], 'dep_id');
  604. $depList = (new \app\common\model\Dep())->getList();
  605. $this->assign('dep_id', $dep);
  606. $this->assign('dep_list', $depList);
  607. $order_type = (new \app\common\model\OrderType())->getList();
  608. $address = (new \app\common\model\Address())->getListByType(1);
  609. $this->assign('order_type_list', $order_type);
  610. $this->assign('address_list', $address);
  611. $order_repair = Db::name('order_repair')
  612. ->where('order_id', $id)
  613. ->find();
  614. $this->assign('order_repair', $order_repair);
  615. $workType = Db::name('work_type_mode')
  616. ->where('type',1)
  617. ->select();
  618. $config = Db::name('config')
  619. ->where('name','web_order_transfer_type')
  620. ->value('value');
  621. if(empty($config)){
  622. $workType = [];
  623. }else{
  624. $ll = explode('|',$config);
  625. foreach ($workType as $kk=>$vv){
  626. if(!in_array($vv['id'],$ll)){
  627. unset($workType[$kk]);
  628. }
  629. }
  630. }
  631. if(!is_admin($this->userId)){
  632. $auth = get_dispatch_auth($this->userId);
  633. if(empty($auth)){
  634. $workType = [];
  635. }else{
  636. foreach ($workType as $kk=>$vv){
  637. if(!in_array($vv['id'],$auth)){
  638. unset($workType[$kk]);
  639. }
  640. }
  641. }
  642. }
  643. foreach ($workType as $k=>$v){
  644. $this->assign('send_user_num'.$v['id'], $this->model->sendUserNum($v['id'], $this->orgId));
  645. $this->assign('user_list'.$v['id'], (new \app\common\model\WorkTypeMode())->getRolesUserByNum($v['id'], $this->orgId, 1));
  646. $two_dispatch_roles = model('user')->get_two_dispatch_role($this->orgId, $v['id']);
  647. $this->assign('dispatch_roles'.$v['id'], $two_dispatch_roles);
  648. }
  649. $this->assign('dispatch_type', check_two_dispatch($this->userId));
  650. $this->assign('two_dispatch_off', two_dispatch_off($this->orgId));
  651. $this->assign('workType', $workType);
  652. $address = (new \app\common\model\Address())->getListByType(2);
  653. $conveyCate = (new \app\common\model\ConveyCate());
  654. $priority = $conveyCate->priority;
  655. $order_convey = $conveyCate->getList();
  656. $order_device = (new \app\common\model\ConveyDevice())->getList();
  657. $this->assign('address', $address);
  658. $this->assign('priority', $priority);
  659. $this->assign('order_convey_type', $order_convey);
  660. $this->assign('order_device', $order_device);
  661. $oCid = Db::name('order_convey')
  662. ->where('order_id',$id)
  663. ->find();
  664. $opt = Db::name('order_convey_patient')
  665. ->where('order_id',$id)
  666. ->find();
  667. $this->assign('ocid',$oCid);
  668. $this->assign('opt',$opt);
  669. $this->assign('ps',empty($opt)?1:0);
  670. $this->assign('id', $id);
  671. $this->assign('mode', $mode);
  672. return $this->fetch('yjhj_dispatch_add');
  673. }else{
  674. $dep = $this->getTableField('user_dep', ['user_id' => $this->userId], 'dep_id');
  675. $depList = (new \app\common\model\Dep())->getList();
  676. $order_type = (new \app\common\model\OrderType())->getList();
  677. $address = (new \app\common\model\Address())->getListByType(1);
  678. $this->assign('dep_id', $dep);
  679. $this->assign('dep_list', $depList);
  680. $this->assign('order_type_list', $order_type);
  681. $this->assign('mode', $mode);
  682. $this->assign('send_user_num', $this->model->sendUserNum($mode, $this->orgId));
  683. $this->assign('user_list', (new \app\common\model\WorkTypeMode())->getRolesUserByNum($mode, $this->orgId,1));
  684. $this->assign('address_list', $address);
  685. $this->assign('address_id', '');
  686. if ($mode == 3) {
  687. $address = (new \app\common\model\Address())->getListByType(2);
  688. $conveyCate = (new \app\common\model\ConveyCate());
  689. $priority = $conveyCate->priority;
  690. $order_convey = $conveyCate->getList();
  691. $order_device = (new \app\common\model\ConveyDevice())->getList();
  692. $this->assign('address', $address);
  693. $this->assign('priority', $priority);
  694. $this->assign('order_convey_type', $order_convey);
  695. $this->assign('order_device', $order_device);
  696. }
  697. if ($id > 0) {
  698. // $phoneInfo = Db::name('phone_monitor_record')
  699. // ->where('id', $id)
  700. // ->find();
  701. $this->assign('address_id', 0);
  702. // $depId = Db::name('user_dep')
  703. // ->where('user_id', $phoneInfo['user_id'])
  704. // ->value('dep_id');
  705. $this->assign('dep_id', 0);
  706. }
  707. $two_dispatch_roles = model('user')->get_two_dispatch_role($this->orgId, $mode);
  708. $this->assign('dispatch_roles', $two_dispatch_roles);
  709. $this->assign('dispatch_type', check_two_dispatch($this->userId));
  710. $this->assign('two_dispatch_off', two_dispatch_off($this->orgId));
  711. $this->assign('id', $id);
  712. if ($mode == 3) {
  713. return $this->fetch('dispatch_add3');
  714. }
  715. else {
  716. return $this->fetch('dispatch_add');
  717. }
  718. }
  719. }
  720. }
  721. //调度查看订单详情
  722. public function detail2($id) {
  723. if (!$id) {
  724. $this->error('参数错误');
  725. }
  726. $type = input('type/d',0);
  727. $this->assign('type', $type);
  728. $order = Db::name('orders')->where(['id' => $id])->find();
  729. $order = $this->model->formatOrder($order, 1);
  730. $order['images'] = !empty($order['images']) ? explode(',', $order['images']) : '';
  731. $is_ch = 0;
  732. if($order['order_mode'] == 4){
  733. $todoInfo = Db::name('todo')->where('order_id',$order['id'])->where('del',0)->where('todo_mode','>',1)->find();
  734. if(!$todoInfo){
  735. $is_ch = 1;
  736. }
  737. }
  738. $order['is_ch'] = $is_ch;
  739. if($order['work_type_mode'] == 3){
  740. // 地点路径
  741. $conveyends = Db::name('order_convey_end')
  742. ->alias('a')
  743. ->join('address b','b.id = a.addr')
  744. ->where('a.order_id',$id)
  745. ->order('a.id asc')
  746. ->field('a.*,b.title')
  747. ->select();
  748. $order['ends'] = $conveyends?$conveyends:[];
  749. }
  750. $this->assign('info', $order);
  751. $workTypeName = $this->getTableField('work_type_mode', ['id' => $order['work_type_mode']], 'name');
  752. $this->assign('meta_title', $workTypeName . '订单详情');
  753. $level2 = check_two_dispatch($this->userId);
  754. $level1 = check_is_dispatch($this->userId);
  755. $turnoff = two_dispatch_off($this->orgId);
  756. $this->assign('level1', $level1);
  757. $this->assign('level2', $level2);
  758. $this->assign('turnoff', $turnoff);
  759. $this->assign('dispatch_type', $level2);
  760. $this->assign('org_auto_send',(new \app\common\model\Config())
  761. ->getConfig('org_auto_send',$this->orgId));
  762. return $this->fetch();
  763. }
  764. public function zg_detail($id) {
  765. if (!$id) {
  766. $this->error('参数错误');
  767. }
  768. $type = input('type/d',0);
  769. $this->assign('type', $type);
  770. $order = Db::name('orders')->where(['id' => $id])->find();
  771. $order = $this->model->formatOrder($order, 1);
  772. $order['images'] = !empty($order['images']) ? explode(',', $order['images']) : '';
  773. $this->assign('info', $order);
  774. $workTypeName = $this->getTableField('work_type_mode', ['id' => $order['work_type_mode']], 'name');
  775. $this->assign('meta_title', $workTypeName . '订单详情');
  776. $level2 = check_two_dispatch($this->userId);
  777. $level1 = check_is_dispatch($this->userId);
  778. $turnoff = two_dispatch_off($this->orgId);
  779. $this->assign('level1', $level1);
  780. $this->assign('level2', $level2);
  781. $this->assign('turnoff', $turnoff);
  782. $this->assign('dispatch_type', $level2);
  783. return $this->fetch();
  784. }
  785. public function print($id) {
  786. if (!$id) {
  787. $this->error('参数错误');
  788. }
  789. $type = input('type/d',0);
  790. $this->assign('type', $type);
  791. $order = Db::name('orders')->where(['id' => $id])->find();
  792. $order = $this->model->formatOrder($order, 1);
  793. $order['images'] = !empty($order['images']) ? explode(',', $order['images']) : '';
  794. $this->assign('info', $order);
  795. $workTypeName = $this->getTableField('work_type_mode', ['id' => $order['work_type_mode']], 'name');
  796. $this->assign('meta_title', $workTypeName . '订单详情');
  797. $level2 = check_two_dispatch($this->userId);
  798. $level1 = check_is_dispatch($this->userId);
  799. $turnoff = two_dispatch_off($this->orgId);
  800. $this->assign('level1', $level1);
  801. $this->assign('level2', $level2);
  802. $this->assign('turnoff', $turnoff);
  803. $this->assign('dispatch_type', $level2);
  804. return $this->fetch();
  805. }
  806. //派单
  807. public function send($id, $mode = 1) {
  808. if (request()->isGet()) {
  809. $this->assign('id', $id);
  810. $this->assign('mode', $mode);
  811. $orders = Db::name('orders')
  812. ->where('id',$id)
  813. ->find();
  814. if($orders['source_type']==4 && $orders['work_type_mode']==0 && $orders['is_deal']==0){//一键呼叫
  815. $order_type = (new \app\common\model\OrderType())->getList();
  816. $address = (new \app\common\model\Address())->getListByType(1);
  817. $this->assign('order_type_list', $order_type);
  818. $this->assign('address_list', $address);
  819. $order_repair = Db::name('order_repair')
  820. ->where('order_id', $id)
  821. ->find();
  822. $this->assign('order_repair', $order_repair);
  823. $workType = Db::name('work_type_mode')
  824. ->where('type',1)
  825. ->select();
  826. $config = Db::name('config')
  827. ->where('name','web_order_transfer_type')
  828. ->value('value');
  829. if(empty($config)){
  830. $workType = [];
  831. }else{
  832. $ll = explode('|',$config);
  833. foreach ($workType as $kk=>$vv){
  834. if(!in_array($vv['id'],$ll)){
  835. unset($workType[$kk]);
  836. }
  837. }
  838. }
  839. foreach ($workType as $k=>$v){
  840. $this->assign('send_user_num'.$v['id'], $this->model->sendUserNum($v['id'], $this->orgId));
  841. $this->assign('user_list'.$v['id'], (new \app\common\model\WorkTypeMode())->getRolesUserByNum($v['id'], $this->orgId, 1));
  842. $two_dispatch_roles = model('user')->get_two_dispatch_role($this->orgId, $v['id']);
  843. $this->assign('dispatch_roles'.$v['id'], $two_dispatch_roles);
  844. }
  845. $this->assign('dispatch_type', check_two_dispatch($this->userId));
  846. $this->assign('two_dispatch_off', two_dispatch_off($this->orgId));
  847. $this->assign('workType', $workType);
  848. $this->assign('orders', $orders);
  849. $address = (new \app\common\model\Address())->getListByType(2);
  850. $conveyCate = (new \app\common\model\ConveyCate());
  851. $priority = $conveyCate->priority;
  852. $order_convey = $conveyCate->getList();
  853. $order_device = (new \app\common\model\ConveyDevice())->getList();
  854. $this->assign('address', $address);
  855. $this->assign('priority', $priority);
  856. $this->assign('order_convey_type', $order_convey);
  857. $this->assign('order_device', $order_device);
  858. $oCid = Db::name('order_convey')
  859. ->where('order_id',$id)
  860. ->find();
  861. $opt = Db::name('order_convey_patient')
  862. ->where('order_id',$id)
  863. ->find();
  864. $this->assign('ocid',$oCid);
  865. $this->assign('opt',$opt);
  866. $this->assign('ps',empty($opt)?1:0);
  867. $auths = [1,2,3,4,15,0];
  868. if(!is_admin($this->userId)){
  869. $auth = get_dispatch_auth($this->userId);
  870. if($auth){
  871. $auths = array_intersect($auths,$auth);
  872. if($mode > 0){
  873. $auths = array_intersect($auths,[$mode]);
  874. }
  875. }else{
  876. $auths = [];
  877. }
  878. }
  879. $this->assign('auths',$auths);
  880. return $this->fetch('yjhj_send');
  881. }else{
  882. if ($mode == 1) {
  883. $order_type = (new \app\common\model\OrderType())->getList();
  884. $address = (new \app\common\model\Address())->getListByType(1);
  885. $this->assign('order_type_list', $order_type);
  886. $this->assign('address_list', $address);
  887. $order_repair = Db::name('order_repair')
  888. ->where('order_id', $id)
  889. ->find();
  890. $this->assign('order_repair', $order_repair);
  891. }
  892. $this->assign('send_user_num', $this->model->sendUserNum($mode, $this->orgId));
  893. $this->assign('user_list', (new \app\common\model\WorkTypeMode())->getRolesUserByNum($mode, $this->orgId, 1));
  894. $two_dispatch_roles = model('user')->get_two_dispatch_role($this->orgId, $mode);
  895. $this->assign('dispatch_roles', $two_dispatch_roles);
  896. $this->assign('dispatch_type', check_two_dispatch($this->userId));
  897. $this->assign('two_dispatch_off', two_dispatch_off($this->orgId));
  898. return $this->fetch();
  899. }
  900. }
  901. else {
  902. $data = request()->post();
  903. $data['org_id'] = $this->orgId;
  904. $res = $this->model->send($id, $this->userId, $data);
  905. if (!$res) {
  906. $this->error($this->model->getError());
  907. }
  908. $this->success('操作成功');
  909. }
  910. }
  911. //转单
  912. public function zd_send($id, $mode = 1) {
  913. if (request()->isGet()) {
  914. $this->assign('id', $id);
  915. $this->assign('mode', $mode);
  916. $orders = Db::name('orders')
  917. ->where('id',$id)
  918. ->find();
  919. if($orders['source_type']==4 && $orders['is_deal']==0){//一键呼叫
  920. $order_type = (new \app\common\model\OrderType())->getList();
  921. $address = (new \app\common\model\Address())->getListByType(1);
  922. $this->assign('order_type_list', $order_type);
  923. $this->assign('address_list', $address);
  924. $order_repair = Db::name('order_repair')
  925. ->where('order_id', $id)
  926. ->find();
  927. $this->assign('order_repair', $order_repair);
  928. $workType = Db::name('work_type_mode')
  929. ->where('type',1)
  930. ->select();
  931. $config = Db::name('config')
  932. ->where('name','web_order_transfer_type')
  933. ->value('value');
  934. if(empty($config)){
  935. $workType = [];
  936. }else{
  937. $ll = explode('|',$config);
  938. foreach ($workType as $kk=>$vv){
  939. if(!in_array($vv['id'],$ll)){
  940. unset($workType[$kk]);
  941. }
  942. }
  943. }
  944. foreach ($workType as $k=>$v){
  945. $this->assign('send_user_num'.$v['id'], $this->model->sendUserNum($v['id'], $this->orgId));
  946. $this->assign('user_list'.$v['id'], (new \app\common\model\WorkTypeMode())->getRolesUser($v['id'], $this->orgId, 1));
  947. $two_dispatch_roles = model('user')->get_two_dispatch_role($this->orgId, $v['id']);
  948. $this->assign('dispatch_roles'.$v['id'], $two_dispatch_roles);
  949. }
  950. $this->assign('dispatch_type', check_two_dispatch($this->userId));
  951. $this->assign('two_dispatch_off', two_dispatch_off($this->orgId));
  952. $this->assign('workType', $workType);
  953. $this->assign('orders', $orders);
  954. $address = (new \app\common\model\Address())->getListByType(2);
  955. $conveyCate = (new \app\common\model\ConveyCate());
  956. $priority = $conveyCate->priority;
  957. $order_convey = $conveyCate->getList();
  958. $order_device = (new \app\common\model\ConveyDevice())->getList();
  959. $this->assign('address', $address);
  960. $this->assign('priority', $priority);
  961. $this->assign('order_convey_type', $order_convey);
  962. $this->assign('order_device', $order_device);
  963. $oCid = Db::name('order_convey')
  964. ->where('order_id',$id)
  965. ->find();
  966. $opt = Db::name('order_convey_patient')
  967. ->where('order_id',$id)
  968. ->find();
  969. $this->assign('ocid',$oCid);
  970. $this->assign('opt',$opt);
  971. $this->assign('ps',empty($opt)?1:0);
  972. $auths = [1,2,3,4,15,0];
  973. if(!is_admin($this->userId)){
  974. $auth = get_dispatch_auth($this->userId);
  975. if($auth){
  976. $auths = array_intersect($auths,$auth);
  977. if($mode > 0){
  978. $auths = array_intersect($auths,[$mode]);
  979. }
  980. }else{
  981. $auths = [];
  982. }
  983. }
  984. $this->assign('auths',$auths);
  985. return $this->fetch('yjhj_zd_send');
  986. }
  987. }
  988. else {
  989. $data = request()->post();
  990. $data['org_id'] = $this->orgId;
  991. $res = $this->model->zd_send($id, $data);
  992. if (!$res) {
  993. $this->error($this->model->getError());
  994. }
  995. $this->success('操作成功');
  996. }
  997. }
  998. //批量派单
  999. public function batchsend($id, $mode = 1) {
  1000. if (request()->isGet()) {
  1001. $this->assign('id', $id);
  1002. $this->assign('mode', $mode);
  1003. if ($mode == 1) {
  1004. $order_type = (new \app\common\model\OrderType())->getList();
  1005. $address = (new \app\common\model\Address())->getListByType(1);
  1006. $this->assign('order_type_list', $order_type);
  1007. $this->assign('address_list', $address);
  1008. $order_repair = Db::name('order_repair')
  1009. ->where('order_id', $id)
  1010. ->find();
  1011. $this->assign('order_repair', $order_repair);
  1012. }
  1013. $user = (new \app\common\model\WorkTypeMode())->getRolesUser($mode, $this->orgId, 1);
  1014. $newUser = [];
  1015. $pinyin = new Pinyin();
  1016. foreach ($user as $k => $v) {
  1017. foreach ($v['user'] as $k1 => $v1) {
  1018. $v1['pinyin'] = $pinyin->abbr($v1['real_name'],PINYIN_KEEP_ENGLISH); //只保留汉字首字母 和 字母的首字母 //例如:'汉字sszz11' = hzs
  1019. $newUser[] = $v1;
  1020. }
  1021. }
  1022. $newUser = arraySequence($newUser,'pinyin');
  1023. $mm = new \app\common\model\User();
  1024. foreach ($newUser as $key => $value) {
  1025. $nums = Db::name('todo')
  1026. ->where(['to_user_id' => $value['id'], 'work_type_mode' => 3])
  1027. ->where('create_yyyymmdd', date('Ymd'))
  1028. ->where('todo_mode', 'in', [1, 2, 3])
  1029. ->count();
  1030. $newUser[$key]['nums'] = $nums;
  1031. $addr = Db::name('order_convey')
  1032. ->alias('cpr')
  1033. ->join('todo os', 'cpr.order_id = os.order_id')
  1034. ->join('orders ods', 'cpr.order_id = ods.id')
  1035. ->join('address ca', 'ca.id = cpr.start')
  1036. ->join('address cad', 'cad.id = cpr.end')
  1037. ->field('os.todo_mode,ca.title as start_name,cad.title as end_name,os.create_time')
  1038. ->where('os.to_user_id', $value['id'])
  1039. ->where('os.del', 0)
  1040. ->where('ods.del', 0)
  1041. ->order('os.id desc')
  1042. ->find();
  1043. $newUser[$key]['title'] = '';
  1044. $newUser[$key]['addr_time'] = '';
  1045. if($addr){
  1046. if(in_array($addr['todo_mode'],[1,2])){
  1047. $newUser[$key]['title'] = $addr['start_name'];
  1048. }else{
  1049. $newUser[$key]['title'] = $addr['end_name'];
  1050. }
  1051. $newUser[$key]['addr_time'] = $addr['create_time'];
  1052. }
  1053. $u = Db::name('user')
  1054. ->where('id',$value['id'])
  1055. ->value('sex');
  1056. $newUser[$key]['sex_name'] = isset($mm->sex[$u])?$mm->sex[$u]:"";
  1057. }
  1058. if($this->orgId==3){
  1059. // echo "<pre/>";
  1060. // print_r($newUser);
  1061. // die();
  1062. }
  1063. $this->assign('user_list', $newUser);
  1064. return $this->fetch();
  1065. }
  1066. else {
  1067. $data = request()->post();
  1068. $data['org_id'] = $this->orgId;
  1069. if (empty($data['to_user_id'])) {
  1070. $this->error('请选择执行人');
  1071. }
  1072. $data['to_user_id'] = implode(',', $data['to_user_id']);
  1073. $res = $this->model->batchsend($id, $this->userId, $data);
  1074. if (!$res) {
  1075. $this->error($this->model->getError());
  1076. }
  1077. $this->success('操作成功');
  1078. }
  1079. }
  1080. public function onesend($id, $mode = 1) {
  1081. $data = request()->post();
  1082. $data['org_id'] = $this->orgId;
  1083. if (empty($data['to_user_id'])) {
  1084. $this->error('请选择执行人');
  1085. }
  1086. // $data['to_user_id'] = implode(',', $data['to_user_id']);
  1087. $res = $this->model->batchsend($id, $this->userId, $data);
  1088. if (!$res) {
  1089. $this->error($this->model->getError());
  1090. }
  1091. $this->success('操作成功');
  1092. }
  1093. //完成订单
  1094. public function finish($id) {
  1095. $res = $this->model->finish($id);
  1096. if (!$res) {
  1097. $this->error($this->model->getError());
  1098. }
  1099. $this->success('操作成功');
  1100. }
  1101. //批量完成订单
  1102. public function batchfinish($id) {
  1103. $res = $this->model->batchfinish($id);
  1104. if (!$res) {
  1105. $this->error($this->model->getError());
  1106. }
  1107. $this->success('操作成功');
  1108. }
  1109. //评价
  1110. public function comment() {
  1111. $id = input('id');
  1112. $score = input('score');
  1113. $content = input('content');
  1114. if ($score <= 0 || $score > 5) {
  1115. $this->error('参数错误');
  1116. }
  1117. $res = $this->model->addComment($id, $score, $content, $this->userId, $this->orgId);
  1118. if (!$res) {
  1119. $this->error($this->model->getError());
  1120. }
  1121. $this->success('操作成功');
  1122. }
  1123. public function phone() {
  1124. $phone = input('phone','','trim');
  1125. $fp = input('fp','','trim');
  1126. $id = input('id/d',0,'trim');
  1127. if($phone){
  1128. $fp = $fp?base64_decode($fp):'';
  1129. $md5 = md5($this->orgId.'|'.$fp);
  1130. $ret = Db::name('phone_monitor_record')->where('md5',$md5)->find();
  1131. if(!$ret){
  1132. $id = Db::name('phone_monitor_record')->insertGetId([
  1133. 'org_id' => $this->orgId,
  1134. 'phone' => $phone,
  1135. 'path' => $fp,
  1136. 'md5' => $md5,
  1137. 'create_time' => date('Y-m-d H:i:s')
  1138. ]);
  1139. }else{
  1140. $id = $ret['id'];
  1141. }
  1142. }
  1143. $worktype = [
  1144. ['id' => 1, 'title' => '报修'],
  1145. ['id' => 2, 'title' => '保洁'],
  1146. ['id' => 3, 'title' => '运送'],
  1147. ['id' => 4, 'title' => '应急'],
  1148. ];
  1149. $info = Db::name('phone_monitor_record')->where('id',$id)->find();
  1150. if(!$info){
  1151. halt('数据存储失败');
  1152. }
  1153. $this->assign('worktype', $worktype);
  1154. $this->assign('info', $info);
  1155. $this->assign('id', $id);
  1156. return $this->fetch();
  1157. }
  1158. public function phoneAdd() {
  1159. $id = input('id');
  1160. $worktype = [
  1161. ['id' => 1, 'title' => '报修'],
  1162. ['id' => 2, 'title' => '保洁'],
  1163. ['id' => 3, 'title' => '运送'],
  1164. ['id' => 4, 'title' => '应急'],
  1165. ];
  1166. $info = Db::name('phone_monitor')
  1167. ->where('id', $id)->find();
  1168. if (!$info) {
  1169. echo '负责人不存在', exit();
  1170. }
  1171. $info['real_name'] = Db::name('user')
  1172. ->where('id', $info['user_id'])
  1173. ->value('real_name');
  1174. $info['dep'] = Db::name('user_dep')
  1175. ->alias('a')
  1176. ->join('dep b', 'a.dep_id=b.id')
  1177. ->where('a.user_id', $info['user_id'])
  1178. ->value('b.title');
  1179. $this->assign('worktype', $worktype);
  1180. $this->assign('info', $info);
  1181. $this->assign('id', $id);
  1182. return $this->fetch();
  1183. }
  1184. //运送调度订单列表
  1185. public function convey() {
  1186. set_time_limit(0);
  1187. ini_set("memory_limit","1024M");
  1188. $mode = input('mode', 1);
  1189. if (request()->isAjax()) {
  1190. //分页参数
  1191. $length = input('rows', 10, 'intval'); //每页条数
  1192. $page = input('page', 1, 'intval'); //第几页
  1193. $start = ($page - 1) * $length; //分页开始位置
  1194. //排序
  1195. $sortRow = input('sidx', 'id', 'trim'); //排序列
  1196. $sort = input('sord', 'desc', 'trim'); //排序方式
  1197. $order = $sortRow . ' ' . $sort;
  1198. $content = input('content', '', 'trim');
  1199. if ($content) {
  1200. $map[] = ['o.content', 'like', '%' . $content . '%'];
  1201. }
  1202. $dep_id = input('dep_id', '', 'trim');
  1203. if ($dep_id != '') {
  1204. $map[] = ['o.dep_id', '=', $dep_id];
  1205. }
  1206. $priority = input('priority', '', 'trim');
  1207. if ($priority) {
  1208. $map[] = ['oc.priority', '=', $priority];
  1209. }
  1210. $s = input('start', '', 'trim');
  1211. $end = input('end', '', 'trim');
  1212. if ($s) {
  1213. $map[] = ['oc.start', '=', $start];
  1214. }
  1215. if ($end) {
  1216. $map[] = ['oc.end', '=', $end];
  1217. }
  1218. $type = input('type', '', 'trim');
  1219. if ($type) {
  1220. $map[] = ['oc.type', '=', $type];
  1221. }
  1222. $xqtime = input('xqtime', '', 'trim');
  1223. $ywctime = input('ywctime', '', 'trim');
  1224. if ($xqtime) {
  1225. $xqtimes = explode(' - ', $xqtime);
  1226. $x1 = date('Ymd', strtotime($xqtimes[0]));
  1227. $x2 = date('Ymd', strtotime($xqtimes[1]));
  1228. $map[] = ['oc.xq_time', '>=', $x1];
  1229. $map[] = ['oc.xq_time', '<=', $x2];
  1230. }
  1231. if ($ywctime) {
  1232. $ywctimes = explode(' - ', $ywctime);
  1233. $y1 = date('Ymd', strtotime($ywctimes[0]));
  1234. $y2 = date('Ymd', strtotime($ywctimes[1]));
  1235. $map[] = ['oc.ywc_time', '>=', $y1];
  1236. $map[] = ['oc.ywc_time', '<=', $y2];
  1237. }
  1238. $map[] = ['o.del', '=', 0];
  1239. $map[] = ['o.org_id', '=', $this->orgId];
  1240. $map[] = ['o.work_type_mode', '=', 3];
  1241. $map[] = ['o.order_mode', 'in', [1, 4]];
  1242. $status = input('status', '', 'trim');
  1243. $ysName = input('ysname', '');
  1244. if ($ysName) {
  1245. $orders = Db::name('todo')
  1246. ->alias('t')
  1247. ->where('t.org_id', $this->orgId)
  1248. ->where('t.del', 0)
  1249. ->where('t.work_type_mode', 3)
  1250. ->where('t.todo_mode', [1, 2, 4])
  1251. ->where('u.real_name', 'like', '%' . $ysName . '%')
  1252. ->join('orders o', 'o.id = t.order_id')
  1253. ->join('user u', 't.to_user_id = u.id')
  1254. ->group('o.id')
  1255. ->column('o.id');
  1256. if ($orders) {
  1257. $map[] = ['o.id', 'in', $orders];
  1258. }
  1259. else {
  1260. $map[] = ['o.id', '=', 0];
  1261. }
  1262. }
  1263. $map = empty($map) ? true : $map;
  1264. //数据查询
  1265. $lists = db($this->table)->alias('o')
  1266. ->join('order_convey oc', 'oc.order_id=o.id')
  1267. ->field('o.*,oc.type,oc.start,oc.end,oc.xq_time,oc.ywc_time,oc.device_id,oc.name,oc.phone,oc.priority')
  1268. ->where($map)
  1269. ->order(['o.order_mode' => 'asc', 'oc.xq_time' => 'desc'])
  1270. ->select();
  1271. $newret = [];
  1272. $newret1 = [];
  1273. $newret2 = [];
  1274. $newret3 = [];
  1275. $newret4 = [];
  1276. foreach ($lists as $k => $v) {
  1277. $v = $this->model->formatOrder($v);
  1278. $v['bed_number'] = '';
  1279. $ocp = Db::name('order_convey_patient')
  1280. ->where('order_id', $v['id'])
  1281. ->find();
  1282. $v['bed_number'] = !empty($ocp)?$ocp['bed_number']:'';
  1283. $todo = Db::name('todo')
  1284. ->alias('t')
  1285. ->where('t.order_id', $v['id'])
  1286. ->join('user u', 'u.id = t.to_user_id')
  1287. ->where('t.todo_mode', 'in', [1, 2, 3, 4])
  1288. ->where('t.del', 0)
  1289. ->field('u.real_name,t.create_time,t.confirm_time')
  1290. ->order('t.id asc')
  1291. ->select();
  1292. $users = [];
  1293. $confirmtime = '';
  1294. foreach ($todo as $kk => $vv) {
  1295. $users[] = $vv['real_name'];
  1296. if (!$confirmtime && $vv['confirm_time']) {
  1297. $confirmtime = $vv['confirm_time'];
  1298. }
  1299. else {
  1300. if ($confirmtime && $vv['confirm_time'] && $vv['confirm_time'] < $confirmtime) {
  1301. $confirmtime = $vv['confirm_time'];
  1302. }
  1303. }
  1304. }
  1305. $v['real_names'] = implode(',', $users);
  1306. $v['confirm_time'] = $confirmtime;
  1307. $last = strtotime($v['ywc_time']) - time();
  1308. $v['last_time'] = $last > 0 ? round($last / 60) : 0;
  1309. //是否有延时
  1310. $v['delay'] = 0; // 0=未延迟 1=延迟
  1311. $v['delay_diff'] = 0;
  1312. $v['delay_reason'] = '';
  1313. $delays = Db::name('order_delay')
  1314. ->where('order_id', $v['id'])
  1315. ->select();
  1316. $delays = $delays ? $delays : [];
  1317. foreach ($delays as $vv) {
  1318. if ($vv['status'] == 0) {
  1319. $v['delay'] = 1;
  1320. $v['delay_reason'] = $this->gettablefield('delay_reason', ['id' => $vv['delay_reason_id']], 'title');
  1321. $vv['diff'] = time() - strtotime($vv['start_time']);
  1322. }
  1323. $v['delay_diff'] += $vv['diff'];
  1324. }
  1325. $v['delay_diff'] = round($v['delay_diff'] / 60);
  1326. if ($v['delay'] == 1) {
  1327. $v['status'] = 3;
  1328. } else {
  1329. if ($v['order_mode'] == 1) {
  1330. $v['status'] = 1;
  1331. } else {
  1332. $v['status'] = 2;
  1333. }
  1334. }
  1335. $convey = Db::name('convey_cate')
  1336. ->alias('oc')
  1337. ->join('time ot', 'ot.id = oc.time_id')
  1338. ->where('oc.id', $v['type'])
  1339. ->field('ot.*')
  1340. ->find();
  1341. $createtime = strtotime($v['create_time']);
  1342. $curtime = time();
  1343. $ct = round(($curtime - $createtime) / 60);
  1344. if ($ct < $convey['yy_time']) {
  1345. $ss = 0;
  1346. }
  1347. else {
  1348. if ($ct >= $convey['yy_time'] && $ct < $convey['bz_time']) {
  1349. $ss = 1;
  1350. }
  1351. else {
  1352. if ($ct >= $convey['bz_time'] && $ct < $convey['jg_time']) {
  1353. $ss = 2;
  1354. }
  1355. else {
  1356. if ($ct >= $convey['jg_time'] && $ct < $convey['wjjg_time']) {
  1357. $ss = 3;
  1358. }
  1359. else {
  1360. $ss = 4;
  1361. }
  1362. }
  1363. }
  1364. }
  1365. $v['ss'] = $ss;
  1366. $v['xtime'] = date('H:i', strtotime($v['xq_time']));
  1367. $v['stime'] = $v['send_time'] ? date('H:i', strtotime($v['send_time'])) : "";
  1368. $v['ctime'] = $v['confirm_time'] ? date('H:i', strtotime($v['confirm_time'])) : "";
  1369. $v['priorityName'] = isset($this->model->priority[$v['priority']])?$this->model->priority[$v['priority']]:'';
  1370. if ($status == 3 && $v['delay'] == 1) { //延时任务
  1371. $newret[] = $v;
  1372. $newret1[] = $v;
  1373. }
  1374. if ($status == 1 && $v['order_mode'] == 1) { //新任务
  1375. $newret[] = $v;
  1376. $newret2[] = $v;
  1377. }
  1378. if ($status == 2 && $v['order_mode'] == 4) { // 进行中
  1379. $newret[] = $v;
  1380. $newret3[] = $v;
  1381. }
  1382. if (!$status || !in_array($status, [1, 2, 3])) {
  1383. $newret[] = $v;
  1384. $newret4[] = $v;
  1385. }
  1386. $lists[$k] = $v;
  1387. }
  1388. if(!empty($newret)){
  1389. //$newret = arraySequence($newret,'status');//返回数组中指定的一列
  1390. // $newret1 = $newret1?arraySequence($newret1,'xtime','SORT_DESC'):[];
  1391. // $newret3 = $newret3?arraySequence($newret3,'xtime','SORT_DESC'):[];
  1392. // $newret4 = $newret4?arraySequence($newret4,'xtime','SORT_DESC'):[];
  1393. // $newret = array_merge($newret2,$newret3,$newret4,$newret1);
  1394. $all = [];
  1395. $newret2 = $newret2?arraySequence($newret2,'status'):[];
  1396. $newret3 = $newret3?arraySequence($newret3,'status'):[];
  1397. //$newret4 = $newret4?arraySequence($newret4,'status'):[];
  1398. $newret1 = $newret1?arraySequence($newret1,'status'):[];
  1399. $newret2 = $newret2?arraySequence($newret2,'xtime','SORT_DESC'):[];
  1400. $newret3 = $newret3?arraySequence($newret3,'xtime','SORT_DESC'):[];
  1401. // $newret4 = $newret4?arraySequence($newret4,'xtime','SORT_DESC'):[];
  1402. $newret1 = $newret1?arraySequence($newret1,'xtime','SORT_DESC'):[];
  1403. foreach ($newret2 as $k=>$v){
  1404. $all[] = $v;
  1405. }
  1406. foreach ($newret3 as $k=>$v){
  1407. $all[] = $v;
  1408. }
  1409. foreach ($newret1 as $k=>$v){
  1410. $all[] = $v;
  1411. }
  1412. $a1 = $a2 = $a3 = [];
  1413. foreach ($newret4 as $k=>$v){
  1414. if ($v['status'] == 3) { //延时任务
  1415. $a1[] = $v;
  1416. }
  1417. if ($v['status'] == 1) { //新任务
  1418. $a2[] = $v;
  1419. }
  1420. if ($v['status'] == 2) { // 进行中
  1421. $a3[] = $v;
  1422. }
  1423. }
  1424. $a1 = $a1?arraySequence($a1,'status'):[];
  1425. $a2 = $a2?arraySequence($a2,'status'):[];
  1426. $a3 = $a3?arraySequence($a3,'status'):[];
  1427. $a1 = $a1?arraySequence($a1,'xtime','SORT_DESC'):[];
  1428. $a2 = $a2?arraySequence($a2,'xtime','SORT_DESC'):[];
  1429. $a3 = $a3?arraySequence($a3,'xtime','SORT_DESC'):[];
  1430. // 预约类型-取15分钟后之前的订单
  1431. $curtime15 = $curtime+60*15;
  1432. foreach ($a2 as $k=>$v){
  1433. if($v['priority'] !=4 && $v['xq_time'] < date('Y-m-d H:i:s',$curtime15) ){
  1434. $all[] = $v;
  1435. }
  1436. }
  1437. foreach ($a3 as $k=>$v){
  1438. if($v['priority'] !=4 && $v['xq_time'] < date('Y-m-d H:i:s',$curtime15) ){
  1439. $all[] = $v;
  1440. }
  1441. }
  1442. foreach ($a1 as $k=>$v){
  1443. if($v['priority'] !=4 && $v['xq_time'] < date('Y-m-d H:i:s',$curtime15) ){
  1444. $all[] = $v;
  1445. }
  1446. }
  1447. $newret= $all;
  1448. }
  1449. $sdd[] =['org_id','=',$this->orgId];
  1450. $sdd[] =['del','=',0];
  1451. $sdd[] =['work_type_mode','=',3];
  1452. $sdd[] =['create_yyyymmdd','=',date('Ymd')];
  1453. $dcl = Db::name('orders')
  1454. ->where($sdd)
  1455. ->where('order_mode',1)
  1456. ->count();
  1457. $ypf = Db::name('orders')
  1458. ->where($sdd)
  1459. ->where('order_mode',4)
  1460. ->count();
  1461. $ywc = Db::name('orders')
  1462. ->where($sdd)
  1463. ->where('order_mode','in',[5,6])
  1464. ->count();
  1465. $yqx = Db::name('orders')
  1466. ->where($sdd)
  1467. ->where('order_mode','in',[2,3])
  1468. ->count();
  1469. //数据返回
  1470. $totalCount = count($newret);
  1471. $totalPage = ceil($totalCount / $length);
  1472. $result['dcl'] = $dcl;
  1473. $result['ypf'] = $ypf;
  1474. $result['ywc'] = $ywc;
  1475. $result['yqx'] = $yqx;
  1476. $result['page'] = $page;
  1477. $result['total'] = $totalPage;
  1478. $result['records'] = $totalCount;
  1479. $result['rows'] = $newret;
  1480. return json($result);
  1481. }
  1482. else {
  1483. $mode_name = $this->getTableField('work_type_mode', ['id' => $mode], 'name');
  1484. $order_type = (new \app\common\model\ConveyCate())->getList();
  1485. $order_mode = Db::name('order_mode')
  1486. ->select();
  1487. $this->assign('order_type_list', $order_type);
  1488. $this->assign('m_name', $mode_name);
  1489. $this->assign('mode', $mode);
  1490. $this->assign('order_mode_list', $order_mode);
  1491. $this->assign('dispatch_type', check_two_dispatch($this->userId));
  1492. $address = (new \app\common\model\Address())->getListByType(2);
  1493. $this->assign('address', $address);
  1494. $count = Db::name('todo')
  1495. ->where('org_id', $this->orgId)
  1496. ->where('del', 0)
  1497. ->where('work_type_mode', 3)
  1498. ->where('todo_mode', 4)
  1499. ->count();
  1500. $this->assign('count', $count);
  1501. $info = Db::name('config')->where('name','org_order_refresh')
  1502. ->find();
  1503. $orgConfig = Db::name('config_org')
  1504. ->where('config_id',$info['id'])
  1505. ->where('org_id',$this->orgId)
  1506. ->find();
  1507. $value = $orgConfig?$orgConfig['value']:0;
  1508. $this->assign('refresh',$value);
  1509. $sxJg = (new Config())->getConfig('ys_auto_sx',$this->orgId);
  1510. $this->assign('sxJg',$sxJg?$sxJg:30);
  1511. return $this->fetch();
  1512. }
  1513. }
  1514. //运送员状态
  1515. public function conveystatus($id='') {
  1516. if (request()->isAjax()) {
  1517. //分页参数
  1518. $length = input('rows', 10, 'intval'); //每页条数
  1519. $page = input('page', 1, 'intval'); //第几页
  1520. $start = ($page - 1) * $length; //分页开始位置
  1521. //排序
  1522. $sortRow = input('sidx', 'id', 'trim'); //排序列
  1523. $sort = input('sord', 'desc', 'trim'); //排序方式
  1524. $order = $sortRow . ' ' . $sort;
  1525. $real_name = input('real_name', '');
  1526. $map8 = [];
  1527. if ($real_name) {
  1528. $map8[] = ['real_name', 'like', '%'.$real_name.'%'];
  1529. }
  1530. $work = input('work', '');
  1531. if ($work!='') {
  1532. $map8[] = ['work', '=',$work];
  1533. }
  1534. $user = (new \app\common\model\WorkTypeMode())->getRolesUser(3, $this->orgId);
  1535. $newUser = [];
  1536. foreach ($user as $k => $v) {
  1537. foreach ($v['user'] as $k1 => $v1) {
  1538. $newUser[] = $v1['id'];
  1539. }
  1540. }
  1541. $userIds1 = [];
  1542. if($id){
  1543. $ids = explode(',', $id);
  1544. $map[] = ['order_id', 'in', $ids];
  1545. $map[] = ['del', '=', 0];
  1546. $map[] = ['org_id', '=', $this->orgId];
  1547. $map[] = ['work_type_mode', '=', 3];
  1548. $userIds = Db::name('todo')->where($map)->column('to_user_id');
  1549. $userIds1 = $userIds?$userIds:[];
  1550. $newUser = array_intersect($userIds1,$newUser);
  1551. }
  1552. if(empty($newUser)){
  1553. $map8[] = ['id','=',0];
  1554. }else{
  1555. $map8[] = ['id','in',$newUser];
  1556. }
  1557. $mm = [];
  1558. $group = input('group', '');
  1559. if ($group) {
  1560. $uid = Db::name('user_group_user')
  1561. ->where('group_id',$group)
  1562. ->column('user_id');
  1563. if(!empty($uid)){
  1564. $mm[] = ['id','in',$uid];
  1565. }else{
  1566. $mm[] = ['id','in',[-1]];
  1567. }
  1568. }
  1569. $lists = db('user')
  1570. ->where($mm)
  1571. ->where($map8)
  1572. ->limit($start, $length)
  1573. ->order($order)
  1574. ->select();
  1575. foreach ($lists as $key => $value) {
  1576. $lists[$key]['user_group_title'] = Db::name('user_group')
  1577. ->alias('ug')
  1578. ->join('user_group_user ugu','ugu.group_id=ug.id')
  1579. ->where('ugu.user_id',$value['id'])
  1580. ->value('ug.title');
  1581. $nums = Db::name('todo')
  1582. ->where(['to_user_id' => $value['id'], 'work_type_mode' => 3])
  1583. ->where('create_yyyymmdd', date('Ymd'))
  1584. ->where('todo_mode', 'in', [1, 2, 3])
  1585. ->count();
  1586. $lists[$key]['nums'] = $nums;
  1587. $addr = Db::name('order_convey')
  1588. ->alias('cpr')
  1589. ->join('todo os', 'cpr.order_id = os.order_id')
  1590. ->join('orders ods', 'cpr.order_id = ods.id')
  1591. ->join('address ca', 'ca.id = cpr.start')
  1592. ->join('address cad', 'cad.id = cpr.end')
  1593. ->field('os.todo_mode,ca.title as start_name,cad.title as end_name,os.create_time')
  1594. ->where('os.to_user_id', $value['id'])
  1595. ->where('os.del', 0)
  1596. ->where('ods.del', 0)
  1597. ->order('os.id desc')
  1598. ->find();
  1599. $lists[$key]['title'] = '';
  1600. $lists[$key]['addr_time'] = '';
  1601. if($addr){
  1602. if(in_array($addr['todo_mode'],[1,2])){
  1603. $lists[$key]['title'] = $addr['start_name'];
  1604. }else{
  1605. $lists[$key]['title'] = $addr['end_name'];
  1606. }
  1607. $lists[$key]['addr_time'] = $addr['create_time'];
  1608. }
  1609. $lists[$key]['worktxt'] = $value['work'] == 1 ? '上班' : '下班';
  1610. $lists[$key]['stationtxt'] = $value['station'] == 1 ? '驻守' : '取消驻守';
  1611. }
  1612. //数据返回
  1613. // $totalCount = db('user')
  1614. // ->where($map1)->count();
  1615. $totalCount = db('user')
  1616. ->where($map8)->count();
  1617. $totalPage = ceil($totalCount / $length);
  1618. $result['page'] = $page;
  1619. $result['total'] = $totalPage;
  1620. $result['records'] = $totalCount;
  1621. $result['rows'] = $lists;
  1622. return json($result);
  1623. }
  1624. else {
  1625. $group = model('UserGroup')->getList();
  1626. $this->assign('group', $group);
  1627. $this->assign('id', $id);
  1628. return $this->fetch();
  1629. }
  1630. }
  1631. //上下班
  1632. public function work($id) {
  1633. $user = Db::name('user')
  1634. ->where('id', $id)
  1635. ->find();
  1636. $value = $user['work'] == 1 ? 0 : 1;
  1637. $res = Db::name('user')
  1638. ->where('id', $id)
  1639. ->update(['work' => $value, 'update_time' => getTime()]);
  1640. $res ? $this->success('操作成功') : $this->error('操作失败');
  1641. }
  1642. //驻守
  1643. public function station($id) {
  1644. $user = Db::name('user')
  1645. ->where('id', $id)
  1646. ->find();
  1647. $value = $user['station'] == 1 ? 0 : 1;
  1648. $res = Db::name('user')
  1649. ->where('id', $id)
  1650. ->update(['station' => $value, 'update_time' => getTime()]);
  1651. $res ? $this->success('操作成功') : $this->error('操作失败');
  1652. }
  1653. //驳回工单列表
  1654. public function bhTodoList() {
  1655. if (request()->isAjax()) {
  1656. $length = input('rows', 10, 'intval'); //每页条数
  1657. $page = input('page', 1, 'intval'); //第几页
  1658. $start = ($page - 1) * $length; //分页开始位置
  1659. $map[] = ['todo.org_id', '=', $this->orgId];
  1660. $map[] = ['todo.del', '=', 0];
  1661. $map[] = ['todo.todo_mode', '=', 4];
  1662. $map[] = ['todo.work_type_mode', '=', 3];
  1663. $totalCount = Db::name('todo')
  1664. ->alias('todo')
  1665. ->join('orders orders', 'orders.id = todo.order_id')
  1666. ->join('order_convey oc', 'oc.order_id = orders.id')
  1667. ->join('user u', 'u.id = todo.to_user_id')
  1668. ->where($map)
  1669. ->count();
  1670. $totalPage = ceil($totalCount / $length);
  1671. $ret = Db::name('todo')
  1672. ->alias('todo')
  1673. ->join('orders orders', 'orders.id = todo.order_id')
  1674. ->join('order_convey oc', 'oc.order_id = orders.id')
  1675. ->join('user u', 'u.id = todo.to_user_id')
  1676. ->field('orders.*,u.real_name as to_real_name,oc.type,oc.start,oc.end,oc.xq_time,oc.ywc_time,oc.device_id,oc.name,oc.phone,oc.priority,todo.nodo_reason,todo.id,todo.reject_time')
  1677. ->order('oc.xq_time', 'desc')
  1678. ->where($map)
  1679. ->limit($start, $length)
  1680. ->select();
  1681. foreach ($ret as $k => $v) {
  1682. $ret[$k]['start_name'] = $this->gettablefield('address', array('id' => $v['start']), 'title');
  1683. $ret[$k]['end_name'] = $this->gettablefield('address', array('id' => $v['end']), 'title');
  1684. $ret[$k]['type_name'] = $this->gettablefield('convey_cate', array('id' => $v['type']), 'title');
  1685. $ret[$k]['real_name'] = $this->gettablefield('user', array('id' => $v['user_id']), 'real_name');
  1686. $ret[$k]['device_name'] = '';
  1687. if ($v['device_id'] > 0) {
  1688. $ret[$k]['device_name'] = $this->gettablefield('convey_device', array('id' => $v['device_id']), 'title');
  1689. }
  1690. $last = strtotime($v['ywc_time']) - time();
  1691. $ret[$k]['last_time'] = $last > 0 ? round($last / 60) : 0;
  1692. $ret[$k]['reject_time'] = $v['reject_time'] ? date('Y-m-d h:i', strtotime($v['reject_time'])) : '';
  1693. }
  1694. $result['page'] = $page;
  1695. $result['total'] = $totalPage;
  1696. $result['records'] = $totalCount;
  1697. $result['rows'] = $ret;
  1698. return json($result);
  1699. }
  1700. else {
  1701. return $this->fetch();
  1702. }
  1703. }
  1704. //excel导出
  1705. public function export($mode) {
  1706. set_time_limit(0);
  1707. ini_set("memory_limit", "1024M");
  1708. $meta_title = '订单列表';
  1709. if ($mode == 1) {
  1710. $meta_title = '报修' . $meta_title;
  1711. }
  1712. elseif ($mode == 2) {
  1713. $meta_title = '保洁' . $meta_title;
  1714. }
  1715. elseif ($mode == 3) {
  1716. $meta_title = '运送' . $meta_title;
  1717. }
  1718. elseif ($mode == 4) {
  1719. $meta_title = '应急' . $meta_title;
  1720. }
  1721. elseif ($mode == 15) {
  1722. $meta_title = '品质整改' . $meta_title;
  1723. }elseif ($mode == -1) {
  1724. $meta_title = '一键呼叫' . $meta_title;
  1725. }
  1726. $level1 = check_is_dispatch($this->userId);
  1727. $level2 = check_two_dispatch($this->userId);
  1728. $turnoff = two_dispatch_off($this->orgId);
  1729. $quality_type = input('quality_type','');
  1730. if (request()->isGet()) {
  1731. //排序
  1732. $sortRow = input('sidx', 'a.id', 'trim'); //排序列
  1733. $sort = input('sord', 'desc', 'trim'); //排序方式
  1734. $order = $sortRow . ' ' . $sort;
  1735. $content = input('content', '', 'trim');
  1736. if ($content) {
  1737. $map[] = ['a.content', 'like', '%' . $content . '%'];
  1738. }
  1739. $dep_id = input('dep_id', '', 'trim');
  1740. if ($dep_id != '') {
  1741. $map[] = ['a.dep_id', '=', $dep_id];
  1742. }
  1743. $order_mode = input('order_mode', '', 'trim');
  1744. $map6 = [];
  1745. if ($order_mode != '') {
  1746. if($level1 && $turnoff && $mode != 15){ // 一级调度且二级调度开关开着,品质整改例外
  1747. if ($order_mode == 1) {
  1748. $map[] = ['a.is_deal', '=', 0];
  1749. }else if ($order_mode == 4) {
  1750. $map6[] = ['a.is_deal', '=', 1];
  1751. }
  1752. }
  1753. if($order_mode==100){//已挂起
  1754. $gq = Db::name('todo')
  1755. ->where('work_type_mode',1)
  1756. ->where('todo_mode',2)
  1757. ->where('pause',1)
  1758. ->column('order_id');
  1759. if(empty($gq)){
  1760. $map[] = ['a.id', '=', -1];
  1761. }else{
  1762. $map[] = ['a.id', 'in', $gq];
  1763. }
  1764. }else{
  1765. $map[] = ['a.order_mode', '=', $order_mode];
  1766. }
  1767. }
  1768. $b = input('start', '', 'trim');
  1769. $e = input('end', '', 'trim');
  1770. if ($b) {
  1771. // $b = date('Ymd', strtotime($b));
  1772. // $map[] = ['a.create_yyyymmdd', '>=', $b];
  1773. $map[] = ['a.create_time', '>=', $b];
  1774. }
  1775. if ($e) {
  1776. // $e = date('Ymd', strtotime($e));
  1777. // $map[] = ['a.create_yyyymmdd', '<=', $e];
  1778. $map[] = ['a.create_time', '<=', $e];
  1779. }
  1780. $map[] = ['a.del', '=', 0];
  1781. $map[] = ['a.org_id', '=', $this->orgId];
  1782. if($mode==-1){
  1783. $map[] = ['a.source_type', '=', 4];
  1784. }
  1785. $type = input('type', '', 'trim');
  1786. $oids = [];
  1787. if ($type != '') {
  1788. $map1[] = ['parent_id', '=', $type];
  1789. $type_id = Db::name('order_type')
  1790. ->where($map1)
  1791. ->where('org_id', $this->orgId)
  1792. ->where('enable', 1)
  1793. ->column('id');
  1794. if (!empty($type_id)) {
  1795. $map3[] = ['type_id', 'in', $type_id];
  1796. $ids = Db::name('order_repair')
  1797. ->where($map3)
  1798. ->column('order_id');
  1799. if (!empty($ids)) {
  1800. $oids = $ids;
  1801. }
  1802. else {
  1803. $oids = [];
  1804. }
  1805. }
  1806. else {
  1807. $oids = [];
  1808. }
  1809. }
  1810. $typeName = input('typeName', '', 'trim');
  1811. if ($typeName != '') {
  1812. $map_11[] = ['a.title', 'like', '%'.$typeName.'%'];
  1813. $typeNameId = Db::name('convey_cate')
  1814. ->alias('a')
  1815. ->join('order_convey b','a.id=b.type')
  1816. ->where($map_11)
  1817. ->where('a.org_id', $this->orgId)
  1818. ->where('a.enable', 1)
  1819. ->where('a.del', 0)
  1820. ->column('b.order_id');
  1821. if (!empty($typeNameId)) {
  1822. $map[] = ['a.id', 'in', $typeNameId];
  1823. }
  1824. else {
  1825. $map[] = ['a.id', '=', -1];
  1826. }
  1827. }
  1828. if($level2 && $turnoff){ // 二级调度
  1829. $roles_id = Db::name('user_roles')
  1830. ->where('user_id', $this->userId)
  1831. ->value('roles_id');
  1832. $ids = Db::name('dispatch_log')
  1833. ->where('roles_id', $roles_id)
  1834. ->whereOr('to_user_id', $this->userId)
  1835. ->column('order_id');
  1836. if (empty($ids)) {
  1837. $map[] = ['a.id', '=', -1];
  1838. } else {
  1839. if($type != ''){
  1840. $oids = array_intersect($oids,$ids);
  1841. if($oids){
  1842. $map[] = ['a.id', 'in', $oids];
  1843. }else{
  1844. $map[] = ['a.id', '=', -1];
  1845. }
  1846. }else{
  1847. $map[] = ['a.id', 'in', $ids];
  1848. }
  1849. }
  1850. }else{
  1851. if($type != ''){
  1852. if($oids){
  1853. $map[] = ['a.id', 'in', $oids];
  1854. }else{
  1855. $map[] = ['a.id', '=', 0];
  1856. }
  1857. }
  1858. }
  1859. if($mode == 15){ // 品质检查,单独处理
  1860. $map[] = ['a.work_type_mode','=',$mode];
  1861. if($quality_type !=''){
  1862. $map[] = ['a.quality_type','=',$quality_type];
  1863. }
  1864. }else{
  1865. $work_type_mode = input('work_type_mode','','trim');
  1866. if(!is_admin($this->userId)){
  1867. $auth = get_dispatch_auth($this->userId);
  1868. if($auth){
  1869. $map[] = ['a.work_type_mode', 'in', $auth];
  1870. if($mode > 0){
  1871. $map[] = ['a.work_type_mode', '=', $mode];
  1872. }else{
  1873. if($work_type_mode!=''){
  1874. $map[] = ['a.work_type_mode','=',$work_type_mode];
  1875. }
  1876. }
  1877. }else{
  1878. $map[] = ['a.work_type_mode', '=', -1];
  1879. }
  1880. }else{
  1881. if($mode > 0){
  1882. $map[] = ['a.work_type_mode', '=', $mode];
  1883. }else{
  1884. if($work_type_mode!=''){
  1885. $map[] = ['a.work_type_mode','=',$work_type_mode];
  1886. }
  1887. }
  1888. }
  1889. }
  1890. $sn = input('sn', '', 'trim');
  1891. if ($sn) {
  1892. $map[] = ['a.sn', 'like', '%' . $sn . '%'];
  1893. }
  1894. $from = input('from', '', 'trim');
  1895. if ($from) {
  1896. if($from >3){
  1897. $map[] = ['a.from','=',0];
  1898. $map[] = ['a.work_type_mode','=',$from-3];
  1899. }else{
  1900. $map[] = ['a.from','=',$from];
  1901. }
  1902. }
  1903. $dep_cate = input('dep_cate', '', 'trim');
  1904. if ($dep_cate != '') {
  1905. $depIds = Db::name('dep')
  1906. ->where('org_id',$this->orgId)
  1907. ->where('cate_id',$dep_cate)
  1908. ->where('del',0)
  1909. ->column('id');
  1910. if(!empty($depIds)){
  1911. $map[] = ['a.dep_id', 'in', $depIds];
  1912. }else{
  1913. $map[] = ['a.dep_id', '=', -1];
  1914. }
  1915. }
  1916. $priority = input('priority', '', 'trim');
  1917. if($priority !=''){
  1918. $map[] = ['b.priority', '=',$priority];
  1919. }
  1920. $sddr = input('saddr','','trim');
  1921. if($sddr !=''){
  1922. $map[] = ['b.start','=',$sddr];
  1923. }
  1924. $eddr = input('eaddr','','trim');
  1925. if($eddr !=''){
  1926. $map[] = ['b.end','=',$eddr];
  1927. }
  1928. $map = empty($map) ? true : $map;
  1929. //数据查询
  1930. if($mode==3){
  1931. $lists = db($this->table)->where($map)
  1932. ->alias('a')
  1933. ->leftJoin('order_convey b','a.id=b.order_id')
  1934. ->leftJoin('address ad','b.start=ad.id')
  1935. ->leftJoin('address ade','b.end=ade.id')
  1936. ->leftJoin('convey_cate cc','b.type=cc.id')
  1937. ->leftJoin('convey_device cd','b.device_id=cd.id')
  1938. ->leftJoin('dep dp','a.dep_id=dp.id')
  1939. // ->leftJoin('dep_cate dc','dp.cate_id=dc.id')
  1940. ->leftJoin('order_mode om','a.order_mode=om.id')
  1941. ->field('a.*,om.in_content as order_mode_text,dp.title as dep,cd.title as device_name,cc.title as type_name,b.priority,ad.title as start_name,ade.title as end_name')
  1942. ->whereOr($map6)
  1943. ->order($order)->select();
  1944. foreach ($lists as $k => $v) {
  1945. // $lists[$k] = $this->model->newFormatOrder($v);
  1946. $lists[$k]['priority'] = isset($this->model->priority[$v['priority']])?$this->model->priority[$v['priority']]:"";
  1947. $lists[$k]['task_priority'] = $v['priority']==3?2:0;
  1948. $lists[$k]['source_type_text'] =$v['from']>0? isset($this->model->source_type[$v['from']])?$this->model->source_type[$v['from']]:'':$this->getTableField('work_type_mode', ['id' => $v['work_type_mode']], 'name');
  1949. if ($turnoff && $level1 && $v['order_mode'] == 1 && $v['is_deal'] == 1) {
  1950. $lists[$k]['order_mode_text'] = '已派发';
  1951. }
  1952. }
  1953. }else{
  1954. $lists = db($this->table)->where($map)
  1955. ->alias('a')
  1956. ->leftJoin('order_convey b','a.id=b.order_id')
  1957. ->field('a.*,b.priority')
  1958. ->whereOr($map6)
  1959. ->order($order)->select();
  1960. foreach ($lists as $k => $v) {
  1961. $lists[$k] = $this->model->newFormatOrder($v);
  1962. $lists[$k]['priority'] = isset($this->model->priority[$v['priority']])?$this->model->priority[$v['priority']]:"";
  1963. if ($turnoff && $level1 && $v['order_mode'] == 1 && $v['is_deal'] == 1) {
  1964. $lists[$k]['order_mode_text'] = '已派发';
  1965. }
  1966. }
  1967. }
  1968. include_once env('root_path') . '/extend/phpexcel/Classes/PHPExcel.php';
  1969. //实例化PHPExcel类
  1970. $objPHPExcel = new \PHPExcel();
  1971. //激活当前的sheet表
  1972. $objPHPExcel->setActiveSheetIndex(0);
  1973. //设置表格头(即excel表格的第一行)
  1974. if ($mode == 1) {
  1975. $objPHPExcel->setActiveSheetIndex(0)
  1976. ->setCellValue('A1', '编号')
  1977. ->setCellValue('B1', '申请时间')
  1978. ->setCellValue('C1', '内容')
  1979. ->setCellValue('D1', '所在科室/部门')
  1980. ->setCellValue('E1', '报修类型')
  1981. ->setCellValue('F1', '状态')
  1982. ->setCellValue('G1', '紧急程度')
  1983. ->setCellValue('H1', '来源');
  1984. }
  1985. else {
  1986. if ($mode == 3) {
  1987. $objPHPExcel->setActiveSheetIndex(0)
  1988. ->setCellValue('A1', '编号')
  1989. ->setCellValue('B1', '申请时间')
  1990. ->setCellValue('C1', '开始地点')
  1991. ->setCellValue('D1', '结束地点')
  1992. ->setCellValue('E1', '运送类型')
  1993. ->setCellValue('F1', '任务备注')
  1994. ->setCellValue('G1', '所在科室/部门')
  1995. ->setCellValue('H1', '状态')
  1996. ->setCellValue('I1', '来源')
  1997. ->setCellValue('J1', '优先级');
  1998. }
  1999. else {
  2000. if($mode==0){
  2001. $objPHPExcel->setActiveSheetIndex(0)
  2002. ->setCellValue('A1', '编号')
  2003. ->setCellValue('B1', '申请时间')
  2004. ->setCellValue('C1', '内容')
  2005. ->setCellValue('D1', '所在科室/部门')
  2006. ->setCellValue('E1', '状态')
  2007. ->setCellValue('F1', '订单类型')
  2008. ->setCellValue('G1', '来源');
  2009. }else{
  2010. if($mode==15){
  2011. $objPHPExcel->setActiveSheetIndex(0)
  2012. ->setCellValue('A1', '编号')
  2013. ->setCellValue('B1', '申请时间')
  2014. ->setCellValue('C1', '内容')
  2015. ->setCellValue('D1', '所在科室/部门')
  2016. ->setCellValue('E1', '状态')
  2017. ->setCellValue('F1', '来源')
  2018. ->setCellValue('H1', '部门分类');
  2019. }else{
  2020. $objPHPExcel->setActiveSheetIndex(0)
  2021. ->setCellValue('A1', '编号')
  2022. ->setCellValue('B1', '申请时间')
  2023. ->setCellValue('C1', '内容')
  2024. ->setCellValue('D1', '所在科室/部门')
  2025. ->setCellValue('E1', '状态')
  2026. ->setCellValue('F1', '来源');
  2027. }
  2028. }
  2029. }
  2030. }
  2031. // 设置表格头水平居中
  2032. $objPHPExcel->setActiveSheetIndex(0)->getStyle('A1')->getAlignment()
  2033. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2034. $objPHPExcel->setActiveSheetIndex(0)->getStyle('B1')->getAlignment()
  2035. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2036. $objPHPExcel->setActiveSheetIndex(0)->getStyle('C1')->getAlignment()
  2037. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2038. $objPHPExcel->setActiveSheetIndex(0)->getStyle('D1')->getAlignment()
  2039. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2040. $objPHPExcel->setActiveSheetIndex(0)->getStyle('E1')->getAlignment()
  2041. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2042. $objPHPExcel->setActiveSheetIndex(0)->getStyle('F1')->getAlignment()
  2043. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2044. $objPHPExcel->setActiveSheetIndex(0)->getStyle('G1')->getAlignment()
  2045. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2046. $objPHPExcel->setActiveSheetIndex(0)->getStyle('H1')->getAlignment()
  2047. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2048. //设置列水平居中
  2049. $objPHPExcel->setActiveSheetIndex(0)->getStyle('A')->getAlignment()
  2050. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2051. $objPHPExcel->setActiveSheetIndex(0)->getStyle('B')->getAlignment()
  2052. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2053. $objPHPExcel->setActiveSheetIndex(0)->getStyle('C')->getAlignment()
  2054. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2055. $objPHPExcel->setActiveSheetIndex(0)->getStyle('D')->getAlignment()
  2056. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2057. $objPHPExcel->setActiveSheetIndex(0)->getStyle('E')->getAlignment()
  2058. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2059. $objPHPExcel->setActiveSheetIndex(0)->getStyle('F')->getAlignment()
  2060. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2061. $objPHPExcel->setActiveSheetIndex(0)->getStyle('G')->getAlignment()
  2062. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2063. $objPHPExcel->setActiveSheetIndex(0)->getStyle('H')->getAlignment()
  2064. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2065. //设置单元格宽度
  2066. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('A')->setWidth(10);
  2067. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('B')->setWidth(20);
  2068. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('C')->setWidth(20);
  2069. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('D')->setWidth(20);
  2070. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('E')->setWidth(20);
  2071. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('F')->setWidth(50);
  2072. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('G')->setWidth(20);
  2073. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('H')->setWidth(20);
  2074. //循环刚取出来的数组,将数据逐一添加到excel表格。
  2075. if ($mode == 1) {
  2076. for ($i = 0; $i < count($lists); $i++) {
  2077. $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $lists[$i]['sn']);
  2078. $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $lists[$i]['create_time']);
  2079. $objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $lists[$i]['content']);
  2080. $objPHPExcel->getActiveSheet()->setCellValue('D' . ($i + 2), $lists[$i]['dep']);
  2081. $objPHPExcel->getActiveSheet()->setCellValue('E' . ($i + 2), $lists[$i]['order_type']);
  2082. $objPHPExcel->getActiveSheet()->setCellValue('F' . ($i + 2), $lists[$i]['order_mode_text']);
  2083. $objPHPExcel->getActiveSheet()->setCellValue('G' . ($i + 2), $lists[$i]['repair_priority']);
  2084. $objPHPExcel->getActiveSheet()->setCellValue('H' . ($i + 2), $lists[$i]['source_type_text']);
  2085. }
  2086. }
  2087. else {
  2088. if ($mode == 3) {
  2089. for ($i = 0; $i < count($lists); $i++) {
  2090. $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $lists[$i]['sn']);
  2091. $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $lists[$i]['create_time']);
  2092. $objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $lists[$i]['start_name']);
  2093. $objPHPExcel->getActiveSheet()->setCellValue('D' . ($i + 2), $lists[$i]['end_name']);
  2094. $objPHPExcel->getActiveSheet()->setCellValue('E' . ($i + 2), $lists[$i]['type_name']);
  2095. $objPHPExcel->getActiveSheet()->setCellValue('F' . ($i + 2), $lists[$i]['content']);
  2096. $objPHPExcel->getActiveSheet()->setCellValue('G' . ($i + 2), $lists[$i]['dep']);
  2097. $objPHPExcel->getActiveSheet()->setCellValue('H' . ($i + 2), $lists[$i]['order_mode_text']);
  2098. $objPHPExcel->getActiveSheet()->setCellValue('I' . ($i + 2), $lists[$i]['source_type_text']);
  2099. $objPHPExcel->getActiveSheet()->setCellValue('J' . ($i + 2), $lists[$i]['priority']);
  2100. }
  2101. }
  2102. else {
  2103. if($mode==0){
  2104. for ($i = 0; $i < count($lists); $i++) {
  2105. $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $lists[$i]['sn']);
  2106. $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $lists[$i]['create_time']);
  2107. $objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $lists[$i]['content']);
  2108. $objPHPExcel->getActiveSheet()->setCellValue('D' . ($i + 2), $lists[$i]['dep']);
  2109. $objPHPExcel->getActiveSheet()->setCellValue('E' . ($i + 2), $lists[$i]['order_mode_text']);
  2110. $objPHPExcel->getActiveSheet()->setCellValue('F' . ($i + 2), $lists[$i]['work_type_mode_text']);
  2111. $objPHPExcel->getActiveSheet()->setCellValue('G' . ($i + 2), $lists[$i]['source_type_text']);
  2112. }
  2113. }else{
  2114. if($mode==15){
  2115. for ($i = 0; $i < count($lists); $i++) {
  2116. $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $lists[$i]['sn']);
  2117. $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $lists[$i]['create_time']);
  2118. $objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $lists[$i]['content']);
  2119. $objPHPExcel->getActiveSheet()->setCellValue('D' . ($i + 2), $lists[$i]['dep']);
  2120. $objPHPExcel->getActiveSheet()->setCellValue('E' . ($i + 2), $lists[$i]['order_mode_text']);
  2121. $objPHPExcel->getActiveSheet()->setCellValue('F' . ($i + 2), $lists[$i]['source_type_text']);
  2122. $objPHPExcel->getActiveSheet()->setCellValue('G' . ($i + 2), $lists[$i]['quality_cate_name']);
  2123. }
  2124. }else{
  2125. for ($i = 0; $i < count($lists); $i++) {
  2126. $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $lists[$i]['sn']);
  2127. $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $lists[$i]['create_time']);
  2128. $objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $lists[$i]['content']);
  2129. $objPHPExcel->getActiveSheet()->setCellValue('D' . ($i + 2), $lists[$i]['dep']);
  2130. $objPHPExcel->getActiveSheet()->setCellValue('E' . ($i + 2), $lists[$i]['order_mode_text']);
  2131. $objPHPExcel->getActiveSheet()->setCellValue('F' . ($i + 2), $lists[$i]['source_type_text']);
  2132. }
  2133. }
  2134. }
  2135. }
  2136. }
  2137. //设置保存的Excel表格名称
  2138. $filename = $meta_title . '_' . date('YmdHis', time()) . '.xls';
  2139. //设置当前激活的sheet表格名称
  2140. $objPHPExcel->getActiveSheet()->setTitle($meta_title);
  2141. //设置浏览器窗口下载表格
  2142. ob_end_clean();
  2143. header("Content-Type: application/force-download");
  2144. header("Content-Type: application/octet-stream");
  2145. header("Content-Type: application/download");
  2146. header('Content-Disposition:inline;filename="' . $filename);
  2147. //生成excel文件
  2148. $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  2149. //下载文件在浏览器窗口
  2150. return $objWriter->save('php://output');
  2151. }
  2152. }
  2153. public function rejectTodoList(){
  2154. $orderId = input('orderId',0);
  2155. if (request()->isAjax()) {
  2156. $length = input('rows', 10, 'intval'); //每页条数
  2157. $page = input('page', 1, 'intval'); //第几页
  2158. $start = ($page - 1) * $length; //分页开始位置
  2159. $map[] = ['org_id','=',$this->orgId];
  2160. $map[] = ['del','=',0];
  2161. $map[] = ['todo_mode','=',4];
  2162. $map[] = ['order_id','=',$orderId];
  2163. $lists = Db::name('todo')
  2164. ->where($map)
  2165. ->limit($start,$length)
  2166. ->order('id desc')
  2167. ->select();
  2168. $workTypeMode = [
  2169. '0'=>'一键呼叫',
  2170. '1'=>'报修',
  2171. '2'=>'保洁',
  2172. '3'=>'运送',
  2173. '4'=>'应急',
  2174. ];
  2175. foreach ($lists as $k=>$v){
  2176. $lists[$k]['to_user_name'] = Db::name('user')->where('id',$v['to_user_id'])->value('real_name');
  2177. $lists[$k]['work_type_mode_text'] = $workTypeMode[$v['work_type_mode']];
  2178. $lists[$k]['todo_mode_in_content'] = Db::name('todo_mode')->where('id',$v['todo_mode'])->value('in_content');
  2179. $lists[$k]['todo_mode_color'] = Db::name('todo_mode')->where('id',$v['todo_mode'])->value('color');
  2180. }
  2181. $totalCount = Db::name('todo')
  2182. ->where($map)
  2183. ->count();
  2184. $totalPage = ceil($totalCount / $length);
  2185. $result['page'] = $page;
  2186. $result['total'] = $totalPage;
  2187. $result['records'] = $totalCount;
  2188. $result['rows'] = $lists;
  2189. return json($result);
  2190. }
  2191. else {
  2192. $this->assign('orderId',$orderId);
  2193. return $this->fetch();
  2194. }
  2195. }
  2196. public function orderRefreshOff(){
  2197. $info = Db::name('config')->where('name','org_order_refresh')
  2198. ->find();
  2199. $orgConfig = Db::name('config_org')
  2200. ->where('config_id',$info['id'])
  2201. ->where('org_id',$this->orgId)
  2202. ->find();
  2203. if($orgConfig){
  2204. $value = $orgConfig['value']==1?0:1;
  2205. $res = Db::name('config_org')
  2206. ->where('config_id',$info['id'])
  2207. ->where('org_id',$this->orgId)
  2208. ->update(['value'=>$value]);
  2209. }else{
  2210. $value = 1;
  2211. $res = Db::name('config_org')
  2212. ->insertGetId([
  2213. 'config_id'=>$info['id'],
  2214. 'org_id'=>$this->orgId,
  2215. 'value'=>$value,
  2216. ]);
  2217. }
  2218. $res?$this->success('操作成功','',['status'=>$value]):$this->error('操作失败');
  2219. }
  2220. public function print1($id){
  2221. $order = Db::name('orders')->where(['id' => $id])->find();
  2222. $depName = Db::name('dep')
  2223. ->where('id',$order['dep_id'])
  2224. ->value('title');
  2225. $info['depName'] = $depName;
  2226. $info['create_time'] = $order['create_time'];
  2227. $users = Db::name('todo')
  2228. ->alias('t')
  2229. ->join('user u','u.id=t.to_user_id')
  2230. ->where('t.order_id',$order['id'])
  2231. ->column('u.real_name');
  2232. $info['users'] = $users?implode(',',$users):'';
  2233. $info['content'] = $order['content'];
  2234. $info['cons'] = [];
  2235. $tList = Db::name('todo')
  2236. ->where('order_id',$order['id'])
  2237. ->select();
  2238. $total = $totalPrice = 0;
  2239. $signs = [];
  2240. foreach ($tList as $k=>$v){
  2241. if($v['sign']){
  2242. $signs[] = $v['sign'];
  2243. }
  2244. $mate = Db::name('todo_mate_item')
  2245. ->alias('tmi')
  2246. ->join('todo_mate tm','tmi.todo_mate_id = tm.id')
  2247. ->join('mate_goods mg','mg.id = tmi.items_id')
  2248. ->field('tmi.items_id,tmi.total,tmi.money,tmi.total_money,mg.title')
  2249. ->where('tm.todo_id',$v['id'])
  2250. ->select();
  2251. if(!empty($mate)){
  2252. foreach ($mate as $kk=>$todo_mate){
  2253. $info['cons'][] = [
  2254. 'title' =>$todo_mate['title'],
  2255. 'total' =>$todo_mate['total'],
  2256. 'money' =>$todo_mate['money'],
  2257. 'total_money' =>$todo_mate['total_money'],
  2258. ];
  2259. $total +=$todo_mate['total'];
  2260. $totalPrice +=$todo_mate['total_money'];
  2261. }
  2262. }
  2263. }
  2264. $aa = [
  2265. 'title'=>'',
  2266. 'total'=>'',
  2267. 'money'=>'',
  2268. 'total_money'=>'',
  2269. ];
  2270. if(empty($info['cons'])){
  2271. for ($i=1;$i<=4;$i++){
  2272. $info['cons'][] = $aa;
  2273. }
  2274. }elseif (count($info['cons']) <4){
  2275. $ii = 4-count($info['cons']);
  2276. for ($i=1;$i<=$ii;$i++){
  2277. $info['cons'][] = $aa;
  2278. }
  2279. }
  2280. $info['total'] = $total;
  2281. $info['totalPrice'] = round($totalPrice,2);
  2282. $info['signs'] = $signs;
  2283. $this->assign('info', $info);
  2284. return $this->fetch();
  2285. }
  2286. public function withdraw(){
  2287. $id = input('id');
  2288. $info = Db::name('orders')
  2289. ->where('id',$id)
  2290. ->where('del',0)
  2291. ->where('order_mode',4)
  2292. ->find();
  2293. if(!$info){
  2294. $this->error('参数错误');
  2295. }
  2296. $saveOrder = Db::name('orders')
  2297. ->where('id',$id)
  2298. ->update(['order_mode'=>1,'withdraw_time'=>getTime()]);
  2299. $saveTodo = Db::name('todo')
  2300. ->where('order_id',$id)
  2301. ->update(['del'=>1]);
  2302. $todoIds = Db::name('todo')
  2303. ->where('order_id',$id)
  2304. ->where('todo_mode',1)
  2305. ->column('id');
  2306. $task = Db::name('task')
  2307. ->where('type',1)
  2308. ->whereIn('bus_id',$todoIds)
  2309. ->delete();
  2310. if($info['work_type_mode'] == 3){
  2311. Db::name('order_convey_end')->where('order_id',$info['id'])->setField('del',0);
  2312. }
  2313. if(!$saveOrder){
  2314. $this->error('操作失败');
  2315. }
  2316. $this->success('操作成功');
  2317. }
  2318. public function autoSend($id,$form=0) {
  2319. if(request()->isGet() && $form==0){
  2320. $order_type = (new \app\common\model\OrderType())->getList();
  2321. $order_repair = Db::name('order_repair')
  2322. ->where('order_id', $id)
  2323. ->find();
  2324. $this->assign('order_repair', $order_repair);
  2325. $this->assign('order_type_list',$order_type);
  2326. $this->assign('id',$id);
  2327. return $this->fetch();
  2328. }else{
  2329. $type_id = input('type_id/d','');
  2330. if(!empty($type_id)){
  2331. $old = Db::name('order_repair')
  2332. ->where('order_id', $id)
  2333. ->find();
  2334. $rData['type_id'] = $type_id;
  2335. if ($old) {
  2336. $rData['update_time'] = getTime();
  2337. Db::name('order_repair')
  2338. ->where('order_id', $id)
  2339. ->update($rData);
  2340. }
  2341. else {
  2342. $rData['order_id'] = $id;
  2343. Db::name('order_repair')
  2344. ->insert($rData);
  2345. }
  2346. }
  2347. $res = $this->model->autoSend($id);
  2348. if (!$res) {
  2349. $this->error($this->model->getError());
  2350. }
  2351. $this->success('操作成功');
  2352. }
  2353. }
  2354. public function setType($id) {
  2355. if(request()->isGet()){
  2356. $order_type = (new \app\common\model\OrderType())->getList();
  2357. $order_repair = Db::name('order_repair')
  2358. ->where('order_id', $id)
  2359. ->find();
  2360. $this->assign('order_repair', $order_repair);
  2361. $this->assign('order_type_list',$order_type);
  2362. $this->assign('id',$id);
  2363. return $this->fetch();
  2364. }else{
  2365. $type_id = input('type_id/d','');
  2366. if(empty($type_id)){
  2367. $this->error('请选择报修事项');
  2368. }
  2369. $old = Db::name('order_repair')
  2370. ->where('order_id', $id)
  2371. ->find();
  2372. $rData['type_id'] = $type_id;
  2373. if ($old) {
  2374. $rData['update_time'] = getTime();
  2375. $r = Db::name('order_repair')
  2376. ->where('order_id', $id)
  2377. ->update($rData);
  2378. }
  2379. else {
  2380. $rData['order_id'] = $id;
  2381. $r = Db::name('order_repair')
  2382. ->insert($rData);
  2383. }
  2384. $r?$this->success('操作成功'):$this->error('操作失败');
  2385. }
  2386. }
  2387. public function batchSb(){
  2388. $id = input('ids',[]);
  2389. if(!$id){
  2390. $this->error('参数错误');
  2391. }
  2392. $res = db('user')->where('id','in',$id)->setField('work',1);
  2393. if($res){
  2394. $this->success('操作成功');
  2395. }else{
  2396. $this->error('操作失败');
  2397. }
  2398. }
  2399. public function batchXb(){
  2400. $id = input('ids',[]);
  2401. if(!$id){
  2402. $this->error('参数错误');
  2403. }
  2404. $res = db('user')->where('id','in',$id)->setField('work',0);
  2405. if($res){
  2406. $this->success('操作成功');
  2407. }else{
  2408. $this->error('操作失败');
  2409. }
  2410. }
  2411. public function getTime(){
  2412. $type = input('type');
  2413. $start = input('start');
  2414. $v = Db::name('convey_cate')
  2415. ->where('id',$type)
  2416. ->where('enable',1)
  2417. ->where('del',0)
  2418. ->find();
  2419. if($v['time_id'] > 0){
  2420. $time = Db::name('time')
  2421. ->where('id',$v['time_id'])
  2422. ->find();
  2423. $v['xq_time'] = $start?$start:date('Y-m-d H:i');
  2424. $v['ywc_time'] = date('Y-m-d H:i',strtotime($v['xq_time']) + 60*$time['bz_time']);
  2425. }else{
  2426. $v['xq_time'] = $start?$start:date('Y-m-d H:i');
  2427. $v['ywc_time'] = '';
  2428. }
  2429. $this->success('','',$v);
  2430. }
  2431. }