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.
653 lines
20 KiB
653 lines
20 KiB
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
|
// +----------------------------------------------------------------------
|
|
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
|
// +----------------------------------------------------------------------
|
|
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
|
// +----------------------------------------------------------------------
|
|
// | Author: 萤火科技 <admin@yiovo.com>
|
|
// +----------------------------------------------------------------------
|
|
declare (strict_types=1);
|
|
|
|
namespace app\api\controller;
|
|
|
|
use app\common\enum\RecoveryStatusEnum;
|
|
use app\common\model\UploadFile;
|
|
use app\store\model\Article as ArticleModel;
|
|
use app\store\model\article\Category as CategoryModel;
|
|
use app\store\model\dealer\Order as DealerOrderModel;
|
|
use app\store\model\Express as ExpressModel;
|
|
use app\store\model\Goods as GoodsModel;
|
|
use app\store\model\goods\GoodsPrice as GoodsPriceModel;
|
|
use app\store\model\Order as OrderModel;
|
|
use app\store\model\OrderRefund as OrderRefundModel;
|
|
use app\store\model\store\Address as AddressModel;
|
|
use app\store\model\store\shop\Clerk as ClerkModel;
|
|
use app\store\service\order\Delivery as DeliveryService;
|
|
use cores\exception\BaseException;
|
|
use think\App;
|
|
use think\db\exception\DbException;
|
|
use think\response\Json;
|
|
use app\common\model\MerchantRemarks as MerchantRemarksModel;
|
|
|
|
/**
|
|
* 店主管理
|
|
* Class Store
|
|
* @package app\api\controller
|
|
*/
|
|
class StoreKeeper extends Controller
|
|
{
|
|
public function __construct(App $app)
|
|
{
|
|
parent::__construct($app);
|
|
// $res = UserService::isStore();
|
|
// if ($res === false) {
|
|
// print_r(json_encode(['code' => config('status.error'), 'msg' => '无权操作']));
|
|
// exit;
|
|
// }
|
|
}
|
|
|
|
/**
|
|
* 商品列表
|
|
* @return Json
|
|
* @throws DbException
|
|
*/
|
|
public function list(): Json
|
|
{
|
|
|
|
RecoveryStatusEnum::keys();
|
|
// 获取列表记录
|
|
$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 DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
*/
|
|
public function detail(int $goodsId): Json
|
|
{
|
|
// 获取商品详情
|
|
$model = new GoodsModel;
|
|
$goodsInfo = $model->getDetail($goodsId);
|
|
return $this->renderSuccess(compact('goodsInfo'));
|
|
}
|
|
|
|
/**
|
|
* 商品详情(基础信息)
|
|
* @param int $goodsId
|
|
* @return Json
|
|
* @throws BaseException
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
*/
|
|
public function basic(int $goodsId): Json
|
|
{
|
|
// 获取商品详情
|
|
$model = new GoodsModel;
|
|
$detail = $model->getBasic($goodsId);
|
|
return $this->renderSuccess(compact('detail'));
|
|
}
|
|
|
|
/**
|
|
* 添加商品
|
|
* @return Json
|
|
* @throws BaseException
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
*/
|
|
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 BaseException
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
*/
|
|
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('删除成功');
|
|
}
|
|
|
|
//订单相关
|
|
|
|
/**
|
|
* 订单列表
|
|
* @param string $dataType
|
|
* @return Json
|
|
*/
|
|
public function orderList(string $dataType): Json
|
|
{
|
|
$params = $this->request->param();
|
|
$params['searchType'] = 'all';
|
|
$goodsModel = new GoodsModel;
|
|
$MerchantRemarks = new MerchantRemarksModel();
|
|
// 订单列表
|
|
if (!empty($params['dataType']) && $params['dataType'] == 'refund') {
|
|
$model = new OrderRefundModel;
|
|
$list = $model->getNewList($params);
|
|
if (!empty($list['data'])) {
|
|
foreach ($list['data'] as $key => &$value) {
|
|
$goods_images = $goodsModel->storeUsePlatformGoodsImage(array_column($value['goods'], 'origin_goods_id'));
|
|
foreach ($value['goods'] as &$good) {
|
|
//使用总后台的商品图片
|
|
if ($good['origin_goods_id'] && $value['store_id'] > 0) {
|
|
$good['goods_image'] = $goods_images[$good['origin_goods_id']][0]['file']['preview_url'] ?? "";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return $this->renderSuccess(compact('list'));
|
|
} else {
|
|
$model = new OrderModel;
|
|
$list = $model->getNewList($params);
|
|
|
|
if (!empty($list['data'])) {
|
|
foreach ($list['data'] as $key => &$value) {
|
|
if (!empty($value['transfer']) && !empty($value['transfer']['chat_image_id'])) {
|
|
$chat_image_ids = UploadFile::whereIn('file_id', explode(",", $value['transfer']['chat_image_id']))->field('file_id,file_path,file_type,storage,domain')->select();
|
|
foreach ($chat_image_ids as &$chat_image_id) {
|
|
$chat_image_id['file_path'] = getUrl($chat_image_id['file_path'], $chat_image_id['domain']);
|
|
}
|
|
$list['data'][$key]['transfer']['chat_image_ids'] = $chat_image_ids;
|
|
}
|
|
if (!empty($value['transfer']) && !empty($value['transfer']['transfer_image_id'])) {
|
|
$transfer_image_ids = UploadFile::whereIn('file_id', explode(",", $value['transfer']['transfer_image_id']))->field('file_id,file_path,file_type,storage,domain')->select();
|
|
foreach ($transfer_image_ids as &$transfer_image_id) {
|
|
$transfer_image_id['file_path'] = getUrl($transfer_image_id['file_path'], $transfer_image_id['domain']);
|
|
}
|
|
$list['data'][$key]['transfer']['transfer_image_ids'] = $transfer_image_ids;
|
|
}
|
|
//复制信息
|
|
$copy_text = "订单号:{$value['order_no']}\n";
|
|
$goods_images = $goodsModel->storeUsePlatformGoodsImage(array_column($value['goods'], 'origin_goods_id'));
|
|
|
|
foreach ($value['goods'] as &$good) {
|
|
//使用总后台的商品图片
|
|
if ($good['origin_goods_id'] && $value['store_id'] > 0) {
|
|
$good['goods_image'] = $goods_images[$good['origin_goods_id']][0]['file']['preview_url'] ?? "";
|
|
}
|
|
|
|
$copy_text .= "商品名称:{$good['goods_name']}\n";
|
|
if (!empty($good['goods_no'])) {
|
|
$copy_text .= "商品编码:{$good['goods_no']}\n";
|
|
}
|
|
$copy_text .= "单价:{$good['goods_price']}\n";
|
|
$copy_text .= "数量:{$good['total_num']}\n";
|
|
$copy_text .= "总价:{$good['total_price']}\n";
|
|
$copy_text .= "\n";
|
|
}
|
|
|
|
if (!empty($value['address'])) {
|
|
$copy_text .= "\n";
|
|
$copy_text .= "收件人:{$value['address']['name']}\n";
|
|
$copy_text .= "电话:{$value['address']['phone']}\n";
|
|
$address = '';
|
|
if (!empty($value['address']['region'])) {
|
|
$address = $value['address']['region']['province'] . $value['address']['region']['city'] . $value['address']['region']['region'];
|
|
}
|
|
$copy_text .= "地址:$address{$value['address']['detail']}\n";
|
|
}
|
|
|
|
$list['data'][$key]['copy_text'] = $copy_text;
|
|
}
|
|
}
|
|
return $this->renderSuccess(compact('dataType', 'list'));
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* 获取全部记录
|
|
* @return Json
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
*/
|
|
public function expressAll(): Json
|
|
{
|
|
$model = new ExpressModel;
|
|
$list = $model->getAll($this->request->param());
|
|
return $this->renderSuccess(compact('list'));
|
|
}
|
|
|
|
/**
|
|
* 修改订单价格
|
|
* @param int $orderId
|
|
* @return Json
|
|
*/
|
|
public function updatePrice(int $orderId): Json
|
|
{
|
|
// 订单详情
|
|
$model = OrderModel::detail($orderId);
|
|
if ($model->updatePrice($this->postForm())) {
|
|
return $this->renderSuccess('操作成功');
|
|
}
|
|
return $this->renderError($model->getError() ?: '操作失败');
|
|
}
|
|
|
|
/**
|
|
* 修改订单地址
|
|
* @param int $orderId
|
|
* @return Json
|
|
*/
|
|
public function updateAddress(int $orderId): Json
|
|
{
|
|
// 订单详情
|
|
$model = OrderModel::detail($orderId);
|
|
if ($model->updateAddress($this->postForm())) {
|
|
return $this->renderSuccess('操作成功');
|
|
}
|
|
return $this->renderError($model->getError() ?: '操作失败');
|
|
}
|
|
|
|
/**
|
|
* 修改物流信息
|
|
* @param int $orderId
|
|
* @return Json
|
|
*/
|
|
public function updateDelivery(int $orderId): Json
|
|
{
|
|
// 订单详情
|
|
$model = OrderModel::detail($orderId);
|
|
if ($model->updateDelivery($this->postForm())) {
|
|
return $this->renderSuccess('操作成功');
|
|
}
|
|
return $this->renderError($model->getError() ?: '操作失败');
|
|
}
|
|
|
|
/**
|
|
* 审核:用户取消订单
|
|
* @param $orderId
|
|
* @return Json
|
|
*/
|
|
public function confirmCancel($orderId): Json
|
|
{
|
|
// 订单详情
|
|
$model = OrderModel::detail($orderId);
|
|
if ($model->confirmCancel($this->postForm())) {
|
|
return $this->renderSuccess('操作成功');
|
|
}
|
|
return $this->renderError($model->getError() ?: '操作失败');
|
|
}
|
|
|
|
/**
|
|
* 删除订单记录
|
|
* @param int $orderId
|
|
* @return Json
|
|
*/
|
|
public function oderDelete(int $orderId): Json
|
|
{
|
|
// 订单详情
|
|
$model = OrderModel::detail($orderId);
|
|
// 确认核销
|
|
if ($model->setDelete()) {
|
|
return $this->renderSuccess('删除成功');
|
|
}
|
|
return $this->renderError($model->getError() ?: '操作失败');
|
|
}
|
|
|
|
/**
|
|
* 门店自提核销
|
|
* @param int $orderId
|
|
* @return Json
|
|
*/
|
|
public function extract(int $orderId): Json
|
|
{
|
|
// 订单详情
|
|
$model = OrderModel::detail($orderId);
|
|
if ($model->extractEvent($this->postForm())) {
|
|
return $this->renderSuccess('核销成功');
|
|
}
|
|
return $this->renderError($model->getError() ?: '核销失败');
|
|
}
|
|
|
|
public function clerkAll(): Json
|
|
{
|
|
// 店员列表
|
|
$model = new ClerkModel;
|
|
$list = $model->getAll($this->request->param());
|
|
return $this->renderSuccess(compact('list'));
|
|
}
|
|
|
|
/**
|
|
* 确认发货 (手动录入)
|
|
* @param int $orderId 订单ID
|
|
* @return Json
|
|
*/
|
|
public function delivery(int $orderId): Json
|
|
{
|
|
$service = new DeliveryService;
|
|
if ($service->delivery($orderId, $this->postForm())) {
|
|
return $this->renderSuccess('发货成功');
|
|
}
|
|
return $this->renderError($service->getError() ?: '发货失败');
|
|
}
|
|
|
|
/**
|
|
* 商家审核
|
|
* @param int $orderRefundId
|
|
* @return Json
|
|
*/
|
|
public function audit(int $orderRefundId): Json
|
|
{
|
|
// 售后单详情
|
|
$model = OrderRefundModel::detail($orderRefundId);
|
|
// 确认审核
|
|
if ($model->audit($this->postForm())) {
|
|
return $this->renderSuccess('操作成功');
|
|
}
|
|
return $this->renderError($model->getError() ?: '操作失败');
|
|
}
|
|
|
|
/**
|
|
* 确认收货并退款
|
|
* @param int $orderRefundId
|
|
* @return Json
|
|
*/
|
|
public function receipt(int $orderRefundId): Json
|
|
{
|
|
// 售后单详情
|
|
$model = OrderRefundModel::detail($orderRefundId);
|
|
// 确认收货并退款
|
|
if ($model->receipt($this->postForm())) {
|
|
return $this->renderSuccess('操作成功');
|
|
}
|
|
return $this->renderError($model->getError() ?: '操作失败');
|
|
}
|
|
|
|
/**
|
|
* 全部记录
|
|
* @return Json
|
|
* @throws \think\db\exception\DbException
|
|
*/
|
|
public function storeAddress(): Json
|
|
{
|
|
$model = new AddressModel;
|
|
$list = $model->getAll($this->request->param());
|
|
return $this->renderSuccess(compact('list'));
|
|
}
|
|
|
|
//分销
|
|
|
|
/**
|
|
* 分销订单列表
|
|
* @return Json
|
|
*/
|
|
public function dealerList(): Json
|
|
{
|
|
$model = new DealerOrderModel();
|
|
$list = $model->getList($this->request->param());
|
|
return $this->renderSuccess(compact('list'));
|
|
}
|
|
|
|
|
|
//文章管理
|
|
|
|
/**
|
|
* 文章分类列表
|
|
* @return Json
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
*/
|
|
public function articleCatList(): Json
|
|
{
|
|
$model = new CategoryModel;
|
|
$list = $model->getList();
|
|
return $this->renderSuccess(compact('list'));
|
|
}
|
|
|
|
/**
|
|
* 添加文章分类
|
|
* @return Json
|
|
*/
|
|
public function articleCatAdd(): Json
|
|
{
|
|
// 新增记录
|
|
$model = new CategoryModel;
|
|
if ($model->add($this->postForm())) {
|
|
return $this->renderSuccess('添加成功');
|
|
}
|
|
return $this->renderError($model->getError() ?: '添加失败');
|
|
}
|
|
|
|
/**
|
|
* 编辑文章分类
|
|
* @param int $categoryId
|
|
* @return Json
|
|
*/
|
|
public function articleCatEdit(int $categoryId): Json
|
|
{
|
|
// 分类详情
|
|
$model = CategoryModel::detail($categoryId);
|
|
// 更新记录
|
|
if ($model->edit($this->postForm())) {
|
|
return $this->renderSuccess('更新成功');
|
|
}
|
|
return $this->renderError($model->getError() ?: '更新失败');
|
|
}
|
|
|
|
/**
|
|
* 删除文章分类
|
|
* @param int $categoryId
|
|
* @return Json
|
|
*/
|
|
public function articleCatDelete(int $categoryId): Json
|
|
{
|
|
$model = CategoryModel::detail($categoryId);
|
|
if (!$model->remove($categoryId)) {
|
|
return $this->renderError($model->getError() ?: '删除失败');
|
|
}
|
|
return $this->renderSuccess('删除成功');
|
|
}
|
|
|
|
/**
|
|
* 文章列表
|
|
* @return Json
|
|
* @throws \think\db\exception\DbException
|
|
*/
|
|
public function articleList(): Json
|
|
{
|
|
$model = new ArticleModel;
|
|
$list = $model->getList($this->request->param());
|
|
return $this->renderSuccess(compact('list'));
|
|
}
|
|
|
|
|
|
/**
|
|
* 文章详情
|
|
* @param int $articleId
|
|
* @return Json
|
|
*/
|
|
public function articleDetail(int $articleId): Json
|
|
{
|
|
$detail = \app\store\model\Article::detail($articleId);
|
|
// 获取image (这里不能用with因为编辑页需要image对象)
|
|
!empty($detail) && $detail['image'];
|
|
return $this->renderSuccess(compact('detail'));
|
|
}
|
|
|
|
/**
|
|
* 添加文章
|
|
* @return Json
|
|
*/
|
|
public function articleAdd(): Json
|
|
{
|
|
// 新增记录
|
|
$model = new ArticleModel;
|
|
if ($model->add($this->postForm())) {
|
|
return $this->renderSuccess('添加成功');
|
|
}
|
|
return $this->renderError($model->getError() ?: '添加失败');
|
|
}
|
|
|
|
/**
|
|
* 更新文章
|
|
* @param int $articleId
|
|
* @return Json
|
|
*/
|
|
public function articleEdit(int $articleId): Json
|
|
{
|
|
// 文章详情
|
|
$model = ArticleModel::detail($articleId);
|
|
// 更新记录
|
|
if ($model->edit($this->postForm())) {
|
|
return $this->renderSuccess('更新成功');
|
|
}
|
|
return $this->renderError($model->getError() ?: '更新失败');
|
|
}
|
|
|
|
/**
|
|
* 删除文章
|
|
* @param int $articleId
|
|
* @return Json
|
|
*/
|
|
public function articleDelete(int $articleId): Json
|
|
{
|
|
// 文章详情
|
|
$model = ArticleModel::detail($articleId);
|
|
if (!$model->setDelete()) {
|
|
return $this->renderError($model->getError() ?: '删除失败');
|
|
}
|
|
return $this->renderSuccess('删除成功');
|
|
}
|
|
|
|
|
|
//会员、分销价格配置
|
|
|
|
/**
|
|
* 配置列表
|
|
* @return Json
|
|
* @throws \think\db\exception\DbException
|
|
*/
|
|
public function priceList(): Json
|
|
{
|
|
$model = new GoodsPriceModel;
|
|
$list = $model->getAll($this->request->param());
|
|
return $this->renderSuccess(compact('list'));
|
|
}
|
|
|
|
public function addPrice(): Json
|
|
{
|
|
$model = new GoodsPriceModel;
|
|
if (!$model->add($this->request->param())) {
|
|
return $this->renderError($model->getError() ?: '添加失败');
|
|
}
|
|
return $this->renderSuccess('添加成功');
|
|
}
|
|
|
|
public function editPrice(): Json
|
|
{
|
|
$model = new GoodsPriceModel;
|
|
if (!$model->edit($this->request->param())) {
|
|
return $this->renderError($model->getError() ?: '编辑失败');
|
|
}
|
|
return $this->renderSuccess('编辑成功');
|
|
}
|
|
|
|
/**
|
|
* 店长修改价格
|
|
* @return Json
|
|
*/
|
|
public function editGoodsPrice(): Json
|
|
{
|
|
$model = new \app\api\model\Goods();
|
|
if (!$model->editGoodsPrice($this->request->param())) {
|
|
return $this->renderError($model->getError() ?: '编辑失败');
|
|
}
|
|
return $this->renderSuccess('编辑成功');
|
|
}
|
|
|
|
/**
|
|
* 店长修改秒杀价格
|
|
* @return Json
|
|
* @throws \Exception
|
|
*/
|
|
public function editGoodsSeckillPrice()
|
|
{
|
|
$model = new \app\api\model\Goods();
|
|
if (!$model->editGoodsSeckillPrice($this->request->param())) {
|
|
return $this->renderError($model->getError() ?: '编辑失败');
|
|
}
|
|
return $this->renderSuccess('编辑成功');
|
|
}
|
|
|
|
public function delPrice(): Json
|
|
{
|
|
$model = new GoodsPriceModel;
|
|
if (!$model->del($this->request->param())) {
|
|
return $this->renderError($model->getError() ?: '删除失败');
|
|
}
|
|
return $this->renderSuccess('删除成功');
|
|
}
|
|
|
|
|
|
} |