diff --git a/app/admin/model/Store.php b/app/admin/model/Store.php index e09abdcd..85c8e55d 100644 --- a/app/admin/model/Store.php +++ b/app/admin/model/Store.php @@ -50,6 +50,12 @@ class Store extends StoreModel */ public function add(array $data) { + //商城端添加商城,去除store_id字段 + if (isset($data['is_store']) && $data['is_store'] == 1) { + //去掉where条件store_id + self::$storeId = 0; + app()->request->setStoreId(0); + } if ($data['password'] !== $data['password_confirm']) { $this->error = '确认密码不正确'; return false; @@ -71,8 +77,12 @@ class Store extends StoreModel if ($user_id) { (new StoreUserModel)->where(['store_id' => $this['store_id']])->save(['user_id' => $user_id]); } - //复制商品分类 - $this->copyCategory((int)$this['store_id']); + //只有总后台开通商城,才需要复制分类 + if (!isset($data['is_store'])) { + //复制商品分类 + $this->copyCategory((int)$this['store_id']); + } + //多商户版本新增一个商户角色 if (isset($data['store_version']) && $data['store_version'] == 1) { $this->addMerchantRoleAndMenu((int)$this['store_id']); diff --git a/app/api/controller/Category.php b/app/api/controller/Category.php index f0f4b1eb..4905d3f9 100644 --- a/app/api/controller/Category.php +++ b/app/api/controller/Category.php @@ -38,9 +38,14 @@ class Category extends Controller $list = Cache::get($cache_key); return $this->renderSuccess(compact('list')); } + $param = $this->request->param(); + $param['p_store_id'] = $this->storeInfo->p_store_id; $model = new CategoryModel; - $list = $model->getListPublic($this->request->param()); - Cache::set($cache_key, $list, 3600); + $list = $model->getListPublic($param); + if ($list) { + Cache::set($cache_key, $list, 3600); + } + return $this->renderSuccess(compact('list')); } diff --git a/app/api/controller/Checkout.php b/app/api/controller/Checkout.php index 66ae4727..86117b52 100644 --- a/app/api/controller/Checkout.php +++ b/app/api/controller/Checkout.php @@ -92,10 +92,14 @@ class Checkout extends Controller (int)$params['goodsNum'] ); $merchantId = 0; - - foreach ($goodsList as $g) { - $merchantId = $g['merchant_id']; + //有上级商城的,商户ID都=0 + if ($this->storeInfo->p_store_id == 0) { + foreach ($goodsList as $g) { + $merchantId = $g['merchant_id']; + } } + + // 获取订单确认信息 $orderInfo = $Checkout->onCheckout($goodsList); // echo "
"; @@ -116,8 +120,8 @@ class Checkout extends Controller // 创建订单 增加订单 $orderInfo['merchantId'] = $merchantId; if ($merchantId) { - $model = \app\store\model\Merchant::detail($merchantId, $this->storeId); - $orderInfo['commission_ratio'] = $model['commission_ratio']; + $model = \app\store\model\Merchant::withoutGlobalScope()->where("merchant_id", $merchantId)->find(); + $orderInfo['commission_ratio'] = $model['commission_ratio'] ?? 0; } //print_r($orderInfo);die; if (!$Checkout->createOrder($orderInfo)) { diff --git a/app/api/controller/Goods.php b/app/api/controller/Goods.php index 95718ff6..108dd6ff 100644 --- a/app/api/controller/Goods.php +++ b/app/api/controller/Goods.php @@ -19,6 +19,8 @@ use think\facade\Cache; use EasyWeChat\Factory; use app\api\service\Setting as SettingService; use app\common\service\GoodsCateEs; +use app\common\service\Jd; + /** * 商品控制器 * Class Goods @@ -88,6 +90,11 @@ class Goods extends Controller $setting = $service->getGoodsCustomer($merchantId,$storeId); $goodsInfo['setting'] = $setting; + //京东短链 + $jd = new Jd(); + $jd_short_url = $jd->getJdShortLink($goodsInfo['goods_no']); + //获取商品短链 + $goodsInfo['jd_short_url'] = $jd_short_url; return $this->renderSuccess(['detail' => $goodsInfo]); } @@ -129,6 +136,8 @@ class Goods extends Controller $return[] = $data; continue; } + // var_dump($goods->channel); + // exit(); switch ($goods->channel) { case 'sn': case 'sn1': diff --git a/app/api/controller/sharp/Goods.php b/app/api/controller/sharp/Goods.php index ee1535a5..1ccc9374 100644 --- a/app/api/controller/sharp/Goods.php +++ b/app/api/controller/sharp/Goods.php @@ -19,6 +19,7 @@ use app\api\service\sharp\Active as ActiveService; use app\common\service\qrcode\sharp\Goods as GoodsPoster; use cores\exception\BaseException; use app\api\service\Setting as SettingService; +use app\common\service\Jd; /** * 整点秒杀-商品管理 @@ -64,6 +65,11 @@ class Goods extends Controller $service = new SettingService; $setting = $service->getGoodsCustomer($merchantId,$storeId); $data['setting'] = $setting; + + //京东短链 + $jd = new Jd(); + $jd_short_url = $jd->getJdShortLink($data['goods']['goods_no']); + $data['goods']['jd_short_url'] = $jd_short_url; return $this->renderSuccess($data); } diff --git a/app/api/model/Goods.php b/app/api/model/Goods.php index b09055ff..aae09250 100644 --- a/app/api/model/Goods.php +++ b/app/api/model/Goods.php @@ -437,7 +437,7 @@ class Goods extends GoodsModel { // 关联查询(商品图片、sku列表) //$with = ['images.file', 'skuList.image', 'video', 'videoCover']; - $info = $this->field('spec_type,goods_id')->find($goodsId); + $info = self::withoutGlobalScope()->field('spec_type,goods_id')->find($goodsId); if (!$info) { throwError('很抱歉,商品信息不存在'); } diff --git a/app/api/model/Order.php b/app/api/model/Order.php index 07a47cd8..29a50e1f 100644 --- a/app/api/model/Order.php +++ b/app/api/model/Order.php @@ -136,9 +136,10 @@ class Order extends OrderModel $list = $query->paginate(10)->toArray(); //这边后面改成多商户的话需要根据storeid去获取信息 $service = new StoreService; - $goodsModel = new GoodsModel; + $info = $service->data(); - //if (!empty($info['storeInfo'])) { + $goodsModel = new GoodsModel; + if (!empty($info['storeInfo'])) { $info = $info['storeInfo']->toArray(); foreach ($list['data'] as &$v) { $v['storeInfo'] = $info; @@ -154,7 +155,7 @@ class Order extends OrderModel $v['total_num'] = $total_num; $v['delivery'] = DeliveryModel::where('order_id', $v['order_id'])->find(); } - //} + } return $list; } @@ -497,6 +498,9 @@ class Order extends OrderModel //$onlyCurrentUser && $where['user_id'] = UserService::getCurrentLoginUserId(); // 查询订单记录 $order = static::detail($where, $with); + // echo ""; + // print_r($order->toArray()); + // exit(); empty($order) && throwError('订单不存在'); //这边后面改成多商户的话需要根据storeid去获取信息 $service = new StoreService; diff --git a/app/common/model/Category.php b/app/common/model/Category.php index ef2d343d..a7ff693c 100644 --- a/app/common/model/Category.php +++ b/app/common/model/Category.php @@ -93,6 +93,15 @@ class Category extends BaseModel */ protected function getAll(array $param = []): \think\Collection { + $storeId = self::$storeId; + //去掉where条件store_id + self::$storeId = 0; + app()->request->setStoreId(0); + $storeIds = [$storeId]; + if (isset($param['p_store_id']) && $param['p_store_id']) { + $storeIds[] = $param['p_store_id']; + } + // 默认查询参数 $params = $this->setQueryDefaultValue($param, [ 'status' => -1 // 状态(1显示 0隐藏 -1全部) @@ -101,6 +110,8 @@ class Category extends BaseModel $filter = []; $params['status'] > -1 && $filter[] = ['status', '=', $params['status']]; + $filter[] = ['store_id', 'in', $storeIds]; + if (isset($param['is_hot']) && $param['is_hot'] != "") { $filter[] = ['is_hot', '=', $params['is_hot']]; } diff --git a/app/common/model/Goods.php b/app/common/model/Goods.php index 7b33bd4b..4ede44f2 100644 --- a/app/common/model/Goods.php +++ b/app/common/model/Goods.php @@ -45,6 +45,10 @@ class Goods extends BaseModel // 追加字段 protected $append = ['goods_sales']; + // public function __construct(){ + // self::$storeId = 0; + // // app()->request->setStoreId(0); + // } /** * 关联模型:主图视频文件 * @return HasOne @@ -539,6 +543,9 @@ class Goods extends BaseModel if (isset($param['goodsIds']) && $param['goodsIds'] !== '') { $filter[] = ['goods.goods_id', 'in', explode(",", $param['goodsIds'])]; } + if (isset($param['goodsId']) && $param['goodsId'] !== '') { + $filter[] = ['goods.goods_id', 'in', explode(",", $param['goodsId'])]; + } // 商品名称 if (!empty($params['goodsName'])) { $goods_name = str_replace(" ", "", $params['goodsName']); @@ -773,7 +780,7 @@ class Goods extends BaseModel // 商品状态 $status > 0 && $filter[] = ['status', '=', $status]; // 获取商品列表数据 - $data = $this->withoutField(['content']) + $data = self::withoutGlobalScope()->withoutField(['content']) ->with(['images.file']) ->where($filter) ->where('is_delete', '=', 0) @@ -791,8 +798,8 @@ class Goods extends BaseModel */ public static function detail(int $goodsId, array $with = []) { - // var_dump($with); - // exit(); + self::$storeId = 0; + app()->request->setStoreId(0); return static::get($goodsId, $with); } } diff --git a/app/common/model/GoodsSku.php b/app/common/model/GoodsSku.php index fa96724d..a37018cb 100644 --- a/app/common/model/GoodsSku.php +++ b/app/common/model/GoodsSku.php @@ -87,6 +87,8 @@ class GoodsSku extends BaseModel */ public static function detail(int $goodsId, string $goodsSkuId) { + self::$storeId = 0; + app()->request->setStoreId(0); return static::get(['goods_id' => $goodsId, 'goods_sku_id' => $goodsSkuId], ['image']); } diff --git a/app/common/service/order/source/Basics.php b/app/common/service/order/source/Basics.php index 3cefa321..7e8e77af 100644 --- a/app/common/service/order/source/Basics.php +++ b/app/common/service/order/source/Basics.php @@ -14,6 +14,7 @@ namespace app\common\service\order\source; use app\common\service\BaseService; use app\common\model\GoodsSku as GoodsSkuModel; +use app\common\model\Goods as GoodsModel; use app\common\enum\goods\Status as GoodsStatusEnum; use app\common\enum\order\PayStatus as PayStatusEnum; use app\common\enum\order\OrderStatus as OrderStatusEnum; @@ -65,9 +66,17 @@ abstract class Basics extends BaseService { foreach ($goodsList as $goods) { // 判断商品是否下架 - if ($verifyStatus && $goods['goods']['status'] == GoodsStatusEnum::OFF_SALE) { - $this->error = "很抱歉,商品 [{$goods['goods_name']}] 已下架"; - return false; + // if ($verifyStatus && $goods['goods']['status'] == GoodsStatusEnum::OFF_SALE) { + // $this->error = "很抱歉,商品 [{$goods['goods_name']}] 已下架"; + // return false; + // } + if ($verifyStatus) { + $info = GoodsModel::detail($goods['goods_id']); + if ($info['status'] == GoodsStatusEnum::OFF_SALE) { + $this->error = "很抱歉,商品 [{$goods['goods_name']}] 已下架"; + return false; + } + } // 获取商品的sku信息 $goodsSku = $this->getOrderGoodsSku($goods['goods_id'], $goods['goods_sku_id']); diff --git a/app/store/controller/Category.php b/app/store/controller/Category.php index d3df33b2..bb6a6922 100644 --- a/app/store/controller/Category.php +++ b/app/store/controller/Category.php @@ -31,8 +31,9 @@ class Category extends Controller */ public function list(): Json { + $params['p_store_id'] = $this->storeInfo->p_store_id; $model = new CategoryModel; - $list = $model->getList(); + $list = $model->getList($params); return $this->renderSuccess(compact('list')); } diff --git a/app/store/controller/Store.php b/app/store/controller/Store.php index 1432708b..160d9541 100644 --- a/app/store/controller/Store.php +++ b/app/store/controller/Store.php @@ -35,8 +35,13 @@ class Store extends Controller public function index(): Json { // 商城列表 - $model = new AdminStoreModel; - $list = $model->getList(); + $list = AdminStoreModel::withoutGlobalScope()->where('is_recycle', '=', 0) + ->where('p_store_id', '=', $this->storeId) + + ->where('is_delete', '=', 0) + ->order(['sort' => 'asc', 'create_time' => 'desc']) + ->paginate(15); + if (!$list->isEmpty()) { $list = $list->toArray(); foreach ($list['data'] as &$value) { @@ -53,7 +58,15 @@ class Store extends Controller { // 新增记录 $model = new AdminStoreModel; - if ($model->add($this->postForm())) { + $params = $this->postForm(); + $params['is_store'] = 1; + $params['p_store_id'] = $this->storeId; + $store = AdminStoreModel::detail($this->storeId); + $count = AdminStoreModel::withoutGlobalScope()->where('p_store_id', $this->storeId)->where('is_recycle', '=', 0)->where('is_delete', '=', 0)->count(); + if ($store['limit_open_store_num'] <= $count) { + return $this->renderError("您授权的商城数量已达到上限:".$count); + } + if ($model->add($params)) { return $this->renderSuccess('添加成功'); } return $this->renderError($model->getError() ?: '添加失败'); @@ -65,11 +78,10 @@ class Store extends Controller public function edit(int $storeId): Json { $params = $this->postForm(); - // 商城详情 - $model = AdminStoreModel::detail($storeId); + // 更新记录 - if (!$model->edit($params)) { - return $this->renderError($model->getError() ?: '更新失败'); + if (!AdminStoreModel::withoutGlobalScope()->where('store_id', $storeId)->update($params)) { + return $this->renderError('更新失败'); } return $this->renderSuccess('更新成功'); } diff --git a/app/store/model/Goods.php b/app/store/model/Goods.php index 834c9d13..6ab35921 100644 --- a/app/store/model/Goods.php +++ b/app/store/model/Goods.php @@ -72,7 +72,7 @@ class Goods extends GoodsModel */ public function getBasic(int $goodsId) { - $info = $this->field('spec_type,goods_id')->find($goodsId); + $info = self::withoutGlobalScope()->field('spec_type,goods_id')->find($goodsId); // 关联查询 if ($info->spec_type == GoodsSpecTypeEnum::SINGLE) { $with = ['images.file', 'skuList1.image', 'video', 'videoCover'];