Pārlūkot izejas kodu

qapp user send order id

zz 4 gadi atpakaļ
vecāks
revīzija
2f78aab5e2

+ 3 - 1
app/Http/Controllers/QuickApp/BaseController.php

@@ -4,6 +4,7 @@ namespace App\Http\Controllers\QuickApp;
 
 use App\Modules\User\Models\User;
 use App\Modules\User\Services\QappUserService;
+use App\Modules\User\Services\ReadRecordService;
 use Illuminate\Routing\Controller;
 
 /**
@@ -39,7 +40,8 @@ class BaseController extends Controller
                 $this->field[$name] = $qapp_user->user->distribution_channel_id;
             }
             if ($name == 'send_order_id') {
-                $this->field[$name] = $qapp_user->send_order_id;
+                //$this->field[$name] = $qapp_user->send_order_id;
+                $this->field[$name] = ReadRecordService::getSendOrderId($qapp_user->uid);
             }
             if ($name == 'app_pay_merchat_id') {
                 $this->field[$name] = $qapp_user->app_pay_merchat_id;

+ 3 - 0
app/Http/Middleware/QuickAppGetUserFromToken.php

@@ -4,6 +4,7 @@ namespace App\Http\Middleware;
 
 use App\Cache\Push\PushCache;
 use App\Modules\Push\Services\PushService;
+use App\Modules\SendOrder\Services\SendOrderService;
 use App\Modules\User\Services\QappUserService;
 use App\Modules\User\Services\UserService;
 use Closure;
@@ -39,8 +40,10 @@ class QuickAppGetUserFromToken extends BaseMiddleware
             $user = $this->auth->authenticate($token);
             if ($sendOrderId) {
                 UserService::setUserSendOrder($user->id, $sendOrderId);
+                SendOrderService::recordUserSendOrder($user->id,$sendOrderId);
             }
 
+
             // 设置全局信息
             (new QappUserService)->setGolableUser($user->id, $package);
         } catch (TokenExpiredException $e) {

+ 12 - 16
app/Modules/Channel/Models/Channel.php

@@ -68,17 +68,17 @@ class Channel extends Model
         return '';
     }
     
-    /**
-     * 获取渠道公司等信息
-     */
-    static function get_distribution_channel_info($distribution_channel_id)
-    {
-    	$info = self::select('channel_users.company_name','channel_users.person_in_charge_name')
-    	->join('channel_users','channel_users.id','=','distribution_channels.channel_user_id')
-    	->where('distribution_channels.id',$distribution_channel_id)
+    /**
+     * 获取渠道公司等信息
+     */
+    static function get_distribution_channel_info($distribution_channel_id)
+    {
+    	$info = self::select('channel_users.company_name','channel_users.person_in_charge_name')
+    	->join('channel_users','channel_users.id','=','distribution_channels.channel_user_id')
+    	->where('distribution_channels.id',$distribution_channel_id)
     	->first();
- 
-    	return $info;
+ 
+    	return $info;
     }
 
     static function getChanneIdByCompanyId($companyId)
@@ -120,11 +120,7 @@ class Channel extends Model
         return self::create(compact('phone', 'password', 'name', 'pay_type', 'nickname', 'latest_login_ip', 'latest_login_time', 'remark', 'register_ip', 'distribution_manages_id', 'person_in_charge_name', 'channel_user_id'));
     }
 
-    //修改密码
-    static function modifyPassword($phone, $password)
-    {
-        return self::where('phone', $phone)->update(compact('password'));
-    }
+
 
     /**
      * 获取渠道列表
@@ -307,7 +303,7 @@ class Channel extends Model
     }
     
     static function deleteChannel($distribution_channel_id, $channel_user_id){
-    	return self::where('channel_user_id', $channel_user_id)->where('id', $distribution_channel_id)->update(['is_enabled'=>0,'updated_at'=>now()]);
+    	return self::where('channel_user_id', $channel_user_id)->where('id', $distribution_channel_id)->update(['is_enabled'=>0,'updated_at'=>now()]);
     }
     
     /**

+ 0 - 6
app/Modules/Channel/Models/ChannelUser.php

@@ -34,12 +34,6 @@ class ChannelUser extends Model
         return self::firstOrCreate(compact('phone'), compact('password', 'name', 'pay_type', 'nickname', 'latest_login_ip', 'latest_login_time', 'remark', 'register_ip', 'distribution_manages_id', 'person_in_charge_name'));
     }
 
-    //修改密码
-    static function modifyPassword($phone, $password)
-    {
-        return self::where('phone', $phone)->update(compact('password'));
-    }
-
     //手机号码、密码获取
     static function login($phone, $password)
     {

+ 0 - 33
app/Modules/Channel/Services/ChannelService.php

@@ -160,41 +160,8 @@ class ChannelService
         return Channel::createChannel($params);
     }
 
-    /**
-     * 获取渠道统计数据
-     */
-    static function getChannelData()
-    {
-        //获取所有的渠道
-        $channels = Channel::getAllChannels();
-        //获取所有渠道账户余额总额(可提现金额总额)
-        $avaliableBalanceAll = FinanceService::getChannelAccountBalanceAll();
-        //所有充值总则
-//        $chargeAllAmount = TradeSevices::getChannelPriceCountAll();
-        if (empty($channels)) {
-            foreach ($channels as $channelItem) {
-                $channelId = $channelItem->id;
-                //获取渠道下的账户余额
-                $channelAvaliableBalance = FinanceService::getChannelAccountBalance($channelId);
-                //获取渠道下的充值总额
-//                $channelChargeAllAmount = Trade::getChannelPriceCountSingle($channelId);
-                //获取渠道下的总派单数
-                $sendOrderCount = SendOrderService::getPromotionCountByChannelId($channelId);
-            }
-        }
-    }
 
 
-    /**
-     * 修改渠道密码
-     * @param  string $phone 手机号码
-     * @param  string $password 加密后密码
-     * @return boolen
-     */
-    static function modifyPassword($phone, $password)
-    {
-        return Channel::modifyPassword($phone, $password);
-    }
 
     /**
      * 获取渠道列表

+ 1 - 9
app/Modules/Channel/Services/ChannelUserService.php

@@ -32,15 +32,7 @@ class ChannelUserService
         return ChannelUser::login($phone, $password);
     }
 
-    /**
-     * 修改密码
-     * @param  string $phone 手机号码
-     * @param  string $password 加密后密码
-     */
-    static function modifyPassword($phone, $password)
-    {
-        return ChannelUser::modifyPassword($phone, $password);
-    }
+
 
     /**
      * 判断是否注册

+ 5 - 10
app/Modules/CpUser/Models/CpUser.php

@@ -16,16 +16,11 @@ class CpUser extends Model
         return self::where(['username'=>$username])->first();
     }
     
-    /**
+    /**
      * 获取用户by id
-     */
-    public static function getCpUserById($id) {
-    	return self::where(['id'=>$id])->first();
-    }
-    
-    //修改密码
-    static function modifyPassword($username, $password)
-    {
-        return self::where('username', $username)->update(compact('password'));
+     */
+    public static function getCpUserById($id) {
+    	return self::where(['id'=>$id])->first();
     }
+
 }

+ 1 - 10
app/Modules/CpUser/Services/CpUserService.php

@@ -23,16 +23,7 @@ class CpUserService
     	return CpUser::getCpUserById($id);
     }
     
-    /**
-     * 修改Cp密码
-     * @param  string $username   用户名
-     * @param  string $password 加密后密码
-     * @return boolen
-     */
-    static function modifyPassword($username, $password)
-    {
-    	return CpUser::modifyPassword($username, $password);
-    }
+
 
 
     static function createCp($username){

+ 8 - 12
app/Modules/Manage/Models/Manage.php

@@ -19,18 +19,18 @@ class Manage extends Model
     	return self::where('account', $account)->first();
     }
     
-    static function getAll($is_all=1)
+    static function getAll($is_all=1)
     {
     	if($is_all){
-    		return self::orderBy('is_enabled', 'desc')->orderBy('id', 'desc')->paginate();
+    		return self::orderBy('is_enabled', 'desc')->orderBy('id', 'desc')->paginate();
     	}else{
-    		return self::where('is_enabled', 1)->orderBy('id', 'desc')->paginate();
-    	}
+    		return self::where('is_enabled', 1)->orderBy('id', 'desc')->paginate();
+    	}
     }
 
-    static function add($params)
-    {
-    	return self::firstOrCreate($params);
+    static function add($params)
+    {
+    	return self::firstOrCreate($params);
     }
     
     static function getById($id)
@@ -55,11 +55,7 @@ class Manage extends Model
         return self::firstOrCreate(compact('account'),compact('password','role','nickname','latest_login_ip','latest_login_time','remark','register_ip'));
     }
 
-    //修改密码
-    static function modifyPassword($account, $password)
-    {
-        return self::where('account', $account)->update(compact('password'));
-    }
+
 
     //根据商务编号获取商务用户信息
     static function getBusinesserByNumber($number)

+ 1 - 10
app/Modules/Manage/Services/ManageService.php

@@ -29,16 +29,7 @@ class ManageService
         return Manage::getById($id);
     }
 
-    /**
-     * 修改渠道密码
-     * @param  string $phone    手机号码
-     * @param  string $password 加密后密码
-     * @return boolen           
-     */
-    static function modifyPassword($phone, $password)
-    {
-        return Manage::modifyPassword($phone, $password);
-    }
+
 
     static  function getBusinesserByNumber($number)
     {

+ 20 - 0
app/Modules/SendOrder/Models/QappUserSendOrderId.php

@@ -0,0 +1,20 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: z-yang
+ * Date: 2020/12/16
+ * Time: 11:23
+ */
+
+namespace App\Modules\SendOrder\Models;
+
+use Illuminate\Database\Eloquent\Model;
+
+class QappUserSendOrderId extends Model
+{
+    protected $table = 'qapp_user_send_order_id';
+    protected $fillable = [
+        'uid',
+        'send_order_id'
+    ];
+}

+ 0 - 494
app/Modules/SendOrder/Models/SendOrder.php

@@ -47,498 +47,4 @@ class SendOrder extends Model
         'force_show_qrcode'
     ];
 
-    /**
-     * 通过bid获取该书的推广次数
-     * @param $bid 书本id
-     * @param $channelId 渠道id
-     */
-    static function getPromotionCountByBid($bid, $channelId)
-    {
-        return self::where('book_id', $bid)->where('distribution_channel_id', $channelId)->count();
-    }
-
-    /**
-     * 通过bid获取该书的推广次数
-     * @param $bid 书本id
-     * @param $channelId 渠道id
-     */
-    static function getDuringPromotionCountByBid($bid, $begin_time, $end_time)
-    {
-        $search_obj = self::orderBy('id', 'desc')->where('is_enable', 1);
-        if ($bid) {
-            $search_obj->where('book_id', $bid);
-        }
-
-        if ($begin_time) {
-            $search_obj->where('send_time', '>=', $begin_time);
-        }
-
-        if ($end_time) {
-            $search_obj->where('send_time', '<=', $end_time);
-        }
-        return $search_obj->count();
-    }
-
-    /**
-     * 获取渠道下某时间段内推广次数
-     * @param $channelId 渠道id
-     * @param $begin_time 开始日期
-     * @param $end_time 结束日期
-     */
-    static function getChannelPromotionCount($channelId, $begin_time, $end_time)
-    {
-        return self::where('created_at', '>=', $begin_time)->where('created_at', '<=', $end_time)->where('distribution_channel_id', $channelId)->count();
-    }
-
-    /**
-     * 获取渠道下某时间段内实际推广次数
-     * @param $channelId 渠道id
-     * @param $begin_time 开始日期
-     * @param $end_time 结束日期
-     */
-    static function getChannelRealPromotionCount($channelId, $begin_time, $end_time)
-    {
-        return self::where('send_time', '>=', $begin_time)->where('send_time', '<=', $end_time)->where('distribution_channel_id', $channelId)->count();
-    }
-
-    /**
-     * 获取实际推广次数
-     * @param $params
-     */
-    static function getRealPromotionCount($params)
-    {
-        $search_obj = self::orderBy('id', 'desc');
-        if (isset($params['begin_time'])) $search_obj->where('send_time', '>=', $params['begin_time']);
-        if (isset($params['end_time'])) $search_obj->where('send_time', '<=', $params['end_time']);
-        if (isset($params['distribution_channel_id'])) $search_obj->where('distribution_channel_id', $params['distribution_channel_id']);
-        return $search_obj->count();
-    }
-
-    /**
-     * 获取推广次数
-     * @param $params
-     */
-    static function getPromotionCount($params)
-    {
-        $search_obj = self::orderBy('id', 'desc');
-        if (isset($params['begin_time'])) $search_obj->where('created_at', '>=', $params['begin_time']);
-        if (isset($params['end_time'])) $search_obj->where('created_at', '<=', $params['end_time']);
-        if (isset($params['distribution_channel_id'])) $search_obj->where('distribution_channel_id', $params['distribution_channel_id']);
-        if (isset($params['channels'])) $search_obj->whereIn('distribution_channel_id', $params['channels']);
-        if (isset($params['book_id'])) $search_obj->where('book_id', $params['book_id']);
-        return $search_obj->count();
-    }
-
-    /**
-     * 通过渠道id获取该渠道的推广次数
-     * @param $channelId 渠道id
-     */
-    static function getPromotionCountByChannelId($channelId)
-    {
-        return self::where('distribution_channel_id', $channelId)->count();
-    }
-
-    /**
-     * 获取渠道id下所有的推广次数
-     * @param $channelId 渠道id
-     */
-    static function getTotalPromotionCountByChannelIds($channelIds)
-    {
-        return self::whereIn('distribution_channel_id', $channelIds)->count();
-    }
-
-
-    /**
-     * 通过区间内的渠道id获取该渠道的推广次数
-     * @param $channelId 渠道id
-     * @param $start_time 开始时间
-     * @param $end_time 结束时间
-     */
-    static function getDuraingPromotionCountByChannelId($distribution_channel_id, $start_time = '', $end_time = '')
-    {
-        $search_object = self::where('is_enable', 1);
-        if ($distribution_channel_id) {
-            $search_object->where('distribution_channel_id', $distribution_channel_id);
-        }
-        if ($start_time) {
-            $search_object->where('created_at', '>=', $start_time);
-        }
-        if ($end_time) {
-            $search_object->where('created_at', '<=', $end_time);
-        }
-
-        return $search_object->count();
-    }
-
-
-    /**
-     * 获取派单信息
-     * @param $bookId 推广书籍id
-     * @param $distribution_channel_id 推广渠道id
-     * @param $name 派单名称
-     * @param $bookName 书名
-     * @param $sendOrderId 派单id
-     * @param string $start_date 开始时间
-     * @param string $end_date 结束时间
-     * @param string $isAll 是否获取所有
-     * @return mixed
-     */
-    static function getSendOrders($bookId, $distribution_channel_id, $name = null, $bookName = null, $sendOrderId, $start_time = '', $end_time = '', $isAll = false)
-    {
-        $search_object = self::orderBy('created_at', 'desc');
-        if ($bookId) {
-            $search_object->where('book_id', $bookId);
-        }
-        if ($distribution_channel_id) {
-            $search_object->where('distribution_channel_id', $distribution_channel_id);
-        }
-        if ($bookName) {
-            $search_object->where('book_name', $bookName);
-        }
-        if ($sendOrderId) {
-            $search_object->where('id', $sendOrderId);
-        }
-        if ($name) {
-            $search_object->where('name', 'like', '%' . $name . '%');
-        }
-        if ($start_time) {
-            $search_object->where('created_at', '>=', $start_time);
-        }
-        if ($end_time) {
-            $search_object->where('created_at', '<=', $end_time . ' 23:59:59');
-        }
-
-        $search_object->where('is_enable', 1);
-        if ($isAll) {
-            return $search_object->get();
-        } else {
-            return $search_object->paginate();
-        }
-    }
-
-    /**
-     * 获取派单信息
-     * @param $bookId 推广书籍id
-     * @param $distribution_channel_id 推广渠道id
-     * @param $name 派单名称
-     * @param $bookName 书名
-     * @param $sendOrderId 派单id
-     * @param string $start_date 开始时间
-     * @param string $end_date 结束时间
-     * @param string $isAll 是否获取所有
-     * @return mixed
-     */
-    static function getManageSendOrders($params = [], $is_all = false)
-    {
-        $search_object = self::orderBy('send_orders.created_at', 'desc')->where('is_enable', 1)
-            ->join('books', 'books.id', '=', 'send_orders.book_id')
-            ->join('book_categories', 'book_categories.id', '=', 'books.category_id');
-
-        if (isset($params['id']) && $params['id']) $search_object->where('send_orders.id', $params['id']);
-        if (isset($params['book_id']) && $params['book_id']) $search_object->where('book_id', $params['book_id']);
-        if (isset($params['name']) && $params['name']) $search_object->where('name', 'like', '%' . $params['name'] . '%');
-        if (isset($params['book_name']) && $params['book_name']) $search_object->where('book_name', 'like', '%' . $params['book_name'] . '%');
-        if (isset($params['start_time']) && $params['start_time']) $search_object->where('send_orders.created_at', '>=', $params['start_time']);
-        if (isset($params['end_time']) && $params['end_time']) $search_object->where('send_orders.created_at', '<=', $params['end_time'] . ' 23:59:59');
-        if (isset($params['distribution_channel_id']) && $params['distribution_channel_id']) $search_object->where('send_orders.distribution_channel_id', $params['distribution_channel_id']);
-        if (isset($params['gender']) && $params['gender']) $search_object->where('book_categories.pid', '=', $params['gender']);
-        $search_object->select('send_orders.id', 'send_orders.name', 'send_orders.channel_type', 'send_orders.distribution_channel_id', 'send_orders.created_at', 'send_orders.updated_at', 'book_id', 'book_name', 'chapter_id', 'chapter_name', 'headline_id',
-            'body_template_id', 'document_cover_id', 'original_guide_id', 'subscribe_chapter_id', 'subscribe_chapter_name', 'qr_code_id',
-            'subscribe_chapter_seq', 'cost', 'sex_preference', 'is_enable', 'entrance', 'domain', 'redirect_url', 'send_time', 'charge_type', 'channel_name',
-
-            DB::raw('(select ifnull(count(*),0) from force_subscribe_users where send_order_id=send_orders.id and is_subscribed=1) as fansNum'),
-            DB::raw('(select ifnull(sum(price),0) from orders where send_order_id=send_orders.id and status="PAID" and pay_end_at BETWEEN send_orders.send_time and DATE_ADD(send_orders.send_time,interval 12 HOUR)) as half_day_charge_amount'),
-            DB::raw('(select ifnull(sum(price),0) from orders where send_order_id=send_orders.id and status="PAID" and pay_end_at BETWEEN send_orders.send_time and DATE_ADD(send_orders.send_time,interval 7 DAY)) as weekend_charge_amount'));
-
-        //判断内外部派单
-        /*  if (isset($params['order_status']) && $params['order_status']) {
-              if (1 == $params['order_status']) {
-  //                $search_object->whereExists('fansNum', '<', 20);
-                  $search_object->whereExists(function ($query) {
-                      $query->from('force_subscribe_users')
-                          ->whereRaw('send_order_id=send_orders.id and is_subscribed=1')->where(DB::raw('count(*)'), '<', 20);
-                  });
-              } elseif (2 == $params['order_status']) {
-  //                $search_object->having('fansNum', '>=', 20);
-                  $search_object->whereExists(function ($query) {
-                      $query->from('force_subscribe_users')
-                          ->whereRaw('send_order_id=send_orders.id and is_subscribed=1')->where(DB::raw('count(*)'), '>=', 20);
-                  });
-              }
-          }*/
-
-        if (isset($params['orderBy']) && $params['orderBy']) {
-            $orderByType = 'desc';
-            $orderColum = 'send_orders.created_at'; //排序的列
-            if (isset($params['orderByType']) && $params['orderByType']) {
-                if (2 == $params['orderByType']) {
-                    $orderByType = 'asc';
-                }
-            }
-            //12小时充值
-            if (1 == $params['orderBy']) {
-                $orderColum = 'half_day_charge_amount';
-                //7天充值充值
-            } elseif (2 == $params['orderBy']) {
-                $orderColum = 'weekend_charge_amount';
-                //充值总额
-            }
-            $search_object->orderBy($orderColum, $orderByType);
-        }
-
-        if ($is_all) {
-            return $search_object->get();
-        } else {
-            return $search_object->paginate();
-        }
-    }
-
-    /**
-     * 获取派单信息
-     * @param $bookId 推广书籍id
-     * @param $distribution_channel_id 推广渠道id
-     * @param $name 派单名称
-     * @param $bookName 书名
-     * @param $sendOrderId 派单id
-     * @param string $start_date 开始时间
-     * @param string $end_date 结束时间
-     * @param string $isAll 是否获取所有
-     * @return mixed
-     */
-    static function search($params, $isAll = false)
-    {
-        $search_object = self::where('is_enable', 1)->orderBy('id', 'desc');
-
-        if (isset($params['book_id']) && $params['book_id']) {
-            $search_object->where('send_orders.book_id', $params['book_id']);
-        }
-
-        if (isset($params['distribution_channel_id']) && $params['distribution_channel_id']) {
-            $search_object->where('send_orders.distribution_channel_id', $params['distribution_channel_id']);
-        }
-
-        if (isset($params['book_name']) && $params['book_name']) {
-            $book_ids = BookConfig::getIdByName($params['book_name']);
-            if ($book_ids) {
-                $bids = [];
-                foreach ($book_ids as $item) {
-                    $bids[] = $item->bid;
-                }
-                $search_object->whereIn('send_orders.book_id', $bids);
-            }
-        }
-
-        if (isset($params['import_company_name']) && $params['import_company_name']) {
-            $search_object->where('send_orders.import_company_name', 'like', '%' . $params['import_company_name'] . '%');
-        }
-
-        if (isset($params['name']) && $params['name']) {
-            $search_object->where('send_orders.name', 'like', '%' . $params['name'] . '%');
-        }
-
-        if (isset($params['start_time']) && $params['start_time']) {
-            $search_object->where('send_orders.created_at', '>=', $params['start_time']);
-        }
-
-        if (isset($params['end_time']) && $params['end_time']) {
-            $search_object->where('send_orders.created_at', '<=', $params['end_time']);
-        }
-
-        if (isset($params['send_time_start_time']) && $params['send_time_start_time']) {
-            $search_object->where('send_orders.send_time', '>=', $params['send_time_start_time']);
-        }
-
-        if (isset($params['send_time_end_time']) && $params['send_time_end_time']) {
-            $search_object->where('send_orders.send_time', '<=', $params['send_time_end_time']);
-        }
-
-        if (isset($params['pre_send_date_end']) && $params['pre_send_date_end']) {
-            $search_object->where('send_orders.pre_send_date', '<=', $params['pre_send_date_end']);
-        }
-
-        if (isset($params['pre_send_date_start']) && $params['pre_send_date_start']) {
-            $search_object->where('send_orders.pre_send_date', '>=', $params['pre_send_date_start']);
-        }
-
-        if (isset($params['start_send_time']) && $params['start_send_time']) {
-            $search_object->where('send_orders.send_time', '>=', $params['start_send_time']);
-        }
-
-        if (isset($params['end_send_time']) && $params['end_send_time']) {
-            $search_object->where('send_orders.send_time', '<=', $params['end_send_time']);
-        }
-
-        if (isset($params['promotion_type']) && $params['promotion_type']) {
-            $search_object->where('send_orders.promotion_type', $params['promotion_type']);
-        }
-
-        if (isset($params['id']) && $params['id']) {
-            $search_object->where('send_orders.id', $params['id']);
-        }
-
-        if (isset($params['promotion_point']) && $params['promotion_point']) {
-            $search_object->where('send_orders.promotion_point', $params['promotion_point']);
-        }
-//        \Log::info('my_sql:'.($search_object->toSql()));
-        if ($isAll) {
-            return $search_object->get();
-        } else {
-            return $search_object->paginate();
-        }
-    }
-
-    /**
-     *  更新派单的备注
-     * @param $id  派单id
-     * @param $distribution_channel_id 渠道id
-     * @param $remark 备注
-     * @return mixed
-     */
-    static function updateRemark($id, $distribution_channel_id, $remark)
-    {
-        return self::where('id', $id)->where('distribution_channel_id', $distribution_channel_id)->update(['remark' => $remark]);
-    }
-
-    /**
-     *  更新派单的星数
-     * @param $id  派单id
-     * @param $distribution_channel_id 渠道id
-     * @param $starNum 星数
-     * @return mixed
-     */
-    static function updateStarNum($id, $distribution_channel_id, $starNum)
-    {
-        return self::where('id', $id)->where('distribution_channel_id', $distribution_channel_id)->update(['star_num' => $starNum]);
-    }
-
-    /**
-     *  更新派单的星数、备注
-     * @param $id  派单id
-     * @param $distribution_channel_id 渠道id
-     * @param $starNum 星数
-     * @param $remark 备注
-     * @return mixed
-     */
-    static function updateStarNumAndRemark($id, $distribution_channel_id, $starNum, $remark)
-    {
-        return self::where('id', $id)->where('distribution_channel_id', $distribution_channel_id)->update(['star_num' => $starNum, 'remark' => $remark]);
-    }
-
-
-    /**
-     * 更新派单
-     * @param $id  派单id
-     * @param $distribution_channel_id 渠道id
-     * @param $name 派单名称
-     * @param $cost 成本
-     * @param $channel_type  派单渠道类型.(允许值: AUTHENTICATED, UNAUTHENTICATED)
-     * @param $promotion_type  派单类型.(允许值: INTERNAL, EXTERNAL)
-     * @return mixed
-     */
-    static function updateSendOrderInfo($id, $distribution_channel_id, $name, $pre_send_date, $channel_type, $cost, $promotion_type, $subscribe_chapter = [])
-    {
-        $object = self::where('id', $id)->where('distribution_channel_id', $distribution_channel_id);
-        $params = [];
-        if ($name) {
-            $params['name'] = $name;
-        }
-        if ($channel_type) {
-            $params['channel_type'] = $channel_type;
-        }
-        if ($cost) {
-            $params['cost'] = $cost;
-        }
-        if ($promotion_type) {
-            $params['promotion_type'] = $promotion_type;
-        }
-        if ($pre_send_date) {
-            $params['pre_send_date'] = $pre_send_date;
-        }
-        if ($subscribe_chapter) {
-            $params['subscribe_chapter_id'] = $subscribe_chapter['subscribe_chapter_id'];
-            $params['subscribe_chapter_seq'] = $subscribe_chapter['subscribe_chapter_seq'];
-            $params['subscribe_chapter_name'] = $subscribe_chapter['subscribe_chapter_name'];
-        }
-        return $object->update($params);
-    }
-
-    /**
-     * 创建推广派单(章节)
-     */
-    static function createFromChapter($data)
-    {
-        return self::create($data);
-    }
-
-    /**
-     * 创建推广派单(页面)
-     */
-    static function createFromPage($data)
-    {
-        return self::create($data);
-    }
-
-    /**
-     * 创建推广派单(目录)
-     */
-    static function createFromDirectory($data)
-    {
-        return self::create($data);
-    }
-
-    /**
-     * 删除派单
-     * @param $id 派单id
-     * @param $distribution_channel_id 渠道id
-     * @return
-     */
-    static function removeSendOrder($id, $distribution_channel_id)
-    {
-        return self::where('id', $id)->where('distribution_channel_id', $distribution_channel_id)->update(['is_enable' => 0]);
-    }
-
-    /**
-     * 设置成本
-     * @param $id  派单id
-     * @param $distribution_channel_id 渠道id
-     * @param $cost  成本
-     * @return mixed
-     */
-    static function setSendOrderCost($id, $distribution_channel_id, $cost)
-    {
-        return self::where('id', $id)->where('distribution_channel_id', $distribution_channel_id)->update(['cost' => $cost]);
-    }
-
-    /**
-     * 获取派单下的首充用户数
-     * @param $id 派单id
-     */
-    static function getFirstChargeUserNum($id)
-    {
-        $result = DB::select("SELECT COUNT(*) as num FROM ( SELECT (SELECT IFNULL(COUNT(*),0) as isss FROM orders WHERE uid=a.uid and `status` = 'PAID' and pay_end_at < a.end LIMIT 1)  as temp FROM (SELECT uid,MIN(pay_end_at) as 'end' FROM orders WHERE status='PAID' and send_order_id ='{$id}' GROUP BY uid) a ) b WHERE temp = 0");
-        return ($result && isset($result[0]->num)) ? $result[0]->num : 0;
-    }
-
-    /**
-     * 获取派单下的非首充用户数
-     * @param $id 派单id
-     */
-    static function getRepetitiousChargeUserNum($id)
-    {
-        $result = DB::select("SELECT COUNT(*) as num FROM (SELECT (SELECT IFNULL(COUNT(*),0) as isss FROM orders WHERE uid=a.uid and `status` = 'PAID' and pay_end_at < a.end LIMIT 1)  as temp FROM (SELECT uid,MIN(pay_end_at) as 'end' FROM orders WHERE status='PAID' and send_order_id ='{$id}' GROUP BY uid) a ) b WHERE temp = 1");
-        return ($result && isset($result[0]->num)) ? $result[0]->num : 0;
-    }
-
-
-    /**
-     * 获取实际派单数
-     */
-    static function getSendOrderCount($distribution_channel_id = '', $date)
-    {
-        $search_object = self::where('send_time', '>=', $date)->where('send_time', '<=', date('Y-m-d', strtotime($date) + 86400));
-        if ($distribution_channel_id) {
-            $search_object->where('distribution_channel_id', $distribution_channel_id);
-        }
-        return $search_object->count();
-    }
 }

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 120
app/Modules/SendOrder/Models/SendOrderForceDayStat.php


+ 0 - 206
app/Modules/SendOrder/Models/SendOrderStat.php

@@ -20,210 +20,4 @@ class SendOrderStat extends Model
         'recharge_amount_in_two_weeks', 'send_time', 'cost', 'year_recharge_user_num', 'ticket_recharge_user_num', 'first_recharge_amount', 'first_recharge_user_num',
         'year_paid_num', 'year_unpaid_num', 'pay_user_num', 'force_user_num', 'register_user_num', 'distribution_channel_name', 'name', 'charge_type', 'create_time', 'recharge_amount_in_one_day', 'recharge_amount_in_three_days'];
 
-    static function generateStat($data)
-    {
-        $conditions = [
-            'send_order_id' => $data['send_order_id']
-        ];
-        unset($data['send_order_id']);
-        return self::updateOrCreate($conditions, $data);
-    }
-
-    //获取派单
-    static function getList($params = [], $is_all = false)
-    {
-        $order_type = isset($params['order_type']) ? $params['order_type'] : 'desc';
-
-        if (isset($params['order_field']) && $params['order_field']) {
-            switch ($params['order_field']) {
-                case 1:
-                    $order_field = 'recharge_amount_in_one_day';
-                    break;
-                case 2:
-                    $order_field = 'recharge_amount_in_three_days';
-                    break;
-                case 3:
-                    $order_field = 'recharge_amount';
-                    break;
-                case 4:
-                    $order_field = 'first_recharge_amount';
-                    break;
-                case 5:
-                    $order_field = 'uv';
-                    break;
-                case 6:
-                    $order_field = 'register_user_num';
-                    break;
-            }
-        } else {
-            $order_field = 'create_time';
-        }
-        $search_obj = self::orderBy($order_field, $order_type);
-        if (isset($params['gender']) && $params['gender']) {
-            $search_obj->join('books','books.id','=','send_orders_stats.bid')
-                ->join('book_categories','book_categories.id','=','books.category_id')
-                ->where('book_categories.pid', '=', $params['gender']);
-        }
-        if (isset($params['start_time']) && $params['start_time']) $search_obj->where('send_time', '>=', $params['start_time']);
-        if (isset($params['end_time']) && $params['end_time']) $search_obj->where('send_time', '<=', $params['end_time']);
-        if (isset($params['send_order_id']) && $params['send_order_id']) $search_obj->where('send_order_id', '=', $params['send_order_id']);
-        if (isset($params['bid']) && $params['bid']) $search_obj->where('bid', '=', $params['bid']);
-        if (isset($params['name']) && $params['name']) $search_obj->where('name', 'like', "%" . $params['name'] . "%");
-        if (isset($params['book_name']) && $params['book_name']) $search_obj->where('book_name', 'like', '%'.$params['book_name'].'%');
-        if (isset($params['distribution_channel_id']) && $params['distribution_channel_id']) $search_obj->where('distribution_channel_id', '=', $params['distribution_channel_id']);
-
-        if (isset($params['order_status']) && $params['order_status']) {
-            if ($params['order_status'] == 1) $search_obj->where('force_user_num', '<', 20);
-            if ($params['order_status'] == 2) $search_obj->where('force_user_num', '>=', 20);
-        }
-        //\Log::info($search_obj->toSql());
-        if ($is_all) {
-            return $search_obj->get();
-        } else {
-            return $search_obj->paginate();
-        }
-    }
-
-    //获取派单obj
-    static function getObj($params = [])
-    {
-        $order_type = isset($params['order_type']) ? $params['order_type'] : 'desc';
-
-        if (isset($params['order_field']) && $params['order_field']) {
-            switch ($params['order_field']) {
-                case 1:
-                    $order_field = 'recharge_amount_in_half_day';
-                    break;
-                case 2:
-                    $order_field = 'recharge_amount_in_two_weeks';
-                    break;
-                case 3:
-                    $order_field = 'recharge_amount';
-                    break;
-                case 4:
-                    $order_field = 'first_recharge_amount';
-                    break;
-            }
-        } else {
-            $order_field = 'create_time';
-        }
-        $search_obj = self::orderBy($order_field, $order_type);
-        if (isset($params['start_time']) && $params['start_time']) $search_obj->where('create_time', '>=', $params['start_time']);
-        if (isset($params['end_time']) && $params['end_time']) $search_obj->where('create_time', '<=', $params['end_time']);
-        if (isset($params['send_order_id']) && $params['send_order_id']) $search_obj->where('send_order_id', '=', $params['send_order_id']);
-        if (isset($params['bid']) && $params['bid']) $search_obj->where('bid', '=', $params['bid']);
-        if (isset($params['name']) && $params['name']) $search_obj->where('name', 'like', "%" . $params['name'] . "%");
-        if (isset($params['book_name']) && $params['book_name']) $search_obj->where('book_name', '=', $params['book_name']);
-        if (isset($params['distribution_channel_id']) && $params['distribution_channel_id']) $search_obj->where('distribution_channel_id', '=', $params['distribution_channel_id']);
-
-        if (isset($params['order_status']) && $params['order_status']) {
-            if ($params['order_status'] == 1) $search_obj->where('force_user_num', '<', 20);
-            if ($params['order_status'] == 2) $search_obj->where('force_user_num', '>=', 20);
-        }
-        return $search_obj;
-    }
-
-    static function getRechargeAmountByBookId($params = [], $is_out_side = true, $is_24_hour = true)
-    {
-        $search_obj = self::orderBy('create_time');
-        if (isset($params['book_id']) && $params['book_id']) $search_obj->where('bid', $params['book_id']);
-        if (isset($params['end_time']) && $params['end_time']) $search_obj->where('send_time', '<=', $params['end_time']);
-        if (isset($params['start_time']) && $params['start_time']) $search_obj->where('send_time', '>=', $params['start_time']);
-
-        if ($is_out_side) {
-            $search_obj->where('register_user_num', '>=', 20);
-        } else {
-            $search_obj->where('register_user_num', '<', 20);
-        }
-
-        if ($is_24_hour) {
-            $search_obj->select('recharge_amount_in_one_day');
-            return $search_obj->sum('recharge_amount_in_one_day');
-        } else {
-            $search_obj->select('recharge_amount_in_three_days');
-            return $search_obj->sum('recharge_amount_in_three_days');
-        }
-    }
-
-    public static function getBookSendOrdersRechargeStats($channels) {
-        // self::
-        $sum_stats = self::select(DB::raw('count(id) as send_orders_num,
-                sum(recharge_amount) as recharge_amount_sum,
-                sum(paid_num) as paid_num_sum,
-                sum(unpaid_num) as unpaid_num_sum,
-                sum(pay_user_num) as pay_user_num_sum,
-                bid')
-            )
-            //->where('date',date('Y-m-d'))
-            ->whereIn('distribution_channel_id',$channels)
-            ->whereNotNull('bid')
-            ->groupBy('bid')
-            ->orderBy('recharge_amount_sum','desc')
-            ->paginate();
-        $channels_str = implode(',',$channels);
-        //\Log::info('sum_stats_origin:'.json_encode($sum_stats));
-        foreach ($sum_stats as $sum_stat) {
-            $yesterday_recharge =  DB::select("select book_name,sum(recharge_amount) as yesterday_recharge
-            from send_orders_force_day_stats where distribution_channel_id in ($channels_str) and  bid =".($sum_stat->bid)." and date='".date('Y-m-d',strtotime('-1 day'))."'");
-            $yesterday_recharge_sum = $yesterday_recharge[0]->yesterday_recharge;
-            $book_name = $yesterday_recharge[0]->book_name;
-            if(empty($book_name)){
-                $book = BookConfig::where('bid',$sum_stat->bid)->first();
-                if($book){
-                    $book_name = $book->book_name;
-                }
-            }
-            $sum_stat->yesterday_recharge = $yesterday_recharge_sum;
-            $sum_stat->book_name = $book_name;
-            $sum_stat->order_total = intval($sum_stat->paid_num_sum) + intval($sum_stat->unpaid_num_sum);
-            $sum_stat->average_recharge = $sum_stat->pay_user_num_sum >0?round($sum_stat->recharge_amount_sum/$sum_stat->pay_user_num_sum,2):0;
-            $sum_stat->success_rate = $sum_stat->order_total>0?(round($sum_stat->paid_num_sum/$sum_stat->order_total,2)*100).'%':0;
-        }
-        //\Log::info('sum_stats:'.json_encode($sum_stats));
-        return $sum_stats;
-    }
-
-    /**
-     * @param $channels
-     * @return array
-     */
-    public static function exportBookSendOrdersRechargeStats($channels){
-        \Log::info($channels);
-        $channels_str = implode(',',$channels);
-        $sum_stats = DB::select("select book_name,count(id) as send_orders_num,
-                    sum(recharge_amount) as recharge_amount_sum,
-                    sum(paid_num) as paid_num_sum,
-                    sum(unpaid_num) as unpaid_num_sum,
-                    sum(pay_user_num) as pay_user_num_sum,
-                    bid from send_orders_stats where distribution_channel_id in ($channels_str)
-                     group by bid"
-            );
-        $sum_stats = json_decode(json_encode($sum_stats),true);
-        $yesterday = date('Y-m-d',strtotime('-1 day'));
-        $sum_day_stats = DB::select("select bid,sum(recharge_amount) as yesterday_recharge from send_orders_force_day_stats 
-          where date='{$yesterday}' and distribution_channel_id in ($channels_str) group by bid
-          ");
-        $sum_day_stats = json_decode(json_encode($sum_day_stats),true);
-        $sum_stats_day_temp = [];
-        /*foreach ($sum_stats as $sum_stat){
-            $sum_stats_total[$sum_stats->bid] = $sum_stat;
-        }*/
-        foreach ($sum_day_stats as $sum_day_stat){
-            $sum_stats_day_temp[$sum_day_stat['bid']] = $sum_day_stat;
-        }
-        $data = array();
-        $header = ['书名','派单数','充值总额','充值人数','人均充值','昨日充值','成功订单数','订单总数','订单成功率'];
-        foreach ($sum_stats as $key=>$value){
-            $yesterday_recharge = array_key_exists($value['bid'],$sum_stats_day_temp)?$sum_stats_day_temp[$value['bid']]['yesterday_recharge']:0;
-            $order_num = $value['paid_num_sum']+$value['unpaid_num_sum'];
-            $data[] = [
-                $value['book_name'],$value['send_orders_num'],
-                $value['recharge_amount_sum'],$value['pay_user_num_sum'],
-                $value['pay_user_num_sum']>0?round($value['recharge_amount_sum']/$value['pay_user_num_sum'],2):0,
-                $yesterday_recharge, $value['paid_num_sum'], $order_num,
-                $order_num>0?round($value['paid_num_sum']/$order_num,2):0
-            ];
-        }
-        return ['header'=>$header,'data'=>$data];
-    }
 }

+ 0 - 42
app/Modules/SendOrder/Services/SendOrderDayStatService.php

@@ -17,48 +17,6 @@ use App\Modules\Trade\Services\OrderService;
 class SendOrderDayStatService
 {
 
-    //生成每日派单
-    static function generateStat()
-    {
-        $end_send_time = date("Y-m-d");
-        $send_orders = SendOrderService::search(compact('end_send_time'),true);
-
-        //用户
-
-        //注册用户
-        foreach ($send_orders as $send_order)
-        {
-            $data = [];
-
-            $channel = ChannelService::getById($send_order->distribution_channel_id);
-
-            $data['send_order_id'] = $send_order->id;
-            $data['distribution_channel_id'] = $send_order->distribution_channel_id;
-            $data['distribution_channel_name'] = $channel->nickname;
-            $data['book_id'] = $send_order->book_id;
-            $data['book_name'] = $send_order->book_name;
-            $data['pv'] = SendOrderService::getPv($send_order->id);
-            $data['uv'] = SendOrderService::getUv($send_order->id);
-            $data['register_user_num'] = 0;//UserService::getPromotionTotal($send_order->id);
-            $data['force_user_num'] = 0;// ForceSubscribeService::getFansNum($send_order->id);
-            $data['send_time'] = $send_order->send_time;
-            $data['cost'] = $send_order->cost;
-
-            $data['pay_user_num'] = 0;
-            $data['year_recharge_user_num'] = 0;
-            $data['ticket_recharge_user_num'] = 0;
-            $data['recharge_amount'] = 0;
-            $data['first_recharge_amount'] = 0;
-            $data['year_unpaid_num'] = 0;
-            $data['year_paid_num'] = 0;
-            $data['recharge_amount_in_half_day'] = 0;
-            $data['recharge_amount_in_two_weeks'] = 0;
-
-            dd($data);
-
-        }
-
-    }
 
 
 }

+ 0 - 159
app/Modules/SendOrder/Services/SendOrderForceDayStatService.php

@@ -16,166 +16,7 @@ use DB;
 
 class SendOrderForceDayStatService
 {
-    //按书统计
-    static function getSendOrderDayStatsByBook($params)
-    {
-        return SendOrderForceDayStat::getSendOrderDayStatsByBook($params);
-    }
 
-    //生成
-    static function generateForceDayStat($date)
-    {
-        $end_send_time = date('Y-m-d H:i:s', strtotime($date) + 86400 - 1);
 
-        $fields = DB::raw("
-              send_order_id,
-              count(1) paid_num,
-              sum(price) recharge_amount,
-              count(distinct uid) pay_user_num
-        ");
-        //TODO 解除limit
-        $order_data = DB::table('orders')->select($fields)->where('status', 'PAID')->where('created_at','>=', $date)->where('created_at','<=', $end_send_time)->groupBy('send_order_id')->get();
-        $order_data_array = [];
-        if ($order_data) {
-            foreach ($order_data as $order) {
-                $order_data_array[$order->send_order_id] = $order;
-            }
-        }
-        $order_total_fields = DB::raw("
-                send_order_id,
-                count(1) order_num
-        ");
-        $order_total_data = DB::table('orders')->select($order_total_fields)->where('created_at','>=', $date)->where('created_at','<=', $end_send_time)->groupBy('send_order_id')->get();
-        $order_total_data_array = [];
-        if ($order_total_data) {
-            foreach ($order_total_data as $_order) {
-                $order_total_data_array[$_order->send_order_id] = $_order;
-            }
-        }
 
-        //注册用户
-        $register_fields = DB::raw("
-              send_order_id,
-              count(1) num
-        ");
-        $register_data = DB::table('users')->select($register_fields)->where('created_at','>=', $date)->where('created_at','<=', $end_send_time)->groupBy('send_order_id')->get();
-        $register_data_array = [];
-        if ($register_data) {
-            foreach ($register_data as $_register_data) {
-                $register_data_array[$_register_data->send_order_id] = $_register_data->num;
-            }
-        }
-
-
-        DB::table('send_orders')->where('is_enable', 1)->where('send_time', '<=', $end_send_time)->orderBy('id')->chunk(1000,function($send_orders) use($date,$order_data_array,$order_total_data_array,$register_data_array){
-//        $send_orders = SendOrderService::search(compact('end_send_time'), true);
-            $return_data = [];
-            foreach ($send_orders as $send_order) {
-                $data = [];
-                $data['send_order_id'] = $send_order->id;
-                $data['date'] = $date;
-                $data['create_time'] = $send_order->created_at;
-                $data['name'] = $send_order->name;
-                $data['charge_type'] = $send_order->charge_type;
-
-                if(isset($book_name_array[$send_order->book_id])){
-                    $book_name = $book_name_array[$send_order->book_id];
-                }else{
-                    $book_name =self::getBookNameByBid($send_order->book_id);
-                    $book_name_array[$send_order->book_id] = $book_name;
-                }
-                $data['book_name'] = $book_name;
-                $data['bid'] = $send_order->book_id;
-                $uv = SendOrderService::getUvInfo($send_order->id);
-                $pv = SendOrderService::getPvInfo($send_order->id);
-
-                $data['total_uv'] = isset($uv['total']) ? $uv['total'] : 0;
-                $data['uv'] = isset($uv[$date]) ? $uv[$date] : 0;
-                $data['total_pv'] = isset($pv['total']) ? $pv['total'] : 0;
-                $data['pv'] = isset($pv[$date]) ? $pv[$date] : 0;
-                $data['recharge_amount'] = isset($order_data_array[$send_order->id]) ? $order_data_array[$send_order->id]->recharge_amount : 0;
-                $data['paid_num'] = isset($order_data_array[$send_order->id]) ? $order_data_array[$send_order->id]->paid_num : 0;
-                $data['unpaid_num'] = isset($order_total_data_array[$send_order->id]) ? $order_total_data_array[$send_order->id]->order_num - $data['paid_num'] : 0;
-                $data['pay_user_num'] = isset($order_data_array[$send_order->id]) ? $order_data_array[$send_order->id]->pay_user_num : 0;
-                $data['distribution_channel_id'] = $send_order->distribution_channel_id;
-                $data['distribution_channel_name'] = ChannelService::getChannelCompanyNameById($send_order->distribution_channel_id);//ChannelService::getChannelNicknameById($send_order->distribution_channel_id);
-                $data['cost'] = $send_order->cost;
-                $data['send_time'] = $send_order->send_time;
-
-                $total_order_num = $data['unpaid_num'] + $data['paid_num'];
-
-                //强关用户数
-                $force_user_num = DB::table('force_subscribe_users')->where('send_order_id', $send_order->id)->whereDate('created_at', $date)->count();
-                $data['force_user_num'] = $force_user_num;
-
-                //注册用户数
-                $data['register_user_num'] = isset($register_data_array[$send_order->id]) ? $register_data_array[$send_order->id] : 0;
-
-                //首充数据
-                if ($data['pay_user_num']) {
-                    $begin_time = $date;
-                    $end_time = date("Y-m-d", strtotime($date) + 86400);
-                    $first_data = DB::select("select count(distinct uid) count,sum(price) amount from orders a where created_at>='{$begin_time}' and created_at<'{$end_time}' and send_order_id = '{$send_order->id}' and status ='PAID' and not exists (select uid from orders where a.uid = uid and created_at < '{$begin_time}' and status= 'PAID' limit 1)");
-                    $data['first_recharge_user_num'] = (int)$first_data[0]->count;
-                    $data['first_recharge_amount'] = (float)$first_data[0]->amount;
-                } else {
-                    $data['first_recharge_user_num'] = 0;
-                    $data['first_recharge_amount'] = 0;
-                }
-
-                //12小时充值数据
-                if ($send_order->send_time) {
-                    $end_timestamp = min(strtotime($send_order->send_time) + 7 * 24 * 3600, strtotime($date) + 86400);
-                    $end_time = date("Y-m-d H:i:s", $end_timestamp);
-                    $data['recharge_amount_in_two_weeks'] = OrderService::getAmount(['send_order_id' => $send_order->id,  'end_time' => $end_time]);
-                    $end_timestamp = min(strtotime($send_order->send_time) + 12 * 3600, strtotime($date) + 86400);
-                    $end_time = date("Y-m-d H:i:s", $end_timestamp);
-                    $data['recharge_amount_in_half_day'] = OrderService::getAmount(['send_order_id' => $send_order->id, 'end_time' => $end_time]);
-                    //24小时
-                    $end_time = date("Y-m-d H:i:s", min(strtotime($send_order->send_time) + 24 * 3600,strtotime($date) + 86400));
-                    $data['recharge_amount_in_one_day'] = OrderService::getAmount(['send_order_id' => $send_order->id,  'end_time' => $end_time]);
-                    //3天
-                    $end_time = date("Y-m-d H:i:s", min(strtotime($send_order->send_time) + 3 * 24 * 3600,strtotime($date) + 86400));
-                    $data['recharge_amount_in_three_days'] = OrderService::getAmount(['send_order_id' => $send_order->id,  'end_time' => $end_time]);
-                } else {
-                    $data['recharge_amount_in_two_weeks'] = 0;
-                    $data['recharge_amount_in_half_day'] = 0;
-                    $data['recharge_amount_in_one_day'] = 0;
-                    $data['recharge_amount_in_three_days'] = 0;
-                }
-                //包年充值用户数
-                $data['year_recharge_user_num'] = $data['pay_user_num'] ? (int)DB::table('orders')->whereDate('created_at', $date)->where('order_type', 'YEAR')->where('status', 'PAID')->distinct('uid')->where('send_order_id', $send_order->id)->count() : 0;
-                $data['ticket_recharge_user_num'] = $data['pay_user_num'] - $data['year_recharge_user_num'];
-                $data['year_paid_num'] = $data['pay_user_num'] ? (int)DB::table('orders')->whereDate('created_at', $date)->where('order_type', 'YEAR')->where('status', 'PAID')->where('send_order_id', $send_order->id)->count() : 0;
-                $data['year_unpaid_num'] = $total_order_num ? (int)DB::table('orders')->whereDate('created_at', $date)->where('order_type', 'YEAR')->where('status', 'UNPAID')->where('send_order_id', $send_order->id)->count() : 0;
-
-                SendOrderForceDayStat::generateForceDayStat($data);
-                $return_data[] = $data;
-            }
-            SendOrderStatService::generateStatsByDayStats($return_data,$date);
-        });
-        //return $return_data;
-    }
-
-    /**
-     * 管理后台获历史取派单信息
-     * @param $params 字段列表
-     * @param string $isAll 是否获取所有
-     * @return mixed
-     */
-    static function getHistorySendOrders($params = [], $is_all = false)
-    {
-        return SendOrderForceDayStat::getHistorySendOrders($params, $is_all);
-    }
-
-    public static function getSendOrdersRechargeDetail($distribution_channels) {
-        SendOrderForceDayStat::getBookSendOrdersRechargeStats();
-    }
-
-    private static function getBookNameByBid($bid){
-        $book = BookConfig::where('bid',$bid)->select('book_name')->first();
-        if($book)
-            return $book->book_name;
-        return 'unknown';
-    }
 }

+ 11 - 435
app/Modules/SendOrder/Services/SendOrderService.php

@@ -9,12 +9,10 @@
 
 namespace App\Modules\SendOrder\Services;
 
+use App\Modules\SendOrder\Models\QappUserSendOrderId;
 use App\Modules\SendOrder\Models\QuickAppSendOrder;
 use App\Modules\SendOrder\Models\SendOrder;
-use App\Modules\SendOrder\Models\SendOrderExtraStat;
-use App\Modules\Statistic\Services\WapVisitStatService;
 use DB;
-use Redis;
 
 class SendOrderService
 {
@@ -28,267 +26,7 @@ class SendOrderService
         return QuickAppSendOrder::where('send_order_id', $send_order_id)->first();
     }
 
-    /**
-     *  更新派单的备注
-     * @param $id  派单id
-     * @param $distribution_channel_id 渠道id
-     * @param $remark 备注
-     * @return mixed
-     */
-    static function updateRemark($id, $distribution_channel_id, $remark)
-    {
-        return SendOrder::updateRemark($id, $distribution_channel_id, $remark);
-    }
-
-    /**
-     *  更新派单的星数
-     * @param $id  派单id
-     * @param $distribution_channel_id 渠道id
-     * @param $starNum 星数
-     * @return mixed
-     */
-    static function updateStarNum($id, $distribution_channel_id, $starNum)
-    {
-        return SendOrder::updateStarNum($id, $distribution_channel_id, $starNum);
-    }
-
-    /**
-     *  更新派单的星数、备注
-     * @param $id  派单id
-     * @param $distribution_channel_id 渠道id
-     * @param $starNum 星数
-     * @return mixed
-     */
-    static function updateStarNumAndRemark($id, $distribution_channel_id, $starNum, $remark)
-    {
-        return SendOrder::updateStarNumAndRemark($id, $distribution_channel_id, $starNum, $remark);
-    }
-
-    /**
-     * 更新派单
-     * @param $id  派单id
-     * @param $distribution_channel_id 渠道id
-     * @param $name 派单名称
-     * @param $cost 成本
-     * @param $channel_type  派单渠道类型.(允许值: AUTHENTICATED, UNAUTHENTICATED)
-     * @return mixed
-     */
-    static function updateSendOrderInfo($id, $distribution_channel_id, $name, $pre_send_date, $channel_type, $cost, $promotion_type, $subscribe_chapter = [])
-    {
-        return SendOrder::updateSendOrderInfo($id, $distribution_channel_id, $name, $pre_send_date, $channel_type, $cost, $promotion_type, $subscribe_chapter);
-    }
-
-    /**
-     * 通过bid获取该书的推广次数
-     * @param $bid 书本id
-     */
-    static function getPromotionCountByBid($bid, $channelId)
-    {
-        return SendOrder::getPromotionCountByBid($bid, $channelId);
-    }
-
-    /**
-     * 通过渠道id获取该渠道的推广次数
-     * @param $channelId 渠道id
-     */
-    static function getPromotionCountByChannelId($channelId)
-    {
-        return SendOrder::getPromotionCountByChannelId($channelId);
-    }
-
-    /**
-     * 获取渠道下某时间段内推广次数
-     * @param $channelId 渠道id
-     * @param $begin_time 开始日期
-     * @param $end_time 结束日期
-     */
-    static function getChannelPromotionCount($channelId, $begin_time, $end_time)
-    {
-        return SendOrder::getChannelPromotionCount($channelId, $begin_time, $end_time);
-    }
-
-    /**
-     * 获取渠道下某时间段内实际推广次数
-     * @param $channelId 渠道id
-     * @param $begin_time 开始日期
-     * @param $end_time 结束日期
-     */
-    static function getChannelRealPromotionCount($channelId, $begin_time, $end_time)
-    {
-        return SendOrder::getChannelRealPromotionCount($channelId, $begin_time, $end_time);
-    }
-
-    /**
-     * 获取实际推广次数
-     * @param $channelId 渠道id
-     * @param $begin_time 开始日期
-     * @param $end_time 结束日期
-     */
-    static function getRealPromotionCount($params)
-    {
-        return SendOrder::getRealPromotionCount($params);
-    }
 
-    /**
-     * 获取渠道下某时间段内推广次数
-     * @param $params begin_time、end_time、distribution_channel_id
-     */
-    static function getPromotionCount($params)
-    {
-        return SendOrder::getPromotionCount($params);
-    }
-
-    /**
-     * 通过渠道id下所有的推广次数
-     * @param $channelId 渠道id
-     */
-    static function getTotalPromotionCountByChannelIds($channelIds)
-    {
-        return SendOrder::getTotalPromotionCountByChannelIds($channelIds);
-    }
-
-    /**
-     * 通过区间内的渠道id获取该渠道的推广次数
-     * @param $channelId 渠道id
-     * @param $start_time 开始时间
-     * @param $end_time 结束时间
-     */
-    static function getDuraingPromotionCountByChannelId($channelId, $start_time = '', $end_time = '')
-    {
-        return SendOrder::getDuraingPromotionCountByChannelId($channelId, $start_time, $end_time);
-    }
-
-    /**
-     * 获取派单信息
-     * @param $bookId 推广书籍id
-     * @param $distribution_channel_id 推广渠道id
-     * @param $name 派单名称
-     * @param $bookName 书名
-     * @param $sendOrderId 派单id
-     * @param string $start_date 开始时间
-     * @param string $end_date 结束时间
-     * @param string $isAll 是否获取所有
-     * @return mixed
-     */
-    static function getSendOrders($bookId, $distribution_channel_id, $name = null, $bookName = null, $sendOrderId, $start_time = '', $end_time = '', $isAll = false)
-    {
-        return SendOrder::getSendOrders($bookId, $distribution_channel_id, $name, $bookName, $sendOrderId, $start_time, $end_time, $isAll);
-    }
-
-
-    /**
-     * 管理后台获取派单信息
-     * @param $bookId 推广书籍id
-     * @param $distribution_channel_id 推广渠道id
-     * @param $name 派单名称
-     * @param $bookName 书名
-     * @param $sendOrderId 派单id
-     * @param string $start_date 开始时间
-     * @param string $end_date 结束时间
-     * @param string $isAll 是否获取所有
-     * @return mixed
-     */
-    static function getManageSendOrders($params = [], $is_all = false)
-    {
-        return SendOrder::getManageSendOrders($params, $is_all);
-    }
-
-    /**
-     * 创建推广派单(章节)
-     * @param  array ['name', 'channel_type', 'promotion_type','sex_preference', 'book_id', 'cost','book_name','qr_code_id', 'chapter_id', 'chapter_name', 'document_end_chapter_seq', 'original_guide_id', 'headline_id', 'body_template_id', 'document_cover_id', 'subscribe_chapter_id', 'subscribe_chapter_name', 'subscribe_chapter_seq', 'distribution_channel_id', 'redirect_url']
-     */
-    static function createFromChapter($data)
-    {
-        return SendOrder::createFromChapter($data);
-    }
-
-    /**
-     * 创建推广派单(推广页面)
-     * @param  array ['name', 'channel_type','promotion_type', 'page_id', 'entrance','cost', 'qr_code_id','distribution_channel_id', 'redirect_url', 'subscribe_chapter_id', 'subscribe_chapter_name', 'subscribe_chapter_seq']
-     */
-    static function createFromPage($data)
-    {
-        return SendOrder::createFromPage($data);
-    }
-
-    /**
-     * 创建推广派单(目录)
-     * @param  array ['name', 'channel_type', 'promotion_type','book_id', 'book_name','cost', 'chapter_id','qr_code_id', 'chapter_name', 'distribution_channel_id', 'redirect_url', 'subscribe_chapter_id', 'subscribe_chapter_name', 'subscribe_chapter_seq']
-     */
-    static function createFromDirectory($data)
-    {
-        return SendOrder::createFromDirectory($data);
-    }
-
-    /**
-     * 获取Pv
-     * @param $id 派单id
-     * @return int PV
-     */
-    static function getPv($id)
-    {
-        return WapVisitStatService::getSendOrderTotalPv($id);
-        //return (float)Redis::hget('send_order_pv_' . $id, 'total');
-    }
-
-    static function getBrowserUvAndPv($id)
-    {
-        return WapVisitStatService::getBrowserSendOrderTotalPvAndUv($id);
-    }
-
-    /**
-     * 获取Uv
-     * @param $id 派单id
-     * @return int UV
-     */
-    static function getUv($id)
-    {
-        return WapVisitStatService::getSendOrderTotalUv($id);
-        //return (float)Redis::hget('send_order_uv_' . $id, 'total');
-    }
-
-    /**
-     * 获取每一天的Uv信息列表
-     * @param $id 派单id
-     * @return int UV
-     */
-    static function getUvInfo($id)
-    {
-        return WapVisitStatService::getSendOrderUv($id);
-        //return Redis::hgetAll('send_order_uv_' . $id);
-    }
-
-    /**
-     * 获取每一天的pv信息列表
-     * @param $id 派单id
-     * @return int PV
-     */
-    static function getPvInfo($id)
-    {
-        return WapVisitStatService::getSendOrderPv($id);
-        //return Redis::hgetAll('send_order_pv_' . $id);
-    }
-
-    /**
-     * 删除派单
-     * @param $id 派单id
-     * @param $distribution_channel_id 渠道id
-     * @return
-     */
-    static function removeSendOrder($id, $distribution_channel_id)
-    {
-        return SendOrder::removeSendOrder($id, $distribution_channel_id);
-    }
-
-    /**
-     * 获取重定向url
-     * @param $id
-     * @return mixed
-     */
-    static function getRedirectUrlById($id)
-    {
-        return SendOrder::where('id', $id)->select('redirect_url', 'book_id', 'send_time', 'distribution_channel_id', 'name', 'promotion_point', 'force_show_qrcode', 'promotion_type')->first();
-    }
 
     /**
      * 根据id获取信息
@@ -300,112 +38,6 @@ class SendOrderService
         return SendOrder::find($id);
     }
 
-    //获取推广总uv、pv
-    static function getChannelPromotionTotalUvPv($distribution_channel_id, $date)
-    {
-        //return WapVisitStatService::getChannelPromotionTotalUvPv($distribution_channel_id,$date);
-        $send_orders = SendOrder::getSendOrders(null, $distribution_channel_id, null, null, '', '', '', true);
-        $uv = 0;
-        $pv = 0;
-        foreach ($send_orders as $send_order) {
-            $uv += (float) Redis::hget('send_order_uv_' . $send_order->id, $date);
-            $pv += (float) Redis::hget('send_order_pv_' . $send_order->id, $date);
-        }
-        return compact('uv', 'pv');
-    }
-
-    /**
-     * 获取date的实际派单数
-     */
-    static function getActualSendOrderNum($distribution_channel_id, $date)
-    {
-        return SendOrder::whereBetween('send_time', [$date, date('Y-m-d', strtotime($date) + 86400)])->where('distribution_channel_id', $distribution_channel_id)->count();
-    }
-
-    /**
-     * 获取继续阅读的uv
-     * @param $distribution_channel_id
-     * @param $date
-     * @return array
-     */
-    static function getContinueTotalReadUv($send_order_id)
-    {
-        return (float) Redis::hget('send_order:continue:' . $send_order_id, 'total');
-    }
-
-    /**
-     * 设置成本
-     * @param $id  派单id
-     * @param $distribution_channel_id 渠道id
-     * @param $cost  成本
-     * @return mixed
-     */
-    static function setSendOrderCost($id, $distribution_channel_id, $cost)
-    {
-        return SendOrder::setSendOrderCost($id, $distribution_channel_id, $cost);
-    }
-
-    /**
-     * 获取派单下的首充用户数
-     * $id 派单id
-     * @param $id
-     */
-    static function getFirstChargeUserNum($id)
-    {
-        return SendOrder::getFirstChargeUserNum($id);
-    }
-
-    /**
-     * 获取派单下的非首充用户数
-     * $id 派单id
-     * @param $id
-     */
-    static function getRepetitiousChargeUserNum($id)
-    {
-        return SendOrder::getRepetitiousChargeUserNum($id);
-    }
-
-    /**
-     * 获取派单uv大于20的时间
-     * @param $sendOrderId 派单id
-     * @return float|int 时间
-     */
-    static function getUv20Time($sendOrderId)
-    {
-        $uv20Time = '';
-        $periodTotalUV = 0;
-        $uvInfos = SendOrderService::getUvInfo($sendOrderId);
-        if (isset($uvInfos['total'])) {
-            unset($uvInfos['total']);
-        }
-        ksort($uvInfos);
-        foreach ($uvInfos as $key => $v) {
-            $periodTotalUV += $v;
-            //如果uv总数大于20
-            if ($periodTotalUV > 20) {
-                $uv20Time = $key;
-                break;
-            }
-        }
-        return $uv20Time;
-    }
-
-    /**
-     * 新获取派单列表
-     * @param $bookId 推广书籍id
-     * @param $distribution_channel_id 推广渠道id
-     * @param $name 派单名称
-     * @param $bookName 书名
-     * @param $sendOrderId 派单id
-     * @param string $start_date 开始时间
-     * @param string $end_date 结束时间
-     * @param string $isAll 是否获取所有
-     * @return mixed
-     */
-    static function search($params, $isAll = false)
-    {
-        return SendOrder::search($params, $isAll);
-    }
 
     /*
      * 更新派单时间
@@ -416,74 +48,18 @@ class SendOrderService
     }
 
     /**
-     * 获取实际派单数
+     * 记录用户派单id
+     * @param $uid
+     * @param $send_order_id
      */
-    static function getRealSendOrderCount($distribution_channel_id = '', $date)
-    {
-        return SendOrder::getSendOrderCount($distribution_channel_id, $date);
-    }
-
-    static function getChannelPromotionBooks($distribution_channel_id = [], $endData, $book_name = '', $channel_name = '', $isAll = false)
-    {
-        $obj = SendOrder::select('send_orders.book_name', "companies.name as nickname", DB::raw("GROUP_CONCAT(distinct send_orders.distribution_channel_id) as distribution_channel_id"), DB::raw("count(*) as count"))
-            ->join("distribution_channels", 'send_orders.distribution_channel_id', "=", "distribution_channels.id")
-            ->join("channel_users", 'distribution_channels.channel_user_id', "=", "channel_users.id")
-            ->join('companies', 'companies.id', "=", "channel_users.company_id")
-            ->where("send_orders.created_at", "<=", $endData)
-            ->groupBy('send_orders.book_name')
-            ->groupBy('distribution_channels.channel_user_id');
-
-        if ($book_name) {
-            $obj = $obj->where('send_orders.book_name', $book_name);
-        }
-
-        if ($channel_name) {
-            $obj = $obj->where('companies.name', 'like', '%' . $channel_name . '%');
-        }
-
-        if ($distribution_channel_id) {
-            $obj = $obj->whereIn('send_orders.distribution_channel_id', $distribution_channel_id);
-        }
-
-        if ($isAll) {
-            return $obj->get();
-        } else {
-            return $obj->paginate();
+    static function recordUserSendOrder($uid,$send_order_id){
+        $info = QappUserSendOrderId::where('uid',$uid)->select('send_order_id',$send_order_id)->orderBy('id','desc')->first();
+        if($info && $info->send_order_id == $send_order_id){
+            return ;
         }
+        QappUserSendOrderId::create([
+            'uid'=>$uid,'send_order_id'=>$send_order_id
+        ]);
     }
 
-    static function getExtraStat($send_order_id)
-    {
-        return SendOrderExtraStat::getBySendOrderId($send_order_id);
-    }
-
-    static function getPeriodActualSendOrdersNum($channel_id, $start_time, $end_time)
-    {
-        return SendOrder::where([
-            ['distribution_channel_id', '=', $channel_id],
-            ['send_time', '>=', $start_time],
-            ['send_time', '<=', $end_time],
-        ])->count();
-    }
-
-    static function getCompanyPromotionBooks($company_id, $start_time, $end_time)
-    {
-        $res = DB::select("select * from (select bcs.bid,bcs.book_name,count(so.id) as promotion_times 
- from channel_users cu
- left join distribution_channels dc on dc.channel_user_id=cu.id
- left join send_orders so on so.distribution_channel_id=dc.id
- left join book_configs bcs on bcs.bid=so.book_id
- where cu.company_id=" . $company_id . " and so.book_id is not null and so.send_time between '" . $start_time . "' and '" . $end_time . "' 
- group by so.book_id) tmp order by tmp.promotion_times desc");
-        return $res;
-    }
-
-    //成本统计
-    static function getCostStats($distribution_channels)
-    {
-        return SendOrder::whereIn('distribution_channel_id', $distribution_channels)
-            ->where('is_enable', 1)
-            ->whereNotNull('send_time')
-            ->sum('cost');
-    }
 }

+ 0 - 324
app/Modules/SendOrder/Services/SendOrderStatService.php

@@ -14,332 +14,8 @@ use DB;
 
 class SendOrderStatService
 {
-    /**
-     * 获取派单汇总统计信息
-     * @param $params 字段列表
-     * @param string $isAll 是否获取所有
-     * @return mixed
-     */
-    static function getSendOrderStats($params = [], $is_all = false)
-    {
-        return SendOrderStat::getSendOrderStats($params, $is_all);
-    }
 
-    //生成统计
-    static function generateStat()
-    {
-        $fields = DB::raw("send_order_id,max(date) max_date,book_name,bid,sum(uv) sum_uv,sum(pv) sum_pv,sum(recharge_amount) sum_recharge_amount,sum(paid_num) sum_paid_num,sum(unpaid_num) sum_unpaid_num,
-        distribution_channel_id,max(recharge_amount_in_half_day) max_recharge_amount_in_half_day,max(recharge_amount_in_one_day) max_recharge_amount_in_one_day,max(recharge_amount_in_two_weeks) max_recharge_amount_in_two_weeks,
-        max(recharge_amount_in_three_days) max_recharge_amount_in_three_days,max(recharge_amount_in_one_day) max_recharge_amount_in_one_day,send_time,cost,sum(year_recharge_user_num) sum_year_recharge_user_num,
-        sum(ticket_recharge_user_num) sum_ticket_recharge_user_num,sum(first_recharge_amount) sum_first_recharge_amount, sum(first_recharge_user_num) sum_first_recharge_user_num,sum(year_paid_num) sum_year_paid_num,
-        sum(year_unpaid_num) sum_year_unpaid_num,sum(pay_user_num) sum_pay_user_num,sum(force_user_num) sum_force_user_num,sum(register_user_num) sum_register_user_num,distribution_channel_name,charge_type,name,create_time");
-        $stats = DB::table('send_orders_force_day_stats')->select($fields)->groupBy('send_order_id')->get();
 
-        foreach ($stats as $stat)
-        {
-            $end_time = date("Y-m-d",strtotime($stat->max_date)+86400);
-            $data = [];
-            $data['send_order_id'] = $stat->send_order_id;
-            $data['book_name'] = $stat->book_name;
-            $data['bid'] = $stat->bid;
-            $data['uv'] = $stat->sum_uv;
-            $data['pv'] = $stat->sum_pv;
-            $data['recharge_amount'] = $stat->sum_recharge_amount;
-            $data['paid_num'] = $stat->sum_paid_num;
-            $data['unpaid_num'] = $stat->sum_unpaid_num;
 
-            $data['distribution_channel_id'] = $stat->distribution_channel_id;
-            $data['recharge_amount_in_half_day'] = $stat->max_recharge_amount_in_half_day;
-            $data['recharge_amount_in_one_day'] = $stat->max_recharge_amount_in_one_day;
-            $data['recharge_amount_in_two_weeks'] = $stat->max_recharge_amount_in_two_weeks;
-            $data['recharge_amount_in_three_days'] = $stat->max_recharge_amount_in_three_days;
-            $data['recharge_amount_in_one_day'] = $stat->max_recharge_amount_in_one_day;
-            $data['send_time'] = $stat->send_time;
-            $data['cost'] = $stat->cost;
 
-            //付费用户数
-            $data['year_recharge_user_num'] = (int)DB::table('orders')
-                                                    ->where('send_order_id',$stat->send_order_id)
-                                                    ->distinct('uid')->where('order_type','YEAR')
-                                                    ->where('created_at','<',$end_time)
-                                                    ->where('status','PAID')
-                                                    ->count();
-            $data['ticket_recharge_user_num'] = (int)DB::table('orders')->where('send_order_id',$stat->send_order_id)->distinct('uid')->where('order_type','RECHARGE')->where('created_at','<',$end_time)->where('status','PAID')->count();
-
-            $data['pay_user_num'] = (int)DB::table('orders')->where('send_order_id',$stat->send_order_id)->distinct('uid')->where('status','PAID')->where('created_at','<',$end_time)->count();
-
-            $data['first_recharge_amount'] = $stat->sum_first_recharge_amount;
-            $data['first_recharge_user_num'] = $stat->sum_first_recharge_user_num;
-            $data['year_paid_num'] = $stat->sum_year_paid_num;
-            $data['year_unpaid_num'] = $stat->sum_year_unpaid_num;
-            $data['force_user_num'] = $stat->sum_force_user_num;
-            $data['register_user_num'] = $stat->sum_register_user_num;
-            $data['distribution_channel_name'] = $stat->distribution_channel_name;
-            $data['charge_type'] = $stat->charge_type;
-            $data['name'] = $stat->name;
-            $data['create_time'] = $stat->create_time;
-
-            SendOrderStat::generateStat($data);
-        }
-    }
-
-    //获取派单
-    static function getList($params=[],$is_all = false)
-    {
-        return SendOrderStat::getList($params,$is_all);
-    }
-
-    //获取派单obj
-    static function getObj($params=[])
-    {
-        return SendOrderStat::getObj($params);
-    }
-
-    static function generateStatsByDayStats($data,$date)
-    {
-        //$yesterday = date('Y-m-d',strtotime($date.' -1 day'));
-        //$save_data = [];
-        foreach ($data as $key=>$item) {
-            $yest_data =  SendOrderStat::where('send_order_id',$item['send_order_id'])->first();
-            $end_time = date('Y-m-d',strtotime($date)+86400);
-            $save_data = array();
-            if($yest_data){
-                $save_data = array(
-                    'send_order_id' => $yest_data->send_order_id,
-                    'book_name' => $yest_data->book_name,
-                    'bid'   => $yest_data->bid,
-                    'uv' => $item['uv'] + $yest_data->uv,
-                    'pv' => $item['pv'] + $yest_data->pv,
-                    'recharge_amount' => $item['recharge_amount'] + $yest_data->recharge_amount,
-                    'paid_num' => $item['paid_num'] + $yest_data->paid_num,
-                    'unpaid_num' => $item['unpaid_num'] + $yest_data->unpaid_num,
-                    'distribution_channel_id' => $item['distribution_channel_id'],
-                    'recharge_amount_in_half_day' => ($item['recharge_amount_in_half_day']>=$yest_data->recharge_amount_in_half_day)?$item['recharge_amount_in_half_day']:$yest_data->recharge_amount_in_half_day,
-                    'recharge_amount_in_one_day' => ($item['recharge_amount_in_one_day']>=$yest_data->recharge_amount_in_one_day)?$item['recharge_amount_in_one_day']:$yest_data->recharge_amount_in_one_day,
-                    'recharge_amount_in_two_weeks' => ($item['recharge_amount_in_two_weeks']>=$yest_data->recharge_amount_in_two_weeks)?$item['recharge_amount_in_two_weeks']:$yest_data->recharge_amount_in_two_weeks,
-                    'recharge_amount_in_three_days' => ($item['recharge_amount_in_three_days']>=$yest_data->recharge_amount_in_three_days)?$item['recharge_amount_in_three_days']:$yest_data->recharge_amount_in_three_days,
-
-                    'send_time' => $item['send_time'],
-                    'cost' => $item['cost'],
-
-                    //付费用户数
-                    'year_recharge_user_num' => (int)DB::table('orders')
-                        ->where('send_order_id',$item['send_order_id'])
-                        ->distinct('uid')->where('order_type','YEAR')
-                        ->where('created_at','<',$end_time)
-                        ->where('status','PAID')
-                        ->count(),
-                    'ticket_recharge_user_num' => (int)DB::table('orders')
-                        ->where('send_order_id',$item['send_order_id'])
-                        ->distinct('uid')->where('order_type','RECHARGE')
-                        ->where('created_at','<',$end_time)
-                        ->where('status','PAID')
-                        ->count(),
-                    'pay_user_num' => (int)DB::table('orders')
-                        ->where('send_order_id',$item['send_order_id'])
-                        ->distinct('uid')
-                        ->where('status','PAID')
-                        ->where('created_at','<',$end_time)
-                        ->count(),
-                    'first_recharge_amount' => $item['first_recharge_amount'] + $yest_data->first_recharge_amount,
-                    'first_recharge_user_num' => $item['first_recharge_user_num'] + $yest_data->first_recharge_user_num,
-                    'year_paid_num' => $item['year_paid_num'] + $yest_data->year_paid_num,
-                    'year_unpaid_num' => $item['year_unpaid_num'] + $yest_data->year_unpaid_num,
-                    'force_user_num' => $item['force_user_num'] + $yest_data->force_user_num,
-                    'register_user_num' =>$item['register_user_num'] + $yest_data->register_user_num,
-                    'distribution_channel_name' => $item['distribution_channel_name'],
-                    'charge_type' => $item['charge_type'],
-                    'name' => $item['name'],
-                    'create_time' => $item['create_time']
-                );
-            }else{
-                $save_data = array(
-                    'send_order_id' => $item['send_order_id'],
-                    'book_name' => $item['book_name'],
-                    'bid'   => $item['bid'],
-                    'uv' => $item['uv'] ,
-                    'pv' => $item['pv'] ,
-                    'recharge_amount' => $item['recharge_amount'],
-                    'paid_num' => $item['paid_num'],
-                    'unpaid_num' => $item['unpaid_num'],
-                    'distribution_channel_id' => $item['distribution_channel_id'],
-                    'recharge_amount_in_half_day' => $item['recharge_amount_in_half_day'],
-                    'recharge_amount_in_one_day' => $item['recharge_amount_in_one_day'],
-                    'recharge_amount_in_two_weeks' => $item['recharge_amount_in_two_weeks'],
-                    'recharge_amount_in_three_days' => $item['recharge_amount_in_three_days'],
-
-                    'send_time' => $item['send_time'],
-                    'cost' => $item['cost'],
-
-                    //付费用户数
-                    'year_recharge_user_num' => (int)DB::table('orders')
-                        ->where('send_order_id',$item['send_order_id'])
-                        ->distinct('uid')->where('order_type','YEAR')
-                        ->where('created_at','<',$end_time)
-                        ->where('status','PAID')
-                        ->count(),
-                    'ticket_recharge_user_num' => (int)DB::table('orders')
-                        ->where('send_order_id',$item['send_order_id'])
-                        ->distinct('uid')->where('order_type','RECHARGE')
-                        ->where('created_at','<',$end_time)
-                        ->where('status','PAID')
-                        ->count(),
-                    'pay_user_num' => (int)DB::table('orders')
-                        ->where('send_order_id',$item['send_order_id'])
-                        ->distinct('uid')
-                        ->where('status','PAID')
-                        ->where('created_at','<',$end_time)
-                        ->count(),
-                    'first_recharge_amount' => $item['first_recharge_amount'],
-                    'first_recharge_user_num' => $item['first_recharge_user_num'],
-                    'year_paid_num' => $item['year_paid_num'],
-                    'year_unpaid_num' => $item['year_unpaid_num'],
-                    'force_user_num' => $item['force_user_num'],
-                    'register_user_num' =>$item['register_user_num'],
-                    'distribution_channel_name' => ChannelService::getChannelCompanyNameById($item['distribution_channel_id']),
-                    'charge_type' => $item['charge_type'],
-                    'name' => $item['name'],
-                    'create_time' => $item['create_time']
-                );
-            }
-            SendOrderStat::updateOrCreate(['send_order_id'=>$item['send_order_id']],$save_data);
-        }
-    }
-
-    static function generateStatsByChunk(){
-        $fields = DB::raw("send_order_id,max(date) max_date,book_name,bid,sum(uv) sum_uv,sum(pv) sum_pv,sum(recharge_amount) sum_recharge_amount,sum(paid_num) sum_paid_num,sum(unpaid_num) sum_unpaid_num,
-        distribution_channel_id,max(recharge_amount_in_half_day) max_recharge_amount_in_half_day,max(recharge_amount_in_one_day) max_recharge_amount_in_one_day,max(recharge_amount_in_two_weeks) max_recharge_amount_in_two_weeks,
-        max(recharge_amount_in_three_days) max_recharge_amount_in_three_days,max(recharge_amount_in_one_day) max_recharge_amount_in_one_day,send_time,cost,sum(year_recharge_user_num) sum_year_recharge_user_num,
-        sum(ticket_recharge_user_num) sum_ticket_recharge_user_num,sum(first_recharge_amount) sum_first_recharge_amount, sum(first_recharge_user_num) sum_first_recharge_user_num,sum(year_paid_num) sum_year_paid_num,
-        sum(year_unpaid_num) sum_year_unpaid_num,sum(pay_user_num) sum_pay_user_num,sum(force_user_num) sum_force_user_num,sum(register_user_num) sum_register_user_num,distribution_channel_name,charge_type,name,create_time");
-        DB::table('send_orders_force_day_stats')
-            ->select($fields)
-            ->groupBy('send_order_id')
-            ->orderBy('send_order_id')
-            ->chunk(1000,function($stats){
-                foreach ($stats as $stat)
-                {
-                    $end_time = date("Y-m-d",strtotime($stat->max_date)+86400);
-                    $data = [];
-                    $data['send_order_id'] = $stat->send_order_id;
-                    $data['book_name'] = $stat->book_name;
-                    $data['bid'] = $stat->bid;
-                    $data['uv'] = $stat->sum_uv;
-                    $data['pv'] = $stat->sum_pv;
-                    $data['recharge_amount'] = $stat->sum_recharge_amount;
-                    $data['paid_num'] = $stat->sum_paid_num;
-                    $data['unpaid_num'] = $stat->sum_unpaid_num;
-
-                    $data['distribution_channel_id'] = $stat->distribution_channel_id;
-                    $data['recharge_amount_in_half_day'] = $stat->max_recharge_amount_in_half_day;
-                    $data['recharge_amount_in_one_day'] = $stat->max_recharge_amount_in_one_day;
-                    $data['recharge_amount_in_two_weeks'] = $stat->max_recharge_amount_in_two_weeks;
-                    $data['recharge_amount_in_three_days'] = $stat->max_recharge_amount_in_three_days;
-                    $data['recharge_amount_in_one_day'] = $stat->max_recharge_amount_in_one_day;
-                    $data['send_time'] = $stat->send_time;
-                    $data['cost'] = $stat->cost;
-
-                    //付费用户数
-                    $data['year_recharge_user_num'] = (int)DB::table('orders')
-                        ->where('send_order_id', $stat->send_order_id)
-                        ->distinct('uid')->where('order_type', 'YEAR')
-                        ->where('created_at', '<', $end_time)
-                        ->where('status', 'PAID')
-                        ->count();
-                    $data['ticket_recharge_user_num'] = (int)DB::table('orders')->where('send_order_id', $stat->send_order_id)->distinct('uid')->where('order_type', 'RECHARGE')->where('created_at', '<', $end_time)->where('status', 'PAID')->count();
-
-                    $data['pay_user_num'] = (int)DB::table('orders')->where('send_order_id', $stat->send_order_id)->distinct('uid')->where('status', 'PAID')->where('created_at', '<', $end_time)->count();
-
-                    $data['first_recharge_amount'] = $stat->sum_first_recharge_amount;
-                    $data['first_recharge_user_num'] = $stat->sum_first_recharge_user_num;
-                    $data['year_paid_num'] = $stat->sum_year_paid_num;
-                    $data['year_unpaid_num'] = $stat->sum_year_unpaid_num;
-                    $data['force_user_num'] = $stat->sum_force_user_num;
-                    $data['register_user_num'] = $stat->sum_register_user_num;
-                    $data['distribution_channel_name'] = $stat->distribution_channel_name;
-                    $data['charge_type'] = $stat->charge_type;
-                    $data['name'] = $stat->name;
-                    $data['create_time'] = $stat->create_time;
-
-                    SendOrderStat::generateStat($data);
-                }
-            });
-    }
-
-    public static function getSendOrdersRechargeDetail($distribution_channels)
-    {
-        return SendOrderStat::getBookSendOrdersRechargeStats($distribution_channels);
-    }
-
-    public static function exportSendOrdersRechargeDetail($distribution_channels)
-    {
-        return SendOrderStat::exportBookSendOrdersRechargeStats($distribution_channels);
-    }
-
-    static function getChannelPromotionBook($channels, $params, $isAll = false)
-    {
-        $orderBy = 'register_user_num';
-        $obj = SendOrderStat::select(
-            DB::raw('date(send_orders_stats.send_time) as date'),
-            'send_orders_stats.book_name',
-            'send_orders_stats.bid',
-            "channel_users.company_name",
-            "channel_users.company_id",
-            DB::raw('sum(register_user_num) as register_user_num'),
-            DB::raw('sum(uv_one_day) as uv_one_day'),
-            DB::raw('sum(uv_three_day) as uv_three_day'),
-            DB::raw('sum(recharge_amount_in_three_days) as recharge_amount_in_three_days'),
-            DB::raw('sum(recharge_amount_in_one_day) as recharge_amount_in_one_day'),
-            DB::raw('sum(recharge_amount_in_one_day)/sum(uv_one_day) as percent_recharge_devide_uv'),
-            DB::raw('sum(recharge_amount_in_three_days)/sum(uv_three_day) as percent_recharge_devide_uv_three_day')
-
-        )
-            ->join("distribution_channels", 'send_orders_stats.distribution_channel_id', "=", "distribution_channels.id")
-            ->join("channel_users", 'distribution_channels.channel_user_id', "=", "channel_users.id")
-            ->join('send_order_extra_stats', 'send_orders_stats.send_order_id', '=', 'send_order_extra_stats.send_order_id')
-            ->groupBy('channel_users.company_id')
-            ->groupBy('send_orders_stats.book_name')
-            ->groupBy(DB::raw('date(send_orders_stats.send_time)'));
-
-        if ($channels) {
-            $obj->whereIn('send_orders_stats.distribution_channel_id', $channels);
-        }
-
-        if (isset($params['company_name']) && $params['company_name']) {
-            $obj->where('channel_users.company_name', $params['company_name']);
-        }
-
-        if (isset($params['book_name']) && $params['book_name']) {
-            $obj->where('send_orders_stats.book_name', 'like', '%' . $params['book_name'] . '%');
-        }
-
-        if (isset($params['begin_date']) && $params['begin_date']) {
-            $obj->where(DB::raw('date(send_orders_stats.send_time)'), '>=', $params['begin_date']);
-        }
-
-        if (isset($params['end_date']) && $params['end_date']) {
-            $obj->where(DB::raw('date(send_orders_stats.send_time)'), '<=', $params['end_date']);
-        }
-
-        if (isset($params['orderBy']) && $params['orderBy']) {
-            if ($params['orderBy'] == 'register_user_num') {
-                $orderBy = 'register_user_num';
-            }
-
-            if ($params['orderBy']== 'percent_recharge_devide_uv') {
-                $orderBy = 'percent_recharge_devide_uv';
-            }
-
-            if ($params['orderBy']== 'percent_recharge_devide_uv_three_day') {
-                $orderBy = 'percent_recharge_devide_uv_three_day';
-            }
-        }
-
-        $obj->orderBy($orderBy, 'desc');
-        if ($isAll) {
-            return $obj->get();
-        } else {
-            return $obj->paginate();
-        }
-    }
 }

+ 1 - 10
app/Modules/Statistic/Services/WapVisitStatService.php

@@ -157,16 +157,7 @@ class WapVisitStatService
         return $data;
     }
 
-    //获取推广总uv、pv
-    public static function getChannelPromotionTotalUvPv($distribution_channel_id, $date)
-    {
-        $sql_format = "select sum(wap_visit_stats.uv) as uv,sum(wap_visit_stats.pv) as pv from send_orders  join wap_visit_stats on send_orders.id=wap_visit_stats.key and wap_visit_stats.type=3 and wap_visit_stats.from_type='send_orders' and wap_visit_stats.day='%s' where distribution_channel_id=%d";
-        $sql = sprintf($sql_format, $date, $distribution_channel_id);
-        $res = DB::select($sql);
-        $uv = $res[0]->uv;
-        $pv = $res[0]->pv;
-        return compact('uv', 'pv');
-    }
+
 
     /**
      *获取site下的uv,pv

+ 0 - 190
app/Modules/Trade/Services/OrderDayStatService.php

@@ -1,190 +0,0 @@
-<?php
-/**
- * Created by PhpStorm.
- * User: hp
- * Date: 2017/11/21
- * Time: 10:42
- */
-
-namespace App\Modules\Trade\Services;
-use App\Modules\Trade\Services\OrderService;
-use App\Modules\OfficialAccount\Services\ForceSubscribeService;
-use App\Modules\SendOrder\Services\SendOrderService;
-use App\Modules\User\Services\UserService;
-use App\Modules\Trade\Models\OrderDayStat;
-use DB;
-
-class OrderDayStatService
-{
-
-    //创建日统计数据
-    //'distribution_channel_id', 'date','pay_success_user_num', 'ticket_recharge_user_num', 'year_recharge_user_num', 'total_recharge_amount','unpaid_num','paid_num','current_month_unpaid_num','promotion_total_uv','promotion_total_pv','force_user_num'
-    static function add($distribution_channel_id, $channel_user_id, $date, $distribution_channel_name,$real_reg_num)
-    {
-        $data = [];
-        $data['channel_user_id'] = $channel_user_id;
-        $data['distribution_channel_id'] = $distribution_channel_id;
-        $data['distribution_channel_name'] = $distribution_channel_name;
-        $data['date'] = $date;
-        $data['month'] = date("Y-m",strtotime($date));
-        $data['pay_success_user_num'] = OrderService::getDayPayUserNumByChannelId($distribution_channel_id, $date);//付费总用户数
-        $data['ticket_recharge_user_num'] = OrderService::getDayRechargePayUserNumByChannelId($distribution_channel_id, $date);//ticket_recharge_user_num
-        $data['year_recharge_user_num'] = OrderService::getDayVipPayUserNumByChannelId($distribution_channel_id, $date);//year_recharge_user_num
-        
-        $end_time = date('Y-m-d H:i:s',strtotime($date) + 86400-1);
-        $data['total_recharge_amount'] = OrderService::getAmount(['distribution_channel_id'=>$distribution_channel_id,'begin_time'=>$date,'end_time'=>$end_time]);//total_recharge_amount
-        
-        $order_info = OrderService::getChannelDateOrderInfo($distribution_channel_id,$date);
-        $data['unpaid_num'] = $order_info['total_num'] - $order_info['paid_number'];
-        $data['paid_num'] = $order_info['paid_number'];
-
-        $uv_pv = SendOrderService::getChannelPromotionTotalUvPv($distribution_channel_id,$date);
-        $data['promotion_total_uv'] = $uv_pv['uv'];
-        $data['promotion_total_pv'] = $uv_pv['pv'];
-
-        $data['force_user_num'] = ForceSubscribeService::forceSubscribeUserCountByChannelIdAndDate($distribution_channel_id,$date,'');
-
-        //普通充值数据
-        $ticket_recharge_data = OrderService::getChannelDayTicketRechargeData($distribution_channel_id, $date);
-        $data['ticket_recharge_paid_num'] = $ticket_recharge_data['ticket_recharge_paid_num'];
-        $data['ticket_recharge_unpaid_num'] = $ticket_recharge_data['ticket_recharge_unpaid_num'];
-        $data['ticket_recharge_amount'] =  $ticket_recharge_data['ticket_recharge_amount'];
-
-        //包年充值数据
-        $year_recharge_data = OrderService::getChannelDayYearRechargeData($distribution_channel_id, $date);
-        $data['year_recharge_paid_num'] = $year_recharge_data['year_recharge_paid_num'];
-        $data['year_recharge_unpaid_num'] = $year_recharge_data['year_recharge_unpaid_num'];
-        $data['year_recharge_amount'] = $year_recharge_data['year_recharge_amount'];
-
-        //派单数
-        $data['send_order_num'] = SendOrderService::getChannelPromotionCount($distribution_channel_id, $date, $end_time);
-
-        //实际派单数
-        $data['real_send_order_num'] = SendOrderService::getChannelRealPromotionCount($distribution_channel_id, $date, $end_time);
-
-        //注册用户数
-        $data['register_user_num'] = UserService::getChannelDayTotal($distribution_channel_id,$date);
-
-        //实际注册用户数
-        $data['real_register_user_num'] = $real_reg_num;
-
-        //注册用户当日充值数据
-        $reg_user_data = DB::select("select count(distinct uid) num,sum(price) amount from orders,users where orders.distribution_channel_id = '{$distribution_channel_id}' and orders.created_at > '{$date}' and orders.created_at <= '{$end_time}' and status ='PAID' and users.id = orders.uid and users.created_at > '{$date}' and users.created_at < '{$end_time}'");
-        $data['reg_user_first_recharge_amount'] = (float)$reg_user_data[0]->amount;
-        $data['reg_user_first_recharge_user_num'] = (float)$reg_user_data[0]->num;
-
-        //渠道方通道充值总额
-        $not_in_pay_merchant_ids = env('not_in_pay_merchant_id');
-        if($not_in_pay_merchant_ids)
-        {
-            $channel_merchant_recharge_amount = DB::select("select sum(price) amount from orders where distribution_channel_id = '{$distribution_channel_id}' and created_at > '{$date}' and created_at <= '{$end_time}' and status ='PAID' and pay_merchant_id in ({$not_in_pay_merchant_ids})");
-        }
-        $data['channel_merchant_recharge_amount'] = (float)$channel_merchant_recharge_amount[0]->amount;
-
-        //首充数据
-        $first_recharge_data = OrderService::getChannelDayFirstRechargeData($distribution_channel_id,$date);
-        $data['first_recharge_user_num'] = $first_recharge_data['count'];
-        $data['first_recharge_amount'] = $first_recharge_data['amount'];
-        
-        //获取前天用户充值
-        $dayBeforeYesDay = OrderDayStat::where('distribution_channel_id',$distribution_channel_id)
-            ->where('date',date('Y-m-d',strtotime($date.' -1 day')))
-            ->first();
-        //\Log::info(date('Y-m-d',strtotime($date.' -1 day')));
-        if($dayBeforeYesDay){
-            $dayBeforeYesDay = $dayBeforeYesDay->total_recharge_amount;
-            $dayBeforeYesDayReal = OrderService::getAmount(['distribution_channel_id'=>$distribution_channel_id,'begin_time'=>date('Y-m-d',strtotime($date.' -1 day')),'end_time'=>date('Y-m-d',strtotime($date.' -1 day')).' 23:59:59']);
-            $diff = $dayBeforeYesDayReal-$dayBeforeYesDay;
-            if($diff>0){
-                $data['total_recharge_amount'] +=$diff;
-                \Log::info('distribution_channel_recharge_regards_as_next_day_for_order_day_stats:distribution:'.$distribution_channel_id.':date:'.$date.':diff:'.$diff);
-            }
-        }
-        return OrderDayStat::add($data);
-    }
-
-    /**
-     * 查询日统计
-     * @param  $params $distribution_channel_id
-     */
-    static function search($params, $is_all=false)
-    {
-        return OrderDayStat::search($params, $is_all);
-    }
-    
-    /**
-     * 账户级别查询日统计
-     * @param  $params $distribution_channel_id
-     */
-    static function accountSearch($params, $is_all=false)
-    {
-    	return OrderDayStat::accountSearch($params, $is_all);
-    }
-
-    /**
-     * 获取渠道汇总统计
-     */
-    static function getSumByChannelId($distribution_channel_id)
-    {
-        return OrderDayStat::getSumByChannelId($distribution_channel_id);
-    }
-
-    /**
-     * 获取昨日渠道汇总统计
-     */
-    static function getYesterdaySumByChannelId($distribution_channel_id)
-    {
-        return OrderDayStat::getYesterdaySumByChannelId($distribution_channel_id);
-    }
-
-    /**
-     * 获取当月渠道汇总统计
-     */
-    static function getCurrentMonthSumByChannelId($distribution_channel_id)
-    {
-        return OrderDayStat::getCurrentMonthSumByChannelId($distribution_channel_id);
-    }
-
-    /**
-     * 获取上月渠道汇总统计
-     */
-    static function getLastMonthSumByChannelId($distribution_channel_id)
-    {
-        return OrderDayStat::getLastMonthSumByChannelId($distribution_channel_id);
-    }
-
-    /**
-     * 根据渠道获取合计
-     */
-    static function getStatByChannel($params)
-    {
-        return OrderDayStat::getStatByChannel($params);
-    }
-
-    /**
-     *
-     */
-    static function getAllGroupbyMonth()
-    {
-        return OrderDayStat::getAllGroupbyMonth();
-    }
-
-    static function getAllGroupbyMonthChannel($params,$is_all=false)
-    {
-        return OrderDayStat::getAllGroupbyMonthChannel($params,$is_all);
-    }
-
-
-    /**
-     * 获取外部渠道充值数据
-     * @param array $params
-     * @param bool $isAll
-     */
-    static function getOutPayData($params = [], $isAll = false) {
-        return OrderDayStat::getOutPayData($params, $isAll);
-    }
-
-    static function getRechargeByChannels($distribution_channels,$time_range){
-        return OrderDayStat::getRechargeByChannels($distribution_channels,$time_range);
-    }
-}

+ 1 - 199
app/Modules/User/Services/ReadRecordService.php

@@ -88,31 +88,6 @@ class ReadRecordService
 
     private static $not_uid_key = ['last_read', 'send_order_id', 'sign_count', 'sign_counts', 'sign_info', 'sign_day', 'smart_push', 'inner_send_order_id', 'gxhp', 'property', 'bind_phone_status', 'ua', 'sign_version', 'new_outer', 'new_inner', 'new_total', 'next_push_hour', 'person_account_id'];
 
-    /**
-     * 获取
-     * @param $uid
-     * @return array
-     */
-    public static function getReadRecord_($uid)
-    {
-        $read_bids = Redis::hgetall('book_read:' . $uid);
-        $res       = [];
-        $i         = 0;
-        foreach ($read_bids as $key => $v) {
-            $record           = explode('_', $v);
-            $latest_read_cid  = $record[0];
-            $book_name        = $record[1];
-            $chapter_name     = $record[2];
-            $latest_read_time = $record[count($record) - 1];
-            $res[$i]          = ['book_name' => $book_name, 'bid' => $key, 'cid' => (int)$latest_read_cid, 'time' => (int)$latest_read_time, 'chapter_name' => $chapter_name];
-            $i++;
-        }
-        usort($res, function ($a, $b) {
-            if ($a['time'] >= $b['time']) return -1;
-            return 1;
-        });
-        return $res;
-    }
 
 
     /**
@@ -120,7 +95,7 @@ class ReadRecordService
      * @param $uid
      * @return array
      */
-    public static function getReadRecord($uid, $is_need_check_db = false)
+    public static function getReadRecord($uid)
     {
         self::delTheLastRecord($uid);
         $read_bids = Redis::hgetall('book_read:' . $uid);
@@ -155,25 +130,6 @@ class ReadRecordService
         return collect($res)->sortByDesc('time')->values()->all();
     }
 
-    /**
-     * 新增
-     * @param $uid
-     * @param $bid
-     * @param $cid
-     * @param $book_name
-     * @param $chapter_name
-     */
-    public static function addReadRecord_($param)
-    {
-        $uid          = $param['uid'];
-        $bid          = $param['bid'];
-        $cid          = $param['cid'];
-        $book_name    = $param['book_name'];
-        $chapter_name = $param['chapter_name'];
-        Redis::hset('book_base:' . $uid, 'last_read', "{$bid}_{$cid}_{$book_name}_{$chapter_name}_" . time());
-        //Redis::hset('book_read:'.$uid, $bid, $cid."_".time());
-        Redis::hset('book_read:' . $uid, $bid, "{$cid}_{$book_name}_{$chapter_name}_" . time());
-    }
 
     /**
      * 添加阅读记录升级版
@@ -212,36 +168,6 @@ class ReadRecordService
     }
 
     /**
-     * 获取最近一条阅读记录
-     * @param $uid
-     */
-    public static function getFirstReadRecord_($uid)
-    {
-        $all = self::getReadRecord($uid);
-        if (empty($all)) return [];
-        $first = $all[0];
-        if (!$first) return [];
-        if (!isset($first['bid'])) return [];
-        try {
-            //$bid = Hashids::encode($first['bid']);
-            $bid       = $first['bid'];
-            $book_info = BookConfigService::getBookById($bid);
-            $cid       = $first['cid'];
-            $book_name = $first['book_name'];
-            $res       = [
-                'url'          => '/reader?bid=' . $bid . '&cid=' . $cid,
-                'book_name'    => $book_name,
-                'cover'        => $book_info->cover,
-                'channel_name' => $book_info->channel_name,
-            ];
-        } catch (\Exception $e) {
-            $res = [];
-        }
-
-        return $res;
-    }
-
-    /**
      * 获取最近一条阅读记录(升级版)
      * @param $uid
      * @return array
@@ -291,15 +217,6 @@ class ReadRecordService
         return 0;
     }
 
-    /**
-     * 获取客服消息点击数
-     * @param $uid
-     */
-    public static function getCustomerMsgClickNum($channel_id, $from, $date)
-    {
-        $key = "fromcustomermsgenter:distribution_channel_id:" . $channel_id . 'from:' . $from;
-        return Redis::hget($key, $date);
-    }
 
     /**
      * 获取某本书的阅读记录
@@ -355,42 +272,6 @@ class ReadRecordService
         return $chapter_name;
     }
 
-    /**
-     * 删除阅读记录中的书名和章节名
-     * @param $uid
-     * @param $record
-     */
-    public static function delBookNameAndChapter($uid)
-    {
-        $base_record = Redis::hget('book_base:' . $uid, 'last_read');
-        if ($base_record) {
-            $record_arr = explode('_', $base_record);
-            $c          = count($record_arr);
-            if ($c > 3) {
-                $bid  = $record_arr[0];
-                $cid  = $record_arr[1];
-                $time = $record_arr[$c - 1];
-                Redis::hset('book_base:' . $uid, 'last_read', "{$bid}_{$cid}_" . $time);
-            }
-        }
-        $records = Redis::hgetall('book_read:' . $uid);
-        foreach ($records as $key => $v) {
-            $record = explode('_', $v);
-            $count  = count($record);
-            if ($count > 3) {
-                $latest_read_cid  = $record[0];
-                $book_name        = $record[1];
-                $chapter_name     = $record[2];
-                $latest_read_time = $record[$count - 1];
-                Redis::hset('book_read:' . $uid, $key, "{$latest_read_cid}_" . $latest_read_time);
-
-                $book_key    = 'wap:string:book:' . $key;
-                $chapter_key = 'wap:string:chapter:' . $latest_read_cid;
-                Redis::set($book_key, $book_name);
-                Redis::set($chapter_key, $chapter_name);
-            }
-        }
-    }
 
     public static function delBookBase($uid)
     {
@@ -423,20 +304,6 @@ class ReadRecordService
     }
 
 
-    public static function ReadRecordStatistical(int $uid, int $distribution_channel_id, string $from)
-    {
-        try {
-            DB::table('temp_read_active')->insert([
-                'uid'                     => $uid,
-                'distribution_channel_id' => $distribution_channel_id,
-                'from'                    => $from,
-                'created_at'              => date('Y-m-d H:i:s'),
-                'updated_at'              => date('Y-m-d H:i:s'),
-            ]);
-        } catch (\Exception $e) {
-        }
-    }
-
     /**
      * 获取当前的send_order_id
      * @param int $uid
@@ -454,37 +321,6 @@ class ReadRecordService
     }
 
     /**
-     * 设置内部派单
-     * @param $uid
-     * @param $inner_order_id
-     */
-    public static function setInnerSendOrderId($uid, $inner_order_id)
-    {
-        try {
-            Redis::hset('book_read:' . $uid, 'inner_send_order_id', $inner_order_id);
-        } catch (\Exception $e) {
-        }
-    }
-
-    /**
-     * 获取内部派单
-     * @param $uid
-     * @return string
-     */
-    public static function getInnerSendOrderId($uid)
-    {
-        try {
-            $inner_send_order_id = Redis::hget('book_read:' . $uid, 'inner_send_order_id');
-            if ($inner_send_order_id) {
-                return $inner_send_order_id;
-            }
-            return '';
-        } catch (\Exception $e) {
-        }
-        return '';
-    }
-
-    /**
      * 签到日期
      * @param int $uid
      * @return mixed
@@ -567,26 +403,7 @@ class ReadRecordService
         Redis::hset('book_read:' . $uid, 'sign_info', $info);
     }
 
-    public static function setSmartPush($uid, $bid)
-    {
-        $old = self::getSmartPush($uid);
-        if ($old && !in_array($bid, $old)) {
-            array_push($old, $bid);
-            $bid_str = implode(',', $old);
-            return Redis::hset('book_read:' . $uid, 'smart_push', $bid_str);
-        } else {
-            return Redis::hset('book_read:' . $uid, 'smart_push', $bid);
-        }
-    }
 
-    public static function getSmartPush(int $uid): array
-    {
-        $res = Redis::hget('book_read:' . $uid, 'smart_push');
-        if ($res) {
-            return explode(',', $res);
-        }
-        return [];
-    }
 
     public static function getByField(int $uid, $field)
     {
@@ -634,21 +451,6 @@ class ReadRecordService
     }
 
 
-    private static function resetRecordFromDB($uid)
-    {
-        if (self::getByField($uid, 'last_read')) {
-            return;
-        }
-        $record = ReadRecordFromRedis::where('uid', $uid)->select('field', 'value')->get();
-        if ($record->isNotEmpty()) {
-            foreach ($record as $item) {
-                if (!in_array($item->field, self::$not_uid_key) || $item->field == 'last_read') {
-                    Redis::hset('book_read:' . $uid, $item->field, $item->value);
-                }
-            }
-        }
-    }
-
     //删除多余的阅读纪律
     public static function delTheLastRecord($uid)
     {