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. $this->outstandingYearOrder($this->uid);
  243. \Log::info('recordFirstIntoPayPage:$template_id:' . $template_id);
  244. $res = ProductService::getChargeProduct($template_id);
  245. if (!$res) {
  246. return response()->error('WAP_SYS_ERROR');
  247. }
  248. /*if ($this->send_order_id) {
  249. try {
  250. Redis::sadd('pay_page_uv' . $this->send_order_id, $this->uid);
  251. Redis::sadd('pay_page_uv_send_order_ids', $this->send_order_id);
  252. } catch (\Exception $e) {
  253. }
  254. }*/
  255. //TODO 长篇小数才有模板2
  256. //$user = $this->_user_info;
  257. $uid = $this->uid;
  258. $is_first_recharge = OrderService::judgeUserFirstRecharge($uid);
  259. //yqLog('user')->info('user is ',['user'=>$user]);
  260. //yqLog('user')->info('user is ',['charge_count'=>$user->charge_count]);
  261. $data = [];
  262. $appad = 0;
  263. if (in_array($this->distribution_channel_id, explode(',', env('ADS_OPEN_SITE')))) {
  264. $appad = $this->appad();
  265. $my_bid = $bid;
  266. if ($appad) {
  267. try {
  268. AdvertiseUsersService::addAdAccessRec(['uid' => $this->uid,
  269. 'bid' => $my_bid,
  270. 'position' => 'RECHARGE',
  271. 'created_at' => date('Y-m-d H:i:s'),
  272. 'updated_at' => date('Y-m-d H:i:s'),
  273. 'remark' => $request->url()
  274. ]);
  275. } catch (\Exception $e) {
  276. \Log::error('insert into advertise_access_rec failded:' . $e->getMessage());
  277. }
  278. }
  279. }
  280. //\Log::info('ad-tu:uid:'.$uid.':'.$appad);
  281. foreach ($res as $v) {
  282. if ($template_id == 7 && $book_config && $book_config->charge_type == 'BOOK' && $v->price == 2) {
  283. continue;
  284. }
  285. if ($v->type == 'NEW_USER' && $is_first_recharge) {
  286. if (env('NO_NEW_USER_CHARGE') &&
  287. in_array(
  288. $this->distribution_channel_id,
  289. explode(',', env('NO_NEW_USER_CHARGE'))
  290. )
  291. ) {
  292. continue;
  293. }
  294. $temp = [
  295. 'price' => (float)$v->price . '元',
  296. 'is_year_order' => 0,
  297. 'text' => sprintf('%s+%s书币', $v->price * 100, $v->given),
  298. 'first_charge' => true,
  299. 'today_special' => false,
  300. 'save_text' => round($v->given / 100, 1) . '元',
  301. 'product_id' => $v->id,
  302. 'show_free_ads' => $appad
  303. ];
  304. $data[] = $temp;
  305. } elseif ($v->type == 'YEAR_ORDER') {
  306. if ($v->type == 'NEW_USER') {
  307. continue;
  308. }
  309. $save_text = '年费vip会员';
  310. $text = '每天1元,全年免费看';
  311. $temp = [
  312. 'price' => (int)$v->price . '元',
  313. 'is_year_order' => 1,
  314. 'text' => $text,
  315. 'first_charge' => false,
  316. 'today_special' => false,
  317. 'save_text' => $save_text,
  318. 'product_id' => $v->id,
  319. 'show_free_ads' => $appad
  320. ];
  321. $data[] = $temp;
  322. } else {
  323. if ($v->type == 'NEW_USER') {
  324. continue;
  325. }
  326. $save_text = '';
  327. if ($v->given) {
  328. $save_text = round($v->given / 100, 1) . '元';
  329. $text = sprintf('%s+%s书币', $v->price * 100, $v->given);
  330. } else {
  331. $text = sprintf('%s书币', $v->price * 100);
  332. }
  333. $temp = [
  334. 'price' => (float)$v->price . '元',
  335. 'is_year_order' => 0,
  336. 'text' => $text,
  337. 'first_charge' => false,
  338. 'today_special' => $v->is_default == 1 ? true : false,
  339. 'save_text' => $save_text,
  340. 'product_id' => $v->id,
  341. 'show_free_ads' => $appad
  342. ];
  343. $data[] = $temp;
  344. }
  345. }
  346. return response()->success($data);
  347. }
  348. public function substitutePayChargeList(Request $request)
  349. {
  350. $default = $request->get('product_id');
  351. if (!$this->checkUid()) {
  352. return response()->error('WAP_NOT_LOGIN');
  353. }
  354. $su = $request->get('su');
  355. $res = ProductService::getChargeProduct();
  356. if (!$res) {
  357. return response()->error('WAP_SYS_ERROR');
  358. }
  359. $is_can_allow_pay = 1;
  360. if ($su) {
  361. $su_user = UserService::getById($su);
  362. $now_user = $this->_user_info;
  363. if ($now_user && $su_user && $su_user->openid == $now_user->openid) {
  364. $is_can_allow_pay = 0;
  365. }
  366. }
  367. SubstituteOrderService::substitutePageUvPv($this->uid, $this->distribution_channel_id);
  368. $data = [];
  369. foreach ($res as $v) {
  370. if ($v->type == 'YEAR_ORDER') {
  371. $temp = [
  372. 'price' => (int)$v->price . '元',
  373. 'text' => '年费VIP会员',
  374. 'first_charge' => false,
  375. 'today_special' => $v->is_default == 1 ? true : false,
  376. 'save_text' => '全年免费',
  377. 'product_id' => $v->id,
  378. 'default' => false,
  379. 'is_vip' => 1,
  380. 'is_can_allow_pay' => $is_can_allow_pay
  381. ];
  382. if ($default) {
  383. if ($default == $v->id) {
  384. $temp['default'] = true;
  385. }
  386. } else {
  387. $temp['default'] = $v->is_default == 1 ? true : false;
  388. }
  389. $data[] = $temp;
  390. } else {
  391. $save_text = '';
  392. if ($v->given) {
  393. $save_text = round($v->given / 100, 1) . '元';
  394. $text = sprintf('%s+%s书币', $v->price * 100, $v->given);
  395. } else {
  396. $text = sprintf('%s书币', $v->price * 100);
  397. }
  398. $temp = [
  399. 'price' => (int)$v->price . '元',
  400. 'text' => $text,
  401. 'first_charge' => false,
  402. 'today_special' => $v->is_default == 1 ? true : false,
  403. 'save_text' => $save_text,
  404. 'product_id' => $v->id,
  405. 'default' => false,
  406. 'is_vip' => 0,
  407. 'is_can_allow_pay' => $is_can_allow_pay
  408. ];
  409. if ($default) {
  410. if ($default == $v->id) {
  411. $temp['default'] = true;
  412. }
  413. } else {
  414. $temp['default'] = $v->is_default == 1 ? true : false;
  415. }
  416. $data[] = $temp;
  417. }
  418. }
  419. return response()->success($data);
  420. }
  421. /**
  422. * @apiVersion 1.0.0
  423. * @apiDescription 单本消费记录
  424. * @api {get} order/bookOrderList 单本消费记录
  425. * @apiGroup Order
  426. * @apiName bookOrderList
  427. * @apiSuccess {int} code 状态码
  428. * @apiSuccess {String} msg 信息
  429. * @apiSuccess {object} data 结果集
  430. * @apiSuccess {Int} uid uid
  431. * @apiSuccess {Int} bid bid
  432. * @apiSuccess {Int} book_name 书名
  433. * @apiSuccess {Int} fee 钱
  434. * @apiSuccess {String} created_at 时间
  435. * @apiSuccessExample {json} Success-Response:
  436. * HTTP/1.1 200 OK
  437. * {
  438. * code: 0,
  439. * msg: "",
  440. * data: list:[
  441. * {
  442. * uid: 4,
  443. * bid: 1,
  444. * book_name: "dfsedfertrwet",
  445. * fee: 100,
  446. * created_at: "2017-12-02 16:24:54"
  447. * }
  448. * ]
  449. * meta: {
  450. * total: 1,
  451. * per_page: 15,
  452. * current_page: 1,
  453. * last_page: 1,
  454. * next_page_url: "",
  455. * prev_page_url: ""
  456. * }
  457. * }
  458. */
  459. public function bookOrderList(Request $request)
  460. {
  461. if (!$this->checkUid()) {
  462. return response()->error('WAP_NOT_LOGIN');
  463. }
  464. $page_size = $request->input('page_size', 15);
  465. $book_order = BookOrderService::getRecord($this->uid, $page_size);
  466. //$book_order = BookOrder::where('uid', $this->uid)->select('bid', 'uid', 'book_name', 'created_at', 'fee')->paginate($page_size);
  467. return response()->pagination(new BookOrderTransformer(), $book_order);
  468. }
  469. /**
  470. * @apiVersion 1.0.0
  471. * @apiDescription 章节消费记录
  472. * @api {get} order/chapterOrderList 章节消费记录
  473. * @apiGroup Order
  474. * @apiName chapterOrderList
  475. * @apiSuccess {int} code 状态码
  476. * @apiSuccess {String} msg 信息
  477. * @apiSuccess {object} data 结果集
  478. * @apiSuccess {Int} uid uid
  479. * @apiSuccess {Int} bid bid
  480. * @apiSuccess {Int} cid cid
  481. * @apiSuccess {Int} chapter_name 章节名
  482. * @apiSuccess {Int} book_name 书名
  483. * @apiSuccess {Int} fee 钱
  484. * @apiSuccess {String} created_at 时间
  485. * @apiSuccessExample {json} Success-Response:
  486. * HTTP/1.1 200 OK
  487. * {
  488. * code: 0,
  489. * msg: "",
  490. * data: list:[
  491. * {
  492. * uid: 4,
  493. * bid: 1,
  494. * cid: 1,
  495. * chapter_name: "sdfsd",
  496. * book_name: "dfsedfertrwet",
  497. * fee: 100,
  498. * created_at: "2017-12-02 16:24:54"
  499. * }
  500. * ]
  501. * meta: {
  502. * total: 1,
  503. * per_page: 15,
  504. * current_page: 1,
  505. * last_page: 1,
  506. * next_page_url: "",
  507. * prev_page_url: ""
  508. * }
  509. * }
  510. */
  511. public function chapterOrderList(Request $request)
  512. {
  513. if (!$this->checkUid()) {
  514. return response()->error('WAP_NOT_LOGIN');
  515. }
  516. $chapter_model = new ChapterOrderService();
  517. $page_size = $request->input('page_size', 15);
  518. $chapter_order = $chapter_model->getByUid($this->uid, $page_size);
  519. foreach ($chapter_order as $item) {
  520. if ($item->fee == 0) {
  521. $result = AdVisitStatService::getInfoV2($this->uid, $item->cid, ['UNLOCK', 'UNLOCK_2']);
  522. if ($result) $item->fee = '解锁';
  523. }
  524. }
  525. return response()->pagination(new ChapterOrderTransformer(), $chapter_order);
  526. }
  527. /**
  528. * @apiVersion 1.0.0
  529. * @apiDescription 充值记录
  530. * @api {get} order/chargeRecordLists 充值记录
  531. * @apiGroup Order
  532. * @apiName chargeRecordLists
  533. * @apiSuccess {int} code 状态码
  534. * @apiSuccess {String} msg 信息
  535. * @apiSuccess {object} data 结果集
  536. * @apiSuccess {String} data.price 价格
  537. * @apiSuccess {String} data.status 状态
  538. * @apiSuccess {String} data.trade_no 订单号
  539. * @apiSuccess {String} data.created_at 时间
  540. * @apiSuccessExample {json} Success-Response:
  541. * HTTP/1.1 200 OK
  542. * {
  543. * code: 0,
  544. * msg: "",
  545. * data: {
  546. * list: [
  547. * {
  548. * id: 134,
  549. * price: "1.00",
  550. * status: "PAID",
  551. * trade_no: "201712021915481585670623626232",
  552. * created_at: "2017-12-02 19:15:56"
  553. * }
  554. * ],
  555. * meta: {
  556. * total: 1,
  557. * per_page: 15,
  558. * current_page: 1,
  559. * last_page: 1,
  560. * next_page_url: "",
  561. * prev_page_url: ""
  562. * }
  563. * }
  564. * }
  565. */
  566. public function chargeRecordLists(Request $request)
  567. {
  568. $page_size = $request->input('page_size', 15);
  569. $res = OrderService::getOrderList($this->uid, $page_size);
  570. return response()->pagination(new ChargeListTransformer(), $res);
  571. }
  572. //订单是否成功
  573. public function isSuccess(Request $request)
  574. {
  575. $order = $request->input('order');
  576. $order_info = OrderService::getByTradeNo($order);
  577. if ($order_info && $order_info->status == 'PAID') {
  578. return response()->success();
  579. }
  580. return response()->error('WAP_SYS_ERROR');
  581. }
  582. public function substitutePay(Request $request)
  583. {
  584. if (!$this->checkUid()) {
  585. return response()->error('WAP_NOT_LOGIN');
  586. }
  587. $product_id = $request->get('product_id');
  588. SubstituteOrderService::substituteButtonUvPv($this->uid, $this->distribution_channel_id);
  589. $user = $this->_user_info;
  590. $data = [
  591. 'head_img' => '',
  592. 'nickname' => $user->nickname
  593. ];
  594. //$help_pay_page_channel_id = env('HELP_PAY_PAGE_CHANNEL_ID', 123);
  595. $help_pay_page_channel_id = $this->distribution_channel_id;
  596. $url_format = '%s://site%s.%s.com/helppay?%s';
  597. $param = [];
  598. $param['su'] = $this->uid;
  599. if ($product_id) {
  600. $param['product_id'] = $product_id;
  601. }
  602. $help_pay_page = sprintf(
  603. $url_format,
  604. env('PROTOCOL'),
  605. encodeDistributionChannelId($help_pay_page_channel_id),
  606. env('CUSTOM_HOST'),
  607. http_build_query($param)
  608. );
  609. $data['help_pay_page'] = $help_pay_page;
  610. return response()->success($data);
  611. }
  612. private function recordFirstIntoPayPage($bid)
  613. {
  614. $start_time = env('RECORD_FIRST_VISIT_PAY_PAGE_TIME');
  615. $template_id = 0;
  616. if (in_array($this->distribution_channel_id, [123, 211]) && $start_time && $this->uid) {
  617. $user = $this->_user_info;
  618. if (strtotime($user->created_at) > $start_time) {
  619. $old = DB::table('user_first_visit_pay_page')->where('uid', $this->uid)->select('uid', 'template_type')->first();
  620. if ($old) {
  621. $template_id = $old->template_type;
  622. if ($template_id) return $template_id;
  623. }
  624. if ($bid && $bid == 1148) {
  625. $template_id = $this->uid % 2 == 0 ? 2 : 1;
  626. if (empty($old)) {
  627. try {
  628. DB::table('user_first_visit_pay_page')->insert([
  629. 'uid' => $this->uid,
  630. 'template_type' => $template_id,
  631. 'created_at' => date('Y-m-d H:i:s'),
  632. 'updated_at' => date('Y-m-d H:i:s')
  633. ]);
  634. } catch (\Exception $e) {
  635. }
  636. }
  637. }
  638. }
  639. }
  640. return $template_id;
  641. }
  642. private function templateCompare()
  643. {
  644. //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])){
  645. /*$start_time = env('TEMPLATE_COMPARE_START_TIME_3',0);
  646. if(!$start_time){
  647. return 0;
  648. }*/
  649. 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])) {
  650. return 0;
  651. }
  652. //$user = $this->_user_info;
  653. /*if(strtotime($user->created_at) < $start_time){
  654. return 0;
  655. }*/
  656. $template_id = 0;
  657. $user = DataAnalysisSelectUserService::getByUidAndType($this->uid, 'TEMPLATE_COMPARE_V3');
  658. if ($user) {
  659. $template_id = $user->attach;
  660. }
  661. return $template_id;
  662. }
  663. private function templateCompareV2()
  664. {
  665. $start_time = env('TEMPLATE_COMPARE_START_TIME', 0);
  666. if (!$start_time) {
  667. return 0;
  668. }
  669. if (!in_array($this->distribution_channel_id, [2, 146, 155, 255, 256, 691, 722, 4364, 695, 4174, 4025, 4593, 4426, 4742, 4053, 4334, 4487])) {
  670. return 0;
  671. }
  672. $user = $this->_user_info;
  673. if (strtotime($user->created_at) < $start_time) {
  674. return 0;
  675. }
  676. $user = DataAnalysisSelectUserService::getByUidAndType($this->uid, 'TEMPLATE_COMPAREV2');
  677. if ($user) {
  678. $template_id = $user->attach;
  679. } else {
  680. $template_id = $this->uid % 2 == 0 ? 1 : 6;
  681. DataAnalysisSelectUserService::create(
  682. $this->uid,
  683. $this->distribution_channel_id,
  684. 'TEMPLATE_COMPAREV2',
  685. -1, $template_id);
  686. }
  687. return $template_id;
  688. }
  689. private function maleSite($distribution_channel_id)
  690. {
  691. $info = ChannelService::getChannelCompanyInfo($distribution_channel_id);
  692. //\Log::info('maleSite info is:');
  693. //\Log::info($info);
  694. if ($info && isset($info->fans_gender)) {
  695. if ($info->fans_gender == 1) {
  696. return 1;
  697. }
  698. }
  699. return 0;
  700. }
  701. private function appad()
  702. {
  703. if ($this->force_subscribe_info) {
  704. $force_subscribe_info = $this->force_subscribe_info;
  705. } else {
  706. $force_subscribe_info = $this->force_subscribe_info = ForceSubscribeService::forceSubscribeUsersByUid(['uid' => $this->uid]);
  707. }
  708. if (!$force_subscribe_info) {
  709. return 0;
  710. }
  711. //\Log::info('force1:'.json_encode($force_subscribe_info));
  712. $force_sub_user_by_openid = ForceSubscribeUserIService::getForceSubscribeByUidOpenid($this->uid);
  713. if ($force_sub_user_by_openid) {
  714. $force_subscribe_info = $force_sub_user_by_openid;
  715. //\Log::info('force:'.json_encode($force_subscribe_info));
  716. }
  717. if ($force_subscribe_info->subscribe_time &&
  718. (time() - strtotime($force_subscribe_info->subscribe_time) >= 3 * 86400)
  719. && !OrderService::isPaidUserByOpenid($force_subscribe_info->openid) &&
  720. !AdvertiseUserQueueService::getUserAdvertise($this->uid) &&
  721. in_array($this->distribution_channel_id, explode(',', env('ADS_OPEN_SITE')))
  722. ) {
  723. return 1;
  724. }
  725. return 0;
  726. }
  727. private function outstandingYearOrder($uid)
  728. {
  729. if (!in_array($this->distribution_channel_id, explode(',', env('OUTSTANDING_YEAR_ORDER_SITE')))) {
  730. return '';
  731. }
  732. $exist = DataAnalysisSelectUserService::getByUidAndType($uid, 'OUTSTANDING_YEAR_ORDER');
  733. if($exist) return '';
  734. $userDivisionProperty = UserDivisionPropertyService::getUserProperty($uid);
  735. if (!$userDivisionProperty) return '';
  736. if ($userDivisionProperty != 'high') return '';
  737. if ($uid % 2 == 0) {
  738. $template_id = 1;
  739. } else {
  740. $template_id = 2;
  741. }
  742. DataAnalysisSelectUserService::create(
  743. $uid,
  744. $this->distribution_channel_id,
  745. 'OUTSTANDING_YEAR_ORDER',
  746. -1, $template_id);
  747. return '';
  748. }
  749. }