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

120 lines
3.3 KiB

10 months ago
<?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();
10 months ago
$list = $model->where('store_id', $this->storeId)->paginate(15);
10 months ago
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);
9 months ago
$detail['goods_list'] = $goodsModel->with(['images.file'])->whereIn('goods_id', explode(',', $detail['goods_list']))->select()->toArray();
10 months ago
return $this->renderSuccess(compact('detail'));
}
/**
* 预约记录
*/
public function log(int $pre_id): Json {
$model = new PreSaleLogModel();
9 months ago
$list = $model->with(['goods.images.file'])
10 months ago
->where('store_id', $this->storeId)
->where('pre_id', $pre_id)
10 months ago
->paginate(15);
10 months ago
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;
9 months ago
$data = $this->postForm();
$data['store_id'] = $this->storeId;
9 months ago
$data['ctime'] = format_time(time());
$data['p_time'] = format_time(time());
9 months ago
if ($model->save($data)) {
10 months ago
return $this->renderSuccess('添加成功');
}
return $this->renderError($model->getError() ?: '添加失败');
}
/**
* 编辑店员
* @param int $id
* @return Json
*/
public function edit(int $id): Json
{
// 评论详情
$model = PreSaleModel::get($id);
9 months ago
$data = $this->postForm();
9 months ago
// $data['p_time'] = format_time(time());
10 months ago
// 更新记录
9 months ago
if ($model->save($data)) {
10 months ago
return $this->renderSuccess('更新成功');
}
return $this->renderError($model->getError() ?: '更新失败');
}
/**
* 删除店员
* @param int $id
* @return Json
*/
9 months ago
public function del(int $id): Json
10 months ago
{
// 店员详情
$model = PreSaleModel::get($id);
if (!$model->delete()) {
return $this->renderError($model->getError() ?: '删除失败');
}
return $this->renderSuccess('删除成功');
}
}