UserController.php 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885
  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. $bind_status = 0;
  293. $bind_link = '';
  294. if ($sign && $sign == date('Y-m-d')) {
  295. if ($sign_count % 7 == 1 && $sign_count <= 7) {
  296. $fee = 30;
  297. } elseif ($sign_count % 7 == 3) {
  298. $fee = 120;
  299. } elseif ($sign_count % 7 == 0) {
  300. $fee = 150;
  301. } else {
  302. $fee = 50;
  303. }
  304. if ($sign_count >= 8) {
  305. $fee_pool[1] = 50;
  306. }
  307. $day = $sign_count % 7;
  308. if ($day == 0) {
  309. $day = 7;
  310. }
  311. //签过到了
  312. $name = $user->nickname;
  313. $head_img = $user->head_img;
  314. $balance = $user->balance;
  315. $data = ['sign_count' => $sign_count, 'fee' => $fee, 'fee_pool' => $fee_pool,
  316. 'day' => $day, 'is_alert' => 0, 'read_record' => $read_record, 'name' => $name,
  317. 'head_img' => $head_img,
  318. 'balance' => $balance,
  319. 'recommend_book' => $recommend_book,
  320. 'bind_status'=>$bind_status,
  321. 'bind_link'=>$bind_link
  322. ];
  323. return view('wap.signV3', $data);
  324. }
  325. $fee = UserSignService::signToday($this->uid, 'v2');
  326. if (!$fee) {
  327. return response()->error('WAP_SYS_ERROR');
  328. }
  329. $sign_count = ReadRecordService::getSignCount($this->uid);
  330. //$sign_count++;
  331. if ($sign_count >= 8) {
  332. $fee_pool[1] = 50;
  333. }
  334. $day = $sign_count % 7;
  335. if ($day == 0) {
  336. $day = 7;
  337. }
  338. //签过到了
  339. $name = $user->nickname;
  340. $head_img = $user->head_img;
  341. $balance = $user->balance;
  342. //导粉
  343. list($inner_sites,$active_qrcode) = redisEnvMulti(
  344. 'GUIDE_PERSONAL_ACCOUNT_SITES',
  345. 'ACTIVE_GUIDE_PERSONAL_ACCOUNT_OURS_QRCODE'
  346. );
  347. if ($active_qrcode && $inner_sites && in_array($this->distribution_channel_id, explode(',', $inner_sites))){
  348. $get_info = UserBindHkWelfareService::isHasGet($this->uid);
  349. if(!$get_info){
  350. $property = UserDivisionCpcPropertyService::getUserPropertyV2($this->uid);
  351. $charge = false;
  352. if (in_array($property, ['medium', 'high'])) {
  353. $charge = true;
  354. } else {
  355. if ($property == 'undefined' && OrderService::getChargeNum($this->uid) >= 10) {
  356. $charge = true;
  357. }
  358. }
  359. if($charge){
  360. $bind_status = 1;
  361. $bind_link = '/guidestrem?uid=' . $this->uid . '&fee=500';
  362. }
  363. }
  364. }
  365. $data = ['sign_count' => $sign_count, 'fee' => $fee, 'fee_pool' => $fee_pool,
  366. 'day' => $day, 'is_alert' => 1, 'read_record' => $read_record,
  367. 'name' => $name,
  368. 'head_img' => $head_img,
  369. 'balance' => $balance,
  370. 'recommend_book' => $recommend_book,
  371. 'bind_status'=>$bind_status,
  372. 'bind_link'=>$bind_link
  373. ];
  374. return view('wap.signV3', $data);
  375. }
  376. private function getSignPageReadRecord(&$all_id)
  377. {
  378. $res = ReadRecordService::getReadRecord($this->uid);
  379. if ($res) {
  380. $id_arr = [];
  381. foreach ($res as $key => $value) {
  382. if ($key < 2) {
  383. $id_arr[] = $value['bid'];
  384. }
  385. $all_id[] = $value['bid'];
  386. }
  387. $book = BookConfigService::getBooksByIds($id_arr);
  388. foreach ($res as $key => &$value) {
  389. $value['cover'] = '';
  390. $value['url'] = sprintf('/reader?bid=%s&cid=%s', Hashids::encode($value['bid']), $value['cid']);
  391. $value['last_chapter'] = 0;
  392. $value['update_count'] = 0;
  393. foreach ($book as $val) {
  394. if ($value['bid'] == $val->bid) {
  395. $value['cover'] = $val->cover;
  396. $value['last_chapter'] = $val->last_chapter;
  397. if ($val->status == 0) {
  398. $value['update_count'] = DB::table('book_updates')
  399. ->where('bid', $val->bid)->where('update_type', 'add_chapter')
  400. ->where('created_at', '>=', date('Y-m-d H:i:s', $value['time']))
  401. ->sum('update_chapter_count');
  402. }
  403. break;
  404. }
  405. }
  406. }
  407. }
  408. return $res;
  409. }
  410. private function getSignRecomandBook(int $sex, array $all_bid):array
  411. {
  412. if ($sex == 1) {
  413. $set_key = 'male_high_reco_bids';
  414. } else {
  415. $set_key = 'female_high_reco_bids';
  416. }
  417. $bids = Cookie::get('sign_recomand_bids');
  418. if (!$bids) {
  419. $bid_array = Redis::Srandmember($set_key, 16);
  420. //Log::info($bid_array);
  421. $time = strtotime(date('Y-m-d', time() + 86400)) - time();
  422. $new_bid_array = [];
  423. foreach ($bid_array as $item) {
  424. if (in_array($item, $all_bid)) {
  425. array_unshift($new_bid_array, $item);
  426. } else {
  427. array_push($new_bid_array, $item);
  428. }
  429. }
  430. $bids = implode(',', $new_bid_array);
  431. Cookie::queue('sign_recomand_bids', $bids, $time);
  432. }
  433. //Log::info($bids);
  434. $result = DB::select(sprintf('select book_configs.book_name,intro,bid,books.category_name,book_configs.cover,first_cid,
  435. (select GROUP_CONCAT(tags) from book_tags where bid = book_configs.bid and `status` = 1) as tag from book_configs
  436. left join books on books.id = book_configs.bid left join book_categories on book_categories.id = books.category_id
  437. where bid in (%s) and is_on_shelf =2 ORDER by field(book_configs.bid,%s)', $bids, $bids));
  438. $data = [];
  439. foreach ($result as $item) {
  440. $tag_list = [];
  441. if ($item->tag) {
  442. $tag_list = explode(',', $item->tag);
  443. }
  444. $data[] = [
  445. 'book_name' => $item->book_name,
  446. 'intro' => $item->intro,
  447. 'bid' => $item->bid,
  448. 'category_name' => $item->category_name,
  449. 'cover' => $item->cover,
  450. 'tag' => $item->tag,
  451. 'tag_list' => $tag_list,
  452. 'url' => sprintf('/reader?bid=%s&cid=%s&source=wechatmsg&fromtype=sign_recommend', Hashids::encode($item->bid), $item->first_cid),
  453. ];
  454. }
  455. return $data;
  456. }
  457. public function recordShare(Request $request)
  458. {
  459. if (!$this->checkUid()) {
  460. return response()->error('NOT_LOGIN');
  461. }
  462. $uid = $this->uid;
  463. $distribution_channel_id = $this->distribution_channel_id;
  464. $type = 'click';
  465. $bid = $request->get('bid');
  466. $cid = $request->get('cid', 0);
  467. if (!$bid) {
  468. return response()->error('PARAM_ERROR');
  469. }
  470. !is_numeric($bid) && $bid = Hashids::decode($bid)[0];
  471. WapReaderPageFissionService::createV2($uid, $bid, $distribution_channel_id, $type, 0, $cid);
  472. $user = $this->_user_info;
  473. $data = [];
  474. if (in_array($distribution_channel_id, [2, 14, 211]) && $user) {
  475. $data['username'] = $user->nickname;
  476. $data['head_img'] = $user->head_img;
  477. $url = 'https://' . _domain() . '/detail?fromtype=readershare&id=' . Hashids::encode($bid) . '&fromflag=' . $uid;
  478. //$url = str_replace('http://', $h5_scheme . '://', url()->current() . '?' . http_build_query($params));
  479. $data['share_url'] = $url;
  480. }
  481. return response()->success($data);
  482. }
  483. /**
  484. * @apiVersion 1.0.0
  485. * @apiDescription 用户点击广告统计
  486. * @api {post} user/advisitstat 用户点击广告统计
  487. * @apiGroup User
  488. * @apiName signRecord
  489. * @apiParam {Int} bid bid
  490. * @apiParam {Int} cid cid
  491. * @apiParam {Int} type type类型(CLICK|UNLOCK)
  492. * @apiSuccess {int} code 状态码
  493. * @apiSuccess {String} msg 信息
  494. * @apiSuccess {object} data 结果集
  495. * @apiParam {page} page
  496. * @apiSuccessExample {json} Success-Response:
  497. *
  498. * {
  499. * code: 0,
  500. * msg: "",
  501. * data: {
  502. * {
  503. * reward: 50,
  504. * sign_time: "2018-03-20 13:43:11"
  505. * },
  506. * {
  507. * reward: 50,
  508. * sign_time: "2018-01-18 16:22:33"
  509. * },
  510. * }
  511. * }
  512. */
  513. public function adVisitStat(Request $request)
  514. {
  515. $bid = $request->get('bid');
  516. $cid = $request->get('cid', 0);
  517. $type = $request->get('type');
  518. if (!$bid || !$type) {
  519. return response()->error('PARAM_ERROR');
  520. }
  521. !is_numeric($bid) && $bid = Hashids::decode($bid)[0];
  522. AdVisitStatService::create($this->uid, $bid, $cid, $type);
  523. return response()->success();
  524. }
  525. public function urgeUpdate(Request $request)
  526. {
  527. $bid = $request->get('bid');
  528. if (!$bid) {
  529. return response()->error('PARAM_ERROR');
  530. }
  531. $bid = Hashids::decode($bid)[0];
  532. $result = BookUrgeUpdateService::UrgeRecord($this->uid, $bid);
  533. if ($result && !$result->id) {
  534. BookUrgeUpdateService::UrgeUpdate($this->uid, $bid, $result->updated_at);
  535. }
  536. return response()->success();
  537. }
  538. function logout(Request $request, $channel_id, $domain)
  539. {
  540. //echo $channel_id.'----';
  541. //echo $domain;
  542. $domains = ['zhuishuyun', '66kshu', 'iycdm', 'leyuee'];
  543. setcookie(env('COOKIE_AUTH_WEB_WECHAT'), '', -1);
  544. setcookie('u', '', -1);
  545. setcookie('force_show_qrcode', '', -1);
  546. setcookie('sub_random_num', '', -1);
  547. setcookie('cpc_ad_status', '', -1);
  548. //return response('logout');
  549. $param = $request->except('_url');
  550. $url_format = '%s://site%s.%s.com/logout?%s';
  551. if (in_array($domain, $domains)) {
  552. $i = 0;
  553. foreach ($domains as $k => $v) {
  554. if ($v == $domain) {
  555. $i = $k;
  556. }
  557. }
  558. if (isset($domains[$i + 1])) {
  559. $link = sprintf($url_format, env('PROTOCOL'), $channel_id, $domains[$i + 1], http_build_query($param));
  560. return redirect()->to($link);
  561. }
  562. }
  563. return view('help.logout');
  564. }
  565. function setOrderDelCookie(Request $request)
  566. {
  567. $param = $request->except('_url');
  568. $type = isset($param['type']) ? $param['type'] : 'set';
  569. foreach ($param as $k => $v) {
  570. if ($k == 'type') continue;
  571. if ($type == 'set') {
  572. Cookie::queue($k, $v, 1000, null, null, false, false);
  573. } else {
  574. setcookie($k, '', -1);
  575. }
  576. }
  577. return response('ok');
  578. }
  579. function test_add_user_login_cookie(Request $request)
  580. {
  581. $uid = $request->get('uid');
  582. \Log::info('test_add_user_login_cookie:' . $uid);
  583. Cookie::queue(env('COOKIE_AUTH_WEB_WECHAT'), $uid, env('U_COOKIE_EXPIRE'), null, null, false, false);
  584. return response('add_cookie:' . $uid);
  585. }
  586. //日常随机签到
  587. function day_rand_sign(Request $request)
  588. {
  589. $uid = $this->uid;
  590. $day = date('Y-m-d');
  591. $hasSigned = UserRandSignService::hasSigned(compact('uid', 'day'));
  592. $fee = 0;
  593. if (!$hasSigned) {
  594. $fee = mt_rand(5, 15);
  595. UserRandSignService::sign(compact('uid', 'day', 'fee'));
  596. }
  597. return view('wap.rand_sign', compact('hasSigned', 'fee'));
  598. }
  599. public function sendCode(Request $request)
  600. {
  601. $phone = $request->post('phone');
  602. $code = random_int(1000, 9999);
  603. Redis::setex('code:' . $phone, 120, $code);
  604. AliSMS::send($phone, 'paid_user_bind_phone', ['code' => $code]);
  605. return response()->success();
  606. }
  607. public function bindPhone(Request $request)
  608. {
  609. $code = $request->post('code');
  610. $phone = $request->post('phone');
  611. $from = $request->post('from');
  612. $old = Redis::get('code:' . $phone);
  613. if ($old && $old == $code) {
  614. Redis::del('code:' . $phone);
  615. $user_info = UserService::getById($this->uid);
  616. if (!$user_info) {
  617. return response()->error();
  618. }
  619. try {
  620. $result = UserBindPhoneService::bind($this->uid, $user_info->openid, $phone, $from);
  621. if ($result == 0) {
  622. UserService::addBalance($this->uid, 100, 0, 100);
  623. UserWealthyOperateRecordService::create($this->uid, 100, $this->distribution_channel_id, 'bind_phone');
  624. return response()->success();
  625. }
  626. if ($result == -1) {
  627. return response()->error('WAP_BIND_PHONE_EXIST');
  628. }
  629. if ($result == -2) {
  630. return response()->error('WAP_SEND_OPENID_EXIST');
  631. }
  632. } catch (\Exception $e) {
  633. }
  634. } else {
  635. return response()->error('WAP_SEND_CODE_ERROR');
  636. }
  637. return response()->error();
  638. }
  639. public function bindPhoneView(Request $request)
  640. {
  641. $from = 'personal';
  642. $order = '';
  643. $url = '/personal';
  644. return view('pay.order.bindPhone', compact('order', 'url', 'from'));
  645. }
  646. public function guidePersonalAccount(Request $request)
  647. {
  648. $bid = $request->get('bid');
  649. $cid = $request->get('cid');
  650. $prev_cid = $request->get('prev_cid');
  651. $book_name = $request->get('book_name');
  652. $bid_no = Hashids::decode($bid)[0];
  653. if (Redis::SISMEMBER('crm:out_channel_sites', $this->distribution_channel_id)) {
  654. $group = 'OUT_FORCE';
  655. } else {
  656. $group = 'FORCE';
  657. }
  658. $env_config = redisEnvMulti($group . '_GUIDE_PERSONAL_ACCOUNT_OURS_QRCODE', $group . '_GUIDE_PERSONAL_ACCOUNT_MAX_UV',
  659. $group . '_GUIDE_PERSONAL_ACCOUNT_ID', $group . '_GUIDE_PERSONAL_ACCOUNT_MAX_EVERY_UV');
  660. if (empty($env_config[0])) return back();
  661. $img = $env_config[0];
  662. $max = empty($env_config[1]) ? 100 : $env_config[1];
  663. $one_loop_max = empty($env_config[3]) ? 10 : $env_config[3];
  664. $now_id = (int)$env_config[2];
  665. $uv = Redis::scard(strtolower($group) . '_guide_personal_uv');
  666. $personal_info = DB::table('personal_account_list')->where('id', $now_id)->select('count')->first();
  667. $total_max = $personal_info->count + $uv;
  668. //Log::info('$total_max is: '.);
  669. if ($uv >= $one_loop_max || $total_max >= $max) {
  670. if ($total_max >= $max) {
  671. DB::table('personal_account_list')->where('id', $now_id)->update([
  672. 'status' => 2,
  673. 'count' => $total_max,
  674. 'updated_at' => date('Y-m-d H:i:s')
  675. ]);
  676. } else {
  677. DB::table('personal_account_list')->where('id', $now_id)->increment('count', $uv, [
  678. 'updated_at' => date('Y-m-d H:i:s')
  679. ]);
  680. }
  681. $account = DB::table('personal_account_list')
  682. ->where('is_enable', 1)
  683. ->whereIn('status', [1, 0])
  684. ->select('id', 'url')
  685. ->where('count', '<', $max)
  686. ->where('group', $group)
  687. ->orderBy('count', 'asc')
  688. ->orderBy('id')
  689. ->first();
  690. Redis::del(strtolower($group) . '_guide_personal_uv');
  691. if ($account) {
  692. DB::table('personal_account_list')->where('id', $account->id)->update([
  693. 'status' => 1,
  694. 'updated_at' => date('Y-m-d H:i:s')
  695. ]);
  696. $img = $account->url;
  697. $now_id = $account->id;
  698. Redis::Hmset('env', $group . '_GUIDE_PERSONAL_ACCOUNT_OURS_QRCODE', $account->url, $group . '_GUIDE_PERSONAL_ACCOUNT_ID', $account->id);
  699. } else {
  700. Redis::Hmset('env', $group . '_GUIDE_PERSONAL_ACCOUNT_OURS_QRCODE', '', $group . '_GUIDE_PERSONAL_ACCOUNT_ID', '');
  701. }
  702. }
  703. Redis::sadd(strtolower($group) . '_guide_personal_uv', $this->uid);
  704. if ($group == 'OUT_FORCE') {
  705. $data = UserService::getById($this->uid);
  706. Redis::hset('crm:out_guide_exposure_user', $data->openid, $this->uid);
  707. }
  708. $personal_info = DB::table('personal_account_list')->where('id', $now_id)->select('name')->first();
  709. DB::table('ad_pdd')->insert([
  710. 'uid' => $this->uid,
  711. 'img' => $group . '_GUIDE_PERSONAL_ACCOUNT_' . $now_id,
  712. 'date' => date('Y-m-d'),
  713. 'created_at' => date('Y-m-d H:i:s'),
  714. 'updated_at' => date('Y-m-d H:i:s')
  715. ]);
  716. ForceGuidePersonAccountService::create($this->uid, $bid_no, $cid);
  717. $link['next'] = sprintf('/reader?bid=%s&cid=%s', $bid, $cid);
  718. $link['prev'] = sprintf('/reader?bid=%s&cid=%s', $bid, $prev_cid);
  719. $link['catalog'] = sprintf('/catalog?id=%s', $bid);
  720. return view('jump.forceGuidePersonalAccountV2', ['img' => $img, 'link' => $link, 'title' => $book_name, 'name' => $personal_info->name]);
  721. }
  722. /*public function crmPushView(Request $request)
  723. {
  724. $out_status = Redis::SISMEMBER('crm:out_channel_sites', $this->distribution_channel_id);
  725. if ($out_status) {
  726. $group = 'OUT_ACTIVE';
  727. } else {
  728. $group = 'ACTIVE';
  729. }
  730. list($qrcode, $max_uv, $account_id, $one_uv) = redisEnvMulti($group . '_GUIDE_PERSONAL_ACCOUNT_OURS_QRCODE', $group . '_GUIDE_PERSONAL_ACCOUNT_MAX_UV',
  731. $group . '_GUIDE_PERSONAL_ACCOUNT_ID', $group . '_GUIDE_PERSONAL_ACCOUNT_MAX_EVERY_UV');
  732. $uv = Redis::scard(strtolower($group) . '_guide_personal_uv');
  733. if (!$max_uv) $max_uv = 100;
  734. if ($uv >= $max_uv) {
  735. //名额不足
  736. $data = ['code' => -1, 'read_url' => '/continue'];
  737. return view('crm.crmPush', $data);
  738. }
  739. $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';
  740. $friend_link_uid_bind = DB::select(sprintf($sql, $this->uid));
  741. //$get_info = UserBindHkWelfareService::isHasGet($this->uid);
  742. if ($friend_link_uid_bind) {
  743. $info = DB::table('ad_pdd')->where('uid', $friend_link_uid_bind[0]->uid)->orderBy('id', 'desc')->first();
  744. if ($info) {
  745. $personal_account_id = preg_replace('/\D+/', '', $info->img);
  746. if ($info) {
  747. $personal_info = DB::table('personal_account_list')
  748. ->where('id', $personal_account_id)
  749. ->where('is_enable', 1)
  750. ->select('name', 'url', 'status', 'is_enable')->first();
  751. //$user_info = UserService::getById($friend_link_uid_bind[0]->uid);
  752. //$link = sprintf('https://site%s.leyuee.com',encodeDistributionChannelId($user_info->distribution_channel_id));
  753. if ($personal_info) {
  754. $data = ['code' => -2, 'name' => $personal_info->name, 'read_url' => '/guidestrem?uid=' . $this->uid . '&name=' . $personal_info->name . '&img=' . urlencode($personal_info->url)];
  755. return view('crm.crmPush', $data);
  756. }
  757. }
  758. }
  759. $data = ['code' => -3, 'read_url' => '/guidestrem?uid=' . $this->uid . '&fee=500', 'name' => ''];
  760. return view('crm.crmPush', $data);
  761. } else {
  762. $data = ['code' => 0, 'read_url' => '/guidestrem?uid=' . $this->uid . '&fee=500', 'name' => ''];
  763. return view('crm.crmPush', $data);
  764. }
  765. }*/
  766. public function crmPushView(Request $request)
  767. {
  768. $crm_config = redisEnvMulti('ACTIVE_GUIDE_PERSONAL_ACCOUNT_OURS_QRCODE',
  769. 'ACTIVE_GUIDE_PERSONAL_ACCOUNT_MAX_UV', 'ACTIVE_GUIDE_PERSONAL_ACCOUNT_ID',
  770. 'ACTIVE_GUIDE_PERSONAL_ACCOUNT_MAX_EVERY_UV');
  771. $img = $crm_config[0];
  772. $max = empty($crm_config[1]) ? 100 : $crm_config[1];
  773. $max = (int)$max;
  774. $one_loop_max = empty($crm_config[3]) ? 10 : $crm_config[3];
  775. $now_id = (int)$crm_config[2];
  776. $uv_key = 'active_guide_personal_uv';
  777. $uv = Redis::scard($uv_key);
  778. $personal_info = DB::table('personal_account_list')->where('id', $now_id)->select('id','count','name')->first();
  779. $total_max = (int)($personal_info->count + $uv);
  780. if (empty($img) || empty($now_id) || $total_max >= $max) {
  781. //没有名额
  782. $data = ['code' => -1, 'read_url' => '/sign'];
  783. return view('crm.crmPush', $data);
  784. }
  785. $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';
  786. $friend_link_uid_bind = DB::select(sprintf($sql, $this->uid));
  787. //$get_info = UserBindHkWelfareService::isHasGet($this->uid);
  788. if ($friend_link_uid_bind) {
  789. $info = DB::table('ad_pdd')->where('uid', $friend_link_uid_bind[0]->uid)->orderBy('id', 'desc')->first();
  790. if ($info) {
  791. $personal_account_id = preg_replace('/\D+/', '', $info->img);
  792. if ($info) {
  793. $personal_info = DB::table('personal_account_list')
  794. ->where('id', $personal_account_id)
  795. ->where('is_enable', 1)
  796. ->select('name', 'url', 'status', 'is_enable')->first();
  797. if ($personal_info) {
  798. $data = ['code' => -2, 'name' => $personal_info->name];
  799. return view('crm.crmPush', $data);
  800. }
  801. }
  802. }
  803. $user_info = UserService::getById($friend_link_uid_bind[0]->uid);
  804. $link = 'https://site'.encodeDistributionChannelId($user_info->distribution_channel_id).'.leyuee.com/sign';
  805. $data = ['code' => -3, 'read_url' => $link];
  806. return view('crm.crmPush', $data);
  807. }
  808. $property = UserDivisionCpcPropertyService::getUserPropertyV2($this->uid);
  809. $charge = false;
  810. if (in_array($property, ['medium', 'high'])) {
  811. $charge = true;
  812. } else {
  813. if ($this->property == 'undefined' && OrderService::getChargeNum($this->uid) >= 10) {
  814. $charge = true;
  815. }
  816. }
  817. if (!$charge) {
  818. //不符合条件
  819. $data = ['code' => -1, 'read_url' => '/sign'];
  820. return view('crm.crmPush', $data);
  821. }
  822. Redis::sadd($uv_key, $this->uid);
  823. DB::table('ad_pdd')->insert([
  824. 'uid' => $this->uid,
  825. 'img' => 'GUIDE_PERSONAL_ACCOUNT_' . $now_id,
  826. 'date' => date('Y-m-d'),
  827. 'created_at' => date('Y-m-d H:i:s'),
  828. 'updated_at' => date('Y-m-d H:i:s')
  829. ]);
  830. return view('crm.crmPush2', ['name' => $personal_info->name, 'img' => $img]);
  831. }
  832. }