财务流水兼容

This commit is contained in:
liu 2024-06-05 17:43:38 +08:00
parent a648821407
commit e15161a2d4
2 changed files with 48 additions and 11 deletions

View File

@ -9,6 +9,7 @@ use app\common\model\store_finance_flow\StoreFinanceFlow;
use app\common\model\store_order\StoreOrder;
use app\common\model\user\User;
use app\common\model\user\UserRecharge;
use app\common\model\user\UserShip;
use app\common\service\PushService;
use support\Log;
use think\facade\Db;
@ -91,7 +92,7 @@ class PayNotifyLogic extends BaseLogic
if ($order->pay_type == 9) {
$order->status = 2;
}
self::afterPay($order);
self::afterPay($order,$extra['transaction_id']);
if ($order->pay_type == 9) {
$extra['create_time'] = $order['create_time'];
@ -114,10 +115,22 @@ class PayNotifyLogic extends BaseLogic
if ($order->isEmpty() || $order->paid == PayEnum::ISPAID) {
return true;
}
$order->price = bcdiv($extra['amount']['payer_total'], 100, 2);
$price = bcdiv($extra['amount']['payer_total'], 100, 2);
$order->price = $price;
$order->paid = 1;
$order->pay_time = time();
$order->save();
$uid = $order->uid;
$user = User::where('id',$uid)->findOrEmpty();
if ($user->isEmpty()) {
return true;
}
bcscale(2);
$user->user_money = bcadd($user->user_money, $price, 2);
$user->total_recharge_amount = bcadd($user->total_recharge_amount, $price, 2);
$user->save();
//更新等级
self::dealLevel($uid,$user->total_recharge_amount);
return true;
}
@ -184,18 +197,36 @@ class PayNotifyLogic extends BaseLogic
* @param $order
* @return void
*/
public static function afterPay($order)
public static function afterPay($order,$transaction_id)
{
$financeLogic = new StoreFinanceFlowLogic();
$financeLogic->order = $order;
$financeLogic->user = ['uid' => $order['uid']];
if ($order->pay_type != 9 || $order->pay_type != 10) {
$financeLogic->in($order['pay_price'], OrderEnum::USER_ORDER_PAY);
$financeLogic->in($transaction_id,$order['pay_price'], OrderEnum::USER_ORDER_PAY);
}
$financeLogic->out($order['pay_price'], OrderEnum::MERCHANT_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 0);
$financeLogic->out($transaction_id,$order['pay_price'], OrderEnum::MERCHANT_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 0);
$financeLogic->save();
}
//等级处理
public static function dealLevel($uid,$total_money)
{
$userShip = UserShip::where('limit', '<=', $total_money)
->field('id,title,limit')
->order('limit', 'desc')
->find();
$info = User::where('id',$uid)->findOrEmpty();
if($info && $userShip){
if ($info->user_ship != $userShip['id']) {
$info->user_ship = $userShip['id'];
$info->save();
}
}
return true;
}
/**
* 回调日志

View File

@ -3,6 +3,7 @@
namespace app\common\logic;
use app\common\enum\OrderEnum;
use app\common\enum\PayEnum;
use app\common\model\store_finance_flow\StoreFinanceFlow;
class StoreFinanceFlowLogic extends BaseLogic
@ -16,46 +17,51 @@ class StoreFinanceFlowLogic extends BaseLogic
/**
* 支出财务流水
* @param $transaction_id
* @param $number
* @param $financialType
* @param $storeId
* @param $staffId
* @param $status
*/
public function out($number, $financialType, $storeId = 0, $staffId = 0, $status = 1)
public function out($transaction_id,$number, $financialType, $storeId = 0, $staffId = 0, $status = 1)
{
$this->setData($number, $financialType, 0, $storeId, $staffId, $status);
$this->setData($number, $financialType, 1, $storeId, $staffId, $status,$transaction_id);
}
/**
* 收入财务流水
* @param $transaction_id
* @param $number
* @param $financialType
* @param $storeId
* @param $staffId
* @param $status
*/
public function in($number, $financialType, $storeId = 0, $staffId = 0, $status = 1)
public function in($transaction_id,$number, $financialType, $storeId = 0, $staffId = 0, $status = 1)
{
$this->setData($number, $financialType, 1, $storeId, $staffId, $status);
$this->setData($number, $financialType, 0, $storeId, $staffId, $status,$transaction_id);
}
public function setData($number, $financialType, $pm, $storeId, $staffId, $status)
public function setData($number, $financialType, $pm, $storeId, $staffId, $status,$transaction_id)
{
if (empty($this->financeSn)) {
$this->financeSn = $this->getSn();
}
$this->list[] = [
'order_id' => $this->order['id'],
'transaction_id' => $transaction_id,
'order_sn' => $this->order['order_id'],
'user_id' => $this->user['uid'],
'financial_type' => $financialType,
'financial_pm' => $pm,
'number' => $number,
'pay_type' => PayEnum::WECHAT_PAY_MINI,
'status' => $status,
'store_id' => $storeId !== '' ? $storeId : $this->order['store_id'],
'staff_id' => $staffId !== '' ? $staffId : $this->order['staff_id'],
'financial_record_sn' => $this->financeSn . ($this->index++)
'financial_record_sn' => $this->financeSn . ($this->index++),
'create_time'=>time()
];
}