OrdersController.php 31 KB

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