Initial commit: queue workspace

Made-with: Cursor
This commit is contained in:
apple
2026-03-21 02:55:24 +08:00
commit 78de918c37
12388 changed files with 1840126 additions and 0 deletions

View File

@@ -0,0 +1,232 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\services\supplier\finance;
use app\dao\supplier\finance\SupplierExtractDao;
use app\services\BaseServices;
use app\services\supplier\SystemSupplierServices;
use app\services\system\admin\SystemAdminServices;
use crmeb\services\FormBuilder as Form;
use think\annotation\Inject;
use think\exception\ValidateException;
use think\facade\Route as Url;
/**
* 门店提现
* Class StoreExtractServices
* @package app\services\store\finance
* @mixin SupplierExtractDao
*/
class SupplierExtractServices extends BaseServices
{
/**
* @var SupplierExtractDao
*/
#[Inject]
protected SupplierExtractDao $dao;
/**
* 获取一条提现记录
* @param int $id
* @param array $field
* @return array|\think\Model|null
*/
public function getExtract(int $id, array $field = [])
{
return $this->dao->get($id, $field);
}
/**
* 显示资源列表
* @param array $where
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function index(array $where, array $whereData = [])
{
$list = $this->getStoreExtractList($where);
//待审核金额
$where['status'] = 0;
$extract_statistics['price'] = $this->dao->getExtractMoneyByWhere($where, 'extract_price');
//待转账金额
$where['status'] = 1;
$where['pay_status'] = 0;
$extract_statistics['unPayPrice'] = $this->dao->getExtractMoneyByWhere($where, 'extract_price');
//累计提现
$where['status'] = 1;
$where['pay_status'] = 1;
$extract_statistics['paidPrice'] = $this->dao->getExtractMoneyByWhere($where, 'extract_price');
$extract_statistics['price_count'] = 0;
//未提现金额
/** @var SupplierFlowingWaterServices $financeFlowServices */
$financeFlowServices = app()->make(SupplierFlowingWaterServices::class);
$price_not = $financeFlowServices->getSumFinance(['supplier_id' => isset($where['supplier_id']) && $where['supplier_id'] ? $where['supplier_id'] : 0], $whereData);
$extract_statistics['price_not'] = max($price_not, 0);
$extract_statistics['extract_min_price'] = sys_config('supplier_extract_min_price');
$extract_statistics['extract_max_price'] = sys_config('supplier_extract_max_price');
return compact('extract_statistics', 'list');
}
/**
* 获取提现列表
* @param array $where
* @param string $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getStoreExtractList(array $where, string $field = '*')
{
[$page, $limit] = $this->getPageValue();
$list = $this->dao->getExtractList($where, $field, ['supplier'], $page, $limit);
if ($list) {
/** @var SystemAdminServices $adminServices */
$adminServices = app()->make(SystemAdminServices::class);
$adminIds = array_unique(array_column($list, 'admin_id'));
$adminInfos = [];
if ($adminIds) $adminInfos = $adminServices->getColumn([['id', 'in', $adminIds]], 'id,real_name', 'id');
foreach ($list as &$item) {
$item['add_time'] = $item['add_time'] ? date("Y-m-d H:i:s", $item['add_time']) : '';
$item['admin_name'] = $item['admin_id'] ? ($adminInfos[$item['admin_id']]['real_name'] ?? '') : '';
}
}
$count = $this->dao->count($where);
return compact('list', 'count');
}
/**
* 提现申请
* @param int $supplierId
* @param array $data
* @return bool
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function cash(int $supplierId, array $data)
{
/** @var SystemSupplierServices $systemSupplier */
$systemSupplier = app()->make(SystemSupplierServices::class);
$supplierInfo = $systemSupplier->getSupplierInfo($supplierId);
$insertData = [];
switch ($data['extract_type']) {
case 'bank':
if (!$supplierInfo['bank_code'] || !$supplierInfo['bank_address']) {
throw new ValidateException('请先设置提现银行与开户行信息');
}
$insertData['bank_code'] = $supplierInfo['bank_code'];
$insertData['bank_address'] = $supplierInfo['bank_address'];
break;
case 'alipay':
if (!$supplierInfo['alipay_account'] || !$supplierInfo['alipay_qrcode_url']) {
throw new ValidateException('请先设置提现支付宝信息');
}
$insertData['alipay_account'] = $supplierInfo['alipay_account'];
$insertData['qrcode_url'] = $supplierInfo['alipay_qrcode_url'];
break;
case 'weixin':
if (!$supplierInfo['wechat'] || !$supplierInfo['wechat_qrcode_url']) {
throw new ValidateException('请先设置提现微信信息');
}
$insertData['wechat'] = $supplierInfo['wechat'];
$insertData['qrcode_url'] = $supplierInfo['wechat_qrcode_url'];
break;
default:
throw new ValidateException('暂不支持该类型提现');
break;
}
$insertData['supplier_id'] = $supplierInfo['id'];
$insertData['extract_type'] = $data['extract_type'];
$insertData['extract_price'] = $data['money'];
$insertData['add_time'] = time();
$insertData['supplier_mark'] = $data['mark'];
$insertData['status'] = 0;
if (!$this->dao->save($insertData)) {
return false;
}
return true;
}
/**
* 拒绝
* @param $id
* @return mixed
*/
public function refuse(int $id, string $message, int $adminId)
{
$extract = $this->getExtract($id);
if (!$extract) {
throw new ValidateException('操作记录不存在!');
}
if ($extract->status == 1) {
throw new ValidateException('已经提现,错误操作');
}
if ($extract->status == -1) {
throw new ValidateException('您的提现申请已被拒绝,请勿重复操作!');
}
if ($this->dao->update($id, ['fail_time' => time(), 'fail_msg' => $message, 'status' => -1, 'admin_id' => $adminId])) {
return true;
} else {
throw new ValidateException('操作失败!');
}
}
/**
* 通过
* @param $id
* @return mixed
*/
public function adopt(int $id, int $adminId)
{
$extract = $this->getExtract($id);
if (!$extract) {
throw new ValidateException('操作记录不存!');
}
if ($extract->status == 1) {
throw new ValidateException('您已提现,请勿重复提现!');
}
if ($extract->status == -1) {
throw new ValidateException('您的提现申请已被拒绝!');
}
if ($this->dao->update($id, ['status' => 1, 'admin_id' => $adminId])) {
return true;
} else {
throw new ValidateException('操作失败!');
}
}
/**
* 转账页面
* @param int $id
* @return string
*/
public function add_transfer(int $id)
{
$field = array();
$title = '转账信息';
$field[] = Form::input('voucher_title', '转账说明', '')->maxlength(30)->required();
$field[] = Form::frameImage('voucher_image', '转账凭证', Url::buildUrl(config('admin.admin_prefix') . '/widget.images/index', array('fodder' => 'voucher_image')), '')->icon('ios-add')->width('960px')->height('505px')->modal(['footer-hide' => true]);
return create_form($title, $field, Url::buildUrl('/supplier/extract/save_transfer/' . $id), 'POST');
}
}

View File

@@ -0,0 +1,250 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\services\supplier\finance;
use app\dao\supplier\finance\SupplierFlowingWaterDao;
use app\services\BaseServices;
use app\services\order\StoreOrderCreateServices;
use app\services\order\StoreOrderCartInfoServices;
use app\services\order\StoreOrderRefundServices;
use app\services\order\StoreOrderServices;
use think\annotation\Inject;
/**
* 供应商流水
* Class SupplierFlowingWaterServices
* @package app\services\supplier\finance
* @mixin SupplierFlowingWaterDao
*/
class SupplierFlowingWaterServices extends BaseServices
{
/**
* 支付类型
* @var string[]
*/
public array $pay_type = ['weixin' => '微信支付', 'yue' => '余额支付', 'offline' => '线下支付', 'alipay' => '支付宝支付', 'cash' => '现金支付', 'automatic' => '自动转账', 'store' => '微信支付'];
/**
* 交易类型
* @var string[]
*/
public array $type = [
1 => '支付订单',
2 => '退款订单'
];
/**
* @var SupplierFlowingWaterDao
*/
#[Inject]
protected SupplierFlowingWaterDao $dao;
/**
* 显示资源列表
* @param array $where
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $where)
{
[$page, $limit] = $this->getPageValue();
$list = $this->dao->getList($where, '*', $page, $limit, ['user', 'supplierName']);
foreach ($list as &$item) {
$item['type_name'] = isset($this->type[$item['type']]) ? $this->type[$item['type']] : '其他类型';
$item['pay_type_name'] = isset($this->pay_type[$item['pay_type']]) ? $this->pay_type[$item['pay_type']] : '其他方式';
$item['add_time'] = $item['add_time'] ? date('Y-m-d H:i:s', $item['add_time']) : '';
$item['finish_time'] = $item['finish_time'] ? date('Y-m-d H:i:s', $item['finish_time']) : '';
$item['trade_time'] = $item['trade_time'] ? date('Y-m-d H:i:s', $item['trade_time']) : $item['add_time'];
$item['user_nickname'] = $item['user_nickname'] ?: '游客';
}
$count = $this->dao->count($where);
return compact('list', 'count');
}
/**
* 供应商账单
* @param $where
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getFundRecord($where)
{
[$page, $limit] = $this->getPageValue();
$where['is_del'] = 0;
$data = $this->dao->getFundRecord($where, $page, $limit);
$i = 1;
foreach ($data['list'] as &$item) {
$item['id'] = $i;
$i++;
$item['entry_num'] = bcsub($item['income_num'], $item['exp_num'], 2);
switch ($where['timeType']) {
case "day" :
$item['title'] = "日账单";
$item['add_time'] = date('Y-m-d', $item['add_time']);
break;
case "week" :
$item['title'] = "周账单";
$item['add_time'] = '第' . $item['day'] . '周(' . date('m', $item['add_time']) . '月)';
break;
case "month" :
$item['title'] = "月账单";
$item['add_time'] = date('Y-m', $item['add_time']);
break;
}
}
return $data;
}
/**
* 获取百分比
* @param $num
* @return string|null
*/
public function getPercent($num)
{
return bcdiv($num, '100', 4);
}
/**
* 写入流水账单
* @param $oid
* @param $type
* @return bool|void
* @throws \Exception
*/
public function setSupplierFinance($oid, $type = 1)
{
/** @var SupplierTransactionsServices $transactionsServices */
$transactionsServices = app()->make(SupplierTransactionsServices::class);
/** @var StoreOrderCartInfoServices $cartInfoServices */
$cartInfoServices = app()->make(StoreOrderCartInfoServices::class);
/** @var StoreOrderServices $storeOrderServices */
$storeOrderServices = app()->make(StoreOrderServices::class);
/** @var StoreOrderRefundServices $storeOrderRefundServices */
$storeOrderRefundServices = app()->make(StoreOrderRefundServices::class);
$order = $storeOrderServices->get($oid);
if (!$order) {
return true;
}
if ($order['supplier_id'] <= 0) return true;
$data = $cartInfoServices->getOrderCartInfoSettlePrice($order['id']);
$pay_postage = 0;
if (isset($order['shipping_type']) && !in_array($order['shipping_type'], [2, 4])) {
$pay_postage = floatval($storeOrderRefundServices->getOrderSumPrice($data['info'], 'postage_price', false));
}
if ($order['type'] == 8) {
$order['pay_price'] = $order['total_price'];
}
$append = [
'pay_price' => $order['pay_price'],
'pay_postage' => $pay_postage,
'total_price' => $order['total_price'],
];
switch ($type) {
case 1 ://支付
$number = bcadd((string)$data['settlePrice'], $pay_postage, 2);
//支付订单
$this->savaData($order, $number, 1, 1, $append);
//交易订单记录
$transactionsServices->savaData($order, 1, 1, $append);
break;
case 2://退款
$number = bcadd((string)$data['refundSettlePrice'], $pay_postage, 2);
$this->savaData($order, $number, 0, 2, $append);
//交易订单记录
$transactionsServices->savaData($order, 0, 2, $append);
break;
}
}
/**
* 写入数据
* @param $order
* @param $number
* @param $pm
* @param $type
* @param $trade_type
* @param array $append
* @throws \Exception
*/
public function savaData($order, $number, $pm, $type, array $append = [])
{
/** @var StoreOrderCreateServices $storeOrderCreateServices */
$storeOrderCreateServices = app()->make(StoreOrderCreateServices::class);
$order_id = $storeOrderCreateServices->getNewOrderId('ls');
$data = [
'supplier_id' => $order['supplier_id'] ?? 0,
'uid' => $order['uid'] ?? 0,
'order_id' => $order_id,
'link_id' => $order['order_id'] ?? '',
'pay_type' => $order['pay_type'] ?? '',
'trade_time' => $order['pay_time'] ?? $order['add_time'] ?? '',
'pm' => $pm,
'number' => $number ?: 0,
'type' => $type,
'add_time' => time()
];
if ($type == 2) {
$data['status'] = 1;
$data['finish_time'] = time();
//更改正常订单状态
$this->dao->update(['link_id' => $order['order_id'], 'type' => 1], ['status' => 1, 'finish_time' => time()]);
}
$data = array_merge($data, $append);
$this->dao->save($data);
}
/**
* 关联门店店员
* @param $link_id
* @param int $staff_id
* @return mixed
*/
public function setStaff($link_id, int $staff_id)
{
return $this->dao->update(['link_id' => $link_id], ['staff_id' => $staff_id]);
}
/**
* 可提现金额
* @param array $where
* @return int|string
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getSumFinance(array $where, array $whereData)
{
$field = 'sum(if(pm = 1,number,0)) as income_num,sum(if(pm = 0,number,0)) as exp_num';
$whereData['status'] = 1;
$data = $this->dao->getList($whereData, $field);
if (!$data) return 0;
$income_num = $data[0]['income_num'] ?? 0;
$exp_num = $data[0]['exp_num'] ?? 0;
$number = bcsub($income_num, $exp_num, 2);
//已提现金额
/** @var SupplierExtractServices $extractServices */
$extractServices = app()->make(SupplierExtractServices::class);
$where['not_status'] = -1;
$extract_price = $extractServices->getExtractMoneyByWhere($where, 'extract_price');
$price_not = bcsub((string)$number, (string)$extract_price, 2);
return $price_not;
}
}

View File

@@ -0,0 +1,94 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\services\supplier\finance;
use app\dao\supplier\finance\SupplierTransactionsDao;
use app\services\BaseServices;
use app\services\order\StoreOrderCreateServices;
use think\annotation\Inject;
/**
* 门店流水
* Class StoreExtractServices
* @package app\services\store\finance
* @mixin SupplierTransactionsDao
*/
class SupplierTransactionsServices extends BaseServices
{
/**
* 支付类型
* @var string[]
*/
public array $pay_type = ['weixin' => '微信支付', 'yue' => '余额支付', 'offline' => '线下支付', 'alipay' => '支付宝支付', 'cash' => '现金支付', 'automatic' => '自动转账', 'store' => '微信支付'];
/**
* 交易类型
* @var string[]
*/
public array $type = [
1 => '支付订单',
2 => '支付订单',
3 => '订单手续费',
4 => '退款订单',
5 => '充值返点',
6 => '付费会员返点',
7 => '充值订单',
8 => '付费订单',
9 => '收银订单',
10 => '核销订单',
11 => '分配订单',
12 => '配送订单',
13 => '同城配送订单',
];
/**
* @var SupplierTransactionsDao
*/
#[Inject]
protected SupplierTransactionsDao $dao;
/**
* 写入数据
* @param $order
* @param $number
* @param $pm
* @param $type
* @param $trade_type
* @param array $append
* @throws \Exception
*/
public function savaData($order, $pm, $type, array $append = [])
{
/** @var StoreOrderCreateServices $storeOrderCreateServices */
$storeOrderCreateServices = app()->make(StoreOrderCreateServices::class);
$order_id = $storeOrderCreateServices->getNewOrderId('ls');
$data = [
'supplier_id' => $order['supplier_id'] ?? 0,
'uid' => $order['uid'] ?? 0,
'order_id' => $order_id,
'link_id' => $order['order_id'] ?? '',
'pay_type' => $order['pay_type'] ?? '',
'trade_time' => $order['pay_time'] ?? $order['add_time'] ?? '',
'pm' => $pm,
'type' => $type,
'add_time' => time()
];
if ($type == 2) {
$data['status'] = 1;
$data['finish_time'] = time();
}
$data = array_merge($data, $append);
$this->dao->save($data);
}
}