mirror of
https://gitee.com/technical-laohu/mpay_v2_webman.git
synced 2026-04-24 11:04:26 +08:00
丰富基础代码
This commit is contained in:
@@ -37,5 +37,43 @@ class MerchantAppRepository extends BaseRepository
|
||||
->where('status', 1)
|
||||
->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* 后台按 app_id 查询(不过滤状态)
|
||||
*/
|
||||
public function findAnyByAppId(string $appId): ?MerchantApp
|
||||
{
|
||||
return $this->model->newQuery()
|
||||
->where('app_id', $appId)
|
||||
->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* 后台列表:支持筛选与模糊搜索
|
||||
*/
|
||||
public function searchPaginate(array $filters = [], int $page = 1, int $pageSize = 10)
|
||||
{
|
||||
$query = $this->model->newQuery();
|
||||
|
||||
if (!empty($filters['merchant_id'])) {
|
||||
$query->where('merchant_id', (int)$filters['merchant_id']);
|
||||
}
|
||||
if (($filters['status'] ?? '') !== '' && $filters['status'] !== null) {
|
||||
$query->where('status', (int)$filters['status']);
|
||||
}
|
||||
if (!empty($filters['app_id'])) {
|
||||
$query->where('app_id', 'like', '%' . $filters['app_id'] . '%');
|
||||
}
|
||||
if (!empty($filters['app_name'])) {
|
||||
$query->where('app_name', 'like', '%' . $filters['app_name'] . '%');
|
||||
}
|
||||
if (!empty($filters['api_type'])) {
|
||||
$query->where('api_type', (string)$filters['api_type']);
|
||||
}
|
||||
|
||||
$query->orderByDesc('id');
|
||||
|
||||
return $query->paginate($pageSize, ['*'], 'page', $page);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,5 +24,27 @@ class MerchantRepository extends BaseRepository
|
||||
->where('merchant_no', $merchantNo)
|
||||
->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* 后台列表:支持模糊搜索
|
||||
*/
|
||||
public function searchPaginate(array $filters = [], int $page = 1, int $pageSize = 10)
|
||||
{
|
||||
$query = $this->model->newQuery();
|
||||
|
||||
if (($filters['status'] ?? '') !== '' && $filters['status'] !== null) {
|
||||
$query->where('status', (int)$filters['status']);
|
||||
}
|
||||
if (!empty($filters['merchant_no'])) {
|
||||
$query->where('merchant_no', 'like', '%' . $filters['merchant_no'] . '%');
|
||||
}
|
||||
if (!empty($filters['merchant_name'])) {
|
||||
$query->where('merchant_name', 'like', '%' . $filters['merchant_name'] . '%');
|
||||
}
|
||||
|
||||
$query->orderByDesc('id');
|
||||
|
||||
return $query->paginate($pageSize, ['*'], 'page', $page);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,4 +31,36 @@ class PaymentMethodRepository extends BaseRepository
|
||||
->where('status', 1)
|
||||
->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* 后台按 code 查询(不过滤状态)
|
||||
*/
|
||||
public function findAnyByCode(string $methodCode): ?PaymentMethod
|
||||
{
|
||||
return $this->model->newQuery()
|
||||
->where('method_code', $methodCode)
|
||||
->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* 后台列表:支持筛选与排序
|
||||
*/
|
||||
public function searchPaginate(array $filters = [], int $page = 1, int $pageSize = 10)
|
||||
{
|
||||
$query = $this->model->newQuery();
|
||||
|
||||
if (($filters['status'] ?? '') !== '' && $filters['status'] !== null) {
|
||||
$query->where('status', (int)$filters['status']);
|
||||
}
|
||||
if (!empty($filters['method_code'])) {
|
||||
$query->where('method_code', 'like', '%' . $filters['method_code'] . '%');
|
||||
}
|
||||
if (!empty($filters['method_name'])) {
|
||||
$query->where('method_name', 'like', '%' . $filters['method_name'] . '%');
|
||||
}
|
||||
|
||||
$query->orderBy('sort', 'asc')->orderByDesc('id');
|
||||
|
||||
return $query->paginate($pageSize, ['*'], 'page', $page);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,4 +53,43 @@ class PaymentOrderRepository extends BaseRepository
|
||||
}
|
||||
return $this->updateById($order->id, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 后台订单列表:支持筛选与模糊搜索
|
||||
*/
|
||||
public function searchPaginate(array $filters = [], int $page = 1, int $pageSize = 10)
|
||||
{
|
||||
$query = $this->model->newQuery();
|
||||
|
||||
if (!empty($filters['merchant_id'])) {
|
||||
$query->where('merchant_id', (int)$filters['merchant_id']);
|
||||
}
|
||||
if (!empty($filters['merchant_app_id'])) {
|
||||
$query->where('merchant_app_id', (int)$filters['merchant_app_id']);
|
||||
}
|
||||
if (!empty($filters['method_id'])) {
|
||||
$query->where('method_id', (int)$filters['method_id']);
|
||||
}
|
||||
if (!empty($filters['channel_id'])) {
|
||||
$query->where('channel_id', (int)$filters['channel_id']);
|
||||
}
|
||||
if (($filters['status'] ?? '') !== '' && $filters['status'] !== null) {
|
||||
$query->where('status', (int)$filters['status']);
|
||||
}
|
||||
if (!empty($filters['order_id'])) {
|
||||
$query->where('order_id', 'like', '%' . $filters['order_id'] . '%');
|
||||
}
|
||||
if (!empty($filters['mch_order_no'])) {
|
||||
$query->where('mch_order_no', 'like', '%' . $filters['mch_order_no'] . '%');
|
||||
}
|
||||
if (!empty($filters['created_from'])) {
|
||||
$query->where('created_at', '>=', $filters['created_from']);
|
||||
}
|
||||
if (!empty($filters['created_to'])) {
|
||||
$query->where('created_at', '<=', $filters['created_to']);
|
||||
}
|
||||
|
||||
$query->orderByDesc('id');
|
||||
return $query->paginate($pageSize, ['*'], 'page', $page);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,4 +29,61 @@ class PaymentPluginRepository extends BaseRepository
|
||||
->where('status', 1)
|
||||
->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* 后台按编码查询(不过滤状态)
|
||||
*/
|
||||
public function findByCode(string $pluginCode): ?PaymentPlugin
|
||||
{
|
||||
return $this->model->newQuery()
|
||||
->where('plugin_code', $pluginCode)
|
||||
->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* 后台列表:支持筛选与模糊搜索
|
||||
*/
|
||||
public function searchPaginate(array $filters = [], int $page = 1, int $pageSize = 10)
|
||||
{
|
||||
$query = $this->model->newQuery();
|
||||
|
||||
if (($filters['status'] ?? '') !== '' && $filters['status'] !== null) {
|
||||
$query->where('status', (int)$filters['status']);
|
||||
}
|
||||
if (!empty($filters['plugin_code'])) {
|
||||
$query->where('plugin_code', 'like', '%' . $filters['plugin_code'] . '%');
|
||||
}
|
||||
if (!empty($filters['plugin_name'])) {
|
||||
$query->where('plugin_name', 'like', '%' . $filters['plugin_name'] . '%');
|
||||
}
|
||||
|
||||
$query->orderByDesc('created_at');
|
||||
return $query->paginate($pageSize, ['*'], 'page', $page);
|
||||
}
|
||||
|
||||
/**
|
||||
* 后台保存:存在则更新,不存在则创建
|
||||
*/
|
||||
public function upsertByCode(string $pluginCode, array $data): PaymentPlugin
|
||||
{
|
||||
$row = $this->findByCode($pluginCode);
|
||||
if ($row) {
|
||||
$this->model->newQuery()
|
||||
->where('plugin_code', $pluginCode)
|
||||
->update($data);
|
||||
return $this->findByCode($pluginCode) ?: $row;
|
||||
}
|
||||
|
||||
$data['plugin_code'] = $pluginCode;
|
||||
/** @var PaymentPlugin $created */
|
||||
$created = $this->create($data);
|
||||
return $created;
|
||||
}
|
||||
|
||||
public function updateStatus(string $pluginCode, int $status): bool
|
||||
{
|
||||
return (bool)$this->model->newQuery()
|
||||
->where('plugin_code', $pluginCode)
|
||||
->update(['status' => $status]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user