allocatr/application/common/Logic/OrderLogic.php
2025-03-31 11:33:44 +08:00

69 lines
1.9 KiB
PHP

<?php
namespace app\common\Logic;
use app\admin\model\Order;
use app\admin\model\OrderDispatch;
use think\db\exception\DataNotFoundException;
use think\db\exception\ModelNotFoundException;
use think\Exception;
use think\exception\DbException;
use think\Hook;
class OrderLogic
{
private $OrderModel;
public function __construct()
{
$this->OrderModel = new Order();
}
/**
* 任务完成以后,修改订单
* $roleInfo = ['role'=>1,'auth'=>$userInfo,'remark'='']
*
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @throws Exception
*/
public function dispachFinishAfter(OrderDispatch $orderDispatch,$roleInfo=[]): void
{
$order = $this->OrderModel->where('id',$orderDispatch->order_id)->find();
if($order->status != Order::STATUS_DISPATCHED){
throw new Exception('订单状态不允许当前操作');
}
$orderUpdate = [
'status' => Order::STATUS_CHECKING
];
if($orderDispatch->is_receipt == 1){ //要收款,计算确认尾款
$offline_amount = $orderDispatch->total;
$total = bcadd($order->online_amount,$offline_amount,2);
$orderUpdate['offline_amount'] = $offline_amount;
$orderUpdate['total'] = $total;
}
$order->allowField(true)->save($orderUpdate);
$params['role'] = $roleInfo['role'];
$params['auth'] = $roleInfo['auth'];
$params['order']= $order;
$params['remark'] = $roleInfo['remark'] ?? $orderDispatch->remark;
Hook::listen('order_change', $params);
$hookParams = [
'dispatch' => $orderDispatch,
'remark' => $roleInfo['remark'] ?? $orderDispatch->remark,
];
Hook::listen('order_dispatch_change', $hookParams);
}
}