Presell.php 4.0 KB

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