ProcessWait.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace app\admin\model;
  3. use think\facade\Db;
  4. use think\Model;
  5. //待办已办
  6. class ProcessWait extends Model
  7. {
  8. protected $table = 'wsm_process_wait';
  9. protected $pk = 'id';
  10. protected $autoWriteTimestamp = false;
  11. public static $status_wait_handle = 1;//状态,1待处理
  12. public static $status_handle_finish = 2;//状态,2待处理
  13. //添加待办记录
  14. public static function add(array $data = [], int $wait_id = 0, string $wait_name = '')
  15. {
  16. // $data数据格式实例
  17. // $data=[
  18. // "order_type"=>'',
  19. // "order_code"=>'',
  20. // "order_id"=>'',
  21. // "order_status"=>'',
  22. // "action_process"=>'',
  23. // "action_status"=>'',
  24. // "action_uid"=>'',
  25. // "action_name"=>'',
  26. // "addtime"=>'',
  27. // ];
  28. //把上一个节点改成已完成
  29. Db::name('process_wait')
  30. ->where(['order_type' => $data['order_type'], 'order_process' => $data['action_status'], 'order_code' => $data['order_code'], 'order_id' => $data['order_id'], 'status' => self::$status_wait_handle])
  31. ->update(['status' => self::$status_handle_finish, 'updatetime' => date('Y-m-d H:i:s')]);
  32. //查询流程下该节点值的id
  33. $id = Db::name('process')
  34. ->alias('a')
  35. ->join('action_process p', 'p.process_id=a.id AND p.order_process=' . $data['action_process'] . ' AND p.operation_type = ' . ActionProcess::$operation_type_approval)
  36. ->where(['a.process_type' => $data['order_type'], 'a.status' => Process::$status_normal, 'a.is_del' => Process::$is_del_normal])->value('p.id', 0);
  37. if ($id) {
  38. $insert_data = [
  39. 'order_type' => $data['order_type'],
  40. 'order_code' => $data['order_code'],
  41. 'order_id' => $data['order_id'],
  42. 'action_uid' => $data['action_uid'],
  43. 'action_name' => $data['action_name'],
  44. 'status' => self::$status_wait_handle,
  45. 'order_process' => $data['action_process'],
  46. 'addtime' => date('Y-m-d H:i:s'),
  47. 'updatetime' => date('Y-m-d H:i:s'),
  48. ];
  49. if ($wait_id) {
  50. $insert_data['wait_id'] = $wait_id;
  51. $insert_data['wait_name'] = $wait_name;
  52. } else {
  53. //查询该节点值对应的角色id
  54. $roleid = Db::name('role_process')
  55. ->whereFindInSet('action_data', $id)
  56. ->where('is_del', 0)
  57. ->column('role_id');
  58. $insert_data['roleid'] = implode(',', $roleid);
  59. }
  60. //增加新的节点
  61. return self::create($insert_data)->save();
  62. }
  63. }
  64. }