public function index(Request $request) { $start = $request->input('start', 0); $length = $request->input('length', 5); $draw = $request->input('draw', 1); $show_putaway = $request->input('show_putaway', 0); $category_id = $request->input('category_id'); if ($category_id != null) { if ($show_putaway == 0) { $goods = Goods::where('is_putaway', 1); $goods = $goods->where('category_id', $category_id); } else { $goods = Goods::where('category_id', $category_id); } $count = $goods->count(); $goods->skip($start)->take($length)->orderBy('id', 'desc'); } else { if ($show_putaway == 0) { $goods = Goods::where('is_putaway', 1); $count = $goods->count(); $goods = $goods->skip($start)->take($length)->orderBy('id', 'desc'); } else { $goods = Goods::orderBy('goods.id', 'desc'); $keywords = $request->input('key_words'); if ($keywords != null && $keywords != '') { $goods = $goods->where('goods.name', 'like', '%' . $keywords . '%')->orWhere('goods.goods_description', 'like', '%' . $keywords . '%'); } $baoyou = $request->input('baoyou'); if ($baoyou != 0) { $goods = $goods->join('free_post_goods', 'free_post_goods.goods_id', '=', 'goods.id'); } $baopin = $request->input('baopin'); if ($baopin != 0) { $goods = $goods->join('conversion_goods', 'conversion_goods.goods_id', '=', 'goods.id'); } $guanlian = $request->input('guanlian'); if ($guanlian != 0) { $goods = $goods->join('theme_goods', 'theme_goods.goods_id', '=', 'goods.id'); } $fenlei = $request->input('fenlei'); if ($fenlei != -1) { $goods = $goods->join('activity_classification_goods', 'activity_classification_goods.goods_id', '=', 'goods.id')->where('activity_classification_goods.activity_classification_id', '=', $fenlei); } $presell = $request->input('presell'); if ($presell != 0) { $goods = $goods->where('goods.is_presell', '=', 1); } $goods = $goods->select('goods.*'); $count = $goods->count(); $goods = $goods->skip($start)->take($length); } } $goods = $goods->get(); $arrGoodsList = []; foreach ($goods as $g) { $arrGoods['id'] = $g->id; $arrGoods['name'] = $g->name; $arrGoods['price'] = $g->price; $arrGoods['original_price'] = $g->original_price; $arrGoods['use_coupon'] = $g->use_coupon; $arrGoods['coupon_amount'] = $g->coupon_amount; $arrGoods['express_way'] = $g->express_way; $arrGoods['express_fee'] = $g->express_fee; $arrGoods['returned_goods'] = $g->returned_goods; $arrGoods['is_putaway'] = $g->is_putaway; //$arrGoods['express_fee']=$g->express_fee; $arrGoodsList[] = $arrGoods; } echo json_encode(array("draw" => intval($draw), "recordsTotal" => intval($count), "recordsFiltered" => intval($count), "data" => $arrGoodsList)); }