初始化项目

This commit is contained in:
2026-09-01 22:15:50 +08:00
commit b5a26a8848
11217 changed files with 1710987 additions and 0 deletions
+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\admin\model;
use app\common\model\Store as StoreModel;
/**
* 商家记录表模型
* Class Store
* @package app\admin\model
*/
class Store extends StoreModel
{
/**
* 获取列表数据
* @param bool $isRecycle
* @return \think\Paginator
* @throws \think\db\exception\DbException
*/
public function getList(bool $isRecycle = false): \think\Paginator
{
return $this->where('is_recycle', '=', (int)$isRecycle)
->where('is_delete', '=', 0)
->order(['create_time' => 'desc'])
->paginate(15);
}
/**
* 移入移出回收站
* @param bool $isRecycle
* @return false|int
*/
public function recycle($isRecycle = true)
{
return $this->save(['is_recycle' => (int)$isRecycle]);
}
}
+25
View File
@@ -0,0 +1,25 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\admin\model;
use app\common\model\UploadFile as UploadFileModel;
/**
* 文件库模型
* Class UploadFile
* @package app\admin\model
*/
class UploadFile extends UploadFileModel
{
}
+110
View File
@@ -0,0 +1,110 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\admin\model\admin;
use app\common\model\admin\User as UserModel;
use app\admin\service\admin\User as AdminUserService;
/**
* 超管后台用户模型
* Class User
* @package app\admin\model\admin
*/
class User extends UserModel
{
/**
* 隐藏的字段
* @var array
*/
protected $hidden = [
'password',
];
// 用户登录token
private $token;
/**
* 超管后台用户登录
* @param array $data
* @return array|bool|null|\think\Model
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function login(array $data)
{
// 验证用户名密码是否正确
if (!$user = $this->getUserInfoByLogin($data)) {
$this->error = '登录失败, 用户名或密码错误';
return false;
}
// 记录登录状态, 并记录token
$this->token = AdminUserService::login($user->toArray());
return $user;
}
/**
* 返回生成的token
* @return mixed
*/
public function getToken()
{
return $this->token;
}
/**
* 获取登录的用户信息
* @param $data
* @return array|false|\think\Model
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
private function getUserInfoByLogin(array $data)
{
// 用户信息
$useInfo = static::withoutGlobalScope()
->where(['user_name' => $data['username']])
->find();
if (empty($useInfo)) return false;
// 验证密码是否正确
if (!password_verify($data['password'], $useInfo['password'])) {
return false;
}
return $useInfo;
}
/**
* 更新当前管理员信息
* @param $data
* @return bool
*/
public function renew(array $data)
{
if ($data['password'] !== $data['password_confirm']) {
$this->error = '确认密码不正确';
return false;
}
// 更新管理员信息
if ($this->save([
'user_name' => $data['user_name'],
'password' => encryption_hash($data['password']),
]) === false) {
return false;
}
// 更新登录信息
AdminUserService::update($this->toArray());
return true;
}
}
+129
View File
@@ -0,0 +1,129 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\admin\model\store;
use app\common\model\store\Api as ApiModel;
/**
* 商家后台API权限模型
* Class Api
* @package app\admin\model\store
*/
class Api extends ApiModel
{
/**
* 获取权限列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList()
{
$all = static::getAll();
return $this->getTreeData($all);
}
/**
* 新增记录
* @param $data
* @return false|int
*/
public function add(array $data)
{
return $this->allowField(['name', 'parent_id', 'url', 'sort'])->save($data);
}
/**
* 更新记录
* @param $data
* @return bool
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function edit($data)
{
// 判断上级角色是否为当前子级
if ($data['parent_id'] > 0) {
// 获取所有上级id集
$parentIds = $this->getTopApiIds($data['parent_id']);
if (in_array($this['api_id'], $parentIds)) {
$this->error = '上级权限不允许设置为当前子权限';
return false;
}
}
return $this->allowField(['name', 'parent_id', 'url', 'sort'])->save($data) !== false;
}
/**
* 删除权限
* @return bool
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @throws \Exception
*/
public function remove()
{
// 判断是否存在下级权限
if (self::detail(['parent_id' => $this['api_id']])) {
$this->error = '当前权限下存在子权限,请先删除';
return false;
}
return $this->delete();
}
/**
* 获取所有上级id集
* @param int $apiId
* @param null $all
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
private function getTopApiIds(int $apiId, $all = null)
{
static $ids = [];
is_null($all) && $all = $this->getAll();
foreach ($all as $item) {
if ($item['api_id'] == $apiId && $item['parent_id'] > 0) {
$ids[] = $item['parent_id'];
$this->getTopApiIds($item['parent_id'], $all);
}
}
return $ids;
}
/**
* 获取树状列表
* @param array $list
* @param int $parentId
* @return array
*/
private function getTreeData(array &$list, int $parentId = 0)
{
$data = [];
foreach ($list as $key => $item) {
if ($item['parent_id'] == $parentId) {
$children = $this->getTreeData($list, (int)$item['api_id']);
!empty($children) && $item['children'] = $children;
$data[] = $item;
unset($list[$key]);
}
}
return $data;
}
}
+116
View File
@@ -0,0 +1,116 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\admin\model\store;
use app\common\model\store\Menu as MenuModel;
use app\admin\model\store\MenuApi as MenuApiModel;
/**
* 商家后台菜单模型
* Class Menu
* @package app\admin\model\store
*/
class Menu extends MenuModel
{
/**
* 新增记录
* @param $data
* @return false|int
*/
public function add(array $data)
{
return $this->save($data);
}
/**
* 更新记录
* @param array $data
* @return bool
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function edit(array $data)
{
// 判断上级角色是否为当前子级
if (isset($data['parent_id']) && $data['parent_id'] > 0) {
// 获取所有上级id集
$parentIds = $this->getTopMenuIds($data['parent_id']);
if (in_array($this['menu_id'], $parentIds)) {
$this->error = '上级菜单不允许设置为当前子菜单';
return false;
}
}
// 如果模块是操作, 不允许修改上级菜单id
if ($this['module'] == 20 && isset($data['parent_id'])) {
unset($data['parent_id']);
}
return $this->save($data) !== false;
}
/**
* 设置菜单的API权限
* @param array $data
* @return bool|int
*/
public function setApis(array $data)
{
if (!isset($data['apiIds']) || empty($data['apiIds'])) {
$this->error = 'API权限不能为空';
return false;
}
// 根据菜单id批量更新API关联记录
return (new MenuApiModel)->updateByMenuId($this['menu_id'], $data['apiIds']);
}
/**
* 删除菜单
* @return bool
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @throws \Exception
*/
public function remove()
{
// 判断是否存在下级菜单
if (self::detail(['parent_id' => $this['menu_id']])) {
$this->error = '当前菜单下存在子菜单或操作,请先删除';
return false;
}
return $this->delete();
}
/**
* 获取所有上级id集
* @param int $menuId
* @param null $menuList
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
private function getTopMenuIds(int $menuId, $menuList = null)
{
static $ids = [];
is_null($menuList) && $menuList = $this->getAll();
foreach ($menuList as $item) {
if ($item['menu_id'] == $menuId && $item['parent_id'] > 0) {
$ids[] = $item['parent_id'];
$this->getTopMenuIds($item['parent_id'], $menuList);
}
}
return $ids;
}
}
@@ -0,0 +1,64 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\admin\model\store;
use app\common\model\store\MenuApi as MenuApiModel;
/**
* 商家后台用户角色与菜单权限关系表模型
* Class MenuApi
* @package app\admin\model\store
*/
class MenuApi extends MenuApiModel
{
/**
* 根据菜单id批量更新记录
* @param int $menuId
* @param array $apiIds
* @return int
*/
public function updateByMenuId(int $menuId, array $apiIds)
{
return $this->transaction(function () use ($menuId, $apiIds) {
$this->removeByMenuId($menuId);
return $this->insertByMenuId($menuId, $apiIds);
});
}
/**
* 根据菜单id批量删除记录
* @param int $menuId
* @return bool
* @throws \Exception
*/
private function removeByMenuId(int $menuId)
{
return $this->where('menu_id', '=', $menuId)->delete();
}
/**
* 根据菜单id批量新增记录
* @param int $menuId
* @param array $apiIds
* @return bool
*/
private function insertByMenuId(int $menuId, array $apiIds)
{
$data = [];
foreach ($apiIds as $api) {
$data[] = ['menu_id' => $menuId, 'api_id' => $api];
}
return (bool)$this->addAll($data);
}
}
+60
View File
@@ -0,0 +1,60 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\admin\model\store;
use cores\exception\BaseException;
use app\common\model\store\User as StoreUserModel;
/**
* 商家用户模型
* Class StoreUser
* @package app\admin\model
*/
class User extends StoreUserModel
{
/**
* 商家用户登录
* @param int $storeId
* @throws BaseException
* @throws \think\Exception
*/
public function login(int $storeId)
{
// 获取该商户管理员用户信息
$userInfo = $this->getSuperStoreUser($storeId);
if (empty($userInfo)) {
throwError('超级管理员用户信息不存在');
}
}
/**
* 获取该商户管理员用户信息
* @param int $storeId
* @return static|null
*/
private function getSuperStoreUser(int $storeId)
{
return static::detail(['store_id' => $storeId, 'is_super' => 1], ['wxapp']);
}
/**
* 删除小程序下的商家用户
* @param $storeId
* @return false|int
*/
public static function setDelete(int $storeId)
{
static::update(['is_delete' => '1'], ['store_id' => $storeId]);
return true;
}
}