diff --git a/crmeb/app/dao/BaseDao.php b/crmeb/app/dao/BaseDao.php index 8cfb30181..ca604a7b3 100644 --- a/crmeb/app/dao/BaseDao.php +++ b/crmeb/app/dao/BaseDao.php @@ -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 diff --git a/crmeb/app/dao/activity/combination/StoreCombinationDao.php b/crmeb/app/dao/activity/combination/StoreCombinationDao.php index ef78215ce..f8f14349a 100644 --- a/crmeb/app/dao/activity/combination/StoreCombinationDao.php +++ b/crmeb/app/dao/activity/combination/StoreCombinationDao.php @@ -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(); } /** diff --git a/crmeb/app/dao/activity/integral/StoreIntegralDao.php b/crmeb/app/dao/activity/integral/StoreIntegralDao.php index 94df3303b..a39f9faeb 100644 --- a/crmeb/app/dao/activity/integral/StoreIntegralDao.php +++ b/crmeb/app/dao/activity/integral/StoreIntegralDao.php @@ -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(); } /** diff --git a/crmeb/app/dao/activity/integral/StoreIntegralOrderDao.php b/crmeb/app/dao/activity/integral/StoreIntegralOrderDao.php index 31f6142bc..c9af9bc1f 100644 --- a/crmeb/app/dao/activity/integral/StoreIntegralOrderDao.php +++ b/crmeb/app/dao/activity/integral/StoreIntegralOrderDao.php @@ -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(); } /** diff --git a/crmeb/app/dao/order/OtherOrderDao.php b/crmeb/app/dao/order/OtherOrderDao.php index 770eddaf5..c5e6f1437 100644 --- a/crmeb/app/dao/order/OtherOrderDao.php +++ b/crmeb/app/dao/order/OtherOrderDao.php @@ -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(); } } diff --git a/crmeb/app/dao/order/StoreOrderDao.php b/crmeb/app/dao/order/StoreOrderDao.php index 703c88d6b..67c94b37c 100644 --- a/crmeb/app/dao/order/StoreOrderDao.php +++ b/crmeb/app/dao/order/StoreOrderDao.php @@ -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(); } /** diff --git a/crmeb/app/dao/product/product/StoreProductLogDao.php b/crmeb/app/dao/product/product/StoreProductLogDao.php index 8285db7fe..58fa07cae 100644 --- a/crmeb/app/dao/product/product/StoreProductLogDao.php +++ b/crmeb/app/dao/product/product/StoreProductLogDao.php @@ -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()); } /** diff --git a/crmeb/app/dao/wechat/WechatReplyKeyDao.php b/crmeb/app/dao/wechat/WechatReplyKeyDao.php index 633d53d82..a14560f9d 100644 --- a/crmeb/app/dao/wechat/WechatReplyKeyDao.php +++ b/crmeb/app/dao/wechat/WechatReplyKeyDao.php @@ -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(); } } diff --git a/crmeb/app/services/article/ArticleServices.php b/crmeb/app/services/article/ArticleServices.php index 0cc0032b3..4cc3b5f86 100644 --- a/crmeb/app/services/article/ArticleServices.php +++ b/crmeb/app/services/article/ArticleServices.php @@ -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(); } /**获取一条数据