| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <?php
- namespace app\api\controller\board;
- use crmeb\services\UtilService;
- use app\models\board\UserBoard;
- use \think\facade\Config;
- use crmeb\utils\Redis;
- use tw\redis\BoardRds;
- /**
- * 协议见文档 docs/board.md, 协议可能变更
- *
- * 使用 UserBoard Model, 数据表为 store_order_cart_info
- *
- * 策略:定时利用 sql 生成排行榜,缓存 json 到 redis
- *
- * Class UserBoardController
- * @package app\api\controller\board
- */
- class UserBoardController
- {
- /**
- * @api {get} /boards 获取排行榜
- * @apiName GetBoards
- * @apiGroup Activity
- *
- * @apiParam {int=1,2} type 1|2 日榜单|周榜单
- *
- * @apiSuccess {string} banner 顶部 banner 图片
- * @apiSuccess {string} name 排行榜名称, 暂未使用
- * @apiSuccess {Object[]} board 排行榜数据
- *
- * @apiSuccessExample
- * {
- * "banner": "http://xxx.png",
- * "name": "daily board",
- * "board": [{
- * "uid": 123,
- * "avatar": "http://2.png",
- * "nickname": "xxx",
- * "level": 1,
- * "value": 23.3,
- * "border": 1,
- * "vip": 2
- * }]
- * }
- */
- public function boards()
- {
- [$type,] = UtilService::getMore([
- ['type', 1],
- ], null, true);
- $board = json_decode((new BoardRds)->get($type), true);
- return app('json')->successful('ok', $board);
- }
- /**
- * 读库
- */
- protected function daily_win_money()
- {
- $board = new UserBoard();
- $res = $board->getDailyWinMoney();
- foreach ($res as &$row) {
- $row['value'] = floatval($row['value']);
- $row['border'] = 0;
- $row['vip'] = 0;
- }
- return array(
- 'banner' => Config::get('app.leader_board_banner'),
- 'name' => "日榜",
- 'board' => $res,
- );
- }
- /**
- * 缓存数据库取得的排行结果,定时调用
- */
- public function cache_board()
- {
- $res = (new BoardRds)->set(BoardRds::DAILY, json_encode($this->daily_win_money()));
- if (!$res) {
- errlog("cache_board() returned $res");
- }
- }
- }
|