diff --git a/app/api/controller/Billions.php b/app/api/controller/Billions.php index b41f4861..3390b87f 100644 --- a/app/api/controller/Billions.php +++ b/app/api/controller/Billions.php @@ -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('操作失败'); + } } \ No newline at end of file diff --git a/app/api/logic/BillionsLogic.php b/app/api/logic/BillionsLogic.php index 68a1bc3f..a2677064 100644 --- a/app/api/logic/BillionsLogic.php +++ b/app/api/logic/BillionsLogic.php @@ -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; + } + } } \ No newline at end of file diff --git a/app/common/enum/MenuEnum.php b/app/common/enum/MenuEnum.php index 9e699e99..dffb7fb5 100644 --- a/app/common/enum/MenuEnum.php +++ b/app/common/enum/MenuEnum.php @@ -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, diff --git a/app/common/model/subsidy_withdrawal/SubsidyWithdrawal.php b/app/common/model/subsidy_withdrawal/SubsidyWithdrawal.php new file mode 100644 index 00000000..f2cd218b --- /dev/null +++ b/app/common/model/subsidy_withdrawal/SubsidyWithdrawal.php @@ -0,0 +1,17 @@ + + * @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'; +} \ No newline at end of file diff --git a/app/common/model/subsidy_withdrawal/SubsidyWithdrawalRecord.php b/app/common/model/subsidy_withdrawal/SubsidyWithdrawalRecord.php new file mode 100644 index 00000000..99ad2d2a --- /dev/null +++ b/app/common/model/subsidy_withdrawal/SubsidyWithdrawalRecord.php @@ -0,0 +1,17 @@ + + * @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'; +} \ No newline at end of file