You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
yanzong/app/store/controller/Server.php

377 lines
11 KiB

11 months ago
<?php
11 months ago
declare (strict_types=1);
11 months ago
namespace app\store\controller;
11 months ago
use app\common\enum\ServerEnum;
use app\common\model\store\StoreServerConfig;
11 months ago
use app\store\model\server\Server as ServerModel;
11 months ago
use app\store\model\ServerCategory;
11 months ago
use cores\exception\BaseException;
11 months ago
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
{
11 months ago
$data = $this->postForm();
if (!$data) {
return $this->renderError('缺少必要参数');
11 months ago
}
$model = new ServerCategory();
11 months ago
if ($model->add($data)) {
11 months ago
return $this->renderSuccess('添加成功');
}
return $this->renderError($model->getError() ?: '添加失败');
}
/**
* @notes:编辑分类
* @param int $categoryId
* @return Json
* @author: wanghousheng
*/
11 months ago
public function editCategory(int $categoryId): Json
11 months ago
{
11 months ago
$data = $this->postForm();
if (!$data) {
return $this->renderError('缺少必要参数');
11 months ago
}
11 months ago
$model = ServerCategory::detail($categoryId);
if ($model->edit($data)) {
11 months ago
return $this->renderSuccess('编辑成功');
}
return $this->renderError($model->getError() ?: '编辑失败');
}
11 months ago
11 months ago
public function deleteCategory(int $categoryId): Json
11 months ago
{
$model = ServerCategory::detail($categoryId);
if ($model->remove()) {
return $this->renderSuccess('删除成功');
}
return $this->renderError('删除失败');
}
11 months ago
/**
* @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
{
9 months ago
if (ServerModel::destroy($serverId)) {
11 months ago
return $this->renderSuccess('删除成功');
}
return $this->renderError('删除失败');
}
11 months ago
/**
* 根据服务ID集获取列表记录
* @param $serverIds
* @return Json
*/
public function listByIds($serverIds): Json
{
// 获取列表记录
$model = new ServerModel();
$list = $model->getListByIds($serverIds);
return $this->renderSuccess(compact('list'));
}
11 months ago
/**
* 修改服务状态(上下架)
* @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('操作成功');
}
11 months ago
/**
* @notes:服务订单列表
* @return Json
* @author: wanghousheng
*/
public function orderList(): Json
{
$model = new \app\common\model\server\Order;
$server_name = $this->request->post('server_name');
$order_no = $this->request->post('order_no');
$order_status = intval($this->request->post('order_status'));
$where = [];
if (!empty($server_name)) {
10 months ago
$where[] = ['a.server_name', 'like', "%$server_name%"];
11 months ago
}
if (!empty($order_no)) {
$where[] = ['a.order_no', '=', $order_no];
}
if ($order_status) {
$where[] = ['a.order_status', '=', $order_status];
}
$user_mobile = $this->request->post('user_mobile');
if ($user_mobile) {
$where[] = ['b.mobile', '=', $user_mobile];
}
$user_nickname = $this->request->post('user_nickname');
if ($user_nickname) {
$where[] = ['b.nick_name', 'like', "%$server_name%"];
}
$list = $model->getList($where);
10 months ago
$data['list'] = $list->items();
$data['total'] = $list->total();
return $this->renderSuccess($data);
11 months ago
}
9 months ago
/**
* @notes:订单详情
* @return Json
* @author: wanghousheng
*/
public function orderDetail(): Json
{
$orderId = intval($this->request->post('orderId'));
$data = \app\common\model\server\Order::detail(['order_id' => $orderId], ['user', 'dealer', 'image']);
$data['server_info'] = null;
if (!empty($data['server_id'])) {
$data['server_info'] = ServerModel::detail($data['server_id'], ['category']);
}
return $this->renderSuccess(['detail' => $data]);
}
11 months ago
/**
* @notes:订单状态
* @return Json
* @author: wanghousheng
*/
public function OrderStatus(): Json
{
$list = array_values(ServerEnum::data());
return $this->renderSuccess(compact('list'));
}
11 months ago
/**
* @notes:取消服务订单
* @param int $orderId
* @return Json
* @author: wanghousheng
*/
public function cancelOrder(int $orderId): Json
{
$order = \app\common\model\server\Order::detail($orderId);
if (empty($order)) {
return $this->renderError('订单信息不存在');
}
try {
$result = \app\common\service\server\Order::cancelOrder($order->toArray());
if ($result) {
return $this->renderSuccess('操作成功');
}
} catch (BaseException|DataNotFoundException|ModelNotFoundException|DbException $e) {
return $this->renderError($e->getMessage() ?: '取消失败');
}
return $this->renderError('取消失败');
}
9 months ago
/**
* @notes:删除订单
* @return Json
* @author: wanghousheng
*/
public function delOrder(): Json
{
$orderId = intval($this->request->post('order_id'));
if (!$orderId) {
return $this->renderError('非法请求');
}
if ((new \app\common\model\server\Order())->remove($orderId)) {
return $this->renderSuccess('操作成功');
}
return $this->renderError('操作失败');
}
11 months ago
/**
* @notes:派单
* @return Json
* @author: wanghousheng
*/
public function dispatchOrders(): Json
{
$data = $this->postForm();
if (empty($data['dealer_id'])) {
return $this->renderError('指派人员不能为空');
}
if (empty($data['order_id'])) {
return $this->renderError('缺少必要参数');
}
$order = \app\common\model\server\Order::detail($data['order_id']);
if (empty($order)) {
return $this->renderError('订单信息不存在');
}
$result = \app\common\service\server\Order::dispatchOrders($order->toArray(), $data['dealer_id']);
if ($result) {
return $this->renderSuccess('操作成功');
}
return $this->renderError('操作失败');
}
/**
* 服务配置
*/
9 months ago
public function configList()
{
$model = new StoreServerConfig();
9 months ago
$list = $model->with(['iconImage'])->hidden(['iconImage'])->order(['sort' => 'desc', 'create_time' => 'desc'])->paginate(10);
return $this->renderSuccess(compact('list'));
}
/**
* 服务配置添加
*/
9 months ago
public function configAdd()
{
$model = new StoreServerConfig();
if ($model->save(array_merge(['store_id' => $this->storeId], $this->postForm()))) {
return $this->renderSuccess('新增成功');
}
return $this->renderError('新增失败');
}
/**
* 服务配置编辑
*/
9 months ago
public function configEdit(int $id)
{
$detail = StoreServerConfig::get($id);
if ($detail) {
if ($detail->save($this->postForm())) {
return $this->renderSuccess('编辑成功');
}
}
return $this->renderError('编辑失败');
}
/**
* 删除服务配置
*/
9 months ago
public function configDel(int $id)
{
$detail = StoreServerConfig::get($id);
9 months ago
if ($detail->delete()) {
return $this->renderSuccess('删除成功');
}
return $this->renderError('删除失败');
}
11 months ago
}