OrdersController.php 29 KB

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