OrdersController.php 26 KB

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