12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <?php
- namespace app\common\service;
- use app\common\constant\CommonConstant;
- use app\common\model\Approve;
- use app\common\model\ApproveInfo;
- use app\common\model\User;
- use think\Db;
- use think\Exception;
- /**
- * 审批服务类
- */
- class ApproveService
- {
- /**
- * 列表
- *
- * @param $module
- * @param $status
- * @param $start_time
- * @param $end_time
- * @param $search
- * @param $offset
- * @param $length
- * @param $user
- **/
- public static function get_list($module, $status, $start_time, $end_time, $search, $offset, $length, $user)
- {
- if (!array_key_exists($module, CommonConstant::get_module_list())) {
- return [];
- }
- if (!in_array($status, [1, 2, 3])) {
- return [];
- }
- $userid = $user['userid'];
- $aliasName = 'approve.';
- // $jobName = 'approveInfo.';
- $field = 'id,info_id,status,create_at';
- $joinField = 'id,user_id,order_no,apply_date,reason,type,desc,start_time,end_time';
- $list = Approve::field($field)
- ->when($status, function ($query) use ($aliasName,$status) {
- if ($status == 1) {
- $query->where($aliasName.'status', 'in',[CommonConstant::STATUS_1,CommonConstant::STATUS_2]);
- }
- if ($status == 2) {
- $query->where($aliasName.'status', 'in', [CommonConstant::STATUS_3,CommonConstant::STATUS_4]);
- }
- })
- ->where($aliasName.'is_deleted', CommonConstant::IS_DELETED_0)
- ->where($aliasName.'approve_user', $userid)
- ->withJoin(['approveInfo' => function ($query) use ($joinField) {
- $query->withField($joinField)
- ->where('is_deleted',CommonConstant::IS_DELETED_0);
- }]);
- // $list = self::get_with($list, $module, $status);
- $list = $list->limit($offset, $length)
- ->order('id desc')
- ->select();
- return $list;
- }
- public static function get_with($list, $module, $status)
- {
- switch ($module) {
- case CommonConstant::MODULE_5:
- $list = $list->with(['peer_user' => function ($query) {
- $query->field('id,info_id,name');
- }, 'approve_info' => function ($query) use ($status) {
- $query->field('id,info_id,status,approve_user')
- ->where('status', $status)
- ->with(['user' => function ($query) {
- $query->field('userid,name');
- }]);
- }]);
- break;
- }
- return $list;
- }
- /**
- * 拼接查询字段
- */
- public static function getAliasField($field, $aliasName)
- {
- $field = explode(',', $field);
- foreach ($field as &$value) {
- $value = $aliasName . $value;
- }
- return $field;
- }
- }
|