Orders.php 83 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932
  1. <?php
  2. namespace app\admin\controller;
  3. use think\App;
  4. use think\Db;
  5. use think\Exception;
  6. class Orders extends Auth {
  7. public function __construct(App $app = null) {
  8. parent::__construct($app);
  9. $this->model = new \app\common\model\Orders();
  10. $this->table = $this->model->table;
  11. }
  12. //用户订单列表
  13. public function selfIndex() {
  14. $mode = input('mode', 1);
  15. if (request()->isAjax()) {
  16. //分页参数
  17. $length = input('rows', 10, 'intval'); //每页条数
  18. $page = input('page', 1, 'intval'); //第几页
  19. $start = ($page - 1) * $length; //分页开始位置
  20. //排序
  21. $sortRow = input('sidx', 'id', 'trim'); //排序列
  22. $sort = input('sord', 'desc', 'trim'); //排序方式
  23. $order = $sortRow . ' ' . $sort;
  24. $map[] = ['del', '=', 0];
  25. $map[] = ['org_id', '=', $this->orgId];
  26. $order_mode = input('order_mode', '', 'trim');
  27. if ($order_mode != '') {
  28. $map[] = ['order_mode', '=', $order_mode];
  29. }
  30. if($mode >0){
  31. $map[] = ['work_type_mode', '=', $mode];
  32. }else{
  33. $map[] = ['source_type', '=', 4];
  34. }
  35. $sn = input('sn', '', 'trim');
  36. if ($sn) {
  37. $map[] = ['sn', 'like', '%' . $sn . '%'];
  38. }
  39. if (!is_admin($this->userId)) {
  40. $map[] = ['user_id', '=', $this->userId];
  41. }
  42. $map = empty($map) ? true : $map;
  43. //数据查询
  44. $lists = db($this->table)->where($map)->limit($start, $length)->order($order)->select();
  45. foreach ($lists as $k => $v) {
  46. $lists[$k] = $this->model->formatOrder($v);
  47. }
  48. //数据返回
  49. $totalCount = db($this->table)->where($map)->count();
  50. $totalPage = ceil($totalCount / $length);
  51. $result['page'] = $page;
  52. $result['total'] = $totalPage;
  53. $result['records'] = $totalCount;
  54. $result['rows'] = $lists;
  55. return json($result);
  56. }
  57. else {
  58. $mode_name = $this->getTableField('work_type_mode', ['id' => $mode], 'name');
  59. if($mode==4){
  60. $mode_name = '安保';
  61. }
  62. $this->assign('m_name', $mode_name);
  63. $this->assign('mode', $mode);
  64. $order_mode = Db::name('order_mode')->select();
  65. $this->assign('order_mode_list', $order_mode);
  66. if ($mode == 1) {
  67. return $this->fetch('selfIndex1');
  68. }
  69. else {
  70. if ($mode == 3) {
  71. return $this->fetch('selfIndex3');
  72. }
  73. else {
  74. return $this->fetch('selfIndex');
  75. }
  76. }
  77. }
  78. }
  79. //用户添加订单
  80. public function selfAdd($mode = 1) {
  81. if (request()->isPost()) {
  82. $data = request()->post();
  83. $data['user_id'] = $this->userId;
  84. $data['org_id'] = $this->orgId;
  85. $data['work_type_mode'] = $mode;
  86. $data['images'] = isset($data['images']) && !empty($data['images']) ? implode(',', $data['images']) : '';
  87. $res = $this->model->addSave($data);
  88. if ($res) {
  89. $this->success('操作成功');
  90. }
  91. else {
  92. $this->error($this->model->getError());
  93. }
  94. }
  95. else {
  96. $dep = $this->getTableField('user_dep', ['user_id' => $this->userId], 'dep_id');
  97. $depList = (new \app\common\model\Dep())->getList();
  98. $this->assign('dep_id', $dep);
  99. $this->assign('dep_list', $depList);
  100. $this->assign('mode', $mode);
  101. if ($mode == 3) {
  102. $address = (new \app\common\model\Address())->getListByType(2);
  103. $conveyCate = (new \app\common\model\ConveyCate());
  104. $priority = $conveyCate->priority;
  105. $order_convey = $conveyCate->getList();
  106. $order_device = (new \app\common\model\ConveyDevice())->getList();
  107. $this->assign('address', $address);
  108. $this->assign('priority', $priority);
  109. $this->assign('order_convey_type', $order_convey);
  110. $this->assign('order_device', $order_device);
  111. }
  112. $user = Db::name('user')
  113. ->where('id',$this->userId)
  114. ->find();
  115. $this->assign('user',$user);
  116. if ($mode == 3) {
  117. return $this->fetch('self_add3');
  118. }
  119. else {
  120. return $this->fetch('self_add');
  121. }
  122. }
  123. }
  124. //用户取消订单
  125. public function cancel($id) {
  126. $res = $this->model->cancel($id, $this->userId);
  127. if (!$res) {
  128. $this->error($this->model->getError());
  129. }
  130. $this->success('取消成功');
  131. }
  132. //调度取消订单
  133. public function disCancel($id) {
  134. if (request()->isGet()) {
  135. $this->assign('id', $id);
  136. return $this->fetch();
  137. }
  138. else {
  139. $reason = input('cancel_reason');
  140. $res = $this->model->cancel($id, $this->userId, 2, $reason);
  141. if (!$res) {
  142. $this->error($this->model->getError());
  143. }
  144. $this->success('取消成功');
  145. }
  146. }
  147. //延迟订单
  148. public function batchdelay($id) {
  149. if (request()->isGet()) {
  150. $delay_reason = Db::name('delay_reason')
  151. ->where('org_id', $this->orgId)
  152. ->where('enable', 1)
  153. ->where('del', 0)
  154. ->select();
  155. $this->assign('delay_reason', $delay_reason);
  156. $this->assign('id', $id);
  157. return $this->fetch();
  158. }
  159. else {
  160. $delay_reason_id = input('delay_reason_id');
  161. if (empty($delay_reason_id)) {
  162. $this->error('请选择延迟原因');
  163. }
  164. $res = $this->model->delay_reason($id, $delay_reason_id);
  165. if (!$res) {
  166. $this->error($this->model->getError());
  167. }
  168. $this->success('延迟成功');
  169. }
  170. }
  171. //取消延迟订单
  172. public function batchcanceldelay($id) {
  173. if (request()->isGet()) {
  174. $this->assign('id', $id);
  175. return $this->fetch();
  176. }
  177. else {
  178. $res = $this->model->batchcanceldelay($id);
  179. if (!$res) {
  180. $this->error($this->model->getError());
  181. }
  182. $this->success('延迟成功');
  183. }
  184. }
  185. //用户查看订单详情
  186. public function detail($id) {
  187. if (!$id) {
  188. $this->error('参数错误');
  189. }
  190. $order = Db::name('orders')->where(['id' => $id])->find();
  191. $order = $this->model->formatOrder($order, 1);
  192. $order['images'] = !empty($order['images']) ? explode(',', $order['images']) : '';
  193. if($order['work_type_mode'] == 3){
  194. // 地点路径
  195. $conveyends = Db::name('order_convey_end')
  196. ->alias('a')
  197. ->join('address b','b.id = a.addr')
  198. ->where('a.order_id',$id)
  199. ->order('a.id asc')
  200. ->field('a.addr,b.title,a.scan,a.create_time,a.update_time')
  201. ->select();
  202. $order['ends'] = $conveyends?$conveyends:[];
  203. }
  204. $this->assign('info', $order);
  205. $workTypeName = $this->getTableField('work_type_mode', ['id' => $order['work_type_mode']], 'name');
  206. $this->assign('meta_title', $workTypeName . '订单详情');
  207. return $this->fetch();
  208. }
  209. //调度订单列表
  210. public function index() {
  211. $mode = input('mode', 0);
  212. $quality_type = input('quality_type','');
  213. $level1 = check_is_dispatch($this->userId);
  214. $level2 = check_two_dispatch($this->userId);
  215. $turnoff = two_dispatch_off($this->orgId);
  216. if (request()->isAjax()) {
  217. //分页参数
  218. $length = input('rows', 10, 'intval'); //每页条数
  219. $page = input('page', 1, 'intval'); //第几页
  220. $start = ($page - 1) * $length; //分页开始位置
  221. //排序
  222. $sortRow = input('sidx', 'id', 'trim'); //排序列
  223. $sort = input('sord', 'desc', 'trim'); //排序方式
  224. $order = $sortRow . ' ' . $sort;
  225. $content = input('content', '', 'trim');
  226. if ($content) {
  227. $map[] = ['content', 'like', '%' . $content . '%'];
  228. }
  229. $dep_id = input('dep_id', '', 'trim');
  230. if ($dep_id != '') {
  231. $map[] = ['dep_id', '=', $dep_id];
  232. }
  233. $dep_cate = input('dep_cate', '', 'trim');
  234. if ($dep_cate != '') {
  235. $depIds = Db::name('dep')
  236. ->where('org_id',$this->orgId)
  237. ->where('cate_id',$dep_cate)
  238. ->where('del',0)
  239. ->column('id');
  240. if(!empty($depIds)){
  241. $map[] = ['dep_id', 'in', $depIds];
  242. }else{
  243. $map[] = ['dep_id', '=', -1];
  244. }
  245. }
  246. $order_mode = input('order_mode', '', 'trim');
  247. $map6 = [];
  248. if ($order_mode != '') {
  249. if($level1 && $turnoff && $mode != 15){ // 一级调度且二级调度开关开着,品质整改例外
  250. if ($order_mode == 1) {
  251. $map[] = ['is_deal', '=', 0];
  252. }else if ($order_mode == 4) {
  253. $map6[] = ['is_deal', '=', 1];
  254. }
  255. }
  256. if($order_mode==100){//已挂起
  257. $gq = Db::name('todo')
  258. ->where('work_type_mode',1)
  259. ->where('todo_mode',2)
  260. ->where('pause',1)
  261. ->column('order_id');
  262. if(empty($gq)){
  263. $map[] = ['id', '=', -1];
  264. }else{
  265. $map[] = ['id', 'in', $gq];
  266. }
  267. }else{
  268. $map[] = ['order_mode', '=', $order_mode];
  269. }
  270. }
  271. $b = input('start', '', 'trim');
  272. $e = input('end', '', 'trim');
  273. if ($b) {
  274. $b = date('Ymd', strtotime($b));
  275. $map[] = ['create_yyyymmdd', '>=', $b];
  276. }
  277. if ($e) {
  278. $e = date('Ymd', strtotime($e));
  279. $map[] = ['create_yyyymmdd', '<=', $e];
  280. }
  281. $map[] = ['del', '=', 0];
  282. $map[] = ['org_id', '=', $this->orgId];
  283. if($mode==-1){
  284. $map[] = ['source_type', '=', 4];
  285. }
  286. $type = input('type', '', 'trim');
  287. $oids = [];
  288. if ($type != '') {
  289. $map1[] = ['parent_id', '=', $type];
  290. $type_id = Db::name('order_type')
  291. ->where($map1)
  292. ->where('org_id', $this->orgId)
  293. ->where('enable', 1)
  294. ->column('id');
  295. if (!empty($type_id)) {
  296. $map3[] = ['type_id', 'in', $type_id];
  297. $ids = Db::name('order_repair')
  298. ->where($map3)
  299. ->column('order_id');
  300. if (!empty($ids)) {
  301. $oids = $ids;
  302. }
  303. else {
  304. $oids = [];
  305. }
  306. }
  307. else {
  308. $oids = [];
  309. }
  310. }
  311. if($level2 && $turnoff){ // 二级调度
  312. $roles_id = Db::name('user_roles')
  313. ->where('user_id', $this->userId)
  314. ->value('roles_id');
  315. $ids = Db::name('dispatch_log')
  316. ->where('roles_id', $roles_id)
  317. ->whereOr('to_user_id', $this->userId)
  318. ->column('order_id');
  319. if (empty($ids)) {
  320. $map[] = ['id', '=', -1];
  321. } else {
  322. if($type != ''){
  323. $oids = array_intersect($oids,$ids);
  324. if($oids){
  325. $map[] = ['id', 'in', $oids];
  326. }else{
  327. $map[] = ['id', '=', -1];
  328. }
  329. }else{
  330. $map[] = ['id', 'in', $ids];
  331. }
  332. }
  333. }else{
  334. if($type != ''){
  335. if($oids){
  336. $map[] = ['id', 'in', $oids];
  337. }else{
  338. $map[] = ['id', '=', 0];
  339. }
  340. }
  341. }
  342. if($mode == 15){ // 品质检查,单独处理
  343. $map[] = ['work_type_mode','=',$mode];
  344. if($quality_type!=''){
  345. $map[] = ['quality_type','=',$quality_type];
  346. }
  347. }else{
  348. $work_type_mode = input('work_type_mode','','trim');
  349. if(!is_admin($this->userId)){
  350. $auth = get_dispatch_auth($this->userId);
  351. if($auth){
  352. $map[] = ['work_type_mode', 'in', $auth];
  353. if($mode > 0){
  354. $map[] = ['work_type_mode', '=', $mode];
  355. }else{
  356. if($work_type_mode!=''){
  357. $map[] = ['work_type_mode','=',$work_type_mode];
  358. }
  359. }
  360. }else{
  361. $map[] = ['work_type_mode', '=', -1];
  362. }
  363. }else{
  364. if($mode > 0){
  365. $map[] = ['work_type_mode', '=', $mode];
  366. }else{
  367. if($work_type_mode!=''){
  368. $map[] = ['work_type_mode','=',$work_type_mode];
  369. }
  370. }
  371. }
  372. }
  373. $sn = input('sn', '', 'trim');
  374. if ($sn) {
  375. $map[] = ['sn', 'like', '%' . $sn . '%'];
  376. }
  377. $from = input('from', '', 'trim');
  378. if ($from) {
  379. if($from >3){
  380. $map[] = ['from','=',0];
  381. $map[] = ['work_type_mode','=',$from-3];
  382. }else{
  383. $map[] = ['from','=',$from];
  384. }
  385. }
  386. $map = empty($map) ? true : $map;
  387. //数据查询
  388. $lists = db($this->table)->where($map)
  389. ->whereOr($map6)
  390. ->limit($start, $length)->order($order)->select();
  391. foreach ($lists as $k => $v) {
  392. $lists[$k] = $this->model->formatOrder($v);
  393. if ($turnoff && $level1 && $v['order_mode'] == 1 && $v['is_deal'] == 1) {
  394. $lists[$k]['order_mode_text'] = '已派发';
  395. }
  396. $lists[$k]['bh_nums'] = Db::name('todo')->where('order_id',$v['id'])->where('del',0)->where('todo_mode',4)->count();
  397. $gq = Db::name('todo')
  398. ->where('order_id',$v['id'])
  399. ->where('work_type_mode',1)
  400. ->where('todo_mode',2)
  401. ->where('pause',1)
  402. ->find();
  403. $lists[$k]['gq'] = $gq?'存在挂起':'';
  404. }
  405. //数据返回
  406. $totalCount = db($this->table)->where($map)->count();
  407. $totalPage = ceil($totalCount / $length);
  408. $result['page'] = $page;
  409. $result['total'] = $totalPage;
  410. $result['records'] = $totalCount;
  411. $result['rows'] = $lists;
  412. return json($result);
  413. }
  414. else {
  415. if($mode >0){
  416. $mode_name = $this->getTableField('work_type_mode', ['id' => $mode], 'name');
  417. }else{
  418. $mode_name = '';
  419. }
  420. if($mode==4){
  421. $mode_name = '安保';
  422. }
  423. $auths = [1,2,3,4,15,0];
  424. if(!is_admin($this->userId)){
  425. $auth = get_dispatch_auth($this->userId);
  426. if($auth){
  427. $auths = array_intersect($auths,$auth);
  428. if($mode > 0){
  429. $auths = array_intersect($auths,[$mode]);
  430. }
  431. }else{
  432. $auths = [];
  433. }
  434. }
  435. $this->assign('auths',$auths);
  436. $dep_list = (new \app\common\model\Dep())->getList();
  437. $order_type = (new \app\common\model\OrderType())->list();
  438. $order_mode = Db::name('order_mode')
  439. ->select();
  440. $this->assign('dep_list', $dep_list);
  441. $this->assign('order_type_list', $order_type);
  442. $this->assign('m_name', $mode_name);
  443. $this->assign('mode', $mode);
  444. $this->assign('order_mode_list', $order_mode);
  445. $this->assign('dispatch_type', check_two_dispatch($this->userId));
  446. $this->assign('quality_type',$quality_type);
  447. $dep_cate = model('DepCate')->getList();
  448. $this->assign('dep_cate',$dep_cate);
  449. $is = 0;
  450. if(!isset($_GET['quality_type']) && $mode==15){
  451. $is = 1;
  452. }
  453. $this->assign('is',$is);
  454. if ($mode == 1) {
  455. return $this->fetch('index1');
  456. }
  457. else {
  458. if ($mode == 3) {
  459. return $this->fetch('index3');
  460. }else if (in_array($mode,[0,-1])) {
  461. return $this->fetch('index0');
  462. }
  463. else {
  464. return $this->fetch('index');
  465. }
  466. }
  467. }
  468. }
  469. //调度删除订单
  470. public function del($id = 0) {
  471. if (!$id) {
  472. $this->error('参数错误');
  473. }
  474. $model = (new \app\common\model\Orders());
  475. $res = $model->del($id, $this->userId);
  476. if (!$res) {
  477. $this->error($model->getError());
  478. }
  479. $this->success('删除成功');
  480. }
  481. //调度添加订单
  482. public function dispatchAdd($mode = 1) {
  483. $id = input('id', 0);
  484. if (request()->isPost()) {
  485. $data = request()->post();
  486. $data['user_id'] = $this->userId;
  487. $data['org_id'] = $this->orgId;
  488. $data['work_type_mode'] = isset($data['work_type_mode'])?$data['work_type_mode']:$mode;
  489. $data['images'] = isset($data['images']) && !empty($data['images']) ? implode(',', $data['images']) : '';
  490. if ($id > 0) {
  491. // $phoneInfo = Db::name('phone_monitor_record')
  492. // ->where('id', $id)
  493. // ->find();
  494. $data['id'] = $id;
  495. $data['user_id'] = $this->userId;
  496. }
  497. $res = $this->model->addSave($data, 1);
  498. if ($res) {
  499. $this->success('操作成功');
  500. }
  501. else {
  502. $this->error($this->model->getError());
  503. }
  504. }
  505. else {
  506. if($mode==0){//创建一键呼叫
  507. $dep = $this->getTableField('user_dep', ['user_id' => $this->userId], 'dep_id');
  508. $depList = (new \app\common\model\Dep())->getList();
  509. $this->assign('dep_id', $dep);
  510. $this->assign('dep_list', $depList);
  511. $order_type = (new \app\common\model\OrderType())->getList();
  512. $address = (new \app\common\model\Address())->getListByType(1);
  513. $this->assign('order_type_list', $order_type);
  514. $this->assign('address_list', $address);
  515. $order_repair = Db::name('order_repair')
  516. ->where('order_id', $id)
  517. ->find();
  518. $this->assign('order_repair', $order_repair);
  519. $workType = Db::name('work_type_mode')
  520. ->where('type',1)
  521. ->select();
  522. $config = Db::name('config')
  523. ->where('name','web_order_transfer_type')
  524. ->value('value');
  525. if(empty($config)){
  526. $workType = [];
  527. }else{
  528. $ll = explode('|',$config);
  529. foreach ($workType as $kk=>$vv){
  530. if(!in_array($vv['id'],$ll)){
  531. unset($workType[$kk]);
  532. }
  533. }
  534. }
  535. if(!is_admin($this->userId)){
  536. $auth = get_dispatch_auth($this->userId);
  537. if(empty($auth)){
  538. $workType = [];
  539. }else{
  540. foreach ($workType as $kk=>$vv){
  541. if(!in_array($vv['id'],$auth)){
  542. unset($workType[$kk]);
  543. }
  544. }
  545. }
  546. }
  547. foreach ($workType as $k=>$v){
  548. $this->assign('send_user_num'.$v['id'], $this->model->sendUserNum($v['id'], $this->orgId));
  549. $this->assign('user_list'.$v['id'], (new \app\common\model\WorkTypeMode())->getRolesUserByNum($v['id'], $this->orgId, 1));
  550. $two_dispatch_roles = model('user')->get_two_dispatch_role($this->orgId, $v['id']);
  551. $this->assign('dispatch_roles'.$v['id'], $two_dispatch_roles);
  552. }
  553. $this->assign('dispatch_type', check_two_dispatch($this->userId));
  554. $this->assign('two_dispatch_off', two_dispatch_off($this->orgId));
  555. $this->assign('workType', $workType);
  556. $address = (new \app\common\model\Address())->getListByType(2);
  557. $conveyCate = (new \app\common\model\ConveyCate());
  558. $priority = $conveyCate->priority;
  559. $order_convey = $conveyCate->getList();
  560. $order_device = (new \app\common\model\ConveyDevice())->getList();
  561. $this->assign('address', $address);
  562. $this->assign('priority', $priority);
  563. $this->assign('order_convey_type', $order_convey);
  564. $this->assign('order_device', $order_device);
  565. $oCid = Db::name('order_convey')
  566. ->where('order_id',$id)
  567. ->find();
  568. $opt = Db::name('order_convey_patient')
  569. ->where('order_id',$id)
  570. ->find();
  571. $this->assign('ocid',$oCid);
  572. $this->assign('opt',$opt);
  573. $this->assign('ps',empty($opt)?1:0);
  574. $this->assign('id', $id);
  575. $this->assign('mode', $mode);
  576. return $this->fetch('yjhj_dispatch_add');
  577. }else{
  578. $dep = $this->getTableField('user_dep', ['user_id' => $this->userId], 'dep_id');
  579. $depList = (new \app\common\model\Dep())->getList();
  580. $order_type = (new \app\common\model\OrderType())->getList();
  581. $address = (new \app\common\model\Address())->getListByType(1);
  582. $this->assign('dep_id', $dep);
  583. $this->assign('dep_list', $depList);
  584. $this->assign('order_type_list', $order_type);
  585. $this->assign('mode', $mode);
  586. $this->assign('send_user_num', $this->model->sendUserNum($mode, $this->orgId));
  587. $this->assign('user_list', (new \app\common\model\WorkTypeMode())->getRolesUserByNum($mode, $this->orgId,1));
  588. $this->assign('address_list', $address);
  589. $this->assign('address_id', '');
  590. if ($mode == 3) {
  591. $address = (new \app\common\model\Address())->getListByType(2);
  592. $conveyCate = (new \app\common\model\ConveyCate());
  593. $priority = $conveyCate->priority;
  594. $order_convey = $conveyCate->getList();
  595. $order_device = (new \app\common\model\ConveyDevice())->getList();
  596. $this->assign('address', $address);
  597. $this->assign('priority', $priority);
  598. $this->assign('order_convey_type', $order_convey);
  599. $this->assign('order_device', $order_device);
  600. }
  601. if ($id > 0) {
  602. // $phoneInfo = Db::name('phone_monitor_record')
  603. // ->where('id', $id)
  604. // ->find();
  605. $this->assign('address_id', 0);
  606. // $depId = Db::name('user_dep')
  607. // ->where('user_id', $phoneInfo['user_id'])
  608. // ->value('dep_id');
  609. $this->assign('dep_id', 0);
  610. }
  611. $two_dispatch_roles = model('user')->get_two_dispatch_role($this->orgId, $mode);
  612. $this->assign('dispatch_roles', $two_dispatch_roles);
  613. $this->assign('dispatch_type', check_two_dispatch($this->userId));
  614. $this->assign('two_dispatch_off', two_dispatch_off($this->orgId));
  615. $this->assign('id', $id);
  616. if ($mode == 3) {
  617. $user = Db::name('user')
  618. ->where('id',$this->userId)
  619. ->find();
  620. $this->assign('user',$user);
  621. return $this->fetch('dispatch_add3');
  622. }
  623. else {
  624. return $this->fetch('dispatch_add');
  625. }
  626. }
  627. }
  628. }
  629. //调度查看订单详情
  630. public function detail2($id) {
  631. if (!$id) {
  632. $this->error('参数错误');
  633. }
  634. $type = input('type/d',0);
  635. $this->assign('type', $type);
  636. $order = Db::name('orders')->where(['id' => $id])->find();
  637. $order = $this->model->formatOrder($order, 1);
  638. $order['images'] = !empty($order['images']) ? explode(',', $order['images']) : '';
  639. $this->assign('info', $order);
  640. $workTypeName = $this->getTableField('work_type_mode', ['id' => $order['work_type_mode']], 'name');
  641. $this->assign('meta_title', $workTypeName . '订单详情');
  642. $level2 = check_two_dispatch($this->userId);
  643. $level1 = check_is_dispatch($this->userId);
  644. $turnoff = two_dispatch_off($this->orgId);
  645. $this->assign('level1', $level1);
  646. $this->assign('level2', $level2);
  647. $this->assign('turnoff', $turnoff);
  648. $this->assign('dispatch_type', $level2);
  649. return $this->fetch();
  650. }
  651. public function zg_detail($id) {
  652. if (!$id) {
  653. $this->error('参数错误');
  654. }
  655. $type = input('type/d',0);
  656. $this->assign('type', $type);
  657. $order = Db::name('orders')->where(['id' => $id])->find();
  658. $order = $this->model->formatOrder($order, 1);
  659. $order['images'] = !empty($order['images']) ? explode(',', $order['images']) : '';
  660. $this->assign('info', $order);
  661. $workTypeName = $this->getTableField('work_type_mode', ['id' => $order['work_type_mode']], 'name');
  662. $this->assign('meta_title', $workTypeName . '订单详情');
  663. $level2 = check_two_dispatch($this->userId);
  664. $level1 = check_is_dispatch($this->userId);
  665. $turnoff = two_dispatch_off($this->orgId);
  666. $this->assign('level1', $level1);
  667. $this->assign('level2', $level2);
  668. $this->assign('turnoff', $turnoff);
  669. $this->assign('dispatch_type', $level2);
  670. return $this->fetch();
  671. }
  672. public function print($id) {
  673. if (!$id) {
  674. $this->error('参数错误');
  675. }
  676. $type = input('type/d',0);
  677. $this->assign('type', $type);
  678. $order = Db::name('orders')->where(['id' => $id])->find();
  679. $order = $this->model->formatOrder($order, 1);
  680. $order['images'] = !empty($order['images']) ? explode(',', $order['images']) : '';
  681. $this->assign('info', $order);
  682. $workTypeName = $this->getTableField('work_type_mode', ['id' => $order['work_type_mode']], 'name');
  683. $this->assign('meta_title', $workTypeName . '订单详情');
  684. $level2 = check_two_dispatch($this->userId);
  685. $level1 = check_is_dispatch($this->userId);
  686. $turnoff = two_dispatch_off($this->orgId);
  687. $this->assign('level1', $level1);
  688. $this->assign('level2', $level2);
  689. $this->assign('turnoff', $turnoff);
  690. $this->assign('dispatch_type', $level2);
  691. return $this->fetch();
  692. }
  693. //派单
  694. public function send($id, $mode = 1) {
  695. if (request()->isGet()) {
  696. $this->assign('id', $id);
  697. $this->assign('mode', $mode);
  698. $orders = Db::name('orders')
  699. ->where('id',$id)
  700. ->find();
  701. if($orders['source_type']==4 && $orders['work_type_mode']==0 && $orders['is_deal']==0){//一键呼叫
  702. $order_type = (new \app\common\model\OrderType())->getList();
  703. $address = (new \app\common\model\Address())->getListByType(1);
  704. $this->assign('order_type_list', $order_type);
  705. $this->assign('address_list', $address);
  706. $order_repair = Db::name('order_repair')
  707. ->where('order_id', $id)
  708. ->find();
  709. $this->assign('order_repair', $order_repair);
  710. $workType = Db::name('work_type_mode')
  711. ->where('type',1)
  712. ->select();
  713. $config = Db::name('config')
  714. ->where('name','web_order_transfer_type')
  715. ->value('value');
  716. if(empty($config)){
  717. $workType = [];
  718. }else{
  719. $ll = explode('|',$config);
  720. foreach ($workType as $kk=>$vv){
  721. if(!in_array($vv['id'],$ll)){
  722. unset($workType[$kk]);
  723. }
  724. }
  725. }
  726. foreach ($workType as $k=>$v){
  727. $this->assign('send_user_num'.$v['id'], $this->model->sendUserNum($v['id'], $this->orgId));
  728. $this->assign('user_list'.$v['id'], (new \app\common\model\WorkTypeMode())->getRolesUserByNum($v['id'], $this->orgId, 1));
  729. $two_dispatch_roles = model('user')->get_two_dispatch_role($this->orgId, $v['id']);
  730. $this->assign('dispatch_roles'.$v['id'], $two_dispatch_roles);
  731. }
  732. $this->assign('dispatch_type', check_two_dispatch($this->userId));
  733. $this->assign('two_dispatch_off', two_dispatch_off($this->orgId));
  734. $this->assign('workType', $workType);
  735. $this->assign('orders', $orders);
  736. $address = (new \app\common\model\Address())->getListByType(2);
  737. $conveyCate = (new \app\common\model\ConveyCate());
  738. $priority = $conveyCate->priority;
  739. $order_convey = $conveyCate->getList();
  740. $order_device = (new \app\common\model\ConveyDevice())->getList();
  741. $this->assign('address', $address);
  742. $this->assign('priority', $priority);
  743. $this->assign('order_convey_type', $order_convey);
  744. $this->assign('order_device', $order_device);
  745. $oCid = Db::name('order_convey')
  746. ->where('order_id',$id)
  747. ->find();
  748. $opt = Db::name('order_convey_patient')
  749. ->where('order_id',$id)
  750. ->find();
  751. $this->assign('ocid',$oCid);
  752. $this->assign('opt',$opt);
  753. $this->assign('ps',empty($opt)?1:0);
  754. $auths = [1,2,3,4,15,0];
  755. if(!is_admin($this->userId)){
  756. $auth = get_dispatch_auth($this->userId);
  757. if($auth){
  758. $auths = array_intersect($auths,$auth);
  759. if($mode > 0){
  760. $auths = array_intersect($auths,[$mode]);
  761. }
  762. }else{
  763. $auths = [];
  764. }
  765. }
  766. $this->assign('auths',$auths);
  767. return $this->fetch('yjhj_send');
  768. }else{
  769. if ($mode == 1) {
  770. $order_type = (new \app\common\model\OrderType())->getList();
  771. $address = (new \app\common\model\Address())->getListByType(1);
  772. $this->assign('order_type_list', $order_type);
  773. $this->assign('address_list', $address);
  774. $order_repair = Db::name('order_repair')
  775. ->where('order_id', $id)
  776. ->find();
  777. $this->assign('order_repair', $order_repair);
  778. }
  779. $this->assign('send_user_num', $this->model->sendUserNum($mode, $this->orgId));
  780. $this->assign('user_list', (new \app\common\model\WorkTypeMode())->getRolesUserByNum($mode, $this->orgId, 1));
  781. $two_dispatch_roles = model('user')->get_two_dispatch_role($this->orgId, $mode);
  782. $this->assign('dispatch_roles', $two_dispatch_roles);
  783. $this->assign('dispatch_type', check_two_dispatch($this->userId));
  784. $this->assign('two_dispatch_off', two_dispatch_off($this->orgId));
  785. return $this->fetch();
  786. }
  787. }
  788. else {
  789. $data = request()->post();
  790. $data['org_id'] = $this->orgId;
  791. $res = $this->model->send($id, $this->userId, $data);
  792. if (!$res) {
  793. $this->error($this->model->getError());
  794. }
  795. $this->success('操作成功');
  796. }
  797. }
  798. //转单
  799. public function zd_send($id, $mode = 1) {
  800. if (request()->isGet()) {
  801. $this->assign('id', $id);
  802. $this->assign('mode', $mode);
  803. $orders = Db::name('orders')
  804. ->where('id',$id)
  805. ->find();
  806. if($orders['source_type']==4 && $orders['is_deal']==0){//一键呼叫
  807. $order_type = (new \app\common\model\OrderType())->getList();
  808. $address = (new \app\common\model\Address())->getListByType(1);
  809. $this->assign('order_type_list', $order_type);
  810. $this->assign('address_list', $address);
  811. $order_repair = Db::name('order_repair')
  812. ->where('order_id', $id)
  813. ->find();
  814. $this->assign('order_repair', $order_repair);
  815. $workType = Db::name('work_type_mode')
  816. ->where('type',1)
  817. ->select();
  818. $config = Db::name('config')
  819. ->where('name','web_order_transfer_type')
  820. ->value('value');
  821. if(empty($config)){
  822. $workType = [];
  823. }else{
  824. $ll = explode('|',$config);
  825. foreach ($workType as $kk=>$vv){
  826. if(!in_array($vv['id'],$ll)){
  827. unset($workType[$kk]);
  828. }
  829. }
  830. }
  831. foreach ($workType as $k=>$v){
  832. $this->assign('send_user_num'.$v['id'], $this->model->sendUserNum($v['id'], $this->orgId));
  833. $this->assign('user_list'.$v['id'], (new \app\common\model\WorkTypeMode())->getRolesUser($v['id'], $this->orgId, 1));
  834. $two_dispatch_roles = model('user')->get_two_dispatch_role($this->orgId, $v['id']);
  835. $this->assign('dispatch_roles'.$v['id'], $two_dispatch_roles);
  836. }
  837. $this->assign('dispatch_type', check_two_dispatch($this->userId));
  838. $this->assign('two_dispatch_off', two_dispatch_off($this->orgId));
  839. $this->assign('workType', $workType);
  840. $this->assign('orders', $orders);
  841. $address = (new \app\common\model\Address())->getListByType(2);
  842. $conveyCate = (new \app\common\model\ConveyCate());
  843. $priority = $conveyCate->priority;
  844. $order_convey = $conveyCate->getList();
  845. $order_device = (new \app\common\model\ConveyDevice())->getList();
  846. $this->assign('address', $address);
  847. $this->assign('priority', $priority);
  848. $this->assign('order_convey_type', $order_convey);
  849. $this->assign('order_device', $order_device);
  850. $oCid = Db::name('order_convey')
  851. ->where('order_id',$id)
  852. ->find();
  853. $opt = Db::name('order_convey_patient')
  854. ->where('order_id',$id)
  855. ->find();
  856. $this->assign('ocid',$oCid);
  857. $this->assign('opt',$opt);
  858. $this->assign('ps',empty($opt)?1:0);
  859. $auths = [1,2,3,4,15,0];
  860. if(!is_admin($this->userId)){
  861. $auth = get_dispatch_auth($this->userId);
  862. if($auth){
  863. $auths = array_intersect($auths,$auth);
  864. if($mode > 0){
  865. $auths = array_intersect($auths,[$mode]);
  866. }
  867. }else{
  868. $auths = [];
  869. }
  870. }
  871. $this->assign('auths',$auths);
  872. return $this->fetch('yjhj_zd_send');
  873. }
  874. }
  875. else {
  876. $data = request()->post();
  877. $data['org_id'] = $this->orgId;
  878. $res = $this->model->zd_send($id, $data);
  879. if (!$res) {
  880. $this->error($this->model->getError());
  881. }
  882. $this->success('操作成功');
  883. }
  884. }
  885. //批量派单
  886. public function batchsend($id, $mode = 1) {
  887. if (request()->isGet()) {
  888. $this->assign('id', $id);
  889. $this->assign('mode', $mode);
  890. if ($mode == 1) {
  891. $order_type = (new \app\common\model\OrderType())->getList();
  892. $address = (new \app\common\model\Address())->getListByType(1);
  893. $this->assign('order_type_list', $order_type);
  894. $this->assign('address_list', $address);
  895. $order_repair = Db::name('order_repair')
  896. ->where('order_id', $id)
  897. ->find();
  898. $this->assign('order_repair', $order_repair);
  899. }
  900. $user = (new \app\common\model\WorkTypeMode())->getRolesUser($mode, $this->orgId, 1);
  901. $newUser = [];
  902. foreach ($user as $k => $v) {
  903. foreach ($v['user'] as $k1 => $v1) {
  904. $newUser[] = $v1;
  905. }
  906. }
  907. foreach ($newUser as $key => $value) {
  908. $nums = Db::name('todo')
  909. ->where(['to_user_id' => $value['id'], 'work_type_mode' => 3])
  910. ->where('create_yyyymmdd', date('ymd'))
  911. ->where('todo_mode', 'in', [1, 2, 3])
  912. ->count();
  913. $newUser[$key]['nums'] = $nums;
  914. $addr = Db::name('convey_plan_record')
  915. ->alias('cpr')
  916. ->join('address ca', 'ca.id = cpr.addr_id')
  917. ->field('ca.title,cpr.create_time')
  918. ->where('cpr.user_id', $value['id'])
  919. ->order('cpr.id desc')
  920. ->find();
  921. $newUser[$key]['title'] = $addr ? $addr['title'] : '';
  922. $newUser[$key]['addr_time'] = $addr ? $addr['create_time'] : '';
  923. }
  924. $this->assign('user_list', $newUser);
  925. return $this->fetch();
  926. }
  927. else {
  928. $data = request()->post();
  929. $data['org_id'] = $this->orgId;
  930. if (empty($data['to_user_id'])) {
  931. $this->error('请选择执行人');
  932. }
  933. $data['to_user_id'] = implode(',', $data['to_user_id']);
  934. $res = $this->model->batchsend($id, $this->userId, $data);
  935. if (!$res) {
  936. $this->error($this->model->getError());
  937. }
  938. $this->success('操作成功');
  939. }
  940. }
  941. //完成订单
  942. public function finish($id) {
  943. $res = $this->model->finish($id);
  944. if (!$res) {
  945. $this->error($this->model->getError());
  946. }
  947. $this->success('操作成功');
  948. }
  949. //批量完成订单
  950. public function batchfinish($id) {
  951. $res = $this->model->batchfinish($id);
  952. if (!$res) {
  953. $this->error($this->model->getError());
  954. }
  955. $this->success('操作成功');
  956. }
  957. //评价
  958. public function comment() {
  959. $id = input('id');
  960. $score = input('score');
  961. $content = input('content');
  962. if ($score <= 0 || $score > 5) {
  963. $this->error('参数错误');
  964. }
  965. $res = $this->model->addComment($id, $score, $content, $this->userId, $this->orgId);
  966. if (!$res) {
  967. $this->error($this->model->getError());
  968. }
  969. $this->success('操作成功');
  970. }
  971. public function phone() {
  972. $phone = input('phone','','trim');
  973. $fp = input('fp','','trim');
  974. $id = input('id/d',0,'trim');
  975. if($phone){
  976. $fp = $fp?base64_decode($fp):'';
  977. $md5 = md5($this->orgId.'|'.$fp);
  978. $ret = Db::name('phone_monitor_record')->where('md5',$md5)->find();
  979. if(!$ret){
  980. $id = Db::name('phone_monitor_record')->insertGetId([
  981. 'org_id' => $this->orgId,
  982. 'phone' => $phone,
  983. 'path' => $fp,
  984. 'md5' => $md5,
  985. 'create_time' => date('Y-m-d H:i:s')
  986. ]);
  987. }else{
  988. $id = $ret['id'];
  989. }
  990. }
  991. $worktype = [
  992. ['id' => 1, 'title' => '报修'],
  993. ['id' => 2, 'title' => '保洁'],
  994. ['id' => 3, 'title' => '运送'],
  995. ['id' => 4, 'title' => '安保'],
  996. ];
  997. $info = Db::name('phone_monitor_record')->where('id',$id)->find();
  998. if(!$info){
  999. halt('数据存储失败');
  1000. }
  1001. $this->assign('worktype', $worktype);
  1002. $this->assign('info', $info);
  1003. $this->assign('id', $id);
  1004. return $this->fetch();
  1005. }
  1006. public function phoneAdd() {
  1007. $id = input('id');
  1008. $worktype = [
  1009. ['id' => 1, 'title' => '报修'],
  1010. ['id' => 2, 'title' => '保洁'],
  1011. ['id' => 3, 'title' => '运送'],
  1012. ['id' => 4, 'title' => '安保'],
  1013. ];
  1014. $info = Db::name('phone_monitor')
  1015. ->where('id', $id)->find();
  1016. if (!$info) {
  1017. echo '负责人不存在', exit();
  1018. }
  1019. $info['real_name'] = Db::name('user')
  1020. ->where('id', $info['user_id'])
  1021. ->value('real_name');
  1022. $info['dep'] = Db::name('user_dep')
  1023. ->alias('a')
  1024. ->join('dep b', 'a.dep_id=b.id')
  1025. ->where('a.user_id', $info['user_id'])
  1026. ->value('b.title');
  1027. $this->assign('worktype', $worktype);
  1028. $this->assign('info', $info);
  1029. $this->assign('id', $id);
  1030. return $this->fetch();
  1031. }
  1032. //运送调度订单列表
  1033. public function convey() {
  1034. $mode = input('mode', 1);
  1035. if (request()->isAjax()) {
  1036. //分页参数
  1037. $length = input('rows', 10, 'intval'); //每页条数
  1038. $page = input('page', 1, 'intval'); //第几页
  1039. $start = ($page - 1) * $length; //分页开始位置
  1040. //排序
  1041. $sortRow = input('sidx', 'id', 'trim'); //排序列
  1042. $sort = input('sord', 'desc', 'trim'); //排序方式
  1043. $order = $sortRow . ' ' . $sort;
  1044. $content = input('content', '', 'trim');
  1045. if ($content) {
  1046. $map[] = ['o.content', 'like', '%' . $content . '%'];
  1047. }
  1048. $dep_id = input('dep_id', '', 'trim');
  1049. if ($dep_id != '') {
  1050. $map[] = ['o.dep_id', '=', $dep_id];
  1051. }
  1052. $priority = input('priority', '', 'trim');
  1053. if ($priority) {
  1054. $map[] = ['oc.priority', '=', $priority];
  1055. }
  1056. $s = input('start', '', 'trim');
  1057. $end = input('end', '', 'trim');
  1058. if ($s) {
  1059. $map[] = ['oc.start', '=', $start];
  1060. }
  1061. if ($end) {
  1062. $map[] = ['oc.end', '=', $end];
  1063. }
  1064. $type = input('type', '', 'trim');
  1065. if ($type) {
  1066. $map[] = ['oc.type', '=', $type];
  1067. }
  1068. $xqtime = input('xqtime', '', 'trim');
  1069. $ywctime = input('ywctime', '', 'trim');
  1070. if ($xqtime) {
  1071. $xqtimes = explode(' - ', $xqtime);
  1072. $x1 = date('Ymd', strtotime($xqtimes[0]));
  1073. $x2 = date('Ymd', strtotime($xqtimes[1]));
  1074. $map[] = ['oc.xq_time', '>=', $x1];
  1075. $map[] = ['oc.xq_time', '<=', $x2];
  1076. }
  1077. if ($ywctime) {
  1078. $ywctimes = explode(' - ', $ywctime);
  1079. $y1 = date('Ymd', strtotime($ywctimes[0]));
  1080. $y2 = date('Ymd', strtotime($ywctimes[1]));
  1081. $map[] = ['oc.ywc_time', '>=', $y1];
  1082. $map[] = ['oc.ywc_time', '<=', $y2];
  1083. }
  1084. $map[] = ['o.del', '=', 0];
  1085. $map[] = ['o.org_id', '=', $this->orgId];
  1086. $map[] = ['o.work_type_mode', '=', 3];
  1087. $map[] = ['o.order_mode', 'in', [1, 4]];
  1088. $status = input('status', '', 'trim');
  1089. $ysName = input('ysname', '');
  1090. if ($ysName) {
  1091. $orders = Db::name('todo')
  1092. ->alias('t')
  1093. ->where('t.org_id', $this->orgId)
  1094. ->where('t.del', 0)
  1095. ->where('t.work_type_mode', 3)
  1096. ->where('t.todo_mode', [1, 2, 4])
  1097. ->where('u.real_name', 'like', '%' . $ysName . '%')
  1098. ->join('orders o', 'o.id = t.order_id')
  1099. ->join('user u', 't.to_user_id = u.id')
  1100. ->group('o.id')
  1101. ->column('o.id');
  1102. if ($orders) {
  1103. $map[] = ['o.id', 'in', $orders];
  1104. }
  1105. else {
  1106. $map[] = ['o.id', '=', 0];
  1107. }
  1108. }
  1109. $map = empty($map) ? true : $map;
  1110. //数据查询
  1111. $lists = db($this->table)->alias('o')
  1112. ->join('order_convey oc', 'oc.order_id=o.id')
  1113. ->field('o.*,oc.type,oc.start,oc.end,oc.xq_time,oc.ywc_time,oc.device_id,oc.name,oc.phone,oc.priority')
  1114. ->where($map)
  1115. ->order(['o.order_mode' => 'asc', 'oc.xq_time' => 'desc'])
  1116. ->select();
  1117. $newret = [];
  1118. foreach ($lists as $k => $v) {
  1119. $v = $this->model->formatOrder($v);
  1120. $todo = Db::name('todo')
  1121. ->alias('t')
  1122. ->where('t.order_id', $v['id'])
  1123. ->join('user u', 'u.id = t.to_user_id')
  1124. ->where('t.todo_mode', 'in', [1, 2, 3, 4])
  1125. ->where('t.del', 0)
  1126. ->field('u.real_name,t.create_time,t.confirm_time')
  1127. ->order('t.id asc')
  1128. ->select();
  1129. $users = [];
  1130. $confirmtime = '';
  1131. foreach ($todo as $kk => $vv) {
  1132. $users[] = $vv['real_name'];
  1133. if (!$confirmtime && $vv['confirm_time']) {
  1134. $confirmtime = $vv['confirm_time'];
  1135. }
  1136. else {
  1137. if ($confirmtime && $vv['confirm_time'] && $vv['confirm_time'] < $confirmtime) {
  1138. $confirmtime = $vv['confirm_time'];
  1139. }
  1140. }
  1141. }
  1142. $v['real_names'] = implode(',', $users);
  1143. $v['confirm_time'] = $confirmtime;
  1144. $last = strtotime($v['ywc_time']) - time();
  1145. $v['last_time'] = $last > 0 ? round($last / 60) : 0;
  1146. //是否有延时
  1147. $v['delay'] = 0; // 0=未延迟 1=延迟
  1148. $v['delay_diff'] = 0;
  1149. $v['delay_reason'] = '';
  1150. $delays = Db::name('order_delay')
  1151. ->where('order_id', $v['id'])
  1152. ->select();
  1153. $delays = $delays ? $delays : [];
  1154. foreach ($delays as $vv) {
  1155. if ($vv['status'] == 0) {
  1156. $v['delay'] = 1;
  1157. $v['delay_reason'] = $this->gettablefield('delay_reason', ['id' => $vv['delay_reason_id']], 'title');
  1158. $vv['diff'] = time() - strtotime($vv['start_time']);
  1159. }
  1160. $v['delay_diff'] += $vv['diff'];
  1161. }
  1162. $v['delay_diff'] = round($v['delay_diff'] / 60);
  1163. if ($v['delay'] == 1) {
  1164. $v['status'] = 3;
  1165. } else {
  1166. if ($v['order_mode'] == 1) {
  1167. $v['status'] = 1;
  1168. } else {
  1169. $v['status'] = 2;
  1170. }
  1171. }
  1172. $convey = Db::name('convey_cate')
  1173. ->alias('oc')
  1174. ->join('time ot', 'ot.id = oc.time_id')
  1175. ->where('oc.id', $v['type'])
  1176. ->field('ot.*')
  1177. ->find();
  1178. $createtime = strtotime($v['create_time']);
  1179. $curtime = time();
  1180. $ct = round(($curtime - $createtime) / 60);
  1181. if ($ct < $convey['yy_time']) {
  1182. $ss = 0;
  1183. }
  1184. else {
  1185. if ($ct >= $convey['yy_time'] && $ct < $convey['bz_time']) {
  1186. $ss = 1;
  1187. }
  1188. else {
  1189. if ($ct >= $convey['bz_time'] && $ct < $convey['jg_time']) {
  1190. $ss = 2;
  1191. }
  1192. else {
  1193. if ($ct >= $convey['jg_time'] && $ct < $convey['wjjg_time']) {
  1194. $ss = 3;
  1195. }
  1196. else {
  1197. $ss = 4;
  1198. }
  1199. }
  1200. }
  1201. }
  1202. $v['ss'] = $ss;
  1203. $v['xtime'] = date('H:i', strtotime($v['xq_time']));
  1204. $v['stime'] = $v['send_time'] ? date('H:i', strtotime($v['send_time'])) : "";
  1205. $v['ctime'] = $v['confirm_time'] ? date('H:i', strtotime($v['confirm_time'])) : "";
  1206. $v['priorityName'] = isset($this->model->priority[$v['priority']])?$this->model->priority[$v['priority']]:'';
  1207. if ($status == 3 && $v['delay'] == 1) { //延时任务
  1208. $newret[] = $v;
  1209. }
  1210. if ($status == 1 && $v['order_mode'] == 1) { //新任务
  1211. $newret[] = $v;
  1212. }
  1213. if ($status == 2 && $v['order_mode'] == 4) { // 进行中
  1214. $newret[] = $v;
  1215. }
  1216. if (!$status || !in_array($status, [1, 2, 3])) {
  1217. $newret[] = $v;
  1218. }
  1219. $lists[$k] = $v;
  1220. }
  1221. if(!empty($newret)){
  1222. $newret = arraySequence($newret,'status');//返回数组中指定的一列
  1223. }
  1224. //数据返回
  1225. $totalCount = count($lists);
  1226. $totalPage = ceil($totalCount / $length);
  1227. $result['page'] = $page;
  1228. $result['total'] = $totalPage;
  1229. $result['records'] = $totalCount;
  1230. $result['rows'] = $newret;
  1231. return json($result);
  1232. }
  1233. else {
  1234. $mode_name = $this->getTableField('work_type_mode', ['id' => $mode], 'name');
  1235. $order_type = (new \app\common\model\ConveyCate())->getList();
  1236. $order_mode = Db::name('order_mode')
  1237. ->select();
  1238. $this->assign('order_type_list', $order_type);
  1239. $this->assign('m_name', $mode_name);
  1240. $this->assign('mode', $mode);
  1241. $this->assign('order_mode_list', $order_mode);
  1242. $this->assign('dispatch_type', check_two_dispatch($this->userId));
  1243. $address = (new \app\common\model\Address())->getListByType(2);
  1244. $this->assign('address', $address);
  1245. $count = Db::name('todo')
  1246. ->where('org_id', $this->orgId)
  1247. ->where('del', 0)
  1248. ->where('work_type_mode', 3)
  1249. ->where('todo_mode', 4)
  1250. ->count();
  1251. $this->assign('count', $count);
  1252. $info = Db::name('config')->where('name','org_order_refresh')
  1253. ->find();
  1254. $orgConfig = Db::name('config_org')
  1255. ->where('config_id',$info['id'])
  1256. ->where('org_id',$this->orgId)
  1257. ->find();
  1258. $value = $orgConfig?$orgConfig['value']:0;
  1259. $this->assign('refresh',$value);
  1260. return $this->fetch();
  1261. }
  1262. }
  1263. //运送员状态
  1264. public function conveystatus($id='') {
  1265. if (request()->isAjax()) {
  1266. //分页参数
  1267. $length = input('rows', 10, 'intval'); //每页条数
  1268. $page = input('page', 1, 'intval'); //第几页
  1269. $start = ($page - 1) * $length; //分页开始位置
  1270. //排序
  1271. $sortRow = input('sidx', 'id', 'trim'); //排序列
  1272. $sort = input('sord', 'desc', 'trim'); //排序方式
  1273. $order = $sortRow . ' ' . $sort;
  1274. $real_name = input('real_name', '');
  1275. $map8 = [];
  1276. if ($real_name) {
  1277. $map8[] = ['real_name', 'like', '%'.$real_name.'%'];
  1278. }
  1279. $user = (new \app\common\model\WorkTypeMode())->getRolesUser(3, $this->orgId);
  1280. $newUser = [];
  1281. foreach ($user as $k => $v) {
  1282. foreach ($v['user'] as $k1 => $v1) {
  1283. $newUser[] = $v1['id'];
  1284. }
  1285. }
  1286. $userIds1 = [];
  1287. if($id){
  1288. $ids = explode(',', $id);
  1289. $map[] = ['order_id', 'in', $ids];
  1290. $map[] = ['del', '=', 0];
  1291. $map[] = ['org_id', '=', $this->orgId];
  1292. $map[] = ['work_type_mode', '=', 3];
  1293. $userIds = Db::name('todo')->where($map)->column('to_user_id');
  1294. $userIds1 = $userIds?$userIds:[];
  1295. $newUser = array_intersect($userIds1,$newUser);
  1296. }
  1297. if(empty($newUser)){
  1298. $map8[] = ['id','=',0];
  1299. }else{
  1300. $map8[] = ['id','in',$newUser];
  1301. }
  1302. $lists = db('user')
  1303. ->where($map8)->limit($start, $length)
  1304. ->order($order)->select();
  1305. foreach ($lists as $key => $value) {
  1306. $nums = Db::name('todo')
  1307. ->where(['to_user_id' => $value['id'], 'work_type_mode' => 3])
  1308. ->where('create_yyyymmdd', date('ymd'))
  1309. ->where('todo_mode', 'in', [1, 2, 3])
  1310. ->count();
  1311. $lists[$key]['nums'] = $nums;
  1312. $addr = Db::name('convey_plan_record')
  1313. ->alias('cpr')
  1314. ->join('address ca', 'ca.id = cpr.addr_id')
  1315. ->field('ca.title,cpr.create_time')
  1316. ->where('cpr.user_id', $value['id'])
  1317. ->order('cpr.id desc')
  1318. ->find();
  1319. $lists[$key]['title'] = $addr ? $addr['title'] : '';
  1320. $lists[$key]['addr_time'] = $addr ? $addr['create_time'] : '';
  1321. $lists[$key]['worktxt'] = $value['work'] == 1 ? '上班' : '下班';
  1322. $lists[$key]['stationtxt'] = $value['station'] == 1 ? '驻守' : '取消驻守';
  1323. }
  1324. //数据返回
  1325. // $totalCount = db('user')
  1326. // ->where($map1)->count();
  1327. $totalCount = db('user')
  1328. ->where($map8)->count();
  1329. $totalPage = ceil($totalCount / $length);
  1330. $result['page'] = $page;
  1331. $result['total'] = $totalPage;
  1332. $result['records'] = $totalCount;
  1333. $result['rows'] = $lists;
  1334. return json($result);
  1335. }
  1336. else {
  1337. $this->assign('id', $id);
  1338. return $this->fetch();
  1339. }
  1340. }
  1341. //上下班
  1342. public function work($id) {
  1343. $user = Db::name('user')
  1344. ->where('id', $id)
  1345. ->find();
  1346. $value = $user['work'] == 1 ? 0 : 1;
  1347. $res = Db::name('user')
  1348. ->where('id', $id)
  1349. ->update(['work' => $value, 'update_time' => getTime()]);
  1350. $res ? $this->success('操作成功') : $this->error('操作失败');
  1351. }
  1352. //驻守
  1353. public function station($id) {
  1354. $user = Db::name('user')
  1355. ->where('id', $id)
  1356. ->find();
  1357. $value = $user['station'] == 1 ? 0 : 1;
  1358. $res = Db::name('user')
  1359. ->where('id', $id)
  1360. ->update(['station' => $value, 'update_time' => getTime()]);
  1361. $res ? $this->success('操作成功') : $this->error('操作失败');
  1362. }
  1363. //驳回工单列表
  1364. public function bhTodoList() {
  1365. if (request()->isAjax()) {
  1366. $length = input('rows', 10, 'intval'); //每页条数
  1367. $page = input('page', 1, 'intval'); //第几页
  1368. $start = ($page - 1) * $length; //分页开始位置
  1369. $map[] = ['todo.org_id', '=', $this->orgId];
  1370. $map[] = ['todo.del', '=', 0];
  1371. $map[] = ['todo.todo_mode', '=', 4];
  1372. $map[] = ['todo.work_type_mode', '=', 3];
  1373. $totalCount = Db::name('todo')
  1374. ->alias('todo')
  1375. ->join('orders orders', 'orders.id = todo.order_id')
  1376. ->join('order_convey oc', 'oc.order_id = orders.id')
  1377. ->join('user u', 'u.id = todo.to_user_id')
  1378. ->where($map)
  1379. ->count();
  1380. $totalPage = ceil($totalCount / $length);
  1381. $ret = Db::name('todo')
  1382. ->alias('todo')
  1383. ->join('orders orders', 'orders.id = todo.order_id')
  1384. ->join('order_convey oc', 'oc.order_id = orders.id')
  1385. ->join('user u', 'u.id = todo.to_user_id')
  1386. ->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')
  1387. ->order('oc.xq_time', 'desc')
  1388. ->where($map)
  1389. ->limit($start, $length)
  1390. ->select();
  1391. foreach ($ret as $k => $v) {
  1392. $ret[$k]['start_name'] = $this->gettablefield('address', array('id' => $v['start']), 'title');
  1393. $ret[$k]['end_name'] = $this->gettablefield('address', array('id' => $v['end']), 'title');
  1394. $ret[$k]['type_name'] = $this->gettablefield('convey_cate', array('id' => $v['type']), 'title');
  1395. $ret[$k]['real_name'] = $this->gettablefield('user', array('id' => $v['user_id']), 'real_name');
  1396. $ret[$k]['device_name'] = '';
  1397. if ($v['device_id'] > 0) {
  1398. $ret[$k]['device_name'] = $this->gettablefield('convey_device', array('id' => $v['device_id']), 'title');
  1399. }
  1400. $last = strtotime($v['ywc_time']) - time();
  1401. $ret[$k]['last_time'] = $last > 0 ? round($last / 60) : 0;
  1402. $ret[$k]['reject_time'] = $v['reject_time'] ? date('Y-m-d h:i', strtotime($v['reject_time'])) : '';
  1403. }
  1404. $result['page'] = $page;
  1405. $result['total'] = $totalPage;
  1406. $result['records'] = $totalCount;
  1407. $result['rows'] = $ret;
  1408. return json($result);
  1409. }
  1410. else {
  1411. return $this->fetch();
  1412. }
  1413. }
  1414. //excel导出
  1415. public function export($mode) {
  1416. $meta_title = '订单列表';
  1417. if ($mode == 1) {
  1418. $meta_title = '报修' . $meta_title;
  1419. }
  1420. elseif ($mode == 2) {
  1421. $meta_title = '保洁' . $meta_title;
  1422. }
  1423. elseif ($mode == 3) {
  1424. $meta_title = '运送' . $meta_title;
  1425. }
  1426. elseif ($mode == 4) {
  1427. $meta_title = '安保' . $meta_title;
  1428. }
  1429. elseif ($mode == 15) {
  1430. $meta_title = '品质整改' . $meta_title;
  1431. }elseif ($mode == -1) {
  1432. $meta_title = '一键呼叫' . $meta_title;
  1433. }
  1434. $level1 = check_is_dispatch($this->userId);
  1435. $level2 = check_two_dispatch($this->userId);
  1436. $turnoff = two_dispatch_off($this->orgId);
  1437. $quality_type = input('quality_type','');
  1438. if (request()->isGet()) {
  1439. //排序
  1440. $sortRow = input('sidx', 'id', 'trim'); //排序列
  1441. $sort = input('sord', 'desc', 'trim'); //排序方式
  1442. $order = $sortRow . ' ' . $sort;
  1443. $content = input('content', '', 'trim');
  1444. if ($content) {
  1445. $map[] = ['content', 'like', '%' . $content . '%'];
  1446. }
  1447. $dep_id = input('dep_id', '', 'trim');
  1448. if ($dep_id != '') {
  1449. $map[] = ['dep_id', '=', $dep_id];
  1450. }
  1451. $order_mode = input('order_mode', '', 'trim');
  1452. $map6 = [];
  1453. if ($order_mode != '') {
  1454. if($level1 && $turnoff && $mode != 15){ // 一级调度且二级调度开关开着,品质整改例外
  1455. if ($order_mode == 1) {
  1456. $map[] = ['is_deal', '=', 0];
  1457. }else if ($order_mode == 4) {
  1458. $map6[] = ['is_deal', '=', 1];
  1459. }
  1460. }
  1461. if($order_mode==100){//已挂起
  1462. $gq = Db::name('todo')
  1463. ->where('work_type_mode',1)
  1464. ->where('todo_mode',2)
  1465. ->where('pause',1)
  1466. ->column('order_id');
  1467. if(empty($gq)){
  1468. $map[] = ['id', '=', -1];
  1469. }else{
  1470. $map[] = ['id', 'in', $gq];
  1471. }
  1472. }else{
  1473. $map[] = ['order_mode', '=', $order_mode];
  1474. }
  1475. }
  1476. $b = input('start', '', 'trim');
  1477. $e = input('end', '', 'trim');
  1478. if ($b) {
  1479. $b = date('Ymd', strtotime($b));
  1480. $map[] = ['create_yyyymmdd', '>=', $b];
  1481. }
  1482. if ($e) {
  1483. $e = date('Ymd', strtotime($e));
  1484. $map[] = ['create_yyyymmdd', '<=', $e];
  1485. }
  1486. $map[] = ['del', '=', 0];
  1487. $map[] = ['org_id', '=', $this->orgId];
  1488. if($mode==-1){
  1489. $map[] = ['source_type', '=', 4];
  1490. }
  1491. $type = input('type', '', 'trim');
  1492. $oids = [];
  1493. if ($type != '') {
  1494. $map1[] = ['parent_id', '=', $type];
  1495. $type_id = Db::name('order_type')
  1496. ->where($map1)
  1497. ->where('org_id', $this->orgId)
  1498. ->where('enable', 1)
  1499. ->column('id');
  1500. if (!empty($type_id)) {
  1501. $map3[] = ['type_id', 'in', $type_id];
  1502. $ids = Db::name('order_repair')
  1503. ->where($map3)
  1504. ->column('order_id');
  1505. if (!empty($ids)) {
  1506. $oids = $ids;
  1507. }
  1508. else {
  1509. $oids = [];
  1510. }
  1511. }
  1512. else {
  1513. $oids = [];
  1514. }
  1515. }
  1516. if($level2 && $turnoff){ // 二级调度
  1517. $roles_id = Db::name('user_roles')
  1518. ->where('user_id', $this->userId)
  1519. ->value('roles_id');
  1520. $ids = Db::name('dispatch_log')
  1521. ->where('roles_id', $roles_id)
  1522. ->whereOr('to_user_id', $this->userId)
  1523. ->column('order_id');
  1524. if (empty($ids)) {
  1525. $map[] = ['id', '=', -1];
  1526. } else {
  1527. if($type != ''){
  1528. $oids = array_intersect($oids,$ids);
  1529. if($oids){
  1530. $map[] = ['id', 'in', $oids];
  1531. }else{
  1532. $map[] = ['id', '=', -1];
  1533. }
  1534. }else{
  1535. $map[] = ['id', 'in', $ids];
  1536. }
  1537. }
  1538. }else{
  1539. if($type != ''){
  1540. if($oids){
  1541. $map[] = ['id', 'in', $oids];
  1542. }else{
  1543. $map[] = ['id', '=', 0];
  1544. }
  1545. }
  1546. }
  1547. if($mode == 15){ // 品质检查,单独处理
  1548. $map[] = ['work_type_mode','=',$mode];
  1549. if($quality_type !=''){
  1550. $map[] = ['quality_type','=',$quality_type];
  1551. }
  1552. }else{
  1553. $work_type_mode = input('work_type_mode','','trim');
  1554. if(!is_admin($this->userId)){
  1555. $auth = get_dispatch_auth($this->userId);
  1556. if($auth){
  1557. $map[] = ['work_type_mode', 'in', $auth];
  1558. if($mode > 0){
  1559. $map[] = ['work_type_mode', '=', $mode];
  1560. }else{
  1561. if($work_type_mode!=''){
  1562. $map[] = ['work_type_mode','=',$work_type_mode];
  1563. }
  1564. }
  1565. }else{
  1566. $map[] = ['work_type_mode', '=', -1];
  1567. }
  1568. }else{
  1569. if($mode > 0){
  1570. $map[] = ['work_type_mode', '=', $mode];
  1571. }else{
  1572. if($work_type_mode!=''){
  1573. $map[] = ['work_type_mode','=',$work_type_mode];
  1574. }
  1575. }
  1576. }
  1577. }
  1578. $sn = input('sn', '', 'trim');
  1579. if ($sn) {
  1580. $map[] = ['sn', 'like', '%' . $sn . '%'];
  1581. }
  1582. $from = input('from', '', 'trim');
  1583. if ($from) {
  1584. if($from >3){
  1585. $map[] = ['from','=',0];
  1586. $map[] = ['work_type_mode','=',$from-3];
  1587. }else{
  1588. $map[] = ['from','=',$from];
  1589. }
  1590. }
  1591. $dep_cate = input('dep_cate', '', 'trim');
  1592. if ($dep_cate != '') {
  1593. $depIds = Db::name('dep')
  1594. ->where('org_id',$this->orgId)
  1595. ->where('cate_id',$dep_cate)
  1596. ->where('del',0)
  1597. ->column('id');
  1598. if(!empty($depIds)){
  1599. $map[] = ['dep_id', 'in', $depIds];
  1600. }else{
  1601. $map[] = ['dep_id', '=', -1];
  1602. }
  1603. }
  1604. $map = empty($map) ? true : $map;
  1605. //数据查询
  1606. $lists = db($this->table)->where($map)
  1607. ->whereOr($map6)
  1608. ->order($order)->select();
  1609. foreach ($lists as $k => $v) {
  1610. $lists[$k] = $this->model->formatOrder($v);
  1611. if ($turnoff && $level1 && $v['order_mode'] == 1 && $v['is_deal'] == 1) {
  1612. $lists[$k]['order_mode_text'] = '已派发';
  1613. }
  1614. }
  1615. include_once env('root_path') . '/extend/phpexcel/Classes/PHPExcel.php';
  1616. //实例化PHPExcel类
  1617. $objPHPExcel = new \PHPExcel();
  1618. //激活当前的sheet表
  1619. $objPHPExcel->setActiveSheetIndex(0);
  1620. //设置表格头(即excel表格的第一行)
  1621. if ($mode == 1) {
  1622. $objPHPExcel->setActiveSheetIndex(0)
  1623. ->setCellValue('A1', '编号')
  1624. ->setCellValue('B1', '申请时间')
  1625. ->setCellValue('C1', '内容')
  1626. ->setCellValue('D1', '所在科室/部门')
  1627. ->setCellValue('E1', '报修类型')
  1628. ->setCellValue('F1', '状态')
  1629. ->setCellValue('G1', '紧急程度')
  1630. ->setCellValue('H1', '来源')
  1631. ->setCellValue('I1', '部门分类');
  1632. }
  1633. else {
  1634. if ($mode == 3) {
  1635. $objPHPExcel->setActiveSheetIndex(0)
  1636. ->setCellValue('A1', '编号')
  1637. ->setCellValue('B1', '申请时间')
  1638. ->setCellValue('C1', '始发大厅')
  1639. ->setCellValue('D1', '内容')
  1640. ->setCellValue('E1', '所在科室/部门')
  1641. ->setCellValue('F1', '状态')
  1642. ->setCellValue('G1', '来源')
  1643. ->setCellValue('H1', '部门分类');
  1644. }
  1645. else {
  1646. if($mode==0){
  1647. $objPHPExcel->setActiveSheetIndex(0)
  1648. ->setCellValue('A1', '编号')
  1649. ->setCellValue('B1', '申请时间')
  1650. ->setCellValue('C1', '内容')
  1651. ->setCellValue('D1', '所在科室/部门')
  1652. ->setCellValue('E1', '状态')
  1653. ->setCellValue('F1', '订单类型')
  1654. ->setCellValue('G1', '来源')
  1655. ->setCellValue('H1', '部门分类');
  1656. }else{
  1657. if($mode==15){
  1658. $objPHPExcel->setActiveSheetIndex(0)
  1659. ->setCellValue('A1', '编号')
  1660. ->setCellValue('B1', '申请时间')
  1661. ->setCellValue('C1', '内容')
  1662. ->setCellValue('D1', '所在科室/部门')
  1663. ->setCellValue('E1', '状态')
  1664. ->setCellValue('F1', '来源')
  1665. ->setCellValue('G1', '部门分类')
  1666. ->setCellValue('H1', '整改分类');
  1667. }else{
  1668. $objPHPExcel->setActiveSheetIndex(0)
  1669. ->setCellValue('A1', '编号')
  1670. ->setCellValue('B1', '申请时间')
  1671. ->setCellValue('C1', '内容')
  1672. ->setCellValue('D1', '所在科室/部门')
  1673. ->setCellValue('E1', '状态')
  1674. ->setCellValue('F1', '来源')
  1675. ->setCellValue('G1', '部门分类');
  1676. }
  1677. }
  1678. }
  1679. }
  1680. // 设置表格头水平居中
  1681. $objPHPExcel->setActiveSheetIndex(0)->getStyle('A1')->getAlignment()
  1682. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  1683. $objPHPExcel->setActiveSheetIndex(0)->getStyle('B1')->getAlignment()
  1684. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  1685. $objPHPExcel->setActiveSheetIndex(0)->getStyle('C1')->getAlignment()
  1686. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  1687. $objPHPExcel->setActiveSheetIndex(0)->getStyle('D1')->getAlignment()
  1688. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  1689. $objPHPExcel->setActiveSheetIndex(0)->getStyle('E1')->getAlignment()
  1690. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  1691. $objPHPExcel->setActiveSheetIndex(0)->getStyle('F1')->getAlignment()
  1692. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  1693. $objPHPExcel->setActiveSheetIndex(0)->getStyle('G1')->getAlignment()
  1694. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  1695. $objPHPExcel->setActiveSheetIndex(0)->getStyle('H1')->getAlignment()
  1696. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  1697. //设置列水平居中
  1698. $objPHPExcel->setActiveSheetIndex(0)->getStyle('A')->getAlignment()
  1699. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  1700. $objPHPExcel->setActiveSheetIndex(0)->getStyle('B')->getAlignment()
  1701. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  1702. $objPHPExcel->setActiveSheetIndex(0)->getStyle('C')->getAlignment()
  1703. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  1704. $objPHPExcel->setActiveSheetIndex(0)->getStyle('D')->getAlignment()
  1705. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  1706. $objPHPExcel->setActiveSheetIndex(0)->getStyle('E')->getAlignment()
  1707. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  1708. $objPHPExcel->setActiveSheetIndex(0)->getStyle('F')->getAlignment()
  1709. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  1710. $objPHPExcel->setActiveSheetIndex(0)->getStyle('G')->getAlignment()
  1711. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  1712. $objPHPExcel->setActiveSheetIndex(0)->getStyle('H')->getAlignment()
  1713. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  1714. //设置单元格宽度
  1715. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('A')->setWidth(10);
  1716. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('B')->setWidth(20);
  1717. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('C')->setWidth(20);
  1718. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('D')->setWidth(20);
  1719. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('E')->setWidth(20);
  1720. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('F')->setWidth(50);
  1721. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('G')->setWidth(20);
  1722. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('H')->setWidth(20);
  1723. //循环刚取出来的数组,将数据逐一添加到excel表格。
  1724. if ($mode == 1) {
  1725. for ($i = 0; $i < count($lists); $i++) {
  1726. $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $lists[$i]['sn']);
  1727. $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $lists[$i]['create_time']);
  1728. $objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $lists[$i]['content']);
  1729. $objPHPExcel->getActiveSheet()->setCellValue('D' . ($i + 2), $lists[$i]['dep']);
  1730. $objPHPExcel->getActiveSheet()->setCellValue('E' . ($i + 2), $lists[$i]['order_type']);
  1731. $objPHPExcel->getActiveSheet()->setCellValue('F' . ($i + 2), $lists[$i]['order_mode_text']);
  1732. $objPHPExcel->getActiveSheet()->setCellValue('G' . ($i + 2), $lists[$i]['repair_priority']);
  1733. $objPHPExcel->getActiveSheet()->setCellValue('H' . ($i + 2), $lists[$i]['source_type_text']);
  1734. $objPHPExcel->getActiveSheet()->setCellValue('I' . ($i + 2), $lists[$i]['dep_cate_name']);
  1735. }
  1736. }
  1737. else {
  1738. if ($mode == 3) {
  1739. for ($i = 0; $i < count($lists); $i++) {
  1740. $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $lists[$i]['sn']);
  1741. $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $lists[$i]['create_time']);
  1742. $objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $lists[$i]['start_name']);
  1743. $objPHPExcel->getActiveSheet()->setCellValue('D' . ($i + 2), $lists[$i]['content']);
  1744. $objPHPExcel->getActiveSheet()->setCellValue('E' . ($i + 2), $lists[$i]['dep']);
  1745. $objPHPExcel->getActiveSheet()->setCellValue('F' . ($i + 2), $lists[$i]['order_mode_text']);
  1746. $objPHPExcel->getActiveSheet()->setCellValue('G' . ($i + 2), $lists[$i]['source_type_text']);
  1747. $objPHPExcel->getActiveSheet()->setCellValue('H' . ($i + 2), $lists[$i]['dep_cate_name']);
  1748. }
  1749. }
  1750. else {
  1751. if($mode==0){
  1752. for ($i = 0; $i < count($lists); $i++) {
  1753. $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $lists[$i]['sn']);
  1754. $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $lists[$i]['create_time']);
  1755. $objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $lists[$i]['content']);
  1756. $objPHPExcel->getActiveSheet()->setCellValue('D' . ($i + 2), $lists[$i]['dep']);
  1757. $objPHPExcel->getActiveSheet()->setCellValue('E' . ($i + 2), $lists[$i]['order_mode_text']);
  1758. $objPHPExcel->getActiveSheet()->setCellValue('F' . ($i + 2), $lists[$i]['work_type_mode_text']);
  1759. $objPHPExcel->getActiveSheet()->setCellValue('G' . ($i + 2), $lists[$i]['source_type_text']);
  1760. $objPHPExcel->getActiveSheet()->setCellValue('H' . ($i + 2), $lists[$i]['dep_cate_name']);
  1761. }
  1762. }else{
  1763. if($mode==15){
  1764. for ($i = 0; $i < count($lists); $i++) {
  1765. $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $lists[$i]['sn']);
  1766. $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $lists[$i]['create_time']);
  1767. $objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $lists[$i]['content']);
  1768. $objPHPExcel->getActiveSheet()->setCellValue('D' . ($i + 2), $lists[$i]['dep']);
  1769. $objPHPExcel->getActiveSheet()->setCellValue('E' . ($i + 2), $lists[$i]['order_mode_text']);
  1770. $objPHPExcel->getActiveSheet()->setCellValue('F' . ($i + 2), $lists[$i]['source_type_text']);
  1771. $objPHPExcel->getActiveSheet()->setCellValue('G' . ($i + 2), $lists[$i]['dep_cate_name']);
  1772. $objPHPExcel->getActiveSheet()->setCellValue('H' . ($i + 2), $lists[$i]['quality_cate_name']);
  1773. }
  1774. }else{
  1775. for ($i = 0; $i < count($lists); $i++) {
  1776. $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $lists[$i]['sn']);
  1777. $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $lists[$i]['create_time']);
  1778. $objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $lists[$i]['content']);
  1779. $objPHPExcel->getActiveSheet()->setCellValue('D' . ($i + 2), $lists[$i]['dep']);
  1780. $objPHPExcel->getActiveSheet()->setCellValue('E' . ($i + 2), $lists[$i]['order_mode_text']);
  1781. $objPHPExcel->getActiveSheet()->setCellValue('F' . ($i + 2), $lists[$i]['source_type_text']);
  1782. $objPHPExcel->getActiveSheet()->setCellValue('G' . ($i + 2), $lists[$i]['dep_cate_name']);
  1783. }
  1784. }
  1785. }
  1786. }
  1787. }
  1788. //设置保存的Excel表格名称
  1789. $filename = $meta_title . '_' . date('YmdHis', time()) . '.xls';
  1790. //设置当前激活的sheet表格名称
  1791. $objPHPExcel->getActiveSheet()->setTitle($meta_title);
  1792. //设置浏览器窗口下载表格
  1793. ob_end_clean();
  1794. header("Content-Type: application/force-download");
  1795. header("Content-Type: application/octet-stream");
  1796. header("Content-Type: application/download");
  1797. header('Content-Disposition:inline;filename="' . $filename);
  1798. //生成excel文件
  1799. $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  1800. //下载文件在浏览器窗口
  1801. return $objWriter->save('php://output');
  1802. }
  1803. }
  1804. public function rejectTodoList(){
  1805. $orderId = input('orderId',0);
  1806. if (request()->isAjax()) {
  1807. $length = input('rows', 10, 'intval'); //每页条数
  1808. $page = input('page', 1, 'intval'); //第几页
  1809. $start = ($page - 1) * $length; //分页开始位置
  1810. $map[] = ['org_id','=',$this->orgId];
  1811. $map[] = ['del','=',0];
  1812. $map[] = ['todo_mode','=',4];
  1813. $map[] = ['order_id','=',$orderId];
  1814. $lists = Db::name('todo')
  1815. ->where($map)
  1816. ->limit($start,$length)
  1817. ->order('id desc')
  1818. ->select();
  1819. $workTypeMode = [
  1820. '0'=>'一键呼叫',
  1821. '1'=>'报修',
  1822. '2'=>'保洁',
  1823. '3'=>'运送',
  1824. '4'=>'安保',
  1825. ];
  1826. foreach ($lists as $k=>$v){
  1827. $lists[$k]['to_user_name'] = Db::name('user')->where('id',$v['to_user_id'])->value('real_name');
  1828. $lists[$k]['work_type_mode_text'] = $workTypeMode[$v['work_type_mode']];
  1829. $lists[$k]['todo_mode_in_content'] = Db::name('todo_mode')->where('id',$v['todo_mode'])->value('in_content');
  1830. $lists[$k]['todo_mode_color'] = Db::name('todo_mode')->where('id',$v['todo_mode'])->value('color');
  1831. }
  1832. $totalCount = Db::name('todo')
  1833. ->where($map)
  1834. ->count();
  1835. $totalPage = ceil($totalCount / $length);
  1836. $result['page'] = $page;
  1837. $result['total'] = $totalPage;
  1838. $result['records'] = $totalCount;
  1839. $result['rows'] = $lists;
  1840. return json($result);
  1841. }
  1842. else {
  1843. $this->assign('orderId',$orderId);
  1844. return $this->fetch();
  1845. }
  1846. }
  1847. public function orderRefreshOff(){
  1848. $info = Db::name('config')->where('name','org_order_refresh')
  1849. ->find();
  1850. $orgConfig = Db::name('config_org')
  1851. ->where('config_id',$info['id'])
  1852. ->where('org_id',$this->orgId)
  1853. ->find();
  1854. if($orgConfig){
  1855. $value = $orgConfig['value']==1?0:1;
  1856. $res = Db::name('config_org')
  1857. ->where('config_id',$info['id'])
  1858. ->where('org_id',$this->orgId)
  1859. ->update(['value'=>$value]);
  1860. }else{
  1861. $value = 1;
  1862. $res = Db::name('config_org')
  1863. ->insertGetId([
  1864. 'config_id'=>$info['id'],
  1865. 'org_id'=>$this->orgId,
  1866. 'value'=>$value,
  1867. ]);
  1868. }
  1869. $res?$this->success('操作成功','',['status'=>$value]):$this->error('操作失败');
  1870. }
  1871. }