must('space_sign|广告位标识')->errors; if (!empty($errors)) { return reValue(4002, null, $errors); } $spaceSign = $request->get('space_sign'); $version = $request->header('version',null); $cid = $request->header('cid',0); if(2000 == $cid && $version && $this->versionCompare($version,'<','2.2.2')){ //记账项目ios版用 return reValue(4004, null, '未查询到有效数据'); } //获取广告位id $advertId = Advert::getAdvertIdsBySpaceId($spaceSign); if (empty($advertId)) { return reValue(4004, null, '广告位标识错误'); } //获取广告具体信息 $advert = Advert::getAdvertById($advertId, [2], time()); if (!empty($advert)) { //如果获取的结果大于一条随机取出一条返回 if (count($advert) > 1) { $advert = [$advert[array_rand($advert, 1)]]; } if ($advert[0]->type == 2) { $advert[0]->img_url = env('BACK_SERVER') . $advert[0]->img_url; } if(9 == $spaceSign){//记账项目用字段:link_type:1跳转h5 2跳转到发现页 $advert[0]->link_type=1; } $advert[0]->period=60; return reValue(0, $advert); } return reValue(4004, null, '未查询到有效数据'); } public function versionCompare($version1, $operator, $version2) { $_fv = intval ( trim ( str_replace ( '.', '', $version1 ) ) ); $_sv = intval ( trim ( str_replace ( '.', '', $version2 ) ) ); if (strlen ( $_fv ) > strlen ( $_sv )) { $_sv = str_pad ( $_sv, strlen ( $_fv ), 0 ); } if (strlen ( $_fv ) < strlen ( $_sv )) { $_fv = str_pad ( $_fv, strlen ( $_sv ), 0 ); } return version_compare ( ( string ) $_fv, ( string ) $_sv, $operator ); } /** * [advertRecord 广告被点击添加浏览记录] * @Author mzb * @DateTime 2018-07-25T13:49:01+0800 * @param Request $request [description] * @return [type] [description] */ public function advertRecord(Request $request) { $errors = app('check')->must('space_sign|广告位标识')->NonNInt('advert_id|广告id', true)->errors; if (!empty($errors)) { return reValue(4002, null, $errors); } $spaceId = $request->get('space_sign'); $advertId = $request->get('advert_id'); //根据广告位唯一标识获取广告位具体信息 $exists = Advert::getAdvertIdsBySpaceId($spaceId); if (!in_array($advertId, $exists->all())) { return reValue(0, null, '广告标识错误或广告已经下架'); } $advertSpaceInfo = Advert::getAdverSpaceInfoBySign($spaceId, 1); if (empty($advertSpaceInfo)) { return reValue(4004, null); } //插入广告浏览记录 $success = Advert::addBrowseRecords($spaceId, $advertId, $advertSpaceInfo->app_advert_id); if ($success) { return reValue(0, null); } return reValue(4003, null, '记录插入失败'); } public function allStaff(Request $request){ $list = DB::table('annual_meeting')->groupBy('department')->pluck('department'); $list = json_decode(json_encode($list),true); $item = array(); foreach($list as $key=>$value) { $item[$key]['department'] = $value; $data = DB::table('annual_meeting')->select('name','seat_number')->where('department', $value)->get(); $data = json_decode(json_encode($data),true); $item[$key]['list'] = $data; } return reValue(0,$item); } public function searchStaff(Request $request){ $department = $request->input('department'); $name = $request->input('name'); $list = DB::table('annual_meeting')->where('department',$department)->where('name','like','%'.$name.'%')->get(); $list = json_decode(json_encode($list),true); return reValue(0,$list); } public function staffSignUp(Request $request){ $name = $request->input('name'); $info = DB::table('annual_meeting')->where('name',$name)->first(); if(isset($info->is_sign) && $info->is_sign == 1){ return reValue(1000,$info); } $data['is_sign'] = 1; $data['sign_time'] = time(); $res = DB::table('annual_meeting')->where('name',$name)->where('is_sign',0)->update($data); if($res){ return reValue(0,$res); } else { return reValue(1001,$res); } } public function signUpStaffList(Request $request){ $time = $request->input('time'); $list = DB::table('annual_meeting')->where('is_sign',1)->where('sign_time','>',$time)->orderBy('sign_time','asc')->get(); $list = json_decode(json_encode($list)); return reValue(0,$list); } public function luckDraw(Request $request){ $type = $request->input('type'); if(!in_array($type,array(1,2,3))){ return reValue(4002,null); } // //查询该奖项已中奖人数 // $num = DB::table('annual_meeting')->where('is_sign',1)->where('prize',$type)->count(); // //判断中奖人数是否已满 // if( ($type==1) && ($num>=1) ){ // return reValue(1003,null); // } else if(($type == 2) && ($num >= 5)){ // return reValue(1003,null); // } else if(($type == 3) && ($num >= 10)){ // return reValue(1003,null); // } //取出所有已经签到但未中奖的人名单 $list = DB::table('annual_meeting')->where('is_sign',1)->where('prize',0)->get(); $list = json_decode(json_encode($list),true); //获取中奖人 $total = count($list)-1; if($total<0){ return reValue(1004,null); } $key = mt_rand(0,$total); $info = $list[$key]; $id = $info['id']; $res = DB::table('annual_meeting')->where('id',$id)->update(['prize'=>$type]); if($res){ return reValue(0,$info); } else { return reValue(1002,null); } } public function luckDrawInit(){ // $data['is_sign'] = 0; $data['prize'] = 0; // $data['sign_time'] = 0; DB::table('annual_meeting')->where('prize','!=','-1')->update($data); return reValue(0); } public function signUpInit(){ $data['is_sign'] = 0; $data['sign_time'] = 0; DB::table('annual_meeting')->update($data); return reValue(0); } }