* @day: 2017/11/02 */ namespace app\models\auction; use crmeb\traits\ModelTrait; use crmeb\basic\BaseModel; /** * 竞拍上坪 Model * Class WechatNews * @package app\admin\model\wechat */ class AuctionProduct extends BaseModel { use ModelTrait; protected $pk = 'id'; protected $name = 'auction_product'; protected $autoWriteTimestamp = true; /** * 竞拍商品列表 * @param $data * @param $uid * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public static function list($data, $uid){ $model = self::where('auction_id', $data['id'])->order('succeed_time ASC,is_show DESC,id DESC'); $model = $model->page($data['page'], $data['limit']); if ($data['name']) $model->where('name', 'like', '%'.$data['name'].'%'); $list = $model->select(); $list = empty($list)? [] : $list->toArray(); foreach ($list as &$item){ $item['status'] = 1; if ($item['succeed_time'] == strtotime('today') || $item['is_show'] == 0) $item['status'] = 2; } return $list; } /** * 用户商品 * @param $data * @param $uid * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public static function user_product($data, $uid){ $model = self::alias('a') ->field('a.*,b.nickname') ->leftJoin('auction b', 'a.auction_id = b.id') ->where('a.uid', $uid)->order('a.id DESC'); $model->page($data['page'], $data['limit']); $list = $model->select(); $list = empty($list)? [] : $list->toArray(); return $list; } /** * 场次时间到期用户未出售商品下架 * @return void */ public static function off_the_shelf(){ $auction = Auction::where('rend_time', '<', date('H:i:s'))->select(); if ($auction){ foreach ($auction as $k => $v) { $productId = AuctionTime::where('auction_id', '=', $v['id'])->where('add_time', '=', strtotime(date('Y-m-d', time())))->column('product_id'); if ($productId){ $orderId = AuctionOrder::where('product_id', 'in', $productId)->where('frequency', '=', $v['frequency'])->where('status','>', 0)->column('product_id'); if ($orderId){ foreach ($orderId as $value){ if (in_array($value, $productId))unset($productId[$value]); } } if ($productId){ foreach ($productId as $item){ $product = AuctionProduct::where([['id', '=', $item], ['is_admin', '=', 2]])->find();// 查找今天场次没买出去的商品下架 if ($product){ $product['is_show'] = 0; $product['hanging_price'] = $product['price']; $product->save(); } } } $order = AuctionProduct::where([['id', 'in', $productId], ['auction_id', '=', $v['id']], ['is_admin', '=', 2]])->column('order');// 查找今天场次没买出去的商品订单 AuctionOrder::where('order_id', 'in', $order)->save(['is_gs' => 0]);//订单为未挂售状态 AuctionTime::where('auction_id', '=', $v['id'])->where('add_time', '<=', strtotime(date('Y-m-d', time())))->delete(); // 清除今天挂售时间 } } } } public static function bs($id) { $product = AuctionProduct::where('id',$id)->find(); $auction = Auction::where('id', $product['auction_id'])->find(); if (!$product) return app('json')->fail('商品不存在'); $time = explode(',', $auction['site']); $date = date('w', time()); // 今天星期几 if ($date == 0) $date = 7;//星期天 $count = count($time); $week = [ 1 => 'Monday', // 星期一 2 => 'Tuesday', // 星期二 3 => 'Wednesday', // 星期三 4 => 'Thursday', // 星期四 5 => 'Friday', // 星期五 6 => 'Saturday', // 星期六 7 => 'Sunday', //星期天 ]; $data['gs_time'] = ''; $bs = 0; if ($count <= 1){ $toweek = $week[$time[0]]; $bs = (strtotime("next ".$toweek) - strtotime('today'))/86400; $data['gs_time'] = date('Y-m-d H:i:s', strtotime("next ".$toweek)); }else{ $node = 0; foreach ($time as $item) { $node ++; if ($node < $count){ if ($date >= $item and $date < $time[$node]){ $bs = $time[$node] - $date; $data['gs_time'] = date('Y-m-d H:i:s', strtotime($week[$time[$node]])); } }else{ if ($date >= $item){ $toweek = $week[$time[0]]; $bs = (strtotime("next ".$toweek) - strtotime('today'))/86400; $data['gs_time'] = date('Y-m-d H:i:s', strtotime("next ".$toweek)); } } } } $hanging_price = round($product['hanging_price'] * $product['rise']/100, 2); // 溢价 $anticipate = round($product['hanging_price'] * $product['deduct']/100, 2); // 扣除 $give = $product['hanging_price'] * $product['give']/100;// 赠送趣豆 $data['price'] = $product['hanging_price']; $data['hanging_price'] = ($product['hanging_price'] + ($hanging_price * $bs)); $data['anticipate'] = round($anticipate*$bs,2); $data['give'] = round($give*$bs,2); return $data; } }