Blame view

addons/qingdong/model/Attendance.php 3.99 KB
2db47680   hexiaodong   chore: 初始提交 php 遗...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
  <?php
  
  namespace addons\qingdong\model;
  
  use think\Model;
  use traits\model\SoftDelete;
  use think\Db;
  
  /**
   *考勤管理
   */
  class Attendance Extends Model {
      use SoftDelete;
  
      // 表名,不含前缀
      protected $name = 'qingdong_attendance';
      // 开启自动写入时间戳字段
      protected $autoWriteTimestamp = 'int';
      // 定义时间戳字段名
      protected $createTime = 'createtime';
      protected $updateTime = 'updatetime';
      protected $deleteTime = 'deletetime';
      // 追加属性
      protected $append = [
          'files',
      ];
  
      /**
       * 
       * 每天执行一次,获取一星期是否是节假日再判断是否可以打卡签到
       * 查询今天和后面七天的数据
       */
      public function resetWeekdidi()
      {
          $tarr = [];
          for($i=0;$i<7;$i++){
              $tarr[] = date('Y-m-d', strtotime("+$i days"));
          }
  
  //        halt("https://apis.tianapi.com/jiejiari/index?key=YOUR_API_KEY&date=".implode(',',$tarr)."&type=0");
             
  //        $ret = \fast\Http::get("https://apis.tianapi.com/jiejiari/index?key=YOUR_API_KEY&date=".implode(',',$tarr)."&type=0");//date('Y-m-d H:i:s', strtotime('+7 days'));
  		$curl = curl_init();
          $data = [
              "date"=>$tarr,
              "type"=>0,
          ];
          $jsonData = json_encode($data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); // 生成 JSON 字符串
          curl_setopt_array($curl, array(
              CURLOPT_URL => 'https://apis.tianapi.com/jiejiari/index?key=YOUR_API_KEY',
              CURLOPT_RETURNTRANSFER => true,
              CURLOPT_ENCODING => '',
              CURLOPT_MAXREDIRS => 10,
              CURLOPT_TIMEOUT => 0,
              CURLOPT_FOLLOWLOCATION => true,
              CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
              CURLOPT_CUSTOMREQUEST => 'GET',
              CURLOPT_POSTFIELDS =>$jsonData,
              CURLOPT_HTTPHEADER => array(
                  'Content-Type: application/json'
              ),
          ));
          $ret = curl_exec($curl);
          curl_close($curl);
  		
          $data = json_decode($ret,true);//weekday
  //     halt($data);
          if(isset($data['code']) && $data['code']==200){
              $list = $data['result']['list'];
              $week = [
                 'weekday','monday','tuesday','wednesday','thursday','friday','saturday'
              ];
              $updata = [];
              // halt($list);
              $updateobj = [];
              foreach($list as $item){
                  $updata[$week[$item['weekday']]] = !$item['isnotwork'];
                  $updateobj[] = [ 
                      'name'=>$week[$item['weekday']],
                      'value'=>!$item['isnotwork'],
                      'date'=>$item['date']
                  ];
              }
              //可添加特殊上班日期
              $lists = Db::name('qingdong_attendance_time')->whereNull('deletetime')->select();//->update($updata);
              foreach ($lists as $ii){
                  $yarr = explode(',',$ii['more']);
                  $up = [];
                  foreach($updateobj as &$iv){
                      $up[$iv['name']] = $iv['value'];
                      if(in_array($iv['date'],$yarr)){
                          $up[$iv['name']] = !$iv['value'];
                      }
                      Db::name('qingdong_attendance_time')->where('id',$ii['id'])->setField($iv['name'],$up[$iv['name']]);
                  }
                  
              }
          }
          //weekday 星期数字 0-6 0表示星期天
          
      }
      //创建人
      public function createStaff() {
          return $this->hasOne(Staff::class, 'id', 'staff_id')->field('id,name,img,post');
      }
  
  
  
      //创建人
      public function staff() {
          return $this->hasOne(Staff::class, 'id', 'staff_id')->field('id,name,img,post');
      }
  
      /**
       * 获取
       */
      public function getFilesAttr($value, $data)
      {
          if (empty($data['file_ids'])) {
              return '';
          }
          $paths = File::where(['id' => ['in', $data['file_ids']]])->column('file_path');
          return $paths?implode(',', $paths):'';
      }
  }