Orders.php 121 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892
  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,u.mobile,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'].($vv['mobile']?'['.$vv['mobile'].']':'');
  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['starttime'] = '';
  1588. if($v['confirm_time']){ // 如果确认时间不为空
  1589. $todoconvey = Db::name('todo_convey')
  1590. ->alias('a')
  1591. ->join('todo t','t.id = a.todo_id')
  1592. ->where('t.order_id', $v['id'])
  1593. ->field('a.*')
  1594. ->order('a.id asc')
  1595. ->find();
  1596. if($todoconvey){
  1597. $v['starttime'] = date('H:i', strtotime($todoconvey['start_time']));
  1598. }
  1599. }
  1600. $v['priorityName'] = isset($this->model->priority[$v['priority']])?$this->model->priority[$v['priority']]:'';
  1601. if ($status == 3 && $v['delay'] == 1) { //延时任务
  1602. $newret[] = $v;
  1603. $newret1[] = $v;
  1604. }
  1605. if ($status == 1 && $v['order_mode'] == 1) { //新任务
  1606. $newret[] = $v;
  1607. $newret2[] = $v;
  1608. }
  1609. if ($status == 2 && $v['order_mode'] == 4) { // 进行中
  1610. $newret[] = $v;
  1611. $newret3[] = $v;
  1612. }
  1613. if (!$status || !in_array($status, [1, 2, 3])) {
  1614. $newret[] = $v;
  1615. $newret4[] = $v;
  1616. }
  1617. $lists[$k] = $v;
  1618. }
  1619. if(!empty($newret)){
  1620. //$newret = arraySequence($newret,'status');//返回数组中指定的一列
  1621. // $newret1 = $newret1?arraySequence($newret1,'xtime','SORT_DESC'):[];
  1622. // $newret3 = $newret3?arraySequence($newret3,'xtime','SORT_DESC'):[];
  1623. // $newret4 = $newret4?arraySequence($newret4,'xtime','SORT_DESC'):[];
  1624. // $newret = array_merge($newret2,$newret3,$newret4,$newret1);
  1625. $all = [];
  1626. $newret2 = $newret2?arraySequence($newret2,'status'):[];
  1627. $newret3 = $newret3?arraySequence($newret3,'status'):[];
  1628. //$newret4 = $newret4?arraySequence($newret4,'status'):[];
  1629. $newret1 = $newret1?arraySequence($newret1,'status'):[];
  1630. $newret2 = $newret2?arraySequence($newret2,'xtime','SORT_DESC'):[];
  1631. $newret3 = $newret3?arraySequence($newret3,'xtime','SORT_DESC'):[];
  1632. // $newret4 = $newret4?arraySequence($newret4,'xtime','SORT_DESC'):[];
  1633. $newret1 = $newret1?arraySequence($newret1,'xtime','SORT_DESC'):[];
  1634. foreach ($newret2 as $k=>$v){
  1635. $all[] = $v;
  1636. }
  1637. foreach ($newret3 as $k=>$v){
  1638. $all[] = $v;
  1639. }
  1640. foreach ($newret1 as $k=>$v){
  1641. $all[] = $v;
  1642. }
  1643. $a1 = $a2 = $a3 = [];
  1644. foreach ($newret4 as $k=>$v){
  1645. if ($v['status'] == 3) { //延时任务
  1646. $a1[] = $v;
  1647. }
  1648. if ($v['status'] == 1) { //新任务
  1649. $a2[] = $v;
  1650. }
  1651. if ($v['status'] == 2) { // 进行中
  1652. $a3[] = $v;
  1653. }
  1654. }
  1655. $a1 = $a1?arraySequence($a1,'status'):[];
  1656. $a2 = $a2?arraySequence($a2,'status'):[];
  1657. $a3 = $a3?arraySequence($a3,'status'):[];
  1658. $a1 = $a1?arraySequence($a1,'xtime','SORT_DESC'):[];
  1659. $a2 = $a2?arraySequence($a2,'xtime','SORT_DESC'):[];
  1660. $a3 = $a3?arraySequence($a3,'xtime','SORT_DESC'):[];
  1661. // 预约类型-取15分钟后之前的订单
  1662. $curtime15 = $curtime+60*15;
  1663. foreach ($a2 as $k=>$v){
  1664. if($v['priority'] !=4 && $v['xq_time'] < date('Y-m-d H:i:s',$curtime15) ){
  1665. $all[] = $v;
  1666. }
  1667. }
  1668. foreach ($a3 as $k=>$v){
  1669. if($v['priority'] !=4 && $v['xq_time'] < date('Y-m-d H:i:s',$curtime15) ){
  1670. $all[] = $v;
  1671. }
  1672. }
  1673. foreach ($a1 as $k=>$v){
  1674. if($v['priority'] !=4 && $v['xq_time'] < date('Y-m-d H:i:s',$curtime15) ){
  1675. $all[] = $v;
  1676. }
  1677. }
  1678. $newret= $all;
  1679. }
  1680. $sdd[] =['org_id','=',$this->orgId];
  1681. $sdd[] =['del','=',0];
  1682. $sdd[] =['work_type_mode','=',3];
  1683. $sdd[] =['create_yyyymmdd','=',date('Ymd')];
  1684. $dcl = Db::name('orders')
  1685. ->where($sdd)
  1686. ->where('order_mode',1)
  1687. ->count();
  1688. $ypf = Db::name('orders')
  1689. ->where($sdd)
  1690. ->where('order_mode',4)
  1691. ->count();
  1692. $ywc = Db::name('orders')
  1693. ->where($sdd)
  1694. ->where('order_mode','in',[5,6])
  1695. ->count();
  1696. $yqx = Db::name('orders')
  1697. ->where($sdd)
  1698. ->where('order_mode','in',[2,3])
  1699. ->count();
  1700. //数据返回
  1701. $totalCount = count($newret);
  1702. $totalPage = ceil($totalCount / $length);
  1703. $result['dcl'] = $dcl;
  1704. $result['ypf'] = $ypf;
  1705. $result['ywc'] = $ywc;
  1706. $result['yqx'] = $yqx;
  1707. $result['page'] = $page;
  1708. $result['total'] = $totalPage;
  1709. $result['records'] = $totalCount;
  1710. $result['rows'] = $newret;
  1711. return json($result);
  1712. }
  1713. else {
  1714. $mode_name = $this->getTableField('work_type_mode', ['id' => $mode], 'name');
  1715. $order_type = (new \app\common\model\ConveyCate())->getList();
  1716. $order_mode = Db::name('order_mode')
  1717. ->select();
  1718. $this->assign('order_type_list', $order_type);
  1719. $this->assign('m_name', $mode_name);
  1720. $this->assign('mode', $mode);
  1721. $this->assign('order_mode_list', $order_mode);
  1722. $this->assign('dispatch_type', check_two_dispatch($this->userId));
  1723. $address = (new \app\common\model\Address())->getListByType(2);
  1724. $this->assign('address', $address);
  1725. $count = Db::name('todo')
  1726. ->where('org_id', $this->orgId)
  1727. ->where('del', 0)
  1728. ->where('work_type_mode', 3)
  1729. ->where('todo_mode', 4)
  1730. ->count();
  1731. $this->assign('count', $count);
  1732. $info = Db::name('config')->where('name','org_order_refresh')
  1733. ->find();
  1734. $orgConfig = Db::name('config_org')
  1735. ->where('config_id',$info['id'])
  1736. ->where('org_id',$this->orgId)
  1737. ->find();
  1738. $value = $orgConfig?$orgConfig['value']:0;
  1739. $this->assign('refresh',$value);
  1740. $sxJg = (new Config())->getConfig('ys_auto_sx',$this->orgId);
  1741. $this->assign('sxJg',$sxJg?$sxJg:30);
  1742. return $this->fetch();
  1743. }
  1744. }
  1745. public function reminder(){
  1746. $id = input('id/d',0);
  1747. $touserids = Db::name('todo')->where('order_id',$id)->where('todo_mode','in',[1,2])->where('del',0)->column('to_user_id');
  1748. if($touserids){
  1749. $touserids = array_unique($touserids);
  1750. send_jpush($touserids,AppMsg::PUSH_WORKER_ORDER_SEND,'您有订单需要处理');
  1751. }
  1752. $this->success('催单成功');
  1753. }
  1754. //运送员状态
  1755. public function conveystatus($id='') {
  1756. if (request()->isAjax()) {
  1757. //分页参数
  1758. $length = input('rows', 10, 'intval'); //每页条数
  1759. $page = input('page', 1, 'intval'); //第几页
  1760. $start = ($page - 1) * $length; //分页开始位置
  1761. //排序
  1762. $sortRow = input('sidx', 'id', 'trim'); //排序列
  1763. $sort = input('sord', 'desc', 'trim'); //排序方式
  1764. $order = $sortRow . ' ' . $sort;
  1765. $real_name = input('real_name', '');
  1766. $map8 = [];
  1767. if ($real_name) {
  1768. $map8[] = ['real_name', 'like', '%'.$real_name.'%'];
  1769. }
  1770. $work = input('work', '');
  1771. if ($work!='') {
  1772. $map8[] = ['work', '=',$work];
  1773. }
  1774. $user = (new \app\common\model\WorkTypeMode())->getRolesUser(3, $this->orgId);
  1775. $newUser = [];
  1776. foreach ($user as $k => $v) {
  1777. foreach ($v['user'] as $k1 => $v1) {
  1778. $newUser[] = $v1['id'];
  1779. }
  1780. }
  1781. $userIds1 = [];
  1782. if($id){
  1783. $ids = explode(',', $id);
  1784. $map[] = ['order_id', 'in', $ids];
  1785. $map[] = ['del', '=', 0];
  1786. $map[] = ['org_id', '=', $this->orgId];
  1787. $map[] = ['work_type_mode', '=', 3];
  1788. $userIds = Db::name('todo')->where($map)->column('to_user_id');
  1789. $userIds1 = $userIds?$userIds:[];
  1790. $newUser = array_intersect($userIds1,$newUser);
  1791. }
  1792. if(empty($newUser)){
  1793. $map8[] = ['id','=',0];
  1794. }else{
  1795. $map8[] = ['id','in',$newUser];
  1796. }
  1797. $mm = [];
  1798. $group = input('group', '');
  1799. if ($group) {
  1800. $uid = Db::name('user_group_user')
  1801. ->where('group_id',$group)
  1802. ->column('user_id');
  1803. if(!empty($uid)){
  1804. $mm[] = ['id','in',$uid];
  1805. }else{
  1806. $mm[] = ['id','in',[-1]];
  1807. }
  1808. }
  1809. $lists = db('user')
  1810. ->where($mm)
  1811. ->where($map8)
  1812. ->limit($start, $length)
  1813. ->order($order)
  1814. ->select();
  1815. foreach ($lists as $key => $value) {
  1816. $lists[$key]['user_group_title'] = Db::name('user_group')
  1817. ->alias('ug')
  1818. ->join('user_group_user ugu','ugu.group_id=ug.id')
  1819. ->where('ugu.user_id',$value['id'])
  1820. ->value('ug.title');
  1821. $nums = Db::name('todo')
  1822. ->where(['to_user_id' => $value['id'], 'work_type_mode' => 3])
  1823. ->where('create_yyyymmdd', date('Ymd'))
  1824. ->where('todo_mode', 'in', [1, 2, 3])
  1825. ->count();
  1826. $lists[$key]['nums'] = $nums;
  1827. $addr = Db::name('order_convey')
  1828. ->alias('cpr')
  1829. ->join('todo os', 'cpr.order_id = os.order_id')
  1830. ->join('orders ods', 'cpr.order_id = ods.id')
  1831. ->join('address ca', 'ca.id = cpr.start')
  1832. ->join('address cad', 'cad.id = cpr.end')
  1833. ->field('os.todo_mode,ca.title as start_name,cad.title as end_name,os.create_time')
  1834. ->where('os.to_user_id', $value['id'])
  1835. ->where('os.del', 0)
  1836. ->where('ods.del', 0)
  1837. ->order('os.id desc')
  1838. ->find();
  1839. $lists[$key]['title'] = '';
  1840. $lists[$key]['addr_time'] = '';
  1841. if($addr){
  1842. if(in_array($addr['todo_mode'],[1,2])){
  1843. $lists[$key]['title'] = $addr['start_name'];
  1844. }else{
  1845. $lists[$key]['title'] = $addr['end_name'];
  1846. }
  1847. $lists[$key]['addr_time'] = $addr['create_time'];
  1848. }
  1849. $lists[$key]['worktxt'] = $value['work'] == 1 ? '上班' : '下班';
  1850. $lists[$key]['stationtxt'] = $value['station'] == 1 ? '驻守' : '取消驻守';
  1851. }
  1852. //数据返回
  1853. // $totalCount = db('user')
  1854. // ->where($map1)->count();
  1855. $totalCount = db('user')
  1856. ->where($map8)->count();
  1857. $totalPage = ceil($totalCount / $length);
  1858. $result['page'] = $page;
  1859. $result['total'] = $totalPage;
  1860. $result['records'] = $totalCount;
  1861. $result['rows'] = $lists;
  1862. return json($result);
  1863. }
  1864. else {
  1865. $group = model('UserGroup')->getList();
  1866. $this->assign('group', $group);
  1867. $this->assign('id', $id);
  1868. return $this->fetch();
  1869. }
  1870. }
  1871. //上下班
  1872. public function work($id) {
  1873. $user = Db::name('user')
  1874. ->where('id', $id)
  1875. ->find();
  1876. $value = $user['work'] == 1 ? 0 : 1;
  1877. $res = Db::name('user')
  1878. ->where('id', $id)
  1879. ->update(['work' => $value, 'update_time' => getTime()]);
  1880. $res ? $this->success('操作成功') : $this->error('操作失败');
  1881. }
  1882. //驻守
  1883. public function station($id) {
  1884. $user = Db::name('user')
  1885. ->where('id', $id)
  1886. ->find();
  1887. $value = $user['station'] == 1 ? 0 : 1;
  1888. $res = Db::name('user')
  1889. ->where('id', $id)
  1890. ->update(['station' => $value, 'update_time' => getTime()]);
  1891. $res ? $this->success('操作成功') : $this->error('操作失败');
  1892. }
  1893. //驳回工单列表
  1894. public function bhTodoList() {
  1895. if (request()->isAjax()) {
  1896. $length = input('rows', 10, 'intval'); //每页条数
  1897. $page = input('page', 1, 'intval'); //第几页
  1898. $start = ($page - 1) * $length; //分页开始位置
  1899. $map[] = ['todo.org_id', '=', $this->orgId];
  1900. $map[] = ['todo.del', '=', 0];
  1901. $map[] = ['todo.todo_mode', '=', 4];
  1902. $map[] = ['todo.work_type_mode', '=', 3];
  1903. $totalCount = Db::name('todo')
  1904. ->alias('todo')
  1905. ->join('orders orders', 'orders.id = todo.order_id')
  1906. ->join('order_convey oc', 'oc.order_id = orders.id')
  1907. ->join('user u', 'u.id = todo.to_user_id')
  1908. ->where($map)
  1909. ->count();
  1910. $totalPage = ceil($totalCount / $length);
  1911. $ret = Db::name('todo')
  1912. ->alias('todo')
  1913. ->join('orders orders', 'orders.id = todo.order_id')
  1914. ->join('order_convey oc', 'oc.order_id = orders.id')
  1915. ->join('user u', 'u.id = todo.to_user_id')
  1916. ->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')
  1917. ->order('oc.xq_time', 'desc')
  1918. ->where($map)
  1919. ->limit($start, $length)
  1920. ->select();
  1921. foreach ($ret as $k => $v) {
  1922. $ret[$k]['start_name'] = $this->gettablefield('address', array('id' => $v['start']), 'title');
  1923. $ret[$k]['end_name'] = $this->gettablefield('address', array('id' => $v['end']), 'title');
  1924. $ret[$k]['type_name'] = $this->gettablefield('convey_cate', array('id' => $v['type']), 'title');
  1925. $ret[$k]['real_name'] = $this->gettablefield('user', array('id' => $v['user_id']), 'real_name');
  1926. $ret[$k]['device_name'] = '';
  1927. if ($v['device_id'] > 0) {
  1928. $ret[$k]['device_name'] = $this->gettablefield('convey_device', array('id' => $v['device_id']), 'title');
  1929. }
  1930. $last = strtotime($v['ywc_time']) - time();
  1931. $ret[$k]['last_time'] = $last > 0 ? round($last / 60) : 0;
  1932. $ret[$k]['reject_time'] = $v['reject_time'] ? date('Y-m-d h:i', strtotime($v['reject_time'])) : '';
  1933. }
  1934. $result['page'] = $page;
  1935. $result['total'] = $totalPage;
  1936. $result['records'] = $totalCount;
  1937. $result['rows'] = $ret;
  1938. return json($result);
  1939. }
  1940. else {
  1941. return $this->fetch();
  1942. }
  1943. }
  1944. //excel导出
  1945. public function export($mode) {
  1946. set_time_limit(0);
  1947. ini_set("memory_limit", "1024M");
  1948. $meta_title = '订单列表';
  1949. if ($mode == 1) {
  1950. $meta_title = '报修' . $meta_title;
  1951. }
  1952. elseif ($mode == 2) {
  1953. $meta_title = '保洁' . $meta_title;
  1954. }
  1955. elseif ($mode == 3) {
  1956. $meta_title = '运送' . $meta_title;
  1957. }
  1958. elseif ($mode == 4) {
  1959. $meta_title = '应急' . $meta_title;
  1960. }
  1961. elseif ($mode == 15) {
  1962. $meta_title = '品质整改' . $meta_title;
  1963. }elseif ($mode == -1) {
  1964. $meta_title = '一键呼叫' . $meta_title;
  1965. }
  1966. $level1 = check_is_dispatch($this->userId);
  1967. $level2 = check_two_dispatch($this->userId);
  1968. $turnoff = two_dispatch_off($this->orgId);
  1969. $quality_type = input('quality_type','');
  1970. if (request()->isGet()) {
  1971. //排序
  1972. $sortRow = input('sidx', 'a.id', 'trim'); //排序列
  1973. $sort = input('sord', 'desc', 'trim'); //排序方式
  1974. $order = $sortRow . ' ' . $sort;
  1975. $content = input('content', '', 'trim');
  1976. if ($content) {
  1977. $map[] = ['a.content', 'like', '%' . $content . '%'];
  1978. }
  1979. $dep_id = input('dep_id', '', 'trim');
  1980. if ($dep_id != '') {
  1981. $map[] = ['a.dep_id', '=', $dep_id];
  1982. }
  1983. $order_mode = input('order_mode', '', 'trim');
  1984. $map6 = [];
  1985. if ($order_mode != '') {
  1986. if($level1 && $turnoff && $mode != 15){ // 一级调度且二级调度开关开着,品质整改例外
  1987. if ($order_mode == 1) {
  1988. $map[] = ['a.is_deal', '=', 0];
  1989. }else if ($order_mode == 4) {
  1990. $map6[] = ['a.is_deal', '=', 1];
  1991. }
  1992. }
  1993. if($order_mode==100){//已挂起
  1994. $gq = Db::name('todo')
  1995. ->where('work_type_mode',1)
  1996. ->where('todo_mode',2)
  1997. ->where('pause',1)
  1998. ->column('order_id');
  1999. if(empty($gq)){
  2000. $map[] = ['a.id', '=', -1];
  2001. }else{
  2002. $map[] = ['a.id', 'in', $gq];
  2003. }
  2004. }else{
  2005. $map[] = ['a.order_mode', '=', $order_mode];
  2006. }
  2007. }
  2008. $b = input('start', '', 'trim');
  2009. $e = input('end', '', 'trim');
  2010. if ($b) {
  2011. // $b = date('Ymd', strtotime($b));
  2012. // $map[] = ['a.create_yyyymmdd', '>=', $b];
  2013. $map[] = ['a.create_time', '>=', $b];
  2014. }
  2015. if ($e) {
  2016. // $e = date('Ymd', strtotime($e));
  2017. // $map[] = ['a.create_yyyymmdd', '<=', $e];
  2018. $map[] = ['a.create_time', '<=', $e];
  2019. }
  2020. $map[] = ['a.del', '=', 0];
  2021. $map[] = ['a.org_id', '=', $this->orgId];
  2022. if($mode==-1){
  2023. $map[] = ['a.source_type', '=', 4];
  2024. }
  2025. $type = input('type', '', 'trim');
  2026. $oids = [];
  2027. if ($type != '') {
  2028. $map1[] = ['parent_id', '=', $type];
  2029. $type_id = Db::name('order_type')
  2030. ->where($map1)
  2031. ->where('org_id', $this->orgId)
  2032. ->where('enable', 1)
  2033. ->column('id');
  2034. if (!empty($type_id)) {
  2035. $map3[] = ['type_id', 'in', $type_id];
  2036. $ids = Db::name('order_repair')
  2037. ->where($map3)
  2038. ->column('order_id');
  2039. if (!empty($ids)) {
  2040. $oids = $ids;
  2041. }
  2042. else {
  2043. $oids = [];
  2044. }
  2045. }
  2046. else {
  2047. $oids = [];
  2048. }
  2049. }
  2050. $typeName = input('typeName', '', 'trim');
  2051. if ($typeName != '') {
  2052. $map_11[] = ['a.title', 'like', '%'.$typeName.'%'];
  2053. $typeNameId = Db::name('convey_cate')
  2054. ->alias('a')
  2055. ->join('order_convey b','a.id=b.type')
  2056. ->where($map_11)
  2057. ->where('a.org_id', $this->orgId)
  2058. ->where('a.enable', 1)
  2059. ->where('a.del', 0)
  2060. ->column('b.order_id');
  2061. if (!empty($typeNameId)) {
  2062. $map[] = ['a.id', 'in', $typeNameId];
  2063. }
  2064. else {
  2065. $map[] = ['a.id', '=', -1];
  2066. }
  2067. }
  2068. if($level2 && $turnoff){ // 二级调度
  2069. $roles_id = Db::name('user_roles')
  2070. ->where('user_id', $this->userId)
  2071. ->value('roles_id');
  2072. $ids = Db::name('dispatch_log')
  2073. ->where('roles_id', $roles_id)
  2074. ->whereOr('to_user_id', $this->userId)
  2075. ->column('order_id');
  2076. if (empty($ids)) {
  2077. $map[] = ['a.id', '=', -1];
  2078. } else {
  2079. if($type != ''){
  2080. $oids = array_intersect($oids,$ids);
  2081. if($oids){
  2082. $map[] = ['a.id', 'in', $oids];
  2083. }else{
  2084. $map[] = ['a.id', '=', -1];
  2085. }
  2086. }else{
  2087. $map[] = ['a.id', 'in', $ids];
  2088. }
  2089. }
  2090. }else{
  2091. if($type != ''){
  2092. if($oids){
  2093. $map[] = ['a.id', 'in', $oids];
  2094. }else{
  2095. $map[] = ['a.id', '=', 0];
  2096. }
  2097. }
  2098. }
  2099. if($mode == 15){ // 品质检查,单独处理
  2100. $map[] = ['a.work_type_mode','=',$mode];
  2101. if($quality_type !=''){
  2102. $map[] = ['a.quality_type','=',$quality_type];
  2103. }
  2104. }else{
  2105. $work_type_mode = input('work_type_mode','','trim');
  2106. if(!is_admin($this->userId)){
  2107. $auth = get_dispatch_auth($this->userId);
  2108. if($auth){
  2109. $map[] = ['a.work_type_mode', 'in', $auth];
  2110. if($mode > 0){
  2111. $map[] = ['a.work_type_mode', '=', $mode];
  2112. }else{
  2113. if($work_type_mode!=''){
  2114. $map[] = ['a.work_type_mode','=',$work_type_mode];
  2115. }
  2116. }
  2117. }else{
  2118. $map[] = ['a.work_type_mode', '=', -1];
  2119. }
  2120. }else{
  2121. if($mode > 0){
  2122. $map[] = ['a.work_type_mode', '=', $mode];
  2123. }else{
  2124. if($work_type_mode!=''){
  2125. $map[] = ['a.work_type_mode','=',$work_type_mode];
  2126. }
  2127. }
  2128. }
  2129. }
  2130. $sn = input('sn', '', 'trim');
  2131. if ($sn) {
  2132. $map[] = ['a.sn', 'like', '%' . $sn . '%'];
  2133. }
  2134. $from = input('from', '', 'trim');
  2135. if ($from) {
  2136. if($from >3){
  2137. $map[] = ['a.from','=',0];
  2138. $map[] = ['a.work_type_mode','=',$from-3];
  2139. }else{
  2140. $map[] = ['a.from','=',$from];
  2141. }
  2142. }
  2143. $dep_cate = input('dep_cate', '', 'trim');
  2144. if ($dep_cate != '') {
  2145. $depIds = Db::name('dep')
  2146. ->where('org_id',$this->orgId)
  2147. ->where('cate_id',$dep_cate)
  2148. ->where('del',0)
  2149. ->column('id');
  2150. if(!empty($depIds)){
  2151. $map[] = ['a.dep_id', 'in', $depIds];
  2152. }else{
  2153. $map[] = ['a.dep_id', '=', -1];
  2154. }
  2155. }
  2156. $priority = input('priority', '', 'trim');
  2157. if($priority !=''){
  2158. $map[] = ['b.priority', '=',$priority];
  2159. }
  2160. $sddr = input('saddr','','trim');
  2161. if($sddr !=''){
  2162. $map[] = ['b.start','=',$sddr];
  2163. }
  2164. $eddr = input('eaddr','','trim');
  2165. if($eddr !=''){
  2166. $map[] = ['b.end','=',$eddr];
  2167. }
  2168. $toUserName = input('toUserName','','trim');
  2169. if($toUserName !=''){
  2170. $ooids = Db::name('user')
  2171. ->alias('u')
  2172. ->join('todo t','t.to_user_id=u.id')
  2173. ->where('t.del',0)
  2174. ->where('t.org_id',$this->orgId)
  2175. ->where('u.real_name',$toUserName)
  2176. ->column('t.order_id');
  2177. if($ooids){
  2178. $map[] = ['a.id','in',$ooids];
  2179. }else{
  2180. $map[] = ['a.id','=',-1];
  2181. }
  2182. }
  2183. $conveyCateId = input('conveyCateId','','trim');
  2184. if($conveyCateId !=''){
  2185. $typeNameId = Db::name('convey_cate')
  2186. ->alias('a')
  2187. ->join('order_convey b','a.id=b.type')
  2188. ->where('a.org_id', $this->orgId)
  2189. ->where('a.enable', 1)
  2190. ->where('a.del', 0)
  2191. ->where('a.id', $conveyCateId)
  2192. ->column('b.order_id');
  2193. if (!empty($typeNameId)) {
  2194. $map[] = ['a.id', 'in', $typeNameId];
  2195. }else {
  2196. $map[] = ['a.id', '=', -1];
  2197. }
  2198. }
  2199. $map = empty($map) ? true : $map;
  2200. //数据查询
  2201. if($mode==3){
  2202. $lists = db($this->table)->where($map)
  2203. ->alias('a')
  2204. ->leftJoin('order_convey b','a.id=b.order_id')
  2205. ->leftJoin('address ad','b.start=ad.id')
  2206. ->leftJoin('address ade','b.end=ade.id')
  2207. ->leftJoin('convey_cate cc','b.type=cc.id')
  2208. ->leftJoin('convey_device cd','b.device_id=cd.id')
  2209. ->leftJoin('dep dp','a.dep_id=dp.id')
  2210. // ->leftJoin('dep_cate dc','dp.cate_id=dc.id')
  2211. ->leftJoin('order_mode om','a.order_mode=om.id')
  2212. ->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')
  2213. ->whereOr($map6)
  2214. ->order($order)
  2215. ->select();
  2216. foreach ($lists as $k => $v) {
  2217. // $lists[$k] = $this->model->newFormatOrder($v);
  2218. $lists[$k]['priority'] = isset($this->model->priority[$v['priority']])?$this->model->priority[$v['priority']]:"";
  2219. $lists[$k]['task_priority'] = $v['priority']==3?2:0;
  2220. $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');
  2221. if ($turnoff && $level1 && $v['order_mode'] == 1 && $v['is_deal'] == 1) {
  2222. $lists[$k]['order_mode_text'] = '已派发';
  2223. }
  2224. }
  2225. }else{
  2226. $lists = db($this->table)->where($map)
  2227. ->alias('a')
  2228. ->leftJoin('order_convey b','a.id=b.order_id')
  2229. ->field('a.*,b.priority')
  2230. ->whereOr($map6)
  2231. ->order($order)->select();
  2232. foreach ($lists as $k => $v) {
  2233. $lists[$k] = $this->model->newFormatOrder($v);
  2234. $lists[$k]['priority'] = isset($this->model->priority[$v['priority']])?$this->model->priority[$v['priority']]:"";
  2235. if ($turnoff && $level1 && $v['order_mode'] == 1 && $v['is_deal'] == 1) {
  2236. $lists[$k]['order_mode_text'] = '已派发';
  2237. }
  2238. }
  2239. }
  2240. include_once env('root_path') . '/extend/phpexcel/Classes/PHPExcel.php';
  2241. //实例化PHPExcel类
  2242. $objPHPExcel = new \PHPExcel();
  2243. //激活当前的sheet表
  2244. $objPHPExcel->setActiveSheetIndex(0);
  2245. //设置表格头(即excel表格的第一行)
  2246. if ($mode == 1) {
  2247. $objPHPExcel->setActiveSheetIndex(0)
  2248. ->setCellValue('A1', '编号')
  2249. ->setCellValue('B1', '申请时间')
  2250. ->setCellValue('C1', '内容')
  2251. ->setCellValue('D1', '所在科室/部门')
  2252. ->setCellValue('E1', '报修类型')
  2253. ->setCellValue('F1', '状态')
  2254. ->setCellValue('G1', '紧急程度')
  2255. ->setCellValue('H1', '来源')
  2256. ->setCellValue('I1', '物料名称')
  2257. ->setCellValue('J1', '单价')
  2258. ->setCellValue('K1', '数量')
  2259. ->setCellValue('L1', '总价');
  2260. }
  2261. else {
  2262. if ($mode == 3) {
  2263. $objPHPExcel->setActiveSheetIndex(0)
  2264. ->setCellValue('A1', '编号')
  2265. ->setCellValue('B1', '申请时间')
  2266. ->setCellValue('C1', '开始地点')
  2267. ->setCellValue('D1', '结束地点')
  2268. ->setCellValue('E1', '运送类型')
  2269. ->setCellValue('F1', '任务备注')
  2270. ->setCellValue('G1', '所在科室/部门')
  2271. ->setCellValue('H1', '状态')
  2272. ->setCellValue('I1', '来源')
  2273. ->setCellValue('J1', '优先级');
  2274. }
  2275. else {
  2276. if($mode==0){
  2277. $objPHPExcel->setActiveSheetIndex(0)
  2278. ->setCellValue('A1', '编号')
  2279. ->setCellValue('B1', '申请时间')
  2280. ->setCellValue('C1', '内容')
  2281. ->setCellValue('D1', '所在科室/部门')
  2282. ->setCellValue('E1', '状态')
  2283. ->setCellValue('F1', '订单类型')
  2284. ->setCellValue('G1', '来源');
  2285. }else{
  2286. if($mode==15){
  2287. $objPHPExcel->setActiveSheetIndex(0)
  2288. ->setCellValue('A1', '编号')
  2289. ->setCellValue('B1', '申请时间')
  2290. ->setCellValue('C1', '内容')
  2291. ->setCellValue('D1', '所在科室/部门')
  2292. ->setCellValue('E1', '状态')
  2293. ->setCellValue('F1', '来源')
  2294. ->setCellValue('H1', '部门分类');
  2295. }else{
  2296. $objPHPExcel->setActiveSheetIndex(0)
  2297. ->setCellValue('A1', '编号')
  2298. ->setCellValue('B1', '申请时间')
  2299. ->setCellValue('C1', '内容')
  2300. ->setCellValue('D1', '所在科室/部门')
  2301. ->setCellValue('E1', '状态')
  2302. ->setCellValue('F1', '来源');
  2303. }
  2304. }
  2305. }
  2306. }
  2307. // 设置表格头水平居中
  2308. $objPHPExcel->setActiveSheetIndex(0)->getStyle('A1')->getAlignment()
  2309. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2310. $objPHPExcel->setActiveSheetIndex(0)->getStyle('B1')->getAlignment()
  2311. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2312. $objPHPExcel->setActiveSheetIndex(0)->getStyle('C1')->getAlignment()
  2313. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2314. $objPHPExcel->setActiveSheetIndex(0)->getStyle('D1')->getAlignment()
  2315. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2316. $objPHPExcel->setActiveSheetIndex(0)->getStyle('E1')->getAlignment()
  2317. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2318. $objPHPExcel->setActiveSheetIndex(0)->getStyle('F1')->getAlignment()
  2319. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2320. $objPHPExcel->setActiveSheetIndex(0)->getStyle('G1')->getAlignment()
  2321. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2322. $objPHPExcel->setActiveSheetIndex(0)->getStyle('H1')->getAlignment()
  2323. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2324. //设置列水平居中
  2325. $objPHPExcel->setActiveSheetIndex(0)->getStyle('A')->getAlignment()
  2326. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2327. $objPHPExcel->setActiveSheetIndex(0)->getStyle('B')->getAlignment()
  2328. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2329. $objPHPExcel->setActiveSheetIndex(0)->getStyle('C')->getAlignment()
  2330. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2331. $objPHPExcel->setActiveSheetIndex(0)->getStyle('D')->getAlignment()
  2332. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2333. $objPHPExcel->setActiveSheetIndex(0)->getStyle('E')->getAlignment()
  2334. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2335. $objPHPExcel->setActiveSheetIndex(0)->getStyle('F')->getAlignment()
  2336. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2337. $objPHPExcel->setActiveSheetIndex(0)->getStyle('G')->getAlignment()
  2338. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2339. $objPHPExcel->setActiveSheetIndex(0)->getStyle('H')->getAlignment()
  2340. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2341. //设置单元格宽度
  2342. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('A')->setWidth(10);
  2343. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('B')->setWidth(20);
  2344. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('C')->setWidth(20);
  2345. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('D')->setWidth(20);
  2346. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('E')->setWidth(20);
  2347. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('F')->setWidth(50);
  2348. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('G')->setWidth(20);
  2349. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('H')->setWidth(20);
  2350. //循环刚取出来的数组,将数据逐一添加到excel表格。
  2351. if ($mode == 1) {
  2352. // halt($lists);
  2353. for ($i = 0; $i < count($lists); $i++) {
  2354. $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $lists[$i]['sn']);
  2355. $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $lists[$i]['create_time']);
  2356. $objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $lists[$i]['content']);
  2357. $objPHPExcel->getActiveSheet()->setCellValue('D' . ($i + 2), $lists[$i]['dep']);
  2358. $objPHPExcel->getActiveSheet()->setCellValue('E' . ($i + 2), $lists[$i]['order_type']);
  2359. $objPHPExcel->getActiveSheet()->setCellValue('F' . ($i + 2), $lists[$i]['order_mode_text']);
  2360. $objPHPExcel->getActiveSheet()->setCellValue('G' . ($i + 2), $lists[$i]['repair_priority']);
  2361. $objPHPExcel->getActiveSheet()->setCellValue('H' . ($i + 2), $lists[$i]['source_type_text']);
  2362. $goodsName = $goodsPrice = $goodsNum = $goodsTotal = '';
  2363. if(empty($lists[$i]['cons'])){
  2364. $objPHPExcel->getActiveSheet()->setCellValue('I' . ($i + 2), "");
  2365. $objPHPExcel->getActiveSheet()->setCellValue('J' . ($i + 2), "");
  2366. $objPHPExcel->getActiveSheet()->setCellValue('K' . ($i + 2), "");
  2367. $objPHPExcel->getActiveSheet()->setCellValue('L' . ($i + 2), "");
  2368. }else{
  2369. $objPHPExcel->getActiveSheet()->getStyle('I'.($i + 2))->getAlignment()->setWrapText(true);
  2370. $objPHPExcel->getActiveSheet()->getStyle('J'.($i + 2))->getAlignment()->setWrapText(true);
  2371. $objPHPExcel->getActiveSheet()->getStyle('K'.($i + 2))->getAlignment()->setWrapText(true);
  2372. $objPHPExcel->getActiveSheet()->getStyle('L'.($i + 2))->getAlignment()->setWrapText(true);
  2373. foreach ($lists[$i]['cons'] as $kk=>$vv){
  2374. // $consstr[] = $vv['title'].'_'.$vv['total'].'_'.$vv['money']."_".$vv['total_money']."_".$vv['realName'];
  2375. $goodsName.= $vv['title']."\r\n";
  2376. $goodsPrice.= $vv['money']."\r\n";
  2377. $goodsNum.= $vv['total']."\r\n";
  2378. $goodsTotal.= $vv['total_money']."\r\n";
  2379. }
  2380. $objPHPExcel->getActiveSheet()->setCellValue('I' . ($i + 2), $goodsName);
  2381. $objPHPExcel->getActiveSheet()->setCellValue('J' . ($i + 2), $goodsPrice);
  2382. $objPHPExcel->getActiveSheet()->setCellValue('K' . ($i + 2), $goodsNum);
  2383. $objPHPExcel->getActiveSheet()->setCellValue('L' . ($i + 2), $goodsTotal);
  2384. }
  2385. }
  2386. }
  2387. else {
  2388. if ($mode == 3) {
  2389. for ($i = 0; $i < count($lists); $i++) {
  2390. $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $lists[$i]['sn']);
  2391. $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $lists[$i]['create_time']);
  2392. $objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $lists[$i]['start_name']);
  2393. $objPHPExcel->getActiveSheet()->setCellValue('D' . ($i + 2), $lists[$i]['end_name']);
  2394. $objPHPExcel->getActiveSheet()->setCellValue('E' . ($i + 2), $lists[$i]['type_name']);
  2395. $objPHPExcel->getActiveSheet()->setCellValue('F' . ($i + 2), $lists[$i]['content']);
  2396. $objPHPExcel->getActiveSheet()->setCellValue('G' . ($i + 2), $lists[$i]['dep']);
  2397. $objPHPExcel->getActiveSheet()->setCellValue('H' . ($i + 2), $lists[$i]['order_mode_text']);
  2398. $objPHPExcel->getActiveSheet()->setCellValue('I' . ($i + 2), $lists[$i]['source_type_text']);
  2399. $objPHPExcel->getActiveSheet()->setCellValue('J' . ($i + 2), $lists[$i]['priority']);
  2400. }
  2401. }
  2402. else {
  2403. if($mode==0){
  2404. for ($i = 0; $i < count($lists); $i++) {
  2405. $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $lists[$i]['sn']);
  2406. $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $lists[$i]['create_time']);
  2407. $objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $lists[$i]['content']);
  2408. $objPHPExcel->getActiveSheet()->setCellValue('D' . ($i + 2), $lists[$i]['dep']);
  2409. $objPHPExcel->getActiveSheet()->setCellValue('E' . ($i + 2), $lists[$i]['order_mode_text']);
  2410. $objPHPExcel->getActiveSheet()->setCellValue('F' . ($i + 2), $lists[$i]['work_type_mode_text']);
  2411. $objPHPExcel->getActiveSheet()->setCellValue('G' . ($i + 2), $lists[$i]['source_type_text']);
  2412. }
  2413. }else{
  2414. if($mode==15){
  2415. for ($i = 0; $i < count($lists); $i++) {
  2416. $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $lists[$i]['sn']);
  2417. $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $lists[$i]['create_time']);
  2418. $objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $lists[$i]['content']);
  2419. $objPHPExcel->getActiveSheet()->setCellValue('D' . ($i + 2), $lists[$i]['dep']);
  2420. $objPHPExcel->getActiveSheet()->setCellValue('E' . ($i + 2), $lists[$i]['order_mode_text']);
  2421. $objPHPExcel->getActiveSheet()->setCellValue('F' . ($i + 2), $lists[$i]['source_type_text']);
  2422. $objPHPExcel->getActiveSheet()->setCellValue('G' . ($i + 2), $lists[$i]['quality_cate_name']);
  2423. }
  2424. }else{
  2425. for ($i = 0; $i < count($lists); $i++) {
  2426. $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $lists[$i]['sn']);
  2427. $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $lists[$i]['create_time']);
  2428. $objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $lists[$i]['content']);
  2429. $objPHPExcel->getActiveSheet()->setCellValue('D' . ($i + 2), $lists[$i]['dep']);
  2430. $objPHPExcel->getActiveSheet()->setCellValue('E' . ($i + 2), $lists[$i]['order_mode_text']);
  2431. $objPHPExcel->getActiveSheet()->setCellValue('F' . ($i + 2), $lists[$i]['source_type_text']);
  2432. }
  2433. }
  2434. }
  2435. }
  2436. }
  2437. //设置保存的Excel表格名称
  2438. $filename = $meta_title . '_' . date('YmdHis', time()) . '.xls';
  2439. //设置当前激活的sheet表格名称
  2440. $objPHPExcel->getActiveSheet()->setTitle($meta_title);
  2441. //设置浏览器窗口下载表格
  2442. ob_end_clean();
  2443. header("Content-Type: application/force-download");
  2444. header("Content-Type: application/octet-stream");
  2445. header("Content-Type: application/download");
  2446. header('Content-Disposition:inline;filename="' . $filename);
  2447. //生成excel文件
  2448. $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  2449. //下载文件在浏览器窗口
  2450. return $objWriter->save('php://output');
  2451. }
  2452. }
  2453. public function rejectTodoList(){
  2454. $orderId = input('orderId',0);
  2455. if (request()->isAjax()) {
  2456. $length = input('rows', 10, 'intval'); //每页条数
  2457. $page = input('page', 1, 'intval'); //第几页
  2458. $start = ($page - 1) * $length; //分页开始位置
  2459. $map[] = ['org_id','=',$this->orgId];
  2460. $map[] = ['del','=',0];
  2461. $map[] = ['todo_mode','=',4];
  2462. $map[] = ['order_id','=',$orderId];
  2463. $lists = Db::name('todo')
  2464. ->where($map)
  2465. ->limit($start,$length)
  2466. ->order('id desc')
  2467. ->select();
  2468. $workTypeMode = [
  2469. '0'=>'一键呼叫',
  2470. '1'=>'报修',
  2471. '2'=>'保洁',
  2472. '3'=>'运送',
  2473. '4'=>'应急',
  2474. ];
  2475. foreach ($lists as $k=>$v){
  2476. $lists[$k]['to_user_name'] = Db::name('user')->where('id',$v['to_user_id'])->value('real_name');
  2477. $lists[$k]['work_type_mode_text'] = $workTypeMode[$v['work_type_mode']];
  2478. $lists[$k]['todo_mode_in_content'] = Db::name('todo_mode')->where('id',$v['todo_mode'])->value('in_content');
  2479. $lists[$k]['todo_mode_color'] = Db::name('todo_mode')->where('id',$v['todo_mode'])->value('color');
  2480. }
  2481. $totalCount = Db::name('todo')
  2482. ->where($map)
  2483. ->count();
  2484. $totalPage = ceil($totalCount / $length);
  2485. $result['page'] = $page;
  2486. $result['total'] = $totalPage;
  2487. $result['records'] = $totalCount;
  2488. $result['rows'] = $lists;
  2489. return json($result);
  2490. }
  2491. else {
  2492. $this->assign('orderId',$orderId);
  2493. return $this->fetch();
  2494. }
  2495. }
  2496. public function orderRefreshOff(){
  2497. $info = Db::name('config')->where('name','org_order_refresh')
  2498. ->find();
  2499. $orgConfig = Db::name('config_org')
  2500. ->where('config_id',$info['id'])
  2501. ->where('org_id',$this->orgId)
  2502. ->find();
  2503. if($orgConfig){
  2504. $value = $orgConfig['value']==1?0:1;
  2505. $res = Db::name('config_org')
  2506. ->where('config_id',$info['id'])
  2507. ->where('org_id',$this->orgId)
  2508. ->update(['value'=>$value]);
  2509. }else{
  2510. $value = 1;
  2511. $res = Db::name('config_org')
  2512. ->insertGetId([
  2513. 'config_id'=>$info['id'],
  2514. 'org_id'=>$this->orgId,
  2515. 'value'=>$value,
  2516. ]);
  2517. }
  2518. $res?$this->success('操作成功','',['status'=>$value]):$this->error('操作失败');
  2519. }
  2520. public function print1($id){
  2521. $order = Db::name('orders')->where(['id' => $id])->find();
  2522. $depName = Db::name('dep')
  2523. ->where('id',$order['dep_id'])
  2524. ->value('title');
  2525. $info['depName'] = $depName;
  2526. $info['create_time'] = $order['create_time'];
  2527. $users = Db::name('todo')
  2528. ->alias('t')
  2529. ->join('user u','u.id=t.to_user_id')
  2530. ->where('t.order_id',$order['id'])
  2531. ->column('u.real_name');
  2532. $info['users'] = $users?implode(',',$users):'';
  2533. $info['content'] = $order['content'];
  2534. $info['cons'] = [];
  2535. $tList = Db::name('todo')
  2536. ->where('order_id',$order['id'])
  2537. ->select();
  2538. $total = $totalPrice = 0;
  2539. $signs = [];
  2540. foreach ($tList as $k=>$v){
  2541. if($v['sign']){
  2542. $signs[] = $v['sign'];
  2543. }
  2544. $mate = Db::name('todo_mate_item')
  2545. ->alias('tmi')
  2546. ->join('todo_mate tm','tmi.todo_mate_id = tm.id')
  2547. ->join('mate_goods mg','mg.id = tmi.items_id')
  2548. ->field('tmi.items_id,tmi.total,tmi.money,tmi.total_money,mg.title')
  2549. ->where('tm.todo_id',$v['id'])
  2550. ->select();
  2551. if(!empty($mate)){
  2552. foreach ($mate as $kk=>$todo_mate){
  2553. $info['cons'][] = [
  2554. 'title' =>$todo_mate['title'],
  2555. 'total' =>$todo_mate['total'],
  2556. 'money' =>$todo_mate['money'],
  2557. 'total_money' =>$todo_mate['total_money'],
  2558. ];
  2559. $total +=$todo_mate['total'];
  2560. $totalPrice +=$todo_mate['total_money'];
  2561. }
  2562. }
  2563. }
  2564. $aa = [
  2565. 'title'=>'',
  2566. 'total'=>'',
  2567. 'money'=>'',
  2568. 'total_money'=>'',
  2569. ];
  2570. if(empty($info['cons'])){
  2571. for ($i=1;$i<=4;$i++){
  2572. $info['cons'][] = $aa;
  2573. }
  2574. }elseif (count($info['cons']) <4){
  2575. $ii = 4-count($info['cons']);
  2576. for ($i=1;$i<=$ii;$i++){
  2577. $info['cons'][] = $aa;
  2578. }
  2579. }
  2580. $info['total'] = $total;
  2581. $info['totalPrice'] = round($totalPrice,2);
  2582. $info['signs'] = $signs;
  2583. $this->assign('info', $info);
  2584. return $this->fetch();
  2585. }
  2586. public function withdraw(){
  2587. $id = input('id');
  2588. $info = Db::name('orders')
  2589. ->where('id',$id)
  2590. ->where('del',0)
  2591. ->where('order_mode',4)
  2592. ->find();
  2593. if(!$info){
  2594. $this->error('参数错误');
  2595. }
  2596. $saveOrder = Db::name('orders')
  2597. ->where('id',$id)
  2598. ->update(['order_mode'=>1,'withdraw_time'=>getTime()]);
  2599. $saveTodo = Db::name('todo')
  2600. ->where('order_id',$id)
  2601. ->update(['del'=>1]);
  2602. $todoIds = Db::name('todo')
  2603. ->where('order_id',$id)
  2604. ->where('todo_mode',1)
  2605. ->column('id');
  2606. $task = Db::name('task')
  2607. ->where('type',1)
  2608. ->whereIn('bus_id',$todoIds)
  2609. ->delete();
  2610. if($info['work_type_mode'] == 3){
  2611. Db::name('order_convey_end')->where('order_id',$info['id'])->setField('del',0);
  2612. }
  2613. if(!$saveOrder){
  2614. $this->error('操作失败');
  2615. }
  2616. $this->success('操作成功');
  2617. }
  2618. public function autoSend($id,$form=0) {
  2619. if(request()->isGet() && $form==0){
  2620. $order_type = (new \app\common\model\OrderType())->getList();
  2621. $order_repair = Db::name('order_repair')
  2622. ->where('order_id', $id)
  2623. ->find();
  2624. $this->assign('order_repair', $order_repair);
  2625. $this->assign('order_type_list',$order_type);
  2626. $this->assign('id',$id);
  2627. return $this->fetch();
  2628. }else{
  2629. $type_id = input('type_id/d','');
  2630. if(!empty($type_id)){
  2631. $old = Db::name('order_repair')
  2632. ->where('order_id', $id)
  2633. ->find();
  2634. $rData['type_id'] = $type_id;
  2635. if ($old) {
  2636. $rData['update_time'] = getTime();
  2637. Db::name('order_repair')
  2638. ->where('order_id', $id)
  2639. ->update($rData);
  2640. }
  2641. else {
  2642. $rData['order_id'] = $id;
  2643. Db::name('order_repair')
  2644. ->insert($rData);
  2645. }
  2646. }
  2647. $res = $this->model->autoSend($id);
  2648. if (!$res) {
  2649. $this->error($this->model->getError());
  2650. }
  2651. $this->success('操作成功');
  2652. }
  2653. }
  2654. public function setType($id) {
  2655. if(request()->isGet()){
  2656. $order_type = (new \app\common\model\OrderType())->getList();
  2657. $order_repair = Db::name('order_repair')
  2658. ->where('order_id', $id)
  2659. ->find();
  2660. $this->assign('order_repair', $order_repair);
  2661. $this->assign('order_type_list',$order_type);
  2662. $this->assign('id',$id);
  2663. return $this->fetch();
  2664. }else{
  2665. $type_id = input('type_id/d','');
  2666. if(empty($type_id)){
  2667. $this->error('请选择报修事项');
  2668. }
  2669. $old = Db::name('order_repair')
  2670. ->where('order_id', $id)
  2671. ->find();
  2672. $rData['type_id'] = $type_id;
  2673. if ($old) {
  2674. $rData['update_time'] = getTime();
  2675. $r = Db::name('order_repair')
  2676. ->where('order_id', $id)
  2677. ->update($rData);
  2678. }
  2679. else {
  2680. $rData['order_id'] = $id;
  2681. $r = Db::name('order_repair')
  2682. ->insert($rData);
  2683. }
  2684. $r?$this->success('操作成功'):$this->error('操作失败');
  2685. }
  2686. }
  2687. public function batchSb(){
  2688. $id = input('ids',[]);
  2689. if(!$id){
  2690. $this->error('参数错误');
  2691. }
  2692. $res = db('user')->where('id','in',$id)->setField('work',1);
  2693. if($res){
  2694. $this->success('操作成功');
  2695. }else{
  2696. $this->error('操作失败');
  2697. }
  2698. }
  2699. public function batchXb(){
  2700. $id = input('ids',[]);
  2701. if(!$id){
  2702. $this->error('参数错误');
  2703. }
  2704. $res = db('user')->where('id','in',$id)->setField('work',0);
  2705. if($res){
  2706. $this->success('操作成功');
  2707. }else{
  2708. $this->error('操作失败');
  2709. }
  2710. }
  2711. public function getTime(){
  2712. $type = input('type');
  2713. $start = input('start');
  2714. $v = Db::name('convey_cate')
  2715. ->where('id',$type)
  2716. ->where('enable',1)
  2717. ->where('del',0)
  2718. ->find();
  2719. if($v['time_id'] > 0){
  2720. $time = Db::name('time')
  2721. ->where('id',$v['time_id'])
  2722. ->find();
  2723. $v['xq_time'] = $start?$start:date('Y-m-d H:i');
  2724. $v['ywc_time'] = date('Y-m-d H:i',strtotime($v['xq_time']) + 60*$time['bz_time']);
  2725. }else{
  2726. $v['xq_time'] = $start?$start:date('Y-m-d H:i');
  2727. $v['ywc_time'] = '';
  2728. }
  2729. $this->success('','',$v);
  2730. }
  2731. }