page($data['page'], $data['limit']); $model->order('id DESC, sort DESC'); $id = []; if ($data['advance']){ $model->where('id', 'in', $id); } $list = $model->select(); $list = count($list) ? $list->toArray() : []; if ($list){ foreach ($list as $k =>$v) { $list[$k]['time'] = strtotime($v['radd_time']) - 1800; $list[$k]['e_time'] = strtotime($v['rend_time']); $list[$k]['day'] = date('Y-m-d H:i:s', strtotime($v['radd_time']) - 1800); if (strtotime($v['rend_time']) < time()){ $booking = AuctionBooking::where([['uid', '=', $uid], ['frequency', '=', $v['frequency']+1], ['auction_id', '=', $v['id']]])->field('auction_id')->find(); if ($booking){ $list[$k]['sta'] = 2; // 进入 $list[$k]['str'] = '进入'; }else{ $list[$k]['sta'] = 1; // 预约 $list[$k]['str'] = '预约'; } }else{ $booking = AuctionBooking::where([['uid', '=', $uid], ['frequency', '=', $v['frequency']], ['auction_id', '=', $v['id']]])->field('auction_id')->find(); if ($booking){ $list[$k]['sta'] = 2; // 进入 $list[$k]['str'] = '进入'; }else{ $list[$k]['sta'] = 1; // 预约 $list[$k]['str'] = '预约'; } } } } return $list; } /** * 每日修改场次 * @return void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public static function frequency() { $list = self::select(); foreach ($list as $k => $v){ if ($v['day_time'] < time()){ $find = self::find($v['id']); $find['day_time'] = strtotime(date('Y-m-d 23:59:59')); $find['frequency'] = $v['frequency'] + 1; $find->save(); } } } public static function recovery() { $auction = Auction::select(); $recovery = (int)SystemConfigService::get('recovery'); if ($auction){ foreach ($auction as $k => $v) { if (strtotime($v['rend_time'])-300 < time()){ //关闭场次五分钟前 $orderCount = AuctionOrder::where('auction_id', '=', $v['id'])->where('status', '>',0)->where('price', '<', $recovery)->count();// 当前订单数量 $bok = AuctionBooking::where([['auction_id', '=', $v['id']], ['frequency', '=', $v['frequency']]])->count(); $count = ceil($bok * ($v['dispatch']/100)); $orderId = AuctionOrder::where([['auction_id', '=', $v['id']], ['frequency', '=', $v['frequency']], ['status', '>', 0]])->column('product_id'); if ($orderCount < $count){ // 如果购买人数没有到放单人数 for ($x=1 ; $x <= $count; $x++){ $orderId = AuctionOrder::where([['auction_id', '=', $v['id']], ['frequency', '=', $v['frequency']], ['status', '>', 0]])->column('product_id'); $product = AuctionProduct::where([['auction_id', '=', $v['id']], ['is_show', '=', 1], ['id', 'notIn', $orderId], ['uid', '<>', 1], ['hanging_price', '<', $recovery]] )->orderRaw('rand()') ->limit(1) ->find(); // 随机出来一个商品 $orderData = [ 'uid' => 1, 'collection_id' => $product['uid'], 'order_id' => getNewOrderId(), 'auction_id' => $v['id'], 'product_id' => $product['id'], 'name' => $product['name'], 'image' => $product['image'], 'price' => $product['hanging_price'], 'actual_price' => $product['hanging_price'] - $product['price'], 'create_time' => time(), 'frequency' => $v['frequency'] ]; AuctionOrder::create($orderData); unset($orderData);// 清空数组 } } $auctionProduct = AuctionProduct::where([['auction_id', '=', $v['id']], ['is_show', '=', 1],['id', 'notIn', $orderId],['hanging_price', '>', $recovery]])->select();// 如果又商品成功回收价格 if ($auctionProduct){ // 商品价格超出规定值进行回收 foreach ($auctionProduct as $key => $value){ $orderData = [ 'uid' => 1, 'collection_id' => $value['uid'], 'order_id' => getNewOrderId(), 'auction_id' => $v['id'], 'product_id' => $value['id'], 'name' => $value['name'], 'image' => $value['image'], 'price' => $value['hanging_price'], 'actual_price' => $value['hanging_price'] - $value['price'], 'create_time' => time(), 'frequency' => $v['frequency'] ]; AuctionOrder::insert($orderData); unset($orderData); // 清空数组 } } } } } } }