Note.php 9.8 KB

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