<?php
|
|
namespace app\supplier\controller\setting;
|
|
use app\supplier\controller\Controller;
|
use app\supplier\model\settings\Stall as StallModel;
|
use app\common\enum\settings\StallTypeEnum;
|
use app\common\model\settings\Printer as PrinterModel;
|
|
/**
|
* 打印档口控制器
|
*/
|
class Stall extends Controller
|
{
|
/**
|
* 档口列表
|
*/
|
public function index()
|
{
|
$model = new StallModel;
|
if (StallModel::checkDefault($this->getSupplierId())) {
|
$list = $model->getList($this->postData(), $this->getSupplierId());
|
}
|
return $this->renderSuccess('', compact('list'));
|
}
|
|
|
/**
|
* 档口类型
|
*/
|
public function type()
|
{
|
$model = new StallModel;
|
$stallType = $model::getStallTypeList();
|
return $this->renderSuccess('', compact('stallType'));
|
}
|
|
|
/**
|
* 添加打印机
|
*/
|
public function add($stall_type)
|
{
|
if($this->request->isGet()){
|
$type_info = StallTypeEnum::data()[$stall_type];
|
// 档口名称
|
$stallTypeName = $type_info['name'];
|
// 打印机列表
|
$printerList = PrinterModel::getAll($this->getSupplierId(), $type_info['printer_type']);
|
return $this->renderSuccess('', compact('printerList', 'stallTypeName'));
|
}
|
// 新增记录
|
$model = new StallModel;
|
$data = $this->postData();
|
$data['shop_supplier_id'] = $this->getSupplierId();
|
if ($model->add($data)) {
|
return $this->renderSuccess('添加成功');
|
}
|
return $this->renderError($model->getError() ?: '添加失败');
|
}
|
|
/**
|
* 打印机详情
|
*/
|
public function detail($stall_id)
|
{
|
$detail = StallModel::detail($stall_id);
|
return $this->renderSuccess('', compact('detail'));
|
|
}
|
|
public function edit($stall_id)
|
{
|
if($this->request->isGet()){
|
$detail = StallModel::detail($stall_id);
|
$type_info = StallTypeEnum::data()[$detail['stall_type']];
|
// 档口名称
|
$stallTypeName = $type_info['name'];
|
// 打印机列表
|
$printerList = PrinterModel::getAll($this->getSupplierId(), $type_info['printer_type']);
|
return $this->renderSuccess('', compact('printerList', 'stallTypeName', 'detail'));
|
}
|
$model = StallModel::detail($stall_id);
|
// 更新记录
|
if ($model->edit($this->postData())) {
|
return $this->renderSuccess('更新成功');
|
}
|
return $this->renderError($model->getError() ?: '更新失败');
|
}
|
|
/**
|
* 删除记录
|
*/
|
public function delete($stall_id)
|
{
|
$model = StallModel::detail($stall_id);
|
if ($model->setDelete()) {
|
return $this->renderSuccess('删除成功');
|
}
|
return $this->renderError($model->getError() ?:'删除失败');
|
}
|
|
public function getAllList()
|
{
|
$list = (new StallModel)->getAll($this->getSupplierId(), true);
|
return $this->renderSuccess('', compact('list'));
|
}
|
|
}
|