暫無描述

AdvertController.php 7.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <?php
  2. namespace App\Http\Controllers\Advert\V1;
  3. use App\Http\Controllers\Controller;
  4. use App\Model\Advert\V1\Advert;
  5. use Illuminate\Http\Request;
  6. use Illuminate\Support\Facades\DB;
  7. class AdvertController extends Controller
  8. {
  9. /**
  10. * [getAdvert 根据广告位唯一标识获取广告详细信息]
  11. * @Author mzb
  12. * @DateTime 2018-07-25T13:48:17+0800
  13. * @param Request $request [description]
  14. * @return [type] [description]
  15. */
  16. public function getAdvert(Request $request)
  17. {
  18. // return reValue(4004, null, '未查询到有效数据');
  19. $errors = app('check')->must('space_sign|广告位标识')->errors;
  20. if (!empty($errors)) {
  21. return reValue(4002, null, $errors);
  22. }
  23. $spaceSign = $request->get('space_sign');
  24. $version = $request->header('version',null);
  25. $cid = $request->header('cid',0);
  26. if(2000 == $cid && $version && $this->versionCompare($version,'<','2.2.2')){
  27. //记账项目ios版用
  28. return reValue(4004, null, '未查询到有效数据');
  29. }
  30. //获取广告位id
  31. $advertId = Advert::getAdvertIdsBySpaceId($spaceSign);
  32. if (empty($advertId)) {
  33. return reValue(4004, null, '广告位标识错误');
  34. }
  35. //获取广告具体信息
  36. $advert = Advert::getAdvertById($advertId, [2], time());
  37. if (!empty($advert)) {
  38. //如果获取的结果大于一条随机取出一条返回
  39. if (count($advert) > 1) {
  40. $advert = [$advert[array_rand($advert, 1)]];
  41. }
  42. if ($advert[0]->type == 2) {
  43. $advert[0]->img_url = env('BACK_SERVER') . $advert[0]->img_url;
  44. }
  45. if(9 == $spaceSign){//记账项目用字段:link_type:1跳转h5 2跳转到发现页
  46. $advert[0]->link_type=1;
  47. }
  48. $advert[0]->period=60;
  49. return reValue(0, $advert);
  50. }
  51. return reValue(4004, null, '未查询到有效数据');
  52. }
  53. public function versionCompare($version1, $operator, $version2) {
  54. $_fv = intval ( trim ( str_replace ( '.', '', $version1 ) ) );
  55. $_sv = intval ( trim ( str_replace ( '.', '', $version2 ) ) );
  56. if (strlen ( $_fv ) > strlen ( $_sv )) {
  57. $_sv = str_pad ( $_sv, strlen ( $_fv ), 0 );
  58. }
  59. if (strlen ( $_fv ) < strlen ( $_sv )) {
  60. $_fv = str_pad ( $_fv, strlen ( $_sv ), 0 );
  61. }
  62. return version_compare ( ( string ) $_fv, ( string ) $_sv, $operator );
  63. }
  64. /**
  65. * [advertRecord 广告被点击添加浏览记录]
  66. * @Author mzb
  67. * @DateTime 2018-07-25T13:49:01+0800
  68. * @param Request $request [description]
  69. * @return [type] [description]
  70. */
  71. public function advertRecord(Request $request)
  72. {
  73. $errors = app('check')->must('space_sign|广告位标识')->NonNInt('advert_id|广告id', true)->errors;
  74. if (!empty($errors)) {
  75. return reValue(4002, null, $errors);
  76. }
  77. $spaceId = $request->get('space_sign');
  78. $advertId = $request->get('advert_id');
  79. //根据广告位唯一标识获取广告位具体信息
  80. $exists = Advert::getAdvertIdsBySpaceId($spaceId);
  81. if (!in_array($advertId, $exists->all())) {
  82. return reValue(0, null, '广告标识错误或广告已经下架');
  83. }
  84. $advertSpaceInfo = Advert::getAdverSpaceInfoBySign($spaceId, 1);
  85. if (empty($advertSpaceInfo)) {
  86. return reValue(4004, null);
  87. }
  88. //插入广告浏览记录
  89. $success = Advert::addBrowseRecords($spaceId, $advertId, $advertSpaceInfo->app_advert_id);
  90. if ($success) {
  91. return reValue(0, null);
  92. }
  93. return reValue(4003, null, '记录插入失败');
  94. }
  95. public function allStaff(Request $request){
  96. $list = DB::table('annual_meeting')->groupBy('department')->pluck('department');
  97. $list = json_decode(json_encode($list),true);
  98. $item = array();
  99. foreach($list as $key=>$value) {
  100. $item[$key]['department'] = $value;
  101. $data = DB::table('annual_meeting')->select('name','seat_number')->where('department', $value)->get();
  102. $data = json_decode(json_encode($data),true);
  103. $item[$key]['list'] = $data;
  104. }
  105. return reValue(0,$item);
  106. }
  107. public function searchStaff(Request $request){
  108. $department = $request->input('department');
  109. $name = $request->input('name');
  110. $list = DB::table('annual_meeting')->where('department',$department)->where('name','like','%'.$name.'%')->get();
  111. $list = json_decode(json_encode($list),true);
  112. return reValue(0,$list);
  113. }
  114. public function staffSignUp(Request $request){
  115. $name = $request->input('name');
  116. $info = DB::table('annual_meeting')->where('name',$name)->first();
  117. if(isset($info->is_sign) && $info->is_sign == 1){
  118. return reValue(1000,$info);
  119. }
  120. $data['is_sign'] = 1;
  121. $data['sign_time'] = time();
  122. $res = DB::table('annual_meeting')->where('name',$name)->where('is_sign',0)->update($data);
  123. if($res){
  124. return reValue(0,$res);
  125. } else {
  126. return reValue(1001,$res);
  127. }
  128. }
  129. public function signUpStaffList(Request $request){
  130. $time = $request->input('time');
  131. $list = DB::table('annual_meeting')->where('is_sign',1)->where('sign_time','>',$time)->orderBy('sign_time','asc')->get();
  132. $list = json_decode(json_encode($list));
  133. return reValue(0,$list);
  134. }
  135. public function luckDraw(Request $request){
  136. $type = $request->input('type');
  137. if(!in_array($type,array(1,2,3))){
  138. return reValue(4002,null);
  139. }
  140. // //查询该奖项已中奖人数
  141. // $num = DB::table('annual_meeting')->where('is_sign',1)->where('prize',$type)->count();
  142. // //判断中奖人数是否已满
  143. // if( ($type==1) && ($num>=1) ){
  144. // return reValue(1003,null);
  145. // } else if(($type == 2) && ($num >= 5)){
  146. // return reValue(1003,null);
  147. // } else if(($type == 3) && ($num >= 10)){
  148. // return reValue(1003,null);
  149. // }
  150. //取出所有已经签到但未中奖的人名单
  151. $list = DB::table('annual_meeting')->where('is_sign',1)->where('prize',0)->get();
  152. $list = json_decode(json_encode($list),true);
  153. //获取中奖人
  154. $total = count($list)-1;
  155. if($total<0){
  156. return reValue(1004,null);
  157. }
  158. $key = mt_rand(0,$total);
  159. $info = $list[$key];
  160. $id = $info['id'];
  161. $res = DB::table('annual_meeting')->where('id',$id)->update(['prize'=>$type]);
  162. if($res){
  163. return reValue(0,$info);
  164. } else {
  165. return reValue(1002,null);
  166. }
  167. }
  168. public function luckDrawInit(){
  169. // $data['is_sign'] = 0;
  170. $data['prize'] = 0;
  171. // $data['sign_time'] = 0;
  172. DB::table('annual_meeting')->where('prize','!=','-1')->update($data);
  173. return reValue(0);
  174. }
  175. public function signUpInit(){
  176. $data['is_sign'] = 0;
  177. $data['sign_time'] = 0;
  178. DB::table('annual_meeting')->update($data);
  179. return reValue(0);
  180. }
  181. }