wesley 7 年之前
父節點
當前提交
9adfda64d0

+ 2 - 1
.gitignore

xqd
@@ -11,4 +11,5 @@ Homestead.yaml
 _ide_helper*
 *.lock
 /storage/logs
-/public/upload
+/public/upload
+/public/download

+ 32 - 0
app/Http/Controllers/Admin/Card/InfoController.php

xqd xqd xqd
@@ -8,7 +8,10 @@
  */
 namespace App\Http\Controllers\Admin\Card;
 use App\Http\Controllers\Admin\Controller;
+use App\Models\CardInfoModel;
 use App\Models\ProductCategoryModel;
+use App\Models\SettingInfoModel;
+use EasyWeChat\Factory;
 use Illuminate\Http\Request;
 use App\Repositories\Base\Criteria\OrderBy;
 use App\Repositories\Card\Criteria\MultiWhere;
@@ -113,6 +116,34 @@ class InfoController extends Controller
         }
     }
 
+    public function getQrcode($id)
+    {
+        $this->setting = SettingInfoModel::first();
+
+        $config = [
+            'app_id' => $this->setting->app_id,
+            'secret' => $this->setting->app_secret,
+
+            // 指定 API 调用返回结果的类型:array(default)/collection/object/raw/自定义类名
+            'response_type' => 'array',
+        ];
+
+
+        $app = Factory::miniProgram($config);
+        $response = $app->app_code->getQrCode('/pages/card/active?card_no='.$id);
+        $path = public_path() . '/download';
+        $qrcode = $response->save($path, $id);
+        if ($qrcode) {
+            $qrcode = env('APP_URL') . '/download/' . $id . '.jpg';
+            $card = CardInfoModel::where('card_no',$id)->first();
+            $card->qrcode = $qrcode;
+            $card->save();
+            return true;
+        } else {
+            return false;
+        }
+    }
+
     public function store(Request $request)
     {
         $data = (array) request('data');
@@ -124,6 +155,7 @@ class InfoController extends Controller
         for ($i =0 ;$i<$number;$i++){
             $data['card_no'] = time() . $i;
             $this->repository->create($data);
+            $this->getQrcode($data['card_no']);
         }
 
         return back();

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

xqd
@@ -0,0 +1,32 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class AddQrcodeToCardInfo extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('card_info', function (Blueprint $table) {
+            $table->string('qrcode',255)->after('end_time')->nullable()->comment('二维码');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('card_info', function (Blueprint $table) {
+            //
+        });
+    }
+}

+ 2 - 4
resources/views/admin/card/info/index.blade.php

xqd xqd
@@ -36,9 +36,8 @@
                     <table class="table table-striped table-bordered table-hover dataTables-example dataTable">
                         <thead>
                         <tr>
-
-                            <th class="sorting" data-sort="id"> ID</th>
                             <th class="sorting" data-sort="card_no"> 优惠卡编号</th>
+                            <th class="sorting" data-sort="qrcode"> 二维码</th>
                             <th class="sorting" data-sort="price"> 金额</th>
                             <th class="sorting" data-sort="min_price">最低使用价格</th>
                             <th class="sorting" data-sort="end_time">有效期</th>
@@ -52,9 +51,8 @@
                         @if(isset($list))
                             @foreach($list as $key => $item)
                                 <tr>
-
-                                    <td>{{ $item->id }}</td>
                                     <td>{{ $item->card_no }}</td>
+                                    <td><img src="{{ $item->qrcode }}" style="height: 80px" alt=""></td>
                                     <td>{{ $item->price }}</td>
                                     <td>{{ $item->min_price }}</td>
                                     <td>{{ $item->end_time }}</td>

+ 9 - 2
resources/views/admin/card/info/view.blade.php

xqd
@@ -18,8 +18,15 @@
                                                    
                    <p class="list-group-item-text"> {{ $data['card_no'] or ''}}</p>
                                                  
-               </div>                     
-               <div class="list-group-item">
+               </div>
+            <div class="list-group-item">
+
+                <h3 class="list-group-item-heading">二维码</h3>
+
+                <p class="list-group-item-text"><img src="{{ $data['qrcode'] }}" style="height: 200px" alt=""></p>
+
+            </div>
+            <div class="list-group-item">
                                                   
                    <h3 class="list-group-item-heading">金额</h3>