91 lines
2.8 KiB
PHP
91 lines
2.8 KiB
PHP
<?php
|
|
namespace app\common\repositories\system\merchant;
|
|
|
|
|
|
use app\common\dao\system\merchant\MerchantQuotaDao;
|
|
use app\common\repositories\BaseRepository;
|
|
|
|
|
|
class MerchantQuotaRepository extends BaseRepository{
|
|
|
|
public function __construct(MerchantQuotaDao $dao){
|
|
$this->dao = $dao;
|
|
}
|
|
|
|
/**
|
|
* Common: 列表获取
|
|
* Author: wu-hui
|
|
* Time: 2024/06/04 14:59
|
|
* @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){
|
|
$field = [
|
|
'm.mer_id',
|
|
'm.mer_name',
|
|
'm.merchant_type',
|
|
'mqr.title_brand_limit',
|
|
'mqr.title_brand_used',
|
|
'mqr.title_brand_total',
|
|
'mqr.other_brand_limit',
|
|
'mqr.other_brand_used',
|
|
'mqr.other_brand_total',
|
|
];
|
|
|
|
$query = $this->dao->searchList($params,$field);
|
|
$count = $query->count();
|
|
$list = $query->page($page,$limit)->select();
|
|
|
|
return compact('count','list');
|
|
}
|
|
/**
|
|
* Common: 获取指定商户的补货额度信息&冠名品牌名称
|
|
* Author: wu-hui
|
|
* Time: 2024/06/07 11:23
|
|
* @param int $merId
|
|
* @return mixed
|
|
*/
|
|
public function getMerQuotaAndBrandInfo(int $merId){
|
|
// 获取信息
|
|
$info = $this->getQuotaInfo($merId);
|
|
// 计算剩余可用冠名品牌额度和其他品牌额度
|
|
if($info){
|
|
$info = $info->toArray();
|
|
$info['title_surplus_quota'] = (float)sprintf("%.2f", $info['title_brand_limit'] - $info['title_brand_used']);
|
|
$info['other_surplus_quota'] = (float)sprintf("%.2f", $info['other_brand_limit'] - $info['other_brand_used']);
|
|
}
|
|
// 获取当前商户品牌信息
|
|
$info['mer_brand_name'] = '';
|
|
$merBrandId = (int)app()->make(MerchantRepository::class)->getSearch(['mer_id'=>$merId])->value('brand_id');
|
|
if($merBrandId > 0) $info['mer_brand_name'] = app()->make(MerchantBrandRepository::class)->getSearch(['id'=>$merBrandId])->value('title');
|
|
|
|
return $info;
|
|
}
|
|
/**
|
|
* Common: 获取商户补货额度信息 不存在则创建并且返回
|
|
* Author: wu-hui
|
|
* Time: 2024/06/07 15:04
|
|
* @param $merId
|
|
* @return array|\think\Model
|
|
*/
|
|
public function getQuotaInfo($merId){
|
|
// 获取信息
|
|
$info = $this->dao->getSearch(['mer_id'=>$merId])->findOrEmpty();
|
|
if($info->id <= 0){
|
|
$info->mer_id = $merId;
|
|
$info->save();
|
|
|
|
return $this->getQuotaInfo($merId);
|
|
}
|
|
|
|
return $info ?? [];
|
|
}
|
|
|
|
|
|
}
|