UserController.php 29 KB

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