GenerateDayByBooksStat.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: sogndb
  5. * Date: 2018/02/05
  6. * Time: 下午5:26
  7. */
  8. namespace App\Console\Commands\SendOrder;
  9. use App\Modules\SendOrder\Models\SendOrderForceDayStat;
  10. use App\Modules\SendOrder\Services\SendOrderForceDayStatService;
  11. use App\Modules\SendOrder\Services\SendOrderStatService;
  12. use Illuminate\Console\Command;
  13. use Log;
  14. use DB;
  15. class GenerateDayByBooksStat extends Command
  16. {
  17. /**
  18. * 执行命令 php artisan send_order_generate_force_day_stat
  19. *
  20. * The name and signature of the console command.
  21. *
  22. * @var string
  23. */
  24. protected $signature = 'send_order:generate_stats_by_bid';
  25. /**
  26. * The console command description.
  27. *
  28. * @var string
  29. */
  30. protected $description = '每日图书派单数据生成';
  31. /**
  32. * Execute the console command.
  33. *
  34. * @return mixed
  35. */
  36. public function handle()
  37. {
  38. $i=1;
  39. $date = date("Y-m-d", strtotime(' -'.$i.' day'));
  40. $data = SendOrderForceDayStatService::getSendOrdersDayStatsByBid($date);
  41. $to_insert = json_decode(json_encode($data),true);
  42. \DB::table('book_promotion_day_stats')->insert($to_insert);
  43. $end_order_stats = \DB::table('send_orders_force_day_stats')
  44. ->join('books','send_orders_force_day_stats.bid','=','books.id')
  45. ->join('book_categories','book_categories.id','=','books.category_id')
  46. ->where('send_orders_force_day_stats.date',$date)
  47. ->select([DB::raw('sum(send_orders_force_day_stats.recharge_amount) as total_recharge'),'pid'])
  48. ->groupBy('book_categories.pid')
  49. ->get();
  50. $male_recharge=$female_recharge=0;
  51. foreach ($end_order_stats as $end_order_stat){
  52. if($end_order_stat->pid==1) $male_recharge = $end_order_stat->total_recharge;
  53. if($end_order_stat->pid==2) $female_recharge = $end_order_stat->total_recharge;
  54. }
  55. $insert_data = compact('male_recharge','female_recharge');
  56. $insert_data['date'] = $date;
  57. $insert_data['created_at']=date('Y-m-d H:i:s');
  58. $insert_data['updated_at']=date('Y-m-d H:i:s');
  59. DB::table('order_gender_stats')->insert($insert_data);
  60. }
  61. }