208 lines
6.3 KiB
PHP
208 lines
6.3 KiB
PHP
<?php
|
||
// +----------------------------------------------------------------------
|
||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||
// +----------------------------------------------------------------------
|
||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||
// +----------------------------------------------------------------------
|
||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||
// +----------------------------------------------------------------------
|
||
// | Author: 萤火科技 <admin@yiovo.com>
|
||
// +----------------------------------------------------------------------
|
||
declare (strict_types=1);
|
||
|
||
namespace app\store\controller;
|
||
|
||
use app\api\model\Company as CompanyModel;
|
||
use app\common\library\helper;
|
||
use app\common\model\Coupon as CouponModel;
|
||
use app\common\model\UserCoupon as UserCouponModel;
|
||
use think\response\Json;
|
||
use app\store\model\Goods as GoodsModel;
|
||
use app\common\exception\BaseException;
|
||
use app\console\model\Setting as SettingModel;
|
||
use app\common\service\SybOil;
|
||
|
||
/**
|
||
* 商品管理控制器
|
||
* Class Goods
|
||
* @package app\store\controller
|
||
*/
|
||
class Goods extends Controller
|
||
{
|
||
/**
|
||
* 商品列表
|
||
* @return Json
|
||
* @throws \think\db\exception\DbException
|
||
*/
|
||
public function list(): Json
|
||
{
|
||
// 获取列表记录
|
||
$model = new GoodsModel;
|
||
$list = $model->getList($this->request->param());
|
||
return $this->renderSuccess(compact('list'));
|
||
}
|
||
|
||
/**
|
||
* 根据商品ID集获取列表记录
|
||
* @param array $goodsIds
|
||
* @return Json
|
||
*/
|
||
public function listByIds(array $goodsIds): Json
|
||
{
|
||
// 获取列表记录
|
||
$model = new GoodsModel;
|
||
$list = $model->getListByIds($goodsIds);
|
||
return $this->renderSuccess(compact('list'));
|
||
}
|
||
|
||
/**
|
||
* 商品详情
|
||
* @param int $goodsId
|
||
* @return Json
|
||
* @throws BaseException
|
||
* @throws \think\db\exception\DataNotFoundException
|
||
* @throws \think\db\exception\DbException
|
||
* @throws \think\db\exception\ModelNotFoundException
|
||
* @throws \cores\exception\BaseException
|
||
*/
|
||
public function detail(int $goodsId): Json
|
||
{
|
||
// 获取商品详情
|
||
$model = new GoodsModel;
|
||
$goodsInfo = $model->getDetail($goodsId);
|
||
return $this->renderSuccess(compact('goodsInfo'));
|
||
}
|
||
|
||
/**
|
||
* 添加商品
|
||
* @return Json
|
||
* @throws \think\db\exception\DataNotFoundException
|
||
* @throws \think\db\exception\DbException
|
||
* @throws \think\db\exception\ModelNotFoundException
|
||
* @throws \cores\exception\BaseException
|
||
*/
|
||
public function add(): Json
|
||
{
|
||
$model = new GoodsModel;
|
||
if ($model->add($this->postForm())) {
|
||
return $this->renderSuccess('添加成功');
|
||
}
|
||
return $this->renderError($model->getError() ?: '添加失败');
|
||
}
|
||
|
||
/**
|
||
* 编辑商品
|
||
* @param int $goodsId
|
||
* @return Json
|
||
* @throws \think\db\exception\DataNotFoundException
|
||
* @throws \think\db\exception\DbException
|
||
* @throws \think\db\exception\ModelNotFoundException
|
||
* @throws \cores\exception\BaseException
|
||
*/
|
||
public function edit(int $goodsId): Json
|
||
{
|
||
// 商品详情
|
||
$model = GoodsModel::detail($goodsId);
|
||
// 更新记录
|
||
if ($model->edit($this->postForm())) {
|
||
return $this->renderSuccess('更新成功');
|
||
}
|
||
return $this->renderError($model->getError() ?: '更新失败');
|
||
}
|
||
|
||
/**
|
||
* 修改商品状态(上下架)
|
||
* @param array $goodsIds 商品id集
|
||
* @param bool $state 为true表示上架
|
||
* @return Json
|
||
*/
|
||
public function state(array $goodsIds, bool $state): Json
|
||
{
|
||
$model = new GoodsModel;
|
||
if (!$model->setStatus($goodsIds, $state)) {
|
||
return $this->renderError($model->getError() ?: '操作失败');
|
||
}
|
||
return $this->renderSuccess('操作成功');
|
||
}
|
||
|
||
/**
|
||
* 删除商品
|
||
* @param array $goodsIds
|
||
* @return Json
|
||
*/
|
||
public function delete(array $goodsIds): Json
|
||
{
|
||
$model = new GoodsModel;
|
||
if (!$model->setDelete($goodsIds)) {
|
||
return $this->renderError($model->getError() ?: '删除失败');
|
||
}
|
||
return $this->renderSuccess('删除成功');
|
||
}
|
||
|
||
/**
|
||
* 获取省份
|
||
* @return Json
|
||
*/
|
||
public function province(): Json
|
||
{
|
||
$province_list = SettingModel::getItem('trade', $this->storeId)['province_list'];
|
||
$list = explode(',',$province_list);
|
||
return $this->renderSuccess(compact('list'));
|
||
}
|
||
/**
|
||
* 获取所有产品
|
||
* @param string $province
|
||
* @param string $oilCardType
|
||
* @return mixed
|
||
* @throws \think\exception\DbException
|
||
*/
|
||
public function all($province, $oilCardType): Json
|
||
{
|
||
/*if (!$province) {
|
||
return $this->renderSuccess('请选择省份');
|
||
}*/
|
||
if (!$oilCardType) {
|
||
return $this->renderSuccess('请选择卡券类型');
|
||
}
|
||
$where = [
|
||
['province', '=', $province],
|
||
['oilCardType', '=', $oilCardType],
|
||
];
|
||
$list = GoodsModel::getAll($where);
|
||
return $this->renderSuccess(compact('list'));
|
||
}
|
||
|
||
/**
|
||
* 编辑商品
|
||
* @param int $goodsId
|
||
* @return Json
|
||
* @throws \think\db\exception\DataNotFoundException
|
||
* @throws \think\db\exception\DbException
|
||
* @throws \think\db\exception\ModelNotFoundException
|
||
* @throws \cores\exception\BaseException
|
||
*/
|
||
public function onReloadStock(int $goodsId): Json
|
||
{
|
||
// 企油通改造:上游库存同步已停用(企油通无油券库存概念,库存改为平台内部维护)。
|
||
return $this->renderError('上游库存同步已停用,请直接在「合作商」中维护可下单额度');
|
||
}
|
||
|
||
/**
|
||
* 获取所有产品
|
||
* @param string $oilCardType
|
||
* @return mixed
|
||
* @throws \think\exception\DbException
|
||
*/
|
||
public function oilAll($oilCardType): Json
|
||
{
|
||
if (!$oilCardType) {
|
||
return $this->renderSuccess('请选择卡券类型');
|
||
}
|
||
$where = [
|
||
['oilCardType', '=', $oilCardType],
|
||
];
|
||
$list = GoodsModel::getAll($where);
|
||
return $this->renderSuccess(compact('list'));
|
||
}
|
||
}
|