-1) { $model = $model->where('status', '=', $param['status']); } if (isset($param['title']) && !empty($param['title'])) { // 修改为正确的字段名 active_name $model = $model->where('active_name', 'like', '%' . trim($param['title']) . '%'); } $res = $model->with(['file']) ->order('create_time', 'desc') ->paginate($param); foreach ($res as $key => $val) { $res[$key]['start_time'] = format_time($val['start_time']); $res[$key]['end_time'] = format_time($val['end_time']); } return $res; } /** * 获取有效的团购活动 */ public static function getValidActive() { return (new static()) ->where('start_time', '<=', time()) ->where('end_time', '>', time()) ->where('status', '=', 1) ->where('is_delete', '=', 0) ->order(['sort' => 'asc', 'create_time' => 'desc']) ->find(); } /** * 获取团购商品列表 */ public function getGroupbuyProductList($groupbuy_active_id, $limit) { // 获取列表数据 $list = $this->alias("a") ->with(['product.image.file', 'groupbuySku']) ->join('product product', 'product.product_id=a.product_id') ->join('supplier supplier', 'product.shop_supplier_id = supplier.shop_supplier_id', 'left') ->where('groupbuy_active_id', '=', $groupbuy_active_id) ->where('a.is_delete', '=', 0) ->where('a.status', '=', 10) ->where('a.state', '=', 10) ->where('product.is_delete', '=', 0) ->where('supplier.is_delete', '=', 0) ->where('supplier.status', '=', 0) ->limit($limit) ->select(); $data = []; foreach ($list as $item) { $data[] = [ 'product' => $item['product'], 'groupbuySku' => $item['groupbuySku'], 'groupbuy_price' => $item['groupbuySku'][0]['groupbuy_price'], 'product_price' => $item['groupbuySku'][0]['product_price'], 'groupbuy_num' => $item['groupbuy_num'], 'limit_num' => $item['limit_num'], 'stock' => $item['groupbuySku'][0]['groupbuy_stock'], 'product_sales' => $item['product']['product_sales'] + $item['sales_initial'], ]; } return $data; } }