mirror of
https://github.com/crmeb/CRMEB.git
synced 2026-10-30 14:31:04 +00:00
更新basedao
This commit is contained in:
parent
f135b9c35b
commit
b11bfd0fa3
@ -46,12 +46,13 @@ abstract class BaseDao
|
||||
/**
|
||||
* 读取数据条数
|
||||
* @param array $where
|
||||
* @param bool $search
|
||||
* @return int
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
public function count(array $where = [])
|
||||
public function count(array $where = [], bool $search = true)
|
||||
{
|
||||
return $this->search($where)->count();
|
||||
return $this->search($where, $search)->count();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -324,7 +325,6 @@ abstract class BaseDao
|
||||
$with = [];
|
||||
$otherWhere = [];
|
||||
$responses = new \ReflectionClass($this->setModel());
|
||||
|
||||
foreach ($where as $key => $value) {
|
||||
$method = 'search' . Str::studly($key) . 'Attr';
|
||||
if ($responses->hasMethod($method)) {
|
||||
@ -352,10 +352,29 @@ abstract class BaseDao
|
||||
{
|
||||
[$with, $otherWhere] = $this->getSearchData($where);
|
||||
return $this->getModel()->withSearch($with, $where)->when($search, function ($query) use ($otherWhere) {
|
||||
$query->where($otherWhere);
|
||||
$query->where($this->filterWhere($otherWhere));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 过滤数据表中不存在的where条件字段
|
||||
* @param array $where
|
||||
* @return array
|
||||
* @author 吴汐
|
||||
* @email 442384644@qq.com
|
||||
* @date 2023/04/11
|
||||
*/
|
||||
protected function filterWhere(array $where = [])
|
||||
{
|
||||
$fields = $this->getModel()->getTableFields();
|
||||
foreach ($where as $key => $item) {
|
||||
if (!in_array($item[0], $fields)) {
|
||||
unset($where[$key]);
|
||||
}
|
||||
}
|
||||
return $where;
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜索
|
||||
* @param array $where
|
||||
|
||||
@ -65,12 +65,13 @@ class StoreCombinationDao extends BaseDao
|
||||
/**
|
||||
* 获取指定条件下的条数
|
||||
* @param array $where
|
||||
* @param bool $search
|
||||
* @return int
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
public function count(array $where = []): int
|
||||
public function count(array $where = [], bool $search = true): int
|
||||
{
|
||||
return $this->search($where)->count();
|
||||
return $this->search($where, $search)->count();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -35,11 +35,13 @@ class StoreIntegralDao extends BaseDao
|
||||
/**
|
||||
* 获取指定条件下的条数
|
||||
* @param array $where
|
||||
* @param bool $search
|
||||
* @return int
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
public function count(array $where = []): int
|
||||
public function count(array $where = [], bool $search = true): int
|
||||
{
|
||||
return $this->search($where)->count();
|
||||
return $this->search($where, $search)->count();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -89,11 +89,13 @@ class StoreIntegralOrderDao extends BaseDao
|
||||
/**
|
||||
* 获取订单总数
|
||||
* @param array $where
|
||||
* @param bool $search
|
||||
* @return int
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
public function count(array $where = []): int
|
||||
public function count(array $where = [], bool $search = true): int
|
||||
{
|
||||
return $this->search($where)->count();
|
||||
return $this->search($where, $search)->count();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -181,8 +181,17 @@ class OtherOrderDao extends BaseDao
|
||||
});
|
||||
}
|
||||
|
||||
public function count(array $where = []): int
|
||||
/**
|
||||
* @param array $where
|
||||
* @param bool $search
|
||||
* @return int
|
||||
* @throws \ReflectionException
|
||||
* @author 吴汐
|
||||
* @email 442384644@qq.com
|
||||
* @date 2023/04/11
|
||||
*/
|
||||
public function count(array $where = [], bool $search = true): int
|
||||
{
|
||||
return $this->search($where)->count();
|
||||
return $this->search($where, $search)->count();
|
||||
}
|
||||
}
|
||||
|
||||
@ -263,11 +263,13 @@ class StoreOrderDao extends BaseDao
|
||||
/**
|
||||
* 获取订单总数
|
||||
* @param array $where
|
||||
* @param bool $search
|
||||
* @return int
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
public function count(array $where = []): int
|
||||
public function count(array $where = [], bool $search = true): int
|
||||
{
|
||||
return $this->search($where)->count();
|
||||
return $this->search($where, $search)->count();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -28,7 +28,7 @@ class StoreProductLogDao extends BaseDao
|
||||
|
||||
public function getRanking($where)
|
||||
{
|
||||
return $this->search($where)->with('storeName')
|
||||
return $this->search($where, false)->with('storeName')
|
||||
->field([
|
||||
'product_id',
|
||||
'SUM(visit_num) as visit',
|
||||
@ -47,7 +47,7 @@ class StoreProductLogDao extends BaseDao
|
||||
|
||||
public function getRepeats($where, $product_id)
|
||||
{
|
||||
return count($this->search($where)->where('type', 'pay')->where('product_id', $product_id)->field('count(pay_uid) as p')->group('pay_uid')->having('p>1')->select());
|
||||
return count($this->search($where, false)->where('type', 'pay')->where('product_id', $product_id)->field('count(pay_uid) as p')->group('pay_uid')->having('p>1')->select());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -103,10 +103,11 @@ class WechatReplyKeyDao extends BaseDao
|
||||
/**
|
||||
* 获取条件下的条数
|
||||
* @param array $where
|
||||
* @param bool $search
|
||||
* @return int
|
||||
*/
|
||||
public function count(array $where = []): int
|
||||
public function count(array $where = [], bool $search = true): int
|
||||
{
|
||||
return $this->search($where)->group($this->alias . '.id')->count();
|
||||
return $this->search($where, $search)->group($this->alias . '.id')->count();
|
||||
}
|
||||
}
|
||||
|
||||
@ -131,11 +131,12 @@ class ArticleServices extends BaseServices
|
||||
/**
|
||||
* 获取数量
|
||||
* @param array $where
|
||||
* @param bool $search
|
||||
* @return int
|
||||
*/
|
||||
public function count(array $where)
|
||||
public function count(array $where = [], bool $search = true): int
|
||||
{
|
||||
return $this->dao->count($where);
|
||||
return $this->search($where, $search)->count();
|
||||
}
|
||||
|
||||
/**获取一条数据
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user