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.
126 lines
3.4 KiB
126 lines
3.4 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\store\model\Goods();
|
|
$list = $model->where('store_id', $this->storeId)->paginate(15);
|
|
foreach ($list as &$row) {
|
|
if ($row['goods_list']) {
|
|
$goods_list = $goodsModel->getListByIds(explode(',', $row['goods_list']));
|
|
$row['goods_list'] = json_decode($goods_list, true);
|
|
}
|
|
|
|
}
|
|
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->with(['images.file'])->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.images.file'])
|
|
->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;
|
|
$data = $this->postForm();
|
|
$data['store_id'] = $this->storeId;
|
|
$data['ctime'] = format_time(time());
|
|
$data['p_time'] = format_time(time());
|
|
if ($model->save($data)) {
|
|
return $this->renderSuccess('添加成功');
|
|
}
|
|
return $this->renderError($model->getError() ?: '添加失败');
|
|
}
|
|
|
|
/**
|
|
* 编辑店员
|
|
* @param int $id
|
|
* @return Json
|
|
*/
|
|
public function edit(int $id): Json
|
|
{
|
|
// 评论详情
|
|
$model = PreSaleModel::get($id);
|
|
$data = $this->postForm();
|
|
// var_dump($data);
|
|
// exit();
|
|
// $data['p_time'] = format_time(time());
|
|
// 更新记录
|
|
if ($model->save($data)) {
|
|
return $this->renderSuccess('更新成功');
|
|
}
|
|
return $this->renderError($model->getError() ?: '更新失败');
|
|
}
|
|
|
|
/**
|
|
* 删除店员
|
|
* @param int $id
|
|
* @return Json
|
|
*/
|
|
public function del(int $id): Json
|
|
{
|
|
// 店员详情
|
|
$model = PreSaleModel::get($id);
|
|
if (!$model->delete()) {
|
|
return $this->renderError($model->getError() ?: '删除失败');
|
|
}
|
|
return $this->renderSuccess('删除成功');
|
|
}
|
|
} |