Нет описания

DayGrandRoiHistory.php 3.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use DB;
  5. class DayGrandRoiHistory extends Command {
  6. protected $signature = 'DayGrandRoiHistory';
  7. /**
  8. * The console command description.
  9. *
  10. * @var string
  11. */
  12. protected $description = '每日汇总投放,成本,毛利等数据';
  13. public function handle()
  14. {
  15. $this->DayGrandRoiHistory();
  16. }
  17. public function DayGrandRoiHistory(){
  18. $result = DB::table('day_grand_total')->select('id','idate')->get();
  19. $result = json_decode(json_encode($result), true);
  20. foreach($result as $k=>$v){
  21. //7 - 60 roi汇总
  22. $s7 = $v['idate']. ' -7 day';
  23. $date = date('Y-m-d', strtotime($s7));
  24. $data['cost7'] = DB::table('roi_total')->where('type', 1)->where('ad_time', '<=', $date)->sum('cost');
  25. $data['order_count7'] = DB::table('roi_total')->where('type', 1)->where('ad_time', '<=', $date)->sum('order_count');
  26. $data['order_amount7'] = DB::table('roi_total')->where('type', 1)->where('ad_time', '<=', $date)->sum('order_amount');
  27. $s15 = $v['idate']. ' -15 day';
  28. $date = date('Y-m-d', strtotime($s15));
  29. $data['cost15'] = DB::table('roi_total')->where('type', 2)->where('ad_time', '<=', $date)->sum('cost');
  30. $data['order_count15'] = DB::table('roi_total')->where('type', 2)->where('ad_time', '<=', $date)->sum('order_count');
  31. $data['order_amount15'] = DB::table('roi_total')->where('type', 2)->where('ad_time', '<=', $date)->sum('order_amount');
  32. $s30 = $v['idate']. ' -30 day';
  33. $date = date('Y-m-d', strtotime($s30));
  34. $data['cost30'] = DB::table('roi_total')->where('type', 3)->where('ad_time', '<=', $date)->sum('cost');
  35. $data['order_count30'] = DB::table('roi_total')->where('type', 3)->where('ad_time', '<=', $date)->sum('order_count');
  36. $data['order_amount30'] = DB::table('roi_total')->where('type', 3)->where('ad_time', '<=', $date)->sum('order_amount');
  37. $s45 = $v['idate']. ' -45 day';
  38. $date = date('Y-m-d', strtotime($s45));
  39. $data['cost45'] = DB::table('roi_total')->where('type', 4)->where('ad_time', '<=', $date)->sum('cost');
  40. $data['order_count45'] = DB::table('roi_total')->where('type', 4)->where('ad_time', '<=', $date)->sum('order_count');
  41. $data['order_amount45'] = DB::table('roi_total')->where('type', 4)->where('ad_time', '<=', $date)->sum('order_amount');
  42. $s60 = $v['idate']. ' -60 day';
  43. $date = date('Y-m-d', strtotime($s60));
  44. $data['cost60'] = DB::table('roi_total')->where('type', 5)->where('ad_time', '<=', $date)->sum('cost');
  45. $data['order_count60'] = DB::table('roi_total')->where('type', 5)->where('ad_time', '<=', $date)->sum('order_count');
  46. $data['order_amount60'] = DB::table('roi_total')->where('type', 5)->where('ad_time', '<=', $date)->sum('order_amount');
  47. $res = DB::table('day_grand_total')->where('id', $v['id'])->update($data);
  48. echo "\n日期:".$v['idate']." 更新结果:".$res;
  49. }
  50. }
  51. }