Zhouzhendong 4 лет назад
Родитель
Сommit
fc521dfb54

+ 64 - 0
app/Http/Controllers/NotificationController.php

@@ -0,0 +1,64 @@
+<?php
+
+
+namespace App\Http\Controllers;
+
+use App\Components\AsyncResponse;
+use App\SeeLog;
+use App\User;
+use Illuminate\Database\Eloquent\Builder;
+use Illuminate\Support\Facades\Auth;
+
+class NotificationController
+{
+    use AsyncResponse;
+
+    /**
+     * @return User|\stdClass
+     */
+    private function getUser()
+    {
+        /** @var User|\stdClass $user */
+        $user = new User();
+        $user->id = Auth::id();
+        return $user;
+    }
+
+    public function regular()
+    {
+        $user = $this->getUser();
+        $user->loadCount(["seeLogs"=>function($query){
+            /** @var Builder $query */
+            $query->where("delivered",'0');
+        }]);
+        $user->load(["seeLogs"=>function($query){
+            /** @var Builder $query */
+            $query->limit(15)->orderBy("delivered")->orderByDesc("id");
+        }]);
+        $infos = $user->seeLogs;
+        $count = $user->see_logs_count;
+        return view("layouts.notification",compact("infos","count"));
+    }
+
+    public function toTarget()
+    {
+        $id = request("id");
+        if (!$id)$this->error("服务器异常");
+        $this->success(SeeLog::query()->where("id",$id)
+        ->where("delivered",'0')->update(["delivered"=>'1']));
+    }
+    public function getRegularData()
+    {
+        $id = request("id");
+        if (!$id)$this->error("服务器异常");
+        $page = request("page");
+        $user = $this->getUser();
+        $user->load(["seeLogs"=>function($query)use($id,$page){
+            /** @var Builder $query */
+            $query->limit("{$page},15")
+                ->orderBy("delivered")
+                ->orderByDesc("id");
+        }]);
+        $this->success($user->seeLogs);
+    }
+}

+ 26 - 0
app/Http/Controllers/TestController.php

@@ -12,6 +12,7 @@ use App\ErrorTemp;
 use App\Feature;
 use App\Http\ApiControllers\LoginController;
 use App\Http\Requests\OrderDelivering;
+use App\Jobs\BatchTaskJob;
 use App\Jobs\CacheShelfTaskJob;
 use App\Jobs\OrderCreateInstantBill;
 use App\Jobs\OrderCreateWaybill;
@@ -23,6 +24,7 @@ use App\LaborReport;
 use App\LaborReportStatus;
 use App\MaterialBox;
 use App\MaterialBoxModel;
+use App\Notifications\RoutineNotification;
 use App\OracleDOCASNHeader;
 use App\OracleDOCOrderHeader;
 use App\OracleDocOrderPackingSummary;
@@ -42,9 +44,11 @@ use App\OwnerPriceOperation;
 use App\OrderPackageCountingRecord;
 use App\ProcurementCheckSheet;
 use App\RejectedBill;
+use App\SeeLog;
 use App\Services\BatchService;
 use App\Services\CacheShelfService;
 use App\Services\ForeignHaiRoboticsService;
+use App\Services\NotificationService;
 use App\Services\OrderPackageReceivedSyncService;
 use App\Services\OrderPackageService;
 use App\Services\OrderService;
@@ -77,12 +81,14 @@ use Illuminate\Database\Eloquent\Collection;
 use Illuminate\Database\Eloquent\HigherOrderBuilderProxy;
 use Illuminate\Foundation\Http\FormRequest;
 use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Broadcast;
 use Illuminate\Support\Facades\Cache;
 use Illuminate\Support\Facades\Auth;
 use Illuminate\Support\Facades\Cookie;
 use Illuminate\Support\Facades\DB;
 use Illuminate\Support\Facades\Http;
 use Illuminate\Support\Facades\Log;
+use Illuminate\Support\Facades\Notification;
 use Illuminate\Support\Facades\URL;
 use Illuminate\Support\Facades\Validator;
 use Illuminate\Support\Str;
@@ -110,6 +116,22 @@ class TestController extends Controller
 
     public function test()
     {
+        $user = Auth::user();
+        $remark = "zengjunlj";
+        $ownerName = 'zengjunlj' ?? '';
+        $clientCode = 'zengjunljljlj' ?? '';
+        $msg = $user["name"]."建立了新工单<br/>".$ownerName.":".$clientCode."<br/>".$remark;
+        NotificationService::SingleRegister($msg,$clientCode,"订单管理-问题件");
+        dd(1);
+        $seeLog = SeeLog::query()->find(9);
+        Notification::send(Auth::user(),new RoutineNotification($seeLog->toArray()));
+        dd(1);
+        Broadcast::channel('notification', function ($user, $id) {
+            return (int) $user->id === (int) $id;
+        });
+        dd(1);
+        Notification::send(Auth::user(),new RoutineNotification($seeLog->toArray()));
+        dd(1);
         $username = config('database.connections.oracle.username');
         $password = config('database.connections.oracle.password');
         $host = config('database.connections.oracle.host');
@@ -386,4 +408,8 @@ sql;
             '75803656098612'
         ]);
     }
+
+    public function teset12313(){
+        dd(route("discharge.storeApi"));
+    }
 }

+ 50 - 0
app/Notifications/RoutineNotification.php

@@ -0,0 +1,50 @@
+<?php
+
+namespace App\Notifications;
+
+use Illuminate\Bus\Queueable;
+use Illuminate\Contracts\Queue\ShouldQueue;
+use Illuminate\Notifications\Messages\BroadcastMessage;
+use Illuminate\Notifications\Notification;
+
+class RoutineNotification extends Notification implements ShouldQueue
+{
+    use Queueable;
+
+    /** @var array|mixed $seeLog */
+    private $seeLog;
+
+    public function __construct(array $seeLog)
+    {
+        $seeLog["no"] = $seeLog["id"];
+        unset($seeLog["id"]);
+        $this->seeLog = $seeLog;
+    }
+
+    /**
+     * Get the notification's delivery channels.
+     *
+     * @param  mixed  $notifiable
+     * @return array
+     */
+    public function via($notifiable):array
+    {
+        return ['broadcast'];
+    }
+
+    public function viaQueues():array
+    {
+        return [
+            'broadcast' => 'notification-broadcast',
+        ];
+    }
+    public function broadcastType():string
+    {
+        return 'common';
+    }
+
+    public function toBroadcast($notifiable):BroadcastMessage
+    {
+        return new BroadcastMessage($this->seeLog);
+    }
+}

+ 3 - 1
app/Providers/AppServiceProvider.php

@@ -183,6 +183,7 @@ use App\Services\WorkOrderService;
 use App\Services\WorkOrderTypeService;
 use App\Services\OrderPackageRemarkService;
 use App\Services\LaborCompanyService;
+use App\Services\NotificationService;
 
 class AppServiceProvider extends ServiceProvider
 {
@@ -210,7 +211,6 @@ class AppServiceProvider extends ServiceProvider
     }
 
     private function loadingService(){
-        app()->singleton('ReviewService',ReviewService::class);
         app()->singleton('AllInventoryService',AllInventoryService::class);
         app()->singleton('AuthorityService',AuthorityService::class);
         app()->singleton('BatchService',BatchService::class);
@@ -266,6 +266,7 @@ class AppServiceProvider extends ServiceProvider
         app()->singleton('MaterialBoxService', MaterialBoxService::class);
         app()->singleton('MenuService',MenuService::class);
         app()->singleton('NewOrderCountingRecordService',NewOrderCountingRecordService::class);
+        app()->singleton('NotificationService',NotificationService::class);
         app()->singleton('OracleActAllocationDetailService', OracleActAllocationDetailService::class);
         app()->singleton('OracleBasCustomerService', OracleBasCustomerService::class);
         app()->singleton('OracleBasSkuService', OracleBasSkuService::class);
@@ -339,6 +340,7 @@ class AppServiceProvider extends ServiceProvider
         app()->singleton('RejectedService', RejectedService::class);
         app()->singleton('RequirementService',RequirementService::class);
         app()->singleton('RequirementUserService',RequirementUserService::class);
+        app()->singleton('ReviewService',ReviewService::class);
         app()->singleton('RoleService',RoleService::class);
         app()->singleton('SFDeliveryService',SFDeliveryService::class);
         app()->singleton('SFQHDDeliveryService',SFQHDDeliveryService::class);

+ 27 - 0
app/SeeLog.php

@@ -0,0 +1,27 @@
+<?php
+
+namespace App;
+
+use App\Traits\ModelTimeFormat;
+use Illuminate\Database\Eloquent\Model;
+
+use App\Traits\ModelLogChanging;
+use Illuminate\Database\Eloquent\Relations\BelongsToMany;
+
+class SeeLog extends Model
+{
+    use ModelLogChanging,ModelTimeFormat;
+
+    protected $fillable = [
+        "message","title","delivered","link","mark"
+    ];
+
+    const MARK = [
+        0,//工单通知
+    ];
+
+    public function users():BelongsToMany
+    {
+        return $this->belongsToMany(User::class);
+    }
+}

+ 13 - 0
app/Services/AuthorityService.php

@@ -5,6 +5,7 @@ namespace App\Services;
 
 
 use App\Authority;
+use App\User;
 use Illuminate\Database\Eloquent\Builder;
 use Illuminate\Database\Eloquent\Collection;
 use Illuminate\Support\Facades\Auth;
@@ -123,4 +124,16 @@ class AuthorityService
         }
         return false;
     }
+
+    /**
+     * 通过权限CODE获取用户
+     */
+    public function authorityGetUsers(string $aliasName)
+    {
+        return User::query()->whereHas("roles",function ($query)use($aliasName){
+            $query->whereHas("authorities",function ($query)use($aliasName){
+                $query->where("alias_name",$aliasName);
+            });
+        })->orWhereIn("name",config("users.superAdmin"))->get();
+    }
 }

+ 32 - 0
app/Services/NotificationService.php

@@ -0,0 +1,32 @@
+<?php
+
+namespace App\Services;
+
+use App\Notifications\RoutineNotification;
+use App\SeeLog;
+use Illuminate\Support\Facades\Notification;
+
+class NotificationService
+{
+    static function SingleRegister(string $message,string $number,string $authorityName)
+    {
+
+        $default = [
+            "message"   => $message,
+            "title"     => "工单提示",
+            "link"      => "order/workOrder/index?client_code={$number}",
+            "mark"      => 0,
+            "delivered" => '0',
+        ];
+        /** @var SeeLog $info */
+        $info = SeeLog::query()->create($default);
+        $users = app("AuthorityService")->authorityGetUsers($authorityName);
+        if ($users->count()==0)return;
+        $ids = [];
+        foreach ($users as $user){
+            $ids[] = $user->id;
+            Notification::send($user,new RoutineNotification($info->toArray()));
+        }
+        $info->users()->sync($ids);
+    }
+}

+ 7 - 7
app/Services/OrderService.php

@@ -224,7 +224,8 @@ class OrderService
         if ($edisendflag) $sql.=" and edisendflag like '".$edisendflag."%'";
         if ($manualflag) $sql.=" and manualflag = '".$manualflag."'";
         if ($soreference1){
-            $arr=array_values(array_filter(preg_split('/[,, ]+/is', $soreference1)));
+            mb_regex_encoding('utf-8');
+            $arr=array_values(array_filter(preg_split('/[,, ]+/u', $soreference1,-1,PREG_SPLIT_NO_EMPTY)));
             if (count($arr)==1){
                 $sql.=" and soreference1 like '".$soreference1."%'";
             }
@@ -239,7 +240,6 @@ class OrderService
                 }
                 $sql.=")";
             }
-            if ($params['soreference']) $sql.=" and soreference1 like '".$params['soreference']."'";
         }
         return $sql;
     }
@@ -335,22 +335,22 @@ class OrderService
         if ($params['soreference1']??false){
             $arr=array_values(array_filter(preg_split('/[,, ]+/is', $params['soreference1'])));
             if (count($arr)==1){
-                $params['soreference']='';$sql = $this->getSql($params,$params['page'] ?? 1, $params['paginate'] ?? 50);
+                $params['soreference1']='';$sql = $this->getSql($params,$params['page'] ?? 1, $params['paginate'] ?? 50);
             }
             if (count($arr)>1 && !strpos($params['soreference1'],'%')){
-                $params['soreference']='';$sql = $this->getSql($params,$params['page'] ?? 1, $params['paginate'] ?? 50);
+                $params['soreference1']='';$sql = $this->getSql($params,$params['page'] ?? 1, $params['paginate'] ?? 50);
             }
             if (count($arr)>1 && strpos($params['soreference1'],'%')){
                 foreach ($arr as $index=>$str){
                     if ($index==0){
-                        $params['soreference']=$str; $sql=$this->getSql($params,$params['page'] ?? 1, $params['paginate'] ?? 50); continue;
+                        $params['soreference1']=$str; $sql=$this->getSql($params,$params['page'] ?? 1, $params['paginate'] ?? 50); continue;
                     }
-                    $params['soreference']=$str;
+                    $params['soreference1']=$str;
                     $sql.=" union ".$this->getSql($params,$params['page'] ?? 1, $params['paginate'] ?? 50);
                 }
             }
         }else{
-            $params['soreference']='';
+            $params['soreference1']='';
             $sql = $this->getSql($params,$params['page'] ?? 1, $params['paginate'] ?? 50);
         }
         if ($sql)$orders=DB::connection('oracle')->select(DB::raw($sql));

+ 9 - 4
app/Services/StoreService.php

@@ -20,6 +20,7 @@ use Illuminate\Support\Facades\Cache;
 
 use App\Traits\ServiceAppAop;
 use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Log;
 
 
 class StoreService
@@ -374,10 +375,14 @@ class StoreService
      */
     public function clearFeeInfo(string $docNumber)
     {
-        $models = OwnerFeeOperation::query()->where("doc_number",$docNumber)->get();
-        if ($models->count()==0)return;
-        OwnerFeeOperationDetail::query()->whereIn("owner_fee_operation_id",array_column($models->toArray(),"id"))->delete();
-        OwnerFeeOperation::query()->where("doc_number",$docNumber)->delete();
+        try {
+            $models = OwnerFeeOperation::query()->where("doc_number",$docNumber)->get();
+            if ($models->count()==0)return;
+            OwnerFeeOperationDetail::query()->whereIn("owner_fee_operation_id",array_column($models->toArray(),"id"))->delete();
+            OwnerFeeOperation::query()->where("doc_number",$docNumber)->delete();
+        }catch (\Exception $e){
+            Log::warning("清除费用信息发送错误",["ASN号:{$docNumber}",isset($models) ? $models->toJson() : "查费用信息时被锁定"]);
+        }
     }
 
     /**

+ 9 - 0
app/Services/WorkOrderService.php

@@ -101,6 +101,15 @@ class WorkOrderService
         }
         if (isset($inner_params)) {
             WorkOrder::query()->insert($inner_params);
+            $workOrders = WorkOrder::query()->with('owner','order')->whereIn('order_id',data_get($inner_params,"*.order_id"))->where('created_at',">=",$data)->get();
+            foreach ($workOrders as $workOrder){
+                $user = Auth::user();
+                $remark = $workOrder->remark;
+                $ownerName = $workOrder->owner->name ?? '';
+                $clientCode = $workOrder->order->client_code ?? '';
+                $msg = $user["name"]."建立了新工单<br/>".$ownerName.":".$clientCode."<br/>".$remark;
+                NotificationService::SingleRegister($msg,$clientCode,"订单管理-问题件");
+            }
             return ['success' => true];
         }
         return ['success' => false, 'message' => '参数异常'];

+ 2 - 1
app/Services/common/BatchUpdateService.php

@@ -8,7 +8,8 @@ use Illuminate\Support\Facades\DB;
 use App\Traits\ServiceAppAop;
 
 
-class BatchUpdateService
+class
+BatchUpdateService
 {
     use ServiceAppAop,ErrorPush;
     public function batchUpdate($tableName = '', $multipleData = array(), $connection = 'mysql')

+ 6 - 0
app/User.php

@@ -3,6 +3,7 @@
 namespace App;
 
 use App\Traits\ModelLogChanging;
+use Illuminate\Database\Eloquent\Relations\BelongsToMany;
 use Illuminate\Database\Eloquent\SoftDeletes;
 use Illuminate\Notifications\Notifiable;
 use Illuminate\Foundation\Auth\User as Authenticatable;
@@ -177,4 +178,9 @@ class User extends Authenticatable
     {
         return $this->morphedByMany(UserOwnerGroup::class, 'user_authable');
     }
+
+    public function seeLogs():BelongsToMany
+    {
+        return $this->belongsToMany(SeeLog::class);
+    }
 }

+ 1 - 2
config/database.php

@@ -186,14 +186,13 @@ return [
     | such as APC or Memcached. Laravel makes it easy to dig right in.
     |
     */
-
     'redis' => [
 
         'client' => env('REDIS_CLIENT', 'predis'),
 
         'options' => [
             'cluster' => env('REDIS_CLUSTER', 'predis'),
-            'prefix' => Str::slug(env('APP_NAME', 'laravel'), '_').'_database_',
+            'prefix' => '',//Str::slug(env('APP_NAME', 'laravel'), '_').'_database_',
         ],
 
         'default' => [

+ 36 - 0
database/migrations/2021_09_15_144213_create_see_logs_table.php

@@ -0,0 +1,36 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class CreateSeeLogsTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('see_logs', function (Blueprint $table) {
+            $table->id();
+            $table->string('message');
+            $table->string('title', 50);
+            $table->string("link")->nullable();
+            $table->tinyInteger("mark")->default(0);
+            $table->enum('delivered', [0, 1])->default(0);
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('see_logs');
+    }
+}

+ 31 - 0
database/migrations/2021_09_15_144836_create_see_log_user_table.php

@@ -0,0 +1,31 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class CreateSeeLogUserTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('see_log_user', function (Blueprint $table) {
+            $table->bigInteger("user_id")->index();
+            $table->bigInteger("see_log_id");
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('see_log_user');
+    }
+}

+ 2 - 7
laravel-echo-server.json

@@ -1,12 +1,7 @@
 {
-	"authHost": "http://localhost",
+	"authHost": "http://bswas",
 	"authEndpoint": "/broadcasting/auth",
-	"clients": [
-		{
-			"appId": "85568e6915a996da",
-			"key": "4339d8623127f8f4e8819901cbf62833"
-		}
-	],
+	"clients": [],
 	"database": "redis",
 	"databaseConfig": {
 		"redis": {},

+ 18 - 1
resources/js/queryForm/header.js

@@ -556,7 +556,7 @@ window.Header = function getHeader(object) {
         div22.id = "setting-header-body";
         div22.style.display="none";
         let div221 = document.createElement("div");
-        div221.className = "row";
+        div221.className = "row mt-2";
         let text = document.createElement("label");
         text.innerText = "清除本地列宽设置:";
         text.className = "text-right col-3";
@@ -585,7 +585,24 @@ window.Header = function getHeader(object) {
             settingInfo.isCopyNoWrap = event.target.checked;
             localStorage.setItem("settingInfo",JSON.stringify(settingInfo));
         };
+        let div223 = document.createElement("div");
+        div223.className = "row";
+        let text3 = document.createElement("label");
+        text3.innerText = "消息通知:";
+        text3.className = "text-right col-3";
+        div223.appendChild(text3);
+        let btn3 = document.createElement("button");
+        btn3.className = "btn btn-sm btn-outline-info";
+        btn3.innerText = "打开消息面板";
+        btn3.onclick= function (){
+            let height = window.screen.height;
+            window.open ("https://"+window.location.host+"/notification/regular", 'newwindow', 'height='+(height*0.7)+', width=510 ,top='+(height*0.10)+
+                'toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no');
+        };
+        div223.appendChild(btn3);
+
         div222.appendChild(input);
+        div22.appendChild(div223);
         div22.appendChild(div221);
         div22.appendChild(div222);
         div2.appendChild(div22);

+ 197 - 0
resources/views/layouts/notification.blade.php

@@ -0,0 +1,197 @@
+<!DOCTYPE html>
+<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
+<head>
+    <meta charset="utf-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1">
+    <link rel="icon" href="{{asset('icon/faviconc.ico')}}" type="image/x-icon"/>
+    <title>通知栏</title>
+    <!-- CSRF Token -->
+    <meta name="csrf-token" content="{{ csrf_token() }}">
+    <link href="{{ mix('css/app.css') }}" rel="stylesheet">
+    <style>
+        html{
+            height: 100%;
+            width: 100%;
+        }
+        body{
+            width: 510px;
+            margin : 0 auto;
+        }
+        .b-container{
+            background: RGB(245,250,245) !important;
+        }
+        li{
+            cursor: pointer;
+        }
+        ul{
+            max-height: 100%;
+            max-width: 100%;
+            overflow: auto;
+            border: RGB(204, 204, 204) solid 1px;
+            border-radius: 5px;
+        }
+        #msg{
+            width:266px;
+            position: fixed;
+            z-index:999;
+            top: 49%;
+            margin-top:-80px;
+            left:50%;
+            margin-left:-133px;
+            background:#fff;
+            box-shadow:5px 5px 8px #999;
+            font-size:17px;
+            color:#666;
+            border:1px solid #f8f8f8;
+            text-align: center;
+            line-height: 2rem;
+            display:inline-block;
+            padding-bottom:20px;
+            border-radius:5px;
+        }
+        #msg_top {
+            background: #f8f8f8;
+            padding: 5px 15px 5px 20px;
+            text-align: left;
+        }
+        #msg_top span{
+            font-size:22px;
+            float:right;
+            cursor:pointer;
+        }
+        #msg_cont{
+            padding:15px 20px 20px;
+            text-align:left;
+        }
+        #msg_clear{
+            background:#8fc31f;
+            float:right;
+        }
+        #msg_success{
+            background:#2a9055;
+            float:right;
+        }
+        .msg_btn{
+            display:inline-block;
+            color:#fff;
+            padding:1px 15px;
+            border-radius:2px;
+            margin-right:15px;
+            cursor:pointer;
+        }
+    </style>
+</head>
+<body class="h-100">
+    <div id="notification" class="w-100 h-100 b-container p-0 card">
+        <div class="card-header">
+            <label class="h3 text-center w-100">
+                <b style="font-family:STHupo">@{{ count }}</b>
+                <label class="text-secondary" style="font-family:STZhongsong">条未处理通知</label>
+            </label>
+        </div>
+        <div class="card-body p-0">
+            <ul class="list-group" id="scroll-list">
+                <li class="list-group-item mt-3" v-for="info in infos" @click="toTarget(info)">
+                    <div class="row">
+                        <div class="col-7 row">
+                            <div class="col-3 pr-0 h5" v-if="info.delivered=='0'"><span class="badge badge-secondary">New</span></div>
+                            <div v-else class="col-1"></div>
+                            <div class="text-left text-overflow-replace font-weight-bold col-8 p-0">@{{ info.title }}</div>
+                        </div>
+                        <div class="text-right text-secondary col-5">@{{ info.created_at }}</div>
+                    </div>
+                    <div class="offset-2 mt-2 text-muted" v-html="info.message">
+                    </div>
+                </li>
+            </ul>
+        </div>
+    </div>
+</body>
+<script src="{{ mix('js/app.js') }}"></script>
+<script type="text/javascript">
+        var audioPlay = false;
+        //重绘弹窗样式
+        function alert(e){
+            $("body").append('<div id="msg"><div id="msg_top">设置<span class="msg_close">×</span></div><div id="msg_cont">'+e+
+                '</div><div class="msg_close msg_btn" id="msg_clear">取消</div><div class="msg_close msg_btn" id="msg_success">确定</div></div>');
+            $("#msg_clear").click(function (){
+                $("#msg").remove();
+            });
+            $("#msg_success").click(function (){
+                audioPlay = true;
+                $("#msg").remove();
+            });
+        }
+        alert("是否开启音频?");
+        new Vue({
+            el:"#notification",
+            data:{
+                infos:{!! $infos !!},
+                loadSign:false,
+                count: {!! $count !!},
+                page:2,
+                mark:{
+                    "0" : "/storage/audio.mp3",
+                }
+            },
+            mounted(){
+                if(this.infos.length===15)this.bindListen();
+                $(document.body).append($('<audio id="audio" src="" autoplay></audio>'));
+                this.initBroadcast();
+            },
+            methods: {
+                bindListen(){
+                    $("#scroll-list").scroll(()=>{
+                        let element = $("#scroll-list");
+                        let scrollTop = element.scrollTop();
+                        let scrollHeight = element[0].scrollHeight;
+                        let height = element.height();
+                        if(scrollTop + height > scrollHeight-50){
+                            this.loadData();
+                        }
+                    });
+                },
+                initBroadcast() {
+                    initEcho();
+                    Echo.private('App.User.' + {{\Illuminate\Support\Facades\Auth::id()}})
+                        .notification((notification) => {
+                            console.log(notification);
+                            this.count++;
+                            this.infos.unshift(notification);
+                            if (notification.mark==0)this.playAudio(notification.mark);
+                        });
+                },
+                playAudio(mark){
+                    if (!audioPlay)return;
+                    let audio = document.getElementById('audio');
+                    audio.src = this.mark[mark];
+                    setTimeout(()=>{
+                        audio.play();
+                    },0);
+                },
+                toTarget(info = null){
+                    if (info.delivered==='0'){
+                        window.tempTip.postBasicRequest("{{url('notification/toTarget')}}",
+                            {id:info.no ? info.no : info.id},res=>{
+                                info.delivered = '1';
+                                this.count--;
+                            })
+                    }
+                    window.open('{{url('')}}'+'/'+info.link);
+                },
+                loadData(){
+                    if (this.loadSign)return;
+                    this.loadSign = true;
+                    let last = this.infos[this.infos.length-1];
+                    window.tempTip.postBasicRequest("{{url('notification/regular')}}",
+                        {id:last.no ? last.no : last.id,page:this.page},res=>{
+                            this.loadSign = false;
+                            this.page++;
+                            if (res)this.infos.push.apply(this.infos,res);
+                            if (!res || res.length<15)$("#scroll-list").unbind("scroll");
+                        })
+                }
+            }
+        });
+</script>
+</html>

+ 6 - 0
routes/web.php

@@ -1045,5 +1045,11 @@ Route::group(['prefix'=>'package'],function(){
         });
     });
 
+    Route::group(['prefix' => 'notification'],static function () {
+            Route::get('/regular', 'NotificationController@regular');
+            Route::post('/regular', 'NotificationController@getRegularData');
+            Route::post('/toTarget', 'NotificationController@toTarget');
+        }
+    );
 });