瀏覽代碼

教师端,上课统计

lizhen_gitee 7 月之前
父節點
當前提交
fadfb08131
共有 1 個文件被更改,包括 21 次插入2 次删除
  1. 21 2
      application/api/controller/coach/Lesson.php

+ 21 - 2
application/api/controller/coach/Lesson.php

@@ -287,6 +287,7 @@ class Lesson extends Apic
         $date_end = strtotime('+1 month', $date) - 1;//月末
 
         $cate_id = input('cate_id',0);
+        $lesson_type = input('lesson_type',0);//私教课,普通课
 
         $where = [
             'slot.starttime' => ['BETWEEN',[$date,$date_end]],
@@ -295,6 +296,9 @@ class Lesson extends Apic
         if($cate_id){
             $where['lesson.lessoncate_id'] = $cate_id;
         }
+        if($lesson_type){
+            $where['lesson.type'] = $lesson_type;
+        }
         //课时
         $list = Db::name('lesson_slot')->alias('slot')
             ->field('slot.*,lesson.name,lesson.name_en')
@@ -304,20 +308,35 @@ class Lesson extends Apic
         $list->where('find_in_set(:coach_ids,coach_ids)', ['coach_ids' => $this->auth->id]);
 
         $list = $list->order('slot.starttime asc')->select();
+
+        $result = [
+            'list' => [],
+            'total' => 0,
+            'total_hours' => 0,
+        ];
         if(empty($list)){
-            $this->success(1,[]);
+            $this->success(1,$result);
         }
+
         $list = $this->list_lang($list,['name']);
 
+        $total_hours = 0;
         foreach($list as $key => &$slot){
             //hours转换
             $slot['hours'] = floatval($slot['hours']);
             //已报名数量
             $pay_number = Db::name('lesson_order')->where('slot_id',$slot['id'])->where('order_status',20)->sum('usernumber');
             $slot['usernumber'] = $pay_number;
+
+            $total_hours = bcadd($total_hours,$slot['hours'],1);
         }
 
-        $this->success(1,$list);
+        $result = [
+            'list' => $list,
+            'total' => count($list),
+            'total_hours' => $total_hours,
+        ];
+        $this->success(1,$result);
     }
 
 }