OrdersController.php 37 KB

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