Orders.php 120 KB

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