WapVisitStatService.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: z_yang
  5. * Date: 2018/03/09
  6. * Time: 20:18
  7. */
  8. namespace App\Modules\Statistic\Services;
  9. use App\Modules\Statistic\Models\WapVisitStat;
  10. use App\Modules\SendOrder\Models\SendOrder;
  11. use App\Modules\Subscribe\Services\OrderService;
  12. use DB;
  13. use Redis;
  14. class WapVisitStatService
  15. {
  16. /**
  17. * 获取派单总pv
  18. * @param int $id
  19. */
  20. public static function getSendOrderTotalPv($id)
  21. {
  22. //return (int)Redis::hget('send_order_pv_' . $id, 'total');
  23. $today = (int)Redis::hget('send_order_pv_'.$id,date('Y-m-d'));
  24. $old = (int)WapVisitStat::where('key', $id)->where('type', 3)->where('from_type','send_orders')->sum('pv');
  25. return $today+$old;
  26. }
  27. /**
  28. * 获取浏览器派单总pv uv
  29. * @param $id
  30. * @return array
  31. */
  32. public static function getBrowserSendOrderTotalPvAndUv($id):array
  33. {
  34. $sql_format = "select sum(pv) as pv,sum(uv) as uv from wap_visit_stats WHERE `key`=%s and from_type='%s' and `type`=3 ";
  35. $sql = sprintf($sql_format, $id, 'browser_send_orders');
  36. $today_pv = (int)Redis::hget('browser_send_order_pv_' . $id, date('Y-m-d'));
  37. $today_uv = (int)Redis::hget('browser_send_order_uv_' . $id, date('Y-m-d'));
  38. $res = DB::select($sql);
  39. $uv = (int)$res[0]->uv + $today_uv;
  40. $pv = (int)$res[0]->pv + $today_pv;
  41. return compact('uv', 'pv');
  42. }
  43. /**
  44. * 获取派单总pv
  45. * @param $id int
  46. */
  47. public static function getSendOrderTotalUv($id)
  48. {
  49. //return (int)Redis::hget('send_order_uv_' . $id, 'total');
  50. $today = (int)Redis::hget('send_order_uv_'.$id,date('Y-m-d'));
  51. $old = WapVisitStat::where('key', $id)->where('type', 3)->where('from_type','send_orders')->sum('uv');
  52. return $today+$old;
  53. }
  54. /**
  55. * 获取活动的pv uv
  56. * @param int $channel_id
  57. * @param int $activity_id
  58. * @return array
  59. */
  60. public static function getActivityUvAndPv(int $channel_id, int $activity_id):array
  61. {
  62. $day = date('Y-m-d');
  63. $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
  64. $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
  65. $sql_format = "select sum(pv) as pv,sum(uv) as uv from wap_visit_stats WHERE `key`=%s and from_type='%s' and `day` >= '2018-01-10' and type=2 ";
  66. $sql = sprintf($sql_format, $channel_id, $activity_id);
  67. $res = DB::select($sql);
  68. $today_pv = (int)Redis::hget(sprintf($pv_key_format, $activity_id, $channel_id), $day);
  69. $today_uv = (int)Redis::scard(sprintf($uv_key_format, $activity_id, $channel_id, $day));
  70. $uv = $res[0]->uv + $today_uv;
  71. $pv = $res[0]->pv + $today_pv;
  72. return compact('uv', 'pv');
  73. }
  74. /**
  75. * 获取活动的pv uv
  76. * @param int $channel_id
  77. * @param int $activity_id
  78. * @param string $day
  79. * @return array
  80. */
  81. public static function getActivityUvAndPvByDay(int $channel_id, int $activity_id, string $day):array
  82. {
  83. $sql_format = "select sum(pv) as pv,sum(uv) as uv from wap_visit_stats WHERE `key`=%s and from_type='%s' and `day` = '%s' and type=2 ";
  84. $sql = sprintf($sql_format, $channel_id, $activity_id, $day);
  85. $res = DB::select($sql);
  86. $uv = $res[0]->uv;
  87. $pv = $res[0]->pv;
  88. return compact('uv', 'pv');
  89. }
  90. /**
  91. * 获取派单每一天的Uv信息列表
  92. * @param $id int
  93. * @return array UV
  94. */
  95. public static function getSendOrderUv($id)
  96. {
  97. $now = date('Y-m-d');
  98. $res = WapVisitStat::where('key', $id)->where('type', 3)->where('from_type', 'send_orders')->select('day', 'uv')->get();
  99. $data = [];
  100. $total = 0;
  101. if ($res) {
  102. foreach ($res as $v) {
  103. $data[$v->day] = $v->uv;
  104. $total += $v->uv;
  105. }
  106. $data['total'] = $total;
  107. }
  108. $today = (int)Redis::hget('send_order_uv_' . $id, $now);
  109. $data[$now] = $today;
  110. return $data;
  111. }
  112. /**
  113. * 获取派单某一天的UvPV
  114. * @param $id int
  115. * @return array UvPV
  116. */
  117. public static function getSendOrderDayUvPvFromStat($id,$date)
  118. {
  119. $res = WapVisitStat::where('key', $id)->where('type', 3)->where('from_type', 'send_orders')->where('day',$date)->select('uv','pv')->first();
  120. $uv = $res ? $res->uv : 0;
  121. $pv = $res ? $res->pv : 0;
  122. return compact('uv','pv');
  123. }
  124. /**
  125. * 获取每一天的pv信息列表
  126. * @param $id int
  127. * @return array $data
  128. */
  129. public static function getSendOrderPv($id)
  130. {
  131. $now = date('Y-m-d');
  132. $res = WapVisitStat::where('key', $id)->where('type', 3)->where('from_type', 'send_orders')->select('day', 'pv')->get();
  133. $data = [];
  134. $total = 0;
  135. if ($res) {
  136. foreach ($res as $v) {
  137. $data[$v->day] = $v->pv;
  138. $total += $v->pv;
  139. }
  140. $data['total'] = $total;
  141. }
  142. $today = (int)Redis::hget('send_order_pv_' . $id, $now);
  143. $data[$now] = $today;
  144. return $data;
  145. }
  146. //获取推广总uv、pv
  147. public static function getChannelPromotionTotalUvPv($distribution_channel_id, $date)
  148. {
  149. $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";
  150. $sql = sprintf($sql_format, $date, $distribution_channel_id);
  151. $res = DB::select($sql);
  152. $uv = $res[0]->uv;
  153. $pv = $res[0]->pv;
  154. return compact('uv', 'pv');
  155. }
  156. /**
  157. *获取site下的uv,pv
  158. */
  159. public static function getSitePvAndUv($distribution_channel_id, $from, $start_day, $end_day)
  160. {
  161. $res = WapVisitStat::where('key', $distribution_channel_id)
  162. ->where('type', 1)
  163. ->where('from_type', $from);
  164. if ($start_day) {
  165. $res = $res->where('day', '>=', $start_day);
  166. }
  167. if ($end_day) {
  168. $res = $res->where('day', '<=', $end_day);
  169. }
  170. $res = $res->select(DB::raw('sum(uv) as uv'), DB::raw('sum(pv) as pv'))
  171. ->get();
  172. $temp = $res->first();
  173. $pv = $temp->pv;
  174. $uv = $temp->uv;
  175. $now = date('Y-m-d');
  176. if ($end_day && $end_day == $now) {
  177. $pv += (int)Redis::hget('customer:push:click:distribution_channel_id:' . $distribution_channel_id . 'from:' . $from, $now);
  178. $uv += (int)Redis::scard('push:distribution_channel_id:' . $distribution_channel_id . 'from:' . $from . ':date:' . $now);
  179. }
  180. if (!$end_day) {
  181. $pv += (int)Redis::hget('customer:push:click:distribution_channel_id:' . $distribution_channel_id . 'from:' . $from, $now);
  182. $uv += (int)Redis::scard('push:distribution_channel_id:' . $distribution_channel_id . 'from:' . $from . ':date:' . $now);
  183. }
  184. return compact('uv', 'pv');
  185. }
  186. /**
  187. * 获取某天的uvAndpv
  188. * @param int $distribution_channel_id
  189. * @param string $from
  190. * @param string $day
  191. * @return array
  192. */
  193. public static function getSitePvAndUvOneDay(int $distribution_channel_id, string $from, string $day):array
  194. {
  195. $res = WapVisitStat::where('key', $distribution_channel_id)
  196. ->where('type', 1)
  197. ->where('from_type', $from)
  198. ->where('day', '=', $day)
  199. ->select('pv', 'uv')
  200. ->first();
  201. if ($res)
  202. return ['pv' => $res->pv, 'uv' => $res->uv];
  203. else {
  204. return ['pv' => 0, 'uv' => 0];
  205. }
  206. }
  207. /**
  208. * 获取强关前一张的uv,pv
  209. */
  210. public static function getBeforeForceSubAndBeforeVipUv($bid, $send_order_id, $date, $one_day)
  211. {
  212. if ($one_day) {
  213. $res = WapVisitStat::where('key', $bid)->where('from_type', (string)$send_order_id)->where('type', 4)->where('day', $date)->select('uv', 'pv')->first();
  214. } else {
  215. $res = WapVisitStat::where('key', $bid)
  216. ->where('from_type', (string)$send_order_id)
  217. ->where('type', 4)
  218. ->where('day', '>=', $date)
  219. ->where('day', '<=', date('Y-m-d'))
  220. ->select(DB::raw('sum(uv) as uv'), DB::raw('sum(pv) as pv'))
  221. ->get();
  222. $res = $res->first();
  223. }
  224. $beforevippv = 0;
  225. $beforevipuv = 0;
  226. if ($res) {
  227. $beforevippv = $res->pv;
  228. $beforevipuv = $res->uv;
  229. }
  230. $res = null;
  231. if ($one_day) {
  232. $res = WapVisitStat::where('key', $bid)->where('from_type', (string)$send_order_id)->where('type', 5)->where('day', $date)->select('uv', 'pv')->first();
  233. } else {
  234. $res = WapVisitStat::where('key', $bid)
  235. ->where('from_type', (string)$send_order_id)
  236. ->where('type', 5)
  237. ->where('day', '>=', $date)
  238. ->where('day', '<=', date('Y-m-d'))
  239. ->select(DB::raw('sum(uv) as uv'), DB::raw('sum(pv) as pv'))
  240. ->get();
  241. $res = $res->first();
  242. }
  243. $beforeforcesubpv = 0;
  244. $beforeforcesubuv = 0;
  245. if ($res) {
  246. $beforeforcesubpv = $res->pv;
  247. $beforeforcesubuv = $res->uv;
  248. }
  249. return compact('beforevipuv', 'beforevippv', 'beforeforcesubpv', 'beforeforcesubuv');
  250. }
  251. public static function getUvAndPVByFromAndDay($distribution_channel_id, $from, $day)
  252. {
  253. $from = array_map(function ($i) {
  254. return sprintf("'%s'", $i);
  255. }, $from);
  256. $from_str = implode(',', $from);
  257. if ($day) {
  258. if (is_string($day)) {
  259. $sql_fromat = "select sum(uv) as uv,sum(pv) as pv from wap_visit_stats where `type`=1 and `key`=%s and from_type in (%s) and `day`='%s'";
  260. $sql = sprintf($sql_fromat, $distribution_channel_id, $from_str, $day);
  261. } else {
  262. $sql_fromat = "select sum(uv) as uv,sum(pv) as pv from wap_visit_stats where `type`=1 and `key`=%s and from_type in (%s) and `day` BETWEEN '%s' and '%s'";
  263. $sql = sprintf($sql_fromat, $distribution_channel_id, $from_str, $day[0], $day[1]);
  264. }
  265. } else {
  266. $sql_fromat = "select sum(uv) as uv,sum(pv) as pv from wap_visit_stats where `type`=1 and `key`=%s and from_type in (%s)";
  267. $sql = sprintf($sql_fromat, $distribution_channel_id, $from_str);
  268. }
  269. $res = DB::select($sql);
  270. $uv = $res[0]->uv;
  271. $pv = $res[0]->pv;
  272. return compact('uv', 'pv');
  273. }
  274. public static function smartPushTestBookStats(int $bid)
  275. {
  276. $data = [
  277. 'uv' => 0,
  278. 'pv' => 0,
  279. 'charge_amount' => 0,
  280. 'charge_user_num' => 0,
  281. 'book_amount' => 0,
  282. 'book_user_num' => 0,
  283. 'real_push_user_num' => 0,
  284. 'second_chapter_uv' => 0
  285. ];
  286. if (empty($bid))
  287. return $data;
  288. $uv_key = sprintf('%s_%s_uv', $bid, 'smart_push');
  289. $db_uv = DB::table('smart_push_uv')->where('bid',$bid)->select('smart_push_uv')->first();
  290. //1
  291. $uv = (int)(Redis::scard($uv_key));
  292. if($db_uv) $uv += $db_uv->smart_push_uv;
  293. $pv = (int)Redis::hget('smart_push_test_book', $bid);
  294. $book_user_num = Redis::scard('smart_push_test_book_user_count' . $bid);
  295. $field = sprintf('%s_amount', $bid);
  296. $book_amount = Redis::hget('smart_push_test_book', $field);
  297. $real_push_user_num = (int)Redis::hget('SmartPushBookUserNum', $bid);
  298. $data['uv'] = $uv;
  299. $data['pv'] = $pv;
  300. $data['book_amount'] = $book_amount;
  301. $data['book_user_num'] = $book_user_num;
  302. $data['real_push_user_num'] = $real_push_user_num;
  303. $data['second_chapter_uv'] = (int)Redis::scard('smart_push_test_book_second_uv' . $bid);
  304. return $data;
  305. }
  306. public static function customerAllStats($from)
  307. {
  308. $uv = Redis::scard('push:distribution_channel_id:alluv:from:' . $from);
  309. $pv = Redis::hget('push:distribution_channel_id:allpv', $from);
  310. $pay_user_num = Redis::scard('push:all:paidnum:from:' . $from);
  311. $charge_amount = Redis::hget('push:all:paidamount', $from);
  312. $register_user_num = 0;
  313. return compact('uv', 'pv', 'pay_user_num', 'charge_amount', 'register_user_num');
  314. }
  315. /**
  316. * 内部派单统计
  317. * @param $from
  318. * @return array
  319. */
  320. public static function innerCustomerAllStats($from)
  321. {
  322. $uv = Redis::scard('push:inner_send_order_id:uv:' . $from);
  323. $pv = Redis::hget('push:inner_send_order_id:pv', $from);
  324. $order_info = OrderService::getInnerSendOrderStats($from);
  325. $pay_user_num = 0;
  326. $charge_amount = 0;
  327. if ($order_info) {
  328. $pay_user_num = $order_info->pay_user_num;
  329. $charge_amount = $order_info->charge_amount;
  330. }
  331. $register_user_num = 0;
  332. return compact('uv', 'pv', 'pay_user_num', 'charge_amount', 'register_user_num');
  333. }
  334. /**
  335. * 211站点特殊统计
  336. * @param int $uid
  337. * @param int $bid
  338. * @param int $send_order_id
  339. */
  340. public static function specialChannelIdStatsMarkUser(int $uid,int $bid,int $send_order_id):void
  341. {
  342. if(!$uid || !$bid || !$send_order_id){
  343. return ;
  344. }
  345. try{
  346. if(!Redis::Sismember('specialChannelIdStatsMarkUser:set:'.$uid,$bid)){
  347. Redis::sadd('specialChannelIdStatsMarkUser:set:'.$uid,$bid);
  348. $key = $uid.'-'.$bid;
  349. Redis::hset('specialChannelIdStatsMarkUser:hash:',$key,$send_order_id);
  350. }
  351. }catch (\Exception $e){}
  352. return ;
  353. }
  354. /**
  355. * 211站点特殊统计
  356. * @param int $uid
  357. * @param int $bid
  358. * @return int
  359. */
  360. public static function specialChannelIdStatsGetSendOrder(int $uid,int $bid):int{
  361. if(!$uid || !$bid ){
  362. return 0;
  363. }
  364. try{
  365. $key = $uid.'-'.$bid;
  366. $send_order_id = Redis::hget('specialChannelIdStatsMarkUser:hash:',$key);
  367. if($send_order_id) {
  368. return (int)$send_order_id;
  369. }
  370. }catch (\Exception $e){}
  371. return 0;
  372. }
  373. /**
  374. * 211站点特殊统计
  375. * @param int $uid
  376. * @param $bid
  377. * @param int $fee
  378. */
  379. public static function specialChannelIdStatsSave(int $uid,$bid,int $fee):void{
  380. if(!$uid || !$bid || !$fee){
  381. return ;
  382. }
  383. $send_order_id = self::specialChannelIdStatsGetSendOrder($uid,$bid);
  384. if(!$send_order_id){
  385. return ;
  386. }
  387. try{
  388. $day = date('Y-m-d');
  389. Redis::HINCRBY('specialChannelIdStats:hash',$send_order_id.'_'.$day,$fee);
  390. Redis::HINCRBY('specialChannelIdStats:hash',$send_order_id,$fee);
  391. $set_key = 'specialChannelIdStats:set:sendorder:%s:day:%s';
  392. Redis::sadd(sprintf($set_key,$send_order_id,$day),$uid);
  393. Redis::sadd(sprintf($set_key,$send_order_id,'all'),$uid);
  394. }catch (\Exception $e){}
  395. return ;
  396. }
  397. /**
  398. * 获取 211站点特殊统计
  399. * @param int $send_order_id
  400. * @param string $start_date
  401. * @return array
  402. */
  403. public static function getSpecialChannelIdStats(int $send_order_id,string $start_date):array{
  404. $data = [
  405. 'first_day_subscribe_num'=>0,//首日累计订阅人数
  406. 'first_day_subscribe_amount'=>0,//首日累计订阅总额
  407. 'three_day_subscribe_num'=>0,// 三日累计订阅人数
  408. 'three_day_subscribe_amount'=>0,//三日累计订阅总额
  409. 'total_subscribe_num'=>0,//累计订阅人数
  410. 'total_subscribe_amount'=>0//累计订阅总额
  411. ];
  412. if(!$send_order_id || !$start_date){
  413. return $data;
  414. }
  415. try{
  416. $set_key = 'specialChannelIdStats:set:sendorder:%s:day:%s';
  417. $data['first_day_subscribe_num'] = (int)(Redis::scard(sprintf($set_key,$send_order_id,$start_date)));
  418. $data['first_day_subscribe_amount'] = (int)(Redis::hget('specialChannelIdStats:hash',$send_order_id.'_'.$start_date));
  419. $data['total_subscribe_num'] = (int)(Redis::scard(sprintf($set_key,$send_order_id,'all')));
  420. $data['total_subscribe_amount'] = (int)(Redis::hget('specialChannelIdStats:hash',$send_order_id));
  421. $second_day = date('Y-m-d',strtotime($start_date)+86400);
  422. $three_day = date('Y-m-d',strtotime($second_day)+86400);
  423. //$second_day_subscribe_num = (int)(Redis::scrad(sprintf($set_key,$send_order_id,$second_day)));
  424. $second__day_subscribe_amount = (int)(Redis::hget('specialChannelIdStats:hash',$send_order_id.'_'.$second_day));
  425. //$three_day_subscribe_num = (int)(Redis::scrad(sprintf($set_key,$send_order_id,$three_day)));
  426. $three__day_subscribe_amount = (int)(Redis::hget('specialChannelIdStats:hash',$send_order_id.'_'.$three_day));
  427. Redis::SUNIONSTORE(
  428. 'SpecialChannelIdStatstemp',
  429. sprintf($set_key,$send_order_id,$start_date),
  430. sprintf($set_key,$send_order_id,$second_day),
  431. sprintf($set_key,$send_order_id,$three_day)
  432. );
  433. $data['three_day_subscribe_num'] = (int)( Redis::scard('SpecialChannelIdStatstemp') );
  434. Redis::del('SpecialChannelIdStatstemp');
  435. $data['three_day_subscribe_amount'] = $second__day_subscribe_amount+$three__day_subscribe_amount+$data['first_day_subscribe_amount'];
  436. }catch (\Exception $e){}
  437. return $data;
  438. }
  439. /**
  440. * 阅读器uv pv 统计
  441. * @param $uid
  442. * @param $distribution_channel_id
  443. */
  444. public static function recordReaderUvAndPv($uid,$distribution_channel_id){
  445. if(empty($uid) || empty($distribution_channel_id)){
  446. return ;
  447. }
  448. $day = date('Y-m-d');
  449. $uv_key = sprintf('readeruv:date:%s:channel_id:%s',$day,$distribution_channel_id);
  450. $pv_key = sprintf('readerpv:channel_id:%s',$distribution_channel_id);
  451. $record_key = sprintf('recordReaderUvAndPv:date:%s',$day);
  452. try{
  453. Redis::sadd($uv_key,$uid);
  454. Redis::HINCRBY($pv_key,$day,1);
  455. Redis::sadd($record_key,$distribution_channel_id);
  456. }catch (\Exception $e){
  457. }
  458. }
  459. /**
  460. * 获取阅读器uv pv 统计 ['day'=>'2018-12-25','pv'=>1,'uv'=>3];
  461. * [ ['day'=>'2018-12-25','pv'=>1,'uv'=>3], ['day'=>'2018-12-26','pv'=>2342,'uv'=>342]];
  462. * @param $distribution_channel_id
  463. * @param string $day
  464. * @return array
  465. */
  466. public static function getReaderUvAndPv($distribution_channel_id,$day=''){
  467. $pv_key = sprintf('readerpv:channel_id:%s',$distribution_channel_id);
  468. if($day){
  469. $pv = (int)Redis::hget($pv_key,$day);
  470. $uv_key = sprintf('readeruv:date:%s:channel_id:%s',$day,$distribution_channel_id);
  471. $uv = Redis::scard($uv_key);
  472. return ['day'=>$day,'pv'=>$pv,'uv'=>$uv];
  473. }
  474. $all_pv = Redis::hgetAll($pv_key);
  475. if(!$all_pv){
  476. return [];
  477. }
  478. $data = [];
  479. foreach ($all_pv as $d=>$v){
  480. $uv_key = sprintf('readeruv:date:%s:channel_id:%s',$d,$distribution_channel_id);
  481. $uv = Redis::scard($uv_key);
  482. $data[] = ['day'=>$d,'pv'=>$v,'uv'=>$uv];
  483. }
  484. return $data;
  485. }
  486. /**
  487. * 保存到数据库后,删除数据
  488. * @param $date
  489. */
  490. public static function deleteReaderUvAndPvRedisKey($date){
  491. $id_key = sprintf('recordReaderUvAndPv:date:%s',$date);
  492. $channel_ids = Redis::smembers($id_key );
  493. if($channel_ids){
  494. foreach ($channel_ids as $channel_id){
  495. $pv_key = sprintf('readerpv:channel_id:%s',$channel_id);
  496. Redis::hdel($pv_key,$date);
  497. $uv_key = sprintf('readeruv:date:%s:channel_id:%s',$date,$channel_id);
  498. Redis::del($uv_key);
  499. }
  500. }
  501. Redis::del($id_key);
  502. }
  503. public static function smartPushTestBookStatsNew(int $bid)
  504. {
  505. $data = [
  506. 'uv' => 0,
  507. 'pv' => 0,
  508. 'book_amount' => 0,//订阅
  509. 'book_user_num' => 0,
  510. 'real_push_user_num' => 0,
  511. 'first_chapter_uv'=>0,
  512. 'second_chapter_uv' =>0,
  513. 'fiftieth_chapter_uv'=>0,
  514. 'thirtieth_chapter_uv'=>0,
  515. 'chapter_uv_110'=>0,
  516. ];
  517. if (empty($bid))
  518. return $data;
  519. $uv_key = sprintf('%s_%s_uv', $bid, 'smart_push');
  520. $db_uv = DB::table('smart_push_uv')->where('bid',$bid)->select('smart_push_uv')->first();
  521. $uv = (int)(Redis::scard($uv_key));
  522. if($db_uv) $uv += $db_uv->smart_push_uv;
  523. $pv = (int)Redis::hget('smart_push_test_book', $bid);
  524. $book_user_num = Redis::scard('smart_push_test_book_user_count' . $bid);
  525. $field = sprintf('%s_amount', $bid);
  526. $book_amount = Redis::hget('smart_push_test_book', $field);
  527. $real_push_user_num = (int)Redis::hget('SmartPushBookUserNum', $bid);
  528. $key = 'smartPushTestBookChapterUv:bid:%s:seq:%s';
  529. $data['uv'] = $uv;
  530. $data['pv'] = $pv;
  531. $data['book_amount'] = $book_amount;
  532. $data['book_user_num'] = $book_user_num;
  533. $data['real_push_user_num'] = $real_push_user_num;
  534. $data['first_chapter_uv'] = (int)(Redis::scard(sprintf($key,$bid,'1')));
  535. $data['second_chapter_uv'] = (int)(Redis::scard('smart_push_test_book_second_uv' . $bid));
  536. $data['thirtieth_chapter_uv'] = (int)(Redis::scard(sprintf($key,$bid,'30')));
  537. $data['fiftieth_chapter_uv'] = (int)(Redis::scard(sprintf($key,$bid,'50')));
  538. $data['chapter_uv_110'] = (int)(Redis::scard(sprintf($key,$bid,'110')));
  539. return $data;
  540. }
  541. }