OrdersController.php 36 KB

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