xmo/mine-helpers

MineAdmin Helpers Library

v2.0.1.1 2024-06-22 16:25 UTC

This package is auto-updated.

Last update: 2024-10-22 17:10:21 UTC


README

FastBuilderWhere

use Hyperf\Database\Model\Builder;

use Mine\Helper\FastBuilderWhere as BaseBuilder;

// old 
class oldDao {
    public function handleSearch(Builder $builder,array $params) {
        if (!empty($params['username'])){
            $builder->where('username',$params['username']);
        }
        if (!empty($params['user_created_at'])){
            list($startDate,$endDate) = $params['user_created_at'];
            $builder->whereBetween('created_at',[
            \Carbon\Carbon::createFromFormat('Y-m-d',$startDate)->startOfDay()->format('Y-m-d'),
            \Carbon\Carbon::createFromFormat('Y-m-d',$endDate)->startOfDay()->format('Y-m-d')
            ]);
        }
        if (!empty($params['sign_timestamp_at'])){
            list($startDate,$endDate) = $params['created_at'];
            $builder->whereBetween('created_at',[
            \Carbon\Carbon::createFromFormat('Y-m-d',$startDate)->startOfDay()->timestamp,
            \Carbon\Carbon::createFromFormat('Y-m-d',$endDate)->startOfDay()->timestamp
            ]);
        }
        return $builder;
    }
}

// new dao
class newDao {
    public function handleSearch(BaseBuilder $builder,array $params) {
        $builder->eq('username')
                ->dateRange('created_at','user_created_at')
                ->timestampsRange('created_at','sign_timestamp_at');
        return $builder;
    }
}