|
@@ -2,6 +2,7 @@
|
|
|
|
|
|
namespace App\Service;
|
|
|
|
|
|
+use App\Model\Record;
|
|
|
use Illuminate\Support\Facades\Redis;
|
|
|
|
|
|
class DrbService extends Service
|
|
@@ -74,12 +75,7 @@ class DrbService extends Service
|
|
|
return [true, $res];
|
|
|
}
|
|
|
|
|
|
- private function getManDetail($user){
|
|
|
- // 1. 获取 access_token
|
|
|
- [$success, $tokenData] = $this->getAccessToken();
|
|
|
- if (! $success) return [false, $tokenData]; // tokenData 是错误信息
|
|
|
- $accessToken = $tokenData['access_token'];
|
|
|
-
|
|
|
+ private function getManDetail($user, $accessToken){
|
|
|
// 3. 根据 userid 获取详细用户信息(包括部门)
|
|
|
$urlDetail = "https://oapi.dingtalk.com/topapi/v2/user/get?access_token={$accessToken}";
|
|
|
$respDetail = $this->curlOpen1($urlDetail, [
|
|
@@ -101,25 +97,61 @@ class DrbService extends Service
|
|
|
{
|
|
|
if(empty($data['type'])) return [false, '单据类型不能为空'];
|
|
|
$type = $data['type'];
|
|
|
- $userId = $user['userId'];
|
|
|
- [$success, $userDetail] = $this->getManDetail($user);
|
|
|
- if(!$success) return [false, $userDetail];
|
|
|
+ if(empty($data['order_number'])) return [false,'订单号不能为空'];
|
|
|
+ [$success, $msg] = $this->checkCreateProcessInstance($data, $user);
|
|
|
+ if(! $success) return [false, $msg];
|
|
|
+
|
|
|
+ //获取模板id
|
|
|
+ $code = $this->getModelCode($type);
|
|
|
+ //获取模板数据
|
|
|
+ [$success, $formData] = $this->getFormData($data, $user);
|
|
|
+ if(! $success) return [false, $formData];
|
|
|
|
|
|
// 1. 获取 access_token
|
|
|
[$success, $tokenData] = $this->getAccessToken();
|
|
|
if (!$success) return [false, $tokenData];
|
|
|
$accessToken = $tokenData['access_token'];
|
|
|
|
|
|
- //获取模板id
|
|
|
- $code = $this->getModelCode($type);
|
|
|
- //获取模板数据
|
|
|
- $formData = $this->getFormData($data);
|
|
|
+ $userId = $user['userId'];
|
|
|
+ [$success, $userDetail] = $this->getManDetail($user, $accessToken);
|
|
|
+ if(!$success) return [false, $userDetail];
|
|
|
|
|
|
//创建审批
|
|
|
[$success, $msg] = $this->createFlow($accessToken, $code, $userId, $userDetail, $formData);
|
|
|
if(! $success) return [false, $msg];
|
|
|
|
|
|
//记录信息
|
|
|
+ $this->recordDatabase($data, $user, $msg);
|
|
|
+
|
|
|
+ return [true, ''];
|
|
|
+ }
|
|
|
+
|
|
|
+ private function recordDatabase($data, $user, $process_instance_id){
|
|
|
+ $type = $data['type'];
|
|
|
+
|
|
|
+ Record::insert([
|
|
|
+ 'type' => $type,
|
|
|
+ 'database' => $user['zt_database'],
|
|
|
+ 'order_number'=> $data['order_number'],
|
|
|
+ 'crt_time' => time(),
|
|
|
+ 'process_instance_id' => $process_instance_id
|
|
|
+ ]);
|
|
|
+
|
|
|
+ return [true, ''];
|
|
|
+ }
|
|
|
+
|
|
|
+ private function checkCreateProcessInstance($data, $user){
|
|
|
+ list($status,$msg) = $this->limitingSendRequestBackgExpire($data['order_number'].$data['type'].$user['zt_database']);
|
|
|
+ if(! $status) return [false,$msg];
|
|
|
+
|
|
|
+ $type = $data['type'];
|
|
|
+
|
|
|
+ $bool = Record::where('del_time',0)
|
|
|
+ ->where('type', $type)
|
|
|
+ ->where('database', $user['zt_database'])
|
|
|
+ ->where('order_number',$data['order_number'])
|
|
|
+ ->exists();
|
|
|
+ if($bool) return [false, '单号' . $data['order_number'] . '已创建审批流'];
|
|
|
|
|
|
return [true, ''];
|
|
|
}
|
|
@@ -132,7 +164,7 @@ class DrbService extends Service
|
|
|
$payload = [
|
|
|
"process_code" => $code, // 审批模板编码
|
|
|
"originator_user_id" => $userId, // 发起人 userId
|
|
|
- "dept_id" => $userDetail['dept_id_list'], // 发起人部门 ID
|
|
|
+ "dept_id" => $userDetail['dept_id_list'][0], // 发起人部门 ID
|
|
|
"form_component_values" => $formData, // 表单数据
|
|
|
];
|
|
|
|
|
@@ -173,78 +205,189 @@ class DrbService extends Service
|
|
|
return $code;
|
|
|
}
|
|
|
|
|
|
- private function getFormData($data){
|
|
|
- $model = [];
|
|
|
+ private function getFormData($data, $user){
|
|
|
+ //cs
|
|
|
+// $formData = [ [ "name" => "订单日期", "value" => "2025-09-23" ], [ "name" => "订单编号", "value" => "PO20250923001" ], [ "name" => "业务类型", "value" => "标准采购" ], [ "name" => "供应商", "value" => "XX供应商有限公司" ], [ "name" => "制单人", "value" => "陈庆鹏" ], [ "name" => "表体", "value" => json_encode([ [ [ "name" => "存货名称", "value" => "打印机" ], [ "name" => "数量", "value" => "2" ], [ "name" => "主计量单位", "value" => "台" ], [ "name" => "原币价税合计", "value" => "3000" ] ], [ [ "name" => "存货名称", "value" => "显示器" ], [ "name" => "数量", "value" => "5" ], [ "name" => "主计量单位", "value" => "个" ], [ "name" => "原币价税合计", "value" => "5000" ] ] ], JSON_UNESCAPED_UNICODE) ] ];
|
|
|
+// return [true, $formData];
|
|
|
+ //cs
|
|
|
+ $service = new U8ServerService($user);
|
|
|
+ $error = $service->getError();
|
|
|
+ if(! empty($error)) return [false, $error];
|
|
|
+ [$success, $order] = $service->getOrderDetails($data, $user);
|
|
|
+ if(! $success) return [false, $order];
|
|
|
|
|
|
+ $type = $data['type'];
|
|
|
+ if($type == 1){
|
|
|
+ // 采购单
|
|
|
+ $formData = $this->typeOne($order);
|
|
|
+ }elseif ($type == 2){
|
|
|
+ // 请购单
|
|
|
+ $formData = $this->typeTwo($order);
|
|
|
+ }else{
|
|
|
+ // 付款单
|
|
|
+ $formData = $this->typeThree($order);
|
|
|
+ }
|
|
|
+ if(empty($formData)) return [false, '审批参数不能为空'];
|
|
|
+
|
|
|
+ return [true, $formData];
|
|
|
+ }
|
|
|
+
|
|
|
+ private function typeOne($userOrder){
|
|
|
+ if (empty($userOrder)) return [];
|
|
|
$formData = [
|
|
|
[
|
|
|
"name" => "订单日期",
|
|
|
- "value" => "2025-09-23" // 日期型字段,字符串 yyyy-MM-dd
|
|
|
+ "value" => date('Y-m-d', strtotime($userOrder['order_date'] ?? ''))
|
|
|
],
|
|
|
[
|
|
|
"name" => "订单编号",
|
|
|
- "value" => "PO20250923001"
|
|
|
+ "value" => $userOrder['order_number'] ?? ''
|
|
|
],
|
|
|
[
|
|
|
"name" => "业务类型",
|
|
|
- "value" => "标准采购"
|
|
|
+ "value" => $userOrder['business_type'] ?? ''
|
|
|
],
|
|
|
[
|
|
|
"name" => "供应商",
|
|
|
- "value" => "XX供应商有限公司"
|
|
|
+ "value" => $userOrder['supplier_title'] ?? ''
|
|
|
],
|
|
|
[
|
|
|
"name" => "制单人",
|
|
|
- "value" => "陈庆鹏"
|
|
|
+ "value" => $userOrder['crt_name'] ?? ''
|
|
|
],
|
|
|
[
|
|
|
- "name" => "表格",
|
|
|
- "value" => json_encode([
|
|
|
- [
|
|
|
- [
|
|
|
- "name" => "存货名称",
|
|
|
- "value" => "打印机"
|
|
|
- ],
|
|
|
- [
|
|
|
- "name" => "数量",
|
|
|
- "value" => "2"
|
|
|
- ],
|
|
|
- [
|
|
|
- "name" => "主计量单位",
|
|
|
- "value" => "台"
|
|
|
- ],
|
|
|
- [
|
|
|
- "name" => "原币价税合计",
|
|
|
- "value" => "3000"
|
|
|
- ]
|
|
|
- ],
|
|
|
- [
|
|
|
- [
|
|
|
- "name" => "存货名称",
|
|
|
- "value" => "显示器"
|
|
|
- ],
|
|
|
- [
|
|
|
- "name" => "数量",
|
|
|
- "value" => "5"
|
|
|
- ],
|
|
|
- [
|
|
|
- "name" => "主计量单位",
|
|
|
- "value" => "个"
|
|
|
- ],
|
|
|
- [
|
|
|
- "name" => "原币价税合计",
|
|
|
- "value" => "5000"
|
|
|
- ]
|
|
|
- ]
|
|
|
- ], JSON_UNESCAPED_UNICODE) // 表格必须是字符串化的 JSON 数组
|
|
|
+ "name" => "表体", // 对应 TableField 的 label
|
|
|
+ "value" => json_encode(
|
|
|
+ array_map(function($item){
|
|
|
+ return [
|
|
|
+ [
|
|
|
+ "name" => "存货名称",
|
|
|
+ "value" => $item['product_title'] ?? ''
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ "name" => "数量",
|
|
|
+ "value" => $item['quantity'] ?? ''
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ "name" => "主计量", // 修改这里,对应模板字段
|
|
|
+ "value" => $item['unit_title'] ?? ''
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ "name" => "原币价税合计",
|
|
|
+ "value" => $item['amount'] ?? ''
|
|
|
+ ]
|
|
|
+ ];
|
|
|
+ }, $userOrder['detail'] ?? []),
|
|
|
+ JSON_UNESCAPED_UNICODE
|
|
|
+ )
|
|
|
]
|
|
|
];
|
|
|
|
|
|
- return $model;
|
|
|
+ return $formData;
|
|
|
}
|
|
|
|
|
|
- private function recordDatabase($data, $user, $process_instance_id){
|
|
|
+ private function typeTwo($userOrder){
|
|
|
+ if (empty($userOrder)) return [];
|
|
|
+ $formData = [
|
|
|
+ [
|
|
|
+ "name" => "单据号",
|
|
|
+ "value" => $userOrder['order_number'] ?? ''
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ "name" => "日期",
|
|
|
+ "value" => date('Y-m-d', strtotime($userOrder['order_date'] ?? ''))
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ "name" => "业务类型",
|
|
|
+ "value" => $userOrder['business_type'] ?? ''
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ "name" => "请购人",
|
|
|
+ "value" => $userOrder['purchase_name'] ?? ''
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ "name" => "制单人",
|
|
|
+ "value" => $userOrder['crt_name'] ?? ''
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ "name" => "表体", // 对应 TableField 的 label
|
|
|
+ "value" => json_encode(
|
|
|
+ array_map(function($item){
|
|
|
+ return [
|
|
|
+ [
|
|
|
+ "name" => "存货名称",
|
|
|
+ "value" => $item['product_title'] ?? ''
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ "name" => "数量",
|
|
|
+ "value" => $item['quantity'] ?? ''
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ "name" => "主计量", // 修改这里,对应模板字段
|
|
|
+ "value" => $item['unit_title'] ?? ''
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ "name" => "要求到货日期",
|
|
|
+ "value" => $item['need_arrived_date'] ?? ''
|
|
|
+ ]
|
|
|
+ ];
|
|
|
+ }, $userOrder['detail'] ?? []),
|
|
|
+ JSON_UNESCAPED_UNICODE
|
|
|
+ )
|
|
|
+ ]
|
|
|
+ ];
|
|
|
+
|
|
|
+ return $formData;
|
|
|
+ }
|
|
|
+
|
|
|
+ private function typeThree($userOrder){
|
|
|
+ if (empty($userOrder)) return [];
|
|
|
+ $formData = [
|
|
|
+ [
|
|
|
+ "name" => "单据编号",
|
|
|
+ "value" => $userOrder['order_number'] ?? ''
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ "name" => "日期",
|
|
|
+ "value" => date('Y-m-d', strtotime($userOrder['order_date'] ?? ''))
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ "name" => "供应商",
|
|
|
+ "value" => $userOrder['supplier_title'] ?? ''
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ "name" => "制单人",
|
|
|
+ "value" => $userOrder['crt_name'] ?? ''
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ "name" => "表体", // 对应 TableField 的 label
|
|
|
+ "value" => json_encode(
|
|
|
+ array_map(function($item){
|
|
|
+ return [
|
|
|
+ [
|
|
|
+ "name" => "来源",
|
|
|
+ "value" => $item['source'] ?? ''
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ "name" => "来源单据号",
|
|
|
+ "value" => $item['source_order_number'] ?? ''
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ "name" => "主计量", // 修改这里,对应模板字段
|
|
|
+ "value" => $item['unit_title'] ?? ''
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ "name" => "申请金额",
|
|
|
+ "value" => $item['amount'] ?? ''
|
|
|
+ ]
|
|
|
+ ];
|
|
|
+ }, $userOrder['detail'] ?? []),
|
|
|
+ JSON_UNESCAPED_UNICODE
|
|
|
+ )
|
|
|
+ ]
|
|
|
+ ];
|
|
|
|
|
|
+ return $formData;
|
|
|
}
|
|
|
|
|
|
public function getTemplateFields($data)
|