OrdersController.php 26 KB

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