WholeController.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. <?php
  2. namespace app\api\controller\activity;
  3. use app\models\store\Package;
  4. use app\models\store\StoreWholesale;
  5. use app\models\user\User;
  6. use app\models\user\UserBill;
  7. use app\Request;
  8. use crmeb\services\QrcodeService;
  9. use crmeb\services\UtilService;
  10. class WholeController
  11. {
  12. /**
  13. * 秒杀产品时间区间
  14. * @return mixed
  15. * @throws \think\db\exception\DataNotFoundException
  16. * @throws \think\db\exception\ModelNotFoundException
  17. * @throws \think\exception\DbException
  18. */
  19. public function index()
  20. {
  21. //秒杀时间段
  22. $seckillTime = sys_data('whole_time') ?? [];
  23. $seckillTimeIndex = 0;
  24. if (count($seckillTime)) {
  25. foreach ($seckillTime as $key => &$value) {
  26. $currentHour = date('H');
  27. $activityEndHour = bcadd((int)$value['time'], (int)$value['continued'], 0);
  28. if ($activityEndHour > 24) {
  29. $value['time'] = strlen((int)$value['time']) == 2 ? (int)$value['time'] . ':00' : '0' . (int)$value['time'] . ':00';
  30. $value['state'] = '即将开始';
  31. $value['status'] = 2;
  32. $value['stop'] = (int)bcadd(strtotime(date('Y-m-d')), bcmul($activityEndHour, 3600, 0));
  33. } else {
  34. if ($currentHour >= (int)$value['time'] && $currentHour < $activityEndHour) {
  35. $value['time'] = strlen((int)$value['time']) == 2 ? (int)$value['time'] . ':00' : '0' . (int)$value['time'] . ':00';
  36. $value['state'] = '抢购中';
  37. $value['stop'] = (int)bcadd(strtotime(date('Y-m-d')), bcmul($activityEndHour, 3600, 0));
  38. $value['status'] = 1;
  39. if (!$seckillTimeIndex) $seckillTimeIndex = $key;
  40. } else if ($currentHour < (int)$value['time']) {
  41. $value['time'] = strlen((int)$value['time']) == 2 ? (int)$value['time'] . ':00' : '0' . (int)$value['time'] . ':00';
  42. $value['state'] = '即将开始';
  43. $value['status'] = 2;
  44. $value['stop'] = (int)bcadd(strtotime(date('Y-m-d')), bcmul($activityEndHour, 3600, 0));
  45. } else if ($currentHour >= $activityEndHour) {
  46. $value['time'] = strlen((int)$value['time']) == 2 ? (int)$value['time'] . ':00' : '0' . (int)$value['time'] . ':00';
  47. $value['state'] = '已结束';
  48. $value['status'] = 0;
  49. $value['stop'] = (int)bcadd(strtotime(date('Y-m-d')), bcmul($activityEndHour, 3600, 0));
  50. }
  51. }
  52. }
  53. }
  54. $data['lovely'] = sys_config('seckill_header_banner');
  55. if (strstr($data['lovely'], 'http') === false && strlen(trim($data['lovely']))) $data['lovely'] = sys_config('site_url') . $data['lovely'];
  56. $data['lovely'] = str_replace('\\', '/', $data['lovely']);
  57. $data['seckillTime'] = $seckillTime;
  58. $data['seckillTimeIndex'] = $seckillTimeIndex;
  59. $data['seckillCont'] = StoreWholesale::getWholeContStatus();
  60. return app('json')->successful($data);
  61. }
  62. /**
  63. * 秒杀产品列表
  64. * @param Request $request
  65. * @param $time
  66. * @return mixed
  67. * @throws \think\db\exception\DataNotFoundException
  68. * @throws \think\db\exception\ModelNotFoundException
  69. * @throws \think\exception\DbException
  70. */
  71. public function lst(Request $request, $time)
  72. {
  73. list($page, $limit) = UtilService::getMore([
  74. ['page', 0],
  75. ['limit', 0],
  76. ], $request, true);
  77. if (!$time) return app('json')->fail('参数错误');
  78. $seckillInfo = Package::lst(['time_id'=>$time,'page'=>$page,'limit'=>$limit,'status'=>2]);
  79. if (count($seckillInfo)) {
  80. foreach ($seckillInfo['data'] as &$v) {
  81. $v['price'] = bcadd(bcmul($v['price'],bcdiv(sys_config('pass_on',3),100,2),2),$v['price'],2);
  82. }
  83. }
  84. return app('json')->successful($seckillInfo);
  85. }
  86. /**
  87. * 秒杀产品详情
  88. * @param Request $request
  89. * @param $id
  90. * @return mixed
  91. */
  92. public function detail(Request $request, $id, $time = 0, $status = 1,$is_news=0)
  93. {
  94. $storeInfo = StoreWholesale::getValidProduct($id,'',$is_news);
  95. if ($storeInfo)
  96. $storeInfo = $storeInfo->hidden(['cost', 'add_time', 'is_del'])->toArray();
  97. else
  98. $storeInfo = [];
  99. if (!$id || !$storeInfo) return app('json')->fail('商品不存在或已下架!');
  100. $siteUrl = sys_config('site_url');
  101. $storeInfo['image'] = set_file_url($storeInfo['image'], $siteUrl);
  102. $storeInfo['image_base'] = set_file_url($storeInfo['image'], $siteUrl);
  103. $storeInfo['code_base'] = QrcodeService::getWechatQrcodePath($id . '_seckill_detail_wap.jpg', '/activity/seckill_detail/' . $id . '/' . $time . '/' .$status);
  104. $uid = $request->uid();
  105. $storeInfo['uid'] = $uid;
  106. $data['storeInfo'] = $storeInfo;
  107. $user = $request->user();
  108. $data['isSeckillEnd'] = StoreWholesale::checkStatus($id);
  109. return app('json')->successful($data);
  110. }
  111. /**
  112. * 预约
  113. * @param Request $request
  114. */
  115. public function reserve(Request $request)
  116. {
  117. list($whole_id,$time_id,$price,$to_uid,$first_price,$last_id) = UtilService::postMore(
  118. [
  119. ['whole_id',0],
  120. ['time_id',0],
  121. ['price',0],
  122. ['to_uid',0],
  123. ['first_price',0],
  124. ['last_id',0],
  125. ],$request,true
  126. );
  127. if($whole_id==0) return app('json')->fail('商品不能为空');
  128. if($time_id==0) return app('json')->fail('时间段不能为空');
  129. if($price==0) return app('json')->fail('价格不能为0');
  130. if($to_uid==0) $first_price = $price;
  131. $rs = Package::reserve($request->uid(),$whole_id,$time_id,$to_uid,$price,$first_price,$last_id);
  132. if($rs)
  133. {
  134. return app('json')->successful($rs);
  135. }
  136. else
  137. {
  138. return app('json')->fail(Package::getErrorInfo());
  139. }
  140. }
  141. /**
  142. * 我的记录
  143. * @param Request $request
  144. * @return mixed
  145. */
  146. public function mylist(Request $request)
  147. {
  148. $where = UtilService::postMore(
  149. [
  150. ['page',1],
  151. ['limit',10],
  152. ['data',''],
  153. ['status',-4],
  154. ],$request
  155. );
  156. $where['uid'] = $request->uid();
  157. return app('json')->successful(Package::lst($where));
  158. }
  159. /**
  160. * 上传评证
  161. * @param Request $request
  162. */
  163. public function evaluation(Request $request)
  164. {
  165. $where = UtilService::postMore(
  166. [
  167. ['pay_evaluation',''],
  168. ],$request
  169. );
  170. if($where['pay_evaluation']=='') return app('json')->fail('上传图片评证');
  171. if(!Package::be(['uid'=>$request->uid(),'id'=>input('id'),'status'=>0]))return app('json')->fail('参数错误或已上传!');
  172. $where['submit_time'] = time();
  173. $where['status'] = 1;
  174. return app('json')->successful(Package::edit($where,input('id')));
  175. }
  176. /**
  177. * 我的订单
  178. * @param Request $request
  179. * @return mixed
  180. */
  181. public function order(Request $request)
  182. {
  183. $where = UtilService::postMore(
  184. [
  185. ['page',1],
  186. ['limit',0],
  187. ['status',-4],
  188. ],$request
  189. );
  190. $where['to_uid'] = $request->uid();
  191. return app('json')->successful(Package::lst($where));
  192. }
  193. /**
  194. * 订单审核
  195. * @param Request $request
  196. */
  197. public function audit(Request $request)
  198. {
  199. $where = UtilService::postMore(
  200. [
  201. ['re',''],
  202. ['status',1],
  203. ],$request
  204. );
  205. $id = input('id');
  206. if(!Package::be(['to_uid'=>$request->uid(),'status'=>1,'id'=>$id])) return app('json')->fail('参数有误或已审核');
  207. if($where['status']==2)
  208. {
  209. $rs = Package::take($id);
  210. }
  211. else
  212. {
  213. $rs = Package::invalid($id,$where['re']);
  214. }
  215. if($rs) return app('json')->successful('审核通过');
  216. else return app('json')->fail(Package::getErrorInfo());
  217. }
  218. /**
  219. * 新人批发
  220. * @param Request $request
  221. */
  222. public function news(Request $request)
  223. {
  224. $time_id = input('time_id',0);
  225. $where = null;
  226. if($time_id>0)
  227. {
  228. $where['time_id'] = $time_id;
  229. }
  230. return app('json')->successful(StoreWholesale::where('is_del',0)->where($where)->where('is_show',1)->select()->toArray());
  231. }
  232. /**
  233. * 批发详情
  234. * @param Request $request
  235. * @param $id
  236. * @return mixed
  237. * @throws \think\db\exception\DataNotFoundException
  238. * @throws \think\db\exception\DbException
  239. * @throws \think\db\exception\ModelNotFoundException
  240. */
  241. public function info(Request $request,$id)
  242. {
  243. $info = Package::find($id);
  244. if (!$info) return app('json')->fail('非法数据');
  245. $info = $info->toArray();
  246. $info['whole'] = StoreWholesale::find($info['whole_id'])->toArray();
  247. $info['isSeckillEnd'] = StoreWholesale::checkStatus($info['whole_id']);
  248. $info['price'] = bcadd(bcmul($info['price'],bcdiv(sys_config('pass_on',3),100,2),2),$info['price'],2);
  249. return app('json')->successful($info);
  250. }
  251. /**
  252. * 金豆池
  253. * @param Request $request
  254. * @return mixed
  255. * @throws \think\db\exception\DataNotFoundException
  256. * @throws \think\db\exception\DbException
  257. * @throws \think\db\exception\ModelNotFoundException
  258. */
  259. public function pool(Request $request)
  260. {
  261. $sum = Package::where('status','in',join(",",['-1','-2']))->value('sum(use_integral)')?:0;
  262. $sum1 = Package::where('admin_id','>',0)->value('sum(use_integral)/2')?:0;
  263. $count = Package::where('status','in',join(",",['-1','-2']))->value('count(use_integral)')?:0;
  264. $count1 = Package::where('admin_id','>',0)->value('count(use_integral)')?:0;
  265. $sum = bcadd($sum,$sum1,2);
  266. $count = bcadd($count,$count1,2);
  267. $data = Package::where('status','in',join(",",['-1','-2']))->whereor(function ($query){
  268. $query->where('admin_id','>','0');
  269. })->order('id desc')->page(input('page',1),input('limit',10))->select()->toArray();
  270. foreach ($data as &$v)
  271. {
  272. $v['user'] = User::find($v['uid'])->toArray();
  273. if($v['status'] == -1)
  274. {
  275. $v['title'] = '审核无效扣除';
  276. }elseif($v['status'] == -2)
  277. {
  278. $v['title'] = '支付超时扣除';
  279. }else
  280. {
  281. $v['title'] = '未确认,扣除收益';
  282. $v['use_integral'] = bcdiv($v['use_integral'],2,2);
  283. }
  284. }
  285. return app('json')->successful(compact('sum','count','data'));
  286. }
  287. public function take_delivery(Request $request,$id)
  288. {
  289. $info = Package::find($id);
  290. if (!$info) return app('json')->fail('非法数据');
  291. $info = $info->toArray();
  292. if($info['status']!=2) return app('json')->fail('状态是不是支付完成,不能提货');
  293. User::where('uid',$info['uid'])->inc('integral',$info['price'])->update();
  294. $user = $request->user();
  295. UserBill::income('订单提货',$info['uid'],'integral','package',$info['price'],$info['id'],bcadd($user['integral'],$info['price'],2),'订单收货'.$info['price']);
  296. Package::edit(['status'=>5],$id);
  297. return app('json')->successful('提货完成');
  298. }
  299. }