fail('场次不存在'); if (AuctionOrder::where([['auction_id', '=', $data['id']], ['frequency', '=', $auction['frequency']], ['uid', '=', $request->uid()]])->count() >= 1) return app('json')->fail('当前场次已购买商品'); $orderCount = AuctionOrder::where([['auction_id', '=', $data['id']], ['frequency', '=', $auction['frequency']]])->count(); // 查找出当前场次已派单多少 $pd = AuctionBooking::where([['auction_id', '=', $data['id']], ['frequency', '=', $auction['frequency']]])->count(); // 当前预约人数 $pds = ceil($pd * ($auction['dispatch']/100)); if ($orderCount >= $pds) return app('json')->fail('商品已买完'); $show = AuctionProduct::random($data['id'], $request->uid()); if ($show == 'false') return app('json')->fail('购买失败'); return app('json')->successful($show); } /** * 用户商品 * @param Request $request * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function user_product(Request $request) { $data = UtilService::getMore([ [['page', 'd'], 0], [['limit', 'd'], 0], ]); return app('json')->successful(AuctionProduct::user_product( $data,$request->uid())); } /** * 用户订单 * @param Request $request * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function user_auction_order(Request $request) { $data = UtilService::getMore([ [['type', 'd'], 0], [['page', 'd'], 0], [['limit', 'd'], 0], ['order_id'] ]); return app('json')->successful(AuctionOrder::userOrder($data,$request->uid())); } /** * 卖家显示订单 * @param Request $request * @return void */ public function seller(Request $request) { $data = UtilService::getMore([ ['type', 0], [['page', 'd'], 0], [['limit', 'd'], 0], ['order_id'] ]); return app('json')->successful(AuctionOrder::seller_list($data,$request->uid())); } /** * 支付订单 * @param Request $request * @return void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function zfpay(Request $request) { $data = UtilService::postMore([ ['order_id'] ]); $model = new User(); $order = AuctionOrder::where('order_id', $data['order_id'])->find(); if (!$order) return app('json')->fail('订单不存在'); if ($order['status'] == 0 or $order['status'] == 2) return app('json')->fail('订单状态不对'); $user = $model->where('uid', $request->uid())->find(); if ($user['now_money'] < $order['actual_price']) return app('json')->fail('余额不足'); try { Db::startTrans(); AuctionOrder::pay($order, $request->uid()); Db::commit(); return app('json')->successful('支付成功'); } catch (\Exception $e) { Db::rollback(); return app('json')->fail('支付失败'); } } }