Presell.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Db;
  4. /**
  5. * ============================================================================
  6. *
  7. * ============================================================================
  8. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  9. * 网站地址: https://www.valimart.net/
  10. * ----------------------------------------------------------------------------
  11. *
  12. * ============================================================================
  13. * 预售控制器
  14. */
  15. class Presell extends MobileMall {
  16. public function initialize() {
  17. parent::initialize();
  18. }
  19. /**
  20. * @api {POST} api/Presell/index 获取预售列表
  21. * @apiVersion 1.0.0
  22. * @apiGroup Presell
  23. *
  24. * @apiParam {Int} page 页码
  25. * @apiParam {Int} per_page 每页数量
  26. *
  27. * @apiSuccess {String} code 返回码,10000为成功
  28. * @apiSuccess {String} message 返回消息
  29. * @apiSuccess {Object} result 返回数据
  30. * @apiSuccess {Object[]} result.presell_list 预售列表 (返回字段参考presell表)
  31. * @apiSuccess {Int} result.page_total 总页数
  32. * @apiSuccess {Boolean} result.hasmore 是否有更多 true是false否
  33. */
  34. public function index() {
  35. $presell_type=input('param.presell_type');
  36. $start_time=input('param.start_time');
  37. $presell_model = model('presell');
  38. $goods_model = model('goods');
  39. $condition = array(
  40. array('presell_state', 'in', [1,2]),
  41. array('presell_end_time', '>', TIMESTAMP),
  42. );
  43. if($presell_type){
  44. $condition[]=array('presell_type','=',$presell_type);
  45. }
  46. if($start_time){
  47. $start_time=strtotime($start_time);
  48. if($start_time){
  49. if($start_time<TIMESTAMP){
  50. $condition[]=array('presell_start_time', '<', $start_time+86399);
  51. }else{
  52. $condition[]=array('presell_start_time', 'between', [$start_time,$start_time+86399]);
  53. }
  54. }
  55. }
  56. $presell_list = $presell_model->getPresellList($condition, $this->pagesize);
  57. foreach ($presell_list as $key => $presell) {
  58. $goods_info=$goods_model->getGoodsInfoByID($presell['goods_id']);
  59. if(!$goods_info || $goods_info['goods_state']!=1 || $goods_info['goods_verify']!=1){
  60. unset($presell_list[$key]);
  61. continue;
  62. }
  63. $presell_list[$key]['goods_price'] = $goods_info['goods_price'];
  64. $presell_list[$key]['goods_image_url'] = goods_cthumb($goods_info['goods_image'], 240);
  65. }
  66. $page_count = $presell_model->page_info;
  67. $result = array_merge(array('presell_list' => $presell_list,), mobile_page($page_count));
  68. ds_json_encode(10000, '', $result);
  69. }
  70. public function time_list(){
  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. }