Note.php 8.0 KB

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