ApproveFlow.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace app\common\model;
  3. use think\Model;
  4. // 审批流程设置
  5. class ApproveFlow extends Model
  6. {
  7. // 获取审批人
  8. public static function getApproveUser($module,$user_id){
  9. $check_flow = ApproveFlow::where('user_id',$user_id)->where('type',1)->where('module',$module)->find();
  10. $where = [];
  11. $where[] = ['l.type','=',1];
  12. $where[] = ['l.module','=',$module];
  13. if($check_flow)$where[] = ['l.sort','>',$check_flow->sort];
  14. $list = static::field('l.user_id,u.name user_name,u.headimg')->alias('l')
  15. ->where($where)
  16. ->order('l.sort asc')
  17. ->leftJoin('StoreMember u','u.id = l.user_id')
  18. ->select()->toArray();
  19. return $list;
  20. }
  21. // 获取抄送人
  22. public static function getCopyTo($module)
  23. {
  24. return static::where('type',2)->where('module',$module)->order('sort asc ,id asc')->select()->toArray();
  25. }
  26. // 获取审批流程数据
  27. public static function getApproveData($flow_user,$copy_user,$info_id)
  28. {
  29. $flow_data = [];// 审批流程
  30. $flow_num = 0;
  31. // 审批人
  32. foreach (explode(',',$flow_user) as $fk=>$fv) {
  33. if(!$fv) continue;
  34. $flow_num++;
  35. $flow_data[] = [
  36. 'info_id' => $info_id,
  37. 'approve_user' => $fv,
  38. 'flow' =>$flow_num,
  39. 'create_at'=>date('Y-m-d H:i:s'),
  40. 'start_time'=> $flow_num == 1 ? date('Y-m-d H:i:s'):null,
  41. 'status'=> $flow_num == 1 ? 1 : 0,
  42. ];
  43. }
  44. // 抄送人
  45. foreach (explode(',',$copy_user) as $ck=>$cv) {
  46. if(!$cv) continue;
  47. $flow_data[] = [
  48. 'info_id' => $info_id,
  49. 'approve_user' => $cv,
  50. 'approve_type' =>2
  51. ];
  52. }
  53. return ['flow_data'=>$flow_data,'flow_num'=>$flow_num];
  54. }
  55. }