修正损耗注释,删除BackController
This commit is contained in:
parent
090955158f
commit
26f47a0a43
@ -1,138 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace app\api\controller;
|
|
||||||
|
|
||||||
use app\common\model\finance\CapitalFlow;
|
|
||||||
use app\common\model\user\User;
|
|
||||||
use app\common\model\vip_flow\VipFlow;
|
|
||||||
|
|
||||||
class BackController extends BaseApiController
|
|
||||||
{
|
|
||||||
public $notNeedLogin = ['backProfit'];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 返利
|
|
||||||
* @return void
|
|
||||||
* @throws \think\db\exception\DataNotFoundException
|
|
||||||
* @throws \think\db\exception\DbException
|
|
||||||
* @throws \think\db\exception\ModelNotFoundException
|
|
||||||
*/
|
|
||||||
public function backProfit()
|
|
||||||
{
|
|
||||||
//读取前3天的值 按照用户id和类型分下 加到对应的钱
|
|
||||||
$startTime = strtotime(date('Y-m-d', strtotime('-3 days')));
|
|
||||||
$endTime = strtotime(date('Y-m-d'));
|
|
||||||
|
|
||||||
$result = VipFlow::where('create_time', '>=', $startTime)
|
|
||||||
->where('create_time', '<', $endTime)
|
|
||||||
->group('user_id, pay_type')
|
|
||||||
->field('user_id, pay_type, COUNT(*) as transaction_count, SUM(number) as total_amount')
|
|
||||||
->select()->toArray();
|
|
||||||
|
|
||||||
// 遍历查询结果并分类 现金不进入反的逻辑
|
|
||||||
//3余额 18采购款 7微信小程序 9微信条码 13 支付宝条码支付
|
|
||||||
$Balance = [];
|
|
||||||
$Procurement = [];
|
|
||||||
$WechatMiniPay = [];
|
|
||||||
$WechatBarcodePay = [];
|
|
||||||
$AliBarcodePay = [];
|
|
||||||
foreach ($result as $row) {
|
|
||||||
$payType = $row['pay_type'];
|
|
||||||
$userId = $row['user_id'];
|
|
||||||
$totalAmount = $row['total_amount'];
|
|
||||||
switch ($payType) {
|
|
||||||
case 3:
|
|
||||||
$user_now_money = User::where(
|
|
||||||
[
|
|
||||||
'id' => $userId
|
|
||||||
]
|
|
||||||
)->withTrashed()->value('now_money');
|
|
||||||
$Balance[] = [
|
|
||||||
'id' => $userId,
|
|
||||||
'now_money' => bcadd($user_now_money, $totalAmount, 2),
|
|
||||||
];
|
|
||||||
break;
|
|
||||||
case 7:
|
|
||||||
$WechatMiniPay[] = [
|
|
||||||
'id' => $userId,
|
|
||||||
'total_amount' => $totalAmount,
|
|
||||||
];
|
|
||||||
break;
|
|
||||||
case 9:
|
|
||||||
$WechatBarcodePay[] = [
|
|
||||||
'id' => $userId,
|
|
||||||
'total_amount' => $totalAmount,
|
|
||||||
];
|
|
||||||
break;
|
|
||||||
case 13:
|
|
||||||
$AliBarcodePay[] = [
|
|
||||||
'id' => $userId,
|
|
||||||
'total_amount' => $totalAmount,
|
|
||||||
];
|
|
||||||
break;
|
|
||||||
case 18:
|
|
||||||
$purchase_funds_money = User::where(
|
|
||||||
[
|
|
||||||
'id' => $userId
|
|
||||||
]
|
|
||||||
)->withTrashed()->value('purchase_funds');
|
|
||||||
$Procurement[] = [
|
|
||||||
'id' => $userId,
|
|
||||||
'purchase_funds' => bcadd($purchase_funds_money, $totalAmount, 2),
|
|
||||||
];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
//入记录表的话查询后便利入 3余额 18采购款
|
|
||||||
if ($Balance) {
|
|
||||||
(new User())->saveAll($Balance);
|
|
||||||
$this->dealCapital($startTime, $endTime, 3);
|
|
||||||
}
|
|
||||||
if ($Procurement) {
|
|
||||||
(new User())->saveAll($Procurement);
|
|
||||||
$this->dealCapital($startTime, $endTime, 18);
|
|
||||||
}
|
|
||||||
//7微信小程序 9微信条码 13 支付宝条码支付
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public function dealCapital($startTime, $endTime, $pay_type)
|
|
||||||
{
|
|
||||||
$vipFrozen = VipFlow::where('create_time', '>=', $startTime)
|
|
||||||
->where('create_time', '<', $endTime)
|
|
||||||
->where('pay_type', $pay_type)->select()->toArray();
|
|
||||||
if ($pay_type == 18) {
|
|
||||||
$category_title = 'system_purchase_add';
|
|
||||||
$title = '系统增加采购款';
|
|
||||||
$mark = '系统增加采购款';
|
|
||||||
$filed = 'purchase_funds';
|
|
||||||
} else {
|
|
||||||
$category_title = 'system_balance_add';
|
|
||||||
$title = '系统增加余额';
|
|
||||||
$mark = '系统反余额冻结';
|
|
||||||
$filed = 'now_money';
|
|
||||||
}
|
|
||||||
|
|
||||||
$newArr = [];
|
|
||||||
foreach ($vipFrozen as $k => $value) {
|
|
||||||
$user_funds = User::where('id', $value['user_id'])->value($filed);
|
|
||||||
$newArr[$k]['uid'] = $value['user_id'];
|
|
||||||
$newArr[$k]['category'] = $category_title;
|
|
||||||
$newArr[$k]['link_type'] = 'order';
|
|
||||||
$newArr[$k]['link_id'] = $value['order_id'];
|
|
||||||
$newArr[$k]['amount'] = $value['number'];
|
|
||||||
$newArr[$k]['before_balance'] = $user_funds;
|
|
||||||
$newArr[$k]['balance'] = bcadd($user_funds, $value['number'], 2);
|
|
||||||
$newArr[$k]['create_time'] = date('Y-m-d H:i:s');
|
|
||||||
$newArr[$k]['type'] = 'in';
|
|
||||||
$newArr[$k]['title'] = $title . "{$value['number']}元";
|
|
||||||
$newArr[$k]['mark'] = $mark;
|
|
||||||
}
|
|
||||||
(new CapitalFlow())->saveAll($newArr);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
120
app/common/logic/BackLogic.php
Normal file
120
app/common/logic/BackLogic.php
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\common\logic;
|
||||||
|
|
||||||
|
use app\common\model\finance\CapitalFlow;
|
||||||
|
use app\common\model\store_order\StoreOrder;
|
||||||
|
use app\common\model\user\User;
|
||||||
|
use app\common\model\vip_flow\VipFlow;
|
||||||
|
use app\common\service\pay\PayService;
|
||||||
|
use support\Log;
|
||||||
|
|
||||||
|
class BackLogic extends BaseLogic
|
||||||
|
{
|
||||||
|
public $payService=new PayService();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返利
|
||||||
|
* @return void
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\DbException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
*/
|
||||||
|
public function backProfit()
|
||||||
|
{
|
||||||
|
//读取前3天的值
|
||||||
|
$startTime = strtotime(date('Y-m-d', strtotime('-3 days')));
|
||||||
|
$endTime = strtotime(date('Y-m-d'));
|
||||||
|
|
||||||
|
$result = VipFlow::where('create_time', '>=', $startTime)
|
||||||
|
->where('create_time', '<', $endTime)
|
||||||
|
->where('status', 0)
|
||||||
|
->where('type', 0)
|
||||||
|
->select();
|
||||||
|
//3余额 18采购款 7微信小程序 9微信条码 13 支付宝条码支付
|
||||||
|
foreach ($result as $row) {
|
||||||
|
switch ($row['pay_type']) {
|
||||||
|
case 3:
|
||||||
|
case 18:
|
||||||
|
$this->dealCapital($row['pay_type'],$row);
|
||||||
|
break;
|
||||||
|
case 7:
|
||||||
|
case 9:
|
||||||
|
$this->wechat_refund($row['pay_type'],$row);
|
||||||
|
break;
|
||||||
|
case 13:
|
||||||
|
$this->ali_pay_refund($row['pay_type'],$row);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//7微信小程序 9微信条码 13 支付宝条码支付
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function dealCapital($pay_type, $order)
|
||||||
|
{
|
||||||
|
|
||||||
|
$user = User::where('id', $order['user_id'])->find();
|
||||||
|
if ($pay_type == 18) {
|
||||||
|
$category_title = 'system_purchase_add';
|
||||||
|
$title = '系统增加采购款';
|
||||||
|
$mark = '系统增加采购款';
|
||||||
|
$filed = 'purchase_funds';
|
||||||
|
$user->purchase_funds = bcadd($user['purchase_funds'], $order['number'], 2);
|
||||||
|
} else {
|
||||||
|
$category_title = 'system_balance_add';
|
||||||
|
$title = '系统增加余额';
|
||||||
|
$mark = '系统反余额冻结';
|
||||||
|
$filed = 'now_money';
|
||||||
|
$user->now_money = bcadd($user['now_money'], $order['number'], 2);
|
||||||
|
}
|
||||||
|
$user->save();
|
||||||
|
$newArr['uid'] = $order['user_id'];
|
||||||
|
$newArr['category'] = $category_title;
|
||||||
|
$newArr['link_type'] = 'order';
|
||||||
|
$newArr['link_id'] = $order['order_id'];
|
||||||
|
$newArr['amount'] = $order['number'];
|
||||||
|
$newArr['before_balance'] = $user[$filed];
|
||||||
|
$newArr['balance'] = bcadd($user[$filed], $order['number'], 2);
|
||||||
|
$newArr['create_time'] = date('Y-m-d H:i:s');
|
||||||
|
$newArr['type'] = 'in';
|
||||||
|
$newArr['title'] = $title . "{$order['number']}元";
|
||||||
|
$newArr['mark'] = $mark;
|
||||||
|
CapitalFlow::create($newArr);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function wechat_refund($pay_type, $row){
|
||||||
|
$pay_price=StoreOrder::where('id',$row['order_id'])->value('pay_price');
|
||||||
|
$order = [
|
||||||
|
'out_trade_no' => (string)$row['order_sn'],
|
||||||
|
'out_refund_no' => time(),
|
||||||
|
'reason' => '待返还金返还',
|
||||||
|
'amount' => [
|
||||||
|
'refund' => bcmul($row['number'], 100),
|
||||||
|
'total' => bcmul($pay_price, 100),
|
||||||
|
'currency' => 'CNY',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
try{
|
||||||
|
$this->payService->wechat->refund($order);
|
||||||
|
VipFlow::where('id',$row['id'])->update(['status'=>1]);
|
||||||
|
}catch (\Exception $e){
|
||||||
|
Log::error('微信退款失败'.$e->getMessage(),$row->toArray());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function ali_pay_refund($pay_type, $row){
|
||||||
|
$order = [
|
||||||
|
'out_trade_no' => (string)$row['order_sn'],
|
||||||
|
'refund_reason' => '待返还金返还',
|
||||||
|
'refund_amount' => $row['number'],
|
||||||
|
];
|
||||||
|
try{
|
||||||
|
$this->payService->alipay->refund($order);
|
||||||
|
VipFlow::where('id',$row['id'])->update(['status'=>1]);
|
||||||
|
}catch (\Exception $e){
|
||||||
|
Log::error('支付宝退款失败'.$e->getMessage(),$row->toArray());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -70,7 +70,7 @@ class StoreFinanceFlowLogic extends BaseLogic
|
|||||||
switch ($financialType) {
|
switch ($financialType) {
|
||||||
case OrderEnum::MERCHANT_ORDER_OBTAINS: // 商户
|
case OrderEnum::MERCHANT_ORDER_OBTAINS: // 商户
|
||||||
case OrderEnum::ORDER_MARGIN: // 商户保证金
|
case OrderEnum::ORDER_MARGIN: // 商户保证金
|
||||||
case OrderEnum::OTHER_ORDER_OBTAINS: // 损耗
|
case OrderEnum::OTHER_ORDER_OBTAINS: // 损耗'
|
||||||
$data['type'] = OrderEnum::MERCHANT;
|
$data['type'] = OrderEnum::MERCHANT;
|
||||||
break;
|
break;
|
||||||
case OrderEnum::PLATFORM_ORDER_OBTAINS: // 平台
|
case OrderEnum::PLATFORM_ORDER_OBTAINS: // 平台
|
||||||
|
Loading…
x
Reference in New Issue
Block a user