SuperviseRecord.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. namespace app\api\controller\v1;
  3. use app\api\controller\Base;
  4. use app\hander\HelpHander;
  5. use think\App;
  6. use think\Db;
  7. class SuperviseRecord extends Base
  8. {
  9. public function add(){
  10. $data = [
  11. 'org_id'=>$this->orgId,
  12. 'user_id'=>$this->userId,
  13. 'supervise_id'=>input('superviseId',0),
  14. 'content'=>input('content','','trim'),
  15. 'create_time'=>date('Y-m-d H:i:s'),
  16. ];
  17. if($data['supervise_id'] < 1){
  18. HelpHander::error('参数错误');
  19. }
  20. $content = json_decode($data['content'],true);
  21. if(!$content || count($content) < 1){
  22. HelpHander::error('内容不能为空');
  23. }
  24. $score = 0;
  25. $score1 = 0;//总分
  26. foreach ($content as $k=>$v){
  27. $subscore = 0;
  28. foreach ($v['sub'] as $kk=>$vv){
  29. $score1+=$vv['score'];
  30. $subsubscoreAll = 0;
  31. foreach ($vv['sub'] as $kkk=>$vvv){
  32. $subsubscoreAll +=$vvv['score'];
  33. }
  34. if($vv['scored'] == ''){
  35. HelpHander::error('扣分不能为空');
  36. }else{
  37. if($vv['scored'] < 0){
  38. HelpHander::error('扣分不能为空');
  39. }
  40. }
  41. if($vv['scored'] > $subsubscoreAll){
  42. HelpHander::error('扣分不能大于考核总分值');
  43. }
  44. $subscore +=$vv['scored'];
  45. }
  46. $score +=$subscore;
  47. }
  48. $data['score'] = $score;
  49. $data['score1'] = $score1;
  50. $data['score2'] = $score1-$score;
  51. $add = Db::name('supervise_record')->insert($data);
  52. if(!$add){
  53. HelpHander::error('操作失败');
  54. }
  55. HelpHander::success([],'操作成功');
  56. }
  57. public function list(){
  58. $page = input('page',1);
  59. $size = input('size',10);
  60. $list = Db::name('supervise_record')
  61. ->field('id,score,score1,score2,create_time,org_id,supervise_id')
  62. ->where('user_id',$this->userId)
  63. ->where('del',0)
  64. ->page($page,$size)
  65. ->order('id desc')
  66. ->select();
  67. foreach ($list as $k=>$v){
  68. $list[$k]['org_name'] = Db::name('org')->where('id',$v['org_id'])->value('name');
  69. $list[$k]['supervise_name'] = Db::name('supervise')->where('id',$v['supervise_id'])->value('title');
  70. $list[$k]['score'] = $v['score2'];
  71. }
  72. HelpHander::success($list);
  73. }
  74. public function detail(){
  75. $id = input('id',0);
  76. $info = Db::name('supervise_record')->field('id,org_id,user_id,supervise_id,score,content,create_time')->where('id',$id)->find();
  77. if(!$info){
  78. HelpHander::success('参数错误');
  79. }
  80. $info['supervise_title'] = Db::name('supervise')->where('id',$info['supervise_id'])->value('title');
  81. $info['user_name'] = Db::name('user')->where('id',$info['user_id'])->value('real_name');
  82. $info['org_name'] = Db::name('org')->where('id',$info['org_id'])->value('name');
  83. $info['content'] = json_decode($info['content'] ,true);
  84. HelpHander::success($info);
  85. }
  86. }