OrdersController.php 26 KB

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