Order.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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,grade.gradename,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('grade','us.grade_id = grade.id','LEFT')
  59. ->join('classes','us.classes_id = classes.id','LEFT')
  60. ->where('order.id',$id)->find();
  61. $status_text = '进行中';
  62. $status = 2;
  63. if(time() < $info['activestarttime']){
  64. $status_text = '报名中';
  65. $status = 1;
  66. }
  67. if(time() > $info['activeendtime']){
  68. $status_text = '已结束';
  69. $status = 3;
  70. }
  71. $info['status_text'] = $status_text;
  72. $info['active_status'] = $status;
  73. $this->success(1,$info);
  74. }
  75. }