初始化项目
This commit is contained in:
@@ -0,0 +1,216 @@
|
||||
<?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
|
||||
{
|
||||
// 商品详情
|
||||
$model = GoodsModel::detail($goodsId);
|
||||
$company = CompanyModel::detail(['status'=>10]);
|
||||
$SybOil = new SybOil();
|
||||
// 对接平台接口
|
||||
$res = $SybOil->stockList(['goodsNo' => $model['goods_no']], $company);
|
||||
// 更新记录
|
||||
if ($res['code'] == '00') {
|
||||
return $this->renderSuccess($res['data']);
|
||||
}
|
||||
return $this->renderError($model->getError() ?: $res['errMessage']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有产品
|
||||
* @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'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user