119 lines
3.9 KiB
PHP
119 lines
3.9 KiB
PHP
<?php
|
|
namespace app\common\repositories\system\merchant;
|
|
|
|
|
|
|
|
use app\common\dao\system\merchant\MerchantShareholderIntegralDao;
|
|
use app\common\repositories\BaseRepository;
|
|
|
|
class MerchantShareholderIntegralRepository extends BaseRepository{
|
|
|
|
public function __construct(MerchantShareholderIntegralDao $dao){
|
|
$this->dao = $dao;
|
|
}
|
|
|
|
/**
|
|
* Common: 公共查询模型
|
|
* Author: wu-hui
|
|
* Time: 2024/06/19 16:04
|
|
* @param $search
|
|
* @return \app\common\model\system\merchant\MerchantShareholderIntegral
|
|
*/
|
|
public function getSearchModel($search){
|
|
return $this->dao->searchModel($search);
|
|
}
|
|
|
|
|
|
/**
|
|
* Common: 获取分组持有信息(同股东等级、门店、用户为一组)
|
|
* Author: wu-hui
|
|
* Time: 2024/06/20 9:32
|
|
* @param array $params
|
|
* @param int $page
|
|
* @param int $limit
|
|
* @return array
|
|
*/
|
|
public function groupList(array $params,int $page,int $limit){
|
|
// 查询模型
|
|
$query = $this->getSearchModel($params)
|
|
->field([
|
|
'uid',
|
|
'mer_id',
|
|
'level_id',
|
|
'CONCAT(uid,"_",mer_id,"_",level_id) as group_key',
|
|
'SUM(integral_total) as sum_integral_total',
|
|
'SUM(integral_use) as sum_integral_use',
|
|
'SUM(CASE status WHEN 2 THEN (integral_total - integral_use) ELSE 0 END) as sum_used_overdue',// 已过期可用
|
|
'SUM(CASE status WHEN 0 THEN integral_total ELSE 0 END) as sum_used_freeze',// 冻结中可用
|
|
'SUM(CASE status WHEN 1 THEN (integral_total - integral_use) ELSE 0 END) as sum_used_surplus',// 当前可用
|
|
])
|
|
->group('group_key')
|
|
->order('create_time DESC,id DESC');
|
|
// 信息获取
|
|
$count = $query->count();
|
|
$list = $query->page($page,$limit)->select()->toArray();
|
|
|
|
return compact('count','list');
|
|
}
|
|
/**
|
|
* Common: 获取信息列表
|
|
* Author: wu-hui
|
|
* Time: 2024/06/20 10:21
|
|
* @param array $params
|
|
* @param int $page
|
|
* @param int $limit
|
|
* @return array
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
*/
|
|
public function getList(array $params,int $page,int $limit){
|
|
// 查询模型
|
|
$query = $this->getSearchModel($params)->order('id asc');
|
|
// 信息获取
|
|
$count = $query->count();
|
|
$list = $query->page($page,$limit)->select()->toArray();
|
|
|
|
return compact('count','list');
|
|
}
|
|
/**
|
|
* Common: 获取统计信息
|
|
* Author: wu-hui
|
|
* Time: 2024/06/20 16:44
|
|
* @param $params
|
|
* @return array
|
|
*/
|
|
public function getStatistics($params){
|
|
$info = $this->getSearchModel($params)
|
|
->field([
|
|
'SUM(integral_total) as sum_integral_total',
|
|
'SUM(integral_use) as sum_integral_use',
|
|
'SUM(CASE status WHEN 2 THEN (integral_total - integral_use) ELSE 0 END) as sum_used_overdue',// 已过期可用
|
|
'SUM(CASE status WHEN 0 THEN integral_total ELSE 0 END) as sum_used_freeze',// 冻结中可用
|
|
'SUM(CASE status WHEN 1 THEN (integral_total - integral_use) ELSE 0 END) as sum_used_surplus',// 当前可用
|
|
])
|
|
->findOrEmpty()
|
|
->toArray();
|
|
|
|
return $info ?? [];
|
|
}
|
|
|
|
// 获取用户绑定商户列表
|
|
public function getMerList(array $params,int $page,int $limit){
|
|
// 获取股东列表
|
|
$data = app()->make(MerchantShareholderRepository::class)->getList($params,$page,$limit);
|
|
foreach($data['list'] as &$item){
|
|
$item->statistics = $this->getStatistics([
|
|
'uid' => $item->uid,
|
|
'mer_id' => $item->mer_id,
|
|
]);
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|