OrdersController.php 27 KB

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