OfficialAccountBills.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace App\Modules\Finance\Models;
  3. use DB;
  4. use Illuminate\Database\Eloquent\Model;
  5. /**
  6. * Class Bill 账单
  7. * @package App\Modules\Finance\Models
  8. */
  9. class OfficialAccountBills extends Model
  10. {
  11. protected $table = 'official_account_bills';
  12. protected $fillable = ['distribution_channel_id', 'appid', 'date', 'nickname', 'recharge_amount', 'channel_recharge_amount'];
  13. /**
  14. * 获取服务号的充值信息
  15. * @param $distribution_channel_id
  16. * @param $start_time
  17. * @param $end_time
  18. * @param $isAll
  19. * @return mixed
  20. */
  21. static function getOfficialAccountBills($distribution_channel_id, $start_time, $end_time, $isAll)
  22. {
  23. $search_object = self::orderBy('official_account_bills.date', 'desc')->where('official_account_bills.distribution_channel_id', $distribution_channel_id)
  24. ->join('official_accounts', 'official_account_bills.appid', '=', 'official_accounts.appid')
  25. ->leftjoin('send_order_breakeven_stats', function ($join) {
  26. $join->on('official_accounts.id', '=', 'send_order_breakeven_stats.official_account_id')->on('official_account_bills.date', '=', 'send_order_breakeven_stats.date');
  27. });
  28. $search_object->select('official_account_bills.distribution_channel_id', 'official_account_bills.appid',
  29. 'official_account_bills.date', 'official_account_bills.nickname',
  30. 'official_account_bills.recharge_amount', 'official_account_bills.channel_recharge_amount',
  31. 'send_order_breakeven_stats.recharge_amount_in_one_month as recharge_amount_in_30_days',
  32. 'send_order_breakeven_stats.recharge_amount_in_two_months as recharge_amount_in_60_days',
  33. 'send_order_breakeven_stats.recharge_amount_in_three_months as recharge_amount_in_90_days',
  34. 'send_order_breakeven_stats.force_user_num as new_fans_num');
  35. if ($start_time) {
  36. $search_object->where('official_account_bills.date', '>=', $start_time);
  37. }
  38. if ($end_time) {
  39. $search_object->where('official_account_bills.date', '<=', $end_time);
  40. }
  41. if ($isAll) {
  42. return $search_object->get();
  43. } else {
  44. return $search_object->paginate();
  45. }
  46. }
  47. }