123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726 |
- <?php
- namespace App\Service;
- use App\Model\Employee;
- use App\Model\SysMenu;
- use App\Model\WorkFlow;
- use App\Model\WorkFlowGenerated;
- use App\Model\WorkFlowGeneratedSub;
- use App\Model\WorkFlowGeneratedSubDetail;
- use App\Model\WorkFlowGeneratedSubDetailCondition;
- use App\Model\WorkFlowSub;
- use App\Model\WorkFlowSubDetail;
- use App\Model\WorkFlowSubDetailCondition;
- use Illuminate\Support\Facades\DB;
- class WorkFlowService extends Service
- {
- public function orderList($data,$user){
- $model = WorkFlow::where('del_time',0)
- ->select('title','id','menu_id','crt_time','crt_id')
- ->orderby('id', 'desc');
- if(! empty($data['title'])) $model->where('title', 'LIKE', '%'.$data['title'].'%');
- if(! empty($data['crt_time'][0]) && ! empty($data['crt_time'][1])) {
- $return = $this->changeDateToTimeStampAboutRange($data['crt_time']);
- $model->where('crt_time','>=',$return[0]);
- $model->where('crt_time','<=',$return[1]);
- }
- $list = $this->limit($model,'',$data);
- $list = $this->fillData($list,$data);
- return [true, $list];
- }
- public function fillData($data,$ergs){
- if(empty($data['data'])) return $data;
- $emp = Employee::whereIn('id',array_unique(array_column($data['data'],'crt_id')))
- ->pluck('emp_name','id')
- ->toArray();
- $menu = SysMenu::whereIn('id',array_unique(array_column($data['data'],'menu_id')))
- ->pluck('title','id')
- ->toArray();
- foreach ($data['data'] as $key => $value){
- $data['data'][$key]['crt_time'] = $value['crt_time'] ? date('Y-m-d H:i:s',$value['crt_time']) : '';
- $data['data'][$key]['crt_name'] = $emp[$value['crt_id']] ?? '';
- $data['data'][$key]['menu_title'] = $menu[$value['menu_id']] ?? '';
- }
- return $data;
- }
- public function detail($data, $user){
- if($this->isEmpty($data,'id')) return [false,'请选择工作流'];
- $workFlow = WorkFlow::where('del_time',0)
- ->where('id',$data['id'])
- ->first();
- if(empty($workFlow)) return [false,'工作流不存在或已被删除'];
- $workFlow = $workFlow->toArray();
- $emp_map = Employee::where('id',$workFlow['crt_id'])
- ->pluck('emp_name','id')
- ->toArray();
- $workFlow['crt_name'] = $emp_map[$workFlow['crt_id']] ?? '';
- $workFlow['crt_time'] = $workFlow['crt_time'] ? date("Y-m-d H:i:s", $workFlow['crt_time']): '';
- return [true, $workFlow];
- }
- public function del($data, $user){
- if($this->isEmpty($data,'id')) return [false,'请选择工作流'];
- $workFlow = WorkFlow::where('del_time',0)
- ->where('id',$data['id'])
- ->first();
- if(empty($workFlow)) return [false,'工作流不存在或已被删除'];
- try {
- DB::beginTransaction();
- $time = time();
- $workFlow->del_time = $time;
- $workFlow->save();
- $this->updateSonModel($data, $time);
- DB::commit();
- }catch (\Throwable $e){
- DB::rollBack();
- return [false, $e->getFile() . '|' . $e->getLine() . '|' . $e->getMessage()];
- }
- return [true, ''];
- }
- public function EditWorkFlowMenu($data, $user){
- list($status, $msg) = $this->EditWorkFlowMenuRule($data);
- if(! $status) return [false, $msg];
- try{
- DB::beginTransaction();
- //将前端给到的工作流数据组成多个一维数组
- $array = $this->flattenWorkflow($data['nodeConfig']);
- //踢掉没用的数据,为了组成树结构
- $clear_array = $this->organizationData($array);
- //树结构
- $tree = $this->makeTree(0, $clear_array);
- //通过节点id 找到当下流程
- // $aa = $this->createIdToNodeMap($tree);
- list($status, $msg) = $this->settleWorkFlowData($data,$array);
- if(! $status) return [false, $msg];
- list($detail, $detail_son, $array_detail_map) = $msg;
- $time = time();
- if(! empty($data['id'])){
- //更新
- $model = WorkFlow::where('id', $data['id'])->first();
- $model->title = $data['title'] ?? "";
- $model->menu_id = $data['tableId'] ?? 0;
- $model->vue_param = json_encode($data);
- $model->my_param = json_encode($tree);
- $model->save();
- //子表更新
- $this->updateSonModel($data, $time);
- }else{
- //添加
- $model = new WorkFlow();
- $model->title = $data['title'] ?? "";
- $model->menu_id = $data['tableId'] ?? 0;
- $model->vue_param = json_encode($data);
- $model->my_param = json_encode($tree);
- $model->crt_id = $user['id'];
- $model->save();
- $data['id'] = $model->id;
- }
- //子表写入
- $this->insertSonModel($data, $array, $detail, $detail_son, $array_detail_map,$time);
- DB::commit();
- }catch (\Throwable $exception){
- DB::rollBack();
- return [false, $exception->getLine() . ' | ' . $exception->getFile() . ' | ' . $exception->getMessage()];
- }
- return [true, ''];
- }
- public function insertSonModel($data, $array, $detail, $detail_son, $array_detail_map, $time){
- $sub = [];
- if(empty($array)) return;
- foreach ($array as $value){
- $sub[] = [
- 'workflow_id' => $data['id'],
- 'menu_id' => $data['tableId'],
- 'm_id' => $value['id'],
- 'crt_time' => $time
- ];
- }
- WorkFlowSub::insert($sub);
- //获取上一次插入订单的所有id
- $last_insert_id = WorkFlowSub::where('workflow_id', $data['id'])
- ->where('menu_id', $data['tableId'])
- ->where('crt_time', $time)
- ->where('del_time', 0)
- ->select('id')->get()->toArray();
- $last_insert_id = array_column($last_insert_id,'id');
- //组织 detail 数据 做写入
- $detail_array = [];
- foreach ($sub as $key => $value){
- $workflow_sub_id = $last_insert_id[$key];
- $keys = $array_detail_map[$key];
- if(empty($keys)) continue;
- foreach ($keys as $k){
- $detail_tmp = $detail[$k] ?? [];
- if(empty($detail_tmp)) continue;
- $detail_tmp['workflow_id'] = $value['workflow_id'];
- $detail_tmp['menu_id'] = $value['menu_id'];
- $detail_tmp['workflow_sub_id'] = $workflow_sub_id;
- $detail_tmp['crt_time'] = $time;
- $detail_array[] = $detail_tmp;
- }
- }
- if(! empty($detail_array)) WorkFlowSubDetail::insert($detail_array);
- if(empty($detail_son)) return;
- //获取上一次插入订单的所有id
- $last_insert_id = WorkFlowSubDetail::where('workflow_id', $data['id'])
- ->where('menu_id', $data['tableId'])
- ->where('crt_time', $time)
- ->where('del_time', 0)
- ->select('id')->get()->toArray();
- $last_insert_id = array_column($last_insert_id,'id');
- //组织 条件数据 做写入
- $detail_son_array = [];
- foreach ($detail_array as $key => $value){
- $workflow_sub_detail_id = $last_insert_id[$key];
- $detail_son_tmp = $detail_son[$key] ?? [];
- if(empty($detail_son_tmp)) continue;
- foreach ($detail_son_tmp as $val){
- $val['workflow_id'] = $value['workflow_id'];
- $val['menu_id'] = $value['menu_id'];
- $val['workflow_sub_id'] = $value['workflow_sub_id'];
- $val['workflow_sub_detail_id'] = $workflow_sub_detail_id;
- $val['crt_time'] = $value['crt_time'];
- $detail_son_array[] = $val;
- }
- }
- if(! empty($detail_son_array)) WorkFlowSubDetailCondition::insert($detail_son_array);
- }
- public function updateSonModel($data, $time){
- WorkFlowSub::where('del_time',0)
- ->where('workflow_id', $data['id'])
- ->update(['del_time' => $time]);
- WorkFlowSubDetail::where('del_time',0)
- ->where('workflow_id', $data['id'])
- ->update(['del_time' => $time]);
- WorkFlowSubDetailCondition::where('del_time',0)
- ->where('workflow_id', $data['id'])
- ->update(['del_time' => $time]);
- }
- public function EditWorkFlowMenuRule($data){
- // 最外层
- // tableId = 菜单id
- // flowPermission 发起人 空数组则为所有人 非空 则是指定人
- // directorMaxLevel 主管层级 (暂时没用到)
- // nodeConfig 节点数据
- if(empty($data['tableId'])) return [false, '菜单ID不能为空'];
- $menu = SysMenu::where('id', $data['tableId'])->first();
- if(empty($menu)) return [false, '菜单不存在或已被删除'];
- $menu = $menu->toArray();
- if($menu['del_time'] > 0) return [false, '菜单不存在或已被删除'];
- if(! isset($data['nodeConfig'])) return [false, '请传入节点参数'];
- $id = $data['id'] ?? 0;
- $bool = WorkFlow::where('del_time',0)
- ->where('menu_id',$data['tableId'])
- ->when(! empty($id),function ($query) use ($id){
- return $query->where('id', '<>', $id);
- })->exists();
- if($bool) return [false, '该菜单工作流已创建'];
- return [true, ''];
- }
- //给入节点id 获取节点下所有子集结构
- function createIdToNodeMap(array $tree, &$map = []) {
- foreach ($tree as $node) {
- // 如果节点有ID,则将其添加到映射中
- if (isset($node['id'])) {
- $map[$node['id']] = $node;
- }
- // 如果当前节点有子节点,则递归调用以处理子节点
- if (isset($node['children']) && is_array($node['children']) && ! empty($node['children'])) {
- $this->createIdToNodeMap($node['children'], $map);
- }
- }
- return $map;
- }
- function organizationData($array){
- $return = [];
- foreach ($array as $key => $value){
- $return[] = [
- 'id' => $value['id'],//节点id
- 'parent_id' => $value['parent_id'] ?? 0,//0代表无父级
- 'type' => $value['type'], // 0 发起人 1审批 2抄送 3条件 4路由
- 'priorityLevel' => $value['priorityLevel'] ?? 0,//0代表无优先级
- ];
- }
- return $return;
- }
- function flattenWorkflow($node, &$result = [], $parentId = null, &$idCounter = 0) {
- $idCounter++;
- $currentId = $idCounter;
- $nodeData = [
- 'id' => $currentId,
- 'parent_id' => $parentId,
- ];
- foreach ($node as $key => $value) {
- if (!in_array($key, ['childNode', 'conditionNodes'])) {
- $nodeData[$key] = $value;
- }
- }
- $result[] = $nodeData;
- // echo "Added node: " . $node['nodeName'] . "\n"; // Debugging line
- if ($node['type'] == 4 && isset($node['conditionNodes']) && is_array($node['conditionNodes']) && ! empty($node['conditionNodes'])) {
- foreach ($node['conditionNodes'] as $conditionNode) {
- $this->flattenWorkflow($conditionNode, $result, $currentId, $idCounter);
- }
- }
- if (isset($node['childNode']) && is_array($node['childNode']) && ! empty($node['childNode'])) {
- $this->flattenWorkflow($node['childNode'], $result, $currentId, $idCounter);
- }
- return $result;
- }
- function settleWorkFlowData($data, $array){
- $return = $return_detail = $map = [];
- if(empty($array)) return [true, [$return, $return_detail]];
- foreach ($array as $key => $value){
- $tmp = [
- 'm_id' => $value['id'],//节点id 后端生成
- 'type' => $value['type'],// 0 发起人 1审批 2抄送 3条件 4路由
- 'p_id' => 0,//人员id
- 'd_id' => 0,//部门id
- 'settype' => $value['settype'] ?? 0,// 审批人设置 1指定成员 2主管 4发起人自选 5发起人自己 7连续多级主管
- 'selectMode' => $value['selectMode'] ?? 0,//审批人数 1选一个人 2选多个人
- 'selectRange' => $value['selectRange'] ?? 0,//选择范围 1.全公司 2指定成员 2指定角色
- 'examineMode' => $value['examineMode'] ?? 0,//多人审批时采用的审批方式 1依次审批 2会签
- 'priorityLevel' => $value['priorityLevel'] ?? 0,//优先级
- ];
- $tmp_return = $return;
- if($value['type'] == 0){
- //发起人
- list($status, $msg) = $this->settleTypeZero($tmp, $data, $return);
- if(! $status) return [false, $msg];
- }elseif ($value['type'] == 1){
- //审批人
- list($status, $msg) = $this->settleTypeOne($tmp, $data, $value, $return);
- if(! $status) return [false, $msg];
- }elseif ($value['type'] == 2){
- //抄送人
- $this->settleTypeTwo($tmp, $value, $return);
- }elseif ($value['type'] == 3){
- //条件
- $this->settleTypeThree($tmp, $value, $return, $return_detail);
- }elseif ($value['type'] == 4){
- //路由
- $this->settleTypeFour($tmp, $value, $return);
- }else{
- return [false, '非法参数:节点TYPE'];
- }
- $differences = array_diff_key($return, $tmp_return);
- $keys = array_keys($differences);
- $map[$key] = $keys;
- }
- return [true, [$return, $return_detail,$map]];
- }
- //发起人
- function settleTypeZero($tmp, $data, &$return){
- if(empty($data['flowPermission'])) {
- //为空 则是 发起人为所有人
- $return[] = $tmp;
- }else{
- foreach ($data['flowPermission'] as $n){
- $t = $tmp;
- //发起人为指定的人或部门
- if($n['type'] == 1){
- $t['p_id'] = $n['targetId'];
- }elseif($n['type'] == 3){
- $t['d_id'] = $n['targetId'];
- }else{
- return [false, '非法参数:发起人'];
- }
- $return[] = $t;
- }
- }
- return [true, ''];
- }
- //审批人
- function settleTypeOne($tmp, $data, $value, &$return){
- //"settype": "",// 审批人设置 1指定成员 2主管 4发起人自选 5发起人自己 7连续多级主管
- //"selectMode": "", //审批人数 1选一个人 2选多个人
- //"selectRange": "", //选择范围 1.全公司 2指定成员 2指定角色
- //"directorLevel": "", //审批终点 最高层主管数
- //"examineMode": "", //多人审批时采用的审批方式 1依次审批 2会签
- //"noHanderAction": "",//审批人为空时 1自动审批通过/不允许发起 2转交给审核管理员
- //"examineEndDirectorLevel": "", //审批终点 第n层主管
- if($value['settype'] == 1){
- foreach ($value['nodeUserList'] as $n){
- $t = $tmp;
- //指定成员
- $t['p_id'] = $n['targetId'];
- $return[] = $t;
- }
- }elseif ($value['settype'] == 2){
- return [false, '暂不支持主管设置'];
- }elseif ($value['settype'] == 4){
- if($value['selectMode'] == 1){
- if($value['selectRange'] == 1){
- //全公司下的一个人
- $return[] = $tmp;
- }elseif ($value['selectRange'] == 2){
- foreach ($value['nodeUserList'] as $n){
- $t = $tmp;
- //指定人里的一个人
- $t['p_id'] = $n['targetId'];
- $return[] = $t;
- }
- }else{
- return [false, '非法参数:选择范围'];
- }
- }elseif ($value['selectMode'] == 2){
- if($value['selectRange'] == 1){
- //全公司里的所有人
- $return[] = $tmp;
- }elseif ($value['selectRange'] == 2){
- //指定人里的所有人
- foreach ($value['nodeUserList'] as $n){
- $t = $tmp;
- $t['p_id'] = $n['targetId'];
- $return[] = $t;
- }
- }else{
- return [false, '非法参数:选择范围'];
- }
- }
- }elseif ($value['settype'] == 5){
- //发起人则是触发工作流的那个人
- $tmp['selectMode'] = 1;
- $tmp['selectRange'] = 2;
- $return[] = $tmp;
- }elseif ($value['settype'] == 7){
- return [false, '暂不支持连续多级主管设置'];
- }else{
- return [false, '非法参数:审批人设置'];
- }
- return [true, ''];
- }
- //抄送人
- function settleTypeTwo($tmp, $value, &$return){
- foreach ($value['nodeUserList'] as $n){
- //抄送人为指定的一些人
- $tmp['p_id'] = $n['targetId'];
- $return[] = $tmp;
- }
- }
- //条件
- function settleTypeThree($tmp, $value, &$return, &$return_detail){
- $return[] = $tmp;
- $lastIndex = count($return) - 1;
- $tt = [];
- foreach ($value['conditionList'] as $val){
- $tt[] = [
- 'column' => $val['columnDbname'],
- 'opt1' => $val['opt1'],
- 'opt2' => $val['opt2'],
- 'opt_type' => $val['optType'],
- 'zdy1' => $val['zdy1'],
- 'zdy2' => $val['zdy2'],
- ];
- }
- $return_detail[$lastIndex] = $tt;
- }
- //路由
- function settleTypeFour($tmp, $value, &$return){
- $return[] = $tmp;
- }
- //触发工作流并生成
- public function create($data, $user){
- list($status, $msg) = $this->createRule($data, $user);
- if(! $status) return [false, $msg];
- try {
- //生成
- list($status, $msg) = $this->createWorkFlowDetail($data, $user);
- if(! $status){
- DB::rollBack();
- return [false, $msg];
- }
- DB::commit();
- } catch (\Exception $e) {
- DB::rollBack();
- return [false, $e->getFile() . '|' . $e->getLine() . '|' . $e->getMessage()];
- }
- return [true, ''];
- }
- public function createRule($data, $user){
- if(empty($data['menu_id'])) return [false, '菜单ID不能为空'];
- if(empty($data['order_number'])) return [false, 'order_number不能为空'];
- if(empty($data['opt_case'])) return [false, 'opt_case不能为空'];
- $oa = config('oa');
- if(empty($oa)) return [false, '工作流配置未设置,请联系开发者'];
- $menu_id = array_column($oa,'menu_id');
- if(! in_array($data['menu_id'], $menu_id)) return [false, '该菜单暂不支持工作流'];
- return [true, ''];
- }
- public function createWorkFlowDetail($data, $user){
- list($status, $msg) = $this->createWorkFlowDetailRule($data, $user);
- if(! $status) {
- if(isset($data['is_check'])){
- //因为工作流不存在,或者点击的人不触发工作流,所以直接成功返回
- list($status, $msg) = $this->callCheck($data, CheckService::TYPE_ONE, $user);
- return [$status, $msg];
- }
- return [false, $msg];
- }
- //创建审批流根据工作流
- list($status, $msg) = $this->createWorkFlow($data, $user, $msg);
- if(! $status) return [false, $msg];
- return [true, ''];
- }
- public function createWorkFlowDetailRule($data, $user){
- $workFlow = WorkFlow::where('del_time',0)
- ->where('menu_id', $data['menu_id'])
- ->first();
- if(empty($workFlow)) return [false, [-1, '菜单工作流不存在、已被删除或未新建']];
- $workFlow = $workFlow->toArray();
- //判断是否创建工作流
- list($status, $msg) = $this->getStartWorkFlow($workFlow['id'], $user);
- if(! $status) return [false, $msg];
- return [true, $workFlow];
- }
- //获取工作流的开始 判断是否激活审批流
- public function getStartWorkFlow($workFlowId = 0, $user){
- //用户的部门
- $depart_user = $user['depart_range'] ?? [];
- //工作流开始节点数据
- $list = WorkFlowSubDetail::where('del_time',0)
- ->where('workflow_id',$workFlowId)
- ->where('type', WorkFlowSubDetail::type_zero)
- ->get()->toArray();
- //工作流的部门 人
- $workflow_depart = $workflow_man = [];
- foreach ($list as $value){
- if($value['p_id'] > 0 && ! in_array($value['p_id'], $workflow_man)) $workflow_man[] = $value['p_id'];
- if($value['d_id'] > 0 && ! in_array($value['d_id'], $workflow_depart)) $workflow_depart[] = $value['d_id'];
- }
- //所有人都能触发审批流
- if(empty($workflow_depart) && empty($workflow_man)) return [true, ''];
- if(! empty($workflow_depart)){
- $d = array_intersect($depart_user, $workflow_depart);
- if(! empty($d)) return [true, ''];
- }
- if(! empty($workflow_man)){
- $p = array_intersect([$user['id']], $workflow_man);
- if(! empty($p)) return [true, ''];
- }
- return [false, [-1, '触发人不在工作流发起者内']];
- }
- //创建审批流根据工作流
- public function createWorkFlow($data, $user, $workFlow){
- try {
- DB::beginTransaction();
- $time = time();
- $model = new WorkFlowGenerated();
- $model->title = $workFlow['title'];
- $model->menu_id = $workFlow['menu_id'];
- $model->vue_param = $workFlow['vue_param'];
- $model->my_param = $workFlow['my_param'];
- $model->order_number = $data['order_number'];
- $model->crt_id = $user['id'];
- $model->save();
- $id = $model->id;
- $this->insertSonModel2($workFlow['id'], $id, $time);
- DB::commit();
- }catch (\Throwable $e){
- DB::rollBack();
- if (str_contains($e->getMessage(), '1062') || str_contains($e->getMessage(), 'Duplicate entry')) {
- return [false, '审批流程已存在'];
- }
- return [false, $e->getFile() . '|' . $e->getLine() . '|' . $e->getMessage()];
- }
- return [true, $id];
- }
- public function insertSonModel2($workFlowId = 0, $workFlowGeneratedId = 0, $time){
- $insert = [];
- $workFlowSub = WorkFlowSub::where('del_time',0)
- ->where('workflow_id', $workFlowId)
- ->select('id','menu_id','m_id')
- ->get()->toArray();
- $keys = [];
- foreach ($workFlowSub as $value){
- $insert[] = [
- 'menu_id' => $value['menu_id'],
- 'm_id' => $value['m_id'],
- 'workflow_generated_id' => $workFlowGeneratedId,
- 'crt_time' => $time,
- ];
- $keys[] = $value['id'];
- }
- WorkFlowGeneratedSub::insert($insert);
- //获取上一次插入订单的所有id
- $last_insert_id = WorkFlowGeneratedSub::where('workflow_generated_id', $workFlowGeneratedId)
- ->where('crt_time', $time)
- ->where('del_time', 0)
- ->select('id')->get()->toArray();
- $last_insert_id = array_column($last_insert_id,'id');
- $map = array_combine($keys, $last_insert_id);
- $workFlowSubDetail = WorkFlowSubDetail::where('del_time',0)
- ->where('workflow_id', $workFlowId)
- ->select('id','menu_id','m_id','workflow_sub_id','type','p_id','d_id','settype','selectMode','selectRange','examineMode','priorityLevel')
- ->get()->toArray();
- $insert2 = [];
- $keys = [];
- foreach ($workFlowSubDetail as $value){
- $keys[] = $value['id'];
- $workflow_generated_sub_id = $map[$value['workflow_sub_id']] ?? 0;
- unset($value['id']);unset($value['workflow_sub_id']);
- $value['workflow_generated_id'] = $workFlowGeneratedId;
- $value['workflow_generated_sub_id'] = $workflow_generated_sub_id;
- $value['crt_time'] = $time;
- $insert2[] = $value;
- }
- WorkFlowGeneratedSubDetail::insert($insert2);
- //获取上一次插入订单的所有id
- $last_insert_id = WorkFlowGeneratedSubDetail::where('workflow_generated_id', $workFlowGeneratedId)
- ->where('crt_time', $time)
- ->where('del_time', 0)
- ->get()->toArray();
- $last_map = array_column($last_insert_id,null,'id');
- $last_insert_id = array_column($last_insert_id,'id');
- $map = array_combine($keys, $last_insert_id);
- $insert3 = [];
- $workFlowSubDetailCondition = WorkFlowSubDetailCondition::where('del_time',0)
- ->where('workflow_id', $workFlowId)
- ->select('menu_id','workflow_sub_detail_id','column','opt1','opt2','opt_type','zdy1','zdy2')
- ->get()->toArray();
- if(! empty($workFlowSubDetailCondition)){
- foreach ($workFlowSubDetailCondition as $value){
- $workflow_generated_sub_detail_id = $map[$value['workflow_sub_detail_id']] ?? 0;
- unset($value['workflow_sub_detail_id']);
- $tmp = $last_map[$workflow_generated_sub_detail_id] ?? [];
- $value['workflow_generated_id'] = $tmp['workflow_generated_id'];
- $value['workflow_generated_sub_id'] = $tmp['workflow_generated_sub_id'];
- $value['workflow_generated_sub_detail_id'] = $workflow_generated_sub_detail_id;
- $value['crt_time'] = $time;
- $insert3[] = $value;
- }
- WorkFlowGeneratedSubDetailCondition::insert($insert3);
- }
- }
- //运行工作流
- public function runWorkFlow($order_number = "", $workFlowGeneratedId = 0){
- $workFlowGenerated = WorkFlowGenerated::where('del_time', 0)
- ->when(! empty($order_number), function ($query) use ($order_number) {
- return $query->where('order_number', $order_number);
- })
- ->when(! empty($workFlowGeneratedId), function ($query) use ($workFlowGeneratedId) {
- return $query->where('id', $workFlowGeneratedId);
- })
- ->first();
- if(empty($workFlowGenerated)) return [false, '工作流不存在或已被删除'];
- $workFlowGenerated = $workFlowGenerated->toArray();
- // if($workFlowGenerated['node_id'])
- }
- //调用审批
- public function callCheck($data, $type, $user)
- {
- $service = new CheckService();
- list($bool, $msg) = $service->createRecordAndInventory([
- 'order_number' => $data['order_number'],
- 'type' => $type,
- 'opt_case' => $data['opt_case'],
- 'user_data' => $user,
- ]);
- return [$bool, $msg];
- }
- }
|