OrdersController.php 27 KB

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