get('page',1); $pageSize = $request->get('pageSize',1); $memberId = $request->get('member_id', ''); $datetime = $request->get('order_addtimes',[]); $goodsName = $request->get('goods_name',''); if (!$memberId) { return json_fail('查询错误'); } $goodsIds = []; if (!empty($goodsName)){ $goodsIds = Goods::where('goods_name','like','%'.$goodsName.'%')->pluck('goods_id')->toArray(); } // 预约单 $appointments = Db::table('appointment') // ->leftJoin('member', 'member.member_id', '=', 'appointment.join_appointment_member_id') // ->leftJoin('member_cert', 'member_cert.join_cert_member_id', '=', 'appointment.join_appointment_member_id') // ->leftJoin('member_info', 'member_info.join_info_member_id', '=', 'appointment.join_appointment_member_id') ->leftJoin('goods', 'goods.goods_id', '=', 'appointment.join_appointment_goods_id') // ->leftJoin('order', 'order.order_id', '=', 'appointment.join_appointment_order_id') ->leftJoin('member_benefit', 'member_benefit.member_benefit_id', '=', 'appointment.join_appointment_member_benefit_id') // ->leftJoin('goods_sku', 'goods_sku.goods_sku_id', '=', 'appointment.join_appointment_goods_sku_id') ->where('join_appointment_member_id', $memberId) ->whereIn('appointment_status', ['WAITING', 'PENDING', 'DOING', 'DONE', 'CANCEL', 'REVOKE']) ->select('appointment.*', // 'member.member_mobile', // 'member_cert.member_cert_name', // 'member_info.member_info_nickname', 'goods.goods_name', 'goods.goods_sales_price', // 'order.order_name', 'goods_sku.goods_sku_specs_json', 'order.order_amount_total', 'order.order_amount_pay', // 'order.order_category', 'order.order_status_system', 'order.order_status_payment', 'order.order_status_storage', // 'order.order_addtimes', 'member_benefit.member_benefit_name' )->when(!empty($goodsIds),function($query) use ($goodsIds){ $query->whereIn('join_appointment_goods_id',$goodsIds); }) ->when(!empty($datetime), function($query) use ($datetime){ $datetime[0] = strtotime($datetime[0]); $datetime[1] = strtotime($datetime[1]); $query->whereBetween('appointment_addtimes',$datetime); }); $total = $appointments->count(); $rows = $appointments->orderBy('appointment.appointment_addtimes', 'desc') ->get(); foreach ($rows as &$row) { if ($row->appointment_category == 'NOFEE') { $row->member_benefit_name = "后付费预约"; } $row->appointment_addtimes = date('Y-m-d H:i:s', $row->appointment_addtimes); } return json_success('', compact('rows', 'page', 'pageSize', 'total')); } }