UserPayUpdateTask.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: tandunzhao
  5. * Date: 2017/11/20
  6. * Time: 下午5:26
  7. */
  8. namespace App\Console\Commands;
  9. use DB;
  10. use Illuminate\Console\Command;
  11. use Log;
  12. use Redis;
  13. class UserPayUpdateTask extends Command
  14. {
  15. /**
  16. * 执行命令 php artisan force_user_active
  17. *
  18. * The name and signature of the console command.
  19. *
  20. * @var string
  21. */
  22. protected $signature = 'userPayUpdateTask';
  23. /**
  24. * The console command description.
  25. *
  26. * @var string
  27. */
  28. protected $description = '更新user_pay表字段';
  29. /**
  30. * Execute the console command.
  31. *
  32. * @return mixed
  33. */
  34. public function handle()
  35. {
  36. $min_id = DB::table('global_configs')->where('config','pay_user_orders_max_id')->first();
  37. $min_id = $min_id->config_value;
  38. $max_id = DB::table('orders')->max('id');
  39. while ($min_id <= $max_id) {
  40. \Log::info('insert_sql:'."insert into user_pay (uid,distribution_channel_id,first_recharge_time,first_recharge_amount)
  41. select uid,distribution_channel_id,min(created_at),price from orders
  42. where status ='PAID' and orders.id >=".$min_id." and orders.id<=".($min_id+9999)." and not EXISTS
  43. (select 1 from user_pay where uid = orders.uid) GROUP BY uid");
  44. \Log::info("sec_recharge_update:update user_pay set user_pay.sec_recharge_time = (SELECT orders.created_at FROM orders
  45. where user_pay.uid = orders.uid and orders.created_at > user_pay.first_recharge_time and status = 'PAID' LIMIT 1),user_pay.sec_recharge_amount=(SELECT orders.price FROM orders
  46. where user_pay.uid = orders.uid and orders.created_at > user_pay.first_recharge_time and status = 'PAID' LIMIT 1) WHERE user_pay.sec_recharge_time is null");
  47. $min_id+9999;
  48. }
  49. }
  50. private function test1()
  51. {
  52. $array = ['recent_read','subscribe','text_sign','text_search','readerover','readrecord','daily_sign'];//
  53. // $array = ['daily_sign'];
  54. foreach ($array as $v){
  55. $users = Redis::SMEMBERS("temp_from_where:".$v);
  56. foreach ($users as $user){
  57. $sub = DB::connection('chapter_order_mysql')
  58. ->table('chapter_orders'.($user%512))
  59. ->where('uid',$user)
  60. ->whereBetween('created_at',['2018-11-23','2018-12-07 23:59:59'])
  61. ->first();
  62. if($sub){
  63. $fee = DB::connection('chapter_order_mysql')
  64. ->table($v.'_user')
  65. ->select('uid','fee')
  66. ->where('uid',$user)
  67. ->first();
  68. DB::connection('chapter_order_mysql')
  69. ->table($v.'_user_sub')
  70. ->insert(['uid'=>$user,'fee'=>isset($fee->fee)?$fee->fee:-1]);
  71. }
  72. }
  73. }
  74. }
  75. private function test2() {
  76. $users = DB::table('daily_sign_user_sub')->where('fee',-1)->get();
  77. foreach ($users as $user){
  78. $fee = DB::table('chapter_orders'.($user%512))
  79. ->where('uid',$user->uid)
  80. ->where('created_at','<=','2018-12-07 23:59:59')
  81. ->sum('fee');
  82. $user->fee = $fee;
  83. $user->save();
  84. }
  85. }
  86. }