Active.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. use addons\epay\library\Service;
  6. /**
  7. * 活动
  8. */
  9. class Active extends Api
  10. {
  11. protected $noNeedLogin = ['lists'];
  12. protected $noNeedRight = ['*'];
  13. public function lists()
  14. {
  15. $where = ['is_show'=>1];
  16. $list = Db::name('active')->field('content',true)->where($where)->order('weigh desc')->autopage()->select();
  17. $list = list_domain_image($list,['image']);
  18. if(!empty($list)){
  19. foreach($list as $key => &$item){
  20. $status_text = '进行中';
  21. $status = 2;
  22. if(time() < $item['activestarttime']){
  23. $status_text = '报名中';
  24. $status = 1;
  25. }
  26. if(time() > $item['activeendtime']){
  27. $status_text = '已结束';
  28. $status = 3;
  29. }
  30. $item['status_text'] = $status_text;
  31. $item['active_status'] = $status;
  32. }
  33. }
  34. $this->success(1,$list);
  35. }
  36. public function info(){
  37. $id = input('id',0);
  38. $info = Db::name('active')->where('is_show',1)->where('id',$id)->find();
  39. if(!$info){
  40. $this->error('不存在的活动');
  41. }
  42. $info = info_domain_image($info,['image']);
  43. //几人已报名
  44. $info['payednumber'] = Db::name('order')->where('active_id',$id)->where('status',1)->count();
  45. $this->success(1,$info);
  46. }
  47. //报名
  48. public function join(){
  49. $remark = input('remark',0);
  50. $active_id = input('id',0);
  51. $info = Db::name('active')->where('is_show',1)->where('id',$active_id)->find();
  52. if(!$info){
  53. $this->error('不存在的活动');
  54. }
  55. $student_id = input('student_id',0);
  56. if(!$student_id){
  57. $this->error('请选择学生');
  58. }
  59. //匹配学生
  60. $check = Db::name('user_student')->where('id',$student_id)->where('user_id',$this->auth->id)->find();
  61. if(!$check){
  62. $this->error('不存在的学生');
  63. }
  64. //重复报名
  65. $map = [
  66. 'active_id' => $active_id,
  67. 'user_id' => $this->auth->id,
  68. 'student_id' => $student_id,
  69. 'status' => 1,
  70. ];
  71. $check = Db::name('order')->where($map)->find();
  72. if($check){
  73. $this->error('该学生已经报名本次活动');
  74. }
  75. Db::startTrans();
  76. //下单
  77. $data = [
  78. 'order_no' => createUniqueNo('A',$this->auth->id),
  79. 'active_id' => $active_id,
  80. 'user_id' => $this->auth->id,
  81. 'student_id' => $student_id,
  82. 'createtime' => time(),
  83. 'pay_fee' => $info['pay_fee'],
  84. 'status' => 0,
  85. 'remark' => $remark,
  86. ];
  87. $order_id = Db::name('order')->insertGetId($data);
  88. if(!$order_id){
  89. Db::rollback();
  90. $this->error('报名失败');
  91. }
  92. Db::commit();
  93. $this->success(1,$order_id);
  94. }
  95. }