* @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('is_show', 1)->where('auction_id', $data['id'])->order('sort DESC,id DESC'); $model->page($data['page'], $data['limit']); if ($data['name']) $model->where('name', 'like', '%'.$data['name'].'%'); $list = $model->select(); $list = empty($list)? [] : $list->toArray(); $lists = []; if ($list){ foreach ($list as $k => $v) { $auction = Auction::where('id', $v['auction_id'])->find(); $order = AuctionOrder::where('product_id', $v['id'])->where('status', '>', 0)->where('frequency', $auction['frequency'])->find(); if ($order){ $list[$k]['status'] = 2;// 已被购买 $list[$k]['str'] = '已卖完'; }else{ $list[$k]['status'] = 1;// 能购买 $list[$k]['str'] = '购买'; } if ($v['is_admin'] == 2){ $time = AuctionTime::where([['auction_id', '=', $auction['id']], ['product_id', '=', $v['id']], ['add_time', '=', strtotime(date('Y-m-d', time()))]])->find(); if (!$time){ unset($list); } else{ $lists[] = $list[$k]; } }else{ $lists[] = $list[$k]; } } }; return $lists; } /** * 用户商品 * @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::where('uid', $uid)->order('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]); } } AuctionProduct::where([['id', 'in', $productId], ['auction_id', '=', $v['id']], ['is_admin', '=', 2]])->save(['is_show' => 0]);// 查找今天场次没买出去的商品下架 // self::where('auction_id', '=', $v['id'])->where('add_time', '<=', strtotime(date('Y-m-d', time())))->delete(); // 清除今天挂售时间 } } } } }