Active.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. $this->success(1,$info);
  44. }
  45. //报名
  46. public function join(){
  47. $remark = input('remark',0);
  48. $active_id = input('id',0);
  49. $info = Db::name('active')->where('is_show',1)->where('id',$active_id)->find();
  50. if(!$info){
  51. $this->error('不存在的活动');
  52. }
  53. $student_id = input('student_id',0);
  54. if(!$student_id){
  55. $this->error('请选择学生');
  56. }
  57. //匹配学生
  58. $check = Db::name('user_student')->where('id',$student_id)->where('user_id',$this->auth->id)->find();
  59. if(!$check){
  60. $this->error('不存在的学生');
  61. }
  62. //重复报名
  63. $map = [
  64. 'active_id' => $active_id,
  65. 'user_id' => $this->auth->id,
  66. 'student_id' => $student_id,
  67. 'status' => 1,
  68. ];
  69. $check = Db::name('order')->where($map)->find();
  70. if($check){
  71. $this->error('该学生已经报名本次活动');
  72. }
  73. Db::startTrans();
  74. //下单
  75. $data = [
  76. 'order_no' => createUniqueNo('A',$this->auth->id),
  77. 'active_id' => $active_id,
  78. 'user_id' => $this->auth->id,
  79. 'student_id' => $student_id,
  80. 'createtime' => time(),
  81. 'pay_fee' => $info['pay_fee'],
  82. 'status' => 0,
  83. 'remark' => $remark,
  84. ];
  85. $order_id = Db::name('order')->insertGetId($data);
  86. if(!$order_id){
  87. Db::rollback();
  88. $this->error('报名失败');
  89. }
  90. Db::commit();
  91. $this->success(1,$order_id);
  92. }
  93. }