Browse Source

当月日历

lizhen_gitee 10 months ago
parent
commit
4d21daaa8b
1 changed files with 92 additions and 0 deletions
  1. 92 0
      application/api/controller/coach/Lesson.php

+ 92 - 0
application/api/controller/coach/Lesson.php

@@ -64,6 +64,98 @@ class Lesson extends Apic
         $this->success(1,$list);
         $this->success(1,$list);
     }
     }
 
 
+    //课时列表首页
+    //根据年,月获取当月剩余日期,有课程的标记1
+    public function slot_index(){
+
+        $getdate = input('date',date('Y-m'));
+        if(empty($getdate)){
+            $getdate = date('Y-m');
+        }
+        $year = substr($getdate,0,4);
+        $month = substr($getdate,-2,2);
+
+        //今天是哪日
+        if($year == date('Y') && $month == date('m')){
+            //如果是今年今月,默认今天开始
+            $startday = date('d');
+        }else{
+            //从1号开始
+            $startday = '01';
+        }
+
+        //本月结束日
+        $endday_arr = [
+            '01' => 31,
+            '02' => 28,
+            '03' => 31,
+            '04' => 30,
+            '05' => 31,
+            '06' => 30,
+            '07' => 31,
+            '08' => 31,
+            '09' => 30,
+            '10' => 31,
+            '11' => 30,
+            '12' => 31,
+        ];
+        if($year%4 == 0){
+            $endday_arr['02'] = 29;
+        }
+        $endday = $endday_arr[$month];
+
+        //拿数据
+        $startdate = $getdate.'-'.$startday;
+        $enddate   = $getdate.'-'.$endday;
+        $where = [
+            'starttime' => ['BETWEEN',[strtotime($startdate),strtotime($enddate)+86399]],
+            'status'    => 0,
+        ];
+        //dump($where);exit;
+        $slots = Db::name('lesson_slot')
+            ->where($where)
+            ->where('find_in_set(:coach_ids,coach_ids)', ['coach_ids' => $this->auth->id])
+            ->field('id,starttime')->select();
+
+        $date_arr = [];
+        for($i=intval($startday);$i<=$endday;$i++){
+
+            $j = $i;
+            if($j < 10){
+                $j = 0 . $j;
+            }
+            $idate = $year.'-'.$month.'-'.$j;
+
+            $itime = strtotime($idate);
+            $week = $this->lang == 'en' ? date('D',$itime) : '周'.date('w',$itime);
+
+            $i_data = [
+                'yeah' =>$year,
+                'month'=>$month,
+                'day'  => $j.'',
+                'date' => $idate,
+                'week' => $week,
+                'is_today' => 0,
+                'slot_num' => 0,
+            ];
+
+            foreach($slots as $slot){
+                if(date('Y-m-d',$slot['starttime']) == $idate)
+                {
+                    $i_data['slot_num'] += 1;
+                }
+            }
+
+            if($idate == date('Y-m-d')){
+                $i_data['is_today'] = 1;
+            }
+
+            $date_arr[] = $i_data;
+        }
+
+        $this->success(1,$date_arr);
+    }
+
     //课时详情
     //课时详情
     public function slot_info(){
     public function slot_info(){
         $slot_id = input('slot_id',0);
         $slot_id = input('slot_id',0);