Workflow.php 3.5 KB

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