OrdersController.php 30 KB

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