123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400 |
- <?php
- namespace app\admin\controller;
- use app\admin\model\NoteLog;
- use app\BaseController;
- use think\console\command\Make;
- use think\facade\Db;
- use think\App;
- class Note extends BaseController
- {
- public $post="";
- public function __construct(App $app)
- {
- parent::__construct($app);
- $this->post = $this->request->post();
- }
- public function create(){
- $token = isset($this->post['token']) && $this->post['token'] !=="" ?trim($this->post['token']):"";
- if($token==""){
- return error_show(101,'token不能为空');
- }
- $title = isset($this->post['title']) && $this->post['title']!==""? trim($this->post['title']):"";
- if($title==""){
- return error_show(1002,"参数title不能为空");
- }
- $remark = isset($this->post['remark']) && $this->post['remark']!==""? trim($this->post['remark']):"";
- if($remark==""){
- return error_show(1002,"参数remark不能为空");
- }
- $company_type= isset($this->post['company_type']) && $this->post['company_type']!==""? trim($this->post['company_type']):"";
- if($company_type==""){
- return error_show(1002,"参数company_type不能为空");
- }
- $model_id= isset($this->post['model_id']) && $this->post['model_id']!==""? $this->post['model_id']:[];
- $noteNo= isset($this->post['noteNo']) && $this->post['noteNo'] !==""? $this->post['noteNo']:"";
- $bugNo= makeNo("BG");
- $apply_id =VerifyTokens($token);
- if(empty($apply_id)||$apply_id['code']!=0){
- return error_show($apply_id['code'],$apply_id['message']);
- }
- $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
- $ri= isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
- $tem=[];
- $tem['bugNo']=$bugNo;
- $tem['title']="";
- $tem['level']="";
- $tem['status']="";
- $tem['remark']="";
- $tem['noteNo']="";
- //$tem['company_type']="";
- $tem['deal_name']="";
- $tem['type']="";
- //array_column($in,"id");
- $tem['model_id']="";
- $level= isset($this->post['level']) && $this->post['level']!==""? intval($this->post['level']):"2";
- $type= isset($this->post['type']) && $this->post['type']!==""? intval($this->post['type']):"2";
- $weight= isset($this->post['weight']) && $this->post['weight']!==""? trim($this->post['weight']):"";
- $status= isset($this->post['status']) && $this->post['status']!==""? intval($this->post['status']):"0";
- $submit = isset($this->post['submit']) && $this->post['submit']!==""? intval($this->post['submit']):"1";
- $data=[
- "model_id"=>!empty($model_id) ? array_pop($model_id):"0",
- "bugNo"=>$bugNo,
- "noteNo"=>$noteNo,
- "title"=>$title,
- "remark"=>$remark,
- "company_type"=>$company_type,
- "apply_name"=>$ri,
- "apply_id"=>$rm,
- "level"=>$level,
- "type"=>$type,
- "submit"=>$submit,
- "weight"=>$weight,
- "status"=>$status,
- "is_del"=>0,
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- $datainfo= Db::name('note')->insert($data);
- if($datainfo){
- NoteLog::log($tem,$this->post,1);
- return error_show(0,"新建成功");
- }else{
- return error_show(1002,"新建失败");
- }
- }
- public function list(){
- $token = isset($this->post['token']) && $this->post['token'] !=="" ?trim($this->post['token']):"";
- if($token==""){
- return error_show(101,'token不能为空');
- }
- $page = isset($this->post['page']) && $this->post['page'] !==""? intval($this->post['page']):"1";
- $size = isset($this->post['size']) && $this->post['size'] !==""? intval($this->post['size']):"10";
- $where =[['is_del','=',0]];
- $bugNo =isset($this->post['bugNo']) &&$this->post['bugNo'] !=="" ? trim($this->post['bugNo']):"";
- if($bugNo!=""){
- $where[]=['bugNo',"like","%$bugNo%"];
- }
- $model_id =isset($this->post['model_id']) &&$this->post['model_id'] !=="" ? trim($this->post['model_id']):"";
- if($model_id!=""){
- $where[]=['model_id',"=",$model_id];
- }
- $noteNo =isset($this->post['noteNo']) &&$this->post['noteNo'] !=="" ? trim($this->post['noteNo']):"";
- if($noteNo!=""){
- $where[]=['noteNo',"like","%$noteNo%"];
- }
- $company_type =isset($this->post['company_type']) &&$this->post['company_type'] !=="" ? trim($this->post['company_type']):"";
- if($company_type!=""){
- $where[]=['company_type',"=",$company_type];
- }
- $apply_name = isset($this->post['apply_name']) && $this->post['apply_name'] !==""? trim($this->post['apply_name']):"";
- if($apply_name!==""){
- $where[]=['apply_name',"like","%$apply_name%"];
- }
- $apply_id =VerifyTokens($token);
- if(empty($apply_id)||$apply_id['code']!=0){
- return error_show($apply_id['code'],$apply_id['message']);
- }
- $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
- $status = isset($this->post['status']) && $this->post['status'] !==""? intval($this->post['status']):"";
- $is_created = isset($this->post['is_created']) && $this->post['is_created'] !==""? intval($this->post['is_created']):"0";
- if($status!==""){
- if($status<8){
- $where[]=['status',"=",$status];
- }elseif ($status==8){
- $where[]=['status',"<=",$status];
- $where[]=['status',"<>",5];
- }elseif ($status===9){
- // $where[]=['apply_id',"=",$rm];
- }elseif ($status===10){
- $str = Db::name('deal')->where(['action_id'=>$rm,'is_del'=>0])->select()->toArray();
- $data =array_unique(array_column($str,'bugNo')) ;
- $where[]=['bugNo',"in",$data];
- }elseif ($status===11){
- $var = Db::name('deal')->where(['deal_id'=>$rm,'is_del'=>0,'status'=>0])->select()->toArray();
- $da =array_unique(array_column($var,'bugNo')) ;
- $where[]=['bugNo',"in",$da];
- }
- }
- if($is_created==1){
- $where[]=['apply_id',"=",$rm];
- }
- $start = isset($this->post['start']) && $this->post['start']!=="" ? $this->post['start']:"";
- if($start!==""){
- $where[]=['addtime',">=",date('Y-m-d H:i:s',strtotime($start))];
- }
- $end = isset($this->post['end']) && $this->post['end']!=="" ? $this->post['end']:"";
- if($end!==""){
- $where[]=['addtime',"<",date('Y-m-d H:i:s',strtotime($end)+24*3600)];
- }
- $title = isset($this->post['title']) && $this->post['title'] !==""? intval($this->post['title']):"";
- if($title!==""){
- $where[]=['title',"like","%$title%"];
- }
- $level = isset($this->post['level']) && $this->post['level'] !==""? intval($this->post['level']):"";
- if($level!==""){
- $where[]=['level','=',$level];
- }
- $type = isset($this->post['type']) && $this->post['type'] !==""? intval($this->post['type']):"";
- if($type!==""){
- $where[]=['type','=',$type];
- }
- $deal_name= isset($this->post['deal_name']) && $this->post['deal_name'] !==""? trim($this->post['deal_name']):"";
- if ($deal_name!==""){
- $item = Db::name('deal')->where([["deal_name","like","%$deal_name%"],["is_del","=",0],['status',"=",0]])->select()->toArray();
- $cn =array_unique(array_column($item,'bugNo'));
- $where[]=["bugNo","in",$cn];
- }
- $count = Db::name('note')->where($where)->count();
- $total = ceil($count/$size);
- $page = $page>$total ? $total:$page;
- $list = Db::name('note')->where($where)->page($page,$size)->order("addtime desc")->select();
- $data=[];
- foreach ($list as $value){
- $var = Db::name('depart_user')->alias('a')->join("company_item b","a.itemid = b.id","left")
- ->where(['a.uid'=>$value['apply_id'],'a.is_del'=>0])->column('b.name,b.id');
- $dn=[];
- foreach ($var as $vmp){
- $dn[]=isset($vmp['id']) && $vmp['id'] !=0 ? make($vmp['id']):[];
- }
- //$value['rename'] =$var;
- $str = Db::name("deal")->where(['bugNo'=>$value['bugNo'],'status'=>0,'is_del'=>0])->find();
- $value['deal_id']=isset($str['deal_id']) ?$str['deal_id']:"";
- $value['deal_name']=isset($str['deal_name']) ?$str['deal_name']:"";
- $value['can']= isset($value['model_id']) && $value['model_id'] !=0 ? made($value['model_id']):[];
- $value['company_name']=$dn;
- $data[]=$value;
- }
- return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
- }
- public function edit(){
- $token = isset($this->post['token']) && $this->post['token'] !=="" ?trim($this->post['token']):"";
- if($token==""){
- return error_show(101,'token不能为空');
- }
- $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']):"";
- if($id==""){
- return error_show(1002,"参数id不能为空");
- }
- $info=Db::name('note')->where(['id'=>$id,'is_del'=>0])->find();
- if(empty($info)){
- return error_show(1004,"未找到数据");
- }
- $title = isset($this->post['title']) && $this->post['title']!==""? trim($this->post['title']):"";
- if($title==""){
- return error_show(1002,"参数title不能为空");
- }
- $model_id= isset($this->post['model_id']) && $this->post['model_id']!==""? $this->post['model_id']:[];
- // if(empty($model_id)){
- // return error_show(1002,"参数model_id不能为空");
- // }
- $remark = isset($this->post['remark']) && $this->post['remark']!==""? trim($this->post['remark']):"";
- if($remark==""){
- return error_show(1002,"参数remark不能为空");
- }
- $company_type= isset($this->post['company_type']) && $this->post['company_type']!==""? trim($this->post['company_type']):"";
- if($company_type==""){
- return error_show(1002,"参数company_type不能为空");
- }
- $level= isset($this->post['level']) && $this->post['level']!==""? intval($this->post['level']):"1";
- if($level==""){
- return error_show(1002,"参数level不能为空");
- }
- $status= isset($this->post['status']) && $this->post['status']!==""? intval($this->post['status']):$info['status'];
- $noteNo= isset($this->post['noteNo']) && $this->post['noteNo'] !==""? $this->post['noteNo']:"";
- $type= isset($this->post['type']) && $this->post['type']!==""? intval($this->post['type']):"0";
- if($type===""){
- return error_show(1002,"参数type不能为空");
- }
- $weight= isset($this->post['weight']) && $this->post['weight']!==""? trim($this->post['weight']):"0";
- $inf=Db::name('deal')->where(['bugNo'=>$info['bugNo'],'status'=>0,"is_del"=>0])->find();
- // $deal_name = isset($this->post['deal_name']) && $this->post['deal_name']!=="" ? trim($this->post['deal_name']):"";
- // if($deal_name==""){
- // return error_show(1004,"参数deal_name不能为空");
- // }
- $tem=[];
- $tem['noteNo']=$info['noteNo'];
- $tem['bugNo']=$info['bugNo'];
- $tem['title']=$info['title'];
- $tem['level']=$info['level'];
- $tem['status']=$info['status'];
- $tem['remark']=$info['remark'];
- // $tem['company_type']=$info['company_type'];
- $tem['deal_name']=isset($inf['deal_name']) ? $inf['deal_name']:"";
- $tem['type']=$info['type'];
- //array_column($in,"id");
- $tem['model_id']=$info['model_id'];
- $apply_id =VerifyTokens($token);
- if(empty($apply_id)||$apply_id['code']!=0){
- return error_show($apply_id['code'],$apply_id['message']);
- }
- $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
- $ri= isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
- // $dom = Db::name('manange')->where(['manange_id'=>$rm,'company_id'=>$company_type,'is_del'=>0])->find();
- // if ($info['status']!=$status){
- // if($dom==false){
- // return error_show(1002,"无权限修改");
- // }
- // }
- $deal_id = isset($this->post['deal_id']) && $this->post['deal_id']!=="" ? intval($this->post['deal_id']):"";
- $this->post['deal_name']='';
- $datai=[];
- if($deal_id!==""){
- // if($dom==false){
- // return error_show(1002,"无权限修改");
- // }
- // $stn = Db::name('manange')->where(['manange_id'=>$deal_id,'company_id'=>$company_type,'is_del'=>0])->find();
- // if($stn==false){
- // return error_show(1002,"处理人不存在");
- // }
- $to= GetInfoById($token,['id'=>$deal_id]);
- if((!empty($to) && $to['code']!=0) ||empty($to) ){
- return error_show($to['code'],"未找到处理人信息");
- }
- $in = $to['data'];
- $this->post['deal_name']=$in['nickname'];
- if(empty($inf)||$info['status']!=$status){
- $datai['deal_id'] = $in['id'];
- $datai['deal_name'] = $in['nickname'];
- $datai['action_id'] =$rm;
- $datai['action_name'] = $ri;
- $datai['bugNo'] = $info['bugNo'];
- $datai['level'] = 1;
- $datai['type'] = 1;
- $datai['status'] =0;
- $datai['is_del'] = 0;
- $datai['addtime'] = date("Y-m-d H:i:s");
- $datai['updatetime'] = date("Y-m-d H:i:s");
- }else{
- $datai['action_id'] =$rm;
- $datai['action_name'] = $ri;
- $datai['id']= $inf['id'];
- $datai['deal_name'] = $in['nickname'];
- $datai['deal_id'] = $in['id'];
- $datai['updatetime'] = date("Y-m-d H:i:s");
- }
- }
- Db::startTrans();
- try{
- $data=[
- "id"=>$id,
- "title"=>$title,
- "noteNo"=>$noteNo,
- "remark"=>$remark,
- //"model_id"=>is_null(array_pop($model_id)) ? array_pop($model_id):"0",
- "model_id"=>!empty($model_id) ? array_pop($model_id):"0",
- "company_type"=>$company_type,
- // "apply_name"=>$ri,
- // "apply_id"=>$rm,
- "level"=>$level,
- "type"=>$type,
- "weight"=>$weight,
- "status"=>$status,
- "is_del"=>0,
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- $datainfo = Db::name('note')->where($info)->save($data);
- if($datainfo){
- if ($info['status']!=$status && $inf!=false){
- $inf['action_id']=$rm;
- $inf['action_name']=$ri;
- $inf['status']=1;
- $inf['updatetime']=date("Y-m-d H:i:s");
- $dc = Db::name('deal')->where(['id'=>$inf['id'],'status'=>0,'is_del'=>0])->save($inf);
- if($dc==false){
- Db::rollback();
- return error_show(1002,"更新失败");
- }
- }
- if(!empty($datai)){
- $dai= Db::name('deal')->save($datai);
- if($dai==false){
- Db::rollback();
- return error_show(1002,"更新失败");
- }
- }
- NoteLog::log($tem,$this->post,2);
- Db::commit();
- return error_show(0,"更新成功");
- }else{
- Db::rollback();
- return error_show(1002,"更新失败");
- }
- }catch (\Exception $e){
- Db::rollback();
- return error_show(1004,$e->getMessage());
- }
- // $item['deal_id']
- }
- public function info(){
- $id=isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']):"";
- if($id=="") {
- return error_show(1002, "参数id不能为空");
- }
- $info = Db::name('note')->where(['id'=>$id,'is_del'=>0])->find();
- $var = Db::name('depart_user')->alias('a')->join("company_item b","a.itemid = b.id","left")
- ->where(['a.uid'=>$info['apply_id'],'a.is_del'=>0])->column('b.name,b.id');
- // $dn=[];
- // foreach ($var as $vmp){
- // $dn[]=isset($vmp['id']) && $vmp['id'] !=0 ? make($vmp['id']):[];
- // }
- $item = Db::name('deal')->where(['bugNo'=>$info['bugNo'],'is_del'=>0,'status'=>0])->find();
- $info['deal_id']=isset($item['deal_id']) ? $item['deal_id']:"";
- $info['deal_name']=isset($item['deal_name']) ? $item['deal_name']:"";
- $in= isset($info['model_id']) && $info['model_id'] !=0 ? made($info['model_id']):[];
- $info['can']=$in;
- $info['company_name']=$var;
- $info['model_id']=array_column($in,"id");
- if(empty($info)){
- return error_show(1002,"未找到数据");
- }else{
- return app_show(0,"获取成功",$info);
- }
- }
- public function del(){
- $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']) :"";
- if($id==""){
- return error_show(1002,"参数id不能为空");
- }
- $info=Db::name('note')->where(['id'=>$id,'is_del'=>0])->find();
- if(empty($info)){
- return error_show(1002,"未找到数据");
- }
- $str['is_del']=1;
- $str['updatetime']=date("Y-m-d H:i:s");
- $info=Db::name('note')->where(['is_del'=>0])->save($str);
- return $info ? app_show(0,"删除成功") :error_show(1002,"删除失败");
- }
- }
|