WholeController.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. namespace app\api\controller\activity;
  3. use app\models\store\Package;
  4. use app\models\store\StoreWholesale;
  5. use app\Request;
  6. use crmeb\services\QrcodeService;
  7. use crmeb\services\UtilService;
  8. class WholeController
  9. {
  10. /**
  11. * 秒杀产品时间区间
  12. * @return mixed
  13. * @throws \think\db\exception\DataNotFoundException
  14. * @throws \think\db\exception\ModelNotFoundException
  15. * @throws \think\exception\DbException
  16. */
  17. public function index()
  18. {
  19. //秒杀时间段
  20. $seckillTime = sys_data('whole_time') ?? [];
  21. $seckillTimeIndex = 0;
  22. if (count($seckillTime)) {
  23. foreach ($seckillTime as $key => &$value) {
  24. $currentHour = date('H');
  25. $activityEndHour = bcadd((int)$value['time'], (int)$value['continued'], 0);
  26. if ($activityEndHour > 24) {
  27. $value['time'] = strlen((int)$value['time']) == 2 ? (int)$value['time'] . ':00' : '0' . (int)$value['time'] . ':00';
  28. $value['state'] = '即将开始';
  29. $value['status'] = 2;
  30. $value['stop'] = (int)bcadd(strtotime(date('Y-m-d')), bcmul($activityEndHour, 3600, 0));
  31. } else {
  32. if ($currentHour >= (int)$value['time'] && $currentHour < $activityEndHour) {
  33. $value['time'] = strlen((int)$value['time']) == 2 ? (int)$value['time'] . ':00' : '0' . (int)$value['time'] . ':00';
  34. $value['state'] = '抢购中';
  35. $value['stop'] = (int)bcadd(strtotime(date('Y-m-d')), bcmul($activityEndHour, 3600, 0));
  36. $value['status'] = 1;
  37. if (!$seckillTimeIndex) $seckillTimeIndex = $key;
  38. } else if ($currentHour < (int)$value['time']) {
  39. $value['time'] = strlen((int)$value['time']) == 2 ? (int)$value['time'] . ':00' : '0' . (int)$value['time'] . ':00';
  40. $value['state'] = '即将开始';
  41. $value['status'] = 2;
  42. $value['stop'] = (int)bcadd(strtotime(date('Y-m-d')), bcmul($activityEndHour, 3600, 0));
  43. } else if ($currentHour >= $activityEndHour) {
  44. $value['time'] = strlen((int)$value['time']) == 2 ? (int)$value['time'] . ':00' : '0' . (int)$value['time'] . ':00';
  45. $value['state'] = '已结束';
  46. $value['status'] = 0;
  47. $value['stop'] = (int)bcadd(strtotime(date('Y-m-d')), bcmul($activityEndHour, 3600, 0));
  48. }
  49. }
  50. }
  51. }
  52. $data['lovely'] = sys_config('seckill_header_banner');
  53. if (strstr($data['lovely'], 'http') === false && strlen(trim($data['lovely']))) $data['lovely'] = sys_config('site_url') . $data['lovely'];
  54. $data['lovely'] = str_replace('\\', '/', $data['lovely']);
  55. $data['seckillTime'] = $seckillTime;
  56. $data['seckillTimeIndex'] = $seckillTimeIndex;
  57. $data['seckillCont'] = StoreWholesale::getWholeContStatus();
  58. return app('json')->successful($data);
  59. }
  60. /**
  61. * 秒杀产品列表
  62. * @param Request $request
  63. * @param $time
  64. * @return mixed
  65. * @throws \think\db\exception\DataNotFoundException
  66. * @throws \think\db\exception\ModelNotFoundException
  67. * @throws \think\exception\DbException
  68. */
  69. public function lst(Request $request, $time)
  70. {
  71. list($page, $limit) = UtilService::getMore([
  72. ['page', 0],
  73. ['limit', 0],
  74. ], $request, true);
  75. if (!$time) return app('json')->fail('参数错误');
  76. $seckillInfo = StoreWholesale::WholeList($time, $page, $limit);
  77. if (count($seckillInfo)) {
  78. foreach ($seckillInfo as $key => &$item) {
  79. }
  80. }
  81. return app('json')->successful($seckillInfo);
  82. }
  83. /**
  84. * 秒杀产品详情
  85. * @param Request $request
  86. * @param $id
  87. * @return mixed
  88. */
  89. public function detail(Request $request, $id, $time = 0, $status = 1)
  90. {
  91. $storeInfo = StoreWholesale::getValidProduct($id);
  92. if ($storeInfo)
  93. $storeInfo = $storeInfo->hidden(['cost', 'add_time', 'is_del'])->toArray();
  94. else
  95. $storeInfo = [];
  96. if (!$id || !$storeInfo) return app('json')->fail('商品不存在或已下架!');
  97. $siteUrl = sys_config('site_url');
  98. $storeInfo['image'] = set_file_url($storeInfo['image'], $siteUrl);
  99. $storeInfo['image_base'] = set_file_url($storeInfo['image'], $siteUrl);
  100. $storeInfo['code_base'] = QrcodeService::getWechatQrcodePath($id . '_seckill_detail_wap.jpg', '/activity/seckill_detail/' . $id . '/' . $time . '/' .$status);
  101. $uid = $request->uid();
  102. $storeInfo['uid'] = $uid;
  103. $data['storeInfo'] = $storeInfo;
  104. $user = $request->user();
  105. $data['isSeckillEnd'] = StoreWholesale::checkStatus($id);
  106. return app('json')->successful($data);
  107. }
  108. /**
  109. * 预约
  110. * @param Request $request
  111. */
  112. public function reserve(Request $request)
  113. {
  114. list($package_manager,$price,$day,$proportion,$pass) = UtilService::postMore(
  115. [
  116. ['package_manager',0],
  117. ['price',0],
  118. ['day',0],
  119. ['proportion',0],
  120. ['pass',0]
  121. ],$request,true
  122. );
  123. if($package_manager==0) return app('json')->fail('包编号错误');
  124. if($price==0) return app('json')->fail('价值不能为空');
  125. if($day==0) return app('json')->fail('收益天数错误');
  126. if($proportion==0) return app('json')->fail('收益比例不能为空');
  127. $rs = Package::reserve($request->uid(),$package_manager,$price,$day,$proportion,$pass);
  128. if($rs)
  129. {
  130. return app('json')->successful($rs);
  131. }
  132. else
  133. {
  134. return app('json')->fail(Package::getErrorInfo());
  135. }
  136. }
  137. /**
  138. * 新人批发
  139. * @param Request $request
  140. */
  141. public function news(Request $request)
  142. {
  143. return app('json')->successful(StoreWholesale::where('is_news',1)->where('is_del',0)->where('is_show',1)->select()->toArray());
  144. }
  145. }