Online2021Controller.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  1. <?php
  2. namespace App\Http\Controllers\Mobile\Active;
  3. use App\Http\Controllers\Mobile\MobileBaseController;
  4. use App\Models\LotteryLog;
  5. use App\Models\LotteryPrize;
  6. use App\Models\LotteryWin;
  7. use App\Models\Thirdlogin;
  8. use App\Services\Common\CategoryService;
  9. use App\Services\Common\WechatService;
  10. use App\Services\Auth\AuthService;
  11. use App\Services\HomeService;
  12. use Illuminate\Http\Request;
  13. use Illuminate\Support\Facades\Cache;
  14. use Illuminate\Support\Facades\DB;
  15. use Illuminate\Support\Facades\Session;
  16. class Online2021Controller extends MobileBaseController
  17. {
  18. private $wechatService;
  19. protected $categoryService;
  20. protected $authService;
  21. protected $homeService;
  22. public function __construct(WechatService $wechatService, CategoryService $categoryService, authService $authService, HomeService $homeService)
  23. {
  24. $this->wechatService = $wechatService;
  25. $this->categoryService = $categoryService;
  26. $this->authService = $authService;
  27. $this->homeService = $homeService;
  28. }
  29. /**
  30. * 专题页
  31. */
  32. public function index(Request $request)
  33. {
  34. //是否登录
  35. $user = auth('web-member')->user();
  36. if (empty($user)) {
  37. $open_id = Session::get('open_id');
  38. if (empty($open_id)) {
  39. return redirect(route('mobile.lottery.login'));
  40. }
  41. } else {
  42. $third = Thirdlogin::where('uid', $user->id)->first();
  43. $open_id = $third['openid'];
  44. }
  45. // $open_id = '11';
  46. //抽奖次数
  47. $type = $request->input('type', 1);
  48. $date = date('Y-m-d');
  49. $log = LotteryLog::where([
  50. ['create_time', '=', $date],
  51. ['type', '=', $type],
  52. ['open_id', '=', $open_id],
  53. ])->first();
  54. $number = 1;
  55. if (!empty($log)) {
  56. $number = 0;
  57. }
  58. //奖品列表
  59. $prize = LotteryPrize::all();
  60. $ids = [];
  61. $restaraunts = [];
  62. $colors = [];
  63. $images = [];
  64. foreach ($prize as $v) {
  65. $ids[] = $v->id;
  66. $restaraunts[] = $v->prize_name;
  67. $colors[] = $v->prize_bg;
  68. $images[] = upload_asset($v->prize_image);
  69. }
  70. //中奖记录
  71. $win = [];
  72. $user = auth('web-member')->user();
  73. if (!empty($user)) {
  74. $win = LotteryWin::with('prize')->where('member_id', $user->id)->orderBy('status', 'asc')->orderBy('created_at', 'desc')->limit(8)->get();
  75. }
  76. $return_data = [
  77. 'open_id' => $open_id,
  78. 'current_url' => \Illuminate\Support\Facades\Request::getRequestUri(),
  79. 'user' => $user,
  80. 'number' => $number,
  81. 'type' => $type,
  82. 'prize' => $prize,
  83. 'win' => $win,
  84. 'ids' => $ids,
  85. 'restaraunts' => $restaraunts,
  86. 'colors' => $colors,
  87. 'images' => $images,
  88. 'wap_title' => '抽奖',
  89. 'share_title' => '【福利通知】免费找工作,抽大奖拿好礼',
  90. 'share_desc' => '晋江好福利!免费找工作、找人才,还能抽奖,100%中奖,万份好礼免费拿!',
  91. 'share_link' => route('mobile.lottery.login'),
  92. 'share_image_url' => theme_asset('mobile/images/online2021/share_logo.jpg'),
  93. 'live_list' => $this->homeService->getOnline2021Live(),
  94. ];
  95. return view('mobile.app.active.online2021', $return_data);
  96. }
  97. /**
  98. * 专区页
  99. */
  100. public function special(Request $request)
  101. {
  102. $offset = isset($request->page) ? $request->page : 0;
  103. $limit = 8;
  104. $citycategory = $request->input('citycategory', '');
  105. $trade = $request->input('trade', '');
  106. $param_array = ['citycategory', 'trade', 'nature'];
  107. $params = [];
  108. if ($request->all()) {
  109. foreach ($request->all() as $k => $v) {
  110. if (in_array($k, $param_array) && $v) {
  111. $params[$k] = $v;
  112. }
  113. }
  114. }
  115. $filter_where = [
  116. 'AIX_trade' => 100,
  117. 'AIX_company_type' => 100,
  118. ];
  119. $categories = $this->categoryService->getCategories($filter_where);
  120. $subsites = Cache::get('subsites_list');
  121. if ($subsites) {
  122. if (!array_has($params, 'citycategory')) {
  123. if (get_subsite_id() > 0) {
  124. $citycategory = $subsites[get_subsite_id()]['district'];
  125. }
  126. }
  127. }
  128. $title = '晋江市新春招聘会';
  129. $citys = $this->categoryService->getCitys($citycategory);
  130. if (empty($citycategory)) {
  131. $district_str = "(district like ? or district like ?)";
  132. $district_arr = ["%.623%", "%623.%"];
  133. } else {
  134. $select_id = $citys['select']['id'];
  135. $district_str = "(district like ? or district like ?)";
  136. $district_arr = ["%.{$select_id}%", "%{$select_id}.%"];
  137. $title = $citys['select']['name'] . '专区';
  138. }
  139. $companys = DB::table('jobs')->join('companys', 'jobs.company_id', '=', 'companys.id')->whereRaw("jobs.updated_at > '2021-01-01 00:00:00' and jobs.deleted_at is null")->groupBy('jobs.company_id')->select('jobs.company_id')->pluck('company_id')->toArray();
  140. $where = [];
  141. $where[] = ['user_status', '=', 1];
  142. $where[] = ['audit', '=', 1];
  143. $where[] = ['deleted_at', '=', null];
  144. if (!empty($trade)) {
  145. $where[] = ['trade', '=', $trade];
  146. }
  147. $list = DB::table('companys')->where($where)->whereRaw($district_str, $district_arr)->whereIn('id', $companys)->orderBy('sort_index', 'desc')->orderBy('id', 'desc')->offset($limit * $offset)->limit($limit)->get();
  148. $more = count($list) >= $limit ? true : false;
  149. $res = [];
  150. foreach ($list as $val) {
  151. $item = [
  152. 'id' => $val->id,
  153. 'companyname' => $val->companyname,
  154. 'jobs' => [],
  155. 'tag_arr' => [],
  156. ];
  157. //在招职位
  158. $jobs_where = [
  159. ['company_id', '=', $val->id],
  160. ['valid', '=', 1],
  161. ['display', '=', 1],
  162. ['audit', '=', 1],
  163. ['deleted_at', '=', null],
  164. ];
  165. $jobs = DB::table('jobs')->where($jobs_where)->get();
  166. if (!$jobs->isEmpty()) {
  167. foreach ($jobs as $value) {
  168. $job = [
  169. 'id' => $value->id,
  170. 'jobs_name' => $value->jobs_name,
  171. 'amount' => $value->amount,
  172. 'wage' => $value->wage,
  173. 'wage_min' => $value->wage_min,
  174. 'wage_max' => $value->wage_max,
  175. ];
  176. array_push($item['jobs'], $job);
  177. }
  178. }
  179. //企业福利
  180. if (!empty($val->tag)) {
  181. $tags = explode(',', $val->tag);
  182. $tag_arr = DB::table('categorys')->whereIn('id', $tags)->limit(3)->get(['demand'])->toArray();
  183. $item['tag_arr'] = $tag_arr;
  184. }
  185. array_push($res, $item);
  186. }
  187. if ($request->ajax()) {
  188. if (count($res)) {
  189. return response()->json(['status' => 1, 'data' => view('mobile.app.active.ajax.ajax_online2021_special_com', [
  190. 'res' => $res,
  191. 'city' => $citys,
  192. 'params' => $params,
  193. 'categories' => $categories,
  194. 'more' => $more,
  195. ])->render()]);
  196. }
  197. return response()->json(['status' => 0]);
  198. }
  199. return view('mobile.app.active.online2021_special', [
  200. 'title' => $title,
  201. 'res' => $res,
  202. 'city' => $citys,
  203. 'params' => $params,
  204. 'categories' => $categories,
  205. 'more' => $more,
  206. 'share_title' => "【{$title}】免费找工作",
  207. 'share_desc' => '晋江好福利!免费找工作、找人才,还能抽奖,100%中奖,万份好礼免费拿!',
  208. 'share_image_url' => theme_asset('mobile/images/online2021/share_logo.jpg'),
  209. 'share_link' => route('mobile.active.online2021_special') . '?citycategory=' . $citycategory,
  210. ]);
  211. }
  212. /**
  213. * 经开区专区页
  214. */
  215. public function special_jkq(Request $request)
  216. {
  217. $source = $request->input('source', 0);
  218. $type = $request->input('type', 1);
  219. if (!$request->ajax()) {
  220. //是否登录
  221. $user = auth('web-member')->user();
  222. if (empty($user)) {
  223. $open_id = Session::get('open_id');
  224. if (empty($open_id)) {
  225. return redirect(route('mobile.active.online2021_jkq_login', ['type' => $type, 'source' => $source]));
  226. }
  227. } else {
  228. $third = Thirdlogin::where('uid', $user->id)->first();
  229. $open_id = $third['openid'];
  230. }
  231. // $open_id = '11';
  232. //抽奖次数
  233. $date = date('Y-m-d');
  234. $log = LotteryLog::where([
  235. ['create_time', '=', $date],
  236. ['type', '=', $type],
  237. ['open_id', '=', $open_id],
  238. ])->first();
  239. $number = 1;
  240. if (!empty($log)) {
  241. $number = 0;
  242. }
  243. //奖品列表
  244. $prize = LotteryPrize::all();
  245. $ids = [];
  246. $restaraunts = [];
  247. $colors = [];
  248. $images = [];
  249. foreach ($prize as $v) {
  250. $ids[] = $v->id;
  251. $restaraunts[] = $v->prize_name;
  252. $colors[] = $v->prize_bg;
  253. $images[] = upload_asset($v->prize_image);
  254. }
  255. //中奖记录
  256. $win = [];
  257. $user = auth('web-member')->user();
  258. if (!empty($user)) {
  259. $win = LotteryWin::with('prize')->where('member_id', $user->id)->orderBy('status', 'asc')->orderBy('created_at', 'desc')->limit(8)->get();
  260. }
  261. }
  262. $offset = isset($request->page) ? $request->page : 0;
  263. $limit = 8;
  264. $citycategory = 'jjkfq';
  265. $companys = DB::table('jobs')->join('companys', 'jobs.company_id', '=', 'companys.id')->whereRaw("jobs.updated_at > '2021-01-01 00:00:00' and jobs.deleted_at is null")->groupBy('jobs.company_id')->select('jobs.company_id')->pluck('company_id')->toArray();
  266. $citys = $this->categoryService->getCitys($citycategory);
  267. $select_id = $citys['select']['id'];
  268. $district_str = "(district like ? or district like ?)";
  269. $district_arr = ["%.{$select_id}%", "%{$select_id}.%"];
  270. $where = [];
  271. $where[] = ['user_status', '=', 1];
  272. $where[] = ['audit', '=', 1];
  273. $where[] = ['deleted_at', '=', null];
  274. $list = DB::table('companys')->where($where)->whereRaw($district_str, $district_arr)->whereIn('id', $companys)->orderBy('sort_index', 'desc')->orderBy('id', 'desc')->offset($limit * $offset)->limit($limit)->get();
  275. $more = count($list) >= $limit ? true : false;
  276. $res = [];
  277. foreach ($list as $val) {
  278. $item = [
  279. 'id' => $val->id,
  280. 'companyname' => $val->companyname,
  281. 'jobs' => [],
  282. 'tag_arr' => [],
  283. ];
  284. //在招职位
  285. $jobs_where = [
  286. ['company_id', '=', $val->id],
  287. ['valid', '=', 1],
  288. ['display', '=', 1],
  289. ['audit', '=', 1],
  290. ['deleted_at', '=', null],
  291. ];
  292. $jobs = DB::table('jobs')->where($jobs_where)->get();
  293. if (!$jobs->isEmpty()) {
  294. foreach ($jobs as $value) {
  295. $job = [
  296. 'id' => $value->id,
  297. 'jobs_name' => $value->jobs_name,
  298. 'amount' => $value->amount,
  299. 'wage' => $value->wage,
  300. 'wage_min' => $value->wage_min,
  301. 'wage_max' => $value->wage_max,
  302. 'wage_str' => $value->wage_str,
  303. ];
  304. array_push($item['jobs'], $job);
  305. }
  306. }
  307. //企业福利
  308. if (!empty($val->tag)) {
  309. $tags = explode(',', $val->tag);
  310. $tag_arr = DB::table('categorys')->whereIn('id', $tags)->limit(3)->get(['demand'])->toArray();
  311. $item['tag_arr'] = $tag_arr;
  312. }
  313. array_push($res, $item);
  314. }
  315. if ($request->ajax()) {
  316. if (count($res)) {
  317. return response()->json(['status' => 1, 'data' => view('mobile.app.active.ajax.ajax_online2021_special_com', [
  318. 'res' => $res,
  319. 'more' => $more,
  320. ])->render()]);
  321. }
  322. return response()->json(['status' => 0]);
  323. }
  324. return view('mobile.app.active.online2021_special_jkq', [
  325. 'source' => $source,
  326. 'params' => ['citycategory' => 'jjkfq'],
  327. 'open_id' => $open_id,
  328. 'current_url' => \Illuminate\Support\Facades\Request::getRequestUri(),
  329. 'user' => $user,
  330. 'number' => $number,
  331. 'type' => $type,
  332. 'prize' => $prize,
  333. 'win' => $win,
  334. 'ids' => $ids,
  335. 'restaraunts' => $restaraunts,
  336. 'colors' => $colors,
  337. 'images' => $images,
  338. 'res' => $res,
  339. 'more' => $more,
  340. 'share_title' => '【福利通知】免费找工作,抽大奖拿好礼',
  341. 'share_desc' => '晋江好福利!免费找工作、找人才,还能抽奖,100%中奖,万份好礼免费拿!',
  342. 'share_image_url' => theme_asset('mobile/images/online2021/share_logo.jpg'),
  343. 'live_list' => $this->homeService->getOnline2021Live(),
  344. ]);
  345. }
  346. /**
  347. * 微信登录
  348. */
  349. public function jkq_login(Request $request)
  350. {
  351. //type:web-电脑端,mobile-手机端,
  352. $app_id = subsite_config('aix.system.oauth.wechat_official.app_id');
  353. $redirect_uri = urlencode(route('mobile.active.online2021_jkq_wechat_back'));
  354. $type = $request->input('type', 1);
  355. $source = $request->input('source', 0);
  356. $wechat_url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid={$app_id}&redirect_uri={$redirect_uri}&response_type=code&scope=snsapi_userinfo&state={$type}_{$source}#wechat_redirect";
  357. return redirect($wechat_url);
  358. }
  359. /**
  360. * 微信回调
  361. */
  362. public function jkq_wechat_back(Request $request)
  363. {
  364. //微信登录
  365. $officialAccount = $this->wechatService->getOfficialAccount();
  366. $wechatUser = $officialAccount->oauth->user()->getOriginal();
  367. $thirdlogin = Thirdlogin::where('openid', $wechatUser['openid'])->first();
  368. if (!$thirdlogin && $wechatUser['unionid']) {
  369. $thirdlogin = Thirdlogin::where('unionid', $wechatUser['unionid'])->first();
  370. }
  371. if ($thirdlogin) {
  372. $member = $thirdlogin->member()->withTrashed()->first();
  373. $this->authService->login($member, 1);
  374. } else {
  375. Session::put('open_id', $wechatUser['openid']);
  376. Session::put('union_id', $wechatUser['unionid'] ?: '');
  377. Session::save();
  378. }
  379. $state = $request->input('state', '');
  380. $state = explode('_', $state);
  381. $url = route('mobile.active.online2021_special_jkq', ['type' => $state[0], 'source' => $state[1]]);
  382. return redirect($url);
  383. }
  384. /**
  385. * 直播专用页
  386. */
  387. public function special_live(Request $request)
  388. {
  389. if (!$request->ajax()) {
  390. //奖品列表
  391. $prize = LotteryPrize::all();
  392. }
  393. $offset = isset($request->page) ? $request->page : 0;
  394. $limit = 8;
  395. $citycategory = 'jjkfq';
  396. $companys = DB::table('jobs')->join('companys', 'jobs.company_id', '=', 'companys.id')->whereRaw("jobs.updated_at > '2021-01-01 00:00:00' and jobs.deleted_at is null")->groupBy('jobs.company_id')->select('jobs.company_id')->pluck('company_id')->toArray();
  397. $citys = $this->categoryService->getCitys($citycategory);
  398. $select_id = $citys['select']['id'];
  399. $district_str = "(district like ? or district like ?)";
  400. $district_arr = ["%.{$select_id}%", "%{$select_id}.%"];
  401. $where = [];
  402. $where[] = ['user_status', '=', 1];
  403. $where[] = ['audit', '=', 1];
  404. $where[] = ['deleted_at', '=', null];
  405. $list = DB::table('companys')->where($where)->whereRaw($district_str, $district_arr)->whereIn('id', $companys)->orderBy('sort_index', 'desc')->orderBy('id', 'desc')->offset($limit * $offset)->limit($limit)->get();
  406. $more = count($list) >= $limit ? true : false;
  407. $res = [];
  408. foreach ($list as $val) {
  409. $item = [
  410. 'id' => $val->id,
  411. 'companyname' => $val->companyname,
  412. 'jobs' => [],
  413. 'tag_arr' => [],
  414. ];
  415. //在招职位
  416. $jobs_where = [
  417. ['company_id', '=', $val->id],
  418. ['valid', '=', 1],
  419. ['display', '=', 1],
  420. ['audit', '=', 1],
  421. ['deleted_at', '=', null],
  422. ];
  423. $jobs = DB::table('jobs')->where($jobs_where)->get();
  424. if (!$jobs->isEmpty()) {
  425. foreach ($jobs as $value) {
  426. $job = [
  427. 'id' => $value->id,
  428. 'jobs_name' => $value->jobs_name,
  429. 'amount' => $value->amount,
  430. 'wage' => $value->wage,
  431. 'wage_min' => $value->wage_min,
  432. 'wage_max' => $value->wage_max,
  433. 'wage_str' => $value->wage_str,
  434. ];
  435. array_push($item['jobs'], $job);
  436. }
  437. }
  438. //企业福利
  439. if (!empty($val->tag)) {
  440. $tags = explode(',', $val->tag);
  441. $tag_arr = DB::table('categorys')->whereIn('id', $tags)->limit(3)->get(['demand'])->toArray();
  442. $item['tag_arr'] = $tag_arr;
  443. }
  444. array_push($res, $item);
  445. }
  446. if ($request->ajax()) {
  447. if (count($res)) {
  448. return response()->json(['status' => 1, 'data' => view('mobile.app.active.ajax.ajax_online2021_special_com', [
  449. 'res' => $res,
  450. 'more' => $more,
  451. ])->render()]);
  452. }
  453. return response()->json(['status' => 0]);
  454. }
  455. return view('mobile.app.active.online2021_special_live', [
  456. 'params' => ['citycategory' => 'jjkfq'],
  457. 'current_url' => \Illuminate\Support\Facades\Request::getRequestUri(),
  458. 'res' => $res,
  459. 'more' => $more,
  460. 'prize' => $prize,
  461. 'share_title' => '【福利通知】免费找工作,抽大奖拿好礼',
  462. 'share_desc' => '晋江好福利!免费找工作、找人才,还能抽奖,100%中奖,万份好礼免费拿!',
  463. 'share_image_url' => theme_asset('mobile/images/online2021/share_logo.jpg'),
  464. 'live_list' => $this->homeService->getOnline2021Live(),
  465. ]);
  466. }
  467. }