Training.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. public function lst()
  10. {
  11. $where = UtilService::getMore(
  12. [
  13. ['status',1],
  14. ['page',1],
  15. ['limit',10],
  16. ]
  17. );
  18. return $this->success('获取成功',TrainingModel::lst($where));
  19. }
  20. public function apply(Request $request)
  21. {
  22. $where = UtilService::postMore(
  23. [
  24. ['training_id',0],
  25. ['user_id',$this->auth->getUserinfo()['id']],
  26. ['cid',$this->cid],
  27. ['name',''],
  28. ['Phone',''],
  29. ['num',0],
  30. ],$request
  31. );
  32. if($where['training_id']==0) $this->error('活动编号不能为空');
  33. if($where['name']=='') $this->error('姓名不能为空');
  34. if($where['Phone']=='') $this->error('电话不能为空');
  35. if($where['num']==0) $this->error('人数不能为0');
  36. if(TrainingInfo::Where('training_id',$where['training_id'])->where('user_id',$where['user_id'])->find()) $this->error('已报名,不能重复报名!');
  37. $rs = TrainingInfo::create($where);
  38. $this->success('创建成功',$rs);
  39. }
  40. public function mylst(Request $request)
  41. {
  42. $where = UtilService::getMore(
  43. [
  44. ['cid',$this->cid],
  45. ['user_id',$this->auth->getUserinfo()['id']],
  46. ['page',1],
  47. ['limit',10],
  48. ]
  49. );
  50. return $this->success('获取成功',TrainingInfo::lst($where));
  51. }
  52. public function view()
  53. {
  54. $id = input('id',0);
  55. if($id==0) $this->error('参数错误!');
  56. $rs = TrainingModel::info($id);
  57. if(!$rs)$this->error(TrainingModel::getErrorInfo());
  58. return $this->success('获取成功',$rs);
  59. }
  60. }