Training.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use liuniu\UtilService;
  5. use think\Request;
  6. use app\common\model\training\{Training as TrainingModel,TrainingInfo,Volunteer};
  7. class Training extends Api
  8. {
  9. protected $noNeedRight = ['*'];
  10. public function lst()
  11. {
  12. $where = UtilService::getMore(
  13. [
  14. ['status',1],
  15. ['page',1],
  16. ['limit',10],
  17. ]
  18. );
  19. return $this->success('获取成功',TrainingModel::lst($where));
  20. }
  21. public function apply(Request $request)
  22. {
  23. $where = UtilService::postMore(
  24. [
  25. ['training_id',0],
  26. ['user_id',$this->auth->getUserinfo()['id']],
  27. ['cid',$this->cid],
  28. ['name',''],
  29. ['Phone',''],
  30. ['num',0],
  31. ],$request
  32. );
  33. if($where['training_id']==0) $this->error('活动编号不能为空');
  34. if($where['name']=='') $this->error('姓名不能为空');
  35. if($where['Phone']=='') $this->error('电话不能为空');
  36. if($where['num']==0) $this->error('人数不能为0');
  37. if(TrainingInfo::Where('training_id',$where['training_id'])->where('user_id',$where['user_id'])->find()) $this->error('已报名,不能重复报名!');
  38. $rs = TrainingInfo::create($where);
  39. $this->success('创建成功',$rs);
  40. }
  41. public function mylst(Request $request)
  42. {
  43. $where = UtilService::getMore(
  44. [
  45. ['cid',$this->cid],
  46. ['user_id',$this->auth->getUserinfo()['id']],
  47. ['page',1],
  48. ['limit',10],
  49. ]
  50. );
  51. return $this->success('获取成功',TrainingInfo::lst($where));
  52. }
  53. public function view()
  54. {
  55. $id = input('id',0);
  56. if($id==0) $this->error('参数错误!');
  57. $rs = TrainingModel::info($id);
  58. if(!$rs)$this->error(TrainingModel::getErrorInfo());
  59. return $this->success('获取成功',$rs);
  60. }
  61. }