BookTest.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Jobs\SendTexts;
  4. use App\Modules\Book\Services\BookSubscribleChapterService;
  5. use App\Modules\Product\Services\ProductService;
  6. use App\Modules\Subscribe\Services\ChapterOrderService;
  7. use App\Modules\Subscribe\Services\SubstituteOrderService;
  8. use App\Modules\User\Services\ReadRecordService;
  9. use App\Modules\User\Services\UserService;
  10. use App\Modules\YunQi\Models\BookUser;
  11. use App\Modules\YunQi\Models\YqUserBidRelation;
  12. use App\Modules\YunQi\Models\YqZsyTest;
  13. use App\Modules\YunQi\Services\YqZsyTestService;
  14. use GuzzleHttp\Client;
  15. use Illuminate\Console\Command;
  16. use Log;
  17. use DB;
  18. use Redis;
  19. use App\Modules\Book\Models\Book;
  20. use App\Modules\Book\Models\Chapter;
  21. use App\Modules\SendOrder\Models\SendOrder;
  22. use App\Modules\SendOrder\Services\SendOrderService;
  23. use App\Modules\Subscribe\Models\Order;
  24. use App\Jobs\SendStatisticsList;
  25. use App\Modules\OfficialAccount\Models\ForceSubscribeUsers;
  26. use App\Modules\User\Services\UserSignService;
  27. use App\Modules\Book\Models\BookUvStat;
  28. use App\Modules\Subscribe\Models\ChapterOrder;
  29. class BookTest extends Command
  30. {
  31. /**
  32. * The name and signature of the console command.
  33. *
  34. * @var string
  35. */
  36. protected $signature = 'book:test
  37. {--bid= : the id of a book}';
  38. /**
  39. * The console command description.
  40. *
  41. * @var string
  42. */
  43. protected $client;
  44. protected $description = 'Command description';
  45. /**
  46. * Create a new command instance.
  47. *
  48. * @return void
  49. */
  50. public function __construct()
  51. {
  52. parent::__construct();
  53. $this->client = new Client(['timeout' => 8.0, 'allow_redirects' => true]);
  54. }
  55. /**
  56. * Execute the console command.
  57. *
  58. * @return mixed
  59. */
  60. public function handle()
  61. {
  62. //$this->data1();
  63. //$this->testTest();
  64. //$this->activity();
  65. //$this->testBookSmartPushStats();
  66. //$this->sendOrderStats105();
  67. //$this->you2();
  68. //$this->transfromUserOrder();
  69. $this->successPayPushMsg();
  70. }
  71. public function activity()
  72. {
  73. $res = \App\Modules\Activity\Services\ActivityService::ActivityStatsI(16);
  74. $str = "日期,site id,活动页面访问uv,按钮uv,生成订单数,成功支付订单数,首充用户数,点击阅读页面文字链uv,阅读页面文字链订单数,阅读页面文字链成功订单数,阅读页面文字链首充用户数,签到回调文字链uv,签到回调文字链生成订单数,签到回调文字链成功成功订单数,签到回调文字链首充用户数\r\n";
  75. $str = mb_convert_encoding($str, 'gbk');
  76. $file_name = date('Y-m-d') . '.csv';
  77. file_put_contents($file_name, $str);
  78. $temp = '';
  79. foreach ($res as $val) {
  80. $temp .= "{$val['day']},{$val['siteid']},{$val['uv']},{$val['button_uv']},{$val['order_num']},{$val['success_order_num']},{$val['first_charge_num']},{$val['reader_uv']},{$val['reader_order']},{$val['reader_success_order']},{$val['reader_first_charge']},{$val['signcallback_uv']},{$val['signcallback_order']},{$val['signcallback_success_order']},{$val['signcallback_first_charge']}\r\n";
  81. }
  82. file_put_contents($file_name, $temp, FILE_APPEND);
  83. }
  84. public function data1(){
  85. //1,图书uv
  86. $keys = Redis::SMEMBERS('book_before_five_uvs');
  87. if(!$keys){
  88. return 0;
  89. }
  90. $data = [];
  91. $book_name_arr = [];
  92. $i = 0;
  93. foreach ($keys as $k){
  94. $k_array = explode('_',$k);
  95. $uv = Redis::scard('book_before_five_uv_'.$k);
  96. Redis::del('book_before_five_uv_'.$k);
  97. if(isset($book_name_arr[$k_array[1]]) && !empty($book_name_arr[$k_array[1]])){
  98. $book_name = $book_name_arr[$k_array[1]];
  99. }else{
  100. $book_name_info = DB::table('book_configs')->where('bid',$k_array[1])->select('book_name')->first();
  101. if($book_name_info){
  102. $book_name_arr[$k_array[1]] = $book_name_info->book_name;
  103. $book_name = $book_name_info->book_name;
  104. }else{
  105. $book_name = '未知';
  106. }
  107. }
  108. $data[] = [
  109. 'bid'=>$k_array[1],
  110. 'day'=>$k_array[0],
  111. 'sequence'=>$k_array[2],
  112. 'book_name'=>$book_name,
  113. 'uv'=>$uv,
  114. 'created_at'=>date('Y-m-d H:i:s'),
  115. 'updated_at'=>date('Y-m-d H:i:s')
  116. ];
  117. $i++;
  118. if($i && $i%200 == 0){
  119. DB::table('book_five_chapter_uv')->insert($data);
  120. $data = [];
  121. }
  122. }
  123. DB::table('book_five_chapter_uv')->insert($data);
  124. Redis::del('book_before_five_uvs');
  125. }
  126. public function data2(){
  127. //强关
  128. $keys = Redis::SMEMBERS('subscribe_page_uv_send_order_ids');
  129. $data = [];
  130. $i = 0;
  131. foreach ($keys as $k){
  132. $subscribe_uv = Redis::scard('subscribe_page_uv'.$k);
  133. Redis::del('subscribe_page_uv'.$k);
  134. $data[] = [
  135. 'send_order_id'=>$k,
  136. 'subscribe_uv'=>$subscribe_uv,
  137. 'pay_uv'=>0,
  138. 'created_at'=>date('Y-m-d H:i:s'),
  139. 'updated_at'=>date('Y-m-d H:i:s')
  140. ];
  141. $i++;
  142. if($i && $i%200 == 0){
  143. DB::table('subscribe_pay_page_uv')->insert($data);
  144. $data = [];
  145. }
  146. }
  147. $keys = null;
  148. $k = null;
  149. DB::table('subscribe_pay_page_uv')->insert($data);
  150. $data = [];
  151. //支付
  152. $keys = Redis::SMEMBERS('pay_page_uv_send_order_ids');
  153. foreach ($keys as $v){
  154. $pay_uv = Redis::scard('pay_page_uv'.$v);
  155. Redis::del('pay_page_uv'.$v);
  156. $o = DB::table('subscribe_pay_page_uv')->where('send_order_id',$v)->first();
  157. if($o){
  158. DB::table('subscribe_pay_page_uv')->where('send_order_id',$v)->update([
  159. 'pay_uv'=>$pay_uv
  160. ]);
  161. }else{
  162. DB::table('subscribe_pay_page_uv')->insert([
  163. 'send_order_id'=>$v,
  164. 'subscribe_uv'=>0,
  165. 'pay_uv'=>$pay_uv,
  166. 'created_at'=>date('Y-m-d H:i:s'),
  167. 'updated_at'=>date('Y-m-d H:i:s')
  168. ]);
  169. }
  170. }
  171. Redis::del('subscribe_page_uv_send_order_ids');
  172. Redis::del('pay_page_uv_send_order_ids');
  173. }
  174. public function testTest(){
  175. $res = \App\Modules\Statistic\Services\WapVisitStatService::smartPushTestBookStats(6);
  176. echo \Hashids::encode(6).PHP_EOL;
  177. print_r($res);
  178. }
  179. private function testBookSmartPushStats(){
  180. $sql1 = 'TRUNCATE test_book_smart_push_stats';
  181. DB::update($sql1);
  182. $result = DB::table('book_configs')->whereIn('test_status',[1,2])->select('bid','vip_seq')->get();
  183. /*foreach ($result as $v){
  184. t($v->bid,$v->vip_seq);
  185. }*/
  186. function t($bid,$vip_seq){
  187. $data = [];
  188. $key1 = 'smartPushTestBookPayPageUv:bid:%s';
  189. $pay_page_uv = (int)(Redis::scard(sprintf($key1,$bid)));
  190. $key2 = 'smartPushTestBookPaidUv:bid:%s';
  191. $paid_num = (int)(Redis::scard(sprintf($key2,$bid)));
  192. $amount = Redis::Hget('smartPushTestBookPaidAmount',$bid);
  193. if(!$amount)
  194. $amount = 0;
  195. for ($i = 1;$i<=60;$i++){
  196. $key3 = 'smartPushTestBookChapterUv:bid:%s:seq:%s';
  197. $sequence_uv = (int)(Redis::scard(sprintf($key3,$bid,$i)));
  198. if(!$sequence_uv){
  199. continue;
  200. }
  201. $data[] = [
  202. 'bid'=>$bid,
  203. 'sequence'=>$i,
  204. 'sequence_uv'=>$sequence_uv,
  205. 'vip_sequence'=>$vip_seq,
  206. 'pay_page_uv'=>$pay_page_uv,
  207. 'paid_user_num'=>$paid_num,
  208. 'amount'=>$amount,
  209. 'created_at'=>date('Y-m-d H:i:s'),
  210. 'updated_at'=>date('Y-m-d H:i:s')
  211. ];
  212. }
  213. if($data){
  214. DB::table('test_book_smart_push_stats')->insert($data);
  215. }
  216. }
  217. foreach ($result as $v){
  218. t($v->bid,$v->vip_seq);
  219. }
  220. }
  221. private function sendOrderStats105(){
  222. //$sql1 = 'TRUNCATE send_order_stats_105';
  223. //DB::update($sql1);
  224. $send_order_ids = Redis::hgetall('sendOrderIdToBid');
  225. if(!$send_order_ids){
  226. return ;
  227. }
  228. function one(int $sendOrderId,int $time){
  229. $info = SendOrderService::getById($sendOrderId);
  230. if(!$info || !$info->book_id){
  231. return ;
  232. }
  233. $subscribe_chaper_seq = 0;
  234. if($info && $info->subscribe_chapter_seq){
  235. $subscribe_chaper_seq = $info->subscribe_chapter_seq;
  236. }
  237. if(!$subscribe_chaper_seq){
  238. $subscribe = BookSubscribleChapterService::getSubcribleChapter($info->book_id,$info->distribution_channel_id);
  239. if ($subscribe) {
  240. $subscribe_chaper_seq = (isset($subscribe->subscribe_chapter_id) && $subscribe->subscribe_chapter_id > 0) ? $subscribe->subscribe_chapter_id : 0;
  241. }
  242. }
  243. $key_1 = 'accurateSendOrderSubscribePageUv:bid:%s:sendorderid:'.$sendOrderId;
  244. //强关页面uv
  245. $subscribe_uv = (int)(Redis::scard(sprintf($key_1,$info->book_id)));
  246. Redis::del( sprintf($key_1,$info->book_id) );
  247. $key_2 = 'accurateSendOrderPayPageUv:bid:%s:send_order_id:'.$sendOrderId;
  248. //付费页面UV
  249. $pay_page_uv = (int)(Redis::scard(sprintf($key_2,$info->book_id)));
  250. Redis::del( sprintf($key_2,$info->book_id) );
  251. //强关数
  252. $subscribe_num = DB::table('force_subscribe_users')
  253. ->where('send_order_id',$sendOrderId)
  254. ->where('bid',$info->book_id)
  255. ->where('created_at','>=',date('Y-m-d H:i:s',$time))
  256. ->count();
  257. $paid_user_num = DB::table('orders')
  258. ->where('send_order_id',$sendOrderId)
  259. ->where('from_bid',$info->book_id)
  260. ->where('status','PAID')
  261. ->where('created_at','>=',date('Y-m-d H:i:s',$time))
  262. ->count();
  263. $book_info = DB::table('book_configs')->where('bid',$info->book_id)->select('book_name','force_subscribe_chapter_seq','vip_seq')->first();
  264. $send_order_chapter_sequence_info = DB::table('chapters')->where('id',$info->chapter_id)->select('sequence')->first();
  265. $send_order_chapter_sequence = 0;
  266. if($send_order_chapter_sequence_info && $send_order_chapter_sequence_info->sequence){
  267. $send_order_chapter_sequence = $send_order_chapter_sequence_info->sequence;
  268. }
  269. if(!$subscribe_chaper_seq){
  270. if($book_info){
  271. $subscribe_chaper_seq = $book_info->force_subscribe_chapter_seq;
  272. }else{
  273. $subscribe_chaper_seq = 0;
  274. }
  275. }
  276. $vip_seq = 0;
  277. $vip_seq_info = Chapter::where('bid',$info->book_id)->where('is_vip',1)->orderBy('sequence')->select('sequence')->first();
  278. if($vip_seq_info){
  279. $vip_seq = $vip_seq_info->sequence;
  280. }
  281. $data = [];
  282. for ($i = 1;$i<=30;$i++){
  283. $key_3 = 'accurateSendOrderChapterUv:bid:%s:seq:%s:sendorderid:'.$sendOrderId;
  284. $chapter_seq_uv = (int)(Redis::scard(sprintf($key_3,$info->book_id,$i)));
  285. Redis::del( sprintf($key_3,$info->book_id,$i) );
  286. if(!$chapter_seq_uv){
  287. continue;
  288. }
  289. /*$data[] = [
  290. 'send_order_id'=>$sendOrderId,
  291. 'send_order_chapter_seq'=>$send_order_chapter_sequence,
  292. 'bid'=>$info->book_id,
  293. 'book_name'=>$book_info?$book_info->book_name:'xx',
  294. 'chaper_sequence'=>$i,
  295. 'chapter_uv'=>$chapter_seq_uv,
  296. 'subscribe_chaper_seq'=>$subscribe_chaper_seq,
  297. 'subscribe_page_uv'=>$subscribe_uv,
  298. 'subscribe_user_num'=>$subscribe_num,
  299. 'vip_chapter_sequence'=>$vip_seq,
  300. 'pay_page_uv'=>$pay_page_uv,
  301. 'paid_user_num'=>$paid_user_num,
  302. 'created_at'=>date('Y-m-d H:i:s'),
  303. 'updated_at'=>date('Y-m-d H:i:s')
  304. ];*/
  305. }
  306. if($data){
  307. DB::table('send_order_stats_105')->insert($data);
  308. }
  309. }
  310. foreach ($send_order_ids as $send_order_id=> $v){
  311. $array = explode('-',$v);
  312. if(count($array) == 2){
  313. one($send_order_id,$array[1]);
  314. }
  315. }
  316. Redis::del('sendOrderIdToBid');
  317. }
  318. private function you2(){
  319. $sql1 = 'TRUNCATE yq_stats2';
  320. DB::update($sql1);
  321. $info = BookUser::where('type','ENABLE')->select('bid','uid','type','updated_at')
  322. ->orderBy('updated_at')->limit(1500)->get();
  323. $info2 = BookUser::where('type','GROUP_1')
  324. ->select('bid','uid','type','updated_at')->orderBy('updated_at')->limit(1500)->get();
  325. $this->you2Type($info,'GROUP_2');
  326. $this->you2Type($info2,'GROUP_1');
  327. }
  328. private function you2Type($info,$type){
  329. $result = [];
  330. $chapter_model = new ChapterOrder();
  331. foreach ($info as $item){
  332. $to_bids = YqUserBidRelation::where('uid',$item->uid)->where('to_bid','>',0)->select('to_bid','created_at')->get();
  333. $from_bids = YqUserBidRelation::where('uid',$item->uid)->where('from_bid','>',0)->select('from_bid','created_at')->get();
  334. $chapter_model->setCurrentTable($item->uid);
  335. if($to_bids){
  336. foreach ($to_bids as $v){
  337. $to_bid = $v->to_bid;
  338. $time = $v->created_at->format('Y-m-d H:i:s');
  339. $end_time = date('Y-m-d H:i:s',strtotime($time)+2*86400);
  340. if(!$to_bid) continue;
  341. $fee = $chapter_model->where('uid',$item->uid)
  342. ->where('bid',$to_bid)
  343. ->where('created_at','>=',$time)
  344. ->where('created_at','<=',$end_time)
  345. ->sum('fee');
  346. $amount = Order::where('uid',$item->uid)
  347. ->where('from_bid',$to_bid)
  348. ->where('created_at','>=',$time)
  349. ->where('created_at','<=',$end_time)
  350. ->where('status','PAID')
  351. ->sum('price');
  352. $result[] = [
  353. 'bid'=>$to_bid,
  354. 'uid'=>$item->uid,
  355. 'fee'=>$fee,
  356. 'amount'=>$amount,
  357. 'start_time'=>$time,
  358. 'type'=>'to',
  359. 'group'=>$type,
  360. 'created_at'=>date('Y-m-d H:i:s'),
  361. 'updated_at'=>date('Y-m-d H:i:s')
  362. ];
  363. }
  364. if($result){
  365. DB::table('yq_stats2')->insert($result);
  366. $result = [];
  367. }
  368. }
  369. $to_bid = null;
  370. if($from_bids){
  371. foreach ($from_bids as $from_bid){
  372. $bid = $from_bid->from_bid;
  373. $test = YqZsyTestService::getByBid($bid);
  374. if($test) continue;
  375. $time = $from_bid->created_at->format('Y-m-d H:i:s');
  376. $end_time = date('Y-m-d H:i:s',strtotime($time)+2*86400);
  377. $fee = $chapter_model->where('uid',$item->uid)
  378. ->where('bid',$bid)
  379. ->where('created_at','>=',$time)
  380. ->where('created_at','<=',$end_time)
  381. ->sum('fee');
  382. $amount = Order::where('uid',$item->uid)
  383. ->where('from_bid',$bid)
  384. ->where('created_at','>=',$time)
  385. ->where('created_at','<=',$end_time)
  386. ->where('status','PAID')
  387. ->sum('price');
  388. $result[] = [
  389. 'bid'=>$bid,
  390. 'uid'=>$item->uid,
  391. 'fee'=>$fee,
  392. 'amount'=>$amount,
  393. 'start_time'=>$time,
  394. 'type'=>'from',
  395. 'group'=>$type,
  396. 'created_at'=>date('Y-m-d H:i:s'),
  397. 'updated_at'=>date('Y-m-d H:i:s')
  398. ];
  399. }
  400. if($result){
  401. DB::table('yq_stats2')->insert($result);
  402. $result = [];
  403. }
  404. }
  405. }
  406. }
  407. private function transfromUserOrder(){
  408. $user = DB::table('users')
  409. ->where('distribution_channel_id',4815)
  410. ->where('created_at','>=','2019-01-31 15:00:00')
  411. ->select('openid','id')
  412. ->get();
  413. $chapter_model = new ChapterOrder();
  414. foreach ($user as $v){
  415. Log::info('now user is :');
  416. Log::info('openid is: '.$v->openid.',old uid is :'.$v->id);
  417. $froce_user = DB::table('force_subscribe_users')
  418. ->where('openid',$v->openid)
  419. ->where('distribution_channel_id',384)
  420. ->select('uid')
  421. ->first();
  422. if(!$froce_user){
  423. continue;
  424. }
  425. Log::info('$froce_user user is :');
  426. Log::info('$froce_user is: '.$froce_user->uid);
  427. if($froce_user && $froce_user->uid != $v->id){
  428. $chapter_model->setCurrentTable($froce_user->uid);
  429. $data = [];
  430. //章节订购
  431. $chapter_order_info = $chapter_model->where('uid',$froce_user->uid)->get();
  432. Log::info('$chapter_order_info user is :');
  433. Log::info($chapter_order_info);
  434. if($chapter_order_info){
  435. foreach ($chapter_order_info as $chapter_order_item){
  436. $data = [
  437. 'distribution_channel_id'=>4815,
  438. 'bid'=>$chapter_order_item->bid,
  439. 'cid'=>$chapter_order_item->cid,
  440. 'chapter_name'=>$chapter_order_item->chapter_name,
  441. 'book_name'=>$chapter_order_item->book_name,
  442. 'uid'=>$v->id,
  443. 'send_order_id'=>0,
  444. 'fee'=>0,
  445. 'created_at'=>$chapter_order_item->created_at,
  446. 'updated_at'=>date('Y-m-d H:i:s'),
  447. 'charge_balance'=>0,
  448. 'reward_balance'=>0
  449. ];
  450. $chapter_model->setCurrentTable($v->id);
  451. $old = $chapter_model->where('uid',$v->id)
  452. ->where('bid',$chapter_order_item->bid)
  453. ->where('cid',$chapter_order_item->cid)
  454. ->select('id')->first();
  455. if(!$old){
  456. $chapter_model->insert($data);
  457. }
  458. }
  459. }
  460. /*if($data){
  461. Log::info('$chapter_order_info user $data is :');
  462. Log::info($data);
  463. $chapter_model->setCurrentTable($v->id);
  464. $chapter_model->insert($data);
  465. }*/
  466. //单本订购
  467. if($froce_user && $froce_user->uid != $v->id){
  468. $book_order_data = [];
  469. $book_orders = DB::table('book_orders')->where('uid',$froce_user->uid)->get();
  470. Log::info('$book_orders user is :');
  471. if($book_orders){
  472. foreach ($book_orders as $book_order_item){
  473. $book_order_data[] = [
  474. 'uid'=>$v->id,
  475. 'distribution_channel_id'=>4815,
  476. 'bid'=>$book_order_item->bid,
  477. 'book_name'=>$book_order_item->book_name,
  478. 'u'=>$book_order_item->u,
  479. 'send_order_id'=>0,
  480. 'charge_balance'=>0,
  481. 'reward_balance'=>0,
  482. 'fee'=>0,
  483. 'created_at'=>$book_order_item->created_at,
  484. 'updated_at'=>date('Y-m-d H:i:s'),
  485. ];
  486. }
  487. }
  488. if($book_order_data){
  489. Log::info('$book_order_data user is :');
  490. Log::info($book_order_data);
  491. foreach ($book_order_data as $book_o ){
  492. $old = DB::table('book_orders')
  493. ->where('uid',$book_o['uid'])
  494. ->where('bid',$book_o['bid'])
  495. ->select('id')->first();
  496. if(!$old){
  497. DB::table('book_orders')->insert($book_order_data);
  498. }
  499. }
  500. }
  501. }
  502. //阅读记录
  503. $read_bids = Redis::hgetall('book_read:' . $froce_user->uid);
  504. Log::info('$read_bids is :');
  505. Log::info($read_bids);
  506. if ($read_bids){
  507. foreach ($read_bids as $key=>$field){
  508. Redis::hset('book_read:' . $v->id,$key,$field);
  509. }
  510. }
  511. //用户信息
  512. $old_user = DB::table('users')->where('id', $froce_user->uid)->first();
  513. if($old_user){
  514. DB::table('users')->where('id',$v->id)->update([
  515. 'balance'=>$old_user->balance,
  516. 'charge_balance'=>$old_user->charge_balance,
  517. 'reward_balance'=>$old_user->reward_balance,
  518. ]);
  519. }
  520. //年费
  521. $year = DB::table('year_orders')->where('uid',$froce_user->uid)->orderBy('id','desc')->first();
  522. if($year){
  523. $old_year = DB::table('year_orders')->where('uid',$v->id)->orderBy('id','desc')->first();
  524. if(!$old_year){
  525. DB::table('year_orders')->insert([[
  526. 'uid'=>$v->id,
  527. 'begin_time'=>$year->begin_time,
  528. 'end_time'=>$year->end_time,
  529. 'distribution_channel_id'=>4815,
  530. 'created_at'=>$year->created_at,
  531. 'updated_at'=>date('Y-m-d H:i:s'),
  532. 'fee'=>0,
  533. ]]);
  534. }
  535. }
  536. }
  537. }
  538. }
  539. protected function successPayPushMsg()
  540. {
  541. try {
  542. $uid = 10008;
  543. $order_id = 10910163;
  544. $product_info = ProductService::getProductSingle(2);
  545. $force_sub_info = DB::table('force_subscribe_users')->where('uid',$uid)->where('is_subscribed', 1)->get();
  546. $data = UserService::getById($uid);
  547. if (!in_array($data->distribution_channel_id, [5, 123])) {
  548. //return false;
  549. }
  550. if ($force_sub_info) {
  551. //$content_format = "您好,你已经成功充值\r\n\r\n会员:%s\r\n会员ID:%s\r\n充值金额:%s\r\n充值状态:充值成功\r\n如有疑问,请点击用户中心-联系客服\r\n\r\n><a href='%s'>点击继续阅读上次阅读</a>";
  552. if (SubstituteOrderService::getByOrderId($order_id)) {
  553. $content_format = "代充值客服消息:\r\n\r\n你好,您的好友为你代付成功\r\n会员:%s\r\n会员ID:%s\r\n代付金额:%s\r\n充值状态:充值成功\r\n如有疑问,请点击用户中心-联系客服\r\n\r\n><a href='%s'>点击继续阅读上次阅读</a>";
  554. } else {
  555. $content_format = "您好,你已经成功充值\r\n\r\n会员:%s\r\n会员ID:%s\r\n充值金额:%s\r\n充值状态:充值成功\r\n如有疑问,请点击用户中心-联系客服\r\n\r\n><a href='%s'>点击继续阅读上次阅读</a>";
  556. }
  557. if ($product_info->type == 'YEAR_ORDER') {
  558. $money_text = $product_info->price . '元(尊贵的年费VIP会员)';
  559. } elseif ($product_info->type == 'TICKET_RECHARGE') {
  560. if ($product_info->given) {
  561. $money_text = $product_info->price . '元(' . ($product_info->price * 100) . '书币+赠送' . $product_info->given . '书币)';
  562. } else {
  563. $money_text = $product_info->price . '元(' . ($product_info->price * 100) . '书币)';
  564. }
  565. } else {
  566. $money_text = '未知';
  567. }
  568. $delay = 0;
  569. $url = env('PROTOCOL') . '://site' . encodeDistributionChannelId($data->distribution_channel_id) . '.' . env('CUSTOM_HOST') . '.com/continue';;
  570. $content = sprintf($content_format, $data->nickname ? $data->nickname : '匿名', $uid, $money_text, $url);
  571. foreach ($force_sub_info as $item){
  572. $res['openid'] = $item->openid;
  573. $res['appid'] = $item->appid;
  574. $res['content'] = $content;
  575. $res['type'] = 'one_task';
  576. $res['send_time'] = date("Y-m-d H:i:s");
  577. $res['task_id'] = md5('pay_success_push');
  578. $send_data = array(
  579. 'send_time' => date("Y-m-d H:i:s"),
  580. 'data' => $res
  581. );
  582. Log::info($send_data);
  583. dispatch((new SendTexts($send_data))->onConnection('rabbitmq')->delay($delay)->onQueue('send_texts_list'));
  584. }
  585. }
  586. } catch (\Exception $e) {
  587. Log::info('pay_success_push error');
  588. Log::info($e);
  589. }
  590. return true;
  591. }
  592. }