采购单审批流程
This commit is contained in:
@@ -9,6 +9,7 @@ use app\common\logic\PurchaseOrdersLogic;
|
||||
use app\common\model\PurchaseOrderItems;
|
||||
use app\common\model\User;
|
||||
use support\Db;
|
||||
use support\exception\BusinessException;
|
||||
use support\Request;
|
||||
|
||||
class PurchaseOrdersService
|
||||
@@ -70,7 +71,7 @@ class PurchaseOrdersService
|
||||
|
||||
public function beforeServiceStore(array $data, Request $request)
|
||||
{
|
||||
$data['po_no'] = generateStockNo('CG');
|
||||
$data['order_no'] = generateStockNo('CG');
|
||||
$data['buyer_id'] = $request->user->uid;
|
||||
$data['buyer_name'] = User::where('id', $request->user->uid)->value('name');
|
||||
return $data;
|
||||
@@ -165,6 +166,7 @@ class PurchaseOrdersService
|
||||
case 'index':
|
||||
$config['order']['id'] = 'desc';
|
||||
break;
|
||||
case 'show':
|
||||
case 'update':
|
||||
$config['where']['id'] = $p['id'] ?? 0;
|
||||
break;
|
||||
@@ -190,7 +192,7 @@ class PurchaseOrdersService
|
||||
// 使用事务确保数据一致性
|
||||
return Db::transaction(function () use ($request) {
|
||||
// 构建查询条件
|
||||
$config = $this->buildQueryConfig($request, 'update');
|
||||
$config = $this->buildQueryConfig($request, 'show');
|
||||
|
||||
// 软删除采购单明细
|
||||
$order = $this->logicShow($config);
|
||||
@@ -201,9 +203,46 @@ class PurchaseOrdersService
|
||||
}
|
||||
|
||||
// 软删除采购单主表
|
||||
$order->delete();
|
||||
$res = $order->delete();
|
||||
|
||||
return $this->postProcess('Destroy', $order);
|
||||
return $this->postProcess('Destroy', $res);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建采购单成功后处理
|
||||
*/
|
||||
protected function afterServiceStore($res)
|
||||
{
|
||||
if ($res->status == 1) {
|
||||
$this->startApproval($res, ['resubmitted'=>0]);
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function startApproval($item, $formData)
|
||||
{
|
||||
$appro = new \app\common\utils\approval\service\ApprovalFlowService();
|
||||
$appro->start('purchase_orders', 'purchase_orders', $item->id, ['resubmitted'=>0], $item->buyer_id);
|
||||
}
|
||||
|
||||
|
||||
public function serviceResubmit(Request $request, array $data = [])
|
||||
{
|
||||
$info = $this->logicShow($this->buildQueryConfig($request, 'show'));
|
||||
if ($info->status == 3) {
|
||||
$instance = \app\common\model\ApprovalInstances::where('biz_id', $info->id)->where('flow_type', 'purchase_orders')->first();
|
||||
if ( $instance === null) {
|
||||
new BusinessException('未找到审批实例');
|
||||
}
|
||||
// 审批服务
|
||||
$appro = new \app\common\utils\approval\service\ApprovalFlowService();
|
||||
// 重新提交
|
||||
$appro->resubmit($instance->id, $instance->initiator_id, ['resubmitted'=>1], $data['remark']);
|
||||
// 添加到讨论
|
||||
$appro->postDiscussion($instance->id, $instance->initiator_id, $data['remark'], true, [], 'name');
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user