Proposal.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use app\common\model\ProposalModel;
  5. use think\Db;
  6. /**
  7. * 报修与建议
  8. */
  9. class Proposal extends Api
  10. {
  11. protected $noNeedLogin = ['proposalType','proposalInfo'];
  12. protected $noNeedRight = ['*'];
  13. /**
  14. * 报修与建议
  15. * @param string $page 页数
  16. * @param string $limit 条数
  17. */
  18. public function proposalType()
  19. {
  20. $page = $this->request->get('page');
  21. $limit = $this->request->get('limit');
  22. if (!$page) {
  23. $pages = '0,10';
  24. } else {
  25. $page = $page - 1;
  26. if ($page<0) $page = 0;
  27. $pages = $page.','.$limit;
  28. }
  29. $proposalModel = new ProposalModel();
  30. $data = $proposalModel->where('switch',1)
  31. ->limit($pages)
  32. ->order('sort desc')
  33. ->select();
  34. if ($data) {
  35. return $this->success('',$data);
  36. } else {
  37. return $this->success('',[]);
  38. }
  39. }
  40. /**
  41. * 报修与建议详情
  42. * @param string $id id
  43. */
  44. public function proposalInfo()
  45. {
  46. $id = $this->request->get('id');
  47. $proposalModel = new ProposalModel();
  48. $data = $proposalModel
  49. ->where('id',$id)
  50. ->find();
  51. if ($data) {
  52. return $this->success('', $data);
  53. } else {
  54. return $this->success('暂无数据');
  55. }
  56. }
  57. /**
  58. * 保修与建议提交
  59. * @ApiMethod (POST)
  60. * @param string $tid 报修id
  61. * @param string $images 配图多图,号拼接
  62. * @param string $str 文字
  63. */
  64. public function proposalSub()
  65. {
  66. $data = $this->request->post();
  67. if (!isset($data['tid']) || empty($data['tid'])) return $this->error('请选择所报修内容');
  68. if (!isset($data['images'])) return $this->error('参数错误');
  69. if (!isset($data['str'])) return $this->error('参数错误');
  70. if (empty($data['images']) && empty($data['str'])) return $this->error('文字和图片最少输入一样');
  71. $user = $this->auth->getUser();
  72. if (!$user) return $this->error(__('Please login first'), null, 401);
  73. $data['uid'] = $user['id'];
  74. $data['create_time'] = date('Y-m-d H:i:s');
  75. $add = Db::name('proposal_info')->insert($data);
  76. if ($add) {
  77. return $this->success('提交成功');
  78. } else {
  79. return $this->error('提交失败');
  80. }
  81. }
  82. /**
  83. * 报修反馈
  84. * @ApiMethod (POST)
  85. * @param string $notice 文字
  86. */
  87. public function fankui()
  88. {
  89. $notice = $this->request->post('notice');
  90. if (!isset($notice) || empty($notice)) return $this->error('请输入要提交的内容');
  91. $user = $this->auth->getUser();
  92. if (!$user) return $this->error(__('Please login first'), null, 401);
  93. $data['uid'] = $user['id'];
  94. $data['create_time'] = date('Y-m-d H:i:s');
  95. $data['notice'] = $notice;
  96. $isert = Db::name('proposal_fankui')->where('uid',$user['id'])->where('notice',$data['notice'])->find();
  97. if ($isert) return $this->error('您已经反馈过了');
  98. $add = Db::name('proposal_fankui')->insert($data);
  99. if ($add) {
  100. return $this->success('提交成功');
  101. } else {
  102. return $this->error('提交失败');
  103. }
  104. }
  105. }