Files
zzp-server/app/adminapi/logic/withdraw/WithdrawMethodLogic.php
2026-01-19 14:19:22 +08:00

162 lines
4.9 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\logic\withdraw;
use app\common\model\withdraw\{WithdrawMethod,WithdrawWallet};
use app\common\logic\BaseLogic;
use think\facade\Db;
use app\common\service\{FileService};
use app\common\enum\YesNoEnum;
/**
* 提现方式逻辑
* Class WithdrawMethodLogic
* @package app\adminapi\logic\withdraw
*/
class WithdrawMethodLogic extends BaseLogic
{
/**
* @notes 添加提现方式
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/02/23 14:34
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
WithdrawMethod::create([
'lang_id' => $params['lang_id'],
'type' => $params['type'],
'name' => $params['name'],
'logo' => $params['logo'] ? FileService::setFileUrl($params['logo']) : '',
'symbol' => $params['symbol'],
'rate' => $params['rate'],
'symbol_rate' => $params['symbol_rate'],
'precision' => $params['precision'],
'charge' => $params['charge'],
'is_show' => $params['is_show'],
'is_qrcode' => $params['is_qrcode'],
'sort' => $params['sort']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑提现方式
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/02/23 14:34
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
$method = WithdrawMethod::find($params['id']);
if ($method->isEmpty()) {
throw new \Exception('提现方式不存在');
}
WithdrawWallet::where('method_id', $method['id'])->update([
'lang_id' => $params['lang_id'],
]);
WithdrawMethod::where('id', $params['id'])->update([
'lang_id' => $params['lang_id'],
'type' => $params['type'],
'name' => $params['name'],
'logo' => $params['logo'] ? FileService::setFileUrl($params['logo']) : '',
'symbol' => $params['symbol'],
'rate' => $params['rate'],
'symbol_rate' => $params['symbol_rate'],
'precision' => $params['precision'],
'charge' => $params['charge'],
'is_qrcode' => $params['is_qrcode'],
'is_show' => $params['is_show'],
'sort' => $params['sort']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除提现方式
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/02/23 14:34
*/
public static function delete(array $params): bool
{
return WithdrawMethod::destroy($params['id']);
}
/**
* @notes 获取提现方式详情
* @param $params
* @return array
* @author likeadmin
* @date 2024/02/23 14:34
*/
public static function detail($params): array
{
return WithdrawMethod::findOrEmpty($params['id'])->toArray();
}
/**
* @notes 提现方式数据
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author 段誉
* @date 2022/10/13 10:53
*/
public static function getAllData()
{
$field = 'wm.id,wm.name,wm.lang_id';
$field .= ',l.name as lang_name';
return WithdrawMethod::alias('wm')
->join('language l', 'l.id = wm.lang_id')
->field($field)
->where(['wm.is_show' => YesNoEnum::YES])
->order(['wm.sort' => 'desc', 'wm.id' => 'desc'])
->select()
->toArray();
}
}