1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?php
- namespace app\common\model;
- use app\hander\HelpHander;
- use think\Db;
- use think\Model;
- class AttendanceLeaveType extends Model
- {
- public function add(){
- $data = [
- 'id' => input('id/d',0),
- 'name' => input('name','','trim'),
- 'org_id' => input('orgId/d',0),
- 'limit' => input('limit/d',0),
- 'enable' => input('enable/d',0),
- 'type' => input('type/d',0),
- ];
- $result = validate('AttendanceLeaveType')->check($data,[],'');
- if(true !== $result){
- HelpHander::error(validate('AttendanceLeaveType')->getError());
- }
- $id = $data['id'];
- unset($data['id']);
- if($id > 0){
- $ret = $this->allowField(true)->save($data,['id'=>$id]);
- }else{
- $ret = $this->allowField(true)->save($data);
- }
- if(!$ret){
- HelpHander::error('操作失败');
- }
- return true;
- }
- public function info($id){
- $info = $this->where('id',$id)->where('del',0)->find();
- if(!$info){
- HelpHander::error('数据不存在');
- }
- return $info->toArray();
- }
- public function lists($enable,$userId,$orgId){
- $map[] = ['del','=',0];
- $map[] = ['org_id','=',$orgId];
- if($enable != ''){
- $map[] = ['enable','=',$enable];
- }
- $lists = $this
- ->where($map)
- ->order('id asc')
- ->select();
- $lists = $lists?$lists->toArray():[];
- $startTime = date('Y').'-00-01 00:00:00';
- foreach ($lists as $k=>$v){
- $usedays = Db::name('attendance_leave')
- ->where('user_id',$userId)
- ->where('leave_type',$v['id'])
- ->where('start_time','>=',$startTime)
- ->where('status',1)
- ->sum('cur_days');
- $lists[$k]['useDay'] = $usedays;
- $lists[$k]['lastDay'] = -1;
- if($v['id'] == 3){ // 年假
- $annual_leave = Db::name('user_info')->where('user_id',$userId)->value('annual_leave');
- $lists[$k]['lastDay'] = $annual_leave?round($annual_leave,1):0;
- }
- }
- return $lists;
- }
- public function del($id){
- $ret = $this->where('id',$id)->setField('del',1);
- if(!$ret){
- HelpHander::error('删除失败');
- }
- return true;
- }
- public function changeStatus($id,$enable){
- $ret = $this->where('id',$id)->setField('enable',$enable);
- if(!$ret){
- HelpHander::error('操作失败');
- }
- return true;
- }
- }
|