OrdersController.php 29 KB

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