123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use app\common\model\ProposalModel;
- use think\Db;
- /**
- * 报修与建议
- */
- class Proposal extends Api
- {
- protected $noNeedLogin = ['proposalType','proposalInfo'];
- protected $noNeedRight = ['*'];
- /**
- * 报修与建议
- * @param string $page 页数
- * @param string $limit 条数
- */
- public function proposalType()
- {
- $page = $this->request->get('page');
- $limit = $this->request->get('limit');
- if (!$page) {
- $pages = '0,10';
- } else {
- $page = $page - 1;
- if ($page<0) $page = 0;
- $pages = $page.','.$limit;
- }
- $proposalModel = new ProposalModel();
- $data = $proposalModel->where('switch',1)
- ->limit($pages)
- ->order('sort desc')
- ->select();
- if ($data) {
- return $this->success('',$data);
- } else {
- return $this->success('',[]);
- }
- }
- /**
- * 报修与建议详情
- * @param string $id id
- */
- public function proposalInfo()
- {
- $id = $this->request->get('id');
- $proposalModel = new ProposalModel();
- $data = $proposalModel
- ->where('id',$id)
- ->find();
- if ($data) {
- return $this->success('', $data);
- } else {
- return $this->success('暂无数据');
- }
- }
- /**
- * 保修与建议提交
- * @ApiMethod (POST)
- * @param string $tid 报修id
- * @param string $images 配图多图,号拼接
- * @param string $str 文字
- */
- public function proposalSub()
- {
- $data = $this->request->post();
- if (!isset($data['tid']) || empty($data['tid'])) return $this->error('请选择所报修内容');
- if (!isset($data['images'])) return $this->error('参数错误');
- if (!isset($data['str'])) return $this->error('参数错误');
- if (empty($data['images']) && empty($data['str'])) return $this->error('文字和图片最少输入一样');
- $user = $this->auth->getUser();
- if (!$user) return $this->error(__('Please login first'), null, 401);
- $data['uid'] = $user['id'];
- $data['create_time'] = date('Y-m-d H:i:s');
- $add = Db::name('proposal_info')->insert($data);
- if ($add) {
- return $this->success('提交成功');
- } else {
- return $this->error('提交失败');
- }
- }
- /**
- * 报修反馈
- * @ApiMethod (POST)
- * @param string $notice 文字
- */
- public function fankui()
- {
- $notice = $this->request->post('notice');
- if (!isset($notice) || empty($notice)) return $this->error('请输入要提交的内容');
- $user = $this->auth->getUser();
- if (!$user) return $this->error(__('Please login first'), null, 401);
- $data['uid'] = $user['id'];
- $data['create_time'] = date('Y-m-d H:i:s');
- $data['notice'] = $notice;
- $isert = Db::name('proposal_fankui')->where('uid',$user['id'])->where('notice',$data['notice'])->find();
- if ($isert) return $this->error('您已经反馈过了');
- $add = Db::name('proposal_fankui')->insert($data);
- if ($add) {
- return $this->success('提交成功');
- } else {
- return $this->error('提交失败');
- }
- }
- }
|