OrdersController.php 31 KB

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