chore: 添加静态资源文件和版本配置文件

添加大量图片、字体、音频等静态资源文件,包括用户界面图片、模板文件和安装界面素材
添加系统版本配置文件(.version)和常量定义文件(.constant)
更新供应商依赖文件,包括Symfony VarDumper组件和相关许可证文件
添加验证码配置文件(captcha.php)和.gitignore规则
This commit is contained in:
2026-03-06 20:14:23 +08:00
commit c9a98f342c
4485 changed files with 490986 additions and 0 deletions

View File

@@ -0,0 +1,113 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\user;
use app\dao\BaseDao;
use app\model\user\User;use app\model\user\UserAddress;
/**
* 用户收获地址
* Class UserAddressDao
* @package app\dao\user
*/
class UserAddressDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return UserAddress::class;
}
/**
* 设置关联模型
* @return string
*/
protected function JoinModel() : string
{
return User::class;
}
/**
* 获取关联模型查询
* @param string $alias 主表别名
* @param string $join_alias 关联表别名
* @param string $join 关联类型
* @return \crmeb\basic\BaseModel
*/
public function getJoinModel(string $alias = 'a', string $join_alias = 'u', $join = 'left')
{
$this->alias = $alias;
$this->joinAlis = $join_alias;
/** @var User $user */
$user = app()->make($this->joinModel());
$table = $user->getName();
return parent::getModel()->alias($alias)->join($table . ' ' . $join_alias, $alias . '.uid = ' . $join_alias . '.uid', $join);
}
/**
* 获取列表
* @param array $where
* @param string $field
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $where, string $field = '*', int $page = 0, int $limit = 0): array
{
return $this->search($where)->field($field)->page($page, $limit)->order('is_default DESC')->select()->toArray();
}
/**
* 地域全部用户
* @param $time
* @param $userType
* @return mixed
*/
public function getRegionAll($time, $userType)
{
return $this->getJoinModel()->when($userType != '', function ($query) use ($userType) {
$query->where($this->joinAlis . '.user_type', $userType);
})->where(function ($query) use ($time) {
$query->whereTime($this->joinAlis . '.add_time', '<', strtotime($time[1]) + 86400)->whereOr($this->joinAlis . '.add_time', NULL);
})->field('count(distinct(' . $this->alias . '.uid)) as allNum,' . $this->alias . '.province')
->group($this->alias . '.province')->select()->toArray();
}
/**
* 地域新增用户
* @param $time
* @param $userType
* @return mixed
*/
public function getRegionNew($time, $userType)
{
return $this->getJoinModel()->when($userType != '', function ($query) use ($userType) {
$query->where($this->joinAlis . '.user_type', $userType);
})->where(function ($query) use ($time) {
if ($time[0] == $time[1]) {
$query->whereDay($this->joinAlis . '.add_time', $time[0]);
} else {
$time[1] = date('Y-m-d', strtotime($time[1]) + 86400);
$query->whereTime($this->joinAlis . '.add_time', 'between', $time);
}
})->field('count(distinct(' . $this->alias . '.uid)) as newNum,' . $this->alias . '.province')
->group($this->alias . '.province')->select()->toArray();
}
}

View File

@@ -0,0 +1,35 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types = 1);
namespace app\dao\user;
use app\dao\BaseDao;
use app\model\user\User;
/**
*
* Class UserAuthDao
* @package app\dao\user
*/
class UserAuthDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return User::class;
}
}

View File

@@ -0,0 +1,290 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\user;
use app\dao\BaseDao;
use app\model\user\UserBill;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
/**
* 积分&经验
* Class UserBilldao
* @package app\dao\user
*/
class UserBillDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return UserBill::class;
}
/**
* 获取列表
* @param array $where
* @param string $field
* @param int $page
* @param int $limit
* @param array $typeWhere
* @return array
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function getList(array $where, string $field = '*', int $page = 0, int $limit = 0, array $typeWhere = [])
{
return $this->search($where)->when(count($typeWhere) > 0, function ($query) use ($typeWhere) {
$query->where($typeWhere);
})->field($field)->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order('id desc')->select()->toArray();
}
/**
* 获取列表
* @param array $where
* @param string $field
* @param int $page
* @param int $limit
* @return array
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function getBillList(array $where, string $field = '*', int $page = 0, int $limit = 0): array
{
return $this->search($where)
->field($field)
->with(['user' => fn($query) => $query->field('uid,nickname')])
->when($page && $limit, fn($query) => $this->pageQueryModel($query, $page, $limit, isset($where['id']) ? (int)$where['id'] : 0, '<'))
->order('id desc')
->select()
->toArray();
}
/**
* 获取某个条件总数
* @param array $where
* @return float
*/
public function getBillSum(array $where)
{
return $this->search($where)->sum('number');
}
/**
* 获取某个条件总条数
* @param array $where
* @return int
* @throws DbException
*/
public function getBillCount(array $where)
{
return $this->getModel()->where($where)->count();
}
/**
* 获取某些条件的bill总数
* @param array $where
* @return mixed
*/
public function getBillSumColumn(array $where)
{
if (isset($where['uid']) && is_array($where['uid'])) {
return $this->search($where)->group('uid')->column('sum(number) as num', 'uid');
} else
return $this->search($where)->sum('number');
}
/**
* 获取类型
* @param array $where
* @param string $filed
* @return mixed
*/
public function getType(array $where, string $filed = 'title,type')
{
return $this->search($where)->distinct(true)->field($filed)->group('type')->select();
}
/**
* 获取签到用户数量
* @param array $where
* @return int
* @throws DbException
*/
public function getUserSignPoint(array $where)
{
return $this->search($where)->count();
}
/**
* @param array $where
* @return array
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function getUserBillList(array $where): array
{
return $this->search($where)->select()->toArray();
}
/**
* 获取佣金排行
* @param array $where
* @param int $page
* @param int $limit
* @return array
*/
public function brokerageRankList(array $where, int $page = 0, int $limit = 0)
{
return $this->search($where)->field('uid,SUM(IF(pm=1,`number`,-`number`)) as brokerage_price')->with(['user' => function ($query) {
$query->field('uid,avatar,nickname');
}])->order('brokerage_price desc')->group('uid')->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->select()->toArray();
}
/**
* 时间分组
* @param array $where
* @param string $filed
* @param string $group
* @param int $page
* @param int $limit
* @return mixed
*/
public function getUserBillListByGroup(array $where, string $filed, string $group, int $page, int $limit)
{
return $this->search($where)->field($filed)->where('number', '>', 0)->order('add_time desc')->group($group)->page($page, $limit)->select()->toArray();
}
/**
* @param array $where
* @param int $page
* @param int $limit
* @return array
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function getBalanceRecord(array $where, int $page, int $limit)
{
return $this->search($where)->order('add_time desc')->page($page, $limit)->select()->toArray();
}
/**
* 计算某个条件下订单内商品总数
* @param array $where
* @return float|int
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function getTotalSum(array $where)
{
$list = $this->search($where)->with('order')->select()->toArray();
if (count($list)) {
$sum = 0;
foreach ($list as $item) {
$sum += $item['total_num'];
}
return $sum;
} else {
return 0;
}
}
/**
* 获取某个字段总和
* @param array $where
* @param string $field
* @return float
*/
public function getWhereSumField(array $where, string $field)
{
return $this->search($where)
->when(isset($where['timeKey']), function ($query) use ($where) {
$query->whereBetweenTime('add_time', $where['timeKey']['start_time'], $where['timeKey']['end_time']);
})
->sum($field);
}
/**
* 根据某字段分组查询
* @param array $where
* @param string $field
* @param string $group
* @return array
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function getGroupField(array $where, string $field, string $group)
{
return $this->search($where)
->when(isset($where['timeKey']), function ($query) use ($where, $field, $group) {
$query->whereBetweenTime('add_time', $where['timeKey']['start_time'], $where['timeKey']['end_time']);
if ($where['timeKey']['days'] == 1) {
$timeUinx = "%H";
} elseif ($where['timeKey']['days'] == 30) {
$timeUinx = "%Y-%m-%d";
} elseif ($where['timeKey']['days'] == 365) {
$timeUinx = "%Y-%m";
} elseif ($where['timeKey']['days'] > 1 && $where['timeKey']['days'] < 30) {
$timeUinx = "%Y-%m-%d";
} elseif ($where['timeKey']['days'] > 30 && $where['timeKey']['days'] < 365) {
$timeUinx = "%Y-%m";
} else {
$timeUinx = "%Y-%m";
}
$query->field("sum($field) as number,FROM_UNIXTIME($group, '$timeUinx') as time");
$query->group("FROM_UNIXTIME($group, '$timeUinx')");
})
->order('add_time ASC')->select()->toArray();
}
/**
* 积分趋势
* @param $time
* @param $timeType
* @param $field
* @param $str
* @return mixed
*/
public function getPointTrend($time, $timeType, $field, $str, $orderStatus = '')
{
return $this->getModel()->where(function ($query) use ($field, $orderStatus) {
$query->where('category', 'integral');
if ($orderStatus == 'add') {
$query->where('pm', 1);
} elseif ($orderStatus == 'sub') {
$query->where('pm', 0);
}
})->where(function ($query) use ($time, $field) {
if ($time[0] == $time[1]) {
$query->whereDay($field, $time[0]);
} else {
$query->whereTime($field, 'between', $time);
}
})->field("FROM_UNIXTIME($field,'$timeType') as days,$str as num")->group('days')->select()->toArray();
}
}

View File

@@ -0,0 +1,178 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\user;
use app\dao\BaseDao;
use app\model\user\UserBrokerage;
use think\db\exception\DbException;
/**
* 用户佣金
* Class UserBrokerageDao
* @package app\dao\user
*/
class UserBrokerageDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return UserBrokerage::class;
}
/**
* 获取列表
* @param array $where
* @param string $field
* @param int $page
* @param int $limit
* @param array $typeWhere
* @param array $with
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $where, string $field = '*', int $page = 0, int $limit = 0, array $typeWhere = [], array $with = [])
{
return $this->search($where)->when(count($typeWhere) > 0, function ($query) use ($typeWhere) {
$query->where($typeWhere);
})->field($field)->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->when(!empty($with), function ($query) use ($with) {
$query->with($with);
})->order('id desc')->select()->toArray();
}
/**
* 获取佣金排行
* @param array $where
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function brokerageRankList(array $where, int $page = 0, int $limit = 0)
{
return $this->search($where)
->field("
uid,
SUM(
CASE
WHEN type NOT IN ('refund', 'extract_fail') AND pm = 1 THEN number
WHEN type = 'refund' THEN -number
END
) AS brokerage_price
")
->with(['user' => function ($query) {
$query->field('uid, avatar, nickname');
}])
->order('brokerage_price DESC')
->group('uid')
->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})
->select()
->toArray();
}
/**
* @param array $where
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getUserBrokerageList(array $where)
{
return $this->search($where)->select()->toArray();
}
/**
* 获取佣金记录类型
* @param array $where
* @param string $filed
* @return mixed
*/
public function getType(array $where, string $filed = 'title,type')
{
return $this->search($where)->distinct(true)->field($filed)->group('type')->select();
}
/**
* 修改收货状态
* @param int $uid
* @param int $id
* @return \crmeb\basic\BaseModel
*/
public function takeUpdate(int $uid, int $id)
{
return $this->getModel()->where('uid', $uid)->where('link_id', $id)->where('type', 'IN', ['one_brokerage', 'two_brokerage'])->update(['take' => 1]);
}
/**
* 获取某个账户下的冻结佣金
* @param int $uid
* @return float
* @throws \ReflectionException
*/
public function getUserFrozenPrice(int $uid)
{
return $this->search(['uid' => $uid, 'status' => 1, 'pm' => 1])->where('frozen_time', '>', time())->sum('number');
}
/**
* 获取某个条件总数
* @param array $where
*/
public function getBrokerageSum(array $where)
{
return $this->search($where)->sum('number');
}
/**
* 获取列表
* @param array $where
* @param string $field
* @param int $page
* @param int $limit
* @return array
*/
public function getBrokerageList(array $where, string $field = '*', int $page = 0, int $limit = 0)
{
return $this->search($where)->field($field)->with([
'user' => function ($query) {
$query->field('uid,nickname');
}])->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order('id desc')->select()->toArray();
}
/**
* 获取某些条件的bill总数
* @param array $where
* @return mixed
*/
public function getBrokerageSumColumn(array $where)
{
if (isset($where['uid']) && is_array($where['uid'])) {
return $this->search($where)->group('uid')->column('sum(number) as num', 'uid');
} else
return $this->search($where)->sum('number');
}
}

View File

@@ -0,0 +1,35 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\user;
use app\dao\BaseDao;
use app\model\user\UserBrokerageFrozen;
use crmeb\basic\BaseModel;
/**
* 佣金冻结
* Class UserBrokerageFrozenDao
* @package app\dao\user
*/
class UserBrokerageFrozenDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return UserBrokerageFrozen::class;
}
}

View File

@@ -0,0 +1,56 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\user;
use app\dao\BaseDao;
use app\model\user\UserCard;
/**
* 用户领取卡券
* Class UserCardDao
* @package app\dao\user
*/
class UserCardDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return UserCard::class;
}
/**
* 获取激活会员卡列表
* @param array $where
* @param string $field
* @param array $with
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $where, string $field = '*', array $with = [], int $page = 0, $limit = 0)
{
return $this->search($where)->field($field)
->when($with, function ($query) use ($with) {
$query->with($with);
})->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order('add_time desc,id desc')->select()->toArray();
}
}

449
app/dao/user/UserDao.php Normal file
View File

@@ -0,0 +1,449 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\user;
use app\dao\BaseDao;
use app\model\user\User;
use crmeb\basic\BaseModel;
/**
* 用户
* Class UserDao
* @package app\dao\user
*/
class UserDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return User::class;
}
/**
* @param array $where
* @param bool $search
* @return BaseModel
* @throws \ReflectionException
*/
public function search(array $where = [], bool $search = false)
{
return parent::search($where, $search)->when(isset($where['label_id']) && $where['label_id'], function ($query) use ($where) {
$query->whereIn('uid', function ($q) use ($where) {
if (is_array($where['label_id'])) {
$q->name('user_label_relation')->whereIn('label_id', $where['label_id'])->field('uid')->select();
} else {
if (strpos($where['label_id'], ',') !== false) {
$q->name('user_label_relation')->whereIn('label_id', explode(',', $where['label_id']))->field('uid')->select();
} else {
$q->name('user_label_relation')->where('label_id', $where['label_id'])->field('uid')->select();
}
}
});
});
}
/**
* 是否存在
* @param int $uid
* @return bool
*/
public function exist(int $uid)
{
return !!$this->getModel()->where('uid', $uid)->count();
}
/**
* @param array $where
* @return mixed
*/
public function getWithTrashedCount(array $where = [], array $time = [])
{
return $this->getModel()->withTrashed()->where($where)->whereTime('add_time', 'between', $time)->count();
}
/**
* 仅查询已删除用户
* @param array $where
* @return mixed
*/
public function getUserOnlyTrashedCount(array $where = [])
{
return $this->getModel()->onlyTrashed()->where($where)->count();
}
/**
* 获取删除和没有删除的用户信息
* @param int $uid
* @param $field
* @return mixed
*/
public function getUserWithTrashedInfo(int $uid, $field = '*')
{
return $this->getModel()->withTrashed()->field($field)->find($uid);
}
/**
* 获取用户列表
* @param array $where
* @param string $field
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $where, string $field = '*', int $page = 0, int $limit = 0, $order = ''): array
{
return $this->search($where)->field($field)->with(['label'])->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->when($order != '', function ($query) use ($order) {
$query->order($order);
})->select()->toArray();
}
/**
* @param array $where
* @return array|string
*/
public function getCountList(array $where)
{
return $this->getModel()->where($where)->group('uid')->column('count(*) as user_count', 'uid');
}
/**
* 获取特定条件的总数
* @param array $where
* @return int
* @throws \think\db\exception\DbException
*/
public function getCount(array $where): int
{
return $this->getModel()->where($where)->count();
}
/**
* 用户支付成功个数增加
* @param int $uid
* @return mixed
*/
public function incPayCount(int $uid)
{
event('user.update', [$uid]);
return $this->getModel()->where('uid', $uid)->inc('pay_count', 1)->update();
}
/**
* 某个字段累加某个数值
* @param string $field
* @param int $num
*/
public function incField(int $uid, string $field, int $num = 1)
{
event('user.update', [$uid]);
return $this->getModel()->where('uid', $uid)->inc($field, $num)->update();
}
/**
* @param $uid
* @return \think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getUserLabel($uid, $field = '*')
{
return $this->search(['uid' => $uid])->field($field)->with(['label'])->select()->toArray();
}
/**
* 获取分销用户
* @param array $where
* @param string $field
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getAgentUserList(array $where, string $field = '*', int $page = 0, int $limit = 0)
{
return $this->search($where)->field($field)->with([
'extract' => function ($query) {
$query->field('sum(extract_price + extract_fee) as extract_count_price,count(id) as extract_count_num,uid')->where('status', '1')->group('uid');
}, 'order' => function ($query) {
$query->field('sum(pay_price) as order_price,count(id) as order_count,uid')->where('pid', '>=', 0)->where('paid', 1)->where('is_del', 0)->where('is_system_del', 0)->where('refund_status', 'IN', [0, 3])->group('uid');
}, 'brokerage' => function ($query) {
$query->field('sum(number) as brokerage_money,uid')->where('status', 1)->where('pm', 1)->group('uid');
}, 'spreadCount' => function ($query) {
$query->field('count(`uid`) as spread_count,spread_uid')->group('spread_uid');
}, 'spreadUser' => function ($query) {
$query->field('uid,phone,nickname');
}, 'agentLevel' => function ($query) {
$query->field('id,name');
}
])->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order('uid desc')->select()->toArray();
}
/**
* 获取推广人列表
* @param array $where
* @param string $field
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getSairList(array $where, string $field = '*', int $page = 0, int $limit = 0)
{
return $this->search($where)->field($field)->with([
'order' => function ($query) {
$query->field('sum(pay_price) as order_price,count(id) as order_count,uid')->where('paid', 1)->where('refund_status', 0)->group('uid');
}, 'spreadCount' => function ($query) {
$query->field('count(`uid`) as spread_count,spread_uid')->group('spread_uid');
}, 'spreadUser' => function ($query) {
$query->field('uid,phone,nickname');
}
])->page($page, $limit)->order('uid desc')->select()->toArray();
}
/**
* 获取推广人排行
* @param array $time
* @param string $field
* @param int $page
* @param int $limit
*/
public function getAgentRankList(array $time, string $field = '*', int $page = 0, int $limit = 0)
{
return $this->getModel()->alias('t0')
->field($field)
->join('user t1', 't0.uid = t1.spread_uid', 'LEFT')
->where('t1.spread_uid', '<>', 0)
->order('count desc')
->order('t0.uid desc')
->where('t1.spread_time', 'BETWEEN', $time)
->page($page, $limit)
->group('t0.uid')
->select()->toArray();
}
/**
* 获取推广员ids
* @param array $where
* @return array
*/
public function getAgentUserIds(array $where)
{
return $this->search($where)->column('uid');
}
/**
* 某个条件 用户某个字段总和
* @param array $where
* @param string $filed
* @return float
*/
public function getWhereSumField(array $where, string $filed)
{
return $this->search($where)->sum($filed);
}
/**
* 根据条件查询对应的用户信息以数组形式返回
* @param array $where
* @param string $field
* @param string $key
* @return array
*/
public function getUserInfoArray(array $where, string $field, string $key)
{
return $this->search($where)->column($field, $key);
}
/**
* 获取特定时间用户访问量
* @param $time
* @param $week
* @return int
*/
public function todayLastVisit($time, $week)
{
switch ($week) {
case 1:
return $this->search(['time' => $time ?: 'today', 'timeKey' => 'last_time'])->count();
case 2:
return $this->search(['time' => $time ?: 'week', 'timeKey' => 'last_time'])->count();
}
}
/**
* 获取特定时间用户访问量
* @param $time
* @return int
*/
public function totalUserCount($time)
{
return $this->search(['time' => $time ?: 'today', 'timeKey' => 'add_time'])->count();
}
/**
* 获取特定时间内用户列表
* @param $starday
* @param $yesterday
* @return mixed
*/
public function userList($starday, $yesterday)
{
return $this->getModel()->where('add_time', 'between time', [$starday, $yesterday])
->field("FROM_UNIXTIME(add_time,'%Y-%m-%d') as day,count(*) as count")
->group("FROM_UNIXTIME(add_time, '%Y%m%d')")
->order('add_time asc')
->select()->toArray();
}
/**
* 购买量范围的用户数量
* @param $status
* @return int
*/
public function userCount($status)
{
switch ($status) {
case 1:
return $this->getModel()->where('pay_count', '>', 1)->where('pay_count', '<=', 4)->count();
case 2:
return $this->getModel()->where('pay_count', '>', 4)->count();
}
}
/**
* 获取用户统计数据
* @param $time
* @param $type
* @param $timeType
* @return mixed
*/
public function getTrendData($time, $type, $timeType)
{
return $this->getModel()->when($type != '', function ($query) use ($type) {
$query->where('user_type', $type);
})->where(function ($query) use ($time) {
if ($time[0] == $time[1]) {
$query->whereDay('add_time', $time[0]);
} else {
$time[1] = date('Y-m-d', strtotime($time[1]) + 86400);
$query->whereTime('add_time', 'between', $time);
}
})->field("FROM_UNIXTIME(add_time,'$timeType') as days,count(uid) as num")->group('days')->select()->toArray();
}
/**
* @param array $where
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getUserInfoList(array $where, $field = "*"): array
{
return $this->search($where)->field($field)->select()->toArray();
}
/**
* 获取用户会员数量
* @param $where (time type)
* @return int
*/
public function getMemberCount($where, int $overdue_time = 0)
{
if (!$overdue_time) $overdue_time = time();
return $this->search($where)->where('is_ever_level', 1)->whereOr(function ($qeury) use ($overdue_time) {
$qeury->where('is_money_level', '>', 0)->where('overdue_time', '>', $overdue_time);
})->count();
}
/**
* 通过UID或手机号获取用户信息
* @param int $uid 用户ID或手机号
* @param string $field 查询字段
* @return array|\think\Model|null
*/
public function getOutOne(int $uid, $field = "*")
{
return $this->getModel()->where('uid|phone', $uid)->field($field)->find();
}
/**
* 带锁的减余额
* @param int $uid
* @param string $incField
* @param string $inc
* @param string|null $keyField
* @param int $acc
* @param bool $dec_return_false
* @return bool
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author 等风来
* @email 136327134@qq.com
* @date 2022/11/22
*/
public function bcDecLook(int $uid, string $incField, string $inc, string $keyField = null, int $acc = 2, bool $dec_return_false = true)
{
$result = $this->getModel()->where('uid', $uid)->lock(true)->find();
if (!$result) return false;
if ($result[$incField] < $inc) {
if ($dec_return_false) return false;
$new = 0;
} else {
$new = bcsub($result[$incField], $inc, $acc);
}
$result->{$incField} = $new;
return false !== $result->save();
}
/**
* 获取指定分组类型和分组ID数组的用户数量
*
* @param int $divisionType 分组类型,1表示部门,其他表示代理商
* @param array $divisionIds 分组ID数组
* @return array 返回一个关联数组,键为分组ID,值为该分组下的用户数量
*/
public function getDivisionCount($divisionType, $divisionIds)
{
// 根据分组类型选择查询字段
$field = $divisionType == 1 ? 'division_id' : 'agent_id';
return $this->getModel()->where('division_type', (int)$divisionType + 1)
->whereIn($field, $divisionIds) // 查询指定分组ID的数据
->group($field)->column('COUNT(uid) as count', $field);
}
}

View File

@@ -0,0 +1,181 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\user;
use app\dao\BaseDao;
use app\model\user\UserExtend;
/**
* 用户扩展数据DAO
* Class UserExtendDao
* @package app\dao\user
*/
class UserExtendDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return UserExtend::class;
}
/**
* 获取用户扩展数据列表
* @param array $where
* @param string $field
* @param int $page
* @param int $limit
* @param string $order
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $where = [], string $field = '*', int $page = 0, int $limit = 0, string $order = 'id desc'): array
{
return $this->search($where)->field($field)
->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order($order)->select()->toArray();
}
/**
* 获取用户某个字段的扩展数据
* @param int $uid
* @param string $fieldName
* @return array|\think\Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getUserFieldData(int $uid, string $fieldName)
{
return $this->search(['uid' => $uid, 'field_name' => $fieldName])->find();
}
/**
* 获取用户所有扩展数据
* @param int $uid
* @param string $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getUserAllExtendData(int $uid, string $field = '*'): array
{
return $this->search(['uid' => $uid])->field($field)->select()->toArray();
}
/**
* 设置用户扩展数据
* @param int $uid
* @param string $fieldName
* @param string $fieldValue
* @param string $remark
* @return bool|\crmeb\basic\BaseModel|int
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function setUserExtendData(int $uid, string $fieldName, $fieldValue, $remark = '')
{
$existData = $this->getUserFieldData($uid, $fieldName);
$data = [
'uid' => $uid,
'field_name' => $fieldName,
'field_value' => $fieldValue,
];
if ($existData) {
// 更新现有数据
return $this->update($existData['id'], $data);
} else {
// 创建新数据
return $this->save($data);
}
}
/**
* 删除用户扩展数据
* @param int $uid
* @param string $fieldName
* @return bool
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function deleteUserExtendData(int $uid, string $fieldName = ''): bool
{
$where = ['uid' => $uid];
if ($fieldName) {
$where['field_name'] = $fieldName;
}
return $this->delete($where) !== false;
}
/**
* 批量设置用户扩展数据
* @param int $uid
* @param array $extendData
* @return bool
*/
public function setBatchUserExtendData(int $uid, array $extendData): bool
{
try {
foreach ($extendData as $item) {
$this->setUserExtendData($uid, $item['field_name'], $item['field_value']);
}
return true;
} catch (\Exception $e) {
return false;
}
}
/**
* 获取用户扩展数据键值对
* @param int $uid
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getUserExtendDataKeyValue(int $uid): array
{
$data = $this->getUserAllExtendData($uid, 'field_name,field_value');
$result = [];
foreach ($data as $item) {
$result[$item['field_name']] = $item['field_value'];
}
return $result;
}
/**
* 验证字段值是否已存在
* @param string $field_name 字段名
* @param mixed $value 字段值
* @param int|null $uid 排除的用户ID
* @return bool
*/
public function isExist(string $field_name, $value, $uid = null)
{
return !!$this->getModel()->where('field_name', $field_name)->where('field_value', $value)
->when($uid, function ($query) use ($uid) {
$query->where('uid', '<>',$uid);
})->find();
}
}

View File

@@ -0,0 +1,149 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\user;
use app\dao\BaseDao;
use app\model\user\UserExtract;
/**
*
* Class UserExtractDao
* @package app\dao\user
*/
class UserExtractDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return UserExtract::class;
}
/**
* 获取列表
* @param array $where
* @param string $field
* @param int $page
* @param int $limit
* @param array $typeWhere
* @return array
*/
public function getList(array $where, string $field = '*', array $with = [], int $page = 0, int $limit = 0)
{
return $this->search($where)->field($field)->when($with, function ($query) use ($with) {
$query->with($with);
})->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order('id desc')->select()->toArray();
}
/**
* 获取某个条件的提现总和
* @param array $where
* @return float
*/
public function getWhereSum(array $where)
{
return $this->search($where)->field('(extract_price + extract_fee) as extract_price')->sum('extract_price');
}
/**
* 获取某些条件总数组合列表
* @param array $where
* @param string $field
* @param string $key
* @return mixed
*/
public function getWhereSumList(array $where, string $field = 'extract_price', string $key = 'uid')
{
return $this->search($where)->group($key)->column('(sum(extract_price) + sum(extract_fee)) as extract_price', $key);
}
/**
* 获取提现列表
* @param array $where
* @param string $field
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getExtractList(array $where, string $field = '*', int $page = 0, int $limit = 0)
{
return $this->search($where)->field($field)->with([
'user' => function ($query) {
$query->field('uid,nickname');
}])->page($page, $limit)->order('id desc')->select()->toArray();
}
/**
* 获取某个字段总和
* @param array $where
* @param string $field
* @return float
*/
public function getWhereSumField(array $where, string $field)
{
return $this->search($where)
->when(isset($where['timeKey']), function ($query) use ($where) {
$query->whereBetweenTime('add_time', $where['timeKey']['start_time'], $where['timeKey']['end_time']);
})
->sum($field);
}
/**
* 根据某字段分组查询
* @param array $where
* @param string $field
* @param string $group
* @return mixed
*/
public function getGroupField(array $where, string $field, string $group)
{
return $this->search($where)
->when(isset($where['timeKey']), function ($query) use ($where, $field, $group) {
$query->whereBetweenTime('add_time', $where['timeKey']['start_time'], $where['timeKey']['end_time']);
if ($where['timeKey']['days'] == 1) {
$timeUinx = "%H";
} elseif ($where['timeKey']['days'] == 30) {
$timeUinx = "%Y-%m-%d";
} elseif ($where['timeKey']['days'] == 365) {
$timeUinx = "%Y-%m";
} elseif ($where['timeKey']['days'] > 1 && $where['timeKey']['days'] < 30) {
$timeUinx = "%Y-%m-%d";
} elseif ($where['timeKey']['days'] > 30 && $where['timeKey']['days'] < 365) {
$timeUinx = "%Y-%m";
} else {
$timeUinx = "%Y-%m";
}
$query->field("sum($field) as number,FROM_UNIXTIME($group, '$timeUinx') as time");
$query->group("FROM_UNIXTIME($group, '$timeUinx')");
})
->order('add_time ASC')->select()->toArray();
}
/**
* @param array $where
* @param string $field
* @return float
*/
public function getExtractMoneyByWhere(array $where, string $field)
{
return $this->search($where)->sum($field);
}
}

View File

@@ -0,0 +1,46 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\user;
use app\dao\BaseDao;
use app\model\user\UserFriends;
class UserFriendsDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return UserFriends::class;
}
/**
* 获取好友关系
* @param array $where
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getFriendList(array $where, int $page, int $limit, array $with = [])
{
return $this->search($where)->when($with, function ($query) use ($with) {
$query->with($with);
})->page($page, $limit)->select()->toArray();
}
}

View File

@@ -0,0 +1,65 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\user;
use app\dao\BaseDao;
use app\model\user\UserInvoice;
use think\exception\ValidateException;
/**
* Class UserInvoiceDao
* @package app\dao\user
*/
class UserInvoiceDao extends BaseDao
{
protected function setModel(): string
{
return UserInvoice::class;
}
/**
* @param array $where
* @param string $field
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $where, string $field = '*', int $page = 0, int $limit = 0)
{
return $this->search($where)->field($field)->page($page, $limit)->order('is_default desc,id desc')->select()->toArray();
}
/**
* 设置默认(个人普通|企业普通|企业专用)
* @param int $uid
* @param int $id
* @param $header_type
* @param $type
* @return bool
*/
public function setDefault(int $uid, int $id, $header_type, $type)
{
if (false === $this->getModel()->where('uid', $uid)->where('header_type', $header_type)->where('type', $type)->update(['is_default' => 0])) {
return false;
}
if (false === $this->getModel()->where('id', $id)->update(['is_default' => 1])) {
return false;
}
return true;
}
}

View File

@@ -0,0 +1,153 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\user;
use app\dao\BaseDao;
use app\model\user\UserMoney;
/**
* 用户余额
* Class UserMoneyDao
* @package app\dao\user
*/
class UserMoneyDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return UserMoney::class;
}
/**
* 获取列表
* @param array $where
* @param string $field
* @param int $page
* @param int $limit
* @param array $with
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $where, string $field = '*', int $page = 0, int $limit = 0, array $with = [])
{
return $this->search($where)->field($field)->when($with, function ($query) use ($with) {
$query->with($with);
})->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order('id desc')->select()->toArray();
}
/**
* 获取某一个月数量
* @param array $where
* @param string $month
* @return int
*/
public function getMonthCount(array $where, string $month)
{
return $this->search($where)->whereMonth('add_time', $month)->count();
}
/**
* 获取余额记录类型
* @param array $where
* @param string $filed
* @return mixed
*/
public function getMoneyType(array $where, string $filed = 'title,type')
{
return $this->search($where)->distinct(true)->field($filed)->group('type')->select();
}
/**
* 余额趋势
* @param $time
* @param $timeType
* @param $field
* @param $str
* @return mixed
*/
public function getBalanceTrend($time, $timeType, $field, $str, $orderStatus = '')
{
return $this->getModel()->where(function ($query) use ($field, $orderStatus) {
if ($orderStatus == 'add') {
$query->where('pm', 1);
} elseif ($orderStatus == 'sub') {
$query->where('pm', 0);
}
})->where(function ($query) use ($time, $field) {
if ($time[0] == $time[1]) {
$query->whereDay($field, $time[0]);
} else {
$query->whereTime($field, 'between', $time);
}
})->field("FROM_UNIXTIME($field,'$timeType') as days,$str as num")->group('days')->select()->toArray();
}
/**
* 获取某个字段总和
* @param array $where
* @param string $field
* @return float
*/
public function getWhereSumField(array $where, string $field)
{
return $this->search($where)
->when(isset($where['timeKey']), function ($query) use ($where) {
$query->whereBetweenTime('add_time', $where['timeKey']['start_time'], $where['timeKey']['end_time']);
})
->sum($field);
}
/**
* 根据某字段分组查询
* @param array $where
* @param string $field
* @param string $group
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getGroupField(array $where, string $field, string $group)
{
return $this->search($where)
->when(isset($where['timeKey']), function ($query) use ($where, $field, $group) {
$query->whereBetweenTime('add_time', $where['timeKey']['start_time'], $where['timeKey']['end_time']);
if ($where['timeKey']['days'] == 1) {
$timeUinx = "%H";
} elseif ($where['timeKey']['days'] == 30) {
$timeUinx = "%Y-%m-%d";
} elseif ($where['timeKey']['days'] == 365) {
$timeUinx = "%Y-%m";
} elseif ($where['timeKey']['days'] > 1 && $where['timeKey']['days'] < 30) {
$timeUinx = "%Y-%m-%d";
} elseif ($where['timeKey']['days'] > 30 && $where['timeKey']['days'] < 365) {
$timeUinx = "%Y-%m";
} else {
$timeUinx = "%Y-%m";
}
$query->field("sum($field) as number,FROM_UNIXTIME($group, '$timeUinx') as time");
$query->group("FROM_UNIXTIME($group, '$timeUinx')");
})
->order('add_time ASC')->select()->toArray();
}
}

View File

@@ -0,0 +1,141 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\user;
use app\dao\BaseDao;
use app\model\user\UserRecharge;
/**
*
* Class UserRechargeDao
* @package app\dao\user
*/
class UserRechargeDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return UserRecharge::class;
}
/**
* 获取充值记录
* @param array $where
* @param string $filed
* @param int $page
* @param int $limit
* @param array $with
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $where, string $filed = "*", int $page = 0, int $limit = 0, array $with = [])
{
return $this->search($where)->field($filed)->with(array_merge([
'user' => function ($query) {
$query->field('uid,phone,nickname,avatar,delete_time');
}], $with))->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order('id desc')->select()->toArray();
}
/**
* 获取某个字段总和
* @param array $where
* @param string $field
* @return float
*/
public function getWhereSumField(array $where, string $field)
{
return $this->search($where)
->when(isset($where['timeKey']), function ($query) use ($where) {
$query->whereBetweenTime('pay_time', $where['timeKey']['start_time'], $where['timeKey']['end_time']);
})
->sum($field);
}
/**
* 根据某字段分组查询
* @param array $where
* @param string $field
* @param string $group
* @return mixed
*/
public function getGroupField(array $where, string $field, string $group)
{
return $this->search($where)
->when(isset($where['timeKey']), function ($query) use ($where, $field, $group) {
$query->whereBetweenTime('pay_time', $where['timeKey']['start_time'], $where['timeKey']['end_time']);
if ($where['timeKey']['days'] == 1) {
$timeUinx = "%H";
} elseif ($where['timeKey']['days'] == 30) {
$timeUinx = "%Y-%m-%d";
} elseif ($where['timeKey']['days'] == 365) {
$timeUinx = "%Y-%m";
} elseif ($where['timeKey']['days'] > 1 && $where['timeKey']['days'] < 30) {
$timeUinx = "%Y-%m-%d";
} elseif ($where['timeKey']['days'] > 30 && $where['timeKey']['days'] < 365) {
$timeUinx = "%Y-%m";
} else {
$timeUinx = "%Y-%m";
}
$query->field("sum($field) as number,FROM_UNIXTIME($group, '$timeUinx') as time");
$query->group("FROM_UNIXTIME($group, '$timeUinx')");
})
->order('add_time ASC')->select()->toArray();
}
/**
* 获取充值统计曲线
* @param $time
* @param $type
* @param $timeType
* @param string $str
* @return mixed
*/
public function getTrendData($time, $type, $timeType, $str = 'count(id)')
{
return $this->getModel()->when($type != '', function ($query) use ($type) {
$query->where('channel_type', $type);
})->where('paid', 1)->where(function ($query) use ($time) {
if ($time[0] == $time[1]) {
$query->whereDay('pay_time', $time[0]);
} else {
$time[1] = date('Y-m-d', strtotime($time[1]) + 86400);
$query->whereTime('pay_time', 'between', $time);
}
})->field("FROM_UNIXTIME(pay_time,'$timeType') as days, " . $str . "as num")
->group('days')->select()->toArray();
}
/**
* 每月统计数据
* @param int $page
* @param int $limit
* @return array
*/
public function getDataPriceCount(array $where, array $field, int $page = 0, int $limit = 0)
{
return $this->search($where)
->field($field)->group("FROM_UNIXTIME(add_time, '%Y-%m-%d')")
->order('add_time DESC')->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->select()->toArray();
}
}

View File

@@ -0,0 +1,51 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\user;
use app\dao\BaseDao;
use app\model\user\UserRelation;
/**
* Class UserRelationDao
* @package app\dao\user
*/
class UserRelationDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return UserRelation::class;
}
/**
* 获取收藏列表
* @param array $where
* @param string $field
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $where, string $field = '*', array $with = [], int $page = 0, int $limit = 0)
{
return $this->search($where)->field($field)->when($with, function($query) use ($with) {
$query->with($with);
})->when($page && $limit, function($query) use ($page, $limit) {
$query->page($page, $limit);
})->order('add_time desc')->select()->toArray();
}
}

View File

@@ -0,0 +1,77 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\user;
use app\dao\BaseDao;
use app\model\user\UserSearch;
/**
* 用户搜索
* Class UserSearchDao
* @package app\dao\user
*/
class UserSearchDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return UserSearch::class;
}
/**
* 获取列表
* @param array $where
* @param string $field
* @param int $page
* @param int $limit
* @param string $order
* @return array
* @throws \ReflectionException
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $where = [], string $field = '*', int $page = 0, int $limit = 0, string $order = 'id desc'): array
{
return $this->search($where)->field($field)
->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order($order)->select()->toArray();
}
/**
* * 获取全局|用户某个关键词搜素结果
* @param int $uid
* @param string $keyword 关键词
* @param int $preTime 多长时间内认为结果集有效
* @return array|\think\Model
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getKeywordResult(int $uid, string $keyword, int $preTime = 7200)
{
if (!$keyword) return [];
$where = ['keyword' => $keyword];
if ($uid) $where['uid'] = $uid;
return $this->search($where)->when($uid && $preTime == 0, function ($query) {
$query->where('is_del', 0);
})->when($preTime > 0, function ($query) use ($preTime) {
$query->where('add_time', '>', time() - $preTime);
})->order('add_time desc,id desc')->find() ?? [];
}
}

View File

@@ -0,0 +1,103 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\user;
use app\dao\BaseDao;
use app\model\user\UserSign;
/**
*
* Class UserSignDao
* @package app\dao\user
*/
class UserSignDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return UserSign::class;
}
/**
* 获取列表
* @param array $where
* @param string $field
* @param int $page
* @param int $limit
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $where, string $field, int $page, int $limit)
{
return $this->search($where)->field($field)->order('id desc')->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->select()->toArray();
}
/**
* 获取列表
* @param array $where
* @param string $field
* @param int $page
* @param int $limit
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getListGroup(array $where, string $field, int $page, int $limit, string $group)
{
return $this->search($where)->field($field)->order('id desc')->group($group)->page($page, $limit)->select()->toArray();
}
/**
* 获取本周、本月、某月的签到列表
* @param $type
* @param $uid
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getUserSignList($type, $uid, $time): array
{
return $this->getModel()->where('uid', $uid)->where(function ($query) use ($type, $time) {
if ($type == 1) {
$query->whereWeek('add_time');
} else {
$query->whereMonth('add_time', $time);
}
})->order('id asc')->select()->toArray();
}
/**
* 获取累积签到次数
* @param $uid
* @return int
* @throws \think\db\exception\DbException
*/
public function getCumulativeDays($uid, $sign_mode)
{
return $this->getModel()->where(function ($query) use ($sign_mode) {
if ($sign_mode == 1) {
$query->whereWeek('add_time');
} elseif ($sign_mode == 0) {
$query->whereMonth('add_time');
}
})->where('uid', $uid)->count();
}
}

View File

@@ -0,0 +1,125 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\user;
use app\dao\BaseDao;
use app\model\user\UserSpread;
/**
* Class UserSpreadDao
* @package app\dao\user
*/
class UserSpreadDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return UserSpread::class;
}
/**
* 获取推广列表
* @param array $where
* @param string $field
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $where, string $field = '*', array $with = [], int $page = 0, int $limit = 0)
{
return $this->search($where)->field($field)
->when($with, function ($query) use ($with) {
$query->with($with);
})->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order('spread_time desc,id desc')->select()->toArray();
}
/**
* 获取推广uids
* @param array $where
* @param string $field
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getSpreadUids(array $where)
{
return $this->search($where)->order('spread_time desc,id desc')->column('uid');
}
/**
* 获取一段时间内推广人数
* @param $datebefor
* @param $dateafter
* @return mixed
*/
public function spreadTimeList(array $where, array $time, string $timeType = "week", string $countField = '*', string $sumField = 'pay_price', string $groupField = 'add_time')
{
return $this->getModel()->where($where)
->where($groupField, 'between time', $time)
->when($timeType, function ($query) use ($timeType, $countField, $sumField, $groupField) {
switch ($timeType) {
case "hour":
$timeUnix = "%H";
break;
case "day" :
$timeUnix = "%m-%d";
break;
case "week" :
$timeUnix = "%w";
break;
case "month" :
$timeUnix = "%d";
break;
case "year" :
$timeUnix = "%m";
break;
default:
$timeUnix = "%m-%d";
break;
}
$query->field("FROM_UNIXTIME(`" . $groupField . "`,'$timeUnix') as day,count(`" . $countField . "`) as count,sum(`" . $sumField . "`) as price");
$query->group("FROM_UNIXTIME($groupField, '$timeUnix')");
})->order('add_time asc')->select()->toArray();
}
/**
* 获取推广人排行
* @param array $time
* @param string $field
* @param int $page
* @param int $limit
*/
public function getAgentRankList(array $time, string $field = '*', int $page = 0, int $limit = 0)
{
return $this->getModel()->with(['spreadUser'])
->field($field)
->order('count desc')
->order('uid desc')
->where('spread_time', 'BETWEEN', $time)
->page($page, $limit)
->group('spread_uid')
->select()->toArray();
}
}

View File

@@ -0,0 +1,87 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\user;
use app\dao\BaseDao;
use app\model\order\StoreOrder;
use app\model\user\User;
/**
*
* Class UserStoreOrderDao
* @package app\dao\user
*/
class UserStoreOrderDao extends BaseDao
{
/**
* @var string
*/
protected string $alias = '';
/**
* @var string
*/
protected string $join_alis = '';
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return User::class;
}
public function joinModel(): string
{
return StoreOrder::class;
}
/**
* 关联模型
* @param string $alias
* @param string $join_alias
* @return \crmeb\basic\BaseModel
*/
public function getModel(string $table = '', string $alias = 'u', string $join_alias = 'p', $join = 'left')
{
$this->alias = $alias;
$this->join_alis = $join_alias;
if (!$table) {
/** @var StoreOrder $storeOrder */
$storeOrder = app()->make($this->joinModel());
$table = $storeOrder->getName();
}
return parent::getModel()->join($table . ' ' . $join_alias, $alias . '.uid = ' . $join_alias . '.uid', $join)->alias($alias);
}
/**
* 推广团队列表
* @param array $where
* @param string $field
* @param string $order_by
* @param $page
* @param $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getUserSpreadCountList(array $where, string $field, string $order_by, int $page, int $limit)
{
$table = app()->make($this->joinModel())->getModel()->where('o.pid', 'IN', [0, -1])->group('o.uid')->field(['SUM(o.pay_price) as numberCount', 'count(o.id) as orderCount', 'o.uid', 'o.order_id'])
->where('o.is_del', 0)->where('o.is_system_del', 0)->where('o.paid', 1)->where('o.refund_status', 'IN', [0, 3])->alias('o')->fetchSql(true)->select();
return $this->getModel('(' . $table . ')')->where($where)->field($field)->order($order_by)->page($page, $limit)->select()->toArray();
}
}

View File

@@ -0,0 +1,35 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types = 1);
namespace app\dao\user;
use app\dao\BaseDao;
use app\model\user\UserTaskFinish;
/**
*
* Class UserTaskFinishDao
* @package app\dao\user
*/
class UserTaskFinishDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return UserTaskFinish::class;
}
}

View File

@@ -0,0 +1,187 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\user;
use app\dao\BaseDao;
use app\model\user\User;
use app\model\user\UserBrokerage;
/**
* 用户关联佣金
* Class UserUserBrokerageDao
* @package app\dao\user
*/
class UserUserBrokerageDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return User::class;
}
/**
* 设置关联模型
* @return string
*/
public function joinModel(): string
{
return UserBrokerage::class;
}
/**
* 关联模型
* @param string $alias
* @param string $join_alias
* @return \crmeb\basic\BaseModel
*/
public function getModel(string $alias = 'u', string $join_alias = 'b', $join = 'left')
{
$this->alias = $alias;
$this->join_alis = $join_alias;
/** @var UserBrokerage $userBrokerage */
$userBrokerage = app()->make($this->joinModel());
$table = $userBrokerage->getName();
return parent::getModel()->withTrashed()
->join($table . ' ' . $join_alias, $alias . '.uid = ' . $join_alias . '.uid', $join)
->alias($alias);
}
/**
* 组合条件模型查询列表
* @param array $where
* @param string $field
* @param string $order
* @param int $page
* @param int $limit
* @return array
*/
public function getList(array $where, string $field = '', string $order = '', int $page = 0, int $limit = 0)
{
$time = $where['time'];
unset($where['time']);
return $this->getModel()->when($time != '', function ($query) use ($time) {
$timeKey = $this->join_alis . '.add_time';
switch ($time) {
case 'today':
case 'week':
case 'month':
case 'year':
case 'yesterday':
case 'last year':
case 'last week':
case 'last month':
$query->whereTime($timeKey, $time);
break;
case 'quarter':
[$startTime, $endTime] = $this->getMonth();
$query->whereBetween($timeKey, [$startTime, $endTime]);
break;
case 'lately7':
$query->whereBetween($timeKey, [strtotime("-7 day"), time()]);
break;
case 'lately30':
$query->whereBetween($timeKey, [strtotime("-30 day"), time()]);
break;
default:
if (strstr($time, '-') !== false) {
[$startTime, $endTime] = explode('-', $time);
$startTime = trim($startTime);
$endTime = trim($endTime);
if ($startTime && $endTime) {
$query->whereBetween($timeKey, [strtotime($startTime), $startTime == $endTime ? strtotime($endTime) + 86400 : strtotime($endTime)]);
} else if (!$startTime && $endTime) {
$query->whereTime($timeKey, '<', strtotime($endTime) + 86400);
} else if ($startTime && !$endTime) {
$query->whereTime($timeKey, '>=', strtotime($startTime));
}
}
break;
}
})->where($where)->field($field)->group('u.uid')->order($order)->order('id desc')
->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->select()->toArray();
}
/**
* 获取条数
* @param array $where
* @return mixed
*/
public function getCount(array $where):int
{
$time = $where['time'];
unset($where['time']);
return $this->getModel()->when($time != '', function ($query) use ($time) {
$timeKey = $this->join_alis . '.add_time';
switch ($time) {
case 'today':
case 'week':
case 'month':
case 'year':
case 'yesterday':
case 'last year':
case 'last week':
case 'last month':
$query->whereTime($timeKey, $time);
break;
case 'quarter':
[$startTime, $endTime] = $this->getMonth();
$query->whereBetween($timeKey, [$startTime, $endTime]);
break;
case 'lately7':
$query->whereBetween($timeKey, [strtotime("-7 day"), time()]);
break;
case 'lately30':
$query->whereBetween($timeKey, [strtotime("-30 day"), time()]);
break;
default:
if (strstr($time, '-') !== false) {
[$startTime, $endTime] = explode('-', $time);
$startTime = trim($startTime);
$endTime = trim($endTime);
if ($startTime && $endTime) {
$query->whereBetween($timeKey, [strtotime($startTime), $startTime == $endTime ? strtotime($endTime) + 86400 : strtotime($endTime)]);
} else if (!$startTime && $endTime) {
$query->whereTime($timeKey, '<', strtotime($endTime) + 86400);
} else if ($startTime && !$endTime) {
$query->whereTime($timeKey, '>=', strtotime($startTime));
}
}
break;
}
})->where($where)->group('u.uid')->count();
}
/**
* 获取本季度 time
* @param int $ceil
* @return array
*/
public function getMonth(int $ceil = 0)
{
if ($ceil != 0) {
$season = ceil(date('n') / 3) - $ceil;
} else {
$season = ceil(date('n') / 3);
}
$firstday = date('Y-m-01', mktime(0, 0, 0, ($season - 1) * 3 + 1, 1, date('Y')));
$lastday = date('Y-m-t', mktime(0, 0, 0, $season * 3, 1, date('Y')));
return [$firstday, $lastday];
}
}

View File

@@ -0,0 +1,88 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\user;
use app\dao\BaseDao;
use app\model\user\UserVisit;
/**
*
* Class UserVisitDao
* @package app\dao\user
*/
class UserVisitDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return UserVisit::class;
}
/**
* 用户趋势数据
* @param $time
* @param $type
* @param $timeType
* @param $str
* @return mixed
*/
public function getTrendData($time, $type, $timeType, $str)
{
return $this->getModel()->when($type != '', function ($query) use ($type) {
$query->where('channel_type', $type);
})->where(function ($query) use ($time) {
if ($time[0] == $time[1]) {
$query->whereDay('add_time', $time[0]);
} else {
$time[1] = date('Y-m-d', strtotime($time[1]) + 86400);
$query->whereTime('add_time', 'between', $time);
}
})->field("FROM_UNIXTIME(add_time,'$timeType') as days,$str as num")->group('days')->select()->toArray();
}
/**
* 用户地域数据
* @param $time
* @param $userType
* @return mixed
*/
public function getRegion($time, $userType)
{
return $this->getModel()->when($userType != '', function ($query) use ($userType) {
$query->where('channel_type', $userType);
})->where(function ($query) use ($time) {
if ($time[0] == $time[1]) {
$query->whereDay('add_time', $time[0]);
} else {
$time[1] = date('Y-m-d', strtotime($time[1]) + 86400);
$query->whereTime('add_time', 'between', $time);
}
})->field('COUNT(distinct(uid)) as visitNum,province')
->group('province')->select()->toArray();
}
/**
* 根据分组获取记录条数
* @param array $where
* @param string $group
* @return mixed
*/
public function groupCount(array $where, string $group = 'uid')
{
return $this->search($where)->group($group)->count();
}
}

View File

@@ -0,0 +1,342 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\user;
use think\model;
use app\dao\BaseDao;
use app\model\user\User;
use app\model\wechat\WechatUser;
/**
*
* Class UserWechatUserDao
* @package app\dao\user
*/
class UserWechatUserDao extends BaseDao
{
/**
* @var string
*/
protected string $alias = '';
/**
* @var string
*/
protected string $join_alis = '';
/**
* 精确搜索白名单
* @var string[]
*/
protected array $withField = ['uid', 'nickname', 'user_type', 'phone'];
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return User::class;
}
/**
* 设置关联模型
* @return string
*/
public function joinModel(): string
{
return WechatUser::class;
}
/**
* 关联模型
* @param string $alias
* @param string $join_alias
* @return \crmeb\basic\BaseModel
*/
public function getModel(string $alias = 'u', string $join_alias = 'w', $join = 'left')
{
$this->alias = $alias;
$this->join_alis = $join_alias;
/** @var WechatUser $wechcatUser */
$wechcatUser = app()->make($this->joinModel());
$table = $wechcatUser->getName();
return parent::getModel()->withTrashed()->alias($alias)->join($table . ' ' . $join_alias, $alias . '.uid = ' . $join_alias . '.uid', $join);
}
/**
* 获取列表
* @param array $where
* @param string $field
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $where, $field = '*', int $page = 0, int $limit = 0)
{
return $this->getModel()->where($where)->field($field)->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->select()->toArray();
}
/**
* 获取总数
* @param array $where
* @return int
*/
public function getCount(array $where): int
{
return $this->getModel()->where($where)->count();
}
/**
* 组合条件模型条数
* @param Model $model
* @return int
*/
public function getCountByWhere(array $where): int
{
return $this->searchWhere($where)->group($this->alias . '.uid')->count();
}
/**
* 组合条件模型查询列表
* @param array $where
* @param string $field
* @param string $order
* @param int $page
* @param int $limit
* @return array
*/
public function getListByModel(array $where, string $field = '', string $order = '', int $page = 0, int $limit = 0): array
{
return $this->searchWhere($where)->field($field)->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->group($this->alias . '.uid')->order(($order ? $order . ' ,' : '') . $this->alias . '.uid desc')->select()->toArray();
}
/**
* @param $where
* @param array|null $field
* @param int $page
* @param int $limit
* @return \crmeb\basic\BaseModel
*/
public function searchWhere($where, ?array $field = [])
{
$model = $this->getModel();
$userAlias = $this->alias . '.';
$wechatUserAlias = $this->join_alis . '.';
if (isset($where['is_filter_del']) && $where['is_filter_del'] == 1) {
$model = $model->where($userAlias . 'delete_time', null);
}
//购买次数
if (isset($where['uid']) && $where['uid'] !== '') {
if (is_array($where['uid'])) {
$model = $model->whereIn($userAlias . 'uid', $where['uid']);
} else {
$model = $model->where($userAlias . 'uid', $where['uid']);
}
}
// 用户访问时间
if (isset($where['user_time_type']) && isset($where['user_time'])) {
//最后一次访问时间
if ($where['user_time_type'] == 'visitno' && $where['user_time'] != '') {
[$startTime, $endTime] = explode('-', $where['user_time']);
if ($startTime && $endTime) {
$endTime = strtotime($endTime) + 24 * 3600;
$model = $model->where($userAlias . "last_time < " . strtotime($startTime) . " OR " . $userAlias . "last_time > " . $endTime);
}
}
//访问时间
if ($where['user_time_type'] == 'visit' && $where['user_time'] != '') {
[$startTime, $endTime] = explode('-', $where['user_time']);
if ($startTime && $endTime) {
$model = $model->where($userAlias . 'last_time', '>', strtotime($startTime));
$model = $model->where($userAlias . 'last_time', '<', strtotime($endTime) + 24 * 3600);
}
}
//添加时间
if ($where['user_time_type'] == 'add_time' && $where['user_time'] != '') {
[$startTime, $endTime] = explode('-', $where['user_time']);
if ($startTime && $endTime) {
$model = $model->where($userAlias . 'add_time', '>', strtotime($startTime));
$model = $model->where($userAlias . 'add_time', '<', strtotime($endTime) + 24 * 3600);
}
}
}
//购买次数
if (isset($where['pay_count']) && $where['pay_count'] != '') {
if ($where['pay_count'] == '-1') {
$model = $model->where($userAlias . 'pay_count', 0);
} else {
$model = $model->where($userAlias . 'pay_count', '>', $where['pay_count']);
}
}
//用户等级
if (isset($where['level']) && $where['level']) {
$model = $model->where($userAlias . 'level', $where['level']);
}
//用户分组
if (isset($where['group_id']) && $where['group_id']) {
$model = $model->where($userAlias . 'group_id', $where['group_id']);
}
//是否采购商
if (isset($where['is_channel']) && $where['is_channel'] !== '') {
$model = $model->where($userAlias . 'is_channel', $where['is_channel']);
}
//用户状态
if (isset($where['status']) && $where['status'] != '') {
$model = $model->where($userAlias . 'status', $where['status']);
}
//用户是否为推广员
if (isset($where['is_promoter']) && $where['is_promoter'] != '') {
$model = $model->where($userAlias . 'is_promoter', $where['is_promoter']);
}
//用户标签
if (isset($where['label_id']) && $where['label_id']) {
$model = $model->whereIn($userAlias . 'uid', function ($query) use ($where) {
if (is_array($where['label_id'])) {
$query->name('user_label_relation')->whereIn('label_id', $where['label_id'])->field('uid')->select();
} else {
if (strpos(strval($where['label_id']), ',') !== false) {
$query->name('user_label_relation')->whereIn('label_id', explode(',', $where['label_id']))->field('uid')->select();
} else {
$query->name('user_label_relation')->where('label_id', $where['label_id'])->field('uid')->select();
}
}
});
}
//是否付费会员
if (isset($where['isMember']) && $where['isMember'] != '') {
if ($where['isMember'] == 0) {
$model = $model->where($userAlias . 'is_money_level', 0);
} else {
$model = $model->where($userAlias . 'is_money_level', '>', 0);
}
}
//用户昵称,uid,手机号搜索
$fieldKey = $where['field_key'] ?? '';
$nickname = $where['nickname'] ?? '';
if ($fieldKey && $nickname && in_array($fieldKey, $this->withField)) {
switch ($fieldKey) {
case "nickname":
case "phone":
$model = $model->where($userAlias . trim($fieldKey), 'like', "%" . trim($nickname) . "%");
break;
case "uid":
$model = $model->where($userAlias . trim($fieldKey), trim($nickname));
break;
}
} else if ((!$fieldKey || $fieldKey == 'all') && $nickname) {
$model = $model->where($userAlias . 'nickname|' . $userAlias . 'uid|' . $userAlias . 'phone', 'LIKE', "%$where[nickname]%");
}
//用户类型
if (isset($where['user_type']) && $where['user_type']) {
$model = $model->where($userAlias . 'user_type', $where['user_type']);
}
//用户性别
if (isset($where['sex']) && $where['sex'] !== '' && in_array($where['sex'], [0, 1, 2])) {
$model = $model->where(function ($query) use ($wechatUserAlias, $userAlias, $where) {
$query->where($userAlias . 'sex', $where['sex']);
});
}
//所在国家 所在省份 所在城市
if ((isset($where['country']) && $where['country']) || (isset($where['province']) && $where['province']) || (isset($where['city']) && $where['city'])) {
$model = $model->where(function ($query) use ($wechatUserAlias, $userAlias, $where) {
$query->when(isset($where['country']) && $where['country'], function ($g) use ($wechatUserAlias, $userAlias, $where) {
if ($where['country'] == 'domestic') {
$g->where($wechatUserAlias . 'country', 'in', ['中国', 'China']);
} else if ($where['country'] == 'abroad') {
$g->whereOr($userAlias . 'addres', '');
}
})->when(isset($where['province']) && $where['province'], function ($q) use ($wechatUserAlias, $userAlias, $where) {
$q->whereOr($wechatUserAlias . 'province', $where['province'])->whereOr($userAlias . 'provincials', 'Like', '%' . $where['province'] . '%')->whereOr($userAlias . 'addres', 'Like', '%' . $where['province'] . '%');
})->when(isset($where['city']) && $where['city'], function ($c) use ($wechatUserAlias, $userAlias, $where) {
$c->whereOr($wechatUserAlias . 'city', $where['city'])->whereOr($userAlias . 'provincials', 'Like', '%' . $where['city'] . '%')->whereOr($userAlias . 'addres', 'Like', '%' . $where['city'] . '%');
});
});
}
if (isset($where['time'])) {
$model->withSearch(['time'], ['time' => $where['time'], 'timeKey' => 'u.add_time']);
}
return $field ? $model->field($field) : $model;
}
/**
* 地域全部用户
* @param $time
* @param $userType
* @return mixed
*/
public function getRegionAll($time, $userType)
{
return $this->getModel()->when($userType != '', function ($query) use ($userType) {
$query->where($this->alias . '.user_type', $userType);
})->where(function ($query) use ($time) {
$query->whereTime($this->alias . '.add_time', '<', strtotime($time[1]) + 86400)->whereOr($this->alias . '.add_time', NULL);
})->field('count(' . $this->alias . '.uid) as allNum,' . $this->join_alis . '.province')
->group($this->join_alis . '.province')->select()->toArray();
}
/**
* 地域新增用户
* @param $time
* @param $userType
* @return mixed
*/
public function getRegionNew($time, $userType)
{
return $this->getModel()->when($userType != '', function ($query) use ($userType) {
$query->where($this->alias . '.user_type', $userType);
})->where(function ($query) use ($time) {
if ($time[0] == $time[1]) {
$query->whereDay($this->alias . '.add_time', $time[0]);
} else {
$time[1] = date('Y-m-d', strtotime($time[1]) + 86400);
$query->whereTime($this->alias . '.add_time', 'between', $time);
}
})->field('count(' . $this->alias . '.uid) as newNum,' . $this->join_alis . '.province')
->group($this->join_alis . '.province')->select()->toArray();
}
/**
* 统计获取用户性别
* @param $time
* @param $userType
* @return mixed
* @author 等风来
* @email 136327134@qq.com
* @date 2023/10/13
*/
public function getSex($time, $userType)
{
return app()->make($this->setModel())->when($userType != '', function ($query) use ($userType) {
$query->where('user_type', $userType);
})->where(function ($query) use ($time) {
if ($time[0] == $time[1]) {
$query->whereDay('add_time', $time[0]);
} else {
$time[1] = date('Y-m-d', strtotime($time[1]) + 86400);
$query->whereTime('add_time', 'between', $time);
}
})->field('sex,count(sex) as number')->group('sex')->select()->toArray();
}
}

View File

@@ -0,0 +1,193 @@
<?php
declare (strict_types=1);
namespace app\dao\user\channel;
use app\dao\BaseDao;
use app\model\user\channel\ChannelMerchant;
/**
* 采购商DAO
* Class ChannelMerchantDao
* @package app\dao\user\channel
*/
class ChannelMerchantDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return ChannelMerchant::class;
}
/**
* 获取采购商列表
* @param array $where
* @param int $page
* @param int $limit
* @return array
*/
public function getChannelList(array $where, int $page, int $limit)
{
$where['is_del'] = 0;
return $this->search($where)
->when(isset($where['keyword']) && $where['keyword'] !== '', function ($query) use ($where) {
if (isset($where['field_key']) && $where['keyword'] !== '') {
$query->where($where['field_key'], 'like', '%' . $where['keyword'] . '%');
} else {
$query->where('channel_name|real_name|phone|uid', 'like', '%' . $where['keyword'] . '%');
}
})->when(isset($where['verify_status']) && $where['verify_status'] !== '', function ($query) use ($where) {
$query->where('verify_status', $where['verify_status']);
})->when(isset($where['date']) && $where['date'] !== '', function ($query) use ($where) {
getModelTime($query, $where['date'], 'add_time');
})->when(isset($where['count']) && $where['count'] !== '', function ($query) use ($where) {
$counts = explode('-', $where['count']);
if(count($counts) == 1){
$query->where('order_count', '>=', $counts[0]);
}
if (count($counts) == 2 && ($counts[0] !== '' || $counts[1] !== '')) {
if ($counts[0] === '') {
$query->where('order_count', '<=', $counts[1]);
} elseif ($counts[1] === '') {
$query->where('order_count', '>=', $counts[0]);
} else {
$query->whereBetween('order_count', $counts);
}
}
})->when(isset($where['money']) && $where['money'] !== '', function ($query) use ($where) {
$moneys = explode('-', $where['money']);
if(count($moneys) == 1){
$query->where('order_price', '>=', $moneys[0]);
}
if (count($moneys) == 2 && ($moneys[0] !== '' || $moneys[1] !== '')) {
if ($moneys[0] === '') {
$query->where('order_price', '<=', $moneys[1]);
} elseif ($moneys[1] === '') {
$query->where('order_price', '>=', $moneys[0]);
} else {
$query->whereBetween('order_price', $moneys);
}
}
})->page($page, $limit)->order('id DESC')->select()->toArray();
}
/**
* 获取采购商数量
* @param array $where
* @return int
*/
public function count(array $where = []): int
{
$where['is_del'] = 0;
return $this->search($where)->when(isset($where['keyword']) && $where['keyword'] !== '', function ($query) use ($where) {
$query->where('channel_name|real_name|phone|uid', 'like', '%' . $where['keyword'] . '%');
})->when(isset($where['verify_status']) && $where['verify_status'] !== '', function ($query) use ($where) {
$query->where('verify_status', $where['verify_status']);
})->when(isset($where['date']) && $where['date'] !== '', function ($query) use ($where) {
getModelTime($query, $where['date'], 'add_time');
})->count();
}
/**
* 获取单个采购商信息
* @param int $id
* @param string $field
* @return array|\think\Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getInfo(int $id, string $field = '*')
{
return $this->getModel()->where('id', $id)->where('is_del', 0)->field($field)->find($id);
}
/**
* 根据条件获取采购商信息
* @param array $where
* @param string $field
* @param array $with
* @return array|\think\Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getChannelInfo(array $where, string $field = '*', array $with = [])
{
return $this->search($where, false)->field($field)->when(!empty($with), function ($query) use ($with) {
$query->with($with);
})->find();
}
/**
* 根据用户ID获取采购商信息
* @param int $uid
* @param string $field
* @return array|\think\Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getChannelByUid(int $uid, string $field = '*')
{
return $this->getModel()->field($field)->where('uid', $uid)->find();
}
/**
* 获取所有采购商
* @param array $where
* @param string $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getAllChannel(array $where, string $field = '*')
{
return $this->getModel()->field($field)->where($where)->where('verify_status', 1)->select()->toArray();
}
/**
* 检查采购商是否存在
* @param int $uid
* @param int $id
* @return bool
*/
public function isChannelExist(int $uid, int $id = 0)
{
return $this->getModel()->where('uid', $uid)->when($id > 0, function ($query) use ($id) {
$query->where('id', '<>', $id);
})->count() > 0;
}
/**
* 检查手机号是否已被使用
* @param string $phone
* @param int $id
* @return bool
*/
public function isPhoneExist(string $phone, int $id = 0)
{
return $this->getModel()->where('phone', $phone)->when($id > 0, function ($query) use ($id) {
$query->where('id', '<>', $id);
})->count() > 0;
}
/**
* 获取指定地区的采购商
* @param string $province
* @param string $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getChannelByProvince(string $province, string $field = '*')
{
return $this->getModel()->field($field)->whereFindInSet('province', $province)->where('verify_status', 1)->select()->toArray();
}
}

View File

@@ -0,0 +1,98 @@
<?php
declare (strict_types=1);
namespace app\dao\user\channel;
use app\dao\BaseDao;
use app\model\user\channel\ChannelMerchantIdentity;
/**
* 采购商身份DAO
* Class ChannelMerchantIdentityDao
* @package app\dao\user\channel
*/
class ChannelMerchantIdentityDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return ChannelMerchantIdentity::class;
}
/**
* 获取采购商身份列表
* @param array $where
* @param int $page
* @param int $limit
* @return array
*/
public function getList(array $where, int $page, int $limit)
{
return $this->search($where,false)
->page($page, $limit)
->order('id DESC')
->select()
->toArray();
}
/**
* 获取单个采购商身份信息
* @param int $id
* @param string $field
* @return array|\think\Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getInfo(int $id, string $field = '*')
{
return $this->getModel()->field($field)->find($id);
}
/**
* 根据等级获取采购商身份
* @param int $level
* @param string $field
* @return array|\think\Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getIdentityByLevel(int $level, string $field = '*')
{
return $this->getModel()->field($field)->where('level', $level)->where('is_show', 1)->find();
}
/**
* 检查等级是否已存在
* @param int $level
* @param int $id
* @return bool
*/
public function isLevelExist(int $level, int $id = 0)
{
return $this->getModel()->where('level', $level)
->when($id > 0, function ($query) use ($id) {
$query->where('id', '<>', $id);
})
->count() > 0;
}
/**
* 检查名称是否已存在
* @param string $name
* @param int $id
* @return bool
*/
public function isNameExist(string $name, int $id = 0)
{
return $this->getModel()->where('name', $name)
->when($id > 0, function ($query) use ($id) {
$query->where('id', '<>', $id);
})
->count() > 0;
}
}

View File

@@ -0,0 +1,50 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\user\group;
use app\dao\BaseDao;
use app\model\user\group\UserGroup;
/**
* 用户分组
* Class UserGroupDao
* @package app\dao\user\group
*/
class UserGroupDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return UserGroup::class;
}
/**
* 获取列表
* @param array $where
* @param string $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $where = [], string $field = '*', int $page = 0, int $limit = 0)
{
return $this->search($where)->field($field)->when($page, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order('id desc')->select()->toArray();
}
}

View File

@@ -0,0 +1,65 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\user\label;
use app\dao\BaseDao;
use app\model\user\label\UserLabelCate;
/**
* 标签分类
* Class UserLabelCateDao
* @package app\dao\user\level
*/
class UserLabelCateDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return UserLabelCate::class;
}
/**
* 获取标签分类列表
* @param array $where
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getLabelList(array $where, int $page, int $limit)
{
return $this->search($where)->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order('sort DESC')->select()->toArray();
}
/**
* 获取全部标签分类
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getAll(array $with = [])
{
return $this->getModel()->when(count($with), function ($query) use ($with) {
$query->with($with);
})->order('sort DESC')->select()->toArray();
}
}

View File

@@ -0,0 +1,56 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\user\label;
use app\dao\BaseDao;
use app\model\user\label\UserLabel;
/**
* 用户标签
* Class UserLabelDao
* @package app\dao\user\label
*/
class UserLabelDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return UserLabel::class;
}
/**
* 获取列表
* @param int $page
* @param int $limit
* @param array $where
* @param array|string[] $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(int $page = 0, int $limit = 0, array $where = [], array $field = ['*'],array $with = []): array
{
return $this->search($where)
->when($with, function ($query) use ($with) {
$query->with($with);
})
->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->field($field)->order('id desc')->select()->toArray();
}
}

View File

@@ -0,0 +1,90 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\user\label;
use app\dao\BaseDao;
use app\model\user\label\UserLabelExtend;
/**
* 标签规则关联表
* Class UserLabelExtendDao
* @package app\dao\user\label
*/
class UserLabelExtendDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return UserLabelExtend::class;
}
/**
* 获取列表
* @param int $page
* @param int $limit
* @param array $where
* @param array|string[] $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(int $page = 0, int $limit = 0, array $where = [], array $field = ['*']): array
{
return $this->search($where)->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->field($field)->order('id desc')->select()->toArray();
}
/**
* 根据标签ID获取扩展规则
* @param int $labelId
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getByLabelId(int $labelId): array
{
return $this->search(['label_id' => $labelId])->select()->toArray();
}
/**
* 根据规则类型获取扩展规则
* @param int $ruleType
* @param array $where
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getByRuleType(int $ruleType, array $where = []): array
{
$where['rule_type'] = $ruleType;
return $this->search($where)->select()->toArray();
}
/**
* 根据条件批量删除
* @param array $where 删除条件
* @return int
*/
public function searchDel(array $where)
{
return $this->search($where)->delete();
}
}

View File

@@ -0,0 +1,119 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\user\label;
use app\dao\BaseDao;
use app\model\user\label\UserLabelExtendRelation;
/**
* 标签规则扩展表
* Class UserLabelExtendRelationDao
* @package app\dao\user\label
*/
class UserLabelExtendRelationDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return UserLabelExtendRelation::class;
}
/**
* 获取列表
* @param int $page
* @param int $limit
* @param array $where
* @param array|string[] $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(int $page = 0, int $limit = 0, array $where = [], array $field = ['*']): array
{
return $this->search($where)->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->field($field)->order('id desc')->select()->toArray();
}
/**
* 根据左侧ID获取关联关系
* @param int $leftId
* @param int $type
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getByLeftId(int $leftId, int $type = 0): array
{
$where = ['left_id' => $leftId];
if ($type) {
$where['type'] = $type;
}
return $this->search($where)->select()->toArray();
}
/**
* 根据右侧ID获取关联关系
* @param int $rightId
* @param int $type
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getByRightId(int $rightId, int $type = 0): array
{
$where = ['right_id' => $rightId];
if ($type) {
$where['type'] = $type;
}
return $this->search($where)->select()->toArray();
}
/**
* 根据类型获取关联关系
* @param int $type
* @param array $where
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getByType(int $type, array $where = []): array
{
$where['type'] = $type;
return $this->search($where)->select()->toArray();
}
/**
* 批量删除关联关系
* @param int $leftId
* @param int $type
* @return bool
*/
public function deleteByLeftId(int $leftId, int $type = 0): bool
{
$where = ['left_id' => $leftId];
if ($type) {
$where['type'] = $type;
}
return $this->getModel()->where($where)->delete();
}
}

View File

@@ -0,0 +1,61 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\user\label;
use app\dao\BaseDao;
use app\model\user\label\UserLabelRelation;
/**
* 用户关联标签
* Class UserLabelRelationDao
* @package app\dao\user\label
*/
class UserLabelRelationDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return UserLabelRelation::class;
}
/**
* 获取用户个标签列表按照用户id进行分组
* @param array $uids
* @param int $type
* @param int $relation_id
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getLabelList(array $uids, int $type = 0, int $relation_id = 0)
{
return $this->search(['uid' => $uids])->where('type', $type)->where('relation_id', $relation_id)->with('label')->select()->toArray();
}
/**
* 根据标签查询标签用户数
* @param array $label_ids 标签ID数组
* @return array
*/
public function getLabelUserCount(array $label_ids)
{
$list = $this->search([])->whereIn('label_id', $label_ids)->group('label_id')->field('label_id,count(label_id) as count')->select()->toArray();
return array_column($list, 'count', 'label_id');
}
}

View File

@@ -0,0 +1,95 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\user\level;
use think\Model;
use app\dao\BaseDao;
use think\db\exception\DbException;
use app\model\user\level\SystemUserLevel;
use think\db\exception\DataNotFoundException;
use think\db\exception\ModelNotFoundException;
/**
* 系统设置用户等级
* Class SystemUserLevelDao
* @package app\dao\user\level
*/
class SystemUserLevelDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return SystemUserLevel::class;
}
/**
* 获取列表
* @param array $where
* @param string $field
* @param int $page
* @param int $limit
* @return array
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function getList(array $where, string $field = '*', int $page = 0, $limit = 0)
{
return $this->getModel()->where($where)->field($field)->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order('grade asc')->select()->toArray();
}
/**
* 复杂条件获取总数
* @param array $where
* @return int
* @throws DbException
*/
public function getCount(array $where): int
{
return $this->getModel()->where($where)->count();
}
/**
* 获取上一个用户等级
* @param $grade
* @param string $field
* @return array|Model|null
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function getPreLevel($grade, string $field = '*')
{
return $this->getModel()->where('grade', '<', $grade)->where('is_del', 0)->field($field)->order('grade desc')->find();
}
/**
* 获取下一个用户等级
* @param $grade
* @param string $field
* @return array|Model|null
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function getNextLevel($grade, string $field = '*')
{
return $this->getModel()->where('grade', '>', $grade)->where('is_del', 0)->field($field)->order('grade asc')->find();
}
}

View File

@@ -0,0 +1,59 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\user\level;
use app\dao\BaseDao;
use app\model\user\level\UserLevel;
/**
* 用户等技
* Class UserLevelDao
* @package app\dao\user\level
*/
class UserLevelDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return UserLevel::class;
}
/**
* 根据uid 获取用户会员等级详细信息
* @param int $uid
* @param string $field
* @return array|\think\Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getUserLevel(int $uid, string $field = '*')
{
return $this->getModel()->where('uid', $uid)->where('is_del', 0)->where('status', 1)->field($field)->with(['levelInfo'])->order('grade desc,add_time desc')->find();
}
/**
* 获取用户等级折扣
* @param int $uid
* @return mixed
*/
public function getDiscount(int $uid)
{
$level = $this->getModel()->where(['uid' => $uid, 'is_del' => 0, 'status' => 1])->with(['levelDiscount'])->order('id desc')->find();
return $level ? $level->toArray()['discount_num'] : NULL;
}
}

View File

@@ -0,0 +1,52 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\user\member;
use app\dao\BaseDao;
use app\model\user\member\MemberCardBatch;
/**
* Class MemberCardBatchDao
* @package app\dao\user\member
*/
class MemberCardBatchDao extends BaseDao
{
/** 设置模型
* @return string
*/
protected function setModel(): string
{
return MemberCardBatch::class;
}
/**
* 获取会员卡批次列表
* @param array $where
* @param int $page
* @param int $limit
* @param string $order
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $where, int $page = 0, int $limit = 0, string $order = '')
{
return $this->search($where)
->order(($order ? $order . ' ,' : '') . 'sort desc,id desc')
->page($page, $limit)->select()->toArray();
}
}

View File

@@ -0,0 +1,67 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\user\member;
use app\dao\BaseDao;
use app\model\user\member\MemberCard;
/**
* Class MemberCardDao
* @package app\dao\user\member
*/
class MemberCardDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return MemberCard::class;
}
/**
* 获取列表
* @param array $where
* @param int $page
* @param int $limit
* @param array|string[] $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getSearchList(array $where, int $page = 0, int $limit = 0, array $field = ['*'])
{
return $this->search($where)->order('use_time desc,id desc')
->field($field)
->when($page > 0 || $limit > 0, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->select()->toArray();
}
/**
* 获取当条会员卡信息
* @param array $where
* @return array|\think\Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getOneByWhere(array $where)
{
return $this->getModel()->where($where)->find();
}
}

View File

@@ -0,0 +1,54 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\user\member;
use app\dao\BaseDao;
use app\model\user\member\MemberRight;
/**
* Class MemberRightDao
* @package app\dao\user\member
*/
class MemberRightDao extends BaseDao
{
/** 设置模型
* @return string
*/
protected function setModel(): string
{
return MemberRight::class;
}
/**获取会员权益接口
* @param array $where
* @param int $page
* @param int $limit
* @param array $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getSearchList(array $where, int $page = 0, int $limit = 0, array $field = ['*'])
{
return $this->search($where)->order('sort desc,id desc')
->field($field)
->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})
->select()->toArray();
}
}

View File

@@ -0,0 +1,67 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\user\member;
use app\dao\BaseDao;
use app\model\user\member\MemberShip;
/**
* Class MemberShipDao
* @package app\dao\user\member
*/
class MemberShipDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return MemberShip::class;
}
/**
* 后台获取会员卡类型接口
* @param array $where
* @param int $page
* @param int $limit
* @param array $field
* @return \think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getSearchList(array $where, int $page = 0, int $limit = 0, array $field = ['*'])
{
return $this->search($where)->order('sort desc,id desc')
->field($field)
->page($page, $limit)
->select();
}
/**
* 获取会员类型api接口
* @param array $where
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getApiList(array $where)
{
return $this->search()->where($where)->order('sort desc')->select()->toArray();
}
}