UserController.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. <?php
  2. namespace App\Http\Controllers\Wap\User;
  3. use App\Modules\Book\Services\BookConfigService;
  4. use App\Modules\Book\Services\BookUrgeUpdateService;
  5. use App\Modules\Book\Services\SignBookService;
  6. use App\Modules\Statistic\Services\AdVisitStatService;
  7. use App\Modules\Subscribe\Services\OrderService;
  8. use App\Modules\User\Services\ForceGuidePersonAccountService;
  9. use App\Modules\User\Services\ReadRecordService;
  10. use App\Modules\User\Services\WapReaderPageFissionService;
  11. use Illuminate\Http\Request;
  12. use App\Http\Controllers\Wap\BaseController;
  13. use App\Modules\Subscribe\Services\YearOrderService;
  14. use App\Modules\User\Services\UserService;
  15. use App\Modules\User\Services\UserRandSignService;
  16. use App\Modules\User\Services\UserSignService;
  17. use App\Http\Controllers\Wap\User\Transformers\SignRecordTransformer;
  18. use Log;
  19. use Redis;
  20. use Cookie;
  21. use DB;
  22. use Hashids;
  23. class UserController extends BaseController
  24. {
  25. /**
  26. * @apiDefine User 用户
  27. */
  28. /**
  29. * @apiVersion 1.0.0
  30. * @apiDescription 获取用户信息
  31. * @api {GET} userinfo 获取用户信息
  32. * @apiGroup User
  33. * @apiName index
  34. * @apiSuccess {Number} id 用户ID.
  35. * @apiSuccess {String} openid 微信openid.
  36. * @apiSuccess {String} unionid 微信unionid.
  37. * @apiSuccess {Number} distribution_channel_id 分销渠道ID.
  38. * @apiSuccess {String} province 省份.
  39. * @apiSuccess {String} city 城市.
  40. * @apiSuccess {String} country 国家.
  41. * @apiSuccess {String} headimgurl 头像地址.
  42. * @apiSuccess {Number} send_order_id 派单ID.
  43. * @apiSuccess {Number=0,1} sex 性别.
  44. * @apiSuccess {String} balance 书币余额.
  45. * @apiSuccess {Int} is_vip 是否vip
  46. * @apiSuccess {String} vip_days 364天.
  47. * @apiSuccessExample {json} Success-Response:
  48. *
  49. * {
  50. * "code": 0,
  51. * "msg": "",
  52. * "data": {
  53. * "id": 56,
  54. * "openid": "sdfs34ssdfdsf",
  55. * "unionid": "SDFSD3343S",
  56. * "distribution_channel_id": 1212,
  57. * "province": "浙江省",
  58. * "city": "杭州",
  59. * "country": "中国",
  60. * "headimgurl": "http://.."
  61. * "send_order_id": 323
  62. * "balance": 8956
  63. * "register_time": "2017-12-12 12:12:12"
  64. * }
  65. * }
  66. */
  67. public function index(){
  68. if(!$this->checkUid()){
  69. return response()->error('NOT_LOGIN');
  70. }
  71. $data = UserService::getById($this->uid);
  72. $data['is_vip'] = 0;
  73. $data['vip_days'] = 0;
  74. $year_record = YearOrderService::getRecord($this->uid);
  75. if($year_record){
  76. $data['is_vip'] = 1;
  77. $time = strtotime($year_record['end_time'])-time();
  78. if($time>=86400){
  79. $data['vip_days'] = floor($time/86400).'天';
  80. }elseif ($time>3600) {
  81. $data['vip_days'] = floor($time/3600).'小时';
  82. }elseif ($time>60) {
  83. $data['vip_days'] = floor($time/60).'分钟';
  84. }else{
  85. $data['vip_days'] = $time.'秒';
  86. }
  87. }
  88. $data['is_all_life'] = 0;
  89. $activity_id = env('FOREVER_ACTIVITY_ID');
  90. if($activity_id){
  91. if(OrderService::userIsParticipateActivity($this->uid,$activity_id)){
  92. $data['is_vip'] = 0 ;
  93. $data['vip_days'] = '99年';
  94. $data['is_all_life'] = 1;
  95. }
  96. }
  97. return response()->success($data);
  98. }
  99. /**
  100. * @apiVersion 1.0.0
  101. * @apiDescription 用户签到记录
  102. * @api {GET} user/sign_record 用户签到记录
  103. * @apiGroup User
  104. * @apiName signRecord
  105. * @apiSuccess {int} code 状态码
  106. * @apiSuccess {String} msg 信息
  107. * @apiSuccess {object} data 结果集
  108. * @apiSuccess {reward} data.reward 奖励金额.
  109. * @apiSuccess {sign_time} data.sign_time 签到时间.
  110. * @apiParam {page} page
  111. * @apiSuccessExample {json} Success-Response:
  112. *
  113. * {
  114. * code: 0,
  115. * msg: "",
  116. * data: {
  117. * list: [
  118. * {
  119. * reward: 50,
  120. * sign_time: "2018-03-20 13:43:11"
  121. * },
  122. * {
  123. * reward: 50,
  124. * sign_time: "2018-01-18 16:22:33"
  125. * },
  126. * ],
  127. * meta: {
  128. * total: 12,
  129. * per_page: 15,
  130. * current_page: 1,
  131. * last_page: 1,
  132. * next_page_url: "",
  133. * prev_page_url: ""
  134. * }
  135. * }
  136. * }
  137. */
  138. public function signRecord(Request $request){
  139. $sign_result = paginationTransform(new SignRecordTransformer(),UserSignService::getUserSignRecord($this->uid));
  140. $sign_status = UserSignService::isSign($this->uid);
  141. $sign_today = [];
  142. if($sign_status){
  143. $sign_today = ReadRecordService::getByField($this->uid,'sign_info');
  144. if($sign_today) $sign_today = json_decode($sign_today,1);
  145. isset($sign_today['sign_time']) && $sign_today['sign_time'] = date('Y-m-d H:i:s',$sign_today['sign_time']);
  146. isset($sign_today['sign_at']) && $sign_today['sign_time'] = $sign_today['sign_at'];
  147. isset($sign_today['price']) && $sign_today['reward'] = $sign_today['price'];
  148. }
  149. $result = [
  150. 'sign_status'=>$sign_status,
  151. 'sign_result'=>$sign_result,
  152. 'sign_today'=>$sign_today
  153. ];
  154. return response()->success($result);
  155. }
  156. public function getCoupons(Request $request){
  157. $activity_id = $request->input('activity_id');
  158. if(!DB::table('discount_coupons')->where('uid',$this->uid)->where('activity_id',$activity_id)->count()){
  159. DB::table('discount_coupons')->insert([
  160. 'uid'=>$this->uid,
  161. 'activity_id'=>$activity_id,
  162. 'created_at'=>date('Y-m-d H:i:s'),
  163. 'updated_at'=>date('Y-m-d H:i:s')
  164. ]);
  165. }
  166. return response()->success();
  167. }
  168. public function sign(Request $request){
  169. //sign_days
  170. //$day = date('Y-m-d');
  171. $sign = UserSignService::isSign($this->uid);
  172. $sign_count = ReadRecordService::getSignCount($this->uid);
  173. if($sign){
  174. //如果已经签过到
  175. if(!$sign_count){
  176. ReadRecordService::setSignCount($this->uid,1);
  177. ReadRecordService::setSignDay($this->uid);
  178. $sign_count = 1;
  179. }
  180. $fee = 30;
  181. if($sign_count>=3){
  182. $fee = 50;
  183. }
  184. $data = ['sign_days'=>$sign_count,'sign_reard'=>$fee,'status'=>1];
  185. return response()->success($data);
  186. }
  187. //还没有签到
  188. $status = UserSignService::signToday($this->uid);
  189. $sign_count = ReadRecordService::getSignCount($this->uid);
  190. $data = ['sign_days'=>$sign_count,'sign_reard'=>$status,'status'=>0];
  191. return response()->success($data);
  192. }
  193. /**
  194. * @return string
  195. */
  196. public function signi()
  197. {
  198. /*if(in_array($this->distribution_channel_id,explode(',',redisEnv('NEW_SIGN_CHANNELS','')))){
  199. $version = UserSignService::getUserSignVersion($this->uid);
  200. }else{
  201. $version = 'v1';
  202. }*/
  203. $version = UserSignService::getUserSignVersion($this->uid);
  204. if($version == 'v1'){
  205. $page = 'wap.sign';
  206. }else{
  207. $page = 'wap.signv2';
  208. }
  209. $book1= $book2 = null;
  210. if($version == 'v2' ){
  211. $sex = $this->_user_info->sex;
  212. $sex = $sex?$sex:2;
  213. $book1 = BookConfigService::getRandomOneHighQualityBook($sex);
  214. $book1->url = sprintf('/reader?bid=%s&cid=%s&source=wechatmsg&fromtype=sign_recommend',Hashids::encode($book1->bid),$book1->first_cid);
  215. $book2 = SignBookService::getRandomBook($sex);
  216. \Log::info($book2);
  217. foreach ($book2 as $item){
  218. $item->url = sprintf('/reader?bid=%s&cid=%s&source=wechatmsg&fromtype=sign_recommend',Hashids::encode($item->bid),$item->first_cid);
  219. }
  220. }
  221. $tomorrow_pool = $fee_pool = [0,30,50,120,50,50,50,150];
  222. $day = [0,'一','二','三','四','五','六','七'];
  223. list($sign,$sign_count) = ReadRecordService::getByMultiField($this->uid,'sign_day','sign_counts');
  224. if ($sign && $sign == date('Y-m-d')) {
  225. if($version == 'v1'){
  226. $fee = $sign_count>=3 ? 50:30;
  227. }else{
  228. if ($sign_count % 7 == 1 && $sign_count<=7) {
  229. $fee = 30;
  230. } elseif ($sign_count % 7 == 3) {
  231. $fee = 120;
  232. } elseif ($sign_count % 7 == 0) {
  233. $fee = 150;
  234. } else {
  235. $fee = 50;
  236. }
  237. }
  238. if($sign_count >=8){
  239. $fee_pool[1] = 50;
  240. }
  241. $tomorrow = (($sign_count+1) % 7 == 0? 7:($sign_count+1) % 7);
  242. if($sign_count+1 >=8){
  243. $tomorrow_pool[1] = 50;
  244. }
  245. //签过到了
  246. $data = ['sign_count'=>$sign_count,'fee'=>$fee,'fee_pool'=>$fee_pool,'day'=>$day,'book1'=>$book1,'book2'=>$book2,'tomorrow_fee'=>$tomorrow_pool[$tomorrow]];
  247. return view($page,$data);
  248. }
  249. $fee = UserSignService::signToday($this->uid,$version);
  250. if(!$fee){
  251. return response()->error('WAP_SYS_ERROR');
  252. }
  253. $sign_count = ReadRecordService::getSignCount($this->uid);
  254. if($sign_count >=8){
  255. $fee_pool[1] = 50;
  256. }
  257. if($sign_count+1 >=8){
  258. $tomorrow_pool[1] = 50;
  259. }
  260. $tomorrow = (($sign_count+1) % 7 == 0? 7:($sign_count+1) % 7);
  261. $data = ['sign_count'=>$sign_count,'fee'=>$fee,'fee_pool'=>$fee_pool,'day'=>$day,'book1'=>$book1,'book2'=>$book2,'tomorrow_fee'=>$tomorrow_pool[$tomorrow]];
  262. return view($page,$data);
  263. }
  264. public function recordShare(Request $request){
  265. if(!$this->checkUid()){
  266. return response()->error('NOT_LOGIN');
  267. }
  268. $uid = $this->uid;
  269. $distribution_channel_id = $this->distribution_channel_id;
  270. $type = 'click';
  271. $bid = $request->get('bid');
  272. $cid = $request->get('cid',0);
  273. if(!$bid){
  274. return response()->error('PARAM_ERROR');
  275. }
  276. !is_numeric($bid) && $bid = Hashids::decode($bid)[0];
  277. WapReaderPageFissionService::createV2($uid,$bid,$distribution_channel_id,$type,0,$cid);
  278. $user = $this->_user_info;
  279. $data = [];
  280. if(in_array($distribution_channel_id,[2,14,211]) && $user){
  281. $data['username'] = $user->nickname;
  282. $data['head_img'] = $user->head_img;
  283. $url = 'https://'._domain().'/detail?fromtype=readershare&id='.Hashids::encode($bid).'&fromflag='.$uid;
  284. //$url = str_replace('http://', $h5_scheme . '://', url()->current() . '?' . http_build_query($params));
  285. $data['share_url'] = $url;
  286. }
  287. return response()->success($data);
  288. }
  289. /**
  290. * @apiVersion 1.0.0
  291. * @apiDescription 用户点击广告统计
  292. * @api {post} user/advisitstat 用户点击广告统计
  293. * @apiGroup User
  294. * @apiName signRecord
  295. * @apiParam {Int} bid bid
  296. * @apiParam {Int} cid cid
  297. * @apiParam {Int} type type类型(CLICK|UNLOCK)
  298. * @apiSuccess {int} code 状态码
  299. * @apiSuccess {String} msg 信息
  300. * @apiSuccess {object} data 结果集
  301. * @apiParam {page} page
  302. * @apiSuccessExample {json} Success-Response:
  303. *
  304. * {
  305. * code: 0,
  306. * msg: "",
  307. * data: {
  308. * {
  309. * reward: 50,
  310. * sign_time: "2018-03-20 13:43:11"
  311. * },
  312. * {
  313. * reward: 50,
  314. * sign_time: "2018-01-18 16:22:33"
  315. * },
  316. * }
  317. * }
  318. */
  319. public function adVisitStat(Request $request){
  320. $bid = $request->get('bid');
  321. $cid = $request->get('cid',0);
  322. $type = $request->get('type');
  323. if(!$bid || !$type){
  324. return response()->error('PARAM_ERROR');
  325. }
  326. !is_numeric($bid) && $bid = Hashids::decode($bid)[0];
  327. AdVisitStatService::create($this->uid,$bid,$cid,$type);
  328. return response()->success();
  329. }
  330. public function urgeUpdate(Request $request){
  331. $bid = $request->get('bid');
  332. if(!$bid){
  333. return response()->error('PARAM_ERROR');
  334. }
  335. $bid = Hashids::decode($bid)[0];
  336. $result = BookUrgeUpdateService::UrgeRecord($this->uid,$bid);
  337. if($result && !$result->id){
  338. BookUrgeUpdateService::UrgeUpdate($this->uid,$bid,$result->updated_at);
  339. }
  340. return response()->success();
  341. }
  342. function logout(Request $request,$channel_id,$domain)
  343. {
  344. //echo $channel_id.'----';
  345. //echo $domain;
  346. $domains = ['zhuishuyun','66kshu','iycdm','leyuee'];
  347. setcookie(env('COOKIE_AUTH_WEB_WECHAT'), '', -1);
  348. setcookie('u', '', -1);
  349. setcookie('force_show_qrcode', '', -1);
  350. setcookie('sub_random_num', '', -1);
  351. setcookie('cpc_ad_status', '', -1);
  352. //return response('logout');
  353. $param = $request->except('_url');
  354. $url_format = '%s://site%s.%s.com/logout?%s';
  355. if(in_array($domain,$domains)){
  356. $i = 0;
  357. foreach ($domains as $k=>$v){
  358. if($v == $domain){
  359. $i = $k;
  360. }
  361. }
  362. if(isset($domains[$i+1])){
  363. $link = sprintf($url_format,env('PROTOCOL'),$channel_id,$domains[$i+1],http_build_query($param)) ;
  364. return redirect()->to($link);
  365. }
  366. }
  367. return view('help.logout');
  368. }
  369. function setOrderDelCookie(Request $request){
  370. $param = $request->except('_url');
  371. $type = isset($param['type']) ?$param['type']:'set';
  372. foreach ($param as $k=>$v){
  373. if($k == 'type') continue;
  374. if($type == 'set'){
  375. Cookie::queue($k, $v, 1000, null, null, false, false);
  376. }else{
  377. setcookie($k, '', -1);
  378. }
  379. }
  380. return response('ok');
  381. }
  382. function test_add_user_login_cookie(Request $request)
  383. {
  384. $uid = $request->get('uid');
  385. \Log::info('test_add_user_login_cookie:'.$uid);
  386. Cookie::queue(env('COOKIE_AUTH_WEB_WECHAT'), $uid, env('U_COOKIE_EXPIRE'), null, null, false, false);
  387. return response('add_cookie:'.$uid);
  388. }
  389. //日常随机签到
  390. function day_rand_sign(Request $request)
  391. {
  392. $uid = $this->uid;
  393. $day = date('Y-m-d');
  394. $hasSigned = UserRandSignService::hasSigned(compact('uid','day'));
  395. $fee = 0;
  396. if(!$hasSigned)
  397. {
  398. $fee = mt_rand(5,15);
  399. UserRandSignService::sign(compact('uid','day','fee'));
  400. }
  401. return view('wap.rand_sign',compact('hasSigned','fee'));
  402. }
  403. private function bindTelephoneStatus(){
  404. }
  405. public function guidePersonalAccount(Request $request){
  406. //
  407. Log::info('in000000000000000000000000000');
  408. $img = redisEnv('GUIDE_PERSONAL_ACCOUNT_OURS_QRCODE');
  409. $bid = $request->get('bid');
  410. $cid = $request->get('cid');
  411. $book_name = $request->get('book_name');
  412. $bid_no = Hashids::decode($bid)[0];
  413. Log::info($bid);
  414. Log::info($cid);
  415. Log::info($bid_no);
  416. ForceGuidePersonAccountService::create($this->uid,$bid_no,$cid);
  417. $link = sprintf('/reader?bid=%s&cid=%s',$bid,$cid);
  418. return view('jump.forceGuidePersonalAccount',['img'=>$img,'link'=>$link,'title'=>$book_name]);
  419. }
  420. }