Training.php 2.2 KB

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