init: 项目初始代码

This commit is contained in:
2026-10-14 14:00:29 +08:00
commit cc434cf89f
464 changed files with 66984 additions and 0 deletions

92
app/api/model/Admin.php Normal file
View File

@@ -0,0 +1,92 @@
<?php
namespace app\api\model;
/**
* 管理员模型
* @mixin \think\Model
*/
class Admin extends BaseModel
{
protected $schema = [
'id' => 'int',
'code' => 'string',
'username' => 'string',
'nickname' => 'string',
'password' => 'string',
'avatar' => 'string',
'role_id' => 'int',
'org_id' => 'int',
'dept_group_id' => 'int',
'dept_id' => 'int',
'mobile' => 'string',
'create_time' => 'int',
'create_ip' => 'string',
'last_time' => 'int',
'last_ip' => 'string',
'status' => 'int',
'update_time' => 'int',
];
/**
* 获取管理员列表
* @param array $where
* @param int $page
* @param int $size
* @param string $order
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList($where, $page=1, $size=12, $order='id asc')
{
$w = [];
if (isset($where['username']) && $where['username'] != '') {
$w[] = ['username', 'like', $where['username'] . '%'];
}
if (isset($where['role_id']) && $where['role_id'] != 0) {
$w[] = ['role_id', '=', $where['role_id']];
}
if ($page < 0) $page = 1;
if ($size > 100) $size = 100;
$result = $this->where($w)->limit(($page-1)*$size, intval($size))->order($order)->withoutField(['password'])->select()->toArray();
return $result;
}
/**
* 通过用户名获取信息
* @param string $username
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getInfoByUserName($username)
{
$result = $this->where(['username' => $username])->find();
return $result ? $result->toArray() : [];
}
/**
* 获取用户信息
* @param int $id 管理员表主键
* @param bool $type
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getUserInfo(int $id,bool $type=false):array
{
if ($type) {
$result = $this->find($id);
} else {
$result = $this->withoutField('password')->find($id);
}
return $result ? $result->toArray() : [];
}
}

View File

@@ -0,0 +1,100 @@
<?php
declare(strict_types=1);
namespace app\api\model;
/**
* 广告页模型
* @mixin \think\Model
*/
class AdvertisePage extends BaseModel
{
protected $schema = [
'id' =>'int',
'platform_id' =>'int',
'language_id' =>'int',
'site_id' =>'int',
'name' =>'string',
'sort' =>'int',
'create_time' =>'int',
'update_time' =>'int',
];
/**
* 广告页关系广告位模型
*/
public function PageSpace()
{
return $this->hasMany(AdvertiseSpace::class);
}
/**
* 获取列表
* @param array $data 查询条件
* @param mixed $simple 模糊搜索条件
* @param mixed $focus 精准搜索条件
* @param null $sort
* @param null $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getAllList(array $data,$simple = null,$focus = null,$sort = null,$field=null):array
{
$fields = array_keys($this->schema);
$collection = $this->field($field)->where(function ($query) use ($data,$fields,$simple,$focus) {
if (isset($data['platform_id'])) {
if (in_array('platform_id',$fields)) {
$query->where('platform_id',$data['platform_id']);
}
}
//模糊查询条件
if (!empty($simple)) {
foreach ($simple as $key => $item) {
if (in_array($key,$fields)) {
$query->where($key,'like',"%".$item."%");
}
}
}
//精准查询
if (!empty($focus)) {
foreach ($focus as $key => $item) {
if (in_array($key,$fields)) {
$query->where($key,$item);
}
}
}
});
if (isset($data['page']) && isset($data['size'])) {
$count = $collection->count() ?: 0;
$page = $collection->limit((int)$data['size'])->page((int)$data['page'])->order($sort)->select()->toArray();
foreach ($page as $key => $item) {
$page[$key]['language_id'] = $item['site_id'];
}
return ['page'=>$page,'count'=>$count];
} else {
$page = $collection->order($sort)->select()->toArray();
foreach ($page as $key => $item) {
$page[$key]['language_id'] = $item['site_id'];
}
return $page;
}
}
/**
* @param $data
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getAdSpace($data)
{
$result = $this->where('id',$data['id'])->with('PageSpace')->find()->toArray();
return $result['PageSpace'];
}
}

View File

@@ -0,0 +1,140 @@
<?php
declare(strict_types=1);
namespace app\api\model;
/**
* @mixin \think\Model
*/
class AdvertiseSpace extends BaseModel
{
protected $schema = [
'id' =>'int',
'platform_id' =>'int',
'language_id' =>'int',
'site_id' =>'int',
'name' =>'string',
'advertise_page_id'=>'int',
'max_num' =>'int',
'width' =>'int',
'height' =>'int',
'sort' =>'int',
'create_time' =>'int',
'update_time' =>'int',
];
/**
* 一个广告位对应一个多多个广告
*/
public function pageAd():\think\model\relation\HasMany
{
return $this->hasMany(Advertisement::class);
}
/**
* 获取列表
* @param array $data 查询条件
* @param mixed $simple 模糊搜索条件
* @param mixed $focus 精准搜索条件
* @param null $sort
* @param null $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getAllList(array $data,$simple = null,$focus = null,$sort = null,$field=null):array
{
$fields = array_keys($this->schema);
$collection = $this->field($field)->where(function ($query) use ($data,$fields,$simple,$focus) {
if (in_array('platform_id',$fields)) {
$query->where('platform_id',$data['platform_id']);
}
//模糊查询条件
if (!empty($simple)) {
foreach ($simple as $key => $item) {
if (in_array($key,$fields)) {
$query->where($key,'like',"%".$item."%");
}
}
}
//精准查询
if (!empty($focus)) {
foreach ($focus as $key => $item) {
if (in_array($key,$fields)) {
$query->where($key,$item);
}
}
}
});
if (isset($data['page']) && isset($data['size'])) {
$count = $collection->count() ?: 0;
$page = $collection->limit((int)$data['size'])->page((int)$data['page'])->order($sort)->select()->toArray();
if (!empty($page)) {
foreach ($page as $key => $item) {
$page[$key]['language_name'] = $this->getLanguageName($item['site_id']);
$page[$key]['advertise_page_name'] = $this->getAdvertisePageName($item['advertise_page_id']);
}
}
return ['page'=>$page,'count'=>$count];
} else {
$page = $collection->order($sort)->select()->toArray();
if (!empty($page)) {
foreach ($page as $key => $item) {
$page[$key]['language_name'] = $this->getLanguageName($item['site_id']);
$page[$key]['advertise_page_name'] = $this->getAdvertisePageName($item['advertise_page_id']);
}
}
return $page;
}
}
/**
* 广告位-广告的关联模型
*/
public function spaceToAD():\think\model\relation\HasMany
{
return $this->hasMany(Advertisement::class);
}
/**
* 获取列表
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList($data):array
{
$result = $this->where('site_id',$data['site_id'])->select();
if ($result) {
foreach ($result as &$item) {
$item['use_num'] = $item->spaceToAD()->count();
}
}
return $result->toArray();
}
/**
* 获取此广告位已经使用了的数量
* @param $data
* @return int
*/
public function getUseSpaceNum($data):int
{
return Advertisement::where('advertise_space_id',$data['id'])->where('site_id',$data['site_id'])->count();
}
/**
* @param $data
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getAd($data):array
{
return $this->where('id',$data['id'])->with('pageAd')->find()->toArray()['pageAd'];
}
}

View File

@@ -0,0 +1,154 @@
<?php
declare(strict_types=1);
namespace app\api\model;
/**
* 广告模型
* @mixin \think\Model
*/
class Advertisement extends BaseModel
{
protected $schema = [
'id' =>'int',
'platform_id' =>'int',
'language_id' =>'int',
'site_id' =>'int',
'advertise_space_id' =>'int',
'command' =>'string',
'name' =>'string',
'image' =>'string',
'url' =>'string',
'start_time' =>'int',
'stop_time' =>'int',
'play_order' =>'int',
'sort' =>'int',
'status' =>'int',
'create_time' =>'int',
'update_time' =>'int',
];
/**
* 获取列表
* @param array $data 查询条件
* @param mixed $simple 模糊搜索条件
* @param mixed $focus 精准搜索条件
* @param null $sort
* @param null $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getAllList(array $data,$simple = null,$focus = null,$sort = null,$field=null):array
{
$fields = array_keys($this->schema);
$collection = $this->field($field)->where(function ($query) use ($data,$fields,$simple,$focus) {
if (in_array('platform_id',$fields)) {
$query->where('platform_id',$data['platform_id']);
}
//模糊查询条件
if (!empty($simple)) {
foreach ($simple as $key => $item) {
if (in_array($key,$fields)) {
$query->where($key,'like',"%".$item."%");
}
}
}
//精准查询
if (!empty($focus)) {
foreach ($focus as $key => $item) {
if (in_array($key,$fields)) {
$query->where($key,$item);
}
}
}
});
if (isset($data['page']) && isset($data['size'])) {
$count = $collection->count() ?: 0;
$page = $collection->limit((int)$data['size'])->page((int)$data['page'])->order($sort)->select()->toArray();
foreach ($page as $key => $item) {
$page[$key]['language_name'] = $this->getLanguageName($item['site_id']);
$page[$key]['advertise_space_name'] = $this->getAdertiseSpaceName($item['advertise_space_id']);
$page[$key]['spec'] = $this->getAdvertiseSpaceSpec($item['advertise_space_id']);
}
return ['page'=>$page,'count'=>$count];
} else {
$page = $collection->order($sort)->select()->toArray();
foreach ($page as $key => $item) {
$page[$key]['language_name'] = $this->getLanguageName($item['site_id']);
$page[$key]['advertise_space_name'] = $this->getAdertiseSpaceName($item['advertise_space_id']);
$page[$key]['spec'] = $this->getAdvertiseSpaceSpec($item['advertise_space_id']);
}
return $page;
}
}
/**
* 广告对应广告位,一对一
* @return \think\model\relation\BelongsTo
*/
public function getAdToSpace()
{
return $this->belongsTo(AdvertiseSpace::class);
}
/**
* 获取详情
* @param array $data
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getInfo(array $data):array
{
$advertisement = $this->find($data['id']);
if ($advertisement) {
$advertisement['ad_space_max_num'] = $advertisement->getAdToSpace()->value('max_num');
$advertisement['size'] = $advertisement->getAdToSpace()->value('width')."x".$advertisement->getAdToSpace()->value('height');
}
return $advertisement->toArray() ? : [];
}
/**
* 通过id获取当前广告位最大的广告数量
* @param $data
* @return int|mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getAdvertiseSpaceMaxNum($data):int
{
$result = AdvertiseSpace::find($data);
return $result ? $result['max_num'] : 1;
}
/**
* 通过id获取当前广告位已经有多少条广告
* @param $data
* @return int
*/
public function getAdvertiseUseSpaceNum($data):int
{
return $this->where('advertise_space_id',$data['advertise_space_id'])->where('site_id',$data['site_id'])->count();
}
/**
* 查询当前数据是否是修改自己,还是别的项目修改成其他的
* @param $data
* @return bool
*/
public function getBeforeUpdate($data):bool
{
$result = $this->findOrEmpty($data['id']);
if (!empty($result)) {
if ($result['advertise_space_id'] == $data['advertise_space_id']) {
return true;
}
}
return false;
}
}

16
app/api/model/Area.php Normal file
View File

@@ -0,0 +1,16 @@
<?php
namespace app\api\model;
/**
* 全球国家列表
* @mixin \think\Model
*/
class Area extends BaseModel
{
protected $schema = [
'id' => 'int',
'pid' => 'int',
'name' => 'string',
'level' => 'int',
];
}

96
app/api/model/Article.php Normal file
View File

@@ -0,0 +1,96 @@
<?php
declare(strict_types=1);
namespace app\api\model;
/**
* 文章
* @mixin \think\Model
*/
class Article extends BaseModel
{
protected $schema = [
'id' => 'int',
'platform_id' => 'int',
'language_id' => 'int',
'site_id' => 'int',
'article_type_id' => 'int',
'title' => 'string',
'brief' => 'string',
'desc' => 'string',
'thumb' => 'string',
'url' => 'string',
'meta_title' => 'string',
'keywords' => 'string',
'detail' => 'string',
'sort' => 'int',
'status' => 'int',
'is_outer_chain' => 'int',
'click_num' => 'int',
'create_time' => 'int',
'update_time' => 'int'
];
/**
*
*/
public function articleType():\think\model\relation\HasOne
{
return $this->hasOne(ArticleType::class,'id','article_type_id')->bind(['article_type_name'=>'name']);
}
/**
*/
public function languageName():\think\model\relation\HasOne
{
return $this->hasOne(Language::class,'id','site_id')->bind(['language_name'=>'name']);
}
/**
* 获取列表
* @param array $data 查询条件
* @param mixed $simple 模糊搜索条件
* @param mixed $focus 精准搜索条件
* @param null $sort
* @param null $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getAllList(array $data,$simple = null,$focus = null,$sort = null,$field=null):array
{
$fields = array_keys($this->schema);
$collection = $this->field($field)->where(function ($query) use ($data,$fields,$simple,$focus) {
if (isset($data['platform_id'])) {
if (in_array('platform_id',$fields)) {
$query->where('platform_id',$data['platform_id']);
}
}
//模糊查询条件
if (!empty($simple)) {
foreach ($simple as $key => $item) {
if (in_array($key,$fields)) {
$query->where($key,'like',"%".$item."%");
}
}
}
//精准查询
if (!empty($focus)) {
foreach ($focus as $key => $item) {
if (in_array($key,$fields)) {
$query->where($key,$item);
}
}
}
});
if (isset($data['page']) && isset($data['size'])) {
$count = $collection->count() ?: 0;
$page = $collection->limit((int) $data['size'])->page((int)$data['page'])->order($sort)->with(['articleType','languageName'])->select()->toArray();
return ['page'=>$page,'count'=>$count];
} else {
return $collection->order($sort)->with(['articleType','languageName'])->select()->toArray();
}
}
}

View File

@@ -0,0 +1,105 @@
<?php
declare(strict_types=1);
namespace app\api\model;
/**
* 文章分类
* @mixin \think\Model
*/
class ArticleType extends BaseModel
{
protected $schema = [
'id' =>'int',
'platform_id' =>'int',
'site_id' =>'int',
'name' =>'string',
'desc' =>'string',
'icon' =>'string',
'sort' =>'int',
'create_time' =>'int',
'update_time' =>'int',
];
/**
* article分类与article表模型
* @return \think\model\relation\HasMany
*/
public function getArticle()
{
return $this->hasMany(Article::class);
}
/**
* 获取列表
* @param array $data 查询条件
* @param mixed $simple 模糊搜索条件
* @param mixed $focus 精准搜索条件
* @param null $sort
* @param null $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getAllList(array $data,$simple = null,$focus = null,$sort = null,$field=null):array
{
$fields = array_keys($this->schema);
$collection = $this->field($field)->where(function ($query) use ($data,$fields,$simple,$focus) {
if (isset($data['platform_id'])) {
if (in_array('platform_id',$fields)) {
$query->where('platform_id',$data['platform_id']);
}
}
//模糊查询条件
if (!empty($simple)) {
foreach ($simple as $key => $item) {
if (in_array($key,$fields)) {
$query->where($key,'like',"%".$item."%");
}
}
}
//精准查询
if (!empty($focus)) {
foreach ($focus as $key => $item) {
if (in_array($key,$fields)) {
$query->where($key,$item);
}
}
}
});
if (isset($data['page']) && isset($data['size'])) {
$count = $collection->count() ?: 0;
$page = $collection->limit((int)$data['size'])->page((int)$data['page'])->order($sort)->select()->toArray();
foreach ($page as $key => $item) {
$page[$key]['language_id'] = $item['site_id'];
}
return ['page'=>$page,'count'=>$count];
} else {
$page = $collection->order($sort)->select()->toArray();
foreach ($page as $key => $item) {
$page[$key]['language_id'] = $item['site_id'];
}
return $page;
}
}
/**
* 获取对应分类下的文章内容
* @param $data
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getArticleData($data):array
{
$article = $this->find($data['id']);
if (!empty($article)) {
return $article->getArticle()->select()->toArray();
}
return [];
}
}

View File

@@ -0,0 +1,24 @@
<?php
namespace app\api\model;
/**
* 文章
* @mixin \think\Model
*/
class Attachment extends BaseModel
{
protected $schema = [
'id' => 'int',
'platform_id' => 'int',
'site_id' => 'int',
'name' => 'string',
'type' => 'string',
'local' => 'string',
'path' => 'string',
'hash' => 'string',
'md5' => 'string',
'create_time' => 'int',
'update_time' => 'int'
];
}

View File

@@ -0,0 +1,34 @@
<?php
namespace app\api\model;
/**
* 属性模型
* @mixin \think\Model
*/
class Attribute extends BaseModel
{
protected $schema = [
'id' => 'int',
'platform_id' => 'int',
'language_id' => 'int',
'site_id' => 'int',
'name' => 'string',
'create_time' => 'int',
'update_time' => 'int',
];
/**
* 通过属性ID,查找是否有商品引用属性
* @param $data
* @return array|\think\Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getGoodsAttrById($data)
{
return GoodsAttribute::where('attribute_id',$data['id'])->find();
}
}

417
app/api/model/BaseModel.php Normal file
View File

@@ -0,0 +1,417 @@
<?php
declare(strict_types = 1);
namespace app\api\model;
use app\library\SSOApi;
use think\facade\Env;
use think\Model;
/**
* 后台模型基类
* Class BaseModel
* @package app\api\model
*/
class BaseModel extends Model
{
use SSOApi;
/**
* 查看列表数据
* @param int $page 分页页码
* @param int $pageSize 分页类目数量
* @param array $field 需要输入的字段,默认为全部输出,筛选表字段
* @param array $vague 需要进行模糊查询的字段,如: a like %a%
* @param array $focus 精确搜索条件,如a=1,b=2这种精确等于某个值的
* @param array $order 排序字段,如:['id'=>'desc','sort'=>'desc']
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getIndexList(int $page,int $pageSize,array $field = [], array $vague = [],array $focus = [],array $order = []):array
{
$fields = array_keys($this->schema);
$collection = $this->field($field)->where(function ($query) use ($fields,$focus) {
//精准查询
if (!empty($focus)) {
foreach ($focus as $key => $item) {
if (in_array($key,$fields)) {
$query->where($key,$item);
}
}
}
})->where(function($query) use ($fields,$vague) {
//模糊查询
if (!empty($vague)) {
foreach ($vague as $key => $item) {
if (in_array($key,$fields)) {
$query->whereOr($key,'like',"%".$item."%");
}
}
}
})->order($order);
//判断是否需要分页
if (0 == $page || 0 == $pageSize) {
//不需要分页
return $collection->select()->toArray();
} else {
//需要分布
$totalNum = $collection->count();
$data = $collection->page($page)->limit($pageSize)->select()->toArray();;
return ['count'=>$totalNum,'data'=>$data];
}
}
/**
* 新增数据
* @param array $data
* @return bool
*/
public function addData(array $data) : bool
{
$result = $this->create($data);
return (bool)$result;
}
/**
* 编辑数据
* @param array $data
* @return bool
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function editData(array $data) : bool
{
if (isset($data['id']) && $data['id'] > 0) {
$result = $this->find($data['id']);
return $result && $result->save($data);
}
return false;
}
/**
* 获取详情
* @param array $data
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getInfo(array $data) : array
{
if (isset($data['id'])) {
$result = $this->find($data['id']);
return $result ? $result->toArray() : [];
}
return [];
}
/**
* 删除
* @param array $data
* @return bool
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function delData(array $data) : bool
{
if (isset($data['id'])) {
$result = $this->find($data['id']);
return $result && $result->delete();
}
return false;
}
/**
* 通过ID获取数据
* @param $ids
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getExportData($ids): array
{
$result = $this->whereIn($this->pk,$ids['ids'])->order('create_time','desc')->select();
return $result ? $result->toArray() : [];
}
/**
* 批量修改
* @param $data
* @return bool
* @throws \Exception
*/
public function batchEditData($data):bool
{
$result = $this->saveAll($data);
return (bool)$result;
}
/**
* 批量删除
* @param array $data
* @return bool
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function batchDelData(array $data) : bool
{
$res = true;
foreach ($data as $item) {
if (isset($item['id']) && $item['id'] > 0) {
$result = $this->find($item['id']);
$result = $result->delete();
$res = $res && $result;
}
}
return $res;
}
/**
* 获取地区名称
* @param $id
* @return string
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getAreaNameById($id):string
{
$data = Area::find($id);
return $data ? $data['name'] : '';
}
/**
* 获取币种名称
* @param $id
* @return string
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getCoinName($id):string
{
$result = Currency::find($id);
return $result ? $result['name'] : '';
}
/**
* 获取站点语言名称
* @param $id
* @return string
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getSiteLanguageName($id):string
{
$lang = Site::find($id);
$result = Language::find($lang['language_id']);
return $result ? $result['name'] : '';
}
/**
* 获取语言名称
* @param $id
* @return string
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getLanguageName($id):string
{
$result = Language::find($id);
return $result ? $result['name'] : '';
}
/**
* 获取语言名称
* @param $id
* @return string
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getCountryName($id):string
{
$result = Country::find($id);
return $result ? $result['zh'] : '其他';
}
/**
* 获取币种名称
* @param $id
* @return string
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getPlatformName($id):string
{
$result = Platform::find($id);
return $result ? $result['name'] : '';
}
/**
* 通过id获取名称
* @param $id
* @return string
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getFileTypeName($id):string
{
$result = FileType::find($id);
return $result ? $result['name'] : '';
}
/**
* 通过id获取名称
* @param $id
* @return string
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getFaqTypeName($id):string
{
$result = FaqType::find($id);
return $result ? $result['name'] : '';
}
/**
* 通过id获取名称
* @param $id
* @return string
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getAdvertisePageName($id):string
{
$result = AdvertisePage::find($id);
return $result ? $result['name'] : '';
}
/**
* 通过id获取名称
* @param $id
* @return string
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getAdertiseSpaceName($id):string
{
$result = AdvertiseSpace::find($id);
return $result ? $result['name'] : '';
}
/**
* 通过id获取尺寸
* @param $id
* @return string
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getAdvertiseSpaceSpec($id):string
{
$result = AdvertiseSpace::find($id);
if ($result) {
$width = $result['width'];
$height = $result['height'];
return $width. 'x' . $height;
}
return '';
}
/**
* 通过id获取名称
* @param $id
* @return string
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getGoodsName($id):string
{
$result = Goods::find($id);
return $result ? $result['name'] : '';
}
/**
* 启用禁用
* @param $data
* @return bool
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function changeStatus($data):bool
{
$result = $this->find($data['id']);
return $result && $result->save($data);
}
/**
* 排序
* @param $data
* @return bool
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function changeSort($data):bool
{
$result = $this->find($data['id']);
return $result && $result->save($data);
}
/**
* 获取子类ID
* @param $id
* @return array
*/
public function getChildCategory($id):array
{
$res = $this->where('pid',$id)->column('id');
array_push($res,intval($id));
return $res ?: [];
}
/**
* 获取父类ID
* @param $id
* @return array
*/
public function getPCategory($id):array
{
$res = $this->where('id',$id)->column('id');
array_push($res,intval($id));
return $res ?: [];
}
/**
* 动态数据检测,检测提交过来的数据中ID是否合法
* @param $model
* @param $condition
* @return bool
*/
public function dynamicCheck($model,$condition):bool
{
return (bool) $model::where($condition)->find();
}
}

106
app/api/model/Brand.php Normal file
View File

@@ -0,0 +1,106 @@
<?php
declare(strict_types=1);
namespace app\api\model;
/**
* 文章
* @mixin \think\Model
*/
class Brand extends BaseModel
{
protected $schema = [
'id' => 'int',
'platform_id' => 'int',
'language_id' => 'int',
'site_id' => 'int',
'brand_type_id' => 'int',
'title' => 'string',
'brief' => 'string',
'desc' => 'string',
'thumb' => 'string',
'url' => 'string',
'meta_title' => 'string',
'keywords' => 'string',
'detail' => 'string',
'sort' => 'int',
'status' => 'int',
'is_outer_chain' => 'int',
'is_on_index' => 'int',
'click_num' => 'int',
'create_time' => 'int',
'update_time' => 'int',
'website' => 'string',
'cname' => 'string',
// 'en_name' => 'string',
'belong' => 'string',
// 'turnover' => 'string',
'brand_cate' => 'string',
'work_address' => 'string',
'founded' => 'string',
'founder' => 'string'
];
/**
*
*/
public function BrandType():\think\model\relation\HasOne
{
return $this->hasOne(BrandType::class,'id','brand_type_id')->bind(['brand_type_name'=>'name']);
}
/**
*/
public function languageName():\think\model\relation\HasOne
{
return $this->hasOne(Language::class,'id','site_id')->bind(['language_name'=>'name']);
}
/**
* 获取列表
* @param array $data 查询条件
* @param mixed $simple 模糊搜索条件
* @param mixed $focus 精准搜索条件
* @param null $sort
* @param null $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getAllList(array $data,$simple = null,$focus = null,$sort = null,$field=null):array
{
$fields = array_keys($this->schema);
$collection = $this->field($field)->where(function ($query) use ($data,$fields,$simple,$focus) {
if (isset($data['platform_id'])) {
if (in_array('platform_id',$fields)) {
$query->where('platform_id',$data['platform_id']);
}
}
//模糊查询条件
if (!empty($simple)) {
foreach ($simple as $key => $item) {
if (in_array($key,$fields)) {
$query->where($key,'like',"%".$item."%");
}
}
}
//精准查询
if (!empty($focus)) {
foreach ($focus as $key => $item) {
if (in_array($key,$fields)) {
$query->where($key,$item);
}
}
}
});
if (isset($data['page']) && isset($data['size'])) {
$count = $collection->count() ?: 0;
$page = $collection->limit((int) $data['size'])->page((int)$data['page'])->order($sort)->with(['BrandType','languageName'])->select()->toArray();
return ['page'=>$page,'count'=>$count];
} else {
return $collection->order($sort)->with(['BrandType','languageName'])->select()->toArray();
}
}
}

122
app/api/model/BrandType.php Normal file
View File

@@ -0,0 +1,122 @@
<?php
declare(strict_types=1);
namespace app\api\model;
/**
* 文章分类
* @mixin \think\Model
*/
class BrandType extends BaseModel
{
protected $schema = [
'id' =>'int',
'platform_id' =>'int',
'site_id' =>'int',
'name' =>'string',
'desc' =>'string',
'icon' =>'string',
'sort' =>'int',
'create_time' =>'int',
'update_time' =>'int',
];
/**
* Brand分类与Brand表模型
* @return \think\model\relation\HasMany
*/
public function getBrand()
{
return $this->hasMany(Brand::class);
}
/**
* 获取列表
* @param array $data 查询条件
* @param mixed $simple 模糊搜索条件
* @param mixed $focus 精准搜索条件
* @param null $sort
* @param null $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getAllList(array $data,$simple = null,$focus = null,$sort = null,$field=null):array
{
$fields = array_keys($this->schema);
$collection = $this->field($field)->where(function ($query) use ($data,$fields,$simple,$focus) {
if (isset($data['platform_id'])) {
if (in_array('platform_id',$fields)) {
$query->where('platform_id',$data['platform_id']);
}
}
//模糊查询条件
if (!empty($simple)) {
foreach ($simple as $key => $item) {
if (in_array($key,$fields)) {
$query->where($key,'like',"%".$item."%");
}
}
}
//精准查询
if (!empty($focus)) {
foreach ($focus as $key => $item) {
if (in_array($key,$fields)) {
$query->where($key,$item);
}
}
}
});
if (isset($data['page']) && isset($data['size'])) {
$count = $collection->count() ?: 0;
$page = $collection->limit((int)$data['size'])->page((int)$data['page'])->order($sort)->select()->toArray();
foreach ($page as $key => $item) {
$page[$key]['language_id'] = $item['site_id'];
}
return ['page'=>$page,'count'=>$count];
} else {
$page = $collection->order($sort)->select()->toArray();
foreach ($page as $key => $item) {
$page[$key]['language_id'] = $item['site_id'];
}
return $page;
}
}
/**
* 获取对应分类下的文章内容
* @param $data
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getBrandData($data):array
{
$Brand = $this->find($data['id']);
if (!empty($Brand)) {
return $Brand->getBrand()->select()->toArray();
}
return [];
}
/**
* 获取对应分类下的文章内容
* @param $data
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getArticleData($data):array
{
$article = $this->find($data['id']);
if (!empty($article)) {
return $article->getBrand()->select()->toArray();
}
return [];
}
}

25
app/api/model/BulkBuy.php Normal file
View File

@@ -0,0 +1,25 @@
<?php
namespace app\api\model;
/**
* 大批量采购模型
* @mixin \think\Model
*/
class BulkBuy extends BaseModel
{
protected $schema = [
'id' =>'int',
'platform_id' =>'int',
'language_id' =>'int',
'site_id' =>'int',
'area_id' =>'int',
'name' =>'string',
'phone' =>'string',
'mode_number' =>'string',
'email' =>'string',
'arrival_country'=>'string',
'delivery_time' =>'int',
'create_time' =>'int',
'update_time' =>'int',
];
}

222
app/api/model/Comment.php Normal file
View File

@@ -0,0 +1,222 @@
<?php
declare(strict_types=1);
namespace app\api\model;
use think\facade\Env;
/**
* 用户评论表
* @mixin \think\Model
*/
class Comment extends BaseModel
{
protected $schema = [
'id' =>'int',
'platform_id' =>'int',
'language_id' =>'int',
'site_id' =>'int',
'avatar' =>'string',
'name' =>'string',
'nickname' =>'string',
'comment' =>'string',
'url' =>'string',
'sort' =>'int',
'create_time' =>'int',
'update_time' =>'int',
];
protected $disuse = ['name'];
/**
* 反馈附件关联
* @return \think\model\relation\HasMany
*/
public function CommentImage()
{
return $this->hasMany(CommentImage::class);
}
/**
* 获取列表
* @param array $data 查询条件
* @param mixed $simple 模糊搜索条件
* @param mixed $focus 精准搜索条件
* @param null $sort
* @param null $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getAllList(array $data,$simple = null,$focus = null,$sort = null,$field = null):array
{
$fields = array_keys($this->schema);
$collection = $this->field($field)->where(function ($query) use ($data,$fields,$simple,$focus) {
if (in_array('platform_id',$fields)) {
$query->where('platform_id',$data['platform_id']);
}
//模糊查询条件
if (!empty($simple)) {
foreach ($simple as $key => $item) {
if (in_array($key,$fields)) {
$query->where($key,'like',"%".$item."%");
}
}
}
//精准查询
if (!empty($focus)) {
foreach ($focus as $key => $item) {
if (in_array($key,$fields)) {
$query->where($key,$item);
}
}
}
});
$newCommentImage = [];
if (isset($data['page']) && isset($data['size'])) {
$count = $collection->count() ?: 0;
$page = $collection->limit((int)$data['size'])->page((int)$data['page'])->order($sort)->with('CommentImage')->select()->toArray();
if (!empty($page)) {
foreach ($page as $key => $value) {
$resData[$key]['language_id'] = $value['site_id'];
if (isset($value['CommentImage']) && !empty($value['CommentImage'])) {
foreach ($value['CommentImage'] as $key1 => $value1) {
$newCommentImage[$key1]['name'] = basename($value1['image']);
// $newCommentImage[$key1]['url'] = Env::get('QINIU.cdn') . $value1['image'];
$newCommentImage[$key1]['url'] = $value1['image'];
}
$page[$key]['CommentImage'] = $newCommentImage;
}
}
}
return ['page'=>$page,'count'=>$count];
} else {
$resData = $collection->order($sort)->with('CommentImage')->select()->toArray();
if (!empty($resData)) {
if ($resData['CommentImage']) {
foreach ($resData as $key => $value) {
$resData[$key]['language_id'] = $value['site_id'];
foreach ($value['CommentImage'] as $key1 => $value1) {
$newCommentImage[$key1]['name'] = basename($value1['image']);
// $newCommentImage[$key1]['url'] = Env::get('QINIU.cdn') . $value1['image'];
$newCommentImage[$key1]['url'] = $value1['image'];
}
$resData[$key]['CommentImage'] = $newCommentImage;
}
}
}
return $resData;
}
}
/**
* 新增数据
* @param $data
* @return bool
*/
public function addData($data):bool
{
$this->startTrans();
try {
$data['avatar'] = doImageURLtoRelativePath($data['avatar']);
$comment = $this->create($data);
//处理数据结构
if (!empty($data['CommentImage'])) {
foreach ($data['CommentImage'] as &$value) {
$value['comment_id'] = $comment->id;
$value['image'] = doImageURLtoRelativePath($value['url']);
}
//模型关联新增
$comment->CommentImage()->saveAll($data['CommentImage']);
}
$this->commit();
return true;
} catch (\Exception $e) {
$this->rollback();
return false;
}
}
/**
* 获取详情
* @param array $data
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getInfo(array $data):array
{
$comment = $this->find($data['id']);
$comment['CommentImage'] = $this->CommentImage()->where('comment_id',$data['id'])->select();
if ($comment['CommentImage']) {
$newImage = [];
foreach ($comment['CommentImage'] as $key1 => $value1) {
$newImage[$key1]['name'] = basename($value1['image']);
$newImage[$key1]['url'] = $value1['image'];
}
$comment['CommentImage'] = $newImage;
}
return $comment->toArray();
}
/**
* 编辑数据
* @param array $data
* @return bool
*/
public function editData(array $data):bool
{
$this->startTrans();
try {
$data['comment_image'] = $data['CommentImage'];
unset($data['CommentImage']);
$comment = $this->find($data['id']);
$data['avatar'] = doImageURLtoRelativePath($data['avatar']);
$result1 = $comment->save($data);
//先将原先的全部删除
if (!empty($data['comment_image'])) {
$result2 = $comment->CommentImage->delete();
if ($result1 && $result2) {
//处理数据结构
$newCommentImage = [];
foreach ($data['comment_image'] as $key => $value) {
$newCommentImage[] = [
'comment_id' => $data['id'],
'image' => doImageURLtoRelativePath($value['url']),
];
}
$data['comment_image'] = $newCommentImage;
//新增
$comment->CommentImage()->saveAll($data['comment_image']);
}
}
$this->commit();
return true;
} catch (\Exception $e) {
$this->rollback();
return false;
}
}
/**
* 删除数据
* @param array $data
* @return bool
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function delData(array $data):bool
{
$comment = $this->find($data['id']);
$result1 = $comment->delete();
//先将原先的全部删除
$result2 = $comment->CommentImage->delete();;
return $result1 && $result2;
}
}

View File

@@ -0,0 +1,16 @@
<?php
namespace app\api\model;
/**
* @mixin \think\Model
*/
class CommentImage extends BaseModel
{
protected $schema = [
'id' =>'int',
'comment_id' =>'int',
'image' =>'string',
'create_time' =>'int',
'update_time' =>'int',
];
}

23
app/api/model/Country.php Normal file
View File

@@ -0,0 +1,23 @@
<?php
namespace app\api\model;
/**
* 全球国家列表
* @mixin \think\Model
*/
class Country extends BaseModel
{
protected $schema = [
'id' => 'int',
'en' => 'string',
'code' => 'string',
'tw' => 'string',
'zh' => 'string',
'icon' => 'string',
'locale' => 'string',
'create_time' => 'int',
'update_time' => 'int'
];
}

View File

@@ -0,0 +1,78 @@
<?php
namespace app\api\model;
/**
* 优惠券订阅
* @mixin \think\Model
*/
class CouponSubscribe extends BaseModel
{
protected $schema = [
'id' =>'int',
'platform_id' =>'int',
'language_id' =>'int',
'site_id' =>'int',
'goods_coupon_id' =>'int',
'email' =>'string',
'phone' =>'string',
'create_time' =>'int',
'update_time' =>'int',
];
/**
* 获取列表
* @param array $data 查询条件
* @param mixed $simple 模糊搜索条件
* @param mixed $focus 精准搜索条件
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getAllList($data,$simple = null,$focus = null,$sort = null,$field = null)
{
$fields = array_keys($this->schema);
$collection = $this->field($field)->where(function ($query) use ($data,$fields,$simple,$focus) {
if (in_array('platform_id',$fields)) {
$query->where('platform_id',$data['platform_id']);
}
//模糊查询条件
if (!empty($simple)) {
foreach ($simple as $key => $item) {
if (in_array($key,$fields)) {
$query->where($key,'like',"%".$item."%");
}
}
}
//精准查询
if (!empty($focus)) {
foreach ($focus as $key => $item) {
if (in_array($key,$fields)) {
$query->where($key,$item);
}
}
}
});
if (isset($data['page']) && isset($data['size'])) {
$count = $collection->count() ?: 0;
$page = $collection->limit($data['size'])->page($data['page'])->order($sort)->select()->toArray();
if (!empty($page)) {
foreach ($page as $key => $item) {
$page[$key]['language_name'] = $this->getLanguageName($item['site_id']);
}
}
return ['page'=>$page,'count'=>$count];
} else {
$page = $collection->order($sort)->select()->toArray();
if (!empty($page)) {
foreach ($page as $key => $item) {
$page[$key]['language_name'] = $this->getLanguageName($item['site_id']);
}
}
return $page;
}
}
}

View File

@@ -0,0 +1,84 @@
<?php
declare(strict_types=1);
namespace app\api\model;
/**
* 货币模型
* @mixin \think\Model
*/
class Currency extends BaseModel
{
protected $schema = [
'id' =>'int',
'name' =>'string',
'code' =>'string',
'signal' =>'string',
'status' =>'int',
'create_time' =>'int',
'update_time' =>'int',
];
/**
* 通过币种ID获取平台是否已经使用
* @param $data
* @return array|\think\Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getPlatformCoin($data)
{
return Platform::where('currency_id',$data)->find();
}
/**
* 获取列表
* @param array $data 查询条件
* @param mixed $simple 模糊搜索条件
* @param mixed $focus 精准搜索条件
* @param null $sort
* @param null $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getAllList(array $data,$simple = null,$focus = null,$sort = null,$field=null):array
{
$fields = array_keys($this->schema);
$collection = $this->field($field)->where(function ($query) use ($data,$fields,$simple,$focus) {
if (isset($data['platform_id'])) {
if (in_array('platform_id',$fields)) {
$query->where('platform_id',$data['platform_id']);
}
}
//模糊查询条件
if (!empty($simple)) {
foreach ($simple as $key => $item) {
if (in_array($key,$fields)) {
$query->where($key,'like',"%".$item."%");
}
}
}
//精准查询
if (!empty($focus)) {
foreach ($focus as $key => $item) {
if (in_array($key,$fields)) {
$query->where($key,$item);
}
}
}
});
if (isset($data['page']) && isset($data['size'])) {
$count = $collection->count() ?: 0;
$page = $collection->limit($data['size'])->page($data['page'])->order($sort)->select()->toArray();
return ['page'=>$page,'count'=>$count];
} else {
return $collection->order($sort)->select()->toArray();
}
}
}

94
app/api/model/Faq.php Normal file
View File

@@ -0,0 +1,94 @@
<?php
declare(strict_types=1);
namespace app\api\model;
/**
* 常见问题
* @mixin \think\Model
*/
class Faq extends BaseModel
{
protected $schema = [
'id' =>'int',
'platform_id' =>'int',
'language_id' =>'int',
'site_id' =>'int',
'faq_type_id' =>'int',
'question' =>'string',
'answer' =>'string',
'sort' =>'int',
'status' =>'int',
'create_time' =>'int',
'update_time' =>'int',
];
/**
* 获取列表
* @param array $data 查询条件
* @param mixed $simple 模糊搜索条件
* @param mixed $focus 精准搜索条件
* @param null $sort
* @param null $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getAllList(array $data,$simple = null,$focus = null,$sort = null,$field=null):array
{
$fields = array_keys($this->schema);
$collection = $this->field($field)->where(function ($query) use ($data,$fields,$simple,$focus) {
if (in_array('platform_id',$fields)) {
$query->where('platform_id',$data['platform_id']);
}
//模糊查询条件
// if (!empty($simple)) {
// foreach ($simple as $key => $item) {
// if (in_array($key,$fields)) {
// $query->where($key,'like',"%".$item."%");
// }
// }
// }
//精准查询
if (!empty($focus)) {
foreach ($focus as $key => $item) {
if (in_array($key,$fields)) {
$query->where($key,$item);
}
}
}
})->where(function ($query) use ($data,$fields,$simple) {
//模糊查询条件
if (!empty($simple)) {
foreach ($simple as $key => $item) {
if (in_array($key,$fields)) {
$query->whereOr($key,'like',"%".$item."%");
}
}
}
});
if (isset($data['page']) && isset($data['size'])) {
$count = $collection->count() ?: 0;
$page = $collection->limit((int)$data['size'])->page((int)$data['page'])->order($sort)->select()->toArray();
//获取列表名称
if (!empty($page)) {
foreach ($page as $key => $item) {
$page[$key]['faq_type_name'] = $this->getFaqTypeName($item['faq_type_id']);
$page[$key]['language_id'] = $this->getFaqTypeName($item['site_id']);
}
}
return ['page'=>$page,'count'=>$count];
} else {
$page = $collection->order($sort)->select()->toArray();
if (!empty($page)) {
//获取列表名称
foreach ($page as $key => $item) {
$page[$key]['faq_type_name'] = $this->getFaqTypeName($item['faq_type_id']);
$page[$key]['language_id'] = $this->getFaqTypeName($item['site_id']);
}
}
return $page;
}
}
}

106
app/api/model/FaqType.php Normal file
View File

@@ -0,0 +1,106 @@
<?php
declare(strict_types=1);
namespace app\api\model;
/**
* 常见问题分类
* @mixin \think\Model
*/
class FaqType extends BaseModel
{
protected $schema = [
'id' =>'int',
'platform_id' =>'int',
'language_id' =>'int',
'site_id' =>'int',
'name' =>'string',
'desc' =>'string',
'icon' =>'string',
'sort' =>'int',
'create_time' =>'int',
'update_time' =>'int',
];
/**
* faq分类关联faq表模型
* @return \think\model\relation\HasMany
*/
public function getFaqContents()
{
return $this->hasMany(Faq::class);
}
/**
* 获取列表
* @param array $data 查询条件
* @param mixed $simple 模糊搜索条件
* @param mixed $focus 精准搜索条件
* @param null $sort
* @param null $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getAllList(array $data,$simple = null,$focus = null,$sort = null,$field=null):array
{
$fields = array_keys($this->schema);
$collection = $this->field($field)->where(function ($query) use ($data,$fields,$simple,$focus) {
if (isset($data['platform_id'])) {
if (in_array('platform_id',$fields)) {
$query->where('platform_id',$data['platform_id']);
}
}
//模糊查询条件
if (!empty($simple)) {
foreach ($simple as $key => $item) {
if (in_array($key,$fields)) {
$query->where($key,'like',"%".$item."%");
}
}
}
//精准查询
if (!empty($focus)) {
foreach ($focus as $key => $item) {
if (in_array($key,$fields)) {
$query->where($key,$item);
}
}
}
});
if (isset($data['page']) && isset($data['size'])) {
$count = $collection->count() ?: 0;
$page = $collection->limit((int)$data['size'])->page((int)$data['page'])->order($sort)->select()->toArray();
foreach ($page as $key => $item) {
$page[$key]['language_id'] = $item['site_id'];
}
return ['page'=>$page,'count'=>$count];
} else {
$page = $collection->order($sort)->select()->toArray();
foreach ($page as $key => $item) {
$page[$key]['language_id'] = $item['site_id'];
}
return $page;
}
}
/**
* 获取对应分类下的faq内容
* @param $data
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getFaqData($data)
{
$faqType = $this->find($data['id']);
if (!empty($faqType)) {
return $faqType->getFaqContents()->select()->toArray();
}
return false;
}
}

130
app/api/model/FileType.php Normal file
View File

@@ -0,0 +1,130 @@
<?php
declare(strict_types=1);
namespace app\api\model;
/**
* @mixin \think\Model
*/
class FileType extends BaseModel
{
protected $schema = [
'id' =>'int',
'platform_id' =>'int',
'language_id' =>'int',
'site_id' =>'int',
'name' =>'string',
'desc' =>'string',
'icon' =>'string',
'sort' =>'int',
'create_time' =>'int',
'update_time' =>'int',
];
public function fileTypeSoftManual()
{
return $this->hasMany(SoftManual::class);
}
/**
* 获取列表
* @param array $data 查询条件
* @param mixed $simple 模糊搜索条件
* @param mixed $focus 精准搜索条件
* @param null $sort
* @param null $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getAllList(array $data,$simple = null,$focus = null,$sort = null,$field = null):array
{
$fields = array_keys($this->schema);
$collection = $this->field($field)->where(function ($query) use ($data,$fields,$simple,$focus) {
if (in_array('platform_id',$fields)) {
$query->where('platform_id',$data['platform_id']);
}
//模糊查询条件
if (!empty($simple)) {
foreach ($simple as $key => $item) {
if (in_array($key,$fields)) {
$query->where($key,'like',"%".$item."%");
}
}
}
//精准查询
if (!empty($focus)) {
foreach ($focus as $key => $item) {
if (in_array($key,$fields)) {
$query->where($key,$item);
}
}
}
});
if (isset($data['page']) && isset($data['size'])) {
$count = $collection->count() ?: 0;
$page = $collection->limit((int)$data['size'])->page((int)$data['page'])->order($sort)->select()->toArray();
foreach ($page as $key => $item) {
$page[$key]['language_id'] = $item['site_id'];
}
return ['page'=>$page,'count'=>$count];
} else {
$resData = $collection->order($sort)->with('fileTypeSoftManual')->select()->toArray();
if (!empty($resData)) {
foreach ($resData as $key => $item)
$resData[$key]['language_id'] = $item['site_id'];{
if (count($item['fileTypeSoftManual']) > 0) {
$resData[$key]['is_gray'] = 1;
} else {
$resData[$key]['is_gray'] = 0;
}
}
}
return $resData;
}
}
/**
* 获取当前类型下驱动下载文件内容
* @param $data
* @return false
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getSoftManualData($data)
{
$softManual = $this->find($data['id']);
if (!empty($softManual)) {
return $softManual->fileTypeSoftManual()->select()->toArray();
}
return false;
}
/**
* 批量编辑数据
* @param $data
* @return \think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function batchEditData($data):bool
{
return (bool)$this->saveAll($data);
// $result = $result1 = true;
// foreach ($data as $item) {
// $models = $this->find($item['id']);
// if ($models) {
// $result1 = $models->save($item);
// }
// $result = $result && $result1;
// }
// return $result;
}
}

609
app/api/model/Goods.php Normal file
View File

@@ -0,0 +1,609 @@
<?php
declare(strict_types=1);
namespace app\api\model;
/**
* 商品模型
* @mixin \think\Model
*/
class Goods extends BaseModel
{
protected $schema = [
'id' =>'int',
'platform_id' =>'int',
'language_id' =>'int',
'site_id' =>'int',
'name' =>'string',
'main_img' =>'string',
'model_number' =>'string',
'goods_category_id' =>'int',
'price' =>'int',
'is_new' =>'int',
'is_discount' =>'int',
'is_hot' =>'int',
'is_recommend' =>'int',
'details' =>'string',
'title' =>'string',
'keywords' =>'string',
'description' =>'string',
'sort' =>'int',
'status' =>'int',
'create_time' =>'int',
'update_time' =>'int',
];
/**
* 商品链接关联模型
*/
public function GoodsBuyNow()
{
return $this->hasMany(GoodsBuyNow::class);
}
/**
* 商品关联商品
*/
public function GoodsConnect()
{
return $this->hasMany(GoodsConnect::class);
}
/**
* 商品手册关联模型
* @return \think\model\relation\HasMany
*/
public function GoodsSoftManual()
{
return $this->hasMany(GoodsSoftManual::class);
}
/**
* 商品主图关联模型
* @return \think\model\relation\HasMany
*/
public function GoodsImages()
{
return $this->hasMany(GoodsImages::class);
}
/**
* 商品属性关联
* @return \think\model\relation\HasMany
*/
public function goodsAttr()
{
return $this->hasMany(GoodsAttribute::class);
}
/**
* 获取列表
* @param array $data 查询条件
* @param mixed $simple 模糊搜索条件
* @param mixed $focus 精准搜索条件
* @param null $sort
* @param null $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getAllList(array $data,$simple = null,$focus = null,$sort = null,$field = null):array
{
$fields = array_keys($this->schema);
$collection = $this->field($field)->where(function ($query) use ($data,$fields,$simple,$focus) {
if (in_array('platform_id',$fields)) {
$query->where('platform_id',$data['platform_id']);
}
//模糊查询条件
if (!empty($simple)) {
foreach ($simple as $key => $item) {
if (in_array($key,$fields)) {
$query->where($key,'like',"%".$item."%");
}
}
}
//精准查询
if (!empty($focus)) {
foreach ($focus as $key => $item) {
if (in_array($key,$fields)) {
$query->where($key,$item);
}
}
}
//分类查询
if (!empty($data['goods_category_id']) && is_array($data['goods_category_id'])) {
$query->whereIn('goods_category_id',implode(',',$data['goods_category_id']));
}
});
//先筛选再分
if (isset($data['page']) && isset($data['size'])) {
$count = $collection->order($sort)->select()->count();
$page = $collection->order($sort)->limit((int)$data['size'])->page((int)$data['page'])->select()->toArray();
return ['page'=>array_values($page),'count'=>$count];
} else {
$resData = $collection->order($sort)->select()->toArray();
return array_values($resData);
}
}
/**
* 新增数据
* @param array $data
* @return bool
*/
public function addData(array $data):bool
{
//开启事务
$this->startTrans();
//增加主图
if (isset($data['goods_images'][0]['url'])) {
$data['main_img'] = doImageURLtoRelativePath($data['goods_images'][0]['url']);
} else {
//TODO::没有上传数据则使用空,后面可以替换为默认图片
$data['main_img'] = '';
}
$goods = $this->create($data);
//处理数据结构
$newBuyNow = [];
foreach ($data['buy_now'] as $key => $value) {
if ($value['name'] != '' && $value['url'] != '') {
$newBuyNow[$key]['goods_id'] = $goods->id;
$newBuyNow[$key]['name'] = $value['name'];
$newBuyNow[$key]['url'] = $value['url'];
}
}
$data['buy_now'] = $newBuyNow;
if (!empty($data['buy_now'])) {
$result1 = $goods->GoodsBuyNow()->saveAll($data['buy_now']);
} else {
unset($data['buy_now']);
$result1 = true;
}
$newGoodsImages = [];
foreach ($data['goods_images'] as $key => $value) {
if ($key < 8) {
$newGoodsImages[$key]['goods_id'] = $goods->id;
$newGoodsImages[$key]['image'] = doImageURLtoRelativePath($value['url']);
}
}
$data['goods_images'] = $newGoodsImages;
if (!empty($data['goods_images'])) {
$result2 = $goods->GoodsImages()->saveAll($data['goods_images']);
} else {
unset($data['goods_images']);
$result2 = true;
}
$newConnectGoods = [];
foreach ($data['connect_goods'] as $key => $value) {
if ($value['connect_good_id'] != '' && $value['goods_category_id'] != '') {
$newConnectGoods[$key]['goods_id'] = $goods->id;
$newConnectGoods[$key]['connect_good_id'] = $value['connect_good_id'];
$newConnectGoods[$key]['goods_category_id'] = $value['goods_category_id'];
}
}
$data['connect_goods'] = $newConnectGoods;
if (!empty($data['connect_goods'])) {
$result3 = $goods->GoodsConnect()->saveAll($data['connect_goods']);
} else {
unset($data['connect_goods']);
$result3 = true;
}
//处理驱动文档数据
$newSoft = [];
foreach ($data['soft_manual'] as $key => $value) {
if ($value['file_type_id'] != '' && $value['soft_manual_id'] != '') {
$newSoft[$key]['goods_id'] = $goods->id;
$newSoft[$key]['file_type_id'] = $value['file_type_id'];
$newSoft[$key]['soft_manual_id'] = $value['soft_manual_id'];
}
}
$data['soft_manual'] = $newSoft;
if (!empty($data['soft_manual'])) {
$result4 = $goods->GoodsSoftManual()->saveAll($data['soft_manual']);
} else {
unset($data['soft_manual']);
$result4 = true;
}
//处理属性attr
$newAttr = [];
foreach ($data['attr'] as $key => $item) {
if ($item['attribute_id'] != '' && $item['value'] != '') {
$newAttr[$key]['goods_id'] = $goods->id;
$newAttr[$key]['attribute_id'] = $item['attribute_id'];
$newAttr[$key]['value'] = $item['value'];
}
}
$data['attr'] = $newAttr;
if (!empty($data['attr'])) {
$result5 = $goods->goodsAttr()->saveAll($data['attr']);
} else {
unset($data['attr']);
$result5 = true;
}
//模型关联新增
if($result1 && $result2 && $result3 && $result4 && $result5) {
$this->commit();
return true;
} else {
$this->rollback();
return false;
}
}
/**
* 获取详情
* @param array $data
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getInfo(array $data):array
{
//初始化默认结构
$defaultBuyNow = [['name' => '','url' => '']];
$defaultSoftManual = [['file_type_id'=>'','soft_manual_id'=>'']];
$defaultAttr = [['id'=>'','value'=>'']];
$defaultGoodsImages = [['name'=>'','url'=>'']];
$defaultConnectGoods = [
['connect_good_id'=>'','goods_category_id'=>''],
['connect_good_id'=>'','goods_category_id'=>''],
['connect_good_id'=>'','goods_category_id'=>''],
['connect_good_id'=>'','goods_category_id'=>''],
];
$goods = $this->find($data['id']);
$goods['buy_now'] = $this->GoodsBuyNow()->where('goods_id',$data['id'])->select()->toArray();
$goods['goods_images'] = $this->GoodsImages()->where('goods_id',$data['id'])->select()->toArray();
$goods['connect_goods'] = $this->GoodsConnect()->where('goods_id',$data['id'])->select()->toArray();
$goods['soft_manual'] = $this->GoodsSoftManual()->where('goods_id',$data['id'])->select()->toArray();
$goods['attr'] = $this->goodsAttr()->where('goods_id',$data['id'])->select()->toArray();
//处理buynow
if (!empty($goods['buy_now'])) {
$newBuyNow = [];
foreach ($goods['buy_now'] as $key => $item) {
$newBuyNow[$key]['name'] = $item['name'];
$newBuyNow[$key]['url'] = $item['url'];
}
$goods['buy_now'] = $newBuyNow;
} else {
$goods['buy_now'] = $defaultBuyNow;
}
//处理属性attr
if (!empty($goods['attr'])) {
$newAttr = [];
foreach ($goods['attr'] as $key => $item) {
$newAttr[$key]['attribute_id'] = $item['attribute_id'];
$newAttr[$key]['value'] = $item['value'];
}
$goods['attr'] = $newAttr;
} else {
$goods['attr'] = $defaultAttr;
}
//处理图片
if (!empty($goods['goods_images'])) {
$newGoodsImages = [];
foreach ($goods['goods_images'] as $key => $item) {
if ($key < 8) {
$newGoodsImages[$key]['id'] = $item['id'];
$newGoodsImages[$key]['name'] = basename($item['image']);
$newGoodsImages[$key]['url'] = $item['image'];
}
}
$goods['goods_images'] = $newGoodsImages;
} else {
$goods['goods_images'] = $defaultGoodsImages;
}
//处理关联产品数据
if (!empty($goods['connect_goods'])) {
$newConnectGoods = [];
foreach ($goods['connect_goods'] as $key => $item) {
$newConnectGoods[$key]['id'] = $item['id'];
$newConnectGoods[$key]['connect_good_id'] = $item['connect_good_id'];
$newConnectGoods[$key]['type'] = $key;
$newConnectGoods[$key]['goods_category_id'] = $item['goods_category_id'];
}
if (count($newConnectGoods) < 4 ) {
$arr = [['connect_good_id'=>'','goods_category_id'=>'']];
switch (count($newConnectGoods)) {
case 1:
$newConnectGoods = array_merge(array_merge(array_merge($newConnectGoods,$arr),$arr),$arr);
break;
case 2:
$newConnectGoods = array_merge(array_merge($newConnectGoods,$arr),$arr);
break;
case 3:
$newConnectGoods = array_merge($newConnectGoods,$arr);
break;
}
}
$goods['connect_goods'] = $newConnectGoods;
} else {
$goods['connect_goods'] = $defaultConnectGoods;
}
//处理下载驱动手册
if (!empty($goods['soft_manual'])) {
$newSoft = [];
foreach ($goods['soft_manual'] as $key => $good) {
$newSoft[$key]['file_type_id'] = $good['file_type_id'];
$newSoft[$key]['soft_manual_id'] = $good['soft_manual_id'];
$newSoft[$key]['list'] = SoftManual::where('file_type_id',$good['file_type_id'])->select()->toArray();
}
$goods['soft_manual'] = $newSoft;
} else {
$goods['soft_manual'] = $defaultSoftManual;
}
return $goods->toArray();
}
/**
* 编辑数据
* @param $data
* @return bool
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function editData(array $data):bool
{
$this->startTrans();
$goods = $this->find($data['id']);
//如何编辑商品修改了分类数据,那么需要把相关产品对应的分类一同删除
if ($goods['goods_category_id'] != $data['goods_category_id']) {
$connect = GoodsConnect::where(['goods_id'=>$data['id'],'goods_category_id'=>$goods['goods_category_id']])->column(['id']);
if (!empty($connect)) {
GoodsConnect::destroy($connect);
}
}
// dd($goods['goods_category_id'] , $data['goods_category_id']);
//增加主图
$data['main_img'] = doImageURLtoRelativePath($data['goods_images'][0]['url']);
$result1 = $goods->save($data);
//先将原先的全部删除
$result2 = $goods->GoodsBuyNow->delete();
$result3 = $goods->GoodsImages->delete();
$result4 = $goods->GoodsConnect->delete();
$result5 = $goods->GoodsSoftManual->delete();
$result6 = $goods->goodsAttr->delete();
$result = false;
if ($result1 && $result2 && $result3 && $result4 && $result5 && $result6) {
//处理数据结构
$newBuyNow = [];
foreach ($data['buy_now'] as $key => $value) {
if ($value['name'] != '' && $value != '') {
$newBuyNow[$key]['goods_id'] = $data['id'];
$newBuyNow[$key]['name'] = $value['name'];
$newBuyNow[$key]['url'] = $value['url'];
}
}
$data['buy_now'] = $newBuyNow;
if (!empty($data['buy_now'])) {
$result11 = $goods->GoodsBuyNow()->saveAll($data['buy_now']);
} else {
$result11 = true;
}
$newGoodsImages = [];
foreach ($data['goods_images'] as $key => $value) {
if ($key < 8) {
$newGoodsImages[$key]['goods_id'] = $data['id'];
$newGoodsImages[$key]['image'] = doImageURLtoRelativePath($value['url']);
}
}
$data['goods_images'] = $newGoodsImages;
if (!empty($data['goods_images'])) {
$result22 = $goods->GoodsImages()->saveAll($data['goods_images']);
} else {
$result22 = true;
}
$newConnectGoods = [];
foreach ($data['connect_goods'] as $key => $value) {
if ($value['goods_category_id'] != '' && $value['connect_good_id'] != '') {
$newConnectGoods[$key]['goods_id'] = $data['id'];
$newConnectGoods[$key]['connect_good_id'] = $value['connect_good_id'];
$newConnectGoods[$key]['goods_category_id'] = $value['goods_category_id'];
}
}
$data['connect_goods'] = $newConnectGoods;
if (!empty($data['connect_goods'])) {
$result33 = $goods->GoodsConnect()->saveAll($data['connect_goods']);
} else {
$result33 = true;
}
//处理驱动文档数据
$newSoft = [];
foreach ($data['soft_manual'] as $key => $value) {
if ($value['file_type_id'] != '' && $value['soft_manual_id'] != '') {
$newSoft[$key]['goods_id'] = $data['id'];
$newSoft[$key]['file_type_id'] = $value['file_type_id'];
$newSoft[$key]['soft_manual_id'] = $value['soft_manual_id'];
}
}
$data['soft_manual'] = $newSoft;
if (!empty($data['soft_manual'])) {
$result44 = $goods->GoodsSoftManual()->saveAll($data['soft_manual']);
} else {
$result44 = true;
}
//处理属性attr
$newAttr = [];
foreach ($data['attr'] as $key => $item) {
if ($item['attribute_id'] != '' && $item['value'] != '') {
$newAttr[$key]['goods_id'] = $goods->id;
$newAttr[$key]['attribute_id'] = $item['attribute_id'];
$newAttr[$key]['value'] = $item['value'];
}
}
$data['attr'] = $newAttr;
if (!empty($data['attr'])) {
$result55 = $goods->goodsAttr()->saveAll($data['attr']);
} else {
$result55 = true;
}
$result = $result11 && $result22 && $result33 && $result44 && $result55;
}
if ($result) {
$this->commit();
return true;
} else {
$this->rollback();
return false;
}
}
/**
* 删除数据
* @param array $data
* @return bool
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function delData(array $data):bool
{
$goods = $this->find($data['id']);
$result1 = $goods->delete();
//先将原先的全部删除
$result2 = $goods->GoodsBuyNow->delete();
$result3 = $goods->GoodsImages->delete();
$result4 = $goods->GoodsConnect->delete();
$result5 = $goods->GoodsSoftManual->delete();
$result6 = $goods->goodsAttr->delete();
return $result1 && $result2 && $result3 && $result4 && $result5 && $result6;
}
/**
* 获取平台语言包列表
* @param $data
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getPlatformLanguage($data)
{
$result = (new Platform())->getPlatformLanguage($data);
if ($result) {
foreach ($result as $key => $item) {
$result[$key]['language_name'] = $this->getLanguageName($item['site_id']);
$result[$key]['coin_name'] = $this->getCoinName($item['currency_id']);
foreach ($item['PlatformLanguage'] as $key1 => $item1) {
$result[$key]['PlatformLanguage'][$key1]['language_name'] = $this->getLanguageName($item1['site_id']);
}
foreach ($item['PlatformCoin'] as $key1 => $item1) {
$result[$key]['PlatformCoin'][$key1]['coin_name'] = $this->getCoinName($item1['currency_id']);
}
}
return $result->toArray();
}
return [];
}
/**
* 通过分类ID获取商品列表
* @param $data
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getGoodsInfoByGoodsCategoryId($data)
{
return $this->where(['goods_category_id'=>$data['goods_category_id'],'status'=>0])->select()->toArray();
}
/**
* 批量删除数据
* @param array $data
* @return bool
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function batchDelData(array $data):bool
{
$newResult = true;
foreach ($data as $item) {
$result = $this->delData($item);
$newResult = $newResult && $result;
}
return $newResult;
}
/**
* 批量移除商品分类
* @param $data
* @return bool
*/
public function batchRemoveOldCate($data)
{
return GoodsCate::whereIn('goods_id',implode(',',$data))->delete();
}
/**
* @param $data
* @return bool|\think\Collection
* @throws \Exception
*/
public function goodsBatchEditCategory($data)
{
$this->startTrans();
try {
//修改分类时,先查询当前分类下的分类数据
foreach ($data as $datum) {
$goods = $this->find($datum['id']);
if ($goods['goods_category_id'] != $datum['goods_category_id']) {
$connect = GoodsConnect::where(['goods_id'=>$datum['id'],'goods_category_id'=>$goods['goods_category_id']])->column('id');
if (!empty($connect)) {
GoodsConnect::destroy($connect);
}
}
}
$result = $this->saveAll($data);
if ($result) {
$this->commit();
return true;
} else {
$this->rollback();
return false;
}
}catch (\Exception $e) {
$this->rollback();
return false;
}
}
/**
* 获取分类及其子分类
* @param $data
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getAllSonCategory($data)
{
$newData = (new GoodsCategory())->getAllSonCategory($data);
array_push($newData,$data['id']);
return $newData;
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace app\api\model;
/**
* @mixin \think\Model
*/
class GoodsAttribute extends BaseModel
{
protected $schema = [
'id' =>'int',
'goods_id' =>'int',
'attribute_id' =>'int',
'value' =>'string',
'create_time' =>'int',
'update_time' =>'int',
'sort' =>'int',
];
}

View File

@@ -0,0 +1,21 @@
<?php
namespace app\api\model;
/**
* 商品购买链接模型
* @mixin \think\Model
*/
class GoodsBuyNow extends BaseModel
{
protected $schema = [
'id' =>'int',
'goods_id' =>'int',
'url' =>'string',
'name' =>'string',
'create_time' =>'int',
'update_time' =>'int',
];
}

View File

@@ -0,0 +1,17 @@
<?php
namespace app\api\model;
/**
* @mixin \think\Model
*/
class GoodsCate extends BaseModel
{
protected $schema = [
'id' =>'int',
'goods_id' =>'int',
'goods_category_id' =>'int',
'create_time' =>'int',
'update_time' =>'int',
];
}

View File

@@ -0,0 +1,133 @@
<?php
declare(strict_types=1);
namespace app\api\model;
/**
* 商品分类
* @mixin \think\Model
*/
class GoodsCategory extends BaseModel
{
protected $schema = [
'id' =>'int',
'platform_id' =>'int',
'language_id' =>'int',
'site_id' =>'int',
'name' =>'int',
'desc' =>'int',
'pid' =>'int',
'icon' =>'int',
'sort' =>'int',
'status' =>'int',
'create_time' =>'int',
'update_time' =>'int',
];
/**
* 分类 商品数据
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getGategoryListData($data)
{
return (new Goods())->where(['goods_category_id'=>$data['goods_category_id'],'status'=>0])->select()->toArray();
}
/**
* 分类 商品明细数据
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getGategoryListDataInfo($data)
{
if (isset($data['id']) && $data['id'] != 0) {
$result = GoodsConnect::where('goods_id',$data['id'])->find();
return $result ? $result->toArray() : [] ;
}
return [];
}
/**
* 启用禁用
* @param $data
* @param bool $type
* @return bool
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function changeStatus($data,bool $type = false):bool
{
if (!$type) {
$result = $this->find($data['id']);
//正常更新
if ($result) {
return $result->save($data);
}
} else {
$ret = $this->saveAll($data);
return (bool) $ret;
}
return false;
}
/**
* 获取详情
* @param array $data
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getInfo(array $data):array
{
$allCategory = $this->select()->toArray();
$result = $this->find($data['id']);
$newPid = [];
if (!empty($allCategory)) {
if ($result['pid'] != 0) {
$newPid = category_to_all_pid($allCategory,$result['pid']);
} else {
$newPid = [0];
}
}
$result['pid'] = $newPid;
return $result->toArray();
}
/**
* 查找所有子项
* @param $data
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getAllSonCategory($data):array
{
$newData = $this->select()->toArray();
if (!empty($newData)) {
return category_to_all_children_id($newData,$data['id']);
}
return [];
}
/**
* 查询当前分类下是否在商品
* @param $data
* @return array|\think\Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function hasGoodsOnCategory($data)
{
return Goods::where('goods_category_id',$data['id'])->find();
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace app\api\model;
/**
* 关联商品模型
* @mixin \think\Model
*/
class GoodsConnect extends BaseModel
{
protected $schema = [
'id' =>'int',
'goods_id' =>'int',
'goods_category_id' =>'int',
'connect_good_id' =>'int',
'create_time' =>'int',
'update_time' =>'int',
];
}

View File

@@ -0,0 +1,35 @@
<?php
namespace app\api\model;
use think\Model;
/**
* 优惠券模型
* @mixin \think\Model
*/
class GoodsCoupon extends BaseModel
{
protected $schema = [
'id' =>'int',
'platform_id' =>'int',
'language_id' =>'int',
'site_id' =>'int',
'old_code' =>'string',
'new_code' =>'string',
'create_time' =>'int',
'update_time' =>'int',
];
/**
*
* @param $data
* @return array|Model|void|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getLatest($data)
{
return $this->order($this->pk,'desc')->where($data)->find();
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace app\api\model;
/**
* 商品主力模型
* @mixin \think\Model
*/
class GoodsImages extends BaseModel
{
protected $schema = [
'id' =>'int',
'goods_id' =>'int',
'image' =>'string',
'create_time' =>'int',
'update_time' =>'int',
];
}

View File

@@ -0,0 +1,19 @@
<?php
namespace app\api\model;
/**
* 商品手册驱动模型
* @mixin \think\Model
*/
class GoodsSoftManual extends BaseModel
{
protected $schema = [
'id' =>'int',
'goods_id' =>'int',
'file_type_id' =>'int',
'soft_manual_id'=>'int',
'create_time' =>'int',
'update_time' =>'int',
];
}

View File

@@ -0,0 +1,44 @@
<?php
namespace app\api\model;
/**
* @mixin \think\Model
*/
class ImagesFile extends BaseModel
{
/**
* 上传用户昵称关联
*/
public function uploader()
{
return $this->hasOne(User::class, 'id', 'up_id')->bind(['uploader_name'=>'nickname']);
}
// 根据ID查询
public function scopeId($query, $id)
{
if (is_array($id)) {
$query->where('id', 'in', $id);
} else {
$query->where('id', '=', $id);
}
}
// 根据上传人查询
public function scopeUpId($query, $up_id)
{
$query->where('up_id', '=', $up_id);
}
// 根据文件MD5值查询
public function scopeFileMd5($query, $md5)
{
$query->where('file_md5', '=', $md5);
}
// 根据文件hash值查询
public function scopeFileHash($query, $hash)
{
$query->where('file_hash', '=', $hash);
}
}

View File

@@ -0,0 +1,107 @@
<?php
declare (strict_types = 1);
namespace app\api\model;
/**
* 招商信息模型
*/
class Investment extends BaseModel
{
protected $schema = [
'id' => 'int',
'platform_id' => 'int',
'language_id' => 'int',
'site_id' => 'int',
'country_id' => 'int',
'province_id' => 'int',
'city_id' => 'int',
'from' => 'string',
'area' => 'string',
'phone' => 'string',
'name' => 'string',
'email' => 'string',
'wechat' => 'string',
'qq' => 'string',
'desc' => 'string',
'sort' => 'int',
'is_open' => 'int',
'create_time' => 'int',
'update_time' => 'int'
];
/**
* 查看列表数据
* @param int $page 分页页码
* @param int $pageSize 分页类目数量
* @param array $field 需要输入的字段,默认为全部输出,筛选表字段
* @param array $vague 需要进行模糊查询的字段,如: a like %a%
* @param array $focus 精确搜索条件,如a=1,b=2这种精确等于某个值的
* @param array $order 排序字段,如:['id'=>'desc','sort'=>'desc']
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getIndexList(int $page,int $pageSize,array $field = [], array $vague = [],array $focus = [],array $order = []):array
{
$fields = array_keys($this->schema);
$collection = $this->field($field)->where(function ($query) use ($fields,$focus) {
//精准查询
if (!empty($focus)) {
foreach ($focus as $key => $item) {
if (in_array($key,$fields)) {
$query->where($key,$item);
}
}
}
})->where(function($query) use ($fields,$vague) {
//模糊查询
if (!empty($vague)) {
$query->whereOr('phone','like',"%".$vague['keyword']."%");
$query->whereOr('name','like',"%".$vague['keyword']."%");
$query->whereOr('wechat','like',"%".$vague['keyword']."%");
$query->whereOr('qq','like',"%".$vague['keyword']."%");
$query->whereOr('email','like',"%".$vague['keyword']."%");
}
})->order($order);
//判断是否需要分页
if (0 == $page || 0 == $pageSize) {
//不需要分页
return $collection->select()->toArray();
} else {
//需要分布
$totalNum = $collection->count();
$data = $collection->page($page)->limit($pageSize)->select()->toArray();;
return ['count'=>$totalNum,'data'=>$data];
}
}
/**
* 通过ID获取数据
* @param $ids
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getExportData($ids): array
{
$result = $this->whereIn($this->pk,$ids['ids'])->order('create_time','desc')->select()->toArray();
foreach ($result as &$item){
$item['platform_id'] = $this->getPlatformName($item['platform_id']);
$item['language_id'] = $item['site_id'] = $this->getLanguageName($item['site_id']);
$item['country_id'] = '中国';
$item['province_id'] = $this->getAreaNameById($item['province_id']);
$item['city_id'] = $this->getAreaNameById($item['city_id']);
$item['is_open'] = $item['is_open'] == 0 ? '同意同类厂家查看,以便获得更多产品代理机会' : '同意意向厂家查看';
unset($item['area']);
unset($item['qq']);
unset($item['sort']);
unset($item['update_time']);
unset($item['email']);
}
return $result;
}
}

97
app/api/model/Join.php Normal file
View File

@@ -0,0 +1,97 @@
<?php
declare(strict_types=1);
namespace app\api\model;
/**
* 文章
* @mixin \think\Model
*/
class Join extends BaseModel
{
protected $schema = [
'id' => 'int',
'platform_id' => 'int',
'language_id' => 'int',
'site_id' => 'int',
'join_type_id' => 'int',
'title' => 'string',
'brief' => 'string',
'desc' => 'string',
'thumb' => 'string',
'url' => 'string',
'meta_title' => 'string',
'keywords' => 'string',
'detail' => 'string',
'sort' => 'int',
'status' => 'int',
'is_outer_chain' => 'int',
'is_on_index' => 'int',
'click_num' => 'int',
'create_time' => 'int',
'update_time' => 'int'
];
/**
*
*/
public function JoinType():\think\model\relation\HasOne
{
return $this->hasOne(JoinType::class,'id','join_type_id')->bind(['join_type_name'=>'name']);
}
/**
*/
public function languageName():\think\model\relation\HasOne
{
return $this->hasOne(Language::class,'id','site_id')->bind(['language_name'=>'name']);
}
/**
* 获取列表
* @param array $data 查询条件
* @param mixed $simple 模糊搜索条件
* @param mixed $focus 精准搜索条件
* @param null $sort
* @param null $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getAllList(array $data,$simple = null,$focus = null,$sort = null,$field=null):array
{
$fields = array_keys($this->schema);
$collection = $this->field($field)->where(function ($query) use ($data,$fields,$simple,$focus) {
if (isset($data['platform_id'])) {
if (in_array('platform_id',$fields)) {
$query->where('platform_id',$data['platform_id']);
}
}
//模糊查询条件
if (!empty($simple)) {
foreach ($simple as $key => $item) {
if (in_array($key,$fields)) {
$query->where($key,'like',"%".$item."%");
}
}
}
//精准查询
if (!empty($focus)) {
foreach ($focus as $key => $item) {
if (in_array($key,$fields)) {
$query->where($key,$item);
}
}
}
});
if (isset($data['page']) && isset($data['size'])) {
$count = $collection->count() ?: 0;
$page = $collection->limit((int) $data['size'])->page((int)$data['page'])->order($sort)->with(['JoinType','languageName'])->select()->toArray();
return ['page'=>$page,'count'=>$count];
} else {
return $collection->order($sort)->with(['JoinType','languageName'])->select()->toArray();
}
}
}

105
app/api/model/JoinType.php Normal file
View File

@@ -0,0 +1,105 @@
<?php
declare(strict_types=1);
namespace app\api\model;
/**
* 文章分类
* @mixin \think\Model
*/
class JoinType extends BaseModel
{
protected $schema = [
'id' =>'int',
'platform_id' =>'int',
'site_id' =>'int',
'name' =>'string',
'desc' =>'string',
'icon' =>'string',
'sort' =>'int',
'create_time' =>'int',
'update_time' =>'int',
];
/**
* article分类与article表模型
* @return \think\model\relation\HasMany
*/
public function getArticle()
{
return $this->hasMany(Join::class);
}
/**
* 获取列表
* @param array $data 查询条件
* @param mixed $simple 模糊搜索条件
* @param mixed $focus 精准搜索条件
* @param null $sort
* @param null $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getAllList(array $data,$simple = null,$focus = null,$sort = null,$field=null):array
{
$fields = array_keys($this->schema);
$collection = $this->field($field)->where(function ($query) use ($data,$fields,$simple,$focus) {
if (isset($data['platform_id'])) {
if (in_array('platform_id',$fields)) {
$query->where('platform_id',$data['platform_id']);
}
}
//模糊查询条件
if (!empty($simple)) {
foreach ($simple as $key => $item) {
if (in_array($key,$fields)) {
$query->where($key,'like',"%".$item."%");
}
}
}
//精准查询
if (!empty($focus)) {
foreach ($focus as $key => $item) {
if (in_array($key,$fields)) {
$query->where($key,$item);
}
}
}
});
if (isset($data['page']) && isset($data['size'])) {
$count = $collection->count() ?: 0;
$page = $collection->limit((int)$data['size'])->page((int)$data['page'])->order($sort)->select()->toArray();
foreach ($page as $key => $item) {
$page[$key]['language_id'] = $item['site_id'];
}
return ['page'=>$page,'count'=>$count];
} else {
$page = $collection->order($sort)->select()->toArray();
foreach ($page as $key => $item) {
$page[$key]['language_id'] = $item['site_id'];
}
return $page;
}
}
/**
* 获取对应分类下的文章内容
* @param $data
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getArticleData($data):array
{
$article = $this->find($data['id']);
if (!empty($article)) {
return $article->getArticle()->select()->toArray();
}
return [];
}
}

View File

@@ -0,0 +1,37 @@
<?php
declare(strict_types=1);
namespace app\api\model;
/**
* 语言包模型
* @mixin \think\Model
*/
class Language extends BaseModel
{
protected $schema = [
'id' => 'int',
'name' => 'string',
'code' => 'string',
'icon' => 'string',
'locale' => 'string',
'coin' => 'string',
'sort' => 'int',
'status' => 'int',
'create_time' => 'int',
'update_time' => 'int'
];
/**
* 查找语言包是否被使用
* @param $id
* @return array|\think\Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getLanguageUse($id)
{
return Platform::where('language_id',$id)->find();
}
}

View File

@@ -0,0 +1,51 @@
<?php
namespace app\api\model;
/**
* 访问日志
* @mixin \think\Model
*/
class LogVisit extends BaseModel
{
protected $schema = [
'id' => 'int',
'platform_id' => 'int',
'admin_id' => 'int',
'admin_name' => 'string',
'url' => 'string',
'params' => 'string',
'controller' => 'string',
'action' => 'string',
'ip' => 'string',
'create_time' => 'int',
'update_time' => 'int',
];
/**
* 写入日志
* @param $url
* @param $params
* @param $controller
* @param $action
* @param $admin_id
* @param $admin_name
* @param $platformId
* @return bool
*/
public function log($url, $params, $controller, $action,$admin_id, $admin_name,$platformId)
{
$insert_data = [
'url' => $url,
'params' => $params,
'controller' => $controller,
'action' => $action,
'admin_id' => $admin_id?:0,
'admin_name' => $admin_name?:'',
'ip' => get_client_ip(),
'platform_id' => $platformId?:0,
'create_time' => time()
];
return $this->save($insert_data);
}
}

119
app/api/model/Navigator.php Normal file
View File

@@ -0,0 +1,119 @@
<?php
declare(strict_types=1);
namespace app\api\model;
/**
* 导航样款模型
* @mixin \think\Model
*/
class Navigator extends BaseModel
{
protected $schema = [
'id' => 'int',
'platform_id' => 'int',
'language_id' => 'int',
'site_id' => 'int',
'pid' => 'int',
'name' => 'string',
'desc' => 'string',
'icon' => 'string',
'url' => 'string',
'sort' => 'int',
'status' => 'int',
'is_top' => 'int',
'is_foot' => 'int',
'create_time' => 'int',
'update_time' => 'int'
];
/**
* 查询子项
* @param $id
* @return int
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
private function getPidData($id):int
{
$result = $this->where('pid',$id)->find();
if ($result) {
return 1;
} else {
return 0;
}
}
/**
* 获取列表
* @param array $data 查询条件
* @param mixed $simple 模糊搜索条件
* @param mixed $focus 精准搜索条件
* @param null $sort
* @param null $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getAllList(array $data,$simple = null,$focus = null,$sort = null,$field = null):array
{
$fields = array_keys($this->schema);
$collection = $this->field($field)->where(function ($query) use ($data,$fields,$simple,$focus) {
if (in_array('platform_id',$fields)) {
$query->where('platform_id',$data['platform_id']);
}
//模糊查询条件
if (!empty($simple)) {
foreach ($simple as $key => $item) {
if (in_array($key,$fields)) {
$query->where($key,'like',"%".$item."%");
}
}
}
//精准查询
if (!empty($focus)) {
foreach ($focus as $key => $item) {
if (in_array($key,$fields)) {
$query->where($key,$item);
}
}
}
});
if (isset($data['page']) && isset($data['size'])) {
$count = $collection->count() ?: 0;
$page = $collection->limit((int)$data['size'])->page((int)$data['page'])->order($sort)->select()->toArray();
return ['page'=>$page,'count'=>$count];
} else {
$resData = $collection->order($sort)->select()->toArray();
foreach ($resData as $key => $item) {
if (1 === $this->getPidData($item['id'])) {
$resData[$key]['is_gray'] = 1;
} else {
$resData[$key]['is_gray'] = 0;
}
}
return $resData;
}
}
/**
* 判断导航栏是否有子类
* @param $id
* @return bool
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getNavigatorIsInUse($id):bool
{
$result = $this->where('pid',$id['id'])->find();
return (bool) $result;
}
}

97
app/api/model/News.php Normal file
View File

@@ -0,0 +1,97 @@
<?php
declare(strict_types=1);
namespace app\api\model;
/**
* 文章
* @mixin \think\Model
*/
class News extends BaseModel
{
protected $schema = [
'id' => 'int',
'platform_id' => 'int',
'language_id' => 'int',
'site_id' => 'int',
'news_type_id' => 'int',
'title' => 'string',
'brief' => 'string',
'desc' => 'string',
'thumb' => 'string',
'url' => 'string',
'meta_title' => 'string',
'keywords' => 'string',
'detail' => 'string',
'sort' => 'int',
'status' => 'int',
'is_outer_chain' => 'int',
'is_on_index' => 'int',
'click_num' => 'int',
'create_time' => 'int',
'update_time' => 'int'
];
/**
*
*/
public function NewsType():\think\model\relation\HasOne
{
return $this->hasOne(NewsType::class,'id','news_type_id')->bind(['news_type_name'=>'name']);
}
/**
*/
public function languageName():\think\model\relation\HasOne
{
return $this->hasOne(Language::class,'id','site_id')->bind(['language_name'=>'name']);
}
/**
* 获取列表
* @param array $data 查询条件
* @param mixed $simple 模糊搜索条件
* @param mixed $focus 精准搜索条件
* @param null $sort
* @param null $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getAllList(array $data,$simple = null,$focus = null,$sort = null,$field=null):array
{
$fields = array_keys($this->schema);
$collection = $this->field($field)->where(function ($query) use ($data,$fields,$simple,$focus) {
if (isset($data['platform_id'])) {
if (in_array('platform_id',$fields)) {
$query->where('platform_id',$data['platform_id']);
}
}
//模糊查询条件
if (!empty($simple)) {
foreach ($simple as $key => $item) {
if (in_array($key,$fields)) {
$query->where($key,'like',"%".$item."%");
}
}
}
//精准查询
if (!empty($focus)) {
foreach ($focus as $key => $item) {
if (in_array($key,$fields)) {
$query->where($key,$item);
}
}
}
});
if (isset($data['page']) && isset($data['size'])) {
$count = $collection->count() ?: 0;
$page = $collection->limit((int) $data['size'])->page((int)$data['page'])->order($sort)->with(['NewsType','languageName'])->select()->toArray();
return ['page'=>$page,'count'=>$count];
} else {
return $collection->order($sort)->with(['NewsType','languageName'])->select()->toArray();
}
}
}

105
app/api/model/NewsType.php Normal file
View File

@@ -0,0 +1,105 @@
<?php
declare(strict_types=1);
namespace app\api\model;
/**
* 文章分类
* @mixin \think\Model
*/
class NewsType extends BaseModel
{
protected $schema = [
'id' =>'int',
'platform_id' =>'int',
'site_id' =>'int',
'name' =>'string',
'desc' =>'string',
'icon' =>'string',
'sort' =>'int',
'create_time' =>'int',
'update_time' =>'int',
];
/**
* article分类与article表模型
* @return \think\model\relation\HasMany
*/
public function getArticle()
{
return $this->hasMany(News::class);
}
/**
* 获取列表
* @param array $data 查询条件
* @param mixed $simple 模糊搜索条件
* @param mixed $focus 精准搜索条件
* @param null $sort
* @param null $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getAllList(array $data,$simple = null,$focus = null,$sort = null,$field=null):array
{
$fields = array_keys($this->schema);
$collection = $this->field($field)->where(function ($query) use ($data,$fields,$simple,$focus) {
if (isset($data['platform_id'])) {
if (in_array('platform_id',$fields)) {
$query->where('platform_id',$data['platform_id']);
}
}
//模糊查询条件
if (!empty($simple)) {
foreach ($simple as $key => $item) {
if (in_array($key,$fields)) {
$query->where($key,'like',"%".$item."%");
}
}
}
//精准查询
if (!empty($focus)) {
foreach ($focus as $key => $item) {
if (in_array($key,$fields)) {
$query->where($key,$item);
}
}
}
});
if (isset($data['page']) && isset($data['size'])) {
$count = $collection->count() ?: 0;
$page = $collection->limit((int)$data['size'])->page((int)$data['page'])->order($sort)->select()->toArray();
foreach ($page as $key => $item) {
$page[$key]['language_id'] = $item['site_id'];
}
return ['page'=>$page,'count'=>$count];
} else {
$page = $collection->order($sort)->select()->toArray();
foreach ($page as $key => $item) {
$page[$key]['language_id'] = $item['site_id'];
}
return $page;
}
}
/**
* 获取对应分类下的文章内容
* @param $data
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getArticleData($data):array
{
$article = $this->find($data['id']);
if (!empty($article)) {
return $article->getArticle()->select()->toArray();
}
return [];
}
}

279
app/api/model/Platform.php Normal file
View File

@@ -0,0 +1,279 @@
<?php
declare(strict_types=1);
namespace app\api\model;
/**
* 平台模型
* @mixin \think\Model
*/
class Platform extends BaseModel
{
protected $schema = [
'id' => 'int',
'vi_color1' => 'string',
'vi_color2' => 'string',
'vi_color3' => 'string',
'language_id' => 'int',
'currency_id' => 'int',
'name' => 'string',
'desc' => 'string',
'icon' => 'string',
'sort' => 'int',
'status' => 'int',
'create_time' => 'int',
'update_time' => 'int',
];
/**
* 平台语言包关联模型
*/
public function PlatformLanguage():\think\model\relation\HasMany
{
return $this->hasMany(PlatformLanguage::class);
}
/**
* 平台币种关联模型
*/
public function PlatformCoin():\think\model\relation\HasMany
{
return $this->hasMany(PlatformCoin::class);
}
/**
* 通过平台ID查询平台有没有被使用
* @param $data
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function hasUserPlatform($data):array
{
return Site::where('platform_id',$data['id'])->select()->toArray();
}
/**
* 获取列表
* @param array $data 查询条件
* @param mixed $simple 模糊搜索条件
* @param mixed $focus 精准搜索条件
* @param null $sort
* @param null $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getAllList(array $data,$simple = null,$focus = null,$sort = null,$field = null):array
{
$fields = array_keys($this->schema);
$collection = $this->field($field)->where(function ($query) use ($data,$fields,$simple,$focus) {
if (isset($data['platform_id'])) {
if (in_array('platform_id',$fields)) {
$query->where('platform_id',$data['platform_id']);
}
}
//模糊查询条件
if (!empty($simple)) {
foreach ($simple as $key => $item) {
if (in_array($key,$fields)) {
$query->whereLike($key,'%'.$item.'%');
}
}
}
//精准查询
if (!empty($focus)) {
foreach ($simple as $key => $item) {
if (in_array($key,$fields)) {
$query->where($key,$item);
}
}
}
});
if (isset($data['page']) && isset($data['size'])) {
$count = $collection->count() ?: 0;
$page = $collection->limit($data['size'])->page($data['page'])->with(['PlatformLanguage'=>function($query) {
$query->with(['getLanguage'=>function ($query) {
$query->field(['id','name']);
}]);
},'PlatformCoin'=>function($query) {
$query->with(['getCoin'=>function ($query) {
$query->field(['id','name']);
}]);
}])->select()->toArray();
foreach ($page as $key => $item) {
$page[$key]['language_name'] = $this->getLanguageName($item['language_id']);
$page[$key]['currency_name'] = $this->getLanguageName($item['currency_id']);
}
return ['page'=>$page,'count'=>$count];
} else {
$resData = $this->where(function ($query) use ($data,$fields) {
if (in_array('platform_id',$fields)) {
$query->where('platform_id',$data['platform_id']);
} else {
$query->where(1);
}
})->with(['PlatformLanguage'=>function($query) {
$query->with(['getLanguage'=>function ($query) {
$query->field(['id','name']);
}]);
},'PlatformCoin'=>function($query) {
$query->with(['getCoin'=>function ($query) {
$query->field(['id','name']);
}]);
}])->select()->toArray();
foreach ($resData as $key => $item) {
$resData[$key]['language_name'] = $this->getLanguageName($item['language_id']);
$resData[$key]['currency_name'] = $this->getCoinName($item['currency_id']);
}
return $resData;
}
}
/**
* 新增数据
* @param array $data
* @return bool
*/
public function addData(array $data):bool
{
unset($data['id']);
$platform = $this->create($data);
if ($platform) {
//处理数据结构
foreach ($data['platform_language'] as $k => $value) {
$data['platform_language'][$k]['platform_id'] = $platform->id;
}
foreach ($data['platform_coin'] as $k => $value) {
$data['platform_coin'][$k]['platform_id'] = $platform->id;
}
//模型关联新增
$result = $platform->PlatformLanguage()->saveAll($data['platform_language']);
$result1 = $platform->PlatformCoin()->saveAll($data['platform_coin']);
return $result && $result1;
}
return false;
}
/**
* 获取详情
* @param array $data
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getInfo(array $data):array
{
$platform = $this->find($data['id'])->toArray();
if ($platform) {
$platform['platform_language'] = $this->PlatformLanguage()->where('platform_id',$data['id'])->select()->toArray();
$platform['platform_coin'] = $this->PlatformCoin()->where('platform_id',$data['id'])->select()->toArray();
return $platform;
}
return [];
}
/**
* 编辑数据
* @param $data
* @return bool
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function editData(array $data):bool
{
$this->startTrans();
try {
$platform = $this->find($data['id']);
if ($platform) {
$result1 = $platform->save($data);
//先将原先的全部删除
$result2 = $platform->PlatformLanguage->delete();
$result3 = $platform->PlatformCoin->delete();
$result = false;
if ($result1 && $result2 && $result3) {
//处理数据结构
foreach ($data['platform_language'] as $k => $value) {
$data[$k]['platform_language'] = $data['id'];
}
//处理数据结构
foreach ($data['platform_coin'] as $k => $value) {
$data[$k]['platform_coin'] = $data['id'];
}
//新增
$result4 = $platform->PlatformLanguage()->saveAll($data['platform_language']);
$result5 = $platform->PlatformCoin()->saveAll($data['platform_coin']);
$result = $result4 && $result5;
}
// return $result;
}
$this->commit();
return true;
} catch (\Exception $e) {
$this->rollback();
return false;
}
}
/**
* 删除数据
* @param array $data
* @return bool
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function delData(array $data):bool
{
$platform = $this->find($data['id']);
if ($platform) {
$result1 = $platform->delete();
//先将原先的全部删除
$result2 = $platform->PlatformLanguage->delete();;
$result3 = $platform->PlatformCoin->delete();;
return $result1 && $result2 && $result3;
}
return false;
}
/**
* @param $data
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getPlatformLanguage($data):array
{
return $this->where('id',$data)->with(['PlatformLanguage','PlatformCoin'])->select()->toArray();
}
/**
* @param $field
* @param $status
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getLanguageList($field,$status):array
{
return Language::field($field)->where($status)->select()->toArray();
}
}

View File

@@ -0,0 +1,25 @@
<?php
namespace app\api\model;
/**
* @mixin \think\Model
*/
class PlatformCoin extends BaseModel
{
protected $schema = [
'id' =>'int',
'currency_id' =>'int',
'platform_id' =>'int',
'create_time' =>'int',
'update_time' =>'int',
];
/**
* 平台-币种关联模型
* @return \think\model\relation\BelongsTo
*/
public function getCoin()
{
return $this->belongsTo(Currency::class,'currency_id','id');
}
}

View File

@@ -0,0 +1,27 @@
<?php
namespace app\api\model;
/**
* 平台语言表模型
* @mixin \think\Model
*/
class PlatformLanguage extends BaseModel
{
protected $schema = [
'id' =>'int',
'platform_id' =>'int',
'language_id' =>'int',
'create_time' =>'int',
'update_time' =>'int',
];
/**
* 平台-语言包关联模型
* @return \think\model\relation\BelongsTo
*/
public function getLanguage()
{
return $this->belongsTo(Language::class);
}
}

222
app/api/model/Question.php Normal file
View File

@@ -0,0 +1,222 @@
<?php
namespace app\api\model;
use think\facade\Env;
/**
* 用户反馈模型
* @mixin \think\Model
*/
class Question extends BaseModel
{
protected $schema = [
'id' => 'int',
'platform_id' => 'int',
'language_id' => 'int',
'site_id' => 'int',
'area_id' => 'int',
'country_id' => 'int',
'name' => 'string',
'email' => 'string',
'phone' => 'string',
'order_sn' => 'string',
'product_model' => 'string',
'os' => 'string',
'desc' => 'string',
'is_done' => 'int',
'is_send_email' => 'int',
'is_send_status' => 'int',
'send_time' => 'int',
'send_details' => 'string',
'create_time' => 'int',
'update_time' => 'int'
];
/**
* 反馈附件关联
* @return \think\model\relation\HasMany
*/
public function QuestionAttachment()
{
return $this->hasMany(QuestionAttachment::class);
}
/**
* 获取列表
* @param array $data 查询条件
* @param mixed $simple 模糊搜索条件
* @param mixed $focus 精准搜索条件
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getAllList($data,$simple = null,$focus = null,$sort = null,$field = null)
{
$fields = array_keys($this->schema);
$collection = $this->field($field)->where(function ($query) use ($data,$fields,$simple,$focus) {
if (in_array('platform_id',$fields)) {
$query->where('platform_id',$data['platform_id']);
}
//模糊查询条件
if (!empty($simple)) {
foreach ($simple as $key => $item) {
if (in_array($key,$fields)) {
$query->where($key,'like',"%".$item."%");
}
}
}
//精准查询
if (!empty($focus)) {
foreach ($focus as $key => $item) {
if (in_array($key,$fields)) {
$query->where($key,$item);
}
}
}
});
if (isset($data['page']) && isset($data['size'])) {
$count = $collection->count() ?: 0;
$page = $collection->limit($data['size'])->page($data['page'])->order($sort)->select()->toArray();
if (!empty($page)) {
foreach ($page as $key => $item) {
$lang = Language::find($data['site_id']);
if (!empty($lang)) {
if (strtolower($lang['code']) == 'zh-cn' || strtolower($lang['code']) == 'zh_cn') {
$page[$key]['country_name'] = '中国';
} else {
$page[$key]['country_name'] = $this->getCountryName($item['country_id']);
}
}
$page[$key]['is_done_name'] = $item['is_done'] == 0 ? '未解决': '已解决';
}
}
return ['page'=>$page,'count'=>$count];
} else {
$page = $collection->order($sort)->select()->toArray();
if (!empty($page)) {
foreach ($page as $key => $item) {
$page[$key]['country_name'] = $this->getCountryName($item['country_id']);
$page[$key]['is_done_name'] = $item['is_done'] == 0 ? '未解决': '已解决';
}
}
return $page;
}
}
/**
* 新增数据
* @param $data
* @return bool|void
*/
public function addData($data)
{
$this->startTrans();
$question = $this->create($data);
//处理数据结构
foreach ($data['question_attachment'] as $k => $value) {
$value['question_id'] = $question->id;
}
//模型关联新增
$result = $question->QuestionAttachment()->saveAll($data['question_attachment']);
if ($result && $question) {
$this->commit();
return true;
} else {
$this->rollback();
return false;
}
}
/**
* 获取详情
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getInfo($data)
{
$question = $this->find($data['id']);
$question['question_attachment'] = $this->QuestionAttachment()->where('question_id',$data['id'])->select()->toArray();
if (!empty($question['question_attachment'])) {
$newAttach = [];
foreach ($question['question_attachment'] as $key1 => $value1) {
$newAttach[$key1]['name'] = basename($value1['attach']);
// $newAttach[$key1]['url'] = Env::get('QINIU.cdn').$value1['image'];
$newAttach[$key1]['url'] = $value1['attach'];
}
$question['question_attachment'] = $newAttach;
}
return $question;
}
// /**
// * 编辑数据
// * @param $data
// * @return bool
// * @throws \think\db\exception\DataNotFoundException
// * @throws \think\db\exception\DbException
// * @throws \think\db\exception\ModelNotFoundException
// */
// public function editData($data)
// {
// $question = $this->find($data['id']);
// $result1 = $question->save($data);
// //先将原先的全部删除
// $result2 = $question->QuestionAttachment->delete();
// $result = false;
// if ($result1 && $result2) {
// //处理数据结构
// $newData = [];
// foreach ($data['question_attachment'] as $key => $value) {
// $newData[$key]['question_id'] = $data['id'];
// $newData[$key]['attach'] = $value['url'];
// }
// $data['question_attachment'] = $newData;
// //新增
// $result = $question->QuestionAttachment()->saveAll($data['question_attachment']);
// }
// return $result;
// }
/**
* 删除数据
* @param $data
* @return bool
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function delData($data)
{
$this->startTrans();
$question = $this->find($data['id']);
$result1 = $question->delete();
//先将原先的全部删除
$result2 = $question->QuestionAttachment->delete();;
if ($result1 && $result2) {
$this->commit();
return true;
} else {
$this->rollback();
return false;
}
}
/**
* 解决-未解决
* @param $data
* @return bool
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function isDone($data)
{
$question = $this->find($data['id']);
return $question->save($data);
}
}

View File

@@ -0,0 +1,27 @@
<?php
namespace app\api\model;
/**
* 反馈附件类
* @mixin \think\Model
*/
class QuestionAttachment extends BaseModel
{
protected $schema = [
'id' =>'int',
'question_id' =>'int',
'attach' =>'string',
'create_time' =>'int',
'update_time' =>'int',
];
/**
* 附件-问题关联表
* @return \think\model\relation\BelongsTo
*/
public function getQuestion()
{
return $this->belongsTo(Question::class);
}
}

View File

@@ -0,0 +1,98 @@
<?php
declare(strict_types=1);
namespace app\api\model;
/**
* 文章
* @mixin \think\Model
*/
class Resource extends BaseModel
{
protected $schema = [
'id' => 'int',
'platform_id' => 'int',
'language_id' => 'int',
'site_id' => 'int',
'resource_type_id' => 'int',
'title' => 'string',
's_title' => 'string',
'brief' => 'string',
'desc' => 'string',
'thumb' => 'string',
'url' => 'string',
'meta_title' => 'string',
'keywords' => 'string',
'detail' => 'string',
'sort' => 'int',
'status' => 'int',
'is_outer_chain' => 'int',
'is_on_index' => 'int',
'click_num' => 'int',
'create_time' => 'int',
'update_time' => 'int'
];
/**
*
*/
public function ResourceType():\think\model\relation\HasOne
{
return $this->hasOne(ResourceType::class,'id','resource_type_id')->bind(['resource_type_name'=>'name']);
}
/**
*/
public function languageName():\think\model\relation\HasOne
{
return $this->hasOne(Language::class,'id','site_id')->bind(['language_name'=>'name']);
}
/**
* 获取列表
* @param array $data 查询条件
* @param mixed $simple 模糊搜索条件
* @param mixed $focus 精准搜索条件
* @param null $sort
* @param null $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getAllList(array $data,$simple = null,$focus = null,$sort = null,$field=null):array
{
$fields = array_keys($this->schema);
$collection = $this->field($field)->where(function ($query) use ($data,$fields,$simple,$focus) {
if (isset($data['platform_id'])) {
if (in_array('platform_id',$fields)) {
$query->where('platform_id',$data['platform_id']);
}
}
//模糊查询条件
if (!empty($simple)) {
foreach ($simple as $key => $item) {
if (in_array($key,$fields)) {
$query->where($key,'like',"%".$item."%");
}
}
}
//精准查询
if (!empty($focus)) {
foreach ($focus as $key => $item) {
if (in_array($key,$fields)) {
$query->where($key,$item);
}
}
}
});
if (isset($data['page']) && isset($data['size'])) {
$count = $collection->count() ?: 0;
$page = $collection->limit((int) $data['size'])->page((int)$data['page'])->order($sort)->with(['ResourceType','languageName'])->select()->toArray();
return ['page'=>$page,'count'=>$count];
} else {
return $collection->order($sort)->with(['ResourceType','languageName'])->select()->toArray();
}
}
}

View File

@@ -0,0 +1,105 @@
<?php
declare(strict_types=1);
namespace app\api\model;
/**
* 文章分类
* @mixin \think\Model
*/
class ResourceType extends BaseModel
{
protected $schema = [
'id' =>'int',
'platform_id' =>'int',
'site_id' =>'int',
'name' =>'string',
'desc' =>'string',
'icon' =>'string',
'sort' =>'int',
'create_time' =>'int',
'update_time' =>'int',
];
/**
* article分类与article表模型
* @return \think\model\relation\HasMany
*/
public function getArticle()
{
return $this->hasMany(Resource::class);
}
/**
* 获取列表
* @param array $data 查询条件
* @param mixed $simple 模糊搜索条件
* @param mixed $focus 精准搜索条件
* @param null $sort
* @param null $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getAllList(array $data,$simple = null,$focus = null,$sort = null,$field=null):array
{
$fields = array_keys($this->schema);
$collection = $this->field($field)->where(function ($query) use ($data,$fields,$simple,$focus) {
if (isset($data['platform_id'])) {
if (in_array('platform_id',$fields)) {
$query->where('platform_id',$data['platform_id']);
}
}
//模糊查询条件
if (!empty($simple)) {
foreach ($simple as $key => $item) {
if (in_array($key,$fields)) {
$query->where($key,'like',"%".$item."%");
}
}
}
//精准查询
if (!empty($focus)) {
foreach ($focus as $key => $item) {
if (in_array($key,$fields)) {
$query->where($key,$item);
}
}
}
});
if (isset($data['page']) && isset($data['size'])) {
$count = $collection->count() ?: 0;
$page = $collection->limit((int)$data['size'])->page((int)$data['page'])->order($sort)->select()->toArray();
foreach ($page as $key => $item) {
$page[$key]['language_id'] = $item['site_id'];
}
return ['page'=>$page,'count'=>$count];
} else {
$page = $collection->order($sort)->select()->toArray();
foreach ($page as $key => $item) {
$page[$key]['language_id'] = $item['site_id'];
}
return $page;
}
}
/**
* 获取对应分类下的文章内容
* @param $data
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getArticleData($data):array
{
$article = $this->find($data['id']);
if (!empty($article)) {
return $article->getArticle()->select()->toArray();
}
return [];
}
}

49
app/api/model/Role.php Normal file
View File

@@ -0,0 +1,49 @@
<?php
declare(strict_types=1);
namespace app\api\model;
/**
* 角色类
* @mixin \think\Model
*/
class Role extends BaseModel
{
protected $schema = [
'id' => 'int',
'name' => 'string',
'desc' => 'string',
'create_time' => 'int',
'update_time' => 'int',
];
protected $disuse = [
'desc'
];
/**
* 角色菜单关联
* @return \think\model\relation\HasMany
*/
public function RoleToMenu()
{
return $this->hasMany(RoleToMenu::class);
}
/**
* 获取详情
* @param array $data
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getInfo(array $data):array
{
$result = $this->find($data['role_id']);
return $result ? $result->toArray() : [];
}
}

141
app/api/model/Site.php Normal file
View File

@@ -0,0 +1,141 @@
<?php
declare(strict_types=1);
namespace app\api\model;
use think\db\exception\DataNotFoundException;
use think\facade\Cache;
/**
* 站点类模型
* @mixin \think\Model
*/
class Site extends BaseModel
{
protected $schema = [
'id' =>'int',
'platform_id' =>'int',
'language_id' =>'int',
'currency_id' =>'int',
'domain' =>'string',
'app_id' =>'string',
'app_key' =>'string',
'status' =>'int',
'create_time' =>'int',
'update_time' =>'int',
];
/**
* 获取列表
* @param array $data 查询条件
* @param mixed $simple 模糊搜索条件
* @param mixed $focus 精准搜索条件
* @param null $sort
* @param null $field
* @return array
* @throws DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getAllList(array $data,$simple = null,$focus = null,$sort = null,$field = null):array
{
$fields = array_keys($this->schema);
$collection = $this->field($field)->where(function ($query) use ($data,$fields,$simple,$focus) {
if (isset($data['platform_id'])) {
if (in_array('platform_id',$fields)) {
$query->where('platform_id',$data['platform_id']);
}
}
//模糊查询条件
if (!empty($simple)) {
foreach ($simple as $key => $item) {
if (in_array($key,$fields)) {
$query->whereLike($key,'%'.$item.'%');
}
}
}
//精准查询
if (!empty($focus)) {
foreach ($focus as $key => $item) {
if (in_array($key,$fields)) {
$query->where($key,$item);
}
}
}
});
if (isset($data['page']) && isset($data['size'])) {
$count = $collection->count() ?: 0;
$page = $collection->limit($data['size'])->page($data['page'])->select()->toArray();
if (!empty($page)) {
foreach ($page as $key => $item) {
$lang = Language::find($item['language_id']);
$page[$key]['language_name'] = $lang ? $lang->toArray()['name']: "";
$page[$key]['currency_name'] = $this->getLanguageName($item['currency_id']);
$page[$key]['platform_name'] = $this->getPlatformName($item['platform_id']);
}
}
return ['page'=>$page,'count'=>$count];
} else {
$resData = $collection->field(['id','platform_id','language_id','currency_id','domain','status'])->select()->toArray();
if (!empty($resData)) {
foreach ($resData as $key => $item) {
$lang = Language::find($item['language_id']);
$resData[$key]['language_name'] = $lang ? $lang->toArray()['name']: "";
$resData[$key]['currency_name'] = $this->getCoinName($item['currency_id']);
$resData[$key]['platform_name'] = $this->getPlatformName($item['platform_id']);
}
}
return $resData;
}
}
/**
* 通过品牌ID与语言包ID获取是否存在相同的数据。
* @param $data
* @return array
* @throws DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getSiteData($data):array
{
return $this->where(['platform_id'=>$data['platform_id'],'language_id'=>$data['language_id']])->column('id');
}
/**
* 通过品牌ID判断站点是否存在
* @param $platformId
* @return bool
* @throws DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getSiteInfoByPlatformId($platformId):bool
{
$result = $this->where(['platform_id'=>$platformId])->select()->toArray();
if (!empty($result)) {
return true;
}
return false;
}
/**
* 删除数据
* @param array $data
* @return bool
* @throws DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function delData(array $data):bool
{
$result = $this->find($data['id']);
if ($result) {
Cache::set($result['app_id'],null);
return $result->delete();
}
return false;
}
}

View File

@@ -0,0 +1,230 @@
<?php
declare(strict_types=1);
namespace app\api\model;
use think\facade\Env;
/**
* 驱动手册模型
* @mixin \think\Model
*/
class SoftManual extends BaseModel
{
protected $schema = [
'id' => 'int',
'platform_id' => 'int',
'language_id' => 'int',
'site_id' => 'int',
'file_type_id' => 'int',
'name' => 'string',
'image' => 'string',
'introduce' => 'string',
'file_name' => 'string',
'btn_tips' => 'string',
'url' => 'string',
'support' => 'string',
'os' => 'string',
'sort' => 'int',
'status' => 'int',
'download_count'=> 'int',
'create_time' => 'int',
'update_time' => 'int',
];
/**
* 驱动手册分表
* @return \think\model\relation\HasMany
*/
public function softBtn()
{
return $this->hasMany(SoftManualBtn::class);
}
/**
* 获取列表
* @param array $data 查询条件
* @param mixed $simple 模糊搜索条件
* @param mixed $focus 精准搜索条件
* @param null $sort
* @param null $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getAllList(array $data,$simple = null,$focus = null,$sort = null,$field = null):array
{
$fields = array_keys($this->schema);
$collection = $this->field($field)->where(function ($query) use ($data,$fields,$simple,$focus) {
if (in_array('platform_id',$fields)) {
$query->where('platform_id',$data['platform_id']);
}
//模糊查询条件
if (!empty($simple)) {
foreach ($simple as $key => $item) {
if (in_array($key,$fields)) {
$query->where($key,'like',"%".$item."%");
}
}
}
//精准查询
if (!empty($focus)) {
foreach ($focus as $key => $item) {
if (in_array($key,$fields)) {
$query->where($key,$item);
}
}
}
});
if (isset($data['page']) && isset($data['size'])) {
$count = $collection->count() ?: 0;
$page = $collection->limit((int)$data['size'])->page((int)$data['page'])->with('softBtn')->order($sort)->select()->toArray();
if (!empty($page)) {
foreach ($page as $key => $item) {
$page[$key]['file_type_name'] = $this->getFileTypeName($item['file_type_id']);
}
}
return ['page'=>$page,'count'=>$count];
} else {
$resData = $collection->order($sort)->with('softBtn')->select()->toArray();
if (!empty($resData)) {
foreach ($resData as $key => $item) {
$resData[$key]['file_type_name'] = $this->getFileTypeName($item['file_type_id']);
}
}
return $resData;
}
}
/**
* 新增数据
* @param $data
*/
public function addData($data):bool
{
$this->startTrans();
try {
$soft = $this->create($data);
//处理数据结构
foreach ($data['softBtn'] as $key => $value) {
$data['softBtn'][$key]['soft_manual_id'] = $soft->id;
$data['softBtn'][$key]['btn_tips'] = $value['btn_tips'];
$data['softBtn'][$key]['url'] = $value['url'];
$data['softBtn'][$key]['file_name'] = $value['file_name'];
$data['softBtn'][$key]['md5'] = $value['md5'];
}
//模型关联新增
$soft->softBtn()->saveAll($data['softBtn']);
$this->commit();
return true;
} catch (\Exception $e) {
$this->rollback();
return false;
}
}
/**
* 获取详情
* @param $data
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getInfo($data):array
{
$soft = $this->find($data['id']);
$soft['softBtn'] = $soft->softBtn()->select()->toArray();
if (empty($soft['softBtn'])) {
$soft['softBtn'] = [['name'=>'','url'=>'','md5'=>'']];
}
return $soft->toArray();
}
/**
* 编辑数据
* @param $data
* @return bool
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function editData($data):bool
{
$this->startTrans();
try {
$soft = $this->find($data['id']);
if ($soft) {
$result2 = $soft->softBtn->delete();
$result1 = $soft->save($data);
//先将原先的全部删除
// $result = false;
if ($result1 && $result2) {
//处理数据结构
foreach ($data['softBtn'] as $key => $value) {
$data['softBtn'][$key]['soft_manual_id'] = $data['id'];
$data['softBtn'][$key]['btn_tips'] = $value['btn_tips'];
$data['softBtn'][$key]['url'] = $value['url'];
$data['softBtn'][$key]['file_name'] = $value['file_name'];
$data['softBtn'][$key]['md5'] = $value['md5'];
}
//新增
$result = $soft->softBtn()->saveAll($data['softBtn']);
}
// return $result;
}
$this->commit();
return true;
} catch (\Exception $e) {
$this->rollback();
return false;
}
}
/**
* 删除数据
* @param $data
* @return bool
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function delData($data):bool
{
$soft = $this->find($data['id']);
$result1 = $soft->delete();
//先将原先的全部删除
$result2 = $soft->softBtn->delete();;
return $result1 && $result2;
}
/**
* 编辑排序
* @param $data
* @return bool
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function changeSort($data):bool
{
$result = $this->find($data['id']);
return $result && $result->save($data);
}
/**
* 查询文档驱动是否被引用
* @param $data
* @return bool
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getSoftManualUsed($data)
{
$result = GoodsSoftManual::where('soft_manual_id',$data['id'])->find();
return (bool) $result;
}
}

View File

@@ -0,0 +1,20 @@
<?php
namespace app\api\model;
/**
* @mixin \think\Model
*/
class SoftManualBtn extends BaseModel
{
protected $schema = [
'id' => 'int',
'soft_manual_id'=> 'int',
'btn_tips' => 'string',
'url' => 'string',
'file_name' => 'string',
'md5' => 'string',
'create_time' => 'int',
'update_time' => 'int',
];
}

View File

@@ -0,0 +1,26 @@
<?php
declare (strict_types = 1);
namespace app\api\model;
/**
* 系统配置
* @mixin \think\Model
*/
class SystemConfig extends BaseModel
{
protected $schema = [
'id' =>'int',
'platform_id' =>'int',
'language_id' =>'int',
'site_id' =>'int',
'type' =>'int',
'page' =>'string',
'pos' =>'string',
'name' =>'string',
'value' =>'string',
'image' =>'string',
'create_time' =>'int',
'update_time' =>'int'
];
}

97
app/api/model/User.php Normal file
View File

@@ -0,0 +1,97 @@
<?php
declare (strict_types = 1);
namespace app\api\model;
/**
* 用户中心缓存表
* @mixin \think\Model
*/
class User extends BaseModel
{
protected $schema = [
'id' => 'int',
'uc_id' => 'int',
'admin_id' => 'int',
'role_id' => 'int',
'org_id' => 'int',
'dept_id' => 'int',
'staff_code' => 'string',
'nickname' => 'string',
'mobile' => 'string',
'email' => 'string',
'avatar' => 'string',
'gender' => 'int',
'create_time' => 'int',
'update_time' => 'int',
'signin_time' => 'int',
'signin_ip' => 'string',
'status' => 'int',
];
/**
* 获取详情
* @param array $data
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getInfo($data) : array
{
if (isset($data['admin_id'])) {
$result = $this->where('uc_id',$data['admin_id'])->find();
return $result ? $result->toArray() : [];
}
if (isset($data['uc_id'])) {
$result = $this->where('uc_id',$data['uc_id'])->find();
return $result ? $result->toArray() : [];
}
return [];
}
/**
* 通过角色ID,摘取对应菜单ID
* @param array $data
* @return array
*/
public function getMenuList(array $data):array
{
return $this->getMenuListUserCode($data['staff_code']);
}
/**
* 获取角色名称
* @param $roleId
* @return array|\think\Model|null
*/
public function getRolesName($roleId):string
{
$result = $this->getRoleDetailId($roleId);
return $result['role_name'] ?? '';
}
/**
* 查找菜单列表
* @param $arr
* @return array
*/
public function getMenuSiderList($arr):array
{
$result = $this->getMenuListApp();
if(!empty($result)) {
$newData = [];
foreach ($result as $datum) {
if (in_array($datum['id'],$arr)) {
array_push($newData,$datum);
}
}
return $newData;
} else {
return [];
}
}
}

24
app/api/model/Video.php Normal file
View File

@@ -0,0 +1,24 @@
<?php
declare (strict_types = 1);
namespace app\api\model;
/**
* 产品视频模型
*/
class Video extends BaseModel
{
protected $schema = [
'id' => 'int',
'platform_id' => 'int',
'site_id' => 'int',
'name' => 'string',
'image' => 'string',
'url' => 'string',
'is_top' => 'int',
'sort' => 'int',
'create_time' => 'int',
'update_time' => 'int'
];
}