first commit
This commit is contained in:
184
app/adminapi/logic/setting/RechargeMethodLogic.php
Normal file
184
app/adminapi/logic/setting/RechargeMethodLogic.php
Normal file
@@ -0,0 +1,184 @@
|
||||
<?php
|
||||
namespace app\adminapi\logic\setting;
|
||||
|
||||
|
||||
use app\common\model\setting\RechargeMethod;
|
||||
use app\common\logic\BaseLogic;
|
||||
use think\facade\Db;
|
||||
use app\common\service\{ConfigService, FileService};
|
||||
use app\common\model\setting\Language;
|
||||
use app\common\enum\YesNoEnum;
|
||||
|
||||
|
||||
/**
|
||||
* 充值方式逻辑
|
||||
* Class RechargeMethodLogic
|
||||
* @package app\adminapi\logic\setting
|
||||
*/
|
||||
class RechargeMethodLogic extends BaseLogic
|
||||
{
|
||||
/**
|
||||
* @notes 添加充值方式
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author BD
|
||||
* @date 2023/11/30 15:22
|
||||
*/
|
||||
public static function add(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
RechargeMethod::create([
|
||||
'lang_id' => $params['lang_id'],
|
||||
'type' => $params['type'],
|
||||
'name' => $params['name'],
|
||||
'logo' => $params['logo'] ? FileService::setFileUrl($params['logo']) : '',
|
||||
'account' => $params['account'],
|
||||
'img' => $params['img'] ? FileService::setFileUrl($params['img']) : '',
|
||||
'bank_name' => $params['bank_name'],
|
||||
'bank_username' => $params['bank_username'],
|
||||
'main_coin_type' => $params['main_coin_type'],
|
||||
'coin_type' => $params['coin_type'],
|
||||
'protocol' => $params['protocol'],
|
||||
'address' => $params['address'],
|
||||
'member_id' => $params['member_id'],
|
||||
'avail_num' => $params['avail_num'],
|
||||
'rate' => $params['rate'],
|
||||
'symbol_rate' => $params['symbol_rate'],
|
||||
'precision' => $params['precision'],
|
||||
'symbol' => $params['symbol'],
|
||||
'is_show' => $params['is_show'],
|
||||
'is_voucher' => $params['is_voucher'],
|
||||
'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 BD
|
||||
* @date 2023/11/30 15:22
|
||||
*/
|
||||
public static function edit(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
RechargeMethod::where('id', $params['id'])->update([
|
||||
'lang_id' => $params['lang_id'],
|
||||
'type' => $params['type'],
|
||||
'name' => $params['name'],
|
||||
'logo' => $params['logo'] ? FileService::setFileUrl($params['logo']) : '',
|
||||
'account' => $params['account'],
|
||||
'img' => $params['img'] ? FileService::setFileUrl($params['img']) : '',
|
||||
'bank_name' => $params['bank_name'],
|
||||
'bank_username' => $params['bank_username'],
|
||||
'main_coin_type' => $params['main_coin_type'],
|
||||
'coin_type' => $params['coin_type'],
|
||||
'protocol' => $params['protocol'],
|
||||
'address' => $params['address'],
|
||||
'member_id' => $params['member_id'],
|
||||
'avail_num' => $params['avail_num'],
|
||||
'rate' => $params['rate'],
|
||||
'symbol_rate' => $params['symbol_rate'],
|
||||
'precision' => $params['precision'],
|
||||
'symbol' => $params['symbol'],
|
||||
'is_show' => $params['is_show'],
|
||||
'is_voucher' => $params['is_voucher'],
|
||||
'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 BD
|
||||
* @date 2023/11/30 15:22
|
||||
*/
|
||||
public static function delete(array $params): bool
|
||||
{
|
||||
return RechargeMethod::destroy($params['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取充值方式详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author BD
|
||||
* @date 2023/11/30 15:22
|
||||
*/
|
||||
public static function detail($params): array
|
||||
{
|
||||
$method = RechargeMethod::findOrEmpty($params['id'])->toArray();
|
||||
$method['logo'] = FileService::getFileUrl($method['logo']);
|
||||
$method['img'] = FileService::getFileUrl($method['img']);
|
||||
return $method;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 更改状态
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author heshihu
|
||||
* @date 2022/2/22 10:18
|
||||
*/
|
||||
public static function updateStatus(array $params)
|
||||
{
|
||||
RechargeMethod::update([
|
||||
'id' => $params['id'],
|
||||
'is_show' => $params['is_show']
|
||||
]);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 = 'id,name,lang_id';
|
||||
|
||||
$methods = RechargeMethod::field($field)
|
||||
->where(['is_show' => YesNoEnum::YES])
|
||||
->order(['sort' => 'desc', 'id' => 'desc'])
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
foreach ($methods as &$method) {
|
||||
$method['lang_name'] = '通用';
|
||||
if($method['lang_id'] != 0){
|
||||
$language = Language::where(['id' => $method['lang_id']])->findOrEmpty();
|
||||
if(!$language->isEmpty()){
|
||||
$method['lang_name'] = $language['name'];
|
||||
}
|
||||
}
|
||||
}
|
||||
return $methods;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user