123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892 |
- <?php
- namespace app\admin\controller;
- use app\common\model\Config;
- use app\common\util\AppMsg;
- use Overtrue\Pinyin\Pinyin;
- use think\App;
- use think\Db;
- use think\Exception;
- class Orders extends Auth {
- public function __construct(App $app = null) {
- parent::__construct($app);
- $this->model = new \app\common\model\Orders();
- $this->table = $this->model->table;
- }
- //用户订单列表
- public function selfIndex() {
- $mode = input('mode', 1);
- if (request()->isAjax()) {
- //分页参数
- $length = input('rows', 10, 'intval'); //每页条数
- $page = input('page', 1, 'intval'); //第几页
- $start = ($page - 1) * $length; //分页开始位置
- //排序
- $sortRow = input('sidx', 'a.id', 'trim'); //排序列
- $sort = input('sord', 'desc', 'trim'); //排序方式
- $order = $sortRow . ' ' . $sort;
- $map[] = ['a.del', '=', 0];
- $map[] = ['a.org_id', '=', $this->orgId];
- $order_mode = input('order_mode', '', 'trim');
- if ($order_mode != '') {
- $map[] = ['a.order_mode', '=', $order_mode];
- }
- if($mode >0){
- $map[] = ['a.work_type_mode', '=', $mode];
- }else{
- $map[] = ['a.source_type', '=', 4];
- }
- $sn = input('sn', '', 'trim');
- if ($sn) {
- $map[] = ['a.sn', 'like', '%' . $sn . '%'];
- }
- if (!is_admin($this->userId)) {
- $map[] = ['a.user_id', '=', $this->userId];
- }
- $priority = input('priority', '', 'trim');
- if($priority !=''){
- $map[] = ['b.priority', '=',$priority];
- }
- $map = empty($map) ? true : $map;
- //数据查询
- $lists = db($this->table)
- ->alias('a')
- ->leftJoin('order_convey b','a.id=b.order_id')
- ->where($map)
- ->field('a.*,b.priority')
- ->limit($start, $length)
- ->order($order)
- ->select();
- foreach ($lists as $k => $v) {
- $lists[$k] = $this->model->formatOrder($v);
- $lists[$k]['priority'] = isset($this->model->priority[$v['priority']])?$this->model->priority[$v['priority']]:"";
- }
- //数据返回
- $totalCount = db($this->table)
- ->alias('a')
- ->leftJoin('order_convey b','a.id=b.order_id')
- ->where($map)->count();
- $totalPage = ceil($totalCount / $length);
- $result['page'] = $page;
- $result['total'] = $totalPage;
- $result['records'] = $totalCount;
- $result['rows'] = $lists;
- return json($result);
- }
- else {
- $mode_name = $this->getTableField('work_type_mode', ['id' => $mode], 'name');
- if($mode==4){
- $mode_name = '应急';
- }
- $this->assign('m_name', $mode_name);
- $this->assign('mode', $mode);
- $this->assign('priority', model("Orders")->priority);
- $order_mode = Db::name('order_mode')->select();
- $this->assign('order_mode_list', $order_mode);
- $tsDh = model('Config')->getConfig('org_config_ts',$this->orgId);
- $this->assign('tsDh',$tsDh);
- if ($mode == 1) {
- return $this->fetch('selfIndex1');
- }
- else {
- if ($mode == 3) {
- return $this->fetch('selfIndex3');
- }
- else {
- return $this->fetch('selfIndex');
- }
- }
- }
- }
- //用户添加订单
- public function selfAdd($mode = 1) {
- if (request()->isPost()) {
- $data = request()->post();
- $data['user_id'] = $this->userId;
- $data['org_id'] = $this->orgId;
- $data['work_type_mode'] = $mode;
- $data['images'] = isset($data['images']) && !empty($data['images']) ? implode(',', $data['images']) : '';
- $res = $this->model->addSave($data);
- if ($res) {
- $this->success('操作成功');
- }
- else {
- $this->error($this->model->getError());
- }
- }
- else {
- $dep = $this->getTableField('user_dep', ['user_id' => $this->userId], 'dep_id');
- $depList = (new \app\common\model\Dep())->getList();
- $this->assign('dep_id', $dep);
- $this->assign('dep_list', $depList);
- $this->assign('mode', $mode);
- if ($mode == 3) {
- $address = (new \app\common\model\Address())->getListByType(2);
- $conveyCate = (new \app\common\model\ConveyCate());
- $priority = $conveyCate->priority;
- $order_convey = $conveyCate->getList();
- $order_device = (new \app\common\model\ConveyDevice())->getList();
- $this->assign('address', $address);
- $this->assign('priority', $priority);
- $this->assign('order_convey_type', $order_convey);
- $this->assign('order_device', $order_device);
- }
- $user = Db::name('user')
- ->where('id',$this->userId)
- ->find();
- $this->assign('user',$user);
- $tsDh = model('Config')->getConfig('org_config_ts',$this->orgId);
- $this->assign('tsDh',$tsDh);
- if ($mode == 3) {
- return $this->fetch('self_add3');
- }
- else {
- return $this->fetch('self_add');
- }
- }
- }
- public function getAddr(){
- $id = input('id/d',0);
- $info = Db::name('convey_cate')
- ->where('id',$id)
- ->find();
- if(!empty($info['starts'])){
- $st = explode(',',$info['starts']);
- $s = (new \app\common\model\Address())->getListByTypes($st,2);
- }else{
- $s = (new \app\common\model\Address())->getListByType(2);
- }
- if(!empty($info['ends'])){
- $ent = explode(',',$info['ends']);
- $en = (new \app\common\model\Address())->getListByTypes($ent,2);
- }else{
- $en = (new \app\common\model\Address())->getListByType(2);
- }
- $a = [
- 's'=>$s,
- 'e'=>$en,
- ];
- $this->success('','',$a);
- }
- //用户取消订单
- public function cancel($id) {
- $res = $this->model->cancel($id, $this->userId);
- if (!$res) {
- $this->error($this->model->getError());
- }
- $this->success('取消成功');
- }
- //调度取消订单
- public function disCancel($id) {
- if (request()->isGet()) {
- $this->assign('id', $id);
- return $this->fetch();
- }
- else {
- $reason = input('cancel_reason');
- $res = $this->model->cancel($id, $this->userId, 2, $reason);
- if (!$res) {
- $this->error($this->model->getError());
- }
- $this->success('取消成功');
- }
- }
- //延迟订单
- public function batchdelay($id) {
- if (request()->isGet()) {
- $delay_reason = Db::name('delay_reason')
- ->where('org_id', $this->orgId)
- ->where('enable', 1)
- ->where('del', 0)
- ->select();
- $this->assign('delay_reason', $delay_reason);
- $this->assign('id', $id);
- return $this->fetch();
- }
- else {
- $delay_reason_id = input('delay_reason_id');
- if (empty($delay_reason_id)) {
- $this->error('请选择延迟原因');
- }
- $res = $this->model->delay_reason($id, $delay_reason_id);
- if (!$res) {
- $this->error($this->model->getError());
- }
- $this->success('延迟成功');
- }
- }
- //取消延迟订单
- public function batchcanceldelay($id) {
- if (request()->isGet()) {
- $this->assign('id', $id);
- return $this->fetch();
- }
- else {
- $res = $this->model->batchcanceldelay($id);
- if (!$res) {
- $this->error($this->model->getError());
- }
- $this->success('延迟成功');
- }
- }
- //用户查看订单详情
- public function detail($id) {
- if (!$id) {
- $this->error('参数错误');
- }
- $order = Db::name('orders')->where(['id' => $id])->find();
- $order = $this->model->formatOrder($order, 1);
- $order['images'] = !empty($order['images']) ? explode(',', $order['images']) : '';
- if($order['work_type_mode'] == 3){
- // 地点路径
- $conveyends = Db::name('order_convey_end')
- ->alias('a')
- ->join('address b','b.id = a.addr')
- ->where('a.order_id',$id)
- ->order('a.id asc')
- ->field('a.*,b.title')
- ->select();
- $order['ends'] = $conveyends?$conveyends:[];
- }
- $this->assign('info', $order);
- $workTypeName = $this->getTableField('work_type_mode', ['id' => $order['work_type_mode']], 'name');
- $this->assign('meta_title', $workTypeName . '订单详情');
- return $this->fetch();
- }
- //调度订单列表
- public function index() {
- $mode = input('mode', 0);
- $quality_type = input('quality_type','');
- $level1 = check_is_dispatch($this->userId);
- $level2 = check_two_dispatch($this->userId);
- $turnoff = two_dispatch_off($this->orgId);
- if (request()->isAjax()) {
- //分页参数
- $length = input('rows', 10, 'intval'); //每页条数
- $page = input('page', 1, 'intval'); //第几页
- $start = ($page - 1) * $length; //分页开始位置
- //排序
- $sortRow = input('sidx', 'a.id', 'trim'); //排序列
- $sort = input('sord', 'desc', 'trim'); //排序方式
- $order = $sortRow . ' ' . $sort;
- $content = input('content', '', 'trim');
- if ($content) {
- $map[] = ['a.content', 'like', '%' . $content . '%'];
- }
- $dep_id = input('dep_id', '', 'trim');
- if ($dep_id != '') {
- $map[] = ['a.dep_id', '=', $dep_id];
- }
- $dep_cate = input('dep_cate', '', 'trim');
- if ($dep_cate != '') {
- $depIds = Db::name('dep')
- ->where('org_id',$this->orgId)
- ->where('cate_id',$dep_cate)
- ->where('del',0)
- ->column('id');
- if(!empty($depIds)){
- $map[] = ['a.dep_id', 'in', $depIds];
- }else{
- $map[] = ['a.dep_id', '=', -1];
- }
- }
- $order_mode = input('order_mode', '', 'trim');
- $map6 = [];
- if ($order_mode != '') {
- if($level1 && $turnoff && $mode != 15){ // 一级调度且二级调度开关开着,品质整改例外
- if ($order_mode == 1) {
- $map[] = ['a.is_deal', '=', 0];
- }else if ($order_mode == 4) {
- $map6[] = ['a.is_deal', '=', 1];
- }
- }
- if($order_mode==100){//已挂起
- $gq = Db::name('todo')
- ->where('work_type_mode',1)
- ->where('todo_mode',2)
- ->where('pause',1)
- ->column('order_id');
- if(empty($gq)){
- $map[] = ['a.id', '=', -1];
- }else{
- $map[] = ['a.id', 'in', $gq];
- }
- }else{
- $map[] = ['a.order_mode', '=', $order_mode];
- }
- }
- $b = input('start', '', 'trim');
- $e = input('end', '', 'trim');
- if ($b) {
- // $b = date('Ymd', strtotime($b));
- // $map[] = ['a.create_yyyymmdd', '>=', $b];
- $map[] = ['a.create_time', '>=', $b];
- }
- if ($e) {
- // $e = date('Ymd', strtotime($e));
- // $map[] = ['a.create_yyyymmdd', '<=', $e];
- $map[] = ['a.create_time', '<=', $e];
- }
- $map[] = ['a.del', '=', 0];
- $map[] = ['a.org_id', '=', $this->orgId];
- if($mode==-1){
- $map[] = ['a.source_type', '=', 4];
- }
- $type = input('type', '', 'trim');
- $oids = [];
- if ($type != '') {
- $map1[] = ['parent_id', '=', $type];
- $type_id = Db::name('order_type')
- ->where($map1)
- ->where('org_id', $this->orgId)
- ->where('enable', 1)
- ->column('id');
- if (!empty($type_id)) {
- $map3[] = ['type_id', 'in', $type_id];
- $ids = Db::name('order_repair')
- ->where($map3)
- ->column('order_id');
- if (!empty($ids)) {
- $oids = $ids;
- }
- else {
- $oids = [];
- }
- }
- else {
- $oids = [];
- }
- }
- $typeName = input('typeName', '', 'trim');
- if ($typeName != '') {
- $map_11[] = ['a.title', 'like', '%'.$typeName.'%'];
- $typeNameId = Db::name('convey_cate')
- ->alias('a')
- ->join('order_convey b','a.id=b.type')
- ->where($map_11)
- ->where('a.org_id', $this->orgId)
- ->where('a.enable', 1)
- ->where('a.del', 0)
- ->column('b.order_id');
- if (!empty($typeNameId)) {
- $map[] = ['a.id', 'in', $typeNameId];
- }
- else {
- $map[] = ['a.id', '=', -1];
- }
- }
- if($level2 && $turnoff){ // 二级调度
- $roles_id = Db::name('user_roles')
- ->where('user_id', $this->userId)
- ->value('roles_id');
- $ids = Db::name('dispatch_log')
- ->where('roles_id', $roles_id)
- ->whereOr('to_user_id', $this->userId)
- ->column('order_id');
- if (empty($ids)) {
- $map[] = ['a.id', '=', -1];
- } else {
- if($type != ''){
- $oids = array_intersect($oids,$ids);
- if($oids){
- $map[] = ['a.id', 'in', $oids];
- }else{
- $map[] = ['a.id', '=', -1];
- }
- }else{
- $map[] = ['a.id', 'in', $ids];
- }
- }
- }else{
- if($type != ''){
- if($oids){
- $map[] = ['a.id', 'in', $oids];
- }else{
- $map[] = ['a.id', '=', 0];
- }
- }
- }
- if($mode == 15){ // 品质检查,单独处理
- $map[] = ['a.work_type_mode','=',$mode];
- if($quality_type!=''){
- $map[] = ['a.quality_type','=',$quality_type];
- }
- }else{
- $work_type_mode = input('work_type_mode','','trim');
- if(!is_admin($this->userId)){
- $auth = get_dispatch_auth($this->userId);
- if($auth){
- $map[] = ['a.work_type_mode', 'in', $auth];
- if($mode > 0){
- $map[] = ['a.work_type_mode', '=', $mode];
- }else{
- if($work_type_mode!=''){
- $map[] = ['a.work_type_mode','=',$work_type_mode];
- }
- }
- }else{
- $map[] = ['a.work_type_mode', '=', -1];
- }
- }else{
- if($mode > 0){
- $map[] = ['a.work_type_mode', '=', $mode];
- }else{
- if($work_type_mode!=''){
- $map[] = ['a.work_type_mode','=',$work_type_mode];
- }
- }
- }
- }
- $sn = input('sn', '', 'trim');
- if ($sn) {
- $map[] = ['a.sn', 'like', '%' . $sn . '%'];
- }
- $from = input('from', '', 'trim');
- if ($from) {
- if($from >3){
- $map[] = ['a.from','=',0];
- $map[] = ['a.work_type_mode','=',$from-3];
- }else{
- $map[] = ['a.from','=',$from];
- }
- }
- $priority = input('priority', '', 'trim');
- if($priority !=''){
- $map[] = ['b.priority', '=',$priority];
- }
- $sddr = input('saddr','','trim');
- if($sddr !=''){
- $map[] = ['b.start','=',$sddr];
- }
- $eddr = input('eaddr','','trim');
- if($eddr !=''){
- $map[] = ['b.end','=',$eddr];
- }
- $toUserName = input('toUserName','','trim');
- if($toUserName !=''){
- $ooids = Db::name('user')
- ->alias('u')
- ->join('todo t','t.to_user_id=u.id')
- ->where('t.del',0)
- ->where('t.org_id',$this->orgId)
- ->where('u.real_name',$toUserName)
- ->column('t.order_id');
- if($ooids){
- $map[] = ['a.id','in',$ooids];
- }else{
- $map[] = ['a.id','=',-1];
- }
- }
- $conveyCateId = input('conveyCateId','','trim');
- if($conveyCateId !=''){
- $typeNameId = Db::name('convey_cate')
- ->alias('a')
- ->join('order_convey b','a.id=b.type')
- ->where('a.org_id', $this->orgId)
- ->where('a.enable', 1)
- ->where('a.del', 0)
- ->where('a.id', $conveyCateId)
- ->column('b.order_id');
- if (!empty($typeNameId)) {
- $map[] = ['a.id', 'in', $typeNameId];
- }else {
- $map[] = ['a.id', '=', -1];
- }
- }
- $map = empty($map) ? true : $map;
- //数据查询
- $lists = db($this->table)
- ->where($map)
- ->alias('a')
- ->leftJoin('order_convey b','a.id=b.order_id')
- ->field('a.*,b.priority')
- ->whereOr($map6)
- ->limit($start, $length)
- ->order($order)
- // ->fetchSql()
- ->select();
- // halt($lists);
- foreach ($lists as $k => $v) {
- $lists[$k] = $this->model->formatOrder($v);
- $lists[$k]['priority'] = isset($this->model->priority[$v['priority']])?$this->model->priority[$v['priority']]:"";
- if ($turnoff && $level1 && $v['order_mode'] == 1 && $v['is_deal'] == 1) {
- $lists[$k]['order_mode_text'] = '已派发';
- }
- $lists[$k]['bh_nums'] = Db::name('todo')->where('order_id',$v['id'])->where('del',0)->where('todo_mode',4)->count();
- $gq = Db::name('todo')
- ->where('order_id',$v['id'])
- ->where('work_type_mode',1)
- ->where('todo_mode',2)
- ->where('pause',1)
- ->find();
- $lists[$k]['gq'] = $gq?'存在挂起':'';
- $toUserNames = Db::name('todo')
- ->alias('t')
- ->join('user u','u.id=t.to_user_id')
- ->where('t.order_id',$v['id'])
- ->where('t.del',0)
- ->column('u.real_name');
- $lists[$k]['to_user_names'] = $toUserNames ? implode(',',$toUserNames):'';
- }
- //数据返回
- $totalCount = db($this->table)
- ->alias('a')
- ->leftJoin('order_convey b','a.id=b.order_id')
- ->where($map)->count();
- $totalPage = ceil($totalCount / $length);
- $result['page'] = $page;
- $result['total'] = $totalPage;
- $result['records'] = $totalCount;
- $result['rows'] = $lists;
- return json($result);
- }
- else {
- if($mode >0){
- $mode_name = $this->getTableField('work_type_mode', ['id' => $mode], 'name');
- }else{
- $mode_name = '';
- }
- if($mode==4){
- $mode_name = '应急';
- }
- $auths = [1,2,3,4,15,0];
- if(!is_admin($this->userId)){
- $auth = get_dispatch_auth($this->userId);
- if($auth){
- $auths = array_intersect($auths,$auth);
- if($mode > 0){
- $auths = array_intersect($auths,[$mode]);
- }
- }else{
- $auths = [];
- }
- }
- $this->assign('auths',$auths);
- $this->assign('priority', model("Orders")->priority);
- $dep_list = (new \app\common\model\Dep())->getList();
- $order_type = (new \app\common\model\OrderType())->list();
- $order_mode = Db::name('order_mode')
- ->select();
- $this->assign('dep_list', $dep_list);
- $this->assign('order_type_list', $order_type);
- $this->assign('m_name', $mode_name);
- $this->assign('mode', $mode);
- $this->assign('order_mode_list', $order_mode);
- $this->assign('dispatch_type', check_two_dispatch($this->userId));
- $this->assign('quality_type',$quality_type);
- $dep_cate = model('DepCate')->getList();
- $this->assign('dep_cate',$dep_cate);
- $conveyCate = Db::name('convey_cate')
- ->where('org_id',$this->orgId)
- ->where('del',0)
- ->where('enable',1)
- ->select();
- $this->assign('convey_cate',$conveyCate);
- $addrList = (new \app\common\model\Address())->getListByTypes([],2,$this->orgId);
- $this->assign('addrList',$addrList);
- //抢单开关
- $this->assign('org_grab_order',(new \app\common\model\Config())
- ->getConfig('org_grab_order1',$this->orgId));
- $is = 0;
- if(!isset($_GET['quality_type']) && $mode==15){
- $is = 1;
- }
- $this->assign('is',$is);
- if ($mode == 1) {
- return $this->fetch('index1');
- }
- else {
- if ($mode == 3) {
- return $this->fetch('index3');
- }else if (in_array($mode,[0,-1])) {
- return $this->fetch('index0');
- }
- else {
- return $this->fetch('index');
- }
- }
- }
- }
- //调度删除订单
- public function del($id = 0) {
- if (!$id) {
- $this->error('参数错误');
- }
- $model = (new \app\common\model\Orders());
- $res = $model->del($id, $this->userId);
- if (!$res) {
- $this->error($model->getError());
- }
- $this->success('删除成功');
- }
- //调度添加订单
- public function dispatchAdd($mode = 1) {
- $id = input('id', 0);
- if (request()->isPost()) {
- $data = request()->post();
- $data['user_id'] = $this->userId;
- $data['org_id'] = $this->orgId;
- $data['work_type_mode'] = isset($data['work_type_mode'])?$data['work_type_mode']:$mode;
- $data['images'] = isset($data['images']) && !empty($data['images']) ? implode(',', $data['images']) : '';
- if ($id > 0) {
- // $phoneInfo = Db::name('phone_monitor_record')
- // ->where('id', $id)
- // ->find();
- $data['id'] = $id;
- $data['user_id'] = $this->userId;
- }
- $res = $this->model->addSave($data, 1);
- if ($res) {
- $this->success('操作成功');
- }
- else {
- $this->error($this->model->getError());
- }
- }
- else {
- $tsDh = model('Config')->getConfig('org_config_ts',$this->orgId);
- $this->assign('tsDh',$tsDh);
- $user = Db::name('user')
- ->where('id',$this->userId)
- ->find();
- $this->assign('user',$user);
- if($mode==0){//创建一键呼叫
- $dep = $this->getTableField('user_dep', ['user_id' => $this->userId], 'dep_id');
- $depList = (new \app\common\model\Dep())->getList();
- $this->assign('dep_id', $dep);
- $this->assign('dep_list', $depList);
- $order_type = (new \app\common\model\OrderType())->getList();
- $address = (new \app\common\model\Address())->getListByType(1);
- $this->assign('order_type_list', $order_type);
- $this->assign('address_list', $address);
- $order_repair = Db::name('order_repair')
- ->where('order_id', $id)
- ->find();
- $this->assign('order_repair', $order_repair);
- $workType = Db::name('work_type_mode')
- ->where('type',1)
- ->select();
- $config = Db::name('config')
- ->where('name','web_order_transfer_type')
- ->value('value');
- if(empty($config)){
- $workType = [];
- }else{
- $ll = explode('|',$config);
- foreach ($workType as $kk=>$vv){
- if(!in_array($vv['id'],$ll)){
- unset($workType[$kk]);
- }
- }
- }
- if(!is_admin($this->userId)){
- $auth = get_dispatch_auth($this->userId);
- if(empty($auth)){
- $workType = [];
- }else{
- foreach ($workType as $kk=>$vv){
- if(!in_array($vv['id'],$auth)){
- unset($workType[$kk]);
- }
- }
- }
- }
- foreach ($workType as $k=>$v){
- $this->assign('send_user_num'.$v['id'], $this->model->sendUserNum($v['id'], $this->orgId));
- $this->assign('user_list'.$v['id'], (new \app\common\model\WorkTypeMode())->getRolesUserByNum($v['id'], $this->orgId, 1));
- $two_dispatch_roles = model('user')->get_two_dispatch_role($this->orgId, $v['id']);
- $this->assign('dispatch_roles'.$v['id'], $two_dispatch_roles);
- }
- $this->assign('dispatch_type', check_two_dispatch($this->userId));
- $this->assign('two_dispatch_off', two_dispatch_off($this->orgId));
- $this->assign('workType', $workType);
- $address = (new \app\common\model\Address())->getListByType(2);
- $conveyCate = (new \app\common\model\ConveyCate());
- $priority = $conveyCate->priority;
- $order_convey = $conveyCate->getList();
- $order_device = (new \app\common\model\ConveyDevice())->getList();
- $this->assign('address', $address);
- $this->assign('priority', $priority);
- $this->assign('order_convey_type', $order_convey);
- $this->assign('order_device', $order_device);
- $oCid = Db::name('order_convey')
- ->where('order_id',$id)
- ->find();
- $opt = Db::name('order_convey_patient')
- ->where('order_id',$id)
- ->find();
- $this->assign('ocid',$oCid);
- $this->assign('opt',$opt);
- $this->assign('ps',empty($opt)?1:0);
- $this->assign('id', $id);
- $this->assign('mode', $mode);
- return $this->fetch('yjhj_dispatch_add');
- }else{
- $dep = $this->getTableField('user_dep', ['user_id' => $this->userId], 'dep_id');
- $depList = (new \app\common\model\Dep())->getList();
- $order_type = (new \app\common\model\OrderType())->getList();
- $address = (new \app\common\model\Address())->getListByType(1);
- $this->assign('dep_id', $dep);
- $this->assign('dep_list', $depList);
- $this->assign('order_type_list', $order_type);
- $this->assign('mode', $mode);
- $this->assign('send_user_num', $this->model->sendUserNum($mode, $this->orgId));
- $this->assign('user_list', (new \app\common\model\WorkTypeMode())->getRolesUserByNum($mode, $this->orgId,1));
- $this->assign('address_list', $address);
- $this->assign('address_id', '');
- if ($mode == 3) {
- $address = (new \app\common\model\Address())->getListByType(2);
- $conveyCate = (new \app\common\model\ConveyCate());
- $priority = $conveyCate->priority;
- $order_convey = $conveyCate->getList();
- $order_device = (new \app\common\model\ConveyDevice())->getList();
- $this->assign('address', $address);
- $this->assign('priority', $priority);
- $this->assign('order_convey_type', $order_convey);
- $this->assign('order_device', $order_device);
- }
- if ($id > 0) {
- // $phoneInfo = Db::name('phone_monitor_record')
- // ->where('id', $id)
- // ->find();
- $this->assign('address_id', 0);
- // $depId = Db::name('user_dep')
- // ->where('user_id', $phoneInfo['user_id'])
- // ->value('dep_id');
- $this->assign('dep_id', 0);
- }
- $two_dispatch_roles = model('user')->get_two_dispatch_role($this->orgId, $mode);
- $this->assign('dispatch_roles', $two_dispatch_roles);
- $this->assign('dispatch_type', check_two_dispatch($this->userId));
- $this->assign('two_dispatch_off', two_dispatch_off($this->orgId));
- $this->assign('id', $id);
- if ($mode == 3) {
- return $this->fetch('dispatch_add3');
- }
- else {
- return $this->fetch('dispatch_add');
- }
- }
- }
- }
- public function editOrder() {
- $id = input('id', 0);
- if (request()->isPost()) {
- $data = request()->post();
- $data['user_id'] = $this->userId;
- $data['org_id'] = $this->orgId;
- $data['images'] = isset($data['images']) && !empty($data['images']) ? implode(',', $data['images']) : '';
- $res = $this->model->editSave($data);
- if ($res) {
- $this->success('操作成功');
- }
- else {
- $this->error($this->model->getError());
- }
- }
- else {
- $order = Db::name('orders')->where('id',$id)->find();
- $mode = $order['work_type_mode'];
- $tsDh = model('Config')->getConfig('org_config_ts',$this->orgId);
- $this->assign('tsDh',$tsDh);
- $user = Db::name('user')
- ->where('id',$this->userId)
- ->find();
- $this->assign('user',$user);
- if($mode==0){//创建一键呼叫
- $dep = $this->getTableField('user_dep', ['user_id' => $this->userId], 'dep_id');
- $depList = (new \app\common\model\Dep())->getList();
- $this->assign('dep_id', $dep);
- $this->assign('dep_list', $depList);
- $order_type = (new \app\common\model\OrderType())->getList();
- $address = (new \app\common\model\Address())->getListByType(1);
- $this->assign('order_type_list', $order_type);
- $this->assign('address_list', $address);
- $order_repair = Db::name('order_repair')
- ->where('order_id', $id)
- ->find();
- $this->assign('order_repair', $order_repair);
- $workType = Db::name('work_type_mode')
- ->where('type',1)
- ->select();
- $config = Db::name('config')
- ->where('name','web_order_transfer_type')
- ->value('value');
- if(empty($config)){
- $workType = [];
- }else{
- $ll = explode('|',$config);
- foreach ($workType as $kk=>$vv){
- if(!in_array($vv['id'],$ll)){
- unset($workType[$kk]);
- }
- }
- }
- if(!is_admin($this->userId)){
- $auth = get_dispatch_auth($this->userId);
- if(empty($auth)){
- $workType = [];
- }else{
- foreach ($workType as $kk=>$vv){
- if(!in_array($vv['id'],$auth)){
- unset($workType[$kk]);
- }
- }
- }
- }
- foreach ($workType as $k=>$v){
- $this->assign('send_user_num'.$v['id'], $this->model->sendUserNum($v['id'], $this->orgId));
- $this->assign('user_list'.$v['id'], (new \app\common\model\WorkTypeMode())->getRolesUserByNum($v['id'], $this->orgId, 1));
- $two_dispatch_roles = model('user')->get_two_dispatch_role($this->orgId, $v['id']);
- $this->assign('dispatch_roles'.$v['id'], $two_dispatch_roles);
- }
- $this->assign('dispatch_type', check_two_dispatch($this->userId));
- $this->assign('two_dispatch_off', two_dispatch_off($this->orgId));
- $this->assign('workType', $workType);
- $address = (new \app\common\model\Address())->getListByType(2);
- $conveyCate = (new \app\common\model\ConveyCate());
- $priority = $conveyCate->priority;
- $order_convey = $conveyCate->getList();
- $order_device = (new \app\common\model\ConveyDevice())->getList();
- $this->assign('address', $address);
- $this->assign('priority', $priority);
- $this->assign('order_convey_type', $order_convey);
- $this->assign('order_device', $order_device);
- $oCid = Db::name('order_convey')
- ->where('order_id',$id)
- ->find();
- $opt = Db::name('order_convey_patient')
- ->where('order_id',$id)
- ->find();
- $this->assign('ocid',$oCid);
- $this->assign('opt',$opt);
- $this->assign('ps',empty($opt)?1:0);
- $this->assign('id', $id);
- $this->assign('mode', $mode);
- $this->assign('order',$order);
- return $this->fetch('yjhj_dispatch_edit');
- }else{
- $dep = $this->getTableField('user_dep', ['user_id' => $this->userId], 'dep_id');
- $depList = (new \app\common\model\Dep())->getList();
- $order_type = (new \app\common\model\OrderType())->getList();
- $address = (new \app\common\model\Address())->getListByType(1);
- $this->assign('dep_id', $dep);
- $this->assign('dep_list', $depList);
- $this->assign('order_type_list', $order_type);
- $this->assign('mode', $mode);
- $this->assign('send_user_num', $this->model->sendUserNum($mode, $this->orgId));
- $this->assign('user_list', (new \app\common\model\WorkTypeMode())->getRolesUserByNum($mode, $this->orgId,1));
- $this->assign('address_list', $address);
- $this->assign('address_id', '');
- if ($mode == 3) {
- $address = (new \app\common\model\Address())->getListByType(2);
- $conveyCate = (new \app\common\model\ConveyCate());
- $priority = $conveyCate->priority;
- $order_convey = $conveyCate->getList();
- $order_device = (new \app\common\model\ConveyDevice())->getList();
- $this->assign('address', $address);
- $this->assign('priority', $priority);
- $this->assign('order_convey_type', $order_convey);
- $this->assign('order_device', $order_device);
- $orderconvey = Db::name('order_convey')->where('order_id',$id)->find();
- $this->assign('orderconvey',$orderconvey);
- $orderconveypatient = Db::name('order_convey_patient')->where('order_id',$id)->find();
- $this->assign('orderconveypatient',$orderconveypatient);
- $addrs = Db::name('order_convey_end')->where('order_id',$id)->column('addr');
- $this->assign('addrs',$addrs?implode(',',$addrs):'');
- }else if($mode == 1){
- $orderrepair = Db::name('order_repair')->where('order_id',$id)->find();
- $this->assign('orderrepair',$orderrepair);
- }
- if ($id > 0) {
- // $phoneInfo = Db::name('phone_monitor_record')
- // ->where('id', $id)
- // ->find();
- $this->assign('address_id', 0);
- // $depId = Db::name('user_dep')
- // ->where('user_id', $phoneInfo['user_id'])
- // ->value('dep_id');
- $this->assign('dep_id', 0);
- }
- $two_dispatch_roles = model('user')->get_two_dispatch_role($this->orgId, $mode);
- $this->assign('dispatch_roles', $two_dispatch_roles);
- $this->assign('dispatch_type', check_two_dispatch($this->userId));
- $this->assign('two_dispatch_off', two_dispatch_off($this->orgId));
- $this->assign('id', $id);
- $this->assign('order',$order);
- if ($mode == 3) {
- return $this->fetch('dispatch_edit3');
- }
- else {
- return $this->fetch('dispatch_edit');
- }
- }
- }
- }
- //调度查看订单详情
- public function detail2($id) {
- if (!$id) {
- $this->error('参数错误');
- }
- $type = input('type/d',0);
- $this->assign('type', $type);
- $order = Db::name('orders')->where(['id' => $id])->find();
- $order = $this->model->formatOrder($order, 1);
- $order['images'] = !empty($order['images']) ? explode(',', $order['images']) : '';
- $is_ch = 0;
- if($order['order_mode'] == 4){
- $todoInfo = Db::name('todo')->where('order_id',$order['id'])->where('del',0)->where('todo_mode','>',1)->find();
- if(!$todoInfo){
- $is_ch = 1;
- }
- }
- $order['is_ch'] = $is_ch;
- if($order['work_type_mode'] == 3){
- // 地点路径
- $conveyends = Db::name('order_convey_end')
- ->alias('a')
- ->join('address b','b.id = a.addr')
- ->where('a.order_id',$id)
- ->order('a.id asc')
- ->field('a.*,b.title')
- ->select();
- $order['ends'] = $conveyends?$conveyends:[];
- }
- $this->assign('info', $order);
- $workTypeName = $this->getTableField('work_type_mode', ['id' => $order['work_type_mode']], 'name');
- $this->assign('meta_title', $workTypeName . '订单详情');
- $level2 = check_two_dispatch($this->userId);
- $level1 = check_is_dispatch($this->userId);
- $turnoff = two_dispatch_off($this->orgId);
- $this->assign('level1', $level1);
- $this->assign('level2', $level2);
- $this->assign('turnoff', $turnoff);
- $this->assign('dispatch_type', $level2);
- $this->assign('org_auto_send',(new \app\common\model\Config())
- ->getConfig('org_auto_send',$this->orgId));
- return $this->fetch();
- }
- public function zg_detail($id) {
- if (!$id) {
- $this->error('参数错误');
- }
- $type = input('type/d',0);
- $this->assign('type', $type);
- $order = Db::name('orders')->where(['id' => $id])->find();
- $order = $this->model->formatOrder($order, 1);
- $order['images'] = !empty($order['images']) ? explode(',', $order['images']) : '';
- $this->assign('info', $order);
- $workTypeName = $this->getTableField('work_type_mode', ['id' => $order['work_type_mode']], 'name');
- $this->assign('meta_title', $workTypeName . '订单详情');
- $level2 = check_two_dispatch($this->userId);
- $level1 = check_is_dispatch($this->userId);
- $turnoff = two_dispatch_off($this->orgId);
- $this->assign('level1', $level1);
- $this->assign('level2', $level2);
- $this->assign('turnoff', $turnoff);
- $this->assign('dispatch_type', $level2);
- return $this->fetch();
- }
- public function print($id) {
- if (!$id) {
- $this->error('参数错误');
- }
- $type = input('type/d',0);
- $this->assign('type', $type);
- $order = Db::name('orders')->where(['id' => $id])->find();
- $order = $this->model->formatOrder($order, 1);
- $order['images'] = !empty($order['images']) ? explode(',', $order['images']) : '';
- $this->assign('info', $order);
- $workTypeName = $this->getTableField('work_type_mode', ['id' => $order['work_type_mode']], 'name');
- $this->assign('meta_title', $workTypeName . '订单详情');
- $level2 = check_two_dispatch($this->userId);
- $level1 = check_is_dispatch($this->userId);
- $turnoff = two_dispatch_off($this->orgId);
- $this->assign('level1', $level1);
- $this->assign('level2', $level2);
- $this->assign('turnoff', $turnoff);
- $this->assign('dispatch_type', $level2);
- return $this->fetch();
- }
- //派单
- public function send($id, $mode = 1) {
- if (request()->isGet()) {
- $this->assign('id', $id);
- $this->assign('mode', $mode);
- $orders = Db::name('orders')
- ->where('id',$id)
- ->find();
- if($orders['source_type']==4 && $orders['work_type_mode']==0 && $orders['is_deal']==0){//一键呼叫
- $order_type = (new \app\common\model\OrderType())->getList();
- $address = (new \app\common\model\Address())->getListByType(1);
- $this->assign('order_type_list', $order_type);
- $this->assign('address_list', $address);
- $order_repair = Db::name('order_repair')
- ->where('order_id', $id)
- ->find();
- $this->assign('order_repair', $order_repair);
- $workType = Db::name('work_type_mode')
- ->where('type',1)
- ->select();
- $config = Db::name('config')
- ->where('name','web_order_transfer_type')
- ->value('value');
- if(empty($config)){
- $workType = [];
- }else{
- $ll = explode('|',$config);
- foreach ($workType as $kk=>$vv){
- if(!in_array($vv['id'],$ll)){
- unset($workType[$kk]);
- }
- }
- }
- foreach ($workType as $k=>$v){
- $this->assign('send_user_num'.$v['id'], $this->model->sendUserNum($v['id'], $this->orgId));
- $this->assign('user_list'.$v['id'], (new \app\common\model\WorkTypeMode())->getRolesUserByNum($v['id'], $this->orgId, 1));
- $two_dispatch_roles = model('user')->get_two_dispatch_role($this->orgId, $v['id']);
- $this->assign('dispatch_roles'.$v['id'], $two_dispatch_roles);
- }
- $this->assign('dispatch_type', check_two_dispatch($this->userId));
- $this->assign('two_dispatch_off', two_dispatch_off($this->orgId));
- $this->assign('workType', $workType);
- $this->assign('orders', $orders);
- $address = (new \app\common\model\Address())->getListByType(2);
- $conveyCate = (new \app\common\model\ConveyCate());
- $priority = $conveyCate->priority;
- $order_convey = $conveyCate->getList();
- $order_device = (new \app\common\model\ConveyDevice())->getList();
- $this->assign('address', $address);
- $this->assign('priority', $priority);
- $this->assign('order_convey_type', $order_convey);
- $this->assign('order_device', $order_device);
- $oCid = Db::name('order_convey')
- ->where('order_id',$id)
- ->find();
- $opt = Db::name('order_convey_patient')
- ->where('order_id',$id)
- ->find();
- $this->assign('ocid',$oCid);
- $this->assign('opt',$opt);
- $this->assign('ps',empty($opt)?1:0);
- $auths = [1,2,3,4,15,0];
- if(!is_admin($this->userId)){
- $auth = get_dispatch_auth($this->userId);
- if($auth){
- $auths = array_intersect($auths,$auth);
- if($mode > 0){
- $auths = array_intersect($auths,[$mode]);
- }
- }else{
- $auths = [];
- }
- }
- $this->assign('auths',$auths);
- return $this->fetch('yjhj_send');
- }else{
- if ($mode == 1) {
- $order_type = (new \app\common\model\OrderType())->getList();
- $address = (new \app\common\model\Address())->getListByType(1);
- $this->assign('order_type_list', $order_type);
- $this->assign('address_list', $address);
- $order_repair = Db::name('order_repair')
- ->where('order_id', $id)
- ->find();
- $this->assign('order_repair', $order_repair);
- }
- $this->assign('send_user_num', $this->model->sendUserNum($mode, $this->orgId));
- $this->assign('user_list', (new \app\common\model\WorkTypeMode())->getRolesUserByNum($mode, $this->orgId, 1));
- $two_dispatch_roles = model('user')->get_two_dispatch_role($this->orgId, $mode);
- $this->assign('dispatch_roles', $two_dispatch_roles);
- $this->assign('dispatch_type', check_two_dispatch($this->userId));
- $this->assign('two_dispatch_off', two_dispatch_off($this->orgId));
- return $this->fetch();
- }
- }
- else {
- $data = request()->post();
- $data['org_id'] = $this->orgId;
- $res = $this->model->send($id, $this->userId, $data);
- if (!$res) {
- $this->error($this->model->getError());
- }
- $this->success('操作成功');
- }
- }
- //转单
- public function zd_send($id, $mode = 1) {
- if (request()->isGet()) {
- $this->assign('id', $id);
- $this->assign('mode', $mode);
- $orders = Db::name('orders')
- ->where('id',$id)
- ->find();
- if($orders['source_type']==4 && $orders['is_deal']==0){//一键呼叫
- $order_type = (new \app\common\model\OrderType())->getList();
- $address = (new \app\common\model\Address())->getListByType(1);
- $this->assign('order_type_list', $order_type);
- $this->assign('address_list', $address);
- $order_repair = Db::name('order_repair')
- ->where('order_id', $id)
- ->find();
- $this->assign('order_repair', $order_repair);
- $workType = Db::name('work_type_mode')
- ->where('type',1)
- ->select();
- $config = Db::name('config')
- ->where('name','web_order_transfer_type')
- ->value('value');
- if(empty($config)){
- $workType = [];
- }else{
- $ll = explode('|',$config);
- foreach ($workType as $kk=>$vv){
- if(!in_array($vv['id'],$ll)){
- unset($workType[$kk]);
- }
- }
- }
- foreach ($workType as $k=>$v){
- $this->assign('send_user_num'.$v['id'], $this->model->sendUserNum($v['id'], $this->orgId));
- $this->assign('user_list'.$v['id'], (new \app\common\model\WorkTypeMode())->getRolesUser($v['id'], $this->orgId, 1));
- $two_dispatch_roles = model('user')->get_two_dispatch_role($this->orgId, $v['id']);
- $this->assign('dispatch_roles'.$v['id'], $two_dispatch_roles);
- }
- $this->assign('dispatch_type', check_two_dispatch($this->userId));
- $this->assign('two_dispatch_off', two_dispatch_off($this->orgId));
- $this->assign('workType', $workType);
- $this->assign('orders', $orders);
- $address = (new \app\common\model\Address())->getListByType(2);
- $conveyCate = (new \app\common\model\ConveyCate());
- $priority = $conveyCate->priority;
- $order_convey = $conveyCate->getList();
- $order_device = (new \app\common\model\ConveyDevice())->getList();
- $this->assign('address', $address);
- $this->assign('priority', $priority);
- $this->assign('order_convey_type', $order_convey);
- $this->assign('order_device', $order_device);
- $oCid = Db::name('order_convey')
- ->where('order_id',$id)
- ->find();
- $opt = Db::name('order_convey_patient')
- ->where('order_id',$id)
- ->find();
- $this->assign('ocid',$oCid);
- $this->assign('opt',$opt);
- $this->assign('ps',empty($opt)?1:0);
- $auths = [1,2,3,4,15,0];
- if(!is_admin($this->userId)){
- $auth = get_dispatch_auth($this->userId);
- if($auth){
- $auths = array_intersect($auths,$auth);
- if($mode > 0){
- $auths = array_intersect($auths,[$mode]);
- }
- }else{
- $auths = [];
- }
- }
- $this->assign('auths',$auths);
- return $this->fetch('yjhj_zd_send');
- }
- }
- else {
- $data = request()->post();
- $data['org_id'] = $this->orgId;
- $res = $this->model->zd_send($id, $data);
- if (!$res) {
- $this->error($this->model->getError());
- }
- $this->success('操作成功');
- }
- }
- //批量派单
- public function batchsend($id, $mode = 1) {
- if (request()->isGet()) {
- $this->assign('id', $id);
- $this->assign('mode', $mode);
- if ($mode == 1) {
- $order_type = (new \app\common\model\OrderType())->getList();
- $address = (new \app\common\model\Address())->getListByType(1);
- $this->assign('order_type_list', $order_type);
- $this->assign('address_list', $address);
- $order_repair = Db::name('order_repair')
- ->where('order_id', $id)
- ->find();
- $this->assign('order_repair', $order_repair);
- }
- $user = (new \app\common\model\WorkTypeMode())->getRolesUser($mode, $this->orgId, 1);
- $newUser = [];
- $pinyin = new Pinyin();
- foreach ($user as $k => $v) {
- foreach ($v['user'] as $k1 => $v1) {
- $v1['pinyin'] = $pinyin->abbr($v1['real_name'],PINYIN_KEEP_ENGLISH); //只保留汉字首字母 和 字母的首字母 //例如:'汉字sszz11' = hzs
- $newUser[] = $v1;
- }
- }
- $newUser = arraySequence($newUser,'pinyin');
- $mm = new \app\common\model\User();
- foreach ($newUser as $key => $value) {
- $nums = Db::name('todo')
- ->where(['to_user_id' => $value['id'], 'work_type_mode' => 3])
- ->where('create_yyyymmdd', date('Ymd'))
- ->where('todo_mode', 'in', [1, 2, 3])
- ->count();
- $newUser[$key]['nums'] = $nums;
- $newUser[$key]['cur_status'] = 0; // 空闲
- $nums2 = Db::name('todo')
- ->where(['to_user_id' => $value['id'], 'work_type_mode' => 3])
- ->where('todo_mode', 'in', [1, 2])
- ->count();
- if($nums2 > 0){
- $newUser[$key]['cur_status'] = 1; // 任务中
- }
- $addr = Db::name('order_convey')
- ->alias('cpr')
- ->join('todo os', 'cpr.order_id = os.order_id')
- ->join('orders ods', 'cpr.order_id = ods.id')
- ->join('address ca', 'ca.id = cpr.start')
- ->join('address cad', 'cad.id = cpr.end')
- ->field('os.todo_mode,ca.title as start_name,cad.title as end_name,os.create_time')
- ->where('os.to_user_id', $value['id'])
- ->where('os.del', 0)
- ->where('ods.del', 0)
- ->order('os.id desc')
- ->find();
- $newUser[$key]['title'] = '';
- $newUser[$key]['addr_time'] = '';
- if($addr){
- if(in_array($addr['todo_mode'],[1,2])){
- $newUser[$key]['title'] = $addr['start_name'];
- }else{
- $newUser[$key]['title'] = $addr['end_name'];
- }
- $newUser[$key]['addr_time'] = $addr['create_time'];
- }
- $u = Db::name('user')
- ->where('id',$value['id'])
- ->value('sex');
- $newUser[$key]['sex_name'] = isset($mm->sex[$u])?$mm->sex[$u]:"";
- }
- $newUser = list_sort_by($newUser,"addr_time", 'asc');
- if($this->orgId==3){
- // echo "<pre/>";
- // print_r($newUser);
- // die();
- }
- $this->assign('user_list', $newUser);
- return $this->fetch();
- }
- else {
- $data = request()->post();
- $data['org_id'] = $this->orgId;
- if (empty($data['to_user_id'])) {
- $this->error('请选择执行人');
- }
- $data['to_user_id'] = implode(',', $data['to_user_id']);
- $res = $this->model->batchsend($id, $this->userId, $data);
- if (!$res) {
- $this->error($this->model->getError());
- }
- $this->success('操作成功');
- }
- }
- public function onesend($id, $mode = 1) {
- $data = request()->post();
- $data['org_id'] = $this->orgId;
- if (empty($data['to_user_id'])) {
- $this->error('请选择执行人');
- }
- // $data['to_user_id'] = implode(',', $data['to_user_id']);
- $res = $this->model->batchsend($id, $this->userId, $data);
- if (!$res) {
- $this->error($this->model->getError());
- }
- $this->success('操作成功');
- }
- //完成订单
- public function finish($id) {
- $res = $this->model->finish($id);
- if (!$res) {
- $this->error($this->model->getError());
- }
- $this->success('操作成功');
- }
- //批量完成订单
- public function batchfinish($id) {
- $res = $this->model->batchfinish($id);
- if (!$res) {
- $this->error($this->model->getError());
- }
- $this->success('操作成功');
- }
- //评价
- public function comment() {
- $id = input('id');
- $score = input('score');
- $content = input('content');
- if ($score <= 0 || $score > 5) {
- $this->error('参数错误');
- }
- $res = $this->model->addComment($id, $score, $content, $this->userId, $this->orgId);
- if (!$res) {
- $this->error($this->model->getError());
- }
- $this->success('操作成功');
- }
- public function phone() {
- $phone = input('phone','','trim');
- $fp = input('fp','','trim');
- $id = input('id/d',0,'trim');
- if($phone){
- $fp = $fp?base64_decode($fp):'';
- $md5 = md5($this->orgId.'|'.$fp);
- $ret = Db::name('phone_monitor_record')->where('md5',$md5)->find();
- if(!$ret){
- $id = Db::name('phone_monitor_record')->insertGetId([
- 'org_id' => $this->orgId,
- 'phone' => $phone,
- 'path' => $fp,
- 'md5' => $md5,
- 'create_time' => date('Y-m-d H:i:s')
- ]);
- }else{
- $id = $ret['id'];
- }
- }
- $worktype = [
- ['id' => 1, 'title' => '报修'],
- ['id' => 2, 'title' => '保洁'],
- ['id' => 3, 'title' => '运送'],
- ['id' => 4, 'title' => '应急'],
- ];
- $info = Db::name('phone_monitor_record')->where('id',$id)->find();
- if(!$info){
- halt('数据存储失败');
- }
- $this->assign('worktype', $worktype);
- $this->assign('info', $info);
- $this->assign('id', $id);
- return $this->fetch();
- }
- public function phoneAdd() {
- $id = input('id');
- $worktype = [
- ['id' => 1, 'title' => '报修'],
- ['id' => 2, 'title' => '保洁'],
- ['id' => 3, 'title' => '运送'],
- ['id' => 4, 'title' => '应急'],
- ];
- $info = Db::name('phone_monitor')
- ->where('id', $id)->find();
- if (!$info) {
- echo '负责人不存在', exit();
- }
- $info['real_name'] = Db::name('user')
- ->where('id', $info['user_id'])
- ->value('real_name');
- $info['dep'] = Db::name('user_dep')
- ->alias('a')
- ->join('dep b', 'a.dep_id=b.id')
- ->where('a.user_id', $info['user_id'])
- ->value('b.title');
- $this->assign('worktype', $worktype);
- $this->assign('info', $info);
- $this->assign('id', $id);
- return $this->fetch();
- }
- //运送调度订单列表
- public function convey() {
- set_time_limit(0);
- ini_set("memory_limit","1024M");
- $mode = input('mode', 1);
- if (request()->isAjax()) {
- //分页参数
- $length = input('rows', 10, 'intval'); //每页条数
- $page = input('page', 1, 'intval'); //第几页
- $start = ($page - 1) * $length; //分页开始位置
- //排序
- $sortRow = input('sidx', 'id', 'trim'); //排序列
- $sort = input('sord', 'desc', 'trim'); //排序方式
- $order = $sortRow . ' ' . $sort;
- $content = input('content', '', 'trim');
- if ($content) {
- $map[] = ['o.content', 'like', '%' . $content . '%'];
- }
- $dep_id = input('dep_id', '', 'trim');
- if ($dep_id != '') {
- $map[] = ['o.dep_id', '=', $dep_id];
- }
- $priority = input('priority', '', 'trim');
- if ($priority) {
- $map[] = ['oc.priority', '=', $priority];
- }
- $s = input('start', '', 'trim');
- $end = input('end', '', 'trim');
- if ($s) {
- $map[] = ['oc.start', '=', $start];
- }
- if ($end) {
- $map[] = ['oc.end', '=', $end];
- }
- $type = input('type', '', 'trim');
- if ($type) {
- $map[] = ['oc.type', '=', $type];
- }
- $xqtime = input('xqtime', '', 'trim');
- $ywctime = input('ywctime', '', 'trim');
- if ($xqtime) {
- $xqtimes = explode(' - ', $xqtime);
- $x1 = date('Ymd', strtotime($xqtimes[0]));
- $x2 = date('Ymd', strtotime($xqtimes[1]));
- $map[] = ['oc.xq_time', '>=', $x1];
- $map[] = ['oc.xq_time', '<=', $x2];
- }else{ // 默认只显示当天的订单
- // $map[] = ['oc.xq_time', '>=', date("Y-m-d")." 00:00:00"];
- $map[] = ['oc.xq_time', '<=', date("Y-m-d")." 23:59:59"];
- }
- if ($ywctime) {
- $ywctimes = explode(' - ', $ywctime);
- $y1 = date('Ymd', strtotime($ywctimes[0]));
- $y2 = date('Ymd', strtotime($ywctimes[1]));
- $map[] = ['oc.ywc_time', '>=', $y1];
- $map[] = ['oc.ywc_time', '<=', $y2];
- }
- $map[] = ['o.del', '=', 0];
- $map[] = ['o.org_id', '=', $this->orgId];
- $map[] = ['o.work_type_mode', '=', 3];
- $map[] = ['o.order_mode', 'in', [1, 4]];
- $status = input('status', '', 'trim');
- $ysName = input('ysname', '');
- if ($ysName) {
- $orders = Db::name('todo')
- ->alias('t')
- ->where('t.org_id', $this->orgId)
- ->where('t.del', 0)
- ->where('t.work_type_mode', 3)
- ->where('t.todo_mode', [1, 2, 4])
- ->where('u.real_name', 'like', '%' . $ysName . '%')
- ->join('orders o', 'o.id = t.order_id')
- ->join('user u', 't.to_user_id = u.id')
- ->group('o.id')
- ->column('o.id');
- if ($orders) {
- $map[] = ['o.id', 'in', $orders];
- }
- else {
- $map[] = ['o.id', '=', 0];
- }
- }
- $map = empty($map) ? true : $map;
- //数据查询
- $lists = db($this->table)->alias('o')
- ->join('order_convey oc', 'oc.order_id=o.id')
- ->field('o.*,oc.type,oc.start,oc.end,oc.xq_time,oc.ywc_time,oc.device_id,oc.name,oc.phone,oc.priority')
- ->where($map)
- ->order(['o.order_mode' => 'asc', 'oc.xq_time' => 'desc'])
- ->select();
- // halt($lists);
- $newret = [];
- $newret1 = [];
- $newret2 = [];
- $newret3 = [];
- $newret4 = [];
- foreach ($lists as $k => $v) {
- $v = $this->model->formatOrder($v);
- $v['bed_number'] = '';
- $ocp = Db::name('order_convey_patient')
- ->where('order_id', $v['id'])
- ->find();
- $v['bed_number'] = !empty($ocp)?$ocp['bed_number']:'';
- $todo = Db::name('todo')
- ->alias('t')
- ->where('t.order_id', $v['id'])
- ->join('user u', 'u.id = t.to_user_id')
- ->where('t.todo_mode', 'in', [1, 2, 3, 4])
- ->where('t.del', 0)
- ->field('u.real_name,u.mobile,t.create_time,t.confirm_time')
- ->order('t.id asc')
- ->select();
- $users = [];
- $confirmtime = '';
- foreach ($todo as $kk => $vv) {
- $users[] = $vv['real_name'].($vv['mobile']?'['.$vv['mobile'].']':'');
- if (!$confirmtime && $vv['confirm_time']) {
- $confirmtime = $vv['confirm_time'];
- }
- else {
- if ($confirmtime && $vv['confirm_time'] && $vv['confirm_time'] < $confirmtime) {
- $confirmtime = $vv['confirm_time'];
- }
- }
- }
- $v['is_todo'] = $todo?1:0;
- $v['real_names'] = implode(',', $users);
- $v['confirm_time'] = $confirmtime;
- $last = strtotime($v['ywc_time']) - time();
- $v['last_time'] = $last > 0 ? round($last / 60) : 0;
- //是否有延时
- $v['delay'] = 0; // 0=未延迟 1=延迟
- $v['delay_diff'] = 0;
- $v['delay_reason'] = '';
- $delays = Db::name('order_delay')
- ->where('order_id', $v['id'])
- ->select();
- $delays = $delays ? $delays : [];
- foreach ($delays as $vv) {
- if ($vv['status'] == 0) {
- $v['delay'] = 1;
- $v['delay_reason'] = $this->gettablefield('delay_reason', ['id' => $vv['delay_reason_id']], 'title');
- $vv['diff'] = time() - strtotime($vv['start_time']);
- }
- $v['delay_diff'] += $vv['diff'];
- }
- $v['delay_diff'] = round($v['delay_diff'] / 60);
- if ($v['delay'] == 1) {
- $v['status'] = 3;
- } else {
- if ($v['order_mode'] == 1) {
- $v['status'] = 1;
- } else {
- $v['status'] = 2;
- }
- }
- $convey = Db::name('convey_cate')
- ->alias('oc')
- ->join('time ot', 'ot.id = oc.time_id')
- ->where('oc.id', $v['type'])
- ->field('ot.*')
- ->find();
- $createtime = strtotime($v['create_time']);
- $curtime = time();
- $ct = round(($curtime - $createtime) / 60);
- if ($ct < $convey['yy_time']) {
- $ss = 0;
- }
- else {
- if ($ct >= $convey['yy_time'] && $ct < $convey['bz_time']) {
- $ss = 1;
- }
- else {
- if ($ct >= $convey['bz_time'] && $ct < $convey['jg_time']) {
- $ss = 2;
- }
- else {
- if ($ct >= $convey['jg_time'] && $ct < $convey['wjjg_time']) {
- $ss = 3;
- }
- else {
- $ss = 4;
- }
- }
- }
- }
- $v['ss'] = $ss;
- $v['xtime'] = date('H:i', strtotime($v['xq_time']));
- $v['stime'] = $v['send_time'] ? date('H:i', strtotime($v['send_time'])) : "";
- $v['ctime'] = $v['confirm_time'] ? date('H:i', strtotime($v['confirm_time'])) : "";
- $v['starttime'] = '';
- if($v['confirm_time']){ // 如果确认时间不为空
- $todoconvey = Db::name('todo_convey')
- ->alias('a')
- ->join('todo t','t.id = a.todo_id')
- ->where('t.order_id', $v['id'])
- ->field('a.*')
- ->order('a.id asc')
- ->find();
- if($todoconvey){
- $v['starttime'] = date('H:i', strtotime($todoconvey['start_time']));
- }
- }
- $v['priorityName'] = isset($this->model->priority[$v['priority']])?$this->model->priority[$v['priority']]:'';
- if ($status == 3 && $v['delay'] == 1) { //延时任务
- $newret[] = $v;
- $newret1[] = $v;
- }
- if ($status == 1 && $v['order_mode'] == 1) { //新任务
- $newret[] = $v;
- $newret2[] = $v;
- }
- if ($status == 2 && $v['order_mode'] == 4) { // 进行中
- $newret[] = $v;
- $newret3[] = $v;
- }
- if (!$status || !in_array($status, [1, 2, 3])) {
- $newret[] = $v;
- $newret4[] = $v;
- }
- $lists[$k] = $v;
- }
- if(!empty($newret)){
- //$newret = arraySequence($newret,'status');//返回数组中指定的一列
- // $newret1 = $newret1?arraySequence($newret1,'xtime','SORT_DESC'):[];
- // $newret3 = $newret3?arraySequence($newret3,'xtime','SORT_DESC'):[];
- // $newret4 = $newret4?arraySequence($newret4,'xtime','SORT_DESC'):[];
- // $newret = array_merge($newret2,$newret3,$newret4,$newret1);
- $all = [];
- $newret2 = $newret2?arraySequence($newret2,'status'):[];
- $newret3 = $newret3?arraySequence($newret3,'status'):[];
- //$newret4 = $newret4?arraySequence($newret4,'status'):[];
- $newret1 = $newret1?arraySequence($newret1,'status'):[];
- $newret2 = $newret2?arraySequence($newret2,'xtime','SORT_DESC'):[];
- $newret3 = $newret3?arraySequence($newret3,'xtime','SORT_DESC'):[];
- // $newret4 = $newret4?arraySequence($newret4,'xtime','SORT_DESC'):[];
- $newret1 = $newret1?arraySequence($newret1,'xtime','SORT_DESC'):[];
- foreach ($newret2 as $k=>$v){
- $all[] = $v;
- }
- foreach ($newret3 as $k=>$v){
- $all[] = $v;
- }
- foreach ($newret1 as $k=>$v){
- $all[] = $v;
- }
- $a1 = $a2 = $a3 = [];
- foreach ($newret4 as $k=>$v){
- if ($v['status'] == 3) { //延时任务
- $a1[] = $v;
- }
- if ($v['status'] == 1) { //新任务
- $a2[] = $v;
- }
- if ($v['status'] == 2) { // 进行中
- $a3[] = $v;
- }
- }
- $a1 = $a1?arraySequence($a1,'status'):[];
- $a2 = $a2?arraySequence($a2,'status'):[];
- $a3 = $a3?arraySequence($a3,'status'):[];
- $a1 = $a1?arraySequence($a1,'xtime','SORT_DESC'):[];
- $a2 = $a2?arraySequence($a2,'xtime','SORT_DESC'):[];
- $a3 = $a3?arraySequence($a3,'xtime','SORT_DESC'):[];
- // 预约类型-取15分钟后之前的订单
- $curtime15 = $curtime+60*15;
- foreach ($a2 as $k=>$v){
- if($v['priority'] !=4 && $v['xq_time'] < date('Y-m-d H:i:s',$curtime15) ){
- $all[] = $v;
- }
- }
- foreach ($a3 as $k=>$v){
- if($v['priority'] !=4 && $v['xq_time'] < date('Y-m-d H:i:s',$curtime15) ){
- $all[] = $v;
- }
- }
- foreach ($a1 as $k=>$v){
- if($v['priority'] !=4 && $v['xq_time'] < date('Y-m-d H:i:s',$curtime15) ){
- $all[] = $v;
- }
- }
- $newret= $all;
- }
- $sdd[] =['org_id','=',$this->orgId];
- $sdd[] =['del','=',0];
- $sdd[] =['work_type_mode','=',3];
- $sdd[] =['create_yyyymmdd','=',date('Ymd')];
- $dcl = Db::name('orders')
- ->where($sdd)
- ->where('order_mode',1)
- ->count();
- $ypf = Db::name('orders')
- ->where($sdd)
- ->where('order_mode',4)
- ->count();
- $ywc = Db::name('orders')
- ->where($sdd)
- ->where('order_mode','in',[5,6])
- ->count();
- $yqx = Db::name('orders')
- ->where($sdd)
- ->where('order_mode','in',[2,3])
- ->count();
- //数据返回
- $totalCount = count($newret);
- $totalPage = ceil($totalCount / $length);
- $result['dcl'] = $dcl;
- $result['ypf'] = $ypf;
- $result['ywc'] = $ywc;
- $result['yqx'] = $yqx;
- $result['page'] = $page;
- $result['total'] = $totalPage;
- $result['records'] = $totalCount;
- $result['rows'] = $newret;
- return json($result);
- }
- else {
- $mode_name = $this->getTableField('work_type_mode', ['id' => $mode], 'name');
- $order_type = (new \app\common\model\ConveyCate())->getList();
- $order_mode = Db::name('order_mode')
- ->select();
- $this->assign('order_type_list', $order_type);
- $this->assign('m_name', $mode_name);
- $this->assign('mode', $mode);
- $this->assign('order_mode_list', $order_mode);
- $this->assign('dispatch_type', check_two_dispatch($this->userId));
- $address = (new \app\common\model\Address())->getListByType(2);
- $this->assign('address', $address);
- $count = Db::name('todo')
- ->where('org_id', $this->orgId)
- ->where('del', 0)
- ->where('work_type_mode', 3)
- ->where('todo_mode', 4)
- ->count();
- $this->assign('count', $count);
- $info = Db::name('config')->where('name','org_order_refresh')
- ->find();
- $orgConfig = Db::name('config_org')
- ->where('config_id',$info['id'])
- ->where('org_id',$this->orgId)
- ->find();
- $value = $orgConfig?$orgConfig['value']:0;
- $this->assign('refresh',$value);
- $sxJg = (new Config())->getConfig('ys_auto_sx',$this->orgId);
- $this->assign('sxJg',$sxJg?$sxJg:30);
- return $this->fetch();
- }
- }
- public function reminder(){
- $id = input('id/d',0);
- $touserids = Db::name('todo')->where('order_id',$id)->where('todo_mode','in',[1,2])->where('del',0)->column('to_user_id');
- if($touserids){
- $touserids = array_unique($touserids);
- send_jpush($touserids,AppMsg::PUSH_WORKER_ORDER_SEND,'您有订单需要处理');
- }
- $this->success('催单成功');
- }
- //运送员状态
- public function conveystatus($id='') {
- if (request()->isAjax()) {
- //分页参数
- $length = input('rows', 10, 'intval'); //每页条数
- $page = input('page', 1, 'intval'); //第几页
- $start = ($page - 1) * $length; //分页开始位置
- //排序
- $sortRow = input('sidx', 'id', 'trim'); //排序列
- $sort = input('sord', 'desc', 'trim'); //排序方式
- $order = $sortRow . ' ' . $sort;
- $real_name = input('real_name', '');
- $map8 = [];
- if ($real_name) {
- $map8[] = ['real_name', 'like', '%'.$real_name.'%'];
- }
- $work = input('work', '');
- if ($work!='') {
- $map8[] = ['work', '=',$work];
- }
- $user = (new \app\common\model\WorkTypeMode())->getRolesUser(3, $this->orgId);
- $newUser = [];
- foreach ($user as $k => $v) {
- foreach ($v['user'] as $k1 => $v1) {
- $newUser[] = $v1['id'];
- }
- }
- $userIds1 = [];
- if($id){
- $ids = explode(',', $id);
- $map[] = ['order_id', 'in', $ids];
- $map[] = ['del', '=', 0];
- $map[] = ['org_id', '=', $this->orgId];
- $map[] = ['work_type_mode', '=', 3];
- $userIds = Db::name('todo')->where($map)->column('to_user_id');
- $userIds1 = $userIds?$userIds:[];
- $newUser = array_intersect($userIds1,$newUser);
- }
- if(empty($newUser)){
- $map8[] = ['id','=',0];
- }else{
- $map8[] = ['id','in',$newUser];
- }
- $mm = [];
- $group = input('group', '');
- if ($group) {
- $uid = Db::name('user_group_user')
- ->where('group_id',$group)
- ->column('user_id');
- if(!empty($uid)){
- $mm[] = ['id','in',$uid];
- }else{
- $mm[] = ['id','in',[-1]];
- }
- }
- $lists = db('user')
- ->where($mm)
- ->where($map8)
- ->limit($start, $length)
- ->order($order)
- ->select();
- foreach ($lists as $key => $value) {
- $lists[$key]['user_group_title'] = Db::name('user_group')
- ->alias('ug')
- ->join('user_group_user ugu','ugu.group_id=ug.id')
- ->where('ugu.user_id',$value['id'])
- ->value('ug.title');
- $nums = Db::name('todo')
- ->where(['to_user_id' => $value['id'], 'work_type_mode' => 3])
- ->where('create_yyyymmdd', date('Ymd'))
- ->where('todo_mode', 'in', [1, 2, 3])
- ->count();
- $lists[$key]['nums'] = $nums;
- $addr = Db::name('order_convey')
- ->alias('cpr')
- ->join('todo os', 'cpr.order_id = os.order_id')
- ->join('orders ods', 'cpr.order_id = ods.id')
- ->join('address ca', 'ca.id = cpr.start')
- ->join('address cad', 'cad.id = cpr.end')
- ->field('os.todo_mode,ca.title as start_name,cad.title as end_name,os.create_time')
- ->where('os.to_user_id', $value['id'])
- ->where('os.del', 0)
- ->where('ods.del', 0)
- ->order('os.id desc')
- ->find();
- $lists[$key]['title'] = '';
- $lists[$key]['addr_time'] = '';
- if($addr){
- if(in_array($addr['todo_mode'],[1,2])){
- $lists[$key]['title'] = $addr['start_name'];
- }else{
- $lists[$key]['title'] = $addr['end_name'];
- }
- $lists[$key]['addr_time'] = $addr['create_time'];
- }
- $lists[$key]['worktxt'] = $value['work'] == 1 ? '上班' : '下班';
- $lists[$key]['stationtxt'] = $value['station'] == 1 ? '驻守' : '取消驻守';
- }
- //数据返回
- // $totalCount = db('user')
- // ->where($map1)->count();
- $totalCount = db('user')
- ->where($map8)->count();
- $totalPage = ceil($totalCount / $length);
- $result['page'] = $page;
- $result['total'] = $totalPage;
- $result['records'] = $totalCount;
- $result['rows'] = $lists;
- return json($result);
- }
- else {
- $group = model('UserGroup')->getList();
- $this->assign('group', $group);
- $this->assign('id', $id);
- return $this->fetch();
- }
- }
- //上下班
- public function work($id) {
- $user = Db::name('user')
- ->where('id', $id)
- ->find();
- $value = $user['work'] == 1 ? 0 : 1;
- $res = Db::name('user')
- ->where('id', $id)
- ->update(['work' => $value, 'update_time' => getTime()]);
- $res ? $this->success('操作成功') : $this->error('操作失败');
- }
- //驻守
- public function station($id) {
- $user = Db::name('user')
- ->where('id', $id)
- ->find();
- $value = $user['station'] == 1 ? 0 : 1;
- $res = Db::name('user')
- ->where('id', $id)
- ->update(['station' => $value, 'update_time' => getTime()]);
- $res ? $this->success('操作成功') : $this->error('操作失败');
- }
- //驳回工单列表
- public function bhTodoList() {
- if (request()->isAjax()) {
- $length = input('rows', 10, 'intval'); //每页条数
- $page = input('page', 1, 'intval'); //第几页
- $start = ($page - 1) * $length; //分页开始位置
- $map[] = ['todo.org_id', '=', $this->orgId];
- $map[] = ['todo.del', '=', 0];
- $map[] = ['todo.todo_mode', '=', 4];
- $map[] = ['todo.work_type_mode', '=', 3];
- $totalCount = Db::name('todo')
- ->alias('todo')
- ->join('orders orders', 'orders.id = todo.order_id')
- ->join('order_convey oc', 'oc.order_id = orders.id')
- ->join('user u', 'u.id = todo.to_user_id')
- ->where($map)
- ->count();
- $totalPage = ceil($totalCount / $length);
- $ret = Db::name('todo')
- ->alias('todo')
- ->join('orders orders', 'orders.id = todo.order_id')
- ->join('order_convey oc', 'oc.order_id = orders.id')
- ->join('user u', 'u.id = todo.to_user_id')
- ->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')
- ->order('oc.xq_time', 'desc')
- ->where($map)
- ->limit($start, $length)
- ->select();
- foreach ($ret as $k => $v) {
- $ret[$k]['start_name'] = $this->gettablefield('address', array('id' => $v['start']), 'title');
- $ret[$k]['end_name'] = $this->gettablefield('address', array('id' => $v['end']), 'title');
- $ret[$k]['type_name'] = $this->gettablefield('convey_cate', array('id' => $v['type']), 'title');
- $ret[$k]['real_name'] = $this->gettablefield('user', array('id' => $v['user_id']), 'real_name');
- $ret[$k]['device_name'] = '';
- if ($v['device_id'] > 0) {
- $ret[$k]['device_name'] = $this->gettablefield('convey_device', array('id' => $v['device_id']), 'title');
- }
- $last = strtotime($v['ywc_time']) - time();
- $ret[$k]['last_time'] = $last > 0 ? round($last / 60) : 0;
- $ret[$k]['reject_time'] = $v['reject_time'] ? date('Y-m-d h:i', strtotime($v['reject_time'])) : '';
- }
- $result['page'] = $page;
- $result['total'] = $totalPage;
- $result['records'] = $totalCount;
- $result['rows'] = $ret;
- return json($result);
- }
- else {
- return $this->fetch();
- }
- }
- //excel导出
- public function export($mode) {
- set_time_limit(0);
- ini_set("memory_limit", "1024M");
- $meta_title = '订单列表';
- if ($mode == 1) {
- $meta_title = '报修' . $meta_title;
- }
- elseif ($mode == 2) {
- $meta_title = '保洁' . $meta_title;
- }
- elseif ($mode == 3) {
- $meta_title = '运送' . $meta_title;
- }
- elseif ($mode == 4) {
- $meta_title = '应急' . $meta_title;
- }
- elseif ($mode == 15) {
- $meta_title = '品质整改' . $meta_title;
- }elseif ($mode == -1) {
- $meta_title = '一键呼叫' . $meta_title;
- }
- $level1 = check_is_dispatch($this->userId);
- $level2 = check_two_dispatch($this->userId);
- $turnoff = two_dispatch_off($this->orgId);
- $quality_type = input('quality_type','');
- if (request()->isGet()) {
- //排序
- $sortRow = input('sidx', 'a.id', 'trim'); //排序列
- $sort = input('sord', 'desc', 'trim'); //排序方式
- $order = $sortRow . ' ' . $sort;
- $content = input('content', '', 'trim');
- if ($content) {
- $map[] = ['a.content', 'like', '%' . $content . '%'];
- }
- $dep_id = input('dep_id', '', 'trim');
- if ($dep_id != '') {
- $map[] = ['a.dep_id', '=', $dep_id];
- }
- $order_mode = input('order_mode', '', 'trim');
- $map6 = [];
- if ($order_mode != '') {
- if($level1 && $turnoff && $mode != 15){ // 一级调度且二级调度开关开着,品质整改例外
- if ($order_mode == 1) {
- $map[] = ['a.is_deal', '=', 0];
- }else if ($order_mode == 4) {
- $map6[] = ['a.is_deal', '=', 1];
- }
- }
- if($order_mode==100){//已挂起
- $gq = Db::name('todo')
- ->where('work_type_mode',1)
- ->where('todo_mode',2)
- ->where('pause',1)
- ->column('order_id');
- if(empty($gq)){
- $map[] = ['a.id', '=', -1];
- }else{
- $map[] = ['a.id', 'in', $gq];
- }
- }else{
- $map[] = ['a.order_mode', '=', $order_mode];
- }
- }
- $b = input('start', '', 'trim');
- $e = input('end', '', 'trim');
- if ($b) {
- // $b = date('Ymd', strtotime($b));
- // $map[] = ['a.create_yyyymmdd', '>=', $b];
- $map[] = ['a.create_time', '>=', $b];
- }
- if ($e) {
- // $e = date('Ymd', strtotime($e));
- // $map[] = ['a.create_yyyymmdd', '<=', $e];
- $map[] = ['a.create_time', '<=', $e];
- }
- $map[] = ['a.del', '=', 0];
- $map[] = ['a.org_id', '=', $this->orgId];
- if($mode==-1){
- $map[] = ['a.source_type', '=', 4];
- }
- $type = input('type', '', 'trim');
- $oids = [];
- if ($type != '') {
- $map1[] = ['parent_id', '=', $type];
- $type_id = Db::name('order_type')
- ->where($map1)
- ->where('org_id', $this->orgId)
- ->where('enable', 1)
- ->column('id');
- if (!empty($type_id)) {
- $map3[] = ['type_id', 'in', $type_id];
- $ids = Db::name('order_repair')
- ->where($map3)
- ->column('order_id');
- if (!empty($ids)) {
- $oids = $ids;
- }
- else {
- $oids = [];
- }
- }
- else {
- $oids = [];
- }
- }
- $typeName = input('typeName', '', 'trim');
- if ($typeName != '') {
- $map_11[] = ['a.title', 'like', '%'.$typeName.'%'];
- $typeNameId = Db::name('convey_cate')
- ->alias('a')
- ->join('order_convey b','a.id=b.type')
- ->where($map_11)
- ->where('a.org_id', $this->orgId)
- ->where('a.enable', 1)
- ->where('a.del', 0)
- ->column('b.order_id');
- if (!empty($typeNameId)) {
- $map[] = ['a.id', 'in', $typeNameId];
- }
- else {
- $map[] = ['a.id', '=', -1];
- }
- }
- if($level2 && $turnoff){ // 二级调度
- $roles_id = Db::name('user_roles')
- ->where('user_id', $this->userId)
- ->value('roles_id');
- $ids = Db::name('dispatch_log')
- ->where('roles_id', $roles_id)
- ->whereOr('to_user_id', $this->userId)
- ->column('order_id');
- if (empty($ids)) {
- $map[] = ['a.id', '=', -1];
- } else {
- if($type != ''){
- $oids = array_intersect($oids,$ids);
- if($oids){
- $map[] = ['a.id', 'in', $oids];
- }else{
- $map[] = ['a.id', '=', -1];
- }
- }else{
- $map[] = ['a.id', 'in', $ids];
- }
- }
- }else{
- if($type != ''){
- if($oids){
- $map[] = ['a.id', 'in', $oids];
- }else{
- $map[] = ['a.id', '=', 0];
- }
- }
- }
- if($mode == 15){ // 品质检查,单独处理
- $map[] = ['a.work_type_mode','=',$mode];
- if($quality_type !=''){
- $map[] = ['a.quality_type','=',$quality_type];
- }
- }else{
- $work_type_mode = input('work_type_mode','','trim');
- if(!is_admin($this->userId)){
- $auth = get_dispatch_auth($this->userId);
- if($auth){
- $map[] = ['a.work_type_mode', 'in', $auth];
- if($mode > 0){
- $map[] = ['a.work_type_mode', '=', $mode];
- }else{
- if($work_type_mode!=''){
- $map[] = ['a.work_type_mode','=',$work_type_mode];
- }
- }
- }else{
- $map[] = ['a.work_type_mode', '=', -1];
- }
- }else{
- if($mode > 0){
- $map[] = ['a.work_type_mode', '=', $mode];
- }else{
- if($work_type_mode!=''){
- $map[] = ['a.work_type_mode','=',$work_type_mode];
- }
- }
- }
- }
- $sn = input('sn', '', 'trim');
- if ($sn) {
- $map[] = ['a.sn', 'like', '%' . $sn . '%'];
- }
- $from = input('from', '', 'trim');
- if ($from) {
- if($from >3){
- $map[] = ['a.from','=',0];
- $map[] = ['a.work_type_mode','=',$from-3];
- }else{
- $map[] = ['a.from','=',$from];
- }
- }
- $dep_cate = input('dep_cate', '', 'trim');
- if ($dep_cate != '') {
- $depIds = Db::name('dep')
- ->where('org_id',$this->orgId)
- ->where('cate_id',$dep_cate)
- ->where('del',0)
- ->column('id');
- if(!empty($depIds)){
- $map[] = ['a.dep_id', 'in', $depIds];
- }else{
- $map[] = ['a.dep_id', '=', -1];
- }
- }
- $priority = input('priority', '', 'trim');
- if($priority !=''){
- $map[] = ['b.priority', '=',$priority];
- }
- $sddr = input('saddr','','trim');
- if($sddr !=''){
- $map[] = ['b.start','=',$sddr];
- }
- $eddr = input('eaddr','','trim');
- if($eddr !=''){
- $map[] = ['b.end','=',$eddr];
- }
- $toUserName = input('toUserName','','trim');
- if($toUserName !=''){
- $ooids = Db::name('user')
- ->alias('u')
- ->join('todo t','t.to_user_id=u.id')
- ->where('t.del',0)
- ->where('t.org_id',$this->orgId)
- ->where('u.real_name',$toUserName)
- ->column('t.order_id');
- if($ooids){
- $map[] = ['a.id','in',$ooids];
- }else{
- $map[] = ['a.id','=',-1];
- }
- }
- $conveyCateId = input('conveyCateId','','trim');
- if($conveyCateId !=''){
- $typeNameId = Db::name('convey_cate')
- ->alias('a')
- ->join('order_convey b','a.id=b.type')
- ->where('a.org_id', $this->orgId)
- ->where('a.enable', 1)
- ->where('a.del', 0)
- ->where('a.id', $conveyCateId)
- ->column('b.order_id');
- if (!empty($typeNameId)) {
- $map[] = ['a.id', 'in', $typeNameId];
- }else {
- $map[] = ['a.id', '=', -1];
- }
- }
- $map = empty($map) ? true : $map;
- //数据查询
- if($mode==3){
- $lists = db($this->table)->where($map)
- ->alias('a')
- ->leftJoin('order_convey b','a.id=b.order_id')
- ->leftJoin('address ad','b.start=ad.id')
- ->leftJoin('address ade','b.end=ade.id')
- ->leftJoin('convey_cate cc','b.type=cc.id')
- ->leftJoin('convey_device cd','b.device_id=cd.id')
- ->leftJoin('dep dp','a.dep_id=dp.id')
- // ->leftJoin('dep_cate dc','dp.cate_id=dc.id')
- ->leftJoin('order_mode om','a.order_mode=om.id')
- ->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')
- ->whereOr($map6)
- ->order($order)
- ->select();
- foreach ($lists as $k => $v) {
- // $lists[$k] = $this->model->newFormatOrder($v);
- $lists[$k]['priority'] = isset($this->model->priority[$v['priority']])?$this->model->priority[$v['priority']]:"";
- $lists[$k]['task_priority'] = $v['priority']==3?2:0;
- $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');
- if ($turnoff && $level1 && $v['order_mode'] == 1 && $v['is_deal'] == 1) {
- $lists[$k]['order_mode_text'] = '已派发';
- }
- }
- }else{
- $lists = db($this->table)->where($map)
- ->alias('a')
- ->leftJoin('order_convey b','a.id=b.order_id')
- ->field('a.*,b.priority')
- ->whereOr($map6)
- ->order($order)->select();
- foreach ($lists as $k => $v) {
- $lists[$k] = $this->model->newFormatOrder($v);
- $lists[$k]['priority'] = isset($this->model->priority[$v['priority']])?$this->model->priority[$v['priority']]:"";
- if ($turnoff && $level1 && $v['order_mode'] == 1 && $v['is_deal'] == 1) {
- $lists[$k]['order_mode_text'] = '已派发';
- }
- }
- }
- include_once env('root_path') . '/extend/phpexcel/Classes/PHPExcel.php';
- //实例化PHPExcel类
- $objPHPExcel = new \PHPExcel();
- //激活当前的sheet表
- $objPHPExcel->setActiveSheetIndex(0);
- //设置表格头(即excel表格的第一行)
- if ($mode == 1) {
- $objPHPExcel->setActiveSheetIndex(0)
- ->setCellValue('A1', '编号')
- ->setCellValue('B1', '申请时间')
- ->setCellValue('C1', '内容')
- ->setCellValue('D1', '所在科室/部门')
- ->setCellValue('E1', '报修类型')
- ->setCellValue('F1', '状态')
- ->setCellValue('G1', '紧急程度')
- ->setCellValue('H1', '来源')
- ->setCellValue('I1', '物料名称')
- ->setCellValue('J1', '单价')
- ->setCellValue('K1', '数量')
- ->setCellValue('L1', '总价');
- }
- else {
- if ($mode == 3) {
- $objPHPExcel->setActiveSheetIndex(0)
- ->setCellValue('A1', '编号')
- ->setCellValue('B1', '申请时间')
- ->setCellValue('C1', '开始地点')
- ->setCellValue('D1', '结束地点')
- ->setCellValue('E1', '运送类型')
- ->setCellValue('F1', '任务备注')
- ->setCellValue('G1', '所在科室/部门')
- ->setCellValue('H1', '状态')
- ->setCellValue('I1', '来源')
- ->setCellValue('J1', '优先级');
- }
- else {
- if($mode==0){
- $objPHPExcel->setActiveSheetIndex(0)
- ->setCellValue('A1', '编号')
- ->setCellValue('B1', '申请时间')
- ->setCellValue('C1', '内容')
- ->setCellValue('D1', '所在科室/部门')
- ->setCellValue('E1', '状态')
- ->setCellValue('F1', '订单类型')
- ->setCellValue('G1', '来源');
- }else{
- if($mode==15){
- $objPHPExcel->setActiveSheetIndex(0)
- ->setCellValue('A1', '编号')
- ->setCellValue('B1', '申请时间')
- ->setCellValue('C1', '内容')
- ->setCellValue('D1', '所在科室/部门')
- ->setCellValue('E1', '状态')
- ->setCellValue('F1', '来源')
- ->setCellValue('H1', '部门分类');
- }else{
- $objPHPExcel->setActiveSheetIndex(0)
- ->setCellValue('A1', '编号')
- ->setCellValue('B1', '申请时间')
- ->setCellValue('C1', '内容')
- ->setCellValue('D1', '所在科室/部门')
- ->setCellValue('E1', '状态')
- ->setCellValue('F1', '来源');
- }
- }
- }
- }
- // 设置表格头水平居中
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('A1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('B1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('C1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('D1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('E1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('F1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('G1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('H1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- //设置列水平居中
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('A')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('B')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('C')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('D')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('E')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('F')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('G')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('H')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- //设置单元格宽度
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('A')->setWidth(10);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('B')->setWidth(20);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('C')->setWidth(20);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('D')->setWidth(20);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('E')->setWidth(20);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('F')->setWidth(50);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('G')->setWidth(20);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('H')->setWidth(20);
- //循环刚取出来的数组,将数据逐一添加到excel表格。
- if ($mode == 1) {
- // halt($lists);
- for ($i = 0; $i < count($lists); $i++) {
- $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $lists[$i]['sn']);
- $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $lists[$i]['create_time']);
- $objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $lists[$i]['content']);
- $objPHPExcel->getActiveSheet()->setCellValue('D' . ($i + 2), $lists[$i]['dep']);
- $objPHPExcel->getActiveSheet()->setCellValue('E' . ($i + 2), $lists[$i]['order_type']);
- $objPHPExcel->getActiveSheet()->setCellValue('F' . ($i + 2), $lists[$i]['order_mode_text']);
- $objPHPExcel->getActiveSheet()->setCellValue('G' . ($i + 2), $lists[$i]['repair_priority']);
- $objPHPExcel->getActiveSheet()->setCellValue('H' . ($i + 2), $lists[$i]['source_type_text']);
- $goodsName = $goodsPrice = $goodsNum = $goodsTotal = '';
- if(empty($lists[$i]['cons'])){
- $objPHPExcel->getActiveSheet()->setCellValue('I' . ($i + 2), "");
- $objPHPExcel->getActiveSheet()->setCellValue('J' . ($i + 2), "");
- $objPHPExcel->getActiveSheet()->setCellValue('K' . ($i + 2), "");
- $objPHPExcel->getActiveSheet()->setCellValue('L' . ($i + 2), "");
- }else{
- $objPHPExcel->getActiveSheet()->getStyle('I'.($i + 2))->getAlignment()->setWrapText(true);
- $objPHPExcel->getActiveSheet()->getStyle('J'.($i + 2))->getAlignment()->setWrapText(true);
- $objPHPExcel->getActiveSheet()->getStyle('K'.($i + 2))->getAlignment()->setWrapText(true);
- $objPHPExcel->getActiveSheet()->getStyle('L'.($i + 2))->getAlignment()->setWrapText(true);
- foreach ($lists[$i]['cons'] as $kk=>$vv){
- // $consstr[] = $vv['title'].'_'.$vv['total'].'_'.$vv['money']."_".$vv['total_money']."_".$vv['realName'];
- $goodsName.= $vv['title']."\r\n";
- $goodsPrice.= $vv['money']."\r\n";
- $goodsNum.= $vv['total']."\r\n";
- $goodsTotal.= $vv['total_money']."\r\n";
- }
- $objPHPExcel->getActiveSheet()->setCellValue('I' . ($i + 2), $goodsName);
- $objPHPExcel->getActiveSheet()->setCellValue('J' . ($i + 2), $goodsPrice);
- $objPHPExcel->getActiveSheet()->setCellValue('K' . ($i + 2), $goodsNum);
- $objPHPExcel->getActiveSheet()->setCellValue('L' . ($i + 2), $goodsTotal);
- }
- }
- }
- else {
- if ($mode == 3) {
- for ($i = 0; $i < count($lists); $i++) {
- $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $lists[$i]['sn']);
- $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $lists[$i]['create_time']);
- $objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $lists[$i]['start_name']);
- $objPHPExcel->getActiveSheet()->setCellValue('D' . ($i + 2), $lists[$i]['end_name']);
- $objPHPExcel->getActiveSheet()->setCellValue('E' . ($i + 2), $lists[$i]['type_name']);
- $objPHPExcel->getActiveSheet()->setCellValue('F' . ($i + 2), $lists[$i]['content']);
- $objPHPExcel->getActiveSheet()->setCellValue('G' . ($i + 2), $lists[$i]['dep']);
- $objPHPExcel->getActiveSheet()->setCellValue('H' . ($i + 2), $lists[$i]['order_mode_text']);
- $objPHPExcel->getActiveSheet()->setCellValue('I' . ($i + 2), $lists[$i]['source_type_text']);
- $objPHPExcel->getActiveSheet()->setCellValue('J' . ($i + 2), $lists[$i]['priority']);
- }
- }
- else {
- if($mode==0){
- for ($i = 0; $i < count($lists); $i++) {
- $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $lists[$i]['sn']);
- $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $lists[$i]['create_time']);
- $objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $lists[$i]['content']);
- $objPHPExcel->getActiveSheet()->setCellValue('D' . ($i + 2), $lists[$i]['dep']);
- $objPHPExcel->getActiveSheet()->setCellValue('E' . ($i + 2), $lists[$i]['order_mode_text']);
- $objPHPExcel->getActiveSheet()->setCellValue('F' . ($i + 2), $lists[$i]['work_type_mode_text']);
- $objPHPExcel->getActiveSheet()->setCellValue('G' . ($i + 2), $lists[$i]['source_type_text']);
- }
- }else{
- if($mode==15){
- for ($i = 0; $i < count($lists); $i++) {
- $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $lists[$i]['sn']);
- $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $lists[$i]['create_time']);
- $objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $lists[$i]['content']);
- $objPHPExcel->getActiveSheet()->setCellValue('D' . ($i + 2), $lists[$i]['dep']);
- $objPHPExcel->getActiveSheet()->setCellValue('E' . ($i + 2), $lists[$i]['order_mode_text']);
- $objPHPExcel->getActiveSheet()->setCellValue('F' . ($i + 2), $lists[$i]['source_type_text']);
- $objPHPExcel->getActiveSheet()->setCellValue('G' . ($i + 2), $lists[$i]['quality_cate_name']);
- }
- }else{
- for ($i = 0; $i < count($lists); $i++) {
- $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $lists[$i]['sn']);
- $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $lists[$i]['create_time']);
- $objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $lists[$i]['content']);
- $objPHPExcel->getActiveSheet()->setCellValue('D' . ($i + 2), $lists[$i]['dep']);
- $objPHPExcel->getActiveSheet()->setCellValue('E' . ($i + 2), $lists[$i]['order_mode_text']);
- $objPHPExcel->getActiveSheet()->setCellValue('F' . ($i + 2), $lists[$i]['source_type_text']);
- }
- }
- }
- }
- }
- //设置保存的Excel表格名称
- $filename = $meta_title . '_' . date('YmdHis', time()) . '.xls';
- //设置当前激活的sheet表格名称
- $objPHPExcel->getActiveSheet()->setTitle($meta_title);
- //设置浏览器窗口下载表格
- ob_end_clean();
- header("Content-Type: application/force-download");
- header("Content-Type: application/octet-stream");
- header("Content-Type: application/download");
- header('Content-Disposition:inline;filename="' . $filename);
- //生成excel文件
- $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
- //下载文件在浏览器窗口
- return $objWriter->save('php://output');
- }
- }
- public function rejectTodoList(){
- $orderId = input('orderId',0);
- if (request()->isAjax()) {
- $length = input('rows', 10, 'intval'); //每页条数
- $page = input('page', 1, 'intval'); //第几页
- $start = ($page - 1) * $length; //分页开始位置
- $map[] = ['org_id','=',$this->orgId];
- $map[] = ['del','=',0];
- $map[] = ['todo_mode','=',4];
- $map[] = ['order_id','=',$orderId];
- $lists = Db::name('todo')
- ->where($map)
- ->limit($start,$length)
- ->order('id desc')
- ->select();
- $workTypeMode = [
- '0'=>'一键呼叫',
- '1'=>'报修',
- '2'=>'保洁',
- '3'=>'运送',
- '4'=>'应急',
- ];
- foreach ($lists as $k=>$v){
- $lists[$k]['to_user_name'] = Db::name('user')->where('id',$v['to_user_id'])->value('real_name');
- $lists[$k]['work_type_mode_text'] = $workTypeMode[$v['work_type_mode']];
- $lists[$k]['todo_mode_in_content'] = Db::name('todo_mode')->where('id',$v['todo_mode'])->value('in_content');
- $lists[$k]['todo_mode_color'] = Db::name('todo_mode')->where('id',$v['todo_mode'])->value('color');
- }
- $totalCount = Db::name('todo')
- ->where($map)
- ->count();
- $totalPage = ceil($totalCount / $length);
- $result['page'] = $page;
- $result['total'] = $totalPage;
- $result['records'] = $totalCount;
- $result['rows'] = $lists;
- return json($result);
- }
- else {
- $this->assign('orderId',$orderId);
- return $this->fetch();
- }
- }
- public function orderRefreshOff(){
- $info = Db::name('config')->where('name','org_order_refresh')
- ->find();
- $orgConfig = Db::name('config_org')
- ->where('config_id',$info['id'])
- ->where('org_id',$this->orgId)
- ->find();
- if($orgConfig){
- $value = $orgConfig['value']==1?0:1;
- $res = Db::name('config_org')
- ->where('config_id',$info['id'])
- ->where('org_id',$this->orgId)
- ->update(['value'=>$value]);
- }else{
- $value = 1;
- $res = Db::name('config_org')
- ->insertGetId([
- 'config_id'=>$info['id'],
- 'org_id'=>$this->orgId,
- 'value'=>$value,
- ]);
- }
- $res?$this->success('操作成功','',['status'=>$value]):$this->error('操作失败');
- }
- public function print1($id){
- $order = Db::name('orders')->where(['id' => $id])->find();
- $depName = Db::name('dep')
- ->where('id',$order['dep_id'])
- ->value('title');
- $info['depName'] = $depName;
- $info['create_time'] = $order['create_time'];
- $users = Db::name('todo')
- ->alias('t')
- ->join('user u','u.id=t.to_user_id')
- ->where('t.order_id',$order['id'])
- ->column('u.real_name');
- $info['users'] = $users?implode(',',$users):'';
- $info['content'] = $order['content'];
- $info['cons'] = [];
- $tList = Db::name('todo')
- ->where('order_id',$order['id'])
- ->select();
- $total = $totalPrice = 0;
- $signs = [];
- foreach ($tList as $k=>$v){
- if($v['sign']){
- $signs[] = $v['sign'];
- }
- $mate = Db::name('todo_mate_item')
- ->alias('tmi')
- ->join('todo_mate tm','tmi.todo_mate_id = tm.id')
- ->join('mate_goods mg','mg.id = tmi.items_id')
- ->field('tmi.items_id,tmi.total,tmi.money,tmi.total_money,mg.title')
- ->where('tm.todo_id',$v['id'])
- ->select();
- if(!empty($mate)){
- foreach ($mate as $kk=>$todo_mate){
- $info['cons'][] = [
- 'title' =>$todo_mate['title'],
- 'total' =>$todo_mate['total'],
- 'money' =>$todo_mate['money'],
- 'total_money' =>$todo_mate['total_money'],
- ];
- $total +=$todo_mate['total'];
- $totalPrice +=$todo_mate['total_money'];
- }
- }
- }
- $aa = [
- 'title'=>'',
- 'total'=>'',
- 'money'=>'',
- 'total_money'=>'',
- ];
- if(empty($info['cons'])){
- for ($i=1;$i<=4;$i++){
- $info['cons'][] = $aa;
- }
- }elseif (count($info['cons']) <4){
- $ii = 4-count($info['cons']);
- for ($i=1;$i<=$ii;$i++){
- $info['cons'][] = $aa;
- }
- }
- $info['total'] = $total;
- $info['totalPrice'] = round($totalPrice,2);
- $info['signs'] = $signs;
- $this->assign('info', $info);
- return $this->fetch();
- }
- public function withdraw(){
- $id = input('id');
- $info = Db::name('orders')
- ->where('id',$id)
- ->where('del',0)
- ->where('order_mode',4)
- ->find();
- if(!$info){
- $this->error('参数错误');
- }
- $saveOrder = Db::name('orders')
- ->where('id',$id)
- ->update(['order_mode'=>1,'withdraw_time'=>getTime()]);
- $saveTodo = Db::name('todo')
- ->where('order_id',$id)
- ->update(['del'=>1]);
- $todoIds = Db::name('todo')
- ->where('order_id',$id)
- ->where('todo_mode',1)
- ->column('id');
- $task = Db::name('task')
- ->where('type',1)
- ->whereIn('bus_id',$todoIds)
- ->delete();
- if($info['work_type_mode'] == 3){
- Db::name('order_convey_end')->where('order_id',$info['id'])->setField('del',0);
- }
- if(!$saveOrder){
- $this->error('操作失败');
- }
- $this->success('操作成功');
- }
- public function autoSend($id,$form=0) {
- if(request()->isGet() && $form==0){
- $order_type = (new \app\common\model\OrderType())->getList();
- $order_repair = Db::name('order_repair')
- ->where('order_id', $id)
- ->find();
- $this->assign('order_repair', $order_repair);
- $this->assign('order_type_list',$order_type);
- $this->assign('id',$id);
- return $this->fetch();
- }else{
- $type_id = input('type_id/d','');
- if(!empty($type_id)){
- $old = Db::name('order_repair')
- ->where('order_id', $id)
- ->find();
- $rData['type_id'] = $type_id;
- if ($old) {
- $rData['update_time'] = getTime();
- Db::name('order_repair')
- ->where('order_id', $id)
- ->update($rData);
- }
- else {
- $rData['order_id'] = $id;
- Db::name('order_repair')
- ->insert($rData);
- }
- }
- $res = $this->model->autoSend($id);
- if (!$res) {
- $this->error($this->model->getError());
- }
- $this->success('操作成功');
- }
- }
- public function setType($id) {
- if(request()->isGet()){
- $order_type = (new \app\common\model\OrderType())->getList();
- $order_repair = Db::name('order_repair')
- ->where('order_id', $id)
- ->find();
- $this->assign('order_repair', $order_repair);
- $this->assign('order_type_list',$order_type);
- $this->assign('id',$id);
- return $this->fetch();
- }else{
- $type_id = input('type_id/d','');
- if(empty($type_id)){
- $this->error('请选择报修事项');
- }
- $old = Db::name('order_repair')
- ->where('order_id', $id)
- ->find();
- $rData['type_id'] = $type_id;
- if ($old) {
- $rData['update_time'] = getTime();
- $r = Db::name('order_repair')
- ->where('order_id', $id)
- ->update($rData);
- }
- else {
- $rData['order_id'] = $id;
- $r = Db::name('order_repair')
- ->insert($rData);
- }
- $r?$this->success('操作成功'):$this->error('操作失败');
- }
- }
- public function batchSb(){
- $id = input('ids',[]);
- if(!$id){
- $this->error('参数错误');
- }
- $res = db('user')->where('id','in',$id)->setField('work',1);
- if($res){
- $this->success('操作成功');
- }else{
- $this->error('操作失败');
- }
- }
- public function batchXb(){
- $id = input('ids',[]);
- if(!$id){
- $this->error('参数错误');
- }
- $res = db('user')->where('id','in',$id)->setField('work',0);
- if($res){
- $this->success('操作成功');
- }else{
- $this->error('操作失败');
- }
- }
- public function getTime(){
- $type = input('type');
- $start = input('start');
- $v = Db::name('convey_cate')
- ->where('id',$type)
- ->where('enable',1)
- ->where('del',0)
- ->find();
- if($v['time_id'] > 0){
- $time = Db::name('time')
- ->where('id',$v['time_id'])
- ->find();
- $v['xq_time'] = $start?$start:date('Y-m-d H:i');
- $v['ywc_time'] = date('Y-m-d H:i',strtotime($v['xq_time']) + 60*$time['bz_time']);
- }else{
- $v['xq_time'] = $start?$start:date('Y-m-d H:i');
- $v['ywc_time'] = '';
- }
- $this->success('','',$v);
- }
- }
|