Cloud.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. namespace app\bug\controller;
  3. use app\bug\model\Talk;
  4. use think\App;
  5. use think\facade\Validate;
  6. class Cloud extends Base
  7. {
  8. public function __construct(App $app)
  9. {
  10. parent::__construct($app);
  11. $this->model = new \app\bug\model\Note();
  12. }
  13. /** 图片上传
  14. * @return \think\Response|\think\response\Json|void
  15. * @throws \think\Exception
  16. */
  17. public function upload(){
  18. $files = $this->request->file('image');
  19. $list=[];
  20. if($files!=""){
  21. $list = UploadImg($files);
  22. }
  23. if(is_array($list) &&!empty($list)){
  24. return success("上传成功",$list);
  25. }
  26. return error("上传失败");
  27. }
  28. /**问题反馈工单下评论添加
  29. */
  30. public function create(){
  31. $param = $this->request->param(["bugNo"=>'',"talk_note"=>"","status"=>1],"post","trim");
  32. $valid = Validate::rule([
  33. "bugNo|工单编号"=>"require|max:255",
  34. "talk_note|评论内容"=>"require"
  35. ]);
  36. if($valid->check($param)==false) return error($valid->getError());
  37. $str=$this->model->where(["bugNo"=>$param['bugNo']])->findOrEmpty();
  38. if($str->isEmpty())return error("未找到数据");
  39. $data = [
  40. "talk_name"=>$this->uname,
  41. "talk_id"=>$this->uid,
  42. "talk_note"=>$param['talk_note'],
  43. "bugNo"=>$param['bugNo'],
  44. "status"=>$param['status'],
  45. ];
  46. $talk=Talk::create($data);
  47. if($talk->id>0)event('wx_push',['type'=>'talk','data'=>$talk->toArray()]);
  48. return success("添加成功");
  49. }
  50. /** 工单下评论列表
  51. * @return \think\Response|\think\response\Json
  52. * @throws \think\db\exception\DbException
  53. */
  54. public function list(){
  55. $param = $this->request->param(['id'=>'','page'=>1,'size'=>10,"talk_id"=>"","talk_name"=>'',"bugNo"=>'',"start"=>'',"end"=>''],
  56. 'post','trim');
  57. $where=[["is_del","=",0]];
  58. if($param['id']>0){
  59. $bugNo = $this->model->where(["id"=>$param['id']])->value("bugNo",'');
  60. if($bugNo!=''){
  61. $where[]=[['bugNo',"=",$bugNo]];
  62. }
  63. }
  64. $param['talk_id']!==''?? $where[]=['talk_id','=',$param['talk_id']];
  65. $param['talk_name']!==''?? $where[]=['talk_name',"like","%{$param['talk_name']}%"];
  66. $param['bugNo']!==''?? $where[]=['bugNo','like',"%{$param['bugNo']}%"];
  67. $param['start']!==''?? $where[]=['addtime','>=',startTime($param['start'])];
  68. $param['end']!==''?? $where[]=['addtime','<=',endTime($param['end'])];
  69. $list= Talk::where($where)->order("id desc")->paginate(["list_rows"=>$param['size'],"page"=>$param['page']]);
  70. foreach ($list->items() as &$value){
  71. $value['is_edit']=$value['talk_id'] !=$this->uid ?"1":"0";
  72. }
  73. return success("获取成功",['list'=>$list->items(),"count"=>$list->total()]);
  74. }
  75. /**工单下评论编辑
  76. **/
  77. public function edit(){
  78. $param = $this->request->param(['id'=>'','talk_note'=>'','status'=>1],
  79. 'post','trim');
  80. $valid = Validate::rule([
  81. 'id|主键id'=>'require|number|gt:0',
  82. 'talk_note|评论内容'=>'require'
  83. ]);
  84. if($valid->check($param)==false) return error($valid->getError());
  85. $info = Talk::where(["id"=>$param['id'],"is_del"=>0])->findOrEmpty();
  86. if($info->isEmpty())return error("未找到数据");
  87. $info->talk_name = $this->uname;
  88. $info->talk_id = $this->uid;
  89. $info->talk_note = $param['talk_note'];
  90. $info->status = $param['status'];
  91. $datainfo = $info->save();
  92. if($datainfo==false)return error('更新失败');
  93. return success("更新成功");
  94. }
  95. /**工单下评论删除
  96. **/
  97. public function del(){
  98. $id = $this->request->post('id/d');
  99. $info = Talk::where(['id'=>$id,'is_del'=>0])->findOrEmpty();
  100. if($info->isEmpty())return error('未找到数据');
  101. $info->is_del=1;
  102. $datainfo = $info->save();
  103. if($datainfo==false)return error('删除失败');
  104. return success('删除成功');
  105. }
  106. }