OrdersController.php 37 KB

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