123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- <?php
- namespace app\common\model;
- use app\hander\HelpHander;
- use think\Db;
- use think\Model;
- class LeaveBj extends Model
- {
- public function add($data){
- $data['days'] = calculate_leave($data['start'],$data['end'],0);
- $starts = explode(' ',$data['start']);
- if($starts[1] == '上午'){
- $data['start_time'] = $starts[0].' 00:00:00';
- }else{
- $data['start_time'] = $starts[0].' 12:00:00';
- }
- $ends = explode(' ',$data['end']);
- if($ends[1] == '上午'){
- $data['end_time'] = $ends[0].' 11:59:59';
- }else{
- $data['end_time'] = $ends[0].' 23:59:59';
- }
- unset($data['start']);
- unset($data['end']);
- $data['create_time'] = date('Y-m-d H:i:s');
- $ret = Db::name('leave_bj')->insert($data);
- return $ret?true:false;
- }
- public function advancedStartLeaveBj($id,$orgId,$userId,$formJson){
- $formJson = json_decode($formJson,true);
- $data = [
- 'org_id' => $orgId,
- 'user_id' => $userId,
- 'apply_id' => $id,
- 'type' => 2,
- ];
- foreach ($formJson as $k=>$v){
- if($v['componentName'] == 'ddleavebjfield'){
- foreach ($v['components'] as $key=>$val){
- switch ($val['idx']){
- case '0':
- $data['start'] = $val['values'];
- break;
- case '1':
- $data['end'] = $val['values'];
- break;
- case '2':
- $data['address'] = isset($val['values'])?$val['values']:'';
- break;
- }
- }
- break;
- }
- }
- $ret = $this->add($data);
- return $ret?true:false;
- }
- public function advancedEndLeaveBj($id,$orgId,$userId,$formJson){
- $data = [
- 'update_time' => date('Y-m-d H:i:s'),
- 'status' => 1
- ];
- $ret = Db::name('leave_bj')->where('apply_id',$id)->update($data);
- return $ret?true:false;
- }
- public function advancedDisagreeLeaveBj($applyId){
- $data = [
- 'update_time' => date('Y-m-d H:i:s'),
- 'status' => 2
- ];
- $ret = Db::name('leave_bj')->where('apply_id',$applyId)->update($data);
- return $ret?true:false;
- }
- public function lists($page,$size,$name,$type,$orgId,$userId=0){
- $map[] = ['al.status','=',1];
- $map[] = ['al.org_id','=',$orgId];
- if($name){
- $map[] = ['ui.name','like','%'.$name.'%'];
- }
- if($type > 0){
- $map[] = ['al.leave_type','=',$type];
- }
- if($userId > 0){
- $map[] = ['al.user_id','=',$userId];
- }
- $lists = Db::name('leave_bj')
- ->alias('al')
- ->join('user_info ui','ui.user_id = al.user_id')
- ->where($map)
- ->field('al.*,ui.name as userName')
- ->page($page,$size)
- ->order('al.id desc')
- ->select();
- $lists = $lists?$lists:[];
- foreach ($lists as $k=>$v){
- $startday = date('Y-m-d',strtotime($v['start_time']));
- if($startday.' 12:00:00' > $v['start_time']){
- $lists[$k]['start_time'] = $startday.' 上午';
- } else {
- $lists[$k]['start_time'] = $startday.' 下午';
- }
- $endday = date('Y-m-d',strtotime($v['end_time']));
- if($endday.' 12:00:00' > $v['end_time']){
- $lists[$k]['end_time'] = $endday.' 上午';
- } else {
- $lists[$k]['end_time'] = $endday.' 下午';
- }
- }
- $total = Db::name('leave_bj')
- ->alias('al')
- ->join('user_info ui','ui.user_id = al.user_id')
- ->where($map)->count();
- $data = [
- 'total' => $total,
- 'list' => $lists?$lists:[]
- ];
- return $data;
- }
- }
|