添加网站文件
This commit is contained in:
267
application/admin/logic/LeaveLogic.php
Normal file
267
application/admin/logic/LeaveLogic.php
Normal file
@@ -0,0 +1,267 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
use app\common\logic\AccountLogLogic;
|
||||
use app\admin\logic\StaffLogic;
|
||||
use app\admin\logic\UserLogic;
|
||||
use think\Db;
|
||||
use think\Exception;
|
||||
|
||||
class LeaveLogic{
|
||||
/**
|
||||
* 列表
|
||||
* @param $get
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public static function lists($get){
|
||||
$where = [];
|
||||
//查询
|
||||
if(isset($get['keyword']) && $get['keyword']){
|
||||
$where[] = [$get['keyword_type'],'like','%'.$get['keyword'].'%'];
|
||||
}
|
||||
//等级查询
|
||||
if(isset($get['level']) && $get['level'] != ''){
|
||||
$where[] = ['level','=',$get['level']];
|
||||
}
|
||||
|
||||
//分组查询
|
||||
if(isset($get['group_id']) && $get['group_id']){
|
||||
$where[] = ['group_id','=',$get['group_id']];
|
||||
}
|
||||
|
||||
//日期查询
|
||||
if(isset($get['start_time']) && $get['start_time']!=''){
|
||||
$where[] = ['time','>=',strtotime($get['start_time'])];
|
||||
}
|
||||
if(isset($get['end_time']) && $get['end_time']!=''){
|
||||
$where[] = ['time','<=',strtotime($get['end_time'])];
|
||||
}
|
||||
|
||||
$user_count = Db::name('leave')
|
||||
->where($where)
|
||||
->count();
|
||||
|
||||
$user_list = Db::name('leave')
|
||||
->where($where)
|
||||
->page($get['page'],$get['limit'])
|
||||
->order('id desc')
|
||||
->select();
|
||||
// //请假类型
|
||||
$type = Db::name('leave_type')->column('name','id');
|
||||
foreach ($user_list as &$item){
|
||||
// //会员所属分组
|
||||
if(isset($type[$item['type']])){
|
||||
$item['type'] = $type[$item['type']];
|
||||
}
|
||||
$item['create_time']=date("Y-m-d H:i:s",$item['create_time']);
|
||||
$item['time']=date("Y-m-d",$item['time']);
|
||||
$admin=Db::name('admin')->where('id',$item['admin_id'])->find();
|
||||
if($admin){
|
||||
$item['admin']=$admin['name'];
|
||||
}else{
|
||||
$item['admin']="-";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return ['count'=>$user_count , 'lists'=>$user_list];
|
||||
}
|
||||
|
||||
public static function user(){
|
||||
return Db::name('staff')->where('onwork',1)->select();
|
||||
}
|
||||
|
||||
|
||||
public static function type(){
|
||||
return Db::name('leave_type')->select();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static function add($post){
|
||||
|
||||
$staff=StaffLogic::info($post['privilege']);
|
||||
$starttime_h = date('H',strtotime($post['start_time']));
|
||||
$enttime_h = date('H',strtotime($post['end_time']));
|
||||
//处理0
|
||||
$enttime_0 = date('H:i:s',strtotime($post['end_time']));
|
||||
if($enttime_0 == '00:00:00'){
|
||||
$post['end_time'] = date('Y-m-d',strtotime($post['end_time'])). '00:00:01';
|
||||
}
|
||||
|
||||
$days = [];
|
||||
$period = new \DatePeriod(
|
||||
new \DateTime($post['start_time']),
|
||||
new \DateInterval('P1D'),
|
||||
new \DateTime($post['end_time'])
|
||||
);
|
||||
$len = 0;
|
||||
foreach($period as $k=>$v){
|
||||
$len++;
|
||||
}
|
||||
foreach($period as $k=>$v){
|
||||
if($k == 0 && $starttime_h > 12){
|
||||
$days[] = ['addtime'=>1,'time'=>$v->format('Y-m-d')];
|
||||
continue;
|
||||
}
|
||||
|
||||
if($k === ($len - 1) && $enttime_h < 12){
|
||||
$days[] = ['addtime'=>1,'time'=>$v->format('Y-m-d')];
|
||||
continue;
|
||||
}
|
||||
|
||||
$days[] = ['addtime'=>1,'time'=>$v->format('Y-m-d')];
|
||||
$days[] = ['addtime'=>2,'time'=>$v->format('Y-m-d')];
|
||||
}
|
||||
|
||||
|
||||
if(empty($days)){
|
||||
return;
|
||||
}
|
||||
|
||||
$data = [];
|
||||
foreach($days as $v){
|
||||
|
||||
$data[] = [
|
||||
'name'=> $staff['base']['name'],
|
||||
'phone'=>$staff['base']['mobile'],
|
||||
'user_id'=>$staff['base']['id'],
|
||||
'status'=>0,
|
||||
'admin_id'=>$post['admin_id'],
|
||||
'time'=>strtotime($v['time']),
|
||||
'type'=>$post['level'],
|
||||
'remark'=>$post['remark'],
|
||||
'addtime'=>$v['addtime'],
|
||||
'create_time'=>time()
|
||||
];
|
||||
}
|
||||
// $staff['base']['admin_id']=$post['admin_id'];
|
||||
return Db::name('leave')->insertAll($data);
|
||||
|
||||
|
||||
$data=[
|
||||
'name'=> $staff['base']['name'],
|
||||
'phone'=>$staff['base']['mobile'],
|
||||
'user_id'=>$staff['base']['id'],
|
||||
'status'=>0,
|
||||
'time'=>strtotime($post['end_time']),
|
||||
'type'=>$post['level'],
|
||||
'remark'=>$post['remark'],
|
||||
'addtime'=>$post['level'],
|
||||
'create_time'=>time()
|
||||
];
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static function info($id){
|
||||
return Db::name('leave')->where('id',$id)->find();
|
||||
|
||||
}
|
||||
|
||||
public static function leave_statype(){
|
||||
return Db::name('leave_statype')->select();
|
||||
}
|
||||
|
||||
//员工请假内容
|
||||
|
||||
public static function staff_leave($get){
|
||||
$where = [];
|
||||
//查询
|
||||
//等级查询
|
||||
if(isset($get['staff_id']) && $get['staff_id'] != ''){
|
||||
$where[] = ['staff_id','=',$get['staff_id']];
|
||||
}
|
||||
|
||||
//分组查询
|
||||
if(isset($get['addtimes']) && $get['addtimes']!= ''){
|
||||
$where[] = ['addtime','=',$get['addtimes']];
|
||||
}
|
||||
if(isset($get['type']) && $get['type']){
|
||||
$where[] = ['type','=',$get['type']];
|
||||
}
|
||||
if(isset($get['statussd']) && $get['statussd']!= ''){
|
||||
$where[] = ['status','=',$get['statussd']];
|
||||
}
|
||||
|
||||
//日期查询
|
||||
if(isset($get['start_time']) && $get['start_time']!=''){
|
||||
$where[] = ['time','>=',strtotime($get['start_time'])];
|
||||
}
|
||||
if(isset($get['end_time']) && $get['end_time']!=''){
|
||||
$where[] = ['time','<=',strtotime($get['end_time'])];
|
||||
}
|
||||
|
||||
$user_count = Db::name('leavesd')
|
||||
->where($where)
|
||||
->count();
|
||||
|
||||
$user_list = Db::name('leavesd')
|
||||
->where($where)
|
||||
->page($get['page'],$get['limit'])
|
||||
->order('id desc')
|
||||
->select();
|
||||
// //请假类型
|
||||
$type = Db::name('leave_statype')->column('name','id');
|
||||
foreach ($user_list as &$item){
|
||||
// //会员所属分组
|
||||
if(isset($type[$item['type']])){
|
||||
$item['type'] = $type[$item['type']];
|
||||
}
|
||||
$item['create_time']=date("Y-m-d H:i:s",$item['create_time']);
|
||||
$item['time']=date("Y-m-d",$item['time']);
|
||||
|
||||
}
|
||||
|
||||
return ['count'=>$user_count , 'lists'=>$user_list];
|
||||
}
|
||||
|
||||
|
||||
//请假审核通过
|
||||
public static function passed($post){
|
||||
// return Db::name('leavesd')->where('id',$post['id'])->update(['status'=>1]);
|
||||
$data=Db::name('leavesd')->where('id',$post['id'])->find(); //获取订单的基本信息
|
||||
|
||||
if($data['addtime']=0){ //判断上午订单
|
||||
$ord=Db::name('order_exe')
|
||||
->where('staff_id',$data['staff_id'])
|
||||
// ->where('autotime',$data['time'])
|
||||
->where('addtime',1)
|
||||
->find();
|
||||
return $ord;
|
||||
}
|
||||
else if($data['addtime']=1){ //判断上午订单
|
||||
$ord=Db::name('order_exe')
|
||||
->where('staff_id',$data['staff_id'])
|
||||
->where('autotime',$data['time'])
|
||||
->where('addtime',2)
|
||||
->find();
|
||||
return $ord;
|
||||
}
|
||||
else{
|
||||
return Db::name('leavesd')->where('id',$post['id'])->update(['status'=>1]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
//根据id查询内容出来
|
||||
public static function refuse($id){
|
||||
return Db::name('leavesd')->where('id',$id)->find();
|
||||
}
|
||||
|
||||
//根据id更新请假的状态
|
||||
public static function refusesd($post){
|
||||
return Db::name('leavesd')->where('id',$post['id'])->update(['status'=>2,'refuse'=>$post['code']]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user