Index.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkAdmin
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://demo.thinkadmin.top
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // +----------------------------------------------------------------------
  11. // | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
  12. // | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
  13. // +----------------------------------------------------------------------
  14. namespace app\wechat\controller;
  15. use app\wechat\service\WechatService;
  16. use library\Controller;
  17. use think\Db;
  18. /**
  19. * 微信数据统计
  20. * Class Index
  21. * @package app\wechat\controller
  22. */
  23. class Index extends Controller
  24. {
  25. /**
  26. * 微信数据统计
  27. * @auth true
  28. * @menu true
  29. * @throws \think\Exception
  30. * @throws \think\db\exception\DataNotFoundException
  31. * @throws \think\db\exception\ModelNotFoundException
  32. * @throws \think\exception\DbException
  33. * @throws \think\exception\PDOException
  34. */
  35. public function index()
  36. {
  37. $map = ['appid' => WechatService::getAppid()];
  38. $this->totalJson = ['xs' => [], 'ys' => []];
  39. for ($i = 5; $i >= 0; $i--) {
  40. $time = strtotime("-{$i} months");
  41. $where = [['subscribe_at', '<=', date('Y-m-t 23:59:59', $time)]];
  42. $this->totalJson['xs'][] = date('Y年m月', $time);
  43. $item = ['_0' => 0, '_1' => 0];
  44. $list = Db::name('WechatFans')->field('count(1) count,is_black black')->where($map)->where($where)->group('is_black')->select();
  45. foreach ($list as $vo) $item["_{$vo['black']}"] = $vo['count'];
  46. $this->totalJson['ys']['_0'][] = $item['_0'];
  47. $this->totalJson['ys']['_1'][] = $item['_1'];
  48. }
  49. $this->totalFans = Db::name('WechatFans')->where(['is_black' => '0'])->where($map)->count();
  50. $this->totalBlack = Db::name('WechatFans')->where(['is_black' => '1'])->where($map)->count();
  51. $this->totalNews = Db::name('WechatNews')->where(['is_deleted' => '0'])->count();
  52. $this->totalRule = Db::name('WechatKeys')->count();
  53. $this->fetch();
  54. }
  55. }