128 lines
3.8 KiB
PHP
Executable File
128 lines
3.8 KiB
PHP
Executable File
<?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\api\logic;
|
||
|
||
use app\common\enum\PayEnum;
|
||
use app\common\logic\BaseLogic;
|
||
use app\common\model\recharge\RechargeOrder;
|
||
use app\common\model\user\User;
|
||
use app\common\service\ConfigService;
|
||
use think\facade\Db;
|
||
|
||
|
||
/**
|
||
* 充值逻辑层
|
||
* Class RechargeLogic
|
||
* @package app\shopapi\logic
|
||
*/
|
||
class RechargeLogic extends BaseLogic
|
||
{
|
||
|
||
/**
|
||
* @notes 充值
|
||
* @param array $params
|
||
* @return array|false
|
||
* @author 段誉
|
||
* @date 2023/2/24 10:43
|
||
*/
|
||
public static function recharge(array $params)
|
||
{
|
||
try {
|
||
$data = [
|
||
'sn' => generate_sn(RechargeOrder::class, 'sn'),
|
||
'order_terminal' => $params['terminal'],
|
||
'user_id' => $params['user_id'],
|
||
'pay_status' => PayEnum::UNPAID,
|
||
'order_amount' => $params['money'],
|
||
];
|
||
$order = RechargeOrder::create($data);
|
||
|
||
return [
|
||
'order_id' => (int)$order['id'],
|
||
'from' => 'recharge'
|
||
];
|
||
} catch (\Exception $e) {
|
||
self::setError($e->getMessage());
|
||
return false;
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 充值配置
|
||
* @param $userId
|
||
* @return array
|
||
* @author 段誉
|
||
* @date 2023/2/24 16:56
|
||
*/
|
||
public static function config($userId)
|
||
{
|
||
$userMoney = User::where(['id' => $userId])->value('user_money');
|
||
$minAmount = ConfigService::get('recharge', 'min_amount', 0);
|
||
$status = ConfigService::get('recharge', 'status', 0);
|
||
|
||
return [
|
||
'status' => $status,
|
||
'min_amount' => $minAmount,
|
||
'user_money' => $userMoney,
|
||
];
|
||
}
|
||
|
||
/**
|
||
* 充值记录
|
||
*/
|
||
public static function rechargeRecord($get)
|
||
{
|
||
$list = Db::name('recharge_order')
|
||
->field('order_sn, order_amount, give_money, create_time')
|
||
->where([
|
||
'user_id' => $get['user_id'],
|
||
'pay_status' => 1
|
||
])
|
||
->order('create_time', 'desc')
|
||
->page($get['page_no'], $get['page_size'])
|
||
->select();
|
||
|
||
$count = Db::name('recharge_order')
|
||
->where([
|
||
'user_id' => $get['user_id'],
|
||
'pay_status' => 1
|
||
])
|
||
->count();
|
||
|
||
foreach($list as &$item) {
|
||
$item['create_time'] = date('Y-m-d h:i:s', $item['create_time']);
|
||
if($item['give_money'] > 0) {
|
||
$item['desc'] = '充值'. $item['order_amount'] . '赠送' . $item['give_money'];
|
||
}else{
|
||
$item['desc'] = '充值'. $item['order_amount'];
|
||
}
|
||
$item['total'] = $item['order_amount'] + $item['give_money']; // 充值金额 + 赠送金额
|
||
}
|
||
|
||
$result = [
|
||
'count' => $count,
|
||
'list' => $list,
|
||
'more' => is_more($count, $get['page_no'], $get['page_size']),
|
||
'count' => $count,
|
||
'page_no' => $get['page_no'],
|
||
'page_size' => $get['page_size']
|
||
];
|
||
|
||
return $result;
|
||
}
|
||
|
||
|
||
} |