消息推送增加邮箱&&增加终版保存功能

This commit is contained in:
mzl
2025-09-15 15:01:19 +08:00
parent 3208fbd501
commit f152529364
14 changed files with 209 additions and 24 deletions
+28
View File
@@ -62,4 +62,32 @@ class SysDict extends Model
{
return $this->belongsTo(SysDictCategory::class, 'category_id', 'id');
}
/**
* 一个字典有多个字典项
*/
public function items()
{
return $this->hasMany(SysDictItem::class, 'dict_id', 'id');
}
/**
* 通过 dict_code 快速获取所有 item_value
*/
public function scopeGetItemValuesByCode($query, $dictCode)
{
return $query->where('dict_code', $dictCode)
->with('items') // 预加载关联项
->first()?->items->pluck('item_value'); // 返回 item_value 数组
}
/**
* 通过 dict_code 获取完整字典项(含 label + value)
*/
public function scopeGetItemsByCode($query, $dictCode)
{
return $query->where('dict_code', $dictCode)
->with('items')
->first()?->items;
}
}
+8
View File
@@ -56,4 +56,12 @@ class SysDictItem extends Model
{
return $this->belongsTo(SysDict::class, 'dict_id', 'id');
}
/**
* 字典项属于一个字典
*/
public function dict()
{
return $this->belongsTo(SysDict::class, 'dict_id', 'id');
}
}
@@ -273,4 +273,14 @@ class MessageNotificationsService
{
return User::where('status', 1)->pluck('id')->toArray();
}
public function getUserEmailsById(array $con = []): array
{
$user = User::where('status', 1);
if (count($con) > 0) {
return $user->whereIn('id', $con)->where('email', '!=', '')->pluck('email')->toArray();
}
return $user->where('email', '!=', '')->pluck('email')->toArray();
}
}
+1 -1
View File
@@ -140,7 +140,7 @@ class StockOrdersService
{
// 启动审批
$appro = new \app\common\utils\approval\service\ApprovalFlowService();
$appro->start('stock_order_flow', 'stock_orders', $item->id, $item->toArray(), $item->salesperson_id);
$appro->start('stock_orders', 'stock_orders', $item->id, $item->toArray(), $item->salesperson_id);
// 异步生成pdf文件
\Webman\RedisQueue\Redis::send('stock-order-pdf', ['id'=>$item->id]);
}
@@ -227,7 +227,7 @@ class StockOrdersService_bak
}
// 启动审批
$appro = new \app\common\utils\approval\service\ApprovalFlowService();
$result = $appro->start('stock_order_flow', 'stock_orders', $res->id, $res->toArray(), $res->salesperson_id);
$result = $appro->start('stock_orders', 'stock_orders', $res->id, $res->toArray(), $res->salesperson_id);
var_dump($result);
// 异步生成pdf文件
+22
View File
@@ -25,4 +25,26 @@ class SysDictService
{
return $this->logic->getList();
}
public static function pluckValuesByCode(string $dictCode): \Illuminate\Support\Collection
{
return SysDict::where('dict_code', $dictCode)
->where('status', 1)
->first()?->items()
->where('status', 1)
->orderBy('sort')
->pluck('item_value') ?? collect();
}
public static function pluckKeyValueByCode(string $dictCode): \Illuminate\Support\Collection
{
return SysDict::where('dict_code', $dictCode)
->where('status', 1)
->first()?->items()
->where('status', 1)
->orderBy('sort')
->pluck('item_value', 'item_label') ?? collect();
}
}
@@ -565,23 +565,34 @@ class ApprovalFlowService
/** 发送通知(接你自己的消息系统即可) */
private function sendNotification(array $userIds, object $instance, string $action, bool $isCC): void
{
$map = ['pending'=>'待审批','approve'=>'已通过','reject'=>'已拒绝','revoked'=>'已撤回'];
$prefix = $isCC ? '[抄送]' : '';
$text = $map[$action] ?? $action;
$msg = "{$prefix}您有一条审批 {$text}:流程ID {$instance->id},类型 {$instance->flow_type}";
// MessageService::send($userIds, $msg);
$pushData = [
'sender_id' => 0,
'sender_type' => 'system',
'title' => $msg,
'content' => $msg,
'scene' => 1,
'recipient' => $userIds,
'push_method' => 1
$map = [
'pending' => '待审批',
'approve' => '已通过',
'reject' => '已拒绝',
'revoked' => '已撤回'
];
$msgId = (new MessageNotificationsService())->pushNotice($pushData);
var_dump($msgId);
$prefix = $isCC ? '【抄送】' : '【审批】';
$text = $map[$action] ?? $action;
$approvalType = array_flip(\app\common\service\SysDictService::pluckKeyValueByCode('approval_type')->toArray());
switch ($instance->flow_type) {
case 'stock_orders': // 备货单
$stockOrder = \app\common\model\StockOrders::find($instance->biz_id);
$title = $prefix."备货单:{$stockOrder->order_no}";
$flowType = $approvalType[$instance->flow_type];
$content = "{$prefix}你有一条审批 {$text}:类型 {$flowType},业务单号 {$stockOrder->order_no}";
break;
case 'stock_orders_nullify': // 备货单作废
break;
}
noticePush([
'title' => $title,
'content' => $content,
'recipient' => $userIds,
'email' => 1
]);
}
private function notifyInitiator(object $instance, string $result): void
+26 -2
View File
@@ -2,6 +2,7 @@
namespace app\controller;
use app\common\service\SysDictService;
use app\common\service\UploadService;
use app\common\utils\scaffold\Generate;
use support\Request;
@@ -100,7 +101,7 @@ class IndexController
{
// $flowType = 'stock_order_flow';
// $flowType = 'stock_orders';
// $bizType = 'stock_orders';
// $bizId = 32;
// $formData = [];
@@ -133,7 +134,30 @@ class IndexController
// $result = $service->createdPdfFile($param['id']);
// return json($result);
\Webman\RedisQueue\Redis::send('stock-order-pdf', ['id'=>82]);
// \Webman\RedisQueue\Redis::send('stock-order-pdf', ['id'=>82]);
// $approvalType = array_flip(\app\common\service\SysDictService::pluckKeyValueByCode('approval_type')->toArray());
// $result = $approvalType['stock_orders'];
// var_dump($result);
// $list = \app\common\model\User::where('status', 1)->where('email', '!=', '')->pluck('email')->toArray();
// var_dump($list);
$approvalType = array_flip(\app\common\service\SysDictService::pluckKeyValueByCode('approval_type')->toArray());
$title = "【审批】备货单:BH20250911001";
$flowType = $approvalType['stock_orders'];
$content = "【审批】你有一条审批 待审批:类型 {$flowType},业务单号 BH20250911001";
noticePush([
'title' => $title,
'content' => $content,
'recipient' => [1],
'email' => 1
]);
} catch (\Throwable $th) {
//throw $th;
var_dump($th->getMessage().$th->getLine().$th->getFile());
@@ -182,6 +182,22 @@ class StockOrdersController extends BaseController
}
}
/**
* 最终审批
*/
public function ultimateApproval(Request $request)
{
try {
$raw = $this->service->serviceUltimateApproval($request);
$data = $this->transformData($raw, method_exists($this, 'approvalFormat')
? [$this, 'approvalFormat']
: null);
return $this->success($data);
} catch (\Throwable $e) {
return $this->error($e->getMessage());
}
}
public function desc(Request $request)
{
+25 -1
View File
@@ -15,6 +15,7 @@ use support\Db;
use support\Model;
use app\admin\model\ApprovalInstances;
use app\admin\model\ApprovalRecords;
use support\exception\BusinessException;
class StockOrdersService
{
@@ -140,7 +141,7 @@ class StockOrdersService
{
// 启动审批
$appro = new \app\common\utils\approval\service\ApprovalFlowService();
$appro->start('stock_order_flow', 'stock_orders', $item->id, $item->toArray(), $item->salesperson_id);
$appro->start('stock_orders', 'stock_orders', $item->id, $item->toArray(), $item->salesperson_id);
// 异步生成pdf文件
\Webman\RedisQueue\Redis::send('stock-order-pdf', ['id'=>$item->id]);
}
@@ -393,6 +394,29 @@ class StockOrdersService
return $this->postProcess('Approval', $item);
}
/**
* 最终审批
*/
public function serviceUltimateApproval(Request $request)
{
$config = $this->buildQueryConfig($request, 'detail');
$item = $this->logicShow($config);
foreach ($item->items as $k => $v) {
if ($v->vin === '') {
throw new BusinessException('存在未填写vin的车辆,无法完成提交审核');
}
}
$this->logicUpdateBy($config, [
'approval_status' => 1
]);
// $item = $this->logicShow($config);
$this->startApproval($item);
return $this->postProcess('UltimateApproval', $item);
}
/**
* 创建
*
+1 -1
View File
@@ -236,7 +236,7 @@ class StockOrdersService_bak
}
// 启动审批
$appro = new \app\common\utils\approval\service\ApprovalFlowService();
$result = $appro->start('stock_order_flow', 'stock_orders', $res->id, $res->toArray(), $res->salesperson_id);
$result = $appro->start('stock_orders', 'stock_orders', $res->id, $res->toArray(), $res->salesperson_id);
var_dump($result);
// 异步生成pdf文件
+28
View File
@@ -359,4 +359,32 @@ if (!function_exists('generateStockNo')) {
return $prefix . $date . $paddedSerial;
}
}
/**
* 发送通知
*
* @param string $title
* @param string $content
* @param string $url
* @param string $type
* @return void
*/
if (!function_exists('noticePush')) {
function noticePush(array $notice = [])
{
/*
消息字段:
'sender_id' //发送人
'sender_type' //发送人类型
'title' //标题
'content' //内容
'scene' //场景
'recipient' //接收人
'push_method' //推送方式
// 如果需要同时 邮箱推送 增加推送邮箱字段
'email' //邮箱
*/
\Webman\RedisQueue\Redis::send('notice', $notice);
}
}
+15 -2
View File
@@ -17,10 +17,23 @@ class Notice implements Consumer
public function consume($data)
{
try {
(new \app\common\service\MessageNotificationsService())->pushNotice($data);
// 应用消息
$service = new \app\common\service\MessageNotificationsService();
$service->pushNotice($data);
// 邮件消息
if (isset($data['email']) && $data['email'] === 1) {
$emails = $service->getUserEmailsById($data['recipient']);
foreach ($emails as $email) {
if (empty($email)) {
continue;
}
\app\common\utils\email\MailSend::send($email, $data['title'], $data['content']);
}
}
return true;
} catch (\Throwable $th) {
var_dump('4 :'.$th->getFile()."|".$th->getLine()."|".$th->getMessage());
flg("消息推送异常:".$th->getFile()."|".$th->getLine()."|".$th->getMessage());
throw new BusinessException($th->getFile()."|".$th->getLine()."|".$th->getMessage());
}
}
+1
View File
@@ -387,6 +387,7 @@ Route::group('/crm', function () {
Route::any('/print', [app\crm\controller\StockOrdersController::class, 'print']);
Route::any('/approval', [app\crm\controller\StockOrdersController::class, 'approval']);
Route::any('/detail', [app\crm\controller\StockOrdersController::class, 'detail']);
Route::any('/ultimate/approval', [app\crm\controller\StockOrdersController::class, 'ultimateApproval']);
});
// 审批记录