114 lines
2.9 KiB
PHP
114 lines
2.9 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Author:
|
|
* Date: 2017/11/23
|
|
* Time: 下午3:50
|
|
*/
|
|
|
|
namespace Yunshop\Printer\admin;
|
|
|
|
use app\common\components\BaseController;
|
|
use app\common\exceptions\ShopException;
|
|
use app\common\helpers\PaginationHelper;
|
|
use app\common\helpers\Url;
|
|
use Yunshop\Printer\common\models\Printer;
|
|
|
|
class ListController extends BaseController
|
|
{
|
|
private $printer_model;
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
|
|
|
|
public function index()
|
|
{
|
|
return view('Yunshop\Printer::admin.printer_list')->render();
|
|
}
|
|
|
|
public function getList(){
|
|
$kwd = trim(request()->kwd);
|
|
$list = Printer::fetchPrints($kwd)->orderBy('id', 'desc')->paginate();
|
|
return $this->successJson('success',$list);
|
|
}
|
|
|
|
public function add()
|
|
{
|
|
$printer_data = request()->printer;
|
|
$printer_owner = \app\common\modules\shop\ShopConfig::current()->get('printer_owner');
|
|
|
|
if ($printer_data) {
|
|
$printer_data['uniacid'] = \YunShop::app()->uniacid;
|
|
$printer_data['owner'] = $printer_owner['owner'];
|
|
$printer_data['owner_id'] = $printer_owner['owner_id'];
|
|
|
|
$ret = Printer::add($printer_data);
|
|
if (!$ret) {
|
|
return $this->successJson('添加打印机成功');
|
|
}
|
|
return $this->errorJson($ret);
|
|
}
|
|
|
|
return view('Yunshop\Printer::admin.printer_detail', [
|
|
|
|
])->render();
|
|
}
|
|
|
|
public function edit()
|
|
{
|
|
$this->exception();
|
|
$printer_data = request()->printer;
|
|
if ($printer_data) {
|
|
$ret = Printer::edit($printer_data, $this->printer_model);
|
|
if (!$ret) {
|
|
return $this->successJson('修改打印机成功');
|
|
}
|
|
return $this->errorJson($ret);
|
|
}
|
|
|
|
return view('Yunshop\Printer::admin.printer_detail')->render();
|
|
}
|
|
|
|
|
|
public function info(){
|
|
$id=request()->id;
|
|
$data=Printer::getPrinterById($id)->first();
|
|
return $this->successJson('获取详情成功',$data);
|
|
}
|
|
|
|
public function del()
|
|
{
|
|
$this->exception();
|
|
$this->printer_model->delete();
|
|
return $this->successJson('删除打印机成功');
|
|
}
|
|
|
|
public function changeStatus()
|
|
{
|
|
$id = request()->id;
|
|
$field = request()->type;
|
|
$data = (request()->data == 1 ? '0' : '1');
|
|
$printer = Printer::getPrinterById($id)->first();
|
|
$printer->$field = $data;
|
|
$printer->save();
|
|
return $this->successJson('改变状态成功',$data);
|
|
}
|
|
|
|
private function exception()
|
|
{
|
|
$id = intval(request()->printer['id']);
|
|
if (!$id) {
|
|
throw new ShopException('参数错误');
|
|
}
|
|
$printer = Printer::getPrinterById($id)->first();
|
|
if (!$printer) {
|
|
throw new ShopException('未找到打印机');
|
|
}
|
|
$this->printer_model = $printer;
|
|
}
|
|
}
|