232 lines
9.2 KiB
PHP
232 lines
9.2 KiB
PHP
<?php
|
|
namespace app\inquiry\controller;
|
|
|
|
use app\common\controller\BaseController;
|
|
use app\common\traits\crud\CrudControllerTrait;
|
|
use app\inquiry\service\InquiryLogService;
|
|
use support\Request;
|
|
|
|
class InquiryLogController extends BaseController
|
|
{
|
|
use CrudControllerTrait;
|
|
|
|
protected $service;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->service = new InquiryLogService();
|
|
}
|
|
|
|
/**
|
|
* 列表页数据格式化
|
|
*
|
|
* @param array $data
|
|
* @return array
|
|
*/
|
|
protected function indexFormat($data)
|
|
{
|
|
// $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;
|
|
// }
|
|
|
|
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;
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
|
|
/**
|
|
* 发布
|
|
*
|
|
* @param Request $request
|
|
* @return mixed
|
|
*/
|
|
public function release(Request $request)
|
|
{
|
|
try {
|
|
$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());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 分配
|
|
*
|
|
* @param Request $request
|
|
* @return mixed
|
|
*/
|
|
public function allocation(Request $request)
|
|
{
|
|
try {
|
|
$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());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 重新分配
|
|
*
|
|
* @param Request $request
|
|
* @return mixed
|
|
*/
|
|
public function reAllocation(Request $request)
|
|
{
|
|
try {
|
|
$data = $this->validate($this->service->getValidator(), $request->post(), 'allocation');
|
|
$res = $this->service->serviceReAllocation($request, $data);
|
|
return $this->success([], '重新分配成功');
|
|
} catch (\Throwable $e) {
|
|
return $this->error($e->getMessage());
|
|
}
|
|
}
|
|
|
|
// 导出
|
|
// 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');
|
|
// }
|
|
} |