caipan_shop_admin/app/controller/manager/Express.php

113 lines
2.7 KiB
PHP
Executable File
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?php
namespace app\controller\manager;
use app\model\Log;
use app\repository\OrderRepository;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\exception\ValidateException;
use think\response\Json;
use think\response\View;
/**
* 快递公司
*
* Class Express
* @package app\controller\manager
*/
class Express extends Base
{
/**
* 删除
*
* @return Json
*/
public function del()
{
if ($this->request->isPost()) {
$ids = input('post.ids/a', []);
if (empty($ids)) {
$ids[] = input('post.id/d');
}
$where[] = ['id', 'in', $ids];
OrderRepository::getInstance()->delExpress($where);
Log::write('express del', 'del', '删除了快递涉及到的ID为'.implode(',', $ids));
return $this->json();
}
return $this->json(4001, '非法请求!');
}
/**
* 添加
*
* @return Json|View
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function edit()
{
$id = input('id/d', 0);
if (!$info = OrderRepository::getInstance()->expressInfo($id)) {
return $this->json(4001, '数据不存在');
}
if ($this->request->isPost()) {
$item = input('post.item/a');
try {
unset($item['id']);
OrderRepository::getInstance()->editExpress($item, ['id' => $id]);
return $this->json();
} catch (ValidateException $e) {
return $this->json(4001, $e->getError());
}
}
$this->data['item'] = $info;
$this->data['id'] = $id;
return $this->view();
}
/**
* 添加
*
* @return Json|View
*/
public function add()
{
if ($this->request->isPost()) {
$item = input('post.item/a');
try {
OrderRepository::getInstance()->addExpress($item);
return $this->json();
} catch (ValidateException $e) {
return $this->json(4001, $e->getError());
}
}
return $this->view();
}
/**
* 快递列表
*
* @return View
* @throws DbException
*/
public function index(): View
{
$size = input('size/d', 20);
$urlQuery = input('get.');
$where = [];
$where['size'] = $size;
$this->data['items'] = OrderRepository::getInstance()->express($where, $urlQuery);
return $this->view();
}
}