Training.php 2.2 KB

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