255 lines
9.1 KiB
PHP
Executable File
255 lines
9.1 KiB
PHP
Executable File
<?php
|
||
// +----------------------------------------------------------------------
|
||
// | LikeShop100%开源免费商用电商系统
|
||
// +----------------------------------------------------------------------
|
||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||
// | 开源版本可自由商用,可去除界面版权logo
|
||
// | 商业版本务必购买商业授权,以免引起法律纠纷
|
||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||
// | Gitee下载:https://gitee.com/likeshop_gitee/likeshop
|
||
// | 访问官网:https://www.likemarket.net
|
||
// | 访问社区:https://home.likemarket.net
|
||
// | 访问手册:http://doc.likemarket.net
|
||
// | 微信公众号:好象科技
|
||
// | 好象科技开发团队 版权所有 拥有最终解释权
|
||
// +----------------------------------------------------------------------
|
||
|
||
// | Author: LikeShopTeam
|
||
// +----------------------------------------------------------------------
|
||
|
||
namespace app\common\logic;
|
||
|
||
|
||
use app\common\enum\accountLog\AccountLogEnum;
|
||
use app\common\enum\accountLog\CoachAccountLogEnum;
|
||
use app\common\enum\accountLog\ShopAccountLogEnum;
|
||
use app\common\enum\notice\NoticeEnum;
|
||
use app\common\enum\OrderEnum;
|
||
use app\common\enum\OrderLogEnum;
|
||
use app\common\enum\PayEnum;
|
||
use app\common\model\accountLog\CoachAccountLog;
|
||
use app\common\model\accountLog\ShopAccountLog;
|
||
use app\common\model\coach\Coach;
|
||
use app\common\model\deposit\DepositOrder;
|
||
use app\common\model\goods\Goods;
|
||
use app\common\model\order\Order;
|
||
use app\common\model\order\OrderAppend;
|
||
use app\common\model\order\OrderGap;
|
||
use app\common\model\RechargeOrder;
|
||
use app\common\model\shop\Shop;
|
||
use app\common\model\user\User;
|
||
use app\common\service\ConfigService;
|
||
use think\facade\Db;
|
||
use think\facade\Log;
|
||
|
||
/**
|
||
* 支付成功后处理订单状态
|
||
* 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::write(implode('-', [
|
||
__CLASS__,
|
||
__FUNCTION__,
|
||
$e->getFile(),
|
||
$e->getLine(),
|
||
$e->getMessage()
|
||
]));
|
||
self::setError($e->getMessage());
|
||
return $e->getMessage();
|
||
}
|
||
}
|
||
|
||
/**
|
||
* @notes 调用回调方法统一处理 更新订单支付状态
|
||
* @param $orderSn
|
||
* @param array $extra
|
||
* @author ljj
|
||
* @date 2022/3/1 11:35 上午
|
||
*/
|
||
public static function order($orderSn, $extra = [])
|
||
{
|
||
$order = Order::with(['order_goods'])->where(['sn' => $orderSn])->findOrEmpty();
|
||
//更新订单状态
|
||
Order::update([
|
||
'pay_status' => PayEnum::ISPAID,
|
||
'pay_time' => time(),
|
||
'order_status' => OrderEnum::ORDER_STATUS_WAIT_RECEIVING,
|
||
'transaction_id' => $extra['transaction_id'] ?? ''
|
||
], ['id' => $order['id']]);
|
||
|
||
//添加订单日志
|
||
(new OrderLogLogic())->record(OrderLogEnum::TYPE_USER,OrderLogEnum::USER_PAY_ORDER,$order['id'],$order['user_id']);
|
||
//通知师傅接单
|
||
event('Notice', [
|
||
'scene_id' => NoticeEnum::ACCEPT_ORDER_NOTICE_STAFF,
|
||
'params' => [
|
||
'coach_id' => $order['coach_id'],
|
||
'order_id' => $order['id']
|
||
]
|
||
]);
|
||
// 订单付款通知 - 通知买家
|
||
event('Notice', [
|
||
'scene_id' => NoticeEnum::ORDER_PAY_NOTICE,
|
||
'params' => [
|
||
'user_id' => $order['user_id'],
|
||
'order_id' => $order['id']
|
||
]
|
||
]);
|
||
|
||
//通知平台
|
||
$mobile = ConfigService::get('platform', 'mobile','');
|
||
if($mobile){
|
||
event('Notice', [
|
||
'scene_id' => NoticeEnum::ORDER_PAY_NOTICE_PLATFORM,
|
||
'params' => [
|
||
'mobile' => $mobile,
|
||
'order_id' => $order['id']
|
||
]
|
||
]);
|
||
}
|
||
foreach ($order['order_goods'] as $order_goods){
|
||
Goods::update(['order_num'=>['inc',$order_goods['goods_num']]],['id'=>$order_goods['goods_id']]);
|
||
}
|
||
|
||
// 订单付款通知 - 通知卖家
|
||
// $mobile = ConfigService::get('website', 'mobile');
|
||
// if (!empty($mobile)) {
|
||
// event('Notice', [
|
||
// 'scene_id' => NoticeEnum::ORDER_PAY_NOTICE_PLATFORM,
|
||
// 'params' => [
|
||
// 'mobile' => $mobile,
|
||
// 'order_id' => $order['id']
|
||
// ]
|
||
// ]);
|
||
// }
|
||
}
|
||
|
||
/**
|
||
* @notes 订单差价
|
||
* @param $orderSn
|
||
* @param $extra
|
||
* @return void
|
||
* @author cjhao
|
||
* @date 2024/9/19 01:54
|
||
*/
|
||
private static function orderGap($orderSn, $extra = []){
|
||
$orderGap = OrderGap::where(['sn' => $orderSn])->findOrEmpty();
|
||
//更新订单状态
|
||
OrderGap::update([
|
||
'pay_status' => PayEnum::ISPAID,
|
||
'pay_time' => time(),
|
||
'transaction_id' => $extra['transaction_id'] ?? ''
|
||
], ['id' => $orderGap['id']]);
|
||
Order::where(['id'=>$orderGap['order_id']])->update([
|
||
// 'total_amount' => Db::raw('total_amount+'.$orderGap['order_amount']),
|
||
'total_order_amount' => Db::raw('total_order_amount+'.$orderGap['order_amount']),
|
||
'total_gap_amount' => Db::raw('total_gap_amount+'.$orderGap['order_amount'])
|
||
]);
|
||
//添加订单日志
|
||
(new OrderLogLogic())->record(OrderLogEnum::TYPE_USER,OrderLogEnum::USER_PAY_ORDER_GAP,$orderGap['order_id'],$orderGap['user_id']);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 订单差价
|
||
* @param $orderSn
|
||
* @param $extra
|
||
* @return void
|
||
* @author cjhao
|
||
* @date 2024/9/19 01:54
|
||
*/
|
||
private static function orderAppend($orderSn, $extra = []){
|
||
$orderAppend = OrderAppend::where(['sn' => $orderSn])->findOrEmpty();
|
||
//更新订单状态
|
||
OrderAppend::update([
|
||
'pay_status' => PayEnum::ISPAID,
|
||
'pay_time' => time(),
|
||
'transaction_id' => $extra['transaction_id'] ?? ''
|
||
], ['id' => $orderAppend['id']]);
|
||
Order::where(['id'=>$orderAppend['order_id']])->update([
|
||
// 'total_amount' => Db::raw('total_amount+'.$orderAppend['order_amount']),
|
||
'total_order_amount' => Db::raw('total_order_amount+'.$orderAppend['order_amount']),
|
||
'total_append_amount' => Db::raw('total_append_amount+'.$orderAppend['order_amount'])
|
||
]);
|
||
//添加订单日志
|
||
(new OrderLogLogic())->record(OrderLogEnum::TYPE_USER,OrderLogEnum::USER_PAY_ORDER_APPEND,$orderAppend['order_id'],$orderAppend['user_id']);
|
||
}
|
||
|
||
/**
|
||
* @notes 充值回调
|
||
* @param $orderSn
|
||
* @param array $extra
|
||
* @author ljj
|
||
* @date 2022/12/26 5:00 下午
|
||
*/
|
||
public static function recharge($orderSn, $extra = [])
|
||
{
|
||
$order = RechargeOrder::where('sn', $orderSn)->findOrEmpty()->toArray();
|
||
|
||
// 增加用户累计充值金额及用户余额
|
||
User::update([
|
||
'user_money' => ['inc',$order['order_amount']],
|
||
'total_recharge_amount' => ['inc',$order['order_amount']],
|
||
],['id'=>$order['user_id']]);
|
||
|
||
// 记录账户流水
|
||
AccountLogLogic::add($order['user_id'], AccountLogEnum::MONEY,AccountLogEnum::USER_RECHARGE_ADD_MONEY,AccountLogEnum::INC, $order['order_amount'], $order['sn']);
|
||
|
||
// 更新充值订单状态
|
||
RechargeOrder::update([
|
||
'transaction_id' => $extra['transaction_id'],
|
||
'pay_status' => PayEnum::ISPAID,
|
||
'pay_time' => time(),
|
||
],['id'=>$order['id']]);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes
|
||
* @param $orderSn
|
||
* @param $extra
|
||
* @return void
|
||
* @author cjhao
|
||
* @date 2024/11/29 00:27
|
||
*/
|
||
private static function deposit($orderSn, $extra = []){
|
||
$order = DepositOrder::where('sn', $orderSn)->findOrEmpty()->toArray();
|
||
if(1 == $order['type']){
|
||
Coach::update([
|
||
'deposit' => ['inc',$order['order_amount']],
|
||
],['id'=>$order['relation_id']]);
|
||
|
||
// 记录账户流水
|
||
CoachAccountLog::add($order['relation_id'], CoachAccountLogEnum::DEPOSIT,CoachAccountLogEnum::RECHARGE_INC_DEPOSIT,CoachAccountLogEnum::INC, $order['order_amount'], $order['sn']);
|
||
|
||
}else{
|
||
Shop::update([
|
||
'deposit' => ['inc',$order['order_amount']],
|
||
],['id'=>$order['relation_id']]);
|
||
|
||
// 记录账户流水
|
||
ShopAccountLog::add($order['relation_id'], ShopAccountLogEnum::DEPOSIT,ShopAccountLogEnum::RECHARGE_INC_DEPOSIT,ShopAccountLogEnum::INC, $order['order_amount'], $order['sn']);
|
||
|
||
}
|
||
// 增加用户累计充值金额及用户余额
|
||
|
||
// 更新充值订单状态
|
||
DepositOrder::update([
|
||
'transaction_id' => $extra['transaction_id'] ?? '',
|
||
'pay_status' => PayEnum::ISPAID,
|
||
'pay_time' => time(),
|
||
],['id'=>$order['id']]);
|
||
}
|
||
|
||
} |