Recruitment.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php namespace App\Http\Controllers\Api;
  2. use App\Http\Controllers\Api\Api;
  3. use App\Models\RecruitmentActive as Model;
  4. use App\Models\RecruitmentPrizeRecord;
  5. use App\Models\RecruitmentRecord;
  6. use App\Models\Custom;
  7. use App\Models\WeiBan\Tags;
  8. use Vinkla\Hashids\Facades\Hashids;
  9. /**
  10. * 拉新活动接口
  11. *
  12. * @author 刘相欣
  13. *
  14. * */
  15. class Recruitment extends Api{
  16. /**
  17. * 获取拉新活动 /api/recruitment/get_info
  18. *
  19. * */
  20. public function get_info(Model $Model,Custom $Custom,RecruitmentPrizeRecord $RecruitmentPrizeRecord,RecruitmentRecord $RecruitmentRecord,Tags $WeiBanTags){
  21. // 接口验签
  22. // $this->verify_sign();
  23. // 验证登录
  24. $uid = $this->checkLogin();
  25. // 查询数据
  26. // 获取客户城市ID
  27. $custom = $Custom->getOne($uid);
  28. //查询拉新活动
  29. if( !$custom['city_id'] ) return json_send(['code'=>'error','msg'=>'请选择所在城市后下单','data'=>['error'=>'请选择所在城市后下单']]);
  30. // 获取城市ID
  31. $cityId = (string)$custom['city_id'];
  32. // 查询用户标签
  33. $tags = $WeiBanTags->getListByWeibanExtid($custom['weiban_extid']);
  34. $time = time();
  35. $select = [
  36. ['start_time','<=',$time],
  37. ['end_time','>',$time],
  38. ['status','=',0],
  39. ];
  40. $activeList = $Model::query()->whereRaw("find_in_set('$cityId', city_ids)")->where($select)->get()->toArray();
  41. $activeInfo = [];
  42. if ($activeList) {
  43. foreach ($activeList as $active) {
  44. $allowJoin = 0;
  45. if ($active['tag_scope']) {
  46. // 解析数组
  47. $tag_scope = explode(',', $active['tag_scope']);
  48. // 标签范围限定时,默认不能参与
  49. // 判断标签是不是存在
  50. if ($tags) {
  51. foreach ($tags as $v) {
  52. // 标签范围内,允许参加
  53. if (in_array($v['name'], $tag_scope)) $allowJoin = 1;
  54. }
  55. }
  56. }else{
  57. $allowJoin = 1;
  58. }
  59. if ($active['tag_except']) {
  60. // 解析数组
  61. $tag_except = explode(',', $active['tag_except']);
  62. // 标签范围限定时,默认不能参与
  63. $allowJoin = 0;
  64. // 判断标签是不是存在
  65. if ($tags) {
  66. foreach ($tags as $v) {
  67. // 标签范围内,允许参加
  68. if (in_array($v['name'], $tag_except)) $allowJoin = 0;
  69. }
  70. }
  71. }
  72. if ($allowJoin) {
  73. $activeInfo = $active;
  74. break;
  75. }
  76. }
  77. }
  78. if ($activeInfo){
  79. $activeInfo['start_time'] = date('Y-m-d H:i:s',$activeInfo['start_time']);
  80. $activeInfo['end_time'] = date('Y-m-d H:i:s',$activeInfo['end_time']);
  81. $activeInfo['banner_img'] = path_compat($activeInfo['banner_img']);
  82. }
  83. return json_send(['code'=>'success','msg'=>'获取成功','data'=>$activeInfo]);
  84. }
  85. /**
  86. * 获取奖励记录 /api/recruitment/get_record
  87. *
  88. * */
  89. public function get_record(RecruitmentPrizeRecord $recruitmentPrizeRecord){
  90. // 接口验签
  91. // $this->verify_sign();
  92. // 验证登录
  93. $uid = $this->checkLogin();
  94. // 接收参数
  95. $limit = request('limit',15);
  96. // 查询条件
  97. $map = [['recruitment_prize_record.custom_uid','=',$uid]];
  98. // 查询数据
  99. $Paginator = $recruitmentPrizeRecord->query()
  100. ->join('recruitment_record','recruitment_record.id','=','recruitment_prize_record.recruitment_record_id')
  101. ->join('custom','custom.uid','=','recruitment_record.new_uid')
  102. ->where($map)
  103. ->orderByDesc('id')
  104. ->paginate($limit,['recruitment_prize_record.id','recruitment_prize_record.prize_type','recruitment_prize_record.prize','recruitment_prize_record.type','recruitment_prize_record.custom_uid','recruitment_prize_record.insert_time','recruitment_prize_record.recruitment_record_id','custom.username']);
  105. // 重置数据
  106. $list = [];
  107. // 获取数据
  108. $list['total'] = $Paginator->total();
  109. $list['current_page'] = $Paginator->currentPage();
  110. $list['per_page'] = $Paginator->perPage();
  111. $list['last_page'] = $Paginator->lastPage();
  112. $list['data'] = $Paginator->items();
  113. // 循环数据
  114. foreach ($list['data'] as $key => $value) {
  115. // 处理时间
  116. $value['insert_time'] = date('Y-m-d H:i:s',$value['insert_time']);
  117. // 重组
  118. $list['data'][$key] = $value;
  119. }
  120. // 返回数据
  121. return json_send(['code'=>'success','msg'=>'获取成功','data'=>$list]);
  122. }
  123. }