OrdersController.php 33 KB

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