OrdersController.php 30 KB

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