stat_daily.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  1. <?php
  2. defined('InShopNC') or exit('Access Invalid!');
  3. class stat_dailyControl extends SystemControl
  4. {
  5. public function __construct() {
  6. parent::__construct();
  7. }
  8. public function indexOp()
  9. {
  10. if (chksubmit()) {
  11. }
  12. $mod_stat = Model('stat');
  13. $stat_list = $mod_stat->statDailyList([], '*', 30);
  14. Tpl::output('page',$mod_stat->showpage());
  15. Tpl::output('dailies',$stat_list);
  16. Tpl::output('colomns',$this->daily_colomns());
  17. Tpl::showpage('stat.daily.list');
  18. }
  19. private function daily_colomns()
  20. {
  21. return ['日期','可用金额','今日发送金额','今日未领金额','今日发送个数','今日领取个数','红包支付金额','红包转发金额','红包转发次数','新增用户','总用户','日活','周活','月活','订单总数','订单总额','客单价'];
  22. }
  23. public function interactive_listOp()
  24. {
  25. $mod_stat = Model('stat');
  26. $stat_list = $mod_stat->statDailyList([], 'date_id,call_record', 30);
  27. Tpl::output('page',$mod_stat->showpage());
  28. Tpl::output('dailies',$stat_list);
  29. Tpl::output('colomns',$this->call_colomns());
  30. Tpl::showpage('stat.interactive.list');
  31. }
  32. private function call_colomns()
  33. {
  34. return ['日期','IOS','android','H5','首页','品牌页','专题','搜索','功效','商品详情','获取验证码','红包打开','发送','从红包发送','摇一摇','红包分享','邀请','收藏','我的F码','商城','我的订单','查看'];
  35. }
  36. public function interactive_goodsOp()
  37. {
  38. if(empty( $_GET['date_id'])) {
  39. $date_id = strtotime(date('Y-m-d',time()));
  40. } else {
  41. $date_id = $_GET['date_id'];
  42. }
  43. $mod_stat = Model('stat');
  44. $stat_list = $mod_stat->statDailyList(['date_id' => $date_id], 'date_id,call_record');
  45. if(empty($stat_list) || empty($stat_list[0]['call_record'])) {
  46. return;
  47. }
  48. $record = json_decode($stat_list[0]['call_record'],true);
  49. $goods = $this->all_goods($record);
  50. Tpl::output('dailies',$goods);
  51. Tpl::output('colomns',$this->goods_colomns());
  52. Tpl::showpage('stat.interactive.goods');
  53. }
  54. public function interactive_specialOp()
  55. {
  56. if(empty( $_GET['date_id'])) {
  57. $date_id = strtotime(date('Y-m-d',time()));
  58. } else {
  59. $date_id = $_GET['date_id'];
  60. }
  61. $mod_stat = Model('stat');
  62. $stat_list = $mod_stat->statDailyList(['date_id' => $date_id], 'date_id,call_record');
  63. if(empty($stat_list) || empty($stat_list[0]['call_record'])) {
  64. return;
  65. }
  66. $record = json_decode($stat_list[0]['call_record'],true);
  67. $specials = $this->all_special($record);
  68. Tpl::output('dailies',$specials);
  69. Tpl::output('colomns',$this->special_colomns());
  70. Tpl::showpage('stat.interactive.special');
  71. }
  72. public function interactive_searchOp()
  73. {
  74. if(empty( $_GET['date_id'])) {
  75. $date_id = strtotime(date('Y-m-d',time()));
  76. } else {
  77. $date_id = $_GET['date_id'];
  78. }
  79. $mod_stat = Model('stat');
  80. $stat_list = $mod_stat->statDailyList(['date_id' => $date_id], 'date_id,call_record');
  81. if(empty($stat_list) || empty($stat_list[0]['call_record'])) {
  82. return;
  83. }
  84. $record = json_decode($stat_list[0]['call_record'],true);
  85. $words = $this->all_keyword($record);
  86. Tpl::output('words',$words);
  87. Tpl::output('word_colomns',$this->word_colomns());
  88. Tpl::showpage('stat.interactive.search');
  89. }
  90. private function special_colomns()
  91. {
  92. return ['序号','专题编号','名称','点击量','子专题'];
  93. }
  94. private function goods_colomns()
  95. {
  96. return ['序号','商品编号','商品货架号','名称','点击量'];
  97. }
  98. private function brand_colomns()
  99. {
  100. return ['序号','品牌编号','名称','点击量'];
  101. }
  102. private function word_colomns()
  103. {
  104. return ['序号','关键词','搜索量'];
  105. }
  106. function compatible_decode($unicode)
  107. {
  108. $str = '';
  109. $arr = array_filter(explode('u', $unicode));
  110. foreach ($arr as $k => $v) {
  111. if (strlen($v) == 4) {
  112. $num = (int)hexdec($v);
  113. $ord_1 = decbin(0xe0 | ($num >> 12));
  114. $ord_2 = decbin(0x80 | (($num >> 6) & 0x3f));
  115. $ord_3 = decbin(0x80 | ($num & 0x3f));
  116. $str .= chr(bindec($ord_1)) . chr(bindec($ord_2)) . chr(bindec($ord_3));
  117. }else{
  118. $str .= chr(hexdec($v));
  119. }
  120. }
  121. return $str;
  122. }
  123. private function all_keyword($record)
  124. {
  125. $other = $record['other'];
  126. if(empty($other)) return false;
  127. $words = [];
  128. foreach ($other as $key => $value)
  129. {
  130. $params = preg_split('/_/', $key);
  131. if($params != false && count($params) == 2)
  132. {
  133. if($params[0] == 'keyword') {
  134. $keyword = $this->compatible_decode($params[1]);
  135. $count = $value['count'];
  136. $words[] = array('keyword' => $keyword,'count' => $count);
  137. }
  138. }
  139. }
  140. if(!empty($words)) {
  141. // uasort($words,['special_item','count_desc']);
  142. }
  143. return $words;
  144. }
  145. private function all_special($record)
  146. {
  147. $other = $record['other'];
  148. if(empty($other)) return false;
  149. $specials = [];
  150. foreach ($other as $key => $value)
  151. {
  152. $params = preg_split('/_/', $key);
  153. if($params != false && count($params) == 2)
  154. {
  155. if($params[0] == 'special')
  156. {
  157. $special_id = intval($params[1]);
  158. $count = $value['count'];
  159. $specials[] = new special_item($special_id,$count);
  160. }
  161. }
  162. }
  163. if(!empty($specials)) {
  164. uasort($specials,['special_item','count_desc']);
  165. }
  166. return $specials;
  167. }
  168. private function all_goods($record)
  169. {
  170. $other = $record['other'];
  171. if(empty($other)) return false;
  172. $gid_count = [];
  173. $gids = [];
  174. foreach ($other as $key => $value)
  175. {
  176. $params = preg_split('/_/', $key);
  177. if($params != false && count($params) == 2)
  178. {
  179. if($params[0] == 'goods')
  180. {
  181. $goods_id = intval($params[1]);
  182. $count = $value['count'];
  183. $gid_count[$goods_id] = $count;
  184. $gids[] = $goods_id;
  185. }
  186. }
  187. }
  188. if(!empty($gids)) {
  189. $mod_goods = Model('goods');
  190. $items = $mod_goods->getGoodsList(['goods_id' => ['in',$gids]],'goods_name,goods_id,goods_commonid');
  191. }
  192. $goods_items = [];
  193. if(!empty($items))
  194. {
  195. foreach ($items as $goods)
  196. {
  197. $gid = $goods['goods_id'];
  198. $cid = $goods['goods_commonid'];
  199. $name = $goods['goods_name'];
  200. if(array_key_exists($gid,$gid_count)) {
  201. $count = $gid_count[$gid];
  202. $goods_items[] = new goods_item($gid,$cid,$name,$count);
  203. }
  204. }
  205. }
  206. if(!empty($goods_items)) {
  207. uasort($goods_items,['goods_item','count_desc']);
  208. }
  209. return $goods_items;
  210. }
  211. }
  212. class goods_item
  213. {
  214. private $mGoodsID;
  215. private $mCommonID;
  216. private $mGoodsName;
  217. private $mCount;
  218. public function __construct($gid,$cid,$name,$count)
  219. {
  220. $this->mGoodsID = $gid;
  221. $this->mCommonID = $cid;
  222. $this->mGoodsName = $name;
  223. $this->mCount = $count;
  224. }
  225. public function count() {
  226. return $this->mCount;
  227. }
  228. public function fields()
  229. {
  230. $result = [];
  231. $result[] = $this->mGoodsID;
  232. $result[] = $this->mCommonID;
  233. $result[] = $this->mGoodsName;
  234. $result[] = $this->mCount;
  235. return $result;
  236. }
  237. static public function count_desc($left,$right)
  238. {
  239. $t_l = intval($left->count());
  240. $t_r = intval($right->count());
  241. if($t_l > $t_r) return -1;
  242. elseif($t_l < $t_r) return 1;
  243. else return 0;
  244. }
  245. }
  246. class special_item
  247. {
  248. private $mSpId;
  249. private $mCount;
  250. public function __construct($special_id,$count)
  251. {
  252. $this->mSpId = $special_id;
  253. $this->mCount = $count;
  254. }
  255. public function count() {
  256. return $this->mCount;
  257. }
  258. public function fields()
  259. {
  260. $result = [];
  261. $result[] = $this->mSpId;
  262. $result[] = $this->special_name();
  263. $result[] = $this->mCount;
  264. return $result;
  265. }
  266. private function special_name()
  267. {
  268. $mod = Model('mb_special');
  269. $special = $mod->getMbSpecialList(['special_id' => $this->mSpId]);
  270. if(empty($special)) return false;
  271. return $special[0]['special_desc'];
  272. }
  273. private function sub_specials()
  274. {
  275. }
  276. static public function count_desc($left,$right)
  277. {
  278. $t_l = intval($left->count());
  279. $t_r = intval($right->count());
  280. if($t_l > $t_r) return -1;
  281. elseif($t_l < $t_r) return 1;
  282. else return 0;
  283. }
  284. }
  285. class search_item
  286. {
  287. }
  288. class call_item
  289. {
  290. private $mDateID;
  291. private $mRecord;
  292. public function __construct($item)
  293. {
  294. $this->mDateID = $item['date_id'];
  295. $srecord = $item['call_record'];
  296. if(empty($srecord)) {
  297. $this->mRecord = [];
  298. }
  299. else{
  300. $this->mRecord = json_decode($srecord,true);
  301. }
  302. }
  303. public function date_id() {
  304. return $this->mDateID;
  305. }
  306. public function date()
  307. {
  308. return strftime('%Y%m%d',intval($this->mDateID));
  309. }
  310. public function fields()
  311. {
  312. $result = [];
  313. $result[] = $this->date();
  314. if(empty($this->mRecord)) return $result;
  315. $result[] = $this->mRecord['ios_count'];
  316. $result[] = $this->mRecord['android_count'];
  317. $result[] = $this->mRecord['wap_count'];
  318. $funs = $this->mRecord['function'];
  319. $result[] = $this->accumulate($funs['index']);
  320. $result[] = $this->accumulate($funs['brand']);
  321. $result[] = $this->accumulate($funs['special']);
  322. $result[] = $this->accumulate($funs['search']);
  323. $result[] = $this->accumulate($funs['category']);
  324. $result[] = $this->accumulate($funs['goods_common']);
  325. $result[] = $this->accumulate_op($funs['login'],'getcodex');
  326. $result[] = $this->accumulate_op($funs['bonusex'],'open');
  327. $result[] = $this->accumulate_op($funs['member_bonus'],'make');
  328. $result[] = $this->accumulate_op($funs['member_bonus'],'makeby_bonus');
  329. $result[] = $this->accumulate_op($funs['member_bonus'],'shake');
  330. $result[] = $this->accumulate_op($funs['member_bonus'],'share');
  331. $result[] = $this->accumulate_op($funs['member_bonus'],'invite');
  332. $result[] = $this->accumulate($funs['member_favorites']);
  333. $result[] = $this->accumulate($funs['member_fcode']);
  334. $result[] = $this->accumulate($funs['mshop']);
  335. $result[] = $this->accumulate($funs['member_order']);
  336. return $result;
  337. }
  338. private function accumulate($act)
  339. {
  340. if(empty($act)) return 0;
  341. $count = 0;
  342. foreach ($act as $op => $val) {
  343. $count += $val['count'];
  344. }
  345. return $count;
  346. }
  347. private function accumulate_op($act,$op)
  348. {
  349. if(empty($act)) return 0;
  350. foreach ($act as $key => $val)
  351. {
  352. if($key == $op) {
  353. return $val['count'];
  354. }
  355. }
  356. return 0;
  357. }
  358. }
  359. class daily_item
  360. {
  361. private $mItem;
  362. public function __construct($item)
  363. {
  364. $this->mItem = $item;
  365. }
  366. public function date()
  367. {
  368. return strftime('%Y-%m-%d',intval($this->mItem['date_id']));
  369. }
  370. public function fields()
  371. {
  372. $result = [];
  373. $result[] = $this->date();
  374. $result[] = $this->accumulate($this->mItem['available_total_amount']);
  375. $result[] = $this->accumulate($this->mItem['all_total_amount']);
  376. $result[] = $this->accumulate($this->mItem['all_remain_amount']);
  377. $result[] = $this->mItem['all_bonus_count'];
  378. $result[] = $this->mItem['all_bind_count'];
  379. $result[] = $this->accumulatex($this->mItem['bonus_pay_amount']);
  380. $result[] = $this->accumulatex($this->mItem['person_send_amount']);
  381. $result[] = $this->mItem['all_bonus_count'] - $this->mItem['admin_bonus_count'];
  382. $result[] = $this->mItem['today_user'];
  383. $result[] = $this->mItem['member_total_num'];
  384. $result[] = $this->mItem['day_active_member'];
  385. $result[] = $this->mItem['week_active_member'];
  386. $result[] = $this->mItem['month_active_member'];
  387. $result[] = $this->mItem['order_total_num'];
  388. $result[] = $this->mItem['order_amount'];
  389. $result[] = $this->mItem['order_price_avg'];
  390. return $result;
  391. }
  392. private function accumulate($input)
  393. {
  394. $total = 0;
  395. if(empty($input)) return $total;
  396. $moneys = unserialize($input);
  397. if($moneys == false) return $total;
  398. foreach ($moneys as $val)
  399. {
  400. if(empty($val)) continue;
  401. foreach ($val as $rate => $money) {
  402. $total += $money;
  403. }
  404. }
  405. return $total;
  406. }
  407. private function accumulatex($input)
  408. {
  409. $total = 0;
  410. if(empty($input)) return $total;
  411. $moneys = unserialize($input);
  412. if($moneys == false) return $total;
  413. foreach ($moneys as $rate => $money)
  414. {
  415. $total += $money;
  416. }
  417. return $total;
  418. }
  419. }