new files
This commit is contained in:
299
pro_v3.5.1/app/controller/out/Product.php
Normal file
299
pro_v3.5.1/app/controller/out/Product.php
Normal file
@@ -0,0 +1,299 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\controller\out;
|
||||
|
||||
use app\Request;
|
||||
use app\services\product\category\StoreProductCategoryServices;
|
||||
use app\services\product\product\StoreProductServices;
|
||||
use think\annotation\Inject;
|
||||
|
||||
/**
|
||||
* 商品类
|
||||
* Class StoreProductController
|
||||
* @package app\api\controller\store
|
||||
*/
|
||||
class Product
|
||||
{
|
||||
/**
|
||||
* 商品services
|
||||
* @var StoreProductServices
|
||||
*/
|
||||
#[Inject]
|
||||
protected StoreProductServices $productServices;
|
||||
|
||||
/**
|
||||
* 分类services
|
||||
* @var StoreProductCategoryServices
|
||||
*/
|
||||
#[Inject]
|
||||
protected StoreProductCategoryServices $categoryServices;
|
||||
|
||||
/**
|
||||
* 分类列表
|
||||
* @param Request $request
|
||||
* @return mixed
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function categoryList(Request $request)
|
||||
{
|
||||
$where = $request->getMore([
|
||||
['is_show', ''],
|
||||
['pid', ''],
|
||||
['cate_name', ''],
|
||||
]);
|
||||
$where['pid'] = -2;
|
||||
$data = $this->categoryServices->getCategoryList($where);
|
||||
return app('json')->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分类
|
||||
* @param $id
|
||||
* @return mixed
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function categoryInfo($id)
|
||||
{
|
||||
$info = $this->categoryServices->getInfo((int)$id);
|
||||
return app('json')->success($info);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新建分类
|
||||
* @param Request $request
|
||||
* @return mixed
|
||||
*/
|
||||
public function categoryCreate(Request $request)
|
||||
{
|
||||
$data = $request->postMore([
|
||||
['pid', 0],
|
||||
['cate_name', ''],
|
||||
['pic', ''],
|
||||
['big_pic', ''],
|
||||
['sort', 0],
|
||||
['is_show', 0]
|
||||
]);
|
||||
$cateId = $this->categoryServices->createData($data)->id;
|
||||
return app('json')->success('添加成功', ['id' => $cateId]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改分类
|
||||
* @param Request $request
|
||||
* @param $id
|
||||
* @return mixed
|
||||
*/
|
||||
public function categoryUpdate(Request $request, $id)
|
||||
{
|
||||
$data = $request->postMore([
|
||||
['pid', 0],
|
||||
['cate_name', ''],
|
||||
['pic', ''],
|
||||
['big_pic', ''],
|
||||
['sort', 0],
|
||||
['is_show', 0]
|
||||
]);
|
||||
$this->categoryServices->editData($id, $data);
|
||||
return app('json')->success('修改成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除分类
|
||||
* @param $id
|
||||
* @return mixed
|
||||
*/
|
||||
public function categoryDelete($id)
|
||||
{
|
||||
$this->categoryServices->del((int)$id);
|
||||
return app('json')->success('删除成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改分类状态
|
||||
* @param $id
|
||||
* @param $is_show
|
||||
* @return mixed
|
||||
*/
|
||||
public function categorySetShow($id, $is_show)
|
||||
{
|
||||
$this->categoryServices->setShow($id, $is_show);
|
||||
return app('json')->success('设置成功');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 商品列表
|
||||
* @param Request $request
|
||||
* @return mixed
|
||||
*/
|
||||
public function productList(Request $request)
|
||||
{
|
||||
$where = $request->getMore([
|
||||
['cate_id', ''],
|
||||
['store_name', ''],
|
||||
['type', 1, '', 'status'],
|
||||
['is_live', 0],
|
||||
['is_new', ''],
|
||||
['is_vip_product', ''],
|
||||
['is_presale_product', ''],
|
||||
['store_label_id', '']
|
||||
]);
|
||||
$where['is_show'] = 1;
|
||||
$where['is_del'] = 0;
|
||||
if ($where['cate_id'] !== '') {
|
||||
if ($this->categoryServices->value(['id' => $where['cate_id']], 'pid')) {
|
||||
$where['sid'] = $where['cate_id'];
|
||||
} else {
|
||||
$where['cid'] = $where['cate_id'];
|
||||
}
|
||||
}
|
||||
unset($where['cate_id']);
|
||||
if ($where['store_name']) {//搜索
|
||||
$where['pid'] = 0;
|
||||
}
|
||||
$list = $this->productServices->searchList($where);
|
||||
foreach ($list['list'] as &$item) {
|
||||
$item['pages_url'] = '/pages/goods_details/index?id=' . $item['id'];
|
||||
}
|
||||
$list['pages_url'] = '/pages/goods/goods_list/index';
|
||||
return app('json')->success($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增商品
|
||||
* @param Request $request
|
||||
* @param int $id
|
||||
* @return mixed
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function productSave(Request $request, int $id = 0)
|
||||
{
|
||||
$data = $request->postMore([
|
||||
['product_type', 0],//商品类型
|
||||
['supplier_id', 0],//供应商ID
|
||||
['cate_id', []],
|
||||
['store_name', ''],
|
||||
['store_info', ''],
|
||||
['keyword', ''],
|
||||
['unit_name', '件'],
|
||||
['recommend_image', ''],
|
||||
['slider_image', []],
|
||||
['is_sub', []],//佣金是单独还是默认
|
||||
['sort', 0],
|
||||
['sales', 0],
|
||||
['ficti', 100],
|
||||
['give_integral', 0],
|
||||
['is_show', 0],
|
||||
['is_hot', 0],
|
||||
['is_benefit', 0],
|
||||
['is_best', 0],
|
||||
['is_new', 0],
|
||||
['mer_use', 0],
|
||||
['is_postage', 0],
|
||||
['is_good', 0],
|
||||
['description', ''],
|
||||
['spec_type', 0],
|
||||
['video_open', 0],
|
||||
['video_link', ''],
|
||||
['items', []],
|
||||
['attrs', []],
|
||||
['recommend', []],//商品推荐
|
||||
['activity', []],
|
||||
['coupon_ids', []],
|
||||
['label_id', []],
|
||||
['command_word', ''],
|
||||
['tao_words', ''],
|
||||
['type', 0, '', 'is_copy'],
|
||||
['delivery_type', []],//物流设置
|
||||
['freight', 1],//运费设置
|
||||
['postage', 0],//邮费
|
||||
['temp_id', 0],//运费模版
|
||||
['recommend_list', []],
|
||||
['brand_id', []],
|
||||
['soure_link', ''],
|
||||
['bar_code', ''],
|
||||
['code', ''],
|
||||
['is_support_refund', 1],//是否支持退款
|
||||
['is_presale_product', 0],//预售商品开关
|
||||
['presale_time', []],//预售时间
|
||||
['presale_day', 0],//预售发货日
|
||||
['is_vip_product', 0],//是否付费会员商品
|
||||
['product_clear', ['is_general_product']],//商品用户可见,普通,采购商,付费会员可见
|
||||
['auto_on_time', 0],//自动上架时间
|
||||
['auto_off_time', 0],//自动下架时间
|
||||
['custom_form', []],//自定义表单
|
||||
['store_label_id', []],//商品标签
|
||||
['ensure_id', []],//商品保障服务区
|
||||
['specs', []],//商品参数
|
||||
['specs_id', 0],//商品参数ID
|
||||
['is_limit', 0],//是否限购
|
||||
['limit_type', 0],//限购类型
|
||||
['limit_num', 0],//限购数量
|
||||
['share_content', ''],//分享文案
|
||||
['min_qty', 1],//起购数量
|
||||
['presale_status', 0],//预售结束后状态
|
||||
['is_send_gift', 0],//商品是否支持送礼
|
||||
['send_gift_price', 0],//商品送礼附加费用
|
||||
]);
|
||||
$this->productServices->saveData($id, $data);
|
||||
return app('json')->success(!$id ? '保存商品信息成功' : '修改商品信息成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品详情
|
||||
* @param $id
|
||||
* @return mixed
|
||||
*/
|
||||
public function productInfo($id)
|
||||
{
|
||||
return app('json')->success($this->productServices->getInfo((int)$id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置商品状态
|
||||
* @param $id
|
||||
* @param $is_show
|
||||
* @return mixed
|
||||
*/
|
||||
public function productSetShow($id, $is_show)
|
||||
{
|
||||
$this->productServices->setShow([$id], $is_show);
|
||||
return app('json')->success('设置成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步库存
|
||||
* @return void
|
||||
*/
|
||||
public function uploadStock(Request $request)
|
||||
{
|
||||
[$items] = $request->postMore([['items', []]], true);
|
||||
|
||||
foreach ($items as $item) {
|
||||
if (!isset($item['bar_code']) || !isset($item['qty'])) {
|
||||
return app('json')->fail('请检查属性编码或库存数量');
|
||||
}
|
||||
}
|
||||
|
||||
if (count($items) > 100) {
|
||||
return app('json')->fail('同步条数不能超过100');
|
||||
}
|
||||
|
||||
$this->productServices->syncStock($items);
|
||||
return app('json')->success('操作成功');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user