Merge branch 'main' of http://git.njrzwl.cn:3000/wangmingchuan/yanzong
@ -1,3 +1,4 @@ |
||||
/.idea |
||||
/.vscode |
||||
*.log |
||||
/vendor |
||||
|
@ -0,0 +1,58 @@ |
||||
<?php |
||||
|
||||
namespace app\common\model; |
||||
|
||||
use cores\BaseModel; |
||||
use think\db\exception\DataNotFoundException; |
||||
use think\db\exception\DbException; |
||||
use think\db\exception\ModelNotFoundException; |
||||
use think\model\relation\HasOne; |
||||
|
||||
class ServerCategory extends BaseModel |
||||
{ |
||||
// 定义表名 |
||||
protected $name = 'server_category'; |
||||
|
||||
// 定义主键 |
||||
protected $pk = 'category_id'; |
||||
|
||||
/** |
||||
* 分类图片 |
||||
* @return HasOne |
||||
*/ |
||||
public function image(): HasOne |
||||
{ |
||||
return $this->hasOne('UploadFile', 'file_id', 'image_id'); |
||||
} |
||||
|
||||
/** |
||||
* @notes:分类详情 |
||||
* @param $where |
||||
* @param array $with |
||||
* @return static|array|null |
||||
* @author: wanghousheng |
||||
*/ |
||||
public static function detail($where, array $with = []) |
||||
{ |
||||
return static::get($where, $with); |
||||
} |
||||
|
||||
/** |
||||
* @notes:获取全部记录 |
||||
* @param array $where |
||||
* @return array |
||||
* @throws DataNotFoundException |
||||
* @throws DbException |
||||
* @throws ModelNotFoundException |
||||
* @author: wanghousheng |
||||
*/ |
||||
public function getList(array $where = []): array |
||||
{ |
||||
$where = $this->setQueryDefaultValue($where); |
||||
return $this->with(['image']) |
||||
->where($where) |
||||
->order(['sort', 'create_time']) |
||||
->select() |
||||
->toArray(); |
||||
} |
||||
} |
@ -0,0 +1,87 @@ |
||||
<?php |
||||
|
||||
namespace app\common\model\server; |
||||
|
||||
use app\common\model\ServerCategory; |
||||
use app\common\model\UploadFile; |
||||
use cores\BaseModel; |
||||
use think\db\exception\DbException; |
||||
use think\model\concern\SoftDelete; |
||||
use think\model\relation\HasOne; |
||||
use think\Paginator; |
||||
|
||||
class Server extends BaseModel |
||||
{ |
||||
|
||||
// 定义表名 |
||||
protected $name = 'server'; |
||||
|
||||
// 定义主键 |
||||
protected $pk = 'server_id'; |
||||
|
||||
use SoftDelete; |
||||
|
||||
protected string $deleteTime = 'delete_time'; |
||||
protected $defaultSoftDelete = 0; |
||||
|
||||
/** |
||||
* 图片 |
||||
* @return HasOne |
||||
*/ |
||||
public function image(): HasOne |
||||
{ |
||||
return $this->hasOne(UploadFile::class, 'file_id', 'image_id'); |
||||
} |
||||
|
||||
public function category(): HasOne |
||||
{ |
||||
return $this->hasOne(ServerCategory::class, 'category_id', 'category_id'); |
||||
} |
||||
|
||||
/** |
||||
* @notes:服务详情 |
||||
* @param $where |
||||
* @param array $with |
||||
* @return static|array|null |
||||
* @author: wanghousheng |
||||
*/ |
||||
public static function detail($where, array $with = []) |
||||
{ |
||||
return static::get($where, $with); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* @notes:获取全部记录 |
||||
* @param array $where |
||||
* @param int $listRows |
||||
* @param string $sort |
||||
* @param string $sort_type |
||||
* @return Paginator |
||||
* @throws DbException |
||||
* @author: wanghousheng |
||||
*/ |
||||
public function getList(array $where = [], int $listRows = 15, string $sort = '', string $sort_type = 'desc'): Paginator |
||||
{ |
||||
$where = $this->setQueryDefaultValue($where); |
||||
$sort_arr = ['sort' => $sort_type, 'create_time' => $sort_type]; |
||||
if ($sort) { |
||||
$sort_arr = [$sort => $sort_type, 'create_time' => $sort_type]; |
||||
} |
||||
return $this->with(['image'])->withJoin(['category' => ['category_id', 'name']]) |
||||
->where($where) |
||||
->order($sort_arr) |
||||
->paginate($listRows); |
||||
} |
||||
|
||||
/** |
||||
* 文章详情:HTML实体转换回普通字符 |
||||
* @param $value |
||||
* @return string |
||||
*/ |
||||
public function getContentAttr($value): string |
||||
{ |
||||
return htmlspecialchars_decode($value); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,185 @@ |
||||
<?php |
||||
|
||||
namespace app\store\controller; |
||||
|
||||
use app\store\model\server\Server as ServerModel; |
||||
use app\store\model\ServerCategory; |
||||
use think\db\exception\DataNotFoundException; |
||||
use think\db\exception\DbException; |
||||
use think\db\exception\ModelNotFoundException; |
||||
use think\response\Json; |
||||
|
||||
class Server extends Controller |
||||
{ |
||||
/** |
||||
* @notes:分类列表 10269 |
||||
* @return Json |
||||
* @author: wanghousheng |
||||
*/ |
||||
public function categoryList(): Json |
||||
{ |
||||
$name = $this->request->post('name'); |
||||
$where = []; |
||||
if (!empty($name)) { |
||||
$where[] = ['name', 'like', `%$name%`]; |
||||
} |
||||
$model = new ServerCategory(); |
||||
try { |
||||
$list = $model->getList($where); |
||||
} catch (DataNotFoundException|ModelNotFoundException|DbException $e) { |
||||
return $this->renderError($e->getMessage() ?: '接口异常'); |
||||
} |
||||
return $this->renderSuccess(compact('list')); |
||||
} |
||||
|
||||
/** |
||||
* @notes:添加分类 |
||||
* @return Json |
||||
* @author: wanghousheng |
||||
*/ |
||||
public function addCategory(): Json |
||||
{ |
||||
$data = $this->postForm(); |
||||
if (!$data) { |
||||
return $this->renderError('缺少必要参数'); |
||||
} |
||||
$model = new ServerCategory(); |
||||
if ($model->add($data)) { |
||||
return $this->renderSuccess('添加成功'); |
||||
} |
||||
return $this->renderError($model->getError() ?: '添加失败'); |
||||
} |
||||
|
||||
/** |
||||
* @notes:编辑分类 |
||||
* @param int $categoryId |
||||
* @return Json |
||||
* @author: wanghousheng |
||||
*/ |
||||
public function editCategory(int $categoryId): Json |
||||
{ |
||||
$data = $this->postForm(); |
||||
if (!$data) { |
||||
return $this->renderError('缺少必要参数'); |
||||
} |
||||
$model = ServerCategory::detail($categoryId); |
||||
if ($model->edit($data)) { |
||||
return $this->renderSuccess('编辑成功'); |
||||
} |
||||
return $this->renderError($model->getError() ?: '编辑失败'); |
||||
} |
||||
|
||||
public function deleteCategory(int $categoryId): Json |
||||
{ |
||||
$model = ServerCategory::detail($categoryId); |
||||
if ($model->remove()) { |
||||
return $this->renderSuccess('删除成功'); |
||||
} |
||||
return $this->renderError('删除失败'); |
||||
} |
||||
|
||||
/** |
||||
* @notes:服务列表 |
||||
* @return Json |
||||
* @author: wanghousheng |
||||
*/ |
||||
public function serverList(): Json |
||||
{ |
||||
// 获取列表记录 |
||||
$model = new ServerModel(); |
||||
$server_name = $this->request->post('server_name'); |
||||
$category_id = intval($this->request->post('category_id')); |
||||
$status = intval($this->request->post('status')); |
||||
$where = []; |
||||
if ($server_name) { |
||||
$where[] = ['server.server_name', 'like', "%$server_name%"]; |
||||
} |
||||
if ($category_id) { |
||||
$where[] = ['server.category_id', '=', $category_id]; |
||||
} |
||||
if ($status) { |
||||
$where[] = ['server.status', '=', $status]; |
||||
} |
||||
try { |
||||
$list = $model->getList($where); |
||||
} catch (DbException $e) { |
||||
return $this->renderError($e->getMessage()); |
||||
} |
||||
return $this->renderSuccess(compact('list')); |
||||
} |
||||
|
||||
public function ServerDetail(int $serverId): Json |
||||
{ |
||||
// 获取商品详情 |
||||
$model = new ServerModel; |
||||
$info = $model->getDetail($serverId); |
||||
return $this->renderSuccess(compact('info')); |
||||
} |
||||
|
||||
/** |
||||
* @notes:添加服务 |
||||
* @return Json |
||||
* @author: wanghousheng |
||||
*/ |
||||
public function addServer(): Json |
||||
{ |
||||
$data = $this->postForm(); |
||||
if (!$data) { |
||||
return $this->renderError('缺少必要参数'); |
||||
} |
||||
$model = new ServerModel(); |
||||
if ($model->add($data)) { |
||||
return $this->renderSuccess('添加成功'); |
||||
} |
||||
return $this->renderError($model->getError() ?: '添加失败'); |
||||
} |
||||
|
||||
/** |
||||
* @notes:编辑服务 |
||||
* @param int $serverId |
||||
* @return Json |
||||
* @author: wanghousheng |
||||
*/ |
||||
public function editServer(int $serverId): Json |
||||
{ |
||||
$data = $this->postForm(); |
||||
if (!$data) { |
||||
return $this->renderError('缺少必要参数'); |
||||
} |
||||
$model = ServerModel::detail($serverId); |
||||
if ($model->edit($data)) { |
||||
return $this->renderSuccess('编辑成功'); |
||||
} |
||||
return $this->renderError($model->getError() ?: '编辑失败'); |
||||
} |
||||
|
||||
/** |
||||
* @notes:删除服务 |
||||
* @param array $serverId |
||||
* @return Json |
||||
* @author: wanghousheng |
||||
*/ |
||||
public function deleteServer(array $serverId): Json |
||||
{ |
||||
$model = new ServerModel; |
||||
if ($model->remove($serverId)) { |
||||
return $this->renderSuccess('删除成功'); |
||||
} |
||||
return $this->renderError('删除失败'); |
||||
} |
||||
|
||||
/** |
||||
* 修改服务状态(上下架) |
||||
* @param array $serverIds 商品id集 |
||||
* @param bool $state 为true表示上架 |
||||
* @return Json |
||||
*/ |
||||
public function serverStatus(array $serverIds, bool $state): Json |
||||
{ |
||||
$model = new ServerModel; |
||||
if (!$model->setStatus($serverIds, $state)) { |
||||
return $this->renderError($model->getError() ?: '操作失败'); |
||||
} |
||||
return $this->renderSuccess('操作成功'); |
||||
} |
||||
} |
@ -0,0 +1,52 @@ |
||||
<?php |
||||
|
||||
namespace app\store\model; |
||||
|
||||
use app\common\model\ServerCategory as ServerCategoryModel; |
||||
|
||||
/** |
||||
* 服务分类模型 |
||||
* Class ServerCategory |
||||
* @package app\store\model |
||||
*/ |
||||
class ServerCategory extends ServerCategoryModel |
||||
{ |
||||
/** |
||||
* @notes:新增 |
||||
* @param $data |
||||
* @return bool |
||||
* @author: wanghousheng |
||||
*/ |
||||
public function add($data): bool |
||||
{ |
||||
$data['store_id'] = self::$storeId; |
||||
return $this->save($data); |
||||
} |
||||
|
||||
/** |
||||
* @notes:编辑 |
||||
* @param $data |
||||
* @return bool |
||||
* @author: wanghousheng |
||||
*/ |
||||
public function edit($data): bool |
||||
{ |
||||
// 是否删除图片 |
||||
!isset($data['image_id']) && $data['image_id'] = 0; |
||||
return $this->save($data) !== false; |
||||
} |
||||
|
||||
/** |
||||
* @notes:删除 |
||||
* @return bool |
||||
* @author: wanghousheng |
||||
*/ |
||||
public function remove(): bool |
||||
{ |
||||
if (!static::detail(['category_id' => $this['category_id']])) { |
||||
$this->error = '记录不存在'; |
||||
return false; |
||||
} |
||||
return $this->delete(); |
||||
} |
||||
} |
@ -0,0 +1,69 @@ |
||||
<?php |
||||
|
||||
namespace app\store\model\server; |
||||
|
||||
use app\common\model\server\Server as ServerModel; |
||||
use think\db\exception\DataNotFoundException; |
||||
use think\db\exception\DbException; |
||||
use think\db\exception\ModelNotFoundException; |
||||
|
||||
class Server extends ServerModel |
||||
{ |
||||
|
||||
/** |
||||
* @notes:新增 |
||||
* @param $data |
||||
* @return bool |
||||
* @author: wanghousheng |
||||
*/ |
||||
public function add($data): bool |
||||
{ |
||||
$data['store_id'] = self::$storeId; |
||||
return $this->save($data); |
||||
} |
||||
|
||||
/** |
||||
* @notes:编辑 |
||||
* @param $data |
||||
* @return bool |
||||
* @author: wanghousheng |
||||
*/ |
||||
public function edit($data): bool |
||||
{ |
||||
// 是否删除图片 |
||||
!isset($data['image_id']) && $data['image_id'] = 0; |
||||
return $this->save($data) !== false; |
||||
} |
||||
|
||||
/** |
||||
* @notes:删除 |
||||
* @param array $serverId |
||||
* @return bool |
||||
* @author: wanghousheng |
||||
*/ |
||||
public function remove(array $serverId): bool |
||||
{ |
||||
try { |
||||
return static::whereIn('server_id', $serverId)->select()->delete(); |
||||
} catch (DataNotFoundException|ModelNotFoundException|DbException $e) { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 修改服务状态 |
||||
* @param array $serverIds 商品id集 |
||||
* @param bool $state 为true表示上架 |
||||
* @return bool|false |
||||
*/ |
||||
public function setStatus(array $serverIds, bool $state): bool |
||||
{ |
||||
// 批量更新记录 |
||||
return static::updateBase(['status' => $state ? 1 : 2], [['server_id', 'in', $serverIds]]); |
||||
} |
||||
|
||||
public function getDetail(int $serverId) |
||||
{ |
||||
return static::detail($serverId, ['image', 'category']); |
||||
} |
||||
} |
Before Width: | Height: | Size: 126 B After Width: | Height: | Size: 126 B |
Before Width: | Height: | Size: 202 B After Width: | Height: | Size: 202 B |
Before Width: | Height: | Size: 205 B After Width: | Height: | Size: 205 B |
Before Width: | Height: | Size: 216 B After Width: | Height: | Size: 216 B |
Before Width: | Height: | Size: 210 B After Width: | Height: | Size: 210 B |
Before Width: | Height: | Size: 213 B After Width: | Height: | Size: 213 B |
Before Width: | Height: | Size: 219 B After Width: | Height: | Size: 219 B |
Before Width: | Height: | Size: 211 B After Width: | Height: | Size: 211 B |
Before Width: | Height: | Size: 211 B After Width: | Height: | Size: 211 B |
Before Width: | Height: | Size: 228 B After Width: | Height: | Size: 228 B |
Before Width: | Height: | Size: 225 B After Width: | Height: | Size: 225 B |
Before Width: | Height: | Size: 144 B After Width: | Height: | Size: 144 B |
Before Width: | Height: | Size: 225 B After Width: | Height: | Size: 225 B |
Before Width: | Height: | Size: 235 B After Width: | Height: | Size: 235 B |
Before Width: | Height: | Size: 226 B After Width: | Height: | Size: 226 B |
Before Width: | Height: | Size: 220 B After Width: | Height: | Size: 220 B |
Before Width: | Height: | Size: 242 B After Width: | Height: | Size: 242 B |
Before Width: | Height: | Size: 242 B After Width: | Height: | Size: 242 B |
Before Width: | Height: | Size: 244 B After Width: | Height: | Size: 244 B |
Before Width: | Height: | Size: 237 B After Width: | Height: | Size: 237 B |
Before Width: | Height: | Size: 234 B After Width: | Height: | Size: 234 B |
Before Width: | Height: | Size: 232 B After Width: | Height: | Size: 232 B |
Before Width: | Height: | Size: 147 B After Width: | Height: | Size: 147 B |
Before Width: | Height: | Size: 255 B After Width: | Height: | Size: 255 B |
Before Width: | Height: | Size: 260 B After Width: | Height: | Size: 260 B |
Before Width: | Height: | Size: 262 B After Width: | Height: | Size: 262 B |
Before Width: | Height: | Size: 253 B After Width: | Height: | Size: 253 B |
Before Width: | Height: | Size: 256 B After Width: | Height: | Size: 256 B |
Before Width: | Height: | Size: 243 B After Width: | Height: | Size: 243 B |
Before Width: | Height: | Size: 272 B After Width: | Height: | Size: 272 B |
Before Width: | Height: | Size: 279 B After Width: | Height: | Size: 279 B |
Before Width: | Height: | Size: 279 B After Width: | Height: | Size: 279 B |
Before Width: | Height: | Size: 264 B After Width: | Height: | Size: 264 B |
Before Width: | Height: | Size: 149 B After Width: | Height: | Size: 149 B |
Before Width: | Height: | Size: 267 B After Width: | Height: | Size: 267 B |
Before Width: | Height: | Size: 150 B After Width: | Height: | Size: 150 B |
Before Width: | Height: | Size: 151 B After Width: | Height: | Size: 151 B |
Before Width: | Height: | Size: 189 B After Width: | Height: | Size: 189 B |
Before Width: | Height: | Size: 204 B After Width: | Height: | Size: 204 B |
Before Width: | Height: | Size: 199 B After Width: | Height: | Size: 199 B |