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/api/controller/Server.php

143 lines
4.0 KiB

1 year ago
<?php
/**
* 服务控制器
*/
namespace app\api\controller;
use app\api\model\Server\ServerCategory;
use app\api\model\Server\ServerOrder;
use app\common\enum\ServerEnum;
use cores\exception\BaseException;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\response\Json;
class Server extends Controller
{
/**
* @notes:分类列表
* @return Json
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @author: wanghousheng
*/
public function categoryList(): Json
{
$model = new ServerCategory();
$list = $model->list();
if (!empty($list)) {
foreach ($list as $key => $value) {
unset($list[$key]['image']);
}
}
return $this->renderSuccess(compact('list'));
}
/**
* @notes:服务列表页
* @throws DbException
* @author: wanghousheng
*/
public function list(): Json
{
$server_name = $this->request->post('server_name');
$category_id = intval($this->request->post('category_id'));
$where = [];
if ($server_name) {
$where[] = ['server.server_name', 'like', "%$server_name%"];
}
if ($category_id) {
$where[] = ['server.category_id', '=', $category_id];
}
$model = new \app\api\model\Server($where);
$list = $model->getList();
$data['list'] = $list->items();
$data['total'] = $list->total();
if (!$list->isEmpty()) {
foreach ($data['list'] as $key => $value) {
unset($data['list'][$key]['image']);
unset($data['list'][$key]['category']);
}
}
return $this->renderSuccess($data);
}
/**
* @notes:订单状态
* @return Json
* @author: wanghousheng
*/
public function orderStatus(): Json
{
$list = array_values(ServerEnum::data());
return $this->renderSuccess(compact('list'));
}
/**
* @notes:用户订单列表
* @throws DbException
* @throws BaseException
* @author: wanghousheng
*/
public function userOrderList(): Json
{
$order_no = $this->request->post('order_no');
$order_status = intval($this->request->post('order_status'));
$where = [];
if (!empty($order_no)) {
$where['order_no'] = $order_no;
}
if ($order_status) {
$where['order_status'] = $order_status;
}
$model = new ServerOrder($where);
$list = $model->userOrders($where);
$data['list'] = $list->items();
$data['total'] = $list->total();
if (!$list->isEmpty()) {
if (!$list->isEmpty()) {
foreach ($data['list'] as $key => $value) {
unset($data['list'][$key]['image']);
unset($data['list'][$key]['dealer']);
}
}
}
return $this->renderSuccess($data);
}
/**
* @notes:
* @return Json
* @throws BaseException
* @throws DbException
* @author: wanghousheng
*/
public function dealerOrderList(): Json
{
$order_no = $this->request->post('order_no');
$order_status = intval($this->request->post('order_status'));
$where = [];
if (!empty($order_no)) {
$where['order_no'] = $order_no;
}
if ($order_status) {
$where['order_status'] = $order_status;
}
$model = new ServerOrder($where);
$list = $model->dealerOrders($where);
$data['list'] = $list->items();
$data['total'] = $list->total();
if (!$list->isEmpty()) {
if (!$list->isEmpty()) {
foreach ($data['list'] as $key => $value) {
unset($data['list'][$key]['image']);
unset($data['list'][$key]['dealer']);
}
}
}
return $this->renderSuccess($data);
}
}