OrdersController.php 31 KB

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