123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385 |
- <?php
- namespace app\api\controller\v1;
- use app\api\controller\Base;
- use app\common\model\Config;
- use app\common\util\AppMsg;
- use app\hander\HelpHander;
- use think\App;
- use think\Db;
- use think\Exception;
- use think\exception\Handle;
- class Todo extends Base
- {
- public function __construct(App $app = null) {
- parent::__construct($app);
- $this->model = new \app\common\model\Todo();
- }
- //工单列表
- public function lists(){
- $page =input('page',1);
- $size =input('size',10);
- $type =input('type',0);
- $list = $this->model->lists($page,$size,$this->userId,$this->orgId,$type);
- HelpHander::success($list);
- }
- //工单详情
- public function detail(){
- $todoId =input('todoId',0);
- $info = $this->model->apiDetail($todoId);
- HelpHander::success($info);
- }
- // 处理驳回工单
- public function createNtbo(){
- $todoId = input('todoId');
- $toUserIdArray =input('toUserIdArray');
- $todoContent = input('todoContent');
- $typeId = input('typeId/d',0);
- $addressId = input('addressId/d',0);
- if(!$toUserIdArray){
- HelpHander::error('未选择执行人');
- }
- $ret = $this->model->createNtbo($todoId,$toUserIdArray,$todoContent,$this->userId,$typeId,$addressId);
- if(!$ret){
- HelpHander::error($this->model->getError());
- }
- HelpHander::success([],'操作成功');
- }
- // 修改状态 2=员工已经接单 4=被驳回 6=调度取消
- public function updateState(){
- $todoId = input('todoId/d',0);
- if($todoId <= 0){
- HelpHander::error('参数错误');
- }
- $todoMode =input('todoMode',0);
- if(!in_array($todoMode,[2,4,6])){
- HelpHander::error('参数错误');
- }
- $nodoReason = input('nodoReason','');
- if($todoMode == 6 && !$nodoReason){
- HelpHander::error('取消原因必需填写');
- }
- $rejectVoice = input('rejectVoice','');
- $ret = $this->model->updateState($todoId,$todoMode,$nodoReason,$this->userId,$rejectVoice);
- if(!$ret){
- HelpHander::error($this->model->getError());
- }
- HelpHander::success([],'操作成功');
- }
- //工单完成
- public function finishTodo(){
- $todoId =input('todoId/d');
- if($todoId <= 0){
- HelpHander::error('参数错误');
- }
- $todoMode = input('todoMode');
- if(!in_array($todoMode,[3,5])){
- HelpHander::error('参数错误');
- }
- $content = input('content');
- $consItems = input('consItems');
- $sign = input('sign');
- $images = input('img');
- if(!$content){
- HelpHander::error('未填写备注');
- }
- $ret = $this->model->finishTodo($todoId,$todoMode,$content,$this->userId,$images,$consItems,$sign);
- if(!$ret){
- HelpHander::error($this->model->getError());
- }
- HelpHander::success([],'操作成功');
- }
- //获取物品列表
- public function getMateGoods(){
- $page =input('page',1);
- $size =input('size',10);
- $title =input('title','','trim');
- $list = $this->model->getMateGoods($this->orgId,$this->userId,$title,$page,$size);
- HelpHander::success($list,'操作成功');
- }
- //收藏/取消收藏物品
- public function favGoods(){
- $type = input('type/d',0);
- $goodsId = input('goodsId/d',0);
- if(empty($goodsId)){
- HelpHander::error('物品不能为空');
- }
- $res = $this->model->favGoods($this->userId,$type,$goodsId);
- $res?HelpHander::success([],'操作成功'):HelpHander::error('操作失败');
- }
- //收藏列表
- public function favList(){
- $title =input('title','','trim');
- $list = $this->model->favList($this->userId,$title);
- HelpHander::success($list,'操作成功');
- }
- // 工单挂起
- public function pause(){
- $id = input('id/d',0);
- $reason = input('reason','','trim');
- if($id <= 0){
- HelpHander::error('参数错误');
- }
- if(!$reason){
- HelpHander::error('未填写挂起原因');
- }
- $todo = Db::name('todo')->where('id',$id)->where('del',0)->find();
- if(!$todo||$todo['to_user_id'] != $this->userId){
- HelpHander::error('工单不存在');
- }
- if($todo['todo_mode'] != 2){
- HelpHander::error('该状态不能挂起');
- }
- if($todo['work_type_mode'] != 1){
- HelpHander::error('该订单不能挂起');
- }
- if($todo['pause'] == 1){
- HelpHander::error('该订单已挂起');
- }
- $data = [
- 'pause' => 1,
- 'pause_time' => date('Y-m-d H:i:s'),
- 'pause_reason' => $reason
- ];
- if($todo['pause_time']){
- unset($data['pause_time']);
- }
- $ret = Db::name('todo')->where('id',$id)->update($data);
- // Db::name('todo_puase')
- // ->insert([
- // 'todo_id'=>$id,
- // 'reason'=>$reason,
- // 'create_time'=>getTime(),
- // ]);
- if(!$ret){
- HelpHander::error('操作失败');
- }
- HelpHander::success([],'操作成功');
- }
- //添加挂起进度
- public function addTodoPuase(){
- $id = input('id/d',0);
- $reason = input('reason','','trim');
- if($id <= 0){
- HelpHander::error('参数错误');
- }
- if(!$reason){
- HelpHander::error('未填写挂起原因');
- }
- $todo = Db::name('todo')->where('id',$id)->where('del',0)->find();
- if(!$todo||$todo['to_user_id'] != $this->userId){
- HelpHander::error('工单不存在');
- }
- if($todo['work_type_mode'] != 1){
- HelpHander::error('该订单不能挂起');
- }
- if($todo['pause'] != 1){
- HelpHander::error('该订单未挂起');
- }
- $ret = Db::name('todo_puase')
- ->insert([
- 'todo_id'=>$id,
- 'reason'=>$reason,
- 'create_time'=>getTime(),
- ]);
- if(!$ret){
- HelpHander::error('操作失败');
- }
- HelpHander::success([],'操作成功');
- }
- //获取待处理已完成已评价工单数量
- public function getOrdersCount(){
- $task = Db::name('task')
- ->where('user_id', $this->userId)
- ->where('org_id', $this->orgId)
- ->where('type',1)
- ->order('id','desc')
- ->select();
- $list = [];
- foreach ($task as $k => $value) {
- if ($value['type'] == 1) {//工单
- $todoInfo = Db::name('todo')
- ->where('id', $value['bus_id'])
- ->find();
- if (!empty($todoInfo)) {
- $list[] = $todoInfo;
- }
- } elseif($value['type'] == 2) {//巡更巡检
- $patrolInfo = Db::name('patrol_task')
- ->where('id', $value['bus_id'])
- ->find();
- if (!empty($patrolInfo)) {
- $list[] = $patrolInfo;
- }
- }elseif ($value['type'] == 3){ // 日常工作
- $dailyInfo = Db::name('daily_task')
- ->where('id', $value['bus_id'])
- ->find();
- if (!empty($dailyInfo)) {
- $list[] = $dailyInfo;
- }
- }elseif ($value['type'] == 4){ // 设备台账
- $deviceInfo = Db::name('device_task')
- ->where('id', $value['bus_id'])
- ->find();
- if (!empty($deviceInfo)) {
- $list[] = $deviceInfo;
- }
- }
- }
- $dcl = count($list);
- $map[] = ['to_user_id','=',$this->userId];
- $map[] = ['org_id','=',$this->orgId];
- $map[] = ['del','=',0];
- $a1 = Db::name('todo')
- ->where($map)
- ->where('todo_mode',3)
- ->count();
- $ywc = $a1?$a1:0;
- $ypj = Db::name('todo')
- ->alias('a')
- ->join('orders b','b.id=a.order_id','left')
- ->where('a.to_user_id',$this->userId)
- ->where('a.del',0)
- ->where('b.del',0)
- ->where('a.org_id',$this->orgId)
- ->where('b.order_mode',6)
- ->count();
- $data = [
- 'dcl'=>$dcl,
- 'ywc'=>$ywc,
- 'ypj'=>$ypj,
- 'pfdd'=>model('Orders')->orderCount($this->userId,$this->orgId,0),
- 'org_grab_order'=>(int)getOrgGrabOrder($this->userId,$this->orgId),
- ];
- HelpHander::success($data);
- }
- //工单挂起结束
- public function pauseEnd(){
- $id = input('id/d',0);
- if($id <= 0){
- HelpHander::error('参数错误');
- }
- $todo = Db::name('todo')->where('id',$id)->where('del',0)->find();
- if(!$todo||$todo['to_user_id'] != $this->userId){
- HelpHander::error('工单不存在');
- }
- if($todo['todo_mode'] != 2){
- HelpHander::error('该状态不能挂起');
- }
- if($todo['work_type_mode'] != 1){
- HelpHander::error('该订单不能挂起');
- }
- if($todo['pause'] != 1){
- HelpHander::error('该订单未挂起不能结束');
- }
- $ret = Db::name('todo')->where('id',$id)->update([
- 'pause' => 2,
- 'pause_end' => date('Y-m-d H:i:s'),
- ]);
- Db::name('todo_puase')
- ->insert([
- 'todo_id'=>$id,
- 'reason'=>'挂起结束',
- 'create_time'=>getTime(),
- ]);
- if(!$ret){
- HelpHander::error('操作失败');
- }
- HelpHander::success([],'操作成功');
- }
- //报修协同
- public function addInviteUser(){
- $toUserIds = input('toUserIds','','trim');
- $todoId = input('todoId','');
- $todo = Db::name('todo')->where('del',0)->where('id',$todoId)->find();
- if(!$todo){
- HelpHander::error('订单不存在');
- }
- if($todo['work_type_mode'] != 1){
- HelpHander::error('其他订单不能协同');
- }
- if(!$toUserIds){
- HelpHander::error('协同人不能为空');
- }
- $order = Db::name('orders')->where('id',$todo['order_id'])->where('del',0)->find();
- if(!$order){
- HelpHander::error('订单不存在');
- }
- $toUserIds = explode(',',$toUserIds);
- Db::startTrans();
- try {
- $xtUserIds = Db::name('todo')
- ->where('order_id',$todo['order_id'])
- ->where('del',0)
- ->column('to_user_id');
- foreach ($toUserIds as $k=>$v){
- if(!$v){
- continue;
- }
- if(in_array($v,$xtUserIds)){
- HelpHander::error('无法邀请人员,他已在此任务中');
- }
- $data = [
- 'order_id'=>$todo['order_id'],
- 'to_user_id'=>$v,
- 'todo_content'=>'',
- 'org_id'=>$this->orgId,
- 'create_user_id'=>$this->userId,
- 'create_time'=>date('Y-m-d H:i:s'),
- 'confirm_time'=>date('Y-m-d H:i:s'),
- 'todo_mode'=>2,
- 'work_type_mode'=>1,
- 'create_yyyy'=>date('Y'),
- 'create_yyyymm'=>date('Ym'),
- 'create_yyyymmdd'=>date('Ymd'),
- ];
- $todoId = Db::name('todo')->insertGetId($data);
- if(!$todoId){
- exception('操作失败');
- }
- $taskData = [
- 'org_id'=>$this->orgId,
- 'user_id'=>$v,
- 'type'=>1,
- 'start_time'=>date('Y-m-d H:i:s'),
- 'create_time'=>date('Y-m-d H:i:s'),
- 'bus_id'=>$todoId,
- ];
- $res = Db::name('task')
- ->insert($taskData);
- if(!$res){
- exception('操作失败1');
- }
- send_jpush([$v],AppMsg::PUSH_WORKER_ORDER_SEND,'',['id'=>$todoId]);
- }
- Db::commit();
- HelpHander::success([],'操作成功');
- } catch (Exception $e) {
- Db::rollback();
- HelpHander::error($e->getMessage());
- }
- }
- }
|