备货单&审批流程
This commit is contained in:
@@ -15,6 +15,7 @@ use support\Db;
|
||||
use support\Cache;
|
||||
use app\inquiry\service\InquiryLogService;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use support\Redis;
|
||||
|
||||
class IndexController
|
||||
{
|
||||
@@ -76,27 +77,27 @@ class IndexController
|
||||
public function createResource()
|
||||
{
|
||||
$options = [
|
||||
'controller' => [
|
||||
'module' => 'common',
|
||||
'name' => 'stock_orders'
|
||||
],
|
||||
// 'controller' => [
|
||||
// 'module' => 'common',
|
||||
// 'name' => 'stock_orders'
|
||||
// ],
|
||||
'model' => [
|
||||
'module' => 'common',
|
||||
'name' => 'stock_orders'
|
||||
'module' => 'approval',
|
||||
'name' => 'approval_records'
|
||||
],
|
||||
'service' => [
|
||||
'module' => 'common',
|
||||
'name' => 'stock_orders'
|
||||
],
|
||||
'logic' => [
|
||||
'module' => 'common',
|
||||
'name' => 'stock_orders'
|
||||
],
|
||||
'validate' => [
|
||||
'module' => 'common',
|
||||
'name' => 'stock_orders'
|
||||
],
|
||||
'table' => 'stock_orders'
|
||||
// 'service' => [
|
||||
// 'module' => 'common',
|
||||
// 'name' => 'stock_orders'
|
||||
// ],
|
||||
// 'logic' => [
|
||||
// 'module' => 'common',
|
||||
// 'name' => 'stock_orders'
|
||||
// ],
|
||||
// 'validate' => [
|
||||
// 'module' => 'common',
|
||||
// 'name' => 'stock_orders'
|
||||
// ],
|
||||
'table' => 'approval_records'
|
||||
];
|
||||
|
||||
$result = (new Generate($options))->doGenerate();
|
||||
@@ -106,24 +107,46 @@ class IndexController
|
||||
|
||||
public function test()
|
||||
{
|
||||
$params = [
|
||||
'email' => '',
|
||||
'phone' => '11',
|
||||
'whatsApp' => ''
|
||||
$data = [
|
||||
'id' => 1,
|
||||
'user_id' => 1,
|
||||
'leave_type_id' => 1,
|
||||
'start_date' => '2019-01-01',
|
||||
'end_date' => '2019-01-02',
|
||||
'reason' => 'test',
|
||||
'status' => 1
|
||||
];
|
||||
$corpId = 1;
|
||||
$customer = \app\crm\model\Customer::where('corp_id', $corpId)
|
||||
->where((function (\Illuminate\Database\Eloquent\Builder $query) use ($params) {
|
||||
if(!empty($params['email']))
|
||||
$query->Orwhere('email', '=', $params['email']);
|
||||
if(!empty($params['phone']))
|
||||
$query->Orwhere('phone', '=', $params['phone']);
|
||||
if(!empty($params['whatsApp']))
|
||||
$query->Orwhere('whatsApp', '=', $params['whatsApp']);
|
||||
return $query;
|
||||
}))
|
||||
->first();
|
||||
$code = $this->submitLeaveApplication(1, $data);
|
||||
|
||||
return json($customer);
|
||||
return $code;
|
||||
}
|
||||
|
||||
|
||||
// 假设这是你的业务逻辑
|
||||
public function submitLeaveApplication(int $bizId, $leaveData) {
|
||||
// 1. 保存业务数据
|
||||
// $bizId = DB::table('leave_applications')->insertGetId($leaveData);
|
||||
|
||||
// 2. 启动审批流程
|
||||
$service = new \app\common\approval\service\ApprovalFlowService();
|
||||
try {
|
||||
$result = $service->start(
|
||||
'leave', // 流程类型,对应 approval_flows.type
|
||||
'leave_application', // 业务类型标识
|
||||
$bizId, // 业务ID
|
||||
$leaveData, // 表单数据快照
|
||||
$_SESSION['user_id'] ?? 1 // 发起人ID
|
||||
);
|
||||
|
||||
// 3. 将审批实例ID关联回业务表
|
||||
DB::table('leave_applications')
|
||||
->where('id', $bizId)
|
||||
->update(['approval_instance_id' => $result['instance_id']]);
|
||||
|
||||
return ['status' => 'success', 'message' => '申请已提交,等待审批'];
|
||||
} catch (\Exception $e) {
|
||||
// 处理错误,可能需要回滚业务数据插入
|
||||
return ['status' => 'error', 'message' => $e->getMessage()];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user