OrdersController.php 27 KB

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