采购单审批流程
This commit is contained in:
@@ -112,7 +112,7 @@ class ApprovalRecordsController extends BaseController
|
|||||||
'instance_id' => $record['instance_id'],
|
'instance_id' => $record['instance_id'],
|
||||||
|
|
||||||
'biz_id' => $record['instance']['biz_id'],
|
'biz_id' => $record['instance']['biz_id'],
|
||||||
'biz_desc' => '备货单号【'.$record['instance']['bizInfo']['order_no'].'】',
|
'biz_desc' => '业务单号【'.$record['instance']['bizInfo']['order_no'].'】',
|
||||||
'biz_type' => $record['instance']['flow_type'],
|
'biz_type' => $record['instance']['flow_type'],
|
||||||
|
|
||||||
'initiator_name' => $record['instance']['initiator']['name'],
|
'initiator_name' => $record['instance']['initiator']['name'],
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ class PurchaseOrdersController extends BaseController
|
|||||||
}
|
}
|
||||||
$result = [
|
$result = [
|
||||||
'id' => $record['id'],
|
'id' => $record['id'],
|
||||||
'po_no' => $record['po_no'],
|
'order_no' => $record['order_no'],
|
||||||
'pi_no' => $record['pi_no'],
|
'pi_no' => $record['pi_no'],
|
||||||
'buyer_id' => $record['buyer_id'],
|
'buyer_id' => $record['buyer_id'],
|
||||||
'buyer_name' => $record['buyer_name'],
|
'buyer_name' => $record['buyer_name'],
|
||||||
@@ -44,8 +44,8 @@ class PurchaseOrdersController extends BaseController
|
|||||||
'contract_file_url' => $contractFileUrl,
|
'contract_file_url' => $contractFileUrl,
|
||||||
'status' => $record['status'],
|
'status' => $record['status'],
|
||||||
'remark' => $record['remark'],
|
'remark' => $record['remark'],
|
||||||
'created_at' => date('Y-m-d H:i:s', strtotime($record['created_at'])),
|
'created_at' => date('Y-m-d H:i:s', $record['created_at']),
|
||||||
'updated_at' => date('Y-m-d H:i:s', strtotime($record['updated_at'])),
|
'updated_at' => date('Y-m-d H:i:s', $record['updated_at']),
|
||||||
];
|
];
|
||||||
$record = $result;
|
$record = $result;
|
||||||
}
|
}
|
||||||
@@ -71,7 +71,7 @@ class PurchaseOrdersController extends BaseController
|
|||||||
}
|
}
|
||||||
$result = [
|
$result = [
|
||||||
'id' => $data['id'],
|
'id' => $data['id'],
|
||||||
'po_no' => $data['po_no'],
|
'order_no' => $data['order_no'],
|
||||||
'pi_no' => $data['pi_no'],
|
'pi_no' => $data['pi_no'],
|
||||||
'buyer_id' => $data['buyer_id'],
|
'buyer_id' => $data['buyer_id'],
|
||||||
'buyer_name' => $data['buyer_name'],
|
'buyer_name' => $data['buyer_name'],
|
||||||
@@ -117,4 +117,20 @@ class PurchaseOrdersController extends BaseController
|
|||||||
return $this->error($e->getMessage());
|
return $this->error($e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重提
|
||||||
|
*
|
||||||
|
* @param Request $request
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function resubmit(Request $request)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$raw = $this->service->serviceResubmit($request, $request->all());
|
||||||
|
return $raw === true ? $this->success('提交成功') : $this->error('提交失败');
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
return $this->error($e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -73,7 +73,8 @@ class ApprovalInstances extends Model
|
|||||||
|
|
||||||
// ====== ====== ====== 映射业务表 ====== ====== ======
|
// ====== ====== ====== 映射业务表 ====== ====== ======
|
||||||
protected const BIZ_CLASS = [
|
protected const BIZ_CLASS = [
|
||||||
'stock_orders' => \app\common\model\StockOrders::class
|
'stock_orders' => \app\common\model\StockOrders::class,
|
||||||
|
'purchase_orders' => \app\common\model\PurchaseOrders::class,
|
||||||
];
|
];
|
||||||
|
|
||||||
public function getBizTypeAttribute($value)
|
public function getBizTypeAttribute($value)
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ class PurchaseOrders extends Model
|
|||||||
/**
|
/**
|
||||||
* 允许自动填充模型字段
|
* 允许自动填充模型字段
|
||||||
*/
|
*/
|
||||||
protected $fillable = ['id', 'po_no', 'pi_no', 'buyer_id', 'buyer_name', 'contract_file', 'status', 'remark', 'created_at', 'updated_at'];
|
protected $fillable = ['id', 'order_no', 'pi_no', 'buyer_id', 'buyer_name', 'contract_file', 'status', 'remark', 'created_at', 'updated_at'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 不允许自动填充模型字段
|
* 不允许自动填充模型字段
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ class ApprovalRecordsService
|
|||||||
|
|
||||||
if ($p['scene'] === 'todo') {
|
if ($p['scene'] === 'todo') {
|
||||||
// if (!in_array(1, $request->user->role_ids)) {
|
// if (!in_array(1, $request->user->role_ids)) {
|
||||||
$config['where']['approver_id'] = $request->user->uid;
|
// $config['where']['approver_id'] = $request->user->uid;
|
||||||
// }
|
// }
|
||||||
$config['where']['status'] = 'pending';
|
$config['where']['status'] = 'pending';
|
||||||
$config['where']['instance.status'] = 'processing';
|
$config['where']['instance.status'] = 'processing';
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ use app\common\logic\PurchaseOrdersLogic;
|
|||||||
use app\common\model\PurchaseOrderItems;
|
use app\common\model\PurchaseOrderItems;
|
||||||
use app\common\model\User;
|
use app\common\model\User;
|
||||||
use support\Db;
|
use support\Db;
|
||||||
|
use support\exception\BusinessException;
|
||||||
use support\Request;
|
use support\Request;
|
||||||
|
|
||||||
class PurchaseOrdersService
|
class PurchaseOrdersService
|
||||||
@@ -70,7 +71,7 @@ class PurchaseOrdersService
|
|||||||
|
|
||||||
public function beforeServiceStore(array $data, Request $request)
|
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_id'] = $request->user->uid;
|
||||||
$data['buyer_name'] = User::where('id', $request->user->uid)->value('name');
|
$data['buyer_name'] = User::where('id', $request->user->uid)->value('name');
|
||||||
return $data;
|
return $data;
|
||||||
@@ -165,6 +166,7 @@ class PurchaseOrdersService
|
|||||||
case 'index':
|
case 'index':
|
||||||
$config['order']['id'] = 'desc';
|
$config['order']['id'] = 'desc';
|
||||||
break;
|
break;
|
||||||
|
case 'show':
|
||||||
case 'update':
|
case 'update':
|
||||||
$config['where']['id'] = $p['id'] ?? 0;
|
$config['where']['id'] = $p['id'] ?? 0;
|
||||||
break;
|
break;
|
||||||
@@ -190,7 +192,7 @@ class PurchaseOrdersService
|
|||||||
// 使用事务确保数据一致性
|
// 使用事务确保数据一致性
|
||||||
return Db::transaction(function () use ($request) {
|
return Db::transaction(function () use ($request) {
|
||||||
// 构建查询条件
|
// 构建查询条件
|
||||||
$config = $this->buildQueryConfig($request, 'update');
|
$config = $this->buildQueryConfig($request, 'show');
|
||||||
|
|
||||||
// 软删除采购单明细
|
// 软删除采购单明细
|
||||||
$order = $this->logicShow($config);
|
$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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -594,8 +594,6 @@ class ApprovalFlowService
|
|||||||
|
|
||||||
// 业务标题/内容
|
// 业务标题/内容
|
||||||
$approvalType = array_flip(\app\common\service\SysDictService::pluckKeyValueByCode('approval_type'));
|
$approvalType = array_flip(\app\common\service\SysDictService::pluckKeyValueByCode('approval_type'));
|
||||||
// $title = $prefix.'审批通知';
|
|
||||||
// $content = "{$prefix}你有一条审批 {$text}:类型 {$instance->flow_type},业务ID {$instance->biz_id}";
|
|
||||||
|
|
||||||
switch ($instance->flow_type) {
|
switch ($instance->flow_type) {
|
||||||
case 'stock_orders':
|
case 'stock_orders':
|
||||||
@@ -610,6 +608,15 @@ class ApprovalFlowService
|
|||||||
case 'stock_orders_nullify':
|
case 'stock_orders_nullify':
|
||||||
// 备货单作废
|
// 备货单作废
|
||||||
break;
|
break;
|
||||||
|
case 'purchase_orders':
|
||||||
|
// 采购单
|
||||||
|
$purchaseOrder = \app\common\model\PurchaseOrders::find($instance->biz_id);
|
||||||
|
if ($purchaseOrder) {
|
||||||
|
$title = $prefix."采购单:{$purchaseOrder->order_no}";
|
||||||
|
$flowTxt = $approvalType[$instance->flow_type] ?? $instance->flow_type;
|
||||||
|
$content = "{$prefix}你有一条审批 {$text}:类型 {$flowTxt},业务单号 {$purchaseOrder->order_no}";
|
||||||
|
}
|
||||||
|
break;
|
||||||
case 'purchase_order':
|
case 'purchase_order':
|
||||||
// 采购单
|
// 采购单
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -360,6 +360,7 @@ Route::group('/admin', function () {
|
|||||||
Route::any('/store', [app\common\controller\PurchaseOrdersController::class, 'store']);
|
Route::any('/store', [app\common\controller\PurchaseOrdersController::class, 'store']);
|
||||||
Route::any('/update', [app\common\controller\PurchaseOrdersController::class, 'update']);
|
Route::any('/update', [app\common\controller\PurchaseOrdersController::class, 'update']);
|
||||||
Route::any('/destroy', [app\common\controller\PurchaseOrdersController::class, 'destroy']);
|
Route::any('/destroy', [app\common\controller\PurchaseOrdersController::class, 'destroy']);
|
||||||
|
Route::any('/resubmit', [app\common\controller\PurchaseOrdersController::class, 'resubmit']);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user