erp/app/common/logic/PayNotifyLogic.php
2024-05-10 17:55:36 +08:00

80 lines
2.1 KiB
PHP

<?php
namespace app\common\logic;
use app\common\enum\PayEnum;
use app\common\enum\user\AccountLogEnum;
use app\common\model\order\Cart;
use app\common\model\recharge\RechargeOrder;
use app\common\model\retail\Cashierclass;
use app\common\model\user\User;
use app\common\service\PushService;
use support\Log;
use think\facade\Db;
/**
* 支付成功后处理订单状态
* Class PayNotifyLogic
* @package app\api\logic
*/
class PayNotifyLogic extends BaseLogic
{
public static function handle($action, $orderSn, $extra = [])
{
Db::startTrans();
try {
self::$action($orderSn, $extra);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
Log::error(implode('-', [
__CLASS__,
__FUNCTION__,
$e->getFile(),
$e->getLine(),
$e->getMessage()
]));
self::setError($e->getMessage());
return $e->getMessage();
}
}
/**
* @notes 零售回调
* @param $orderSn
* @param array $extra
* @author 段誉
* @date 2023/2/27 15:28
*/
public static function cashierclass($orderSn, $extra = [])
{
$order = Cashierclass::where('number', $orderSn)->findOrEmpty();
if ($order->isEmpty() || $order->paid == PayEnum::ISPAID) {
return true;
}
$order->money = bcdiv($extra['amount']['payer_total'],100,2);
$order->paid = 1;
$order->status = 1;
if($order->pay_type==9){
$order->status = 2;
}
$order->save();
if ($order['cart_id']) {
if (!is_array($order['cart_id'])) {
$cart_arr = explode(',', $order['cart_id']);
Cart::whereIn('cart_id', $cart_arr)->update(['is_pay' => 1]);
} else {
Cart::whereIn('cart_id', $order['cart_id'])->update(['is_pay' => 1]);
}
}
PushService::push('cash_register_'.$order['user_id'], $order['user_id'], '您有一笔订单已支付');
return true;
}
}