|
|
|
<?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->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();
|
|
|
|
// $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('删除成功');
|
|
|
|
}
|
|
|
|
}
|