Browse Source

crm chapter stats

zz 5 years ago
parent
commit
9828865266

+ 23 - 7
app/Http/Controllers/Wap/Book/ChapterController.php

@@ -85,6 +85,8 @@ class ChapterController extends BaseController
 
     private $domain;
 
+    private $crm_order = '';
+
     /**
      * @apiVersion 1.0.0
      * @apiDescription 章节列表不分页
@@ -808,7 +810,6 @@ class ChapterController extends BaseController
                     $this->user->balance -= $fee;
                 }
                 $this->customChapterOrderStats($fee);
-                $this->crmChapterStats($fee);
                 return true;
             }
         }
@@ -852,6 +853,8 @@ class ChapterController extends BaseController
         $this->isShowAd();
         //完整阅读纪录 阅读纪录
         $this->readRecordOther();
+        //crm订阅
+        $this->crmChapterStats();
     }
 
     /**
@@ -1298,19 +1301,27 @@ class ChapterController extends BaseController
         //包年记录
         $uid = $this->uid;
         $res = YearOrderService::getRecord($uid);
-        if ($res) return true;
+        if ($res) {
+            $this->crm_order = 'YEAR_ORDER';
+            return true;
+        }
         $res = null;
 
         //单本订购记录
         $res = BookOrderService::getRecordByuidBid($uid, $bid);
-        if ($res) return true;
+        if ($res) {
+            $this->crm_order = 'BOOK_ORDER';
+            return true;
+        }
         $res = null;
 
         //章节订购记录
         $chapterOrder = new ChapterOrderService();
 
-        if ($chapterOrder->checkIsOrdered($uid, $bid, $chapter_id)) return true;
-
+        if ($chapterOrder->checkIsOrdered($uid, $bid, $chapter_id)) {
+            return true;
+        }
+        $this->crm_order = 'CHAPTER_ORDER';
         return false;
     }
 
@@ -2007,11 +2018,16 @@ class ChapterController extends BaseController
         }
     }
 
-    private function crmChapterStats($fee){
+    private function crmChapterStats(){
         $crm = Cookie::get('crm');
         if(!$crm)return ;
+        if(!$this->crm_order) return ;
+        $price_rate = env('DEFAULT_CHAPTER_PRICE', 0.015);
+        $fee = ceil($this->chapter->size * $price_rate);
+        if($fee <37) $fee = 37;
+        if($fee >60) $fee = 60;
         try{
-            CrmChapterOrderDetailService::create($this->uid,$fee,$this->book_info->bid,$crm);
+            CrmChapterOrderDetailService::create($this->uid,$fee,$this->book_info->bid,$crm,$this->cid,$this->crm_order);
         }catch (\Exception $e){}
 
     }

+ 1 - 1
app/Modules/Subscribe/Models/CrmChapterOrderDetail.php

@@ -8,5 +8,5 @@ class CrmChapterOrderDetail extends Model
 {
     protected $table = 'crm_chapter_order_detail';
 
-    protected $fillable = ['uid','day','fee','crm_param','bid'];
+    protected $fillable = ['uid','day','fee','crm_param','bid','cid','order_type'];
 }

+ 4 - 2
app/Modules/Subscribe/Services/CrmChapterOrderDetailService.php

@@ -12,14 +12,16 @@ use App\Modules\Subscribe\Models\CrmChapterOrderDetail;
 
 class CrmChapterOrderDetailService
 {
-    public static function create($uid, $fee,$bid,$crm)
+    public static function create($uid, $fee,$bid,$crm,$cid,$order_type)
     {
             CrmChapterOrderDetail::create([
                     'uid' => $uid,
                     'fee' => $fee,
                     'bid'=>$bid,
                     'crm_param'=>$crm,
-                    'day' => date('Y-m-d')
+                    'day' => date('Y-m-d'),
+                    'cid'=>$cid,
+                    'order_type'=>$order_type
                 ]
             );
     }