model = model('app\admin\model\video\Main'); } public function getvideolist(){ $data = $this->request->post(); $where = []; if(isset($data['class_type']) && $data['class_type']){ $where['class_type'] = $data['class_type']; } if(isset($data['class_name']) && $data['class_name']){ $where['class_name'] = ['like',"%{$data['class_name']}%"]; } $page = $data['page']; $list = $this->model ->where($where) ->where('status', '1') ->group('class_name') ->orderRaw('createtime') ->paginate(['page'=> $page?? 1,'list_rows' => 12]); return $this->success("获取公里课堂列表成功",$list); } //获取公益课堂科目列表 public function gettypelist(){ $classType = [ ['value'=>'1','name'=>'语文'], ['value'=>'2','name'=>'数学'], ['value'=>'3','name'=>'地理'], ['value'=>'4','name'=>'英语'], ['value'=>'5','name'=>'物理'], ['value'=>'6','name'=>'语文'], ['value'=>'7','name'=>'其他'] ]; return $this->success("获取成功",$classType); } public function getdetail(){ if($this->request->isPost()){ //随机获取一条广告数据 $AdvertInfo = Advert::where('status','normal')->where('module','gys')->where("type",'video')->orderRaw('rand()')->limit(1)->find(); $id = $this->request->post("id"); $info = $this->model->get($id); $info['AdvertInfo'] = $AdvertInfo; return $this->success("获取成功",$info); } return $this->error("获取课堂信息失败"); } public function consumeAdvert(){ if($this->request->isPost()){ //记录日志 $uid = $this->auth->id?$this->auth->id:0; $vid = $this->request->post('class_id'); $advert_id = $this->request->post('advert_id'); //查询广告信息 $AdvertInfo = Advert::get($advert_id); if(!empty($AdvertInfo)){ //查询供应商信息 $userinfo = User::get($AdvertInfo['gys']); if($userinfo['money']>0.5){ DB::startTrans(); try { $now_money = round(bcadd(-0.5,$userinfo['money']),2); User::money(-0.5, $AdvertInfo['gys'], "公益课堂推广广告消费余额0.5元",0); Log::insert(['uid'=>$uid,'old_money'=>$userinfo['money'],'now_money'=>$now_money,'vid'=>$vid,'type'=>3,'advert_id'=>$advert_id,'content'=>"供应商广告消耗",'gys'=>$userinfo['id'],'createtime'=>date("Y-m-d H:i:s",time())]); Db::commit(); } catch (Exception $e) { Db::rollback(); return $this->error($e->getMessage()); } } $this->success("供应商消费成功"); } } } public function setredpocket(){ if($this->request->post()){ $uid = $this->auth->id; $userinfo = User::get($uid); $class_id = $this->request->post('class_id'); //查询用户是否已经获得红包 $info = Log::where('uid',$uid)->where("type",1)->where('vid',$class_id)->find(); if($info) $this->success("该用户已经获得奖励"); //获取奖励红包数量 $config = get_addon_config('wanlshop'); $sendred = $config['watchvideo']['givered']; $log['old_num'] = $userinfo['redpocket']; $log['uid'] = $uid; $userinfo->redpocket = bcadd($userinfo->redpocket,$sendred); $log['now_num'] = $userinfo['redpocket']; $log['createtime'] = date("Y-m-d H:i:s",time()); $log['content'] = "观看公益课堂,获得奖励红包{$sendred}个"; $log['number'] = $sendred; $log['type'] = 4; $log['pm'] = 0; if($userinfo->save()){ Redlog::insert($log); Log::insert(['uid'=>$uid,'redpocket'=>$sendred,'vid'=>$class_id,'type'=>1,'createtime'=>date("Y-m-d H:i:s",time()),'content'=>"公益课堂观看奖励红包{$sendred}个"]); $this->success("奖励已发放"); } $this->error("奖励发放失败"); } } public function getclassgroup(){ if($this->request->isPost()){ $class_name = $this->request->post('class_name'); $class_type = $this->request->post('class_type'); $id = $this->request->post('class_id'); $list = $this->model->field('class_type,class_page') ->where('class_name', $class_name) ->where('class_type', $class_type) ->group('class_page') ->orderRaw('createtime')->select(); foreach($list as $key => $val){ $list[$key]['children'] = $this->model ->where('class_name', $class_name) ->where('class_type', $class_type) ->where('class_page',$val->class_page) ->orderRaw('createtime')->select(); } return $this->success("获取成功",$list); } //获取课程表 } }