RegisterUserDayStat.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: hp
  5. * Date: 2017/11/21
  6. * Time: 10:42
  7. */
  8. namespace App\Modules\User\Models;
  9. use Illuminate\Database\Eloquent\Model;
  10. use DB;
  11. class RegisterUserDayStat extends Model
  12. {
  13. protected $table = 'promotion_day_city_user_stats';
  14. protected $fillable =
  15. ['id', 'date', 'country', 'province', 'city', 'register_user_num', 'recharge_in_one_day',
  16. 'arpu_in_one_day', 'created_at', 'updated_at'
  17. ];
  18. static function getRecord($date, $country, $province, $city)
  19. {
  20. return self::where('date', $date)->where('country', $country)
  21. ->where('province', $province)
  22. ->where('city', $city)->first();
  23. }
  24. static function addItem($data)
  25. {
  26. return self::create($data);
  27. }
  28. static function getWeekTotalInfo($begin_date, $end_date)
  29. {
  30. $search_obj = self::where('date', '>=', $begin_date)->where('date', '<=', $end_date);
  31. $search_obj->select(
  32. 'country',
  33. 'province',
  34. DB::raw('sum(register_user_num) sum_register_user_num'),
  35. DB::raw('sum(recharge_in_one_day) sum_recharge_in_one_day'),
  36. DB::raw('sum(recharge_in_one_day)/sum(register_user_num) sum_arup')
  37. );
  38. $search_obj->orderBy('sum_recharge_in_one_day', 'desc');
  39. $search_obj->groupBy('country')->groupBy('province');
  40. return $search_obj->get();
  41. }
  42. }