From f28d075702a9562232503c66e4b76b48aeeaa91b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=AD=E5=98=89?= <445241500@qq.com> Date: Fri, 31 May 2024 22:46:33 +0800 Subject: [PATCH] 1 --- app/api/service/order/PaySuccess.php | 9 ++++ app/common/model/Merchant.php | 13 +++++ app/common/model/MerchantPay.php | 71 ++++++++++++++++++++++++++ app/store/model/MerchantPay.php | 65 +++++++++++++++++++++++ public/install/data/install_struct.sql | 40 +++++++++++---- 5 files changed, 187 insertions(+), 11 deletions(-) create mode 100644 app/common/model/MerchantPay.php create mode 100644 app/store/model/MerchantPay.php diff --git a/app/api/service/order/PaySuccess.php b/app/api/service/order/PaySuccess.php index 4d2d78a5..16c86142 100644 --- a/app/api/service/order/PaySuccess.php +++ b/app/api/service/order/PaySuccess.php @@ -15,6 +15,8 @@ namespace app\api\service\order; use think\facade\Event; use app\api\model\User as UserModel; use app\api\model\Order as OrderModel; +use app\common\model\Merchant as merchantModel; +use app\common\model\MerchantPay as merchantPayModel; use app\api\model\PaymentTrade as PaymentTradeModel; use app\api\model\user\BalanceLog as BalanceLogModel; use app\api\service\order\source\Factory as OrderSourceFactory; @@ -292,6 +294,7 @@ class PaySuccess extends BaseService $this->updateOrderStatus(); // 累积用户总消费金额 UserModel::setIncPayMoney($orderInfo['user_id'], (float)$orderInfo['pay_price']); + // 记录订单支付信息 $this->updatePayInfo(); }); @@ -349,6 +352,12 @@ class PaySuccess extends BaseService 'user_id' => (int)$orderInfo['user_id'], 'money' => -$orderInfo['pay_price'], ], ['order_no' => $orderInfo['order_no']]); + + //增加商户支付详情 + (new merchantPayModel())->addDetail($orderInfo); + + //累计商户余额支付金额 + merchantModel::setIncTotal($orderInfo['merchant_id'], (float)$orderInfo['pay_price']); } // 将第三方交易记录更新为已支付状态 if (in_array($this->method, [PaymentMethodEnum::WECHAT, PaymentMethodEnum::ALIPAY])) { diff --git a/app/common/model/Merchant.php b/app/common/model/Merchant.php index 9f2afe19..8e382063 100644 --- a/app/common/model/Merchant.php +++ b/app/common/model/Merchant.php @@ -123,4 +123,17 @@ class Merchant extends BaseModel { return $this->save(['is_delete' => 1]); } + + /** + * 累积用户可用余额 + * @param int $userId + * @param float $money + * @return mixed + */ + public static function setIncTotal(int $merchantId, float $money) + { + (new static)->setInc($merchantId, 'total_amount', $money); + (new static)->setInc($merchantId, 'available_amount', $money); + return true; + } } diff --git a/app/common/model/MerchantPay.php b/app/common/model/MerchantPay.php new file mode 100644 index 00000000..3e04a8d0 --- /dev/null +++ b/app/common/model/MerchantPay.php @@ -0,0 +1,71 @@ + +// +---------------------------------------------------------------------- +declare (strict_types=1); + +namespace app\common\model; + +use cores\BaseModel; +use think\model\relation\HasOne; + +/** + * Class Store + * @package app\common\model + */ +class MerchantPay extends BaseModel +{ + // 定义表名 + protected $name = 'merchant_pay'; + + // 定义主键 + protected $pk = 'merchant_pay_id'; + + + /** + * 累积用户可用余额 + * @param int $userId + * @param float $money + * @return mixed + */ + public function addDetail($orderInfo) + { + if (!empty($orderInfo['merchant_id'])) { + $data = [ + 'order_id' => $orderInfo['order_id'], + //'store_id' => $orderInfo['store_id'], + 'merchant_id' => $orderInfo['merchant_id'], + 'total_amount' => (float)$orderInfo['pay_price'], + ]; + return $this->save($this->createData($data)); + } + return true; + } + + /** + * 创建数据 + * @param array $data + * @return array + */ + private function createData(array $data): array + { + $data['store_id'] = self::$storeId; + return $data; + } + + + /** + * 软删除 + * @return bool + */ + public function setDelete(): bool + { + return $this->save(['is_delete' => 1]); + } +} diff --git a/app/store/model/MerchantPay.php b/app/store/model/MerchantPay.php new file mode 100644 index 00000000..4d05f2c0 --- /dev/null +++ b/app/store/model/MerchantPay.php @@ -0,0 +1,65 @@ + +// +---------------------------------------------------------------------- +declare (strict_types=1); + +namespace app\store\model; + +use app\common\model\MerchantPay as StoreModel; + +/** + * 商家记录表模型 + * Class Store + * @package app\store\model + */ +class MerchantPay extends StoreModel +{ + /** + * 更新记录 + * @param array $data + * @return bool + */ + public function edit(array $data): bool + { + // 是否删除图片 + !isset($data['logo_image_id']) && $data['logo_image_id'] = 0; + return $this->save($data) !== false; + } + + /** + * 新增记录 + * @param array $data + * @return bool + */ + public function add(array $data): bool + { + return $this->save($this->createData($data)); + } + + /** + * 创建数据 + * @param array $data + * @return array + */ + private function createData(array $data): array + { + $data['store_id'] = self::$storeId; + return $data; + } + + /** + * 软删除 + * @return bool + */ + public function setDelete(): bool + { + return $this->save(['is_delete' => 1]); + } +} diff --git a/public/install/data/install_struct.sql b/public/install/data/install_struct.sql index b5ecd942..168019e6 100644 --- a/public/install/data/install_struct.sql +++ b/public/install/data/install_struct.sql @@ -756,7 +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 隔离商城里面的商户' + `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`), @@ -1728,25 +1728,43 @@ ALTER TABLE `yoshop_store_menu` MODIFY COLUMN `type` tinyint UNSIGNED NOT NULL DEFAULT 10 COMMENT '菜单类型(10页面 20操作)' AFTER `menu_id`, ADD COLUMN `is_page` tinyint(3) UNSIGNED NOT NULL DEFAULT 1 COMMENT '是否为页面(1是 0否)' AFTER `path`; -DROP TABLE IF EXISTS `yoshop_merchant`; + DROP TABLE IF EXISTS `yoshop_merchant`; CREATE TABLE `yoshop_merchant` ( - `merchant_id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID', - `shop_name` varchar(100) NOT NULL DEFAULT '' COMMENT '名称', - `shop_label` varchar(100) NOT NULL DEFAULT '' COMMENT '标签', -`logo_image_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '门店logo图片ID', -`license_img_id` varchar(200) NOT NULL DEFAULT '' COMMENT '营业执照图片ID', -`user_name` varchar(100) NOT NULL DEFAULT '' COMMENT '买家用户名', -`sort` int(11) NOT NULL DEFAULT '0' COMMENT '门店排序(数字越小越靠前)', -`score` varchar(100) NOT NULL DEFAULT '' COMMENT '得分', -`sale` varchar(100) NOT NULL DEFAULT '' COMMENT '销量', +`merchant_id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID', + `shop_name` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '名称', + `shop_label` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '标签', + `logo_image_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '门店logo图片ID', + `license_img_id` varchar(200) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '营业执照图片ID', + `user_name` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '买家用户名', + `sort` int(11) NOT NULL DEFAULT '0' COMMENT '门店排序(数字越小越靠前)', `is_delete` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '是否删除', `store_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '商城ID', `create_time` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '创建时间', `update_time` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '更新时间', + `score` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '得分', + `sale` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '销量', + `is_select_mechant` tinyint(4) unsigned NOT NULL DEFAULT '0' COMMENT '是否精选商户', + `total_amount` decimal(10,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '累计金额', + `available_amount` decimal(10,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '可用金额', PRIMARY KEY (`merchant_id`), KEY `store_id` (`store_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='商户表'; +DROP TABLE IF EXISTS `yoshop_merchant_pay`; +CREATE TABLE `yoshop_merchant_pay` ( +`merchant_pay_id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID', + `store_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '商城ID', + `merchant_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '商户id', + `order_id` varchar(200) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '订单id', + `is_delete` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '是否删除', + `create_time` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '创建时间', + `update_time` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '更新时间', + `total_amount` decimal(10,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '金额', + `is_add` tinyint(3) UNSIGNED NOT NULL DEFAULT 1 COMMENT '是否为收入金额', + PRIMARY KEY (`merchant_pay_id`), + KEY `store_id` (`store_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='商户收入表'; + DROP TABLE IF EXISTS `yoshop_style`; CREATE TABLE `yoshop_style` ( `style_id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',