功能合并:基本依赖文件校验完成(所有关联文件已闭环)

This commit is contained in:
wuhui_zzw 2023-12-14 09:58:40 +08:00
parent 406c03a8a1
commit c661e5bc19
800 changed files with 147125 additions and 1705 deletions

View File

@ -0,0 +1,52 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\common\middleware;
use app\Request;
use app\services\supplier\LoginServices;
use crmeb\interfaces\MiddlewareInterface;
use think\facade\Config;
/**
* Class AuthTokenMiddleware
* @package app\http\middleware\supplier
*/
class AuthTokenMiddleware implements MiddlewareInterface
{
/**
* @param Request $request
* @param \Closure $next
* @throws \Psr\SimpleCache\InvalidArgumentException
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function handle(Request $request, \Closure $next)
{
$token = trim(ltrim($request->header(Config::get('cookie.token_name', 'Authori-zation')), 'Bearer'));
/** @var LoginServices $services */
$services = app()->make(LoginServices::class);
$outInfo = $services->parseToken($token);
$request->macro('supplierId', function () use (&$outInfo) {
return (int)$outInfo['id'];
});
$request->macro('supplierInfo', function () use (&$outInfo) {
return $outInfo;
});
return $next($request);
}
}

View File

@ -0,0 +1,32 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\common\middleware;
use app\Request;
use crmeb\interfaces\MiddlewareInterface;
/**
* 站点升级
* Class StationOpenMiddleware
* @package app\api\middleware
*/
class StationOpenMiddleware implements MiddlewareInterface
{
public function handle(Request $request, \Closure $next)
{
if (!systemConfig('station_open', true)) {
return app('json')->make('410010', '站点升级中,请稍候访问');
}
return $next($request);
}
}

View File

@ -0,0 +1,42 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\common\middleware;
use app\Request;
use app\services\supplier\LoginServices;
use crmeb\exceptions\AuthException;
use crmeb\interfaces\MiddlewareInterface;
use crmeb\utils\ApiErrorCode;
/**
* 权限规则验证
* Class SupplierCheckRoleMiddleware
* @package app\http\middleware\supplier
*/
class SupplierCheckRoleMiddleware implements MiddlewareInterface
{
public function handle(Request $request, \Closure $next)
{
if (!$request->supplierId() || !$request->supplierInfo())
throw new AuthException(ApiErrorCode::ERR_ADMINID_VOID);
if ($request->supplierInfo()['level'] ?? 0) {
/** @var LoginServices $services */
$services = app()->make(LoginServices::class);
$services->verifiAuth($request);
}
return $next($request);
}
}

View File

@ -0,0 +1,41 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\common\middleware;
use app\Request;
use app\jobs\system\AdminLogJob;
use crmeb\interfaces\MiddlewareInterface;
/**
* 操作日志记录
* Class SupplierLogMiddleware
* @package app\http\middleware\supplier
*/
class SupplierLogMiddleware implements MiddlewareInterface
{
/**
* @param Request $request
* @param \Closure $next
* @return mixed
*/
public function handle(Request $request, \Closure $next)
{
$module = app('http')->getName();
$rule = trim(strtolower($request->rule()->getRule()));
//记录后台日志
AdminLogJob::dispatch([$request->supplierId(), $request->supplierInfo()['supplier_name'], $module, $rule, $request->ip(), 'supplier']);
return $next($request);
}
}

449
app/dao/BaseDao.php Normal file
View File

@ -0,0 +1,449 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao;
use crmeb\basic\BaseAuth;
use crmeb\basic\BaseModel;
use crmeb\traits\dao\CacheDaoTrait;
use think\Model;
/**
* Class BaseDao
* @package app\dao
*/
abstract class BaseDao
{
use CacheDaoTrait;
/**
* 当前表名别名
* @var string
*/
protected $alias;
/**
* join表别名
* @var string
*/
protected $joinAlis;
/**
* 获取当前模型
* @return string
*/
abstract protected function setModel(): string;
/**
* 设置join链表模型
* @return string
*/
protected function setJoinModel(): string
{
}
/**
* 读取数据条数
* @param array $where
* @return int
*/
public function count(array $where = []): int
{
return $this->search($where)->count();
}
/**
* 获取某些条件总数
* @param array $where
* @return int
*/
public function getCount(array $where)
{
return $this->getModel()->where($where)->count();
}
/**
* 获取某些条件去重总数
* @param array $where
* @param $field
* @param $search
*/
public function getDistinctCount(array $where, $field, $search = true)
{
if ($search) {
return $this->search($where)->field('COUNT(distinct(' . $field . ')) as count')->select()->toArray()[0]['count'] ?? 0;
} else {
return $this->getModel()->where($where)->field('COUNT(distinct(' . $field . ')) as count')->select()->toArray()[0]['count'] ?? 0;
}
}
/**
* 获取模型
* @return BaseModel
*/
protected function getModel()
{
return app()->make($this->setModel());
}
/**
* 获取主键
* @return mixed
*/
protected function getPk()
{
return $this->getModel()->getPk();
}
/**
* 获取一条数据
* @param int|array $id
* @param array|null $field
* @param array|null $with
* @return array|Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function get($id, ?array $field = [], ?array $with = [])
{
if (is_array($id)) {
$where = $id;
} else {
$where = [$this->getPk() => $id];
}
return $this->getModel()::where($where)->when(count($with), function ($query) use ($with) {
$query->with($with);
})->field($field ?? ['*'])->find();
}
/**
* 查询一条数据是否存在
* @param $map
* @param string $field
* @return bool 是否存在
*/
public function be($map, string $field = '')
{
if (!is_array($map) && empty($field)) $field = $this->getPk();
$map = !is_array($map) ? [$field => $map] : $map;
return 0 < $this->getModel()->where($map)->count();
}
/**
* 根据条件获取一条数据
* @param array $where
* @param string|null $field
* @param array $with
* @return array|Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getOne(array $where, ?string $field = '*', array $with = [])
{
$field = explode(',', $field);
return $this->get($where, $field, $with);
}
/**
* 获取单个字段值
* @param array $where
* @param string|null $field
* @return mixed
*/
public function value(array $where, ?string $field = '')
{
$pk = $this->getPk();
return $this->getModel()::where($where)->value($field ?: $pk);
}
/**
* 获取某个字段数组
* @param array $where
* @param string $field
* @param string $key
* @param bool $search
* @return array
*/
public function getColumn(array $where, string $field, string $key = '', bool $search = false)
{
if ($search) {
return $this->search($where)->column($field, $key);
} else {
return $this->getModel()::where($where)->column($field, $key);
}
}
/**
* 删除
* @param int|string|array $id
* @return mixed
*/
public function delete($id, ?string $key = null)
{
if (is_array($id)) {
$where = $id;
} else {
$where = [is_null($key) ? $this->getPk() : $key => $id];
}
return $this->getModel()::where($where)->delete();
}
/**
* 更新数据
* @param int|string|array $id
* @param array $data
* @param string|null $key
* @return mixed
*/
public function update($id, array $data, ?string $key = null)
{
if (is_array($id)) {
$where = $id;
} else {
$where = [is_null($key) ? $this->getPk() : $key => $id];
}
return $this->getModel()::update($data, $where);
}
/**
* 批量更新数据
* @param array $ids
* @param array $data
* @param string|null $key
* @return BaseModel
*/
public function batchUpdate(array $ids, array $data, ?string $key = null)
{
return $this->getModel()::whereIn(is_null($key) ? $this->getPk() : $key, $ids)->update($data);
}
/**
* 批量更新数据,增加条件
* @param array $ids
* @param array $data
* @param array $where
* @param string|null $key
* @return BaseModel
*/
public function batchUpdateAppendWhere(array $ids, array $data, array $where, ?string $key = null)
{
return $this->getModel()::whereIn(is_null($key) ? $this->getPk() : $key, $ids)->where($where)->update($data);
}
/**
* 插入数据
* @param array $data
* @return BaseModel|Model
*/
public function save(array $data)
{
return $this->getModel()::create($data);
}
/**
* 插入数据
* @param array $data
* @return mixed
*/
public function saveAll(array $data)
{
return $this->getModel()::insertAll($data);
}
/**
* 获取某个字段内的值
* @param $value
* @param string $filed
* @param string $valueKey
* @param array|string[] $where
* @return mixed
*/
public function getFieldValue($value, string $filed, ?string $valueKey = '', ?array $where = [])
{
return $this->getModel()->getFieldValue($value, $filed, $valueKey, $where);
}
/**
* 根据搜索器获取搜索内容
* @param array $withSearch
* @param array|null $data
* @return Model
*/
protected function withSearchSelect(array $withSearch, ?array $data = [])
{
[$with] = app()->make(BaseAuth::class)->________($withSearch, $this->setModel());
return $this->getModel()->withSearch($with, $data);
}
/**
* 搜索
* @param array $where
* @return \crmeb\basic\BaseModel|mixed
*/
protected function search(array $where = [])
{
if ($where) {
return $this->withSearchSelect(array_keys($where), $where);
} else {
return $this->getModel();
}
}
/**
* 求和
* @param array $where
* @param string $field
* @param bool $search
* @return float
*/
public function sum(array $where, string $field, bool $search = false)
{
if ($search) {
return $this->search($where)->sum($field);
} else {
return $this->getModel()::where($where)->sum($field);
}
}
/**
* 高精度加法
* @param int|string $key
* @param string $incField
* @param string $inc
* @param string|null $keyField
* @param int $acc
* @return bool
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function bcInc($key, string $incField, string $inc, string $keyField = null, int $acc = 2)
{
return $this->bc($key, $incField, $inc, $keyField, 1);
}
/**
* 高精度 减法
* @param int|string $uid id
* @param string $decField 相减的字段
* @param float|int $dec 减的值
* @param string $keyField id的字段
* @param bool $minus 是否可以为负数
* @param int $acc 精度
* @param bool $dec_return_false 减法 不够减是否返回false 减为0
* @return bool
*/
public function bcDec($key, string $decField, string $dec, string $keyField = null, int $acc = 2, bool $dec_return_false = true)
{
return $this->bc($key, $decField, $dec, $keyField, 2, $acc, $dec_return_false);
}
/**
* 高精度计算并保存
* @param $key
* @param string $incField
* @param string $inc
* @param string|null $keyField
* @param int $type
* @param int $acc
* @param bool $dec_return_false 减法 不够减是否返回false 减为0
* @return bool
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function bc($key, string $incField, string $inc, string $keyField = null, int $type = 1, int $acc = 2, bool $dec_return_false = true)
{
if ($keyField === null) {
$result = $this->get($key);
} else {
$result = $this->getOne([$keyField => $key]);
}
if (!$result) return false;
if ($type === 1) {
$new = bcadd($result[$incField], $inc, $acc);
} else if ($type === 2) {
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();
}
/**
* 减库存加销量
* @param array $where
* @param int $num
* @return mixed
*/
public function decStockIncSales(array $where, int $num, string $stock = 'stock', string $sales = 'sales')
{
return app()->make(BaseAuth::class)->_____($this->getModel(), $where, $num, $stock, $sales) !== false;
}
/**
* 加库存减销量
* @param array $where
* @param int $num
* @return mixed
*/
public function incStockDecSales(array $where, int $num, string $stock = 'stock', string $sales = 'sales')
{
return app()->make(BaseAuth::class)->___($this->getModel(), $where, $num, $stock, $sales) !== false;
}
/**
* 软删除
* @param $id
* @param string|null $key
* @return bool
*/
public function destroy($id, ?string $key = null)
{
if (is_array($id)) {
$where = $id;
} else {
$where = [is_null($key) ? $this->getPk() : $key => $id];
}
return $this->getModel()::destroy($where);
}
/**
* 自增单个数据
* @param $where
* @param string $field
* @param int $number
* @return mixed
*/
public function incUpdate($where, string $field, int $number = 1)
{
return $this->getModel()->where(is_array($where) ? $where : [$this->getPk() => $where])->inc($field, $number)->update();
}
/**
* 自减单个数据
* @param $where
* @param string $field
* @param int $number
* @return mixed
*/
public function decUpdate($where, string $field, int $number = 1)
{
return $this->getModel()->where(is_array($where) ? $where : [$this->getPk() => $where])->dec($field, $number)->update();
}
}

View File

@ -0,0 +1,100 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\activity;
use app\dao\BaseDao;
use app\common\model\store\StoreActivity;
/**
* 活动
* Class StoreActivityDao
* @package app\dao\activity
*/
class StoreActivityDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreActivity::class;
}
/**
* 搜索
* @param array $where
* @return \crmeb\basic\BaseModel|mixed|\think\Model
*/
protected function search(array $where = [])
{
return parent::search($where)->when(isset($where['activityTime']), function ($query) use ($where) {
[$startTime, $stopTime] = is_array($where['activityTime']) ? $where['activityTime'] : [time(), time() - 86400];
$query->where('start_day', '<=', $startTime)->where('end_day', '>=', $stopTime);
})->when(isset($where['start_status']) && $where['start_status'] !== '', function ($query) use ($where) {
$time = time();
switch ($where['start_status']) {
case -1:
$query->where(function ($q) use ($time) {
$q->where('end_day', '<', $time - 86400)->whereOr('status', '0');
});
break;
case 0:
$query->where('start_day', '>', $time)->where('status', 1);
break;
case 1:
$query->where('start_day', '<=', $time)->where('end_day', '>=', $time - 86400)->where('status', 1);
break;
}
});
}
/**
* 获取活动列表
* @param array $where
* @param string $field
* @param int $page
* @param int $limit
* @param array $with
* @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, array $with = [], string $order = 'start_time asc, id desc')
{
return $this->search($where)->field($field)
->when($with, function ($query) use ($with) {
$query->with($with);
})->when($page != 0 && $limit != 0, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order($order)->select()->toArray();
}
/**
* 验证是否有活动
* @param array $where
* @return bool
* @throws \think\db\exception\DbException
*/
public function checkActivity(array $where)
{
return $this->search($where)->where('end_day', '>', time())->count() > 0;
}
}

View File

@ -0,0 +1,143 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\activity\bargain;
use app\dao\BaseDao;
use app\model\activity\bargain\StoreBargain;
/**
* 砍价商品
* Class StoreBargainDao
* @package app\dao\activity\bargain
*/
class StoreBargainDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreBargain::class;
}
/**
* @param array $where
* @return \crmeb\basic\BaseModel|mixed|\think\Model
*/
public function search(array $where = [])
{
return parent::search($where)
->when(isset($where['start_status']) && $where['start_status'] !== '', function ($query) use ($where) {
$time = time();
switch ($where['start_status']) {
case -1:
$query->where('stop_time', '<', $time);
break;
case 0:
$query->where('start_time', '>', $time);
break;
case 1:
$query->where('start_time', '<=', $time)->where('stop_time', '>=', $time);
break;
}
});
}
/**
* 获取砍价列表
* @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 getList(array $where, int $page = 0, int $limit = 0)
{
return $this->search($where)->when($page != 0 && $limit != 0, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order('sort desc,id desc')->select()->toArray();
}
/**
* 获取活动开启中的砍价id以数组形式返回
* @param array $ids
* @param array $field
* @return array
*/
public function getBargainIdsArray(array $ids, array $field = [])
{
return $this->search(['is_del' => 0, 'status' => 1])->where('start_time', '<=', time())
->where('stop_time', '>=', time())->whereIn('product_id', $ids)->column(implode(',', $field), 'product_id');
}
/**
* 根据id获取砍价数据
* @param array $ids
* @param string $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function idByBargainList(array $ids, string $field)
{
return $this->getModel()->whereIn('id', $ids)->field($field)->select()->toArray();
}
/**
* 正在开启的砍价活动
* @param int $status
* @return StoreBargain
*/
public function validWhere(int $status = 1)
{
return $this->getModel()->where('is_del', 0)->where('status', $status)->where('start_time', '<', time())->where('stop_time', '>', time());
}
/**
* 砍价列表
* @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 bargainList(int $page = 0, int $limit = 0)
{
return $this->search(['is_del' => 0, 'status' => 1])
->where('start_time', '<=', time())
->where('stop_time', '>=', time())
->where('product_id', 'IN', function ($query) {
$query->name('store_product')->where('is_show', 1)->where('is_del', 0)->field('id');
})->with('product')->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order('sort DESC,id DESC')->select()->toArray();
}
/**
* 修改砍价状态
* @param int $id
* @param string $field
* @return mixed
*/
public function addBargain(int $id, string $field)
{
return $this->getModel()->where('id', $id)->inc($field, 1)->update();
}
}

View File

@ -0,0 +1,98 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\activity\collage;
use app\dao\BaseDao;
use app\model\activity\collage\UserCollageCode;
/**
* 拼单
* Class UserCollageDao
* @package app\dao\collage
*/
class UserCollageDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return UserCollageCode::class;
}
/**搜索条件处理
* @param array $where
* @return \crmeb\basic\BaseModel|mixed|\think\Model
*/
public function search(array $where = [])
{
return parent::search($where)->when(isset($where['serial_number']) && $where['serial_number'] != '', function ($query) use ($where) {
if (substr($where['serial_number'], 0, 2) == 'wx') {
$query->where(function ($que) use ($where) {
$que->where('oid', 'in', function ($q) use ($where) {
$q->name('store_order')->where('order_id', 'LIKE', '%' . $where['serial_number'] . '%')->where('type', 10)->field(['id'])->select();
});
});
} else {
$query->where('serial_number', 'LIKE', '%' . $where['serial_number'] . '%');
}
})->when(isset($where['status']) && $where['status'], function ($query) use ($where) {
if (is_array($where['status'])) {
$query->whereIn('status', $where['status']);
} else {
$query->where('status', $where['status']);
}
})->when(isset($where['type']) && $where['type'], function ($query) use ($where) {
$query->where('type', $where['type']);
})->when(isset($where['store_id']) && $where['store_id'], function ($query) use ($where) {
$query->where('store_id', $where['store_id']);
})->when(isset($where['staff_id']) && $where['staff_id'] > 0, function ($query) use ($where) {
$query->where(function ($que) use ($where) {
$que->where('oid', 'in', function ($q) use ($where) {
$q->name('store_order')->where('staff_id', $where['staff_id'])->where('type', 10)->field(['id'])->select();
});
});
});
}
/**获取当天最大流水号
* @param $where
* @return mixed
*/
public function getMaxSerialNumber($where)
{
$now_day = strtotime(date('Y-m-d'));
return $this->search($where)->where('add_time', '>', $now_day)->order('add_time desc')->value('serial_number');
}
/**桌码订单
* @param array $where
* @param int $store_id
* @param array $with
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function searchTableCodeList(array $where, array $field = ['*'], int $page = 0, int $limit = 0, array $with = [])
{
return $this->search($where)->field($field)->when(count($with), function ($query) use ($with) {
$query->with($with);
})->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->when(!$page && $limit, function ($query) use ($limit) {
$query->limit($limit);
})->order('add_time desc')->select()->toArray();
}
}

View File

@ -0,0 +1,106 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\activity\collage;
use app\dao\BaseDao;
use app\model\activity\collage\UserCollageCodePartake;
/**
* 用户参与拼单
* Class UserCollagePartakeDao
* @package app\dao\collage
*/
class UserCollagePartakeDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return UserCollageCodePartake::class;
}
/**
* @param array $where
* @return \crmeb\basic\BaseModel|mixed|\think\Model
*/
public function search(array $where = [])
{
return parent::search($where)->when(isset($where['uid']) && $where['uid'], function ($query) use ($where) {
$query->where('uid', $where['uid']);
})->when(isset($where['collate_code_id']) && $where['collate_code_id'], function ($query) use ($where) {
$query->where('collate_code_id', $where['collate_code_id']);
})->when(isset($where['store_id']) && $where['store_id'], function ($query) use ($where) {
$query->where('store_id', $where['store_id']);
})->when(isset($where['status']) && $where['status'], function ($query) use ($where) {
$query->where('status', 1);
});
}
/**
* 用户拼单商品统计数据
* @param int $uid
* @param string $field
* @param array $with
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getUserPartakeList(array $where, string $field = '*', array $with = [])
{
return $this->getModel()->where($where)->when(count($with), function ($query) use ($with) {
$query->with($with);
})->order('add_time DESC')->field($field)->select()->toArray();
}
/**
* 获取拼单信息
* @param array $where
* @param string $field
* @param array $with
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getUserPartakeProductList(array $where, string $field = '*', array $with = [])
{
return $this->getModel()->where($where)->when(count($with), function ($query) use ($with) {
$query->with($with);
})->order('add_time DESC')->field($field)->select()->toArray();
}
/**
* 用户删除拼单、桌码商品
* @param array $where
* @return bool
*/
public function del(array $where)
{
return $this->getModel()->where($where)->delete();
}
/**最后加入的记录
* @param $where
* @return array|\crmeb\basic\BaseModel|mixed|\think\Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getUserPartake(array $where)
{
return $this->getModel()->where($where)->order('add_time DESC')->find();
}
}

View File

@ -0,0 +1,153 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\activity\combination;
use app\dao\BaseDao;
use app\model\activity\combination\StoreCombination;
/**
* 拼团商品
* Class StoreCombinationDao
* @package app\dao\activity\combination
*/
class StoreCombinationDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreCombination::class;
}
/**
* 搜索
* @param array $where
* @return \crmeb\basic\BaseModel|mixed|\think\Model
*/
public function search(array $where = [])
{
return parent::search($where)->when(isset($where['pinkIngTime']), function ($query) use ($where) {
$time = time();
[$startTime, $stopTime] = is_array($where['pinkIngTime']) ? $where['pinkIngTime'] : [$time, $time];
$query->where('start_time', '<=', $startTime)->where('stop_time', '>=', $stopTime);
})->when(isset($where['storeProductId']), function ($query) {
$query->where('product_id', 'IN', function ($query) {
$query->name('store_product')->where('is_show', 1)->where('is_del', 0)->field('id');
});
})->when(isset($where['start_status']) && $where['start_status'] !== '', function ($query) use ($where) {
$time = time();
switch ($where['start_status']) {
case -1:
$query->where(function ($query) use ($time) {
$query->where('stop_time', '<', $time)->whereOr('is_show', 0);
});
break;
case 0:
$query->where('start_time', '>', $time)->where('is_show', 1);
break;
case 1:
$query->where('start_time', '<=', $time)->where('stop_time', '>=', $time)->where('is_show', 1);
break;
}
});
}
/**
* 拼团商品列表
* @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 getList(array $where, int $page = 0, int $limit = 0)
{
return $this->search($where)->with('getPrice')
->when($page != 0 && $limit != 0, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order('sort desc,id desc')->select()->toArray();
}
/**
* 获取正在进行拼团的商品以数组形式返回
* @param array $ids
* @param array $field
* @return array
*/
public function getPinkIdsArray(array $ids, array $field = [])
{
return $this->search(['is_del' => 0, 'is_show' => 1, 'pinkIngTime' => 1])->whereIn('product_id', $ids)->column(implode(',', $field), 'product_id');
}
/**
* 获取拼团列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function combinationList(array $where, int $page = 0, int $limit = 0)
{
return $this->search($where)->with('getPrice')->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order('sort desc,id desc')->select()->toArray();
}
/**
* 根据id获取拼团数据
* @param array $ids
* @param string $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function idCombinationList(array $ids, string $field)
{
return $this->getModel()->whereIn('id', $ids)->field($field)->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 validProduct(int $id, string $field)
{
$where = ['is_show' => 1, 'is_del' => 0, 'pinkIngTime' => true];
return $this->search($where)->where('id', $id)->with(['total'])->field($field)->order('add_time desc')->find();
}
/**
* 获取推荐拼团
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getCombinationHost()
{
$where = ['is_del' => 0, 'is_host' => 1, 'is_show' => 1, 'pinkIngTime' => true];
return $this->search($where)->order('id desc')->select()->toArray();
}
}

View File

@ -0,0 +1,203 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\activity\combination;
use app\dao\BaseDao;
use app\model\activity\combination\StorePink;
/**
* 拼团
* Class StorePinkDao
* @package app\dao\activity\combination
*/
class StorePinkDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StorePink::class;
}
/**
* 获取拼团数量集合
* @param array $where
* @return array
*/
public function getPinkCount(array $where = [])
{
return $this->getModel()->where($where)->group('cid')->column('count(*)', 'cid');
}
/**
* 获取列表
* @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 getList(array $where, int $page = 0, int $limit = 0)
{
return $this->search($where)->when($where['k_id'] != 0, function ($query) use ($where) {
$query->whereOr('id', $where['k_id']);
})->with(['getProduct', 'getUser'])->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order('add_time desc')->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 getPinking(array $where)
{
return $this->search($where)->order('add_time asc')->find();
}
/**
* 获取拼团列表
* @param array $where
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function pinkList(array $where)
{
return $this->search($where)
->where('stop_time', '>', time())
->order('add_time desc')
->select()->toArray();
}
/**
* 获取正在拼团的人数
* @param int $kid
* @return int
*/
public function getPinkPeople(int $kid)
{
return $this->count(['k_id' => $kid, 'is_refund' => 0]) + 1;
}
/**
* 获取正在拼团的人数
* @param array $kids
* @return int
*/
public function getPinkPeopleCount(array $kids)
{
$count = $this->getModel()->whereIn('k_id', $kids)->where('is_refund', 0)->group('k_id')->column('COUNT(id) as count', 'k_id');
$counts = [];
foreach ($kids as &$item) {
if (isset($count[$item])) {
$counts[$item] = $count[$item] + 1;
} else {
$counts[$item] = 1;
}
}
return $counts;
}
/**
* 获取拼团成功的列表
* @param int $uid
* @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 successList(int $uid, string $field = '*', int $page = 0, int $limit = 0)
{
return $this->search(['status' => 2, 'is_refund' => 0])->field($field)
->where('uid', '>', 0)
->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->when(!$page && $limit, function ($query) use ($limit) {
$query->limit($limit);
})->order('id desc')->select()->toArray();
}
/**
* 获取拼团完成的个数
* @return float
*/
public function getPinkOkSumTotalNum()
{
return $this->sum(['status' => 2, 'is_refund' => 0], 'total_num');
}
/**
* 是否能继续拼团
* @param int $id
* @param int $uid
* @return int
*/
public function isPink(int $id, int $uid)
{
return $this->getModel()->where('k_id|id', $id)->where('uid', $uid)->where('is_refund', 0)->count();
}
/**
* 获取一条拼团信息
* @param int $id
* @return array|\think\Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getPinkUserOne(int $id)
{
return $this->search()->with('getProduct')->find($id);
}
/**
* 获取拼团信息
* @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 getPinkUserList(array $where)
{
return $this->getModel()->where($where)->with('getProduct')->select()->toArray();
}
/**
* 获取拼团结束的列表
* @return \crmeb\basic\BaseModel
*/
public function pinkListEnd()
{
return $this->getModel()->where('stop_time', '<=', time())
->where('status', 1)
->where('k_id', 0)
->where('is_refund', 0)
->field('id,people,k_id,order_id_key,uid,stop_time');
}
}

View File

@ -0,0 +1,397 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\activity\coupon;
use app\dao\BaseDao;
use app\model\activity\coupon\StoreCouponIssue;
/**
* 优惠卷
* Class StoreCouponIssueDao
* @package app\dao\activity\coupon
*/
class StoreCouponIssueDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreCouponIssue::class;
}
/**
* @param array $where
* @return \crmeb\basic\BaseModel|mixed|\think\Model
*/
public function search(array $where = [])
{
return parent::search($where)->when(isset($where['receive']) && $where['receive'] != '', function ($query) use ($where) {
if ($where['receive'] == 'send') {
$query->where('receive_type', 3)
->where('status', 1)
->where('is_del', 0)
->where('remain_count > 0 OR is_permanent = 1')
->where(function ($query1) {
$query1->where(function ($query2) {
$query2->where('start_time', '<=', time())->where('end_time', '>=', time());
})->whereOr(function ($query3) {
$query3->where('start_time', 0)->where('end_time', 0);
});
})->where(function ($query4) {
$query4->where(function ($query5) {
$query5->where('coupon_time', 0)->where('end_use_time', '>=', time());
})->whereOr('coupon_time', '>', 0);
});
}
})->when(isset($where['receive_type']) && $where['receive_type'], function ($query) use ($where) {
$query->where('receive_type', $where['receive_type']);
});
}
/**
* 有效优惠券搜索
* @param array $where
* @return \crmeb\basic\BaseModel|mixed|\think\Model
*/
public function validSearch(array $where = [])
{
return parent::search($where)
->where('status', 1)
->where('is_del', 0)
->where('remain_count > 0 OR is_permanent = 1')
->where(function ($query) {
$query->where(function ($query) {
$query->where('start_time', '<=', time())->where('end_time', '>=', time());
})->whereOr(function ($query) {
$query->where('start_time', 0)->where('end_time', 0);
});
})->where(function ($query4) {
$query4->where(function ($query5) {
$query5->where('coupon_time', 0)->where('end_use_time', '>=', time());
})->whereOr('coupon_time', '>', 0);
});
}
/**
* 获取列表
* @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 getList(array $where, int $page = 0, int $limit = 0)
{
return $this->search($where)->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order('id desc')->select()->toArray();
}
/**
* 获取有效的优惠券列表
* @param array $where
* @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 getValidList(array $where = [], int $page = 0, int $limit = 0, array $with = [])
{
return $this->validSearch($where)
->when(isset($where['not_id']) && $where['not_id'], function($query) use ($where) {
$query->whereNotIn('id', $where['not_id']);
})->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->when($with, function ($query) use ($with) {
$query->with($with);
})->order('id desc')->select()->toArray();
}
/**
* 获取有效的赠送券
* @param array $ids
* @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 getValidGiveCoupons(array $ids, string $field = '*' , int $page = 0, int $limit = 0)
{
return $this->validSearch()->field($field)
->where('receive_type',3)
->when(count($ids), function ($query) use ($ids) {
$query->whereIn('id', $ids);
})->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->select()->toArray();
}
/**
* 获取商品优惠券
* @param int $uid
* @param array $where
* @param string $field
* @param int $page
* @param int $limit
* @param string $sort
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getIssueCouponListNew(int $uid, array $where = [], string $field = '*', int $page = 0, int $limit = 0, string $sort = 'sort desc,id desc')
{
return $this->validSearch()->field($field)
->whereIn('receive_type', [1, 4])
->with(['used' => function ($query) use ($uid) {
$query->where('uid', $uid);
}])
->when(isset($where['type']) && $where['type'] != -1, function ($query) use ($where) {
$query->where('type', $where['type']);
})
->when(isset($where['type']) && $where['type'] == 1 && isset($where['cate_id']) && $where['cate_id'], function ($query) use ($where) {
$query->where('category_id', 'in', $where['cate_id']);
})
->when(isset($where['type']) && $where['type'] == 2 && isset($where['product_id']) && $where['product_id'], function ($query) use ($where) {
$query->whereFindinSet('product_id', $where['product_id']);
})
->when(isset($where['type']) && $where['type'] == 3 && isset($where['brand_id']) && $where['brand_id'], function ($query) use ($where) {
$query->where('brand_id', 'in', $where['brand_id']);
})
->when((isset($where['product_id']) && $where['product_id']) || (isset($where['cate_id']) && $where['cate_id']) || isset($where['brand_id']) && $where['brand_id'], function ($query) use ($where) {
$query->where(function ($z) use ($where) {
$z->whereOr('type', 0)
->when(isset($where['product_id']) && $where['product_id'], function ($p) use ($where) {
$p->whereOr(function ($c) use ($where) {
$c->whereFindinSet('product_id', $where['product_id']);
});
})->when(isset($where['cate_id']) && $where['cate_id'], function ($c) use ($where) {
$c->whereOr('category_id', 'in', $where['cate_id']);
})->when(isset($where['brand_id']) && $where['brand_id'], function ($b) use ($where) {
$b->whereOr('brand_id', 'in', $where['brand_id']);
});
});
})
->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order($sort)->select()->toArray();
}
/**
* 获取优惠券列表
* @param int $uid 用户ID
* @param int $type 0通用1分类2商品
* @param int $typeId 分类ID或商品ID
* @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 getIssueCouponList(int $uid, int $type, $typeId, string $field = '*', int $page = 0, int $limit = 0)
{
return $this->validSearch()->field($field)
->whereIn('receive_type', [1, 4])
->with(['used' => function ($query) use ($uid) {
$query->where('uid', $uid);
}])
->where('type', $type)
->when($type == 1, function ($query) use ($typeId) {
if ($typeId) $query->where('category_id', 'in', $typeId);
})
->when($type == 2, function ($query) use ($typeId) {
if ($typeId) $query->whereFindinSet('product_id', $typeId);
})
->when($type == 3, function ($query) use ($typeId) {
if ($typeId) $query->where('brand_id', 'in', $typeId);
})
->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order('sort desc,id desc')->select()->toArray();
}
/**
* PC端获取优惠券
* @param int $uid
* @param array $cate_ids
* @param int $product_id
* @param string $filed
* @param int $page
* @param int $limit
* @param string $sort
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getPcIssueCouponList(int $uid, array $cate_ids = [], int $product_id = 0, string $filed = '*', int $page = 0, int $limit = 0, string $sort = 'sort desc,id desc')
{
return $this->validSearch()->field($filed)
->whereIn('receive_type', [1, 4])
->with(['used' => function ($query) use ($uid) {
$query->where('uid', $uid);
}])->where(function ($query) use ($product_id, $cate_ids) {
if ($product_id != 0 && $cate_ids != []) {
$query->whereFindinSet('product_id', $product_id)->whereOr('category_id', 'in', $cate_ids)->whereOr('type', 0);
}
})->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->when(!$page && $limit, function ($query) use ($page, $limit) {
$query->limit($limit);
})->order($sort)->select()->toArray();
}
/**
* 获取优惠券数量
* @param int $productId
* @param int $cateId
* @return mixed
*/
public function getIssueCouponCount($productId = 0, $cateId = 0, $brandId = 0)
{
$count[0] = $this->validSearch()->whereIn('receive_type', [1, 4])->where('type', 0)->count();
$count[1] = $this->validSearch()->whereIn('receive_type', [1, 4])->where('type', 1)->when($cateId != 0, function ($query) use ($cateId) {
if ($cateId) $query->where('category_id', 'in', $cateId);
})->count();
$count[2] = $this->validSearch()->whereIn('receive_type', [1, 4])->where('type', 2)->when($productId != 0, function ($query) use ($productId) {
if ($productId) $query->whereFindinSet('product_id', $productId);
})->count();
$count[3] = $this->validSearch()->whereIn('receive_type', [1, 4])->where('type', 3)->when($productId != 0, function ($query) use ($brandId) {
if ($brandId) $query->where('brand_id', 'in', $brandId);
})->count();
return $count;
}
/**
* 获取优惠卷详情
* @param int $id
* @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)
{
return $this->validSearch()->where('id', $id)->find();
}
/**
* 获取金大于额的优惠卷金额
* @param string $totalPrice
* @return float
*/
public function getUserIssuePrice(string $totalPrice)
{
return $this->search(['status' => 1, 'is_full_give' => 1, 'is_del' => 0])
->where('full_reduction', '<=', $totalPrice)
->sum('coupon_price');
}
/**
* 获取新人券
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getNewCoupon()
{
return $this->validSearch()->where('receive_type', 2)->select()->toArray();
}
/**
* 获取一条优惠券信息
* @param int $id
* @return mixed
*/
public function getCouponInfo(int $id)
{
return $this->getModel()->where('id', $id)->where('status', 1)->where('is_del', 0)->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 getGiveCoupon(array $where, string $field = '*')
{
return $this->validSearch()->field($field)->where($where)->select()->toArray();
}
/**
* 获取商品优惠卷列表
* @param $where
* @param $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function productCouponList($where, $field)
{
return $this->getModel()->where($where)->field($field)->select()->toArray();
}
/**
* 获取优惠券弹窗列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getTodayCoupon($uid)
{
return $this->validSearch()
->whereIn('receive_type', [1, 4])
->when($uid != 0, function ($query) use ($uid) {
$query->with(['used' => function ($query) use ($uid) {
$query->where('uid', $uid);
}]);
})->whereDay('add_time')->order('sort desc,id desc')->select()->toArray();
}
/**
* api数据获取优惠券
* @param array $where
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getApiIssueList(array $where)
{
return $this->getModel()->where($where)->select()->toArray();
}
}

View File

@ -0,0 +1,242 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\activity\coupon;
use app\dao\BaseDao;
use app\common\model\store\coupon\StoreCouponUser;
/**
* Class StoreCouponUserDao
* @package app\dao\activity\coupon
*/
class StoreCouponUserDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreCouponUser::class;
}
/**
* 搜索
* @param array $where
* @return \crmeb\basic\BaseModel|mixed|\think\Model
*/
public function search(array $where = [])
{
return parent::search($where)->when(isset($where['nickname']) && $where['nickname'] != '', function ($query) use ($where) {
$query->where('uid', 'IN' , function($q) use ($where) {
$q->name('user')->where('uid|real_name|nickname|account|phone', 'like', '%' . $where['nickname'] . '%')->field('uid');
});
})->when(isset($where['coupon_title']) && $where['coupon_title'] != '', function ($query) use ($where) {
$query->where('coupon_title', 'like', '%' . $where['coupon_title'] . '%');
});
}
/**
* 获取列表
* @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 = ['issue'], int $page = 0, int $limit = 0)
{
return $this->search($where)->field($field)->with($with)->page($page, $limit)->order('id desc')->select()->toArray();
}
/**
* 使用优惠券修改优惠券状态
* @param $id
* @return \think\Model|null
*/
public function useCoupon(int $id)
{
return $this->getModel()->where('id', $id)->update(['status' => 1, 'use_time' => time()]);
}
/**
* 获取指定商品id下的优惠卷
* @param array $productIds
* @param int $uid
* @param string $price
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function productIdsByCoupon(array $productIds, int $uid, string $price)
{
return $this->getModel()->whereIn('cid', function ($query) use ($productIds) {
$query->name('store_coupon_issue')->whereIn('id', function ($q) use ($productIds) {
$q->name('store_coupon_product')->whereIn('product_id', $productIds)->field('coupon_id')->select();
})->field(['id'])->select();
})->with('issue')->where(['uid' => $uid, 'status' => 0])->order('coupon_price DESC')
->where('use_min_price', '<=', $price)->select()
->where('start_time', '<=', time())->where('end_time', '>=', time())
->hidden(['status', 'is_fail'])->toArray();
}
/**
* 根据商品id获取
* @param array $cateIds
* @param int $uid
* @param string $price
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function cateIdsByCoupon(array $cateIds, int $uid, string $price)
{
return $this->getModel()->whereIn('cid', function ($query) use ($cateIds) {
$query->name('store_coupon_issue')->whereIn('category_id', $cateIds)->where('type', 1)->field('id')->select();
})->where(['uid' => $uid, 'status' => 0])->where('use_min_price', '<=', $price)
->where('start_time', '<=', time())->where('end_time', '>=', time())
->order('coupon_price DESC')->with('issue')->select()->hidden(['status', 'is_fail'])->toArray();
}
/**
* 获取当前用户可用的优惠卷
* @param array $ids
* @param int $uid
* @param string $price
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getUserCouponV1(int $uid, string $price = '0', array $ids = [])
{
return $this->getModel()->where(['uid' => $uid, 'status' => 0])->when(count($ids) != 0, function ($query) use ($ids) {
$query->whereNotIn('id', $ids);
})->whereIn('cid', function ($query) {
$query->name('store_coupon_issue')->where('type', 0)->field(['id'])->select();
})->when($price, function ($query, $price) {
$query->where('use_min_price', '<=', $price);
})
->where('start_time', '<=', time())->where('end_time', '>=', time())
->order('coupon_price DESC')->with('issue')->select()->hidden(['status', 'is_fail'])->toArray();
}
/**
* 获取当前用户可用的优惠卷
* @param array $ids
* @param int $uid
* @param string $price
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getUserCoupon(array $ids, int $uid, string $price)
{
return $this->getModel()->where(['uid' => $uid, 'status' => 0])->when(count($ids) != 0, function ($query) use ($ids) {
$query->whereNotIn('id', $ids);
})->whereIn('cid', function ($query) {
$query->name('store_coupon_issue')->where('type', 0)->field(['id'])->select();
})->where('use_min_price', '<=', $price)
->where('start_time', '<=', time())->where('end_time', '>=', time())
->order('coupon_price DESC')->with('issue')->select()->hidden(['status', 'is_fail'])->toArray();;
}
/**
* 获取当前用户所有可用的优惠卷
* @param int $uid
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getUserAllCoupon(int $uid)
{
return $this->getModel()->where(['uid' => $uid, 'status' => 0, 'is_fail' => 0])
->where('start_time', '<=', time())->where('end_time', '>=', time())
->order('coupon_price DESC')->with('issue')->select()->hidden(['status', 'is_fail'])->toArray();
}
/**
* 获取列表带排序
* @param array $where
* @param $order
* @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 getCouponListByOrder(array $where, $order, int $page = 0, int $limit = 0)
{
if (isset($where['status']) && $where['status'] == 1) $where['status'] = [1, 2];
return $this->search($where)->with('issue')->when($page > 0 && $limit > 0, function ($qeury) use ($page, $limit) {
$qeury->page($page, $limit);
})->when($order != '', function ($query) use ($order) {
$query->order($order);
})->when(isset($where['coupon_ids']), function ($qeury) use ($where) {
$qeury->whereIn('cid', $where['coupon_ids']);
})->select()->toArray();
}
/**根据月份查询用户获得的优惠券
* @param array $where
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function memberCouponUserGroupBymonth(array $where)
{
return $this->search($where)
->whereMonth('add_time')
->whereIn('cid', $where['couponIds'])
->field('count(id) as num,FROM_UNIXTIME(add_time, \'%Y-%m\') as time')
->group("FROM_UNIXTIME(add_time, '%Y-%m')")
->select()->toArray();
//echo $this->getModel()->getLastSql();die;
}
/**根据时间查询
* @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 getUserCounponByMonth(array $where)
{
return $this->search($where)->whereMonth('add_time')->find();
}
/**
* 获取本月领取的优惠券
* @param $uid
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getVipCouponList($uid)
{
return $this->getModel()->where('uid', $uid)->whereMonth('add_time')->select()->toArray();
}
}

View File

@ -0,0 +1,128 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\activity\discounts;
use app\dao\BaseDao;
use app\model\activity\discounts\StoreDiscounts;
/**
* 优惠套餐
* Class StoreDiscountsDao
* @package app\dao\activity\discounts
*/
class StoreDiscountsDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreDiscounts::class;
}
public function search(array $where = [])
{
return parent::search($where)
->when(isset($where['is_time']) && $where['is_time'] == 1, function ($query) {
$query->where(function ($q) {
$q->where(function ($query) {
$query->where('start_time', '<=', time())->where('stop_time', '>=', time());
})->whereOr(function ($query) {
$query->where('start_time', 0)->where('stop_time', 0);
});
});
});
}
/**
* 获取列表
* @param $where
* @param array $with
* @param $page
* @param $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList($where, array $with = [], $page = 0, $limit = 0)
{
return $this->search($where)->where('is_del', 0)
->when($page != 0 && $limit != 0, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->when($with, function ($query) use ($with) {
$query->with($with);
})->order('sort desc,id desc')->select()->toArray();
}
/**
* 优惠套餐列表
* @param int $product_id
* @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 getDiscounts(int $product_id, string $field = '*', int $page = 0, int $limit = 0)
{
return $this->search(['product_ids' => $product_id])->field($field)
->where('is_del', 0)->where('status', 1)
->where(function ($query) {
$query->where(function ($query) {
$query->where('start_time', '<=', time())->where('stop_time', '>=', time());
})->whereOr(function ($query) {
$query->where('start_time', 0)->where('stop_time', 0);
});
})->where(function ($query) {
$query->where(function ($query) {
$query->where('is_limit', 0);
})->whereOr(function ($query) {
$query->where('is_limit', 1)->where('limit_num', '>', 0);
});
})->with(['products'])
->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order('sort desc,id desc')->select()->toArray();
}
/**
* 优惠套餐数量
* @return int
*/
public function getDiscountsCount()
{
return $this->getModel()
->where('is_del', 0)->where('status', 1)
->where(function ($query) {
$query->where(function ($query) {
$query->where('start_time', '<=', time())->where('stop_time', '>=', time());
})->whereOr(function ($query) {
$query->where('start_time', 0)->where('stop_time', 0);
});
})->count();
}
public function decLimitNum($id, $num = 1)
{
return $this->getModel()->where('id', $id)->dec('limit_num', $num)->update();
}
public function incLimitNum(int $id, $num = 1)
{
return $this->getModel()->where('id', $id)->inc('limit_num', $num)->update();
}
}

View File

@ -0,0 +1,62 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\activity\discounts;
use app\dao\BaseDao;
use app\model\activity\discounts\StoreDiscountsProducts;
/**
* 优惠套餐商品
* Class StoreDiscountsProductsDao
* @package app\dao\activity\discounts
*/
class StoreDiscountsProductsDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreDiscountsProducts::class;
}
/**
* 获取商品列表
* @param $where
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList($where)
{
return $this->search($where)->select()->toArray();
}
/**
* 获取套餐商品
* @param int $id
* @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 getDiscountProductInfo(int $id, string $field, array $with = [])
{
return $this->getModel()->where('id', $id)->when($with, function ($query) use ($with) {
$query->with($with);
})->field($field)->find();
}
}

View File

@ -0,0 +1,83 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\activity\integral;
use app\dao\BaseDao;
use app\model\activity\integral\StoreIntegral;
/**
* 积分商品
* Class StoreIntegralDao
* @package app\dao\activity\integral
*/
class StoreIntegralDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreIntegral::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 getList(array $where, int $page = 0, int $limit = 0, string $field = '*')
{
return $this->search($where)->where('is_del', 0)
->when(isset($where['integral_time']) && $where['integral_time'] !== '', function ($query) use ($where) {
[$startTime, $endTime] = explode('-', $where['integral_time']);
$query->where('add_time', '>', strtotime($startTime))
->where('add_time', '<', strtotime($endTime) + 24 * 3600);
})->when(isset($where['priceOrder']) && $where['priceOrder'] != '', function ($query) use ($where) {
if ($where['priceOrder'] === 'desc') {
$query->order("integral,price desc");
} else {
$query->order("integral,price asc");
}
})->when(isset($where['salesOrder']) && $where['salesOrder'] != '', function ($query) use ($where) {
if ($where['salesOrder'] === 'desc') {
$query->order("sales desc");
} else {
$query->order("sales asc");
}
})->when($page != 0 && $limit != 0, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->field($field)->order('sort desc,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 validProduct(int $id, string $field)
{
$where = ['is_show' => 1, 'is_del' => 0];
return $this->search($where)->where('id', $id)->field($field)->order('add_time desc')->find();
}
}

View File

@ -0,0 +1,160 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\activity\integral;
use app\dao\BaseDao;
use app\model\activity\integral\StoreIntegralOrder;
/**
* 积分订单
* Class StoreIntegralOrderDao
* @package app\dao\activity\integral
*/
class StoreIntegralOrderDao extends BaseDao
{
/**
* 限制精确查询字段
* @var string[]
*/
protected $withField = ['uid', 'order_id', 'real_name', 'user_phone', 'store_name'];
/**
* @return string
*/
protected function setModel(): string
{
return StoreIntegralOrder::class;
}
/**
* 订单搜索
* @param array $where
* @return \crmeb\basic\BaseModel|mixed|\think\Model
*/
public function search(array $where = [])
{
$isDel = isset($where['is_del']) && $where['is_del'] !== '' && $where['is_del'] != -1;
$realName = $where['real_name'] ?? '';
$fieldKey = $where['field_key'] ?? '';
$fieldKey = $fieldKey == 'all' ? '' : $fieldKey;
return parent::search($where)->when($isDel, function ($query) use ($where) {
$query->where('is_del', $where['is_del']);
})->when(isset($where['is_system_del']), function ($query) {
$query->where('is_system_del', 0);
})->when(isset($where['paid']) && $where['paid'] == 1, function ($query) {
$query->where('paid', 1);
})->when(isset($where['is_price']) && $where['is_price'] == 1, function ($query) {
$query->where('price', '>', 0);
})->when(isset($where['is_integral']) && $where['is_integral'] == 1, function ($query) {
$query->where('integral', '>', 0);
})->when($realName && $fieldKey && in_array($fieldKey, $this->withField), function ($query) use ($where, $realName, $fieldKey) {
if ($fieldKey !== 'store_name') {
$query->where(trim($fieldKey), trim($realName));
} else {
$query->whereLike('store_name', '%' . $realName . '%');
}
})->when($realName && !$fieldKey, function ($query) use ($where) {
$query->where(function ($que) use ($where) {
$que->whereLike('order_id|real_name|store_name', '%' . $where['real_name'] . '%')->whereOr('uid', 'in', function ($q) use ($where) {
$q->name('user')->whereLike('nickname|uid|phone', '%' . $where['real_name'] . '%')->field(['uid'])->select();
});
});
});
}
/**
* 订单搜索列表
* @param array $where
* @param array $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 getOrderList(array $where, array $field, int $page, int $limit, array $with = [])
{
return $this->search($where)->field($field)->with(array_merge(['user'], $with))->page($page, $limit)->order('add_time DESC,id DESC')->select()->toArray();
}
/**
* 根据条件获取订单列表
* @param array $where
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getIntegralOrderList(array $where)
{
return $this->search($where)->order('id asc')->select()->toArray();
}
/**
* 获取订单总数
* @param array $where
* @return int
*/
public function count(array $where = []): int
{
return $this->search($where)->count();
}
/**
* 查找指定条件下的订单数据以数组形式返回
* @param array $where
* @param string $field
* @param string $key
* @param string $group
* @return array
*/
public function column(array $where, string $field, string $key = '', string $group = '')
{
return $this->search($where)->when($group, function ($query) use ($group) {
$query->group($group);
})->column($field, $key);
}
/**
* 获取订单详情
* @param $uid
* @param $key
* @return array|\think\Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getUserOrderDetail(string $key, int $uid)
{
return $this->getOne(['order_id' => $key, 'uid' => $uid, 'is_del' => 0]);
}
/**
* 获取用户已购买此活动商品的个数
* @param $uid
* @param $productId
* @return int
*/
public function getBuyCount($uid, $productId): int
{
return $this->getModel()
->where('uid', $uid)
->where('is_del', 0)
->where('product_id', $productId)
->value('sum(total_num)') ?? 0;
}
}

View File

@ -0,0 +1,49 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\activity\integral;
use app\dao\BaseDao;
use app\model\activity\integral\StoreIntegralOrderStatus;
/**
* 积分订单状态
* Class StoreIntegralOrderStatusDao
* @package app\dao\activity\integral
*/
class StoreIntegralOrderStatusDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreIntegralOrderStatus::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 getStatusList(array $where, int $page, int $limit)
{
return $this->search($where)->page($page, $limit)->select()->toArray();
}
}

View File

@ -0,0 +1,124 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\activity\lottery;
use app\dao\BaseDao;
use app\model\activity\lottery\LuckLottery;
/**
* 抽奖活动
* Class LuckLotteryDao
* @package app\dao\activity\lottery
*/
class LuckLotteryDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return LuckLottery::class;
}
public function search(array $data = [])
{
return parent::search($data)->when(isset($data['id']) && $data['id'], function ($query) use ($data) {
$query->where('id', $data['id']);
})->when(isset($data['start']) && $data['start'] !== '', function ($query) use ($data) {
$time = time();
switch ($data['start']) {
case 0:
$query->where('start_time', '>', $time)->where('status', 1);
break;
case -1:
$query->where(function ($query1) use ($time) {
$query1->where('end_time', '<', $time)->whereOr('status', 0);
});
break;
case 1:
$query->where('status', 1)->where(function ($query1) use ($time) {
$query1->where(function ($query2) use ($time) {
$query2->where('start_time', '<=', $time)->where('end_time', '>=', $time);
})->whereOr(function ($query3) {
$query3->where('start_time', 0)->where('end_time', 0);
});
});
break;
}
});
}
/**
* 抽奖活动列表
* @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, 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();
}
/**
* 获取单个活动
* @param int $id
* @param string $field
* @param array|string[] $with
* @param bool $is_doing
* @return array|\think\Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getLottery(int $id, string $field = '*', array $with = ['prize'], bool $is_doing = false)
{
$where = ['id' => $id];
$where['is_del'] = 0;
if ($is_doing) $where['start'] = 1;
return $this->search($where)->field($field)->when($with, function ($query) use ($with) {
$query->with($with);
})->find();
}
/**
* 获取某个抽奖类型的一条抽奖数据
* @param int $factor
* @param string $field
* @param array|string[] $with
* @param bool $is_doing
* @return array|\think\Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getFactorLottery(int $factor = 1, string $field = '*', array $with = ['prize'], bool $is_doing = true)
{
$where = ['factor' => $factor, 'is_del' => 0];
if ($is_doing) $where['start'] = 1;
return $this->search($where)->field($field)->when($with, function ($query) use ($with) {
$query->with($with);
})->order('id desc')->find();
}
}

View File

@ -0,0 +1,69 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\activity\lottery;
use app\dao\BaseDao;
use app\model\activity\lottery\LuckLotteryRecord;
/**
* 中奖记录
* Class LuckLotteryRecordDao
* @package app\dao\activity\lottery
*/
class LuckLotteryRecordDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return LuckLotteryRecord::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, $field = '*', array $with = [], int $page = 0, int $limit = 10)
{
return $this->search($where)->when($with, function ($query) use ($with) {
$query->with($with);
})->field($field)->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order('add_time desc')->select()->toArray();
}
/**
* @param array $where
* @param string $group
* @return int
*/
public function getCount(array $where, string $group = '')
{
return parent::search($where)->when(isset($where['add_time']) && $where['add_time'], function ($query) use ($where) {
$query->where('add_time','>=', $where['add_time']);
})->when($group, function ($query) use ($group) {
$query->group($group);
})->count();
}
}

View File

@ -0,0 +1,88 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\activity\newcomer;
use app\dao\BaseDao;
use app\model\activity\newcomer\StoreNewcomer;
/**
* 新人礼商品
* Class StoreNewcomerDao
* @package app\dao\activity\newcomer
*/
class StoreNewcomerDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreNewcomer::class;
}
/**
* 搜索
* @param array $where
* @return \crmeb\basic\BaseModel|mixed|\think\Model
*/
protected function search(array $where = [])
{
return parent::search($where)->when(isset($where['storeProductId']), function ($query) {
$query->where('product_id', 'IN', function ($query) {
$query->name('store_product')->where('is_show', 1)->where('is_del', 0)->field('id');
});
});
}
/**
* 新人专享商品列表
* @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($page != 0 && $limit != 0, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->when($with, function ($query) use ($with) {
$query->with($with);
})->when(isset($where['priceOrder']) && $where['priceOrder'] != '', function ($query) use ($where) {
if ($where['priceOrder'] === 'desc') {
$query->order("price desc");
} else {
$query->order("price asc");
}
})->when(isset($where['salesOrder']) && $where['salesOrder'] != '', function ($query) use ($where) {
if ($where['salesOrder'] === 'desc') {
$query->order("sales desc");
} else {
$query->order("sales asc");
}
})->order('id desc')->select()->toArray();
}
}

View File

@ -0,0 +1,130 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\activity\promotions;
use app\dao\BaseDao;
use app\model\activity\promotions\StorePromotions;
use app\model\activity\promotions\StorePromotionsAuxiliary;
/**
* 优惠活动辅助表
*/
class StorePromotionsAuxiliaryDao extends BaseDao
{
/**
* @return string
*/
protected function setModel(): string
{
return StorePromotionsAuxiliary::class;
}
public function joinModel(): string
{
return StorePromotions::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, 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);
})->select()->toArray();
}
/**
* 关联模型
* @param string $alias
* @param string $join_alias
* @return \crmeb\basic\BaseModel
*/
public function getJoinModel(string $alias = 'a', string $join_alias = 'p', $join = 'left')
{
$this->alias = $alias;
$this->joinAlis = $join_alias;
/** @var StorePromotions $storePromotions */
$storePromotions = app()->make($this->joinModel());
$table = $storePromotions->getName();
return parent::getModel()->alias($alias)->join($table . ' ' . $join_alias, $alias . '.promotions_id = ' . $join_alias . '.id', $join);
}
/**
* 获取ids
* @param array $product_id
* @param int $product_partake_type
* @param string $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getProductsPromotionsIds(array $product_id, int $product_partake_type = 2, string $field = '')
{
$time = time();
return $this->getJoinModel()->field($field)
->where($this->joinAlis . '.type', 1)
->where($this->joinAlis . '.status', 1)
->where($this->joinAlis . '.is_del', 0)
->where($this->joinAlis . '.start_time', '<=', $time)
->where($this->joinAlis . '.stop_time', '>=', $time)
->where($this->alias . '.type', 1)
->when(in_array($product_partake_type, [2, 3]), function ($query) use ($product_partake_type, $product_id) {
if ($product_partake_type == 2) {
$query->where(function ($q) use ($product_id) {
$q->whereOr( $this->joinAlis.'.product_partake_type', 1)
->whereOr(function ($w) use ($product_id) {
$w->where($this->joinAlis.'.product_partake_type', 2)->where(function ($p) use ($product_id) {
if (is_array($product_id)) {
$p->whereIn($this->alias.'.product_id', $product_id);
} else {
$p->where($this->alias.'.product_id', $product_id);
}
});
})->whereOr(function ($e) use ($product_id) {
$e->where($this->joinAlis.'.product_partake_type', 3)->where($this->alias.'.is_all', 1)->where(function ($p) use ($product_id) {
if (is_array($product_id)) {
$p->whereNotIn($this->alias.'.product_id', $product_id);
} else {
$p->where($this->alias.'.product_id', '<>', $product_id);
}
});
});
});
} else {
$query->where($this->alias.'.product_partake_type', 3)->where($this->alias.'.is_all', 1)->where(function ($p) use ($product_id){
if(is_array($product_id)){
$p->whereNotIn($this->alias.'.product_id', $product_id);
}else{
$p->where($this->alias.'.product_id', $product_id);
}
});
}
})->select()->toArray();
}
}

View File

@ -0,0 +1,155 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\activity\promotions;
use app\dao\BaseDao;
use app\model\activity\promotions\StorePromotions;
/**
* 促销活动
* Class StorePromotionsDao
* @package app\dao\activity\promotions
*/
class StorePromotionsDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StorePromotions::class;
}
/**
* 搜索
* @param array $where
* @return \crmeb\basic\BaseModel|mixed|\think\Model
*/
protected function search(array $where = [])
{
return parent::search($where)->when(isset($where['promotionsTime']), function ($query) use ($where) {
[$startTime, $stopTime] = is_array($where['promotionsTime']) ? $where['promotionsTime'] : [time(), time()];
$query->where('start_time', '<=', $startTime)->where('stop_time', '>=', $stopTime);
})->when(isset($where['ids']) && $where['ids'], function($query) use($where) {
$query->whereIn('id', $where['ids']);
})->when(isset($where['not_ids']) && $where['not_ids'], function($query) use($where) {
$query->whereNotIn('id', $where['not_ids']);
})->when(isset($where['applicable_type']) && $where['applicable_type'], function($query) use($where) {
$query->whereIn('applicable_type', $where['applicable_type']);
})->when(isset($where['start_status']) && $where['start_status'] !== '', function ($query) use ($where) {
$time = time();
switch ($where['start_status']) {
case -1:
$query->where(function ($q) use ($time) {
$q->where('stop_time', '<', $time)->whereOr('status', '0');
});
break;
case 0:
$query->where('start_time', '>', $time)->where('status', 1);
break;
case 1:
$query->where('start_time', '<=', $time)->where('stop_time', '>=', $time)->where('status', 1);
break;
}
})->when(isset($where['product_id']) && $where['product_id'], function ($query) use ($where) {
$query->where(function ($q) use ($where) {
$q->whereOr('product_partake_type', 1)
->whereOr(function ($w) use ($where) {
$w->where('product_partake_type', 2)->whereIn('id', function ($a) use ($where) {
$a->name('store_promotions_auxiliary')->field('promotions_id')->where('type', 1)->where('product_partake_type', 2)->where(function ($p) use ($where) {
if(is_array($where['product_id'])){
$p->whereIn('product_id', $where['product_id']);
} else {
$p->where('product_id', $where['product_id']);
}
});
});
})->whereOr(function ($b) use ($where) {
$b->where('product_partake_type', 4)->whereIn('id', function ($a) use ($where) {
$a->name('store_promotions_auxiliary')->field('promotions_id')->where('type', 1)->where('product_partake_type', 2)->where(function ($p) use ($where) {
if(is_array($where['product_id'])){
$p->whereIn('product_id', $where['product_id']);
} else {
$p->where('product_id', $where['product_id']);
}
});
});
});
});
});
}
/**
* 获取促销活动列表
* @param array $where
* @param string $field
* @param int $page
* @param int $limit
* @param array $with
* @param string $order
* @param string $group
* @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 = [], string $order = 'update_time desc,id desc', string $group = '')
{
return $this->search($where)->field($field)
->when($page != 0 && $limit != 0, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->when($with, function ($query) use ($with) {
$query->with($with);
})->order($order)->when($group, function($query) use($group) {
$query->group($group);
})->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 validPromotions(int $id, string $field = '*')
{
$where = ['status' => 1, 'is_del' => 0];
$time = time();
return $this->search($where)
->where('id', $id)
->where('start_time', '<=', $time)
->where('stop_time', '>=', $time)
->field($field)->find();
}
/**
* 获取一个活动包含子集的所有ID
* @param int $id
* @return array
*/
public function getOnePromotionsIds(int $id)
{
$result = $this->getModel()->where('id|pid', $id)->column('id');
$res = [];
if ($result) {
$res = array_column($result, 'id');
}
return $res;
}
}

View File

@ -0,0 +1,218 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\activity\seckill;
use app\dao\BaseDao;
use app\model\activity\seckill\StoreSeckill;
/**
* 秒杀商品
* Class StoreSeckillDao
* @package app\dao\activity\seckill
*/
class StoreSeckillDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreSeckill::class;
}
/**
* 搜索
* @param array $where
* @return \crmeb\basic\BaseModel|mixed|\think\Model
*/
protected function search(array $where = [])
{
return parent::search($where)->when(isset($where['seckllTime']), function ($query) use ($where) {
[$startTime, $stopTime] = is_array($where['seckllTime']) ? $where['seckllTime'] : [time(), time() - 86400];
$query->where('start_time', '<=', $startTime)->where('stop_time', '>=', $stopTime);
})->when(isset($where['storeProductId']), function ($query) {
$query->where('product_id', 'IN', function ($query) {
$query->name('store_product')->where('is_show', 1)->where('is_del', 0)->field('id');
});
})->when(isset($where['start_status']) && $where['start_status'] !== '', function ($query) use ($where) {
$time = time();
switch ($where['start_status']) {
case -1:
$query->where(function ($q) use ($time) {
$q->where('stop_time', '<', $time - 86400)->whereOr('status', '0');
});
break;
case 0:
$query->where('start_time', '>', $time)->where('status', 1);
break;
case 1:
$query->where('start_time', '<=', $time)->where('stop_time', '>=', $time - 86400)->where('status', 1);
break;
}
});
}
/**
* 获取某个活动下的秒杀商品ids
* @param array $where
* @return array
*/
public function getActivitySeckillIds(array $where)
{
return $this->search($where)->column('id');
}
/**
* 获取秒杀列表
* @param array $where
* @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, int $page = 0, int $limit = 0, array $with = [])
{
return $this->search($where)
->when($with, function ($query) use ($with) {
$query->with($with);
})->when($page != 0 && $limit != 0, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order('sort desc,id desc')->select()->toArray();
}
/**
* 根据商品id获取当前正在开启秒杀产品的列表以数组返回
* @param array $ids
* @param array $field
* @return array
*/
public function getSeckillIdsArray(array $ids, array $field = [])
{
return $this->search(['is_del' => 0, 'status' => 1])
->where('start_time', '<=', time())
->where('stop_time', '>=', time() - 86400)
->whereIn('product_id', $ids)
->field($field)->select()->toArray();
}
/**
* 获取某个时间段的秒杀列表
* @param array $activity_id
* @param array $ids
* @param int $page
* @param int $limit
* @param bool $isStore
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getListByTime(array $activity_id, array $ids = [], int $page = 0, int $limit = 0, bool $isStore = false)
{
if ($activity_id == 0) return [];
return $this->search(['is_del' => 0, 'status' => 1])
->where('start_time', '<=', time())
->where('stop_time', '>=', time() - 86400)
->when($activity_id, function ($query) use ($activity_id) {
$query->whereIn('activity_id', $activity_id);
})->where('product_id', 'IN', function ($query) {
$query->name('store_product')->where('is_show', 1)->where('is_del', 0)->field('id');
})->when($ids, function($query) use($ids) {
$query->whereIn('product_id', $ids);
})->when($isStore, function($query) {
$query->where(function ($q) {
$q->whereOr(function ($c) {
$c->whereFindInSet('delivery_type', 2);
})->whereOr(function ($d) {
$d->whereFindInSet('delivery_type', 3);
});
});
})->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order('sort desc,id desc')->select()->toArray();
}
/**
* 获取正在开启的秒杀总数
* @param array $activity_id
* @param $ids
* @param $not_ids
* @param bool $isStore
* @return int
* @throws \think\db\exception\DbException
*/
public function getTimeCount(array $activity_id, $ids = [], $not_ids = [], bool $isStore = true)
{
if ($activity_id == 0) return 0;
return $this->search(['is_del' => 0, 'status' => 1])
->where('start_time', '<=', time())
->where('stop_time', '>=', time() - 86400)
->when($activity_id, function ($query) use ($activity_id) {
$query->whereIn('activity_id', $activity_id);
})->where('product_id', 'IN', function ($query) {
$query->name('store_product')->where('is_show', 1)->where('is_del', 0)->field('id');
})->when($ids, function($query) use($ids) {
$query->whereIn('product_id', $ids);
})->when($not_ids, function($query) use($not_ids) {
$query->whereNotIn('product_id', $not_ids);
})->when($isStore, function($query) {
$query->where(function ($q) {
$q->whereOr(function ($c) {
$c->whereFindInSet('delivery_type', 2);
})->whereOr(function ($d) {
$d->whereFindInSet('delivery_type', 3);
});
});
})->count();
}
/**
* 根据id获取秒杀数据
* @param array $ids
* @param string $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function idSeckillList(array $ids, string $field)
{
return $this->getModel()->whereIn('id', $ids)->field($field)->select()->toArray();
}
/**获取一条秒杀商品
* @param $id
* @param $field
* @return array|\think\Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function validProduct($id, $field)
{
$where = ['status' => 1, 'is_del' => 0];
$time = time();
return $this->search($where)
->where('id', $id)
->where('start_time', '<', $time)
->where('stop_time', '>', $time - 86400)
->field($field)->with(['product'])->find();
}
}

View File

@ -0,0 +1,119 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\activity\seckill;
use app\dao\BaseDao;
use app\common\model\store\StoreSeckillTime;
/**
* 秒杀时间
* Class StoreSeckillTimeDao
* @package app\dao\activity\seckill
*/
class StoreSeckillTimeDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreSeckillTime::class;
}
/**
* @param array $where
* @return \crmeb\basic\BaseModel|mixed|\think\Model
*/
public function search(array $where = [])
{
return parent::search($where)
->when(isset($where['start_time']) && $where['start_time'] !== '', function ($query) use ($where) {
$query->whereTime('start_time', '<=', intval($where['start_time']));
})
->when(isset($where['end_time']) && $where['end_time'] !== '', function ($query) use ($where) {
$query->whereTime('end_time', '>=', intval($where['end_time']));
});
}
/**
* 获取秒杀时间列表
* @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 = 'start_time asc,id desc')
{
return $this->search($where)->field($field)
->when($page != 0 && $limit != 0, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order($order)->select()->toArray();
}
/**
* 开始时间 在别的时间段中
* @param $time
* @param $id
* @return int
* @throws \think\db\exception\DbException
*/
public function valStartTime($time, $id)
{
return $this->getModel()
->when($id, function ($query) use ($id) {
$query->where('id', '<>', $id);
})->where('start_time', '<=', $time)->where('end_time', '>', $time)->count();
}
/**
* 结束时间在别的时间段中
* @param $time
* @param $id
* @return int
* @throws \think\db\exception\DbException
*/
public function valEndTime($time, $id)
{
return $this->getModel()
->when($id, function ($query) use ($id) {
$query->where('id', '<>', $id);
})->where('start_time', '<', $time)->where('end_time', '>=', $time)->count();
}
/**
* 时间段包含了别的时间段
* @param array $data
* @param $id
* @return int
* @throws \think\db\exception\DbException
*/
public function valAllTime(array $data, $id)
{
return $this->getModel()
->when($id, function ($query) use ($id) {
$query->where('id', '<>', $id);
})->where('start_time', '>', $data['start_time'])->where('end_time', '<=', $data['end_time'])->count();
}
}

View File

@ -0,0 +1,80 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\activity\table;
use app\dao\BaseDao;
use app\model\activity\table\TableQrcode;
/**
* 桌码
* Class TableQrcodeDao
* @package app\dao\activity\table
*/
class TableQrcodeDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return TableQrcode::class;
}
/**条件处理
* @param array $where
* @return \crmeb\basic\BaseModel|mixed|\think\Model
*/
public function search(array $where = [])
{
return parent::search($where)->when(isset($where['store_id']) && $where['store_id'], function ($query) use ($where) {
$query->where('store_id', $where['store_id']);
})->when(isset($where['cate_id']) && $where['cate_id'], function ($query) use ($where) {
$query->where('cate_id', $where['cate_id']);
})->when(isset($where['is_del']), function ($query) use ($where) {
$query->where('is_del', $where['is_del']);
});
}
/**获取桌码列表
* @param array $where
* @param int $storeId
* @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, int $page, int $limit,array $with)
{
return $this->search($where)->when(count($with), function ($query) use ($with) {
$query->with($with);
})->page($page,$limit)->order('add_time Asc')->select()->toArray();
}
/**获取座位信息
* @param array $where
* @param array $with
* @return array|\crmeb\basic\BaseModel|mixed|\think\Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getTableCodeOne(array $where, array $with)
{
return $this->getModel()->where($where)->when(count($with), function ($query) use ($with) {
$query->with($with);
})->find();
}
}

View File

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

51
app/dao/diy/DiyDao.php Normal file
View File

@ -0,0 +1,51 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\diy;
use app\dao\BaseDao;
use app\common\model\system\diy\Diy;
/**
*
* Class DiyDao
* @package app\dao\diy
*/
class DiyDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return Diy::class;
}
/**
* 获取DIY列表
* @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 getDiyList(array $where, int $page, int $limit, array $field = ['*'])
{
return $this->search($where)->field($field)->where('is_del', 0)->page($page, $limit)->order('status desc,id desc')->select()->toArray();
}
}

View File

@ -0,0 +1,51 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\message;
use app\dao\BaseDao;
use app\model\message\SystemMessage;
/**
* 站内信
* Class SystemMessageDao
* @package app\dao\message
*/
class SystemMessageDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return SystemMessage::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 getMessageList(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('add_time desc')->select()->toArray();
}
}

View File

@ -0,0 +1,36 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\message\service;
use app\dao\other\queue\QueueAuxiliaryDao;
/**
* 客服辅助表
* Class StoreServiceAuxiliaryDao
* @package app\dao\message\service
*/
class StoreServiceAuxiliaryDao extends QueueAuxiliaryDao
{
/**
* 搜索
* @param array $where
* @return \crmeb\basic\BaseModel|mixed|\think\Model
*/
protected function search(array $where = [])
{
return parent::search($where)->where('type', 0);
}
}

View File

@ -0,0 +1,85 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\message\service;
use app\dao\BaseDao;
use app\common\model\store\service\StoreService;
/**
* 客服dao
* Class StoreServiceDao
* @package app\dao\message\service
*/
class StoreServiceDao extends BaseDao
{
/**
* 不存在的用户直接禁止掉
* @param array $uids
* @return bool
*/
public function deleteNonExistentService(array $uids = [])
{
if ($uids) {
return $this->getModel()->whereIn('uid', $uids)->update(['status' => 0]);
} else {
return true;
}
}
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreService::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 getServiceList(array $where, int $page, int $limit)
{
return $this->search($where)->with('user')->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->when(isset($where['noId']), function ($query) use ($where) {
$query->whereNotIn('uid', $where['noId']);
})->with(['workMember' => function ($query) {
$query->field(['uid', 'name', 'position', 'qr_code', 'external_position']);
}])->order('id DESC')->field('id,uid,avatar,nickname as wx_name,status,add_time,phone,account_status')->select()->toArray();
}
/**
* 获取接受通知的客服
* @param int $customer
* @param string $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getStoreServiceOrderNotice(int $customer = 0, string $field = 'nickname,phone,uid,customer')
{
return $this->getModel()->where(['account_status' => 1, 'status' => 1, 'notify' => 1])->when($customer, function ($query) use ($customer) {
$query->where('customer', $customer);
})->field($field)->select()->toArray();
}
}

View File

@ -0,0 +1,142 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\message\service;
use app\dao\BaseDao;
use app\common\model\store\service\StoreServiceLog;
/**
*
* Class StoreServiceLogDao
* @package app\dao\service
*/
class StoreServiceLogDao extends BaseDao
{
/**
* StoreServiceLogDao constructor.
*/
public function __construct()
{
//清楚去年的聊天记录
// $this->removeChat();
$this->removeYesterDayChat();
}
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreServiceLog::class;
}
/**
* 获取聊天记录下的uid和to_uid
* @param int $uid
* @return mixed
*/
public function getServiceUserUids(int $uid)
{
return $this->search(['uid' => $uid])->group('uid,to_uid')->field(['uid', 'to_uid'])->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 getServiceList(array $where, int $page, int $limit, array $field = ['*'])
{
return $this->search($where)->with('user')->field($field)->order('add_time DESC')->page($page, $limit)->select()->toArray();
}
/**
* 获取聊天记录上翻页
* @param array $where
* @param int $limit
* @param int $upperId
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getChatList(array $where, int $limit = 20, int $upperId = 0)
{
return $this->search($where)->when($upperId, function ($query) use ($upperId, $limit) {
$query->where('id', '<', $upperId)->limit($limit)->order('id DESC');
})->when(!$upperId, function ($query) use ($limit) {
$query->limit($limit)->order('id DESC');
})->with(['user', 'service'])->select()->toArray();
}
/**
* 清楚去年的聊天记录
* @return bool
*/
public function removeChat()
{
return $this->search(['time' => 'last year'])->delete();
}
/**
* 清楚上周的游客用户聊天记录
* @return bool
*/
public function removeYesterDayChat()
{
return $this->search(['time' => 'last week', 'is_tourist' => 1])->delete();
}
/**
* 根据条件获取条数
* @param array $where
* @return int
*/
public function whereByCount(array $where)
{
return $this->search(['uid' => $where['uid']])->order('id DESC')->where('add_time', '<', time() - 300)->count();
}
/**
* 获取未读消息条数
* @param array $where
* @return int
*/
public function getMessageNum(array $where)
{
return $this->getModel()->where($where)->count();
}
/**
* 搜索聊天记录
* @param array $where
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getMessageList(array $where)
{
return $this->search(['chat' => $where['chat']])->when(isset($where['add_time']) && $where['add_time'], function ($query) use ($where) {
$query->where('add_time', '>', $where['add_time']);
})->select()->toArray();
}
}

View File

@ -0,0 +1,81 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\message\service;
use app\dao\BaseDao;
use app\model\message\service\StoreServiceRecord;
/**
* Class StoreServiceRecordDao
* @package app\dao\message\service
*/
class StoreServiceRecordDao extends BaseDao
{
/**
* StoreServiceRecordDao constructor.
*/
public function __construct()
{
$this->deleteWeekRecord();
}
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreServiceRecord::class;
}
/**
* 删除上周游客记录
*/
protected function deleteWeekRecord()
{
$this->search(['time' => 'last week', 'timeKey' => 'update_time', 'is_tourist' => 1])->delete();
}
/**
* 获取客服聊天用户列表
* @param array $where
* @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 getServiceList(array $where, int $page, int $limit, array $with = [])
{
return $this->search($where)->page($page, $limit)->when(count($with), function ($query) use ($with) {
$query->with($with);
})->order('update_time desc')->select()->toArray();
}
/**
* 查询最近和用户聊天的uid用户
* @param array $where
* @param string $key
* @return array|\think\Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getLatelyMsgUid(array $where, string $key)
{
return $this->search($where)->order('update_time DESC')->value($key);
}
}

View File

@ -0,0 +1,200 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\order;
use app\dao\BaseDao;
use app\model\order\OtherOrder;
class OtherOrderDao extends BaseDao
{
/** 设置模型
* @return string
*/
protected function setModel(): string
{
return OtherOrder::class;
}
/**
* 重写搜索器
* @param array $where
* @return \crmeb\basic\BaseModel|mixed|\think\Model
*/
public function search(array $where = [])
{
return parent::search($where)->when(isset($where['name']) && $where['name'], function ($query) use ($where) {
$query->where('uid', 'in', function ($que) use ($where) {
$que->name('user')->where('nickname|real_name|phone', 'like', '%' . trim($where['name']) . '%')->field(['uid'])->select();
});
});
}
/**
* 获取某个时间点一共有多少用户是付费会员状态
* @param $time
* @param string $channel_type
* @return int|mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getPayUserCount(int $time, string $channel_type = '')
{
return $this->getModel()->when($channel_type != '', function ($query) use ($channel_type) {
$query->where('channel_type', $channel_type);
})->field('distinct(uid),add_time')
->group('uid')->having('add_time < ' . $time)
->order('add_time desc')
->select()->toArray();
}
/**
* 获取VIP曲线
* @param $time
* @param $type
* @param $timeType
* @param string $str
* @return mixed
*/
public function getTrendData($time, $type, $timeType, $str = 'count(uid)')
{
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 array $where
* @param string $sumField
* @return float
*/
public function getWhereSumField(array $where, string $sumField)
{
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($sumField);
}
/**根据某字段分组查询
* @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 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();
}
/**收银订单
* @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 getScanOrderList(array $where = [], int $page = 0, int $limit = 0, string $order = '')
{
foreach ($where as $k => $v) {
if ($v == "") unset($where[$k]);
}
return $this->search($where)
->order(($order ? $order . ' ,' : '') . 'id desc')
->page($page, $limit)->select()->toArray();
}
/**
* 获取会员记录
* @param array $where
* @param string $field
* @param array|string[] $with
* @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 getMemberRecord(array $where = [], string $field = '*', array $with = ['user'], int $page = 0, int $limit = 0, string $order = '')
{
return $this->search($where)->field($field)
->when($with, function ($query) use ($with) {
$query->with($with);
})->order(($order ? $order . ' ,' : '') . 'id desc')
->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->select()->toArray();
}
/**
* 店员统计
* @param array $where
* @param string $countField
* @param string $sumField
* @param string $groupField
* @return mixed
*/
public function preStaffTotal(array $where, string $countField = 'uid', string $sumField = 'pay_price', string $groupField = 'staff_id')
{
return $this->search($where)
->field($groupField . ",count(" . $countField . ") as count,sum(`" . $sumField . "`) as price")
->group($groupField)
->select()->toArray();
}
}

View File

@ -0,0 +1,257 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\order;
use app\dao\BaseDao;
use app\model\order\StoreCart;
/**
*
* Class StoreCartDao
* @package app\dao\order
*/
class StoreCartDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreCart::class;
}
/**
* 搜索
* @param array $where
* @return \crmeb\basic\BaseModel|mixed|\think\Model
*/
public function search(array $where = [])
{
return parent::search($where)->when(isset($where['id']) && $where['id'], function ($query) use ($where) {
$query->whereIn('id', $where['id']);
})->when(isset($where['status']), function ($query) use ($where) {
$query->where('status', $where['status']);
});
}
/**
* @param array $where
* @param array $unique
* @return array
*/
public function getUserCartNums(array $where, array $unique)
{
return $this->search($where)->whereIn('product_attr_unique', $unique)->column('cart_num', 'product_attr_unique');
}
/**
* 获取挂单数据
* @param string $search
* @param int $storeId
* @param int $staffId
* @param int $page
* @param int $limit
* @return mixed
*/
public function getHangOrder(int $storeId, int $staffId = 0, string $search = '', int $page = 0, int $limit = 0)
{
return $this->getModel()->where([
'status' => 1,
'is_del' => 0,
'is_pay' => 0,
'is_new' => 0,
'store_id' => $storeId
])->when($staffId, function ($query) use ($staffId) {
$query->where('staff_id', $staffId);
})->when($search !== '', function ($query) use ($search) {
$query->whereIn('uid', function ($query) use ($search) {
$query->name('user')->where('uid|phone|nickname', 'like', "%" . $search . "%")->field('uid');
});
})->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->field(['tourist_uid', 'add_time', 'GROUP_CONCAT(id) as cart_id', 'store_id', 'staff_id', 'uid'])->with('user')
->group('uid,tourist_uid');
}
/**
* 根据商品id获取购物车数量
* @param array $ids
* @param int $uid
* @param int $staff_id
* @return mixed
*/
public function productIdByCartNum(array $ids, int $uid, int $staff_id = 0, int $touristUid = 0, int $storeId = 0)
{
return $this->search([
'product_id' => $ids,
'is_pay' => 0,
'is_del' => 0,
'is_new' => 0,
'tourist_uid' => $touristUid,
'uid' => $uid,
'store_id' => $storeId])->when($staff_id, function ($query) use ($staff_id) {
$query->where('staff_id', $staff_id);
})->group('product_attr_unique')->column('cart_num,product_id', 'product_attr_unique');
}
/**
* 获取购物车列表
* @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 getCartList(array $where, int $page = 0, int $limit = 0, array $with = [])
{
return $this->search($where)->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->when(count($with), function ($query) use ($with, $where) {
$query->with($with);
})->when(isset($where['is_cashier']), function ($query) use ($where) {
$query->where('is_cashier', $where['is_cashier']);
})->order('add_time DESC')->select()->toArray();
}
/**
* 修改购物车数据未已删除
* @param array $id
* @param array $data
* @return \crmeb\basic\BaseModel
*/
public function updateDel(array $id)
{
return $this->getModel()->whereIn('id', $id)->update(['is_del' => 1]);
}
/**
* 删除购物车
* @param int $uid
* @param array $ids
* @return bool
* @throws \Exception
*/
public function removeUserCart(int $uid, array $ids)
{
return $this->getModel()->where('uid', $uid)->whereIn('id', $ids)->delete();
}
/**
* 获取购物车数量
* @param $uid
* @param $type
* @param $numType
*/
public function getUserCartNum($uid, $type, $numType)
{
$model = $this->getModel()->where(['uid' => $uid, 'type' => $type, 'is_pay' => 0, 'is_new' => 0, 'is_del' => 0]);
if ($numType) {
return $model->count();
} else {
return $model->sum('cart_num');
}
}
/**
* 用户购物车统计数据
* @param int $uid
* @param string $field
* @param array $with
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getUserCartList(array $where, string $field = '*', array $with = [])
{
return $this->getModel()->where(array_merge($where, ['is_pay' => 0, 'is_new' => 0, 'is_del' => 0, 'type' => 0]))
->when(count($with), function ($query) use ($with) {
$query->with($with);
})->order('add_time DESC')->field($field)->select()->toArray();
}
/**
* 修改购物车数量
* @param $cartId
* @param $cartNum
* @param $uid
*/
public function changeUserCartNum(array $where, int $carNum)
{
return $this->getModel()->update(['cart_num' => $carNum], $where);
}
/**
* 修改购物车状态
* @param array $product_ids
* @param int $status
* @return \crmeb\basic\BaseModel
*/
public function changeStatus(array $product_ids, int $status = 0)
{
return $this->getModel()->where('product_id', 'IN', $product_ids)->update(['status' => $status]);
}
/**
* 删除购物车
* @param $cartIds
* @return bool
*/
public function deleteCartStatus($cartIds)
{
return $this->getModel()->where('id', 'IN', $cartIds)->delete();
}
/**
* 获取购物车最大的id
* @return mixed
*/
public function getCartIdMax()
{
return $this->getModel()->max('id');
}
/**
* 求和
* @param $where
* @param $field
* @return float
*/
public function getSum($where, $field)
{
return $this->search($where)->sum($field);
}
/**
* 购物车趋势
* @param $time
* @param $timeType
* @param $str
* @return mixed
*/
public function getProductTrend($time, $timeType, $str)
{
return $this->getModel()->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();
}
}

View File

@ -0,0 +1,57 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\order;
use app\dao\BaseDao;
use app\model\order\StoreDeliveryOrder;
/**
* 发货订单
* Class StoreDeliveryOrderDao
* @package app\dao\order
*/
class StoreDeliveryOrderDao extends BaseDao
{
/**
* @return string
*/
protected function setModel(): string
{
return StoreDeliveryOrder::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();
}
}

View File

@ -0,0 +1,106 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\order;
use app\dao\BaseDao;
use app\model\order\StoreOrderCartInfo;
/**
* 订单详情
* Class StoreOrderCartInfoDao
* @package app\dao\order
* @method saveAll(array $data)
*/
class StoreOrderCartInfoDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreOrderCartInfo::class;
}
/**
* 获取购物车详情列表
* @param array $where
* @param array $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getCartInfoList(array $where, array $field = ['*'])
{
return $this->search($where)->field($field)->select()->toArray();
}
/**
* 获取购物车信息以数组返回
* @param array $where
* @param string $field
* @param string $key
*/
public function getCartColunm(array $where, string $field, string $key = '')
{
return $this->search($where)->order('id asc')->column($field, $key);
}
/**
* @param $cart_ids
* @return array
*/
public function getSplitCartNum($cart_ids)
{
$res = $this->getModel()->whereIn('old_cart_id', $cart_ids)->field('sum(cart_num) as num,old_cart_id')->group('old_cart_id')->select()->toArray();
$data = [];
foreach ($res as $value) {
$data[$value['old_cart_id']] = $value['num'];
}
return $data;
}
/**临期 卡次
* @param int $writeEndTime
* @param int $writeTime
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getAdventCartInfoList(int $time = 0, int $writeTime = 0)
{
$list = $this->getModel()->where(['is_writeoff' => 0, 'is_advent_sms' => 0])->where('write_start', '>', 0)->where('write_end', '>', 0)
->where('write_end', '>', $time)->where('write_end', '<=', $writeTime)
->field('id,oid,product_id,write_times,write_surplus_times,write_start,write_end,cart_info')->select();
$list = count($list) > 0 ? $list->toArray() : [];
return $list;
}
/**过期 卡次
* @param int $writeTime
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getExpireCartInfoList(int $writeTime = 0)
{
$list = $this->getModel()->where(['is_writeoff' => 0, 'is_expire_sms' => 0])->where('write_start', '>', 0)->where('write_end', '>', 0)
->where('write_end', '<', $writeTime)
->field('id,oid,product_id,write_times,write_surplus_times,write_start,write_end,cart_info')->select();
$list = count($list) > 0 ? $list->toArray() : [];
return $list;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,191 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\order;
use app\dao\BaseDao;
use app\model\order\StoreOrderRefund;
/**
* 退款订单
* Class StoreOrderInvoiceDao
* @package app\dao\order
*/
class StoreOrderRefundDao extends BaseDao
{
protected function setModel(): string
{
return StoreOrderRefund::class;
}
/**
* 搜索器
* @param array $where
* @return \crmeb\basic\BaseModel|mixed|\think\Model
*/
public function search(array $where = [])
{
$realName = $where['real_name'] ?? '';
$fieldKey = $where['field_key'] ?? '';
$fieldKey = $fieldKey == 'all' ? '' : $fieldKey;
return parent::search($where)->when(isset($where['refund_type']) && $where['refund_type'] !== '', function ($query) use ($where) {
if ($where['refund_type'] == 0) {
$query->where('refund_type', '>', 0);
} else {
if (is_array($where['refund_type'])) {
$query->whereIn('refund_type', $where['refund_type']);
} else {
$query->where('refund_type', $where['refund_type']);
}
}
})->when(isset($where['order_id']) && $where['order_id'] != '', function ($query) use ($where) {
$query->where(function ($q) use ($where) {
$q->whereLike('order_id', '%' . $where['order_id'] . '%')->whereOr('store_order_id', 'IN', function ($orderModel) use ($where) {
$orderModel->name('store_order')->field('id')->whereLike('order_id|uid|user_phone|staff_id', '%' . $where['order_id'] . '%');
});
});
})->when($realName && !$fieldKey, function ($query) use ($where) {
$query->where(function ($que) use ($where) {
$que->whereLike('order_id', '%' . $where['real_name'] . '%')->whereOr(function ($q) use ($where) {
$q->whereOr('uid', 'in', function ($q) use ($where) {
$q->name('user')->whereLike('nickname|uid|phone', '%' . $where['real_name'] . '%')->field(['uid'])->select();
})->whereOr('store_order_id', 'in', function ($que) use ($where) {
$que->name('store_order_cart_info')->whereIn('product_id', function ($q) use ($where) {
$q->name('store_product')->whereLike('store_name|keyword', '%' . $where['real_name'] . '%')->field(['id'])->select();
})->field(['oid'])->select();
})->whereOr('store_order_id', 'in', function ($orderModel) use ($where) {
$orderModel->name('store_order')->field('id')->whereLike('order_id', '%' . $where['real_name'] . '%');
});
});
});
})->when(isset($where['refundTypes']) && $where['refundTypes'] != '', function ($query) use ($where) {
switch ((int)$where['refundTypes']) {
case 1:
$query->where('refund_type', 'in', '1,2');
break;
case 2:
$query->where('refund_type', 4);
break;
case 3:
$query->where('refund_type', 5);
break;
case 4:
$query->where('refund_type', 6);
break;
}
})->when(isset($where['supplier']) && $where['supplier'] !== '', function ($query) use ($where) {
$query->where('supplier_id', '>', 0);
});
}
/**
* 查询退款订单
* @param $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 getRefundList($where, string $file = '*', array $with = [], int $page = 0, int $limit = 0)
{
return $this->search($where)->field($file)->with(array_merge(['user'], $with))
->when($page != 0 && $limit != 0, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order('add_time desc')->select()->toArray();
}
/**
* 获取退款金额按照时间分组
* @param array $time
* @param string $timeType
* @param string $field
* @param string $str
* @return mixed
*/
public function getUserRefundPriceList(array $time, string $timeType, string $str, string $field = 'add_time')
{
return $this->getModel()->where('is_cancel', 0)->where(function ($query) use ($time, $field) {
if ($time[0] == $time[1]) {
$query->whereDay($field, $time[0]);
} else {
$time[1] = date('Y/m/d', strtotime($time[1]) + 86400);
$query->whereTime($field, 'between', $time);
}
})->field("FROM_UNIXTIME($field,'$timeType') as days,$str as num,GROUP_CONCAT(store_order_id) as link_ids")->group('days')->select()->toArray();
}
/**
* 根据时间获取
* @param array $where
* @return float|int
*/
public function getOrderRefundMoneyByWhere(array $where, string $sum_field, string $selectType, string $group = "")
{
switch ($selectType) {
case "sum" :
return $this->getDayTotalMoney($where, $sum_field);
case "group" :
return $this->getDayGroupMoney($where, $sum_field, $group);
}
}
/**
* 按照支付时间统计支付金额
* @param array $where
* @param string $sumField
* @return mixed
*/
public function getDayTotalMoney(array $where, string $sumField)
{
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($sumField);
}
/**
* 时间分组订单付款金额统计
* @param array $where
* @param string $sumField
* @return mixed
*/
public function getDayGroupMoney(array $where, string $sumField, string $group)
{
return $this->search($where)
->when(isset($where['timeKey']), function ($query) use ($where, $sumField, $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($sumField) 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,52 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\order;
use app\dao\BaseDao;
use app\common\model\store\order\StoreOrderStatus;
/**
* 订单状态
* Class StoreOrderStatusDao
* @package app\dao\order
*/
class StoreOrderStatusDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreOrderStatus::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 getStatusList(array $where, int $page = 0, int $limit = 0)
{
return $this->search($where)
->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order('change_time desc')->select()->toArray();
}
}

View File

@ -0,0 +1,41 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\other;
use app\dao\BaseDao;
use app\common\model\system\Cache;
/**
* Class CacheDao
* @package app\dao\other
*/
class CacheDao extends BaseDao
{
/**
* @return string
*/
public function setModel(): string
{
return Cache::class;
}
/**
* 清除过期缓存
* @throws \Exception
*/
public function delectDeOverdueDbCache()
{
$this->getModel()->where('expire_time', '<>', 0)->where('expire_time', '<', time())->delete();
}
}

View File

@ -0,0 +1,103 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\other;
use app\dao\BaseDao;
use app\model\other\Category;
/**
* 分类
* Class CategoryDao
* @package app\dao\other
*/
class CategoryDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return Category::class;
}
public function search(array $where = [])
{
return parent::search($where)->when(isset($where['name']) && $where['name'], function ($query) use ($where) {
$query->where(function ($q) use ($where) {
$q->whereOr('id|name', 'like', '%' . $where['name'] . '%')
->when(!empty($where['product_label']), function ($query) use ($where) {
$query->whereOr('id', 'IN', function ($l) use ($where) {
$l->name('store_product_label')->whereLike('id|label_name', '%' . $where['name'] . '%')->field('label_cate');
});
});
});
})->when(!empty($where['nowName']), function ($query) use ($where) {
$query->where('name', $where['nowName']);
});
}
/**
* 获取分类
* @param array $where
* @param int $page
* @param int $limit
* @param array|string[] $field
* @param array $with
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getCateList(array $where, int $page = 0, int $limit = 0, array $field = ['*'], array $with = [])
{
$other = false;
if (isset($where['other'])) {
$other = true;
unset($where['other']);
}
return $this->search($where)->field($field)->when(count($with), function ($query) use ($with) {
$query->with($with);
})->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->when($other, function ($query) {
$query->where('other', '<>', '');
})->order('sort DESC,id DESC')->select()->toArray();
}
/**
* 获取全部标签分类
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getAll(array $where = [], array $with = [])
{
return $this->search($where)->when(count($with), function ($query) use ($with) {
$query->with($with);
})->order('sort DESC,id DESC')->select()->toArray();
}
/**
* 添加修改选择上级分类列表
* @param array $where
* @param string $field
* @return array
*/
public function getMenus(array $where, string $field = 'id,pid,name')
{
return $this->search($where)->order('sort desc,id desc')->column($field);
}
}

View File

@ -0,0 +1,109 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\other;
use app\dao\BaseDao;
use app\common\model\store\CityArea;
/**
* Class CityAreaDao
* @package app\dao\other
*/
class CityAreaDao extends BaseDao
{
/**
* @return string
*/
protected function setModel(): string
{
return CityArea::class;
}
public function search(array $where = [])
{
return parent::search($where)->when(isset($where['pid']) && $where['pid'] !== '', function ($query) use ($where) {
$query->where('parent_id', $where['pid']);
})->when(isset($where['address']) && $where['address'] !== '', function ($query) use ($where) {
$address = explode('/', trim($where['address'], '/'));
if (isset($address[0]) && isset($address[1]) && $address[0] == $address[1]) {//直辖市:北京市北京市朝阳区
array_shift($address);
}
$p = array_shift($address);
if (mb_strlen($p) - 1 === mb_strpos($p, '市')) {
$p = mb_substr($p, 0, -1);
} elseif (mb_strlen($p) - 1 === mb_strpos($p, '省')) {
$p = mb_substr($p, 0, -1);
} elseif (mb_strlen($p) - 3 === mb_strpos($p, '自治区')) {
$p = mb_substr($p, 0, -3);
}
$pcity = $this->getModel()->where('name', $p)->value('id');
$path = ['', $pcity];
$street = $p;
$i = 0;
foreach ($address as $item) {
//县级市,只有三级地址;市和县相同
if ($item == ($address[$i-1] ?? '')) continue;
$pcity = $this->getModel()->whereLike('path', implode('/', $path) . '/%')->where('name', $item)->value('id');
if (!$pcity) {
break;
}
$path[] = $pcity;
$street = $item;
$i++;
}
array_pop($path);
$query->whereLike('path', implode('/', $path) . '/%')->where('name', $street);
});
}
/**
* 搜索某个地址
* @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 searchCity(array $where)
{
return $this->search($where)->order('id DESC')->find();
}
/**
* 获取地址
* @param array $where
* @param string $field
* @param array $with
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getCityList(array $where, string $field = '*', array $with = [])
{
return $this->getModel()->where($where)->field($field)->with($with)->order('id asc')->select()->toArray();
}
/**
* 删除上级城市和当前城市id
* @param int $cityId
* @return bool
* @throws \Exception
*/
public function deleteCity(int $cityId)
{
return $this->getModel()->where('id', $cityId)->whereOr('parent_id', $cityId)->delete();
}
}

View File

@ -0,0 +1,76 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\other;
use app\dao\BaseDao;
use app\common\model\store\shipping\Express;
/**
* 物流信息
* Class ExpressDao
* @package app\dao\other
*/
class ExpressDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return Express::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 getExpressList(array $where, string $field, int $page, int $limit)
{
return $this->search($where)->field($field)->order('sort DESC,id DESC')
->when($page > 0 && $limit > 0, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->select()->toArray();
}
/**
* 指定的条件获取物流信息以数组返回
* @param array $where
* @param string $field
* @param string $key
* @return array
*/
public function getExpress(array $where, string $field, string $key)
{
return $this->search($where)->order('id DESC')->column($field, $key);
}
/**
* 通过code获取一条信息
* @param string $code
* @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 getExpressByCode(string $code, string $field = '*')
{
return $this->getModel()->field($field)->where('code', $code)->find();
}
}

View File

@ -0,0 +1,59 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\other;
use app\dao\BaseDao;
use app\model\other\Qrcode;
/**
*
* Class QrcodeDao
* @package app\dao\other
*/
class QrcodeDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return Qrcode::class;
}
/**
* 获取一条二维码
* @param $id
* @param string $type
* @return array|\think\Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getQrcode($id, $type = 'id')
{
return $this->getModel()->where($type, $id)->find();
}
/**
* 修改二维码使用状态
* @param $id
* @param string $type
* @return mixed
*/
public function scanQrcode($id, $type = 'id')
{
return $this->getModel()->where($type, $id)->inc('scan')->update();
}
}

View File

@ -0,0 +1,90 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\other;
use app\dao\BaseDao;
use app\common\model\store\shipping\City as SystemCity;
/**
* 城市数据
* Class SystemCityDao
* @package app\dao\other
*/
class SystemCityDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return SystemCity::class;
}
/**
* 获取城市数据列表
* @param array $where
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getCityList(array $where, string $field = '*')
{
return $this->search($where)->field($field)->select()->toArray();
}
/**
* 获取城市数据以数组形式返回
* @param array $where
* @param string $field
* @param string $key
* @return array
*/
public function getCityArray(array $where, string $field, string $key)
{
return $this->search($where)->column($field, $key);
}
/**
* 删除上级城市和当前城市id
* @param int $cityId
* @return bool
* @throws \Exception
*/
public function deleteCity(int $cityId)
{
return $this->getModel()->where('city_id', $cityId)->whereOr('parent_id', $cityId)->delete();
}
/**
* 获取city_id的最大值
* @return mixed
*/
public function getCityIdMax()
{
return $this->getModel()->max('city_id');
}
/**
* 获取运费模板城市选择
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getShippingCity()
{
return $this->getModel()->with('children')->where('parent_id', 0)->order('id asc')->select()->toArray();
}
}

View File

@ -0,0 +1,108 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\other\queue;
use app\dao\BaseDao;
use app\model\other\queue\QueueAuxiliary;
/**
* 队列辅助
* Class QueueAuxiliaryDao
* @package app\dao\other\queue
*/
class QueueAuxiliaryDao extends BaseDao
{
/**
* @return string
*/
protected function setModel(): string
{
return QueueAuxiliary::class;
}
/**
* 添加订单缓存记录
* @param array $data
* @return int|string
*/
public function saveOrderCacheLog(array $data)
{
return $this->getModel()->insertGetId($data);
}
/**
* 获取发货缓存数据列表
* @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 getOrderExpreList(array $where, int $page = 0, int $limit = 0)
{
return $this->search($where)->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order('add_time asc')->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 getOrderCacheOne(array $where)
{
return $this->search($where)->find();
}
/**
* 获取发货记录
* @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 deliveryLogList(array $where, int $page = 0, int $limit = 0, string $order = '')
{
foreach ($where as $k => $v) {
if ($v == "") unset($where[$k]);
}
return $this->search($where)
->order(($order ? $order . ' ,' : '') . 'add_time desc')
->page($page, $limit)->select()->toArray();
}
/**
* 获取某个队列的数据缓存
* @param $bindingId
* @param $type
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getCacheOidList($bindingId, $type)
{
return $this->search(['binding_id' => $bindingId, 'type' => $type])->select()->toArray();
}
}

View File

@ -0,0 +1,128 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\other\queue;
use app\dao\BaseDao;
use app\model\other\queue\Queue;
/**
* 队列
* Class QueueDao
* @package app\dao\other
*/
class QueueDao extends BaseDao
{
/**
* @return string
*/
public function setModel(): string
{
return Queue::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 = '')
{
foreach ($where as $k => $v) {
if ($v == "") unset($where[$k]);
}
return $this->search($where)
->order(($order ? $order . ' ,' : '') . 'add_time desc')
->page($page, $limit)->select()->toArray();
}
/**
* 获取单个队列详情
* @param array $where
* @return array|bool|\think\Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getQueueOne(array $where)
{
if (!$where) return false;
return $this->search($where)->order('id desc')->find();
}
/**
* 加入队列数据表
* @param string $queueName
* @param int $queueDataNum
* @param int $type
* @param string $redisKey
* @param string $source
* @return mixed
*/
public function addQueueList(string $queueName, int $queueDataNum, int $type, string $redisKey, string $source = "admin")
{
$data = [
'type' => $type,
'source' => $source,
'execute_key' => $redisKey ? $redisKey : '',
'title' => $queueName,
'status' => 0,
'surplus_num' => $queueDataNum,
'total_num' => $queueDataNum,
'add_time' => time(),
];
return $this->getModel()->insertGetId($data);
}
/**
* 将队列置为正在执行状态
* @param $queueInValue
* @param $queueId
* @return bool|mixed
*/
public function setQueueDoing($queueInValue, $queueId, bool $is_again = false)
{
$saveData['queue_in_value'] = is_array($queueInValue) ? json_encode($queueInValue) : $queueInValue;
$saveData['status'] = 1;
if ($is_again) {
$saveData['again_time'] = time();
} else {
$saveData['first_time'] = time();
}
return $this->getModel()->update($saveData, ['id' => $queueId]);
}
/**
* 停止队列
* @param $queueId
* @return \crmeb\basic\BaseModel
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function stopWrongQueue($queueId)
{
$queueInfo = $this->getModel()->where(['id' => $queueId])->find();
if (!$queueInfo) return false;
return $this->getModel()->update(['id' => $queueId], ['status' => 3]);
}
}

View File

@ -0,0 +1,238 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\product\category;
use app\dao\BaseDao;
use app\model\product\category\StoreProductCategory;
/**
* Class StoreProductCategoryDao
* @package app\dao\product\product
*/
class StoreProductCategoryDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreProductCategory::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)->with('children')->when($page && $limit, function ($query) use($page, $limit) {
$query->page($page, $limit);
})->order('sort desc,id desc')->select()->toArray();
}
/**
*
* @param array $where
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getTierList(array $where = [], array $field = ['*'])
{
return $this->search($where)->field($field)->order('sort desc,id desc')->select()->toArray();
}
/**
* 添加修改选择上级分类列表
* @param array $where
* @return array
*/
public function getMenus(array $where)
{
return $this->search($where)->order('sort desc,id desc')->column('cate_name,id');
}
/**
* 根据id获取分类
* @param string $cateIds
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getCateArray(string $cateIds)
{
return $this->search(['id' => $cateIds])->field('cate_name,id')->select()->toArray();
}
/**
* 前端分类页面分离列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getCategory()
{
return $this->getModel()->with('children')->where('is_show', 1)->where('pid', 0)->order('sort desc,id desc')->hidden(['add_time', 'is_show', 'sort', 'children.sort', 'children.add_time', 'children.pid', 'children.is_show'])->select()->toArray();
}
/**
* 根据分类id获取上级id
* @param array $cateId
* @return array
*/
public function cateIdByPid(array $cateId)
{
return $this->getModel()->whereIn('id', $cateId)->column('pid');
}
/**
* 获取首页展示的二级分类 排序默认降序
* @param int $limit
* @param string $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function byIndexList($limit = 4, $field = 'id,cate_name,pid,pic')
{
return $this->getModel()->where('pid', '>', 0)->where('is_show', 1)->field($field)->order('sort DESC')->limit($limit)->select()->toArray();
}
/**
* 获取一级分类和二级分类组成的集合
* @param $cateId
* @return mixed
*/
public function getCateParentAndChildName(string $cateId)
{
return $this->getModel()->where('id', 'IN', $cateId)->field('cate_name as two,id,pid')
->with(['parentCate' => function ($query) {
$query->field('id,pid,cate_name')->bind(['one' => 'cate_name']);
}])->select()->toArray();
}
/**
* 按照个数获取一级分类下有商品的分类ID
* @param $page
* @param $limit
* @return array
*/
public function getCid($page, $limit)
{
return $this->getModel()
->where('is_show', 1)
->where('pid', 0)
->where('id', 'in', function ($query) {
$query->name('store_product_relation')->where('type', 1)->where('status', 1)->group('relation_pid')->field('relation_pid')->select()->toArray();
})
->page($page, $limit)
->order('sort DESC,id DESC')
->select()->toArray();
}
/**
* 按照个数获取一级分类下有商品的分类个数
* @param $page
* @param $limit
* @return int
*/
public function getCidCount()
{
return $this->getModel()
->where('is_show', 1)
->where('pid', 0)
->where('id', 'in', function ($query) {
$query->name('store_product_relation')->where('type', 1)->where('status', 1)->group('relation_pid')->field('relation_pid')->select()->toArray();
})
->count();
}
/**
* 通过分类id 获取(自己以及下级)的所有分类
* @param int $id
* @param string $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getAllById(int $id, string $field = 'id')
{
return $this->getModel()->where(function ($query) use ($id) {
$query->where(function ($q) use ($id) {
$q->where('id', $id)->whereOr('pid', $id);
});
})->where('is_show', 1)->field($field)->select()->toArray();
}
/**
* 通过分类ids 获取(自己以及下级)的所有分类
* @param int $ids
* @param string $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getAllByIds(array $ids, string $field = 'id')
{
return $this->getModel()->where(function ($query) use ($ids) {
$query->where(function ($q) use ($ids) {
$q->where('id', 'in', $ids)->whereOr('pid', 'in', $ids);
});
})->where('is_show', 1)->field($field)->select()->toArray();
}
/**
* 可以搜索的获取所有二级分类
* @param array $where
* @param string $field
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getALlByIndex(array $where, string $field = 'id,cate_name,pid,pic', $limit = 0)
{
$pid = $where['pid'] ?? -1;
return $this->getModel()->where('is_show', 1)->field($field)
->when(in_array($pid, [0, -1]), function ($query) use ($pid) {
switch ($pid) {
case -1://所有一级
$query->where('pid', 0);
break;
case 0://所有二级
$query->where('pid', '>', 0);
break;
}
})->when((int)$pid > 0, function ($query) use ($pid) {
$query->where('pid', $pid);
})->when(isset($where['name']) && $where['name'], function ($query) use ($where) {
$query->whereLike('id|cate_name', '%' . $where['name'] . '%');
})->when($limit > 0, function ($query) use ($limit) {
$query->limit($limit);
})->order('sort DESC')->select()->toArray();
}
}

View File

@ -0,0 +1,55 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\product\ensure;
use app\dao\BaseDao;
use app\model\product\ensure\StoreProductEnsure;
/**
* 商品保障服务
* Class StoreProductEnsureDao
* @package app\dao\product\label
*/
class StoreProductEnsureDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreProductEnsure::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)
->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order('sort desc,id desc')->select()->toArray();
}
}

View File

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

View File

@ -0,0 +1,53 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\product\label;
use app\dao\BaseDao;
use app\common\model\store\product\ProductLabel as StoreProductLabel;
/**
* Class StoreProductLabelDao
* @package app\dao\product\label
*/
class StoreProductLabelDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreProductLabel::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)
->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->select()->toArray();
}
}

View File

@ -0,0 +1,44 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\product\product;
use app\dao\BaseDao;
use app\model\product\product\StoreDescription;
/**
* Class StoreDescriptionDao
* @package app\dao\product\product
*/
class StoreDescriptionDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreDescription::class;
}
/**
* 根据条件获取商品详情
* @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 getDescription(array $where)
{
return $this->getOne($where);
}
}

View File

@ -0,0 +1,78 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\product\product;
use app\dao\BaseDao;
use app\model\product\product\StoreProductCategoryBrand;
use app\model\product\product\StoreProductRelation;
/**
* 商品关联关系dao
* Class StoreProductCategoryBrandDao
* @package app\dao\product\product
*/
class StoreProductCategoryBrandDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreProductCategoryBrand::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, 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);
})->select()->toArray();
}
/**
* 保存数据
* @param array $data
* @return mixed|void
*/
public function saveAll(array $data)
{
$this->getModel()->insertAll($data);
}
/**
* 设置
* @param array $ids
* @param int $is_show
* @param string $key
* @return \crmeb\basic\BaseModel
*/
public function setShow(array $ids, int $is_show = 1, string $key = 'product_id')
{
return $this->getModel()->whereIn($key, $ids)->update(['status' => $is_show]);
}
}

View File

@ -0,0 +1,476 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\product\product;
use app\dao\BaseDao;
use app\common\model\store\product\Product as StoreProduct;
use think\facade\Config;
/**
* Class StoreProductDao
* @package app\dao\product\product
*/
class StoreProductDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreProduct::class;
}
/**
* @param array $where
* @return \crmeb\basic\BaseModel|mixed|\think\Model
*/
public function search(array $where = [])
{
return parent::search($where)
->when(isset($where['collate_code_id']) && $where['collate_code_id'], function ($query) use ($where) {
$query->where('product_type', 0)->where('is_presale_product', 0)->where('system_form_id', 0);
})->when(isset($where['is_integral']) && $where['is_integral'], function ($query) use ($where) {
$query->where('product_type', 'in', [0, 1, 2, 3]);
})
->when(isset($where['store_name']) && $where['store_name'], function ($query) use ($where) {
if (isset($where['field_key']) && $where['field_key'] && in_array($where['field_key'], ['product_id', 'bar_code'])) {
if ($where['field_key'] == 'product_id') {
$query->where('id', trim($where['store_name']));
} else {
$query->where(function ($query) use ($where) {
$query->where('bar_code', trim($where['store_name']))->whereOr('id', 'IN', function ($q) use ($where) {
$q->name('store_product_attr_value')->field('product_id')->where('bar_code', trim($where['store_name']))->select();
});
});
}
} else {
$query->where(function ($q) use ($where) {
$q->where('id|store_name|bar_code|keyword', 'LIKE', '%' . trim($where['store_name']) . '%')->whereOr('id', 'IN', function ($q) use ($where) {
$q->name('store_product_attr_value')->field('product_id')->where('bar_code', trim($where['store_name']))->select();
});
});
}
})->when(isset($where['sid']) && $where['sid'], function ($query) use ($where) {
$query->whereIn('id', function ($query) use ($where) {
$query->name('store_product_relation')->where('type', 1)->where('relation_id', $where['sid'])->field('product_id')->select();
});
})->when(isset($where['cid']) && $where['cid'], function ($query) use ($where) {
$query->whereIn('id', function ($query) use ($where) {
$query->name('store_product_relation')->where('type', 1)->whereIn('relation_id', function ($query) use ($where) {
$query->name('store_product_category')->where('id|pid', $where['cid'])->field('id')->select();
})->field('product_id')->select();
});
})->when(isset($where['brand_id']) && $where['brand_id'], function ($query) use ($where) {
$query->whereIn('id', function ($query) use ($where) {
$query->name('store_product_relation')->where('type', 2)->whereIn('relation_id', $where['brand_id'])->field('product_id')->select();
});
})->when(isset($where['store_label_id']) && $where['store_label_id'], function ($query) use ($where) {
$query->whereIn('id', function ($query) use ($where) {
$query->name('store_product_relation')->where('type', 3)->whereIn('relation_id', $where['store_label_id'])->field('product_id')->select();
});
})->when(isset($where['is_live']) && $where['is_live'] == 1, function ($query) use ($where) {
$query->whereNotIn('id', function ($query) {
$query->name('live_goods')->where('is_del', 0)->where('audit_status', '<>', 3)->field('product_id')->select();
});
})->when(isset($where['is_supplier']) && in_array((int)$where['is_supplier'], [0, 1]), function ($query) use ($where) {
if ($where['is_supplier'] == 1) {//查询供应商商品
$query->where('type', 2);
} else {
$query->where('type', '<>', 2);
}
});
}
/**
* 条件获取数量
* @param array $where
* @return int
*/
public function getCount(array $where)
{
return $this->search($where)
->when(isset($where['unit_name']) && $where['unit_name'] !== '', function ($query) use ($where) {
$query->where('unit_name', $where['unit_name']);
})->when(isset($where['ids']) && $where['ids'], function ($query) use ($where) {
if (!isset($where['type'])) $query->where('id', 'in', $where['ids']);
})->when(isset($where['not_ids']) && $where['not_ids'], function ($query) use ($where) {
$query->whereNotIn('id', $where['not_ids']);
})->when(isset($where['pids']) && $where['pids'], function ($query) use ($where) {
if ((isset($where['priceOrder']) && $where['priceOrder'] != '') || (isset($where['salesOrder']) && $where['salesOrder'] != '')) {
$query->whereIn('pid', $where['pids']);
} else {
$query->whereIn('pid', $where['pids'])->orderField('pid', $where['pids'], 'asc');
}
})->when(isset($where['not_pids']) && $where['not_pids'], function ($query) use ($where) {
$query->whereNotIn('pid', $where['not_pids']);
})->count();
}
/**
* 获取商品列表
* @param array $where
* @param int $page
* @param int $limit
* @param string $order
* @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, int $page = 0, int $limit = 0, string $order = '', array $with = [])
{
$prefix = Config::get('database.connections.' . Config::get('database.default') . '.prefix');
return $this->search($where)->order(($order ? $order . ' ,' : '') . 'sort desc,id desc')
->when(count($with), function ($query) use ($with) {
$query->with($with);
})->when($page != 0 && $limit != 0, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->when(isset($where['store_id']) && $where['store_id'], function ($query) use ($where) {
$query->with(['storeBranchProduct' => function ($querys) use ($where) {
$querys->where('store_id', $where['store_id'])->bind([
'branch_sales' => 'sales',
'branch_stock' => 'stock',
'branch_is_show' => 'is_show'
]);
}]);
})->when(isset($where['ids']), function ($query) use ($where) {
$query->where('id', 'in', $where['ids']);
})->field([
'*',
'(SELECT count(*) FROM `' . $prefix . 'user_relation` WHERE `relation_id` = `' . $prefix . 'store_product`.`id` AND `category` = \'product\' AND `type` = \'collect\') as collect',
'(SELECT count(*) FROM `' . $prefix . 'user_relation` WHERE `relation_id` = `' . $prefix . 'store_product`.`id` AND `category` = \'product\' AND `type` = \'like\') as likes',
'(SELECT SUM(stock) FROM `' . $prefix . 'store_product_attr_value` WHERE `product_id` = `' . $prefix . 'store_product`.`id` AND `type` = 0) as stock',
// '(SELECT SUM(sales) FROM `' . $prefix . 'store_product_attr_value` WHERE `product_id` = `' . $prefix . 'store_product`.`id` AND `type` = 0) as sales',
'(SELECT count(*) FROM `' . $prefix . 'store_visit` WHERE `product_id` = `' . $prefix . 'store_product`.`id` AND `product_type` = \'product\') as visitor',
])->select()->toArray();
}
/**
* 获取商品详情
* @param int $id
* @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)
{
return $this->search()->with('coupons')->find($id);
}
/**
* 获取门店商品
* @param $where
* @return array|\think\Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getBranchProduct($where)
{
return $this->search($where)->find();
}
/**
* 条件获取商品列表
* @param array $where
* @param int $page
* @param int $limit
* @param array $field
* @param string $order
* @param array $with
* @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 = ['*'], string $order = '', array $with = ['couponId', 'descriptions'])
{
if (isset($where['star'])) $with[] = 'star';
return $this->search($where)->with($with)->when($page != 0 && $limit != 0, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->when(isset($where['ids']) && $where['ids'], function ($query) use ($where) {
if ((isset($where['priceOrder']) && $where['priceOrder'] != '') || (isset($where['salesOrder']) && $where['salesOrder'] != '')) {
$query->whereIn('id', $where['ids']);
} else {
$query->whereIn('id', $where['ids'])->orderField('id', $where['ids'], 'asc');
}
})->when(isset($where['not_ids']) && $where['not_ids'], function ($query) use ($where) {
$query->whereNotIn('id', $where['not_ids']);
})->when(isset($where['pids']) && $where['pids'], function ($query) use ($where) {
if ((isset($where['priceOrder']) && $where['priceOrder'] != '') || (isset($where['salesOrder']) && $where['salesOrder'] != '')) {
$query->whereIn('pid', $where['pids']);
} else {
$query->whereIn('pid', $where['pids'])->orderField('pid', $where['pids'], 'asc');
}
})->when(isset($where['not_pids']) && $where['not_pids'], function ($query) use ($where) {
$query->whereNotIn('pid', $where['not_pids']);
})->when(isset($where['priceOrder']) && $where['priceOrder'] != '', function ($query) use ($where) {
if ($where['priceOrder'] === 'desc') {
$query->order("price desc");
} else {
$query->order("price asc");
}
})->when(isset($where['salesOrder']) && $where['salesOrder'] != '', function ($query) use ($where) {
if ($where['salesOrder'] === 'desc') {
$query->order("sales desc");
} else {
$query->order("sales asc");
}
})->when(!isset($where['ids']), function ($query) use ($where, $order) {
if (isset($where['timeOrder']) && $where['timeOrder'] == 1) {
$query->order('id desc');
} else if ($order == 'rand') {
$query->orderRand();
} else if ($order) {
$query->orderRaw($order);
} else {
$query->order('sort desc,id desc');
}
})->when(isset($where['use_min_price']) && $where['use_min_price'], function ($query) use ($where) {
if (is_array($where['use_min_price']) && count($where['use_min_price']) == 2) {
$query->where('price', $where['use_min_price'][0] ?? '=', $where['use_min_price'][1] ?? 0);
}
})->when(!$page && $limit, function ($query) use ($limit) {
$query->limit($limit);
})->field($field)->select()->toArray();
}
/**商品列表
* @param array $where
* @param $limit
* @param $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getProductLimit(array $where, $limit, $field)
{
return $this->search($where)->field($field)->order('val', 'desc')->limit($limit)->select()->toArray();
}
/**
* 根据id获取商品数据
* @param array $ids
* @param string $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function idByProductList(array $ids, string $field)
{
return $this->getModel()->whereIn('id', $ids)->field($field)->select()->toArray();
}
/**
* 获取推荐商品
* @param array $where
* @param array $field
* @param int $num
* @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 getRecommendProduct(array $where, array $field = ['*'], int $num = 0, int $page = 0, int $limit = 0, array $with = ['couponId', 'star'])
{
return $this->search($where)->field($field)
->when(count($with), function ($query) use ($with) {
$query->with($with);
})->when($num, function ($query) use ($num) {
$query->limit($num);
})->when($page, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->when($limit, function ($query) use ($limit) {
$query->limit($limit);
})->order('sort DESC, 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 getProductCartList(array $where, int $page, int $limit, array $field = ['*'])
{
$where['is_verify'] = 1;
$where['is_show'] = 1;
$where['is_del'] = 0;
return $this->search($where)->when($page, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->field($field)->order('sort DESC,id DESC')->select()->toArray();
}
/**
* 获取用户购买热销榜单
* @param array $where
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getUserProductHotSale(array $where, int $limit = 20)
{
return $this->search($where)->field(['IFNULL(sales,0) + IFNULL(ficti,0) as sales', 'store_name', 'image', 'id', 'price', 'ot_price', 'stock'])->limit($limit)->order('sales desc')->select()->toArray();
}
/**
* 通过商品id获取商品分类
* @param array $productIds
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function productIdByCateId(array $productIds)
{
return $this->search(['id' => $productIds])->with('cateName')->field('id')->select()->toArray();
}
/**
* @param array $where
* @param $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getProductListByWhere(array $where, $field)
{
return $this->search($where)->field($field)->select()->toArray();
}
/**
* 搜索条件获取字段column
* @param array $where
* @param string $field
* @param string $key
* @return array
*/
public function getColumnList(array $where, string $field = 'brand_id', string $key = 'id')
{
return $this->search($where)
->when(isset($where['sid']) && $where['sid'], function ($query) use ($where) {
$query->whereIn('id', function ($query) use ($where) {
$query->name('store_product_relation')->where('type', 1)->where('relation_id', $where['sid'])->field('product_id')->select();
});
})->when(isset($where['cid']) && $where['cid'], function ($query) use ($where) {
$query->whereIn('id', function ($query) use ($where) {
$query->name('store_product_relation')->where('type', 1)->whereIn('relation_id', function ($query) use ($where) {
$query->name('store_product_category')->where('id|pid', $where['cid'])->field('id')->select();
})->field('product_id')->select();
});
})->when(isset($where['ids']) && $where['ids'], function ($query) use ($where) {
$query->whereIn('id', $where['ids']);
})->field($field)->column($field, $key);
}
/**
* 自动上下架
* @param int $is_show
* @return \crmeb\basic\BaseModel
*/
public function overUpperShelves($is_show = 0)
{
return $this->getModel()->where(['is_del' => 0])->where('is_verify', 1)
->when(in_array($is_show, [0, 1]), function ($query) use ($is_show) {
if ($is_show == 1) {
$query->where('is_show', 0)->where('auto_on_time', '<>', 0)->where('auto_on_time', '<=', time());
} else {
$query->where('is_show', 1)->where('auto_off_time', '<>', 0)->where('auto_off_time', '<', time());
}
})->update(['is_show' => $is_show]);
}
/**
* 获取预售列表
* @param array $where
* @param int $page
* @param int $limit
* @param string $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getPresaleList(array $where, int $page, int $limit, string $field = '*')
{
$model = $this->getModel()->field($field)
->where('is_presale_product', 1)->where('is_del', 0)->where('is_show', 1)
->where(function ($query) use ($where) {
switch ($where['time_type']) {
case 1:
$query->where('presale_start_time', '>', time());
break;
case 2:
$query->where('presale_start_time', '<=', time())->where('presale_end_time', '>=', time());
break;
case 3:
$query->where('presale_end_time', '<', time());
break;
}
if ($where['type']) $query->whereIn('type', $where['type']);
});
$count = $model->count();
$list = $model->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order('add_time desc')->select()->toArray();
return compact('list', 'count');
}
/**
* 获取使用某服务保障商品数量
* @param int $ensure_id
* @return int
*/
public function getUseEnsureCount(int $ensure_id)
{
return $this->getModel()->whereFindInSet('ensure_id', $ensure_id)->count();
}
/**
* 保存数据
* @param array $data
* @return mixed|\think\Collection
* @throws \Exception
*/
public function saveAll(array $data)
{
return $this->getModel()->saveAll($data);
}
/**
* 同步商品保存获取id
* @param $data
* @return int|string
*/
public function ErpProductSave($data)
{
return $this->getModel()->insertGetId($data);
}
}

View File

@ -0,0 +1,79 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\product\product;
use app\dao\BaseDao;
use app\model\product\product\StoreProductLog;
use think\facade\Config;
class StoreProductLogDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreProductLog::class;
}
public function getRanking($where)
{
// $prefix = Config::get('database.connections.' . Config::get('database.default') . '.prefix');
$sortField = $where['sort'] ?? 'visit';
return $this->search($where)->with('storeName')
->field([
'product_id',
'SUM(visit_num) as visit',
'COUNT(distinct(uid)) as user',
'SUM(cart_num) as cart',
'SUM(order_num) as orders',
'SUM(pay_num) as pay',
'SUM(pay_price * pay_num) as price',
'SUM(cost_price) as cost',
'ROUND((SUM(pay_price)-SUM(cost_price))/SUM(cost_price),2) as profit',
'SUM(collect_num) as collect',
'ROUND((COUNT(distinct(pay_uid))-1)/COUNT(distinct(uid)),2) as changes',
// '(select count(*) from (SELECT COUNT(`pay_uid`) as p,product_id FROM `' . $prefix . 'store_product_log` WHERE `product_id` = `' . $prefix . 'store_product_log`.`product_id` AND `type` = \'pay\' GROUP BY `pay_uid` HAVING p>1) u WHERE `product_id` = `' . $prefix . 'store_product_log`.`product_id`) as aaaa',
'COUNT(distinct(pay_uid))-1 as repeats'
//->having($sortField . ' > 0')
])->group('product_id')->order($sortField . ' desc')->limit(20)->select()->toArray();
}
public function getRepeats($where, $product_id)
{
return count($this->search($where)->where('type', 'pay')->where('product_id', $product_id)->field('count(pay_uid) as p')->group('pay_uid')->having('p>1')->select());
}
/**
* 列表
* @param array $where
* @param string $field
* @param int $page
* @param int $limit
* @param string $group
* @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 $group = '')
{
return $this->search($where)->with(['storeName'])->field($field)
->when($page != 0 && $limit != 0, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->when($group, function ($query) use ($group) {
$query->group($group);
})->order('add_time desc')->select()->toArray();
}
}

View File

@ -0,0 +1,105 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\product\product;
use app\dao\BaseDao;
use app\model\product\product\StoreProductRelation;
/**
* 商品关联关系dao
* Class StoreProductRelationDao
* @package app\dao\product\product
*/
class StoreProductRelationDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreProductRelation::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)
->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->select()->toArray();
}
/**
* 保存数据
* @param array $data
* @return mixed|void
*/
public function saveAll(array $data)
{
$this->getModel()->insertAll($data);
}
/**
* 根据商品id获取分类id
* @param array $productId
* @return array
*/
public function productIdByCateId(array $productId)
{
return $this->getModel()->whereIn('product_id', $productId)->where('type', 1)->column('relation_id');
}
/**
* 根据分类获取商品id
* @param array $cate_id
* @return array
*/
public function cateIdByProduct(array $cate_id)
{
return $this->getModel()->whereIn('relation_id', $cate_id)->where('type', 1)->column('product_id');
}
/**
* 设置
* @param array $ids
* @param int $is_show
* @param int $type
* @param string $key
* @return \crmeb\basic\BaseModel
*/
public function setShow(array $ids, int $is_show = 1, int $type = 1, string $key = 'product_id')
{
return $this->getModel()->whereIn($key, $ids)->where('type', $type)->update(['status' => $is_show]);
}
/**
* 根据条件获取商品ID 或者relation_id
* @param array $where
* @param string $field
* @return array
*/
public function getIdsByWhere(array $where, string $field = 'product_id')
{
return $this->search($where)->column($field);
}
}

View File

@ -0,0 +1,55 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\product\product;
use app\dao\BaseDao;
use app\model\product\product\StoreProductReplyComment;
use crmeb\traits\SearchDaoTrait;
/**
* Class StoreProductReplyCommentDao
* @package app\dao\product\product
*/
class StoreProductReplyCommentDao extends BaseDao
{
use SearchDaoTrait;
/**
* @return string
*/
protected function setModel(): string
{
return StoreProductReplyComment::class;
}
/**
* 更新点赞
* @param int $id
* @return mixed
*/
public function updatePraise(int $id)
{
return $this->getModel()->where('id', $id)->inc('praise', 1)->update();
}
/**
* 获取评论回复条数
* @param array $replyId
* @return mixed
*/
public function getReplyCommentCountList(array $replyId)
{
return $this->getModel()->whereIn('reply_id', $replyId)->where('pid', 0)->group('reply_id')->field(['reply_id', 'count(*) as sum'])->select()->toArray();
}
}

View File

@ -0,0 +1,124 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\product\product;
use app\dao\BaseDao;
use app\common\model\store\product\ProductReply as StoreProductReply;
/**
* Class StoreProductReplyDao
* @package app\dao\product\product
*/
class StoreProductReplyDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreProductReply::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 sysPage(array $where, int $page, int $limit)
{
return $this->search($where)->page($page, $limit)->select()->toArray();
}
/**
* 获取最近一条最好的评论
* @param int $productId
* @param string $field
* @param int $page
* @param $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getProductReply(int $productId, string $field = '*', int $page = 0, $limit = 0)
{
return $this->search(['product_id' => $productId, 'is_del' => 0])
->field($field)
->with(['cartInfo', 'userInfo'])
->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order('add_time DESC,product_score DESC,service_score DESC,add_time DESC')
->select()->toArray();
}
/**
* 评论条件
* @param int $id
* @param int $type
* @return \crmeb\basic\BaseModel|mixed|\think\Model
*/
public function replyWhere(int $id, int $type = 0)
{
return $this->search(['product_id' => $id, 'is_del' => 0])
->when($type == 1, function ($query) {
$query->where('product_score', 5)->where('service_score', 5);
})->when($type == 2, function ($query) {
$query->where(function ($query0) {
$query0->where(function ($query1) {
$query1->where('product_score', '<>', 5)->whereOr('service_score', '<>', 5);
})->where(function ($query2) {
$query2->where('service_score', '>', 2)->where('product_score', '>', 2);
});
});
})->when($type == 3, function ($query) {
$query->where(function ($query0) {
$query0->where('product_score', '<=', 2)->whereOr('service_score', '<=', 2);
});
});
}
/**
* 评论条数
* @param int $id
* @param int $type
* @return int
*/
public function replyCount(int $id, int $type = 0)
{
return $this->replyWhere($id, $type)->count();
}
/**
* 评论内容
* @param int $id
* @param int $type
* @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 replyList(int $id, int $type = 0, int $page = 0, int $limit = 0, array $with = ['cartInfo', 'userInfo'])
{
return $this->replyWhere($id, $type)->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->where('is_del', 0)->with($with)->order('add_time desc')->select()->toArray();
}
}

View File

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

View File

@ -0,0 +1,65 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\product\product;
use app\dao\BaseDao;
use app\model\product\product\StoreVisit;
/**
* Class StoreVisitDao
* @package app\dao\product\product
*/
class StoreVisitDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreVisit::class;
}
/**
*
* @param int $uid
* @return array
*/
public function getUserVisitProductId(int $uid)
{
return $this->getModel()->where('uid', $uid)->column('product_id');
}
public function getSum($where, $field)
{
return $this->search($where)->sum($field);
}
/**
* 商品趋势
* @param $time
* @param $timeType
* @param $str
* @return mixed
*/
public function getProductTrend($time, $timeType, $str)
{
return $this->getModel()->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();
}
}

View File

@ -0,0 +1,81 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\product\shipping;
use app\dao\BaseDao;
use app\model\product\shipping\ShippingTemplates;
/**
* 运费模版
* Class ShippingTemplatesDao
* @package app\dao\product\shipping
*/
class ShippingTemplatesDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return ShippingTemplates::class;
}
/**
* 获取选择模板列表
* @param array $where
* @return array
*/
public function getSelectList(array $where = [])
{
return $this->search($where)->order('sort DESC,id DESC')->column('id,name');
}
/**
* 获取
* @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 getShippingList(array $where, int $page, int $limit)
{
return $this->search($where)->order('sort DESC,id DESC')->page($page, $limit)->select()->toArray();
}
/**
* 插入数据返回主键id
* @param array $data
* @return int|string
*/
public function insertGetId(array $data)
{
return $this->getModel()->insertGetId($data);
}
/**
* 获取运费模板指定条件下的数据
* @param array $where
* @param string $field
* @param string $key
* @return array
*/
public function getShippingColumn(array $where, string $field, string $key)
{
return $this->search($where)->column($field, $key);
}
}

View File

@ -0,0 +1,124 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\product\shipping;
use app\dao\BaseDao;
use app\model\product\shipping\ShippingTemplatesFree;
/**
* 包邮
* Class ShippingTemplatesFreeDao
* @package app\dao\product\shipping
*/
class ShippingTemplatesFreeDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return ShippingTemplatesFree::class;
}
/**
* 获取运费模板列表并按照指定字段进行分组
* @param array $where
* @param string $group
* @param string $field
* @param string $key
* @return mixed
*/
public function getShippingGroupArray(array $where, string $group, string $field, string $key)
{
return $this->search($where)->group($group)->column($field, $key);
}
/**
* 获取列表
* @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 getShippingList(array $where, array $field = ['*'])
{
return $this->search($where)->field($field)->select()->toArray();
}
/**
* 获取运费模板列表
* @param array $where
* @param string $field
* @param string $key
* @return array
*/
public function getShippingArray(array $where, string $field, string $key)
{
return $this->search($where)->column($field, $key);
}
/**
* 是否可以满足包邮
* @param $tempId
* @param $cityid
* @param $number
* @param $price
* @param $type
* @return int
*/
public function isFree($tempId, $cityid, $number, $price, $type = 0)
{
return $this->getModel()->where('temp_id', $tempId)
->where('city_id', $cityid)
->when($type, function ($query) use ($type, $number) {
if ($type == 1) {//数量
$query->where('number', '<=', $number);
} else {//重量、体积
$query->where('number', '>=', $number);
}
})->where('price', '<=', $price)->count();
}
/**
* 是否包邮模版数据列表
* @param $tempId
* @param $cityid
* @param int $price
* @param string $field
* @param string $key
* @return array
*/
public function isFreeList($tempId, $cityid, $price = 0, string $field = '*', string $key = '')
{
return $this->getModel()
->when($cityid, function ($query) use ($cityid) {
if (is_array($cityid)) {
$query->whereIn('city_id', $cityid);
} else {
$query->where('city_id', $cityid);
}
})->when($tempId, function ($query) use ($tempId) {
if (is_array($tempId)) {
$query->whereIn('temp_id', $tempId);
} else {
$query->where('temp_id', $tempId);
}
})->when($price, function ($query) use ($price) {
$query->where('price', '<=', $price);
})->column($field, $key);
}
}

View File

@ -0,0 +1,99 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\product\shipping;
use app\dao\BaseDao;
use app\model\product\shipping\ShippingTemplatesNoDelivery;
/**
* 不送达
* Class ShippingTemplatesNoDeliveryDao
* @package app\dao\shipping
*/
class ShippingTemplatesNoDeliveryDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return ShippingTemplatesNoDelivery::class;
}
/**
* 获取运费模板列表并按照指定字段进行分组
* @param array $where
* @param string $group
* @param string $field
* @param string $key
* @return mixed
*/
public function getShippingGroupArray(array $where, string $group, string $field, string $key)
{
return $this->search($where)->group($group)->column($field, $key);
}
/**
* 获取列表
* @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 getShippingList(array $where, array $field = ['*'])
{
return $this->search($where)->field($field)->select()->toArray();
}
/**
* 获取运费模板列表
* @param array $where
* @param string $field
* @param string $key
* @return array
*/
public function getShippingArray(array $where, string $field, string $key)
{
return $this->search($where)->column($field, $key);
}
/**
* 是否不送达
* @param $tempId
* @param $cityid
* @param string $field
* @param string $key
* @return array
*/
public function isNoDelivery($tempId, $cityid, string $field = 'temp_id', string $key = '')
{
return $this->getModel()
->when($cityid, function ($query) use ($cityid) {
if (is_array($cityid)) {
$query->whereIn('city_id', $cityid);
} else {
$query->where('city_id', $cityid);
}
})->when($tempId, function ($query) use ($tempId) {
if (is_array($tempId)) {
$query->whereIn('temp_id', $tempId);
} else {
$query->where('temp_id', $tempId);
}
})->column($field, $key);
}
}

View File

@ -0,0 +1,85 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\product\shipping;
use app\dao\BaseDao;
use app\model\product\shipping\ShippingTemplatesRegion;
/**
* 指定邮费
* Class ShippingTemplatesRegionDao
* @package app\dao\product\shipping
*/
class ShippingTemplatesRegionDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return ShippingTemplatesRegion::class;
}
/**
* 获取运费模板列表并按照指定字段进行分组
* @param array $where
* @param string $group
* @param string $field
* @param string $key
* @return mixed
*/
public function getShippingGroupArray(array $where, string $group, string $field, string $key)
{
return $this->search($where)->group($group)->column($field, $key);
}
/**
* 获取运费模板列表
* @param array $where
* @param string $field
* @param string $key
* @return array
*/
public function getShippingArray(array $where, string $field, string $key)
{
return $this->search($where)->column($field, $key);
}
/**
* 根据运费模板id和城市id获得包邮数据列表
* @param array $tempIds
* @param array $cityId
* @param string $field
* @param string $key
* @return array
*/
public function getTempRegionList(array $tempIds, array $cityId, string $field = '*', string $key = '*')
{
return $this->getModel()->whereIn('temp_id', $tempIds)->whereIn('city_id', $cityId)->order('city_id asc')->column($field, $key);
}
/**
* 获取列表
* @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 getShippingList(array $where, array $field = ['*'])
{
return $this->search($where)->field($field)->select()->toArray();
}
}

View File

@ -0,0 +1,80 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\product\sku;
use app\dao\BaseDao;
use app\common\model\store\product\ProductAttr as StoreProductAttr;
/**
* Class StoreProductAttrDao
* @package app\dao\product\sku
*/
class StoreProductAttrDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreProductAttr::class;
}
/**
* 删除sku
* @param int $id
* @param int $type
* @return bool
* @throws \Exception
*/
public function del(int $id, int $type)
{
return $this->search(['product_id' => $id, 'type' => $type])->delete();
}
/**
* 保存sku
* @param array $data
* @return mixed|\think\Collection
* @throws \Exception
*/
public function saveAll(array $data)
{
return $this->getModel()->saveAll($data);
}
/**
* 获取商品sku
* @param array $where
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getProductAttr(array $where)
{
return $this->search($where)->select()->toArray();
}
/**
* 获取商品sku
* @param array $where
* @return \think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getProductValue(array $where)
{
return $this->search($where)->select();
}
}

View File

@ -0,0 +1,43 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\product\sku;
use app\dao\BaseDao;
use app\model\product\sku\StoreProductAttrResult;
/**
* Class StoreProductAttrResultDao
* @package app\dao\product\sku
*/
class StoreProductAttrResultDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreProductAttrResult::class;
}
/**
* 删除指定条件下的sku
* @param int $id
* @param int $type
* @return bool
* @throws \Exception
*/
public function del(int $id, int $type)
{
return $this->search(['product_id' => $id, 'type' => $type])->delete();
}
}

View File

@ -0,0 +1,316 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\product\sku;
use app\dao\BaseDao;
use app\model\product\sku\StoreProductAttrValue;
/**
* Class StoreProductAttrValueDao
* @package app\dao\product\sku
*/
class StoreProductAttrValueDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreProductAttrValue::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, $limit = 0)
{
return $this->search($where)->field($field)->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order('id asc')->select()->toArray();
}
/**
* 减库存
* @param array $where
* @param int $num
* @param string $stock
* @param string $sales
* @return bool|mixed
*/
public function decStockIncSales(array $where, int $num, string $stock = 'stock', string $sales = 'sales')
{
$isQuota = false;
if (isset($where['type']) && $where['type']) {
$isQuota = true;
if (count($where) == 2) {
unset($where['type']);
}
}
$field = $isQuota ? 'stock,quota' : 'stock';
$product = $this->getModel()->where($where)->field($field)->find();
if ($product) {
return $this->getModel()->where($where)->when($isQuota, function ($query) use ($num) {
$query->dec('quota', $num);
})->dec($stock, $num)->dec('sum_stock', $num)->inc($sales, $num)->update();
}
return true;
// return $this->getModel()->where($where)->dec($stock, $num)->inc($sales, $num)->dec('sum_stock', $num)->update();
}
/**
* 加库存
* @param array $where
* @param int $num
* @param string $stock
* @param string $sales
* @return bool|mixed
*/
public function incStockDecSales(array $where, int $num, string $stock = 'stock', string $sales = 'sales')
{
$isQuota = false;
if (isset($where['type']) && $where['type']) {
$isQuota = true;
if (count($where) == 2) {
unset($where['type']);
}
}
$salesOne = $this->getModel()->where($where)->value($sales);
if ($salesOne) {
$salesNum = $num;
if ($num > $salesOne) {
$salesNum = $salesOne;
}
return $this->getModel()->where($where)->when($isQuota, function ($query) use ($num) {
$query->inc('quota', $num);
})->inc($stock, $num)->inc('sum_stock', $num)->dec($sales, $salesNum)->update();
}
return true;
// $salesOne = $this->getModel()->where($where)->value($sales);
// if ($salesOne) {
// $salesNum = $num;
// if ($num > $salesOne) {
// $salesNum = $salesOne;
// }
// return $this->getModel()->where($where)->inc($stock, $num)->inc('sum_stock', $num)->dec($sales, $salesNum)->update();
// };
// return true;
}
/**
* 根据条件获取规格value
* @param array $where
* @param string $field
* @param string $key
* @param bool $search
* @return array
*/
public function getColumn(array $where, string $field = '*', string $key = 'suk', bool $search = false)
{
if ($search) {
return $this->search($where)
->when(isset($where['store_id']) && $where['store_id'], function ($query) use ($where) {
$query->with(['storeBranch' => function ($querys) use ($where) {
$querys->where(['store_id' => $where['store_id'], 'product_id' => $where['product_id']]);
}]);
})
->column($field, $key);
} else {
return $this->getModel()::where($where)
->when(isset($where['product_id']) && $where['product_id'], function ($query) use ($where, $field) {
if (is_array($where['product_id'])) {
$query->whereIn('product_id', $where['product_id']);
} else {
$query->where('product_id', $where['product_id']);
}
})
->column($field, $key);
}
}
/**
* 根据条件删除规格value
* @param int $id
* @param int $type
* @param array $suk
* @return bool
*/
public function del(int $id, int $type, array $suk = [])
{
return $this->search(['product_id' => $id, 'type' => $type, 'suk' => $suk])->delete();
}
/**
* 保存数据
* @param array $data
* @return mixed|\think\Collection
* @throws \Exception
*/
public function saveAll(array $data)
{
return $this->getModel()->saveAll($data);
}
/**
* 根据条件获取规格数据列表
* @param array $where
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getProductAttrValue(array $where)
{
return $this->search($where)->order('id asc')->select()->toArray();
}
/**
* 获取属性列表
* @return mixed
*/
public function attrValue()
{
return $this->search()->field('product_id,sum(sales * price) as val')->with(['product'])->group('product_id')->limit(20)->select()->toArray();
}
/**
* 获取属性库存
* @param string $unique
* @return int
*/
public function uniqueByStock(string $unique)
{
return $this->search(['unique' => $unique])->value('stock') ?: 0;
}
/**
* 减库存加销量减限购
* @param array $where
* @param int $num
* @return mixed
*/
public function decStockIncSalesDecQuota(array $where, int $num)
{
return $this->getModel()->where($where)->dec('stock', $num)->dec('quota', $num)->inc('sales', $num)->update();
}
/**
* 根据unique获取一条规格数据
* @param string $unique
* @param int $type
* @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 uniqueByField(string $unique, int $type = 0, string $field = '*', array $with = [])
{
return $this->search(['unique' => $unique, 'type' => $type])->field($field)->with($with)->find();
}
/**
* 根据商品id获取对应规格库存
* @param int $pid
* @param int $type
* @return float
*/
public function pidBuStock(int $pid, $type = 0)
{
return $this->getModel()->where(['product_id' => $pid, 'type' => $type])->sum('stock');
}
/**
* 获取门店规格
* @param array $where
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function storeBranchAttr(array $where)
{
return $this->search($where)
->when(isset($where['store_id']) && $where['store_id'], function ($query) use ($where) {
$query->with(['storeBranch' => function ($querys) use ($where) {
$querys->where('store_id', $where['store_id']);
}]);
})->select()->toArray();
}
/**
* 根据条形码获取一条商品规格信息
* @param string $bar_code
* @return array|\think\Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getAttrByBarCode(string $bar_code)
{
return $this->getModel()->where('bar_code', $bar_code)->order('id desc')->find();
}
/**
* 根据规格信息获取商品库存
* @param array $ids
* @return array|\think\Model|null
*/
public function getProductStockByValues(array $ids)
{
return $this->getModel()->whereIn('product_id', $ids)->where('type', 0)
->field('`product_id` AS `id`, SUM(`stock`) AS `stock`')->group("product_id")->select()->toArray();
}
/**
* 分组查询
* @param string $file
* @param string $group_id
* @param array $where
* @param string $having
* @return mixed
*/
public function getGroupData(string $file, string $group_id, array $where, string $having = '')
{
return $this->getModel()->when($where, function ($query) use ($where) {
$query->where($where);
})->field($file)->group($group_id)->when($having, function ($query) use ($having) {
$query->having($having);
})->select();
}
/**
* 库存警戒查询
* @author 等风来
* @email 136327134@qq.com
* @date 2023/4/18
* @param array $where
* @return int
* @throws \think\db\exception\DbException
*/
public function getPolice(array $where)
{
return $this->getModel()->when($where, function ($query) use ($where) {
$query->where($where);
})->count();
}
}

View File

@ -0,0 +1,74 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\product\sku;
use app\dao\BaseDao;
use app\model\product\sku\StoreProductRule;
/**
* Class StoreProductRuleDao
* @package app\dao\product\sku
*/
class StoreProductRuleDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreProductRule::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 getList(array $where = [], int $page = 0, int $limit = 0)
{
return $this->search($where)
->when($page != 0 && $limit != 0, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order('id desc')->select()->toArray();
}
/**
* 删除数据
* @param string $ids
* @throws \Exception
*/
public function del(string $ids)
{
return $this->getModel()->whereIn('id', $ids)->delete();
}
/**
* @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 getProductRuleList(array $where, $field = "*"): array
{
return $this->search($where)->field($field)->select()->toArray();
}
}

View File

@ -0,0 +1,41 @@
<?php
namespace app\dao\product\sku;
use app\dao\BaseDao;
use app\model\product\sku\StoreProductVirtual;
class StoreProductVirtualDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreProductVirtual::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)
->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->when(!$page && $limit, function ($query) use ($limit) {
$query->limit($limit);
})->order('id asc')->select()->toArray();
}
}

View File

@ -0,0 +1,55 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\product\specs;
use app\dao\BaseDao;
use app\model\product\specs\StoreProductSpecs;
/**
* 商品参数
* Class StoreProductSpecsDao
* @package app\dao\product\specs
*/
class StoreProductSpecsDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreProductSpecs::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)
->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order('sort desc,id desc')->select()->toArray();
}
}

View File

@ -0,0 +1,69 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\store;
use app\dao\BaseDao;
use app\model\store\DeliveryService;
/**
* 配送dao
* Class DeliveryServiceDao
* @package app\dao\store
*/
class DeliveryServiceDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return DeliveryService::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 getServiceList(array $where, int $page = 0, int $limit = 0)
{
$realName = $where['keyword'] ?? '';
$fieldKey = $where['field_key'] ?? '';
$fieldKey = $fieldKey == 'all' ? '' : $fieldKey;
return $this->search($where)->with('user')->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->when($realName && $fieldKey && in_array($fieldKey, ['id', 'phone']), function ($query) use ($where, $realName, $fieldKey) {
$query->whereLike($fieldKey, '%' . $where['keyword'] . '%');
})->when($realName && !$fieldKey, function ($query) use ($where) {
$query->whereLike('uid|id|nickname|phone', '%' . $where['keyword'] . '%');
})->when(isset($where['noId']), function ($query) use ($where) {
$query->where('id', '<>', $where['noId']);
})->order('id DESC')->field('id,uid,avatar,nickname as wx_name,status,add_time,phone')->select()->toArray();
}
/**
* 获取配送员select
* @param array $where
* @return array
*/
public function getSelectList(array $where)
{
return $this->search($where)->field('uid,nickname')->select()->toArray();
}
}

View File

@ -0,0 +1,48 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\store;
use app\dao\BaseDao;
use app\model\store\StoreConfig;
//use crmeb\traits\SearchDaoTrait;
/**
* Class StoreConfigDao
* @package app\dao\store
*/
class StoreConfigDao extends BaseDao
{
// use SearchDaoTrait;
/**
* @return string
*/
protected function setModel(): string
{
return StoreConfig::class;
}
/**
* 获取门店配置
* @param array $keys
* @param int $type
* @param int $relation_id
* @return \crmeb\basic\BaseModel|mixed|\think\Model
*/
public function searchs(array $keys, int $type = 0, int $relation_id = 0)
{
return parent::search()->whereIn('key_name', $keys)->where('type', $type)->where('relation_id', $relation_id);
}
}

View File

@ -0,0 +1,98 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\store;
use app\dao\BaseDao;
use app\model\store\StoreUser;
/**
* 门店用户
* Class StoreUserDao
* @package app\dao\store
*/
class StoreUserDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreUser::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, int $limit = 0): array
{
return $this->search($where)->field($field)->when($with, function ($query) use ($with) {
$query->with(['label']);
})->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->select()->toArray();
}
/**
* 获取一段时间内新增人数
* @param array $where
* @param array $time
* @param string $timeType
* @param string $countField
* @param string $sumField
* @param string $groupField
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function userTimeList(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 "week" :
$timeUnix = "%w";
break;
case "month" :
$timeUnix = "%d";
break;
case "weekly" :
$timeUnix = "%W";
break;
case "year" :
$timeUnix = "%Y-%m";
break;
default:
$timeUnix = "%m-%d";
break;
}
$query->field("FROM_UNIXTIME(`" . $groupField . "`,'$timeUnix') as day,count(" . $countField . ") as count");
$query->group('day');
})->order('add_time asc')->select()->toArray();
}
}

View File

@ -0,0 +1,212 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\store;
use app\dao\BaseDao;
use app\model\store\SystemStore;
/**
* 门店dao
* Class SystemStoreDao
* @package app\dao\system\store
*/
class SystemStoreDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return SystemStore::class;
}
/**
* @param array $where
* @return \crmeb\basic\BaseModel|mixed|\think\Model
*/
public function search(array $where = [])
{
return parent::search($where)->when(isset($where['ids']) && $where['ids'], function ($query) use ($where) {
$query->whereIn('id', $where['ids']);
})->when(isset($where['province']) && $where['province'], function ($query) use ($where) {
$query->where('province', $where['province']);
})->when(isset($where['city']) && $where['city'], function ($query) use ($where) {
$query->where('city', $where['city']);
})->when(isset($where['area']) && $where['area'], function ($query) use ($where) {
$query->where('area', $where['area']);
})->when(isset($where['street']) && $where['street'], function ($query) use ($where) {
$query->where('street', $where['street']);
});
}
/**
* 经纬度排序计算
* @param string $latitude
* @param string $longitude
* @return string
*/
public function distance(string $latitude, string $longitude, bool $type = false)
{
if ($type) {
return "(round(6378137 * 2 * asin(sqrt(pow(sin(((latitude * pi()) / 180 - ({$latitude} * pi()) / 180) / 2), 2) + cos(({$latitude} * pi()) / 180) * cos((latitude * pi()) / 180) * pow(sin(((longitude * pi()) / 180 - ({$longitude} * pi()) / 180) / 2), 2)))))";
} else {
return "(round(6378137 * 2 * asin(sqrt(pow(sin(((latitude * pi()) / 180 - ({$latitude} * pi()) / 180) / 2), 2) + cos(({$latitude} * pi()) / 180) * cos((latitude * pi()) / 180) * pow(sin(((longitude * pi()) / 180 - ({$longitude} * pi()) / 180) / 2), 2))))) AS distance";
}
}
/**
* 获取列表
* @param array $where
* @param array $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, array $field = ['*'], int $page = 0, int $limit = 0)
{
return $this->search($where)->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order('id desc')->field($field)->select()->toArray();
}
/**
* 获取
* @param array $where
* @param array $field
* @param int $page
* @param int $limit
* @param string $latitude
* @param string $longitude
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getStoreList(array $where, array $field = ['*'], int $page = 0, int $limit = 0, array $with = [], string $latitude = '', string $longitude = '', int $order = 0)
{
return $this->search($where)->when($with, function ($query) use ($with) {
$query->with($with);
})->when($latitude && $longitude, function ($query) use ($longitude, $latitude, $order) {
$query->field(['*', $this->distance($latitude, $longitude)]);
})->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->when(isset($order), function ($query) use ($order) {
if ($order == 1) {
$query->order('distance ASC');
} else {
$query->order('id desc');
}
})->field($field)->select()->toArray();
}
/**
* 获取有效门店
* @param array $where
* @return \crmeb\basic\BaseModel|mixed|\think\Model
*/
public function getValidSerch(array $where = [])
{
$validWhere = [
'is_show' => 1,
'is_del' => 0,
];
return $this->search($where)->where($validWhere);
}
/**
* 获取最近距离距离内的一个门店
* @param string $latitude
* @param string $longitude
* @return array|\think\Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getDistanceShortStore(string $latitude = '', string $longitude = '')
{
return $this->getValidSerch()->when($longitude && $longitude, function ($query) use ($longitude, $latitude) {
$query->field(['*', $this->distance($latitude, $longitude)])->order('distance ASC');
})->order('id desc')->find();
}
/**
* 距离排序符合配送范围门店
* @param string $latitude
* @param string $longitude
* @param string $field
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getDistanceShortStoreList(string $latitude = '', string $longitude = '', string $field = '*', int $limit = 0)
{
return $this->getValidSerch()->field($field)->when($longitude && $longitude, function ($query) use ($longitude, $latitude, $field) {
$query->field([$field, $this->distance($latitude, $longitude)])->where('valid_range', 'EXP', '>' . $this->distance($latitude, $longitude, true))->order('distance ASC');
})->when($limit, function ($query) use ($limit) {
$query->limit($limit);
})->order('id desc')->select()->toArray();
}
/**
* 根据地址区、街道信息获取门店列表
* @param string $addressInfo
* @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 getStoreByAddressInfo(string $addressInfo = '', array $where = [], string $field = '*', int $page = 0, int $limit = 0)
{
return $this->getValidSerch($where)->field($field)->when($addressInfo, function ($query) use ($addressInfo) {
$query->whereLike('address', '%' . $addressInfo . '%');
})->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->when(!$page && $limit, function ($query) use ($limit) {
$query->limit($limit);
})->order('id desc')->select()->toArray();
}
/**
* 获取门店不分页
* @param array $where
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getStore(array $where)
{
return $this->search($where)->order('add_time DESC')->field(['id', 'name'])->select()->toArray();
}
/**
* 获取ERP店铺
* @param array $where
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getErpStore(array $where, array $field = ['id','name','erp_shop_id'])
{
return $this->search(['type' => 0])->where($where)->field($field)->select()->toArray();
}
}

View File

@ -0,0 +1,123 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\store;
use app\dao\BaseDao;
use app\model\store\SystemStoreStaff;
/**
* 门店店员
* Class SystemStoreStaffDao
* @package app\dao\system\store
*/
class SystemStoreStaffDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return SystemStoreStaff::class;
}
/**
* @return \crmeb\basic\BaseModel
*/
public function getWhere()
{
return $this->getModel();
}
/**
* 门店店员搜索器
* @param array $where
* @return \crmeb\basic\BaseModel|mixed|\think\Model
*/
public function search(array $where = [])
{
return parent::search($where)->when(isset($where['keyword']) && $where['keyword'], function ($query) use ($where) {
if (!isset($where['field_key']) || $where['field_key'] == '') {
$query->whereLike('id|uid|staff_name|phone', '%' . $where['keyword'] . '%');
} else {
$query->where($where['field_key'], $where['keyword']);
}
});
}
/**
* 获取门店管理员列表
* @param array $where
* @param int $page
* @param int $limit
* @param array|string[] $with
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getStoreAdminList(array $where, int $page = 0, int $limit = 0, array $with = ['user'])
{
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);
})->order('add_time DESC')->select()->toArray();
}
/**
* 获取店员列表
* @param array $where
* @param string $field
* @param int $page
* @param int $limit
* @param array|string[] $with
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getStoreStaffList(array $where, string $field = '*', int $page = 0, int $limit = 0, array $with = ['store', 'user'])
{
return $this->search($where)->field($field)->when($with, function ($query) use ($with) {
$query->with(array_merge($with, ['store', 'user']));
})->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->when(isset($where['notId']), function ($query) use ($where) {
$query->where('id', '<>', $where['notId']);
})->when(isset($where['store_id']), function ($query) use ($where) {
$query->where('store_id', $where['store_id']);
})->order('add_time DESC')->select()->toArray();
}
/**
* 获取店员select
* @param array $where
* @return array
*/
public function getSelectList(array $where)
{
return $this->search($where)->field('id,staff_name')->select()->toArray();
}
/**
* 用户注销删除门店店员
* @param int $uid
* @return \crmeb\basic\BaseModel
*/
public function cancelUserDel(int $uid)
{
return $this->getModel()->where('uid', $uid)->where('level', '>', 0)->update(['is_del' => 1]);
}
}

View File

@ -0,0 +1,181 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\store\finance;
use app\dao\BaseDao;
use app\model\store\finance\StoreFinanceFlow;
/**
* 门店流水
* Class StoreExtractDao
* @package app\dao\store\finance
*/
class StoreFinanceFlowDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreFinanceFlow::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, array $with = [])
{
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();
}
/**
*
* @param array $where
* @return \crmeb\basic\BaseModel|int|mixed|\think\Model
*/
public function getCount(array $where = [])
{
return $this->search($where)->count();
}
/**
* 搜索
* @param array $where
* @return \crmeb\basic\BaseModel|mixed|\think\Model
*/
public function search(array $where = [])
{
return parent::search($where)
->when(isset($where['keyword']) && $where['keyword'] !== '', function ($query) use ($where) {
$query->where(function ($que) use ($where) {
$que->whereLike('order_id', '%' . $where['keyword'] . '%')->whereOr('uid', 'in', function ($q) use ($where) {
$q->name('user')->whereLike('nickname|uid', '%' . $where['keyword'] . '%')->field(['uid'])->select();
});
});
});
}
/**
* 门店账单
* @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 getFundRecord(array $where = [], int $page = 0, int $limit = 0)
{
$model = parent::search($where)
->when(isset($where['timeType']) && $where['timeType'] !== '', function ($query) use ($where) {
$timeUnix = '%Y-%m-%d';
switch ($where['timeType']) {
case "day" :
$timeUnix = "%Y-%m-%d";
break;
case "week" :
$timeUnix = "%Y-%u";
break;
case "month" :
$timeUnix = "%Y-%m";
break;
}
$query->field("FROM_UNIXTIME(add_time,'$timeUnix') as day,sum(if(pm = 1,number,0)) as income_num,sum(if(pm = 0,number,0)) as exp_num,add_time,group_concat(id) as ids");
$query->group("FROM_UNIXTIME(add_time, '$timeUnix')");
});
$count = $model->count();
$list = $model->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order('add_time desc')->select()->toArray();
return compact('list', 'count');
}
/**
* 店员交易统计头部数据
* @param array $where
* @param string $group
* @param string $field
* @return mixed
*/
public function getStatisticsHeader(array $where = [], $group = 'staff_id', string $field = 'number')
{
return parent::search($where)->with(['systemStoreStaff'])
->field("*,sum(`" . $field . "`) as total_number,count(*) as order_count")
->group($group)
->order('total_number desc')
->select()->toArray();
}
/**
* 获取一段时间订单统计数量、金额
* @param array $where
* @param array $time
* @param string $timeType
* @param string $countField
* @param string $sumField
* @param string $groupField
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function orderAddTimeList(array $where, array $time, string $timeType = "week", string $countField = '*', string $sumField = 'number', string $groupField = 'add_time')
{
return parent::search($where)
->where(isset($where['timekey']) && $where['timekey'] ? $where['timekey'] : 'add_time', 'between time', $time)
->when($timeType, function ($query) use ($timeType, $countField, $sumField, $groupField) {
switch ($timeType) {
case "hour":
$timeUnix = "%H";
break;
case "day" :
$timeUnix = "%Y-%m-%d";
break;
case "week" :
$timeUnix = "%Y-%w";
break;
case "month" :
$timeUnix = "%Y-%d";
break;
case "weekly" :
$timeUnix = "%W";
break;
case "year" :
$timeUnix = "%Y-%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('day');
})->order('add_time asc')->select()->toArray();
}
}

View File

@ -0,0 +1,50 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\supplier;
use app\dao\BaseDao;
use app\model\supplier\SupplierTicketPrint;
/**
* 供应商小票打印
* Class SystemSupplierDao
* @package app\dao\system\store
*/
class SupplierTicketPrintDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return SupplierTicketPrint::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 getList(array $where = [], int $page = 0, int $limit = 0)
{
return $this->search($where)
->when($page != 0 && $limit != 0, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order('id desc')->select()->toArray();
}
}

View File

@ -0,0 +1,53 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\supplier;
use app\dao\BaseDao;
use app\model\supplier\SystemSupplier;
/**
* 供应商
* Class SystemSupplierDao
* @package app\dao\system\store
*/
class SystemSupplierDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return SystemSupplier::class;
}
/**
* 列表
* @param array $where
* @param array $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 getSupplierList(array $where, array $field, int $page = 0, int $limit = 10, string $order = 'sort desc,id desc'): array
{
return $this->search($where)->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->when(isset($order), function ($query) use ($order) {
$query->order($order);
})->field($field)->select()->toArray();
}
}

View File

@ -0,0 +1,65 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\supplier\finance;
use app\dao\BaseDao;
use app\model\supplier\finance\SupplierExtract;
/**
* 门店提现
* Class StoreExtractDao
* @package app\dao\store\finance
*/
class SupplierExtractDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return SupplierExtract::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 getExtractList(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
* @param string $field
* @return float
*/
public function getExtractMoneyByWhere(array $where, string $field)
{
return $this->search($where)->sum($field);
}
}

View File

@ -0,0 +1,167 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\supplier\finance;
use app\dao\BaseDao;
use app\model\supplier\finance\SupplierFlowingWater;
/**
* 供应商流水
* Class SupplierFlowingWaterDao
* @package app\dao\supplier\finance
*/
class SupplierFlowingWaterDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return SupplierFlowingWater::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, array $with = [])
{
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();
}
/**
*供应商流水数量
* @param array $where
* @return \crmeb\basic\BaseModel|int|mixed|\think\Model
*/
public function getCount(array $where = [])
{
return $this->search($where)->count();
}
/**
* 搜索
* @param array $where
* @return \crmeb\basic\BaseModel|mixed|\think\Model
*/
public function search(array $where = [])
{
return parent::search($where)
->when(isset($where['type']) && $where['type'] !== '', function ($query) use ($where) {
$query->where('type', $where['type']);
})->when(isset($where['keyword']) && $where['keyword'] !== '', function ($query) use ($where) {
$query->where(function ($que) use ($where) {
$que->whereLike('order_id', '%' . $where['keyword'] . '%')->whereOr('uid', 'in', function ($q) use ($where) {
$q->name('user')->whereLike('nickname|uid', '%' . $where['keyword'] . '%')->field(['uid'])->select();
});
});
});
}
/**
* 供应商账单
* @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 getFundRecord(array $where = [], int $page = 0, int $limit = 0)
{
$model = parent::search($where)
->when(isset($where['timeType']) && $where['timeType'] !== '', function ($query) use ($where) {
$timeUnix = '%Y-%m-%d';
switch ($where['timeType']) {
case "day" :
$timeUnix = "%Y-%m-%d";
break;
case "week" :
$timeUnix = "%Y-%u";
break;
case "month" :
$timeUnix = "%Y-%m";
break;
}
$query->field("FROM_UNIXTIME(add_time,'$timeUnix') as day,sum(if(pm = 1,number,0)) as income_num,sum(if(pm = 0,number,0)) as exp_num,add_time,group_concat(id) as ids");
$query->group("FROM_UNIXTIME(add_time, '$timeUnix')");
});
$count = $model->count();
$list = $model->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order('add_time desc')->select()->toArray();
return compact('list', 'count');
}
/**
* 获取一段时间订单统计数量、金额
* @param array $where
* @param array $time
* @param string $timeType
* @param string $countField
* @param string $sumField
* @param string $groupField
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function orderAddTimeList(array $where, array $time, string $timeType = "week", string $countField = '*', string $sumField = 'number', string $groupField = 'add_time')
{
return parent::search($where)
->where(isset($where['timekey']) && $where['timekey'] ? $where['timekey'] : 'add_time', 'between time', $time)
->when($timeType, function ($query) use ($timeType, $countField, $sumField, $groupField) {
switch ($timeType) {
case "hour":
$timeUnix = "%H";
break;
case "day" :
$timeUnix = "%Y-%m-%d";
break;
case "week" :
$timeUnix = "%Y-%w";
break;
case "month" :
$timeUnix = "%Y-%d";
break;
case "weekly" :
$timeUnix = "%W";
break;
case "year" :
$timeUnix = "%Y-%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('day');
})->order('add_time asc')->select()->toArray();
}
}

View File

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

View File

@ -0,0 +1,72 @@
<?php
namespace app\dao\system;
use app\dao\BaseDao;
use app\model\system\CapitalFlow;
class CapitalFlowDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return CapitalFlow::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)->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order('id desc')->select()->toArray();
}
/**
* 账单记录
* @param $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 getRecordList($where, $page = 0, $limit = 0)
{
$model = $this->search($where)
->when(isset($where['type']) && $where['type'] !== '', function ($query) use ($where) {
$timeUnix = '%Y-%m-%d';
switch ($where['type']) {
case "day" :
$timeUnix = "%Y-%m-%d";
break;
case "week" :
$timeUnix = "%Y-%u";
break;
case "month" :
$timeUnix = "%Y-%m";
break;
}
$query->field("FROM_UNIXTIME(add_time,'$timeUnix') as day,sum(if(price >= 0,price,0)) as income_price,sum(if(price < 0,price,0)) as exp_price,add_time,group_concat(id) as ids");
$query->group("FROM_UNIXTIME(add_time, '$timeUnix')");
});
$count = $model->count();
$list = $model->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order('add_time desc')->select()->toArray();
return compact('list', 'count');
}
}

View File

@ -0,0 +1,57 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\system;
use app\dao\BaseDao;
use app\common\model\system\auth\Role as SystemRole;
/**
* Class SystemRoleDao
* @package app\dao\system\admin
*/
class SystemRoleDao extends BaseDao
{
/**
* 设置模型名
* @return string
*/
protected function setModel(): string
{
return SystemRole::class;
}
/**
* 获取权限
* @param string $field
* @param string $key
* @return mixed
*/
public function getRoule(array $where = [], ?string $field = null, ?string $key = null)
{
return $this->search($where)->column($field ?: 'role_name', $key ?: 'id');
}
/**
* 获取身份列表
* @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 getRouleList(array $where, int $page, int $limit)
{
return $this->search($where)->page($page, $limit)->select()->toArray();
}
}

View File

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

View File

@ -0,0 +1,110 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\system\admin;
use app\dao\BaseDao;
use app\common\model\system\admin\Admin as SystemAdmin;
/**
* Class SystemAdminDao
* @package app\dao\system\admin
*/
class SystemAdminDao extends BaseDao
{
protected function setModel(): string
{
return SystemAdmin::class;
}
/**
* 获取列表
* @param array $where
* @param int $page
* @param int $limit
* @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, int $page = 0, int $limit = 0, string $field = '*')
{
return $this->search($where)->field($field)->when($page && $limit, function ($query) use($page, $limit) {
$query->page($page, $limit);
})->select()->toArray();
}
/**
* 用管理员名查找管理员信息
* @param string $account
* @param int $adminType
* @return array|\think\Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function accountByAdmin(string $account, int $adminType)
{
return $this->search(['account' => $account, 'is_del' => 0, 'status' => 1, 'admin_type' => $adminType])->find();
}
/**
* 用电话查找管理员信息
* @param string $phone
* @param int $adminType
* @return array|\think\Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function phoneByAdmin(string $phone, int $adminType = 1)
{
return $this->search(['phone' => $phone, 'is_del' => 0, 'status' => 1, 'admin_type' => $adminType])->find();
}
/**
* 当前账号是否可用
* @param string $account
* @param int $id
* @param int $admin_type
* @return int
* @throws \think\db\exception\DbException
*/
public function isAccountUsable(string $account, int $id, int $admin_type = 1)
{
return $this->search(['account' => $account, 'is_del' => 0])->where('admin_type', $admin_type)->where('id', '<>', $id)->count();
}
/**
* 获取adminid
* @param int $level
* @return array
*/
public function getAdminIds(int $level)
{
return $this->getModel()->where('level', '>=', $level)->column('id', 'id');
}
/**
* 获取低于等级的管理员名称和id
* @param string $field
* @param int $level
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getOrdAdmin(string $field = 'real_name,id', int $level = 0)
{
return $this->getModel()->where('level', '>=', $level)->field($field)->select()->toArray();
}
}

View File

@ -0,0 +1,122 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\system\attachment;
use app\dao\BaseDao;
use app\common\model\system\attachment\Attachment as SystemAttachment;
/**
*
* Class SystemAttachmentDao
* @package app\dao\attachment
*/
class SystemAttachmentDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return SystemAttachment::class;
}
/**
* 搜索附件分类search
* @param array $where
* @return \crmeb\basic\BaseModel|mixed|\think\Model
*/
public function search(array $where = [])
{
return parent::search($where)->when(isset($where['name']) && $where['name']!='', function ($query) use ($where) {
$query->where('att_id|real_name|name', 'LIKE', '%' . trim($where['name']) . '%');
});
}
/**
* 获取图片列表
* @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 getList(array $where, int $page, int $limit)
{
return $this->search($where)->where('module_type', 1)->page($page, $limit)->order('att_id DESC')->select()->toArray();
}
/**
* 移动图片
* @param array $data
* @return \crmeb\basic\BaseModel
*/
public function move(array $data)
{
return $this->getModel()->whereIn('att_id', $data['images'])->update(['pid' => $data['pid']]);
}
/**
* 获取名称
* @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 getLikeNameList(array $where, int $page, int $limit)
{
return $this->search($where)->page($page, $limit)->order('att_id desc')->select()->toArray();
}
/**
* 获取昨日系统生成
* @param int $type
* @param int $relationId
* @return \think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getYesterday(int $type = 1, $relationId = 0)
{
return $this->getModel()->where('type', $type)->when($relationId, function ($query) use ($relationId) {
$query->where('relation_id', $relationId);
})->whereTime('time', 'yesterday')->where('module_type', 2)->field(['name', 'att_dir', 'att_id', 'image_type'])->select();
}
/**
* 删除昨日生成海报
* @throws \Exception
*/
public function delYesterday()
{
$this->getModel()->whereTime('time', 'yesterday')->where('module_type', 2)->delete();
}
/**
* 获取扫码上传的图片数据
* @param $scan_token
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function scanUploadImage($scan_token)
{
return $this->getModel()->where('scan_token', $scan_token)->field('att_dir,att_id')->select()->toArray();
}
}

View File

@ -0,0 +1,141 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\system\config;
use app\dao\BaseDao;
use app\common\model\system\config\SystemConfig;
/**
* 系统配置
* Class SystemConfigDao
* @package app\dao\system\config
*/
class SystemConfigDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return SystemConfig::class;
}
/**
* 获取某个系统配置
* @param string $configNmae
* @param int $storeId
* @return mixed
*/
public function getConfigValue(string $configNmae, int $storeId = 0)
{
return $this->withSearchSelect(['menu_name', 'store_id'], ['menu_name' => $configNmae, 'store_id' => $storeId])->value('value');
}
/**
* 获取所有配置
* @param array $configName
* @param int $storeId
* @return array
*/
public function getConfigAll(array $configName = [], int $storeId = 0)
{
if ($configName) {
return $this->withSearchSelect(['menu_name', 'store_id'], ['menu_name' => $configName, 'store_id' => $storeId])->column('value', 'menu_name');
} else {
return $this->getModel()->column('value', 'menu_name');
}
}
/**
* @param array $configName
* @param int $storeId
* @param array $field
* @return array
*/
public function getConfigAllField(array $configName = [], int $storeId = 0, array $field = [])
{
return $this->withSearchSelect(['menu_name', 'store_id'], ['menu_name' => $configName, 'store_id' => $storeId])->column(implode(',', $field), 'menu_name');
}
/**
* 获取配置列表分页
* @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 getConfigList(array $where, int $page, int $limit)
{
return $this->search($where)->page($page, $limit)->order('sort desc,id desc')->select()->toArray();
}
/**
* 获取某些分类配置下的配置列表
* @param int $tabId
* @param int $status
* @param int $store_id
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getConfigTabAllList(int $tabId, int $status = 1, int $type = 1, int $relation_id = 0)
{
$where['tab_id'] = $tabId;
if ($status == 1) $where['status'] = $status;
if ($relation_id != 0) $where['is_store'] = 1;
return $this->search($where)
->when(isset($relation_id) && $relation_id != 0, function ($query) use ($type, $relation_id) {
$query->with(['storeConfig' => function ($querys) use ($type, $relation_id) {
$querys->where('type', $type)->where('relation_id', $relation_id);
}]);
})
->order('sort desc')->select()->toArray();
}
/**
* 根据条件获取配置
* @param array $where
* @param int $type
* @param int $relation_id
* @param array $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getConfigAllListByWhere(array $where, int $type = 1, int $relation_id = 0, array $field = ['*'])
{
if ($relation_id != 0) $where['is_store'] = 1;
return $this->search($where)->field($field)
->when(isset($relation_id) && $relation_id != 0, function ($query) use ($type, $relation_id) {
$query->with(['storeConfig' => function ($querys) use ($type, $relation_id) {
$querys->where('type', $type)->where('relation_id', $relation_id);
}]);
})
->order('sort desc')->select()->toArray();
}
/**
* 获取上传配置中的上传类型
* @param string $configName
* @return array
*/
public function getUploadTypeList(string $configName)
{
return $this->search(['menu_name' => $configName])->column('upload_type', 'type');
}
}

View File

@ -0,0 +1,58 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\system\config;
use app\dao\BaseDao;
use app\common\model\system\groupData\SystemGroup;
/**
* Class SystemGroupDao
* @package app\dao\system\config
*/
class SystemGroupDao extends BaseDao
{
/**
* @return string
*/
protected function setModel(): string
{
return SystemGroup::class;
}
/**
* 获取组合数据分页列表
* @param array $where
* @param array $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 getGroupList(array $where, array $field = ['*'], int $page = 0, int $limit = 0)
{
return $this->search($where)->field($field)->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->select()->toArray();
}
/**
* 根据配置名称获取配置id
* @param string $configName
* @return mixed
*/
public function getConfigNameId(string $configName)
{
return $this->value(['config_name' => $configName]);
}
}

View File

@ -0,0 +1,99 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\system\config;
use app\dao\BaseDao;
use app\common\model\system\groupData\SystemGroupData;
/**
* 组合数据
* Class SystemGroupDataDao
* @package app\dao\system\config
*/
class SystemGroupDataDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return SystemGroupData::class;
}
/**
* 获取组合数据列表
* @param array $where
* @param int $page
* @param int $limit
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getGroupDataList(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,id DESC')->select()->toArray();
}
/**
* 获取某个gid下的组合数据
* @param int $gid
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getGroupDate(int $gid, int $limit = 0)
{
return $this->search(['gid' => $gid, 'status' => 1])->when($limit, function ($query) use ($limit) {
$query->limit($limit);
})->field('value,id')->order('sort DESC,id DESC')->select()->toArray();
}
/**
* 根据gid删除组合数据
* @param int $gid
* @return bool
*/
public function delGroupDate(int $gid)
{
return $this->getModel()->where('gid', $gid)->delete();
}
/**
* 批量保存
* @param array $data
* @return mixed|\think\Collection
* @throws \Exception
*/
public function saveAll(array $data)
{
return $this->getModel()->saveAll($data);
}
/**
* 根据id获取秒杀数据
* @param array $ids
* @param string $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function idByGroupList(array $ids, string $field)
{
return $this->getModel()->whereIn('id', $ids)->field($field)->select()->toArray();
}
}

View File

@ -0,0 +1,54 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\system\form;
use app\dao\BaseDao;
use app\model\system\form\SystemForm;
/**
*
* Class SystemFormDao
* @package app\dao\system\form
*/
class SystemFormDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return SystemForm::class;
}
/**
* 获取系统表单
* @param array $where
* @param array $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 getFormList(array $where, array $field = ['*'], int $page = 0, int $limit = 0)
{
return $this->search($where)->field($field)->where('is_del', 0)
->when($page && $limit, function($query) use ($page, $limit){$query->page($page, $limit);
})->order('id desc')->select()->toArray();
}
}

View File

@ -0,0 +1,103 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 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\common\model\user\User;
use app\common\model\user\UserAddress;
/**
* 用户收获地址
* Class UserAddressDao
* @package app\dao\user
*/
class UserAddressDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return UserAddress::class;
}
protected function JoinModel() : string
{
return User::class;
}
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,279 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 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\common\model\user\UserBill;
/**
* 积分&经验
* 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
*/
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
*/
public function getBillList(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();
}
/**
* 获取某个条件总数
* @param array $where
*/
public function getBillSum(array $where)
{
return $this->search($where)->sum('number');
}
/**
* 获取某个条件总条数
* @param array $where
*/
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 mixed
*/
public function getUserSignPoint(array $where)
{
return $this->search($where)->count();
}
/**
* @param array $where
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getUserBillList(array $where)
{
return $this->search($where)->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(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 \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getBalanceRecord(array $where, int $page, int $limit)
{
return $this->search($where)->order('add_time desc')->page($page, $limit)->select()->toArray();
}
/**
* 计算某个条件下订单内商品总数
* @param $where
* @return float|int
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\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 \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();
}
/**
* 积分趋势
* @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,162 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 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\common\model\user\UserBrokerage;
/**
* 用户佣金
* 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)
{
$where['not_type'] = ['extract_fail', 'refund'];
return $this->search($where)->where('pm', 1)->field('uid,SUM(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
* @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
*/
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,56 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 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();
}
}

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

@ -0,0 +1,364 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 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\common\model\user\User;
/**
* 用户
* Class UserDao
* @package app\dao\user
*/
class UserDao extends BaseDao
{
protected function setModel(): string
{
return User::class;
}
/**
* @param array $where
* @return \crmeb\basic\BaseModel|mixed|\think\Model
*/
public function search(array $where = [])
{
return parent::search($where)->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 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): array
{
return $this->search($where)->field($field)->with(['label'])->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->select()->toArray();
}
/**
* 获取特定条件的总数
* @param array $where
* @param bool $is_list
* @return array|int
*/
public function getCount(array $where, bool $is_list = false)
{
if ($is_list)
return $this->getModel()->where($where)->group('uid')->fetchSql(true)->column('count(*) as user_count', 'uid');
else
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();
}
public function getOutOne(int $uid, $field = "*")
{
return $this->getModel()->where('uid|phone', $uid)->field($field)->find();
}
}

View File

@ -0,0 +1,149 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 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\common\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~2020 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~2020 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~2020 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();
}
}

Some files were not shown because too many files have changed in this diff Show More