Workflow.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. namespace app\admin\model;
  3. use think\facade\Config;
  4. //记录操作流程
  5. class Workflow extends \think\Model
  6. {
  7. public static function SaveFlow($data){
  8. $conf =Config::get("process");
  9. $action = isset($conf[$data['order_type']]) ? $conf[$data['order_type']]:[];
  10. $last =end($action);
  11. $order_status=2;//默认进行中
  12. if((is_array($last)&&in_array($data['action_process'],$last))||$last==$data['action_process']){
  13. $order_status=3; //流程结束
  14. }
  15. $header =reset($action);
  16. if((is_array($header)&&in_array($data['action_process'],$header))||$header==$data['action_process']){
  17. $order_status=1; //流程新建
  18. }
  19. $proces = self::where(["order_type"=>$data['order_type'],"order_id"=>$data['order_id'],"is_del"=>0])->find();
  20. if($proces){
  21. $info=[
  22. "order_process"=>$data['order_status'],
  23. "order_status"=>$order_status,
  24. "action_uid"=>$data['action_uid'],
  25. "action_name"=>$data['action_name'],
  26. "updatetime"=>date("Y-m-d H:i:s")
  27. ];
  28. self::where(["id"=>$proces['id']])->update($info);
  29. }else{
  30. $proces=[
  31. "order_type"=>$data['order_type'],
  32. "order_code"=>$data['order_code'],
  33. "order_id"=>$data['order_id'],
  34. "order_process"=>$data['order_status'],
  35. "order_status"=>$order_status,
  36. "apply_id"=>$data['action_uid'],
  37. "apply_name"=>$data['action_name'],
  38. "action_uid"=>$data['action_uid'],
  39. "action_name"=>$data['action_name'],
  40. "addtime"=>date("Y-m-d H:i:s"),
  41. "updatetime"=>date("Y-m-d H:i:s")
  42. ];
  43. self::insert($proces);
  44. }
  45. // self::Addwait($data);
  46. }
  47. /**
  48. * 待办事项新建
  49. *
  50. */
  51. public static function Addwait($data){
  52. $conf =Config::get("process");
  53. $action = isset($conf[$data['order_type']]) ? $conf[$data['order_type']]:[];
  54. $order_status=1 ;
  55. if(!empty($action)){
  56. $last =end($action);
  57. $wait="";
  58. foreach ($action as $key=>$value){
  59. if((is_array($value)&&in_array($data['action_process'],$value))||$value==$data['action_process']){
  60. if($value!=$last){
  61. $order_status=1;
  62. $index=$key+1;
  63. $wait= is_array($action[$index])? $action[$index][0]:$action[$index];
  64. break;
  65. }else{
  66. $wait=$data['action_process'];
  67. $order_status=2;
  68. }
  69. }
  70. }
  71. $orderp =ActionProcess::where(["order_type"=>$data['order_type'],"order_process"=>$wait])->find();
  72. if($orderp!=false){
  73. $data=[
  74. "order_type"=>$data['order_type'],
  75. "order_code"=>$data['order_code'],
  76. "order_id"=>$data['order_id'],
  77. "order_process"=>$wait,
  78. "order_status"=>$data['action_process'],
  79. "wait_id"=>$orderp['uid'],
  80. "wait_name"=>$orderp['uname'],
  81. "roleid"=>$orderp['roleid'],
  82. "action_uid"=>$data['action_uid'],
  83. "action_name"=>$data['action_name'],
  84. "status"=>$order_status,
  85. "addtime"=>date("Y-m-d H:i:s"),
  86. "updatetime"=>date("Y-m-d H:i:s")
  87. ];
  88. $da=ProcessWait::where(['order_code'=>$data['order_code'],"order_type"=>$data['order_type']])
  89. ->find();
  90. if($da==false){
  91. ProcessWait::insert($data);
  92. }else{
  93. ProcessWait::where(['order_code'=>$data['order_code'],"order_type"=>$data['order_type']])->update
  94. ($data);
  95. }
  96. }
  97. }
  98. }
  99. public function checkStatus(){
  100. }
  101. }