Kaynağa Gözat

Merge branch 'jeffry' of ssh://git.9026.com:2212/Silent/PianoTime

Mike 6 yıl önce
ebeveyn
işleme
644415dda8

+ 4 - 1
app/Console/Kernel.php

xqd xqd xqd
@@ -6,6 +6,7 @@ use App\Models\CheckCard;
 use Carbon\Carbon;
 use Illuminate\Console\Scheduling\Schedule;
 use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
+use Illuminate\Support\Facades\Log;
 
 class Kernel extends ConsoleKernel
 {
@@ -32,6 +33,8 @@ class Kernel extends ConsoleKernel
             $begin = Carbon::today()->toDateTimeString();
             $end = Carbon::tomorrow()->toDateTimeString();
 
+            Log::info('定时器已经执行');
+
             $items = CheckCard::where([
                 ['begin_date_time', '>=', $begin],
                 ['begin_date_time', '<', $end],
@@ -41,7 +44,7 @@ class Kernel extends ConsoleKernel
                 $item->end_date_time = Carbon::createFromTimestamp(strtotime($item->begin_date_time))->addHours(2)->toDateTimeString();
                 $item->save();
             }
-        })->dailyAt('23:50');
+        })->dailyAt('21:00');
     }
 
     /**

+ 3 - 3
app/Http/Controllers/Admin/SettingController.php

xqd xqd
@@ -68,10 +68,11 @@ class SettingController extends Controller
     {
         $check_card_location = $this->model->firstOrCreate(['key' => 'check_card_location'], ['value' => '39.916527,116.397128']);
         $check_card_radius = $this->model->firstOrCreate(['key' => 'check_card_radius'], ['value' => '1000']);
+        $check_position = $this->model->firstOrCreate(['key' => 'check_position'], ['value' => '1']);
 
         list($pre_uri, $model, $model_name) = array($this->pre_uri, $this->model, $this->model_name);
 
-        return view($this->view_path . 'system', compact('pre_uri', 'model', 'model_name', 'check_card_location', 'check_card_radius'));
+        return view($this->view_path . 'system', compact('pre_uri', 'model', 'model_name', 'check_card_location', 'check_card_radius', 'check_position'));
     }
 
     public function updateSystem(Request $request)
@@ -79,8 +80,7 @@ class SettingController extends Controller
         if(!$request->isMethod('POST')) {
             return $this->showWarning('访问错误');
         }
-
-        $items = collect(['check_card_location', 'check_card_radius']);
+        $items = collect(['check_card_location', 'check_card_radius', 'check_position']);
 
         foreach($items as $item) {
             if(!empty($request->input($item))) {

+ 2 - 2
app/Http/Controllers/TestController.php

xqd
@@ -15,7 +15,7 @@ class TestController extends Controller
 {
     public function index(Request $request)
     {
-        $text = 'aa:';
-        dd(explode(':', $text));
+        $student = Student::find(7);
+        dd($student->save());
     }
 }

+ 33 - 2
app/Http/Controllers/WeChat/ApiController.php

xqd xqd xqd xqd xqd
@@ -213,6 +213,10 @@ class ApiController extends Controller
                 $result = 'ok';
             }
         }
+        $check_position = Setting::where('key', 'check_position')->first();
+        if(!empty($check_position) && $check_position->value == 2) {
+            $result = 'ok';
+        }
         $now = Carbon::today()->toDateTimeString();
         $checkCard = CheckCard::where([
             ['begin_date_time', '>', $now]
@@ -251,7 +255,10 @@ class ApiController extends Controller
             return response()->json(['status' => 'fail', 'info' => '找不到打卡记录']);
         }
 
-        $item->end_date_time = Carbon::now()->toDateTimeString();
+        if(empty($item->end_date_time)) {
+            $item->end_date_time = Carbon::now()->toDateTimeString();
+        }
+
         if(!$item->save()) {
             return response()->json(['status' => 'fail', 'info' => '打卡失败']);
         }
@@ -285,6 +292,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);
@@ -352,7 +374,7 @@ class ApiController extends Controller
 
         $student_course->course_name = $student_course->course->name;
         $student_course->teacher_names = $student_course->getTeacherNames();
-        $student_course->end_date = Carbon::createFromTimestamp(strtotime($student_course->apply_date))->addDays($student_course->duration)->toDateString();
+        $student_course->end_date = $student_course->computeEndDate();
         $student_course->short_leave_times = $student->short_leave_times;
         $student_course->long_leave_times = $student->long_leave_times;
 
@@ -721,4 +743,13 @@ class ApiController extends Controller
 
         return $response;
     }
+
+    public function checkCardIsEnd(Request $request)
+    {
+        if(empty($request->input('check_card_id')) || empty($check_card = CheckCard::find($request->input('check_card_id')))) {
+            return response()->json(['status' => 'success', 'result' => 'yes']);
+        }
+        $result = empty($check_card->end_date_time) ? 'no' : 'yes';
+        return response()->json(['status' => 'success', 'result' => $result]);
+    }
 }

+ 1 - 1
app/Models/CheckCard.php

xqd
@@ -38,7 +38,7 @@ class CheckCard extends Model
                 if(!empty($tmp)) {
                     $res .= $tmp . '小时';
                 }
-                $tmp = floor($diff_time / 3600);
+                $tmp = floor($diff_time / 60);
                 $diff_time = $diff_time % 60;
                 if(!empty($tmp)) {
                     $res .= $tmp . '分钟';

+ 1 - 1
app/Models/Student.php

xqd
@@ -174,7 +174,7 @@ class Student extends Model
         if(!empty($tmp)) {
             $res .= $tmp . '小时';
         }
-        $tmp = floor($diff_time / 3600);
+        $tmp = floor($diff_time / 60);
         $diff_time = $diff_time % 60;
         if(!empty($tmp)) {
             $res .= $tmp . '分钟';

+ 12 - 0
resources/views/admin/settings/system.blade.php

xqd
@@ -37,6 +37,18 @@
                                 </div>
                             </div>
 
+                            <div class="form-group row">
+                                <label class="col-sm-2 col-sm-offset-1 control-label">位置验证</label>
+                                <div class="col-sm-8">
+                                    <label class="radio-inline">
+                                        <input type="radio" name="check_position" value="1" {{ $check_position->value == 1 ? 'checked' : '' }}>是
+                                    </label>
+                                    <label class="radio-inline">
+                                        <input type="radio" name="check_position" value="2" {{ $check_position->value != 1 ? 'checked' : '' }}>否
+                                    </label>
+                                </div>
+                            </div>
+
                             <div class="form-group row">
                                 <div class="col-sm-8 col-sm-offset-3">
                                     <button type="submit" class="btn btn-sm btn-primary">保存设置</button>

+ 3 - 1
routes/wechat.php

xqd
@@ -20,4 +20,6 @@ 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');
+Route::get('checkCardIsEnd', 'ApiController@checkCardIsEnd');

+ 66 - 42
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,14 +69,26 @@ Page({
             this.setData({
               is_btn_disabled: !validLocation
             })
-            if(validLocation) {
+            if (validLocation) {
               var start_time = wx.getStorageSync('check_card_start_time')
-              if(start_time) {
-                this.setData({
-                  startTime: start_time,
-                  isLearning: true
+              var check_card_id = wx.getStorageSync('check_card_id')
+              if (start_time && check_card_id) {
+                wx.request({
+                  url: api.checkCardIsEndUrl,
+                  method: 'GET',
+                  data: {
+                    check_card_id: check_card_id
+                  },
+                  success: res => {
+                    if (res.data.status == 'success' && res.data.result == 'no') {
+                      this.setData({
+                        startTime: start_time,
+                        isLearning: true
+                      })
+                      this.startClock()
+                    }
+                  }
                 })
-                this.startClock()
               }
             }
           },
@@ -87,7 +98,6 @@ Page({
           currentLongitude: res.longitude,
           accuracy: res.accuracy
         })
-
       }
     })
 
@@ -129,7 +139,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 +259,7 @@ Page({
       let sec = Math.ceil(diff / SEC)
       sec = (sec < 10 ? '0' + sec : sec)
 
-      
+
       this.setData({
         clock: "" + hours + ":" + mins + ":" + sec
       })
@@ -262,30 +272,45 @@ 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',
+        data: {
+          'student_id': app.globalData.ptStudent.id
+        },
+        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
+            console.log(image)
+            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 +356,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": {

+ 2 - 0
wechat/utils/api.js

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