OrdersController.php 28 KB

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