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/store/controller/Presale.php

114 lines
3.0 KiB

<?php
namespace app\store\controller;
use app\common\model\PreSale as PreSaleModel;
use app\common\model\PreSaleLog as PreSaleLogModel;
use think\response\Json;
/**
* 商品预售管理后台
*/
class Presale extends Controller
{
/**
* 列表记录
* @return Json
* @throws \think\db\exception\DbException
*/
public function list(): Json
{
// 店员列表
$model = new PreSaleModel;
$goodsModel = new \app\common\model\Goods();
$list = $model->where('store_id', $this->storeId)->paginate(15);
foreach ($list as &$row) {
$row['goods_list'] = $goodsModel->whereIn('goods_id', explode(',', $row['goods_list']))->select()->toArray();
}
return $this->renderSuccess(compact('list'));
}
/**
* 详情
*/
public function detail(int $id): Json
{
$model = new PreSaleModel;
$goodsModel = new \app\common\model\Goods();
$detail = $model->get($id);
$detail['goods_list'] = $goodsModel->whereIn('goods_id', explode(',', $detail['goods_list']))->select()->toArray();
return $this->renderSuccess(compact('detail'));
}
/**
* 预约记录
*/
public function log(int $pre_id): Json {
$model = new PreSaleLogModel();
$list = $model->with(['goods'])
->where('store_id', $this->storeId)
->where('pre_id', $pre_id)
->paginate(15);
return $this->renderSuccess(compact('list'));
}
/**
* 全部记录
* @return Json
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function all(): Json
{
// 店员列表
$model = new PreSaleModel;
$list = $model->where('store_id',$this->storeId)->select();
return $this->renderSuccess(compact('list'));
}
/**
* 添加
* @return Json
*/
public function add(): Json
{
// 新增记录
$model = new PreSaleModel;
if ($model->save($this->postForm())) {
return $this->renderSuccess('添加成功');
}
return $this->renderError($model->getError() ?: '添加失败');
}
/**
* 编辑店员
* @param int $id
* @return Json
*/
public function edit(int $id): Json
{
// 评论详情
$model = PreSaleModel::get($id);
// 更新记录
if ($model->save($this->postForm())) {
return $this->renderSuccess('更新成功');
}
return $this->renderError($model->getError() ?: '更新失败');
}
/**
* 删除店员
* @param int $id
* @return Json
*/
public function delete(int $id): Json
{
// 店员详情
$model = PreSaleModel::get($id);
if (!$model->delete()) {
return $this->renderError($model->getError() ?: '删除失败');
}
return $this->renderSuccess('删除成功');
}
}