286 lines
10 KiB
PHP
286 lines
10 KiB
PHP
<?php
|
||
|
||
/**
|
||
* SaaSMall商城系统 - 团队十年电商经验汇集巨献!
|
||
* =========================================================
|
||
* Copy right 2019-2029 成都SAAS云科技有限公司, 保留所有权利。
|
||
* ----------------------------------------------
|
||
* 官方网址: https://www.gobuysaas.com
|
||
* =========================================================
|
||
*/
|
||
|
||
namespace app\model\account;
|
||
|
||
use app\model\BaseModel;
|
||
use app\model\system\Config;
|
||
use think\Exception;
|
||
use think\facade\Db;
|
||
|
||
class Account extends BaseModel{
|
||
public array $defaultConfig = [
|
||
'account_type' => [],// 转账方式
|
||
'commission_handling_fees' => '',// 平台抽成相关收益提现手续费(百分比)
|
||
];
|
||
|
||
public array $defaultPointConfig = [
|
||
'is_open' => 0,// 是否开启转增
|
||
'commission_handling_fees' => 0,// 手续费(百分比)
|
||
];
|
||
|
||
/**
|
||
* Common: 财务设置 - 设置
|
||
* Author: wu-hui
|
||
* Time: 2024/05/22 13:35
|
||
* @param int $siteId
|
||
* @param array $data
|
||
* @return array
|
||
*/
|
||
public function setConfig(int $siteId = 0,array $data = []){
|
||
$setWhere = [
|
||
['site_id','=', $siteId],
|
||
['app_module','=','shop'],
|
||
['config_key','=','finance_setting']
|
||
];
|
||
|
||
return (new Config())->setConfig($data, '财务设置', 1, $setWhere);
|
||
}
|
||
/**
|
||
* Common: 财务设置 - 获取
|
||
* Author: wu-hui
|
||
* Time: 2024/05/22 13:35
|
||
* @param int $siteId
|
||
* @return array|string[]
|
||
*/
|
||
public function getConfig(int $siteId = 0){
|
||
$setWhere = [
|
||
['site_id','=', $siteId],
|
||
['app_module','=','shop'],
|
||
['config_key','=','finance_setting']
|
||
];
|
||
$res = (new Config())->getConfig($setWhere);
|
||
$value = $res['data'] ? $res['data']['value'] : [];
|
||
|
||
return array_merge($this->defaultPointConfig, $value);
|
||
}
|
||
|
||
/**
|
||
* Common: 财务设置 - 设置
|
||
* Author: wu-hui
|
||
* Time: 2024/05/22 13:35
|
||
* @param int $siteId
|
||
* @param array $data
|
||
* @return array
|
||
*/
|
||
public function setPointConfig(int $siteId = 0,array $data = []){
|
||
$setWhere = [
|
||
['site_id','=', $siteId],
|
||
['app_module','=','shop'],
|
||
['config_key','=','point_give_setting']
|
||
];
|
||
|
||
return (new Config())->setConfig($data, '积分转赠设置', 1, $setWhere);
|
||
}
|
||
/**
|
||
* Common: 财务设置 - 获取
|
||
* Author: wu-hui
|
||
* Time: 2024/05/22 13:35
|
||
* @param int $siteId
|
||
* @return array|string[]
|
||
*/
|
||
public function getPointConfig(int $siteId = 0){
|
||
$setWhere = [
|
||
['site_id','=', $siteId],
|
||
['app_module','=','shop'],
|
||
['config_key','=','point_give_setting']
|
||
];
|
||
$res = (new Config())->getConfig($setWhere);
|
||
$value = $res['data'] ? $res['data']['value'] : [];
|
||
|
||
return array_merge($this->defaultPointConfig, $value);
|
||
}
|
||
|
||
/**
|
||
* Common: 编辑用户提现账户信息
|
||
* Author: wu-hui
|
||
* Time: 2024/05/22 16:52
|
||
* @param $params
|
||
* @return int|string
|
||
*/
|
||
public function editInfo($params){
|
||
$id = $params['id'] ?? 0;
|
||
$data = [
|
||
'site_id' => $params['site_id'] ?? 0,
|
||
'member_id' => $params['member_id'] ?? 0,
|
||
'realname' => $params['realname'] ?? '',
|
||
'mobile' => $params['mobile'] ?? '',
|
||
'account_type' => $params['account_type'] ?? '',
|
||
'alipay_account' => $params['alipay_account'] ?? '',
|
||
'card_type' => $params['card_type'] ?? '',
|
||
'bank_sub_name' => $params['bank_sub_name'] ?? '',
|
||
'account_id_start' => $params['account_id_start'] ?? '',
|
||
'bank_act_name' => $params['bank_act_name'] ?? '',
|
||
'card_num' => $params['card_num'] ?? '',
|
||
'account_id' => $params['account_id'] ?? '',
|
||
'mer_type' => $params['mer_type'] ?? '',
|
||
];
|
||
|
||
if($id > 0) return model('member_finance_account')->update($data,['id'=>$id]);
|
||
else return model('member_finance_account')->add($data);
|
||
}
|
||
/**
|
||
* Common: 修改默认账户
|
||
* Author: wu-hui
|
||
* Time: 2024/05/22 16:58
|
||
* @param $memberId
|
||
* @param $id
|
||
*/
|
||
public function setDefaultAccount($memberId,$id){
|
||
model('member_finance_account')->update([
|
||
'is_default' => 0
|
||
],['member_id' => $memberId]);
|
||
model('member_finance_account')->update([
|
||
'is_default' => 1
|
||
],['id' => $id,'member_id' => $memberId]);
|
||
}
|
||
/**
|
||
* Common: 获取指定类型的用户可提现金额
|
||
* Author: wu-hui
|
||
* Time: 2024/05/22 17:55
|
||
* @param $memberId
|
||
* @param $incomeType
|
||
* @return int|mixed
|
||
*/
|
||
public function getIncomeMoney($memberId, $incomeType){
|
||
$incomeMoney = 0;
|
||
switch($incomeType){
|
||
case 'commission':
|
||
$incomeMoney = model('member')->getValue([
|
||
['member_id', '=', $memberId]
|
||
],'commission_money');
|
||
break;
|
||
}
|
||
|
||
return $incomeMoney;
|
||
}
|
||
/**
|
||
* Common: 获取提现申请列表
|
||
* Author: wu-hui
|
||
* Time: 2024/05/23 9:19
|
||
* @param $page
|
||
* @param $params
|
||
* @return array
|
||
*/
|
||
public function getPageList($page, $params){
|
||
// 生成查询条件
|
||
$where = [];
|
||
if(isset($params['site_id']) && $params['site_id'] !== '') $where[] = ['a.site_id', '=', $params['site_id']];
|
||
if(isset($params['member_id']) && $params['member_id'] !== '') $where[] = ['a.member_id', '=', $params['member_id']];
|
||
if(isset($params['status']) && $params['status'] !== '') $where[] = ['a.status', '=', $params['status']];
|
||
// 关联查询
|
||
$join = [
|
||
[ 'site s', 's.site_id = a.site_id', 'left' ],
|
||
[ 'member m', 'm.member_id = a.member_id', 'left' ],
|
||
[ 'member_finance_account mfa', 'mfa.id = a.finance_account_id', 'left' ]
|
||
];
|
||
$field = [
|
||
'a.*',
|
||
'm.nickname',
|
||
'm.username',
|
||
'm.headimg',
|
||
'mfa.realname',
|
||
'mfa.mobile',
|
||
'mfa.account_type',
|
||
'mfa.alipay_account',
|
||
'mfa.card_num',
|
||
's.site_name',
|
||
's.username as site_username',
|
||
's.logo as site_logo',
|
||
];
|
||
$result = model('member_finance_apply')->pageList($where, $field,'a.id DESC',$page,PAGE_LIST_ROWS,'a',$join);
|
||
|
||
return $this->success($result);
|
||
}
|
||
/**
|
||
* Common: 打款操作
|
||
* Author: wu-hui
|
||
* Time: 2024/05/23 10:59
|
||
* @param $params
|
||
* @return array|mixed|string|void
|
||
*/
|
||
public function paymentOperation($params){
|
||
// auto=自动打款;manual=线下手动打款
|
||
Db::startTrans();
|
||
try{
|
||
$info = model('member_finance_apply')->getInfo([
|
||
['id', '=', $params['id']]
|
||
]);
|
||
// 如果是自动打款 进行打款操作
|
||
if($params['type'] == 'auto'){
|
||
// 账户类型:card=银行卡,wechat=微信零钱,alipay=支付宝,balance=余额,threeStaff=第三方打款(灵活用工)
|
||
$accountInfo = model('member_finance_account')->getInfo([
|
||
['id', '=', $info['finance_account_id']]
|
||
]);
|
||
switch($accountInfo['account_type']){
|
||
// 银行卡
|
||
case 'card':throw new Exception('当前类型自动打款功能未开启!');break;
|
||
// 微信零钱
|
||
case 'wechat':
|
||
$pay_data = [
|
||
'id' => $params['id'],
|
||
'out_trade_no' => 'tx'.date('YmdHis') . rand(1000, 9999),
|
||
'real_name' => $accountInfo['realname'],
|
||
'amount' => $info['money'],
|
||
'desc' => '会员提现',
|
||
'transfer_type' => 'wechatpay',
|
||
'account_number' => '',
|
||
'site_id' => $accountInfo['site_id'],
|
||
'is_weapp' => 1,// 是否为小程序端申请
|
||
'member_id' => $info['member_id']
|
||
];
|
||
//调用在线转账借口
|
||
$pay_result = event('PayTransfer', $pay_data, true);
|
||
if (empty($pay_result)) $pay_result = $this->error();
|
||
if ($pay_result[ 'code' ] < 0) return $pay_result;
|
||
break;
|
||
// 支付宝
|
||
case 'alipay':throw new Exception('当前类型自动打款功能未开启!');break;
|
||
// 余额
|
||
case 'balance':throw new Exception('当前类型自动打款功能未开启!');break;
|
||
// 第三方打款
|
||
case 'threeStaff':throw new Exception('当前类型自动打款功能未开启!');break;
|
||
}
|
||
}
|
||
// 修改状态
|
||
model('member_finance_apply')->update(['status' => 2],[
|
||
'id' => $params['id']
|
||
]);
|
||
// 修改申请打款方信息
|
||
if($info['apply_site_id'] > 0){
|
||
// 店铺提现
|
||
model('shop')->setDec([
|
||
['site_id', '=', $info['apply_site_id']]
|
||
],'frozen_money', (float)$info['apply_money']);
|
||
model('shop')->setInc([
|
||
['site_id', '=', $info['apply_site_id']]
|
||
],'withdrawn_money', (float)$info['apply_money']);
|
||
}else{
|
||
// 用户提现
|
||
model('member')->setDec([
|
||
['member_id', '=', $info['member_id']]
|
||
],'commission_freeze', (float)$info['apply_money']);
|
||
}
|
||
|
||
Db::commit();
|
||
return $this->success();
|
||
}catch(\Exception $e){
|
||
Db::rollback();
|
||
|
||
return $this->error($e->getMessage());
|
||
}
|
||
}
|
||
|
||
|
||
|
||
|
||
}
|