Note.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <?php
  2. namespace app\bug\controller;
  3. use app\bug\model\Moudel;
  4. use app\user\model\Account;use think\facade\Db;
  5. use think\App;use think\facade\Validate;
  6. class Note extends Base
  7. {
  8. // protected $noLogin=[];
  9. public function __construct(App $app)
  10. {
  11. parent::__construct($app);
  12. $this->model= new \app\bug\model\Note();
  13. }
  14. public function create(){
  15. $param = $this->request->param(["title"=>"","remark"=>"","company_type"=>"","model_id"=>[],"noteNo"=>"",
  16. "level"=>2,"weight"=>1,"type"=>2,"status"=>0,"submit"=>1],"post","trim");
  17. $valid =Validate::rule([
  18. "title|标题"=>"require|max:255",
  19. "remark|描述"=>"require|max:255",
  20. "company_type|公司平台类别"=>"require|max:255",
  21. "model_id|模块分类"=>"require",
  22. ]);
  23. if($valid->check($param)==false)return error($valid->getError());
  24. $bugNo= makeNo("BG");
  25. $data=[
  26. "model_id"=>!empty($model_id) ? array_pop($model_id):"0",
  27. "bugNo"=>$bugNo,
  28. "noteNo"=>$param['noteNo'],
  29. "title"=>$param['title'],
  30. "remark"=>$param['remark'],
  31. "company_type"=>$param['company_type'],
  32. "apply_name"=>$this->uid,
  33. "apply_id"=>$this->uname,
  34. "level"=>$param['level'],
  35. "type"=>$param['type'],
  36. "submit"=>$param['submit'],
  37. "weight"=>$param['weight'],
  38. "status"=>$param['status']
  39. ];
  40. $create = \app\bug\model\Note::create($data);
  41. if($create->isEmpty()) return error("创建失败");
  42. return success("创建成功");
  43. }
  44. public function list(){
  45. $param = $this->request->param([
  46. 'bugNo'=>'','is_created'=>'','company_type'=>'','model_id'=>'','noteNo'=>'','page'=>1,'size'=>10,
  47. 'apply_name'=>'','type'=>'','status'=>'','start'=>'','end'=>'','level'=>'',"deal_name"=>"","title"=>""],
  48. 'post','trim');
  49. $where =[['is_del','=',0]];
  50. if($param['bugNo']!=""){
  51. $where[]=['bugNo',"like","%{$param['bugNo']}%"];
  52. }
  53. if($param['model_id']!=""){
  54. $where[]=['model_id',"=",$param['model_id']];
  55. }
  56. if($param['noteNo']!=""){
  57. $where[]=['noteNo',"like","%{$param['noteNo']}%"];
  58. }
  59. if($param['company_type']!=""){
  60. $where[]=['company_type',"=",$param['company_type']];
  61. }
  62. if($param['apply_name']!==""){
  63. $where[]=['apply_name',"like","%{$param['apply_name']}%"];
  64. }
  65. $status = $param['status'];
  66. if($status!==""){
  67. if($status<8){
  68. $where[]=['status',"=",$status];
  69. }elseif ($status==8){
  70. $where[]=['status',"<=",$status];
  71. $where[]=['status',"not in",[4,5]];
  72. }elseif ($status===9){
  73. }elseif ($status===10){
  74. $str = Db::name('deal')->where(['action_id'=>$this->uid,'is_del'=>0])->select()->toArray();
  75. $data =array_unique(array_column($str,'bugNo')) ;
  76. $where[]=['bugNo',"in",$data];
  77. }elseif ($status===11){
  78. $var = Db::name('deal')->where(['deal_id'=>$this->uid,'is_del'=>0,'status'=>0])->select()->toArray();
  79. $da =array_unique(array_column($var,'bugNo')) ;
  80. $where[]=['bugNo',"in",$da];
  81. }
  82. }
  83. if($param['is_created']==1){
  84. $where[]=['apply_id',"=",$this->uid];
  85. }
  86. if($param['start']!==""){
  87. $where[]=['addtime',">=",startTime($param['start'])];
  88. }
  89. if($param['end']!==""){
  90. $where[]=['addtime',"<",endTime($param['end'])];
  91. }
  92. if($param['title']!==""){
  93. $where[]=['title',"like","%{$param['title']}%"];
  94. }
  95. if($param['level']!==""){
  96. $where[]=['level','=',$param['level']];
  97. }
  98. if($param['type']!==""){
  99. $where[]=['type','=',$param['type']];
  100. }
  101. if ($param['deal_name']!==""){
  102. $item = \app\bug\model\Deal::where([["deal_name","like","%{$param['deal_name']}%"],["is_del","=",0],['status',"=",0]])
  103. ->select()
  104. ->toArray();
  105. $cn =array_unique(array_column($item,'bugNo'));
  106. $where[]=["bugNo","in",$cn];
  107. }
  108. $list = $this->model->where($where)->order('addtime desc')->paginate(["list_rows"=>$param['size'],
  109. "page"=>$param['page']]);
  110. $appLyid= array_column($list->items(),"apply_id");
  111. $bugArr= array_column($list->items(),"bugNo");
  112. $departByUid=(new \app\bug\model\DepartUser())->GetDepartNameByUid($appLyid);
  113. $dealArr = \app\bug\model\Deal::where([["bugNo","in",$bugArr],["status","=",0],["is_del","=",0]])->column
  114. ("deal_name","bugNo");
  115. foreach ($list->items() as &$value){
  116. $value['deal_name']=$dealArr[$value['bugNo']]??"";
  117. $value['can']=Moudel::GetModelByCid($value['model_id']);
  118. $value['company_name']=$departByUid[$value['apply_id']]??"";
  119. $data[]=$value;
  120. }
  121. return success("获取成功",['list'=>$list->items(),'count'=>$list->total()]);
  122. }
  123. public function edit(){
  124. $param = $this->request->param(["id"=>"",'title'=>'','remark'=>'','company_type'=>'','model_id'=>[],'noteNo'=>'',
  125. 'level'=>1,'weight'=>0,'type'=>0,'status'=>0,"deal_id"=>""],'post','trim');
  126. $valid =Validate::rule([
  127. 'id|标题Id'=>'require|number|gt:0',
  128. 'title|标题'=>'require|max:255',
  129. 'remark|描述'=>'require|max:255',
  130. 'company_type|公司平台类别'=>'require|max:255',
  131. 'model_id|模块分类'=>'',
  132. 'level|优先级'=>'require|number|in:1,2,3',
  133. 'type|问题类型'=>'require|number',
  134. ]);
  135. if($valid->check($param)==false)return error($valid->getError());
  136. $info=$this->model->where(['id'=>$param['id'],'is_del'=>0])->findOrEmpty();
  137. if($info->isEmpty())return error("未找到数据");
  138. $inf=\app\bug\model\Deal::where(['bugNo'=>$info['bugNo'],'status'=>0,"is_del"=>0])->findOrEmpty();
  139. $oldStatus=$info->status;
  140. $deal = Account::with(["user_info"])->where("id",$param['deal_id'])->findOrEmpty();
  141. $this->model->startTrans();
  142. try{
  143. $info->title= $param['title'];
  144. $info->noteNo= $param['noteNo'];
  145. $info->remark= $param['remark'];
  146. $info->model_id= !empty($model_id)?array_pop( $param['model_id']):0;
  147. $info->company_type= $param['company_type'];
  148. $info->level= $param['level'];
  149. $info->type= $param['type'];
  150. $info->weight= $param['weight'];
  151. $info->status= $param['status'];
  152. $datainfo =$info->save();
  153. if($datainfo){
  154. $inf->action_id=$this->uid;
  155. $inf->action_name=$this->uname;
  156. $inf->deal_id=$param['deal_id'];
  157. $inf->deal_name=$deal->nickname??"";
  158. $inf->bugNo=$info->bugNo;
  159. $info->level= 1;
  160. $info->type= 1;
  161. $inf->status=$oldStatus!=$param['status']?1:0;
  162. $dc = $inf->save();
  163. if($dc==false)throw new \Exception("更新失败");
  164. }else throw new \Exception('更新失败');
  165. $this->model->commit();
  166. return success("更新成功");
  167. }catch (\Exception $e){
  168. $this->model->rollback();
  169. return error($e->getMessage());
  170. }
  171. }
  172. public function info(){
  173. $id=$this->request->post("id/d");
  174. $info = $this->model->where(['id'=>$id,'is_del'=>0])->findOrEmpty();
  175. $departByUid=(new \app\bug\model\DepartUser())->GetDepartNameByUid($info->apply_id);
  176. $item = \app\bug\model\Deal::where(['bugNo'=>$info['bugNo'],'is_del'=>0,'status'=>0])->findOrEmpty();
  177. $info['deal_id']=isset($item['deal_id']) ? $item['deal_id']:"";
  178. $info['deal_name']=isset($item['deal_name']) ? $item['deal_name']:"";
  179. $info['can']= Moudel::GetModelByCid($info['model_id']);
  180. $info['company_name']=$departByUid[$info->apply_id]??"";
  181. $info['model_id']=array_column($info['can'],"id");
  182. if($info->isEmpty()) return error("未找到数据");
  183. return success("获取成功",$info);
  184. }
  185. public function del(){
  186. $id=$this->request->post('id/d');
  187. $info = $this->model->where(['id'=>$id,'is_del'=>0])->findOrEmpty();
  188. if($info->isEmpty()) return error('未找到数据');
  189. $info->is_del=1;
  190. $del=$info->save();
  191. return $del ? success("删除成功") :error("删除失败");
  192. }
  193. }