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

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

View File

@@ -0,0 +1,101 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\product\brand;
use app\dao\BaseDao;
use app\model\product\brand\StoreBrand;
/**
* Class StoreBrandDao
* @package app\dao\product\brand
*/
class StoreBrandDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreBrand::class;
}
/**
* 获取品牌列表
* @param array $where
* @param array $with
* @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 $with = [], array $field = ['*'], int $page = 0, int $limit = 0)
{
return $this->search($where)->field($field)
->when(in_array('product', $with), function ($query) use ($with) {
$with = array_merge(array_diff($with, ['product']), ['product' => function ($que) {
$que->field(['pid', 'brand_id', "count(`brand_id`) as brand_num"])->where('pid', 0)->where('is_del', 0)->group('brand_id');
}]);
$query->with($with);
})->when($page && $limit, function ($query) use($page, $limit) {
$query->page($page, $limit);
})->order('sort desc,id desc')->select()->toArray();
}
/**
* 获取品牌列表
* @param array $where
* @param array $with
* @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 searchList(array $where, array $with = [], array $field = ['*'], int $page = 0, int $limit = 0)
{
return $this->search($where)->field($field)
->when(in_array('product', $with), function ($query) use ($with) {
$with = array_merge(array_diff($with, ['product']), ['product' => function ($que) {
$que->field(['pid', 'brand_id', "count(`brand_id`) as brand_num"])->where('pid', 0)->where('is_del', 0)->group('brand_id');
}]);
$query->with($with);
})->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 array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getAllById(int $id, string $field = 'id')
{
if (!$id) return [];
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();
}
}

View File

@@ -0,0 +1,234 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\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
* @param array $with
* @return array
* @throws \ReflectionException
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $where, string $field = '*', int $page = 0, int $limit = 0, array $with = ['children'])
{
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('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();
}
/**
* 前端分类页面分离列表
* @param string $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getCategory(string $field = '*')
{
return $this->getModel()->field($field)->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(['parentCateName'])->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', int $limit = 0)
{
$pid = $where['pid'] ?? -1;
$where['is_show'] = 1;
return $this->search($where)->field($field)
->when((int)$pid > -1, 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,id desc')->select()->toArray();
}
}

View File

@@ -0,0 +1,55 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\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~2026 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,62 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\product\label;
use app\dao\BaseDao;
use app\model\product\label\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);
})->order('sort DESC,id DESC')->select()->toArray();
}
/**
* 删除数据
* @param array $ids
* @throws \Exception
*/
public function del(array $ids)
{
return $this->getModel()->whereIn('id', $ids)->delete();
}
}

View File

@@ -0,0 +1,44 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\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,61 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\product\product;
use app\dao\BaseDao;
use app\model\product\product\StoreProductCate;
/**
* Class StoreProductCateDao
* @package app\dao\product\product
*/
class StoreProductCateDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreProductCate::class;
}
/**
* 保存数据
* @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)->column('cate_id');
}
/**
* 根据分类获取商品id
* @param array $cate_id
* @return array
*/
public function cateIdByProduct(array $cate_id)
{
return $this->getModel()->whereIn('cate_id', $cate_id)->column('product_id');
}
}

View File

@@ -0,0 +1,50 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\product\product;
use app\dao\BaseDao;
use app\model\product\product\StoreProductCoupon;
/**
*
* Class StoreProductCouponDao
* @package app\dao\coupon
*/
class StoreProductCouponDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreProductCoupon::class;
}
/**
* 获取商品关联优惠卷
* @param array $product_ids
* @param string $field
* @return array
* @throws \ReflectionException
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getProductCoupon(array $product_ids, string $field = '*')
{
return $this->search(['product_id' => $product_ids])->field($field)->select()->toArray();
}
}

View File

@@ -0,0 +1,693 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\product\product;
use app\dao\BaseDao;
use app\model\product\product\StoreProduct;
use app\services\activity\bargain\StoreBargainServices;
use app\services\activity\combination\StoreCombinationServices;
use app\services\activity\combination\StorePinkServices;
use app\services\activity\seckill\StoreSeckillServices;
use crmeb\basic\BaseModel;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\facade\Config;
use think\Model;
/**
* Class StoreProductDao
* @package app\dao\product\product
*/
class StoreProductDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreProduct::class;
}
/**
* @param array $where
* @param bool $search
* @return BaseModel
* @throws \ReflectionException
*/
public function search(array $where = [], bool $search = false)
{
return parent::search($where, $search)
//商品关键词搜索
->when(isset($where['store_name']) && $where['store_name'] && is_string($where['store_name']), function ($query) use ($where) {
if (isset($where['field_key']) && in_array($where['field_key'], ['product_id', 'bar_code', 'store_name', 'keyword', 'code'])) {
switch ($where['field_key']) {
case 'product_id':
$query->where('id', trim($where['store_name']));
break;
case 'store_name':
$query->where('store_name', 'like', '%' . trim($where['store_name']) . '%');
break;
case 'keyword':
$query->where('keyword', 'like', '%' . trim($where['store_name']) . '%');
break;
case 'code':
$query->where('code', trim($where['store_name']));
break;
case 'bar_code':
$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();
});
});
break;
}
} else {
$query->where(function ($q) use ($where) {
$q->where('id|keyword|store_name|store_info|bar_code|spu', '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['sales_range']) && $where['sales_range'], function ($query) use ($where) {
$sales_range = explode('-', $where['sales_range']);
if (count($sales_range) == 1) {
$query->where('sales', '>=', $sales_range[0]);
}
if (count($sales_range) == 2 && ($sales_range[0] !== '' || $sales_range[1] !== '')) {
if ($sales_range[0] === '') {
$query->where('sales', '<=', $sales_range[1]);
} elseif ($sales_range[1] === '') {
$query->where('sales', '>=', $sales_range[0]);
} else {
$query->whereBetween('sales', $sales_range);
}
}
})
//库存区间
->when(isset($where['stock_range']) && $where['stock_range'], function ($query) use ($where) {
$stock_range = explode('-', $where['stock_range']);
if (count($stock_range) == 1) {
$query->where('stock', '>=', $stock_range[0]);
}
if (count($stock_range) == 2 && ($stock_range[0] !== '' || $stock_range[1] !== '')) {
if ($stock_range[0] === '') {
$query->where('stock', '<=', $stock_range[1]);
} elseif ($stock_range[1] === '') {
$query->where('stock', '>=', $stock_range[0]);
} else {
$query->whereBetween('stock', $stock_range);
}
}
})
//售价区间
->when(isset($where['price_range']) && $where['price_range'], function ($query) use ($where) {
$price_range = explode('-', $where['price_range']);
if (count($price_range) == 1) {
$query->where('price', '>=', $price_range[0]);
}
if (count($price_range) == 2 && ($price_range[0] !== '' || $price_range[1] !== '')) {
if ($price_range[0] === '') {
$query->where('price', '<=', $price_range[1]);
} elseif ($price_range[1] === '') {
$query->where('price', '>=', $price_range[0]);
} else {
$query->whereBetween('price', $price_range);
}
}
})
//收藏区间
->when(isset($where['collect_range']) && $where['collect_range'], function ($query) use ($where) {
$collect_range = explode('-', $where['collect_range']);
if (count($collect_range) == 1) {
$query->where('collect', '>=', $collect_range[0]);
}
if (count($collect_range) == 2 && ($collect_range[0] !== '' || $collect_range[1] !== '')) {
if ($collect_range[0] === '') {
$query->where('collect', '<=', $collect_range[1]);
} elseif ($collect_range[1] === '') {
$query->where('collect', '>=', $collect_range[0]);
} else {
$query->whereBetween('collect', $collect_range);
}
}
})
//添加时间区间
->when(isset($where['create_range']) && $where['create_range'], function ($query) use ($where) {
$create_range = explode('-', $where['create_range']);
$start_time = strtotime($create_range[0]);
$end_time = strtotime($create_range[1]);
if ($start_time && $end_time) {
$query->whereBetween('price', [$start_time, $end_time]);
}
})
//活动类型
->when(isset($where['activity_type']) && $where['activity_type'] !== '', function ($query) use ($where) {
//1:秒杀.2:砍价,3 拼团
$ids = [];
switch ($where['activity_type']) {
case 1:
$ids = app()->make(StoreSeckillServices::class)->search(['is_del' => 0, 'start_status' => 1, 'status' => 1])->column('product_id');
break;
case 2:
$ids = app()->make(StoreBargainServices::class)->search(['is_del' => 0, 'start_status' => 1, 'status' => 1])->column('product_id');
break;
case 3:
$ids = app()->make(StoreCombinationServices::class)->search(['is_del' => 0, 'start_status' => 1, 'status' => 1])->column('product_id');
}
$query->whereIn('id', $ids);
})
->when(isset($where['tid']) && $where['tid'], function ($query) use ($where) {//三级
$query->whereIn('id', function ($query) use ($where) {
$query->name('store_product_relation')->where('type', 1)->where('relation_id', $where['tid'])->field('product_id')->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)->whereIn('relation_id', function ($query) use ($where) {
$query->name('store_product_category')->where('id|pid', $where['sid'])->field('id')->select();
})->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(function ($query) use ($where) {
$query->whereFindinSet('path', $where['cid'])->whereOr('id', $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();
});
});
}
/**
* 条件获取数量
* @param array $where
* @return int
* @throws DbException
*/
public function getCount(array $where): int
{
if (!empty($where['cate_id']) && is_array($where['cate_id'])) {
return $this->getModel()->alias('a')
->join('store_product_relation r', 'r.product_id = a.id')
->when(isset($where['unit_name']) && $where['unit_name'] !== '', function ($query) use ($where) {
$query->where('a.unit_name', $where['unit_name']);
})->when(isset($where['ids']) && $where['ids'], function ($query) use ($where) {
if (!isset($where['type'])) $query->where('a.id', 'in', $where['ids']);
})->when(isset($where['not_ids']) && $where['not_ids'], function ($query) use ($where) {
$query->whereNotIn('a.id', $where['not_ids']);
})->when(isset($where['status']) && '' !== $where['status'], function ($query) use ($where) {
$value = $where['status'];
switch ((int)$value) {
case -2://强制下架
$query->where(['a.is_verify' => -2, 'a.is_del' => 0]);
break;
case -1://审核未通过
$query->where(['a.is_verify' => -1, 'a.is_del' => 0]);
break;
case 0://待审核
$query->where(['a.is_verify' => 0, 'a.is_del' => 0]);
break;
case 1:
$query->where(['a.is_show' => 1, 'a.is_del' => 0, 'is_verify' => 1]);
break;
case 2:
$query->where(['a.is_show' => 0, 'a.is_del' => 0, 'is_verify' => 1]);
break;
case 3:
$query->where(['a.is_del' => 0, 'is_verify' => 1]);
break;
case 4:
$query->where(['a.is_del' => 0, 'a.is_verify' => 1, 'a.is_sold' => 1])->where(function ($query) {
$query->whereOr('stock', 0);
});
break;
case 5:
// if (isset($data['store_stock']) && $data['store_stock']) {
// $store_stock = $data['store_stock'];
// $query->where(['a.is_show' => 1, 'a.is_del' => 0, 'a.is_verify' => 1, 'a.is_police' => 1])->where('a.stock', '<=', $store_stock)->where('a.stock', '>', 0);
// } else {
$query->where(['a.is_show' => 1, 'a.is_del' => 0, 'a.is_verify' => 1, 'a.is_police' => 1])->where('a.stock', '>', 0);
// }
break;
case 6:
$query->where(['a.is_del' => 1]);
break;
case 7://回收站 & 下架商品
$query->where(function ($q) {
$q->where(['a.is_del' => 1])->whereOr('a.is_show', 0);
});
break;
};
})->when(isset($where['pids']) && $where['pids'], function ($query) use ($where) {
if ((isset($where['priceOrder']) && $where['priceOrder'] != '') || (isset($where['salesOrder']) && $where['salesOrder'] != '')) {
$query->whereIn('a.pid', $where['pids']);
} else {
$query->whereIn('a.pid', $where['pids'])->orderField('pid', $where['pids'], 'asc');
}
})->when(isset($where['not_pids']) && $where['not_pids'], function ($query) use ($where) {
$query->whereNotIn('a.pid', $where['not_pids']);
})->where('r.type', 1)
->where('r.relation_id', 'IN', $where['cate_id'])
->group('a.id')
->count('a.id');
} else {
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 DataNotFoundException
* @throws DbException
* @throws 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['ids']), function ($query) use ($where) {
if (!isset($where['type'])) $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|Model|null
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function getInfo(int $id)
{
return $this->search()->with('coupons')->find($id);
}
/**
* 获取门店商品
* @param $where
* @return array|Model|null
* @throws DataNotFoundException
* @throws DbException
* @throws 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 DataNotFoundException
* @throws DbException
* @throws 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['defaultOrder']) && in_array($where['defaultOrder'], [0, 1, 2]), function ($query) use ($where) {
switch ($where['defaultOrder']) {
case 0://默认排序
$query->order('sort desc,id desc');
break;
case 1://好评
$query->order('star desc,sort desc');
break;
case 2://新品
$query->order('id desc,sort desc');
break;
default:
$query->order('sort desc,id desc');
break;
}
})->when(!isset($where['ids']) || !$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 DataNotFoundException
* @throws DbException
* @throws 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 DataNotFoundException
* @throws DbException
* @throws 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
* @param string $order
* @return array
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @throws \ReflectionException
*/
public function getRecommendProduct(array $where, array $field = ['*'], int $num = 0, int $page = 0, int $limit = 0, array $with = ['couponId'], string $order = 'sort DESC, id DESC')
{
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 && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order($order)->select()->toArray();
}
/**
* 获取加入购物车的商品
* @param array $where
* @param int $page
* @param int $limit
* @return array
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function getProductCartList(array $where, int $page, int $limit, array $field = ['*'])
{
$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 DataNotFoundException
* @throws DbException
* @throws 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 DataNotFoundException
* @throws DbException
* @throws 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 DataNotFoundException
* @throws DbException
* @throws 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['ids']) && $where['ids'], function ($query) use ($where) {
$query->whereIn('id', $where['ids']);
})->field($field)->column($field, $key);
}
/**
* 自动上下架
* @param int $is_show
* @return BaseModel
*/
public function overUpperShelves($is_show = 0)
{
return $this->getModel()->where(['is_del' => 0])
->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 $where
* @param $page
* @param $limit
* @return array
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function getPresaleList(array $where, int $page, int $limit)
{
$model = $this->getModel()->where('is_presale_product', 1)->where('is_del', 0)
->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;
}
})->when(isset($where['presale_status']), function ($query) use ($where) {
$query->where('presale_status', $where['presale_status']);
});
$count = $model->count();
$list = $model->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();
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);
}
/**
* 获取商品关联,品牌、标签等
* @param array $productWhere
* @param array $relation_type
* @param string $field
* @return array
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function getProductRelation(array $productWhere, array $relation_type = [], string $field = '*'): array
{
return $this->getModel()->alias('p')->leftJoin('store_product_relation r', 'p.id = r.product_id')
->field($field)->where($productWhere)->whereIn('r,type', $relation_type)->select()->toArray();
}
/**
* 批量删除商品
* @param array $ids 商品ID数组
* @return int
*/
public function delAll(array $ids)
{
return $this->getModel()->whereIn('id', $ids)->update(['is_del' => 1]);
}
/**
* 根据条件、排序、分页获取商品id
* @param $where
* @param $field
* @param $order
* @param $limit
* @return array
* @author wuhaotian
* @email 442384644@qq.com
* @date 2025/9/24
*/
public function getProductIds($where, $field, $order, $limit)
{
return $this->getModel()->where($where)->field($field)->order($order)->limit($limit)->column('id');
}
}

View File

@@ -0,0 +1,135 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\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;
}
/**
* 获取商品排名统计
* @param array $where 查询条件
* @return array
*/
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(pay_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();
}
/**
* 获取复购用户数
* @param array $where 查询条件
* @param int $product_id 商品ID
* @return int
*/
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();
}
/**
* 获取商品列表
* @param array $where
* @return \crmeb\basic\BaseModel|mixed|\think\Model
*/
public function getProduct(array $where, int $page = 0, int $limit = 0)
{
$model = $this->getModel()->alias('L')
->join('StoreProduct S', 'S.id = L.product_id')
->where('S.is_show', 1)->where('S.is_del', 0);
if (isset($where['keyword']) && $where['keyword'] != '') {
$model->whereLike('store_name|keyword', '%' . $where['keyword'] . '%');
}
if (isset($where['type']) && $where['type'] != '') {
$model = $model->where('L.type', $where['type']);
}
if (isset($where['uid']) && $where['uid'] != '') {
$model = $model->where('L.uid', $where['uid']);
}
return $model->when($page != 0 && $limit != 0, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->group('product_id')->field(['L.product_id', 'S.image', 'S.store_name', 'S.price'])->order('L.add_time desc')->select()
->toArray();
}
/**
* 根据类型、条件获取商品id
* @param $type
* @param $field
* @param $order
* @param $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author wuhaotian
* @email 442384644@qq.com
* @date 2025/9/24
*/
public function getProductIds($type, $field, $order, $limit)
{
return $this->getModel()->where('type', $type)->field($field)->group('product_id')->order($order)->limit($limit)->select()->toArray();
}
}

View File

@@ -0,0 +1,108 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\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 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);
}
/**
* 根据商品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~2026 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,127 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\product\product;
use app\dao\BaseDao;
use app\model\product\product\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(['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 != 0, function ($query)use($type) {
$query->where('reply_score',$type );
});
// ->when($type == 1, function ($query) {
// $query->where('product_score', 5)->where('service_score', 5)->where('delivery_score', 5);
// })->when($type == 2, function ($query) {
// $query->where(function ($query0) {
// $query0->where(function ($query1) {
// $query1->where('product_score', '<>', 5)->whereOr('service_score', '<>', 5)->whereOr('delivery_score', '<>', 5);
// })->where(function ($query2) {
// $query2->where('service_score', '>', 2)->where('product_score', '>', 2)->where('delivery_score', '>', 2);
// });
// });
// })->when($type == 3, function ($query) {
// $query->where(function ($query0) {
// $query0->where('product_score', '<=', 2)->whereOr('service_score', '<=', 2)->where('delivery_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 = ['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,121 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\product\product;
use app\dao\BaseDao;
use app\model\product\product\StoreProduct;
use app\model\product\product\StoreProductReply;
/**
*
* Class StoreProductReplyStoreProductDao
* @package app\dao\product\product
*/
class StoreProductReplyStoreProductDao extends BaseDao
{
/**
* 表别名
* @var string
*/
protected string $alias = '';
/**
* 链表别名
* @var string
*/
protected string $joinAlis = '';
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreProductReply::class;
}
/**
* 链表模型
* @return string
*/
public function setJoinModel(): string
{
return StoreProduct::class;
}
/**
* 关联模型
* @param string $alias
* @param string $join_alias
* @return \crmeb\basic\BaseModel
*/
public function getModel(string $alias = 'r', string $join_alias = 'p', $join = 'left')
{
$this->alias = $alias;
$this->joinAlis = $join_alias;
/** @var StoreProduct $storeProduct */
$storeProduct = app()->make($this->setJoinModel());
$table = $storeProduct->getName();
return parent::getModel()->join($table . ' ' . $join_alias, $alias . '.product_id = ' . $join_alias . '.id', $join)->alias($alias);
}
/**
* 获取评论列表
* @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 getProductReplyList(array $where, int $page, int $limit, array $with = [])
{
return $this->searchWhere($where)->page($page, $limit)->with($with)->select()->toArray();
}
/**
* 获取评论条数
* @param array $where
* @return int
*/
public function replyCount(array $where)
{
return $this->searchWhere($where)->count();
}
/**
* 搜索
* @param array $where
* @return \crmeb\basic\BaseModel
*/
public function searchWhere(array $where = [])
{
$model = $this->getModel()->where('r.is_del', 0)->withSearch(['time'], ['time' => $where['data'], 'timeKey' => 'r.add_time'])->order('r.add_time desc,r.is_reply asc')->field('r.*,p.store_name,p.image,r.nickname as account,FROM_UNIXTIME(r.add_time,"%Y-%m-%d %H:%i:%s") as add_time');
if ($where['is_reply'] != '') $model = $model->where('r.is_reply', $where['is_reply']);
if (isset($where['type'])) {
if ($where['type']) $model = $model->where('r.type', $where['type']);
}
if (isset($where['relation_id'])) {
if ($where['relation_id']) $model = $model->where('r.relation_id', $where['relation_id']);
}
if (isset($where['store_id'])) {
if ($where['store_id']) $model = $model->where('r.type', 1)->where('r.relation_id', $where['relation_id']);
}
if ($where['product_id']) $model = $model->where('r.product_id', $where['product_id']);
if ($where['store_name']) $model = $model->where('p.store_name|p.keyword|r.id|r.product_id', 'Like', '%' . $where['store_name'] . '%');
if ($where['account']) $model = $model->where('r.nickname', 'LIKE', '%' . $where['account'] . '%');
return $model;
}
}

View File

@@ -0,0 +1,35 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\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,51 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\product\product;
use app\dao\BaseDao;
use app\model\product\product\StoreProductUnit;
/**
* 商品单位dao
* Class StoreProductUnitDao
* @package app\dao\product\product
*/
class StoreProductUnitDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreProductUnit::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,93 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\product\product;
use app\dao\BaseDao;
use app\model\product\product\StoreProduct;
use app\model\product\product\StoreVisit;
/**
* Class StoreProductVisitDao
* @package app\dao\product\product
*/
class StoreProductVisitDao extends BaseDao
{
/**
* 主表别名
* @var string
*/
protected string $alias = 'a';
/**
* 附表别名
* @var string
*/
protected string $joinAlis = 'c';
/**
* 主表模型设置
* @return string
*/
protected function setModel(): string
{
return StoreProduct::class;
}
/**
* 连表模型设置
* @return string
*/
protected function setJoinModel(): string
{
return StoreVisit::class;
}
/**
* 设置模型
* @return \crmeb\basic\BaseModel
*/
protected function getModel()
{
$name = app()->make($this->setJoinModel())->getName();
return parent::getModel()->alias($this->alias)->join($name . ' ' . $this->joinAlis, $this->alias . '.id = ' . $this->joinAlis . '.product_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 getUserVisitProductList(array $where, int $page, int $limit)
{
return $this->getModel()->when(isset($where['uid']), function ($query) use ($where) {
$query->where($this->joinAlis . '.uid', $where['uid']);
})->when($page, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->when(isset($where['store_name']), function ($query) use ($where) {
$query->whereLike($this->alias . '.store_name', '%' . $where['store_name'] . '%');
})->field([
$this->alias . '.store_name',
$this->alias . '.image',
$this->alias . '.price',
'IFNULL(' . $this->alias . '.sales,0) + IFNULL(' . $this->alias . '.ficti,0) as sales',
$this->alias . '.stock',
$this->alias . '.id'
])->order($this->joinAlis . '.add_time desc,' . $this->alias . '.sort DESC,' . $this->alias . '.id DESC')->select()->toArray();
}
}

View File

@@ -0,0 +1,51 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\product\product;
use app\dao\BaseDao;
use app\model\product\product\StoreProductWords;
/**
* 商品单位dao
* Class StoreProductWordsDao
* @package app\dao\product\product
*/
class StoreProductWordsDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreProductWords::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,71 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\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');
}
/**
* 获取字段求和
* @param array $where 查询条件
* @param string $field 求和字段
* @return float|int
*/
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,92 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\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 int $type
* @param int $relation_id
* @return array
*/
public function getTemp(int $type = 0, int $relation_id = 0)
{
return $this->search(['type' => $type, 'relation_id' => $relation_id])->order('sort DESC,id DESC')->column('id,name');
}
/**
* 获取选择模板列表
* @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,84 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\product\shipping;
use app\dao\BaseDao;
use app\model\product\shipping\ShippingTemplatesFree;
use app\model\other\SystemCity;
/**
* Class ShippingTemplatesFreeCityDao
* @package app\dao\product\shipping
*/
class ShippingTemplatesFreeCityDao extends BaseDao
{
/**
* 主表别名
* @var string
*/
protected string $alias = 'a';
/**
* 附表别名
* @var string
*/
protected string $joinAlis = 'c';
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return ShippingTemplatesFree::class;
}
/**
* 设置join连表模型
* @return string
*/
protected function setJoinModel(): string
{
return SystemCity::class;
}
/**
* 关联模型
* @param string $alias
* @param string $join_alias
* @return \crmeb\basic\BaseModel
*/
protected function getModel(string $key = 'province_id', string $join = 'LEFT')
{
/** @var SystemCity $city */
$city = app()->make($this->setJoinModel());
$name = $city->getName();
return parent::getModel()->join($name . ' ' . $this->joinAlis, $this->alias . '.' . $key . ' = ' . $this->joinAlis . '.city_id', $join)->alias($this->alias);
}
/**
* 获取指定条件下的包邮列表
* @param array $where
* @return mixed
*/
public function getUniqidList(array $where, bool $group = true)
{
return $this->getModel($group ? 'province_id' : 'city_id')->when(isset($where['uniqid']), function ($query) use ($where) {
$query->where($this->alias . '.uniqid', $where['uniqid']);
})->when(isset($where['province_id']), function ($query) use ($where) {
$query->where($this->alias . '.province_id', $where['province_id']);
})->when($group, function ($query) {
$query->group($this->alias . '.province_id');
})->field($this->alias . '.province_id,' . $this->joinAlis . '.name,' . $this->alias . '.city_id')->select()->toArray();
}
}

View File

@@ -0,0 +1,124 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\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,84 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\product\shipping;
use app\dao\BaseDao;
use app\model\product\shipping\ShippingTemplatesNoDelivery;
use app\model\other\SystemCity;
/**
* Class ShippingTemplatesNoDeliveryCityDao
* @package app\dao\product\shipping
*/
class ShippingTemplatesNoDeliveryCityDao extends BaseDao
{
/**
* 主表别名
* @var string
*/
protected string $alias = 'a';
/**
* 附表别名
* @var string
*/
protected string $joinAlis = 'c';
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return ShippingTemplatesNoDelivery::class;
}
/**
* 设置join连表模型
* @return string
*/
protected function setJoinModel(): string
{
return SystemCity::class;
}
/**
* 关联模型
* @param string $alias
* @param string $join_alias
* @return \crmeb\basic\BaseModel
*/
protected function getModel(string $key = 'province_id', string $join = 'LEFT')
{
/** @var SystemCity $city */
$city = app()->make($this->setJoinModel());
$name = $city->getName();
return parent::getModel()->join($name . ' ' . $this->joinAlis, $this->alias . '.' . $key . ' = ' . $this->joinAlis . '.city_id', $join)->alias($this->alias);
}
/**
* 获取指定条件下的包邮列表
* @param array $where
* @return mixed
*/
public function getUniqidList(array $where, bool $group = true)
{
return $this->getModel($group ? 'province_id' : 'city_id')->when(isset($where['uniqid']), function ($query) use ($where) {
$query->where($this->alias . '.uniqid', $where['uniqid']);
})->when(isset($where['province_id']), function ($query) use ($where) {
$query->where($this->alias . '.province_id', $where['province_id']);
})->when($group, function ($query) {
$query->group($this->alias . '.province_id');
})->field($this->alias . '.province_id,' . $this->joinAlis . '.name,' . $this->alias . '.city_id')->select()->toArray();
}
}

View File

@@ -0,0 +1,99 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\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~2026 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;
use app\model\other\SystemCity;
/**
* Class ShippingTemplatesRegionCityDao
* @package app\dao\product\shipping
*/
class ShippingTemplatesRegionCityDao extends BaseDao
{
/**
* 当前表别名
* @var string
*/
protected string $alias = 'a';
/**
* 设置join连表别名
* @var string
*/
protected string $joinAlis = 'c';
/**
* 设置当前模型
* @return string
*/
protected function setModel(): string
{
return ShippingTemplatesRegion::class;
}
/**
* 设置连表模型
* @return string
*/
protected function setJoinModel(): string
{
return SystemCity::class;
}
/**
* 关联模型
* @param string $alias
* @param string $join_alias
* @return \crmeb\basic\BaseModel
*/
protected function getModel(string $key = 'province_id', string $join = 'LEFT')
{
/** @var SystemCity $city */
$city = app()->make($this->setJoinModel());
$name = $city->getName();
return parent::getModel()->join($name . ' ' . $this->joinAlis, $this->alias . '.' . $key . ' = ' . $this->joinAlis . '.city_id', $join)->alias($this->alias);
}
/**
* 获取指定条件下的包邮列表
* @param array $where
* @return mixed
*/
public function getUniqidList(array $where, bool $group = true)
{
return $this->getModel($group ? 'province_id' : 'city_id')->when(isset($where['uniqid']), function ($query) use ($where) {
$query->where($this->alias . '.uniqid', $where['uniqid']);
})->when(isset($where['province_id']), function ($query) use ($where) {
$query->where($this->alias . '.province_id', $where['province_id']);
})->when($group, function ($query) {
$query->group($this->alias . '.province_id');
})->field($this->alias . '.province_id,' . $this->joinAlis . '.name,' . $this->alias . '.city_id')->select()->toArray();
}
}

View File

@@ -0,0 +1,85 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\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~2026 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\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~2026 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,348 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\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
* @param string $order
* @return array
* @throws \ReflectionException
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $where, string $field = '*', int $page = 0, int $limit = 0, string $order = 'id desc', $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);
})->when(!$page && $limit, function ($query) use ($limit) {
$query->limit($limit);
})->order($order)->select()->toArray();
}
/**
* 获取商品规格数量
* @param array $where 查询条件
* @return int
*/
public function getCounts($where = [])
{
return $this->search($where)
->when(isset($where['keyword']) && $where['keyword'] !== '', function ($query) use ($where) {
$query->where(function ($q) use ($where) {
$q->whereLike('bar_code|code|unique', '%' . trim($where['keyword']) . '%')->whereOr('product_id', 'in', function ($q) use ($where) {
$q->name('store_product')->field('id')->where('store_name|keyword|id|bar_code', '%' . trim($where['keyword']) . '%')->select();
});
});
})->count();
}
/**
* 搜索
* @param $where
* @return \crmeb\basic\BaseModel
* User: liusl
* DateTime: 2025/9/19 10:50
*/
public function joinAttrSearch($where = [])
{
return $this->getModel()->alias('a')
->join('store_product p', 'a.product_id=p.id')
->where('p.is_del', 0)
->where('a.product_type', 0)
->when(isset($where['keyword']) && $where['keyword'] !== '', function ($query) use ($where) {
$query->where(function ($q) use ($where) {
$q->whereLike('a.bar_code|a.code|a.unique', '%' . trim($where['keyword']) . '%')
->whereOr('p.store_name|p.keyword|p.id|p.bar_code', 'like', '%' . trim($where['keyword']) . '%');
});
})
->when(isset($where['stock_range']) && $where['stock_range'], function ($query) use ($where) {
$stock_range = explode('-', $where['stock_range']);
if (count($stock_range) == 1) {
$query->where('a.stock', '>=', $stock_range[0]);
}
if (count($stock_range) == 2 && ($stock_range[0] !== '' || $stock_range[1] !== '')) {
if ($stock_range[0] === '') {
$query->where('a.stock', '<=', $stock_range[1]);
} elseif ($stock_range[1] === '') {
$query->where('a.stock', '>=', $stock_range[0]);
} else {
$query->whereBetween('a.stock', $stock_range);
}
}
});
}
/**
* 减库存
* @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;
}
/**
* 加库存
* @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;
}
/**
* 更新商品规格残次库存
* @param int $productId 商品ID
* @param string $unique 规格唯一标识
* @param int $num 数量
* @param int $type 商品类型
* @param int $pm 增减标识(1增加/0减少)
* @return bool
*/
public function productAttrDefectiveStock(int $productId, string $unique, int $num, int $type = 0, int $pm = 1)
{
return !!$this->getModel()->where([
'unique' => $unique,
'product_id' => $productId,
'type' => $type
])->when(isset($pm), function ($query) use ($num, $pm) {
if ($pm == 1) {
$query->inc('defective_stock', $num);
} else {
$query->dec('defective_stock', $num);
}
})->update();
}
/**
* 根据条件获取规格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, $order = '')
{
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']]);
}]);
})
->when($order != '', function ($query) use ($order) {
$query->order($order);
})
->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']);
}
})
->when($order != '', function ($query) use ($order) {
$query->order($order);
})
->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 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 array|\crmeb\basic\BaseModel[]|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
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();
}
/**
* 库存警戒查询
* @param array $where
* @return int
* @throws \think\db\exception\DbException
* @author 等风来
* @email 136327134@qq.com
* @date 2023/4/18
*/
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~2026 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~2026 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,55 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\product\stock;
use app\dao\BaseDao;
use app\model\product\stock\StockInventory;
use app\model\product\stock\StockRecord;
/**
* 出入库记录DAO
* Class StockInventoryDao
* @package app\dao\stock
*/
class StockInventoryDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StockInventory::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 = []): array
{
return $this->search($where, false)->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,176 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\product\stock;
use app\dao\BaseDao;
use app\model\product\stock\StockRecord;
/**
* 出入库记录DAO
* Class StockRecordDao
* @package app\dao\stock
*/
class StockRecordDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StockRecord::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 = []): array
{
return $this->search($where,false)->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 int
*/
public function getCount(array $where = []): int
{
return $this->search($where)->count();
}
/**
* 生成出入库单号
* @param int $type
* @return string
*/
public function generateRecordNo(int $type): string
{
if($type == 3){
$prefix = 'IC';
}else{
$prefix = $type == StockRecord::TYPE_IN ? 'IN' : 'OUT';
}
$date = date('Ymd');
$rand = mt_rand(1000, 9999);
return $prefix . $date . $rand;
}
/**
* 检查单号是否存在
* @param string $recordNo
* @param int $excludeId
* @return bool
*/
public function checkRecordNoExists(string $recordNo, int $excludeId = 0): bool
{
$query = $this->getModel()->where('record_no', $recordNo);
if ($excludeId > 0) {
$query->where('id', '<>', $excludeId);
}
return $query->count() > 0;
}
/**
* 获取统计数据
* @param array $where
* @return array
*/
public function getStatistics(array $where = []): array
{
$query = $this->search($where);
return [
'total_count' => $query->count(),
'in_count' => $query->where('type', StockRecord::TYPE_IN)->count(),
'out_count' => $query->where('type', StockRecord::TYPE_OUT)->count(),
'pending_count' => $query->count(),
'approved_count' => $query->count(),
];
}
/**
* 根据日期范围获取记录
* @param int $startTime 开始时间戳
* @param int $endTime 结束时间戳
* @param array $where
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getRecordsByDateRange(int $startTime, int $endTime, array $where = []): array
{
return $this->search($where)
->where('record_date', '>=', $startTime)
->where('record_date', '<=', $endTime)
->with(['items'])
->order('record_date DESC, id DESC')
->select()
->toArray();
}
/**
* 获取待审核的记录
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getPendingRecords(int $limit = 10): array
{
return $this->getModel()
->with(['items'])
->order('create_time ASC')
->limit($limit)
->select()
->toArray();
}
/**
* 根据出入库类型获取记录
* @param int $type 出入库类型
* @param int $subType 子类型
* @param array $where 其他条件
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getRecordsByType(int $type, int $subType = 0, array $where = []): array
{
$query = $this->search($where)->where('type', $type);
if ($subType > 0) {
$query->where('sub_type', $subType);
}
return $query->with(['items'])
->order('record_date DESC, id DESC')
->select()
->toArray();
}
}

View File

@@ -0,0 +1,270 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\product\stock;
use app\dao\BaseDao;
use app\model\product\stock\StockRecordItem;
/**
* 出入库商品详情DAO
* Class StockRecordItemDao
* @package app\dao\stock
*/
class StockRecordItemDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StockRecordItem::class;
}
/**
* 根据出入库记录ID获取商品详情
* @param int $recordId
* @param string $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getItemsByRecordId(int $recordId, string $field = '*'): array
{
return $this->getModel()
->where('record_id', $recordId)
->where('type', 1)
->field($field)
->order('id ASC')
->select()
->toArray();
}
/**
* 批量添加出入库商品详情
* @param array $data
* @return bool
*/
public function saveAllItems(array $data): bool
{
return $this->getModel()->saveAll($data) !== false;
}
/**
* 根据记录ID删除商品详情
* @param int $recordId
* @return bool
*/
public function deleteByRecordId(int $recordId): bool
{
return $this->getModel()->where('record_id', $recordId)->delete() !== false;
}
/**
* 获取商品的出入库统计
* @param int $productId
* @param int $skuId
* @param string $startDate
* @param string $endDate
* @return array
*/
public function getProductStockStatistics(int $productId, int $skuId = 0, string $startDate = '', string $endDate = ''): array
{
$query = $this->getModel()
->alias('item')
->leftJoin('stock_record record', 'item.record_id = record.id')
->where('item.product_id', $productId)
->where('record.status', 2); // 已审核状态
if ($skuId > 0) {
$query->where('item.sku_id', $skuId);
}
if ($startDate && $endDate) {
$query->whereBetweenTime('record.record_date', $startDate, $endDate);
}
// 入库统计
$inStats = (clone $query)
->where('record.type', 1)
->field([
'SUM(item.good_stock) as total_good_in',
'SUM(item.defective_stock) as total_defective_in',
'COUNT(*) as in_count'
])
->find();
// 出库统计
$outStats = (clone $query)
->where('record.type', 2)
->field([
'SUM(item.good_stock) as total_good_out',
'SUM(item.defective_stock) as total_defective_out',
'COUNT(*) as out_count'
])
->find();
return [
'in_stats' => $inStats ? $inStats->toArray() : ['total_good_in' => 0, 'total_defective_in' => 0, 'in_count' => 0],
'out_stats' => $outStats ? $outStats->toArray() : ['total_good_out' => 0, 'total_defective_out' => 0, 'out_count' => 0],
];
}
/**
* 更新商品库存(这里实际不需要更新,因为库存通过出入库记录计算)
* @param int $productId
* @param int $skuId
* @param int $quantity
* @param string $operation
* @return bool
*/
public function updateProductStock(int $productId, int $skuId, int $quantity, string $operation): bool
{
// 由于库存通过出入库记录实时计算,这里不需要实际更新操作
return true;
}
/**
* 获取商品库存详情
* @param array $where
* @param int $page
* @param int $limit
* @return array
*/
public function getProductStockDetails(array $where = [], int $page = 1, int $limit = 20): array
{
$query = $this->getModel()->alias('item')
->leftJoin('stock_record record', 'item.record_id = record.id')
->leftJoin('store_product p', 'item.product_id = p.id')
->leftJoin('store_product_attr_value pav', 'item.sku_id = pav.unique')
->field([
'item.product_id',
'item.sku_id',
'p.store_name',
'p.image',
'pav.sku as sku_name',
'SUM(CASE WHEN record.type = 1 AND record.status = 2 THEN item.quantity ELSE 0 END) as in_stock',
'SUM(CASE WHEN record.type = 2 AND record.status = 2 THEN item.quantity ELSE 0 END) as out_stock',
'SUM(CASE WHEN record.type = 1 AND record.status = 2 THEN item.quantity ELSE -item.quantity END) as current_stock'
])
->group('item.product_id, item.sku_id')
->order('current_stock desc');
if (!empty($where['product_name'])) {
$query->where('p.store_name', 'like', '%' . $where['product_name'] . '%');
}
if (isset($where['low_stock']) && $where['low_stock']) {
$query->having('current_stock', '<', 10);
}
return $query->page($page, $limit)->select()->toArray();
}
/**
* 获取商品库存详情总数
* @param array $where
* @return int
*/
public function getProductStockDetailsCount(array $where = []): int
{
$query = $this->getModel()->alias('item')
->leftJoin('eb_stock_record record', 'item.record_id = record.id')
->leftJoin('store_product p', 'item.product_id = p.id')
->group('item.product_id, item.sku_id');
if (!empty($where['product_name'])) {
$query->where('p.store_name', 'like', '%' . $where['product_name'] . '%');
}
return $query->count();
}
/**
* 检查库存是否充足
* @param int $productId
* @param int $skuId
* @param int $quantity
* @return bool
*/
public function checkStockSufficient(int $productId, int $skuId, int $quantity): bool
{
$currentStock = $this->getCurrentStock($productId, $skuId);
return $currentStock >= $quantity;
}
/**
* 获取当前库存
* @param int $productId
* @param int $skuId
* @return int
*/
public function getCurrentStock(int $productId, int $skuId): int
{
$inStock = $this->getModel()->alias('item')
->leftJoin('eb_stock_record record', 'item.record_id = record.id')
->where('item.product_id', $productId)
->where('item.sku_id', $skuId)
->where('record.type', 1)
->where('record.status', 2)
->sum('item.quantity');
$outStock = $this->getModel()->alias('item')
->leftJoin('eb_stock_record record', 'item.record_id = record.id')
->where('item.product_id', $productId)
->where('item.sku_id', $skuId)
->where('record.type', 2)
->where('record.status', 2)
->sum('item.quantity');
return ($inStock ?: 0) - ($outStock ?: 0);
}
/**
* 获取库存预警列表
* @param int $warningStock
* @param int $page
* @param int $limit
* @return array
*/
public function getWarningStockList(int $warningStock = 10, int $page = 1, int $limit = 20): array
{
$query = $this->getModel()->alias('item')
->leftJoin('eb_stock_record record', 'item.record_id = record.id')
->leftJoin('store_product p', 'item.product_id = p.id')
->leftJoin('store_product_attr_value pav', 'item.sku_id = pav.unique')
->field([
'item.product_id',
'item.sku_id',
'p.store_name',
'p.image',
'pav.sku as sku_name',
'SUM(CASE WHEN record.type = 1 AND record.status = 2 THEN item.quantity ELSE 0 END) as in_stock',
'SUM(CASE WHEN record.type = 2 AND record.status = 2 THEN item.quantity ELSE 0 END) as out_stock',
'SUM(CASE WHEN record.type = 1 AND record.status = 2 THEN item.quantity ELSE -item.quantity END) as current_stock'
])
->group('item.product_id, item.sku_id')
->having('current_stock', '<', $warningStock)
->order('current_stock ASC');
$total = $query->count();
$list = $query->page($page, $limit)->select()->toArray();
return [
'list' => $list,
'total' => $total,
'page' => $page,
'limit' => $limit
];
}
}