小程序我的排名点击提现会将记录添加到数据库中
This commit is contained in:
parent
72fa9bff26
commit
fa06a34e1c
@ -20,4 +20,16 @@ class Billions extends Api
|
||||
}
|
||||
return JsonServer::success('获取成功', $list);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 提现
|
||||
*/
|
||||
public function withdrawal()
|
||||
{
|
||||
$id = $this->request->post('billions_id');
|
||||
if (BillionsLogic::withdrawRecord($id, $this->user_id)) {
|
||||
return JsonServer::success('操作成功');
|
||||
}
|
||||
return JsonServer::error('操作失败');
|
||||
}
|
||||
}
|
||||
@ -4,6 +4,10 @@ namespace app\api\logic;
|
||||
|
||||
use app\common\basics\Logic;
|
||||
use app\common\model\billions\Billions;
|
||||
use app\common\model\subsidy_withdrawal\SubsidyWithdrawal;
|
||||
use app\common\model\subsidy_withdrawal\SubsidyWithdrawalRecord;
|
||||
use think\Exception;
|
||||
use think\facade\Db;
|
||||
|
||||
class BillionsLogic extends Logic
|
||||
{
|
||||
@ -57,4 +61,50 @@ class BillionsLogic extends Logic
|
||||
$where[] = ['state', '=', 0];
|
||||
return Billions::where($where)->count();
|
||||
}
|
||||
|
||||
// 提现进行记录
|
||||
public static function withdrawRecord($id, $user_id){
|
||||
Db::startTrans();
|
||||
try {
|
||||
$billions = Billions::where([
|
||||
'billions_id' => $id,
|
||||
'state' => 0
|
||||
])->find();
|
||||
|
||||
if ($billions) {
|
||||
Billions::where([
|
||||
'billions_id' => $id,
|
||||
'user_id' => $user_id,
|
||||
])->update(['state' => 1]);
|
||||
|
||||
// 查看用户是否有过余额添加记录
|
||||
$subsidy = SubsidyWithdrawal::where(['user_id' => $user_id])->find();
|
||||
if ($subsidy) {
|
||||
$subsidy_id = $subsidy->id;
|
||||
SubsidyWithdrawal::where(['user_id' => $user_id])->inc('total_amount', $billions->subsidy_price)->update();
|
||||
} else {
|
||||
$subsidy_id = SubsidyWithdrawal::insert([
|
||||
'user_id' => $user_id,
|
||||
'total_amount' => $billions->subsidy_price
|
||||
]);
|
||||
}
|
||||
|
||||
// 增加余额记录
|
||||
SubsidyWithdrawalRecord::insert([
|
||||
'subsidy_withdrawal_id' => $subsidy_id,
|
||||
'user_id' => $user_id,
|
||||
'billions_id' => $id,
|
||||
'type' => 1,
|
||||
'way' => 0,
|
||||
'money' => $billions->subsidy_price,
|
||||
'create_time' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (Exception $e) {
|
||||
Db::rollback();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -141,6 +141,15 @@ class MenuEnum{
|
||||
'link_type' => 1,
|
||||
'menu_type' => 1,
|
||||
],
|
||||
// 我的排名
|
||||
[
|
||||
'index' => 220,
|
||||
'name' => '补贴提现',
|
||||
'link' => '/bundle_b/pages/subsidy_withdrawal/subsidy_withdrawal',
|
||||
'is_tab' => 0,
|
||||
'link_type' => 1,
|
||||
'menu_type' => 1,
|
||||
],
|
||||
//商家入驻
|
||||
[
|
||||
'index' => 115,
|
||||
|
||||
17
app/common/model/subsidy_withdrawal/SubsidyWithdrawal.php
Normal file
17
app/common/model/subsidy_withdrawal/SubsidyWithdrawal.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* @package CipherSYS IM
|
||||
* @author Xiaowei Wang <wangxiaowei@ciphersys.com>
|
||||
* @copyright Copyright (c) 2022 - 2024, CipherSYS Co.,Ltd. (https://www.ciphersys.com/)
|
||||
* @license CipherSYS Commercial License
|
||||
* @link https://www.ciphersys.com
|
||||
*/
|
||||
|
||||
namespace app\common\model\subsidy_withdrawal;
|
||||
|
||||
use app\common\basics\Models;
|
||||
|
||||
class SubsidyWithdrawal extends Models
|
||||
{
|
||||
protected $table = 'ls_subsidy_withdrawal';
|
||||
}
|
||||
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* @package CipherSYS IM
|
||||
* @author Xiaowei Wang <wangxiaowei@ciphersys.com>
|
||||
* @copyright Copyright (c) 2022 - 2024, CipherSYS Co.,Ltd. (https://www.ciphersys.com/)
|
||||
* @license CipherSYS Commercial License
|
||||
* @link https://www.ciphersys.com
|
||||
*/
|
||||
|
||||
namespace app\common\model\subsidy_withdrawal;
|
||||
|
||||
use app\common\basics\Models;
|
||||
|
||||
class SubsidyWithdrawalRecord extends Models
|
||||
{
|
||||
protected $table = 'ls_subsidy_withdrawal_record';
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user