|
|
@@ -3,7 +3,9 @@
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
|
|
use App\Jobs\ProcessDataJob;
|
|
|
+use App\Model\DDEmployee;
|
|
|
use App\Model\Record;
|
|
|
+use App\Model\U8State;
|
|
|
use App\Service\DingCallbackCrypto;
|
|
|
use App\Service\DingService;
|
|
|
use Illuminate\Http\Request;
|
|
|
@@ -89,13 +91,14 @@ class DingTalkController extends BaseController
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 钉钉事件回调
|
|
|
+ * 浙江 钉钉事件回调
|
|
|
*/
|
|
|
public function dinCallback(Request $request)
|
|
|
{
|
|
|
- $token = config('dingtalk.token'); // 钉钉事件订阅 token
|
|
|
- $aesKey = config('dingtalk.aes_key'); // 钉钉事件订阅 aes_key
|
|
|
- $corpid = config('dingtalk.app_key'); // 钉钉事件订阅 corpid
|
|
|
+ $type = DDEmployee::type_one;
|
|
|
+ $token = config("dingtalk.{$type}.token"); // 钉钉事件订阅 token
|
|
|
+ $aesKey = config("dingtalk.{$type}.aes_key"); // 钉钉事件订阅 aes_key
|
|
|
+ $corpid = config("dingtalk.{$type}.app_key");
|
|
|
|
|
|
$crypt = new DingCallbackCrypto($token, $aesKey, $corpid);
|
|
|
|
|
|
@@ -152,18 +155,124 @@ class DingTalkController extends BaseController
|
|
|
|
|
|
private function settleData($type, $result, $processInstanceId, $staffId){
|
|
|
try {
|
|
|
-// ProcessDataJob::dispatch(Record::where('id',71)->first()->toArray())->onQueue(Record::$job);dd(1);
|
|
|
$record = Record::where("del_time",0)
|
|
|
+ ->where('login_type', DDEmployee::type_one)
|
|
|
->where('process_instance_id', $processInstanceId)
|
|
|
->first();
|
|
|
if(empty($record)) return;
|
|
|
|
|
|
$record->userid = $staffId;
|
|
|
+
|
|
|
switch ($type) {
|
|
|
-// case 'start': // 审批实例开始
|
|
|
-// $record->del_time = 9; // 自定义标记,待审批
|
|
|
-// break;
|
|
|
+ case 'finish': // 审批正常结束(同意 / 拒绝)
|
|
|
+ if ($result === 'agree') {
|
|
|
+ $record->del_time = 2; // 成功
|
|
|
+ } elseif ($result === 'refuse') {
|
|
|
+ $record->del_time = 1; // 驳回
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 'terminate': // 审批终止(发起人撤销)
|
|
|
+ $record->del_time = 1; // 终止
|
|
|
+ break;
|
|
|
|
|
|
+ case 'delete': // 审批实例删除
|
|
|
+ $record->del_time = 1; // 删除
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ $record->save();
|
|
|
+
|
|
|
+ $record_array = $record->toArray();
|
|
|
+ if($record_array['del_time'] == 2) {
|
|
|
+ //通过后 =》 逻辑
|
|
|
+ ProcessDataJob::dispatch($record_array)->onQueue(Record::$job);
|
|
|
+ }elseif ($record_array['del_time'] == 1){
|
|
|
+ //其他环节 =》 更新表状态为中
|
|
|
+ U8State::updateOrCreate(
|
|
|
+ ['order_number' => $record_array['order_number'], 'login_type' => $record_array['login_type'], 'type' => $record_array['type']],
|
|
|
+ ['state' => U8State::state_two]
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (\Throwable $exception) {
|
|
|
+ Log::channel('apiLog')->info('钉钉回调处理数据保存异常', ['msg' => $exception->getMessage()]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 杭州 钉钉事件回调
|
|
|
+ */
|
|
|
+ public function dinCallbackH(Request $request)
|
|
|
+ {
|
|
|
+ $type = DDEmployee::type_two;
|
|
|
+ $token = config("dingtalk.{$type}.token"); // 钉钉事件订阅 token
|
|
|
+ $aesKey = config("dingtalk.{$type}.aes_key"); // 钉钉事件订阅 aes_key
|
|
|
+ $corpid = config("dingtalk.{$type}.app_key");
|
|
|
+
|
|
|
+ $crypt = new DingCallbackCrypto($token, $aesKey, $corpid);
|
|
|
+
|
|
|
+ try {
|
|
|
+ $encrypt = $request->input('encrypt');
|
|
|
+ $msgSignature = $request->get('msg_signature');
|
|
|
+ $timeStamp = $request->get('timestamp');
|
|
|
+ $nonce = $request->get('nonce');
|
|
|
+
|
|
|
+ // 1️⃣ 解密
|
|
|
+ $event = $crypt->getDecryptMsg($msgSignature, $timeStamp, $nonce, $encrypt);
|
|
|
+ $event = json_decode($event, true);
|
|
|
+// Log::info('钉钉回调解密后的数据', $event);
|
|
|
+
|
|
|
+ // 2️⃣ 处理事件
|
|
|
+ if (isset($event['EventType'])) {
|
|
|
+ switch ($event['EventType']) {
|
|
|
+ case 'bpms_instance_change':
|
|
|
+ $processInstanceId = $event['processInstanceId'] ?? null;
|
|
|
+ $result = $event['result'] ?? null;
|
|
|
+ $type = $event['type'] ?? null; // start/finish/terminate/delete
|
|
|
+ $staffId = $event['staffId'] ?? "";
|
|
|
+
|
|
|
+ // 动作导致流程成功 或 流程终止
|
|
|
+ $this->settleData($type, $result, $processInstanceId, $staffId);
|
|
|
+// Log::info('审批实例变更', compact('processInstanceId','result'));
|
|
|
+
|
|
|
+// Log::info("最后一个节点审核通过,审批完成", compact('processInstanceId'));
|
|
|
+// Log::info("审批流程被驳回或终止", compact('processInstanceId','result'));
|
|
|
+ break;
|
|
|
+ case 'bpms_task_change':
|
|
|
+ $processInstanceId = $event['processInstanceId'] ?? null;
|
|
|
+ $taskId = $event['taskId'] ?? null;
|
|
|
+ $result = $event['result'] ?? null;
|
|
|
+ $approverUserId = $event['staffId'] ?? null;
|
|
|
+
|
|
|
+ // 捕获节点被驳回
|
|
|
+ if ($result === 'refuse') {
|
|
|
+// Log::info("节点被驳回", compact('processInstanceId','taskId','approverUserId'));
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3️⃣ 返回加密 success
|
|
|
+ $res = $crypt->getEncryptedMap('success');
|
|
|
+ return response($res, 200)->header('Content-Type', 'application/json');
|
|
|
+
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ Log::channel('apiLog')->info('钉钉回调解密异常', ['msg' => $e->getMessage()]);
|
|
|
+ return response()->json(['errcode'=>1, 'errmsg'=>'解密失败']);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private function settleDataH($type, $result, $processInstanceId, $staffId){
|
|
|
+ try {
|
|
|
+ $record = Record::where("del_time",0)
|
|
|
+ ->where('login_type', DDEmployee::type_two)
|
|
|
+ ->where('process_instance_id', $processInstanceId)
|
|
|
+ ->first();
|
|
|
+ if(empty($record)) return;
|
|
|
+
|
|
|
+ $record->userid = $staffId;
|
|
|
+ switch ($type) {
|
|
|
case 'finish': // 审批正常结束(同意 / 拒绝)
|
|
|
if ($result === 'agree') {
|
|
|
$record->del_time = 2; // 成功
|
|
|
@@ -189,21 +298,5 @@ class DingTalkController extends BaseController
|
|
|
} catch (\Throwable $exception) {
|
|
|
Log::channel('apiLog')->info('钉钉回调处理数据保存异常', ['msg' => $exception->getMessage()]);
|
|
|
}
|
|
|
-
|
|
|
-// try {
|
|
|
-// $record = Record::where("del_time",0)
|
|
|
-// ->where('process_instance_id', $processInstanceId)
|
|
|
-// ->first();
|
|
|
-// if(empty($record)) return;
|
|
|
-//
|
|
|
-// if ($result === 'agree') {
|
|
|
-// $record->del_time = 2; //成功
|
|
|
-// }elseif ($result == "refuse") {
|
|
|
-// $record->del_time = 1; //驳回
|
|
|
-// }
|
|
|
-// $record->save();
|
|
|
-// }catch (\Throwable $exception){
|
|
|
-// Log::channel('apiLog')->info('钉钉回调处理数据保存异常', ['msg' => $exception->getMessage()]);
|
|
|
-// }
|
|
|
}
|
|
|
}
|