From 175769f614e4ec2d1486164975ae0c4c7adb483d Mon Sep 17 00:00:00 2001 From: guojia <445241500@qq.com> Date: Mon, 22 Apr 2024 21:25:46 +0800 Subject: [PATCH] merge merchantId --- app/common/model/Goods.php | 6 ++++++ app/common/model/Payment.php | 16 ++++++++++------ app/store/controller/Controller.php | 3 +++ app/store/controller/setting/Payment.php | 3 ++- .../controller/setting/payment/Template.php | 3 ++- app/store/model/Order.php | 6 ++++++ app/store/model/PaymentTemplate.php | 8 ++++++-- public/install/data/install_struct.sql | 4 ++++ 8 files changed, 39 insertions(+), 10 deletions(-) diff --git a/app/common/model/Goods.php b/app/common/model/Goods.php index 40d7b93f..61ea8956 100644 --- a/app/common/model/Goods.php +++ b/app/common/model/Goods.php @@ -434,6 +434,12 @@ class Goods extends BaseModel if (isset($param['is_new']) && $param['is_new'] !== '') { $filter[] = ['is_new', '=', $param['is_new']]; } + + //gj + if (isset($param['merchantId']) && $param['merchantId']) { + $filter[] = ['merchant_id', '=', $param['merchantId']]; + } + if (!empty($param['paihang'])) { $filter[] = ['paihang', '>', 0]; $query->order('paihang asc'); diff --git a/app/common/model/Payment.php b/app/common/model/Payment.php index 58a334ad..48648ede 100644 --- a/app/common/model/Payment.php +++ b/app/common/model/Payment.php @@ -79,17 +79,17 @@ class Payment extends BaseModel * @throws \think\db\exception\DbException * @throws \think\db\exception\DataNotFoundException */ - public static function getAll(int $storeId): array + public static function getAll(int $storeId, int $merchantId = 0): array { // 实例化当前模型 $model = new static; // 默认的支付方式数据 $defaultData = $model->defaultData(); - if (!$data = Cache::get("payment_{$storeId}")) { + if (!$data = Cache::get("payment_{$storeId}_{$merchantId}")) { // 获取所有支付方式 - $data = $model->dataByStorage($storeId, $defaultData); + $data = $model->dataByStorage($storeId, $defaultData, $merchantId); // 写入缓存中 - Cache::tag('cache')->set("payment_{$storeId}", $data); + Cache::tag('cache')->set("payment_{$storeId}_{$merchantId}", $data); } // 重组缓存数据 (多维) return static::reorganize2($defaultData, $data); @@ -133,10 +133,14 @@ class Payment extends BaseModel * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ - private function dataByStorage(int $storeId, array $defaultData): array + private function dataByStorage(int $storeId, array $defaultData, int $merchantId = 0): array { // 获取数据库中所有的支付方式 - $list = $this->where('store_id', '=', $storeId)->select(); + $where = []; + if (isset($merchantId) && $merchantId) { + $where = ['merchant_id', '=', $merchantId]; + } + $list = $this->where($where)->where('store_id', '=', $storeId)->select(); if ($list->isEmpty()) { return []; } diff --git a/app/store/controller/Controller.php b/app/store/controller/Controller.php index c347966e..6ae4e2df 100644 --- a/app/store/controller/Controller.php +++ b/app/store/controller/Controller.php @@ -31,6 +31,9 @@ class Controller extends BaseController // 当前商城ID protected int $storeId; + // 当前商户ID + protected int $merchantId; + // 当前控制器名称 protected string $controller = ''; diff --git a/app/store/controller/setting/Payment.php b/app/store/controller/setting/Payment.php index 9911274b..ed0ad5b0 100644 --- a/app/store/controller/setting/Payment.php +++ b/app/store/controller/setting/Payment.php @@ -22,7 +22,8 @@ class Payment extends Controller */ public function options(): Json { - $options = PaymentModel::getAll($this->storeId); + $this->merchantId = $this->request->param("merchantId"); + $options = PaymentModel::getAll($this->storeId, $this->merchantId); return $this->renderSuccess(compact('options')); } diff --git a/app/store/controller/setting/payment/Template.php b/app/store/controller/setting/payment/Template.php index 2d46a732..da2cf8db 100644 --- a/app/store/controller/setting/payment/Template.php +++ b/app/store/controller/setting/payment/Template.php @@ -31,8 +31,9 @@ class Template extends Controller */ public function list(): Json { + $merchantId = $this->request->param("merchantId"); $model = new PaymentTemplateModel; - $list = $model->getList(); + $list = $model->getList($merchantId); return $this->renderSuccess(compact('list')); } diff --git a/app/store/model/Order.php b/app/store/model/Order.php index db7603aa..34415927 100644 --- a/app/store/model/Order.php +++ b/app/store/model/Order.php @@ -221,6 +221,12 @@ class Order extends OrderModel $params['extractShopId'] > 0 && $filter[] = ['extract_shop_id', '=', (int)$params['extractShopId']]; // 会员ID $params['userId'] > 0 && $filter[] = ['order.user_id', '=', (int)$params['userId']]; + + //gj + if (isset($param['merchantId']) && $param['merchantId']) { + $filter[] = ['merchant_id', '=', $param['merchantId']]; + } + //非售后订单 $filter[] = ['is_refund', '=', 10]; return $filter; diff --git a/app/store/model/PaymentTemplate.php b/app/store/model/PaymentTemplate.php index 44076c52..5fc792cf 100644 --- a/app/store/model/PaymentTemplate.php +++ b/app/store/model/PaymentTemplate.php @@ -32,9 +32,13 @@ class PaymentTemplate extends PaymentTemplateModel * @return \think\Paginator * @throws \think\db\exception\DbException */ - public function getList(): \think\Paginator + public function getList($merchantId = 0): \think\Paginator { - return $this->where('is_delete', '=', 0) + $where = []; + if (isset($merchantId) && $merchantId) { + $where = ['merchant_id', '=', $merchantId]; + } + return $this->where($where)->where('is_delete', '=', 0) ->order(['sort' => 'asc', $this->getPk()]) ->paginate(15); } diff --git a/public/install/data/install_struct.sql b/public/install/data/install_struct.sql index 49b10df0..c8f8270d 100644 --- a/public/install/data/install_struct.sql +++ b/public/install/data/install_struct.sql @@ -429,6 +429,7 @@ CREATE TABLE `yoshop_goods` ( `goods_no` varchar(50) NOT NULL DEFAULT '' COMMENT '商品编码', `video_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '主图视频ID', `video_cover_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '主图视频ID', + `merchant_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '商户ID、商店ID 隔离商城里面的商户', `selling_point` varchar(500) NOT NULL DEFAULT '' COMMENT '商品卖点', `spec_type` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT '商品规格(10单规格 20多规格)', `goods_price_min` decimal(10,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '商品价格(最低)', @@ -755,6 +756,7 @@ CREATE TABLE `yoshop_order` ( `user_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '用户ID', `is_delete` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT '是否删除', `store_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '商城ID', + `merchant_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '商户ID、商店ID 隔离商城里面的商户' `create_time` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '创建时间', `update_time` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '更新时间', PRIMARY KEY (`order_id`), @@ -974,6 +976,7 @@ CREATE TABLE `yoshop_payment` ( `is_default` tinyint(3) unsigned NOT NULL DEFAULT '1' COMMENT '是否为默认支付方式', `others` text NOT NULL COMMENT '其他选项(json格式)', `store_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '商城ID', + `merchant_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '商户ID、商店ID 隔离商城里面的商户', `create_time` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '创建时间', `update_time` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '更新时间', PRIMARY KEY (`payment_id`), @@ -992,6 +995,7 @@ CREATE TABLE `yoshop_payment_template` ( `sort` int(3) unsigned NOT NULL DEFAULT '100' COMMENT '排序(数字越小越靠前)', `is_delete` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '是否删除', `store_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '商城ID', + `merchant_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '商户ID、商店ID 隔离商城里面的商户', `create_time` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '创建时间', `update_time` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '更新时间', PRIMARY KEY (`template_id`),