123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332 |
- <?php
- namespace app\api\controller\v1;
- use app\api\controller\Base;
- use app\common\util\AppMsg;
- use app\hander\HelpHander;
- use think\Controller;
- use think\Db;
- use think\Exception;
- class ModeCate extends Base
- {
- public function list(){
- $lists = Db::name('mode_cate')
- ->where('del',0)
- ->where('enable',1)
- ->where('org_id',$this->orgId)
- ->order('sort desc,id desc')
- ->select();
- foreach ($lists as $k=>$v){
- if($v['mode'] == 2){
- $atable = 'cleaning_type b';
- }else{
- $atable = 'convey_cate b';
- }
- $typeList = Db::name('mode_cate_type')
- ->alias('a')
- ->field('b.id,b.title,b.color')
- ->join($atable,'b.id=a.bus_id')
- ->where('a.mode',$v['mode'])
- ->where('a.cate_id',$v['id'])
- ->order('a.sort desc,a.id desc')
- ->select();
- $lists[$k]['type_list'] = $typeList?$typeList:[];
- }
- HelpHander::success($lists);
- }
- public function addOrder(){
- $mode = input('mode');
- $typeId = input('typeId',0);
- if(!in_array($mode,[2,3])){
- HelpHander::error('参数错误');
- }
- if($typeId < 1){
- HelpHander::error('参数错误');
- }
- $addrId = Db::name('user')->where('id',$this->userId)->value('addr_id');
- if($addrId < 1){
- HelpHander::error('始发空间不能为空');
- }
- $addrInfo = Db::name('address')->where('id',$addrId)->find();
- $bjToUserId = $addrInfo['bj_user_id'] ?$addrInfo['bj_user_id']:0;
- $ysToUserId = $addrInfo['ys_user_id'] ?$addrInfo['ys_user_id']:0;
- $toUserId = 0;
- $content = '';
- if($mode == 2){
- $content = Db::name('cleaning_type')->where('del',0)->where('id',$typeId)->value('title');
- if(!$bjToUserId){
- HelpHander::error('保洁责任人不能为空');
- }
- $toUserId = $bjToUserId;
- }elseif($mode == 3){
- $conveyCate = Db::name('convey_cate')->where('del',0)->where('is_sss',1)->where('id',$typeId)->find();
- if(!$conveyCate){
- HelpHander::error('类型不存在');
- }
- $content = $conveyCate['title'];
- if(!$ysToUserId){
- HelpHander::error('运送责任人不能为空');
- }
- $toUserId = $ysToUserId;
- if($conveyCate['addr_id'] < 1){
- HelpHander::error('地点不能为空');
- }
- if($addrId == $conveyCate['addr_id']){
- HelpHander::error('开始地点和结束地点不能一致');
- }
- }
- // $depId = Db::name('user_dep')
- // ->alias('ud')
- // ->join('dep d','d.id=ud.dep_id')
- // ->where('d.del',0)
- // ->where('ud.user_id',$this->userId)
- // ->value('d.id');
- $odata = [
- 'org_id'=>$this->orgId,
- 'user_id'=>$this->userId,
- 'create_time' => getTime(),
- 'create_yyyy' => date('Y'),
- 'create_yyyymm' => date('Ym'),
- 'create_yyyymmdd' => date('Ymd'),
- 'sn' => get_unique_sn(get_config('sn_prefix')),
- 'content' => $content,
- 'work_type_mode' => $mode,
- 'order_mode'=>4,
- 'source_type' => 2,
- 'dep_id' => 0,
- 'send_time' => getTime(),
- 'is_deal' => 1,
- 'from' => 0,
- ];
- Db::startTrans();
- try {
- $orderId = Db::name('orders')->insertGetId($odata);
- if(!$orderId){
- \exception('订单生成失败');
- }
- if($mode == 2){
- $octData = [
- 'order_id'=>$orderId,
- 'type_id'=>$typeId,
- 'create_time'=>getTime()
- ];
- $oct = Db::name('order_clean_type')->insert($octData);
- if(!$oct){
- \exception('订单保洁类型扩展生成失败');
- }
- }
- if($mode == 3){
- $conveyCateInfo = Db::name('convey_cate')->where('del',0)->where('id',$typeId)->find();
- $time = Db::name('time')->where('del',0)->where('id',$conveyCateInfo['time_id'])->find();
- $ywcTime = time() + $time['bz_time']*60;
- if($conveyCateInfo['type'] == 0){
- $saddr = $addrId;
- $eaddr = $conveyCateInfo['addr_id'];
- }else{
- $saddr = $conveyCateInfo['addr_id'];
- $eaddr = $addrId;
- }
- $ocData = [
- 'order_id'=>$orderId,
- 'type'=>$typeId,
- 'start'=>$saddr,
- 'end'=>$eaddr,
- 'xq_time'=>getTime(),
- 'ywc_time'=>date('Y-m-d H:i:s',$ywcTime),
- 'score'=>$conveyCateInfo['score'],
- 'priority'=>0,
- ];
- $ocAdd = Db::name('order_convey')->insert($ocData);
- if(!$ocAdd){
- \exception('运送扩展生成失败');
- }
- }
- $todoData = [
- 'order_id' => $orderId,
- 'todo_content' => $content,
- 'create_user_id' => $this->userId,
- 'org_id' => $this->orgId,
- 'create_time' => getTime(),
- 'confirm_time' => getTime(),
- 'todo_mode' => 2,
- 'work_type_mode' => $mode,
- 'create_yyyy' => date('Y'),
- 'create_yyyymm' => date('Ym'),
- 'create_yyyymmdd' => date('Ymd'),
- 'quality_type' => 0,
- 'to_user_id'=>$toUserId,
- 'sn'=> get_unique_sn(get_config('sn_prefix')),
- ];
- $todoId = Db::name('todo')->insertGetId($todoData);
- if(!$todoId){
- \exception('分派订单失败');
- }
- $taskData = [
- 'org_id' => $this->orgId,
- 'type' => 1,
- 'start_time' => getTime(),
- 'create_time' => getTime(),
- 'user_id' => $toUserId,
- 'bus_id' => $todoId,
- ];
- $res = Db::name('task')
- ->insert($taskData);
- if (!$res) {
- \exception('任务保存失败');
- }
- send_jpush([$toUserId],AppMsg::PUSH_WORKER_ORDER_SEND,'',['id'=>$todoId]);
- Db::commit();
- }catch (\Exception $e){
- Db::rollback();
- HelpHander::error($e->getMessage());
- }
- HelpHander::success([],'操作成功');
- }
- public function getTodoList(){
- $type = input('type',0);
- $page = input('page',1);
- $size = input('size',10);
- if(!in_array($type,[0,1])){
- HelpHander::error('参数错误');
- }
- $map[] = ['org_id','=',$this->orgId];
- $map[] = ['del','=',0];
- $map[] = ['create_user_id','=',$this->userId];
- $map[] = ['work_type_mode','in',[2,3]];
- if($type == 0){
- $map[] = ['todo_mode','=',2];
- }else{
- $map[] = ['todo_mode','in',[3,6]];
- }
- $list = Db::name('todo')
- ->where($map)
- ->page($page,$size)
- ->order('id','desc')
- ->select();
- $data = [];
- foreach ($list as $k=>$v){
- $data[$k]['id'] = $v['id'];
- $data[$k]['work_type_mode'] = $v['work_type_mode'];
- $data[$k]['create_time'] = $v['create_time'];
- $data[$k]['todo_content'] = $v['todo_content'];
- $data[$k]['order_id'] = $v['order_id'];
- $data[$k]['todo_mode'] = $v['todo_mode'];
- $data[$k]['done_time'] = $v['done_time'];
- $touser = Db::name('user')->where('id',$v['to_user_id'])->find();
- $data[$k]['to_user_name'] = $touser['real_name'];
- $addrName = Db::name('address')->where('id',$touser['addr_id'])->value('title');
- $data[$k]['s_addr'] = $addrName ?$addrName :'';
- $data[$k]['todo_mode_text'] = Db::name('todo_mode')->where('id',$v['todo_mode'])->value('out_content');
- $data[$k]['work_type_mode_text'] = Db::name('work_type_mode')->where('id',$v['work_type_mode'])->value('name');
- $data[$k]['type_name'] = '';
- $data[$k]['e_addr'] = '';
- $data[$k]['last_addr'] = '';
- $data[$k]['last_addr_time'] = '';
- if($v['work_type_mode'] == 2){
- $typeTitle = Db::name('cleaning_type')
- ->alias('ct')
- ->join('order_clean_type oct','oct.type_id=ct.id')
- ->where('oct.order_id',$v['order_id'])
- ->value('ct.title');
- $data[$k]['type_name'] = $typeTitle ? $typeTitle :'';
- }
- if($v['work_type_mode'] == 3){
- $typeInfo = Db::name('convey_cate')
- ->alias('cc')
- ->field('oc.*,cc.title')
- ->join('order_convey oc','oc.type=cc.id')
- ->where('oc.order_id',$v['order_id'])
- ->find();
- if($typeInfo){
- $saddr = Db::name('address')->where('id',$typeInfo['start'])->value('title');
- $eaddr = Db::name('address')->where('id',$typeInfo['end'])->value('title');
- $data[$k]['type_name'] = $typeInfo ? $typeInfo['title'] :'';
- $data[$k]['s_addr'] = $saddr ? $saddr :'';
- $data[$k]['e_addr'] = $eaddr ? $eaddr :'';
- $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', $v['to_user_id'])
- ->where('os.del', 0)
- ->where('ods.del', 0)
- ->order('os.id desc')
- ->find();
- if(in_array($addr['todo_mode'],[1,2])){
- $data[$k]['last_addr'] = $addr['start_name'];
- }else{
- $data[$k]['last_addr'] = $addr['end_name'];
- }
- $data[$k]['last_addr_time'] = $addr['create_time'];
- }
- }
- }
- HelpHander::success($data,'操作成功');
- }
- 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','');
- $rejectVoice = input('rejectVoice','');
- $ret = model('Todo')->updateState($todoId,$todoMode,$nodoReason,$this->userId,$rejectVoice);
- if(!$ret){
- HelpHander::error(model('Todo')->getError());
- }
- HelpHander::success([],'操作成功');
- }
- }
|