2024-08-03 10:04:14 +08:00
|
|
|
<?php
|
|
|
|
|
namespace app\api\logic;
|
|
|
|
|
|
|
|
|
|
use app\common\basics\Logic;
|
|
|
|
|
use app\common\model\RechargeTemplate;
|
|
|
|
|
use app\common\model\RechargeOrder;
|
|
|
|
|
use app\common\server\ConfigServer;
|
|
|
|
|
use app\common\enum\PayEnum;
|
|
|
|
|
use think\facade\Db;
|
|
|
|
|
use app\common\logic\AccountLogLogic;
|
|
|
|
|
use app\common\model\AccountLog;
|
|
|
|
|
use app\common\model\BalanceWithdrawApply;
|
|
|
|
|
|
|
|
|
|
class RechargeLogic extends Logic
|
|
|
|
|
{
|
|
|
|
|
public static function getTemplate(){
|
|
|
|
|
$list = RechargeTemplate::where(['del'=>0])
|
|
|
|
|
->order('sort desc')
|
|
|
|
|
->field('id,money,give_money,is_recommend')
|
|
|
|
|
->select()
|
|
|
|
|
->toArray();
|
|
|
|
|
|
|
|
|
|
foreach ($list as &$item){
|
|
|
|
|
$item['tips'] = '';
|
|
|
|
|
if($item['give_money'] > 0){
|
|
|
|
|
$item['tips'] = '充'.intval($item['money']).'赠送'.intval($item['give_money']).'元';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function recharge($user_id,$client,$post)
|
|
|
|
|
{
|
|
|
|
|
try{
|
|
|
|
|
$give_growth = ConfigServer::get('recharge', 'give_growth', 0);
|
|
|
|
|
|
|
|
|
|
//充值模板
|
|
|
|
|
if(isset($post['id'])){
|
|
|
|
|
$template = RechargeTemplate::where(['del'=>0,'id'=>$post['id']])
|
|
|
|
|
->field('id,money,give_money')
|
|
|
|
|
->findOrEmpty();
|
|
|
|
|
if($template->isEmpty()) {
|
|
|
|
|
throw new \think\Exception('充值模板不存在');
|
|
|
|
|
}
|
|
|
|
|
$money = $template['money'];
|
|
|
|
|
$give_money = $template['give_money'];
|
|
|
|
|
|
|
|
|
|
}else{//自定义充值金额
|
|
|
|
|
$template = RechargeTemplate::where(['del'=>0,'money'=>$post['money']])
|
|
|
|
|
->field('id,money,give_money')
|
|
|
|
|
->findOrEmpty();
|
|
|
|
|
|
|
|
|
|
$money = $post['money'];
|
|
|
|
|
$give_money = 0;
|
|
|
|
|
if(!$template->isEmpty()){
|
|
|
|
|
$money = $template['money'];
|
|
|
|
|
$give_money = $template['give_money'];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//赠送的积分和成长值
|
|
|
|
|
$growth = $money * $give_growth;
|
|
|
|
|
$growth = $growth > 0 ? intval($growth) : 0;
|
|
|
|
|
|
|
|
|
|
$add_order = [
|
|
|
|
|
'user_id' => $user_id,
|
|
|
|
|
'order_sn' => createSn('recharge_order','order_sn'),
|
|
|
|
|
'order_amount' => $money,
|
|
|
|
|
'order_source' => $client,
|
|
|
|
|
'pay_status' => PayEnum::UNPAID, //待支付状态;
|
|
|
|
|
'pay_way' => $post['pay_way'] ?? 1,
|
|
|
|
|
'template_id' => $template['id'] ?? 0,
|
|
|
|
|
'give_money' => $give_money,
|
|
|
|
|
'give_growth' => $growth,
|
|
|
|
|
'create_time' => time(),
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$id = Db::name('recharge_order')->insertGetId($add_order);
|
|
|
|
|
if($id){
|
|
|
|
|
return Db::name('recharge_order')->where(['id'=>$id])->field('id,order_sn,give_growth')->find();
|
|
|
|
|
}
|
|
|
|
|
return [];
|
|
|
|
|
}catch(\Exception $e) {
|
|
|
|
|
self::$error = $e->getMessage();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*卡密核销逻辑*/
|
|
|
|
|
public static function kamihexiao($user_id,$post)
|
|
|
|
|
{
|
|
|
|
|
try{
|
|
|
|
|
|
|
|
|
|
//var_dump($post);
|
|
|
|
|
$where = $post;
|
|
|
|
|
$where["status"] = 0; //未核销
|
|
|
|
|
$card = Db::name("card")->where($where)->find();
|
|
|
|
|
if(!$card){
|
|
|
|
|
self::$error = "卡号或者密码有误!";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Db::name("card")->where("id",$card["id"])->update(["status"=>1,"update_time"=>time()]); //设置该卡为已核销
|
|
|
|
|
|
|
|
|
|
$money = $card["money"];
|
|
|
|
|
//赠送的积分和成长值
|
|
|
|
|
// $growth = $money * $give_growth;
|
|
|
|
|
// $growth = $growth > 0 ? intval($growth) : 0;
|
|
|
|
|
|
|
|
|
|
$add_order = [
|
|
|
|
|
'user_id' => $user_id,
|
|
|
|
|
'order_sn' => createSn('recharge_order','order_sn'),
|
|
|
|
|
'order_amount' => $money,
|
|
|
|
|
'order_source' => 1,
|
|
|
|
|
'pay_status' => PayEnum::ISPAID, //待支付状态;
|
|
|
|
|
'pay_way' => 4, //充值卡
|
|
|
|
|
'template_id' => 0,
|
|
|
|
|
'give_money' => 0,
|
|
|
|
|
'give_growth' => 0,
|
|
|
|
|
'create_time' => time(),
|
|
|
|
|
'pay_time' => time(),
|
|
|
|
|
'transaction_id'=> $card["card_number"],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$id = Db::name('recharge_order')->insertGetId($add_order);
|
|
|
|
|
Db::name('user')->where("id",$user_id)->inc("user_money",$money)->update(); //增加用户余额
|
|
|
|
|
if($id){
|
|
|
|
|
return Db::name('recharge_order')->where(['id'=>$id])->field('id,order_sn,give_growth')->find();
|
|
|
|
|
}
|
|
|
|
|
return [];
|
|
|
|
|
}catch(\Exception $e) {
|
|
|
|
|
self::$error = $e->getMessage();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static function rechargeRecord($get)
|
|
|
|
|
{
|
|
|
|
|
$list = RechargeOrder::field('order_sn, order_amount, give_money, create_time')
|
|
|
|
|
->where([
|
|
|
|
|
'user_id' => $get['user_id'],
|
|
|
|
|
'pay_status' => PayEnum::ISPAID, // 已支付的
|
|
|
|
|
])
|
|
|
|
|
->order('create_time', 'desc')
|
|
|
|
|
->page($get['page_no'], $get['page_size'])
|
|
|
|
|
->select()
|
|
|
|
|
->toArray();
|
|
|
|
|
$count = RechargeOrder::where([
|
|
|
|
|
'user_id' => $get['user_id'],
|
|
|
|
|
'pay_status' => PayEnum::ISPAID
|
|
|
|
|
])
|
|
|
|
|
->count();
|
|
|
|
|
|
|
|
|
|
foreach($list as &$item) {
|
|
|
|
|
if($item['give_money'] > 0) {
|
|
|
|
|
$item['desc'] = '充值'. clearZero($item['order_amount']) . '赠送' . clearZero($item['give_money']);
|
|
|
|
|
}else{
|
|
|
|
|
$item['desc'] = '充值'. clearZero($item['order_amount']);
|
|
|
|
|
}
|
|
|
|
|
$item['total'] = $item['order_amount'] + $item['give_money']; // 充值金额 + 赠送金额
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$result = [
|
|
|
|
|
'count' => $count,
|
|
|
|
|
'lists' => $list,
|
|
|
|
|
'more' => is_more($count, $get['page_no'], $get['page_size']),
|
|
|
|
|
'page_no' => $get['page_no'],
|
|
|
|
|
'page_size' => $get['page_size']
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 提现记录
|
|
|
|
|
*/
|
|
|
|
|
public static function widthdrawlRecord($get)
|
|
|
|
|
{
|
|
|
|
|
$list = BalanceWithdrawApply::where([
|
|
|
|
|
'user_id' => $get['user_id']
|
|
|
|
|
])
|
|
|
|
|
->field('sn, type, money, left_money, poundage, description, create_time, status')
|
|
|
|
|
->order('create_time', 'desc')
|
|
|
|
|
->page($get['page_no'], $get['page_size'])
|
|
|
|
|
->select()
|
|
|
|
|
->toArray();
|
|
|
|
|
|
|
|
|
|
$count = BalanceWithdrawApply::where([
|
|
|
|
|
'user_id' => $get['user_id']
|
|
|
|
|
])->count();
|
|
|
|
|
|
|
|
|
|
foreach ($list as &$v) {
|
|
|
|
|
if (!is_null($v['description'])) {
|
2024-08-16 19:30:00 +08:00
|
|
|
$v['desc'] = $v['description'] ? '审核失败:' . $v['description'] : '审核失败';
|
2024-08-03 10:04:14 +08:00
|
|
|
} else {
|
2024-08-16 19:30:43 +08:00
|
|
|
$v['desc'] = '提现¥' . number_format($v['money'], 2) . ', 手续费: ¥' . $v['poundage'] . ', 实际到账 ¥' . $v['left_money'];
|
2024-08-03 10:04:14 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$result = [
|
|
|
|
|
'count' => $count,
|
|
|
|
|
'lists' => $list,
|
|
|
|
|
'more' => is_more($count, $get['page_no'], $get['page_size']),
|
|
|
|
|
'page_no' => $get['page_no'],
|
|
|
|
|
'page_size' => $get['page_size']
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
}
|