2025-07-22 15:13:27 +08:00
|
|
|
<?php
|
|
|
|
|
namespace app\inquiry\controller;
|
|
|
|
|
|
|
|
|
|
use app\common\controller\BaseController;
|
|
|
|
|
use app\common\traits\crud\CrudControllerTrait;
|
|
|
|
|
use app\inquiry\service\InquiryLogService;
|
2025-07-23 17:06:48 +08:00
|
|
|
use support\Request;
|
2025-07-22 15:13:27 +08:00
|
|
|
|
|
|
|
|
class InquiryLogController extends BaseController
|
|
|
|
|
{
|
|
|
|
|
use CrudControllerTrait;
|
|
|
|
|
|
|
|
|
|
protected $service;
|
|
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
|
{
|
|
|
|
|
$this->service = new InquiryLogService();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 列表页数据格式化
|
|
|
|
|
*
|
|
|
|
|
* @param array $data
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
2025-07-23 15:02:09 +08:00
|
|
|
protected function indexFormat($data)
|
|
|
|
|
{
|
2025-07-23 17:06:48 +08:00
|
|
|
$data['countdown'] = time()-1;
|
|
|
|
|
if (isset($data['r_time'])) {
|
|
|
|
|
$countdown = 60 * 60;
|
|
|
|
|
$data['countdown'] = (time() - $data['r_time']) < $countdown ? $data['r_time'] + (60*60) : time()-1;
|
|
|
|
|
}
|
2025-07-23 15:02:09 +08:00
|
|
|
if (isset($data['created_at']))
|
|
|
|
|
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
|
|
|
|
|
if (isset($data['updated_at']))
|
|
|
|
|
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
|
|
|
|
|
if (isset($data['r_time']))
|
|
|
|
|
$data['r_time'] = $data['r_time'] > 0 ? date('Y-m-d H:i:s', $data['r_time']) : 0;
|
|
|
|
|
if (isset($data['t_time']))
|
|
|
|
|
$data['t_time'] = $data['t_time'] > 0 ? date('Y-m-d H:i:s', $data['t_time']) : 0;
|
2025-07-22 15:13:27 +08:00
|
|
|
|
2025-07-23 17:06:48 +08:00
|
|
|
return $data;
|
2025-07-22 15:13:27 +08:00
|
|
|
}
|
|
|
|
|
|
2025-07-23 17:06:48 +08:00
|
|
|
/**
|
|
|
|
|
* 发布
|
|
|
|
|
*
|
|
|
|
|
* @param Request $request
|
|
|
|
|
* @return mixed
|
|
|
|
|
*/
|
2025-07-22 15:13:27 +08:00
|
|
|
public function release(Request $request)
|
|
|
|
|
{
|
|
|
|
|
try {
|
2025-07-23 17:06:48 +08:00
|
|
|
$data = $this->validate($this->service->getValidator(), $request->post(), 'release');
|
|
|
|
|
$res = $this->service->serviceRelease($request, $data);
|
|
|
|
|
return $this->success([], '发布成功');
|
|
|
|
|
} catch (\Throwable $e) {
|
|
|
|
|
return $this->error($e->getMessage());
|
2025-07-22 15:13:27 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-23 17:06:48 +08:00
|
|
|
/**
|
|
|
|
|
* 分配
|
|
|
|
|
*
|
|
|
|
|
* @param Request $request
|
|
|
|
|
* @return mixed
|
|
|
|
|
*/
|
2025-07-22 15:13:27 +08:00
|
|
|
public function allocation(Request $request)
|
|
|
|
|
{
|
|
|
|
|
try {
|
2025-07-23 17:06:48 +08:00
|
|
|
$data = $this->validate($this->service->getValidator(), $request->post(), 'allocation');
|
|
|
|
|
$res = $this->service->serviceAllocation($request, $data);
|
|
|
|
|
return $this->success([], '分配成功');
|
|
|
|
|
} catch (\Throwable $e) {
|
|
|
|
|
return $this->error($e->getMessage());
|
2025-07-22 15:13:27 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 导出
|
|
|
|
|
public function export(Request $request)
|
|
|
|
|
{
|
|
|
|
|
if ($request->method() == "POST") {
|
|
|
|
|
$data = $request->all();
|
|
|
|
|
|
|
|
|
|
$where = [];
|
|
|
|
|
if (isset($data['log_lusers']) && $data['log_lusers']) {
|
|
|
|
|
$where[] = ['enter_user_id', '=', $data['log_lusers']];
|
|
|
|
|
}
|
|
|
|
|
if (isset($data['log_gusers']) && $data['log_gusers']) {
|
|
|
|
|
$where[] = ['recipient', '=', $data['log_gusers']];
|
|
|
|
|
}
|
|
|
|
|
if (isset($data['log_country']) && $data['log_country']) {
|
|
|
|
|
$where[] = ['log_country', '=', $data['log_country']];
|
|
|
|
|
}
|
|
|
|
|
if (isset($data['log_channel']) && $data['log_channel']) {
|
|
|
|
|
$where[] = ['log_type', '=', $data['log_channel']];
|
|
|
|
|
}
|
|
|
|
|
if (isset($data['log_times']) && $data['log_times']) {
|
|
|
|
|
$times = explode(' - ', $data["log_times"]);
|
|
|
|
|
$specificDayStart = trim($times[0]);
|
|
|
|
|
$specificDayEnd = trim($times[1]);
|
|
|
|
|
$where[] = [
|
|
|
|
|
"c_time", ">", strtotime($specificDayStart)
|
|
|
|
|
];
|
|
|
|
|
$where[] = [
|
|
|
|
|
"c_time", "<=", strtotime($specificDayEnd)
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 查询
|
|
|
|
|
$results = InquiryLogModel::with(['enterUser', 'recipientUser', 'country'])
|
|
|
|
|
->where($where)
|
|
|
|
|
->get()
|
|
|
|
|
->map(function ($log) use($data) {
|
|
|
|
|
$arr = [];
|
|
|
|
|
if (isset($data['hsl_order_no']) && $data['hsl_order_no']) {
|
|
|
|
|
$arr['订单号'] = $log->order_no;
|
|
|
|
|
}
|
|
|
|
|
if (isset($data['hsl_order_no']) && $data['hsl_order_no']) {
|
|
|
|
|
$arr['录入人'] = $log->enterUser->name ?? null;
|
|
|
|
|
}
|
|
|
|
|
if (isset($data['hsl_order_no']) && $data['hsl_order_no']) {
|
|
|
|
|
$arr['接单人'] = $log->recipientUser->name ?? null;
|
|
|
|
|
}
|
|
|
|
|
if (isset($data['hsl_order_no']) && $data['hsl_order_no']) {
|
|
|
|
|
$arr['等级'] = $log->log_quality;
|
|
|
|
|
}
|
|
|
|
|
if (isset($data['hsl_order_no']) && $data['hsl_order_no']) {
|
|
|
|
|
$arr['邮箱'] = $log->log_contact_type;
|
|
|
|
|
}
|
|
|
|
|
if (isset($data['hsl_order_no']) && $data['hsl_order_no']) {
|
|
|
|
|
$arr['电话'] = $log->log_contact_tel;
|
|
|
|
|
}
|
|
|
|
|
if (isset($data['hsl_order_no']) && $data['hsl_order_no']) {
|
|
|
|
|
$arr['WhatsApp'] = $log->log_contact_whatsapp;
|
|
|
|
|
}
|
|
|
|
|
if (isset($data['hsl_order_no']) && $data['hsl_order_no']) {
|
|
|
|
|
$arr['联系人'] = $log->log_contacts;
|
|
|
|
|
}
|
|
|
|
|
if (isset($data['hsl_order_no']) && $data['hsl_order_no']) {
|
|
|
|
|
$arr['国家(中文)'] = $log->country->cn_addr ?? null;
|
|
|
|
|
}
|
|
|
|
|
if (isset($data['hsl_order_no']) && $data['hsl_order_no']) {
|
|
|
|
|
$arr['国家(英文)'] = $log->country->en_full_name ?? null;
|
|
|
|
|
}
|
|
|
|
|
if (isset($data['hsl_r_time']) && $data['hsl_r_time']) {
|
|
|
|
|
$arr['发单时间'] = $log->r_time ? date('Y-m-d H:i:s', $log->r_time) : null;
|
|
|
|
|
}
|
|
|
|
|
if (isset($data['hsl_t_time']) && $data['hsl_t_time']) {
|
|
|
|
|
$arr['跟单时间'] = $log->t_time ? date('Y-m-d H:i:s', $log->t_time) : null;
|
|
|
|
|
}
|
|
|
|
|
return $arr;
|
|
|
|
|
});
|
|
|
|
|
// 创建一个新的 Spreadsheet 对象
|
|
|
|
|
$spreadsheet = new Spreadsheet();
|
|
|
|
|
// 设置当前活动的工作表
|
|
|
|
|
$sheet = $spreadsheet->getActiveSheet();
|
|
|
|
|
// 设置工作表的标题
|
|
|
|
|
$sheet->setCellValue('A1', '订单号');
|
|
|
|
|
$sheet->setCellValue('B1', '录入人');
|
|
|
|
|
$sheet->setCellValue('C1', '接单人');
|
|
|
|
|
$sheet->setCellValue('D1', '等级');
|
|
|
|
|
$sheet->setCellValue('E1', '邮箱');
|
|
|
|
|
$sheet->setCellValue('F1', '电话');
|
|
|
|
|
$sheet->setCellValue('G1', 'WhatsApp');
|
|
|
|
|
$sheet->setCellValue('H1', '联系人');
|
|
|
|
|
$sheet->setCellValue('I1', '国家(中文)');
|
|
|
|
|
$sheet->setCellValue('J1', '国家(英文)');
|
|
|
|
|
$sheet->setCellValue('K1', '发单时间');
|
|
|
|
|
$sheet->setCellValue('L1', '跟单时间');
|
|
|
|
|
$data = $results->toArray();
|
|
|
|
|
|
|
|
|
|
// 将数据填充到工作表中
|
|
|
|
|
$row = 2; // 从第2行开始填充
|
|
|
|
|
foreach ($data as $item) {
|
|
|
|
|
$sheet->setCellValue('A' . $row, $item['订单号']);
|
|
|
|
|
$sheet->setCellValue('B' . $row, $item['录入人']);
|
|
|
|
|
$sheet->setCellValue('C' . $row, $item['接单人']);
|
|
|
|
|
|
|
|
|
|
$sheet->setCellValue('D' . $row, $item['等级']);
|
|
|
|
|
$sheet->setCellValue('E' . $row, $item['邮箱']);
|
|
|
|
|
$sheet->setCellValue('F' . $row, $item['电话']);
|
|
|
|
|
|
|
|
|
|
$sheet->setCellValue('G' . $row, $item['WhatsApp']);
|
|
|
|
|
$sheet->setCellValue('H' . $row, $item['联系人']);
|
|
|
|
|
$sheet->setCellValue('I' . $row, $item['国家(中文)']);
|
|
|
|
|
|
|
|
|
|
$sheet->setCellValue('J' . $row, $item['国家(英文)']);
|
|
|
|
|
$sheet->setCellValue('K' . $row, $item['发单时间']);
|
|
|
|
|
$sheet->setCellValue('L' . $row, $item['跟单时间']);
|
|
|
|
|
$row++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 创建 Excel 文件的写入器
|
|
|
|
|
$writer = new Xlsx($spreadsheet);
|
|
|
|
|
// 名称
|
|
|
|
|
$fileName = $request->user->name.'_'.date('Ymd').'_'.uniqid().'.xlsx';
|
|
|
|
|
// 路径
|
|
|
|
|
$filePath = '/export/'.$fileName;
|
|
|
|
|
// 将文件保存到本地
|
|
|
|
|
$writer->save(public_path().$filePath);
|
|
|
|
|
|
|
|
|
|
return $this->successResponse(['url'=>$filePath, 'name'=>$fileName]);
|
|
|
|
|
}
|
|
|
|
|
return view('inquiry-log/export');
|
|
|
|
|
}
|
|
|
|
|
}
|