103 lines
2.9 KiB
PHP
103 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace app\inquiry\service;
|
|
|
|
use app\common\validate\InquiryLogValidate;
|
|
use app\common\traits\crud\CrudServiceTrait;
|
|
use app\common\model\InquiryLog;
|
|
use support\Request;
|
|
|
|
class InquiryLogService
|
|
{
|
|
|
|
use CrudServiceTrait;
|
|
|
|
/**
|
|
* 指定当前要操作的模型
|
|
*/
|
|
protected string $modelClass = InquiryLog::class;
|
|
|
|
/**
|
|
* 验证器
|
|
*/
|
|
protected $validator = InquiryLogValidate::class;
|
|
|
|
/**
|
|
* 获取验证器
|
|
*/
|
|
public function getValidator()
|
|
{
|
|
return new $this->validator;
|
|
}
|
|
|
|
|
|
protected function buildQueryConfig(Request $request, string $scene = 'index'): array
|
|
{
|
|
$p = $request->all();
|
|
|
|
$config = [];
|
|
$config['model'] = $this->modelClass;
|
|
switch ($scene) {
|
|
case 'default':
|
|
$config['where']['status'] = 1;
|
|
$config['order']['sort'] = 'desc';
|
|
$config['order']['id'] = 'desc';
|
|
break;
|
|
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'] = [
|
|
['>=', strtotime($time[0])],
|
|
['<=', strtotime($time[1])],
|
|
];
|
|
}
|
|
|
|
// 状态
|
|
if (isset($p['status']) && $p['status']) {
|
|
$config['where']['status'] = $p['status'];
|
|
}
|
|
|
|
// 关键字
|
|
if (isset($p['keyword']) && $p['keyword']) {
|
|
// $config['where']['order_no|email|tel|whatsapp|contacts'] = ['like', '%' . $p['keyword'] . '%'];
|
|
}
|
|
|
|
$config['with'][] = 'enter';
|
|
$config['with'][] = 'recipient';
|
|
|
|
$config['withFields']['enter'][] = 'id';
|
|
$config['withFields']['enter'][] = 'name';
|
|
|
|
$config['withFields']['recipient'][] = 'id';
|
|
$config['withFields']['recipient'][] = 'name';
|
|
break;
|
|
case 'show':
|
|
$config['where']['id'] = $p['id'];
|
|
$config['where']['status'] = 1;
|
|
break;
|
|
case 'store':
|
|
break;
|
|
case 'update':
|
|
$config['where']['id'] = $p['id'];
|
|
break;
|
|
case 'destroy':
|
|
$config['where']['id'] = $p['id'];
|
|
break;
|
|
}
|
|
|
|
return $config;
|
|
}
|
|
} |