|
|
@@ -0,0 +1,86 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace App\Jobs\Manager\Process;
|
|
|
+
|
|
|
+use Illuminate\Bus\Queueable;
|
|
|
+use Illuminate\Contracts\Queue\ShouldBeUnique;
|
|
|
+use Illuminate\Contracts\Queue\ShouldQueue;
|
|
|
+use Illuminate\Foundation\Bus\Dispatchable;
|
|
|
+use Illuminate\Queue\InteractsWithQueue;
|
|
|
+use Illuminate\Queue\SerializesModels;
|
|
|
+use App\Models\Manager\Personnel\Employee as EmployeeModel;
|
|
|
+use App\Facades\Servers\Wechat\Official;
|
|
|
+use App\Facades\Servers\Logs\Log;
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * 订阅消息通知推送
|
|
|
+ * @author 唐远望
|
|
|
+ * @version 1.0
|
|
|
+ * @date 2026-03-04
|
|
|
+ */
|
|
|
+class Subscription implements ShouldQueue
|
|
|
+{
|
|
|
+ use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
+ protected $message_data;
|
|
|
+ /**
|
|
|
+ * Create a new job instance.
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function __construct(array $message_data)
|
|
|
+ {
|
|
|
+ $this->message_data = $message_data;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Execute the job.
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function handle()
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ $this->send($this->message_data['user_id_list'], $this->message_data['msg_title']);
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ Log::info('job_error', '订阅消息通知推送队列失败', ['data' => $this->message_data, 'error' => $e->getMessage()]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 公众号消息订阅推送
|
|
|
+ *
|
|
|
+ * */
|
|
|
+ private function send($user_id_list, $msg_title = '')
|
|
|
+ {
|
|
|
+ $EmployeeModel = new EmployeeModel();
|
|
|
+ $user_list = $EmployeeModel->whereIn('id',$user_id_list)->where([['open_subscribe', '=', 0], ['status', '=', 1]])->select(['openid'])->select();
|
|
|
+ if(empty($user_list)) return true;
|
|
|
+ $data = [
|
|
|
+ 'thing1' => $msg_title,
|
|
|
+ 'thing2' => '您有一条新的违规待处理通知要处理,请及时查看',
|
|
|
+ 'time7' => strtotime(time(), 'Y:m:d H:i:s'),
|
|
|
+ 'phrase9' => '待处理',
|
|
|
+ ];
|
|
|
+ foreach ($user_list as $value) {
|
|
|
+ $params = [
|
|
|
+ 'touser' => $value['openid'],
|
|
|
+ 'template_id' => 't559Iagds7Av-YcqwIpeAaS5gt7LuOKuIBDvVKlyfm8',
|
|
|
+ 'url' => '',
|
|
|
+ 'data' => $data,
|
|
|
+ ];
|
|
|
+ //发送模板消息
|
|
|
+ $result = Official::sendSubscription($params);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 告知结果
|
|
|
+ return json_send(['code' => 'success', 'msg' => '成功', 'path' => '']);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public function failed(\Throwable $exception)
|
|
|
+ {
|
|
|
+ Log::info('job_error', '订阅消息通知推送队列完全失败', ['data' => $this->message_data, 'error' => $exception]);
|
|
|
+ }
|
|
|
+}
|