<?php
/**
 * @package merchant
 *
 * @author xaboy
 * @day 2020/5/27
 *
 *
 */

namespace app\common\dao\user;


use app\common\dao\BaseDao;
use app\common\model\user\UserVisitDay;
use think\facade\Db;
use think\Model;

/**
 * Class UserVisitDayDao
 * @package app\common\dao\user
 * @author xaboy
 * @day 2020/5/27
 */
class UserVisitDayDao extends BaseDao
{

    /**
     * @return string
     * @author xaboy
     * @day 2020/5/27
     */
    protected function getModel(): string
    {
        return UserVisitDay::class;
    }

    public function incrUserVisitDay($day,$number=1)
    {
        if (empty(Db::name('user_visit_day')->where('day', $day)->find())) {
            Db::name('user_visit_day')->insert([
                'day'    => $day,
                'number' => 0,
            ]);
        }
        return Db::name('user_visit_day')->where('day', $day)->inc('number',$number)->update();
    }

    public function dateVisitUserNum($date): int
    {
        return (int)UserVisitDay::getDB()->when($date, function ($query, $date) {
            getModelTime($query, $date, 'create_time');
        })->value('number');
    }
}
