SystemDailyReport.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace app\models\system;
  3. use app\models\merchant\Merchant;
  4. use app\models\store\StoreOrder;
  5. use app\models\user\User;
  6. use crmeb\basic\BaseModel;
  7. use crmeb\traits\ModelTrait;
  8. use think\db\exception\DataNotFoundException;
  9. use think\db\exception\DbException;
  10. use think\db\exception\ModelNotFoundException;
  11. class SystemDailyReport extends BaseModel
  12. {
  13. /**
  14. * 数据表主键
  15. * @var string
  16. */
  17. protected $pk = 'id';
  18. /**
  19. * 模型名称
  20. * @var string
  21. */
  22. protected $name = 'system_daily_report';
  23. use ModelTrait;
  24. /**
  25. * 记录昨天的记录
  26. * @throws DataNotFoundException
  27. * @throws DbException
  28. * @throws ModelNotFoundException
  29. */
  30. public static function recordYesterdayReport()
  31. {
  32. if (self::where('report_date', date('Y-m-d', strtotime('-1day')))->find()) {
  33. return;
  34. }
  35. $add = [
  36. 'report_date' => date('Y-m-d', strtotime('-1day')),
  37. 'add_time' => time(),
  38. 'today_reg' => User::whereDay('add_time', 'yesterday')->count(),
  39. 'today_visit' => User::whereDay('last_time', 'yesterday')->count(),
  40. 'today_order' => StoreOrder::whereDay('add_time', 'yesterday')->count(),
  41. 'today_order_money' => StoreOrder::where('paid', 1)
  42. ->where('is_del', 0)
  43. ->where('refund_status', 0)
  44. ->whereDay('pay_time', 'yesterday')
  45. ->sum('pay_price'),];
  46. self::create($add);
  47. }
  48. }