OrdersController.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893
  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($template_id == 2 && $v->type == 'NEW_USER' && !$bid){
  249. //2元模版,直接进充值,不出现
  250. continue;
  251. }
  252. if ($v->type == 'NEW_USER' && $is_first_recharge) {
  253. if (env('NO_NEW_USER_CHARGE') &&
  254. in_array(
  255. $this->distribution_channel_id,
  256. explode(',', env('NO_NEW_USER_CHARGE'))
  257. )
  258. ) {
  259. continue;
  260. }
  261. $temp = [
  262. 'price' => (float)$v->price . '元',
  263. 'is_year_order' => 0,
  264. 'is_month_order' => 0,
  265. 'text' => sprintf('%s+%s书币', $v->price * 100, $v->given),
  266. 'first_charge' => true,
  267. 'today_special' => false,
  268. 'save_text' => round($v->given / 100, 1) . '元',
  269. 'product_id' => $v->id,
  270. 'show_free_ads' => $appad,
  271. 'gift' => BookGiftsService::chargeGiveGift($property, $v->price, $v->type)
  272. ];
  273. $data[] = $temp;
  274. } elseif ($v->type == 'YEAR_ORDER') {
  275. if ($v->type == 'NEW_USER') {
  276. continue;
  277. }
  278. $save_text = '年费vip会员';
  279. $text = '每天1元,全年免费看';
  280. $temp = [
  281. 'price' => (int)$v->price . '元',
  282. 'is_year_order' => 1,
  283. 'is_month_order' => 0,
  284. 'text' => $text,
  285. 'first_charge' => false,
  286. 'today_special' => $outstandingYearOrder,
  287. 'save_text' => $save_text,
  288. 'product_id' => $v->id,
  289. 'show_free_ads' => $appad,
  290. 'gift' => BookGiftsService::chargeGiveGift($property, $v->price, $v->type)
  291. ];
  292. $data[] = $temp;
  293. } /*elseif ($v->type == 'MOUTH') {
  294. if (!$property) $property = 'low';
  295. if (in_array($this->distribution_channel_id, explode(',', redisEnv('INNER_SITES')))
  296. && in_array($property, ['low', 'medium'])
  297. ) {
  298. $data[] = [
  299. 'price' => (int)$v->price . '元',
  300. 'is_year_order' => 0,
  301. 'is_month_order' => 1,
  302. 'text' => sprintf('%s元包月 全站万本精彩小说免费看', (int)$v->price),
  303. 'first_charge' => false,
  304. 'today_special' => false,
  305. 'save_text' => '每月自动续费,可随时关闭',
  306. 'product_id' => $v->id,
  307. 'show_free_ads' => false,
  308. 'link' => generateMonthOrderUrl($this->uid),
  309. 'gift' => BookGiftsService::chargeGiveGift($property, $v->price, $v->type)
  310. ];
  311. } else {
  312. continue;
  313. }
  314. }*/ else {
  315. if ($v->type == 'NEW_USER') {
  316. continue;
  317. }
  318. $save_text = '';
  319. if ($v->given) {
  320. $save_text = round($v->given / 100, 1) . '元';
  321. $text = sprintf('%s+%s书币', $v->price * 100, $v->given);
  322. } else {
  323. $text = sprintf('%s书币', $v->price * 100);
  324. }
  325. $temp = [
  326. 'price' => (float)$v->price . '元',
  327. 'is_year_order' => 0,
  328. 'is_month_order' => 0,
  329. 'text' => $text,
  330. 'first_charge' => false,
  331. 'today_special' => ($v->is_default == 1 && $outstandingYearOrder == false) ? true : false,
  332. 'save_text' => $save_text,
  333. 'product_id' => $v->id,
  334. 'show_free_ads' => $appad,
  335. 'gift' => BookGiftsService::chargeGiveGift($property, $v->price, $v->type)
  336. ];
  337. $data[] = $temp;
  338. }
  339. }
  340. return response()->success($data);
  341. }
  342. public function substitutePayChargeList(Request $request)
  343. {
  344. $default = $request->get('product_id');
  345. if (!$this->checkUid()) {
  346. return response()->error('WAP_NOT_LOGIN');
  347. }
  348. $su = $request->get('su');
  349. $res = ProductService::getChargeProduct();
  350. if (!$res) {
  351. return response()->error('WAP_SYS_ERROR');
  352. }
  353. $is_can_allow_pay = 1;
  354. if ($su) {
  355. $su_user = UserService::getById($su);
  356. $now_user = $this->_user_info;
  357. if ($now_user && $su_user && $su_user->openid == $now_user->openid) {
  358. $is_can_allow_pay = 0;
  359. }
  360. }
  361. SubstituteOrderService::substitutePageUvPv($this->uid, $this->distribution_channel_id);
  362. $data = [];
  363. foreach ($res as $v) {
  364. if ($v->type == 'YEAR_ORDER') {
  365. $temp = [
  366. 'price' => (int)$v->price . '元',
  367. 'text' => '年费VIP会员',
  368. 'first_charge' => false,
  369. 'today_special' => $v->is_default == 1 ? true : false,
  370. 'save_text' => '全年免费',
  371. 'product_id' => $v->id,
  372. 'default' => false,
  373. 'is_vip' => 1,
  374. 'is_can_allow_pay' => $is_can_allow_pay
  375. ];
  376. if ($default) {
  377. if ($default == $v->id) {
  378. $temp['default'] = true;
  379. }
  380. } else {
  381. $temp['default'] = $v->is_default == 1 ? true : false;
  382. }
  383. $data[] = $temp;
  384. } else {
  385. $save_text = '';
  386. if ($v->given) {
  387. $save_text = round($v->given / 100, 1) . '元';
  388. $text = sprintf('%s+%s书币', $v->price * 100, $v->given);
  389. } else {
  390. $text = sprintf('%s书币', $v->price * 100);
  391. }
  392. $temp = [
  393. 'price' => (int)$v->price . '元',
  394. 'text' => $text,
  395. 'first_charge' => false,
  396. 'today_special' => $v->is_default == 1 ? true : false,
  397. 'save_text' => $save_text,
  398. 'product_id' => $v->id,
  399. 'default' => false,
  400. 'is_vip' => 0,
  401. 'is_can_allow_pay' => $is_can_allow_pay
  402. ];
  403. if ($default) {
  404. if ($default == $v->id) {
  405. $temp['default'] = true;
  406. }
  407. } else {
  408. $temp['default'] = $v->is_default == 1 ? true : false;
  409. }
  410. $data[] = $temp;
  411. }
  412. }
  413. return response()->success($data);
  414. }
  415. /**
  416. * @apiVersion 1.0.0
  417. * @apiDescription 单本消费记录
  418. * @api {get} order/bookOrderList 单本消费记录
  419. * @apiGroup Order
  420. * @apiName bookOrderList
  421. * @apiSuccess {int} code 状态码
  422. * @apiSuccess {String} msg 信息
  423. * @apiSuccess {object} data 结果集
  424. * @apiSuccess {Int} uid uid
  425. * @apiSuccess {Int} bid bid
  426. * @apiSuccess {Int} book_name 书名
  427. * @apiSuccess {Int} fee 钱
  428. * @apiSuccess {String} created_at 时间
  429. * @apiSuccessExample {json} Success-Response:
  430. * HTTP/1.1 200 OK
  431. * {
  432. * code: 0,
  433. * msg: "",
  434. * data: list:[
  435. * {
  436. * uid: 4,
  437. * bid: 1,
  438. * book_name: "dfsedfertrwet",
  439. * fee: 100,
  440. * created_at: "2017-12-02 16:24:54"
  441. * }
  442. * ]
  443. * meta: {
  444. * total: 1,
  445. * per_page: 15,
  446. * current_page: 1,
  447. * last_page: 1,
  448. * next_page_url: "",
  449. * prev_page_url: ""
  450. * }
  451. * }
  452. */
  453. public function bookOrderList(Request $request)
  454. {
  455. if (!$this->checkUid()) {
  456. return response()->error('WAP_NOT_LOGIN');
  457. }
  458. $page_size = $request->input('page_size', 15);
  459. $book_order = BookOrderService::getRecord($this->uid, $page_size);
  460. //$book_order = BookOrder::where('uid', $this->uid)->select('bid', 'uid', 'book_name', 'created_at', 'fee')->paginate($page_size);
  461. return response()->pagination(new BookOrderTransformer(), $book_order);
  462. }
  463. /**
  464. * @apiVersion 1.0.0
  465. * @apiDescription 章节消费记录
  466. * @api {get} order/chapterOrderList 章节消费记录
  467. * @apiGroup Order
  468. * @apiName chapterOrderList
  469. * @apiSuccess {int} code 状态码
  470. * @apiSuccess {String} msg 信息
  471. * @apiSuccess {object} data 结果集
  472. * @apiSuccess {Int} uid uid
  473. * @apiSuccess {Int} bid bid
  474. * @apiSuccess {Int} cid cid
  475. * @apiSuccess {Int} chapter_name 章节名
  476. * @apiSuccess {Int} book_name 书名
  477. * @apiSuccess {Int} fee 钱
  478. * @apiSuccess {String} created_at 时间
  479. * @apiSuccessExample {json} Success-Response:
  480. * HTTP/1.1 200 OK
  481. * {
  482. * code: 0,
  483. * msg: "",
  484. * data: list:[
  485. * {
  486. * uid: 4,
  487. * bid: 1,
  488. * cid: 1,
  489. * chapter_name: "sdfsd",
  490. * book_name: "dfsedfertrwet",
  491. * fee: 100,
  492. * created_at: "2017-12-02 16:24:54"
  493. * }
  494. * ]
  495. * meta: {
  496. * total: 1,
  497. * per_page: 15,
  498. * current_page: 1,
  499. * last_page: 1,
  500. * next_page_url: "",
  501. * prev_page_url: ""
  502. * }
  503. * }
  504. */
  505. public function chapterOrderList(Request $request)
  506. {
  507. if (!$this->checkUid()) {
  508. return response()->error('WAP_NOT_LOGIN');
  509. }
  510. $chapter_model = new ChapterOrderService();
  511. $page_size = $request->input('page_size', 15);
  512. $chapter_order = $chapter_model->getByUid($this->uid, $page_size);
  513. foreach ($chapter_order as $item) {
  514. if ($item->fee == 0) {
  515. $result = AdVisitStatService::getInfoV2($this->uid, $item->cid, ['UNLOCK', 'UNLOCK_2']);
  516. //if ($result)$item->fee = '解锁';
  517. $item->fee = '解锁';
  518. }
  519. }
  520. return response()->pagination(new ChapterOrderTransformer(), $chapter_order);
  521. }
  522. /**
  523. * @apiVersion 1.0.0
  524. * @apiDescription 充值记录
  525. * @api {get} order/chargeRecordLists 充值记录
  526. * @apiGroup Order
  527. * @apiName chargeRecordLists
  528. * @apiSuccess {int} code 状态码
  529. * @apiSuccess {String} msg 信息
  530. * @apiSuccess {object} data 结果集
  531. * @apiSuccess {String} data.price 价格
  532. * @apiSuccess {String} data.status 状态
  533. * @apiSuccess {String} data.trade_no 订单号
  534. * @apiSuccess {String} data.created_at 时间
  535. * @apiSuccessExample {json} Success-Response:
  536. * HTTP/1.1 200 OK
  537. * {
  538. * code: 0,
  539. * msg: "",
  540. * data: {
  541. * list: [
  542. * {
  543. * id: 134,
  544. * price: "1.00",
  545. * status: "PAID",
  546. * trade_no: "201712021915481585670623626232",
  547. * created_at: "2017-12-02 19:15:56"
  548. * }
  549. * ],
  550. * meta: {
  551. * total: 1,
  552. * per_page: 15,
  553. * current_page: 1,
  554. * last_page: 1,
  555. * next_page_url: "",
  556. * prev_page_url: ""
  557. * }
  558. * }
  559. * }
  560. */
  561. public function chargeRecordLists(Request $request)
  562. {
  563. $page_size = $request->input('page_size', 15);
  564. $res = OrderService::getOrderList($this->uid, $page_size);
  565. return response()->pagination(new ChargeListTransformer(), $res);
  566. }
  567. //订单是否成功
  568. public function isSuccess(Request $request)
  569. {
  570. $order = $request->input('order');
  571. $order_info = OrderService::getByTradeNo($order);
  572. if ($order_info && $order_info->status == 'PAID') {
  573. return response()->success();
  574. }
  575. return response()->error('WAP_SYS_ERROR');
  576. }
  577. public function substitutePay(Request $request)
  578. {
  579. if (!$this->checkUid()) {
  580. return response()->error('WAP_NOT_LOGIN');
  581. }
  582. $product_id = $request->get('product_id');
  583. SubstituteOrderService::substituteButtonUvPv($this->uid, $this->distribution_channel_id);
  584. $user = $this->_user_info;
  585. $data = [
  586. 'head_img' => '',
  587. 'nickname' => $user->nickname
  588. ];
  589. //$help_pay_page_channel_id = env('HELP_PAY_PAGE_CHANNEL_ID', 123);
  590. $help_pay_page_channel_id = $this->distribution_channel_id;
  591. $url_format = '%s://site%s.%s.com/helppay?%s';
  592. $param = [];
  593. $param['su'] = $this->uid;
  594. if ($product_id) {
  595. $param['product_id'] = $product_id;
  596. }
  597. $help_pay_page = sprintf(
  598. $url_format,
  599. env('PROTOCOL'),
  600. encodeDistributionChannelId($help_pay_page_channel_id),
  601. env('CUSTOM_HOST'),
  602. http_build_query($param)
  603. );
  604. $data['help_pay_page'] = $help_pay_page;
  605. return response()->success($data);
  606. }
  607. private function recordFirstIntoPayPage($bid)
  608. {
  609. $start_time = env('RECORD_FIRST_VISIT_PAY_PAGE_TIME');
  610. $template_id = 0;
  611. if (in_array($this->distribution_channel_id, [123, 211]) && $start_time && $this->uid) {
  612. $user = $this->_user_info;
  613. if (strtotime($user->created_at) > $start_time) {
  614. $old = DB::table('user_first_visit_pay_page')->where('uid', $this->uid)->select('uid', 'template_type')->first();
  615. if ($old) {
  616. $template_id = $old->template_type;
  617. if ($template_id) return $template_id;
  618. }
  619. if ($bid && $bid == 1148) {
  620. $template_id = $this->uid % 2 == 0 ? 2 : 1;
  621. if (empty($old)) {
  622. try {
  623. DB::table('user_first_visit_pay_page')->insert([
  624. 'uid' => $this->uid,
  625. 'template_type' => $template_id,
  626. 'created_at' => date('Y-m-d H:i:s'),
  627. 'updated_at' => date('Y-m-d H:i:s')
  628. ]);
  629. } catch (\Exception $e) {
  630. }
  631. }
  632. }
  633. }
  634. }
  635. return $template_id;
  636. }
  637. private function templateCompare()
  638. {
  639. //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])){
  640. /*$start_time = env('TEMPLATE_COMPARE_START_TIME_3',0);
  641. if(!$start_time){
  642. return 0;
  643. }*/
  644. 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])) {
  645. return 0;
  646. }
  647. //$user = $this->_user_info;
  648. /*if(strtotime($user->created_at) < $start_time){
  649. return 0;
  650. }*/
  651. $template_id = 0;
  652. $user = DataAnalysisSelectUserService::getByUidAndType($this->uid, 'TEMPLATE_COMPARE_V3');
  653. if ($user) {
  654. $template_id = $user->attach;
  655. }
  656. return $template_id;
  657. }
  658. private function templateCompareV2()
  659. {
  660. $start_time = env('TEMPLATE_COMPARE_START_TIME', 0);
  661. if (!$start_time) {
  662. return 0;
  663. }
  664. $template_10_site = redisEnv('TEMPLATE_10_SITE', '');
  665. if (!$template_10_site) {
  666. return 0;
  667. }
  668. if (!in_array($this->distribution_channel_id, explode(',', $template_10_site))) {
  669. return 0;
  670. }
  671. $user = $this->_user_info;
  672. if (strtotime($user->created_at) < $start_time) {
  673. return 0;
  674. }
  675. $user = DataAnalysisSelectUserService::getByUidAndType($this->uid, 'TEMPLATE_COMPAREV10_2');
  676. if ($user) {
  677. return $user->attach;
  678. } else {
  679. if ($this->uid % 2 == 0) {
  680. DataAnalysisSelectUserService::create(
  681. $this->uid,
  682. $this->distribution_channel_id,
  683. 'TEMPLATE_COMPAREV10_2',
  684. -1, 10);
  685. return 10;
  686. } else {
  687. DataAnalysisSelectUserService::create(
  688. $this->uid,
  689. $this->distribution_channel_id,
  690. 'TEMPLATE_COMPAREV10',
  691. -1, 0);
  692. return 0;
  693. }
  694. }
  695. }
  696. //进入4593的心注册用户,若当前阅读的是短篇书籍,则根据注册id的奇偶分别进入AB两个充值模板。
  697. //测试3天(测试时长看数据分析组建议)后,分别统计两个模板下的用户数、付费用户数和充值总额.
  698. private function templateCompareV3()
  699. {
  700. $start_time = redisEnv('TEMPLATE_COMPARE_START_TIME', 0);
  701. if (!$start_time) {
  702. return 0;
  703. }
  704. $template_compare_sites = redisEnv('TEMPLATE_COMPARE_SITES', 0);
  705. if (!in_array($this->distribution_channel_id, explode(',', $template_compare_sites))) {
  706. return 0;
  707. }
  708. $user = $this->_user_info;
  709. if (strtotime($user->created_at) < $start_time) {
  710. return 0;
  711. }
  712. $user = DataAnalysisSelectUserService::getByUidAndType($this->uid, 'TEMPLATE_COMPAREV3');
  713. if ($user) {
  714. $template_id = $user->attach;
  715. } else {
  716. $template_id = $this->uid % 2 == 0 ? 1 : 9;
  717. DataAnalysisSelectUserService::create(
  718. $this->uid,
  719. $this->distribution_channel_id,
  720. 'TEMPLATE_COMPAREV3',
  721. -1, $template_id);
  722. }
  723. return $template_id;
  724. }
  725. private function maleSite($distribution_channel_id)
  726. {
  727. $info = ChannelService::getChannelCompanyInfo($distribution_channel_id);
  728. //\Log::info('maleSite info is:');
  729. //\Log::info($info);
  730. if ($info && isset($info->fans_gender)) {
  731. if ($info->fans_gender == 1) {
  732. return 1;
  733. }
  734. }
  735. return 0;
  736. }
  737. private function appad()
  738. {
  739. if ($this->force_subscribe_info) {
  740. $force_subscribe_info = $this->force_subscribe_info;
  741. } else {
  742. $force_subscribe_info = $this->force_subscribe_info = ForceSubscribeService::forceSubscribeUsersByUid(['uid' => $this->uid]);
  743. }
  744. if (!$force_subscribe_info) {
  745. return 0;
  746. }
  747. //\Log::info('force1:'.json_encode($force_subscribe_info));
  748. $force_sub_user_by_openid = ForceSubscribeUserIService::getForceSubscribeByUidOpenid($this->uid);
  749. if ($force_sub_user_by_openid) {
  750. $force_subscribe_info = $force_sub_user_by_openid;
  751. //\Log::info('force:'.json_encode($force_subscribe_info));
  752. }
  753. if ($force_subscribe_info->subscribe_time &&
  754. (time() - strtotime($force_subscribe_info->subscribe_time) >= 3 * 86400)
  755. && !OrderService::isPaidUserByOpenid($force_subscribe_info->openid) &&
  756. !AdvertiseUserQueueService::getUserAdvertise($this->uid) &&
  757. in_array($this->distribution_channel_id, explode(',', env('ADS_OPEN_SITE')))
  758. ) {
  759. return 1;
  760. }
  761. return 0;
  762. }
  763. private function outstandingYearOrder($uid)
  764. {
  765. /*if (!in_array($this->distribution_channel_id, explode(',', env('OUTSTANDING_YEAR_ORDER_SITE')))) {
  766. return false;
  767. }*/
  768. //$userDivisionProperty = UserDivisionPropertyService::getUserProperty($uid);
  769. $userDivisionProperty = UserDivisionCpcPropertyService::getUserProperty($uid);
  770. if (!$userDivisionProperty) return false;
  771. //if ($userDivisionProperty != 'high') return false;
  772. /*if ($uid % 2 == 0) {
  773. $is_show_outstanding_year_order = true;
  774. $template_id = 1;
  775. } else {
  776. $is_show_outstanding_year_order = false;
  777. $template_id = 2;
  778. }*/
  779. $exist = DataAnalysisSelectUserService::getByUidAndType($uid, 'OUTSTANDING_YEAR_ORDER_V2');
  780. if ($exist) return true;
  781. return false;
  782. /*DataAnalysisSelectUserService::create(
  783. $uid,
  784. $this->distribution_channel_id,
  785. 'OUTSTANDING_YEAR_ORDER_V2',
  786. -1, $template_id);
  787. return $is_show_outstanding_year_order;*/
  788. }
  789. public function exchangeList()
  790. {
  791. foreach ($this->chargeList as &$item) {
  792. if (!$item->switch_to) continue;
  793. $order = Order::where('uid', $this->uid)->where('status', 'PAID')->where('product_id', $item->id)->first();
  794. if ($order) {
  795. $change = ProductService::getProductSingle($item->switch_to);
  796. $item->id = $change->id;
  797. $item->price = $change->price;
  798. $item->given = $change->given;
  799. }
  800. }
  801. }
  802. /*public function monthPay(Request $request,$channel_id,$domain){
  803. \Log::info('monthPay url--------------');
  804. \Log::info($request->all());
  805. $from = $request->get('from_wxpay');
  806. if($from && $from == 1){
  807. //if()
  808. $source = Cookie::get('month_pay_redirect');
  809. if($source){
  810. $source = urldecode($source);
  811. }else{
  812. $source = '/person';
  813. }
  814. return redirect()->to($source);
  815. }
  816. $source = $request->get('redirect_url');
  817. if($source){
  818. Cookie::queue('month_pay_redirect',$source,600);
  819. }
  820. $url = generateMonthOrderUrl($this->uid);
  821. $h5_scheme = env('PROTOCOL', 'https');
  822. $refer = str_replace('http://', $h5_scheme . '://', url()->current());
  823. \Log::info('$refer is :'.$refer);
  824. return redirect()->to($url)->withHeaders([
  825. 'Referer'=>$refer
  826. ]);
  827. }*/
  828. }