初始化项目

This commit is contained in:
2026-09-01 22:15:50 +08:00
commit b5a26a8848
11217 changed files with 1710987 additions and 0 deletions
+72
View File
@@ -0,0 +1,72 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model;
use cores\BaseModel;
use think\model\relation\HasOne;
use think\model\relation\HasMany;
use think\model\relation\BelongsTo;
/**
* 公司用户池模型类
* Class User
* @package app\common\model
*/
class Account extends BaseModel
{
// 定义表名
protected $name = 'account';
// 定义主键
protected $pk = 'account_id';
/**
* 公司表
* @return \think\model\relation\BelongsTo
*/
public function company(): BelongsTo
{
$module = self::getCalledModule();
return $this->belongsTo("app\\{$module}\\model\\Company");
}
/**
* 获取用户信息
* @param $where
* @param array $with
* @return static|array|false|null
*/
public static function detail($where, array $with = [])
{
$filter = ['is_delete' => 0];
if (is_array($where)) {
$filter = array_merge($filter, $where);
} else {
$filter['account_id'] = (int)$where;
}
return static::get($filter, $with);
}
/**
* 指定的手机号是否已存在
* @param string $mobile
* @return bool
*/
public static function checkExistByMobile(string $mobile): bool
{
$model = new static;
return (bool)$model->where('mobile', '=', $mobile)
->where('is_delete', '=', 0)
->value($model->getPk());
}
}
+84
View File
@@ -0,0 +1,84 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model;
use cores\BaseModel;
/**
* 文章模型
* Class Article
* @package app\common\model
*/
class Article extends BaseModel
{
// 定义表名
protected $name = 'article';
// 定义主键
protected $pk = 'article_id';
// 追加字段
protected $append = ['show_views'];
/**
* 关联文章封面图
* @return \think\model\relation\HasOne
*/
public function image()
{
return $this->hasOne('UploadFile', 'file_id', 'image_id')
->bind(['image_url' => 'preview_url']);
}
/**
* 关联文章分类表
* @return \think\model\relation\BelongsTo
*/
public function category()
{
$module = self::getCalledModule();
return $this->BelongsTo("app\\{$module}\\model\\article\\Category", 'category_id');
}
/**
* 文章详情:HTML实体转换回普通字符
* @param $value
* @return string
*/
public function getContentAttr($value)
{
return htmlspecialchars_decode($value);
}
/**
* 展示的浏览次数
* @param $value
* @param $data
* @return mixed
*/
public function getShowViewsAttr($value, $data)
{
return $data['virtual_views'] + $data['actual_views'];
}
/**
* 文章详情
* @param int $articleId
* @param array $with
* @return array|null|static
*/
public static function detail(int $articleId, array $with = [])
{
return self::get($articleId, $with);
}
}
+84
View File
@@ -0,0 +1,84 @@
<?php
declare (strict_types=1);
namespace app\common\model;
use cores\BaseModel;
/**
* 银行账户模型
* Class Bank
* @package app\common\model
*/
class Bank extends BaseModel
{
protected $name = 'bank';
/**
* 关联管理员分类表
* @return \think\model\relation\BelongsTo
*/
public function admin()
{
return $this->belongsTo('app\common\model\store\User','store_user_id','store_user_id');
}
/**
* 获取银行账户列表
* @param int $status
* @param string $search_name
* @param string $sortType
* @param bool $sortPrice
* @param int $listRows
* @param array $power
* @return \think\Paginator
* @throws \think\exception\DbException
*/
public function getList($status = null, $search_name = '', $sortType = 'all', $sortPrice = false, $listRows = 15, $power = [])
{
// 筛选条件
$filter = [];
// 商品表名称
$status > 0 && $this->where('status', '=', $status);
!empty($power) && $this->where('store_user_id', 'in', $power);
!empty($search_name) && $this->where('name', 'like', "%$search_name%");
$r = $this->with(['admin'])
->order(['create_time' => 'desc'])
->paginate(15, false, [
'query' => \request()->request()
]);
return $r;
}
/**
* 关联供货商图片表
* @return \think\model\relation\HasMany
*/
public function image()
{
return $this->hasMany('SupplierImage')->order(['id' => 'asc']);
}
/**
* 银行账户详情
* @param $bank_id
* @return null|static
* @throws \think\exception\DbException
*/
public static function detail($bank_id)
{
return self::get($bank_id);
}
/*public static function detail($supplier_id)
{
$model = new static;
return $model->with([
'image.file'
])->where('supplier_id', '=', $supplier_id)->find();
}*/
/**
* 获取全部
* @return mixed
*/
public static function getAll()
{
$model = new static;
return $model->order(['bank_id' => 'asc'])->select();
}
}
+100
View File
@@ -0,0 +1,100 @@
<?php
namespace app\common\model;
use think\Model;
use think\Request;
use think\Session;
/**
* 模型基类
* Class BaseModel
* @package app\common\model
*/
class BaseModel extends Model
{
public static $wxapp_id;
public static $base_url;
/**
* 模型基类初始化
*/
public static function init()
{
parent::init();
// 获取当前域名
self::$base_url = base_url();
// 后期静态绑定wxapp_id
self::bindWxappId();
}
/**
* 获取当前调用的模块名称
* 例如:admin, api, store, task
* @return string|bool
*/
protected static function getCalledModule()
{
if (preg_match('/app\\\(\w+)/', get_called_class(), $class)) {
return $class[1];
}
return false;
}
/**
* 后期静态绑定类名称
* 用于定义全局查询范围的wxapp_id条件
* 子类调用方式:
* 非静态方法: self::$wxapp_id
* 静态方法中: $self = new static(); $self::$wxapp_id
*/
private static function bindWxappId()
{
if ($module = self::getCalledModule()) {
$callfunc = 'set' . ucfirst($module) . 'WxappId';
method_exists(new self, $callfunc) && self::$callfunc();
}
}
/**
* 设置wxapp_id (store模块)
*/
protected static function setStoreWxappId()
{
$session = Session::get('yoshop_store');
self::$wxapp_id = $session['wxapp']['wxapp_id'];
}
/**
* 设置wxapp_id (api模块)
*/
protected static function setApiWxappId()
{
$request = Request::instance();
self::$wxapp_id = $request->param('wxapp_id');
}
/**
* 获取当前域名
* @return string
*/
protected static function baseUrl()
{
$request = Request::instance();
$host = $request->scheme() . '://' . $request->host();
$dirname = dirname($request->baseUrl());
return empty($dirname) ? $host : $host . $dirname . '/';
}
/**
* 定义全局的查询范围
* @param \think\db\Query $query
*/
protected function base($query)
{
if (self::$wxapp_id > 0) {
$query->where($query->getTable() . '.wxapp_id', self::$wxapp_id);
}
}
}
+93
View File
@@ -0,0 +1,93 @@
<?php
declare (strict_types=1);
namespace app\common\model;
use app\store\model\store\User;
use cores\BaseModel;
/**
* 充值卡模型
* Class Card
* @package app\common\model
*/
class Card extends BaseModel
{
protected $name = 'card';
// 定义主键
protected $pk = 'card_id';
/**
* 关联用户表
* @return \think\model\relation\BelongsTo
*/
public function user()
{
return $this->belongsTo('app\common\model\User','user_id','user_id');
}
/**
* 获取器:图片地址
* @param $value
* @return string
*/
public function getFilePathAttr($value): string
{
return $value; // $value ? request()->domain().'/'.$value : ''
}
/**
* 充值卡详情
* @param $where
* @param array $with
* @return static|null
* @throws \think\exception\DbException
*/
public static function detail($where, $with = [])
{
!is_array($where) && $where = ['card_id' => (int)$where];
return static::get($where, $with);
}
/**
* 获取全部
* @param array $user
* @return mixed
*/
public static function getAll($user = [])
{
$model = new static;
if(isset($user['is_super']) && $user['is_super'] == 0) {
$users = User::getScope($user);
$model->where(function ($query) use($users) {
$query->where('store_user_id', 'in', $users);
});
return $model->order(['card_id' => 'asc'])->where(function ($query) use($users) {
$query->where('store_user_id', 'in', $users);
})->select();
}else{
return $model->order(['card_id' => 'asc'])->select();
}
}
/**
* 获取指定
* @param array $filter
* @return mixed
*/
public static function getQuery($filter): array
{
$model = new static;
return $model->where($filter)->order(['card_id' => 'asc'])->select()->toArray();
}
/**
* 切换使用状态
* @param $is_used
* @return false|int
*/
public function changeStatus($is_used)
{
return $this->save(['is_used' => $is_used]);
}
}
+49
View File
@@ -0,0 +1,49 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model;
use cores\BaseModel;
/**
* 模型类:购物车
* Class Cart
* @package app\common\model
*/
class Cart extends BaseModel
{
// 定义表名
protected $name = 'cart';
// 定义主键
protected $pk = 'id';
/**
* 详情记录
* @param int $userId 用户ID
* @param int $goodsId 商品ID
* @param string $goodsSkuId 商品sku唯一标识
* @return array|static|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function detail(int $userId, int $goodsId, string $goodsSkuId)
{
return (new static)->where('user_id', '=', $userId)
->where('goods_id', '=', $goodsId)
->where('goods_sku_id', '=', $goodsSkuId)
->where('is_delete', '=', 0)
->find();
}
}
+120
View File
@@ -0,0 +1,120 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model;
use cores\BaseModel;
/**
* 商品分类模型
* Class Category
* @package app\common\model
*/
class Category extends BaseModel
{
// 定义表名
protected $name = 'category';
// 定义主键
protected $pk = 'category_id';
/**
* 分类图片
* @return \think\model\relation\HasOne
*/
public function image()
{
return $this->hasOne('UploadFile', 'file_id', 'image_id');
}
/**
* 分类详情
* @param int|array $where
* @param array $with
* @return array|null|static
*/
public static function detail($where, array $with = [])
{
return static::get($where, $with);
}
/**
* 获取列表记录
* @param array $param
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $param = [])
{
$list = $this->getAll($param);
return $this->getTreeData($list);
}
/**
* 获取所有记录
* @param array $param
* @return \think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
protected function getAll(array $param = [])
{
// 默认查询参数
$params = $this->setQueryDefaultValue($param, [
'status' => -1 // 状态(1显示 0隐藏 -1全部)
]);
// 实例化新查询对象
$query = $this->getNewQuery();
// 设置检索条件
$filter = [];
$params['status'] > -1 && $filter[] = ['status', '=', $params['status']];
// !empty($params['province']) && $filter[] = ['province', 'like', "%{$params['province']}%"];
if(!empty($params['province'])){
$province = $params['province'];
$query->where(function ($que) use ($province) {
$que->whereOr([
['province', 'like', "%{$province}%"],
['province', '=','']
]);
});
}
// 查询列表数据
return $query->with(['image'])
->where($filter)
->order(['sort', 'create_time'])
->select();
}
/**
* 获取树状列表
* @param $list
* @param int $parentId
* @return array
*/
private function getTreeData($list, int $parentId = 0)
{
$data = [];
foreach ($list as $key => $item) {
if ($item['parent_id'] == $parentId) {
$children = $this->getTreeData($list, $item['category_id']);
!empty($children) && $item['children'] = $children;
$data[] = $item;
unset($list[$key]);
}
}
return $data;
}
}
+96
View File
@@ -0,0 +1,96 @@
<?php
declare (strict_types=1);
namespace app\common\model;
use cores\BaseModel;
use think\model\relation\BelongsTo;
/**
* 结账模型
* Class Checkout
* @package app\common\model
*/
class Checkout extends BaseModel
{
protected $name = 'checkout';
// 定义主键
protected $pk = 'checkout_id';
/**
* 获取结账人信息
* @return BelongsTo
*/
public function user(): BelongsTo
{
$module = self::getCalledModule();
return $this->belongsTo("app\\{$module}\\model\\store\\User", 'store_user_id');
}
/**
* 结账详情
* @param $where
* @param array $with
* @return static|null
* @throws \think\exception\DbException
*/
public static function detail($where, $with = [])
{
!is_array($where) && $where = ['checkout_id' => (int)$where];
return static::get($where, $with);
}
/**
* 获取全部
* @return mixed
*/
public static function getAll()
{
$model = new static;
return $model->order(['checkout_id' => 'asc'])->select();
}
/**
* 开始时间
* @param $value
* @return false|string
*/
public function getStartTimeAttr($value)
{
return format_time($value);
}
/**
* 结束时间
* @param $value
* @return false|string
*/
public function getEndTimeAttr($value)
{
return format_time($value);
}
/**
* 获取指定
* @param array $filter
* @return mixed
*/
public static function getQuery($filter): array
{
$model = new static;
return $model->where($filter)->order(['checkout_id' => 'asc'])->select()->toArray();
}
/**
* 获取最新一条记录
* @param array $filter
* @return array|null
*/
public static function getSingle(array $filter = []): ?array
{
$model = new static;
$data = $model->where($filter)->order(['checkout_id' => 'desc'])->find();
return $data ? $data->toArray() : null;
}
}
+70
View File
@@ -0,0 +1,70 @@
<?php
declare (strict_types=1);
namespace app\common\model;
use cores\BaseModel;
/**
* 产码模型
* Class User
* @package app\common\model
*/
class Code extends BaseModel
{
protected $name = 'code';
// 定义主键
protected $pk = 'code_id';
/**
* 支付码详情
* @param $where
* @param array $with
* @return static|null
* @throws \think\exception\DbException
*/
public static function detail($where, $with = [])
{
!is_array($where) && $where = ['code_id' => (int)$where];
return static::get($where, $with);
}
/**
* 关联父级用户
* @return \think\model\relation\BelongsTo
*/
public function shop()
{
return $this->belongsTo('Shop');
}
/**
* 关联父级用户
* @return \think\model\relation\BelongsTo
*/
public function user()
{
return $this->belongsTo('app\common\model\store\User','store_user_id','store_user_id');
}
/**
* 获取全部
* @return mixed
*/
public static function getAll()
{
$model = new static;
return $model->order(['shop_id' => 'asc'])->select();
}
/**
* 获取产码数量
* @param array $filter
* @return int|string
*/
public function getCodeTotal($filter=[])
{
return $this->field('code_id')
->where($filter)
->group('code_id')
->count();
}
}
+94
View File
@@ -0,0 +1,94 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model;
use cores\BaseModel;
/**
* 商品评价模型
* Class Comment
* @package app\common\model
*/
class Comment extends BaseModel
{
// 定义表名
protected $name = 'comment';
// 定义主键
protected $pk = 'comment_id';
/**
* 所属订单
* @return \think\model\relation\BelongsTo
*/
public function orderData()
{
return $this->belongsTo('Order');
}
/**
* 订单商品
* @return \think\model\relation\BelongsTo
*/
public function orderGoods()
{
return $this->belongsTo('OrderGoods')
->field(['order_goods_id', 'goods_id', 'goods_name', 'image_id', 'goods_props', 'order_id']);
}
/**
* 关联用户表
* @return \think\model\relation\BelongsTo
*/
public function user()
{
return $this->belongsTo('User')->field(['user_id', 'nick_name', 'avatar_id']);
}
/**
* 关联评价图片表
* @return \think\model\relation\HasMany
*/
public function images()
{
return $this->hasMany('CommentImage')->order(['id']);
}
/**
* 详情记录
* @param int $commentId
* @param array $with
* @return static|array|null
*/
public static function detail(int $commentId, array $with = [])
{
return static::get($commentId, $with);
}
/**
* 添加评论图片
* @param array $images
* @return array|false
*/
protected function addCommentImages(array $images)
{
$data = array_map(function ($imageId) {
return [
'image_id' => $imageId,
'store_id' => self::$storeId
];
}, $images);
return $this->image()->saveAll($data) !== false;
}
}
@@ -0,0 +1,41 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model;
use cores\BaseModel;
/**
* 商品评价图片模型
* Class CommentImage
* @package app\common\model
*/
class CommentImage extends BaseModel
{
// 定义表名
protected $name = 'comment_image';
// 定义主键
protected $pk = 'id';
protected $updateTime = false;
/**
* 关联文件库
* @return \think\model\relation\BelongsTo
*/
public function file()
{
return $this->belongsTo('UploadFile', 'image_id', 'file_id');
}
}
+99
View File
@@ -0,0 +1,99 @@
<?php
declare (strict_types=1);
namespace app\common\model;
use app\store\model\store\User;
use cores\BaseModel;
/**
* 商户模型
* Class Company
* @package app\common\model
*/
class Company extends BaseModel
{
protected $name = 'company';
// 定义主键
protected $pk = 'company_id';
/**
* 公司详情
* @param $where
* @param array $with
* @return static|null
* @throws \think\exception\DbException
*/
public static function detail($where, $with = [])
{
!is_array($where) && $where = ['company_id' => (int)$where];
return static::get($where, $with);
}
/**
* 获取全部
* @param array $user
* @return mixed
*/
public static function getAll($user = [])
{
$model = new static;
if(isset($user['is_super']) && $user['is_super'] == 0) {
$users = User::getScope($user);
$model->where(function ($query) use($users) {
$query->where('store_user_id', 'in', $users);
});
return $model->order(['company_id' => 'asc'])->where(function ($query) use($users) {
$query->where('store_user_id', 'in', $users);
})->select();
}else{
return $model->order(['company_id' => 'asc'])->select();
}
}
/**
* 获取指定
* @param array $filter
* @return mixed
*/
public static function getQuery($filter): array
{
$model = new static;
return $model->where($filter)->order(['company_id' => 'asc'])->select()->toArray();
}
/**
* 累积公司可用余额
* @param int $companyId
* @param float $money
* @return mixed
*/
public static function setIncBalance(int $companyId, float $money)
{
return (new static)->setInc($companyId, 'balance', $money);
}
/**
* 消减公司可用余额
* @param int $companyId
* @param float $money
* @return mixed
*/
public static function setDecBalance(int $companyId, float $money)
{
return (new static)->setDec([['company_id', '=', $companyId]], 'balance', $money);
}
/**
* 切换状态
* @param $status
* @return false|int
*/
public function changeStatus($status)
{
if($bool = $this->save(['status' => $status])){
$bool = true;
}
return $bool;
}
}
+159
View File
@@ -0,0 +1,159 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model;
use cores\BaseModel;
use app\common\library\helper;
/**
* 优惠券模型
* Class Coupon
* @package app\common\model
*/
class Coupon extends BaseModel
{
// 定义表名
protected $name = 'coupon';
// 定义主键
protected $pk = 'coupon_id';
/**
* 追加字段
* @var array
*/
protected $append = ['state'];
/**
* 优惠券状态 (是否可领取)
* @param $value
* @param array $data
* @return array
*/
public function getStateAttr($value, array $data): array
{
if (isset($data['is_receive']) && $data['is_receive']) {
return ['text' => '已领取', 'value' => 0];
}
if ($data['total_num'] > -1 && $data['receive_num'] >= $data['total_num']) {
return ['text' => '已抢光', 'value' => 0];
}
if ($data['expire_type'] == 20 && ($data['end_time'] + 86400) < time()) {
return ['text' => '已过期', 'value' => 0];
}
return ['text' => '正常', 'value' => 1];
}
/**
* 获取器:格式化折扣率
* @param $value
* @return float|int
*/
public function getDiscountAttr($value)
{
return $value / 10;
}
/**
* 获取器:开始时间
* @param $value
* @return string
*/
public function getStartTimeAttr($value): ?string
{
return $value ? date('Y/m/d', $value) : null;
}
/**
* 获取器:结束时间
* @param $value
* @return string
*/
public function getEndTimeAttr($value): ?string
{
return $value ? date('Y/m/d', $value) : null;
}
/**
* 获取器:适用范围配置
* @param $value
* @return mixed
*/
public function getApplyRangeConfigAttr($value)
{
return $value ? helper::jsonDecode($value) : [];
}
/**
* 修改器:格式化折扣率
* @param $value
* @return float|int
*/
public function setDiscountAttr($value)
{
return $value * 10;
}
/**
* 修改器:适用范围配置
* @param $array
* @return mixed
*/
public function setApplyRangeConfigAttr($array)
{
return helper::jsonEncode($array);
}
/**
* 优惠券详情
* @param int $couponId 优惠券ID
* @return static|null
*/
public static function detail(int $couponId): ?Coupon
{
return self::get($couponId);
}
/**
* 验证优惠券状态是否可领取
* @param $couponInfo
* @return bool
*/
public function checkReceive($couponInfo): bool
{
if (empty($couponInfo)) {
$this->error = '当前优惠券不存在';
return false;
}
if ($couponInfo['total_num'] > -1 && $couponInfo['receive_num'] >= $couponInfo['total_num']) {
$this->error = '优惠券已发完';
return false;
}
if ($couponInfo['expire_type'] == 20 && ($couponInfo->getData('end_time') + 86400) < time()) {
$this->error = '优惠券已过期';
return false;
}
return true;
}
/**
* 累计优惠券已领取的数量
* @param int $couponId
* @return mixed
*/
public static function setIncReceiveNum(int $couponId)
{
return (new static)->setInc($couponId, 'receive_num', 1);
}
}
+60
View File
@@ -0,0 +1,60 @@
<?php
declare (strict_types=1);
namespace app\common\model;
use cores\BaseModel;
/**
* 物流公司模型
* Class Express
* @package app\common\model
*/
class Deduct extends BaseModel
{
protected $name = 'deduct';
/**
* 获取全部
* @return mixed
*/
public static function getAll()
{
$model = new static;
return $model->order(['create_time' => 'asc'])->select();
}
/**
* 获取列表
* @return \think\Paginator
* @throws \think\exception\DbException
*/
public function getList()
{
return $this->order(['create_time' => 'asc'])
->paginate(15, false, [
'query' => Request::instance()->request()
]);
}
/**
* 扣减记录详情
* @param $deduct_id
* @return null|static
* @throws \think\exception\DbException
*/
public static function detail($deduct_id)
{
return self::get($deduct_id);
}
/**
* 获取抵扣总金额
* @param array $filter
* @return int|string
*/
public function getDeductTotalMoneyCustom($filter = [])
{
return $this->where($filter)
->sum('money');
}
}
+66
View File
@@ -0,0 +1,66 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model;
use cores\BaseModel;
/**
* 配送模板模型
* Class Delivery
* @package app\common\model
*/
class Delivery extends BaseModel
{
// 定义表名
protected $name = 'delivery';
// 定义主键
protected $pk = 'delivery_id';
/**
* 关联配送模板区域及运费
* @return \think\model\relation\HasMany
*/
public function rule()
{
return $this->hasMany('DeliveryRule');
}
/**
* 运费模板详情
* @param int $deliveryId
* @param array $with
* @return null|static
*/
public static function detail(int $deliveryId, array $with = [])
{
return self::get($deliveryId, ['rule']);
}
/**
* 获取列表(根据模板id集)
* @param array $deliveryIds
* @return \think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getListByIds(array $deliveryIds)
{
return $this->with(['rule'])
->where('delivery_id', 'in', $deliveryIds)
->order(['sort', $this->getPk()])
->select();
}
}
@@ -0,0 +1,73 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model;
use cores\BaseModel;
use app\common\library\helper;
/**
* 配送模板区域及运费模型
* Class DeliveryRule
* @package app\store\model
*/
class DeliveryRule extends BaseModel
{
// 定义表名
protected $name = 'delivery_rule';
// 定义主键
protected $pk = 'rule_id';
protected $updateTime = false;
/**
* 获取器:可配送区域转为数组格式
* @param $value
* @return array
*/
public function getRegionAttr(string $value)
{
return helper::jsonDecode($value);
}
/**
* 修改器:可配送区域转为json格式
* @param array $value
* @return string
*/
public function setRegionAttr(array $value)
{
return helper::jsonEncode($value);
}
/**
* 获取器:可配送区域(文字展示)转为数组格式
* @param $value
* @return array
*/
public function getRegionTextAttr(string $value)
{
return helper::jsonDecode($value);
}
/**
* 修改器:可配送区域转(文字展示)为json格式
* @param array $value
* @return string
*/
public function setRegionTextAttr(array $value)
{
return helper::jsonEncode($value);
}
}
+136
View File
@@ -0,0 +1,136 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model;
use cores\BaseModel;
use app\common\library\express\Kuaidi100;
use app\common\model\store\Setting as SettingModel;
use app\common\enum\Setting as SettingEnum;
/**
* 物流公司模型
* Class Express
* @package app\common\model
*/
class Express extends BaseModel
{
// 定义表名
protected $name = 'express';
// 定义主键
protected $pk = 'express_id';
/**
* 获取全部记录
* @param array $param
* @return \think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getAll($param = [])
{
// 检索查询条件
$filter = $this->getFilter($param);
// 查询列表数据
return $this->where($filter)->order(['sort', $this->getPk()])->select();
}
/**
* 获取列表
* @param array $param
* @return \think\Paginator
* @throws \think\db\exception\DbException
*/
public function getList($param = [])
{
// 检索查询调价你
$filter = $this->getFilter($param);
// 查询列表数据
return $this->where($filter)->order(['sort', 'express_id'])->paginate(15);
}
/**
* 检索查询条件
* @param array $param
* @return array
*/
private function getFilter($param = [])
{
// 默认查询条件
$params = $this->setQueryDefaultValue($param, ['search' => '']);
// 检索查询条件
$filter = [];
!empty($params['search']) && $filter[] = ['express_name', 'like', "%{$params['search']}%"];
return $filter;
}
/**
* 物流公司详情
* @param int $expressId
* @return null|static
*/
public static function detail(int $expressId)
{
return self::get($expressId);
}
/**
* 获取物流动态信息
* @param string $expressName
* @param string $expressCode
* @param string $expressNo
* @return false|string[]
* @throws \app\common\exception\BaseException
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function dynamic(string $expressName, string $expressCode, string $expressNo)
{
$data = [
'express_name' => $expressName,
'express_no' => $expressNo
];
// 获取快递100配置项
$config = $this->getKuaidi100Config();
// 实例化快递100类
$Kuaidi100 = new Kuaidi100($config);
// 请求查询接口
$data['list'] = $Kuaidi100->query($expressCode, $expressNo);
if ($data['list'] === false) {
$this->error = $Kuaidi100->getError();
return false;
}
return $data;
}
/**
* 获取快递100配置项
* @return mixed
* @throws \app\common\exception\BaseException
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
private function getKuaidi100Config()
{
// 实例化快递100类
$config = SettingModel::getItem(SettingEnum::DELIVERY);
if (empty($config['kuaidi100']['customer']) || empty($config['kuaidi100']['key'])) {
throwError('请先到后台-设置-配送方式 补充物流查询API配置');
}
return $config['kuaidi100'];
}
}
+392
View File
@@ -0,0 +1,392 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model;
use think\Paginator;
use think\model\Collection;
use think\model\relation\HasOne;
use cores\BaseModel;
use app\store\model\GoodsCategoryRel as GoodsCategoryRelModel;
use app\common\enum\goods\Status as GoodsStatusEnum;
use app\common\library\helper;
/**
* 商品模型
* Class Goods
* @package app\common\model
*/
class Goods extends BaseModel
{
// 定义表名
protected $name = 'goods';
// 定义主键
protected $pk = 'goods_id';
// 追加字段
protected $append = ['goods_sales'];
/**
* 关联模型:主图视频文件
* @return HasOne
*/
public function video(): HasOne
{
return $this->hasOne('UploadFile', 'file_id', 'video_id');
}
/**
* 关联模型:主图视频封面图片文件
* @return HasOne
*/
public function videoCover(): HasOne
{
return $this->hasOne('UploadFile', 'file_id', 'video_cover_id');
}
/**
* 计算显示销量 (初始销量 + 实际销量)
* @param $value
* @param $data
* @return mixed
*/
public function getGoodsSalesAttr($value, $data)
{
return $data['sales_initial'] + $data['sales_actual'];
}
/**
* 商品详情:HTML实体转换回普通字符
* @param $value
* @return string
*/
public function getContentAttr($value)
{
return htmlspecialchars_decode($value);
}
/**
* 获取器:单独设置折扣的配置
* @param $json
* @return mixed
*/
public function getAloneGradeEquityAttr($json)
{
return helper::jsonDecode($json);
}
/**
* 修改器:单独设置折扣的配置
* @param $data
* @return mixed
*/
public function setAloneGradeEquityAttr($data)
{
return helper::jsonEncode($data);
}
/**
* 获取器:优惠券关联
* @param $json
* @return mixed
*/
public function getCouponIdAttr($json)
{
return helper::jsonDecode($json);
}
/**
* 关联商品规格表
* @return \think\model\relation\HasMany
*/
public function skuList()
{
return $this->hasMany('GoodsSku')->order(['id' => 'asc']);
}
/**
* 关联商品规格关系表
* @return \think\model\relation\HasMany
*/
public function specRel()
{
return $this->hasMany('GoodsSpecRel');
}
/**
* 关联商品图片表
* @return \think\model\relation\HasMany
*/
public function images()
{
return $this->hasMany('GoodsImage')->order(['id']);
}
/**
* 关联运费模板表
* @return \think\model\relation\BelongsTo
*/
public function delivery()
{
return $this->BelongsTo('Delivery');
}
/**
* 关联订单评价表
* @return \think\model\relation\HasMany
*/
public function commentData()
{
return $this->hasMany('Comment');
}
/**
* 获取商品列表
* @param array $param 查询条件
* @param int $listRows 分页数量
* @return mixed
* @throws \think\db\exception\DbException
*/
public function getList(array $param = [], int $listRows = 15)
{
// 筛选条件
$query = $this->getQueryFilter($param);
// 设置显示的销量 goods_sales
$query->field(['(sales_initial + sales_actual) as goods_sales']);
// 排序条件
$sort = $this->setQuerySort($param);
// 执行查询
$list = $query->with(['images.file'])
->alias($this->name)
->field($this->getAliasFields($this->name, ['content']))
->where('is_delete', '=', 0)
->order($sort)
->paginate($listRows);
// 整理列表数据并返回
return $this->setGoodsListData($list);
}
/**
* 检索排序条件
* @param array $param
* @return array|string[]
*/
private function setQuerySort(array $param = [])
{
$params = $this->setQueryDefaultValue($param, [
'sortType' => 'all', // 排序类型
'sortPrice' => false, // 价格排序 (true高到低 false低到高)
]);
// 排序规则
$sort = [];
if ($params['sortType'] === 'all') {
$sort = ['sort' => 'asc'];
} elseif ($params['sortType'] === 'sales') {
$sort = ['goods_sales' => 'desc'];
} elseif ($params['sortType'] === 'price') {
$sort = $params['sortPrice'] ? ['goods_price_max' => 'desc'] : ['goods_price_min' => 'asc'];
}
return array_merge($sort, [$this->getPk() => 'desc']);
}
/**
* 检索查询条件
* @param array $param
* @return \think\db\BaseQuery
*/
private function getQueryFilter(array $param)
{
// 商品列表获取条件
$params = $this->setQueryDefaultValue($param, [
'listType' => 'all', // 列表模式 (全部:all 出售中:on_sale 已下架:off_sale 已售罄:sold_out)
'categoryId' => null, // 分类ID集
'goodsName' => null, // 商品名称
'goodsNo' => null, // 商品编码
'status' => 0, // 商品状态(0全部 10上架 20下架)
'province' => '', // 省份
'location' => '', // 是否通过地图过来
]);
// 实例化新查询对象
$query = $this->getNewQuery();
// 筛选条件
$filter = [];
// 列表模式
if ($params['listType'] === 'on_sale') {
$filter[] = ['status', '=', GoodsStatusEnum::ON_SALE]; // 出售中
} elseif ($params['listType'] === 'off_sale') {
$filter[] = ['status', '=', GoodsStatusEnum::OFF_SALE]; // 已下架
} elseif ($params['listType'] === 'sold_out') {
$filter[] = ['stock_total', '=', 0]; // 已售罄
}
// 商品状态
$params['status'] > 0 && $filter[] = ['status', '=', (int)$params['status']];
// 商品分类
if ($params['categoryId'] > 0) {
// 关联商品与分类关系记录表
$GoodsCategoryRelName = (new GoodsCategoryRelModel)->getName();
$query->join($GoodsCategoryRelName, "{$GoodsCategoryRelName}.goods_id = {$this->name}.goods_id");
// 设置分类ID条件
$query->where('goods_category_rel.category_id', '=', (int)$params['categoryId']);
}elseif(!empty($params['province']) && $params['location'] != 1){
// 前端请求,没有分类则不展示商品
// 关联商品与分类关系记录表
$GoodsCategoryRelName = (new GoodsCategoryRelModel)->getName();
$query->join($GoodsCategoryRelName, "{$GoodsCategoryRelName}.goods_id = {$this->name}.goods_id");
// 设置分类ID条件
$query->where('goods_category_rel.category_id', '=', -1);
}
// 商品名称
!empty($params['goodsName']) && $filter[] = ['goods_name', 'like', "%{$params['goodsName']}%"];
// 商品编码
!empty($params['goodsNo']) && $filter[] = ['goods_no', 'like', "%{$params['goodsNo']}%"];
// 省份
// !empty($params['province']) && $params['location'] == '1' && $filter[] = ['province', 'like', "%{$params['province']}%"];
if(!empty($params['province']) && $params['location'] == '1'){
$province = $params['province'];
$query->where(function ($que) use ($province) {
$que->whereOr([
['province', 'like', "%{$province}%"],
['province', '=','']
]);
});
}
// 实例化新查询对象
return $query->where($filter);
}
/**
* 设置商品展示的数据
* @param Collection|Paginator $list 商品列表
* @param callable|null $callback 回调函数
* @return mixed
*/
protected function setGoodsListData($list, callable $callback = null)
{
if ($list->isEmpty()) return $list;
// 遍历商品列表整理数据
foreach ($list as &$goods) {
$goods = $this->setGoodsData($goods, $callback);
}
return $list;
}
/**
* 整理商品数据
* @param Collection|static $goodsInfo
* @param callable|null $callback
* @return mixed
*/
protected function setGoodsData($goodsInfo, callable $callback = null)
{
// 商品图片列表
$goodsInfo['goods_images'] = helper::getArrayColumn($goodsInfo['images'], 'file');
// 商品主图
$goodsInfo['goods_image'] = current($goodsInfo['goods_images'])['preview_url'];
// 商品销量(实际显示=初始虚拟销量+实际销量)
$goodsInfo['goods_sales'] = $goodsInfo['sales_initial'] + $goodsInfo['sales_actual'];
// 回调函数
is_callable($callback) && call_user_func($callback, $goodsInfo);
return $goodsInfo->hidden(array_merge($this->hidden, ['specRel', 'images']));
}
/**
* 根据商品id集获取商品列表
* @param array $goodsIds
* @param null $status
* @return array|mixed
*/
public function getListByIds(array $goodsIds, $status = null)
{
// 筛选条件
$filter = [['goods_id', 'in', $goodsIds]];
// 商品状态
$status > 0 && $filter[] = ['status', '=', $status];
// 获取商品列表数据
$data = $this->withoutField(['content'])
->with(['images.file'])
->where($filter)
->where('is_delete', '=', 0)
->orderRaw('field(goods_id, ' . implode(',', $goodsIds) . ')')
->select();
// 整理列表数据并返回
return $this->setGoodsListData($data);
}
/**
* 商品多规格信息
* @param \think\Collection $specRel
* @param \think\Collection $skuData
* @return array
*/
public function getManySpecData($specRel, $skuData)
{
// spec_attr
$specAttrData = [];
foreach ($specRel as $item) {
if (!isset($specAttrData[$item['spec_id']])) {
$specAttrData[$item['spec_id']] = [
'group_id' => $item['spec']['spec_id'],
'name' => $item['spec']['spec_name'],
'spec_items' => [],
];
}
$specAttrData[$item['spec_id']]['spec_items'][] = [
'item_id' => $item['spec_value_id'],
'spec_value' => $item['spec_value'],
];
}
// spec_list
$specListData = [];
foreach ($skuData as $item) {
$image = (isset($item['images']) && !empty($item['images'])) ? $item['images'] : ['file_id' => 0, 'external_url' => ''];
$specListData[] = [
'id' => $item['id'],
'goods_sku_id' => $item['goods_sku_id'],
'rows' => [],
'form' => [
'image_id' => $image['file_id'],
'image_path' => $image['external_url'],
'goods_sku_no' => $item['goods_sku_no'],
'goods_price' => $item['goods_price'],
'goods_weight' => $item['goods_weight'],
'line_price' => $item['line_price'],
'stock_num' => $item['stock_num'],
],
];
}
return ['spec_attr' => array_values($specAttrData), 'spec_list' => $specListData];
}
/**
* 获取商品记录
* @param int|array $where
* @param array $with
* @return array|null|static
*/
public static function detail($where, array $with = [])
{
return static::get($where, $with);
}
/**
* 获取全部
* @param array $where
* @return mixed
*/
public static function getAll($where = [])
{
$model = new static;
return $model->order(['goods_id' => 'asc'])->where($where)->select();
}
}
@@ -0,0 +1,32 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model;
use cores\BaseModel;
/**
* 商品与分类关系模型
* Class GoodsCategoryRel
* @package app\common\model
*/
class GoodsCategoryRel extends BaseModel
{
// 定义表名
protected $name = 'goods_category_rel';
// 定义主键
protected $pk = 'id';
protected $updateTime = false;
}
@@ -0,0 +1,63 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model;
use cores\BaseModel;
use app\common\library\helper;
/**
* 商品关联优惠券模型
* Class GoodsCoupon
* @package app\common\model
*/
class GoodsCoupon extends BaseModel
{
// 定义表名
protected $name = 'goods_coupon';
// 定义主键
protected $pk = 'id';
/**
* 关联模型:优惠券
* @return \think\model\relation\HasOne
*/
public function coupon(): \think\model\relation\HasOne
{
return $this->hasOne('Coupon', 'id', 'coupon_id');
}
/**
* 获取优惠券信息详情
* @param int $goodsId
* @param string $goodsCouponId
* @return array|null|static
*/
public static function detail(int $goodsId, string $goodsCouponId)
{
return static::get(['goods_id' => $goodsId, 'coupon_id' => $goodsCouponId], ['coupon']);
}
/**
* 获取商品优惠券列表
* @param int $goodsId 商品ID
* @return \think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function getCouponList(int $goodsId): \think\Collection
{
return (new static)->where('goods_id', '=', $goodsId)->order(['id' => 'asc'])->select();
}
}
@@ -0,0 +1,41 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model;
use cores\BaseModel;
/**
* 商品图片模型
* Class GoodsImage
* @package app\common\model
*/
class GoodsImage extends BaseModel
{
// 定义表名
protected $name = 'goods_image';
// 定义主键
protected $pk = 'id';
protected $updateTime = false;
/**
* 关联文件库
* @return \think\model\relation\BelongsTo
*/
public function file()
{
return $this->belongsTo('UploadFile', 'image_id', 'file_id');
}
}
+103
View File
@@ -0,0 +1,103 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model;
use cores\BaseModel;
use app\common\library\helper;
/**
* 商品SKU模型
* Class GoodsSku
* @package app\common\model
*/
class GoodsSku extends BaseModel
{
// 定义表名
protected $name = 'goods_sku';
// 定义主键
protected $pk = 'id';
/**
* 关联模型:规格图片
* @return \think\model\relation\HasOne
*/
public function image(): \think\model\relation\HasOne
{
return $this->hasOne('UploadFile', 'file_id', 'image_id');
}
/**
* 获取器:规格值ID集
* @param $value
* @return array|mixed
*/
public function getSpecValueIdsAttr($value)
{
return helper::jsonDecode($value);
}
/**
* 获取器:规格属性
* @param $value
* @return array|mixed
*/
public function getGoodsPropsAttr($value)
{
return helper::jsonDecode($value);
}
/**
* 设置器:规格值ID集
* @param $value
* @return string
*/
public function setSpecValueIdsAttr($value): string
{
return helper::jsonEncode($value);
}
/**
* 设置器:规格属性
* @param $value
* @return string
*/
public function setGoodsPropsAttr($value): string
{
return helper::jsonEncode($value);
}
/**
* 获取sku信息详情
* @param int $goodsId
* @param string $goodsSkuId
* @return array|null|static
*/
public static function detail(int $goodsId, string $goodsSkuId)
{
return static::get(['goods_id' => $goodsId, 'goods_sku_id' => $goodsSkuId], ['image']);
}
/**
* 获取商品SKU列表
* @param int $goodsId 商品ID
* @return \think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function getSkuList(int $goodsId): \think\Collection
{
return (new static)->where('goods_id', '=', $goodsId)->select();
}
}
@@ -0,0 +1,89 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model;
use cores\BaseModel;
/**
* 商品规格关系模型
* Class GoodsSpecRel
* @package app\common\model
*/
class GoodsSpecRel extends BaseModel
{
// 定义表名
protected $name = 'goods_spec_rel';
// 定义主键
protected $pk = 'id';
protected $updateTime = false;
/**
* 关联规格组
* @return \think\model\relation\BelongsTo
*/
public function spec()
{
return $this->belongsTo('Spec');
}
/**
* 关联规格值
* @return \think\model\relation\BelongsTo
*/
public function specValue()
{
return $this->belongsTo('SpecValue');
}
/**
* 指定商品的规格列表
* @param int $goodsId 商品ID
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function getSpecList(int $goodsId)
{
// 获取指定商品的规格值关系记录
$data = (new static)->with(['spec', 'specValue'])
->where('goods_id', '=', $goodsId)
->select();
// 规格组
$groupData = [];
foreach ($data as $groupKey => $item) {
$groupData[$item['spec_id']] = [
'spec_id' => $item['spec']['spec_id'],
'spec_name' => $item['spec']['spec_name']
];
}
// 去除索引
$specList = array_values($groupData);
// 规格值
foreach ($specList as $groupKey => &$group) {
$group['key'] = $groupKey;
foreach ($data as $valueKey => $item) {
($item['spec_id'] == $group['spec_id']) && $group['valueList'][] = [
'key' => isset($group['valueList']) ? count($group['valueList']) : 0,
'groupKey' => $groupKey,
'spec_value_id' => $item['specValue']['spec_value_id'],
'spec_value' => $item['specValue']['spec_value']
];
}
}
return $specList;
}
}
+52
View File
@@ -0,0 +1,52 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model;
use cores\BaseModel;
/**
* 模型类:帮助中心
* Class Help
* @package app\common\model
*/
class Help extends BaseModel
{
// 定义表名
protected $name = 'help';
// 定义主键
protected $pk = 'help_id';
/**
* 获取列表记录
* @return \think\Paginator
* @throws \think\db\exception\DbException
*/
public function getList()
{
return $this->where('is_delete', '=', 0)
->order(['sort', $this->getPk()])
->paginate();
}
/**
* 帮助详情
* @param int $helpId
* @return null|static
*/
public static function detail(int $helpId)
{
return self::get($helpId);
}
}
+102
View File
@@ -0,0 +1,102 @@
<?php
declare (strict_types=1);
namespace app\common\model;
use app\store\model\store\User;
use cores\BaseModel;
use think\model\relation\BelongsTo;
/**
* 商户模型
* Class Merchant
* @package app\common\model
*/
class Merchant extends BaseModel
{
protected $name = 'merchant';
// 定义主键
protected $pk = 'merchant_id';
/**
* 获取上级经销商信息
* @return BelongsTo
*/
public function referrer(): BelongsTo
{
$module = self::getCalledModule();
return $this->belongsTo("app\\{$module}\\model\\Merchant", 'parent_merchant_id');
}
/**
* 商户详情
* @param $where
* @param array $with
* @return static|null
* @throws \think\exception\DbException
*/
public static function detail($where, $with = [])
{
!is_array($where) && $where = ['merchant_id' => (int)$where];
return static::get($where, $with);
}
/**
* 获取全部
* @param array $user
* @return mixed
*/
public static function getAll($user = [])
{
$model = new static;
if(isset($user['is_super']) && $user['is_super'] == 0) {
/*$users = User::getScope($user);
$arr = $user['merchant_id']?json_decode($user['merchant_id'],true):[];
return $model->order(['merchant_id' => 'asc'])->where(function ($query) use($users, $arr) {
$query->where('store_user_id', 'in', $users)
->whereOr('merchant_id', 'in', $arr);
})->select();*/
return $model->order(['merchant_id' => 'asc'])->where(function ($query) use($user) {
$query->where('merchant_id', '=', $user['merchant_id'])
->whereOr('parent_merchant_id', '=', $user['merchant_id']);
})->select();
}else{
return $model->order(['merchant_id' => 'asc'])->select();
}
}
/**
* 获取指定
* @param array $filter
* @return mixed
*/
public static function getQuery($filter): array
{
$model = new static;
return $model->where($filter)->order(['merchant_id' => 'asc'])->select()->toArray();
}
/**
* 累积商户可用余额
* @param int $merchantId
* @param float $money
* @return mixed
*/
public static function setIncBalance(int $merchantId, float $money)
{
return (new static)->setInc($merchantId, 'balance', $money);
}
/**
* 消减商户可用余额
* @param int $merchantId
* @param float $money
* @return mixed
*/
public static function setDecBalance(int $merchantId, float $money)
{
return (new static)->setDec([['merchant_id', '=', $merchantId]], 'balance', $money);
}
}
+28
View File
@@ -0,0 +1,28 @@
<?php
declare (strict_types=1);
namespace app\common\model;
use cores\BaseModel;
/**
* 通知类
* Class GoodsSku
* @package app\common\model
*/
class Notify extends BaseModel
{
protected $name = 'notify';
/**
* 通知详情
* @param $where
* @return null|static
* @throws \think\exception\DbException
*/
public static function detail($where)
{
is_array($where) ? $filter = $where : $filter['notify_id'] = (int)$where;
return self::get($filter);
}
}
+324
View File
@@ -0,0 +1,324 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model;
use cores\BaseModel;
use app\common\model\store\shop\Order as ShopOrder;
use app\common\service\Order as OrderService;
use app\common\service\order\Complete as OrderCompleteService;
use app\common\enum\OrderType as OrderTypeEnum;
use app\common\enum\order\PayStatus as PayStatusEnum;
use app\common\enum\order\OrderStatus as OrderStatusEnum;
use app\common\enum\order\DeliveryType as DeliveryTypeEnum;
use app\common\enum\order\DeliveryStatus as DeliveryStatusEnum;
use app\common\library\helper;
use think\model\relation\BelongsTo;
use think\model\relation\HasMany;
use think\model\relation\HasOne;
/**
* 订单模型
* Class Order
* @package app\common\model
*/
class Order extends BaseModel
{
// 定义表名
protected $name = 'order';
// 定义表名(外部引用)
public static $tableName = 'order';
// 定义主键
protected $pk = 'order_id';
// 定义别名
protected $alias = 'order';
/**
* 追加字段
* @var array
*/
protected $append = [
'state_text', // 售后单状态文字描述
];
/**
* 订单商品列表
* @return HasMany
*/
public function goods(): HasMany
{
$module = self::getCalledModule();
return $this->hasMany("app\\{$module}\\model\\OrderGoods")->withoutField('content');
}
/**
* 关联订单收货地址表
* @return HasOne
*/
public function address(): HasOne
{
$module = self::getCalledModule();
return $this->hasOne("app\\{$module}\\model\\OrderAddress");
}
/**
* 关联用户表
* @return BelongsTo
*/
public function user(): BelongsTo
{
$module = self::getCalledModule();
return $this->belongsTo("app\\{$module}\\model\\User");
}
/**
* 店铺用户表
* @return \think\model\relation\BelongsTo
*/
public function shop(): BelongsTo
{
$module = self::getCalledModule();
return $this->belongsTo("app\\{$module}\\model\\Shop");
}
/**
* 商户用户表
* @return \think\model\relation\BelongsTo
*/
public function merchant(): BelongsTo
{
$module = self::getCalledModule();
return $this->belongsTo("app\\{$module}\\model\\Merchant");
}
/**
* 关联物流公司表
* @return BelongsTo
*/
public function express(): BelongsTo
{
$module = self::getCalledModule();
return $this->belongsTo("app\\{$module}\\model\\Express");
}
/**
* 一级推广用户
* @return BelongsTo
*/
public function spreadOne(): BelongsTo
{
$module = self::getCalledModule();
return $this->belongsTo("app\\{$module}\\model\\Merchant", 'spread_uid');
}
/**
* 二级推广用户
* @return BelongsTo
*/
public function spreadTwo(): BelongsTo
{
$module = self::getCalledModule();
return $this->belongsTo("app\\{$module}\\model\\Merchant", 'spread_two_uid');
}
/**
* 订单状态文字描述
* @param $value
* @param array $data
* @return string
*/
public function getStateTextAttr($value, array $data): string
{
// 订单状态
// if (in_array($data['order_status'], [OrderStatusEnum::CANCELLED, OrderStatusEnum::COMPLETED])) {
// $orderStatus = [OrderStatusEnum::CANCELLED => '已取消', OrderStatusEnum::COMPLETED => '已完成'];
// return $orderStatus[$data['order_status']];
// }
// 订单状态
if ($data['order_status'] != OrderStatusEnum::NORMAL) {
return OrderStatusEnum::data()[$data['order_status']]['name'];
}
// 付款状态
if ($data['pay_status'] == PayStatusEnum::PENDING) {
return '待支付';
}
return OrderStatusEnum::data()[$data['order_status']]['name'];
// 订单类型:单独购买
// if ($data['delivery_status'] == 10) {
// return '待发货';
// }
// if ($data['receipt_status'] == 10) {
// return '待收货';
// }
return $value;
}
/**
* 获取器:订单金额(含优惠折扣)
* @param $value
* @param $data
* @return string
*/
public function getOrderPriceAttr($value, $data): string
{
// 兼容旧数据:订单金额
if ($value == 0) {
return helper::bcadd(helper::bcsub($data['total_price'], $data['coupon_money']), $data['update_price']);
}
return $value;
}
/**
* 改价金额(差价)
* @param $value
* @return array
*/
public function getUpdatePriceAttr($value): array
{
return [
'symbol' => $value < 0 ? '-' : '+',
'value' => sprintf('%.2f', abs((float)$value))
];
}
/**
* 付款时间
* @param $value
* @return false|string
*/
public function getPayTimeAttr($value)
{
return format_time($value);
}
/**
* 发货时间
* @param $value
* @return false|string
*/
public function getDeliveryTimeAttr($value)
{
return format_time($value);
}
/**
* 收货时间
* @param $value
* @return false|string
*/
public function getReceiptTimeAttr($value)
{
return format_time($value);
}
/**
* 有效期限
* @param $value
* @return false|string
*/
public function getExpirationTimeAttr($value)
{
return format_time($value);
}
/**
* 生成订单号
* @return string
*/
public function orderNo(): string
{
return OrderService::createOrderNo();
}
/**
* 订单详情
* @param $where
* @param array $with
* @return array|null|static
*/
public static function detail($where, array $with = [])
{
is_array($where) ? $filter = $where : $filter['order_id'] = (int)$where;
return self::get($filter, $with);
}
/**
* 批量获取订单列表
* @param array $orderIds
* @param array $with
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getListByIds(array $orderIds, array $with = []): array
{
$data = $this->getListByInArray('order_id', $orderIds, $with);
return helper::arrayColumn2Key($data, 'order_id');
}
/**
* 批量获取订单列表
* @param $field
* @param $data
* @param array $with
* @return \think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
private function getListByInArray($field, $data, array $with = []): \think\Collection
{
return $this->with($with)
->where($field, 'in', $data)
->where('is_delete', '=', 0)
->select();
}
/**
* 根据订单号批量查询
* @param $orderNos
* @param array $with
* @return \think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getListByOrderNos($orderNos, array $with = []): \think\Collection
{
return $this->getListByInArray('order_no', $orderNos, $with);
}
/**
* 批量更新订单
* @param $orderIds
* @param $data
* @return bool|false
*/
public function onBatchUpdate($orderIds, $data): bool
{
return static::updateBase($data, [['order_id', 'in', $orderIds]]);
}
/**
* 获取订单总金额
* @param array $filter
* @return int|string
*/
public function getOrderTotalPriceCustom($filter = [])
{
return $this->where($filter)
->sum('amount');
}
}
@@ -0,0 +1,75 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model;
use cores\BaseModel;
use app\common\model\Region as RegionModel;
/**
* 订单收货地址模型
* Class OrderAddress
* @package app\common\model
*/
class OrderAddress extends BaseModel
{
// 定义表名
protected $name = 'order_address';
// 定义主键
protected $pk = 'order_address_id';
protected $updateTime = false;
/**
* 追加字段
* @var array
*/
protected $append = ['region'];
/**
* 获取器:地区名称
* @param $value
* @param $data
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getRegionAttr($value, $data)
{
return [
'province' => RegionModel::getNameById($data['province_id']),
'city' => RegionModel::getNameById($data['city_id']),
'region' => RegionModel::getNameById($data['region_id'])
];
}
/**
* 获取完整地址
* @return string
*/
public function getFullAddress()
{
return $this['region']['province'] . $this['region']['city'] . $this['region']['region'] . $this['detail'];
}
/**
* 获取完整地址
* @param $detail
* @return string
*/
public static function fullAddress($detail)
{
return $detail['region']['province'] . $detail['region']['city'] . $detail['region']['region'] . $detail['detail'];
}
}
+111
View File
@@ -0,0 +1,111 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model;
use cores\BaseModel;
use app\common\library\helper;
/**
* 订单商品模型
* Class OrderGoods
* @package app\common\model
*/
class OrderGoods extends BaseModel
{
// 定义表名
protected $name = 'order_goods';
// 定义主键
protected $pk = 'order_goods_id';
protected $updateTime = false;
/**
* 订单商品图片
* @return \think\model\relation\BelongsTo
*/
public function image()
{
$model = "app\\common\\model\\UploadFile";
return $this->belongsTo($model, 'image_id', 'file_id')
->bind(['goods_image' => 'preview_url']);
}
/**
* 关联商品表
* @return \think\model\relation\BelongsTo
*/
public function goods()
{
return $this->belongsTo('Goods');
}
/**
* 关联订单主表
* @return \think\model\relation\BelongsTo
*/
public function orderM()
{
return $this->belongsTo('Order');
}
/**
* 售后单记录表
* @return \think\model\relation\HasOne
*/
public function refund()
{
return $this->hasOne('OrderRefund');
}
/**
* 获取器:规格属性
* @param $value
* @return array
*/
public function getGoodsPropsAttr($value)
{
return helper::jsonDecode($value);
}
/**
* 设置器:规格属性
* @param $value
* @return string
*/
public function setGoodsPropsAttr($value)
{
return $value ? helper::jsonEncode($value) : '';
}
/**
* 有效期限
* @param $value
* @return false|string
*/
public function getExpirationTimeAttr($value)
{
return format_time($value);
}
/**
* 订单商品详情
* @param $where
* @return OrderGoods|null
*/
public static function detail($where)
{
return static::get($where, ['image', 'refund']);
}
}
+104
View File
@@ -0,0 +1,104 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model;
use cores\BaseModel;
/**
* 售后单模型
* Class OrderRefund
* @package app\common\model\wxapp
*/
class OrderRefund extends BaseModel
{
// 定义表名
protected $name = 'order_refund';
// 定义主键
protected $pk = 'order_refund_id';
/**
* 关联用户表
* @return \think\model\relation\BelongsTo
*/
public function user()
{
return $this->belongsTo('User');
}
/**
* 关联订单主表
* @return \think\model\relation\BelongsTo
*/
public function orderData()
{
return $this->belongsTo('Order');
}
/**
* 关联订单商品表
* @return \think\model\relation\BelongsTo
*/
public function orderGoods()
{
return $this->belongsTo('OrderGoods')->withoutField(['content']);
}
/**
* 关联图片记录表
* @return \think\model\relation\HasMany
*/
public function images()
{
return $this->hasMany('OrderRefundImage');
}
/**
* 关联物流公司表
* @return \think\model\relation\BelongsTo
*/
public function express()
{
return $this->belongsTo('Express');
}
/**
* 关联用户表
* @return \think\model\relation\HasOne
*/
public function address()
{
return $this->hasOne('OrderRefundAddress');
}
/**
* 获取器:用户发货时间
* @param $value
* @return false|string
*/
public function getSendTimeAttr($value)
{
return format_time($value);
}
/**
* 售后单详情
* @param array|int $where
* @param array $with
* @return null|static
*/
public static function detail($where, array $with = [])
{
return static::get($where, $with);
}
}
@@ -0,0 +1,57 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model;
use cores\BaseModel;
use app\common\model\Region as RegionModel;
/**
* 售后单退货地址模型
* Class OrderRefundAddress
* @package app\common\model
*/
class OrderRefundAddress extends BaseModel
{
// 定义表名
protected $name = 'order_refund_address';
// 定义主键
protected $pk = 'id';
protected $updateTime = false;
/**
* 追加字段
* @var array
*/
protected $append = ['region'];
/**
* 获取器:地区名称
* @param $value
* @param $data
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getRegionAttr($value, $data)
{
return [
'province' => RegionModel::getNameById($data['province_id']),
'city' => RegionModel::getNameById($data['city_id']),
'region' => RegionModel::getNameById($data['region_id'])
];
}
}
@@ -0,0 +1,41 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model;
use cores\BaseModel;
/**
* 售后单图片模型
* Class OrderRefundImage
* @package app\common\model
*/
class OrderRefundImage extends BaseModel
{
// 定义表名
protected $name = 'order_refund_image';
// 定义主键
protected $pk = 'id';
protected $updateTime = false;
/**
* 关联文件库
* @return \think\model\relation\BelongsTo
*/
public function file()
{
return $this->belongsTo('UploadFile', 'image_id', 'file_id')->bind(['image_url' => 'preview_url']);
}
}
+406
View File
@@ -0,0 +1,406 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model;
use cores\BaseModel;
use app\common\library\helper;
use app\common\enum\page\PageType as PageTypeEnum;
/**
* 店铺页面模型
* Class Page
* @package app\common\model
*/
class Page extends BaseModel
{
// 定义表名
protected $name = 'page';
// 定义主键
protected $pk = 'page_id';
/**
* 获取器:格式化页面数据
* @param string $json
* @return array
*/
public function getPageDataAttr(string $json): array
{
// 数据转义
$array = helper::jsonDecode(htmlspecialchars_decode($json));
// 合并默认数据
return $this->_mergeDefaultData($array);
}
/**
* 修改器:自动转换data为json格式
* @param array $value
* @return string
*/
public function setPageDataAttr(array $value): string
{
return helper::jsonEncode($value ?: ['items' => []]);
}
/**
* 页面标题栏默认数据
* @return array
*/
public function getDefaultPage(): array
{
return [
'name' => '页面设置',
'type' => 'page',
'params' => [
'name' => '页面名称',
'title' => '页面标题',
'shareTitle' => '分享标题'
],
'style' => [
'titleTextColor' => 'black',
'titleBackgroundColor' => '#ffffff',
]
];
}
/**
* 页面diy元素默认数据
* @return array
*/
public function getDefaultItems()
{
return [
'search' => [
'name' => '搜索框',
'type' => 'search',
'params' => ['placeholder' => '请输入关键字进行搜索'],
'style' => [
'textAlign' => 'left',
'searchStyle' => 'square'
]
],
'banner' => [
'name' => '图片轮播',
'type' => 'banner',
'style' => [
'btnColor' => '#ffffff',
'btnShape' => 'round',
'interval' => 2.5
],
'data' => [
[
'imgUrl' => base_url() . 'assets/store/img/diy/banner/01.png',
'link' => null
],
[
'imgUrl' => base_url() . 'assets/store/img/diy/banner/01.png',
'link' => null
]
]
],
'image' => [
'name' => '图片',
'type' => 'image',
'style' => [
'paddingTop' => 0,
'paddingLeft' => 0,
'background' => '#ffffff'
],
'data' => [
[
'imgUrl' => base_url() . 'assets/store/img/diy/banner/01.png',
'imgName' => 'image-1.jpg',
'link' => null
]
]
],
'navBar' => [
'name' => '导航组',
'type' => 'navBar',
'style' => ['rowsNum' => 4, 'background' => '#ffffff', 'paddingTop' => 0, 'textColor' => '#666666'],
'data' => [
[
'imgUrl' => base_url() . 'assets/store/img/diy/navbar/01.png',
'imgName' => 'icon-1.png',
'link' => null,
'text' => '按钮文字1'
],
[
'imgUrl' => base_url() . 'assets/store/img/diy/navbar/01.png',
'imgName' => 'icon-2.jpg',
'link' => null,
'text' => '按钮文字2'
],
[
'imgUrl' => base_url() . 'assets/store/img/diy/navbar/01.png',
'imgName' => 'icon-3.jpg',
'link' => null,
'text' => '按钮文字3'
],
[
'imgUrl' => base_url() . 'assets/store/img/diy/navbar/01.png',
'imgName' => 'icon-4.jpg',
'link' => null,
'text' => '按钮文字4'
]
]
],
'blank' => [
'name' => '辅助空白',
'type' => 'blank',
'style' => [
'height' => 20,
'background' => '#ffffff'
]
],
'guide' => [
'name' => '辅助线',
'type' => 'guide',
'style' => [
'background' => '#ffffff',
'lineStyle' => 'solid',
'lineHeight' => 1,
'lineColor' => "#000000",
'paddingTop' => 10
]
],
'video' => [
'name' => '视频组',
'type' => 'video',
'params' => [
'videoUrl' => 'http://wxsnsdy.tc.qq.com/105/20210/snsdyvideodownload?filekey=30280201010421301f0201690402534804102ca905ce620b1241b726bc41dcff44e00204012882540400.mp4',
'poster' => base_url() . 'assets/store/img/diy/video_poster.png',
'autoplay' => 0
],
'style' => [
'paddingTop' => 0,
'height' => 190
]
],
'article' => [
'name' => '文章组',
'type' => 'article',
'params' => [
'source' => 'auto', // 数据来源 (choice指定 auto自动获取)
'auto' => [
'category' => -1, // -1全部
'showNum' => 6
]
],
// 'style' => [],
// '自动获取' => 默认数据
'defaultData' => [
[
'title' => '此处显示文章标题',
'show_type' => 10,
'image' => base_url() . 'assets/store/img/diy/article/01.png',
'views_num' => 309
],
[
'title' => '此处显示文章标题',
'show_type' => 10,
'image' => base_url() . 'assets/store/img/diy/article/01.png',
'views_num' => 309
]
],
// '手动选择' => 默认数据
'data' => []
],
'notice' => [
'name' => '店铺公告',
'type' => 'notice',
'params' => [
'text' => '这里是第一条自定义公告的标题', // 公告内容
// 'icon' => base_url() . 'assets/store/img/diy/notice.png',
'link' => null, // 链接
'showIcon' => true, // 是否显示图标
'scrollable' => true // 是否滚动
],
'style' => [
'paddingTop' => 0,
'background' => '#fffbe8',
'textColor' => '#de8c17'
]
],
'richText' => [
'name' => '富文本',
'type' => 'richText',
'params' => [
'content' => '<p>这里是文本的内容</p>'
],
'style' => [
'paddingTop' => 0,
'paddingLeft' => 0,
'background' => '#ffffff'
]
],
'window' => [
'name' => '图片橱窗',
'type' => 'window',
'style' => [
'paddingTop' => 0,
'paddingLeft' => 0,
'background' => '#ffffff',
'layout' => 2 // 布局方式: -1橱窗
],
'data' => [
[
'imgUrl' => base_url() . 'assets/store/img/diy/window/01.jpg',
'link' => null
],
[
'imgUrl' => base_url() . 'assets/store/img/diy/window/02.jpg',
'link' => null
],
[
'imgUrl' => base_url() . 'assets/store/img/diy/window/03.jpg',
'link' => null
],
[
'imgUrl' => base_url() . 'assets/store/img/diy/window/04.jpg',
'link' => null
]
],
'dataNum' => 4
],
'goods' => [
'name' => '商品组',
'type' => 'goods',
'params' => [
'source' => 'auto', // 数据来源 (choice手动选择 auto自动获取)
'auto' => [
'category' => 0, // 商品分类 0为全部
'goodsSort' => 'all', // 商品排序 (all默认 sales销量 price价格)
'showNum' => 6 // 显示数量
]
],
'style' => [
'background' => '#F6F6F6',
'display' => 'list', // 显示类型 (list列表平铺 slide横向滑动)
'column' => 2, // 分列数量
'show' => [ // 显示内容
'goodsName', 'goodsPrice', 'linePrice', 'sellingPoint', 'goodsSales'
]
],
// '自动获取' => 默认数据
'defaultData' => [
[
'goods_name' => '此处显示商品名称',
'goods_image' => base_url() . 'assets/store/img/diy/goods/01.png',
'goods_price_min' => '99.00',
'line_price_min' => '139.00',
'selling_point' => '此款商品美观大方 不容错过',
'goods_sales' => 100,
],
[
'goods_name' => '此处显示商品名称',
'goods_image' => base_url() . 'assets/store/img/diy/goods/01.png',
'goods_price_min' => '99.00',
'line_price_min' => '139.00',
'selling_point' => '此款商品美观大方 不容错过',
'goods_sales' => 100,
],
[
'goods_name' => '此处显示商品名称',
'goods_image' => base_url() . 'assets/store/img/diy/goods/01.png',
'goods_price_min' => '99.00',
'line_price_min' => '139.00',
'selling_point' => '此款商品美观大方 不容错过',
'goods_sales' => 100,
],
[
'goods_name' => '此处显示商品名称',
'goods_image' => base_url() . 'assets/store/img/diy/goods/01.png',
'goods_price_min' => '99.00',
'line_price_min' => '139.00',
'selling_point' => '此款商品美观大方 不容错过',
'goods_sales' => 100,
]
],
// '手动选择' => 默认数据
'data' => [
[
'goods_name' => '此处显示商品名称',
'goods_image' => base_url() . 'assets/store/img/diy/goods/01.png',
'goods_price_min' => '99.00',
'line_price_min' => '139.00',
'selling_point' => '此款商品美观大方 不容错过',
'goods_sales' => 100,
'is_default' => true
],
[
'goods_name' => '此处显示商品名称',
'goods_image' => base_url() . 'assets/store/img/diy/goods/01.png',
'goods_price_min' => '99.00',
'line_price_min' => '139.00',
'selling_point' => '此款商品美观大方 不容错过',
'goods_sales' => 100,
'is_default' => true
]
]
],
'service' => [
'name' => '在线客服',
'type' => 'service',
'params' => [
'type' => 'chat', // '客服类型' => chat在线聊天,phone拨打电话
'image' => base_url() . 'assets/store/img/diy/service.png',
'tel' => '' // 电话号吗
],
'style' => [
'right' => 1,
'bottom' => 10,
'opacity' => 100
]
],
];
}
/**
* diy页面详情
* @param int $pageId
* @return static|null
*/
public static function detail(int $pageId)
{
return static::get(['page_id' => $pageId]);
}
/**
* diy页面详情
* @return static|null
*/
public static function getHomePage()
{
return static::get(['page_type' => PageTypeEnum::HOME]);
}
/**
* 合并默认数据
* @param $array
* @return mixed
*/
private function _mergeDefaultData($array)
{
$array['page'] = array_merge_multiple($this->getDefaultPage(), $array['page']);
$defaultItems = $this->getDefaultItems();
foreach ($array['items'] as &$item) {
if (isset($defaultItems[$item['type']])) {
array_key_exists('data', $item) && $defaultItems[$item['type']]['data'] = [];
$item = array_merge_multiple($defaultItems[$item['type']], $item);
}
}
return $array;
}
}
+90
View File
@@ -0,0 +1,90 @@
<?php
declare (strict_types=1);
namespace app\common\model;
use app\store\model\store\User;
use cores\BaseModel;
/**
* 合作商模型
* Class Partners
* @package app\common\model
*/
class Partners extends BaseModel
{
protected $name = 'partners';
// 定义主键
protected $pk = 'partners_id';
/**
* 合作商详情
* @param $where
* @param array $with
* @return static|null
* @throws \think\exception\DbException
*/
public static function detail($where, $with = [])
{
!is_array($where) && $where = ['partners_id' => (int)$where];
return static::get($where, $with);
}
/**
* 获取全部
* @param array $user
* @return mixed
*/
public static function getAll($user = [])
{
$model = new static;
if(isset($user['is_super']) && $user['is_super'] == 0) {
$users = User::getScope($user);
$arr = $user['partners_id']?json_decode($user['partners_id'],true):[];
$model->where(function ($query) use($users, $arr) {
$query->where('store_user_id', 'in', $users)
->whereOr('partners_id', 'in', $arr);
});
return $model->order(['partners_id' => 'asc'])->where(function ($query) use($users, $arr) {
$query->where('store_user_id', 'in', $users)
->whereOr('partners_id', 'in', $arr);
})->select();
}else{
return $model->order(['partners_id' => 'asc'])->select();
}
}
/**
* 获取指定
* @param array $filter
* @return mixed
*/
public static function getQuery($filter): array
{
$model = new static;
return $model->where($filter)->order(['partners_id' => 'asc'])->select()->toArray();
}
/**
* 累积合作商可用余额
* @param int $partnersId
* @param float $money
* @return mixed
*/
public static function setIncBalance(int $partnersId, float $money)
{
return (new static)->setInc($partnersId, 'balance', $money);
}
/**
* 消减合作商可用余额
* @param int $partnersId
* @param float $money
* @return mixed
*/
public static function setDecBalance(int $partnersId, float $money)
{
return (new static)->setDec([['partners_id', '=', $partnersId]], 'balance', $money);
}
}
@@ -0,0 +1,85 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model;
use cores\BaseModel;
use app\common\library\helper;
/**
* 合作商关联商品券模型
* Class PartnersGoods
* @package app\common\model
*/
class PartnersGoods extends BaseModel
{
// 定义表名
protected $name = 'partners_goods';
// 定义主键
protected $pk = 'id';
/**
* 关联模型:商品
* @return \think\model\relation\HasOne
*/
public function goods(): \think\model\relation\HasOne
{
return $this->hasOne('Goods', 'id', 'goods_id');
}
/**
* 获取商品信息详情
* @param int $partnersId
* @param int $goodsId
* @return array|null|static
*/
public static function detail(int $partnersId, int $goodsId)
{
return static::get(['partners_id' => $partnersId, 'goods_id' => $goodsId]);
}
/**
* 获取合作商商品列表
* @param int $partnersId 合作商ID
* @return \think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function getGoodsList(int $partnersId): \think\Collection
{
return (new static)->where('partners_id', '=', $partnersId)->order(['id' => 'asc'])->select();
}
/**
* 累计合作商使用数量
* @param int|array $where
* @param int $num
* @return mixed
*/
public static function setIncUseNum($where, int $num)
{
return (new static)->setInc($where, 'use_num', $num);
}
/**
* 减少合作商库存数量
* @param int|array $where
* @param int $num
* @return mixed
*/
public static function setDecStockNum($where, int $num)
{
return (new static)->setDec($where, 'stock_num', $num);
}
}
+221
View File
@@ -0,0 +1,221 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model;
use cores\BaseModel;
use think\facade\Cache;
use app\common\library\helper;
/**
* 地区模型
* Class Region
* @package app\common\model
*/
class Region extends BaseModel
{
// 定义表名
protected $name = 'region';
// 定义主键
protected $pk = 'id';
protected $createTime = false;
protected $updateTime = false;
/**
* 类型自动转换
* @var array
*/
protected $type = [
'id' => 'integer',
'pid' => 'integer',
'level' => 'integer',
];
// 当前数据版本号
private static $version = '1.0.2';
/**
* 根据id获取地区名称
* @param int $id
* @return mixed|string
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function getNameById(int $id = 0)
{
if ($id == 0) {
return '其他';
}
$data = self::getCacheAll();
return isset($data[$id]) ? $data[$id]['name'] : '其他';
}
/**
* 获取所有地区(树状结构)
* @return array|mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function getCacheTree()
{
return static::getCacheData('tree');
}
/**
* 获取所有地区列表
* @return array|mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function getCacheAll()
{
return static::getCacheData('all');
}
/**
* 获取所有地区的总数
* @return array|mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function getCacheCounts()
{
return static::getCacheData('counts');
}
/**
* 获取缓存中的数据(存入静态变量)
* @param null $item
* @return array|mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
private static function getCacheData($item = null)
{
static $cacheData = [];
if (empty($cacheData)) {
$static = new static;
$cacheData = $static->regionCache();
}
if (is_null($item)) {
return $cacheData;
}
return $cacheData[$item];
}
/**
* 获取地区缓存
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
private function regionCache()
{
// 缓存的数据
$complete = Cache::get('region');
// 如果存在缓存则返回缓存的数据,否则从数据库中查询
// 条件1: 获取缓存数据
// 条件2: 数据版本号要与当前一致
if (
!empty($complete)
&& isset($complete['version'])
&& $complete['version'] == self::$version
) {
return $complete;
}
// 所有地区
$allList = $tempList = $this->getAllList();
// 已完成的数据
$complete = [
'all' => $allList,
'tree' => $this->getTreeList($allList),
'counts' => $this->getCount($allList),
'version' => self::$version,
];
// 写入缓存
Cache::tag('cache')->set('region', $complete);
return $complete;
}
/**
* 地区总数
* @param $allList
* @return array
*/
private static function getCount($allList)
{
$counts = [
'total' => count($allList),
'province' => 0,
'city' => 0,
'region' => 0,
];
$level = [1 => 'province', 2 => 'city', 3 => 'region'];
foreach ($allList as $item) {
$counts[$level[$item['level']]]++;
}
return $counts;
}
/**
* 格式化为树状格式
* @param $allList
* @return array
*/
private function getTreeList($allList)
{
$treeList = [];
foreach ($allList as $pKey => $province) {
if ($province['level'] == 1) { // 省份
$treeList[$province['id']] = $province;
unset($allList[$pKey]);
foreach ($allList as $cKey => $city) {
if ($city['level'] == 2 && $city['pid'] == $province['id']) { // 城市
$treeList[$province['id']]['city'][$city['id']] = $city;
unset($allList[$cKey]);
foreach ($allList as $rKey => $region) {
if ($region['level'] == 3 && $region['pid'] == $city['id']) { // 地区
$treeList[$province['id']]['city'][$city['id']]['region'][$region['id']] = $region;
unset($allList[$rKey]);
}
}
}
}
}
}
return $treeList;
}
/**
* 从数据库中获取所有地区
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
private function getAllList()
{
$list = self::withoutGlobalScope()
->field('id, pid, name, level')
->select()
->toArray();
return helper::arrayColumn2Key($list, 'id');
}
}
+116
View File
@@ -0,0 +1,116 @@
<?php
declare (strict_types=1);
namespace app\common\model;
use app\store\model\store\User;
use cores\BaseModel;
/**
* 商家用户模型
* Class User
* @package app\common\model
*/
class Shop extends BaseModel
{
// 定义表名
protected $name = 'shop';
// 定义主键
protected $pk = 'shop_id';
/**
* 关联管理员分类表
* @return \think\model\relation\BelongsTo
*/
public function admin()
{
return $this->belongsTo('app\common\model\store\User','store_user_id','store_user_id');
}
/**
* 店铺详情
* @param $where
* @param array $with
* @return static|null
* @throws \think\exception\DbException
*/
public static function detail($where, $with = [])
{
!is_array($where) && $where = ['shop_id' => (int)$where];
return static::get(array_merge(['is_delete' => 0], $where), $with);
}
/**
* 切换状态
* @param $status
* @return false|int
*/
public function setStatus($status)
{
if($status == 1 && $this['stop_date'] == date("Y-m-d")){
return '当天已到达收款上限,停止接单';
}
if($bool = $this->save(['status' => $status])){
$bool = true;
}
return $bool;
}
/**
* 获取全部
* @param array $user
* @return mixed
*/
public static function getAll($user = [])
{
$filter = [];
if(isset($user['is_super']) && $user['is_super'] == 0) {
$filter[] = ['store_user_id', 'in', User::getScope($user)];
}
$model = new static;
return $model->where('is_delete', '=', 0)->where($filter)->order(['shop_id' => 'asc'])->select();
}
/**
* 获取启用店铺
* @return mixed
*/
public static function getOnline()
{
$model = new static;
//在线,并且当天未停止接单
$data = $model->where('status', '=', 1)->where('stop_date', '!=', date('Y-m-d'))->order(['shop_id' => 'asc'])->select()->toArray();
return array_column($data,'shop_id');
}
/**
* 切换状态
* @param $status
* @return false|int
*/
public function changeStatus($status)
{
if($status == 1 && $this['stop_date'] == date("Y-m-d")){
return '当天已到达收款上限,停止接单';
}
if($bool = $this->save(['status' => $status])){
$bool = true;
}
return $bool;
}
/**
* 修改收款金额
* @param $data
* @return bool
*/
public function updateMoney($data)
{
if ($data['max_money'] <= 0) {
$this->error = '收款金额必须大于0';
return false;
}
return $this->save([
'max_money' => $data['max_money'],
]) !== false;
}
}
+32
View File
@@ -0,0 +1,32 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model;
use cores\BaseModel;
/**
* 规格/属性(组)模型
* Class Spec
* @package app\common\model
*/
class Spec extends BaseModel
{
// 定义表名
protected $name = 'spec';
// 定义主键
protected $pk = 'spec_id';
protected $updateTime = false;
}
+41
View File
@@ -0,0 +1,41 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model;
use cores\BaseModel;
/**
* 规格/属性(值)模型
* Class SpecValue
* @package app\common\model
*/
class SpecValue extends BaseModel
{
// 定义表名
protected $name = 'spec_value';
// 定义主键
protected $pk = 'spec_value_id';
protected $updateTime = false;
/**
* 关联规格组表
* @return $this|\think\model\relation\BelongsTo
*/
public function spec()
{
return $this->belongsTo('Spec');
}
}
+48
View File
@@ -0,0 +1,48 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model;
use cores\BaseModel;
/**
* 商家记录表模型
* Class Store
* @package app\common\model
*/
class Store extends BaseModel
{
// 定义表名
protected $name = 'store';
// 定义主键
protected $pk = 'store_id';
/**
* 关联logo图片
* @return \think\model\relation\HasOne
*/
public function logoImage()
{
return $this->hasOne('UploadFile', 'file_id', 'logo_image_id');
}
/**
* 详情信息
* @param int $storeId
* @return array|null|static
*/
public static function detail(int $storeId)
{
return self::get($storeId, ['logoImage']);
}
}
@@ -0,0 +1,89 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model;
use cores\BaseModel;
use app\common\enum\file\Storage as StorageEnum;
use app\common\enum\file\FileType as FileTypeEnum;
/**
* 文件库模型
* Class UploadFile
* @package app\common\model
*/
class UploadFile extends BaseModel
{
// 定义表名
protected $name = 'upload_file';
// 定义主键
protected $pk = 'file_id';
// 追加的字段
protected $append = [
'preview_url', // 预览url
'external_url' // 外链url
];
/**
* 关联文件库分组表
* @return \think\model\relation\BelongsTo
*/
public function uploadGroup()
{
return $this->belongsTo('UploadGroup', 'group_id');
}
/**
* 生成预览url (preview_url)
* @param $value
* @param $data
* @return string
*/
public function getPreviewUrlAttr($value, $data)
{
// 图片的预览图直接使用外链
if ($data['file_type'] == FileTypeEnum::IMAGE) {
return $this->getExternalUrlAttr($value, $data);
}
// 生成默认的预览图
$previewPath = FileTypeEnum::data()[$data['file_type']]['preview_path'];
return base_url() . $previewPath;
}
/**
* 生成外链url (external_url)
* @param $value
* @param $data
* @return string
*/
public function getExternalUrlAttr($value, $data)
{
// 存储方式本地:拼接当前域名
if ($data['storage'] === StorageEnum::LOCAL) {
$data['domain'] = rtrim(uploads_url(), '/');
}
return "{$data['domain']}/{$data['file_path']}";
}
/**
* 文件详情
* @param int $fileId
* @return static|array|null
*/
public static function detail(int $fileId)
{
return self::get($fileId);
}
}
@@ -0,0 +1,40 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model;
use cores\BaseModel;
/**
* 文件库分组模型
* Class UploadGroup
* @package app\common\model
*/
class UploadGroup extends BaseModel
{
// 定义表名
protected $name = 'upload_group';
// 定义主键
protected $pk = 'group_id';
/**
* 分组详情
* @param int|array $where
* @return static|array|null
*/
public static function detail($where)
{
return self::get($where);
}
}
+238
View File
@@ -0,0 +1,238 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model;
use cores\BaseModel;
use think\model\relation\HasOne;
use think\model\relation\HasMany;
use think\model\relation\BelongsTo;
use app\common\model\user\PointsLog as PointsLogModel;
/**
* 用户模型类
* Class User
* @package app\common\model
*/
class User extends BaseModel
{
// 定义表名
protected $name = 'user';
// 定义主键
protected $pk = 'user_id';
// 性别
private $gender = [0 => '未知', 1 => '男', 2 => '女'];
/**
* 关联用户头像表
* @return HasOne
*/
public function avatar(): HasOne
{
return $this->hasOne('UploadFile', 'file_id', 'avatar_id')
->bind(['avatar_url' => 'preview_url']);
}
/**
* 关联会员等级表
* @return BelongsTo
*/
public function grade(): BelongsTo
{
$module = self::getCalledModule();
return $this->belongsTo("app\\{$module}\\model\\user\\Grade", 'grade_id');
}
/**
* 商户用户表
* @return \think\model\relation\BelongsTo
*/
public function merchant(): BelongsTo
{
$module = self::getCalledModule();
return $this->belongsTo("app\\{$module}\\model\\Merchant");
}
/**
* 公司表
* @return \think\model\relation\BelongsTo
*/
public function company(): BelongsTo
{
$module = self::getCalledModule();
return $this->belongsTo("app\\{$module}\\model\\Company");
}
/**
* 关联收货地址表
* @return HasMany
*/
public function address(): HasMany
{
return $this->hasMany('UserAddress');
}
/**
* 关联收货地址表 (默认地址)
* @return BelongsTo
*/
public function addressDefault(): BelongsTo
{
return $this->belongsTo('UserAddress', 'address_id');
}
/**
* 获取器:显示性别
* @param $value
* @return string
*/
public function getGenderAttr($value): string
{
return $this->gender[$value];
}
/**
* 获取用户信息
* @param $where
* @param array $with
* @return static|array|false|null
*/
public static function detail($where, array $with = [])
{
$filter = ['is_delete' => 0];
if (is_array($where)) {
$filter = array_merge($filter, $where);
} else {
$filter['user_id'] = (int)$where;
}
return static::get($filter, $with);
}
/**
* 累积用户的实际消费金额
* @param int $userId
* @param float $expendMoney
* @return mixed
*/
public static function setIncUserExpend(int $userId, float $expendMoney)
{
return (new static)->setInc($userId, 'expend_money', $expendMoney);
}
/**
* 累积用户可用余额
* @param int $userId
* @param float $money
* @return mixed
*/
public static function setIncBalance(int $userId, float $money)
{
return (new static)->setInc($userId, 'balance', $money);
}
/**
* 消减用户可用余额
* @param int $userId
* @param float $money
* @return mixed
*/
public static function setDecBalance(int $userId, float $money)
{
return (new static)->setDec([['user_id', '=', $userId]], 'balance', $money);
}
/**
* 指定会员等级下是否存在用户
* @param int $gradeId
* @return bool
*/
public static function checkExistByGradeId(int $gradeId): bool
{
$model = new static;
return (bool)$model->where('grade_id', '=', (int)$gradeId)
->where('is_delete', '=', 0)
->value($model->getPk());
}
/**
* 指定的手机号是否已存在
* @param string $mobile
* @return bool
*/
public static function checkExistByMobile(string $mobile): bool
{
$model = new static;
return (bool)$model->where('mobile', '=', $mobile)
->where('is_delete', '=', 0)
->value($model->getPk());
}
/**
* 累积用户总消费金额
* @param int $userId
* @param float $money
* @return mixed
*/
public static function setIncPayMoney(int $userId, float $money)
{
return (new static)->setInc($userId, 'pay_money', $money);
}
/**
* 累积用户实际消费的金额 (批量)
* @param array $data
* @return bool
*/
public function onBatchIncExpendMoney(array $data): bool
{
foreach ($data as $userId => $expendMoney) {
static::setIncUserExpend($userId, (float)$expendMoney);
}
return true;
}
/**
* 累积用户的可用积分数量 (批量)
* @param array $data
* @return bool
*/
public function onBatchIncPoints(array $data): bool
{
foreach ($data as $userId => $value) {
$this->setInc($userId, 'points', $value);
}
return true;
}
/**
* 累积用户的可用积分
* @param int $userId 用户ID
* @param int $points 累计的积分
* @param string $describe 积分描述
* @param int|null $storeId
* @return mixed
*/
public static function setIncPoints(int $userId, int $points, string $describe, ?int $storeId = null)
{
// 新增积分变动明细
PointsLogModel::add([
'user_id' => $userId,
'value' => $points,
'describe' => $describe,
'store_id' => $storeId
]);
// 更新用户可用积分
return (new static)->setInc($userId, 'points', $points);
}
}
@@ -0,0 +1,55 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model;
use cores\BaseModel;
use app\common\model\Region as RegionModel;
/**
* 用户收货地址模型
* Class UserAddress
* @package app\common\model
*/
class UserAddress extends BaseModel
{
// 定义表名
protected $name = 'user_address';
// 定义主键
protected $pk = 'address_id';
/**
* 追加字段
* @var array
*/
protected $append = ['region'];
/**
* 获取器:地区名称
* @param $value
* @param $data
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getRegionAttr($value, $data)
{
return [
'province' => RegionModel::getNameById($data['province_id']),
'city' => RegionModel::getNameById($data['city_id']),
'region' => RegionModel::getNameById($data['region_id'])
];
}
}
+202
View File
@@ -0,0 +1,202 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model;
use cores\BaseModel;
use app\common\model\Coupon as CouponModel;
use app\common\library\helper;
use app\common\enum\coupon\ExpireType as ExpireTypeEnum;
use think\model\relation\BelongsTo;
/**
* 用户优惠券模型
* Class UserCoupon
* @package app\common\model
*/
class UserCoupon extends BaseModel
{
// 定义表名
protected $name = 'user_coupon';
// 定义主键
protected $pk = 'user_coupon_id';
/**
* 追加字段
* @var array
*/
protected $append = ['state'];
/**
* 关联用户表
* @return BelongsTo
*/
public function user(): BelongsTo
{
return $this->belongsTo('User');
}
/**
* 优惠券状态
* @param $value
* @param $data
* @return array
*/
public function getStateAttr($value, $data): array
{
if ($data['is_use']) {
return ['text' => '已使用', 'value' => 0];
}
if ($data['is_expire']) {
return ['text' => '已过期', 'value' => 0];
}
return ['text' => '正常', 'value' => 1];
}
/**
* 获取器:格式化折扣率
* @param $value
* @return float|int
*/
public function getDiscountAttr($value)
{
return $value / 10;
}
/**
* 有效期-开始时间
* @param $value
* @return string
*/
public function getStartTimeAttr($value): string
{
return date('Y/m/d', $value);
}
/**
* 有效期-结束时间
* @param $value
* @return string
*/
public function getEndTimeAttr($value): string
{
return date('Y/m/d', $value);
}
/**
* 获取器:适用范围配置
* @param $value
* @return mixed
*/
public function getApplyRangeConfigAttr($value)
{
return $value ? helper::jsonDecode($value) : [];
}
/**
* 修改器:格式化折扣率
* @param $value
* @return float|int
*/
public function setDiscountAttr($value)
{
return $value * 10;
}
/**
* 修改器:适用范围配置
* @param $array
* @return mixed
*/
public function setApplyRangeConfigAttr($array)
{
return helper::jsonEncode($array);
}
/**
* 优惠券详情
* @param $couponId
* @return null|static
*/
public static function detail($couponId)
{
return static::get($couponId);
}
/**
* 设置优惠券使用状态
* @param int $userCouponId 用户的优惠券ID
* @param bool $isUse 是否已使用
* @return bool|false
*/
public static function setIsUse(int $userCouponId, bool $isUse = true): bool
{
return static::updateBase(['is_use' => (int)$isUse], ['user_coupon_id' => $userCouponId]);
}
/**
* 验证指定用户是否已领取优惠券
* @param int $couponId 优惠券ID
* @param int $userId 用户ID
* @return bool
*/
public static function checktUserCoupon(int $couponId, int $userId): bool
{
return (bool)(new static)->where('coupon_id', '=', $couponId)
->where('user_id', '=', $userId)
->value('user_coupon_id');
}
/**
* 添加领取记录
* @param int $userId 用户ID
* @param CouponModel $couponInfo
* @return bool
*/
public function add(int $userId, CouponModel $couponInfo): bool
{
// 计算有效期
if ($couponInfo['expire_type'] == ExpireTypeEnum::RECEIVE) {
$startTime = time();
$endTime = $startTime + ($couponInfo['expire_day'] * 86400);
} else {
$startTime = $couponInfo->getData('start_time');
$endTime = $couponInfo->getData('end_time');
}
// 整理领取记录
$data = [
'coupon_id' => $couponInfo['coupon_id'],
'name' => $couponInfo['name'],
'coupon_type' => $couponInfo['coupon_type'],
'reduce_price' => $couponInfo['reduce_price'],
'discount' => $couponInfo['discount'],
'min_price' => $couponInfo['min_price'],
'expire_type' => $couponInfo['expire_type'],
'expire_day' => $couponInfo['expire_day'],
'start_time' => $startTime,
'end_time' => $endTime,
'apply_range' => $couponInfo['apply_range'],
'apply_range_config' => $couponInfo['apply_range_config'],
'user_id' => $userId,
'store_id' => self::$storeId
];
// 事务处理
return $this->transaction(function () use ($data, $couponInfo) {
// 添加领取记录
$this->save($data);
// 累计优惠券已领取的数量
CouponModel::setIncReceiveNum($couponInfo['coupon_id']);
return true;
});
}
}
+84
View File
@@ -0,0 +1,84 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model;
use cores\BaseModel;
/**
* 模型类:第三方用户信息
* Class UserOauth
* @package app\common\model
*/
class UserOauth extends BaseModel
{
// 定义表名
protected $name = 'user_oauth';
// 定义主键
protected $pk = 'id';
/**
* 根据openid获取用户ID
* @param string $oauthId 第三方用户唯一标识 (openid)
* @param string $oauthType 第三方登陆类型
* @return mixed
*/
public static function getUserIdByOauthId(string $oauthId, string $oauthType)
{
return (new static)->where('oauth_id', '=', $oauthId)
->where('oauth_type', '=', $oauthType)
->where('is_delete', '=', 0)
->value('user_id');
}
/**
* 根据用户ID获取OpenID
* @param int $userId 用户ID
* @param string $oauthType 第三方登陆类型
* @return mixed
*/
public static function getOauthIdByUserId(int $userId, string $oauthType)
{
return (new static)->where('user_id', '=', $userId)
->where('oauth_type', '=', $oauthType)
->where('is_delete', '=', 0)
->value('oauth_id');
}
/**
* 根据用户ID获取微信小程序OpenID
* @param int $userId 用户ID
* @return mixed
*/
public static function getMpWeiXinOpenId(int $userId)
{
return static::getOauthIdByUserId($userId, 'MP-WEIXIN');
}
/**
* 获取第三方用户信息
* @param int $userId 用户ID
* @param string $oauthType 第三方登陆类型
* @return array|\think\Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function getOauth(int $userId, string $oauthType)
{
return (new static)->where('user_id', '=', $userId)
->where('oauth_type', '=', $oauthType)
->find();
}
}
+47
View File
@@ -0,0 +1,47 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model;
use app\common\library\helper;
use cores\BaseModel;
use think\facade\Cache;
use app\common\exception\BaseException;
/**
* 微信小程序模型 (当前类已废弃,请勿使用)
* Class Wxapp
* @package app\common\model
*/
class Wxapp extends BaseModel
{
// 定义表名
protected $name = 'wxapp';
// 定义主键名
protected $pk = 'id';
/**
* 获取微信小程序配置 (即将废弃, 用于兼容v2.0.4之前)
* @param int|null $storeId
* @return array
*/
public static function getOldData(?int $storeId = null): array
{
empty($storeId) && $storeId = static::$storeId;
$detail = static::get(['store_id' => $storeId]);
if (empty($detail)) {
return [];
}
return helper::pick($detail->toArray(), ['app_id', 'app_secret', 'mchid', 'apikey', 'cert_pem', 'key_pem']);
}
}
@@ -0,0 +1,40 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model\admin;
use cores\BaseModel;
/**
* 超管后台用户模型
* Class User
* @package app\common\model\admin
*/
class User extends BaseModel
{
// 定义表名
protected $name = 'admin_user';
// 定义主键
protected $pk = 'admin_user_id';
/**
* 超管用户信息
* @param $id
* @return array|null|static
*/
public static function detail(int $id)
{
return static::get($id);
}
}
@@ -0,0 +1,55 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model\article;
use cores\BaseModel;
/**
* 文章分类模型
* Class Category
* @package app\common\model
*/
class Category extends BaseModel
{
// 定义表名
protected $name = 'article_category';
// 定义主键
protected $pk = 'category_id';
/**
* 分类详情
* @param int $categoryId
* @return static|null
*/
public static function detail(int $categoryId)
{
return static::get($categoryId);
}
/**
* 获取列表
* @param array $where
* @return \think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $where = [])
{
return $this->where($where)
->order(['sort', $this->getPk()])
->select();
}
}
@@ -0,0 +1,62 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model\card;
use cores\BaseModel;
/**
* 用户余额变动明细模型
* Class CardLog
* @package app\common\model\card
*/
class CardLog extends BaseModel
{
// 定义表名
protected $name = 'card_log';
// 定义主键
protected $pk = 'log_id';
protected $updateTime = false;
/**
* 关联会员记录表
* @return \think\model\relation\BelongsTo
*/
public function user()
{
$module = self::getCalledModule();
return $this->belongsTo("app\\{$module}\\model\\User");
}
/**
* 关联兑换卡表
* @return \think\model\relation\BelongsTo
*/
public function card()
{
$module = self::getCalledModule();
return $this->belongsTo("app\\{$module}\\model\\Card");
}
/**
* 新增记录
* @param array $data
*/
public static function add(array $data)
{
$model = new static;
$model->save($data);
}
}
@@ -0,0 +1,76 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model\card;
use cores\BaseModel;
/**
* 兑换卡打印模型
* Class CardPrint
* @package app\common\model\card
*/
class CardPrint extends BaseModel
{
// 定义表名
protected $name = 'card_print';
// 定义主键
protected $pk = 'print_id';
protected $updateTime = false;
/**
* 关联兑换卡表
* @return \think\model\relation\BelongsTo
*/
public function card()
{
$module = self::getCalledModule();
return $this->belongsTo("app\\{$module}\\model\\Card");
}
/**
* 获取器:下载时间
* @param $value
* @return string
*/
public function getDownloadTimeAttr($value)
{
return format_time($value);
}
/**
* 新增记录
* @param array $data
*/
public static function add(array $data)
{
$model = new static;
$model->save($data);
}
/**
* 充值卡打印详情
* @param $where
* @param array $with
* @return static|null
* @throws \think\exception\DbException
*/
public static function detail($where, $with = [])
{
!is_array($where) && $where = ['print_id' => (int)$where];
return static::get($where, $with);
}
}
@@ -0,0 +1,59 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model\company;
use cores\BaseModel;
use app\common\enum\company\balanceLog\Scene as SceneEnum;
/**
* 用户余额变动明细模型
* Class BalanceLog
* @package app\common\model\company
*/
class BalanceLog extends BaseModel
{
// 定义表名
protected $name = 'company_balance_log';
// 定义主键
protected $pk = 'log_id';
protected $updateTime = false;
/**
* 关联公司记录表
* @return \think\model\relation\BelongsTo
*/
public function company()
{
$module = self::getCalledModule();
return $this->belongsTo("app\\{$module}\\model\\Company");
}
/**
* 新增记录
* @param int $scene
* @param array $data
* @param array $describeParam
*/
public static function add(int $scene, array $data, array $describeParam)
{
$model = new static;
$model->save(array_merge([
'scene' => $scene,
'describe' => vsprintf(SceneEnum::data()[$scene]['describe'], $describeParam),
'store_id' => $model::$storeId
], $data));
}
}
@@ -0,0 +1,39 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model\goods;
use cores\BaseModel;
/**
* 商品服务与承诺模型
* Class Service
*/
class Service extends BaseModel
{
// 定义表名
protected $name = 'goods_service';
// 定义主键
protected $pk = 'service_id';
/**
* 帮助详情
* @param int $helpId
* @return null|static
*/
public static function detail(int $helpId)
{
return self::get($helpId);
}
}
@@ -0,0 +1,41 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model\goods;
use cores\BaseModel;
/**
* 商品服务与承诺模型
* Class ServiceRel
*/
class ServiceRel extends BaseModel
{
// 定义表名
protected $name = 'goods_service_rel';
// 定义主键
protected $pk = 'id';
protected $updateTime = false;
/**
* 获取商品服务与承诺ID集
* @param int $goodsId
* @return array
*/
public static function getServiceIds(int $goodsId)
{
return (new static)->where('goods_id', '=', $goodsId)->column('service_id');
}
}
+144
View File
@@ -0,0 +1,144 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model\h5;
use cores\BaseModel;
use think\facade\Cache;
use app\common\library\helper;
/**
* H5设置模型
* Class Setting
* @package app\common\model\h5
*/
class Setting extends BaseModel
{
// 定义表名
protected $name = 'h5_setting';
protected $createTime = false;
/**
* 获取器: 转义数组格式
* @param $value
* @return array
*/
public function getValuesAttr($value): array
{
return helper::jsonDecode($value);
}
/**
* 修改器: 转义成json格式
* @param $value
* @return string
*/
public function setValuesAttr($value): string
{
return helper::jsonEncode($value);
}
/**
* 获取指定项设置
* @param string $key
* @param int|null $storeId
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function getItem(string $key, ?int $storeId = null): array
{
$data = static::getAll($storeId);
return isset($data[$key]) ? $data[$key]['values'] : [];
}
/**
* 获取H5访问url
* @param int|null $storeId
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function getH5Url(?int $storeId = null)
{
return static::getItem('basic', $storeId)['baseUrl'];
}
/**
* 获取全部设置
* @param int|null $storeId
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function getAll(int $storeId = null): array
{
$model = new static;
is_null($storeId) && $storeId = static::$storeId;
if (!$data = Cache::get("h5_setting_{$storeId}")) {
// 获取全部设置
$setting = $model->getList($storeId);
$data = $setting->isEmpty() ? [] : helper::arrayColumn2Key($setting->toArray(), 'key');
// 写入缓存中
Cache::tag('cache')->set("h5_setting_{$storeId}", $data);
}
// 合并默认设置
return array_merge_multiple($model->defaultData(), $data);
}
/**
* 获取商城设置列表
* @param int $storeId
* @return \think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
private function getList(int $storeId): \think\Collection
{
return $this->where('store_id', '=', $storeId)->select();
}
/**
* 获取设置项信息
* @param string $key
* @return array|\think\Model|null
*/
public static function detail(string $key)
{
return static::get(compact('key'));
}
/**
* 默认配置
* @return array
*/
public function defaultData(): array
{
return [
'basic' => [
'key' => 'basic',
'describe' => '基础设置',
'values' => [
// 是否启用h5端访问 0=>关闭 1=>开启
'enabled' => 1,
// h5站点url [默认是当前访问的域名]
'baseUrl' => base_url(),
]
]
];
}
}
@@ -0,0 +1,59 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model\merchant;
use cores\BaseModel;
use app\common\enum\merchant\balanceLog\Scene as SceneEnum;
/**
* 用户余额变动明细模型
* Class BalanceLog
* @package app\common\model\merchant
*/
class BalanceLog extends BaseModel
{
// 定义表名
protected $name = 'merchant_balance_log';
// 定义主键
protected $pk = 'log_id';
protected $updateTime = false;
/**
* 关联商户记录表
* @return \think\model\relation\BelongsTo
*/
public function merchant()
{
$module = self::getCalledModule();
return $this->belongsTo("app\\{$module}\\model\\Merchant");
}
/**
* 新增记录
* @param int $scene
* @param array $data
* @param array $describeParam
*/
public static function add(int $scene, array $data, array $describeParam)
{
$model = new static;
$model->save(array_merge([
'scene' => $scene,
'describe' => vsprintf(SceneEnum::data()[$scene]['describe'], $describeParam),
'store_id' => $model::$storeId
], $data));
}
}
@@ -0,0 +1,76 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model\merchant;
use cores\BaseModel;
use think\model\relation\BelongsTo;
use think\model\relation\HasMany;
/**
* 用户余额变动明细模型
* Class MerchantOrder
* @package app\common\model\merchant
*/
class MerchantOrder extends BaseModel
{
// 定义表名
protected $name = 'merchant_order';
// 定义主键
protected $pk = 'merchant_order_id ';
protected $updateTime = false;
/**
* 关联商户记录表
* @return \think\model\relation\BelongsTo
*/
public function merchant()
{
$module = self::getCalledModule();
return $this->belongsTo("app\\{$module}\\model\\Merchant");
}
/**
* 关联用户表
* @return BelongsTo
*/
public function user(): BelongsTo
{
$module = self::getCalledModule();
return $this->belongsTo("app\\{$module}\\model\\User");
}
/**
* 订单商品列表
* @return BelongsTo
*/
public function goods(): BelongsTo
{
$module = self::getCalledModule();
return $this->belongsTo("app\\{$module}\\model\\Goods");
}
/**
* 新增代理商订单
* @param array $data
*/
public static function add(array $data)
{
$model = new static;
$model->save(array_merge([
'store_id' => $model::$storeId
], $data));
}
}
@@ -0,0 +1,59 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model\order;
use cores\BaseModel;
/**
* 订单导出Excel记录模型
* Class Export
* @package app\common\model\order
*/
class Export extends BaseModel
{
// 定义表名
protected $name = 'order_export';
// 定义主键
protected $pk = 'id';
/**
* 获取器:下单时间(开始)
* @param $value
* @return string
*/
public function getStartTimeAttr($value)
{
return format_time($value, false);
}
/**
* 获取器:下单时间(结束)
* @param $value
* @return string
*/
public function getEndTimeAttr($value)
{
return format_time($value, false);
}
/**
* 导出记录详情
* @param int $id
* @return array|null|static
*/
public static function detail(int $id)
{
return self::get($id);
}
}
@@ -0,0 +1,39 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model\order;
use cores\BaseModel;
/**
* 支付码记录
* Class QrCode
* @package app\common\model\order
*/
class QrCode extends BaseModel
{
// 定义表名
protected $name = 'order_qrcode';
// 定义主键
protected $pk = 'order_qrcode_id';
/**
* 导出记录详情
* @param int $id
* @return array|null|static
*/
public static function detail(int $id)
{
return self::get($id);
}
}
@@ -0,0 +1,39 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model\order;
use cores\BaseModel;
/**
* 分油通知记录模型
* Class Record
* @package app\common\model\order
*/
class Record extends BaseModel
{
// 定义表名
protected $name = 'order_record';
// 定义主键
protected $pk = 'order_record_id';
/**
* 导出记录详情
* @param int $id
* @return array|null|static
*/
public static function detail(int $id)
{
return self::get($id);
}
}
@@ -0,0 +1,59 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model\partners;
use cores\BaseModel;
use app\common\enum\partners\balanceLog\Scene as SceneEnum;
/**
* 用户余额变动明细模型
* Class BalanceLog
* @package app\common\model\partners
*/
class BalanceLog extends BaseModel
{
// 定义表名
protected $name = 'partners_balance_log';
// 定义主键
protected $pk = 'log_id';
protected $updateTime = false;
/**
* 关联商户记录表
* @return \think\model\relation\BelongsTo
*/
public function partners()
{
$module = self::getCalledModule();
return $this->belongsTo("app\\{$module}\\model\\Partners");
}
/**
* 新增记录
* @param int $scene
* @param array $data
* @param array $describeParam
*/
public static function add(int $scene, array $data, array $describeParam)
{
$model = new static;
$model->save(array_merge([
'scene' => $scene,
'describe' => vsprintf(SceneEnum::data()[$scene]['describe'], $describeParam),
'store_id' => $model::$storeId
], $data));
}
}
@@ -0,0 +1,81 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model\partners;
use cores\BaseModel;
use think\model\relation\BelongsTo;
/**
* 对接公司订单模型
* Class Order
* @package app\common\model\partners
*/
class Order extends BaseModel
{
// 定义表名
protected $name = 'partners_order';
// 定义主键
protected $pk = 'order_id';
/**
* 关联对接公司记录表
* @return \think\model\relation\BelongsTo
*/
public function partners()
{
$module = self::getCalledModule();
return $this->belongsTo("app\\{$module}\\model\\Partners");
}
/**
* 订单商品列表
* @return BelongsTo
*/
public function goods(): BelongsTo
{
$module = self::getCalledModule();
return $this->belongsTo("app\\{$module}\\model\\Goods");
}
/**
* 分油时间
* @param $value
* @return false|string
*/
public function getOilTimeAttr($value)
{
return format_time($value);
}
/**
* 使用时间
* @param $value
* @return false|string
*/
public function getUseTimeAttr($value)
{
return format_time($value);
}
/**
* 获取订单详情
* @param $where
* @return array|null|\think\Model
*/
public static function detail($where)
{
return static::get($where);
}
}
@@ -0,0 +1,54 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model\partners;
use cores\BaseModel;
/**
* 合作商库存变动记录
* Class StockLog
* @package app\common\model\partners
*/
class StockLog extends BaseModel
{
// 定义表名
protected $name = 'partners_stock_log';
// 定义主键
protected $pk = 'id';
protected $updateTime = false;
/**
* 关联合作商记录表
* @return \think\model\relation\BelongsTo
*/
public function partners()
{
$module = self::getCalledModule();
return $this->belongsTo("app\\{$module}\\model\\Partners");
}
/**
* 新增记录
* @param array $data
*/
public static function add(array $data)
{
$model = new static;
$model->save(array_merge([
'store_id' => $model::$storeId
], $data));
}
}
@@ -0,0 +1,69 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model\recharge;
use cores\BaseModel;
/**
* 用户充值订单模型
* Class Order
* @package app\common\model\recharge
*/
class Order extends BaseModel
{
// 定义表名
protected $name = 'recharge_order';
// 定义主键
protected $pk = 'order_id';
/**
* 关联会员记录表
* @return \think\model\relation\BelongsTo
*/
public function user()
{
$module = self::getCalledModule();
return $this->belongsTo("app\\{$module}\\model\\User");
}
/**
* 关联订单套餐快照表
* @return \think\model\relation\HasOne
*/
public function orderPlan()
{
return $this->hasOne('OrderPlan', 'order_id');
}
/**
* 付款时间
* @param $value
* @return array
*/
public function getPayTimeAttr($value)
{
return format_time($value);
}
/**
* 获取订单详情
* @param $where
* @return array|null|\think\Model
*/
public static function detail($where)
{
return static::get($where);
}
}
@@ -0,0 +1,30 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model\recharge;
use cores\BaseModel;
/**
* 用户充值订单套餐快照模型
* Class OrderPlan
* @package app\common\model\recharge
*/
class OrderPlan extends BaseModel
{
// 定义表名
protected $name = 'recharge_order_plan';
// 定义主键
protected $pk = 'order_plan_id';
}
@@ -0,0 +1,40 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model\recharge;
use cores\BaseModel;
/**
* 用户充值订单模型
* Class Plan
* @package app\common\model\recharge
*/
class Plan extends BaseModel
{
// 定义表名
protected $name = 'recharge_plan';
// 定义主键
protected $pk = 'plan_id';
/**
* 充值套餐详情
* @param $plan_id
* @return null|static
*/
public static function detail($plan_id)
{
return self::get($plan_id);
}
}
@@ -0,0 +1,98 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model\store;
use cores\BaseModel;
use app\common\model\Region as RegionModel;
/**
* 商家地址模型
* Class Address
* @package app\common\model\store
*/
class Address extends BaseModel
{
// 定义表名
protected $name = 'store_address';
// 定义主键
protected $pk = 'address_id';
/**
* 追加字段
* @var array
*/
protected $append = ['cascader', 'region', 'full_address'];
/**
* 省市区id集
* @param $value
* @param $data
* @return array
*/
public function getCascaderAttr($value, $data)
{
return [$data['province_id'], $data['city_id'], $data['region_id']];
}
/**
* 省市区名称集
* @param $value
* @param $data
* @return array
*/
public function getRegionAttr($value, $data)
{
return $this->getRegionNames($data);
}
/**
* 获取完整地址
* @return string
*/
public function getFullAddressAttr($value, $data)
{
$rgionNames = $this->getRegionNames($data);
return "{$rgionNames['province']}{$rgionNames['city']}{$rgionNames['region']}{$data['detail']}";
}
/**
* 获取省市区名称
* @param array $data
* @return mixed
*/
private function getRegionNames(array $data)
{
static $dataset = [];
$id = $data[$this->getPk()];
if (!isset($dataset[$id])) {
$dataset[$id] = [
'province' => RegionModel::getNameById($data['province_id']),
'city' => RegionModel::getNameById($data['city_id']),
'region' => RegionModel::getNameById($data['region_id']),
];
}
return $dataset[$id];
}
/**
* 详情记录
* @param int $addressId
* @return null|static
*/
public static function detail(int $addressId)
{
return self::get($addressId);
}
}
+72
View File
@@ -0,0 +1,72 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model\store;
use cores\BaseModel;
/**
* 商家后台API权限模型
* Class Api
* @package app\common\model\admin
*/
class Api extends BaseModel
{
// 定义表名
protected $name = 'store_api';
// 定义表主键
protected $pk = 'api_id';
/**
* 获取所有权限
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
protected static function getAll()
{
$data = static::withoutGlobalScope()
->order(['sort', 'create_time'])
->select();
return !$data->isEmpty() ? $data->toArray() : [];
}
/**
* 权限信息
* @param int|array $where
* @return array|null|static
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function detail($where)
{
$model = static::withoutGlobalScope();
is_array($where) ? $model->where($where) : $model->where('api_id', '=', $where);
return $model->find();
}
/**
* 获取指定ID集的url
* @param array $apiIds
* @return array
*/
public static function getApiUrls(array $apiIds)
{
return static::withoutGlobalScope()
->where('api_id', 'in', $apiIds)
->order(['sort', 'create_time'])
->column('url');
}
}
+141
View File
@@ -0,0 +1,141 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model\store;
use app\common\library\helper;
use cores\BaseModel;
/**
* 商家后台菜单模型
* Class Menu
* @package app\common\model\admin
*/
class Menu extends BaseModel
{
// 定义表名
protected $name = 'store_menu';
// 定义表主键
protected $pk = 'menu_id';
/**
* 关联操作权限
* @return \think\model\relation\HasMany
*/
public function menuApi()
{
return $this->hasMany('MenuApi', 'menu_id');
}
/**
* 获取菜单列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList()
{
$list = static::getAll();
return $this->getTreeData($list);
}
/**
* 获取所有菜单
* @param array $where
* @return \think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
protected static function getAll(array $where = [])
{
// 菜单列表
$model = (new static)->addHidden(['menuApi']);
$list = static::withoutGlobalScope()
->with(['menuApi'])
->where($where)
->order(['sort' => 'asc', 'create_time' => 'asc'])
->select();
// 整理菜单绑定的apiID集
return $model->getMenuApiIds($list);
}
/**
* 获取树状菜单列表
* @param $menuList
* @param int $parentId
* @return array
*/
protected function getTreeData($menuList, int $parentId = 0)
{
$data = [];
foreach ($menuList as $key => $item) {
if ($item['parent_id'] == $parentId) {
$children = $this->getTreeData($menuList, (int)$item['menu_id']);
!empty($children) && $item['children'] = $children;
$data[] = $item;
unset($menuList[$key]);
}
}
return $data;
}
/**
* 整理菜单的api ID集
* @param $menuList
* @return mixed
*/
private function getMenuApiIds($menuList)
{
foreach ($menuList as &$item) {
if (!empty($item['menuApi'])) {
$item['apiIds'] = helper::getArrayColumn($item['menuApi'], 'api_id');
}
}
return $menuList;
}
/**
* 菜单信息
* @param int|array $where
* @return array|null|static
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function detail($where)
{
$query = static::withoutGlobalScope();
is_array($where) ? $query->where($where) : $query->where('menu_id', '=', $where);
return $query->find();
}
/**
* 获取菜单url集
* @param $menuIds
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function getMenuUrls($menuIds)
{
$urls = [];
foreach (static::getAll() as $item) {
in_array($item['menu_id'], $menuIds) && $urls[] = $item['url'];
}
return $urls;
}
}
@@ -0,0 +1,35 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model\store;
use cores\BaseModel;
/**
* 商家后台用户角色与菜单权限关系表模型
* Class MenuApi
* @package app\common\model\store
*/
class MenuApi extends BaseModel
{
// 定义表名
protected $name = 'store_menu_api';
// 定义表主键
protected $pk = 'id';
protected $updateTime = false;
// 不允许全局查询store_id
protected $isGlobalScopeStoreId = false;
}
@@ -0,0 +1,58 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model\store;
use cores\BaseModel;
/**
* 商家用户角色模型
* Class Role
* @package app\common\model\admin
*/
class Role extends BaseModel
{
// 定义表名
protected $name = 'store_role';
// 定义主键
protected $pk = 'role_id';
/**
* 关联操作权限
* @return \think\model\relation\HasMany
*/
public function roleMenu()
{
return $this->hasMany('RoleMenu', 'role_id');
}
/**
* 关联创建人
* @return \think\model\relation\HasMany
*/
public function storeUser()
{
return $this->hasOne('User', 'store_user_id','store_user_id');
}
/**
* 角色信息
* @param $where
* @return array|null|static
*/
public static function detail($where)
{
return static::get($where);
}
}
@@ -0,0 +1,29 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model\store;
use cores\BaseModel;
/**
* 商家后台用户角色与菜单权限关系模型
* Class RoleAccess
* @package app\common\model\admin
*/
class RoleMenu extends BaseModel
{
// 定义表名
protected $name = 'store_role_menu';
protected $updateTime = false;
}
@@ -0,0 +1,328 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model\store;
use think\facade\Cache;
use app\common\library\helper;
use cores\BaseModel;
use app\common\enum\Setting as SettingEnum;
use app\common\enum\file\Storage as StorageEnum;
use app\common\enum\order\DeliveryType as DeliveryTypeEnum;
use app\common\enum\setting\sms\Scene as SettingSmsSceneEnum;
use app\common\enum\store\page\category\Style as PageCategoryStyleEnum;
/**
* 系统设置模型
* Class Setting
* @package app\common\model
*/
class Setting extends BaseModel
{
// 定义表名
protected $name = 'store_setting';
/**
* 获取器: 转义数组格式
* @param $value
* @return mixed
*/
public function getValuesAttr($value)
{
return helper::jsonDecode($value);
}
/**
* 修改器: 转义成json格式
* @param $value
* @return string
*/
public function setValuesAttr($value): string
{
return helper::jsonEncode($value);
}
/**
* 获取指定项设置
* @param string $key
* @param int|null $storeId
* @return array|mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function getItem(string $key, int $storeId = null)
{
$data = self::getAll($storeId);
return isset($data[$key]) ? $data[$key]['values'] : [];
}
/**
* 获取设置项信息
* @param string $key
* @param int|null $storeId
* @return array|\think\Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function detail(string $key, int $storeId = null)
{
$query = (new static)->getNewQuery();
$storeId > 0 && $query->where('store_id', '=', $storeId);
return $query->where('key', '=', $key)->find();
}
/**
* 全局缓存: 系统设置
* @param int|null $storeId
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function getAll(int $storeId = null): array
{
$model = new static;
is_null($storeId) && $storeId = static::$storeId;
if (!$data = Cache::get("setting_{$storeId}")) {
// 获取商城设置列表
$setting = $model->getList($storeId);
$data = $setting->isEmpty() ? [] : helper::arrayColumn2Key($setting->toArray(), 'key');
// 写入缓存中
Cache::tag('cache')->set("setting_{$storeId}", $data);
}
// 合并默认设置
return array_merge_multiple($model->defaultData(), $data);
}
/**
* 获取商城设置列表
* @param $storeId
* @return \think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
private function getList(int $storeId)
{
return $this->where('store_id', '=', $storeId)->select();
}
/**
* 默认配置
* @return array
*/
public function defaultData(): array
{
return [
// 配送设置
SettingEnum::DELIVERY => [
'key' => SettingEnum::DELIVERY,
'describe' => '配送设置',
'values' => [
// 配送方式
'delivery_type' => array_keys(DeliveryTypeEnum::data()),
// 快递100
'kuaidi100' => [
'customer' => '',
'key' => '',
]
],
],
// 交易设置
SettingEnum::TRADE => [
'key' => SettingEnum::TRADE,
'describe' => '交易设置',
'values' => [
// 订单流程设置
'order' => [
// 'close_days' => '3', // 已废弃
'closeHours' => 3 * 24, // 未支付订单自动关闭期限(单位:小时)
'receive_days' => '10',
'refund_days' => '7'
],
// 运费组合策略
'freight_rule' => '10',
'expiration_time' => '18000',
]
],
// 上传设置
SettingEnum::STORAGE => [
'key' => SettingEnum::STORAGE,
'describe' => '上传设置',
'values' => [
'default' => StorageEnum::LOCAL,
'engine' => [
StorageEnum::LOCAL => null,
StorageEnum::QINIU => [
'bucket' => '',
'access_key' => '',
'secret_key' => '',
'domain' => 'http://'
],
StorageEnum::ALIYUN => [
'bucket' => '',
'access_key_id' => '',
'access_key_secret' => '',
'domain' => 'http://'
],
StorageEnum::QCLOUD => [
'bucket' => '',
'region' => '',
'secret_id' => '',
'secret_key' => '',
'domain' => 'http://'
],
]
],
],
// 短信通知
SettingEnum::SMS => [
'key' => SettingEnum::SMS,
'describe' => '短信通知',
'values' => [
'default' => 'aliyun',
// 短信服务渠道
'engine' => [
// 阿里云
'aliyun' => [
'name' => '阿里云短信',
'website' => 'https://dysms.console.aliyun.com/dysms.htm',
'AccessKeyId' => '',
'AccessKeySecret' => '',
'sign' => '萤火商城' // 短信签名
],
// 腾讯云
'qcloud' => [
'name' => '腾讯云短信',
'website' => 'https://console.cloud.tencent.com/smsv2',
'SdkAppID' => '',
'AccessKeyId' => '',
'AccessKeySecret' => '',
'sign' => '萤火商城' // 短信签名
],
// 七牛云
'qiniu' => [
'name' => '七牛云短信',
'website' => 'https://portal.qiniu.com/sms/dashboard',
'AccessKey' => '',
'SecretKey' => '',
'sign' => '萤火商城' // 短信签名
],
],
// 短信通知场景
'scene' => [
// 短信验证码
SettingSmsSceneEnum::CAPTCHA => [
'name' => '短信验证码 (通知用户)', // 场景名称
'isEnable' => false, // 是否开启
'templateCode' => '', // 模板ID
'content' => '验证码%s,您正在进行身份验证,打死不要告诉别人哦!',
'variables' => [
'aliyun' => ['${code}'],
'qiniu' => ['${code}'],
'qcloud' => ['{1}'],
]
],
// 新付款订单
SettingSmsSceneEnum::ORDER_PAY => [
'name' => '新付款订单 (通知商家)', // 场景名称
'isEnable' => false, // 是否开启
'templateCode' => '', // 模板ID
'acceptPhone' => '', // 接收手机号
'content' => '您有一条新订单,订单号为:%s,请注意查看',
'variables' => [
'aliyun' => ['${order_no}'],
'qiniu' => ['${order_no}'],
'qcloud' => ['{1}'],
]
],
]
],
],
// 满额包邮设置
SettingEnum::FULL_FREE => [
'key' => SettingEnum::FULL_FREE,
'describe' => '满额包邮设置',
'values' => [
'is_open' => 0, // 是否开启满额包邮
'money' => '', // 单笔订单额度
'excludedRegions' => [ // 不参与包邮的地区
'cityIds' => [], // 城市ID集
'selectedText' => '' // 选择的地区(文字)
],
'excludedGoodsIds' => [], // 不参与包邮的商品 (ID集)
'describe' => '' // 满额包邮说明
],
],
// 账户注册设置
SettingEnum::REGISTER => [
'key' => SettingEnum::REGISTER,
'describe' => '账户注册设置',
'values' => [
'registerMethod' => 10, // 默认注册方式: 10=>手机号+短信验证码
'isOauthMpweixin' => 1, // 是否开启微信小程序一键授权登录
'isForceBindMpweixin' => 1, // 客户端是否强制绑定手机号(微信小程序)
'isManualBind' => 1, // 个人中心页显示手动绑定手机号
],
],
// 用户充值设置
SettingEnum::RECHARGE => [
'key' => SettingEnum::RECHARGE,
'describe' => '用户充值设置',
'values' => [
'is_entrance' => 1, // 是否允许用户充值
'is_custom' => 1, // 是否允许自定义金额
'lowest_money' => 10, // 最低充值金额
'is_match_plan' => 1, // 自定义金额是否自动匹配合适的套餐
'describe' => "1. 账户充值仅限微信在线方式支付,充值金额实时到账;\n" .
"2. 账户充值套餐赠送的金额即时到账;\n" .
"3. 账户余额有效期:自充值日起至用完即止;\n" .
"4. 若有其它疑问,可拨打客服电话400-000-1234", // 充值说明
],
],
// 积分设置
SettingEnum::POINTS => [
'key' => SettingEnum::POINTS,
'describe' => SettingEnum::data()[SettingEnum::POINTS]['describe'],
'values' => [
'points_name' => '积分', // 积分名称自定义
'is_shopping_gift' => 0, // 是否开启购物送积分
'gift_ratio' => '100', // 积分赠送比例
'is_shopping_discount' => 0, // 是否允许下单使用积分抵扣
'discount' => [ // 积分抵扣
'discount_ratio' => '0.01', // 积分抵扣比例
'full_order_price' => '100.00', // 订单满[?]元
'max_money_ratio' => '10', // 最高可抵扣订单额百分比
],
// 积分说明
'describe' => "a) 积分不可兑现、不可转让,仅可在本平台使用;\n" .
"b) 您在本平台参加特定活动也可使用积分,详细使用规则以具体活动时的规则为准;\n" .
"c) 积分的数值精确到个位(小数点后全部舍弃,不进行四舍五入)\n" .
"d) 买家在完成该笔交易(订单状态为“已签收”)后才能得到此笔交易的相应积分,如购买商品参加店铺其他优惠,则优惠的金额部分不享受积分获取;",
],
],
// 分类页模板
SettingEnum::PAGE_CATEGORY_TEMPLATE => [
'key' => SettingEnum::PAGE_CATEGORY_TEMPLATE,
'describe' => '分类页模板设置',
'values' => [
'style' => PageCategoryStyleEnum::COMMODITY, // 分类页样式
'shareTitle' => '全部分类', // 分享标题
'showAddCart' => true, // 是否显示购物车按钮
'cartStyle' => 1, // 购物车按钮样式 1-3
]
]
];
}
}
+192
View File
@@ -0,0 +1,192 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model\store;
use cores\BaseModel;
use think\Session;
/**
* 商家用户模型
* Class User
* @package app\common\model
*/
class User extends BaseModel
{
// 定义表名
protected $name = 'store_user';
// 定义主键
protected $pk = 'store_user_id';
/**
* 关联商家记录表
* @return \think\model\relation\BelongsTo
*/
public function store()
{
$module = self::getCalledModule();
return $this->belongsTo("app\\{$module}\\model\\Store", 'store_id');
}
/**
* 关联用户角色表表
* @return \think\model\relation\BelongsToMany
*/
public function role()
{
return $this->belongsToMany('Role', 'StoreUserRole');
}
/**
* 关联父级用户
* @return \think\model\relation\BelongsTo
*/
public function parentUser()
{
return $this->belongsTo('User','parent_id','store_user_id');
}
/**
* 验证用户名是否重复
* @param string $userName
* @return bool
*/
public static function checkExist(string $userName)
{
return (bool)static::withoutGlobalScope()
->where('user_name', '=', $userName)
->where('is_delete', '=', 0)
->value('store_user_id');
}
/**
* 商家用户详情
* @param $where
* @param array $with
* @return array|static|null
*/
public static function detail($where, array $with = [])
{
return static::get($where, $with);
}
/**
* 保存登录状态
* @param $user
* @throws \think\Exception
*/
public function loginState($user)
{
/** @var \app\common\model\Wxapp $wxapp */
$wxapp = $user['wxapp'];
// 保存登录状态
Session::set('yoshop_store', [
'user' => [
'store_user_id' => $user['store_user_id'],
'user_name' => $user['user_name'],
'is_super' => $user['is_super'],
'status' => $user['status'],
'level' => $user['level'],
'parent_id' => $user['parent_id'],
'merchant_id' => $user['merchant_id'],
],
'wxapp' => $wxapp->toArray(),
'is_login' => true,
]);
}
/**
* 切换状态
* @param $status
* @return false|int
*/
public function setStatus($status)
{
if($status == 1 && $this['stop_date'] == date("Y-m-d")){
return '当天已到达收款上限,停止接单';
}
if($bool = $this->save(['status' => $status])){
$session = Session::get('yoshop_store');
$session['user']['status'] = $status;
// 保存登录状态
Session::set('yoshop_store', $session);
$bool = true;
}
return $bool;
}
/**
* 获取全部
* @param array $user
* @return mixed
*/
public static function getAll($user = [])
{
$filter = [];
if($user['is_super'] == 0) {
$filter[] = ['store_user_id', 'in', \app\store\model\store\User::getScope($user)];
}
$model = new static;
//return $model->where('is_delete', '=', 0)->where('is_super', '=', 0)->where($filter)->order(['store_user_id' => 'asc'])->select();
return $model->where('is_delete', '=', 0)->where($filter)->order(['store_user_id' => 'asc'])->select();
}
/**
* 获取在线人员
* @return mixed
*/
public static function getOnline()
{
$model = new static;
//在线,并且当天未停止接单
$data = $model->where('status', '=', 1)->where('stop_date', '!=', date('Y-m-d'))->order(['store_user_id' => 'asc'])->select()->toArray();
return array_column($data,'store_user_id');
}
/**
* 切换状态
* @param $status
* @param $user
* @return false|int
*/
public function changeStatus($status,$user)
{
if($status == 1 && $this['stop_date'] == date("Y-m-d")){
return '当天已到达收款上限,停止接单';
}
if($bool = $this->save(['status' => $status])){
//如果是自己则修改在线状态的session
if($this['store_user_id'] == $user['store_user_id']) {
$session = Session::get('yoshop_store');
$session['user']['status'] = $status;
// 保存登录状态
Session::set('yoshop_store', $session);
}
$bool = true;
}
return $bool;
}
/**
* 修改收款金额
* @param $data
* @return bool
*/
public function updateMoney($data)
{
if ($data['money'] <= 0) {
$this->error = '收款金额必须大于0';
return false;
}
return $this->save([
'max_money' => $data['money'],
]) !== false;
}
}
@@ -0,0 +1,32 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model\store;
use cores\BaseModel;
/**
* 商家用户角色模型
* Class UserRole
* @package app\common\model\admin
*/
class UserRole extends BaseModel
{
// 定义表名
protected $name = 'store_user_role';
// 定义主键
protected $pk = 'id';
protected $updateTime = false;
}
@@ -0,0 +1,74 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model\user;
use cores\BaseModel;
use app\common\enum\user\balanceLog\Scene as SceneEnum;
/**
* 用户余额变动明细模型
* Class BalanceLog
* @package app\common\model\user
*/
class BalanceLog extends BaseModel
{
// 定义表名
protected $name = 'user_balance_log';
// 定义主键
protected $pk = 'log_id';
protected $updateTime = false;
/**
* 关联会员记录表
* @return \think\model\relation\BelongsTo
*/
public function user()
{
$module = self::getCalledModule();
return $this->belongsTo("app\\{$module}\\model\\User");
}
/**
* 新增记录
* @param int $scene
* @param array $data
* @param array $describeParam
*/
public static function add(int $scene, array $data, array $describeParam)
{
$model = new static;
$model->save(array_merge([
'scene' => $scene,
'describe' => vsprintf(SceneEnum::data()[$scene]['describe'], $describeParam),
'store_id' => $model::$storeId
], $data));
}
/**
* 新增记录
* @param int $scene
* @param array $data
* @param array $describeParam
*/
public static function addExchange(int $scene, array $data, array $describeParam)
{
$model = new static;
$model->save(array_merge([
'scene' => $scene,
'describe' => vsprintf(SceneEnum::data()[$scene]['describe'], $describeParam),
], $data));
}
}
+102
View File
@@ -0,0 +1,102 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model\user;
use cores\BaseModel;
use app\common\library\helper;
/**
* 用户会员等级模型
* Class Grade
* @package app\common\model\user
*/
class Grade extends BaseModel
{
// 定义表名
protected $name = 'user_grade';
// 定义主键
protected $pk = 'grade_id';
/**
* 获取器:升级条件
* @param $json
* @return mixed
*/
public function getUpgradeAttr($json)
{
return helper::jsonDecode($json);
}
/**
* 获取器:等级权益
* @param $json
* @return mixed
*/
public function getEquityAttr($json)
{
return helper::jsonDecode($json);
}
/**
* 修改器:升级条件
* @param $data
* @return mixed
*/
public function setUpgradeAttr($data)
{
// 这里需要转换下, 否则会出现浮点数精度丢失问题
$data['expend_money'] = (string)$data['expend_money'];
return helper::jsonEncode($data);
}
/**
* 修改器:等级权益
* @param $data
* @return mixed
*/
public function setEquityAttr($data)
{
// 这里需要转换下, 否则会出现浮点数精度丢失问题
$data['discount'] = (string)$data['discount'];
return helper::jsonEncode($data);
}
/**
* 会员等级详情
* @param int $gradId
* @param array $with
* @return array|null|static
*/
public static function detail(int $gradId, array $with = [])
{
return static::get($gradId, $with);
}
/**
* 验证等级权重是否存在
* @param int $weight 验证的权重
* @param int $gradeId 自身的等级ID
* @return bool
*/
public static function checkExistByWeight(int $weight, int $gradeId = 0): bool
{
$filter = [];
$gradeId > 0 && $filter[] = ['grade_id', '<>', (int)$gradeId];
return !!(new static)->where('weight', '=', (int)$weight)
->where($filter)
->where('is_delete', '=', 0)
->value('grade_id');
}
}
@@ -0,0 +1,50 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model\user;
use cores\BaseModel;
use app\common\enum\user\grade\log\ChangeType as ChangeTypeEnum;
/**
* 用户会员等级变更记录模型
* Class GradeLog
* @package app\common\model\user
*/
class GradeLog extends BaseModel
{
// 定义表名
protected $name = 'user_grade_log';
// 定义主键
protected $pk = 'log_id';
protected $updateTime = false;
/**
* 新增变更记录 (批量)
* @param $data
* @return int
*/
public function records($data)
{
$saveData = [];
foreach ($data as $item) {
$saveData[] = array_merge([
'change_type' => ChangeTypeEnum::ADMIN_USER,
'store_id' => static::$storeId
], $item);
}
return $this->addAll($saveData) !== false;
}
}
@@ -0,0 +1,63 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model\user;
use cores\BaseModel;
use think\model\relation\BelongsTo;
/**
* 用户积分变动明细模型
* Class PointsLog
* @package app\common\model\user
*/
class PointsLog extends BaseModel
{
// 定义表名
protected $name = 'user_points_log';
// 定义主键
protected $pk = 'log_id';
protected $updateTime = false;
/**
* 关联会员记录表
* @return BelongsTo
*/
public function user(): BelongsTo
{
$module = self::getCalledModule();
return $this->belongsTo("app\\{$module}\\model\\User");
}
/**
* 新增记录
* @param array $data
*/
public static function add(array $data)
{
$static = new static;
empty($data['store_id']) && $data['store_id'] = $static::$storeId;
$static->save($data);
}
/**
* 新增记录 (批量)
* @param $saveData
* @return bool
*/
public function onBatchAdd($saveData): bool
{
return $this->addAll($saveData) !== false;
}
}
@@ -0,0 +1,178 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model\wxapp;
use cores\BaseModel;
use think\facade\Cache;
use app\common\model\Wxapp as WxappModel;
use app\common\library\helper;
/**
* 微信小程序设置模型
* Class Setting
* @package app\common\model\wxapp
*/
class Setting extends BaseModel
{
// 定义表名
protected $name = 'wxapp_setting';
protected $createTime = false;
/**
* 获取器: 转义数组格式
* @param $value
* @return array
*/
public function getValuesAttr($value): array
{
return helper::jsonDecode($value);
}
/**
* 修改器: 转义成json格式
* @param $value
* @return string
*/
public function setValuesAttr($value): string
{
return helper::jsonEncode($value);
}
/**
* 获取指定项设置
* @param string $key
* @param int|null $storeId
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function getItem(string $key, int $storeId = null): array
{
$data = static::getAll($storeId);
return isset($data[$key]) ? $data[$key]['values'] : [];
}
/**
* 获取微信小程序基础配置
* @param int|null $storeId
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function getWxappConfig(?int $storeId = null): array
{
return static::getItem('basic', $storeId);
}
/**
* 获取全部设置
* @param int|null $storeId
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function getAll(?int $storeId = null): array
{
$model = new static;
is_null($storeId) && $storeId = static::$storeId;
if (!$data = Cache::get("wxapp_setting_{$storeId}")) {
// 获取全部设置
$data = $model->getList($storeId);
// 写入缓存中
Cache::tag('cache')->set("wxapp_setting_{$storeId}", $data);
}
// 合并默认设置
return array_merge_multiple($model->defaultData(), $data);
}
/**
* 获取商城设置列表
* @param int $storeId
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
private function getList(int $storeId): array
{
// 获取所有设置项
$data = $this->where('store_id', '=', $storeId)->select();
$setting = $data->isEmpty() ? [] : helper::arrayColumn2Key($data->toArray(), 'key');
// 兼容旧数据
return static::compatibleOld($setting, $storeId);
}
/**
* 兼容老版本数据 (v2.0.4之前)
* @param array $newSetting
* @param int|null $storeId
* @return array
*/
private static function compatibleOld(array $newSetting, ?int $storeId = null): array
{
if (empty($newSetting) || !isset($newSetting['basic'])) {
$basic = WxappModel::getOldData($storeId);
$newSetting['basic']['values'] = $basic;
(new static)->save([
'key' => 'basic',
'describe' => '基础设置',
'values' => $basic,
'store_id' => $storeId,
'update_time' => time(),
]);
}
return $newSetting;
}
/**
* 获取设置项信息
* @param string $key
* @return array|\think\Model|null
*/
public static function detail(string $key)
{
return static::get(compact('key'));
}
/**
* 默认配置
* @return array
*/
public function defaultData(): array
{
return [
'basic' => [
'key' => 'basic',
'describe' => '基础设置',
'values' => [
// 小程序AppID
'app_id' => '',
// 小程序AppSecret
'app_secret' => '',
// 微信支付商户号ID
'mchid' => '',
// 微信支付密钥
'apikey' => '',
// 证书文件cert
'cert_pem' => '',
// 证书文件key
'key_pem' => '',
]
]
];
}
}