123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- <?php
- namespace app\common\model;
- use think\Model;
- /**
- * 审批流程设置模型
- */
- class ApproveFlow extends Model
- {
- /**
- * 获取流程条件
- *
- * @param integer $module 模块类型
- * @param integer $type 流程类型
- * @param integer $is_special 是否特殊:0=通用,1=特殊
- * @param string $userid 特殊的用户userid
- **/
- public static function get_where($module, $type, $is_special, $userid = '')
- {
- return self::where('module', $module)
- ->where('type', $type)
- ->where('is_special', $is_special)
- ->when($userid, function ($query) use ($userid) {
- $query->where('special_user_id', $userid);
- });
- }
- protected $module_desc = [
- '1' => '请假',
- '2' => '用车',
- '3' => '出差',
- '4' => '呈批',
- '5' => '维修',
- '6' => '学校文件',
- '7' => '合同',
- ];
- // 获取审批人
- public static function getApproveUser($module, $user_id)
- {
- $check_flow = ApproveFlow::where('user_id', $user_id)->where('type', 1)->where('module', $module)->find();
- $where = [];
- $where[] = ['l.type', '=', 1];
- $where[] = ['l.module', '=', $module];
- if ($check_flow) $where[] = ['l.sort', '>', $check_flow->sort];
- $list = static::field('l.user_id,u.name user_name,u.headimg')->alias('l')
- ->where($where)
- ->order('l.sort asc')
- ->leftJoin('StoreMember u', 'u.id = l.user_id')
- ->select()->toArray();
- return $list;
- }
- // 获取抄送人
- public static function getCopyTo($module, $user_id)
- {
- $check_flow = ApproveFlow::where('user_id', $user_id)->where('type', 2)->where('module', $module)->find();
- $where = [];
- $where[] = ['l.type', '=', 2];
- $where[] = ['l.module', '=', $module];
- if ($check_flow) $where[] = ['l.sort', '>', $check_flow->sort];
- $list = ApproveFlow::field('l.user_id,u.name user_name,u.headimg')
- ->alias('l')
- ->where($where)
- ->order('l.sort asc')
- ->leftJoin('StoreMember u', 'u.id = l.user_id')
- ->select()->toArray();
- return $list;
- }
- // 获取审批流程数据
- public static function getApproveData($flow_user, $copy_user, $info_id)
- {
- $flow_data = [];// 审批流程
- $flow_num = 0;
- // 审批人
- foreach (explode(',', $flow_user) as $fk => $fv) {
- if (!$fv) continue;
- $flow_num++;
- $flow_data[] = [
- 'info_id' => $info_id,
- 'approve_user' => $fv,
- 'flow' => $flow_num,
- 'create_at' => date('Y-m-d H:i:s'),
- 'start_time' => $flow_num == 1 ? date('Y-m-d H:i:s') : null,
- 'status' => $flow_num == 1 ? 1 : 0,
- ];
- }
- // 抄送人
- foreach (explode(',', $copy_user) as $ck => $cv) {
- if (!$cv) continue;
- $flow_data[] = [
- 'info_id' => $info_id,
- 'approve_user' => $cv,
- 'approve_type' => 2
- ];
- }
- return ['flow_data' => $flow_data, 'flow_num' => $flow_num];
- }
- }
|