AuctionProductController.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  1. <?php
  2. namespace app\api\controller\auction;
  3. use app\admin\model\auction\AuctionDeliver;
  4. use app\admin\model\system\SystemConfig;
  5. use app\models\auction\Auction;
  6. use app\models\auction\AuctionBooking;
  7. use app\models\auction\AuctionFrozen;
  8. use app\models\auction\AuctionGu;
  9. use app\models\auction\AuctionOrder;
  10. use app\models\auction\AuctionProduct;
  11. use app\models\auction\AuctionTime;
  12. use app\models\user\User;
  13. use app\models\user\UserAddress;
  14. use app\models\user\UserBill;
  15. use app\Request;
  16. use crmeb\utils\Redis;
  17. use Monolog\Handler\Curl\Util;
  18. use think\facade\Cache;
  19. use crmeb\services\{
  20. CacheService,
  21. ExpressService,
  22. SystemConfigService
  23. };
  24. use crmeb\services\UtilService;
  25. use crmeb\repositories\OrderRepository;
  26. use think\facade\Db;
  27. class AuctionProductController
  28. {
  29. /**
  30. * 获取商品列表
  31. * @param Request $request
  32. * @return mixed
  33. * @throws \think\db\exception\DataNotFoundException
  34. * @throws \think\db\exception\DbException
  35. * @throws \think\db\exception\ModelNotFoundException
  36. */
  37. public function auction_product(Request $request)
  38. {
  39. $data = UtilService::getMore([
  40. [['page', 'd'], 0],
  41. [['limit', 'd'], 0],
  42. ['id'],
  43. ['name']
  44. ]);
  45. if (!$data['id']) return app('json')->fail('数据传入错误');
  46. return app('json')->successful(AuctionProduct::list($data, $request->uid()));
  47. }
  48. /**
  49. * 用户商品
  50. * @param Request $request
  51. * @return mixed
  52. * @throws \think\db\exception\DataNotFoundException
  53. * @throws \think\db\exception\DbException
  54. * @throws \think\db\exception\ModelNotFoundException
  55. */
  56. public function user_product(Request $request)
  57. {
  58. $data = UtilService::getMore([
  59. [['page', 'd'], 0],
  60. [['limit', 'd'], 0],
  61. ]);
  62. return app('json')->successful(AuctionProduct::user_product( $data,$request->uid()));
  63. }
  64. /**
  65. * 购买商品
  66. * @param Request $request
  67. * @return mixed
  68. * @throws \think\db\exception\DataNotFoundException
  69. * @throws \think\db\exception\DbException
  70. * @throws \think\db\exception\ModelNotFoundException
  71. */
  72. public function purchase(Request $request)
  73. {
  74. $data = UtilService::getMore([
  75. ['product_id'],
  76. ]);
  77. if (!$data['product_id']) return app('json')->fail('数据传入错误');
  78. $product = AuctionProduct::where('id', $data['product_id'])->find();
  79. if ($product['is_show'] == 0) return app('json')->fail('商品未挂售');
  80. $auction = Auction::where('id', $product['auction_id'])->find();
  81. $user = $request->user();
  82. $time = strtotime(date('Y-m-d', time()));// 今天
  83. $today = strtotime(date('Y-m-d', strtotime('+1day')));// 明天
  84. $radd_time = strtotime($auction['radd_time']); // 抢购时间
  85. if ($user['is_new'] == 1 or ($user['green_time'] >= $time and $user['green_time'] <= $today)){
  86. // 新人或者绿色通道提前三分钟入场
  87. if ($radd_time - 180 > time()){
  88. return app('json')->fail('未到抢购时间');
  89. }
  90. }else if($radd_time > time()){
  91. return app('json')->fail('当前未到抢购时间');
  92. }
  93. $count = AuctionOrder::where('frequency',$auction['frequency'])->where('uid', $request->uid())->where('auction_id', '=', $auction['id'])->count();// 查找今天订单数量
  94. $orderCount = AuctionOrder::where([['uid', '=', $request->uid()]])->whereBetweenTime('create_time', $time, $today)->count(); // 查找今天抢购的订单数量;
  95. $config = SystemConfigService::get('auction_number');
  96. $max = SystemConfigService::get('maximum');
  97. if ($orderCount >= (int)$max) return app('json')->fail('今日抢购数量已达到最大'); // 查看当前是否已到最大
  98. if ($count >= (int)$config) return app('json')->fail('单场购买数量已到达最大'); // 查看当前是否已到最大
  99. if ($product['uid'] == $request->uid()) return app('json')->fail('无法购买自己商品');
  100. if ($product){
  101. AuctionOrder::beginTrans();
  102. //查询商品是否以卖出
  103. $order = AuctionOrder::where('product_id', $data['product_id'])->where('status', '>', 0)->where('frequency', $auction['frequency'])->find();
  104. if ($order){
  105. return app('json')->fail('商品已卖出');
  106. }
  107. $order_id = getNewOrderId();
  108. if ($count >= 1){
  109. if ($user['anticipate'] < 200) return app('json')->fail('广告值不足');
  110. $user['anticipate'] -= 200;
  111. User::where('uid', $user['uid'])->update(['anticipate' => $user['anticipate']]);
  112. UserBill::expend('冻结广告值',$user['uid'], 'anticipate', 'fz_anticipate', 200, $user['spread_uid'], $user['anticipate'], '购买订单'.$order_id.'冻结广告值');
  113. AuctionFrozen::create([
  114. 'order_id' => $order_id,
  115. 'uid' => $request->uid(),
  116. 'anticipate' => 200
  117. ]);
  118. }
  119. $redis = new \Redis();
  120. $redis->connect('127.0.0.1','6379'); // redis 缓存
  121. if (!$redis->lPop($data['product_id'])){
  122. return app('json')->fail('商品已卖出');
  123. }
  124. $res = AuctionOrder::create([
  125. 'uid' => $request->uid(),
  126. 'collection_id' => $product['uid'],// 商品拥有有人
  127. 'order_id' => $order_id,
  128. 'name' => $product['name'],
  129. 'product_id' => $product['id'],
  130. 'auction_id' => $auction['id'],
  131. 'image'=> $product['image'],
  132. 'price' => $product['hanging_price'],
  133. 'frequency' => $auction['frequency']
  134. ]);
  135. if ($res){
  136. AuctionOrder::commitTrans();
  137. return app('json')->successful('购买成功');
  138. }else{
  139. AuctionOrder::rollbackTrans();
  140. return app('json')->fail('购买失败');
  141. }
  142. }else{
  143. return app('json')->fail('购买商品不存在');
  144. }
  145. }
  146. /**
  147. * 获取用户竞拍订单
  148. * @param Request $request
  149. * @return mixed
  150. * @throws \think\db\exception\DataNotFoundException
  151. * @throws \think\db\exception\DbException
  152. * @throws \think\db\exception\ModelNotFoundException
  153. */
  154. public function user_auction_order(Request $request)
  155. {
  156. $data = UtilService::getMore([
  157. [['type', 'd'], 0],
  158. [['page', 'd'], 0],
  159. [['limit', 'd'], 0],
  160. ['order_id']
  161. ]);
  162. return app('json')->successful(AuctionOrder::userOrder($data,$request->uid()));
  163. }
  164. /**
  165. * 上传打款凭证
  166. * @param Request $request
  167. * @return mixed
  168. * @throws \think\db\exception\DataNotFoundException
  169. * @throws \think\db\exception\DbException
  170. * @throws \think\db\exception\ModelNotFoundException
  171. */
  172. public function up_image(Request $request)
  173. {
  174. $data = UtilService::getMore([
  175. ['image'],
  176. ['id']
  177. ]);
  178. if (!$data['image'] || !$data['id']) return app('json')->fail('请上传打款凭证');
  179. $order = AuctionOrder::where('id', $data['id'])->find();
  180. if (!$order) return app('json')->fail('订单不存在');
  181. $auction = Auction::where('id', $order['auction_id'])->find();
  182. if (strtotime($auction['radd_time']) > time() or strtotime($auction['rend_time']) < time()) return app('json')->fail('没到支付时间,支付时间为'.$auction['radd_time'].'-'.$auction['rend_time']);
  183. if ($order['status'] != 1) return app('json')->fail('当前订单状态无法上传凭证');
  184. $order['upload_image'] = $data['image'];
  185. $order['status'] = 2;
  186. $order['voucher_time'] = time();
  187. if ($order->save()){
  188. return app('json')->successful('上传成功');
  189. }else{
  190. return app('json')->fail('上传失败');
  191. }
  192. }
  193. /**
  194. * 卖家显示订单
  195. * @param Request $request
  196. * @return void
  197. */
  198. public function seller(Request $request)
  199. {
  200. $data = UtilService::getMore([
  201. ['type', 0],
  202. [['page', 'd'], 0],
  203. [['limit', 'd'], 0],
  204. ['order_id']
  205. ]);
  206. return app('json')->successful(AuctionOrder::seller_list($data,$request->uid()));
  207. }
  208. /**
  209. * 确定订单
  210. * @param Request $request
  211. * @return void
  212. */
  213. public function adopt(Request $request){
  214. $data = UtilService::postMore([
  215. ['order_id']
  216. ]);
  217. if (!$data['order_id']) return app('json')->fail('数据传入错误');
  218. $order = AuctionOrder::where('order_id', $data['order_id'])->find();
  219. if ($order['status'] < 1) return app('json')->fail('该订单已失效');
  220. if ($order['status'] == 1) return app('json')->fail('未上传打款凭证');
  221. if ($order['status'] == 3) return app('json')->fail('该订单已完成');
  222. $order['status'] = 3;
  223. try {
  224. Db::startTrans();
  225. $product = AuctionProduct::find($order['product_id']);
  226. if ($product['uid'] == $order['uid']) return app('json')->fail('商品已发放');
  227. if (!$product) return app('json')->fail('数据不存在');
  228. $uid = $product['uid']; // 所属人id
  229. $product['uid'] = $order['uid'];// 商品拥有人更新
  230. $product['add_time'] = time();
  231. $product['order'] = $data['order_id'];
  232. $product['is_show'] = 0;
  233. $res = $product->save();
  234. AuctionTime::where([['product_id', '=', $product['id']]])->delete();
  235. AuctionOrder::where('order_id', $data['order_id'])->update(['status' => 3]);
  236. AuctionOrder::return($order['id']); // 买家
  237. Db::commit();
  238. return app('json')->successful('完成');
  239. } catch (\Exception $e) {
  240. Db::rollback();
  241. return app('json')->fail('失败');
  242. }
  243. }
  244. /**
  245. * 产品详情
  246. * @param Request $request
  247. * @return mixed
  248. * @throws \think\db\exception\DataNotFoundException
  249. * @throws \think\db\exception\DbException
  250. * @throws \think\db\exception\ModelNotFoundException
  251. */
  252. public function details(Request $request)
  253. {
  254. $data = UtilService::getMore([
  255. ['product_id']
  256. ]);
  257. if (!$data['product_id']) return app('json')->fail('数据传入错误');
  258. $details = AuctionProduct::where('id', $data['product_id'])->find();
  259. if (empty($details)) return app('json')->fail('商品不存在');
  260. $details['slider_image'] = is_string($details['slider_image']) ? json_decode($details['slider_image'], true) : [];
  261. $details['description'] = !empty($details['description']) ? html_entity_decode($details['description'], ENT_COMPAT) : '';
  262. $details['user_nickname'] = User::where('uid', $details['uid'])->find()['nickname'];
  263. $auction = Auction::where('id', $details['auction_id'])->find();
  264. $details['time'] = $auction['radd_time'].'-'.$auction['rend_time'];
  265. $details['times'] = strtotime($auction['radd_time']);
  266. $details = $details->toArray();
  267. return app('json')->successful($details);
  268. }
  269. /**商品以前属于人
  270. * @param Request $request
  271. * @return mixed
  272. */
  273. public function belong(Request $request)
  274. {
  275. $data = UtilService::getMore([
  276. ['product_id']
  277. ]);
  278. if (!$data['product_id']) return app('json')->fail('数据传入错误');
  279. $order = AuctionOrder::alias('a')
  280. ->field('u.nickname,u.avatar,a.create_time')
  281. ->leftJoin('user u', 'a.collection_id = u.uid')
  282. ->where('a.product_id', $data['product_id'])->where('a.status', 3)->select();
  283. if (empty($order->toArray())) $order = AuctionProduct::alias('a')
  284. ->field('u.nickname,u.avatar,a.create_time')
  285. ->leftJoin('user u', 'a.uid = u.uid')
  286. ->where('a.id', $data['product_id'])->select();
  287. $order = empty($order)? [] : $order->toArray();
  288. return app('json')->successful($order);
  289. }
  290. /**
  291. * 挂售详情
  292. * @param Request $request
  293. * @return mixed
  294. * @throws \think\db\exception\DataNotFoundException
  295. * @throws \think\db\exception\DbException
  296. * @throws \think\db\exception\ModelNotFoundException
  297. */
  298. public function gsxq(Request $request)
  299. {
  300. $data = UtilService::getMore([
  301. ['id']
  302. ]);
  303. $product = AuctionProduct::where('id', $data['id'])->find();
  304. if (!$product) return app('json')->fail('商品不存在');
  305. $data = AuctionProduct::bs($data['id']);
  306. return app('json')->successful($data);
  307. }
  308. /**
  309. * 挂售商品
  310. * @param Request $request
  311. * @return mixed
  312. * @throws \think\db\exception\DataNotFoundException
  313. * @throws \think\db\exception\DbException
  314. * @throws \think\db\exception\ModelNotFoundException
  315. */
  316. public function hanging_sale(Request $request)
  317. {
  318. $data = UtilService::postMore([
  319. ['id'],
  320. ]);
  321. Db::startTrans();
  322. $product = AuctionProduct::where('id', $data['id'])->lock(true)->where('uid', $request->uid())->find();
  323. $user = User::where('uid', $request->uid())->find();
  324. if (!$product) return app('json')->fail('商品不存在');
  325. if ($product['frozen'] == 1) return app('json')->fail('商品已冻结,无法挂售');
  326. if ($product['is_show'] == 1) return app('json')->fail('商品已挂售');
  327. $guId = Auction::where('id', $product['auction_id'])->value('auction_gu_id');
  328. $auction_id = Auction::where('auction_gu_id', $guId)->column('id');
  329. $max = AuctionGu::where('id', $guId)->value('max_hanging');
  330. $money = AuctionProduct::where('is_show', 1)
  331. ->where('is_admin', 2)
  332. ->where('uid', $request->uid())
  333. ->where('auction_id', 'in', $auction_id)
  334. ->whereBetweenTime('update_time',strtotime('today'), strtotime('tomorrow'))
  335. ->sum('hanging_price');
  336. if (($money+$product['hanging_price']) > (float)$max) return app('json')->fail('今天挂售金额已超出上限');
  337. $datas = AuctionProduct::bs($data['id']);// 获取挂售详情
  338. if ($user['anticipate'] < $datas['anticipate']) return app('json')->fail('广告值不足');
  339. $product['price'] = $product['hanging_price'];
  340. $product['hanging_price'] = $datas['hanging_price']; // 商品变为挂售价格
  341. $product['is_show'] = 1; // 上架
  342. $product['is_admin'] = 2;
  343. $user['anticipate'] -= $datas['anticipate']; // 扣除广告值
  344. $user['integral'] += $datas['give'];
  345. try {
  346. // 新增挂售时间段
  347. AuctionTime::create([
  348. 'uid' => $request->uid(),
  349. 'product_id' => $product['id'],
  350. 'auction_id' => $product['auction_id'],
  351. 'add_time' => strtotime($datas['gs_time'])
  352. ]);
  353. $product->save();
  354. $user->save();
  355. AuctionOrder::where([['uid', '=', $request->uid()], ['product_id', '=', $product['id']], ['is_gs', '=', 0]])->update(['is_gs' => 1, 'gs_price' => $datas['hanging_price']]);// 修改订单挂售
  356. UserBill::expend('挂售扣除广告值', $user['uid'], 'anticipate', 'gs_anticipate', $datas['anticipate'], $user['spread_uid'], $user['anticipate'], '挂售商品'.$product['id'].'扣除广告值');
  357. UserBill::income('赠送趣豆', $user['uid'], 'integral', 'gs_integral', $datas['give'], $user['spread_uid'], $user['integral'], '挂售赠送趣豆');
  358. Db::commit();
  359. return app('json')->successful('挂售成功');
  360. } catch (\Exception $e) {
  361. Db::rollback();
  362. return app('json')->fail($e->getMessage());
  363. }
  364. }
  365. /**
  366. * 取消挂售
  367. * @param Request $request
  368. * @return void
  369. * @throws \think\db\exception\DataNotFoundException
  370. * @throws \think\db\exception\DbException
  371. * @throws \think\db\exception\ModelNotFoundException
  372. */
  373. public function cancel(Request $request)
  374. {
  375. $data = UtilService::postMore([
  376. ['id']
  377. ]);
  378. $productModel = new AuctionProduct();
  379. $details = $productModel->find($data['id']);
  380. if (!$details) return app('json')->fail('商品不存在');
  381. if ($details['uid'] != $request->uid()) return app('json')->fail('当前商品不属于你');
  382. $order = AuctionOrder::where([['product_id', '=', $details['id']], ['status', '<', 3], ['status', '>', 0]])->find();
  383. if ($order) return app('json')->fail('商品已出售,无法取消');
  384. $auction = Auction::where('id', $details['auction_id'])->find();
  385. $data['time'] = explode(',', $auction['site']);
  386. $date = date('w', time()); // 今天星期几
  387. $bs = 0;
  388. if (in_array(1, $data['time'])){
  389. if ($date >= 1 and $date <= 2){
  390. $bs = 3 - $date;
  391. }elseif ($date >= 3 and $date <= 4){
  392. $bs = 5 - $date;
  393. }elseif ($date >= 5 or $date == 0){
  394. if ($date == 5) $bs = 3;
  395. if ($date == 6) $bs = 2;
  396. if ($date == 0) $bs = 1;
  397. }
  398. }else if (in_array(2, $data['time'])){
  399. if ($date >= 2 and $date <= 3){
  400. $bs = 4 - $date;
  401. }elseif ($date >= 4 and $date <= 5){
  402. $bs = 6 - $date;
  403. }elseif ($date >= 6 or $date == 0 or $date == 1){
  404. if ($date == 6) $bs = 3;
  405. if ($date == 0) $bs = 2;
  406. if ($date == 1) $bs = 1;
  407. }
  408. }
  409. $user = User::where('uid', $request->uid())->find();
  410. $anticipate = round($details['price'] * $details['deduct']/100, 2);
  411. $details['hanging_price'] = $details['price']; // 价格变=回未挂售前;
  412. $details['is_show'] = 0; // 价格变回未挂售前;
  413. $user['anticipate'] += $anticipate*$bs;// 退回挂售扣除的预约广告值
  414. $user['integral'] -= round(($details['price'] * $details['give']/100)*$bs, 2);// 挂售赠送趣豆
  415. try {
  416. Db::startTrans();
  417. $details->save();
  418. $user->save();
  419. AuctionOrder::where('order_id', $details['order'])->save(['is_gs' => 0]);
  420. UserBill::income('取消挂售退回广告值', $request->uid(), 'anticipate', 'gsth_anticipate', $anticipate*$bs, 0, $user['anticipate'], '取消挂售退回广告值');
  421. UserBill::expend('取消挂售扣除趣豆', $request->uid(), 'integral', 'gsth_integral', round(($details['price'] * $details['give']/100)*$bs, 2), 0, $user['integral'], '取消挂售扣除赠送趣豆');
  422. AuctionTime::where([['uid', '=', $request->uid()], ['product_id', '=', $data['id']]])->delete(); // 删除上架时间
  423. Db::commit();
  424. return app('json')->successful('取消挂售成功');
  425. } catch (\Exception $e) {
  426. Db::rollback();
  427. return app('json')->fail('取消挂售失败');
  428. }
  429. }
  430. /**
  431. * 订单数量
  432. * @param Request $request
  433. * @return mixed
  434. */
  435. public function untreated(Request $request){
  436. $data = [
  437. 'user' => [
  438. 'paid' => AuctionOrder::where([['uid', '=', $request->uid()], ['status', '=', 1]])->count(), //待支付
  439. 'reviewed' => AuctionOrder::where([['uid', '=', $request->uid()], ['status', '=', 2]])->count(), // 待审核
  440. 'hanging' => AuctionOrder::where([['uid', '=', $request->uid()], ['status', '=', 3], ['is_gs', '=', 0]])->count(), // 待挂售
  441. ],
  442. 'seller' => [
  443. 'paid' => AuctionOrder::where([['collection_id', '=', $request->uid()], ['status', '=', 1]])->count(), //待支付
  444. 'reviewed' => AuctionOrder::where([['collection_id', '=', $request->uid()], ['status', '=', 2]])->count(), // 待审核
  445. 'hanging' => AuctionOrder::where([['uid', '=', $request->uid()], ['status', '=', 3], ['is_gs', '=', 1]])->count(), //挂售中
  446. ]
  447. ];
  448. return app('json')->successful($data);
  449. }
  450. /**
  451. * 提货
  452. * @param Request $request
  453. * @return mixed
  454. * @throws \think\db\exception\DataNotFoundException
  455. * @throws \think\db\exception\DbException
  456. * @throws \think\db\exception\ModelNotFoundException
  457. */
  458. public function carry(Request $request)
  459. {
  460. list($addressId, $productId) = UtilService::postMore([
  461. ['addressId', ''], ['productId', '']
  462. ], $request, true);
  463. if (!$addressId) return app('json')->fail('请选择收货地址');
  464. if (!$productId) return app('json')->fail('请选择提货商品');
  465. $uid = $request->uid();
  466. $address = UserAddress::where('id', $addressId)->where('uid', $uid)->find();
  467. $product = AuctionProduct::where([['uid','=', $uid], ['id', '=', $productId]])->find();
  468. $order = AuctionOrder::where('uid', '<>', $uid)->where('status', '>', 0)->where('product_id', $productId)->where('create_time', '>', strtotime('today'))->find();
  469. if ($product['is_show'] == 1) return app('json')->fail('商品只能下架后提货');
  470. if ($order) return app('json')->fail('该商品出售中,无法提货');
  471. if (!$address) return app('json')->fail('收货地址不存在');
  472. if (!$product) return app('json')->fail('提货商品不存在');
  473. Db::startTrans();
  474. $res = AuctionDeliver::create([
  475. 'uid' => $uid,
  476. 'product_id' => $productId,
  477. 'name' => $product['name'],
  478. 'image' => $product['image'],
  479. 'price' => $product['hanging_price'],
  480. 'real_name' => $address['real_name'],
  481. 'user_phone' => $address['phone'],
  482. 'user_address' => $address['province'].' '.$address['city'].' '.$address['district'].' '.$address['detail'],
  483. ]);
  484. $res1 = $product->delete();
  485. if ($res && $res1){
  486. Db::commit();
  487. return app('json')->success('提货成功');
  488. }else{
  489. Db::rollback();
  490. return app('json')->fail('提货失败');
  491. }
  492. }
  493. /**
  494. * 提货订单
  495. * @param Request $request
  496. * @return mixed
  497. * @throws \think\db\exception\DataNotFoundException
  498. * @throws \think\db\exception\DbException
  499. * @throws \think\db\exception\ModelNotFoundException
  500. */
  501. public function deliver_list(Request $request)
  502. {
  503. list($status, $page, $limit) = UtilService::postMore([
  504. ['status', 0], ['page', 1], ['limit', 10]
  505. ], $request, true);
  506. $list = AuctionDeliver::where('uid', $request->uid())
  507. ->where('status', $status)
  508. ->order('id DESC')
  509. ->page($page, $limit)
  510. ->select();
  511. $list = count($list) > 0? $list->toArray(): [];
  512. foreach ($list as &$item){
  513. if (!empty($item['goods_time'])) $item['goods_time'] = date('Y-m-d H:i:s', $item['goods_time']);
  514. if (!empty($item['collect_time'])) $item['collect_time'] = date('Y-m-d H:i:s', $item['collect_time']);
  515. }
  516. return app('json')->success($list);
  517. }
  518. /**
  519. * 提货订单详情
  520. * @param Request $request
  521. * @return mixed
  522. * @throws \think\db\exception\DataNotFoundException
  523. * @throws \think\db\exception\DbException
  524. * @throws \think\db\exception\ModelNotFoundException
  525. */
  526. public function deliver(Request $request)
  527. {
  528. list($id) = UtilService::postMore([
  529. ['id', 0]
  530. ], $request, true);
  531. $details = AuctionDeliver::where('uid', $request->uid())->where('id', $id)->find();
  532. if (!$details) return app('json')->fail('订单不存在');
  533. if (!empty($details['goods_time'])) $details['goods_time'] = date('Y-m-d H:i:s', $details['goods_time']);
  534. if (!empty($details['collect_time'])) $details['collect_time'] = date('Y-m-d H:i:s', $details['collect_time']);
  535. return app('json')->success($details->toArray());
  536. }
  537. public function collect(Request $request)
  538. {
  539. list($id) = UtilService::postMore([
  540. ['id', 0]
  541. ], $request, true);
  542. $details = AuctionDeliver::where('uid', $request->uid())->where('id', $id)->find();
  543. if (!$details) return app('json')->fail('订单不存在');
  544. if ($details['status'] == 0) return app('json')->fail('未发货');
  545. if ($details['status'] == 2) return app('json')->fail('已收货');
  546. $res = AuctionDeliver::where('uid', $request->uid())->where('id', $id)->update(['status' => 2, 'collect_time' => time()]);
  547. if ($res) return app('json')->success('确认收货');
  548. return app('json')->fail('收货失败');
  549. }
  550. }