feat:客户消息功能模块基础完成
This commit is contained in:
parent
294a6445e7
commit
1431447307
109
app/admin/controller/Customer/CustomerMessage.php
Normal file
109
app/admin/controller/Customer/CustomerMessage.php
Normal file
@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\Customer;
|
||||
|
||||
use app\BaseController;
|
||||
use app\common\model\Customer\CustomerMessage as ModelCustomerMessage;
|
||||
use app\Request;
|
||||
use think\Validate;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Filesystem;
|
||||
use app\common\arw\adjfut\src\Excel;
|
||||
use app\common\arw\adjfut\src\UploadFile;
|
||||
use app\common\exception\Tool;
|
||||
use think\facade\Db;
|
||||
use think\facade\Env;
|
||||
use app\admin\logic\Customer\CustomerMessage as LogicCustomerMessage;
|
||||
|
||||
|
||||
class CustomerMessage extends BaseController
|
||||
{
|
||||
/**
|
||||
* 获取客户消息列表接口
|
||||
*
|
||||
* @param Request $request
|
||||
* @return array
|
||||
* @date 2023-08-01
|
||||
* @author xjh
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getCustomerMessageList(Request $request, $isExport = false): array
|
||||
{
|
||||
$con = Tool::getOptionalQuery(
|
||||
['customer_message.customer_message_title', 'LIKE'],
|
||||
['customer_message.customer_message_content', 'LIKE'],
|
||||
['customer_message.customer_message_postscript', 'LIKE'],
|
||||
['customer_message.customer_message_reading_status', '='],
|
||||
['customer.customer_name|customer.customer_email', 'LIKE', 'customer'],
|
||||
);
|
||||
|
||||
$query = ModelCustomerMessage::where($con)
|
||||
->field([
|
||||
'customer_message.customer_message_id',
|
||||
'customer_message.customer_message_guid',
|
||||
'customer_message.customer_message_title',
|
||||
'customer_message.customer_message_content',
|
||||
'customer_message.customer_message_postscript',
|
||||
'customer_message.customer_message_reading_status',
|
||||
'customer_message.customer_guid',
|
||||
'customer_message.customer_message_create_time',
|
||||
'customer.customer_name',
|
||||
'customer.customer_email',
|
||||
])
|
||||
->leftjoin('customer', 'customer.customer_guid = customer_message.customer_guid ')
|
||||
->order('customer_message_update_time', 'desc');
|
||||
|
||||
return msg("获取客户消息列表成功!", $query);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加客户消息接口
|
||||
*
|
||||
* @param Request $request
|
||||
* @return array
|
||||
* @date 2023-08-01
|
||||
* @author xjh
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function addCustomerMessage(Request $request): array
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$params = $request->param();
|
||||
$this->validate($params, [
|
||||
'customer_message_title|标题' => 'require',
|
||||
'customer_message_content|内容' => 'require',
|
||||
'customer_message_postscript|附言' => 'require',
|
||||
'customer_all|是否发送全部人' => 'require'
|
||||
]);
|
||||
LogicCustomerMessage::create($params);
|
||||
Db::commit();
|
||||
return msg('添加成功!');
|
||||
} catch (\Throwable $th) {
|
||||
Db::rollback();
|
||||
throw $th;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除客户消息接口
|
||||
*
|
||||
* @param Request $request
|
||||
* @return array
|
||||
* @date 2023-08-01
|
||||
* @author xjh
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function deleteCustomerMessage(Request $request): array
|
||||
{
|
||||
$params = $request->param();
|
||||
$this->validate($params, [
|
||||
'customer_message_guid' => 'require',
|
||||
]);
|
||||
$customer_message = ModelCustomerMessage::where([
|
||||
'customer_message_guid' => explode(',', $params['customer_message_guid'])
|
||||
])->select();
|
||||
$customer_message->delete();
|
||||
return msg('删除成功!');
|
||||
}
|
||||
}
|
51
app/admin/logic/Customer/CustomerMessage.php
Normal file
51
app/admin/logic/Customer/CustomerMessage.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\logic\Customer;
|
||||
|
||||
use app\common\model\Customer\CustomerMessage as ModelCustomerMessage;
|
||||
use app\common\model\Customer\Customer as ModelCustomer;
|
||||
use app\common\exception\Tool;
|
||||
use app\common\arw\adjfut\src\Traverse;
|
||||
|
||||
|
||||
class CustomerMessage
|
||||
{
|
||||
/**
|
||||
* 新增客户消息处理
|
||||
*
|
||||
* @param array $params 新增客户消息参数
|
||||
* @return void
|
||||
* @date 2023-08-01
|
||||
* @author xjh
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function create(array $params): void
|
||||
{
|
||||
$params = Tool::filtrationAssociativeArray($params, [
|
||||
'customer_message_title',
|
||||
'customer_message_content',
|
||||
'customer_message_postscript',
|
||||
'customer_message_reading_status',
|
||||
'customer_guid',
|
||||
'customer_message_guid',
|
||||
'customer_message_create_user_guid',
|
||||
'customer_message_update_user_guid',
|
||||
'customer_all',
|
||||
]);
|
||||
//全部人发送消息
|
||||
if ($params['customer_all']) {
|
||||
$customer_guids = ModelCustomer::column('customer_guid');
|
||||
foreach ($customer_guids as $customer_guid) {
|
||||
$params['customer_guid'] = $customer_guid;
|
||||
ModelCustomerMessage::create($params);
|
||||
}
|
||||
}
|
||||
//指定客户发送消息
|
||||
else {
|
||||
if (!isset($params['customer_guid']) || !$params['customer_guid']) {
|
||||
throwErrorMsg("非全部人发送,则需要指定客户");
|
||||
}
|
||||
ModelCustomerMessage::create($params);
|
||||
}
|
||||
}
|
||||
}
|
96
app/api/controller/Customer/CustomerMessage.php
Normal file
96
app/api/controller/Customer/CustomerMessage.php
Normal file
@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller\Customer;
|
||||
|
||||
use app\BaseController;
|
||||
use app\common\model\Customer\CustomerMessage as ModelCustomerMessage;
|
||||
use app\Request;
|
||||
use think\Validate;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Filesystem;
|
||||
use app\common\arw\adjfut\src\Excel;
|
||||
use app\common\arw\adjfut\src\UploadFile;
|
||||
use app\common\model\Token as ModelToken;
|
||||
use app\common\exception\Tool;
|
||||
use think\facade\Db;
|
||||
use think\facade\Env;
|
||||
use app\BaseModel;
|
||||
|
||||
|
||||
class CustomerMessage extends BaseController
|
||||
{
|
||||
/**
|
||||
* 获取客户消息列表接口
|
||||
*
|
||||
* @param Request $request
|
||||
* @return array
|
||||
* @date 2023-08-01
|
||||
* @author xjh
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getCustomerMessageList(Request $request, $isExport = false): array
|
||||
{
|
||||
$customer = ModelToken::getCurrentCustomer();
|
||||
|
||||
$query = ModelCustomerMessage::where('customer_message.customer_guid', $customer->customer_guid)
|
||||
->field([
|
||||
'customer_message.customer_message_guid',
|
||||
'customer_message.customer_message_title',
|
||||
'customer_message.customer_message_content',
|
||||
'customer_message.customer_message_postscript',
|
||||
'customer_message.customer_message_reading_status',
|
||||
'customer_message.customer_message_create_time',
|
||||
'customer.customer_name',
|
||||
'customer.customer_email',
|
||||
])
|
||||
->leftjoin('customer', 'customer.customer_guid = customer_message.customer_guid ')
|
||||
->order('customer_message_update_time', 'desc');
|
||||
|
||||
return msg("获取客户消息列表成功!", $query);
|
||||
}
|
||||
|
||||
/**
|
||||
* 客户消息设置已读接口
|
||||
*
|
||||
* @param Request $request
|
||||
* @return array
|
||||
* @date 2023-08-01
|
||||
* @author xjh
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function haveReadCustomerMessage(Request $request): array
|
||||
{
|
||||
$customer = ModelToken::getCurrentCustomer();
|
||||
$params = $request->param();
|
||||
$this->validate($params, [
|
||||
'customer_message_guid|客户消息guid' => 'require',
|
||||
]);
|
||||
BaseModel::setUserGuid(false);
|
||||
ModelCustomerMessage::update(['customer_message_reading_status' => ModelCustomerMessage::HAVE_READ], [
|
||||
'customer_message_guid' => $params['customer_message_guid'],
|
||||
'customer_guid' => $customer->customer_guid,
|
||||
'customer_message_reading_status' => ModelCustomerMessage::UNREAD,
|
||||
]);
|
||||
return msg("客户消息设置已读成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 客户消息一键设置全部已读接口
|
||||
*
|
||||
* @param Request $request
|
||||
* @return array
|
||||
* @date 2023-08-01
|
||||
* @author xjh
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function haveReadAllCustomerMessage(Request $request): array
|
||||
{
|
||||
$customer = ModelToken::getCurrentCustomer();
|
||||
BaseModel::setUserGuid(false);
|
||||
ModelCustomerMessage::where([
|
||||
'customer_guid' => $customer->customer_guid,
|
||||
'customer_message_reading_status' => ModelCustomerMessage::UNREAD,
|
||||
])->select()->update(['customer_message_reading_status' => ModelCustomerMessage::HAVE_READ]);
|
||||
return msg("客户消息设一键设置全部已读成功!");
|
||||
}
|
||||
}
|
90
app/common/model/Customer/CustomerMessage.php
Normal file
90
app/common/model/Customer/CustomerMessage.php
Normal file
@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model\Customer;
|
||||
|
||||
use app\common\arw\adjfut\src\Validate;
|
||||
use app\BaseModel;
|
||||
use think\model\concern\SoftDelete;
|
||||
use app\common\arw\adjfut\src\Excel;
|
||||
use app\Request;
|
||||
use app\common\exception\Tool;
|
||||
use think\facade\Db;
|
||||
|
||||
class CustomerMessage extends BaseModel
|
||||
{
|
||||
use SoftDelete;
|
||||
// 删除字段
|
||||
protected $deleteTime = 'customer_message_delete_time';
|
||||
// 设置主键名
|
||||
protected $pk = 'customer_message_guid';
|
||||
// 设置废弃字段
|
||||
protected $disuse = [];
|
||||
// 设置字段信息
|
||||
protected $schema = [
|
||||
'customer_message_id' => 'int',
|
||||
'customer_message_guid' => 'string',
|
||||
'customer_message_title' => 'string',
|
||||
'customer_message_content' => 'string',
|
||||
'customer_message_postscript' => 'string',
|
||||
'customer_message_reading_status' => 'int',
|
||||
'customer_guid' => 'string',
|
||||
'customer_message_create_time' => 'datetime',
|
||||
'customer_message_create_user_guid' => 'string',
|
||||
'customer_message_update_time' => 'datetime',
|
||||
'customer_message_update_user_guid' => 'string',
|
||||
'customer_message_delete_time' => 'datetime',
|
||||
'customer_message_delete_user_guid' => 'string',
|
||||
|
||||
];
|
||||
// 设置json类型字段
|
||||
protected $json = [''];
|
||||
// 开启自动写入时间戳字段
|
||||
protected $autoWriteTimestamp = 'datetime';
|
||||
// 创建时间
|
||||
protected $createTime = 'customer_message_create_time';
|
||||
// 修改时间
|
||||
protected $updateTime = 'customer_message_update_time';
|
||||
// 字典
|
||||
public static $dictionaryMap = [
|
||||
'customer_message_reading_status' => [
|
||||
self::HAVE_READ => '已读',
|
||||
self::UNREAD => '未读'
|
||||
],
|
||||
];
|
||||
// 阅读状态 已读
|
||||
const HAVE_READ = 1;
|
||||
// 阅读状态 未读
|
||||
const UNREAD = 2;
|
||||
/**
|
||||
* 新增前
|
||||
*/
|
||||
public static function onBeforeInsert(self $model): void
|
||||
{
|
||||
$model->customer_message_reading_status = self::UNREAD;
|
||||
$model->completeCreateField();
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新前
|
||||
*/
|
||||
public static function onBeforeUpdate(self $model): void
|
||||
{
|
||||
$model->completeUpdateField();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除前
|
||||
*/
|
||||
public static function onBeforeDelete(self $model): void
|
||||
{
|
||||
$model->completeDeleteField();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user