OrdersController.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890
  1. <?php
  2. namespace App\Http\Controllers\Wap\Order;
  3. use App\Modules\Book\Services\BookGiftsService;
  4. use App\Modules\Subscribe\Models\Order;
  5. use App\Http\Controllers\Wap\BaseController;
  6. use App\Modules\Book\Services\BookConfigService;
  7. use App\Modules\Channel\Services\ChannelService;
  8. use App\Modules\Cpa\Services\AdvertiseUserQueueService;
  9. use App\Modules\Cpa\Services\AdvertiseUsersService;
  10. use App\Modules\OfficialAccount\Services\ForceSubscribeService;
  11. use App\Modules\Statistic\Services\AdVisitStatService;
  12. use App\Modules\Statistic\Services\DataAnalysisSelectUserService;
  13. use App\Modules\User\Services\ForceSubscribeUserIService;
  14. use App\Modules\User\Services\UserDivisionCpcPropertyService;
  15. use App\Modules\User\Services\UserDivisionPropertyService;
  16. use App\Modules\User\Services\UserGiftService;
  17. use App\Modules\User\Services\UserService;
  18. use App\Modules\Book\Services\BookService;
  19. use App\Modules\Channel\Services\PayTemplateService;
  20. use Illuminate\Http\Request;
  21. use App\Modules\Subscribe\Services\BookOrderService;
  22. use App\Modules\Subscribe\Services\ChapterOrderService;
  23. use App\Modules\Subscribe\Services\OrderService;
  24. use App\Http\Controllers\Wap\Order\Transformers\BookOrderTransformer;
  25. use App\Http\Controllers\Wap\Order\Transformers\ChapterOrderTransformer;
  26. use App\Http\Controllers\Wap\Order\Transformers\ChargeListTransformer;
  27. use Redis;
  28. use App\Modules\Product\Services\ProductService;
  29. use App\Modules\Subscribe\Services\SubstituteOrderService;
  30. use Hashids;
  31. use DB;
  32. use Cookie;
  33. class OrdersController extends BaseController
  34. {
  35. /**
  36. * @apiDefine Order 订单
  37. */
  38. private $force_subscribe_info;
  39. private $chargeList;
  40. /**
  41. * @apiVersion 1.0.0
  42. * @apiDescription 充值列表
  43. * @api {get} order/chargeList 充值列表
  44. * @apiGroup Order
  45. * @apiName chargeList
  46. * @apiSuccess {int} code 状态码
  47. * @apiSuccess {String} msg 信息
  48. * @apiSuccess {object} data 结果集
  49. * @apiSuccessExample {json} Success-Response:
  50. * HTTP/1.1 200 OK
  51. * {
  52. * code: 0,
  53. * msg: "",
  54. * data: [
  55. * {
  56. * product_id: 1,
  57. * price: "30.00元",
  58. * vip: 0,
  59. * intro: [
  60. * {
  61. * label: 3000,
  62. * important: false
  63. * },
  64. * {
  65. * label: "书币",
  66. * important: true
  67. * }
  68. * ]
  69. * },
  70. * {
  71. * product_id: 2,
  72. * price: "50.00元",
  73. * vip: 1,
  74. * intro: [
  75. * {
  76. * label: 5000,
  77. * important: false
  78. * },
  79. * {
  80. * label: "1000+",
  81. * important: true
  82. * },
  83. * {
  84. * label: "书币",
  85. * important: false
  86. * }
  87. * ]
  88. * },
  89. * {
  90. * product_id: 5,
  91. * price: "365.00元",
  92. * vip: 0,
  93. * intro: [
  94. * {
  95. * label: "年费VIP会员",
  96. * important: true
  97. * }
  98. * ]
  99. * }
  100. * ]
  101. * }
  102. */
  103. public function chargeList_(Request $request)
  104. {
  105. if (!$this->checkUid()) {
  106. return response()->error('WAP_NOT_LOGIN');
  107. }
  108. $res = ProductService::getChargeProduct();
  109. if (!$res->isEmpty()) {
  110. $data = [];
  111. /*if ($this->send_order_id) {
  112. try {
  113. Redis::sadd('pay_page_uv' . $this->send_order_id, $this->uid);
  114. Redis::sadd('pay_page_uv_send_order_ids', $this->send_order_id);
  115. } catch (\Exception $e) {
  116. }
  117. }*/
  118. foreach ($res as $v) {
  119. $intro = [];
  120. if ($v->given > 0 && $v->type == 'TICKET_RECHARGE') {
  121. $intro = [
  122. [
  123. 'label' => ($v->price * 100) . "+",
  124. 'important' => false,
  125. ],
  126. [
  127. 'label' => $v->given,
  128. 'important' => true,
  129. ],
  130. [
  131. 'label' => '书币',
  132. 'important' => false,
  133. ]
  134. ];
  135. $intro2 = [
  136. ['label' => '多送', 'important' => false],
  137. ['label' => (int)($v->given / 100), 'important' => true],
  138. ['label' => '元', 'important' => false],
  139. ];
  140. $v->vip = 0;
  141. }
  142. if ($v->given == 0 && $v->type == 'TICKET_RECHARGE') {
  143. $intro = [
  144. [
  145. 'label' => $v->price * 100,
  146. 'important' => false,
  147. ],
  148. [
  149. 'label' => '书币',
  150. 'important' => false,
  151. ]
  152. ];
  153. $v->vip = 0;
  154. $intro2 = [];
  155. }
  156. if ($v->given == 0 && $v->type == 'YEAR_ORDER') {
  157. $intro = [
  158. [
  159. 'label' => '年费VIP会员',
  160. 'important' => true,
  161. ]
  162. ];
  163. $v->vip = 1;
  164. $intro2 = [
  165. ['label' => '每天1元,全年免费看', 'important' => false],
  166. ];
  167. }
  168. $data[] = [
  169. 'product_id' => $v->id,
  170. 'price' => (int)$v->price . '元',
  171. 'vip' => $v->vip,
  172. 'intro' => $intro,
  173. 'intro2' => $intro2,
  174. 'is_default' => $v->is_default,
  175. ];
  176. }
  177. return response()->success($data);
  178. } else {
  179. return response()->error('WAP_SYS_ERROR');
  180. }
  181. }
  182. public function chargeList(Request $request)
  183. {
  184. if (!$this->checkUid()) {
  185. return response()->error('WAP_NOT_LOGIN');
  186. }
  187. $bid = $request->input('bid', '');
  188. $temp = $bid;
  189. $template_id = PayTemplateService::getPayTemplate($this->distribution_channel_id);
  190. $book_config = null;
  191. if ($bid) {
  192. $bid = Hashids::decode($bid)[0];
  193. $book_config = BookConfigService::getBookById($bid);
  194. }
  195. if ($template_id == 2) { //模板2只有在长篇小说过来的用户才显示
  196. //部分渠道需要2元模板不管哪个入口进来都展示
  197. $exclude_channels = explode(',', env('PRICE_TWO_SHOW_ALL_CHANNEL'));
  198. if (!in_array($this->distribution_channel_id, $exclude_channels)) {
  199. if ($book_config) {
  200. if ($book_config->charge_type == 'BOOK') $template_id = 1;
  201. }
  202. }
  203. }
  204. //男频站点 支付模板
  205. if (($male_site_template = $this->maleSite($this->distribution_channel_id))) {
  206. $template_id = $male_site_template;
  207. }
  208. /*if($book_config && $book_config->charge_type == 'BOOK'){
  209. if( ($compare_id = $this->templateCompareV3()) ){
  210. $template_id = $compare_id;
  211. }
  212. }*/
  213. /*if( ($compare_id = $this->templateCompare()) ){
  214. $template_id = $compare_id;
  215. }*/
  216. /*if( ($comparev2_id = $this->templateCompareV2()) ){
  217. $template_id = $comparev2_id;
  218. }
  219. $template_10_site = redisEnv('TEMPLATE_10_NO_AB_TEST_SITE','');
  220. if($template_10_site && in_array($this->distribution_channel_id,explode(',',$template_10_site)) ){
  221. $template_id = 10;
  222. }*/
  223. $outstandingYearOrder = $this->outstandingYearOrder($this->uid);
  224. $res = ProductService::getChargeProduct($template_id);
  225. if (!$res) {
  226. return response()->error('WAP_SYS_ERROR');
  227. }
  228. $this->chargeList = $res;
  229. $this->exchangeList();
  230. /*if ($this->send_order_id) {
  231. try {
  232. Redis::sadd('pay_page_uv' . $this->send_order_id, $this->uid);
  233. Redis::sadd('pay_page_uv_send_order_ids', $this->send_order_id);
  234. } catch (\Exception $e) {
  235. }
  236. }*/
  237. //TODO 长篇小数才有模板2
  238. //$user = $this->_user_info;
  239. $uid = $this->uid;
  240. $is_first_recharge = OrderService::judgeUserFirstRecharge($uid);
  241. $data = [];
  242. $appad = 0;
  243. $property = UserDivisionCpcPropertyService::getUserProperty($this->uid);
  244. foreach ($res as $v) {
  245. if ($template_id == 7 && $book_config && $book_config->charge_type == 'BOOK' && $v->price == 2) {
  246. continue;
  247. }
  248. if ($v->type == 'NEW_USER' && $is_first_recharge) {
  249. if (env('NO_NEW_USER_CHARGE') &&
  250. in_array(
  251. $this->distribution_channel_id,
  252. explode(',', env('NO_NEW_USER_CHARGE'))
  253. )
  254. ) {
  255. continue;
  256. }
  257. $temp = [
  258. 'price' => (float)$v->price . '元',
  259. 'is_year_order' => 0,
  260. 'is_month_order' => 0,
  261. 'text' => sprintf('%s+%s书币', $v->price * 100, $v->given),
  262. 'first_charge' => true,
  263. 'today_special' => false,
  264. 'save_text' => round($v->given / 100, 1) . '元',
  265. 'product_id' => $v->id,
  266. 'show_free_ads' => $appad,
  267. 'gift' => BookGiftsService::chargeGiveGift($property, $v->price, $v->type)
  268. ];
  269. $data[] = $temp;
  270. } elseif ($v->type == 'YEAR_ORDER') {
  271. if ($v->type == 'NEW_USER') {
  272. continue;
  273. }
  274. $save_text = '年费vip会员';
  275. $text = '每天1元,全年免费看';
  276. $temp = [
  277. 'price' => (int)$v->price . '元',
  278. 'is_year_order' => 1,
  279. 'is_month_order' => 0,
  280. 'text' => $text,
  281. 'first_charge' => false,
  282. 'today_special' => $outstandingYearOrder,
  283. 'save_text' => $save_text,
  284. 'product_id' => $v->id,
  285. 'show_free_ads' => $appad,
  286. 'gift' => BookGiftsService::chargeGiveGift($property, $v->price, $v->type)
  287. ];
  288. $data[] = $temp;
  289. } /*elseif ($v->type == 'MOUTH') {
  290. if (!$property) $property = 'low';
  291. if (in_array($this->distribution_channel_id, explode(',', redisEnv('INNER_SITES')))
  292. && in_array($property, ['low', 'medium'])
  293. ) {
  294. $data[] = [
  295. 'price' => (int)$v->price . '元',
  296. 'is_year_order' => 0,
  297. 'is_month_order' => 1,
  298. 'text' => sprintf('%s元包月 全站万本精彩小说免费看', (int)$v->price),
  299. 'first_charge' => false,
  300. 'today_special' => false,
  301. 'save_text' => '每月自动续费,可随时关闭',
  302. 'product_id' => $v->id,
  303. 'show_free_ads' => false,
  304. 'link' => generateMonthOrderUrl($this->uid),
  305. 'gift' => BookGiftsService::chargeGiveGift($property, $v->price, $v->type)
  306. ];
  307. } else {
  308. continue;
  309. }
  310. }*/ else {
  311. if ($v->type == 'NEW_USER') {
  312. continue;
  313. }
  314. $save_text = '';
  315. if ($v->given) {
  316. $save_text = round($v->given / 100, 1) . '元';
  317. $text = sprintf('%s+%s书币', $v->price * 100, $v->given);
  318. } else {
  319. $text = sprintf('%s书币', $v->price * 100);
  320. }
  321. $temp = [
  322. 'price' => (float)$v->price . '元',
  323. 'is_year_order' => 0,
  324. 'is_month_order' => 0,
  325. 'text' => $text,
  326. 'first_charge' => false,
  327. 'today_special' => ($v->is_default == 1 && $outstandingYearOrder == false) ? true : false,
  328. 'save_text' => $save_text,
  329. 'product_id' => $v->id,
  330. 'show_free_ads' => $appad,
  331. 'gift' => BookGiftsService::chargeGiveGift($property, $v->price, $v->type)
  332. ];
  333. $data[] = $temp;
  334. }
  335. }
  336. return response()->success($data);
  337. }
  338. public function substitutePayChargeList(Request $request)
  339. {
  340. $default = $request->get('product_id');
  341. if (!$this->checkUid()) {
  342. return response()->error('WAP_NOT_LOGIN');
  343. }
  344. $su = $request->get('su');
  345. $res = ProductService::getChargeProduct();
  346. if (!$res) {
  347. return response()->error('WAP_SYS_ERROR');
  348. }
  349. $is_can_allow_pay = 1;
  350. if ($su) {
  351. $su_user = UserService::getById($su);
  352. $now_user = $this->_user_info;
  353. if ($now_user && $su_user && $su_user->openid == $now_user->openid) {
  354. $is_can_allow_pay = 0;
  355. }
  356. }
  357. SubstituteOrderService::substitutePageUvPv($this->uid, $this->distribution_channel_id);
  358. $data = [];
  359. foreach ($res as $v) {
  360. if ($v->type == 'YEAR_ORDER') {
  361. $temp = [
  362. 'price' => (int)$v->price . '元',
  363. 'text' => '年费VIP会员',
  364. 'first_charge' => false,
  365. 'today_special' => $v->is_default == 1 ? true : false,
  366. 'save_text' => '全年免费',
  367. 'product_id' => $v->id,
  368. 'default' => false,
  369. 'is_vip' => 1,
  370. 'is_can_allow_pay' => $is_can_allow_pay
  371. ];
  372. if ($default) {
  373. if ($default == $v->id) {
  374. $temp['default'] = true;
  375. }
  376. } else {
  377. $temp['default'] = $v->is_default == 1 ? true : false;
  378. }
  379. $data[] = $temp;
  380. } else {
  381. $save_text = '';
  382. if ($v->given) {
  383. $save_text = round($v->given / 100, 1) . '元';
  384. $text = sprintf('%s+%s书币', $v->price * 100, $v->given);
  385. } else {
  386. $text = sprintf('%s书币', $v->price * 100);
  387. }
  388. $temp = [
  389. 'price' => (int)$v->price . '元',
  390. 'text' => $text,
  391. 'first_charge' => false,
  392. 'today_special' => $v->is_default == 1 ? true : false,
  393. 'save_text' => $save_text,
  394. 'product_id' => $v->id,
  395. 'default' => false,
  396. 'is_vip' => 0,
  397. 'is_can_allow_pay' => $is_can_allow_pay
  398. ];
  399. if ($default) {
  400. if ($default == $v->id) {
  401. $temp['default'] = true;
  402. }
  403. } else {
  404. $temp['default'] = $v->is_default == 1 ? true : false;
  405. }
  406. $data[] = $temp;
  407. }
  408. }
  409. return response()->success($data);
  410. }
  411. /**
  412. * @apiVersion 1.0.0
  413. * @apiDescription 单本消费记录
  414. * @api {get} order/bookOrderList 单本消费记录
  415. * @apiGroup Order
  416. * @apiName bookOrderList
  417. * @apiSuccess {int} code 状态码
  418. * @apiSuccess {String} msg 信息
  419. * @apiSuccess {object} data 结果集
  420. * @apiSuccess {Int} uid uid
  421. * @apiSuccess {Int} bid bid
  422. * @apiSuccess {Int} book_name 书名
  423. * @apiSuccess {Int} fee 钱
  424. * @apiSuccess {String} created_at 时间
  425. * @apiSuccessExample {json} Success-Response:
  426. * HTTP/1.1 200 OK
  427. * {
  428. * code: 0,
  429. * msg: "",
  430. * data: list:[
  431. * {
  432. * uid: 4,
  433. * bid: 1,
  434. * book_name: "dfsedfertrwet",
  435. * fee: 100,
  436. * created_at: "2017-12-02 16:24:54"
  437. * }
  438. * ]
  439. * meta: {
  440. * total: 1,
  441. * per_page: 15,
  442. * current_page: 1,
  443. * last_page: 1,
  444. * next_page_url: "",
  445. * prev_page_url: ""
  446. * }
  447. * }
  448. */
  449. public function bookOrderList(Request $request)
  450. {
  451. if (!$this->checkUid()) {
  452. return response()->error('WAP_NOT_LOGIN');
  453. }
  454. $page_size = $request->input('page_size', 15);
  455. $book_order = BookOrderService::getRecord($this->uid, $page_size);
  456. //$book_order = BookOrder::where('uid', $this->uid)->select('bid', 'uid', 'book_name', 'created_at', 'fee')->paginate($page_size);
  457. return response()->pagination(new BookOrderTransformer(), $book_order);
  458. }
  459. /**
  460. * @apiVersion 1.0.0
  461. * @apiDescription 章节消费记录
  462. * @api {get} order/chapterOrderList 章节消费记录
  463. * @apiGroup Order
  464. * @apiName chapterOrderList
  465. * @apiSuccess {int} code 状态码
  466. * @apiSuccess {String} msg 信息
  467. * @apiSuccess {object} data 结果集
  468. * @apiSuccess {Int} uid uid
  469. * @apiSuccess {Int} bid bid
  470. * @apiSuccess {Int} cid cid
  471. * @apiSuccess {Int} chapter_name 章节名
  472. * @apiSuccess {Int} book_name 书名
  473. * @apiSuccess {Int} fee 钱
  474. * @apiSuccess {String} created_at 时间
  475. * @apiSuccessExample {json} Success-Response:
  476. * HTTP/1.1 200 OK
  477. * {
  478. * code: 0,
  479. * msg: "",
  480. * data: list:[
  481. * {
  482. * uid: 4,
  483. * bid: 1,
  484. * cid: 1,
  485. * chapter_name: "sdfsd",
  486. * book_name: "dfsedfertrwet",
  487. * fee: 100,
  488. * created_at: "2017-12-02 16:24:54"
  489. * }
  490. * ]
  491. * meta: {
  492. * total: 1,
  493. * per_page: 15,
  494. * current_page: 1,
  495. * last_page: 1,
  496. * next_page_url: "",
  497. * prev_page_url: ""
  498. * }
  499. * }
  500. */
  501. public function chapterOrderList(Request $request)
  502. {
  503. if (!$this->checkUid()) {
  504. return response()->error('WAP_NOT_LOGIN');
  505. }
  506. $chapter_model = new ChapterOrderService();
  507. $page_size = $request->input('page_size', 15);
  508. $chapter_order = $chapter_model->getByUid($this->uid, $page_size);
  509. foreach ($chapter_order as $item) {
  510. if ($item->fee == 0) {
  511. $result = AdVisitStatService::getInfoV2($this->uid, $item->cid, ['UNLOCK', 'UNLOCK_2']);
  512. //if ($result)$item->fee = '解锁';
  513. $item->fee = '解锁';
  514. }
  515. }
  516. return response()->pagination(new ChapterOrderTransformer(), $chapter_order);
  517. }
  518. /**
  519. * @apiVersion 1.0.0
  520. * @apiDescription 充值记录
  521. * @api {get} order/chargeRecordLists 充值记录
  522. * @apiGroup Order
  523. * @apiName chargeRecordLists
  524. * @apiSuccess {int} code 状态码
  525. * @apiSuccess {String} msg 信息
  526. * @apiSuccess {object} data 结果集
  527. * @apiSuccess {String} data.price 价格
  528. * @apiSuccess {String} data.status 状态
  529. * @apiSuccess {String} data.trade_no 订单号
  530. * @apiSuccess {String} data.created_at 时间
  531. * @apiSuccessExample {json} Success-Response:
  532. * HTTP/1.1 200 OK
  533. * {
  534. * code: 0,
  535. * msg: "",
  536. * data: {
  537. * list: [
  538. * {
  539. * id: 134,
  540. * price: "1.00",
  541. * status: "PAID",
  542. * trade_no: "201712021915481585670623626232",
  543. * created_at: "2017-12-02 19:15:56"
  544. * }
  545. * ],
  546. * meta: {
  547. * total: 1,
  548. * per_page: 15,
  549. * current_page: 1,
  550. * last_page: 1,
  551. * next_page_url: "",
  552. * prev_page_url: ""
  553. * }
  554. * }
  555. * }
  556. */
  557. public function chargeRecordLists(Request $request)
  558. {
  559. $page_size = $request->input('page_size', 15);
  560. $res = OrderService::getOrderList($this->uid, $page_size);
  561. return response()->pagination(new ChargeListTransformer(), $res);
  562. }
  563. //订单是否成功
  564. public function isSuccess(Request $request)
  565. {
  566. $order = $request->input('order');
  567. $order_info = OrderService::getByTradeNo($order);
  568. if ($order_info && $order_info->status == 'PAID') {
  569. return response()->success();
  570. }
  571. return response()->error('WAP_SYS_ERROR');
  572. }
  573. public function substitutePay(Request $request)
  574. {
  575. if (!$this->checkUid()) {
  576. return response()->error('WAP_NOT_LOGIN');
  577. }
  578. $product_id = $request->get('product_id');
  579. SubstituteOrderService::substituteButtonUvPv($this->uid, $this->distribution_channel_id);
  580. $user = $this->_user_info;
  581. $data = [
  582. 'head_img' => '',
  583. 'nickname' => $user->nickname
  584. ];
  585. //$help_pay_page_channel_id = env('HELP_PAY_PAGE_CHANNEL_ID', 123);
  586. $help_pay_page_channel_id = $this->distribution_channel_id;
  587. $url_format = '%s://site%s.%s.com/helppay?%s';
  588. $param = [];
  589. $param['su'] = $this->uid;
  590. if ($product_id) {
  591. $param['product_id'] = $product_id;
  592. }
  593. $help_pay_page = sprintf(
  594. $url_format,
  595. env('PROTOCOL'),
  596. encodeDistributionChannelId($help_pay_page_channel_id),
  597. env('CUSTOM_HOST'),
  598. http_build_query($param)
  599. );
  600. $data['help_pay_page'] = $help_pay_page;
  601. return response()->success($data);
  602. }
  603. private function recordFirstIntoPayPage($bid)
  604. {
  605. $start_time = env('RECORD_FIRST_VISIT_PAY_PAGE_TIME');
  606. $template_id = 0;
  607. if (in_array($this->distribution_channel_id, [123, 211]) && $start_time && $this->uid) {
  608. $user = $this->_user_info;
  609. if (strtotime($user->created_at) > $start_time) {
  610. $old = DB::table('user_first_visit_pay_page')->where('uid', $this->uid)->select('uid', 'template_type')->first();
  611. if ($old) {
  612. $template_id = $old->template_type;
  613. if ($template_id) return $template_id;
  614. }
  615. if ($bid && $bid == 1148) {
  616. $template_id = $this->uid % 2 == 0 ? 2 : 1;
  617. if (empty($old)) {
  618. try {
  619. DB::table('user_first_visit_pay_page')->insert([
  620. 'uid' => $this->uid,
  621. 'template_type' => $template_id,
  622. 'created_at' => date('Y-m-d H:i:s'),
  623. 'updated_at' => date('Y-m-d H:i:s')
  624. ]);
  625. } catch (\Exception $e) {
  626. }
  627. }
  628. }
  629. }
  630. }
  631. return $template_id;
  632. }
  633. private function templateCompare()
  634. {
  635. //if(!in_array($this->distribution_channel_id,[2,14,211,155,4427,4488,256,691,146,255,722,4364,5,202,318,4237,266,196,273,4236,148,8,4241,160,271,4053,123,4334,4487,4593,695,4025,4426,4174])){
  636. /*$start_time = env('TEMPLATE_COMPARE_START_TIME_3',0);
  637. if(!$start_time){
  638. return 0;
  639. }*/
  640. if (!in_array($this->distribution_channel_id, [14, 123, 211, 5, 8, 160, 4236, 4237, 4241, 374, 243, 244, 245, 320, 321, 324, 337, 338, 538, 539, 751, 752, 753, 754, 4331, 4384, 4578, 4580, 4768, 4769, 4778, 130, 163, 164, 165, 166, 4126])) {
  641. return 0;
  642. }
  643. //$user = $this->_user_info;
  644. /*if(strtotime($user->created_at) < $start_time){
  645. return 0;
  646. }*/
  647. $template_id = 0;
  648. $user = DataAnalysisSelectUserService::getByUidAndType($this->uid, 'TEMPLATE_COMPARE_V3');
  649. if ($user) {
  650. $template_id = $user->attach;
  651. }
  652. return $template_id;
  653. }
  654. private function templateCompareV2()
  655. {
  656. $start_time = env('TEMPLATE_COMPARE_START_TIME', 0);
  657. if (!$start_time) {
  658. return 0;
  659. }
  660. $template_10_site = redisEnv('TEMPLATE_10_SITE', '');
  661. if (!$template_10_site) {
  662. return 0;
  663. }
  664. if (!in_array($this->distribution_channel_id, explode(',', $template_10_site))) {
  665. return 0;
  666. }
  667. $user = $this->_user_info;
  668. if (strtotime($user->created_at) < $start_time) {
  669. return 0;
  670. }
  671. $user = DataAnalysisSelectUserService::getByUidAndType($this->uid, 'TEMPLATE_COMPAREV10_2');
  672. if ($user) {
  673. return $user->attach;
  674. } else {
  675. if ($this->uid % 2 == 0) {
  676. DataAnalysisSelectUserService::create(
  677. $this->uid,
  678. $this->distribution_channel_id,
  679. 'TEMPLATE_COMPAREV10_2',
  680. -1, 10);
  681. return 10;
  682. } else {
  683. DataAnalysisSelectUserService::create(
  684. $this->uid,
  685. $this->distribution_channel_id,
  686. 'TEMPLATE_COMPAREV10',
  687. -1, 0);
  688. return 0;
  689. }
  690. }
  691. }
  692. //进入4593的心注册用户,若当前阅读的是短篇书籍,则根据注册id的奇偶分别进入AB两个充值模板。
  693. //测试3天(测试时长看数据分析组建议)后,分别统计两个模板下的用户数、付费用户数和充值总额.
  694. private function templateCompareV3()
  695. {
  696. $start_time = redisEnv('TEMPLATE_COMPARE_START_TIME', 0);
  697. if (!$start_time) {
  698. return 0;
  699. }
  700. $template_compare_sites = redisEnv('TEMPLATE_COMPARE_SITES', 0);
  701. if (!in_array($this->distribution_channel_id, explode(',', $template_compare_sites))) {
  702. return 0;
  703. }
  704. $user = $this->_user_info;
  705. if (strtotime($user->created_at) < $start_time) {
  706. return 0;
  707. }
  708. $user = DataAnalysisSelectUserService::getByUidAndType($this->uid, 'TEMPLATE_COMPAREV3');
  709. if ($user) {
  710. $template_id = $user->attach;
  711. } else {
  712. $template_id = $this->uid % 2 == 0 ? 1 : 9;
  713. DataAnalysisSelectUserService::create(
  714. $this->uid,
  715. $this->distribution_channel_id,
  716. 'TEMPLATE_COMPAREV3',
  717. -1, $template_id);
  718. }
  719. return $template_id;
  720. }
  721. private function maleSite($distribution_channel_id)
  722. {
  723. $info = ChannelService::getChannelCompanyInfo($distribution_channel_id);
  724. //\Log::info('maleSite info is:');
  725. //\Log::info($info);
  726. if ($info && isset($info->fans_gender)) {
  727. if ($info->fans_gender == 1) {
  728. return 1;
  729. }
  730. }
  731. return 0;
  732. }
  733. private function appad()
  734. {
  735. if ($this->force_subscribe_info) {
  736. $force_subscribe_info = $this->force_subscribe_info;
  737. } else {
  738. $force_subscribe_info = $this->force_subscribe_info = ForceSubscribeService::forceSubscribeUsersByUid(['uid' => $this->uid]);
  739. }
  740. if (!$force_subscribe_info) {
  741. return 0;
  742. }
  743. //\Log::info('force1:'.json_encode($force_subscribe_info));
  744. $force_sub_user_by_openid = ForceSubscribeUserIService::getForceSubscribeByUidOpenid($this->uid);
  745. if ($force_sub_user_by_openid) {
  746. $force_subscribe_info = $force_sub_user_by_openid;
  747. //\Log::info('force:'.json_encode($force_subscribe_info));
  748. }
  749. if ($force_subscribe_info->subscribe_time &&
  750. (time() - strtotime($force_subscribe_info->subscribe_time) >= 3 * 86400)
  751. && !OrderService::isPaidUserByOpenid($force_subscribe_info->openid) &&
  752. !AdvertiseUserQueueService::getUserAdvertise($this->uid) &&
  753. in_array($this->distribution_channel_id, explode(',', env('ADS_OPEN_SITE')))
  754. ) {
  755. return 1;
  756. }
  757. return 0;
  758. }
  759. private function outstandingYearOrder($uid)
  760. {
  761. /*if (!in_array($this->distribution_channel_id, explode(',', env('OUTSTANDING_YEAR_ORDER_SITE')))) {
  762. return false;
  763. }*/
  764. //$userDivisionProperty = UserDivisionPropertyService::getUserProperty($uid);
  765. $userDivisionProperty = UserDivisionCpcPropertyService::getUserProperty($uid);
  766. if (!$userDivisionProperty) return false;
  767. //if ($userDivisionProperty != 'high') return false;
  768. /*if ($uid % 2 == 0) {
  769. $is_show_outstanding_year_order = true;
  770. $template_id = 1;
  771. } else {
  772. $is_show_outstanding_year_order = false;
  773. $template_id = 2;
  774. }*/
  775. $exist = DataAnalysisSelectUserService::getByUidAndType($uid, 'OUTSTANDING_YEAR_ORDER_V2');
  776. if ($exist) return true;
  777. return false;
  778. /*DataAnalysisSelectUserService::create(
  779. $uid,
  780. $this->distribution_channel_id,
  781. 'OUTSTANDING_YEAR_ORDER_V2',
  782. -1, $template_id);
  783. return $is_show_outstanding_year_order;*/
  784. }
  785. public function exchangeList()
  786. {
  787. foreach ($this->chargeList as &$item) {
  788. if (!$item->switch_to) continue;
  789. $order = Order::where('uid', $this->uid)->where('status', 'PAID')->where('product_id', $item->id)->first();
  790. if ($order) {
  791. $change = ProductService::getProductSingle($item->switch_to);
  792. $item->id = $change->id;
  793. $item->price = $change->price;
  794. $item->given = $change->given;
  795. }
  796. }
  797. }
  798. public function monthPay(Request $request,$channel_id,$domain){
  799. \Log::info('monthPay url--------------');
  800. \Log::info($request->all());
  801. $from = $request->get('from_wxpay');
  802. if($from && $from == 1){
  803. //if()
  804. $source = Cookie::get('month_pay_redirect');
  805. if($source){
  806. $source = urldecode($source);
  807. }else{
  808. $source = '/person';
  809. }
  810. return redirect()->to($source);
  811. }
  812. $source = $request->get('redirect_url');
  813. if($source){
  814. Cookie::queue('month_pay_redirect',$source,600);
  815. }
  816. $url = generateMonthOrderUrl($this->uid);
  817. $h5_scheme = env('PROTOCOL', 'https');
  818. $refer = str_replace('http://', $h5_scheme . '://', url()->current());
  819. Log::info('$refer is :'.$refer);
  820. return redirect()->to($url)->withHeaders([
  821. 'Referer'=>$refer
  822. ]);
  823. }
  824. }