FeedbackController.class.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace Api\Controller;
  3. use Common\Controller\ApiController;
  4. class FeedbackController extends ApiController {
  5. public function __construct(){
  6. parent::__construct();
  7. }
  8. //反馈类型
  9. public function type(){
  10. $res = M('FeedbackType')->order('type_id asc')->field('type_id,type_name,type_level')->select();
  11. $data = array(
  12. array('grp_id'=>1,'name'=>'单词有误',),
  13. array('grp_id'=>2,'name'=>'例句有误',),
  14. );
  15. foreach ($res as $row){
  16. if ($row['type_level']==1){
  17. $data['0']['options'][] = $row;
  18. }else{
  19. $data['1']['options'][] = $row;
  20. }
  21. }
  22. $data = array('code'=>0,'msg'=>'','data'=>$data);
  23. $this->returnData($data);exit;
  24. }
  25. //添加反馈内容
  26. public function add(){
  27. $typeIds = I('type_ids');
  28. $wordsId = I('words_id');
  29. $courseId = I('course_id');
  30. $fbSource = I('fb_source');
  31. $fbContent = I('fb_content');
  32. if (empty($fbSource) || !in_array($fbSource, array(1,2))){
  33. $data = array('code'=>1,'msg'=>'反馈类型错误');
  34. $this->returnData($data);exit;
  35. }
  36. if ($fbSource==1){
  37. if (empty($wordsId)){
  38. $data = array('code'=>1,'msg'=>'单词ID错误');
  39. $this->returnData($data);exit;
  40. }
  41. if (empty($courseId) || $courseId<1000000){
  42. $data = array('code'=>1,'msg'=>'课程ID错误');
  43. $this->returnData($data);exit;
  44. }
  45. if (mb_strlen($fbContent,'UTF8')<2||mb_strlen($fbContent,'UTF8')>80){
  46. $data = array('code'=>1,'msg'=>'反馈内容2到80个汉字');
  47. $this->returnData($data);exit;
  48. }
  49. $typeIds = rtrim($typeIds, ',');
  50. if (empty($typeIds)){
  51. $data = array('code'=>1,'msg'=>'请选择反馈类型');
  52. $this->returnData($data);exit;
  53. }
  54. $resType = M('FeedbackType')->where(array('type_id'=>array('IN',$typeIds)))->order('type_id asc')->field('type_name')->select();
  55. $typeName = '';
  56. if (function_exists('array_column')){
  57. $typeName = array_column($resType, 'type_name');
  58. }else{
  59. foreach ($resType as $r){
  60. $typeName[] = $r['type_name'];
  61. }
  62. }
  63. $typeNames = '['.implode(',', $typeName).']';
  64. $fbContent = $typeNames.$fbContent;
  65. $saveData = array('words_id'=>$wordsId,'course_id'=>$courseId,'type_ids'=>$typeIds,'fb_content'=>$fbContent);
  66. }else{
  67. $saveData = array('fb_content'=>$fbContent);
  68. }
  69. $saveData['operate_dt'] = time();
  70. $saveData['fb_source'] = $fbSource;
  71. $saveData['user_id'] = $this->userId;
  72. M('Feedback')->add($saveData);
  73. $data = array('code'=>0,'msg'=>'反馈成功','data'=>'');
  74. $this->returnData($data);exit;
  75. }
  76. }