parent
11badcb84e
commit
890896d5b9
@ -0,0 +1,31 @@ |
||||
<?php |
||||
// +---------------------------------------------------------------------- |
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ] |
||||
// +---------------------------------------------------------------------- |
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved. |
||||
// +---------------------------------------------------------------------- |
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行 |
||||
// +---------------------------------------------------------------------- |
||||
// | Author: 萤火科技 <admin@yiovo.com> |
||||
// +---------------------------------------------------------------------- |
||||
declare (strict_types=1); |
||||
|
||||
namespace app\common\model; |
||||
|
||||
use cores\BaseModel; |
||||
|
||||
/** |
||||
* 预售模型 |
||||
* Class GoodsSpecRel |
||||
* @package app\api\model |
||||
*/ |
||||
class PreSale extends BaseModel |
||||
{ |
||||
// 定义表名 |
||||
protected $name = 'presale'; |
||||
|
||||
// 定义主键 |
||||
protected $pk = 'id'; |
||||
|
||||
protected $updateTime = false; |
||||
} |
@ -0,0 +1,39 @@ |
||||
<?php |
||||
// +---------------------------------------------------------------------- |
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ] |
||||
// +---------------------------------------------------------------------- |
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved. |
||||
// +---------------------------------------------------------------------- |
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行 |
||||
// +---------------------------------------------------------------------- |
||||
// | Author: 萤火科技 <admin@yiovo.com> |
||||
// +---------------------------------------------------------------------- |
||||
declare (strict_types=1); |
||||
|
||||
|
||||
namespace app\common\model; |
||||
|
||||
use cores\BaseModel; |
||||
use think\model\relation\HasMany; |
||||
|
||||
/** |
||||
* 预售记录系模型 |
||||
* Class GoodsSpecRel |
||||
* @package app\api\model |
||||
*/ |
||||
class PreSaleLog extends BaseModel |
||||
{ |
||||
// 定义表名 |
||||
protected $name = 'presale_log'; |
||||
|
||||
// 定义主键 |
||||
protected $pk = 'id'; |
||||
|
||||
protected $updateTime = false; |
||||
|
||||
public function goods(): HasMany |
||||
{ |
||||
return $this->hasMany(Goods::class,'goods_id', 'goods_id')->withoutField(['content']); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,114 @@ |
||||
<?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)->select(); |
||||
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) |
||||
->select(); |
||||
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('删除成功'); |
||||
} |
||||
} |
Loading…
Reference in new issue