69 lines
2.3 KiB
PHP
69 lines
2.3 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace app\admin\logic;
|
||
|
|
|
||
|
|
use app\common\basics\Logic;
|
||
|
|
use app\common\model\billions\Billions;
|
||
|
|
use app\common\model\order\Order;
|
||
|
|
use app\common\model\RechargeOrder;
|
||
|
|
use app\common\model\shop\Shop;
|
||
|
|
use app\common\model\UserBillionsRechargeBalance;
|
||
|
|
use app\common\server\UrlServer;
|
||
|
|
use app\common\model\goods\Goods;
|
||
|
|
|
||
|
|
class BillionsLogic extends Logic
|
||
|
|
{
|
||
|
|
public static function lists($get)
|
||
|
|
{
|
||
|
|
if (!empty($get['nickname'])) {
|
||
|
|
$where[] = ['u.nickname', 'like', '%' . $get['nickname'] . '%'];
|
||
|
|
}
|
||
|
|
|
||
|
|
if (isset($get['state']) && $get['state'] == 1) {
|
||
|
|
$where[] = ['b.state', '=', 1];
|
||
|
|
} else {
|
||
|
|
$where[] = ['b.state', '=', 0];
|
||
|
|
}
|
||
|
|
|
||
|
|
$lists = Billions::alias('b')
|
||
|
|
->join('user u', 'b.user_id = u.id')
|
||
|
|
->where($where)
|
||
|
|
->order('billions_id', 'desc')
|
||
|
|
->field('b.*, u.id, u.nickname, u.avatar')
|
||
|
|
->paginate([
|
||
|
|
'page' => $get['page'] ?? 1,
|
||
|
|
'list_rows' => $get['limit'] ?? 10,
|
||
|
|
'var_page' => 'page'
|
||
|
|
])->toArray();
|
||
|
|
|
||
|
|
foreach ($lists['data'] as &$v) {
|
||
|
|
if ($v['type'] == 1) {
|
||
|
|
$v['order_sn'] = Order::where('id', $v['order_id'])->value('order_sn');
|
||
|
|
$v['name'] = Shop::where('id',$v['shop_id'])->value('name');
|
||
|
|
} else if ($v['type'] == 2) {
|
||
|
|
$v['order_sn'] = RechargeOrder::where('id', $v['order_id'])->value('order_sn');
|
||
|
|
} else if ($v['type'] == 3) {
|
||
|
|
$v['order_sn'] = UserBillionsRechargeBalance::where('id', $v['order_id'])->value('order_sn');
|
||
|
|
}
|
||
|
|
|
||
|
|
if ($v['goods_id']) {
|
||
|
|
$v['goods_info'] = Goods::field('name, image')->find($v['goods_id']);
|
||
|
|
}
|
||
|
|
|
||
|
|
if ($v['avatar']) {
|
||
|
|
$v['avatar'] = UrlServer::getFileUrl($v['avatar']);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
self::getRanking($lists['data']);
|
||
|
|
return ['count' => $lists['total'], 'lists' => $lists['data']];
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function getRanking(&$data = []){
|
||
|
|
$where[] = ['state', '=', 0];
|
||
|
|
|
||
|
|
foreach ($data as &$v) {
|
||
|
|
$where[] = ['billions_id', '<=', $v['billions_id']];
|
||
|
|
$v['raking'] = Billions::where($where)->count();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|