PartnerController.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use App\Exceptions\AlertException;
  4. use App\Http\Controllers\Core\Auth;
  5. use App\Models\Appearance\AppearanceModel;
  6. use App\Models\CheckLog;
  7. use App\Models\PartnerModel;
  8. use App\Http\Controllers\Controller;
  9. use App\Models\User\FeedcheckLogModel;
  10. use App\Services\Appearance\RankService;
  11. use App\Services\User\PartnerService;
  12. use Illuminate\Database\Query\Builder;
  13. use Illuminate\Database\QueryException;
  14. use Illuminate\Http\Request;
  15. use Illuminate\Support\Facades\DB;
  16. use Illuminate\Support\Facades\Redis;
  17. /**
  18. * Class PartnerController
  19. * @package App\Http\Controllers\Admin
  20. */
  21. class PartnerController extends Controller
  22. {
  23. /**
  24. * 通过qq或微信搜索某条卡片
  25. * @param Request $request
  26. * @return array
  27. */
  28. public function search(Request $request)
  29. {
  30. $this->validate($request, [
  31. 'content' => 'required',
  32. ]);
  33. $content = $request->input('content');
  34. if (is_int(strpos($content, 'uid'))) {
  35. $uid = substr($content, 4);
  36. $where = ['uid' => $uid];
  37. } elseif (is_int(strpos($content, 'qq'))) {
  38. $qq = substr($content, 3);
  39. $where = ['qq' => $qq];
  40. } elseif (is_int(strpos($content, 'weixin'))) {
  41. $weixin = substr($content, 7);
  42. $where = ['weixin' => $weixin];
  43. } elseif (is_int(strpos($content, 'cid'))) {
  44. $partner_id = substr($content, 4);
  45. $where = ['id' => $partner_id];
  46. } else {
  47. return response([
  48. 'code' => 422,
  49. 'message' => '搜索格式:uid=xxx,qq=xx,weixin=xxx,cid=xxx'
  50. ]);
  51. }
  52. $partners = PartnerModel::where($where)->limit(10)->get();
  53. return array(
  54. 'code' => 200,
  55. 'message' => 'success',
  56. 'data' => $partners
  57. );
  58. }
  59. /**
  60. * 添加审核日志
  61. * @param int $partner_id
  62. * @param Request $request
  63. * @return array
  64. */
  65. public function addCheckLog(int $partner_id, Request $request)
  66. {
  67. $data = array(
  68. 'partner_id' => $partner_id,
  69. 'log' => json_encode($request->toArray())
  70. );
  71. $clog = new CheckLog();
  72. $clog->fill($data)->save();
  73. return array(
  74. 'code' => 200,
  75. 'message' => 'success'
  76. );
  77. }
  78. /**
  79. * 审核卡片
  80. * @param int $partner_id
  81. * @param Request $request
  82. * @return array
  83. * @throws \Exception
  84. */
  85. public function checkPartner(int $partner_id, Request $request)
  86. {
  87. $this->validate($request, [
  88. 'field' => 'required',
  89. 'check' => 'required'
  90. ]);
  91. $field = $request->input('field');
  92. $check = $request->input('check', -1);
  93. $ps = new PartnerService();
  94. $ps->check($partner_id, $field, $check);
  95. return array(
  96. 'code' => 200,
  97. 'message' => 'success'
  98. );
  99. }
  100. /**
  101. * 切换是否推送到信息流
  102. * @param int $partner_id
  103. * @return array
  104. */
  105. public function pushFeed(int $partner_id)
  106. {
  107. $partner = PartnerModel::findOrFail($partner_id);
  108. $partner->is_push_feed = abs($partner->is_push_feed - 1);
  109. $partner->save();
  110. return array(
  111. 'code' => 200,
  112. 'message' => 'success'
  113. );
  114. }
  115. /**
  116. * 上/下榜卡片
  117. * @param int $partner_id
  118. * @param Request $request
  119. * @return array
  120. * @throws AlertException
  121. */
  122. public function xhxcrank(int $partner_id, Request $request)
  123. {
  124. $this->validate($request, [
  125. 'xhxc_rank_state' => 'required|in:-1,1,2'
  126. ]);
  127. $partner = PartnerModel::findOrFail($partner_id);
  128. $xhxc_rank_state = $request->post('xhxc_rank_state');
  129. $appearance = AppearanceModel::where('partner_id', $partner_id)->first();
  130. if (!collect($appearance)->isEmpty()) {
  131. if (2 == $xhxc_rank_state) {
  132. // 上榜
  133. if (!(new RankService())->passive($partner->uid)) {
  134. throw new AlertException("不符合上榜条件", 101);
  135. }
  136. } else {
  137. $appearance->state = $xhxc_rank_state;
  138. $appearance->save();
  139. }
  140. } elseif (2 == $xhxc_rank_state) {
  141. // 上榜
  142. if (!(new RankService())->passive($partner->uid)) {
  143. throw new AlertException("不符合上榜条件", 101);
  144. }
  145. }
  146. return array(
  147. 'code' => 200,
  148. 'message' => 'success'
  149. );
  150. }
  151. /**
  152. * 获取审核列表
  153. * @param Request $request
  154. * @return array
  155. */
  156. public function checkList(Request $request)
  157. {
  158. // 页数
  159. $page = $request->get('page', 1);
  160. // 是否是72h活动的
  161. $is_fpdx = $request->post('fpdx', null);
  162. if (!is_null($is_fpdx)) {
  163. $where[] = ['is_fpdx', $is_fpdx];
  164. }
  165. // 性别
  166. $sex = $request->post('sex', null);
  167. if (!is_null($sex)) {
  168. $where[] = ['sex', $sex];
  169. }
  170. // 是否精选
  171. $is_recommend = $request->post('is_recommend', null);
  172. if (!is_null($is_recommend)) {
  173. $where[] = ['is_select', $is_recommend];
  174. }
  175. // 是否需要审核
  176. $is_commit_check = $request->post('is_commit_check', null);
  177. if (!is_null($is_commit_check)) {
  178. $where[] = ['is_commit_check', $is_commit_check];
  179. }
  180. // 是否上架
  181. $is_sell = $request->post('is_sell', null);
  182. if (!is_null($is_sell)) {
  183. $where[] = ['is_sell', $is_sell];
  184. }
  185. // 是否推荐到信息流
  186. $is_push_feed = $request->post('is_push_feed', null);
  187. if (!is_null($is_push_feed)) {
  188. $where[] = ['is_push_feed', $is_push_feed];
  189. }
  190. // 是否有照片
  191. $is_photo = $request->post('photo', 0);
  192. // 是否关注公众号
  193. $is_subscribe = $request->post('is_subscribe', 0);
  194. // 在校花校草榜的状态
  195. $xhxc_rank_state = $request->post('xhxc_rank_state', null);
  196. if (!is_null($xhxc_rank_state)) {
  197. // 获取上榜的卡片集合
  198. $xhxcrank = AppearanceModel::where(
  199. 'state',
  200. $xhxc_rank_state
  201. )->get(['partner_id'])->pluck('partner_id')->toArray();
  202. } else {
  203. $xhxcrank = array();
  204. }
  205. $where[] = ['is_hide', 0];
  206. $orderby = 'update_at';
  207. if (1 == $is_sell) {
  208. $orderby = "upload_at";
  209. }
  210. if ($is_subscribe) {
  211. $where[] = ['openid.subscribe', 1];
  212. $where[] = ['openid.public_id', 'gh_b598cb7474d8'];
  213. if (in_array($sex, [1, 2])) {
  214. $where[] = ['partner.sex', $sex];
  215. }
  216. $partners = DB::table('kdgx_partner_charge_partner as partner')
  217. ->join('kddx_user_openid as openid', 'partner.uid', 'openid.uid')
  218. ->where($where)->when($is_photo, function (/** @var Builder $query */ $query) use ($is_photo) {
  219. if (1 == $is_photo) {
  220. return $query->where(function (/** @var Builder $query */ $query) {
  221. $query->where('check_photo', 1)->orWhere('voice_check', 1)->orWhere('photo_1_check', 1)
  222. ->orWhere('photo_2_check', 1)->orWhere('photo_3_check', 1)->orWhere('photo_4_check', 1);
  223. });
  224. }
  225. })->when(!is_null($xhxc_rank_state), function (/** @var Builder $query */ $query) use ($xhxcrank) {
  226. return $query->whereIn('p.id', $xhxcrank);
  227. })->orderBy(
  228. "partner.{$orderby}",
  229. 'desc'
  230. )->skip(($page - 1) * 100)->take(100)->select('partner.*')->get();
  231. $count = DB::table('kdgx_partner_charge_partner as partner')
  232. ->join('kddx_user_openid as openid', 'partner.uid', 'openid.uid')
  233. ->where($where)->when($is_photo, function (/** @var Builder $query */ $query) use ($is_photo) {
  234. if (1 == $is_photo) {
  235. return $query->where(function (/** @var Builder $query */ $query) {
  236. $query->where('check_photo', 1)->orWhere('voice_check', 1)->orWhere('photo_1_check', 1)
  237. ->orWhere('photo_2_check', 1)->orWhere('photo_3_check', 1)->orWhere('photo_4_check', 1);
  238. });
  239. }
  240. })->count();
  241. } else {
  242. if (in_array($sex, [1, 2])) {
  243. $where[] = ['sex', $sex];
  244. }
  245. /** @var PartnerModel $partners */
  246. $partners = PartnerModel::where($where)->when(
  247. $is_photo,
  248. function (/** @var Builder $query */ $query) use ($is_photo) {
  249. if (1 == $is_photo) {
  250. return $query->where(function (/** @var Builder $query */ $query) {
  251. $query->where('check_photo', 1)->orWhere('voice_check', 1)->orWhere('photo_1_check', 1)
  252. ->orWhere('photo_2_check', 1)->orWhere('photo_3_check', 1)->orWhere('photo_4_check', 1);
  253. });
  254. }
  255. }
  256. )->when(!is_null($xhxc_rank_state), function (/** @var Builder $query */ $query) use ($xhxcrank) {
  257. return $query->whereIn('id', $xhxcrank);
  258. })->orderBy($orderby, 'desc')->skip(($page - 1) * 100)->take(100)->get();
  259. $count = PartnerModel::where($where)->when(
  260. $is_photo,
  261. function (/** @var Builder $query */ $query) use ($is_photo) {
  262. if (1 == $is_photo) {
  263. return $query->where(function (/** @var Builder $query */ $query) {
  264. $query->where('check_photo', 1)->orWhere('voice_check', 1)->orWhere('photo_1_check', 1)
  265. ->orWhere('photo_2_check', 1)->orWhere('photo_3_check', 1)->orWhere('photo_4_check', 1);
  266. });
  267. }
  268. }
  269. )->count();
  270. }
  271. $xhxcranks = AppearanceModel::whereIn('partner_id', $partners->pluck('id')->toArray())->get()->toArray();
  272. $xhxcranks = array_combine(array_column($xhxcranks, "partner_id"), $xhxcranks);
  273. foreach ($partners as &$partner) {
  274. /** @var PartnerModel $partner */
  275. if (isset($xhxcranks[$partner->id])) {
  276. $partner->xhxc_rank_state = $xhxcranks[$partner->id]['state'];
  277. } else {
  278. $partner->xhxc_rank_state = 1;
  279. }
  280. if (!empty($partner->photo_src)) {
  281. $partner->photo_src = "https://oss.pocketuniversity.cn{$partner->photo_src}";
  282. }
  283. if (!empty($partner->photo_1)) {
  284. $partner->photo_1 = "https://oss.pocketuniversity.cn{$partner->photo_1}";
  285. }
  286. if (!empty($partner->photo_2)) {
  287. $partner->photo_2 = "https://oss.pocketuniversity.cn{$partner->photo_2}";
  288. }
  289. if (!empty($partner->photo_3)) {
  290. $partner->photo_3 = "https://oss.pocketuniversity.cn{$partner->photo_3}";
  291. }
  292. if (!empty($partner->photo_4)) {
  293. $partner->photo_4 = "https://oss.pocketuniversity.cn{$partner->photo_4}";
  294. }
  295. $partner->is_recommend = $partner->is_select;
  296. $partner->sell_count = 1;
  297. }
  298. return array(
  299. 'code' => 200,
  300. 'message' => 'success',
  301. 'data' => [
  302. 'page' => $page,
  303. 'limit' => 100,
  304. 'total' => $count,
  305. 'list' => $partners
  306. ],
  307. );
  308. }
  309. /**
  310. * 「list」活动审核卡片
  311. * @param Request $request
  312. * @return array
  313. */
  314. public function feedcheckList(Request $request)
  315. {
  316. $where = array(
  317. ['feedcheck_cnt', '<', 5],
  318. ['is_sell', 1],
  319. ['is_recommend', 0],
  320. ['feed_push_type', 3],
  321. ['login_at', '>', time() - 90 * 86400]
  322. );
  323. // 性别
  324. $sex = $request->post('sex', null);
  325. if (!is_null($sex)) {
  326. $where[] = ['sex', $sex];
  327. }
  328. // 时间排序
  329. $request->post('sort', 'desc');
  330. $uid = Auth::auth();
  331. $seeIds = Redis::zrange("feedcheck:{$uid}", 0, -1);
  332. Redis::expire("feedcheck:{$uid}", 7200);
  333. if (empty($seeIds)) {
  334. $seeIds = array();
  335. }
  336. array_walk($seeIds, function (&$value) {
  337. $value = intval($value);
  338. });
  339. $partnerIds = FeedcheckLogModel::where([
  340. ['uid', $uid],
  341. ['expire_at', 0]
  342. ])->get(['partner_id'])->pluck('partner_id')->toArray();
  343. $partnerIds = array_merge($partnerIds, $seeIds);
  344. /** @var PartnerModel[] $partners */
  345. $partners = PartnerModel::where($where)->whereNotIn('id', $partnerIds)->take(10)->orderBy(
  346. 'feedcheck_cnt',
  347. 'asc'
  348. )->get();
  349. foreach ($partners as &$partner) {
  350. Redis::zadd("feedcheck:{$uid}", [$partner->id => time()]);
  351. if (!empty($partner->photo_src)) {
  352. $partner->photo_src = "https://oss.pocketuniversity.cn{$partner->photo_src}";
  353. }
  354. if (!empty($partner->photo_1)) {
  355. $partner->photo_1 = "https://oss.pocketuniversity.cn{$partner->photo_1}";
  356. }
  357. if (!empty($partner->photo_2)) {
  358. $partner->photo_2 = "https://oss.pocketuniversity.cn{$partner->photo_2}";
  359. }
  360. if (!empty($partner->photo_3)) {
  361. $partner->photo_3 = "https://oss.pocketuniversity.cn{$partner->photo_3}";
  362. }
  363. if (!empty($partner->photo_4)) {
  364. $partner->photo_4 = "https://oss.pocketuniversity.cn{$partner->photo_4}";
  365. }
  366. if (1 != $partner->check_photo) {
  367. unset($partner->photo_src);
  368. }
  369. if (1 != $partner->photo_1_check) {
  370. unset($partner->photo_1);
  371. }
  372. if (1 != $partner->photo_2_check) {
  373. unset($partner->photo_2);
  374. }
  375. if (1 != $partner->photo_3_check) {
  376. unset($partner->photo_3);
  377. }
  378. if (1 != $partner->photo_4_check) {
  379. unset($partner->photo_4);
  380. }
  381. if (1 != $partner->voice_check) {
  382. unset($partner->voice);
  383. }
  384. unset($partner->check_photo);
  385. unset($partner->photo_1_check);
  386. unset($partner->photo_2_check);
  387. unset($partner->photo_3_check);
  388. unset($partner->photo_4_check);
  389. unset($partner->voice_check);
  390. }
  391. return array(
  392. 'code' => 200,
  393. 'message' => 'success',
  394. 'data' => $partners
  395. );
  396. }
  397. /**
  398. * 通过|不通过某卡片
  399. * @param int $partner_id
  400. * @param Request $request
  401. * @return array
  402. * @throws AlertException
  403. */
  404. public function passPartner(int $partner_id, Request $request)
  405. {
  406. $ispass = $request->post('is_pass', 0);
  407. $uid = Auth::auth();
  408. $partner = PartnerModel::findOrFail($partner_id);
  409. if (FeedcheckLogModel::where([['uid', $uid], ['partner_id', $partner_id], ['expire_at', 0]])->exists()) {
  410. return response([
  411. 'code' => 200,
  412. 'message' => 'success'
  413. ]);
  414. }
  415. try {
  416. if (5 <= FeedcheckLogModel::where([['partner_id', $partner_id], ['expire_at', 0]])->count()) {
  417. return response([
  418. 'code' => 200,
  419. 'message' => 'success'
  420. ]);
  421. }
  422. FeedcheckLogModel::create([
  423. 'uid' => $uid,
  424. 'partner_id' => $partner_id,
  425. 'is_pass' => $ispass,
  426. 'created_at' => time(),
  427. 'expire_at' => 0
  428. ]);
  429. $partner->increment('feedcheck_cnt', 1);
  430. if (0 == $ispass) {
  431. $cnt = FeedcheckLogModel::where([
  432. ['partner_id', $partner_id],
  433. ['is_pass', 0],
  434. ['expire_at', 0]
  435. ])->count();
  436. if (3 <= $cnt || 1 == $partner->feedcheck_cnt) {
  437. $partner->is_push_feed = 0;
  438. // 取消推荐通知
  439. try {
  440. $notice = new \App\Services\Partner\NoticeService();
  441. $notice->recommendCancel($partner->uid);
  442. } catch (\Exception $e) {
  443. app('sentry')->captureException($e);
  444. }
  445. }
  446. $partner->save();
  447. } else {
  448. $cnt = FeedcheckLogModel::where([
  449. ['partner_id', $partner_id],
  450. ['is_pass', 1],
  451. ['expire_at', 0]
  452. ])->count();
  453. 3 <= $cnt && $partner->is_push_feed = 1;
  454. $cnt >= 5 && $partner->is_recommend = 1;
  455. $partner->save();
  456. }
  457. } catch (QueryException $e) {
  458. throw new AlertException("划得来太快了哦");
  459. }
  460. return response([
  461. 'code' => 200,
  462. 'message' => 'success'
  463. ]);
  464. }
  465. /**
  466. * 审核排行榜
  467. * @param Request $request
  468. * @return array
  469. */
  470. public function passRank(Request $request)
  471. {
  472. $rank_type = $request->get('ranktype', 'day');
  473. switch ($rank_type) {
  474. case "yesterday":
  475. $begin_at = mktime(0, 0, 0) - 86400;
  476. $end_at = mktime(0, 0, 0);
  477. break;
  478. case "day":
  479. $date = $request->get('date', date('Y-m-d'));
  480. $begin_at = strtotime($date);
  481. $end_at = $begin_at + 86400 - 1;
  482. break;
  483. case "week":
  484. default:
  485. $date = $request->get(
  486. "date",
  487. date('Y-m-d', (time() - ((date('w') == 0 ? 7 : date('w')) - 1) * 24 * 3600))
  488. );
  489. $begin_at = strtotime($date);
  490. $end_at = $begin_at + 7 * 86400 - 1;
  491. break;
  492. }
  493. $ranks = FeedcheckLogModel::select(DB::raw("uid, count(*) as count"))
  494. ->whereBetween('created_at', [$begin_at, $end_at])
  495. ->groupBy('uid')
  496. ->get();
  497. foreach ($ranks as $rank) {
  498. $passCnt = FeedcheckLogModel::whereBetween('created_at', [$begin_at, $end_at])->where([
  499. ['uid', $rank->uid],
  500. ['is_pass', 1]
  501. ])->count();
  502. $rank->pass_count = $passCnt;
  503. $rank->pass = sprintf('%.2f', ($passCnt / $rank->count * 100));
  504. $rank->user = \DB::table('ta_users')->select('uid', 'name', 'headimgurl')->where(
  505. 'uid',
  506. $rank->uid
  507. )->first();
  508. }
  509. $ranks = $ranks->sortByDesc(function ($rank) {
  510. return $rank->count;
  511. })->values()->all();
  512. return response([
  513. "code" => 200,
  514. "message" => "success",
  515. "data" => $ranks
  516. ]);
  517. }
  518. public function unpushList(Request $request)
  519. {
  520. $page = $request->get('page', 1);
  521. $count = PartnerModel::where(array(['is_push_feed', 0], ['is_sell', 1], ['feed_push_type', 3]))->count();
  522. $datas = PartnerModel::where(array(['is_push_feed', 0], ['is_sell', 1], ['feed_push_type', 3]))
  523. ->skip(($page - 1) * 100)->take(100)->get([
  524. 'id',
  525. 'photo_src',
  526. 'check_photo',
  527. 'photo_1',
  528. 'photo_1_check',
  529. 'photo_2',
  530. 'photo_2_check',
  531. 'photo_3',
  532. 'photo_3_check',
  533. 'photo_4',
  534. 'photo_4_check',
  535. ]);
  536. $datas->map(function (&$data) {
  537. /** @var PartnerModel $data */
  538. if (1 != $data->check_photo) {
  539. unset($data->photo_src);
  540. }
  541. if (1 != $data->photo_1_check) {
  542. unset($data->photo_1);
  543. }
  544. if (1 != $data->photo_2_check) {
  545. unset($data->photo_2);
  546. }
  547. if (1 != $data->photo_3_check) {
  548. unset($data->photo_3);
  549. }
  550. if (1 != $data->photo_4_check) {
  551. unset($data->photo_4);
  552. }
  553. unset($data->check_photo);
  554. unset($data->photo_1_check);
  555. unset($data->photo_2_check);
  556. unset($data->photo_3_check);
  557. unset($data->photo_4_check);
  558. if (
  559. !isset($data->photo_src)
  560. && !isset($data->photo_1)
  561. && !isset($data->photo_2)
  562. && !isset($data->photo_3)
  563. && !isset($data->photo_4)
  564. ) {
  565. PartnerModel::where('id', $data->id)->update(['feed_push_type' => 5]);
  566. unset($data);
  567. }
  568. });
  569. return array(
  570. 'code' => 200,
  571. 'message' => 'success',
  572. 'data' => [
  573. 'page' => $page,
  574. 'limit' => 100,
  575. 'total' => $count,
  576. 'list' => $datas
  577. ],
  578. );
  579. }
  580. public function push(int $partner_id)
  581. {
  582. PartnerModel::where('id', $partner_id)->update(['is_push_feed' => 1]);
  583. return array(
  584. 'code' => 200,
  585. 'message' => 'success'
  586. );
  587. }
  588. /**
  589. * 某人卡片列表
  590. * @param Request $request
  591. * @return array
  592. */
  593. public function userList(Request $request)
  594. {
  595. $uid = $request->get('uid');
  596. $partners = PartnerModel::where('uid', $uid)->get();
  597. foreach ($partners as &$partner) {
  598. if (!empty($partner->photo_src)) {
  599. $partner->photo_src = "https://oss.pocketuniversity.cn{$partner->photo_src}";
  600. }
  601. if (!empty($partner->photo_1)) {
  602. $partner->photo_1 = "https://oss.pocketuniversity.cn{$partner->photo_1}";
  603. }
  604. if (!empty($partner->photo_2)) {
  605. $partner->photo_2 = "https://oss.pocketuniversity.cn{$partner->photo_2}";
  606. }
  607. if (!empty($partner->photo_3)) {
  608. $partner->photo_3 = "https://oss.pocketuniversity.cn{$partner->photo_3}";
  609. }
  610. if (!empty($partner->photo_4)) {
  611. $partner->photo_4 = "https://oss.pocketuniversity.cn{$partner->photo_4}";
  612. }
  613. }
  614. return array(
  615. 'code' => 200,
  616. 'message' => 'success',
  617. 'data' => $partners,
  618. );
  619. }
  620. /**
  621. * 推荐/取消 卡片
  622. * @param int $partner_id
  623. * @return array
  624. */
  625. public function commitPartner(int $partner_id)
  626. {
  627. /** @var PartnerModel $partner */
  628. $partner = PartnerModel::findOrFail($partner_id);
  629. $partner->is_select = abs($partner->is_select - 1);
  630. $partner->wait_select = 2;
  631. $partner->save();
  632. return array(
  633. 'code' => 200,
  634. 'message' => 'success'
  635. );
  636. }
  637. /**
  638. * 推荐/取消 语音
  639. * @param int $partner_id
  640. * @return array
  641. */
  642. public function commitVoice(int $partner_id)
  643. {
  644. $partner = PartnerModel::findOrFail($partner_id);
  645. $partner->is_voice_recommend = abs($partner->is_voice_recommend - 1);
  646. $partner->save();
  647. return array(
  648. 'code' => 200,
  649. 'message' => 'success'
  650. );
  651. }
  652. public function selects(Request $request)
  653. {
  654. $selects = $request->post();
  655. foreach ($selects as $select) {
  656. PartnerModel::where([
  657. ['id', $select['partner_id']],
  658. ['wait_select', 1]
  659. ])->update([
  660. 'select_at' => time(),
  661. 'is_select' => $select['select'],
  662. 'wait_select' => 2
  663. ]);
  664. }
  665. return array(
  666. 'code' => 200,
  667. 'message' => 'success'
  668. );
  669. }
  670. public function waitSelects(Request $request)
  671. {
  672. $limit = 20;
  673. $page = $request->get('page', 1);
  674. if (1 == $page) {
  675. $total = PartnerModel::where([
  676. ['is_sell', 1],
  677. ['wait_select', 1]
  678. ])->where(function (/** @var \Illuminate\Database\Eloquent\Builder $query */ $query) {
  679. return $query->where('check_photo', 1)->orWhere('photo_1_check', 1)
  680. ->orWhere('photo_2_check', 1)->orWhere('photo_3_check', 1)
  681. ->orWhere('photo_4_check', 1);
  682. })->count();
  683. } else {
  684. $total = 10000;
  685. }
  686. $datas = PartnerModel::where([
  687. ['is_sell', 1],
  688. ['wait_select', 1]
  689. ])->where(function (/** @var \Illuminate\Database\Eloquent\Builder $query */ $query) {
  690. return $query->where('check_photo', 1)
  691. ->orWhere('photo_1_check', 1)
  692. ->orWhere('photo_2_check', 1)
  693. ->orWhere('photo_3_check', 1)
  694. ->orWhere('photo_4_check', 1);
  695. })->skip(($page - 1) * $limit)
  696. ->take($limit)
  697. ->get();
  698. foreach ($datas as &$data) {
  699. /** @var PartnerModel $data */
  700. if ($data->check_photo == 1) {
  701. $data->photo_src = "http://oss.pocketuniversity.cn{$data->photo_src}";
  702. } else {
  703. unset($data->photo_src);
  704. }
  705. if ($data->photo_1_check == 1) {
  706. $data->photo_1 = "http://oss.pocketuniversity.cn{$data->photo_1}";
  707. } else {
  708. unset($data->photo_1);
  709. }
  710. if ($data->photo_2_check == 1) {
  711. $data->photo_2 = "http://oss.pocketuniversity.cn{$data->photo_2}";
  712. } else {
  713. unset($data->photo_2);
  714. }
  715. if ($data->photo_3_check == 1) {
  716. $data->photo_3 = "http://oss.pocketuniversity.cn{$data->photo_3}";
  717. } else {
  718. unset($data->photo_3);
  719. }
  720. if ($data->photo_4_check == 1) {
  721. $data->photo_4 = "http://oss.pocketuniversity.cn{$data->photo_4}";
  722. } else {
  723. unset($data->photo_4);
  724. }
  725. }
  726. return array(
  727. 'code' => 200,
  728. 'message' => 'success',
  729. 'data' => [
  730. 'page' => [
  731. 'page' => (int)$page,
  732. 'limit' => $limit,
  733. 'total' => $total
  734. ],
  735. 'partners' => $datas
  736. ]
  737. );
  738. }
  739. public function getBeautyList(Request $request)
  740. {
  741. $page = $request->get('page', 1);
  742. $limit = $request->get('limit', 10);
  743. $sex = $request->get('sex', 1);
  744. $photos = \DB::table('partner_beautys')
  745. ->where('new_photo', '!=', '')
  746. ->where('sex', $sex)
  747. ->offset(($page - 1) * $limit)
  748. ->limit($limit)
  749. ->get();
  750. return response([
  751. 'code' => 200,
  752. 'message' => 'OK',
  753. 'data' => $photos
  754. ]);
  755. }
  756. }