Order.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 order extends Api
  10. {
  11. protected $noNeedLogin = [''];
  12. protected $noNeedRight = ['*'];
  13. public function lists()
  14. {
  15. $active_status = input('active_status','all');
  16. $where = [
  17. 'order.user_id'=>$this->auth->id,
  18. 'order.status' =>1,
  19. ];
  20. if($active_status == 1){
  21. $where['active.activestarttime'] = ['gt',time()];
  22. }
  23. if($active_status == 2){
  24. $where['active.activestarttime'] = ['lt',time()];
  25. $where['active.activeendtime'] = ['gt',time()];
  26. }
  27. if($active_status == 3){
  28. $where['active.activeendtime'] = ['lt',time()];
  29. }
  30. $list = Db::name('order')->field('order.*,active.activestarttime,active.activeendtime,active.name,active.image')
  31. ->join('active','order.active_id = active.id','LEFT')
  32. ->where($where)->order('order.id desc')->autopage()->select();
  33. $list = list_domain_image($list,['image']);
  34. if(!empty($list)){
  35. foreach($list as $key => &$item){
  36. $status_text = '进行中';
  37. $status = 2;
  38. if(time() < $item['activestarttime']){
  39. $status_text = '报名中';
  40. $status = 1;
  41. }
  42. if(time() > $item['activeendtime']){
  43. $status_text = '已结束';
  44. $status = 3;
  45. }
  46. $item['status_text'] = $status_text;
  47. $item['active_status'] = $status;
  48. }
  49. }
  50. $this->success(1,$list);
  51. }
  52. public function info(){
  53. $id = input('id',0);
  54. $info = Db::name('order')->field('order.*,active.activestarttime,active.activeendtime,active.name,us.realname,school.schoolname,classes.classname')
  55. ->join('active','order.active_id = active.id','LEFT')
  56. ->join('user_student us','order.student_id = us.id','LEFT')
  57. ->join('school','us.school_id = school.id','LEFT')
  58. ->join('classes','us.classes_id = classes.id','LEFT')
  59. ->where('order.id',$id)->find();
  60. $status_text = '进行中';
  61. $status = 2;
  62. if(time() < $info['activestarttime']){
  63. $status_text = '报名中';
  64. $status = 1;
  65. }
  66. if(time() > $info['activeendtime']){
  67. $status_text = '已结束';
  68. $status = 3;
  69. }
  70. $info['status_text'] = $status_text;
  71. $info['active_status'] = $status;
  72. $this->success(1,$info);
  73. }
  74. }