OrdersController.php 34 KB

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