Files
2026-09-01 22:15:50 +08:00

78 lines
1.9 KiB
PHP

<?php
declare (strict_types=1);
namespace app\store\controller;
use app\store\model\Checkout as CheckoutModel;
use think\response\Json;
/**
* 结账控制器
* Class Checkout
* @package app\store\controller
*/
class Checkout extends Controller
{
/**
* 结账列表
* @return mixed
* @throws \think\exception\DbException
*/
public function index()
{
$model = new CheckoutModel;
$getData = $this->request->param();
$data = [];
if (isset($getData['search']) && !empty($getData['search'])) {
$data[] = ['checkout_id', 'like', "%{$getData['search']}%"];
}
$list = $model->getList($data);
return $this->renderSuccess(['list'=>$list]);
}
/**
* 获取所有结账
* @return mixed
* @throws \think\exception\DbException
*/
public function all(): Json
{
$list = CheckoutModel::getAll();
return $this->renderSuccess(compact('list','user'));
}
/**
* 结账
* @return array|mixed
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function checkout()
{
$model = new CheckoutModel;
$data = $this->postForm();
// 新增记录
if ($model->checkout($data, $this->store['user'])) {
return $this->renderSuccess('结账成功');
}
return $this->renderError($model->getError() ?: '结账失败');
}
/**
* 删除商户
* @return Json
* @throws \think\exception\DbException
*/
public function delete(): Json
{
$arr = $this->postData();
foreach ((array)$arr as $val){
$model = CheckoutModel::detail($val);
$model->setDelete();
}
return $this->renderSuccess('删除成功');
}
}