2025-07-22 15:13:27 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace app\inquiry\service;
|
|
|
|
|
|
|
|
|
|
use app\common\validate\InquiryLogValidate;
|
|
|
|
|
use app\common\traits\crud\CrudServiceTrait;
|
|
|
|
|
use app\common\model\InquiryLog;
|
2025-07-23 17:06:48 +08:00
|
|
|
use support\exception\BusinessException;
|
2025-07-22 15:13:27 +08:00
|
|
|
use support\Request;
|
|
|
|
|
|
|
|
|
|
class InquiryLogService
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
use CrudServiceTrait;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 指定当前要操作的模型
|
|
|
|
|
*/
|
|
|
|
|
protected string $modelClass = InquiryLog::class;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 验证器
|
|
|
|
|
*/
|
|
|
|
|
protected $validator = InquiryLogValidate::class;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取验证器
|
|
|
|
|
*/
|
|
|
|
|
public function getValidator()
|
|
|
|
|
{
|
|
|
|
|
return new $this->validator;
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-23 17:06:48 +08:00
|
|
|
/**
|
|
|
|
|
* 发布
|
|
|
|
|
*/
|
|
|
|
|
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', $updated);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 分配
|
|
|
|
|
*/
|
|
|
|
|
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', $updated);
|
|
|
|
|
}
|
2025-07-22 15:13:27 +08:00
|
|
|
|
2025-07-23 17:06:48 +08:00
|
|
|
/**
|
|
|
|
|
* 构建查询条件
|
|
|
|
|
*/
|
2025-07-22 15:13:27 +08:00
|
|
|
protected function buildQueryConfig(Request $request, string $scene = 'index'): array
|
|
|
|
|
{
|
|
|
|
|
$p = $request->all();
|
|
|
|
|
|
|
|
|
|
$config = [];
|
|
|
|
|
$config['model'] = $this->modelClass;
|
|
|
|
|
switch ($scene) {
|
|
|
|
|
case 'index':
|
2025-07-23 17:06:48 +08:00
|
|
|
// ====== ====== 排序 ====== ======
|
2025-07-22 15:13:27 +08:00
|
|
|
$config['order']['id'] = 'desc';
|
|
|
|
|
|
2025-07-23 17:06:48 +08:00
|
|
|
// ====== ====== 筛选 ====== ======
|
2025-07-22 15:13:27 +08:00
|
|
|
// 渠道
|
|
|
|
|
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']) {
|
2025-07-23 15:02:09 +08:00
|
|
|
$time = explode(' - ', $p['time']);
|
2025-07-22 15:13:27 +08:00
|
|
|
$config['where']['created_at'] = [
|
2025-07-23 15:02:09 +08:00
|
|
|
'between', [strtotime($time[0]), strtotime($time[1])]
|
2025-07-22 15:13:27 +08:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
// 状态
|
|
|
|
|
if (isset($p['status']) && $p['status']) {
|
|
|
|
|
$config['where']['status'] = $p['status'];
|
|
|
|
|
}
|
|
|
|
|
// 关键字
|
|
|
|
|
if (isset($p['keyword']) && $p['keyword']) {
|
2025-07-22 19:30:27 +08:00
|
|
|
$k = '%' . $p['keyword'] . '%';
|
|
|
|
|
foreach (['order_no','email','tel','whatsapp','contacts'] as $col) {
|
|
|
|
|
$config['orWhere'][] = [$col, 'like', $k];
|
|
|
|
|
}
|
2025-07-22 15:13:27 +08:00
|
|
|
}
|
|
|
|
|
|
2025-07-23 17:06:48 +08:00
|
|
|
// ====== ====== 关联 ====== ======
|
2025-07-23 15:02:09 +08:00
|
|
|
$config['with']['country'][] = 'cn_addr';
|
2025-07-23 17:06:48 +08:00
|
|
|
$config['with']['country'][] = 'steering';
|
2025-07-22 19:30:27 +08:00
|
|
|
$config['with']['enter'][] = 'name';
|
|
|
|
|
$config['with']['recipient'][] = 'name';
|
2025-07-23 15:02:09 +08:00
|
|
|
$config['with']['channel'][] = 'name';
|
2025-07-22 15:13:27 +08:00
|
|
|
break;
|
|
|
|
|
case 'show':
|
|
|
|
|
case 'update':
|
|
|
|
|
case 'destroy':
|
2025-07-23 17:06:48 +08:00
|
|
|
case 'release':
|
|
|
|
|
case 'allocation':
|
2025-07-22 15:13:27 +08:00
|
|
|
$config['where']['id'] = $p['id'];
|
2025-07-23 17:06:48 +08:00
|
|
|
case 'store':
|
2025-07-22 15:13:27 +08:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $config;
|
|
|
|
|
}
|
2025-07-23 15:02:09 +08:00
|
|
|
|
2025-07-23 17:06:48 +08:00
|
|
|
/**
|
|
|
|
|
* 添加前置处理
|
|
|
|
|
*/
|
2025-07-23 15:02:09 +08:00
|
|
|
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']);
|
|
|
|
|
return $data;
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-23 17:06:48 +08:00
|
|
|
/**
|
|
|
|
|
* 发布前置处理
|
|
|
|
|
*/
|
|
|
|
|
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;
|
|
|
|
|
}
|
2025-07-23 15:02:09 +08:00
|
|
|
|
2025-07-23 17:06:48 +08:00
|
|
|
/**
|
|
|
|
|
* 分配前置处理
|
|
|
|
|
*/
|
|
|
|
|
public function beforeServiceAllocation($data, Request $request)
|
|
|
|
|
{
|
|
|
|
|
$info = $this->findByPk($request->post('id'));
|
|
|
|
|
if (!$info) {
|
|
|
|
|
throw new BusinessException('数据不存在');
|
|
|
|
|
}
|
|
|
|
|
if ($info->status == 2) {
|
|
|
|
|
throw new BusinessException('询单已被分配');
|
|
|
|
|
}
|
|
|
|
|
$data['t_time'] = time();
|
|
|
|
|
$data['status'] = 2;
|
|
|
|
|
return $data;
|
|
|
|
|
}
|
2025-07-22 15:13:27 +08:00
|
|
|
}
|