123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- <?php
- namespace app\common\model;
- use app\common\constant\CommonConstant;
- use think\Model;
- /**
- * 审批流程设置模型
- */
- class ApproveFlow extends Model
- {
- /**
- * 审批流程条件
- *
- * @param integer $module 模块类型
- * @param integer $flow_type 审批流类型:1=审批人,2=抄送人
- * @param integer $flow_item 审批流项:module=5出差类型,module=6请假周期
- **/
- public static function get_where($module, $flow_type, $flow_item)
- {
- return self::where('module', $module)
- ->where('flow_type', $flow_type)
- ->where(function ($query) use ($module, $flow_item) {
- if (in_array($module, [CommonConstant::MODULE_5, CommonConstant::MODULE_6])) {
- $query->where('flow_item', $flow_item);
- }
- });
- }
- 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];
- }
- }
|