UserController.php 27 KB

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