其余文件

This commit is contained in:
2026-04-14 17:46:22 +08:00
parent 294b68fe37
commit 3691f4db22
1343 changed files with 189847 additions and 0 deletions

View File

@ -0,0 +1,233 @@
<?php
namespace app\admin\logic\finance;
use app\common\basics\Logic;
use app\common\model\AccountLog;
use app\common\model\order\Order;
use app\common\enum\PayEnum;
use app\common\enum\OrderEnum;
use app\common\enum\OrderRefundEnum;
use app\common\enum\AfterSaleEnum;
use app\common\enum\WithdrawalEnum;
use app\common\enum\DistributionOrderGoodsEnum;
use app\common\enum\WithdrawEnum;
use app\common\model\user\User;
use app\common\model\shop\Shop;
use app\common\model\shop\ShopWithdrawal;
use app\common\model\shop\ShopSettlement;
use app\common\model\WithdrawApply;
class FinanceLogic extends Logic
{
/**
* @Notes: 商家汇总
*/
public static function shop()
{
$model = new Order();
$modelShopSettlement = new ShopSettlement();
$modelShopWithdrawal = new ShopWithdrawal();
$modelWithdrawApply = new WithdrawApply();
//已结算交易服务费(平台收入)、(商家)已结算交易服务费
$shopAmount = $settlePoundageAmount = $modelShopSettlement
->sum('trade_service_fee');
//会员提现手续费(平台收入
$userPoundage = $modelWithdrawApply
->where([
['status', '=', WithdrawEnum::STATUS_SUCCESS]
])
->sum('poundage');
//商家提现手续费(平台收入)
$commissionAmount = $modelShopWithdrawal
->sum('poundage_amount');
//成交订单笔数
$orderNum = $model
->where([
['pay_status', '>', PayEnum::UNPAID]
])
->count('id');
//营业额
$orderAmount = $model
->where([
['pay_status', '>', PayEnum::UNPAID]
])
->sum('order_amount');
//退款订单金额
$refundAmount = $model
->where([
['shipping_status', '=', OrderEnum::SHIPPING_NO],
['pay_status', '=', PayEnum::REFUNDED],
['refund_status', 'in', [OrderEnum::REFUND_STATUS_PART_REFUND, OrderEnum::REFUND_STATUS_ALL_REFUND]],
])
->sum('refund_amount');
//待退款订单金额
$refundAmountIng = $model->alias('o')
->join('order_refund or', 'or.order_id = o.id')
->where([
['o.shipping_status', '=', OrderEnum::SHIPPING_NO],
['or.refund_status', '<>', OrderRefundEnum::REFUND_STATUS_COMPLETE]
])
->sum('or.refund_amount');
//售后退款金额
$salesRefundAmount = $model->alias('o')
->join('after_sale as', 'as.order_id = o.id')
->where([
['o.shipping_status', '=', OrderEnum::SHIPPING_FINISH],
['as.status', '=', AfterSaleEnum::STATUS_COMPLETE]
])
->sum('as.refund_price');
//待售后退款金额
$salesRefundAmountIng = $model->alias('o')
->join('after_sale as', 'as.order_id = o.id')
->where([
['o.shipping_status', '=', OrderEnum::SHIPPING_FINISH],
['as.status', '=', AfterSaleEnum::STATUS_WAITING]
])
->sum('as.refund_price');
//已结算成交订单数
$settleOrederNum = $modelShopSettlement
->sum('deal_order_count');
//已结算营业额
$settleOrederAmount = $modelShopSettlement
->sum('business_money');
//待结算营业额
$settleOrederAmountWait = $model
->where([
['refund_status', '=', 0 ],
['settle_id', '=', OrderEnum::SETTLE_WAIT],
['order_status', 'in', [OrderEnum::ORDER_STATUS_DELIVERY,OrderEnum::ORDER_STATUS_GOODS,OrderEnum::ORDER_STATUS_COMPLETE]]
])
->sum('order_amount');
//已结算分销佣金金额
$settleDistributionAmount = $modelShopSettlement
->sum('distribution_money');
//已结算入账金额
$settleWithdrawalAmount = $modelShopSettlement
->sum('entry_account_money');
//已提现金额
$withdrawaLeftamount = $modelShopWithdrawal
->where([
['status', '=', WithdrawalEnum::SUCCESS_STATUS]
])
->sum('apply_amount');
//提现中金额
$withdrawaLeftamountIng = $modelShopWithdrawal
->where([
['status', '=', WithdrawalEnum::HANDLE_STATUS]
])
->sum('apply_amount');
//可提现金额
$modelShop = new Shop();
$shopWallet = $modelShop->sum('wallet');
//会员余额
$modelUser = new User();
$userMoney = $modelUser
->where([
['del', '=', 0]
])
->sum('user_money');
//会员已结算分销佣金金额
$userSettleDistributionAmount = $model->alias('o')
->join('order_goods og', 'og.order_id = o.id')
->join('distribution_order_goods dog', 'dog.order_goods_id = og.id')
->where([
['o.settle_id', '=', OrderEnum::SETTLE_FINISH],
['dog.status', '=', DistributionOrderGoodsEnum::STATUS_SUCCESS]
])
->sum('dog.money');
//已提现佣金金额
$userDistributionMoney = $modelWithdrawApply
->where([
['status', '=', WithdrawEnum::STATUS_SUCCESS]
])
->sum('money');
//提现中佣金金额
$userDistributionMoneyIng = $modelWithdrawApply
->where([
['status', '=', WithdrawEnum::STATUS_ING]
])
->sum('money');
//可提现佣金金额
$userDistributionMoneyWait = $modelUser
->where([
['del', '=', 0]
])
->sum('earnings');
//总积分
$all_integral = AccountLog::where(['change_type'=>1,'source_type'=>AccountLog::integral_change])->sum('change_amount');
//签到送出积分
$sign_in_integral = AccountLog::where(['source_type'=>AccountLog::sign_in_integral])->sum('change_amount');
//使用积分
$use_integral = AccountLog::where(['change_type'=>2,'source_type'=>AccountLog::integral_change])->sum('change_amount');
//下单赠送积分
$consume_award_integral = AccountLog::where(['source_type'=>AccountLog::consume_award_integral])->sum('change_amount');
return [
'shopAmount' => $shopAmount, //已结算交易服务费(平台收入)
'userPoundage' => $userPoundage, //会员提现手续费(平台收入)
'commissionAmount' => $commissionAmount, //提现中佣金金额
'orderNum' => $orderNum, //成交订单笔数
'orderAmount' => $orderAmount, //营业额
'refundAmount' => $refundAmount, //退款订单金额
'refundAmountIng' => $refundAmountIng, //待退款订单金额
'salesRefundAmount' => $salesRefundAmount, //售后退款金额
'salesRefundAmountIng' => $salesRefundAmountIng, //待售后退款金额
'settleOrederNum' => $settleOrederNum, //已结算成交订单数
'settleOrederAmount' => $settleOrederAmount, //已结算营业额
'settleOrederAmountWait' => $settleOrederAmountWait, //待结算营业额
'settleDistributionAmount' => $settleDistributionAmount, //已结算分销佣金金额
'settleWithdrawalAmount' => $settleWithdrawalAmount, //已结算入账金额
'settlePoundageAmount' => $settlePoundageAmount, //已结算交易服务费
'withdrawaLeftamount' => $withdrawaLeftamount, //已提现金额
'withdrawaLeftamountIng' => $withdrawaLeftamountIng, //提现中金额
'shopWallet' => $shopWallet, //可提现金额
'userMoney' => $userMoney, //会员余额
'userSettleDistributionAmount' => $userSettleDistributionAmount, //会员已结算分销佣金金额
'userDistributionMoney' => $userDistributionMoney, //已提现佣金金额
'userDistributionMoneyIng' => $userDistributionMoneyIng, //提现中佣金金额
'userDistributionMoneyWait' => $userDistributionMoneyWait, //可提现佣金金额
'all_integral' => $all_integral, //总积分
'sign_in_integral' => $sign_in_integral, //签到送出积分
'use_integral' => $use_integral, //使用积分
'consume_award_integral' => $consume_award_integral, //下单赠送积分
];
}
}

View File

@ -0,0 +1,123 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权购买去版权授权后方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\admin\logic\finance;
use app\common\basics\Logic;
use app\common\model\AccountLog;
use app\common\server\ExportExcelServer;
class IntegralLogic extends Logic
{
/**
* @notes 积分明细
* @param $get
* @return array
* @author ljj
* @date 2022/2/22 5:59 下午
*/
public static function integral($get, $is_export = false)
{
$where[] = ['source_type','in',AccountLog::integral_change];
//用户信息
if (isset($get['user_info']) && $get['user_info'] != '') {
$where[] = ['u.sn|u.nickname', '=', $get['user_info']];
}
//开始时间
if (isset($get['start_time']) && $get['start_time'] != '') {
$where[] = ['al.create_time', '>=', strtotime($get['start_time'])];
}
//结束时间
if (isset($get['end_time']) && $get['end_time'] != '') {
$where[] = ['al.create_time', '<=', strtotime($get['end_time'])];
}
// 导出
if (true === $is_export) {
return self::export($where);
}
$lists = AccountLog::alias('al')
->join('user u', 'al.user_id = u.id')
->field('al.id,al.user_id,al.source_type,al.change_amount,al.left_amount,al.remark,al.change_type,al.create_time,u.sn as user_sn,u.nickname')
->where($where)
->page($get['page'], $get['limit'])
->order('id','desc')
->select()
->toArray();
foreach ($lists as &$list) {
$list['change_amount'] = $list['change_type'] == 1 ? '+'.$list['change_amount'] : '-'.$list['change_amount'];
}
$count = AccountLog::alias('al')
->join('user u', 'al.user_id = u.id')
->where($where)
->count();
return ['count' => $count, 'lists' => $lists];
}
/**
* @notes 导出商家账户明细Excel
* @param array $where
* @return array|false
* @author 段誉
* @date 2022/4/24 10:10
*/
public static function export($where)
{
try {
$lists = AccountLog::alias('al')
->join('user u', 'al.user_id = u.id')
->field('al.id,al.user_id,al.source_type,al.change_amount,al.left_amount,al.remark,al.change_type,al.create_time,u.sn as user_sn,u.nickname')
->where($where)
->order('id','desc')
->select()
->toArray();
foreach ($lists as &$list) {
$list['change_amount'] = $list['change_type'] == 1 ? '+'.$list['change_amount'] : '-'.$list['change_amount'];
}
$excelFields = [
'user_sn' => '用户编号',
'nickname' => '会员信息',
'source_type' => '变动类型',
'change_amount' => '积分变动',
'left_amount' => '剩余积分',
'remark' => '备注',
'create_time' => '变动时间',
];
$export = new ExportExcelServer();
$export->setFileName('积分明细');
$result = $export->createExcel($excelFields, $lists);
return ['url' => $result];
} catch (\Exception $e) {
self::$error = $e->getMessage();
return false;
}
}
}

View File

@ -0,0 +1,233 @@
<?php
namespace app\admin\logic\finance;
use app\common\basics\Logic;
use app\common\enum\ShopEnum;
use app\common\enum\PayEnum;
use app\common\enum\OrderEnum;
use app\common\model\order\Order;
use app\common\model\shop\ShopSettlement;
use app\common\model\shop\ShopSettlementRecord;
use app\common\server\ExportExcelServer;
use app\common\server\UrlServer;
class ShopSettlementLogic extends Logic
{
/**
* @Notes: 商家结算列表
* @Author: 张无忌
* @param $get
* @return array
*/
public static function lists($get, $is_export = false)
{
try {
$where = [];
if (!empty($get['name'])) {
$where[] = ['S.name', 'like', '%'.$get['name'].'%'];
}
if (!empty($get['start_time'])) {
$where[] = ['SL.create_time', '>=', strtotime($get['start_time'])];
}
if (!empty($get['end_time'])) {
$where[] = ['SL.create_time', '<=', strtotime($get['end_time'])];
}
// 导出
if (true === $is_export) {
return self::settlementExport($where);
}
$model = new ShopSettlement();
$lists = $model->field([
'SL.id,SL.shop_id,S.name,S.type,S.logo',
'sum(SL.deal_order_count) AS deal_order_count',
'sum(SL.business_money) AS business_money',
])->alias('SL')
->join('shop S', 'S.id = SL.shop_id')
->group('shop_id')
->where($where)
->paginate([
'page' => $get['page'],
'list_rows' => $get['limit'],
'var_page' => 'page'
])->toArray();
foreach ($lists['data'] as &$item) {
$item['type'] = ShopEnum::getShopTypeDesc($item['type']);
$item['logo'] = UrlServer::getFileUrl($item['logo']);
}
return ['count'=>$lists['total'], 'lists'=>$lists['data']];
} catch (\Exception $e) {
return ['error'=>$e->getMessage()];
}
}
/**
* @Notes: 商家结算记录
* @Author: 张无忌
* @param $get
* @return array
*/
public static function record($get)
{
try {
$model = new ShopSettlement();
$lists = $model->field(true)
->where(['shop_id'=>$get['shop_id']])
->order('id', 'desc')
->paginate([
'page' => $get['page'],
'list_rows' => $get['limit'],
'var_page' => 'page'
])
->toArray();
return ['count'=>$lists['total'], 'lists'=>$lists['data']];
} catch (\Exception $e) {
return ['error'=>$e->getMessage()];
}
}
/**
* @Notes: 结算详细
* @Author: 张无忌
* @param $get
* @return array
*/
public static function detail($get)
{
try {
$where[] = ['settle_id', '=', (int)$get['settle_id']];
if (!empty($get['order_sn']) and $get['order_sn'])
$where[] = ['order_sn', 'like', '%'.$get['order_sn'].'%'];
$model = new ShopSettlementRecord();
$lists = $model->field(true)
->where($where)
->order('id', 'asc')
->paginate([
'page' => $get['page'],
'list_rows' => $get['limit'],
'var_page' => 'page'
])
->toArray();
return ['count'=>$lists['total'], 'lists'=>$lists['data']];
} catch (\Exception $e) {
return ['error'=>$e->getMessage()];
}
}
/**
* @Notes: 结算统计
* @return array
*/
public static function statistics($shop_id = 0)
{
$where = [];
if($shop_id){
$where[] = ['shop_id', '=' , $shop_id];
}
//营业额
$modelOrder = new Order();
//已结算成交订单数
$modelShopSettlement = new ShopSettlement();
$settleOrederNum = $modelShopSettlement
->where($where)
->sum('deal_order_count');
//已结算营业额
$settleOrederAmount = $modelShopSettlement
->where($where)
->sum('business_money');
//待结算营业额
$settleOrederAmountWait = $modelOrder
->where([
['pay_status', '>', PayEnum::UNPAID],
['settle_id', '=', OrderEnum::SETTLE_WAIT]
])
->sum('order_amount');
//已结算分销佣金金额
$settleDistributionAmount = $modelShopSettlement
->where($where)
->sum('distribution_money');
//已结算入账金额
$settleWithdrawalAmount = $modelShopSettlement
->where($where)
->sum('entry_account_money');
//已结算交易服务费
$settlePoundageAmount = $modelShopSettlement
->where($where)
->sum('trade_service_fee');
return [
'settleOrederNum' => $settleOrederNum, //已结算成交订单数
'settleOrederAmount' => $settleOrederAmount, //已结算营业额
'settleOrederAmountWait' => $settleOrederAmountWait, //待结算营业额
'settleDistributionAmount' => $settleDistributionAmount, //已结算分销佣金金额
'settleWithdrawalAmount' => $settleWithdrawalAmount, //已结算入账金额
'settlePoundageAmount' => $settlePoundageAmount, //已结算交易服务费
];
}
/**
* @notes 导出商家结算Excel
* @param array $where
* @return array|false
* @author 段誉
* @date 2022/4/24 10:10
*/
public static function settlementExport($where)
{
try {
$model = new ShopSettlement();
$lists = $model->field([
'SL.id,SL.shop_id,S.name,S.type,S.logo',
'sum(SL.deal_order_count) AS deal_order_count',
'sum(SL.business_money) AS business_money',
])->alias('SL')
->join('shop S', 'S.id = SL.shop_id')
->group('shop_id')
->where($where)
->select()
->toArray();
foreach ($lists as &$item) {
$item['type'] = ShopEnum::getShopTypeDesc($item['type']);
}
$excelFields = [
'name' => '商家名称',
'type' => '商家类型',
'deal_order_count' => '已结算成交订单数',
'business_money' => '已结算营业额',
];
$export = new ExportExcelServer();
$export->setFileName('商家结算');
$result = $export->createExcel($excelFields, $lists);
return ['url' => $result];
} catch (\Exception $e) {
self::$error = $e->getMessage();
return false;
}
}
}

View File

@ -0,0 +1,446 @@
<?php
namespace app\admin\logic\finance;
use app\common\basics\Logic;
use app\common\enum\ShopEnum;
use app\common\enum\ShopWithdrawEnum;
use app\common\enum\WithdrawalEnum;
use app\common\model\shop\Shop;
use app\common\model\shop\ShopAccountLog;
use app\common\model\shop\ShopAlipay;
use app\common\model\shop\ShopBank;
use app\common\model\shop\ShopWithdrawal;
use app\common\server\ExportExcelServer;
use app\common\server\UrlServer;
use app\common\server\YansongdaAliPayTransferServer;
class ShopWithdrawalLogic extends Logic
{
/**
* @Notes: 申请提现记录列表
* @Author: 张无忌
* @param $get
* @return array
*/
public static function lists($get, $is_export = false)
{
try {
$where[] = ['status', '=', $get['type'] ?? 0];
if (!empty($get['start_time']) and $get['start_time']) {
$where[] = ['create_time', '>=', strtotime($get['start_time'])];
}
if (!empty($get['end_time']) and $get['end_time']) {
$where[] = ['create_time', '<=', strtotime($get['start_time'])];
}
// 导出
if (true === $is_export) {
return self::withdrawalExport($where);
}
$model = new ShopWithdrawal();
$lists = $model->field(true)
->where($where)
->with(['shop'])
->order('id desc')
->paginate([
'page' => $get['page'],
'list_rows' => $get['limit'],
'var_page' => 'page'
])->toArray();
foreach ($lists['data'] as &$item) {
$item['status_text'] = WithdrawalEnum::getStatusDesc($item['status']);
}
return ['count'=>$lists['total'], 'lists'=>$lists['data']];
} catch (\Exception $e) {
static::$error = $e->getMessage();
return ['error'=>$e->getMessage()];
}
}
/**
* @Notes: 统计
* @Author: 张无忌
* @return array
*/
public static function statistics()
{
$model = new ShopWithdrawal();
$apply = $model->where(['status'=>WithdrawalEnum::APPLY_STATUS])->count();
$handle = $model->where(['status'=>WithdrawalEnum::HANDLE_STATUS])->count();
$success = $model->where(['status'=>WithdrawalEnum::SUCCESS_STATUS])->count();
$error = $model->where(['status'=>WithdrawalEnum::ERROR_STATUS])->count();
return ['apply'=>$apply, 'handle'=>$handle, 'success'=>$success, 'error'=>$error];
}
/**
* @Notes: 数据汇总
* @Author: 张无忌
*/
public static function summary()
{
$model = new ShopWithdrawal();
$successWithdrawn = $model->where(['status'=>WithdrawalEnum::SUCCESS_STATUS])->sum('apply_amount');
$handleWithdrawn = $model->where(['status'=>WithdrawalEnum::HANDLE_STATUS])->sum('apply_amount');
$totalWallet = (new Shop())->where(['del'=>0])->sum('wallet');
return ['successWithdrawn'=>$successWithdrawn, 'handleWithdrawn'=>$handleWithdrawn, 'totalWallet'=>$totalWallet];
}
/**
* @Notes: 提现详细
* @Author: 张无忌
* @param $id
* @return array
*/
public static function detail($id)
{
$withdrawal = (new ShopWithdrawal())->findOrEmpty($id)->toArray();
$shop = (new Shop())->with(['category'])->findOrEmpty($withdrawal['shop_id'])->toArray();
$bank = (new ShopBank())->findOrEmpty($withdrawal['bank_id'])->toArray();
$alipay = (new ShopAlipay())->findOrEmpty($withdrawal['alipay_id'])->toArray();
$shop['type'] = ShopEnum::getShopTypeDesc($shop['type']);
$withdrawal['status_text'] = WithdrawalEnum::getStatusDesc($withdrawal['status']);
$withdrawal['type_text'] = ShopWithdrawEnum::getTypeText($withdrawal['type']);
return [ 'withdrawal' => $withdrawal, 'shop' => $shop, 'bank' => $bank, 'alipay' => $alipay ];
}
/**
* @Notes: 审核提现
* @Author: 张无忌
* @param $post
* @return bool
*/
public static function examine($post)
{
try {
if ($post['is_examine']) {
// 同意提现
ShopWithdrawal::update([
'explain' => $post['explain'] ?? '',
'status' => WithdrawalEnum::HANDLE_STATUS,
'update_time' => time()
], ['id'=>$post['id']]);
} else {
// 拒绝提现
$withdrawal = (new ShopWithdrawal())->findOrEmpty($post['id'])->toArray();
ShopWithdrawal::update([
'explain' => $post['explain'] ?? '',
'status' => WithdrawalEnum::ERROR_STATUS,
'update_time' => time()
], ['id'=>$post['id']]);
Shop::update([
'wallet' => ['inc', $withdrawal['apply_amount']],
'update_time' => time()
], ['id'=>$withdrawal['shop_id']]);
(new ShopAccountLog())->where([
'source_id' => $withdrawal['id'],
'source_sn' => $withdrawal['sn']
])->update([
'change_type' => 1,
'left_amount' => ['inc', $withdrawal['apply_amount']],
'source_type' => ShopAccountLog::withdrawal_fail_money
]);
}
return true;
} catch (\Exception $e) {
static::$error = $e->getMessage();
return false;
}
}
/**
* @Notes: 审核提现转账
* @Author: 张无忌
* @param $post
* @return bool
*/
public static function transfer($post)
{
try {
if ($post['is_examine']) {
// 转账成功
ShopWithdrawal::update([
'transfer_content' => $post['transfer_content'] ?? '',
'status' => WithdrawalEnum::SUCCESS_STATUS,
'transfer_voucher' => $post['image'] ?? '',
'transfer_time' => time(),
'update_time' => time()
], ['id'=>(int)$post['id']]);
$withdrawal = (new ShopWithdrawal())->findOrEmpty($post['id'])->toArray();
(new ShopAccountLog())->where([
'source_id' => $withdrawal['id'],
'source_sn' => $withdrawal['sn']
])->update([
'change_type' => 2,
'source_type' => ShopAccountLog::withdrawal_dec_money
]);
} else {
// 转账失败
$withdrawal = (new ShopWithdrawal())->findOrEmpty($post['id'])->toArray();
ShopWithdrawal::update([
'transfer_content' => $post['transfer_content'] ?? '',
'status' => WithdrawalEnum::ERROR_STATUS,
'transfer_voucher' => $post['image'] ?? '',
'transfer_time' => time(),
'update_time' => time()
], ['id'=>$post['id']]);
Shop::update([
'wallet' => ['inc', $withdrawal['apply_amount']],
'update_time' => time()
], ['id'=>$withdrawal['shop_id']]);
(new ShopAccountLog())->where([
'source_id' => $withdrawal['id'],
'source_sn' => $withdrawal['sn']
])->update([
'change_type' => 1,
'left_amount' => ['inc', $withdrawal['apply_amount']],
'source_type' => ShopAccountLog::withdrawal_fail_money
]);
}
return true;
} catch (\Exception $e) {
static::$error = $e->getMessage();
return false;
}
}
static function transfer_online($post) : bool
{
try {
$detail = ShopWithdrawal::with([ 'alipay' ])->findOrEmpty($post['id']);
$result = (new YansongdaAliPayTransferServer())->shopWithdrawTransfer($detail);
if (true === $result) {
// 转账成功
ShopWithdrawal::update([
'explain' => '',
'status' => WithdrawalEnum::SUCCESS_STATUS,
'transfer_voucher' => '',
'transfer_time' => time(),
'update_time' => time()
], [ 'id' => (int) $post['id'] ]);
$withdrawal = (new ShopWithdrawal())->findOrEmpty($post['id'])->toArray();
(new ShopAccountLog())->where([
'source_id' => $withdrawal['id'],
'source_sn' => $withdrawal['sn']
])->update([
'change_type' => 2,
'source_type' => ShopAccountLog::withdrawal_dec_money
]);
} else {
static::$error = (string) $result;
// 转账失败
$withdrawal = (new ShopWithdrawal())->findOrEmpty($post['id'])->toArray();
ShopWithdrawal::update([
'explain' => '支付宝转账失败',
'status' => WithdrawalEnum::ERROR_STATUS,
'transfer_voucher' => '',
'transfer_time' => time(),
'update_time' => time()
], [ 'id' => $post['id'] ]);
Shop::update([
'wallet' => ['inc', $withdrawal['apply_amount']],
'update_time' => time()
], [ 'id' => $withdrawal['shop_id'] ]);
(new ShopAccountLog())->where([
'source_id' => $withdrawal['id'],
'source_sn' => $withdrawal['sn']
])->update([
'change_type' => 1,
'left_amount' => ['inc', $withdrawal['apply_amount']],
'source_type' => ShopAccountLog::withdrawal_fail_money
]);
}
return true;
} catch (\Throwable $e) {
static::$error = $e->getMessage();
return false;
}
}
/**
* @Notes: 账户明细
* @Author: 张无忌
* @param $get
* @return array
*/
public static function account($get, $is_export = false)
{
$where = [];
if (isset($get['shop_name']) && $get['shop_name']) {
$where[] = ['S.name', 'like', '%' . $get['shop_name'] . '%'];
}
if (isset($get['search_key']) && $get['search_key']) {
switch($get['search_key']){
case 'settle':
$where[] = ['SAL.source_type', '=', ShopAccountLog::settlement_add_money];
break;
case 'withdrawal':
$where[] = ['SAL.source_type', '=', ShopAccountLog::withdrawal_dec_money];
break;
case 'withdrawal_stay':
$where[] = ['SAL.source_type', '=', ShopAccountLog::withdrawal_stay_money];
break;
case 'withdrawal_error':
$where[] = ['SAL.source_type', '=', ShopAccountLog::withdrawal_fail_money];
break;
}
}
if (!empty($get['start_time']) and $get['start_time']) {
$where[] = ['SAL.create_time', '>=', strtotime($get['start_time'])];
}
if (!empty($get['end_time']) and $get['end_time']) {
$where[] = ['SAL.create_time', '<=', strtotime($get['end_time'])];
}
// 导出
if (true === $is_export) {
return self::accountExport($where);
}
$model = new ShopAccountLog();
$lists = $model->alias('SAL')
->field(['SAL.*', 'S.name,S.logo,S.type'])
->join('shop S', 'S.id = SAL.shop_id')
->order('SAL.id desc')
->where($where)
->paginate([
'page' => $get['page'],
'list_rows' => $get['limit'],
'var_page' => 'page'
])->toArray();
foreach ($lists['data'] as &$item) {
$item['logo'] = empty($item['logo']) ? '' : UrlServer::getFileUrl($item['logo']);
$item['type'] = ShopEnum::getShopTypeDesc($item['type']);
$item['source_type'] = ShopAccountLog::getSourceType($item['source_type']);
$item['change_amount'] = $item['change_type'] == 1 ? '+'.$item['change_amount'] : '-'.$item['change_amount'];
$item['logo'] = !empty($item['logo']) ? UrlServer::getFileUrl($item['logo']) : "";
}
return ['count'=>$lists['total'], 'lists'=>$lists['data']];
}
/**
* @notes 导出商家明细Excel
* @param array $where
* @return array|false
* @author 段誉
* @date 2022/4/24 10:10
*/
public static function withdrawalExport($where)
{
try {
$model = new ShopWithdrawal();
$lists = $model->field(true)
->where($where)
->with(['shop'])
->select()->toArray();
foreach ($lists as &$item) {
$item['status_text'] = WithdrawalEnum::getStatusDesc($item['status']);
$item['shop_name'] = $item['shop']['name'];
$item['shop_type'] = ShopEnum::getShopTypeDesc($item['shop']['type']);
}
$excelFields = [
'shop_name' => '商家名称',
'shop_type' => '商家类型',
'sn' => '提现单号',
'apply_amount' => '提现金额',
'poundage_amount' => '提现手续费',
'left_amount' => '到账金额',
'status_text' => '提现状态',
'create_time' => '提现时间',
];
$export = new ExportExcelServer();
$export->setFileName('商家提现');
$result = $export->createExcel($excelFields, $lists);
return ['url' => $result];
} catch (\Exception $e) {
self::$error = $e->getMessage();
return false;
}
}
/**
* @notes 导出商家账户明细Excel
* @param array $where
* @return array|false
* @author 段誉
* @date 2022/4/24 10:10
*/
public static function accountExport($where)
{
try {
$model = new ShopAccountLog();
$lists = $model->alias('SAL')
->field(['SAL.*', 'S.name,S.type'])
->join('shop S', 'S.id = SAL.shop_id')
->order('SAL.id desc')
->where($where)
->select()->toArray();
foreach ($lists as &$item) {
$item['type'] = ShopEnum::getShopTypeDesc($item['type']);
$item['source_type'] = ShopAccountLog::getSourceType($item['source_type']);
$item['change_amount'] = $item['change_type'] == 1 ? '+'.$item['change_amount'] : '-'.$item['change_amount'];
}
$excelFields = [
'name' => '商家名称',
'type' => '商家类型',
'log_sn' => '明细流水号',
'source_sn' => '来源单号',
'source_type' => '明细类型',
'change_amount' => '变动金额',
'left_amount' => '剩余金额',
'create_time' => '记录时间',
];
$export = new ExportExcelServer();
$export->setFileName('商家账户明细');
$export->setExportNumber(['log_sn', 'source_sn']);
$result = $export->createExcel($excelFields, $lists);
return ['url' => $result];
} catch (\Exception $e) {
self::$error = $e->getMessage();
return false;
}
}
}

View File

@ -0,0 +1,930 @@
<?php
namespace app\admin\logic\finance;
use app\admin\logic\WechatMerchantTransferLogic;
use app\common\basics\Logic;
use app\common\model\RechargeOrder;
use app\common\model\WithdrawApply;
use app\common\enum\WithdrawEnum;
use app\common\server\ConfigServer;
use app\common\server\ExportExcelServer;
use app\common\server\UrlServer;
use app\common\model\user\User;
use app\common\logic\AccountLogLogic;
use app\common\model\AccountLog;
use app\admin\logic\WechatCorporatePaymentLogic;
use think\facade\Db;
use think\Exception;
/**
* Class WithdrawLogic
* @package app\admin\logic\finance
*/
class WithdrawLogic extends Logic
{
/**
* @notes 会员佣金提现列表
* @param $get
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author suny
* @date 2021/7/14 10:00 上午
*/
public static function lists($get, $is_export = false)
{
$where = [];
// 会员信息
if (!empty($get['search_key']) && !empty($get['keyword'])) {
$keyword = $get['keyword'];
if ($get['search_key'] == 'user_sn') {
$where[] = ['u.sn', '=', $keyword];
} elseif ($get['search_key'] == 'nickname') {
$where[] = ['u.nickname', 'like', '%' . $keyword . '%'];
}
}
//提现单号
if (isset($get['withdraw_sn']) && $get['withdraw_sn'] != '') {
$where[] = ['w.sn', '=', $get['withdraw_sn']];
}
//提现方式
if (isset($get['type']) && $get['type'] != '') {
$where[] = ['w.type', '=', $get['type']];
}
//提现状态
if (isset($get['status']) && $get['status'] != '') {
$where[] = ['status', '=', $get['status']];
}
if (empty($get['start_time']) && empty($get['end_time'])) {
$where[] = ['w.create_time', '>=', strtotime(date("Y-m-d", time()))];
$where[] = ['w.create_time', '<=', strtotime(date("Y-m-d", time())) + 86399];
}
// 提现时间
if (isset($get['start_time']) && $get['start_time'] && isset($get['end_time']) && $get['end_time']) {
$where[] = ['w.create_time', 'between', [strtotime($get['start_time']), strtotime($get['end_time'])]];
// }else{
//// $where[] = ['w.create_time', 'between', Time::today()];
}
// 导出
if (true === $is_export) {
return self::withdrawExport($where);
}
$lists = WithdrawApply::alias('w')
->field('w.*, u.nickname,u.avatar, u.sn as user_sn, u.mobile, ul.name as user_level_name')
->with('user')
->leftJoin('user u', 'u.id = w.user_id')
->leftJoin('user_level ul', 'ul.id = u.level')
->where($where)
->page($get['page'], $get['limit'])
->order('w.id desc')
->select();
$count = WithdrawApply::alias('w')
->field('w.*, u.nickname,u.avatar, u.sn as user_sn, u.mobile, ul.name as user_level_name')
->leftJoin('user u', 'u.id = w.user_id')
->leftJoin('user_level ul', 'ul.id = u.level')
->where($where)
->order('w.id desc')
->count();
foreach ($lists as &$item) {
if (empty($item['user'])) {
// 用户不存在
$user = [
'avatar' => '',
'sn' => '-',
'nickname' => '-',
];
} else {
$user = $item['user'];
}
$item['type_text'] = WithdrawEnum::getTypeDesc($item['type']);
$item['status_text'] = WithdrawEnum::getStatusDesc($item['status']);
$item['avatar'] = UrlServer::getFileUrl($item['avatar']);
$user['avatar'] = UrlServer::getFileUrl($user['avatar']);
$item['user_level_name'] = $item['user_level_name'] ? $item['user_level_name'] : '无等级';
$user['user_level_name'] = $item['user_level_name'];
// 通过中间变量$user解决Indirect modification of overloaded element报错
$item['user'] = $user;
}
return ['count' => $count, 'lists' => $lists];
}
/**
* @notes 数据汇总
* @return array
* @author suny
* @date 2021/7/14 10:01 上午
*/
public static function summary()
{
$model = new WithdrawApply();
$successWithdraw = $model->where(['status' => WithdrawEnum::STATUS_SUCCESS])->sum('money');
$handleWithdraw = $model->where(['status' => WithdrawEnum::STATUS_ING])->sum('money');
$totalEarnings = (new User())->where(['del' => 0])->sum('earnings');
return ['successWithdraw' => $successWithdraw, 'handleWithdraw' => $handleWithdraw, 'totalEarnings' => $totalEarnings];
}
/**
* @notes 佣金明细
* @param $get
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author suny
* @date 2021/7/14 10:01 上午
*/
public static function commission($get, $is_export = false)
{
$where = [];
// 明细类型
$source_type = AccountLog::earnings_change;
if (isset($get['source_type']) && !empty($get['source_type'])) {
$where[] = ['a.source_type', '=', $get['source_type']];
} else {
$where[] = ['a.source_type', 'in', $source_type];
}
//明细搜索
if (!empty($get['search_key']) && !empty($get['keyword'])) {
$keyword = $get['keyword'];
switch ($get['search_key']) {
case 'user_sn' :
$where[] = ['u.sn', '=', $keyword];
break;
case 'nickname' :
$where[] = ['u.nickname', 'like', '%' . $keyword . '%'];
break;
}
}
if (empty($get['start_time']) && empty($get['end_time'])) {
$where[] = ['a.create_time', '>=', strtotime(date("Y-m-d", time()))];
$where[] = ['a.create_time', '<=', strtotime(date("Y-m-d", time())) + 86399];
}
//明细时间
if (isset($get['start_time']) && $get['start_time'] != '') {
$where[] = ['a.create_time', '>=', strtotime($get['start_time'])];
}
if (isset($get['end_time']) && $get['end_time'] != '') {
$where[] = ['a.create_time', '<=', strtotime($get['end_time'])];
}
// 导出
if (true === $is_export) {
return self::commissionExport($where);
}
$lists = AccountLog::alias('a')
->field('a.*,u.nickname,u.sn as user_sn,u.mobile,w.sn as withdraw_sn')
->join('user u', 'u.id = a.user_id')
->leftjoin('withdraw_apply w', 'w.sn = a.source_sn')
->where($where)
->page($get['page'], $get['limit'])
->order('a.id desc')
->select();
$count = AccountLog::alias('a')
->field('a.*,u.nickname,u.sn as user_sn,u.mobile,w.sn as withdraw_sn')
->join('user u', 'u.id = a.user_id')
->leftjoin('withdraw_apply w', 'w.sn = a.source_sn')
->where($where)
->order('a.id desc')
->count();
return ['count' => $count, 'lists' => $lists];
}
/**
* @notes 账户明细
* @param $get
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author suny
* @date 2021/7/14 10:01 上午
*/
public static function account($get, $is_export = false)
{
$where = [];
// 明细类型
$source_type = AccountLog::money_change;
if (isset($get['type']) && !empty($get['type'])) {
switch ($get['type']) {
case 'admin_add_money' :
$type = AccountLog::admin_add_money;
break;
case 'admin_reduce_money' :
$type = AccountLog::admin_reduce_money;
break;
case 'recharge_money' :
$type = AccountLog::recharge_money;
break;
case 'balance_pay_order' :
$type = AccountLog::balance_pay_order;
break;
case 'cancel_order_refund' :
$type = AccountLog::cancel_order_refund;
break;
case 'after_sale_refund' :
$type = AccountLog::after_sale_refund;
break;
case 'withdraw_to_balance' :
$type = AccountLog::withdraw_to_balance;
break;
case 'user_transfer_inc_balance' :
$type = AccountLog::user_transfer_inc_balance;
break;
case 'user_transfer_dec_balance' :
$type = AccountLog::user_transfer_dec_balance;
break;
case 'integral_order_inc_balance' :
$type = AccountLog::integral_order_inc_balance;
break;
case 'integral_order_dec_balance' :
$type = AccountLog::integral_order_dec_balance;
break;
}
$where[] = ['a.source_type', '=', $type];
} else {
$where[] = ['a.source_type', 'in', $source_type];
}
//明细搜索
if (!empty($get['search_key']) && !empty($get['keyword'])) {
$keyword = $get['keyword'];
switch ($get['search_key']) {
case 'user_sn' :
$where[] = ['u.sn', '=', $keyword];
break;
case 'nickname' :
$where[] = ['u.nickname', 'like', '%' . $keyword . '%'];
break;
}
}
if (empty($get['start_time']) && empty($get['end_time'])) {
$where[] = ['a.create_time', '>=', strtotime(date("Y-m-d", time()))];
$where[] = ['a.create_time', '<=', strtotime(date("Y-m-d", time())) + 86399];
}
//明细时间
if (isset($get['start_time']) && $get['start_time'] != '') {
$where[] = ['a.create_time', '>=', strtotime($get['start_time'])];
}
if (isset($get['end_time']) && $get['end_time'] != '') {
$where[] = ['a.create_time', '<=', strtotime($get['end_time'])];
}
// 导出
if (true === $is_export) {
return self::accountExport($where);
}
$lists = AccountLog::alias('a')
->field('a.*,u.nickname,u.sn as user_sn,u.mobile')
->join('user u', 'u.id = a.user_id')
->where($where)
->page($get['page'], $get['limit'])
->order('a.id desc')
->select();
$count = AccountLog::alias('a')
->field('a.*,u.nickname,u.sn as user_sn,u.mobile')
->join('user u', 'u.id = a.user_id')
->where($where)
->order('a.id desc')
->count();
return ['count' => $count, 'lists' => $lists];
}
/**
* @notes 充值明细
* @param $get
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author suny
* @date 2021/7/14 10:01 上午
*/
public static function recharge($get, $is_export = false)
{
$where = [];
//明细搜索
if (isset($get['search_key']) && !empty($get['search_key'])) {
$keyword = $get['keyword'];
switch ($get['search_key']) {
case 'nickname' :
$where[] = ['u.nickname', 'like', '%' . $keyword . '%'];
break;
case 'order_sn' :
$where[] = ['order_sn', '=', $keyword];
break;
case 'user_mobile' :
$where[] = ['u.mobile', '=', $keyword];
break;
}
}
//订单来源
if (isset($get['order_source']) && $get['order_source'] != '') {
$where[] = ['r.order_source', '=', $get['order_source']];
}
//订单状态
if (isset($get['pay_status']) && $get['pay_status'] != '') {
$where[] = ['r.pay_status', '=', $get['pay_status']];
}
//支付方式
if (isset($get['pay_way']) && $get['pay_way'] != '') {
$where[] = ['r.pay_way', '=', $get['pay_way']];
}
if (! empty($get['start_time']) && ! empty($get['end_time'])) {
$where[] = ['r.create_time', '>=', strtotime($get['start_time']) ];
$where[] = ['r.create_time', '<=', strtotime($get['end_time']) ];
}
// 导出
if (true === $is_export) {
return self::rechargeExport($where);
}
$lists = RechargeOrder::alias('r')
->field('r.*,u.id,u.nickname,u.mobile')
->join('user u', 'u.id = r.user_id')
->where($where)
->page($get['page'], $get['limit'])
->order('r.id desc')
->select();
foreach ($lists as $list) {
if (!empty($list['pay_time'])) {
$list['pay_time'] = date('Y-m-d H:i:s', $list['pay_time']);
}
}
$count = RechargeOrder::alias('r')
->field('r.*,u.id,u.nickname,u.mobile')
->join('user u', 'u.id = r.user_id')
->where($where)
->order('r.id desc')
->count();
return ['count' => $count, 'lists' => $lists];
}
/**
* @notes 会员佣金提现详情
* @param $id
* @return array|\think\Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author suny
* @date 2021/7/14 10:01 上午
*/
public static function detail($id)
{
$detail = WithdrawApply::alias('w')
->field('w.*,u.sn as user_sn, u.nickname, u.mobile')
->leftJoin('user u', 'u.id=w.user_id')
->where('w.id', $id)
->find();
$detail['money_qr_code'] = UrlServer::getFileUrl($detail['money_qr_code'] ?? '');
$detail['typeDesc'] = WithdrawEnum::getTypeDesc($detail['type']);
$detail['statusDesc'] = WithdrawEnum::getStatusDesc($detail['status']);
$detail['transfer_time'] = $detail['transfer_time'] ? date('Y-m-d H:i:s', $detail['transfer_time']) : '';
$detail['payment_time'] = $detail['payment_time'] ? date('Y-m-d H:i:s', $detail['payment_time']) : '';
return $detail;
}
/**
* @notes 审核通过
* @param $post
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @author suny
* @date 2021/7/14 10:02 上午
*/
public static function confirm($post)
{
try {
$id = $post['id'];
$withdraw = WithdrawApply::where('id', $id)
->find();
// 判断提现单是否为待提现状态 1
if ($withdraw['status'] != 1) {
return [
'code' => 0,
'msg' => '不是待提现申请单'
];
}
//提现到钱包余额
if ($withdraw['type'] == WithdrawEnum::TYPE_BALANCE) {
$user = User::find($withdraw['user_id']);
$user->user_money = ['inc', $withdraw['left_money']];
$user->save();
AccountLogLogic::AccountRecord(
$withdraw['user_id'],
$withdraw['left_money'],
1,
AccountLog::withdraw_to_balance,
'',
$withdraw['id'],
$withdraw['sn']
);
//更新提现申请单状态为提现成功
WithdrawApply::where('id', $id)
->update(['status' => WithdrawEnum::STATUS_SUCCESS, 'update_time' => time(), 'description' => $post['description']]);
return [
'code' => 1,
'msg' => '提现至钱包余额成功'
];
}
//提现到微信零钱
if ($withdraw['type'] == WithdrawEnum::TYPE_WECHAT_CHANGE) {
// 先更新审核备注
WithdrawApply::where('id', $id)
->update(['update_time' => time(), 'description' => $post['description']]);
//微信零钱接口:1-企业付款到零钱;2-商家转账到零钱
$transfer_way = ConfigServer::get('withdraw', 'transfer_way',1);
if ($transfer_way == 1) {
return WechatCorporatePaymentLogic::pay($withdraw);
}
if ($transfer_way == 2) {
return WechatMerchantTransferLogic::transfer($withdraw);
}
}
//提现到微信收款码、支付收款码
if ($withdraw['type'] == WithdrawEnum::TYPE_WECHAT_CODE || $withdraw['type'] == WithdrawEnum::TYPE_ALI_CODE || WithdrawEnum::TYPE_BANK) {
// 直接标识为提现中状态
WithdrawApply::where('id', $id)
->update(['status' => WithdrawEnum::STATUS_ING, 'update_time' => time(), 'description' => $post['description']]);
return [
'code' => 1,
'msg' => '审核通过,提现中'
];
}
return [
'code' => 1,
'msg' => '审核通过,提现中'
];
} catch(\Throwable $e) {
return [
'code' => 0,
'msg' => $e->getMessage(),
];
}
}
/**
* @notes 审核拒绝
* @param $post
* @throws \think\exception\PDOException
* @author suny
* @date 2021/7/14 10:03 上午
*/
public static function refuse($post)
{
Db::startTrans();
try {
$withdraw_apply = WithdrawApply::where('id', $post['id'])->find();
$withdraw_apply->status = WithdrawEnum::STATUS_FAIL; // 提现失败
$withdraw_apply->description = $post['description'];
$withdraw_apply->update_time = time();
$withdraw_apply->save();
//拒绝提现,回退佣金
$user = User::find($withdraw_apply['user_id']);
$user->earnings = ['inc', $withdraw_apply['money']];
$user->save();
//增加佣金变动记录
AccountLogLogic::AccountRecord(
$withdraw_apply['user_id'],
$withdraw_apply['money'],
1,
AccountLog::withdraw_back_earnings,
'',
$withdraw_apply['id'],
$withdraw_apply['sn']
);
Db::commit();
} catch (Exception $e) {
Db::rollback();
}
}
/**
* @notes 审核拒绝
* @param $post
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @author suny
* @date 2021/7/14 10:03 上午
*/
public static function transferFail($post)
{
if (empty($post['transfer_description'])) {
return [
'code' => 0,
'msg' => '请填写转账说明'
];
}
// 标识提现失败
WithdrawApply::where('id', $post['id'])->update([
'status' => 4, // 提现失败
'transfer_voucher' => $post['transfer_voucher'] ? $post['transfer_voucher'] : '',
'transfer_description' => $post['transfer_description'],
'update_time' => time()
]);
$withdraw_apply = WithdrawApply::where('id', $post['id'])->find();
// 退回佣金
$user = User::find($withdraw_apply['user_id']);
$user->earnings = ['inc', $withdraw_apply['money']];
$user->save();
//增加佣金变动记录
AccountLogLogic::AccountRecord(
$withdraw_apply['user_id'],
$withdraw_apply['money'],
1,
AccountLog::withdraw_back_earnings,
'',
$withdraw_apply['id'],
$withdraw_apply['sn']
);
return [
'code' => 1,
'msg' => '转账失败,提现金额已退回佣金账户'
];
}
/**
* @notes 转账成功
* @param $post
* @return array
* @author suny
* @date 2021/7/14 10:03 上午
*/
public static function transferSuccess($post)
{
if (empty($post['transfer_voucher'])) {
return [
'code' => 0,
'msg' => '请上传转账凭证'
];
}
$post['transfer_voucher'] = UrlServer::getFileUrl($post['transfer_voucher']);
if (empty($post['transfer_description'])) {
return [
'code' => 0,
'msg' => '请填写转账说明'
];
}
// 标识提现成功
WithdrawApply::where('id', $post['id'])->update([
'status' => 3, // 提现成功
'transfer_voucher' => $post['transfer_voucher'],
'transfer_description' => $post['transfer_description'],
'update_time' => time(),
'transfer_time' => time()
]);
return [
'code' => 1,
'msg' => '转账成功'
];
}
/**
* @notes 提现失败
* @param $id
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @author suny
* @date 2021/7/14 10:03 上午
*/
public static function withdrawFailed($id)
{
$withdraw_apply = WithdrawApply::where('id', $id)->find();
$withdraw_apply->status = WithdrawEnum::STATUS_FAIL; // 提现失败
$withdraw_apply->update_time = time();
$withdraw_apply->save();
//拒绝提现,回退佣金
$user = User::find($withdraw_apply['user_id']);
$user->earnings = ['inc', $withdraw_apply['money']];
$user->save();
//增加佣金变动记录
AccountLogLogic::AccountRecord(
$withdraw_apply['user_id'],
$withdraw_apply['money'],
1,
AccountLog::withdraw_back_earnings,
'',
$withdraw_apply['id'],
$withdraw_apply['sn']
);
}
/**
* @notes 搜索
* @param $id
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author suny
* @date 2021/7/14 10:03 上午
*/
public static function search($id)
{
$withdraw = WithdrawApply::where('id', $id)
->find();
// 判断提现单是否为提现中状态 2 且 提现方式为 微信零钱 2
if ($withdraw['status'] == 2 && $withdraw['type'] == 2) {
//微信零钱接口:1-企业付款到零钱;2-商家转账到零钱
$transfer_way = ConfigServer::get('withdraw', 'transfer_way',1);
if ($transfer_way == 1) {
return WechatCorporatePaymentLogic::search($withdraw);
}
if ($transfer_way == 2) {
$result = WechatMerchantTransferLogic::details($withdraw);
// 记录查询结果
WithdrawApply::update(['update_time'=>time(),'pay_search_desc'=>json_encode($result, JSON_UNESCAPED_UNICODE)],['id'=>$withdraw['id']]);
if(isset($result['state'])) {
if ($result['state'] == 'SUCCESS') {
// 转账成功,标记提现申请单为提现成功,记录支付信息
WithdrawApply::update(['status'=>3,'payment_no'=>$result['transfer_bill_no'],'payment_time'=>strtotime($result['update_time'])],['id'=>$withdraw['id']]);
return ['code' => 1, 'msg' => '提现成功'];
}
if ($result['state'] == 'FAIL') {
// 转账失败
WithdrawApply::update(['status'=>4],['id'=>$withdraw['id']]);
//回退佣金
$user = User::find($withdraw['user_id']);
$user->earnings = ['inc', $withdraw['money']];
$user->save();
//增加佣金变动记录
AccountLogLogic::AccountRecord(
$withdraw['user_id'],
$withdraw['money'],
1,
AccountLog::withdraw_back_earnings,
'',
$withdraw['id'],
$withdraw['sn']
);
return ['code' => 1, 'msg' => '提现至微信零钱失败'];
}
if ($result['state'] == 'WAIT_USER_CONFIRM') {
return ['code' => 0, 'msg' => '等待用户确认'];
}
return ['code' => 0, 'msg' => '正在处理中'];
}else{
return ['code' => 0, 'msg' => $result['message'] ?? '商家转账到零钱查询失败'];
}
}
} else {
return [
'code' => 0,
'msg' => '不是提现中的微信零钱申请单,无法查询'
];
}
}
/**
* @notes 导出Excel
* @param array $where
* @return array|false
* @author 段誉
* @date 2022/4/24 10:10
*/
public static function rechargeExport($where)
{
try {
$lists = RechargeOrder::alias('r')
->field('r.*,u.id,u.nickname,u.mobile')
->join('user u', 'u.id = r.user_id')
->where($where)
->order('r.id desc')
->select()->toArray();
foreach ($lists as &$list) {
if (!empty($list['pay_time'])) {
$list['pay_time'] = date('Y-m-d H:i:s', $list['pay_time']);
}
}
$excelFields = [
'order_sn' => '订单编号',
'nickname' => '用户昵称',
'mobile' => '用户手机号',
'order_amount' => '充值金额',
'give_money' => '赠送金额',
'give_growth' => '赠送成长值',
'pay_way' => '支付方式',
'pay_time' => '支付时间',
'pay_status' => '订单状态',
'create_time' => '下单时间',
];
$export = new ExportExcelServer();
$export->setFileName('充值明细');
$result = $export->createExcel($excelFields, $lists);
return ['url' => $result];
} catch (\Exception $e) {
self::$error = $e->getMessage();
return false;
}
}
/**
* @notes 导出Excel
* @param array $where
* @return array|false
* @author 段誉
* @date 2022/4/24 10:10
*/
public static function accountExport($where)
{
try {
$lists = AccountLog::alias('a')
->field('a.*,u.nickname,u.sn as user_sn,u.mobile')
->join('user u', 'u.id = a.user_id')
->where($where)
->order('a.id desc')
->select();
$excelFields = [
'nickname' => '会员昵称',
'user_sn' => '会员编号',
'mobile' => '手机号码',
'change_amount' => '变动金额',
'left_amount' => '剩余金额',
'source_type' => '明细类型',
'source_sn' => '来源单号',
'create_time' => '记录时间',
];
$export = new ExportExcelServer();
$export->setFileName('账户明细');
$result = $export->createExcel($excelFields, $lists);
return ['url' => $result];
} catch (\Exception $e) {
self::$error = $e->getMessage();
return false;
}
}
/**
* @notes 导出Excel
* @param array $condition
* @return array|false
* @author 段誉
* @date 2022/4/24 10:10
*/
public static function commissionExport($where)
{
try {
$lists = AccountLog::alias('a')
->field('a.*,u.nickname,u.sn as user_sn,u.mobile,w.sn as withdraw_sn')
->join('user u', 'u.id = a.user_id')
->leftjoin('withdraw_apply w', 'w.sn = a.source_sn')
->where($where)
->order('a.id desc')
->select();
$excelFields = [
'nickname' => '会员昵称',
'user_sn' => '会员编号',
'mobile' => '手机号码',
'change_amount' => '变动金额',
'left_amount' => '剩余佣金',
'source_type' => '明细类型',
'withdraw_sn' => '来源单号',
'create_time' => '记录时间',
];
$export = new ExportExcelServer();
$export->setFileName('佣金明细');
$result = $export->createExcel($excelFields, $lists);
return ['url' => $result];
} catch (\Exception $e) {
self::$error = $e->getMessage();
return false;
}
}
/**
* @notes 导出Excel
* @param array $condition
* @return array|false
* @author 段誉
* @date 2022/4/24 10:10
*/
public static function withdrawExport($where)
{
try {
$lists = WithdrawApply::alias('w')
->field('w.*, u.nickname,u.avatar, u.sn as user_sn, u.mobile, ul.name as user_level_name')
->with('user')
->leftJoin('user u', 'u.id = w.user_id')
->leftJoin('user_level ul', 'ul.id = u.level')
->where($where)
->order('w.id desc')
->select();
foreach ($lists as &$item) {
$item['type_text'] = WithdrawEnum::getTypeDesc($item['type']);
$item['status_text'] = WithdrawEnum::getStatusDesc($item['status']);
}
$excelFields = [
'sn' => '提现单号',
'nickname' => '会员昵称',
'user_sn' => '会员编号',
'mobile' => '手机号码',
'left_money' => '提现金额',
'type_text' => '提现方式',
'status_text' => '提现状态',
'remark' => '提现说明',
'create_time' => '提现时间',
];
$export = new ExportExcelServer();
$export->setFileName('佣金提现');
$result = $export->createExcel($excelFields, $lists);
return ['url' => $result];
} catch (\Exception $e) {
self::$error = $e->getMessage();
return false;
}
}
}