TempCommand.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. namespace App\Console\Commands\SuperiorBooks;
  3. use App\Modules\Book\Services\SuperiorHistoryBookService;
  4. use App\Modules\Channel\Models\CompanySpecialBook;
  5. use DB;
  6. use Illuminate\Console\Command;
  7. class TempCommand extends Command
  8. {
  9. /**
  10. * The name and signature of the console command.
  11. *
  12. * @var string
  13. */
  14. protected $signature = 'TemporaryCommand {scene}';
  15. /**
  16. * The console command description.
  17. *
  18. * @var string
  19. */
  20. protected $description = '临时任务';
  21. /**
  22. * Create a new command instance.
  23. *
  24. * @return void
  25. */
  26. public function __construct()
  27. {
  28. parent::__construct();
  29. }
  30. /**
  31. * Execute the console command.
  32. *
  33. * @return mixed
  34. */
  35. public function handle()
  36. {
  37. //$array = ['recent_read','subscribe','text_sign','text_search','readerover','readrecord','daily_sign'];//
  38. // $array = ['daily_sign'];
  39. //foreach ($array as $v) {
  40. $books = DB::table('superior_history_books')->where('status',1)->get();
  41. foreach ($books as $book){
  42. DB::table('chapter')->where()->first();
  43. }
  44. return true;
  45. $v = $this->argument('scene');
  46. DB::connection('chapter_order_mysql')
  47. ->table($v.'_user_sub')
  48. ->orderBy('id')
  49. ->where('fee', -1)->chunk(10000, function ($users) use($v){
  50. foreach ($users as $user) {
  51. $fee = DB::connection('chapter_order_mysql')->table('chapter_orders' . (($user->uid) % 512))
  52. ->where('uid', $user->uid)
  53. ->where('created_at', '<=', '2018-12-07 23:59:59')
  54. ->sum('fee');
  55. DB::connection('chapter_order_mysql')
  56. ->table($v.'_user_sub')
  57. ->where('uid',$user->uid)
  58. ->update(['fee'=>$fee]);
  59. }
  60. });
  61. //}
  62. return;
  63. //
  64. /* $companies = DB::table('companies')->where('is_important',1)->get();
  65. $internal_books = DB::table('book_configs')->where('is_on_shelf',1)->get();
  66. foreach ($companies as $company) {
  67. foreach ($internal_books as $internal_book){
  68. $data = ['bid'=>$internal_book->bid,'company_id'=>$company->id];
  69. CompanySpecialBook::updateOrCreate($data);
  70. }
  71. }*/
  72. /*for($i=0;$i<512;$i++){
  73. $count = DB::connection('chapter_order_mysql')->select("SELECT co.uid FROM ".'chapter_orders'."$i as co WHERE co.created_at>='2018-11-15 00:00:00' AND EXISTS(SELECT 1 FROM user_pay WHERE user_pay.uid=co.uid)");
  74. $chapter_order = DB::connection('chapter_order_mysql')
  75. ->select("SELECT co2.uid as Uid,sum(co2.fee) AS Fee FROM ".'chapter_orders'.$i." AS co2 WHERE co2.uid IN(SELECT co.uid FROM ".'chapter_orders'."$i as co WHERE co.created_at>='2018-11-15 00:00:00' AND EXISTS(SELECT 1 FROM user_pay WHERE user_pay.uid=co.uid)) GROUP BY co2.uid");
  76. }*/
  77. /* $res = DB::select("SELECT yq_move_channels.distribution_channel_id AS distribution_channelId,bills.recharge_amount as rechargeAmount,settlement_price AS settlementPrice,bills.recharge_amount-bills.settlement_price AS diff,bills.id as bill_id FROM bills,yq_move_channels WHERE bills.rate=0.9 AND bills.distribution_channel_id = yq_move_channels.distribution_channel_id and bills.date >= date(yq_move_channels.created_at) and yq_move_channels.created_at <= '2018-11-05'");
  78. foreach ($res as $item) {
  79. //DB::table('financial_stats')->where('distribution_channel_id',$item->distribution_channelId)->update()
  80. DB::select("UPDATE financial_stats SET financial_stats.enable_withdrawal_amount=financial_stats.enable_withdrawal_amount+".($item->diff)." WHERE financial_stats.distribution_channel_id=".$item->distribution_channelId);
  81. DB::select("UPDATE bills SET bills.settlement_price=bills.recharge_amount,bills.rate=1 WHERE bills.id=".($item->bill_id));
  82. \Log::info('changed:channel_id:'.($item->distribution_channelId).'diff:'.($item->diff).'bill_id:'.($item->bill_id));
  83. }*/
  84. \Log::info("user subscribe data task start-----time:".date('Y-m-d H:i:s'));
  85. print_r("user subscribe data task start-----time:".date('Y-m-d H:i:s'));
  86. $count =1;
  87. DB::table('force_subscribe_users')
  88. ->join('orders','orders.uid','=','force_subscribe_users.uid')
  89. ->select(DB::raw('distinct force_subscribe_users.uid'))
  90. ->where('orders.status','PAID')
  91. ->where('orders.created_at','>=','2018-11-01')
  92. ->whereBetween('subscribe_time',['2018-11-01','2018-11-25 23:59:59'])
  93. ->orderBy('uid')
  94. ->chunk(10000,function($res) use(&$count){
  95. $data = [];
  96. foreach ($res as $item){
  97. $books_order = DB::table('book_orders')
  98. ->where('uid',$item->uid)
  99. ->select(['uid','bid','created_at','fee as sum_fee','book_name'])
  100. ->whereBetween('created_at',['2018-11-01','2018-12-03 23:59:59'])
  101. ->get();
  102. $books_order = json_decode(json_encode($books_order),true);
  103. $chapter_orders = DB::connection('chapter_order_mysql')
  104. ->table('chapter_orders'.(($item->uid)%512))
  105. ->select(DB::raw('uid,bid,min(created_at) as created_at,book_name,sum(fee) as sum_fee'))
  106. ->groupBy('bid')
  107. ->where('uid',$item->uid)
  108. ->get();
  109. $chapter_orders = json_decode(json_encode($chapter_orders),true);
  110. $temps = array_merge($books_order,$chapter_orders);
  111. foreach ($temps as $temp){
  112. $data[]=array($temp['uid'],$temp['bid'],$temp['book_name'],$temp['sum_fee'],$temp['created_at']);
  113. }
  114. }
  115. $header = ['uid','bid','book_name','订阅书币','订阅时间'];
  116. saveExcelData($header,$data,storage_path('app/subscribe_data'.$count.'.xlsx'));
  117. print_r("done jobs count:".$count);
  118. $count++;
  119. });
  120. print_r("user subscribe data task end-----time:".date('Y-m-d H:i:s'));
  121. \Log::info("user subscribe data task end-----time:".date('Y-m-d H:i:s'));
  122. }
  123. }