OrdersController.php 27 KB

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