model = new StudentCourseUsage(); } /** * 获取学员课时消费记录列表 * @return array */ public function getPage(array $data = []) { $where = []; if($data['emergency_contact']){ $where[] = ['c.emergency_contact','like','%'.$data['emergency_contact'].'%']; } if($data['student_name']){ $where[] = ['c.name','like','%'.$data['student_name'].'%']; } if($data['contact_phone']){ $where[] = ['c.contact_phone','=',$data['contact_phone']]; } $search_model = $this->model ->alias("a") ->join(['school_student_courses' => 'b'],'a.student_course_id = b.id','left') ->join(['school_student' => 'c'],'b.student_id = c.id','left') ->join(['school_course' => 'd'],'b.course_id = d.id','left') ->where($where) ->field("a.*,c.name as student_name,c.emergency_contact,d.course_name,b.total_hours,ROUND(b.total_hours - b.use_total_hours) as sy_time,ROUND(b.gift_hours - b.use_gift_hours) as gift_hours") ->order("a.id desc"); $list = $this->pageQuery($search_model); return $list; } /** * 获取学员课时消费记录信息 * @param int $id * @return array */ public function getInfo(int $id) { $field = 'id,student_course_id,used_hours,usage_date,created_at,updated_at'; $info = $this->model->field($field)->where([['id', "=", $id]])->findOrEmpty()->toArray(); return $info; } /** * 添加学员课时消费记录 * @param array $data * @return mixed */ public function add(array $data) { $res = $this->model->create($data); return $res->id; } /** * 学员课时消费记录编辑 * @param int $id * @param array $data * @return bool */ public function edit(int $id, array $data) { $this->model->where([['id', '=', $id]])->update($data); return true; } /** * 删除学员课时消费记录 * @param int $id * @return bool */ public function del(int $id) { $model = $this->model->where([['id', '=', $id]])->find(); $res = $model->delete(); return $res; } }