UserController.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852
  1. <?php
  2. namespace App\Http\Controllers\Wap\User;
  3. use App\Libs\AliSMS;
  4. use App\Modules\Book\Services\BookConfigService;
  5. use App\Modules\Book\Services\BookUrgeUpdateService;
  6. use App\Modules\Book\Services\SignBookService;
  7. use App\Modules\Statistic\Services\AdVisitStatService;
  8. use App\Modules\Subscribe\Services\OrderService;
  9. use App\Modules\User\Services\ForceGuidePersonAccountService;
  10. use App\Modules\User\Services\ReadRecordService;
  11. use App\Modules\User\Services\UserBindHkWelfareService;
  12. use App\Modules\User\Services\UserBindPhoneService;
  13. use App\Modules\User\Services\UserDivisionCpcPropertyService;
  14. use App\Modules\User\Services\UserWealthyOperateRecordService;
  15. use App\Modules\User\Services\WapReaderPageFissionService;
  16. use Illuminate\Http\Request;
  17. use App\Http\Controllers\Wap\BaseController;
  18. use App\Modules\Subscribe\Services\YearOrderService;
  19. use App\Modules\User\Services\UserService;
  20. use App\Modules\User\Services\UserRandSignService;
  21. use App\Modules\User\Services\UserSignService;
  22. use App\Http\Controllers\Wap\User\Transformers\SignRecordTransformer;
  23. use Log;
  24. use Redis;
  25. use Cookie;
  26. use DB;
  27. use Hashids;
  28. class UserController extends BaseController
  29. {
  30. /**
  31. * @apiDefine User 用户
  32. */
  33. /**
  34. * @apiVersion 1.0.0
  35. * @apiDescription 获取用户信息
  36. * @api {GET} userinfo 获取用户信息
  37. * @apiGroup User
  38. * @apiName index
  39. * @apiSuccess {Number} id 用户ID.
  40. * @apiSuccess {String} openid 微信openid.
  41. * @apiSuccess {String} unionid 微信unionid.
  42. * @apiSuccess {Number} distribution_channel_id 分销渠道ID.
  43. * @apiSuccess {String} province 省份.
  44. * @apiSuccess {String} city 城市.
  45. * @apiSuccess {String} country 国家.
  46. * @apiSuccess {String} headimgurl 头像地址.
  47. * @apiSuccess {Number} send_order_id 派单ID.
  48. * @apiSuccess {Number=0,1} sex 性别.
  49. * @apiSuccess {String} balance 书币余额.
  50. * @apiSuccess {Int} is_vip 是否vip
  51. * @apiSuccess {String} vip_days 364天.
  52. * @apiSuccessExample {json} Success-Response:
  53. *
  54. * {
  55. * "code": 0,
  56. * "msg": "",
  57. * "data": {
  58. * "id": 56,
  59. * "openid": "sdfs34ssdfdsf",
  60. * "unionid": "SDFSD3343S",
  61. * "distribution_channel_id": 1212,
  62. * "province": "浙江省",
  63. * "city": "杭州",
  64. * "country": "中国",
  65. * "headimgurl": "http://.."
  66. * "send_order_id": 323
  67. * "balance": 8956
  68. * "register_time": "2017-12-12 12:12:12"
  69. * }
  70. * }
  71. */
  72. public function index()
  73. {
  74. if (!$this->checkUid()) {
  75. return response()->error('NOT_LOGIN');
  76. }
  77. $data = UserService::getById($this->uid);
  78. $data['bind'] = 0;
  79. $data['bind_phone'] = '';
  80. $data['is_paid'] = $this->is_paid;
  81. if ($this->is_paid) {
  82. $bind_info = UserBindPhoneService::bindInfo($this->uid);
  83. if ($bind_info) {
  84. $data['bind'] = 1;
  85. $data['bind_phone'] = $bind_info->phone;
  86. }
  87. }
  88. $data['is_vip'] = 0;
  89. $data['vip_days'] = 0;
  90. $year_record = YearOrderService::getRecord($this->uid);
  91. if ($year_record) {
  92. $data['is_vip'] = 1;
  93. $time = strtotime($year_record['end_time']) - time();
  94. if ($time >= 86400) {
  95. $data['vip_days'] = floor($time / 86400) . '天';
  96. } elseif ($time > 3600) {
  97. $data['vip_days'] = floor($time / 3600) . '小时';
  98. } elseif ($time > 60) {
  99. $data['vip_days'] = floor($time / 60) . '分钟';
  100. } else {
  101. $data['vip_days'] = $time . '秒';
  102. }
  103. }
  104. $data['is_all_life'] = 0;
  105. $activity_id = env('FOREVER_ACTIVITY_ID');
  106. if ($activity_id) {
  107. if (OrderService::userIsParticipateActivity($this->uid, $activity_id)) {
  108. $data['is_vip'] = 0;
  109. $data['vip_days'] = '99年';
  110. $data['is_all_life'] = 1;
  111. }
  112. }
  113. return response()->success($data);
  114. }
  115. /**
  116. * @apiVersion 1.0.0
  117. * @apiDescription 用户签到记录
  118. * @api {GET} user/sign_record 用户签到记录
  119. * @apiGroup User
  120. * @apiName signRecord
  121. * @apiSuccess {int} code 状态码
  122. * @apiSuccess {String} msg 信息
  123. * @apiSuccess {object} data 结果集
  124. * @apiSuccess {reward} data.reward 奖励金额.
  125. * @apiSuccess {sign_time} data.sign_time 签到时间.
  126. * @apiParam {page} page
  127. * @apiSuccessExample {json} Success-Response:
  128. *
  129. * {
  130. * code: 0,
  131. * msg: "",
  132. * data: {
  133. * list: [
  134. * {
  135. * reward: 50,
  136. * sign_time: "2018-03-20 13:43:11"
  137. * },
  138. * {
  139. * reward: 50,
  140. * sign_time: "2018-01-18 16:22:33"
  141. * },
  142. * ],
  143. * meta: {
  144. * total: 12,
  145. * per_page: 15,
  146. * current_page: 1,
  147. * last_page: 1,
  148. * next_page_url: "",
  149. * prev_page_url: ""
  150. * }
  151. * }
  152. * }
  153. */
  154. public function signRecord(Request $request)
  155. {
  156. $sign_result = paginationTransform(new SignRecordTransformer(), UserSignService::getUserSignRecord($this->uid));
  157. $sign_status = UserSignService::isSign($this->uid);
  158. $sign_today = [];
  159. if ($sign_status) {
  160. $sign_today = ReadRecordService::getByField($this->uid, 'sign_info');
  161. if ($sign_today) $sign_today = json_decode($sign_today, 1);
  162. isset($sign_today['sign_time']) && $sign_today['sign_time'] = date('Y-m-d H:i:s', $sign_today['sign_time']);
  163. isset($sign_today['sign_at']) && $sign_today['sign_time'] = $sign_today['sign_at'];
  164. isset($sign_today['price']) && $sign_today['reward'] = $sign_today['price'];
  165. }
  166. $result = [
  167. 'sign_status' => $sign_status,
  168. 'sign_result' => $sign_result,
  169. 'sign_today' => $sign_today
  170. ];
  171. return response()->success($result);
  172. }
  173. public function getCoupons(Request $request)
  174. {
  175. $activity_id = $request->input('activity_id');
  176. if (!DB::table('discount_coupons')->where('uid', $this->uid)->where('activity_id', $activity_id)->count()) {
  177. DB::table('discount_coupons')->insert([
  178. 'uid' => $this->uid,
  179. 'activity_id' => $activity_id,
  180. 'created_at' => date('Y-m-d H:i:s'),
  181. 'updated_at' => date('Y-m-d H:i:s')
  182. ]);
  183. }
  184. return response()->success();
  185. }
  186. public function sign(Request $request)
  187. {
  188. //sign_days
  189. //$day = date('Y-m-d');
  190. $sign = UserSignService::isSign($this->uid);
  191. $sign_count = ReadRecordService::getSignCount($this->uid);
  192. if ($sign) {
  193. //如果已经签过到
  194. if (!$sign_count) {
  195. ReadRecordService::setSignCount($this->uid, 1);
  196. ReadRecordService::setSignDay($this->uid);
  197. $sign_count = 1;
  198. }
  199. $fee = 30;
  200. if ($sign_count >= 3) {
  201. $fee = 50;
  202. }
  203. $data = ['sign_days' => $sign_count, 'sign_reard' => $fee, 'status' => 1];
  204. return response()->success($data);
  205. }
  206. //还没有签到
  207. $status = UserSignService::signToday($this->uid);
  208. $sign_count = ReadRecordService::getSignCount($this->uid);
  209. $data = ['sign_days' => $sign_count, 'sign_reard' => $status, 'status' => 0];
  210. return response()->success($data);
  211. }
  212. /**
  213. * @return string
  214. */
  215. public function signi()
  216. {
  217. /*if(in_array($this->distribution_channel_id,explode(',',redisEnv('NEW_SIGN_CHANNELS','')))){
  218. $version = UserSignService::getUserSignVersion($this->uid);
  219. }else{
  220. $version = 'v1';
  221. }*/
  222. $version = UserSignService::getUserSignVersion($this->uid);
  223. if ($version == 'v1') {
  224. $page = 'wap.sign';
  225. } else {
  226. $page = 'wap.signv2';
  227. }
  228. $book1 = $book2 = null;
  229. if ($version == 'v2') {
  230. $sex = $this->_user_info->sex;
  231. $sex = $sex ? $sex : 2;
  232. $book1 = BookConfigService::getRandomOneHighQualityBook($sex);
  233. $book1->url = sprintf('/reader?bid=%s&cid=%s&source=wechatmsg&fromtype=sign_recommend', Hashids::encode($book1->bid), $book1->first_cid);
  234. $book2 = SignBookService::getRandomBook($sex);
  235. \Log::info($book2);
  236. foreach ($book2 as $item) {
  237. $item->url = sprintf('/reader?bid=%s&cid=%s&source=wechatmsg&fromtype=sign_recommend', Hashids::encode($item->bid), $item->first_cid);
  238. }
  239. }
  240. $tomorrow_pool = $fee_pool = [0, 30, 50, 120, 50, 50, 50, 150];
  241. $day = [0, '一', '二', '三', '四', '五', '六', '七'];
  242. list($sign, $sign_count) = ReadRecordService::getByMultiField($this->uid, 'sign_day', 'sign_counts');
  243. if ($sign && $sign == date('Y-m-d')) {
  244. if ($version == 'v1') {
  245. $fee = $sign_count >= 3 ? 50 : 30;
  246. } else {
  247. if ($sign_count % 7 == 1 && $sign_count <= 7) {
  248. $fee = 30;
  249. } elseif ($sign_count % 7 == 3) {
  250. $fee = 120;
  251. } elseif ($sign_count % 7 == 0) {
  252. $fee = 150;
  253. } else {
  254. $fee = 50;
  255. }
  256. }
  257. if ($sign_count >= 8) {
  258. $fee_pool[1] = 50;
  259. }
  260. $tomorrow = (($sign_count + 1) % 7 == 0 ? 7 : ($sign_count + 1) % 7);
  261. if ($sign_count + 1 >= 8) {
  262. $tomorrow_pool[1] = 50;
  263. }
  264. //签过到了
  265. $data = ['sign_count' => $sign_count, 'fee' => $fee, 'fee_pool' => $fee_pool, 'day' => $day, 'book1' => $book1, 'book2' => $book2, 'tomorrow_fee' => $tomorrow_pool[$tomorrow]];
  266. return view($page, $data);
  267. }
  268. $fee = UserSignService::signToday($this->uid, $version);
  269. if (!$fee) {
  270. return response()->error('WAP_SYS_ERROR');
  271. }
  272. $sign_count = ReadRecordService::getSignCount($this->uid);
  273. if ($sign_count >= 8) {
  274. $fee_pool[1] = 50;
  275. }
  276. if ($sign_count + 1 >= 8) {
  277. $tomorrow_pool[1] = 50;
  278. }
  279. $tomorrow = (($sign_count + 1) % 7 == 0 ? 7 : ($sign_count + 1) % 7);
  280. $data = ['sign_count' => $sign_count, 'fee' => $fee, 'fee_pool' => $fee_pool, 'day' => $day, 'book1' => $book1, 'book2' => $book2, 'tomorrow_fee' => $tomorrow_pool[$tomorrow]];
  281. return view($page, $data);
  282. }
  283. public function signV3()
  284. {
  285. //修改签到页面,version=v2
  286. $fee_pool = [0, 30, 50, 120, 50, 50, 50, 150];
  287. list($sign, $sign_count) = ReadRecordService::getByMultiField($this->uid, 'sign_day', 'sign_counts');
  288. $read_record = $this->getSignPageReadRecord($all_bid);
  289. if (!$all_bid) $all_bid = [];
  290. $user = $this->_user_info;
  291. $recommend_book = $this->getSignRecomandBook($user->sex, $all_bid);
  292. if ($sign && $sign == date('Y-m-d')) {
  293. if ($sign_count % 7 == 1 && $sign_count <= 7) {
  294. $fee = 30;
  295. } elseif ($sign_count % 7 == 3) {
  296. $fee = 120;
  297. } elseif ($sign_count % 7 == 0) {
  298. $fee = 150;
  299. } else {
  300. $fee = 50;
  301. }
  302. if ($sign_count >= 8) {
  303. $fee_pool[1] = 50;
  304. }
  305. $day = $sign_count % 7;
  306. if ($day == 0) {
  307. $day = 7;
  308. }
  309. //签过到了
  310. $name = $user->nickname;
  311. $head_img = $user->head_img;
  312. $balance = $user->balance;
  313. $data = ['sign_count' => $sign_count, 'fee' => $fee, 'fee_pool' => $fee_pool,
  314. 'day' => $day, 'is_alert' => 0, 'read_record' => $read_record, 'name' => $name,
  315. 'head_img' => $head_img,
  316. 'balance' => $balance,
  317. 'recommend_book' => $recommend_book
  318. ];
  319. return view('wap.signV3', $data);
  320. }
  321. $fee = UserSignService::signToday($this->uid, 'v2');
  322. if (!$fee) {
  323. return response()->error('WAP_SYS_ERROR');
  324. }
  325. $sign_count = ReadRecordService::getSignCount($this->uid);
  326. //$sign_count++;
  327. if ($sign_count >= 8) {
  328. $fee_pool[1] = 50;
  329. }
  330. $day = $sign_count % 7;
  331. if ($day == 0) {
  332. $day = 7;
  333. }
  334. //签过到了
  335. $name = $user->nickname;
  336. $head_img = $user->head_img;
  337. $balance = $user->balance;
  338. $data = ['sign_count' => $sign_count, 'fee' => $fee, 'fee_pool' => $fee_pool,
  339. 'day' => $day, 'is_alert' => 1, 'read_record' => $read_record,
  340. 'name' => $name,
  341. 'head_img' => $head_img,
  342. 'balance' => $balance,
  343. 'recommend_book' => $recommend_book
  344. ];
  345. return view('wap.signV3', $data);
  346. }
  347. private function getSignPageReadRecord(&$all_id)
  348. {
  349. $res = ReadRecordService::getReadRecord($this->uid);
  350. if ($res) {
  351. $id_arr = [];
  352. foreach ($res as $key => $value) {
  353. if ($key < 2) {
  354. $id_arr[] = $value['bid'];
  355. }
  356. $all_id[] = $value['bid'];
  357. }
  358. $book = BookConfigService::getBooksByIds($id_arr);
  359. foreach ($res as $key => &$value) {
  360. $value['cover'] = '';
  361. $value['url'] = sprintf('/reader?bid=%s&cid=%s', Hashids::encode($value['bid']), $value['cid']);
  362. $value['last_chapter'] = 0;
  363. $value['update_count'] = 0;
  364. foreach ($book as $val) {
  365. if ($value['bid'] == $val->bid) {
  366. $value['cover'] = $val->cover;
  367. $value['last_chapter'] = $val->last_chapter;
  368. if ($val->status == 0) {
  369. $value['update_count'] = DB::table('book_updates')
  370. ->where('bid', $val->bid)->where('update_type', 'add_chapter')
  371. ->where('created_at', '>=', date('Y-m-d H:i:s', $value['time']))
  372. ->sum('update_chapter_count');
  373. }
  374. break;
  375. }
  376. }
  377. }
  378. }
  379. return $res;
  380. }
  381. private function getSignRecomandBook(int $sex, array $all_bid):array
  382. {
  383. if ($sex == 1) {
  384. $set_key = 'male_high_reco_bids';
  385. } else {
  386. $set_key = 'female_high_reco_bids';
  387. }
  388. $bids = Cookie::get('sign_recomand_bids');
  389. if (!$bids) {
  390. $bid_array = Redis::Srandmember($set_key, 16);
  391. //Log::info($bid_array);
  392. $time = strtotime(date('Y-m-d', time() + 86400)) - time();
  393. $new_bid_array = [];
  394. foreach ($bid_array as $item) {
  395. if (in_array($item, $all_bid)) {
  396. array_unshift($new_bid_array, $item);
  397. } else {
  398. array_push($new_bid_array, $item);
  399. }
  400. }
  401. $bids = implode(',', $new_bid_array);
  402. Cookie::queue('sign_recomand_bids', $bids, $time);
  403. }
  404. //Log::info($bids);
  405. $result = DB::select(sprintf('select book_configs.book_name,intro,bid,books.category_name,book_configs.cover,first_cid,
  406. (select GROUP_CONCAT(tags) from book_tags where bid = book_configs.bid and `status` = 1) as tag from book_configs
  407. left join books on books.id = book_configs.bid left join book_categories on book_categories.id = books.category_id
  408. where bid in (%s) and is_on_shelf =2 ORDER by field(book_configs.bid,%s)', $bids, $bids));
  409. $data = [];
  410. foreach ($result as $item) {
  411. $tag_list = [];
  412. if ($item->tag) {
  413. $tag_list = explode(',', $item->tag);
  414. }
  415. $data[] = [
  416. 'book_name' => $item->book_name,
  417. 'intro' => $item->intro,
  418. 'bid' => $item->bid,
  419. 'category_name' => $item->category_name,
  420. 'cover' => $item->cover,
  421. 'tag' => $item->tag,
  422. 'tag_list' => $tag_list,
  423. 'url' => sprintf('/reader?bid=%s&cid=%s&source=wechatmsg&fromtype=sign_recommend', Hashids::encode($item->bid), $item->first_cid),
  424. ];
  425. }
  426. return $data;
  427. }
  428. public function recordShare(Request $request)
  429. {
  430. if (!$this->checkUid()) {
  431. return response()->error('NOT_LOGIN');
  432. }
  433. $uid = $this->uid;
  434. $distribution_channel_id = $this->distribution_channel_id;
  435. $type = 'click';
  436. $bid = $request->get('bid');
  437. $cid = $request->get('cid', 0);
  438. if (!$bid) {
  439. return response()->error('PARAM_ERROR');
  440. }
  441. !is_numeric($bid) && $bid = Hashids::decode($bid)[0];
  442. WapReaderPageFissionService::createV2($uid, $bid, $distribution_channel_id, $type, 0, $cid);
  443. $user = $this->_user_info;
  444. $data = [];
  445. if (in_array($distribution_channel_id, [2, 14, 211]) && $user) {
  446. $data['username'] = $user->nickname;
  447. $data['head_img'] = $user->head_img;
  448. $url = 'https://' . _domain() . '/detail?fromtype=readershare&id=' . Hashids::encode($bid) . '&fromflag=' . $uid;
  449. //$url = str_replace('http://', $h5_scheme . '://', url()->current() . '?' . http_build_query($params));
  450. $data['share_url'] = $url;
  451. }
  452. return response()->success($data);
  453. }
  454. /**
  455. * @apiVersion 1.0.0
  456. * @apiDescription 用户点击广告统计
  457. * @api {post} user/advisitstat 用户点击广告统计
  458. * @apiGroup User
  459. * @apiName signRecord
  460. * @apiParam {Int} bid bid
  461. * @apiParam {Int} cid cid
  462. * @apiParam {Int} type type类型(CLICK|UNLOCK)
  463. * @apiSuccess {int} code 状态码
  464. * @apiSuccess {String} msg 信息
  465. * @apiSuccess {object} data 结果集
  466. * @apiParam {page} page
  467. * @apiSuccessExample {json} Success-Response:
  468. *
  469. * {
  470. * code: 0,
  471. * msg: "",
  472. * data: {
  473. * {
  474. * reward: 50,
  475. * sign_time: "2018-03-20 13:43:11"
  476. * },
  477. * {
  478. * reward: 50,
  479. * sign_time: "2018-01-18 16:22:33"
  480. * },
  481. * }
  482. * }
  483. */
  484. public function adVisitStat(Request $request)
  485. {
  486. $bid = $request->get('bid');
  487. $cid = $request->get('cid', 0);
  488. $type = $request->get('type');
  489. if (!$bid || !$type) {
  490. return response()->error('PARAM_ERROR');
  491. }
  492. !is_numeric($bid) && $bid = Hashids::decode($bid)[0];
  493. AdVisitStatService::create($this->uid, $bid, $cid, $type);
  494. return response()->success();
  495. }
  496. public function urgeUpdate(Request $request)
  497. {
  498. $bid = $request->get('bid');
  499. if (!$bid) {
  500. return response()->error('PARAM_ERROR');
  501. }
  502. $bid = Hashids::decode($bid)[0];
  503. $result = BookUrgeUpdateService::UrgeRecord($this->uid, $bid);
  504. if ($result && !$result->id) {
  505. BookUrgeUpdateService::UrgeUpdate($this->uid, $bid, $result->updated_at);
  506. }
  507. return response()->success();
  508. }
  509. function logout(Request $request, $channel_id, $domain)
  510. {
  511. //echo $channel_id.'----';
  512. //echo $domain;
  513. $domains = ['zhuishuyun', '66kshu', 'iycdm', 'leyuee'];
  514. setcookie(env('COOKIE_AUTH_WEB_WECHAT'), '', -1);
  515. setcookie('u', '', -1);
  516. setcookie('force_show_qrcode', '', -1);
  517. setcookie('sub_random_num', '', -1);
  518. setcookie('cpc_ad_status', '', -1);
  519. //return response('logout');
  520. $param = $request->except('_url');
  521. $url_format = '%s://site%s.%s.com/logout?%s';
  522. if (in_array($domain, $domains)) {
  523. $i = 0;
  524. foreach ($domains as $k => $v) {
  525. if ($v == $domain) {
  526. $i = $k;
  527. }
  528. }
  529. if (isset($domains[$i + 1])) {
  530. $link = sprintf($url_format, env('PROTOCOL'), $channel_id, $domains[$i + 1], http_build_query($param));
  531. return redirect()->to($link);
  532. }
  533. }
  534. return view('help.logout');
  535. }
  536. function setOrderDelCookie(Request $request)
  537. {
  538. $param = $request->except('_url');
  539. $type = isset($param['type']) ? $param['type'] : 'set';
  540. foreach ($param as $k => $v) {
  541. if ($k == 'type') continue;
  542. if ($type == 'set') {
  543. Cookie::queue($k, $v, 1000, null, null, false, false);
  544. } else {
  545. setcookie($k, '', -1);
  546. }
  547. }
  548. return response('ok');
  549. }
  550. function test_add_user_login_cookie(Request $request)
  551. {
  552. $uid = $request->get('uid');
  553. \Log::info('test_add_user_login_cookie:' . $uid);
  554. Cookie::queue(env('COOKIE_AUTH_WEB_WECHAT'), $uid, env('U_COOKIE_EXPIRE'), null, null, false, false);
  555. return response('add_cookie:' . $uid);
  556. }
  557. //日常随机签到
  558. function day_rand_sign(Request $request)
  559. {
  560. $uid = $this->uid;
  561. $day = date('Y-m-d');
  562. $hasSigned = UserRandSignService::hasSigned(compact('uid', 'day'));
  563. $fee = 0;
  564. if (!$hasSigned) {
  565. $fee = mt_rand(5, 15);
  566. UserRandSignService::sign(compact('uid', 'day', 'fee'));
  567. }
  568. return view('wap.rand_sign', compact('hasSigned', 'fee'));
  569. }
  570. public function sendCode(Request $request)
  571. {
  572. $phone = $request->post('phone');
  573. $code = random_int(1000, 9999);
  574. Redis::setex('code:' . $phone, 120, $code);
  575. AliSMS::send($phone, 'paid_user_bind_phone', ['code' => $code]);
  576. return response()->success();
  577. }
  578. public function bindPhone(Request $request)
  579. {
  580. $code = $request->post('code');
  581. $phone = $request->post('phone');
  582. $from = $request->post('from');
  583. $old = Redis::get('code:' . $phone);
  584. if ($old && $old == $code) {
  585. Redis::del('code:' . $phone);
  586. $user_info = UserService::getById($this->uid);
  587. if (!$user_info) {
  588. return response()->error();
  589. }
  590. try {
  591. $result = UserBindPhoneService::bind($this->uid, $user_info->openid, $phone, $from);
  592. if ($result == 0) {
  593. UserService::addBalance($this->uid, 100, 0, 100);
  594. UserWealthyOperateRecordService::create($this->uid, 100, $this->distribution_channel_id, 'bind_phone');
  595. return response()->success();
  596. }
  597. if ($result == -1) {
  598. return response()->error('WAP_BIND_PHONE_EXIST');
  599. }
  600. if ($result == -2) {
  601. return response()->error('WAP_SEND_OPENID_EXIST');
  602. }
  603. } catch (\Exception $e) {
  604. }
  605. } else {
  606. return response()->error('WAP_SEND_CODE_ERROR');
  607. }
  608. return response()->error();
  609. }
  610. public function bindPhoneView(Request $request)
  611. {
  612. $from = 'personal';
  613. $order = '';
  614. $url = '/personal';
  615. return view('pay.order.bindPhone', compact('order', 'url', 'from'));
  616. }
  617. public function guidePersonalAccount(Request $request)
  618. {
  619. $bid = $request->get('bid');
  620. $cid = $request->get('cid');
  621. $prev_cid = $request->get('prev_cid');
  622. $book_name = $request->get('book_name');
  623. $bid_no = Hashids::decode($bid)[0];
  624. if (Redis::SISMEMBER('crm:out_channel_sites', $this->distribution_channel_id)) {
  625. $group = 'OUT_FORCE';
  626. } else {
  627. $group = 'FORCE';
  628. }
  629. $env_config = redisEnvMulti($group . '_GUIDE_PERSONAL_ACCOUNT_OURS_QRCODE', $group . '_GUIDE_PERSONAL_ACCOUNT_MAX_UV',
  630. $group . '_GUIDE_PERSONAL_ACCOUNT_ID', $group . '_GUIDE_PERSONAL_ACCOUNT_MAX_EVERY_UV');
  631. if (empty($env_config[0])) return back();
  632. $img = $env_config[0];
  633. $max = empty($env_config[1]) ? 100 : $env_config[1];
  634. $one_loop_max = empty($env_config[3]) ? 10 : $env_config[3];
  635. $now_id = (int)$env_config[2];
  636. $uv = Redis::scard(strtolower($group) . '_guide_personal_uv');
  637. $personal_info = DB::table('personal_account_list')->where('id', $now_id)->select('count')->first();
  638. $total_max = $personal_info->count + $uv;
  639. //Log::info('$total_max is: '.);
  640. if ($uv >= $one_loop_max || $total_max >= $max) {
  641. if ($total_max >= $max) {
  642. DB::table('personal_account_list')->where('id', $now_id)->update([
  643. 'status' => 2,
  644. 'count' => $total_max,
  645. 'updated_at' => date('Y-m-d H:i:s')
  646. ]);
  647. } else {
  648. DB::table('personal_account_list')->where('id', $now_id)->increment('count', $uv, [
  649. 'updated_at' => date('Y-m-d H:i:s')
  650. ]);
  651. }
  652. $account = DB::table('personal_account_list')
  653. ->where('is_enable', 1)
  654. ->whereIn('status', [1, 0])
  655. ->select('id', 'url')
  656. ->where('count', '<', $max)
  657. ->where('group', $group)
  658. ->orderBy('count', 'asc')
  659. ->orderBy('id')
  660. ->first();
  661. Redis::del(strtolower($group) . '_guide_personal_uv');
  662. if ($account) {
  663. DB::table('personal_account_list')->where('id', $account->id)->update([
  664. 'status' => 1,
  665. 'updated_at' => date('Y-m-d H:i:s')
  666. ]);
  667. $img = $account->url;
  668. $now_id = $account->id;
  669. Redis::Hmset('env', $group . '_GUIDE_PERSONAL_ACCOUNT_OURS_QRCODE', $account->url, $group . '_GUIDE_PERSONAL_ACCOUNT_ID', $account->id);
  670. } else {
  671. Redis::Hmset('env', $group . '_GUIDE_PERSONAL_ACCOUNT_OURS_QRCODE', '', $group . '_GUIDE_PERSONAL_ACCOUNT_ID', '');
  672. }
  673. }
  674. Redis::sadd(strtolower($group) . '_guide_personal_uv', $this->uid);
  675. if ($group == 'OUT_FORCE') {
  676. $data = UserService::getById($this->uid);
  677. Redis::hset('crm:out_guide_exposure_user', $data->openid, $this->uid);
  678. }
  679. $personal_info = DB::table('personal_account_list')->where('id', $now_id)->select('name')->first();
  680. DB::table('ad_pdd')->insert([
  681. 'uid' => $this->uid,
  682. 'img' => $group . '_GUIDE_PERSONAL_ACCOUNT_' . $now_id,
  683. 'date' => date('Y-m-d'),
  684. 'created_at' => date('Y-m-d H:i:s'),
  685. 'updated_at' => date('Y-m-d H:i:s')
  686. ]);
  687. ForceGuidePersonAccountService::create($this->uid, $bid_no, $cid);
  688. $link['next'] = sprintf('/reader?bid=%s&cid=%s', $bid, $cid);
  689. $link['prev'] = sprintf('/reader?bid=%s&cid=%s', $bid, $prev_cid);
  690. $link['catalog'] = sprintf('/catalog?id=%s', $bid);
  691. return view('jump.forceGuidePersonalAccountV2', ['img' => $img, 'link' => $link, 'title' => $book_name, 'name' => $personal_info->name]);
  692. }
  693. /*public function crmPushView(Request $request)
  694. {
  695. $out_status = Redis::SISMEMBER('crm:out_channel_sites', $this->distribution_channel_id);
  696. if ($out_status) {
  697. $group = 'OUT_ACTIVE';
  698. } else {
  699. $group = 'ACTIVE';
  700. }
  701. list($qrcode, $max_uv, $account_id, $one_uv) = redisEnvMulti($group . '_GUIDE_PERSONAL_ACCOUNT_OURS_QRCODE', $group . '_GUIDE_PERSONAL_ACCOUNT_MAX_UV',
  702. $group . '_GUIDE_PERSONAL_ACCOUNT_ID', $group . '_GUIDE_PERSONAL_ACCOUNT_MAX_EVERY_UV');
  703. $uv = Redis::scard(strtolower($group) . '_guide_personal_uv');
  704. if (!$max_uv) $max_uv = 100;
  705. if ($uv >= $max_uv) {
  706. //名额不足
  707. $data = ['code' => -1, 'read_url' => '/continue'];
  708. return view('crm.crmPush', $data);
  709. }
  710. $sql = 'SELECT friend_link_uid_bind.uid FROM friend_link_uid_bind where openid = (SELECT openid FROM users WHERE id = %s) ORDER by id desc limit 1';
  711. $friend_link_uid_bind = DB::select(sprintf($sql, $this->uid));
  712. //$get_info = UserBindHkWelfareService::isHasGet($this->uid);
  713. if ($friend_link_uid_bind) {
  714. $info = DB::table('ad_pdd')->where('uid', $friend_link_uid_bind[0]->uid)->orderBy('id', 'desc')->first();
  715. if ($info) {
  716. $personal_account_id = preg_replace('/\D+/', '', $info->img);
  717. if ($info) {
  718. $personal_info = DB::table('personal_account_list')
  719. ->where('id', $personal_account_id)
  720. ->where('is_enable', 1)
  721. ->select('name', 'url', 'status', 'is_enable')->first();
  722. //$user_info = UserService::getById($friend_link_uid_bind[0]->uid);
  723. //$link = sprintf('https://site%s.leyuee.com',encodeDistributionChannelId($user_info->distribution_channel_id));
  724. if ($personal_info) {
  725. $data = ['code' => -2, 'name' => $personal_info->name, 'read_url' => '/guidestrem?uid=' . $this->uid . '&name=' . $personal_info->name . '&img=' . urlencode($personal_info->url)];
  726. return view('crm.crmPush', $data);
  727. }
  728. }
  729. }
  730. $data = ['code' => -3, 'read_url' => '/guidestrem?uid=' . $this->uid . '&fee=500', 'name' => ''];
  731. return view('crm.crmPush', $data);
  732. } else {
  733. $data = ['code' => 0, 'read_url' => '/guidestrem?uid=' . $this->uid . '&fee=500', 'name' => ''];
  734. return view('crm.crmPush', $data);
  735. }
  736. }*/
  737. public function crmPushView(Request $request)
  738. {
  739. $crm_config = redisEnvMulti('ACTIVE_GUIDE_PERSONAL_ACCOUNT_OURS_QRCODE',
  740. 'ACTIVE_GUIDE_PERSONAL_ACCOUNT_MAX_UV', 'ACTIVE_GUIDE_PERSONAL_ACCOUNT_ID',
  741. 'ACTIVE_GUIDE_PERSONAL_ACCOUNT_MAX_EVERY_UV');
  742. $img = $crm_config[0];
  743. $max = empty($crm_config[1]) ? 100 : $crm_config[1];
  744. $max = (int)$max;
  745. $one_loop_max = empty($crm_config[3]) ? 10 : $crm_config[3];
  746. $now_id = (int)$crm_config[2];
  747. $uv_key = 'active_guide_personal_uv';
  748. $uv = Redis::scard($uv_key);
  749. $personal_info = DB::table('personal_account_list')->where('id', $now_id)->select('count')->first();
  750. $total_max = (int)($personal_info->count + $uv);
  751. if (empty($img) || empty($now_id) || $total_max >= $max) {
  752. //没有名额
  753. $data = ['code' => -1, 'read_url' => '/sign'];
  754. return view('crm.crmPush', $data);
  755. }
  756. $sql = 'SELECT friend_link_uid_bind.uid FROM friend_link_uid_bind where openid = (SELECT openid FROM users WHERE id = %s) ORDER by id desc limit 1';
  757. $friend_link_uid_bind = DB::select(sprintf($sql, $this->uid));
  758. //$get_info = UserBindHkWelfareService::isHasGet($this->uid);
  759. if ($friend_link_uid_bind) {
  760. $info = DB::table('ad_pdd')->where('uid', $friend_link_uid_bind[0]->uid)->orderBy('id', 'desc')->first();
  761. if ($info) {
  762. $personal_account_id = preg_replace('/\D+/', '', $info->img);
  763. if ($info) {
  764. $personal_info = DB::table('personal_account_list')
  765. ->where('id', $personal_account_id)
  766. ->where('is_enable', 1)
  767. ->select('name', 'url', 'status', 'is_enable')->first();
  768. if ($personal_info) {
  769. $data = ['code' => -2, 'name' => $personal_info->name];
  770. return view('crm.crmPush', $data);
  771. }
  772. }
  773. }
  774. $data = ['code' => -3, 'read_url' => '/sign'];
  775. return view('crm.crmPush', $data);
  776. }
  777. $property = UserDivisionCpcPropertyService::getUserPropertyV2($this->uid);
  778. $charge = false;
  779. if (in_array($property, ['medium', 'high'])) {
  780. $charge = true;
  781. } else {
  782. if ($this->property == 'undefined' && OrderService::getChargeNum($this->uid) >= 10) {
  783. $charge = true;
  784. }
  785. }
  786. if (!$charge) {
  787. //不符合条件
  788. $data = ['code' => -1, 'read_url' => '/sign'];
  789. return view('crm.crmPush', $data);
  790. }
  791. Redis::sadd($uv_key, $this->uid);
  792. DB::table('ad_pdd')->insert([
  793. 'uid' => $this->uid,
  794. 'img' => 'GUIDE_PERSONAL_ACCOUNT_' . $now_id,
  795. 'date' => date('Y-m-d'),
  796. 'created_at' => date('Y-m-d H:i:s'),
  797. 'updated_at' => date('Y-m-d H:i:s')
  798. ]);
  799. return view('crm.crmPush2', ['name' => $personal_info->name, 'img' => $img]);
  800. }
  801. }