Silent 6 éve
szülő
commit
c5a222a8aa

+ 15 - 0
app/Http/Controllers/WeChat/ApiController.php

xqd
@@ -289,6 +289,21 @@ class ApiController extends Controller
         return response()->json(['status' => 'success', 'width' => $image->width(), 'height' => $image->height(), 'shareImage' => $image_url, 'shareText' => $text, 'shareTextPosX' => $pos[0], 'shareTextPosY' => $pos[1]]);
     }
 
+    public function getShareText(Request $request)
+    {
+        if(empty($request->input('student_id')) || empty($student = Student::find($request->input('student_id')))) {
+            return response()->json(['status' => 'fail', 'info' => '找不到用户信息!']);
+        }
+        $share_text = Setting::where('key', 'share_text')->first();
+        if(empty($share_text) || empty($share_text->value)) {
+            return response()->json(['status' => 'fail', 'info' => '找不到分享的文字!']);
+        }
+        $count = $student->getTodayCheckCardMinutes();
+        $text = str_replace_array('{param}', [$count], $share_text->value);
+
+        return response()->json(['status' => 'success', 'shareText' => $text]);
+    }
+
     public function getMoreVideosAndArticles(Request $request)
     {
         $video_offset = $request->input('video_offset', 0);

+ 2 - 1
routes/wechat.php

xqd
@@ -20,4 +20,5 @@ Route::get('bindPhone', 'ApiController@bindPhone');
 Route::post('getPhone', 'ApiController@getPhone');
 Route::get('getFormSet', 'ApiController@getFormSet');
 Route::post('submitForm', 'ApiController@submitForm');
-Route::any('payNotify', 'ApiController@payNotify');
+Route::any('payNotify', 'ApiController@payNotify');
+Route::get('getShareText', 'ApiController@getShareText');

+ 78 - 61
wechat/pages/index/index.js

xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd
@@ -1,4 +1,3 @@
-
 var app = getApp()
 var api = require('../../utils/api.js');
 
@@ -7,13 +6,13 @@ const MIN = 60 * SEC
 const HOUR = 60 * MIN
 Page({
   data: {
-    currentLatitude: 0,     //用户当前纬度
-    currentLongitude: 0,    //用户当前经度
-    is_btn_disabled: true,  //开始按钮状态
-    locationAccuracy: 0,    //gps 误差
-    isLearning: false,      //是否在学习中?
-    startTime: null,        //开始时间
-    clock: '00:00:00',      //计时
+    currentLatitude: 0, //用户当前纬度
+    currentLongitude: 0, //用户当前经度
+    is_btn_disabled: true, //开始按钮状态
+    locationAccuracy: 0, //gps 误差
+    isLearning: false, //是否在学习中?
+    startTime: null, //开始时间
+    clock: '00:00:00', //计时
     shareCanvasWidth: 200,
     shareCanvasHeight: 280,
     shareImage: '',
@@ -23,7 +22,7 @@ Page({
     shareTempFilePath: '',
     showPopup: false
   },
-  onLoad: function () {
+  onLoad: function() {
     wx.getSystemInfo({
       success: (res) => {
         this.setData({
@@ -37,7 +36,7 @@ Page({
     var pt_student = wx.getStorageSync('pt_student')
     if (!pt_student) {
       var we_chat_user = wx.getStorageSync('we_chat_user')
-      if(we_chat_user) {
+      if (we_chat_user) {
         wx.redirectTo({
           url: '/pages/bind-phone/index',
         })
@@ -70,9 +69,9 @@ Page({
             this.setData({
               is_btn_disabled: !validLocation
             })
-            if(validLocation) {
+            if (validLocation) {
               var start_time = wx.getStorageSync('check_card_start_time')
-              if(start_time) {
+              if (start_time) {
                 this.setData({
                   startTime: start_time,
                   isLearning: true
@@ -91,33 +90,41 @@ Page({
       }
     })
 
-    wx.request({
-      url: api.getShareInfoUrl,
-      method: 'GET',
-      data: {
-        'student_id': pt_student.id
-      },
-      success: res => {
-        if (res.data.status == 'success') {
-          this.setData({
-            shareCanvasWidth: res.data.width,
-            shareCanvasHeight: res.data.height,
-            shareImage: res.data.shareImage,
-            shareText: res.data.shareText,
-            shareTextPosX: res.data.shareTextPosX,
-            shareTextPosY: res.data.shareTextPosY,
-          })
-          wx.downloadFile({
-            url: res.data.shareImage,
-            success: res => {
-              this.setData({
-                shareImage: res.tempFilePath
+    this.updateShareInfo();
+  },
+  updateShareInfo() {
+    var pt_student = wx.getStorageSync('pt_student')
+    if (!pt_student) {
+      wx.request({
+        url: api.getShareInfoUrl,
+        method: 'GET',
+        data: {
+          'student_id': pt_student.id
+        },
+        success: res => {
+          if (res.data.status == 'success') {
+            this.setData({
+              shareCanvasWidth: res.data.width,
+              shareCanvasHeight: res.data.height,
+              shareImage: res.data.shareImage,
+              shareText: res.data.shareText,
+              shareTextPosX: res.data.shareTextPosX,
+              shareTextPosY: res.data.shareTextPosY,
+            })
+            if (!this.data.shareImage) {
+              wx.downloadFile({
+                url: res.data.shareImage,
+                success: res => {
+                  this.setData({
+                    shareImage: res.tempFilePath
+                  })
+                }
               })
             }
-          })
+          }
         }
-      }
-    })
+      })
+    }
   },
   validLocation(latitude, longitude) {
     let res = api.isTest ? true : false;
@@ -129,7 +136,7 @@ Page({
         longitude: longitude
       },
       success: res => {
-        if(res.data.status == 'success' && res.data.result == 'ok') {
+        if (res.data.status == 'success' && res.data.result == 'ok') {
           res = true;
         }
       }
@@ -249,7 +256,7 @@ Page({
       let sec = Math.ceil(diff / SEC)
       sec = (sec < 10 ? '0' + sec : sec)
 
-      
+
       this.setData({
         clock: "" + hours + ":" + mins + ":" + sec
       })
@@ -262,30 +269,41 @@ Page({
       isLearning: false,
       showPopup: true
     })
-    wx.setStorageSync('check_card_start_time', '')
-    const ctx = wx.createCanvasContext('shareCanvas')
-    let width = this.data.shareCanvasWidth
-    let height = this.data.shareCanvasHeight
-    let image = this.data.shareImage
-    let text = this.data.shareText
-    let text_x = this.data.shareTextPosX
-    let text_y = this.data.shareTextPosY
-    // ctx.fillStyle = "#fff"
-    // ctx.fillRect(0, 0, width, height)
-    ctx.drawImage(image)
-    ctx.fillStyle = "#fff"
-    ctx.setFontSize(18)
-    ctx.textAlign = 'center'
-    // ctx.fillText('我已成功打卡14天', width / 2, height / 2 - 7)
-    ctx.fillText(text, text_x, text_y)
-    ctx.draw(false, this.getTempFilePath)
+    var pt_student = wx.getStorageSync('pt_student')
+    if(!pt_student) {
+      wx.request({
+        url: api.getShareTextUrl,
+        method: 'GET',
+        success: res => {
+          if (res.data.status == 'success') {
+            wx.setStorageSync('check_card_start_time', '')
+            const ctx = wx.createCanvasContext('shareCanvas')
+            let width = this.data.shareCanvasWidth
+            let height = this.data.shareCanvasHeight
+            let image = this.data.shareImage
+            let text = res.data.shareText
+            let text_x = this.data.shareTextPosX
+            let text_y = this.data.shareTextPosY
+            // ctx.fillStyle = "#fff"
+            // ctx.fillRect(0, 0, width, height)
+            ctx.drawImage(image)
+            ctx.fillStyle = "#fff"
+            ctx.setFontSize(18)
+            ctx.textAlign = 'center'
+            // ctx.fillText('我已成功打卡14天', width / 2, height / 2 - 7)
+            ctx.fillText(text, text_x, text_y)
+            ctx.draw(false, this.getTempFilePath)
+          }
+        }
+      })
+    }
   },
   togglePopup() {
     this.setData({
       showPopup: !this.data.showPopup
     });
   },
-  getTempFilePath: function () {
+  getTempFilePath: function() {
     wx.canvasToTempFilePath({
       canvasId: 'shareCanvas',
       success: (res) => {
@@ -331,14 +349,13 @@ Page({
       }
     })
   },
-  onShareAppMessage: function (t) {
+  onShareAppMessage: function(t) {
     var a = this;
     return {
       path: "/pages/index/index",
-      success: function (t) {
-      },
+      success: function(t) {},
       title: "钢琴时间打卡"
     };
   },
-  
-})
+
+})

+ 1 - 1
wechat/project.config.json

xqd
@@ -8,7 +8,7 @@
 		"newFeature": true
 	},
 	"compileType": "miniprogram",
-	"libVersion": "2.1.1",
+	"libVersion": "2.2.0",
 	"appid": "wx8350ebbd5f8943ae",
 	"projectname": "PianoTime",
 	"condition": {

+ 1 - 0
wechat/utils/api.js

xqd
@@ -21,4 +21,5 @@ module.exports = {
   getFormSetUrl: headUrl + 'getFormSet',
   submitFormUrl: headUrl + 'submitForm',
   applyLeaveUrl: headUrl + 'applyLeave',
+  getShareTextUrl: headUrl + 'getShareText',
 }