OrdersController.php 29 KB

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