| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238 |
- <?php
- // +----------------------------------------------------------------------
- // | likeshop100%开源免费商用商城系统
- // +----------------------------------------------------------------------
- // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
- // | 开源版本可自由商用,可去除界面版权logo
- // | 商业版本务必购买商业授权,以免引起法律纠纷
- // | 禁止对系统程序代码以任何目的,任何形式的再发布
- // | gitee下载:https://gitee.com/likeshop_gitee
- // | github下载:https://github.com/likeshop-github
- // | 访问官网:https://www.likeshop.cn
- // | 访问社区:https://home.likeshop.cn
- // | 访问手册:http://doc.likeshop.cn
- // | 微信公众号:likeshop技术社区
- // | likeshop团队 版权所有 拥有最终解释权
- // +----------------------------------------------------------------------
- // | author: likeshopTeam
- // +----------------------------------------------------------------------
- namespace app\adminapi\controller\goods;
- use app\common\model\DistributionGoods;
- use app\adminapi\{
- logic\goods\GoodsLogic,
- validate\goods\GoodsValidate,
- lists\goods\GoodsCommonLists,
- controller\BaseAdminController,
- validate\goods\GoodsItemValidate,
- };
- use app\common\enum\GoodsEnum;
- /**
- * 商品控制器
- * Class GoodsController
- * @package app\adminapi\controller\goods
- */
- class GoodsController extends BaseAdminController
- {
- public function commonLists()
- {
- return $this->dataLists(new GoodsCommonLists());
- }
- /**
- * @notes 商品列表
- * @return \think\response\Json
- * @author cjhao
- * @date 2021/7/16 16:51
- */
- public function lists()
- {
- return $this->dataLists();
- }
- /**
- * @notes 添加商品
- * @return \think\response\Json
- * @author cjhao
- * @date 2021/7/13 15:05
- */
- public function add()
- {
- $params = $this->request->post();
- if (GoodsEnum::SEPC_TYPE_MORE == $params['spec_type']) {
- $params['server_spec_value_list'] = cartesian_product(array_converting(array_column($params['spec_value'],'spec_list')));
- }
- (new GoodsValidate())->post()->goCheck('add'); //商品基础信息验证
- (new GoodsItemValidate())->post()->goCheck('', $params); //商品规格验证
- $res = (new GoodsLogic)->add($params);
- if (true === $res) {
- return $this->success('添加商品成功',[],1,1);
- }
- return $this->fail($res);
- }
- /**
- * @notes 编辑商品
- * @return \think\response\Json
- * @author cjhao
- * @date 2021/7/14 17:54
- */
- public function edit()
- {
- $params = $this->request->post();
- if (GoodsEnum::SEPC_TYPE_MORE == $params['spec_type']) {
- $params['server_spec_value_list'] = cartesian_product(array_converting(array_column($params['spec_value'],'spec_list')));
- }
- (new GoodsValidate())->post()->goCheck('edit', $params); //商品基础信息验证
- (new GoodsItemValidate())->post()->goCheck('', $params); //商品规格验证
- $res = (new GoodsLogic)->edit($params);
- if (true === $res['status'] && $res['is_distribution_goods']) {
- // 分销商品
- return $this->success('商品信息修改成功,该商品属于分销商品,请重新设置分销信息',[],1,1);
- }
- if (true === $res['status'] && !$res['is_distribution_goods']) {
- // 非分销商品
- return $this->success('修改成功',[],1,1);
- }
- return $this->fail($res['err']);
- }
- /**
- * @notes 获取商品
- * @return \think\response\Json
- * @author cjhao
- * @date 2021/7/15 14:16
- */
- public function detail(){
- $params = (new GoodsValidate())->goCheck('detail');
- $detail = (new GoodsLogic)->detail($params['id']);
- return $this->success('获取成功',$detail);
- }
- /**
- * @notes 设置商品状态
- * @return \think\response\Json
- * @author cjhao
- * @date 2021/7/17 17:10
- */
- public function status()
- {
- $params = (new GoodsValidate())->post()->goCheck('status');
- (new GoodsLogic)->status($params);
- return $this->success('操作成功',[],1,1);
- }
- /**
- * @notes 设置商品排序
- * @return \think\response\Json
- * @author cjhao
- * @date 2021/7/17 17:16
- */
- public function sort(){
- $params = (new GoodsValidate())->post()->goCheck('sort');
- (new GoodsLogic)->sort($params);
- return $this->success('操作成功');
- }
- /**
- * @notes 删除商品
- * @return \think\response\Json
- * @author cjhao
- * @date 2021/7/17 18:55
- */
- public function del(){
- $params = (new GoodsValidate())->post()->goCheck('del');
- (new GoodsLogic)->del($params['ids']);
- return $this->success('删除成功',[],1,1);
- }
- /**
- * @notes 其他列表
- * @return \think\response\Json
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- * @author cjhao
- * @date 2021/7/22 15:50
- */
- public function otherList(){
- $type = $this->request->get('type','list');
- $list = (new GoodsLogic())->otherList($type);
- return $this->success('',$list);
- }
- /**
- * @notes 修改商品名称
- * @return \think\response\Json
- * @author cjhao
- * @date 2021/7/29 16:12
- */
- public function rename(){
- $params = (new GoodsValidate())->post()->goCheck('rename');
- (new GoodsLogic)->rename($params);
- return $this->success('修改成功',[],1,1);
- }
- /**
- * @notes 移动分类
- * @return \think\response\Json
- * @throws \Exception
- * @author ljj
- * @date 2023/5/6 2:24 下午
- */
- pubLic function changeCategory()
- {
- $params = (new GoodsValidate())->post()->goCheck('changeCategory');
- (new GoodsLogic)->changeCategory($params);
- return $this->success('修改成功',[],1,1);
- }
- /**
- * @notes 商品规格价格导出
- * @return \think\response\Json
- * @author
- * @date 2024/01/01 00:00
- */
- public function exportSpecPrice()
- {
- return $this->dataLists(new \app\adminapi\lists\goods\GoodsSpecPriceLists());
- }
- /**
- * @notes 商品规格价格导入
- * @return \think\response\Json
- * @author
- * @date 2024/01/01 00:00
- */
- public function importSpecPrice()
- {
- $lists = \PhpOffice\PhpSpreadsheet\IOFactory::load($_FILES['file']['tmp_name'])->getActiveSheet()->toArray(null, true, true, true);
-
- $validate = $this->validate(['lists' => $lists], \app\adminapi\validate\goods\GoodsSpecPriceImport::class);
-
- if ($validate !== true) {
- return $this->fail($validate);
- }
-
- $result = (new GoodsLogic)->importSpecPriceLists($lists, $_FILES['file']['name']);
-
- if (!is_array($result)) {
- return $this->fail($result);
- }
-
- return $this->success('导入成功', $result);
- }
-
- }
|