public function listBids($id) { $token = Input::get('token', ''); $u_id = Input::get('u_id', ''); $just_check = Input::get('just_check', 1); try { $user = User::chkUserByToken($token, $u_id); $list = AuctionBid::where('u_id', '=', $u_id)->where('a_id', '=', $id)->get(); $data = []; if (count($list) == 0) { $data['bought'] = 0; } else { $data['bought'] = 1; if (!$just_check) { foreach ($list as $key => $bid) { $data['bids'][] = $bid->shwoInList(); } } } $re = Tools::reTrue('获取出价记录成功', $data); } catch (Exception $e) { $re = Tools::reFalse($e->getCode(), '获取出价记录失败:' . $e->getMessage()); } return Response::json($re); }
public static function cronRunTheWheel() { $now = Tools::getNow(); $auction = Auction::join('event_items', function ($q) { $q->on('event_items.e_id', '=', 'auctions.e_id'); })->where('event_items.e_end_at', '<', $now)->where('auctions.a_status', '=', 1)->orderBy('event_items.e_start_at')->first(); if (empty($auction)) { throw new Exception("没有需要处理的竞拍", 2000); } $auction->load(['eventItem']); $list = AuctionBid::where('a_id', '=', $auction->a_id)->orderBy('b_price', 'DESC')->get(); if ($list->count() <= 0) { throw new Exception("无人出价", 2000); } $win = $list->first(); if ($win->is_win) { throw new Exception("中奖信息已处理", 2000); } $user = User::find($win->u_id); $auction->a_win_username = $user->u_nickname; $auction->a_win_id = $win->b_id; $auction->a_win_price = $win->b_price; $auction->a_status = 2; foreach ($list as $key => $bid) { if ($bid->u_id == $win->u_id) { continue; } else { $msg = new MessageDispatcher($bid->u_id); $msg->fireTextToUser('非常抱歉您参与的' . $auction->eventItem->e_title . '没有拍到'); } } $price = number_format($auction->a_win_price); $msg = new MessageDispatcher($win->u_id, 1, 1, 1); $msg->setMessage(['phone' => $user->u_mobile]); $msg->fireTextToUser('恭喜您以' . $price . '元成功拍得 ' . $auction->eventItem->e_title . ' 产品。请于48小时之内在我的竞拍里完成付款,逾期视为放弃,感谢您的参与'); $win->is_win = 1; $win->is_pay = 0; $auction->save(); $win->save(); return true; }