fly 5 年之前
父节点
当前提交
42c569d13b

+ 62 - 0
app/Client/AnnuallyMonthlyUser.php

@@ -0,0 +1,62 @@
+<?php
+
+namespace App\Client;
+
+use App\Consts\SysConsts;
+use App\Modules\Subscribe\Models\Order;
+use App\Modules\User\Models\UserMonthOrder;
+
+trait AnnuallyMonthlyUser
+{
+    protected $is_monthly;
+    protected $is_annually;
+    private $uid;
+
+    public function __construct(int $uid = 0)
+    {
+        if ($uid) {
+            $this->uid = $uid;
+        } else {
+            $user = app()->make('user');
+            $this->uid = $user->id;
+        }
+    }
+
+    public function __get($property_name)
+    {
+        if (isset($this->$property_name)) {
+            return $this->$property_name;
+        } else {
+            if ($property_name == "is_annually") {
+                $this->setAnnuallyUser();
+                return $this->is_annually;
+            } else if ($property_name == "is_monthly") {
+                $this->setMonthlyUser();
+                return $this->is_monthly;
+            }
+        }
+    }
+
+    /**
+     * 设置用户包年包月属性
+     */
+    private function setAnnuallyUser()
+    {
+        $year_order = Order::where('uid', $this->uid)->where('status', 'PAID')->where('order_type', 'YEAR')->orderBy('id', 'desc')->first();
+        if ($year_order && strtotime($year_order->created_at) > (time() - SysConsts::ONE_YEAR_DAYS * SysConsts::ONE_DAY_SECONDS)) {
+            $this->is_annually = true;
+        } else {
+            $this->is_annually = false;
+        }
+    }
+
+    private function setMonthlyUser()
+    {
+        $month_order = UserMonthOrder::where('uid', $this->uid)->where('type', 'MONTH')->orderBy('id', 'desc')->first();
+        if ($month_order && strtotime($month_order->created_at) > (time() - SysConsts::ONE_YEAR_DAYS * SysConsts::ONE_DAY_SECONDS)) {
+            $this->is_monthly = true;
+        } else {
+            $this->is_monthly = false;
+        }
+    }
+}

+ 4 - 0
app/Consts/SysConsts.php

@@ -16,4 +16,8 @@ class SysConsts
      * 一周:86400 * 7s
      */
     const ONE_WEEK_SECONDS = 86400 * 7;
+    /**
+     * 一年365;
+     */
+    const ONE_YEAR_DAYS = 365;
 }

+ 5 - 2
app/Http/Controllers/Wap/User/CrmBooklistController.php

@@ -2,6 +2,7 @@
 
 namespace App\Http\Controllers\Wap\User;
 
+use App\Client\AnnuallyMonthlyUser;
 use App\Client\SiteUser;
 use Illuminate\Http\Request;
 use App\Http\Controllers\Controller;
@@ -9,7 +10,7 @@ use App\Modules\Book\Services\CrmBookAutoRecommendService;
 use Hashids;
 
 class CrmBooklistController extends Controller
-{
+{    
     public function index(Request $request)
     {
         $month = date('n');
@@ -37,7 +38,9 @@ class CrmBooklistController extends Controller
                 })->take(4)->all();
                 return compact('category_id', 'category_name', 'books');
             })->all();
-        return view('crm.bookshow')->with(compact('book_models'));
+        $annually_monthly_user = new AnnuallyMonthlyUser();
+        $is_annually_monthly_user = $annually_monthly_user->is_monthly || $annually_monthly_user->is_annually;
+        return view('crm.bookshow')->with(compact('book_models','is_annually_monthly_user'));
     }
 
     public function booklist(Request $request)

+ 5 - 0
resources/views/crm/bookshow.blade.php

@@ -50,8 +50,13 @@
             </div>
             <div class="book-read">
               <a href="{{$book_model['books'][0]['link']}}">
+                @if ($is_annually_monthly_user)
                 <img src="https://cdn-novel.iycdm.com/h5/crm_booklist/images/free-read-btn.png" alt=""
                   class="to-read" />
+                @else
+                <img src="https://cdn-novel.iycdm.com/h5/crm_booklist/images/continue-read.png" alt=""
+                  class="to-read" />
+                @endif
               </a>
               <a href="{{url('/crm/booklist?category_id='.$book_model['category_id'])}}">查看更多&gt;</a>
             </div>