OrdersController.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839
  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. }
  511. }
  512. return response()->pagination(new ChapterOrderTransformer(), $chapter_order);
  513. }
  514. /**
  515. * @apiVersion 1.0.0
  516. * @apiDescription 充值记录
  517. * @api {get} order/chargeRecordLists 充值记录
  518. * @apiGroup Order
  519. * @apiName chargeRecordLists
  520. * @apiSuccess {int} code 状态码
  521. * @apiSuccess {String} msg 信息
  522. * @apiSuccess {object} data 结果集
  523. * @apiSuccess {String} data.price 价格
  524. * @apiSuccess {String} data.status 状态
  525. * @apiSuccess {String} data.trade_no 订单号
  526. * @apiSuccess {String} data.created_at 时间
  527. * @apiSuccessExample {json} Success-Response:
  528. * HTTP/1.1 200 OK
  529. * {
  530. * code: 0,
  531. * msg: "",
  532. * data: {
  533. * list: [
  534. * {
  535. * id: 134,
  536. * price: "1.00",
  537. * status: "PAID",
  538. * trade_no: "201712021915481585670623626232",
  539. * created_at: "2017-12-02 19:15:56"
  540. * }
  541. * ],
  542. * meta: {
  543. * total: 1,
  544. * per_page: 15,
  545. * current_page: 1,
  546. * last_page: 1,
  547. * next_page_url: "",
  548. * prev_page_url: ""
  549. * }
  550. * }
  551. * }
  552. */
  553. public function chargeRecordLists(Request $request)
  554. {
  555. $page_size = $request->input('page_size', 15);
  556. $res = OrderService::getOrderList($this->uid, $page_size);
  557. return response()->pagination(new ChargeListTransformer(), $res);
  558. }
  559. //订单是否成功
  560. public function isSuccess(Request $request)
  561. {
  562. $order = $request->input('order');
  563. $order_info = OrderService::getByTradeNo($order);
  564. if ($order_info && $order_info->status == 'PAID') {
  565. return response()->success();
  566. }
  567. return response()->error('WAP_SYS_ERROR');
  568. }
  569. public function substitutePay(Request $request)
  570. {
  571. if (!$this->checkUid()) {
  572. return response()->error('WAP_NOT_LOGIN');
  573. }
  574. $product_id = $request->get('product_id');
  575. SubstituteOrderService::substituteButtonUvPv($this->uid, $this->distribution_channel_id);
  576. $user = $this->_user_info;
  577. $data = [
  578. 'head_img' => '',
  579. 'nickname' => $user->nickname
  580. ];
  581. //$help_pay_page_channel_id = env('HELP_PAY_PAGE_CHANNEL_ID', 123);
  582. $help_pay_page_channel_id = $this->distribution_channel_id;
  583. $url_format = '%s://site%s.%s.com/helppay?%s';
  584. $param = [];
  585. $param['su'] = $this->uid;
  586. if ($product_id) {
  587. $param['product_id'] = $product_id;
  588. }
  589. $help_pay_page = sprintf(
  590. $url_format,
  591. env('PROTOCOL'),
  592. encodeDistributionChannelId($help_pay_page_channel_id),
  593. env('CUSTOM_HOST'),
  594. http_build_query($param)
  595. );
  596. $data['help_pay_page'] = $help_pay_page;
  597. return response()->success($data);
  598. }
  599. private function recordFirstIntoPayPage($bid)
  600. {
  601. $start_time = env('RECORD_FIRST_VISIT_PAY_PAGE_TIME');
  602. $template_id = 0;
  603. if (in_array($this->distribution_channel_id, [123, 211]) && $start_time && $this->uid) {
  604. $user = $this->_user_info;
  605. if (strtotime($user->created_at) > $start_time) {
  606. $old = DB::table('user_first_visit_pay_page')->where('uid', $this->uid)->select('uid', 'template_type')->first();
  607. if ($old) {
  608. $template_id = $old->template_type;
  609. if ($template_id) return $template_id;
  610. }
  611. if ($bid && $bid == 1148) {
  612. $template_id = $this->uid % 2 == 0 ? 2 : 1;
  613. if (empty($old)) {
  614. try {
  615. DB::table('user_first_visit_pay_page')->insert([
  616. 'uid' => $this->uid,
  617. 'template_type' => $template_id,
  618. 'created_at' => date('Y-m-d H:i:s'),
  619. 'updated_at' => date('Y-m-d H:i:s')
  620. ]);
  621. } catch (\Exception $e) {
  622. }
  623. }
  624. }
  625. }
  626. }
  627. return $template_id;
  628. }
  629. private function templateCompare()
  630. {
  631. //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])){
  632. /*$start_time = env('TEMPLATE_COMPARE_START_TIME_3',0);
  633. if(!$start_time){
  634. return 0;
  635. }*/
  636. 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])) {
  637. return 0;
  638. }
  639. //$user = $this->_user_info;
  640. /*if(strtotime($user->created_at) < $start_time){
  641. return 0;
  642. }*/
  643. $template_id = 0;
  644. $user = DataAnalysisSelectUserService::getByUidAndType($this->uid, 'TEMPLATE_COMPARE_V3');
  645. if ($user) {
  646. $template_id = $user->attach;
  647. }
  648. return $template_id;
  649. }
  650. private function templateCompareV2()
  651. {
  652. $start_time = env('TEMPLATE_COMPARE_START_TIME', 0);
  653. if (!$start_time) {
  654. return 0;
  655. }
  656. if (!in_array($this->distribution_channel_id, [2, 146, 155, 255, 256, 691, 722, 4364, 695, 4174, 4025, 4593, 4426, 4742, 4053, 4334, 4487])) {
  657. return 0;
  658. }
  659. $user = $this->_user_info;
  660. if (strtotime($user->created_at) < $start_time) {
  661. return 0;
  662. }
  663. $user = DataAnalysisSelectUserService::getByUidAndType($this->uid, 'TEMPLATE_COMPAREV2');
  664. if ($user) {
  665. $template_id = $user->attach;
  666. } else {
  667. $template_id = $this->uid % 2 == 0 ? 1 : 6;
  668. DataAnalysisSelectUserService::create(
  669. $this->uid,
  670. $this->distribution_channel_id,
  671. 'TEMPLATE_COMPAREV2',
  672. -1, $template_id);
  673. }
  674. return $template_id;
  675. }
  676. //进入4593的心注册用户,若当前阅读的是短篇书籍,则根据注册id的奇偶分别进入AB两个充值模板。
  677. //测试3天(测试时长看数据分析组建议)后,分别统计两个模板下的用户数、付费用户数和充值总额.
  678. private function templateCompareV3()
  679. {
  680. $start_time = redisEnv('TEMPLATE_COMPARE_START_TIME', 0);
  681. if (!$start_time) {
  682. return 0;
  683. }
  684. $template_compare_sites = redisEnv('TEMPLATE_COMPARE_SITES',0);
  685. if (!in_array($this->distribution_channel_id, explode(',',$template_compare_sites))) {
  686. return 0;
  687. }
  688. $user = $this->_user_info;
  689. if (strtotime($user->created_at) < $start_time) {
  690. return 0;
  691. }
  692. $user = DataAnalysisSelectUserService::getByUidAndType($this->uid, 'TEMPLATE_COMPAREV3');
  693. if ($user) {
  694. $template_id = $user->attach;
  695. } else {
  696. $template_id = $this->uid % 2 == 0 ? 1 : 9;
  697. DataAnalysisSelectUserService::create(
  698. $this->uid,
  699. $this->distribution_channel_id,
  700. 'TEMPLATE_COMPAREV3',
  701. -1, $template_id);
  702. }
  703. return $template_id;
  704. }
  705. private function maleSite($distribution_channel_id)
  706. {
  707. $info = ChannelService::getChannelCompanyInfo($distribution_channel_id);
  708. //\Log::info('maleSite info is:');
  709. //\Log::info($info);
  710. if ($info && isset($info->fans_gender)) {
  711. if ($info->fans_gender == 1) {
  712. return 1;
  713. }
  714. }
  715. return 0;
  716. }
  717. private function appad()
  718. {
  719. if ($this->force_subscribe_info) {
  720. $force_subscribe_info = $this->force_subscribe_info;
  721. } else {
  722. $force_subscribe_info = $this->force_subscribe_info = ForceSubscribeService::forceSubscribeUsersByUid(['uid' => $this->uid]);
  723. }
  724. if (!$force_subscribe_info) {
  725. return 0;
  726. }
  727. //\Log::info('force1:'.json_encode($force_subscribe_info));
  728. $force_sub_user_by_openid = ForceSubscribeUserIService::getForceSubscribeByUidOpenid($this->uid);
  729. if ($force_sub_user_by_openid) {
  730. $force_subscribe_info = $force_sub_user_by_openid;
  731. //\Log::info('force:'.json_encode($force_subscribe_info));
  732. }
  733. if ($force_subscribe_info->subscribe_time &&
  734. (time() - strtotime($force_subscribe_info->subscribe_time) >= 3 * 86400)
  735. && !OrderService::isPaidUserByOpenid($force_subscribe_info->openid) &&
  736. !AdvertiseUserQueueService::getUserAdvertise($this->uid) &&
  737. in_array($this->distribution_channel_id, explode(',', env('ADS_OPEN_SITE')))
  738. ) {
  739. return 1;
  740. }
  741. return 0;
  742. }
  743. private function outstandingYearOrder($uid)
  744. {
  745. /*if (!in_array($this->distribution_channel_id, explode(',', env('OUTSTANDING_YEAR_ORDER_SITE')))) {
  746. return false;
  747. }*/
  748. //$userDivisionProperty = UserDivisionPropertyService::getUserProperty($uid);
  749. $userDivisionProperty = UserDivisionCpcPropertyService::getUserProperty($uid);
  750. if (!$userDivisionProperty) return false;
  751. //if ($userDivisionProperty != 'high') return false;
  752. /*if ($uid % 2 == 0) {
  753. $is_show_outstanding_year_order = true;
  754. $template_id = 1;
  755. } else {
  756. $is_show_outstanding_year_order = false;
  757. $template_id = 2;
  758. }*/
  759. $exist = DataAnalysisSelectUserService::getByUidAndType($uid, 'OUTSTANDING_YEAR_ORDER_V2');
  760. if($exist) return true;
  761. return false;
  762. /*DataAnalysisSelectUserService::create(
  763. $uid,
  764. $this->distribution_channel_id,
  765. 'OUTSTANDING_YEAR_ORDER_V2',
  766. -1, $template_id);
  767. return $is_show_outstanding_year_order;*/
  768. }
  769. public function exchangeList(){
  770. foreach ($this->chargeList as &$item){
  771. if(!$item->switch_to) continue;
  772. $order = Order::where('uid',$this->uid)->where('status','PAID')->where('product_id',$item->id)->first();
  773. if($order){
  774. $change = ProductService::getProductSingle($item->switch_to);
  775. $item->id = $change->id;
  776. $item->price = $change->price;
  777. $item->given = $change->given;
  778. }
  779. }
  780. }
  781. }