Presell.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Db;
  4. /**
  5. * ============================================================================
  6. * DSMall多用户商城
  7. * ============================================================================
  8. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  9. * 网站地址: http://www.csdeshang.com
  10. * ----------------------------------------------------------------------------
  11. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  12. * 不允许对程序代码以任何形式任何目的的再发布。
  13. * ============================================================================
  14. * 预售控制器
  15. */
  16. class Presell extends MobileMall {
  17. public function initialize() {
  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. $presell_type=input('param.presell_type');
  37. $start_time=input('param.start_time');
  38. $presell_model = model('presell');
  39. $goods_model = model('goods');
  40. $condition = array(
  41. array('presell_state', 'in', [1,2]),
  42. array('presell_end_time', '>', TIMESTAMP),
  43. );
  44. if($presell_type){
  45. $condition[]=array('presell_type','=',$presell_type);
  46. }
  47. if($start_time){
  48. $start_time=strtotime($start_time);
  49. if($start_time){
  50. if($start_time<TIMESTAMP){
  51. $condition[]=array('presell_start_time', '<', $start_time+86399);
  52. }else{
  53. $condition[]=array('presell_start_time', 'between', [$start_time,$start_time+86399]);
  54. }
  55. }
  56. }
  57. $presell_list = $presell_model->getPresellList($condition, $this->pagesize);
  58. foreach ($presell_list as $key => $presell) {
  59. $goods_info=$goods_model->getGoodsInfoByID($presell['goods_id']);
  60. if(!$goods_info || $goods_info['goods_state']!=1 || $goods_info['goods_verify']!=1){
  61. unset($presell_list[$key]);
  62. continue;
  63. }
  64. $presell_list[$key]['goods_price'] = $goods_info['goods_price'];
  65. $presell_list[$key]['goods_image_url'] = goods_cthumb($goods_info['goods_image'], 240);
  66. }
  67. $page_count = $presell_model->page_info;
  68. $result = array_merge(array('presell_list' => $presell_list,), mobile_page($page_count));
  69. ds_json_encode(10000, '', $result);
  70. }
  71. public function time_list(){
  72. $presell_type=input('param.presell_type');
  73. $presell_model = model('presell');
  74. $condition = array(
  75. array('presell_state', 'in', [1,2]),
  76. array('presell_end_time', '>', TIMESTAMP),
  77. );
  78. if($presell_type){
  79. $condition[]=array('presell_type','=',$presell_type);
  80. }
  81. $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();
  82. foreach($time_list as $key => $val){
  83. $time_list[$key]['text']=str_replace('-','.',substr($val['time'],5));
  84. }
  85. if(empty($time_list) || ($time_list[0]['time']!=date('Y-m-d'))){
  86. if($presell_model->getPresellInfo(array_merge($condition,array(array('presell_start_time', '<', TIMESTAMP))))){
  87. array_unshift($time_list,array('time'=>date('Y-m-d'),'text'=>date('m.d')));
  88. }
  89. }
  90. ds_json_encode(10000, '', array('time_list'=>$time_list));
  91. }
  92. }