海工商新版后台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

153 lines
5.1 KiB

<?php
namespace App\Admin\Extensions\Exporter;
use App\Models\LoanStudentsList;
use App\Models\Order;
use App\Models\PaymentList;
use App\Models\SecondaryCollege;
use App\Models\Speciality;
use App\Models\UsersMember;
use Dcat\Admin\Grid\Exporters\AbstractExporter;
use Illuminate\Support\Facades\DB;
use Maatwebsite\Excel\Concerns\Exportable;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;
class ImportOrder extends AbstractExporter implements WithMapping, WithHeadings, FromCollection
{
use Exportable;
protected $fileName = '订单明细';
protected $titles = [];
public function __construct()
{
$this->fileName = $this->fileName.'_'.time().'.xlsx';//拼接下载文件名称
$this->titles = [
'id'=> '订单ID',
'orders_num'=> '订单号',
'price'=> '实付金额',
'transaction_id'=> '流水单号',
'pay_time'=> '支付时间',
'status'=> '状态',
'annual_session'=> '年份',
'is_new_student_order'=> '新老生订单',
'payment_data'=> '缴费项目',
'msg'=> '订单备注',
'name'=> '姓名',
'mobile'=> '手机',
'idcard'=> '身份证',
'sex'=> '性别',
'speciality_name'=> '专业',
'conllege_name'=> '二级学院',
];
parent::__construct();
}
public function export()
{
// TODO: Implement export() method.
$this->download($this->fileName)->prepare(request())->send();
exit;
}
public function collection()
{
// TODO: Implement collection() method.
$payMentList = DB::select('SELECT DISTINCT(project_code),project_name FROM payment_list');
$payMentListInfo = [];
foreach($payMentList as $item){
$payMentListInfo[$item->project_code] = $item->project_name;
}
$orderList = $this->buildData();
//专业信息
$specialityList = Speciality::query()->get()->toArray();
$specialityList = array_column($specialityList, null,"id");
//二级学院
$secondary_college = SecondaryCollege::query()->get()->toArray();
$secondary_college = array_column($secondary_college, null,"id");
$numberList = array_unique(array_column($orderList, "unique_number"));
$userList = UsersMember::query()->whereIn("unique_number", $numberList)->get()->toArray();
$userList = array_column($userList, null, "unique_number");
$addList = [];
foreach($orderList as $item){
$status = "未支付";
if($item["status"] == Order::STATUS_PAID) $status = "已支付";
if($item["status"] == Order::STATUS_CANCEL) $status = "已取消";
$is_new_student_order = "新生订单";
if($item['is_new_student_order'] == Order::IS_NEW_STUDENT_ORDER_NO) $is_new_student_order = "老生订单";
$sex = "";
if($userList[$item["unique_number"]]['sex'] == 2) $sex = "";
$payment_data = "";
foreach(json_decode($item["payment_data"]) as $k => $v){
$payment_data .= $payMentListInfo[$k]."".$v."|";
}
$arr = [
'id'=> $item['id'],
'orders_num'=> $item['orders_num'],
'price'=> $item['price'],
'transaction_id'=> $item['transaction_id'],
'pay_time'=> date("Y-m-d H:i:s", $item['pay_time']),
'status'=> $status,
'annual_session'=> $item['annual_session'],
'is_new_student_order'=> $is_new_student_order,
'payment_data' => rtrim($payment_data, "|"),
'msg'=> $item["msg"],
'name'=> $userList[$item["unique_number"]]['name'],
'mobile'=> $userList[$item["unique_number"]]['mobile'],
'idcard'=> $userList[$item["unique_number"]]['idcard'],
'sex'=> $sex,
'speciality_name'=> $specialityList[$userList[$item["unique_number"]]["speciality_id"]]["speciality_name"],
'conllege_name'=> $secondary_college[$specialityList[$userList[$item["unique_number"]]["speciality_id"]]['secondary_college_id']]['name'],
];
array_push($addList, $arr);
}
return collect($addList);
}
public function headings(): array
{
// TODO: Implement headings() method.
return $this->titles();
}
public function map($row): array
{
// TODO: Implement map() method.
return [
$row["id"],
$row["orders_num"],
$row["price"],
$row["transaction_id"],
$row["pay_time"],
$row["status"],
$row["annual_session"],
$row["is_new_student_order"],
$row["payment_data"],
$row["msg"],
$row["name"],
$row["mobile"],
"'".$row['idcard'].'',
$row["sex"],
$row["speciality_name"],
$row["conllege_name"],
];
}
}