Presell.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Db;
  4. /**
  5. *
  6. *
  7. * ----------------------------------------------------------------------------
  8. *
  9. * 预售控制器
  10. */
  11. class Presell extends MobileMall
  12. {
  13. public function initialize()
  14. {
  15. parent::initialize();
  16. }
  17. /**
  18. * @api {POST} api/Presell/index 获取预售列表
  19. * @apiVersion 1.0.0
  20. * @apiGroup Presell
  21. *
  22. * @apiParam {Int} page 页码
  23. * @apiParam {Int} per_page 每页数量
  24. *
  25. * @apiSuccess {String} code 返回码,10000为成功
  26. * @apiSuccess {String} message 返回消息
  27. * @apiSuccess {Object} result 返回数据
  28. * @apiSuccess {Object[]} result.presell_list 预售列表 (返回字段参考presell表)
  29. * @apiSuccess {Int} result.page_total 总页数
  30. * @apiSuccess {Boolean} result.hasmore 是否有更多 true是false否
  31. */
  32. public function index()
  33. {
  34. $presell_type = input('param.presell_type');
  35. $start_time = input('param.start_time');
  36. $presell_model = model('presell');
  37. $goods_model = model('goods');
  38. $condition = array(
  39. array('presell_state', 'in', [1, 2]),
  40. array('presell_end_time', '>', TIMESTAMP),
  41. );
  42. if ($presell_type) {
  43. $condition[] = array('presell_type', '=', $presell_type);
  44. }
  45. if ($start_time) {
  46. $start_time = strtotime($start_time);
  47. if ($start_time) {
  48. if ($start_time < TIMESTAMP) {
  49. $condition[] = array('presell_start_time', '<', $start_time + 86399);
  50. } else {
  51. $condition[] = array('presell_start_time', 'between', [$start_time, $start_time + 86399]);
  52. }
  53. }
  54. }
  55. $presell_list = $presell_model->getPresellList($condition, $this->pagesize);
  56. foreach ($presell_list as $key => $presell) {
  57. $goods_info = $goods_model->getGoodsInfoByID($presell['goods_id']);
  58. if (!$goods_info || $goods_info['goods_state'] != 1 || $goods_info['goods_verify'] != 1) {
  59. unset($presell_list[$key]);
  60. continue;
  61. }
  62. $presell_list[$key]['goods_price'] = $goods_info['goods_price'];
  63. $presell_list[$key]['goods_image_url'] = goods_cthumb($goods_info['goods_image'], 240);
  64. }
  65. $page_count = $presell_model->page_info;
  66. $result = array_merge(array('presell_list' => $presell_list,), mobile_page($page_count));
  67. ds_json_encode(10000, '', $result);
  68. }
  69. public function time_list()
  70. {
  71. $presell_type = input('param.presell_type');
  72. $presell_model = model('presell');
  73. $condition = array(
  74. array('presell_state', 'in', [1, 2]),
  75. array('presell_end_time', '>', TIMESTAMP),
  76. );
  77. if ($presell_type) {
  78. $condition[] = array('presell_type', '=', $presell_type);
  79. }
  80. $time_list = Db::name('presell')->fieldRaw('FROM_UNIXTIME(presell_start_time,"%Y-%m-%d") AS time')->where(array_merge($condition, array(array('presell_start_time', '>', TIMESTAMP))))->order('presell_start_time asc')->distinct(true)->limit(10)->select()->toArray();
  81. foreach ($time_list as $key => $val) {
  82. $time_list[$key]['text'] = str_replace('-', '.', substr($val['time'], 5));
  83. }
  84. if (empty($time_list) || ($time_list[0]['time'] != date('Y-m-d'))) {
  85. if ($presell_model->getPresellInfo(array_merge($condition, array(array('presell_start_time', '<', TIMESTAMP))))) {
  86. array_unshift($time_list, array('time' => date('Y-m-d'), 'text' => date('m.d')));
  87. }
  88. }
  89. ds_json_encode(10000, '', array('time_list' => $time_list));
  90. }
  91. }