getActiveSheet(); //列宽 $sheet->getColumnDimension('B')->setWidth(35); $sheet->getColumnDimension('P')->setWidth(35); //设置工作表标题名称 $sheet->setTitle('订单明细'); $sheet->setCellValue('A1', '会员编号'); $sheet->setCellValue('B1', '报单中心'); $sheet->setCellValue('C1', '订单号'); $sheet->setCellValue('D1', '订单状态'); $sheet->setCellValue('E1', '存货编码'); // 商品编码 $sheet->setCellValue('F1', '存货名称'); // 商品名称 $sheet->setCellValue('G1', '规格编码'); $sheet->setCellValue('H1', '数量'); // 商品数量 $sheet->setCellValue('I1', '收货人'); $sheet->setCellValue('J1', '联系方式1'); $sheet->setCellValue('K1', '联系方式2'); // TODO: 新增 $sheet->setCellValue('L1', '省'); $sheet->setCellValue('M1', '市'); $sheet->setCellValue('N1', '区'); $sheet->setCellValue('O1', '详细地址'); $sheet->setCellValue('P1', '期数'); $sheet->setCellValue('Q1', '订单类型'); $sheet->setCellValue('R1', '发货仓'); $sheet->setCellValue('S1', '创建时间'); $sheet->setCellValue('T1', '支付时间'); $sheet->setCellValue('U1', '发货时间'); $sheet->setCellValue('V1', '商品单价'); $sheet->setCellValue('W1', '商品金额'); // 商品总额 $sheet->setCellValue('X1', '商品PV'); // 商品pv $sheet->setCellValue('Y1', 'PV合计'); // 合计pv $sheet->setCellValue('Z1', '运费'); $sheet->setCellValue('AA1', '快递公司'); $sheet->setCellValue('AB1', '快递单号'); $sheet->setCellValue('AC1', '发货方式'); $sheet->setCellValue('AD1','会员备注'); $sheet->setCellValue('AE1','发货状态'); $sheet->setCellValue('AF1','售后状态'); //填充数据 $index = 0; //获取售后记录 $orderProductIds = array_column($list, 'order_product_id'); $refunds = OrderRefund::whereIn('order_product_id', $orderProductIds) ->field('order_refund_id,order_product_id,type,is_agree') ->select(); $refundMap = []; if (!$refunds->isEmpty()) { $refundMap = array_column($refunds->toArray(), null, 'order_product_id'); } foreach ($list as $order) { //售后状态 $refundStatus = '无'; if (isset($refundMap[$order['order_product_id']])) { $info = $refundMap[$order['order_product_id']]; $refundStatus = $info['type']['text'] . '-' . $info['is_agree']['text']; } $state_text = $this->getStateTextAttr($order); $delivery = $order['delivery_status'] == 10?'未发货':'已发货'; if ($order['delivery_type'] == 10) { $type = '快递配送'; }elseif ($order['delivery_type'] == 20) { $type = '上门自提'; }else{ $type = '无需物流'; } $price = empty($order['grade_product_price'])?$order['product_price']:$order['grade_product_price']; $richText = new \PhpOffice\PhpSpreadsheet\RichText\RichText(); $richText->createText((string)$order['user_no']); $sheet->setCellValue('A' . ($index + 2), $richText); $sheet->setCellValue('B'.($index + 2),""); $richText = new \PhpOffice\PhpSpreadsheet\RichText\RichText(); $richText->createText((string)$order['order_no']); $sheet->setCellValue('C'.($index + 2), $richText); $sheet->setCellValue('D'.($index + 2), $state_text); $sheet->setCellValue('E'.($index + 2), trim($order['product_no'])); $sheet->setCellValue('F'.($index + 2), $order['product_name']); $sheet->setCellValue('G'.($index + 2), trim($order['sku_product_no'] ?: $order['product_no'])); $sheet->setCellValue('H'.($index + 2), $order['total_num']); $sheet->setCellValue('I'.($index + 2), $order['name']); $sheet->setCellValue('J'.($index + 2), $order['phone']); $sheet->setCellValue('K'.($index + 2), ''); $sheet->setCellValue('L'.($index + 2), $order['province']); $sheet->setCellValue('M'.($index + 2), $order['city']); $sheet->setCellValue('N'.($index + 2), $order['region']); $sheet->setCellValue('O'.($index + 2), $order['detail']); $sheet->setCellValue('P'.($index + 2), ""); $sheet->setCellValue('Q'.($index + 2), '重消'); $sheet->setCellValue('R'.($index + 2), "\t"."01"."\t"); $sheet->setCellValue('S'.($index + 2), $order['create_time']); $sheet->setCellValue('T'.($index + 2), $this->filterTime($order['pay_time'])); $sheet->setCellValue('U'.($index + 2), $this->filterTime($order['delivery_time'])); $sheet->setCellValue('V'.($index + 2), $price); $sheet->setCellValue('W'.($index + 2), $order['total_price']); $sheet->setCellValue('X'.($index + 2), $order['pv']); $sheet->setCellValue('Y'.($index + 2), $order['pv'] * $order['total_num']); $sheet->setCellValue('Z'.($index + 2), $order['express_price']); $sheet->setCellValue('AA'.($index + 2), $order['express_name']); $sheet->setCellValue('AB'.($index + 2), $order['express_no']); $sheet->setCellValue('AC'.($index + 2), $type); $sheet->setCellValue('AD'.($index + 2), $order['buyer_remark']); $sheet->setCellValue('AE'.($index + 2), $delivery); $sheet->setCellValue('AF'.($index + 2), $refundStatus); $index ++; } //保存文件 $filename = iconv("UTF-8","GB2312//IGNORE", '订单'). '-' . date('YmdHis') . '.xlsx'; header('Content-Type: application/vnd.ms-excel'); header('Content-Disposition: attachment;filename="'.$filename.'"'); header('Cache-Control: max-age=0'); $writer = IOFactory::createWriter($spreadsheet, 'Xlsx'); $writer->save('php://output'); } public function getStateTextAttr($order) { // 订单状态 if ($order['order_status']==20) { return '已取消'; } if ($order['order_status']==30) { return '已完成'; } if ($order['order_status'] == 21) { return '取消申请中'; } // 付款状态 if ($order['pay_status'] == 10) { return '待付款'; } // 发货状态 if ($order['delivery_status'] == 10) { return '已付款,待发货'; } if ($order['receipt_status'] == 10 && $order['delivery_status'] == 20) { return '已发货,待收货'; } return '进行中'; } /** * 订单导出 */ // public function orderList($list) // { // $strTable ='
| 会员编号 | '; // $strTable .= '报单中心 | '; // $strTable .= '订单号 | '; // $strTable .= '订单状态 | '; // $strTable .= '商品编码 | '; // $strTable .= '商品名称 | '; // $strTable .= '商品数量 | '; // $strTable .= '商品单价 | '; // $strTable .= '商品总额 | '; // $strTable .= '商品pv | '; // $strTable .= '合计pv | '; // $strTable .= '收货人 | '; // $strTable .= '联系方式 | '; // $strTable .= '省 | '; // $strTable .= '市 | '; // $strTable .= '区 | '; // $strTable .= '详细地址 | '; // $strTable .= '期数 | '; // $strTable .= '订单类型 | '; // $strTable .= '发货仓 | '; // $strTable .= '创建时间 | '; // $strTable .= '支付时间 | '; // $strTable .= '运费 | '; // $strTable .= '快递公司 | '; // $strTable .= '快递单号 | '; // $strTable .= '发货方式 | '; // $strTable .= '会员备注 | '; // $strTable .= '发货状态 | '; // $strTable .= '发货时间 | '; // $strTable .= '
| '.$order['user']['user_no'].' | '; // $strTable .= ''; // $strTable .= ' | '.$order['order_no'].' | '; // $strTable .= ''.$order['state_text'].' | '; // $strTable .= ''.$product['product']['product_no'].' | '; // $strTable .= ''.$product['product_name'].' | '; // $strTable .= ''.$product['total_num'].' | '; // $strTable .= ''.$price.' | '; // $strTable .= ''.$product['total_price'].' | '; // $strTable .= ''; // $strTable .= ' | '; // $strTable .= ' | '.$order['address']['name'].' | '; // $strTable .= ''.$order['address']['phone'].' | '; // $strTable .= ''.$order['address']['region']['province'].' | '; // $strTable .= ''.$order['address']['region']['city'].' | '; // $strTable .= ''.$order['address']['region']['region'].' | '; // $strTable .= ''.$order['address']['detail'].' | '; // $strTable .= ''; // $strTable .= ' | 重消 | '; // $strTable .= '01 | '; // $strTable .= ''.$order['create_time'].' | '; // $pay_time = empty($order['pay_time'])?'':date('Y-m-d H:i',$order['pay_time']); // $strTable .= ''.$pay_time.' | '; // $strTable .= ''.$order['express_price'].' | '; // $strTable .= ''.$order['express']['express_name'].' | '; // $strTable .= ''.$order['express_no'].' | '; // $strTable .= ''.$order['delivery_type']['text'].' | '; // $strTable .= ''.$order['buyer_remark'].' | '; // $strTable .= ''.$order['delivery_status']['text'].' | '; // $delivery_time = empty($order['delivery_time'])?'':date('Y-m-d H:i',$order['delivery_time']); // $strTable .= ''.$delivery_time.' | '; // } // } // $strTable .='