wesley 7 년 전
부모
커밋
ed6df4fe79

+ 30 - 2
app/Http/Controllers/Admin/Order/InfoController.php

xqd xqd
@@ -23,6 +23,7 @@ use App\Repositories\Order\InfoRepository;
 use Illuminate\Pagination\LengthAwarePaginator;
 use Illuminate\Pagination\Paginator;
 use Illuminate\Support\Collection;
+use Cache;
 
 class InfoController extends Controller
 {
@@ -303,9 +304,36 @@ class InfoController extends Controller
 
     }
 
-    public function notify()
-    {
+    public function checkNewOrder(){
+        $order = OrderInfoModel::where('status',1)->orderBy('id','desc')->first();
+
+        $new_id = $order?$order->id:0;
+        $old_id= Cache::store('database')->get('order_id');
+
+        $count = OrderInfoModel::where('status',1)->count();
+
+        \Log::info($new_id);
+        \Log::info($old_id);
+        if($new_id == $old_id){
+
+            $data = [
+                'code' => 1,
+                'msg' => '没有新的订单',
+                'count' => $count
+            ];
+
+            return json_encode($data);
+        }else{
+            Cache::store('database')->forget('order_id');
+            Cache::store('database')->put('order_id',$new_id,10);
 
+            $data = [
+                'code' => 0,
+                'msg' => '你有新的订单待处理!',
+                'count' => $count
+            ];
+            return json_encode($data);
+        }
     }
 
     /*

+ 32 - 0
database/migrations/2018_09_26_155807_create_cache_table.php

xqd
@@ -0,0 +1,32 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class CreateCacheTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('cache', function (Blueprint $table) {
+            $table->string('key')->unique();
+            $table->mediumText('value');
+            $table->integer('expiration');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('cache');
+    }
+}

BIN
public/.DS_Store


BIN
public/base/5611.wav


+ 61 - 0
resources/views/admin/base/index/index.blade.php

xqd xqd
@@ -131,6 +131,7 @@
         <div id="right-sidebar">
            
         </div>
+    </div>
         <!--右侧边栏结束-->
     <!-- 全局js -->
     <script src="/base/js/jquery-2.1.1.min.js?v={{config("sys.version")}}" ></script>
@@ -145,6 +146,66 @@
 
     <!-- 第三方插件 -->
     <script src="/base/js/plugins/pace/pace.min.js?v={{config("sys.version")}}" ></script>
+
+    <script>
+
+        var checkUrl = "{{U('Order/Info/checkneworder')}}";
+        var sound = "/base/5611.wav";
+
+        function playSound() {
+            var borswer = window.navigator.userAgent.toLowerCase();
+            if (borswer.indexOf("ie") >= 0) {
+                //IE内核浏览器
+                var strEmbed = '<embed name="embedPlay" src="' + sound + '" autostart="true" hidden="true" loop="false"></embed>';
+                if ($("body").find("embed").length <= 0)
+                    $("body").append(strEmbed);
+                var embed = document.embedPlay;
+
+                //浏览器不支持 audion,则使用 embed 播放
+                console.log(23)
+                embed.volume = 100;
+            } else {
+                //非IE内核浏览器
+                var strAudio = "<audio id='audioPlay' src='" + sound + "' hidden='true'>";
+                if ($("body").find("audio").length <= 0)
+                    $("body").append(strAudio);
+
+                var audio = document.getElementById("audioPlay");
+
+                console.log(24)
+                //浏览器支持 audion
+                audio.play();
+            }
+        }
+
+
+        // 订单消息
+        function checkmessage() {
+            $.ajax({
+                url: checkUrl,
+                type: 'get',
+                dataType: 'json',
+                success: function (res) {
+                    console.log(res)
+                    if (res.code == 0) {
+                        $('.cart-waring').html(res.count);
+                        playSound();
+                    }
+
+                }
+            });
+        }
+
+        $(document).ready(function () {
+            var html = "<span class='label label-warning pull-right cart-waring'></span>";
+            $('.fa-shopping-cart').after(html);
+            checkmessage();
+
+            setInterval(function () {
+                checkmessage();
+            }, 60000);
+        });
+    </script>