GreenRecord.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. namespace app\api\controller\v1;
  3. use app\api\controller\Base;
  4. use app\common\model\Roles;
  5. use app\common\util\AppAuth;
  6. use app\hander\HelpHander;
  7. use think\Db;
  8. class GreenRecord extends Base
  9. {
  10. public function addRecord(){
  11. $addrId = input('addrId');
  12. $cateId = input('cateId');
  13. $content = input('content','','trim');
  14. $imgs = input('imgs','','trim');
  15. if(!$addrId){
  16. HelpHander::error('地点不能为空');
  17. }
  18. if(!$cateId){
  19. HelpHander::error('分类不能为空');
  20. }
  21. if(!$content){
  22. HelpHander::error('汇报内容不能为空');
  23. }
  24. if(!$imgs){
  25. HelpHander::error('汇报图片不能为空');
  26. }
  27. $data = [
  28. 'org_id'=>$this->orgId,
  29. 'user_id'=>$this->userId,
  30. 'content'=>$content,
  31. 'images'=>$imgs,
  32. 'create_time'=>date('Y-m-d H:i:s'),
  33. 'create_yyyy'=>date('Y'),
  34. 'create_yyyymm'=>date('Ym'),
  35. 'create_yyyymmdd'=>date('Ymd'),
  36. 'green_addr_id'=>$addrId,
  37. 'green_cate_id'=>$cateId,
  38. ];
  39. $add = Db::name('green_record')->insert($data);
  40. if($add){
  41. HelpHander::success('操作成功');
  42. }else{
  43. HelpHander::error('操作失败');
  44. }
  45. }
  46. public function recordList(){
  47. $page = input('page',1);
  48. $size = input('size',10);
  49. $type = input('type/d',0);
  50. $addId = input('greenAddrId');
  51. if(!$addId){
  52. HelpHander::error('地点不存在');
  53. }
  54. if($type == 1){ // 查看全部记录
  55. $auth = (new Roles())->getAppAuth($this->userId,AppAuth::GREEN_LOOK_ALL_AUTH);
  56. if(!$auth){ // 无权限
  57. $m[] = ['user_id','=',-1];
  58. }
  59. }else{ // 查看个人记录
  60. $m[] = ['user_id','=',$this->userId];
  61. }
  62. $m[] = ['org_id','=',$this->orgId];
  63. $m[] = ['green_addr_id','=',$addId];
  64. $list = Db::name('green_record')
  65. ->field('id,create_time,user_id,green_cate_id')
  66. ->where($m)
  67. ->page($page,$size)
  68. ->order('id desc')
  69. ->select();
  70. foreach ($list as $k=>$v){
  71. $list[$k]['user_name'] = Db::name('user')
  72. ->where('id',$v['user_id'])
  73. ->value('real_name');
  74. $list[$k]['cate_name'] = Db::name('green_cate')
  75. ->where('id',$v['green_cate_id'])
  76. ->value('title');
  77. }
  78. HelpHander::success($list);
  79. }
  80. public function details(){
  81. $id = input('id',0);
  82. $info = Db::name('green_record')
  83. ->where('id',$id)
  84. ->find();
  85. if(!$info){
  86. HelpHander::error('参数错误');
  87. }
  88. $addr = Db::name('green_addr')->where('id',$info['green_addr_id'])->find();
  89. $info['addr_name'] = $addr?$addr['title']:'';
  90. $info['addr_img'] = $addr?$addr['img']:'';
  91. $info['addr_content'] =$addr? $addr['content']:'';
  92. $info['cate_name'] = Db::name('green_cate')
  93. ->where('id',$info['green_cate_id'])
  94. ->value('title');
  95. $info['user_name'] = Db::name('user')
  96. ->where('id',$info['user_id'])
  97. ->value('real_name');
  98. HelpHander::success($info);
  99. }
  100. }