Siorder.php 4.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace App\Console\Commands\Temp;
  3. use Log;
  4. use Illuminate\Console\Command;
  5. use DB;
  6. class Siorder extends Command
  7. {
  8. /**
  9. * 执行命令 php artisan temp:siorder
  10. *
  11. * The name and signature of the console command.
  12. *
  13. * @var string
  14. */
  15. protected $signature = 'temp:siorder';
  16. /**
  17. * The console command description.
  18. *
  19. * @var string
  20. */
  21. protected $description = '书币消耗';
  22. /**
  23. * Execute the console command.
  24. *
  25. * @return mixed
  26. */
  27. public function handle()
  28. {
  29. /**
  30. * CREATE TABLE `si_orders` (
  31. `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  32. `uid` int(11) DEFAULT NULL,
  33. `first_recharge_time` datetime DEFAULT NULL,
  34. `sec_recharge_time` datetime DEFAULT NULL,
  35. `price` decimal(11,2) DEFAULT NULL,
  36. `site_id` int(11) DEFAULT NULL,
  37. `sub_time` datetime DEFAULT NULL,
  38. `balance` decimal(11,2) DEFAULT NULL,
  39. `x` int(11) DEFAULT NULL,
  40. `xx` int(11) DEFAULT NULL,
  41. `xxx` int(11) DEFAULT NULL,
  42. `xxxxxxx` int(11) DEFAULT NULL,
  43. `site_name` varchar(255) DEFAULT NULL,
  44. PRIMARY KEY (`id`)
  45. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  46. *
  47. * select distinct uid,created_at,price,distribution_channel_id from orders o where status ='PAID' and created_at > '2018-04-27' and created_at < '2018-05-02' and not exists(select id from orders where created_at < '2018-04-27' and status ='PAID' and uid = o.uid LIMIT 1)
  48. update si_orders,orders set si_orders.sec_recharge_time = orders.created_at where si_orders.uid = orders.uid and orders.created_at > si_orders.first_recharge_time and status ='PAID'
  49. update si_orders,force_subscribe_users set si_orders.sub_time = force_subscribe_users.created_at where si_orders.uid = force_subscribe_users.uid
  50. update si_orders,users set si_orders.balance = users.balance where si_orders.uid = users.id
  51. *
  52. * update si_orders,distribution_channels set si_orders.site_name = distribution_channels.nickname where si_orders.site_id = distribution_channels.id
  53. *
  54. *
  55. */
  56. print_r("======书币消耗 【任务执行开始】=====".date("y-m-d H:i:s"."\n"));
  57. Log::info("======书币消耗 【任务执行开始】=====".date("y-m-d H:i:s"."\n"));
  58. DB::table('si_orders')->orderBy('id','desc')->chunk(1000,function ($orders){
  59. foreach ($orders as $order)
  60. {
  61. $uid = $order->uid;
  62. $book_fee1 = (int)DB::table('book_orders')->where('uid',$uid)->where('created_at','>',$order->first_recharge_time)->where('created_at','<',date('Y-m-d H:i:s',strtotime($order->first_recharge_time)+86400))->sum('fee');
  63. $book_fee2 = DB::table('book_orders')->where('uid',$uid)->where('created_at','>',$order->first_recharge_time)->where('created_at','<',date('Y-m-d H:i:s',strtotime($order->first_recharge_time)+86400*2))->sum('fee');
  64. $book_fee3 = DB::table('book_orders')->where('uid',$uid)->where('created_at','>',$order->first_recharge_time)->where('created_at','<',date('Y-m-d H:i:s',strtotime($order->first_recharge_time)+86400*3))->sum('fee');
  65. $book_fee7 = DB::table('book_orders')->where('uid',$uid)->where('created_at','>',$order->first_recharge_time)->where('created_at','<',date('Y-m-d H:i:s',strtotime($order->first_recharge_time)+86400*7))->sum('fee');
  66. $table = 'chapter_orders'.$uid%512;
  67. $x = $book_fee1 + (int)DB::connection('chapter_order_mysql')->table($table)->where('uid',$uid)->where('created_at','>',$order->first_recharge_time)->where('created_at','<',date('Y-m-d H:i:s',strtotime($order->first_recharge_time)+86400))->sum('fee');
  68. $xx = $book_fee2 + (int)DB::connection('chapter_order_mysql')->table($table)->where('uid',$uid)->where('created_at','>',$order->first_recharge_time)->where('created_at','<',date('Y-m-d H:i:s',strtotime($order->first_recharge_time)+86400*2))->sum('fee');
  69. $xxx = $book_fee3 + (int)DB::connection('chapter_order_mysql')->table($table)->where('uid',$uid)->where('created_at','>',$order->first_recharge_time)->where('created_at','<',date('Y-m-d H:i:s',strtotime($order->first_recharge_time)+86400*3))->sum('fee');
  70. $xxxxxxx = $book_fee7 + (int)DB::connection('chapter_order_mysql')->table($table)->where('uid',$uid)->where('created_at','>',$order->first_recharge_time)->where('created_at','<',date('Y-m-d H:i:s',strtotime($order->first_recharge_time)+86400*7))->sum('fee');
  71. DB::table('si_orders')->where('id',$order->id)->update(compact('x','xx','xxx','xxxxxxx'));
  72. }
  73. });
  74. Log::info("======书币消耗 【任务执行结束】=====" . date("y-m-d H:i:s" . "\n"));
  75. print_r("======书币消耗 【任务执行结束】=====" . date("y-m-d H:i:s" . "\n"));
  76. }
  77. }