glhcp/server/app/admin/logic/PayConfigLogic.php

131 lines
4.2 KiB
PHP
Raw Normal View History

2023-08-10 06:59:52 +00:00
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权购买去版权授权后方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\admin\logic;
use app\common\basics\Logic;
use app\common\model\Pay;
use app\common\server\UrlServer;
/**
* 支付配置 - 逻辑
* Class PayConfigLogic
* @package app\admin\logic
*/
class PayConfigLogic extends Logic
{
/**
* Notes: 配置列表
* @author 段誉(2021/5/7 18:15)
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function lists()
{
$count = Pay::count();
$lists = Pay::withAttr('status', function($value, $data) {
return $value == 1 ? '启用' : '关闭';
})->order('sort')->select();
return ['lists' => $lists, 'count' => $count];
}
/**
* Notes: 详情
* @param $pay_code
* @author 段誉(2021/5/7 18:15)
* @return array|\think\Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function info($pay_code)
{
return Pay::where(['code' => $pay_code])->find();
}
/**
* Notes: 余额
* @param $post
* @author 段誉(2021/5/7 18:15)
* @return Pay
*/
public static function editBalance($post)
{
return Pay::where('code', 'balance')->update([
'short_name' => $post['short_name'],
'image' => UrlServer::setFileUrl($post['image']) ?? '',
'status' => $post['status'],
'sort' => $post['sort'] ?? 0,
]);
}
/**
* Notes: 微信
* @param $post
* @author 段誉(2021/5/7 18:16)
* @return Pay
*/
public static function editWechat($post)
{
$data = [
'short_name' => $post['short_name'],
'image' => UrlServer::setFileUrl($post['image']) ?? '',
'status' => $post['status'],
'sort' => $post['sort'] ?? 0,
'config' => [
'pay_sign_key' => $post['pay_sign_key'],
'mch_id' => $post['mch_id'],
'apiclient_cert' => $post['apiclient_cert'],
'apiclient_key' => $post['apiclient_key']
]
];
return Pay::where('code', 'wechat')->update($data);
}
/**
* Notes: 支付宝
* @param $post
* @author 段誉(2021/5/7 18:16)
* @return Pay
*/
public static function editAlipay($post)
{
$data = [
'short_name' => $post['short_name'],
'image' => UrlServer::setFileUrl($post['image']) ?? '',
'status' => $post['status'],
'sort' => $post['sort'] ?? 0,
'config' => [
'app_id' => $post['app_id'],
'private_key' => $post['private_key'],//应用私钥
'ali_public_key' => $post['ali_public_key']//支付宝公钥
]
];
return Pay::where('code', 'alipay')->update($data);
}
}