Merge branch 'develop'

This commit is contained in:
mzl
2025-07-29 09:00:04 +08:00
parent a551507e4d
commit d74b374198
106 changed files with 6754 additions and 1346 deletions
@@ -0,0 +1,33 @@
<?php
namespace app\inquiry\controller;
use app\common\controller\BaseController;
use app\common\traits\crud\CrudControllerTrait;
use app\inquiry\service\CountryService;
class CountryController extends BaseController
{
use CrudControllerTrait;
protected $service;
public function __construct()
{
$this->service = new CountryService();
}
/**
* 列表页数据格式化
*
* @param array $data
* @return array
*/
// protected function indexFormat($data)
// {
// 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']);
// return $data;
// }
}
@@ -0,0 +1,220 @@
<?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;
}
if (isset($data['quality'])) {
$inquiryLogService = new InquiryLogService();
$data['quality'] = $inquiryLogService->qualityName($data['quality']);
}
// var_dump($data);
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());
}
}
// 导出
// 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');
// }
}
+17
View File
@@ -0,0 +1,17 @@
<?php
namespace app\inquiry\logic;
use app\common\traits\crud\CrudLogicTrait;
use app\inquiry\model\Country;
class CountryLogic
{
use CrudLogicTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = Country::class;
}
+17
View File
@@ -0,0 +1,17 @@
<?php
namespace app\inquiry\logic;
use app\common\traits\crud\CrudLogicTrait;
use app\common\model\InquiryLog;
class InquiryLogLogic
{
use CrudLogicTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = InquiryLog::class;
}
+31
View File
@@ -0,0 +1,31 @@
<?php
namespace app\inquiry\service;
use app\inquiry\validate\CountryValidate;
use app\common\traits\crud\CrudServiceTrait;
use app\inquiry\model\Country;
class CountryService
{
use CrudServiceTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = Country::class;
/**
* 验证器
*/
protected $validator = CountryValidate::class;
/**
* 获取验证器
*/
public function getValidator()
{
return new $this->validator;
}
}
+242
View File
@@ -0,0 +1,242 @@
<?php
namespace app\inquiry\service;
use app\common\validate\InquiryLogValidate;
use app\common\traits\crud\CrudServiceTrait;
use app\common\model\InquiryLog;
use support\exception\BusinessException;
use support\Request;
use Webman\RedisQueue\Redis as RedisQueueRedis;
class InquiryLogService
{
use CrudServiceTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = InquiryLog::class;
/**
* 验证器
*/
protected $validator = InquiryLogValidate::class;
/**
* 获取验证器
*/
public function getValidator()
{
return new $this->validator;
}
/**
* 发布
*/
public function serviceRelease(Request $request, array $data = [])
{
$data = $this->preProcess('Release', $data, $request);
$config = $this->buildQueryConfig($request, 'release');
$updated = $this->logicUpdateBy($config, $data);
return $this->postProcess('Release', $data);
}
/**
* 分配
*/
public function serviceAllocation(Request $request, array $data = [])
{
$data = $this->preProcess('Allocation', $data, $request);
$config = $this->buildQueryConfig($request, 'allocation');
$updated = $this->logicUpdateBy($config, $data);
return $this->postProcess('Allocation', $data);
}
/**
* 构建查询条件
*/
protected function buildQueryConfig(Request $request, string $scene = 'index'): array
{
$p = $request->all();
$config = [];
$config['model'] = $this->modelClass;
switch ($scene) {
case 'index':
// ====== ====== 排序 ====== ======
$config['order']['id'] = 'desc';
// ====== ====== 筛选 ====== ======
// 渠道
if (isset($p['channel']) && $p['channel']) {
$config['where']['channel'] = $p['channel'];
}
// 国家
if (isset($p['country']) && $p['country']) {
$config['where']['country'] = $p['country'];
}
// 时间
if (isset($p['time']) && $p['time']) {
$time = explode(' - ', $p['time']);
$config['where']['created_at'] = [
'between', [strtotime($time[0]), strtotime($time[1])]
];
}
// 状态
if (isset($p['status']) && in_array($p['status'], [0,1,2])) {
$config['where']['status'] = $p['status'];
}
// 关键字
if (isset($p['keyword']) && $p['keyword']) {
$k = '%' . $p['keyword'] . '%';
foreach (['order_no','email','tel','whatsapp','contacts'] as $col) {
$config['orWhere'][] = [$col, 'like', $k];
}
}
// ====== ====== 关联 ====== ======
$config['with']['countryInfo'][] = 'cn_addr';
$config['with']['countryInfo'][] = 'steering';
$config['with']['enter'][] = 'name';
$config['with']['recipient'][] = 'name';
$config['with']['channelInfo'][] = 'name';
break;
case 'show':
case 'update':
case 'destroy':
case 'release':
case 'allocation':
$config['where']['id'] = $p['id'];
case 'store':
break;
}
return $config;
}
/**
* 添加前置处理
*/
public function beforeServiceStore($data, Request $request)
{
$data['order_no'] = orderNum();
$data['enter_user_id'] = $request->user->uid;
$data['recipient'] = 0;
$data['email'] = trim($data["email"]);
$data['tel'] = trim($data['tel']);
$data['whatsapp'] = trim($data['whatsapp']);
// 将OSS直连地址替换为代理地址
$ossDomain = 'https://vehicle-album.oss-cn-beijing.aliyuncs.com/';
$proxyPath = getenv('MAIN_DOMAIN').'/proxy/ossurl?file=';
$data['content'] = str_replace(
'?Expires=',
'&Expires=',
$data['content']
);
$data['content'] = str_replace(
$ossDomain,
$proxyPath,
$data['content']
);
return $data;
}
/**
* 发布前置处理
*/
public function beforeServiceRelease($data, Request $request)
{
$info = $this->findByPk($request->post('id'));
if (!$info) {
throw new BusinessException('数据不存在');
}
if ($info->status != 0) {
throw new BusinessException('询单已被发布');
}
$data['r_time'] = time();
$data['status'] = 1;
return $data;
}
/**
* 分配前置处理
*/
public function beforeServiceAllocation($data, Request $request)
{
$info = $this->findByPk($request->post('id'));
if (!$info) {
throw new BusinessException('数据不存在');
}
if ($info->status == 2) {
throw new BusinessException('询单已被分配');
}
if ($info->status == 0) {
$data['r_time'] = time();
}
$data['t_time'] = time();
$data['status'] = 2;
return $data;
}
/**
* 发布后置处理
*/
protected function afterServiceRelease($res)
{
RedisQueueRedis::send('inquiry-to-crm', $res);
return $res;
}
/**
* 分配后置处理
*/
protected function afterServiceAllocation($res)
{
RedisQueueRedis::send('inquiry-to-crm', $res);
return $res;
}
/**
* 获取询单ById
* @param int|string $id
* @param string $orderSn
* @return Model|null
*/
public function getInquiryLogBy(int|string $id)
{
$config = [];
$config['model'] = $this->modelClass;
$config['with']['countryInfo'][] = 'cn_addr';
$config['with']['countryInfo'][] = 'steering';
$config['with']['enter'][] = 'name';
$config['with']['recipient'][] = 'name';
$config['with']['channelInfo'][] = 'name';
$config['orWhere'][] = ['id', '=', $id];
$config['orWhere'][] = ['order_no', '=', $id];
return $this->logicShow($config);
}
/**
* 获取等级名称
* @param $id
* @return string
*/
public function qualityName($id)
{
if (!$id) {
return '🤍 银牌商机';
}
$quality = [
1 => '💛金牌商机',
2 => '🤍银牌商机',
3 => '🧡铜牌商机'
];
return $quality[$id];
}
}