123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260 |
- <?php
- // +----------------------------------------------------------------------
- // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
- // +----------------------------------------------------------------------
- // | Author: 萤火科技 <admin@yiovo.com>
- // +----------------------------------------------------------------------
- declare (strict_types = 1);
- namespace app\store\controller;
- use app\common\exception\BaseException;
- use app\common\service\Export as ExportService;
- use app\store\model\Goods as GoodsModel;
- use app\store\model\GoodsSku;
- use app\store\model\GoodsSku as GoodsSkuModel;
- use app\store\model\member\MemberGoods;
- use app\store\model\user\Withdraw as WithdrawModel;
- use app\common\model\ActivityDiscount as ActivityDiscount;
- use app\common\enum\goods\SpecType as SpecTypeEnum;
- use app\store\model\groupbuylb\GroupBuyLbActivity;
- /**
- * 商品管理控制器
- * Class Goods
- * @package app\store\controller
- */
- class Goods extends Controller
- {
- /**
- * 商品列表
- * @return array
- * @throws \think\db\exception\DbException
- */
- public function list()
- {
- // 获取列表记录
- $model = new GoodsModel;
- $params = $this->request->param();
- $params['sortType'] = 'create_time';
- $list = $model->getList($params);
- return $this->renderSuccess(compact('list'));
- }
- //单规格商品列表
- public function listspec(){
- //获取列表记录
- $model = new GoodsModel;
- $params = $this->request->param();
- $params['sortType'] = 'create_time';
- $params['spec_type'] = SpecTypeEnum::SINGLE;
- $list = $model->getList($params);
- return $this->renderSuccess(compact('list'));
- }
- /**
- * 商品列表
- * @return array
- * @throws \think\db\exception\DbException
- */
- public function listdiscount()
- {
- $discount = new ActivityDiscount;
- $params = $this->request->param();
- $activity_id = $params['activity_id']??0;
- $good_id_array = $discount->getActivityGoodIdArray($activity_id);
- // 获取列表记录
- $model = new GoodsModel;
- $params['sortType'] = 'create_time';
- $params['not_goods_id_arr'] = $good_id_array;
- $list = $model->getList($params);
- return $this->renderSuccess(compact('list'));
- }
- //裂变商品搜索
- public function skuPickerGroupBuyList(){
- $model = new GoodsSkuModel;
- $activity = new GroupBuyLbActivity;
- $params = $this->request->param();
- $activity_id = $params['activity_id']??0;
- $good_id_array = $activity->getActivityGoodIdArray($activity_id);
- $params['not_goods_id_arr'] = $good_id_array;
- $list = $model->getPickerList($params);
- return $this->renderSuccess(compact('list'));
- }
- /**
- * 按商品SKU返回列表
- * @return array
- * @throws \think\db\exception\DbException
- */
- public function skuPickerList()
- {
- // 获取列表记录
- $model = new GoodsSkuModel;
- $params = $this->request->param();
- $list = $model->getPickerList($params);
- return $this->renderSuccess(compact('list'));
- }
- /**
- * 根据商品ID集获取列表记录
- * @param array $goodsIds
- * @return array
- */
- public function listByIds(array $goodsIds)
- {
- // 获取列表记录
- $model = new GoodsModel;
- $list = $model->getListByIds($goodsIds);
- return $this->renderSuccess(compact('list'));
- }
- /**
- * 商品详情
- * @param int $goodsId
- * @return array
- * @throws BaseException
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function detail(int $goodsId)
- {
- // 获取商品详情
- $model = new GoodsModel;
- $goodsInfo = $model->getDetail($goodsId);
- return $this->renderSuccess(compact('goodsInfo'));
- }
- /**
- * 添加商品
- * @return array
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function add()
- {
- $model = new GoodsModel;
- if ($model->add($this->postForm())) {
- return $this->renderSuccess('添加成功');
- }
- return $this->renderError($model->getError() ?: '添加失败');
- }
- /**
- * 编辑商品
- * @param int $goodsId
- * @return array
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function edit(int $goodsId)
- {
- // 商品详情
- $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 array
- */
- public function state(array $goodsIds, bool $state)
- {
- $model = new GoodsModel;
- if (!$model->setStatus($goodsIds, $state)) {
- return $this->renderError($model->getError() ?: '操作失败');
- }
- return $this->renderSuccess('操作成功');
- }
- /**
- * 删除商品
- * @param array $goodsIds
- * @return array
- */
- public function delete(array $goodsIds)
- {
- $model = new GoodsModel;
- if (!$model->setDelete($goodsIds)) {
- return $this->renderError($model->getError() ?: '删除失败');
- }
- return $this->renderSuccess('删除成功');
- }
- /**
- * 根据商品id获取SKU列表
- * @param int $goodsId
- * @return array
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function skulist(int $good_id)
- {
- // 商品SKU列表
- $skulist = GoodsSkuModel::where("goods_id",$good_id)->select();
- $list = [];
- foreach($skulist as $row){
- $sku_name = $row->goods_props[0]['value']['name']??'';
- $goods_sku_id = $row->goods_sku_id;
- if(empty($sku_name)||empty($goods_sku_id)){
- continue;
- }
- $new['good_sku_id'] = $goods_sku_id;
- $new['name'] = $sku_name;
- $list[] = $new;
- }
- return $this->renderSuccess(compact('list'));
- }
- //成本管理
- public function manageCosts(){
- $model = new GoodsModel;
- $list = $model->getCostsList($this->request->param());
- return $this->renderSuccess(compact('list'));
- }
- public function editClearingPrices(array $skues){
- //dd($skues);
- GoodsSku::updateClearingPrice($skues);
- return $this->renderSuccess('成功');
- }
- public function editPlatformRate(array $rates){
- //dd($skues);
- GoodsSku::updatePlatformRate($rates);
- return $this->renderSuccess('成功');
- }
- /**
- * 导出成本管理列表功能
- * @return array
- * @author: zjwhust
- * @Time: 2021/10/15 13:43
- */
- public function orderExport(){
- $param = $this->request->param();
- /* if(isset($param['goods_id']) && empty($param['goods_id'])){
- return $this->renderError('请勾选订单商品后再导出');
- }*/
- $model = new GoodsModel();
- $data = $model->listExport($param);
- $res = ExportService::export($data['data'],$data['header'],$data['filename'],'列表','Xls',true);
- return $this->renderSuccess($res,'导出成功');
- }
- }
|