Browse Source

function process

shawn 9 years ago
parent
commit
9cb89c1156
3 changed files with 20 additions and 15 deletions
  1. 19 13
      app/Http/Controllers/VoteController.php
  2. 1 1
      config/app.php
  3. 0 1
      resources/views/front/vote/group.blade.php

+ 19 - 13
app/Http/Controllers/VoteController.php

xqd
@@ -61,22 +61,28 @@ class VoteController extends Controller
         $we_user = session('wechat.oauth_user'); // 拿到授权用户资料
         $user = $this->wechat->user->get($we_user->getId());
         //dd($user);
-        //$res = Vote::where('openid', $user->openid)->where('created_at', 'like', '%'.date('Y-m-d', time()).'%');
-        $res = Vote::where('openid', 'aaaaaa')->where('created_at', 'like', '%'.date('Y-m-d', time()).'%');
-        dd($res);
-        /*if($user->subscribe != 1) {
-            echo json_encode(['status'=>'2']);
-            return;
-        }elseif() {
-
-        }elseif() {
-
-        }*/
+        $today_count = Vote::where('openid', $user->openid)->where('created_at', 'like', '%'.date('Y-m-d', time()).'%')
+            ->count();
 
         // status=1 : 投票成功
         // status=0 : 今日机会用完
         // status=2 : 未关注公众号
-        //echo json_encode(['status'=>'1']);
-        echo json_encode(['status'=>'0']);
+        if($user->subscribe != 1) {
+            echo json_encode(['status'=>'2']);
+            return;
+        }elseif($today_count >= 3) {
+            echo json_encode(['status'=>'0']);
+            return;
+        }else {
+            $flight = new Vote;
+            $flight->player_id = $player_id;
+            $flight->openid = $user->openid;
+            $flight->we_nickname = $user->nickname;
+            $flight->we_image = $user->headimgurl;
+            $flight->we_image = $user->headimgurl;
+            $flight->save();
+            echo json_encode(['status'=>'1']);
+        }
+
     }
 }

+ 1 - 1
config/app.php

xqd
@@ -64,7 +64,7 @@ return [
     |
     */
 
-    'timezone' => 'UTC',
+    'timezone' => 'PRC',
 
     /*
     |--------------------------------------------------------------------------

+ 0 - 1
resources/views/front/vote/group.blade.php

xqd
@@ -167,7 +167,6 @@
 </script>
 <script type="text/javascript">
 function vote(player_id){
-    window.location('http://test.shawns.me/vote/process/'+player_id);
     $.ajax({
         url:'http://test.shawns.me/vote/process/'+player_id,
         type:'get',