Seckill.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace addon\seckill\api\controller;
  11. use addon\seckill\model\Seckill as SeckillModel;
  12. use app\api\controller\BaseApi;
  13. /**
  14. * 秒杀
  15. */
  16. class Seckill extends BaseApi
  17. {
  18. /**
  19. * 列表信息
  20. */
  21. public function lists()
  22. {
  23. $today_time = strtotime(date("Y-m-d"), time());
  24. $time = time() - $today_time;//当日时间戳
  25. $condition = [
  26. [ 'site_id', '=', $this->site_id ],
  27. [ 'seckill_end_time', '>=', $time ]
  28. ];
  29. $order = 'seckill_start_time asc';
  30. $field = 'id,name,seckill_start_time,seckill_end_time';
  31. $seckill_model = new SeckillModel();
  32. $today_list = $seckill_model->getGoodsSeckillTimeList($condition, $field, $order);
  33. $today_list = is_array($today_list[ 'data' ]) ? array_values($today_list[ 'data' ]) : [];
  34. foreach ($today_list as $key => $val) {
  35. $val = $seckill_model->transformSeckillTime($val);
  36. $today_list[ $key ][ 'seckill_start_time_show' ] = "{$val['start_hour']}:{$val['start_minute']}:{$val['start_second']}";
  37. $today_list[ $key ][ 'seckill_end_time_show' ] = "{$val['end_hour']}:{$val['end_minute']}:{$val['end_second']}";
  38. $today_list[ $key ][ 'type' ] = "today";
  39. }
  40. $condition = [
  41. [ 'site_id', '=', $this->site_id ],
  42. [ 'seckill_end_time', '<', $time ]
  43. ];
  44. $tomorrow_list = $seckill_model->getGoodsSeckillTimeList($condition, $field, $order);
  45. $tomorrow_list = is_array($tomorrow_list[ 'data' ]) ? array_values($tomorrow_list[ 'data' ]) : [];
  46. foreach ($tomorrow_list as $key => $val) {
  47. $val = $seckill_model->transformSeckillTime($val);
  48. $tomorrow_list[ $key ][ 'seckill_start_time_show' ] = "{$val['start_hour']}:{$val['start_minute']}:{$val['start_second']}";
  49. $tomorrow_list[ $key ][ 'seckill_end_time_show' ] = "{$val['end_hour']}:{$val['end_minute']}:{$val['end_second']}";
  50. $tomorrow_list[ $key ][ 'type' ] = "tomorrow";
  51. }
  52. $res = [
  53. 'list' => array_merge($today_list, $tomorrow_list)
  54. ];
  55. return $this->response($this->success($res));
  56. }
  57. }