WholeController.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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 = Package::lst(['time_id'=>$time,'page'=>$page,'limit'=>$limit,'status'=>3]);
  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,$is_news=0)
  90. {
  91. $storeInfo = StoreWholesale::getValidProduct($id,'',$is_news);
  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($whole_id,$time_id,$price,$to_uid,$first_price,$last_id) = UtilService::postMore(
  115. [
  116. ['whole_id',0],
  117. ['time_id',0],
  118. ['price',0],
  119. ['to_uid',0],
  120. ['first_price',0],
  121. ['last_id',0],
  122. ],$request,true
  123. );
  124. if($whole_id==0) return app('json')->fail('商品不能为空');
  125. if($time_id==0) return app('json')->fail('时间段不能为空');
  126. if($price==0) return app('json')->fail('价格不能为0');
  127. if($to_uid==0) $first_price = $price;
  128. if($last_id>0 && !self::be(['id'=>$last_id,'uid'=>$to_uid])) return app('json')->fail('非法数据');
  129. $rs = Package::reserve($request->uid(),$whole_id,$time_id,$to_uid,$price,$first_price,$last_id);
  130. if($rs)
  131. {
  132. return app('json')->successful($rs);
  133. }
  134. else
  135. {
  136. return app('json')->fail(Package::getErrorInfo());
  137. }
  138. }
  139. /**
  140. * 我的记录
  141. * @param Request $request
  142. * @return mixed
  143. */
  144. public function mylist(Request $request)
  145. {
  146. $where = UtilService::postMore(
  147. [
  148. ['page',1],
  149. ['limit',0],
  150. ['data',''],
  151. ['status',-4],
  152. ],$request
  153. );
  154. $where['uid'] = $request->uid();
  155. return app('json')->successful(Package::lst($where));
  156. }
  157. /**
  158. * 上传评证
  159. * @param Request $request
  160. */
  161. public function evaluation(Request $request)
  162. {
  163. $where = UtilService::postMore(
  164. [
  165. ['pay_evaluation',''],
  166. ],$request
  167. );
  168. if($where['pay_evaluation']=='') return app('json')->fail('上传图片评证');
  169. if(!Package::be(['uid'=>$request->uid(),'id'=>input('id'),'status'=>1]))return app('json')->fail('参数错误或已上传!');
  170. $where['submit_time'] = time();
  171. $where['status'] = 2;
  172. return app('json')->successful(Package::edit($where,input('id')));
  173. }
  174. /**
  175. * 我的订单
  176. * @param Request $request
  177. * @return mixed
  178. */
  179. public function order(Request $request)
  180. {
  181. $where = UtilService::postMore(
  182. [
  183. ['page',1],
  184. ['limit',0],
  185. ['status',-4],
  186. ],$request
  187. );
  188. $where['to_uid'] = $request->uid();
  189. return app('json')->successful(Package::lst($where));
  190. }
  191. /**
  192. * 订单审核
  193. * @param Request $request
  194. */
  195. public function audit(Request $request)
  196. {
  197. $where = UtilService::postMore(
  198. [
  199. ['re',''],
  200. ['status',3],
  201. ],$request
  202. );
  203. $id = input('id');
  204. if(!Package::be(['to_uid'=>$request->uid(),'status'=>2,'id'=>$id])) return app('json')->fail('参数有误或已审核');
  205. if($where['status']==3)
  206. {
  207. $rs = Package::take($id);
  208. }
  209. else
  210. {
  211. $rs = Package::invalid($id,$where['re']);
  212. }
  213. if($rs) return app('json')->successful('审核通过');
  214. else return app('json')->fail(Package::getErrorInfo());
  215. }
  216. /**
  217. * 新人批发
  218. * @param Request $request
  219. */
  220. public function news(Request $request)
  221. {
  222. return app('json')->successful(StoreWholesale::where('is_news',1)->where('is_del',0)->where('is_show',1)->select()->toArray());
  223. }
  224. }