jh-admin/app/shop/controller/Account.php

431 lines
15 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* SaaSMall商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 成都SAAS云科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.gobuysaas.com
* =========================================================
*/
namespace app\shop\controller;
use app\model\member\Withdraw;
use app\model\order\Order as OrderModel;
use app\model\order\OrderRefund;
use app\model\shop\ShopAccount;
use app\model\system\SiteOrder as SysOrderModel;
use Carbon\Carbon;
use app\model\account\Account as accountModel;
use think\Exception;
use think\facade\Db;
class Account extends BaseShop
{
public function dashboard()
{
$is_memberwithdraw = addon_is_exit('memberwithdraw', $this->site_id);
$this->assign('is_memberwithdraw', $is_memberwithdraw);
//获取分销商账户统计
$is_addon_fenxiao = addon_is_exit('fenxiao', $this->site_id);
$this->assign('is_addon_fenxiao', $is_addon_fenxiao);
$this->income();
$this->disburse();
return $this->fetch('account/dashboard');
}
/**
* 收入
*/
public function income()
{
$start_time = input('start_time', Carbon::today()->timestamp);
$end_time = input('end_time', Carbon::tomorrow()->timestamp);
$order_money = (new OrderModel())->getOrderMoneySum([ ['site_id', '=', $this->site_id], ['pay_time', 'between', [$start_time, $end_time] ], ['order_scene', '=', 'online'] ], 'pay_money')['data'];
$data = [
[
'title' => '商城订单',
'value' => $order_money,
'desc' => '统计时间内,所有付款订单实付金额之和',
'url' => 'shop/order/lists'
]
];
$event = event('IncomeStatistics', ['site_id' => $this->site_id, 'start_time' => $start_time, 'end_time' => $end_time]);
if (!empty($event)) $data = array_merge($data, ...$event);
if (request()->isAjax()) return success(0, '', $data);
$this->assign('total_income', array_sum(array_column($data, 'value')));
$this->assign('income_data', $data);
}
/**
* 支出
*/
public function disburse()
{
$start_time = input('start_time', Carbon::today()->timestamp);
$end_time = input('end_time', Carbon::tomorrow()->timestamp);
$data = [
[
'title' => '订单退款',
'value' => (new OrderRefund())->getRefundSum([ ['site_id', '=', $this->site_id], ['refund_money_type', '=', '1,2'], ['refund_time', 'between', [$start_time, $end_time] ] ], 'refund_pay_money')['data'],
'desc' => '统计时间内,所有订单退款转账金额之和',
'url' => 'shop/orderrefund/lists'
],
[
'title' => '会员提现',
'value' => (new Withdraw())->getMemberWithdrawSum([ ['site_id', '=', $this->site_id], ['payment_time', 'between', [$start_time, $end_time] ] ], 'apply_money')['data'],
'desc' => '统计时间内,所有会员提现转账金额之和',
'url' => 'shop/memberwithdraw/lists'
]
];
$event = event('DisburseStatistics', ['site_id' => $this->site_id, 'start_time' => $start_time, 'end_time' => $end_time]);
if (!empty($event)) $data = array_merge($data, ...$event);
if (request()->isAjax()) return success(0, '', $data);
$this->assign('total_disburse', array_sum(array_column($data, 'value')));
$this->assign('disburse_data', $data);
}
/**
* 我的订购
* @return mixed
*/
public function order()
{
$order_model = new SysOrderModel();
if (request()->isAjax()) {
$page = input('page', 1);
$page_size = input('page_size', PAGE_LIST_ROWS);
$condition = [
[ 'is_delete', '=', 0 ]
];
$condition[] = [ 'buyer_uid', '=', $this->site_id ];
$search_type = input('search_type', '');
$search_text = input('search_text', '');
if (!empty($search_text)) {
$condition[] = [ $search_type, 'LIKE', '%' . $search_text . '%' ];
}
$order_type = input('order_type', '');
if ($order_type) {
$condition[] = [ 'order_type', '=', $order_type ];
}
$order_status = input('order_status', '');
if ($order_status !== '') {
$condition[] = [ 'order_status', '=', $order_status ];
}
$pay_type = input('pay_type', '');
if ($pay_type) {
$condition[] = [ 'pay_type', '=', $pay_type ];
}
$start_time = input('start_time', '');
$end_time = input('end_time', '');
if ($start_time && !$end_time) {
$condition[] = [ 'create_time', '>=', date_to_time($start_time) ];
} elseif (!$start_time && $end_time) {
$condition[] = [ 'create_time', '<=', date_to_time($end_time) ];
} elseif ($start_time && $end_time) {
$condition[] = [ 'create_time', 'between', [ date_to_time($start_time), date_to_time($end_time) ] ];
}
$list = $order_model->getSysOrderPageList($condition, $page, $page_size, '*', "create_time desc");
return $list;
} else {
$this->assign('order_status', $order_model->order_status);
$this->assign('order_type', $order_model->order_type);
$this->assign('pay_type', $order_model->getPayType());
return $this->fetch("account/order");
}
}
/**
* 订单详情
*/
public function orderdetail()
{
$order_id = input('order_id', 0);
$order_model = new SysOrderModel();
$condition = array(
[ 'order_id', '=', $order_id ],
[ 'buyer_uid', '=', $this->sys_uid ],
);
$detail_result = $order_model->getOrderInfo($condition);
$detail = $detail_result["data"];
$this->assign("detail", $detail);
return $this->fetch("account/order_detail");
}
/**
* Common: 基本设置
* Author: wu-hui
* Time: 2024/05/22 11:38
* @return array|mixed
*/
public function set(){
if (request()->isAjax()) {
// 参数获取
$info = input('set',[]);
(new accountModel())->setConfig($this->site_id, $info);
return success(0, '修改成功');
}
else {
$set = (new accountModel())->getConfig($this->site_id);
return $this->fetch("account/set",[
'set' => json_encode($set, JSON_UNESCAPED_UNICODE),
]);
}
}
/**
* Common: 申请提现 - 列表
* Author: wu-hui
* Time: 2024/05/23 9:20
* @return array|mixed
*/
public function withdraw(){
if (request()->isAjax()) {
// 参数获取
$page = input('page', 1);
$params = [
'member_id' => input('member_id', '')
];
$params['site_id'] = $this->site_id;
return (new accountModel())->getPageList($page, $params);
}
return $this->fetch("account/withdraw",[
'is_admin' => $this->site_id == (new accountModel())->adminSiteId
]);
}
/**
* Common: 申请提现 - 审核
* Author: wu-hui
* Time: 2024/05/23 10:56
* @return array
* @throws \think\db\exception\DbException
*/
public function auditing(){
$params = [
'id' => input('id',0),
'type' => input('type',''),
'reason' => input('reason',''),
];
Db::startTrans();
try{
// 判断:审核操作 adopt=通过reject=驳回
if($params['type'] === 'adopt'){
// 通过
model('member_finance_apply')->update([
'status' => 1,
],[
'id' => $params['id']
]);
}else if($params['type'] === 'reject'){
// 驳回
$info = model('member_finance_apply')->getInfo([
['id', '=', $params['id']]
]);
model('member_finance_apply')->update([
'status' => 3,
'reason' => $params['reason'],
],[
'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']]
],'withdrawable_money', (float)$info['apply_money']);
}else{
// 用户提现
model('member')->setDec([
['member_id', '=', $info['member_id']]
],'commission_freeze', (float)$info['apply_money']);
model('member')->setInc([
['member_id', '=', $info['member_id']]
],'commission_money', (float)$info['apply_money']);
}
}
Db::commit();
return success(0, 'success');
}catch(\Exception $e){
Db::rollback();
return error(-1, $e->getMessage());
}
}
/**
* Common: 打款操作
* Author: wu-hui
* Time: 2024/05/23 10:59
* @return array|mixed|string|void
*/
public function paymentOperation(){
$params = [
'id' => input('id',0),
'type' => input('type',''),
];
return (new accountModel())->paymentOperation($params);
}
/**
* Common: 进入店铺收入页面 & 店铺信息获取
* Author: wu-hui
* Time: 2024/07/18 9:13
* @return array|mixed
*/
public function shopIncome(){
if (request()->isAjax()) {
// 参数获取
$page = input('page', 1);
$params = [
'site_id' => $this->site_id,
'order_no' => input('order_no', ''),
'status' => input('status', '')
];
return (new ShopAccount())->getPageList($page, $params);
}
// 获取店铺信息
$info = model('shop')->getInfo([
['site_id', '=', $this->site_id]
]);
// 获取店铺提现账号信息
$account = model('member_finance_account')->getList([
['site_id', '=', $this->site_id],
]);
// 总平台提现设置
$set = (new accountModel())->getConfig(1);
return $this->fetch("account/shop_account",[
'info' => json_encode($info, JSON_UNESCAPED_UNICODE),
'account' => json_encode($account, JSON_UNESCAPED_UNICODE),
'set' => json_encode($set, JSON_UNESCAPED_UNICODE),
]);
}
/**
* Common: 编辑提现账户信息
* Author: wu-hui
* Time: 2024/07/18 15:22
* @return array
*/
public function editFinanceAccount(){
// 参数获取
$params = [
'id' => input('id',0),
'site_id' => $this->site_id,
'member_id' => input('member_id',0),
'realname' => input('realname',''),
'mobile' => input('mobile',''),
'account_type' => input('account_type',''),
'alipay_account' => input('alipay_account',''),
'card_type' => input('card_type',''),
'bank_sub_name' => input('bank_sub_name',''),
'account_id_start' => input('account_id_start',''),
'bank_act_name' => input('bank_act_name',''),
'card_num' => input('card_num',''),
'account_id' => input('account_id',''),
'mer_type' => input('mer_type',''),
];
(new accountModel())->editInfo($params);
return success(0,'success');
}
/**
* Common: 获取店铺提现账户列表
* Author: wu-hui
* Time: 2024/07/18 15:27
* @return array
*/
public function getAccountList(){
$accountList = model('member_finance_account')->getList([
['site_id', '=', $this->site_id],
['member_id', '=', 0],
]);
return success(0,'success', $accountList);
}
/**
* Common: 添加店铺提现申请信息
* Author: wu-hui
* Time: 2024/07/18 16:54
* @return array
*/
public function submitApplyInfo(){
$params = [
'finance_account_id' => input('finance_account_id',0),
'income_type' => input('income_type',0),
'apply_money' => input('apply_money',0),
];
// 总平台提现设置
$set = (new accountModel())->getConfig(1);
// 可提现金额
$incomeMoney = model('shop')->getValue([
['site_id', '=', $this->site_id]
], 'withdrawable_money');
// 数据
$data = [
'site_id' => 1,
'apply_site_id' => (int)$this->site_id,
'member_id' => 0,
'finance_account_id' => $params['finance_account_id'] ?? 0,
'income_type' => $params['income_type'] ?? '',
'apply_money' => $params['apply_money'] ?? 0,
'handling_fees_rate' => $set['commission_handling_fees'],
'handling_fees_money' => 0,
'money' => $params['apply_money'] ?? 0,
];
// 是否存在手续费
if($data['handling_fees_rate'] > 0){
$handlingFeesMoney = sprintf("%.2f", $data['apply_money'] * $data['handling_fees_rate'] / 100);
$data['handling_fees_money'] = $handlingFeesMoney;
$data['money'] = sprintf("%.2f", $data['money'] - $handlingFeesMoney);
}
Db::startTrans();
try{
// 判断
if($data['finance_account_id'] <= 0) throw new Exception('账户不存在');
if(!$data['income_type']) throw new Exception('收益类型不明确');
if($data['apply_money'] <= 0) throw new Exception('提现金额必须大于0');
if($data['apply_money'] > $incomeMoney) throw new Exception('提现金额不能大于可提现金额');
// 记录
model('member_finance_apply')->add($data);
// 修改店铺信息
model('shop')->setInc([
['site_id', '=', $this->site_id]
],'frozen_money', (float)$data['apply_money']);
model('shop')->setDec([
['site_id', '=', $this->site_id]
],'withdrawable_money', (float)$data['apply_money']);
Db::commit();
return success(0,'success');
}catch(\Exception $e){
Db::rollback();
return error(-1,$e->getMessage());
}
}
}