消息推送增加邮箱&&增加终版保存功能
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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文件
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user