From 6ec2a91921a9afe16819e2948a1d14d1f793b000 Mon Sep 17 00:00:00 2001 From: zhouzhongping Date: Sat, 25 Apr 2020 22:53:20 +0800 Subject: [PATCH] 1.1.41 --- README.md | 11 + doc/database/install.sql | 19 + doc/database/upgrade/v1.1.41.sql | 9 + doc/更新日志.txt | 19 + source/application/admin/controller/Store.php | 1 - source/application/admin/model/Wxapp.php | 7 +- .../application/admin/model/store/Access.php | 514 ------------------ source/application/admin/model/store/User.php | 42 +- .../api/behavior/order/PaySuccess.php | 5 +- .../api/controller/sharing/Setting.php | 7 +- .../api/controller/user/dealer/Apply.php | 1 - .../api/controller/user/dealer/Withdraw.php | 2 +- .../api/controller/wxapp/Formid.php | 13 +- .../api/controller/wxapp/Submsg.php | 25 + source/application/api/model/Setting.php | 14 + .../application/api/model/sharing/Setting.php | 20 +- .../api/service/order/Checkout.php | 33 +- .../api/service/sharing/order/Checkout.php | 31 +- source/application/common.php | 14 + source/application/common/enum/Setting.php | 19 +- .../common/enum/dealer/ApplyStatus.php | 45 ++ .../enum/dealer/withdraw/ApplyStatus.php | 52 ++ .../common/enum/sharing/ActiveStatus.php | 51 ++ source/application/common/library/helper.php | 17 +- .../common/library/wechat/WxBase.php | 23 + .../common/library/wechat/WxSubMsg.php | 110 ++++ .../common/library/wechat/WxTplMsg.php | 2 +- source/application/common/model/Setting.php | 110 +++- source/application/common/model/Wxapp.php | 6 +- .../common/model/bargain/Setting.php | 2 - .../application/common/model/dealer/Apply.php | 22 +- .../common/model/dealer/Setting.php | 8 - .../common/model/dealer/Withdraw.php | 21 - .../common/model/sharing/Active.php | 27 +- .../common/model/sharing/Setting.php | 2 - source/application/common/service/Message.php | 358 +----------- .../common/service/message/Basics.php | 71 +++ .../common/service/message/dealer/Apply.php | 90 +++ .../service/message/dealer/Withdraw.php | 122 +++++ .../common/service/message/order/Delivery.php | 116 ++++ .../common/service/message/order/Payment.php | 107 ++++ .../common/service/message/order/Refund.php | 89 +++ .../service/message/sharing/ActiveStatus.php | 82 +++ .../common/service/order/Refund.php | 2 +- .../application/store/controller/Setting.php | 2 +- .../store/controller/apps/dealer/Apply.php | 4 +- .../store/controller/apps/dealer/Withdraw.php | 2 +- .../store/controller/apps/live/Room.php | 2 +- .../store/controller/market/Push.php | 3 +- .../store/controller/wxapp/Submsg.php | 50 ++ source/application/store/extra/menus.php | 25 +- source/application/store/model/Order.php | 14 +- .../application/store/model/OrderRefund.php | 33 +- source/application/store/model/Wxapp.php | 36 +- .../application/store/model/dealer/Apply.php | 39 +- .../store/model/dealer/Setting.php | 1 - .../store/model/dealer/Withdraw.php | 56 +- .../application/store/model/sharing/Order.php | 15 +- .../store/model/sharing/OrderRefund.php | 33 +- .../store/model/wxapp/LiveRoom.php | 28 +- source/application/store/service/Auth.php | 7 +- .../store/service/wxapp/Message.php | 3 +- .../store/service/wxapp/SubMsg.php | 194 +++++++ .../store/view/apps/dealer/setting/index.php | 33 -- .../store/view/apps/sharing/setting/index.php | 16 - .../store/view/wxapp/submsg/index.php | 146 +++++ .../task/behavior/sharing/Active.php | 21 +- version.json | 2 +- 68 files changed, 1907 insertions(+), 1199 deletions(-) create mode 100644 doc/database/upgrade/v1.1.41.sql create mode 100644 source/application/api/controller/wxapp/Submsg.php create mode 100644 source/application/common/enum/dealer/ApplyStatus.php create mode 100644 source/application/common/enum/dealer/withdraw/ApplyStatus.php create mode 100644 source/application/common/enum/sharing/ActiveStatus.php create mode 100644 source/application/common/library/wechat/WxSubMsg.php create mode 100644 source/application/common/service/message/Basics.php create mode 100644 source/application/common/service/message/dealer/Apply.php create mode 100644 source/application/common/service/message/dealer/Withdraw.php create mode 100644 source/application/common/service/message/order/Delivery.php create mode 100644 source/application/common/service/message/order/Payment.php create mode 100644 source/application/common/service/message/order/Refund.php create mode 100644 source/application/common/service/message/sharing/ActiveStatus.php create mode 100644 source/application/store/controller/wxapp/Submsg.php create mode 100644 source/application/store/service/wxapp/SubMsg.php create mode 100644 source/application/store/view/wxapp/submsg/index.php diff --git a/README.md b/README.md index 8970111..352c651 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,17 @@ ## 更新日志 +### v1.1.41 +``` +新增:微信小程序订阅消息 +修复:多开小程序直播间同步ID问题 +修复:库存1下单后提示商品库存不足 +修复:拼团商品预览sku图片报错 +优化:超管后台删除商家用户 + +注:本次更新须重新发布小程序 +``` + ### v1.1.40 ``` 新增:微信小程序直播功能 diff --git a/doc/database/install.sql b/doc/database/install.sql index 1d2fad6..68c3b09 100644 --- a/doc/database/install.sql +++ b/doc/database/install.sql @@ -5603,3 +5603,22 @@ INSERT INTO `yoshop_store_access` VALUES ('10460', '删除场次', 'apps.sharp.a INSERT INTO `yoshop_store_access` VALUES ('10461', '基础设置', 'apps.sharp.setting/index', '10444', '125', '1564449650', '1564449650'); +CREATE TABLE `yoshop_wxapp_live_room` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键id', + `room_id` int(11) unsigned NOT NULL COMMENT '直播间id', + `room_name` varchar(200) NOT NULL DEFAULT '' COMMENT '直播间名称', + `cover_img` varchar(255) DEFAULT '' COMMENT '分享卡片封面', + `share_img` varchar(255) DEFAULT '' COMMENT '直播间背景墙封面', + `anchor_name` varchar(30) NOT NULL DEFAULT '' COMMENT '主播昵称', + `start_time` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '开播时间', + `end_time` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '结束时间', + `live_status` tinyint(3) unsigned NOT NULL DEFAULT '102' COMMENT '直播状态(101: 直播中, 102: 未开始, 103: 已结束, 104: 禁播, 105: 暂停中, 106: 异常, 107: 已过期)', + `is_top` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT '置顶状态(0未置顶 1已置顶)', + `is_delete` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT '软删除(0未删除 1已删除)', + `wxapp_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 '更新时间', + PRIMARY KEY (`id`), + KEY `room_id` (`room_id`) +) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COMMENT='微信小程序直播间记录表'; + diff --git a/doc/database/upgrade/v1.1.41.sql b/doc/database/upgrade/v1.1.41.sql new file mode 100644 index 0000000..01b6978 --- /dev/null +++ b/doc/database/upgrade/v1.1.41.sql @@ -0,0 +1,9 @@ + + +ALTER TABLE `yoshop_wxapp_live_room` +ADD COLUMN `id` int UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键id' FIRST , +DROP PRIMARY KEY, +ADD PRIMARY KEY (`id`), +ADD INDEX `room_id` (`room_id`), +AUTO_INCREMENT=10001; + diff --git a/doc/更新日志.txt b/doc/更新日志.txt index 7b485a4..0f4eb47 100644 --- a/doc/更新日志.txt +++ b/doc/更新日志.txt @@ -1,4 +1,23 @@  +### v1.1.41 更新日志 ### + +新增:微信小程序订阅消息 +修复:多开小程序直播间同步ID问题 +修复:库存1下单后提示商品库存不足 +修复:拼团商品预览sku图片报错 +优化:超管后台删除商家用户 +-------------------------------- +注:本次更新须重新发布小程序 + + +### v1.1.40 更新日志 ### + +新增:微信小程序直播功能 +优化:商品评价过滤无效内容 +-------------------------------- +注:本次更新须重新发布小程序 + + ### v1.1.39 更新日志 ### 优化:后台菜单超出显示滚动条 diff --git a/source/application/admin/controller/Store.php b/source/application/admin/controller/Store.php index 6041b35..c6572ac 100644 --- a/source/application/admin/controller/Store.php +++ b/source/application/admin/controller/Store.php @@ -56,7 +56,6 @@ class Store extends Controller /** * 添加小程序 * @return array|mixed - * @throws \think\exception\PDOException */ public function add() { diff --git a/source/application/admin/model/Wxapp.php b/source/application/admin/model/Wxapp.php index 40e7e36..f5ef640 100644 --- a/source/application/admin/model/Wxapp.php +++ b/source/application/admin/model/Wxapp.php @@ -90,7 +90,12 @@ class Wxapp extends WxappModel */ public function setDelete() { - return $this->save(['is_delete' => 1]); + return $this->transaction(function () { + // 删除商家用户信息 + (new StoreUser)->setDelete($this['wxapp_id']); + // 设置当前商城为已删除 + return $this->save(['is_delete' => 1]); + }); } } diff --git a/source/application/admin/model/store/Access.php b/source/application/admin/model/store/Access.php index e00c2c6..b30557a 100644 --- a/source/application/admin/model/store/Access.php +++ b/source/application/admin/model/store/Access.php @@ -139,518 +139,4 @@ class Access extends AccessModel $this->buildData($defaultData); } - /** - * 生成并写入默认数据 - * @param $defaultData - * @param int $parent_id - */ - private function buildData(&$defaultData, $parent_id = 0) - { - foreach ($defaultData as $key => $item) { - // 保存数据 - $model = new static; - $model->save([ - 'name' => $item['name'], - 'url' => $item['url'], - 'parent_id' => $parent_id, - 'sort' => 100, - ]); - if (isset($item['subset']) && !empty($item['subset'])) { - $this->buildData($item['subset'], $model['access_id']); - } - } - } - - /** - * 默认权限数据 - * @return array - */ - private function defaultData() - { - return [ - [ - 'name' => '首页', - 'url' => 'index/index' - ], - [ - 'name' => '管理员', - 'url' => 'store', - 'subset' => [ - [ - 'name' => '管理员管理', - 'url' => 'store.user', - 'subset' => [ - [ - 'name' => '管理员列表', - 'url' => 'store.user/index' - ], - [ - 'name' => '添加管理员', - 'url' => 'store.user/add' - ], - [ - 'name' => '编辑管理员', - 'url' => 'store.user/edit' - ], - [ - 'name' => '删除管理员', - 'url' => 'store.user/delete' - ], - ] - ], - [ - 'name' => '角色管理', - 'url' => 'store.role', - 'subset' => [ - [ - 'name' => '角色列表', - 'url' => 'store.role/index' - ], - [ - 'name' => '添加角色', - 'url' => 'store.role/add' - ], - [ - 'name' => '编辑角色', - 'url' => 'store.role/edit' - ], - [ - 'name' => '删除角色', - 'url' => 'store.role/delete' - ], - ] - ], - [ - 'name' => '权限管理', - 'url' => 'store.access', - 'subset' => [ - [ - 'name' => '权限列表', - 'url' => 'store.access/index' - ], - [ - 'name' => '添加权限', - 'url' => 'store.access/add' - ], - [ - 'name' => '编辑权限', - 'url' => 'store.access/edit' - ], - [ - 'name' => '删除权限', - 'url' => 'store.access/delete' - ], - ] - ], - ] - ], - [ - 'name' => '商品管理', - 'url' => 'goods', - 'subset' => [ - [ - 'name' => '商品管理', - 'url' => 'goods', - 'subset' => [ - [ - 'name' => '商品列表', - 'url' => 'goods/index', - ], - [ - 'name' => '添加商品', - 'url' => 'goods/add', - ], - [ - 'name' => '编辑商品', - 'url' => 'goods/edit', - ], - [ - 'name' => '复制商品', - 'url' => 'goods/copy', - ], - [ - 'name' => '删除商品', - 'url' => 'goods/delete', - ], - [ - 'name' => '商品上下架', - 'url' => 'goods/state', - ], - ] - ], - [ - 'name' => '商品分类', - 'url' => 'goods.category', - 'subset' => [ - [ - 'name' => '分类列表', - 'url' => 'goods.category/index', - ], - [ - 'name' => '添加分类', - 'url' => 'goods.category/add', - ], - [ - 'name' => '编辑分类', - 'url' => 'goods.category/edit', - ], - [ - 'name' => '删除分类', - 'url' => 'goods.category/delete', - ], - ], - ], - [ - 'name' => '商品评价', - 'url' => 'goods.comment', - 'subset' => [ - [ - 'name' => '评价列表', - 'url' => 'goods.comment/index', - ], - [ - 'name' => '评价详情', - 'url' => 'goods.comment/detail', - ], - [ - 'name' => '删除评价', - 'url' => 'goods.comment/delete', - ], - ], - ], - ] - ], - [ - 'name' => '订单管理', - 'url' => 'order', - 'subset' => [ - [ - 'name' => '订单列表', - 'url' => '', - 'subset' => [ - [ - 'name' => '待发货', - 'url' => 'order/delivery_list' - ], - [ - 'name' => '待收货', - 'url' => 'order/receipt_list' - ], - [ - 'name' => '待付款', - 'url' => 'order/pay_list' - ], - [ - 'name' => '已完成', - 'url' => 'order/complete_list' - ], - [ - 'name' => '已取消', - 'url' => 'order/cancel_list' - ], - [ - 'name' => '全部订单', - 'url' => 'order/all_list', - ], - ] - ], - [ - 'name' => '订单详情', - 'url' => '', - 'subset' => [ - [ - 'name' => '详情信息', - 'url' => 'order/detail', - ], - [ - 'name' => '确认发货', - 'url' => 'order/delivery', - ], - [ - 'name' => '修改订单价格', - 'url' => 'order/updateprice', - ], - ] - ], - [ - 'name' => '订单导出', - 'url' => 'order.operate/export', - ], - [ - 'name' => '批量发货', - 'url' => 'order.operate/batchdelivery', - ], - ] - ], - [ - 'name' => '用户管理', - 'url' => 'user', - 'subset' => [ - [ - 'name' => '用户列表', - 'url' => 'user/index' - ], - [ - 'name' => '删除用户', - 'url' => 'user/delete' - ], - ] - ], - [ - 'name' => '营销设置', - 'url' => 'market', - 'subset' => [ - [ - 'name' => '优惠券', - 'url' => 'coupon', - 'subset' => [ - [ - 'name' => '优惠券列表', - 'url' => 'market.coupon/index', - ], - [ - 'name' => '新增优惠券', - 'url' => 'market.coupon/add', - ], - [ - 'name' => '编辑优惠券', - 'url' => 'market.coupon/edit', - ], - [ - 'name' => '删除优惠券', - 'url' => 'market.coupon/delete', - ], - [ - 'name' => '领取记录', - 'url' => 'market.coupon/receive', - ] - ] - ] - ] - ], - [ - 'name' => '小程序', - 'url' => 'wxapp', - 'subset' => [ - [ - 'name' => '小程序设置', - 'url' => 'wxapp/setting', - ], - [ - 'name' => '页面管理', - 'url' => 'wxapp.page', - 'subset' => [ - [ - 'name' => '页面设计', - 'url' => '', - 'subset' => [ - [ - 'name' => '页面列表', - 'url' => 'wxapp.page/index', - ], - [ - 'name' => '新增页面', - 'url' => 'wxapp.page/add', - ], - [ - 'name' => '编辑页面', - 'url' => 'wxapp.page/edit', - ], - [ - 'name' => '设为首页', - 'url' => 'wxapp.page/sethome', - ], - ] - ], - [ - 'name' => '分类页模板', - 'url' => 'wxapp.page/category', - ], - [ - 'name' => '页面链接', - 'url' => 'wxapp.page/links', - ], - ] - ], - [ - 'name' => '帮助中心', - 'url' => 'wxapp.help', - 'subset' => [ - [ - 'name' => '帮助列表', - 'url' => 'wxapp.help/index', - ], - [ - 'name' => '新增帮助', - 'url' => 'wxapp.help/add', - ], - [ - 'name' => '编辑帮助', - 'url' => 'wxapp.help/edit', - ], - [ - 'name' => '删除帮助', - 'url' => 'wxapp.help/delete', - ], - ] - ], - ] - ], - [ - 'name' => '应用中心', - 'url' => 'apps', - 'subset' => [ - [ - 'name' => '分销中心', - 'url' => 'apps.dealer', - 'subset' => [ - [ - 'name' => '入驻申请', - 'url' => 'apps.dealer.apply', - 'subset' => [ - [ - 'name' => '申请列表', - 'url' => 'apps.dealer.apply/index' - ], - [ - 'name' => '分销商审核', - 'url' => 'apps.dealer.apply/submit' - ] - ] - ], - [ - 'name' => '分销商用户', - 'url' => 'apps.dealer.user', - 'subset' => [ - [ - 'name' => '分销商列表', - 'url' => 'apps.dealer.user/index', - ], - [ - 'name' => '删除分销商', - 'url' => 'apps.dealer.user/delete' - ], - [ - 'name' => '分销商二维码', - 'url' => 'apps.dealer.user/qrcode' - ] - ] - ], - [ - 'name' => '分销订单', - 'url' => 'apps.dealer.order/index', - ], - [ - 'name' => '提现申请', - 'url' => 'apps.dealer.withdraw', - 'subset' => [ - [ - 'name' => '申请列表', - 'url' => 'apps.dealer.withdraw/index', - ], - [ - 'name' => '提现审核', - 'url' => 'apps.dealer.withdraw/submit' - ], - [ - 'name' => '确认打款', - 'url' => 'apps.dealer.withdraw/money' - ] - ] - ], - [ - 'name' => '分销设置', - 'url' => 'apps.dealer.setting/index', - ], - [ - 'name' => '分销海报', - 'url' => 'apps.dealer.setting/qrcode', - ], - ] - ], - ] - ], - [ - 'name' => '设置', - 'url' => 'setting', - 'subset' => [ - [ - 'name' => '商城设置', - 'url' => 'setting/store', - ], - [ - 'name' => '交易设置', - 'url' => 'setting/trade', - ], - [ - 'name' => '配送设置', - 'url' => 'setting.delivery', - 'subset' => [ - [ - 'name' => '运费模板列表', - 'url' => 'setting.delivery/index' - ], - [ - 'name' => '新增运费模板', - 'url' => 'setting.delivery/add' - ], - [ - 'name' => '编辑运费模板', - 'url' => 'setting.delivery/edit' - ], - [ - 'name' => '删除运费模板', - 'url' => 'setting.delivery/delete' - ], - ] - ], - [ - 'name' => '物流公司', - 'url' => 'setting.express', - 'subset' => [ - [ - 'name' => '物流公司列表', - 'url' => 'setting.express/index' - ], - [ - 'name' => '新增物流公司', - 'url' => 'setting.express/add' - ], - [ - 'name' => '编辑物流公司', - 'url' => 'setting.express/edit' - ], - [ - 'name' => '删除物流公司', - 'url' => 'setting.express/delete' - ], - ] - ], - [ - 'name' => '短信通知', - 'url' => 'setting/sms', - ], - [ - 'name' => '模板消息', - 'url' => 'setting/tplmsg', - ], - [ - 'name' => '上传设置', - 'url' => 'setting/storage', - ], - [ - 'name' => '其他', - 'url' => '', - 'subset' => [ - [ - 'name' => '清理缓存', - 'url' => 'setting.cache/clear', - ], - ] - ] - ] - ], - ]; - } - } \ No newline at end of file diff --git a/source/application/admin/model/store/User.php b/source/application/admin/model/store/User.php index 333af4d..1787795 100644 --- a/source/application/admin/model/store/User.php +++ b/source/application/admin/model/store/User.php @@ -2,6 +2,7 @@ namespace app\admin\model\store; +use app\common\exception\BaseException; use app\common\model\store\User as StoreUserModel; /** @@ -13,30 +14,55 @@ class User extends StoreUserModel { /** * 新增商家用户记录 - * @param $wxapp_id - * @param $data + * @param int $wxappId + * @param array $data * @return bool|false|int */ - public function add($wxapp_id, $data) + public function add($wxappId, $data) { return $this->save([ 'user_name' => $data['user_name'], 'password' => yoshop_hash($data['password']), - 'wxapp_id' => $wxapp_id, + 'is_super' => 1, + 'wxapp_id' => $wxappId, ]); } /** * 商家用户登录 - * @param $wxapp_id + * @param int $wxappId * @throws \think\Exception * @throws \think\exception\DbException */ - public function login($wxapp_id) + public function login($wxappId) { - // 验证用户名密码是否正确 - $user = self::detail(['wxapp_id' => $wxapp_id], ['wxapp']); + // 获取获取商城超级管理员用户信息 + $user = $this->getSuperStoreUser($wxappId); + if (empty($user)) { + throw new BaseException(['msg' => '超级管理员用户信息不存在']); + } $this->loginState($user); } + /** + * 获取获取商城超级管理员用户信息 + * @param $wxappId + * @return User|null + * @throws \think\exception\DbException + */ + private function getSuperStoreUser($wxappId) + { + return static::detail(['wxapp_id' => $wxappId, 'is_super' => 1], ['wxapp']); + } + + /** + * 删除小程序下的商家用户 + * @param $wxappId + * @return false|int + */ + public function setDelete($wxappId) + { + return $this->save(['is_delete' => 1], ['wxapp_id' => $wxappId]); + } + } diff --git a/source/application/api/behavior/order/PaySuccess.php b/source/application/api/behavior/order/PaySuccess.php index 02baa03..12c1588 100644 --- a/source/application/api/behavior/order/PaySuccess.php +++ b/source/application/api/behavior/order/PaySuccess.php @@ -79,7 +79,10 @@ class PaySuccess private function onCommonEvent() { // 发送消息通知 - (new MessageService)->payment($this->order, $this->orderType); + MessageService::send('order.payment', [ + 'order' => $this->order, + 'order_type' => $this->orderType, + ]); // 小票打印 (new PrinterService)->printTicket($this->order, OrderStatusEnum::ORDER_PAYMENT); } diff --git a/source/application/api/controller/sharing/Setting.php b/source/application/api/controller/sharing/Setting.php index a8f44a4..480c9ad 100644 --- a/source/application/api/controller/sharing/Setting.php +++ b/source/application/api/controller/sharing/Setting.php @@ -13,13 +13,14 @@ use app\api\model\sharing\Setting as SettingModel; class Setting extends Controller { /** - * 获取所有设置 + * 获取拼团设置 * @return array */ public function getAll() { - $basic = SettingModel::getItem('basic'); - return $this->renderSuccess(['setting' => compact('basic')]); + // 获取拼团设置 + $setting = SettingModel::getSetting(); + return $this->renderSuccess(compact('setting')); } } diff --git a/source/application/api/controller/user/dealer/Apply.php b/source/application/api/controller/user/dealer/Apply.php index 485acd2..737b22e 100644 --- a/source/application/api/controller/user/dealer/Apply.php +++ b/source/application/api/controller/user/dealer/Apply.php @@ -32,7 +32,6 @@ class Apply extends Controller * @param string $mobile * @return array * @throws \think\exception\DbException - * @throws \think\exception\PDOException */ public function submit($name = '', $mobile = '') { diff --git a/source/application/api/controller/user/dealer/Withdraw.php b/source/application/api/controller/user/dealer/Withdraw.php index 99e9011..64963c4 100644 --- a/source/application/api/controller/user/dealer/Withdraw.php +++ b/source/application/api/controller/user/dealer/Withdraw.php @@ -47,7 +47,7 @@ class Withdraw extends Controller $formData = json_decode(htmlspecialchars_decode($data), true); $model = new WithdrawModel; if ($model->submit($this->dealer, $formData)) { - return $this->renderSuccess([], '申请提现成功'); + return $this->renderSuccess([], '提现申请已提交成功,请等待审核'); } return $this->renderError($model->getError() ?: '提交失败'); } diff --git a/source/application/api/controller/wxapp/Formid.php b/source/application/api/controller/wxapp/Formid.php index ccbd629..79777d7 100644 --- a/source/application/api/controller/wxapp/Formid.php +++ b/source/application/api/controller/wxapp/Formid.php @@ -3,10 +3,9 @@ namespace app\api\controller\wxapp; use app\api\controller\Controller; -use app\api\model\wxapp\Formid as FormidModel; /** - * form_id 管理 + * form_id 管理 (已废弃) * Class Formid * @package app\api\controller\wxapp */ @@ -17,20 +16,10 @@ class Formid extends Controller * (因微信模板消息已下线,所以formId取消不再收集) * @param $formId * @return array - * @throws \app\common\exception\BaseException - * @throws \think\exception\DbException */ public function save($formId) { return $this->renderSuccess(); - -// if (!$user = $this->getUser(false)) { -// return $this->renderSuccess(); -// } -// if (FormidModel::add($user['user_id'], $formId)) { -// return $this->renderSuccess(); -// } -// return $this->renderError(); } } \ No newline at end of file diff --git a/source/application/api/controller/wxapp/Submsg.php b/source/application/api/controller/wxapp/Submsg.php new file mode 100644 index 0000000..20306ba --- /dev/null +++ b/source/application/api/controller/wxapp/Submsg.php @@ -0,0 +1,25 @@ +renderSuccess(compact('setting')); + } + +} \ No newline at end of file diff --git a/source/application/api/model/Setting.php b/source/application/api/model/Setting.php index 29034e1..8ed85a7 100644 --- a/source/application/api/model/Setting.php +++ b/source/application/api/model/Setting.php @@ -20,4 +20,18 @@ class Setting extends SettingModel return static::getItem('points')['points_name']; } + /** + * 获取微信订阅消息设置 + */ + public static function getSubmsg() + { + $data = []; + foreach (static::getItem('submsg') as $groupName => $group) { + foreach ($group as $itemName => $item) { + $data[$groupName][$itemName]['template_id'] = $item['template_id']; + } + } + return $data; + } + } diff --git a/source/application/api/model/sharing/Setting.php b/source/application/api/model/sharing/Setting.php index b862589..1b1bcce 100644 --- a/source/application/api/model/sharing/Setting.php +++ b/source/application/api/model/sharing/Setting.php @@ -2,14 +2,15 @@ namespace app\api\model\sharing; -use app\common\model\sharing\Setting as SettingModel; +use app\api\model\Setting as SettingModel; +use app\common\model\sharing\Setting as SharingSettingModel; /** * 拼团设置模型 * Class Setting * @package app\api\model\sharing */ -class Setting extends SettingModel +class Setting extends SharingSettingModel { /** * 隐藏字段 @@ -19,4 +20,19 @@ class Setting extends SettingModel 'update_time', ]; + public static function getSetting() + { + // 订阅消息 + $submsgList = []; + foreach (SettingModel::getItem('submsg')['sharing'] as $key => $item) { + $submsgList[$key] = $item['template_id']; + } + return [ + // 基础设置 + 'basic' => static::getItem('basic'), + // 订阅消息 + 'order_submsg' => $submsgList, + ]; + } + } \ No newline at end of file diff --git a/source/application/api/service/order/Checkout.php b/source/application/api/service/order/Checkout.php index d76c9fa..3bd5ae8 100644 --- a/source/application/api/service/order/Checkout.php +++ b/source/application/api/service/order/Checkout.php @@ -300,8 +300,6 @@ class Checkout { // 系统支持的配送方式 (后台设置) $deliveryType = SettingModel::getItem('store')['delivery_type']; - // 积分设置 - $pointsSetting = SettingModel::getItem('points'); return [ // 配送类型 'delivery' => $this->param['delivery'] > 0 ? $this->param['delivery'] : $deliveryType[0], @@ -326,15 +324,32 @@ class Checkout // 支付方式 'pay_type' => $this->param['pay_type'], // 系统设置 - 'setting' => [ - 'delivery' => $deliveryType, // 支持的配送方式 - 'points_name' => $pointsSetting['points_name'], // 积分名称 - 'points_describe' => $pointsSetting['describe'], // 积分说明 - ], + 'setting' => $this->getSetting(), // 记忆的自提联系方式 'last_extract' => UserService::getLastExtract($this->user['user_id']), - // todo: delete - 兼容处理 - 'deliverySetting' => $deliveryType, + ]; + } + + /** + * 获取订单页面中使用到的系统设置 + * @return array + */ + private function getSetting() + { + // 系统支持的配送方式 (后台设置) + $deliveryType = SettingModel::getItem('store')['delivery_type']; + // 积分设置 + $pointsSetting = SettingModel::getItem('points'); + // 订阅消息 + $orderSubMsgList = []; + foreach (SettingModel::getItem('submsg')['order'] as $item) { + !empty($item['template_id']) && $orderSubMsgList[] = $item['template_id']; + } + return [ + 'delivery' => $deliveryType, // 支持的配送方式 + 'points_name' => $pointsSetting['points_name'], // 积分名称 + 'points_describe' => $pointsSetting['describe'], // 积分说明 + 'order_submsg' => $orderSubMsgList, // 订阅消息 ]; } diff --git a/source/application/api/service/sharing/order/Checkout.php b/source/application/api/service/sharing/order/Checkout.php index e312b3f..6f93297 100644 --- a/source/application/api/service/sharing/order/Checkout.php +++ b/source/application/api/service/sharing/order/Checkout.php @@ -299,8 +299,6 @@ class Checkout { // 系统支持的配送方式 (后台设置) $deliveryType = SettingModel::getItem('store')['delivery_type']; - // 积分设置 - $pointsSetting = SettingModel::getItem('points'); return [ // 订单类型 'order_type' => $this->param['order_type'], @@ -327,11 +325,7 @@ class Checkout // 支付方式 'pay_type' => $this->param['pay_type'], // 系统设置 - 'setting' => [ - 'delivery' => $deliveryType, // 支持的配送方式 - 'points_name' => $pointsSetting['points_name'], // 积分名称 - 'points_describe' => $pointsSetting['describe'], // 积分说明 - ], + 'setting' => $this->getSetting(), // 记忆的自提联系方式 'last_extract' => UserService::getLastExtract($this->user['user_id']), // todo: 兼容处理 @@ -339,6 +333,29 @@ class Checkout ]; } + /** + * 获取订单页面中使用到的系统设置 + * @return array + */ + private function getSetting() + { + // 系统支持的配送方式 (后台设置) + $deliveryType = SettingModel::getItem('store')['delivery_type']; + // 积分设置 + $pointsSetting = SettingModel::getItem('points'); + // 订阅消息 + $orderSubMsgList = []; + foreach (SettingModel::getItem('submsg')['order'] as $item) { + !empty($item['template_id']) && $orderSubMsgList[] = $item['template_id']; + } + return [ + 'delivery' => $deliveryType, // 支持的配送方式 + 'points_name' => $pointsSetting['points_name'], // 积分名称 + 'points_describe' => $pointsSetting['describe'], // 积分说明 + 'order_submsg' => $orderSubMsgList, // 订阅消息 + ]; + } + /** * 当前用户可用的优惠券列表 * @param $orderTotalPrice diff --git a/source/application/common.php b/source/application/common.php index 26a8e61..15bec98 100644 --- a/source/application/common.php +++ b/source/application/common.php @@ -346,3 +346,17 @@ function filter_emoji($text) // 如需支持emoji表情, 需将mysql的编码改为utf8mb4 return preg_replace('/[\xf0-\xf7].{3}/', '', $text); } + +/** + * 根据指定长度截取字符串 + * @param $str + * @param int $length + * @return bool|string + */ +function str_substr($str, $length = 30) +{ + if (strlen($str) > $length) { + $str = mb_substr($str, 0, $length); + } + return $str; +} diff --git a/source/application/common/enum/Setting.php b/source/application/common/enum/Setting.php index 61da965..244f3a0 100644 --- a/source/application/common/enum/Setting.php +++ b/source/application/common/enum/Setting.php @@ -18,8 +18,8 @@ class Setting extends EnumBasics // 短信通知 const SMS = 'sms'; - // 模板消息 - const TPL_MSG = 'tplMsg'; + // // 模板消息 + // const TPL_MSG = 'tplMsg'; // 上传设置 const STORAGE = 'storage'; @@ -36,6 +36,9 @@ class Setting extends EnumBasics // 积分设置 const POINTS = 'points'; + // 订阅消息设置 + const SUBMSG = 'submsg'; + /** * 获取订单类型值 * @return array @@ -55,10 +58,10 @@ class Setting extends EnumBasics 'value' => self::SMS, 'describe' => '短信通知', ], - self::TPL_MSG => [ - 'value' => self::TPL_MSG, - 'describe' => '模板消息', - ], + // self::TPL_MSG => [ + // 'value' => self::TPL_MSG, + // 'describe' => '模板消息', + // ], self::STORAGE => [ 'value' => self::STORAGE, 'describe' => '上传设置', @@ -79,6 +82,10 @@ class Setting extends EnumBasics 'value' => self::POINTS, 'describe' => '积分设置', ], + self::SUBMSG => [ + 'value' => self::SUBMSG, + 'describe' => '小程序订阅消息', + ], ]; } diff --git a/source/application/common/enum/dealer/ApplyStatus.php b/source/application/common/enum/dealer/ApplyStatus.php new file mode 100644 index 0000000..34219f1 --- /dev/null +++ b/source/application/common/enum/dealer/ApplyStatus.php @@ -0,0 +1,45 @@ + [ + 'name' => '待审核', + 'value' => self::AUDIT_WAIT, + ], + self::AUDIT_PASS => [ + 'name' => '审核通过', + 'value' => self::AUDIT_PASS, + ], + self::AUDIT_REJECT => [ + 'name' => '驳回', + 'value' => self::AUDIT_REJECT, + ], + ]; + } + +} \ No newline at end of file diff --git a/source/application/common/enum/dealer/withdraw/ApplyStatus.php b/source/application/common/enum/dealer/withdraw/ApplyStatus.php new file mode 100644 index 0000000..3ee69b5 --- /dev/null +++ b/source/application/common/enum/dealer/withdraw/ApplyStatus.php @@ -0,0 +1,52 @@ + [ + 'name' => '待审核', + 'value' => self::AUDIT_WAIT, + ], + self::AUDIT_PASS => [ + 'name' => '审核通过', + 'value' => self::AUDIT_PASS, + ], + self::AUDIT_REJECT => [ + 'name' => '驳回', + 'value' => self::AUDIT_REJECT, + ], + self::AUDIT_PAID => [ + 'name' => '已打款', + 'value' => self::AUDIT_PAID, + ], + ]; + } + +} \ No newline at end of file diff --git a/source/application/common/enum/sharing/ActiveStatus.php b/source/application/common/enum/sharing/ActiveStatus.php new file mode 100644 index 0000000..49fb03f --- /dev/null +++ b/source/application/common/enum/sharing/ActiveStatus.php @@ -0,0 +1,51 @@ + [ + 'name' => '未拼单', + 'value' => self::ACTIVE_STATE_NORMAL, + ], + self::ACTIVE_STATE_BEGIN => [ + 'name' => '拼单中', + 'value' => self::ACTIVE_STATE_BEGIN, + ], + self::ACTIVE_STATE_SUCCESS => [ + 'name' => '拼单成功', + 'value' => self::ACTIVE_STATE_SUCCESS, + ], + self::ACTIVE_STATE_FAIL => [ + 'name' => '拼单失败', + 'value' => self::ACTIVE_STATE_FAIL, + ], + ]; + } +} \ No newline at end of file diff --git a/source/application/common/library/helper.php b/source/application/common/library/helper.php index 89901ac..40136df 100644 --- a/source/application/common/library/helper.php +++ b/source/application/common/library/helper.php @@ -25,7 +25,7 @@ class helper } /** - * 获取数组中指定的列 + * 获取数组中指定的列 [支持多列] * @param $source * @param $columns * @return array @@ -83,6 +83,21 @@ class helper return $sum / 100; } + /** + * 在二维数组中查找指定值 + * @param array $array 二维数组 + * @param string $searchIdx 查找的索引 + * @param string $searchVal 查找的值 + * @return bool + */ + public static function arraySearch($array, $searchIdx, $searchVal) + { + foreach ($array as $item) { + if ($item[$searchIdx] == $searchVal) return $item; + } + return false; + } + public static function setDataAttribute(&$source, $defaultData, $isArray = false) { if (!$isArray) $dataSource = [&$source]; else $dataSource = &$source; diff --git a/source/application/common/library/wechat/WxBase.php b/source/application/common/library/wechat/WxBase.php index 7750d6a..8fa3bc8 100644 --- a/source/application/common/library/wechat/WxBase.php +++ b/source/application/common/library/wechat/WxBase.php @@ -123,6 +123,29 @@ class WxBase return $result; } + /** + * 模拟POST请求 [第二种方式, 用于兼容微信api] + * @param $url + * @param array $data + * @return mixed + */ + protected function post2($url, $data = []) + { + $header = [ + 'Content-Type: application/x-www-form-urlencoded' + ]; + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_HTTPHEADER, $header); + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);//这个是重点。 + $result = curl_exec($ch); + curl_close($ch); + return $result; + } + /** * 数组转json * @param $data diff --git a/source/application/common/library/wechat/WxSubMsg.php b/source/application/common/library/wechat/WxSubMsg.php new file mode 100644 index 0000000..a9f9de9 --- /dev/null +++ b/source/application/common/library/wechat/WxSubMsg.php @@ -0,0 +1,110 @@ +getAccessToken(); + $url = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token={$accessToken}"; + // 构建请求 + $params = [ + 'touser' => $param['touser'], + 'template_id' => $param['template_id'], + 'page' => $param['page'], + 'data' => $param['data'], + ]; + $result = $this->post($url, $this->jsonEncode($params)); + // 记录日志 + $describe = '发送订阅消息'; + $this->doLogs(compact('describe', 'url', 'params', 'result')); + // 返回结果 + $response = $this->jsonDecode($result); + if (!isset($response['errcode'])) { + $this->error = 'not found errcode'; + return false; + } + if ($response['errcode'] != 0) { + $this->error = $response['errmsg']; + return false; + } + return true; + } + + /** + * 获取当前帐号下的模板列表 + * @throws \app\common\exception\BaseException + */ + public function getTemplateList() + { + // 微信接口url + $accessToken = $this->getAccessToken(); + $url = "https://api.weixin.qq.com/wxaapi/newtmpl/gettemplate?access_token={$accessToken}"; + // 执行post请求 + $result = $this->get($url); + // 记录日志 + $this->doLogs(['describe' => '获取当前帐号下的订阅消息模板列表', 'url' => $url, 'result' => $result]); + // 处理返回结果 + $response = $this->jsonDecode($result); + if (!isset($response['errcode'])) { + $this->error = 'not found errcode'; + return false; + } + if ($response['errcode'] != 0) { + $this->error = $response['errmsg']; + return false; + } + return $response; + } + + /** + * 添加订阅消息模板 + * [addTemplates 组合模板并添加至帐号下的个人模板库](订阅消息) + * @param int $tid 模板标题id + * @param array $kidList 模板关键词列表 + * @param string $sceneDesc 服务场景描述 + * @return bool + * @throws \app\common\exception\BaseException + */ + public function addTemplate($tid, $kidList, $sceneDesc) + { + // 微信接口url + $accessToken = $this->getAccessToken(); + $url = "https://api.weixin.qq.com/wxaapi/newtmpl/addtemplate?access_token={$accessToken}"; + // 构建请求 + $params = [ + 'tid' => $tid, + 'kidList' => $kidList, + 'sceneDesc' => $sceneDesc, + ]; + // 执行post请求 + $result = $this->post2($url, $params); + // 记录日志 + $this->doLogs(['describe' => '添加订阅消息模板', 'url' => $url, 'params' => $params, 'result' => $result]); + // 处理返回结果 + $response = $this->jsonDecode($result); + if (!isset($response['errcode'])) { + $this->error = 'not found errcode'; + return false; + } + if ($response['errcode'] != 0) { + $this->error = $response['errmsg']; + return false; + } + return $response; + } + +} \ No newline at end of file diff --git a/source/application/common/library/wechat/WxTplMsg.php b/source/application/common/library/wechat/WxTplMsg.php index c1f2a5c..9841bac 100644 --- a/source/application/common/library/wechat/WxTplMsg.php +++ b/source/application/common/library/wechat/WxTplMsg.php @@ -3,7 +3,7 @@ namespace app\common\library\wechat; /** - * 微信模板消息 + * 微信模板消息 (废弃) * Class WxTplMsg * @package app\common\library\wechat */ diff --git a/source/application/common/model/Setting.php b/source/application/common/model/Setting.php index 7d02584..7118b44 100644 --- a/source/application/common/model/Setting.php +++ b/source/application/common/model/Setting.php @@ -3,6 +3,7 @@ namespace app\common\model; use think\Cache; +use app\common\enum\Setting as SettingEnum; use app\common\enum\DeliveryType as DeliveryTypeEnum; /** @@ -98,6 +99,7 @@ class Setting extends BaseModel public function defaultData($storeName = null) { return [ + // 商城设置 'store' => [ 'key' => 'store', 'describe' => '商城设置', @@ -113,6 +115,7 @@ class Setting extends BaseModel ] ], ], + // 交易设置 'trade' => [ 'key' => 'trade', 'describe' => '交易设置', @@ -125,6 +128,7 @@ class Setting extends BaseModel 'freight_rule' => '10', ] ], + // 上传设置 'storage' => [ 'key' => 'storage', 'describe' => '上传设置', @@ -154,6 +158,7 @@ class Setting extends BaseModel ] ], ], + // 短信通知 'sms' => [ 'key' => 'sms', 'describe' => '短信通知', @@ -173,24 +178,26 @@ class Setting extends BaseModel ], ], ], - 'tplMsg' => [ - 'key' => 'tplMsg', - 'describe' => '模板消息', - 'values' => [ - 'payment' => [ - 'is_enable' => '0', - 'template_id' => '', - ], - 'delivery' => [ - 'is_enable' => '0', - 'template_id' => '', - ], - 'refund' => [ - 'is_enable' => '0', - 'template_id' => '', - ], - ], - ], + // 模板消息 + // 'tplMsg' => [ + // 'key' => 'tplMsg', + // 'describe' => '模板消息', + // 'values' => [ + // 'payment' => [ + // 'is_enable' => '0', + // 'template_id' => '', + // ], + // 'delivery' => [ + // 'is_enable' => '0', + // 'template_id' => '', + // ], + // 'refund' => [ + // 'is_enable' => '0', + // 'template_id' => '', + // ], + // ], + // ], + // 小票打印机设置 'printer' => [ 'key' => 'printer', 'describe' => '小票打印机设置', @@ -200,6 +207,7 @@ class Setting extends BaseModel 'order_status' => [], // 订单类型 10下单打印 20付款打印 30确认收货打印 ], ], + // 满额包邮设置 'full_free' => [ 'key' => 'full_free', 'describe' => '满额包邮设置', @@ -214,6 +222,7 @@ class Setting extends BaseModel 'notin_goods' => [], // 不参与包邮的商品 (商品id集) ], ], + // 用户充值设置 'recharge' => [ 'key' => 'recharge', 'describe' => '用户充值设置', @@ -227,9 +236,10 @@ class Setting extends BaseModel "4. 若有其它疑问,可拨打客服电话400-000-1234", // 充值说明 ], ], - 'points' => [ - 'key' => 'points', - 'describe' => '积分设置', + // 积分设置 + SettingEnum::POINTS => [ + 'key' => SettingEnum::POINTS, + 'describe' => SettingEnum::data()[SettingEnum::POINTS]['describe'], 'values' => [ 'points_name' => '积分', // 积分名称自定义 'is_shopping_gift' => '0', // 是否开启购物送积分 @@ -247,6 +257,64 @@ class Setting extends BaseModel "d) 买家在完成该笔交易(订单状态为“已签收”)后才能得到此笔交易的相应积分,如购买商品参加店铺其他优惠,则优惠的金额部分不享受积分获取;", ], ], + // 订阅消息设置 + SettingEnum::SUBMSG => [ + 'key' => SettingEnum::SUBMSG, + 'describe' => SettingEnum::data()[SettingEnum::SUBMSG]['describe'], + 'values' => [ + // 订单消息 + 'order' => [ + // 支付成功通知 + 'payment' => [ + 'template_id' => '', + 'keywords' => ['character_string1', 'time2', 'amount4', 'thing3'], + 'title' => '新订单提醒', + ], + // 订单发货通知 + 'delivery' => [ + 'template_id' => '', + 'keywords' => ['character_string1', 'thing2', 'name12', 'thing11', 'thing17'], + 'title' => '订单发货通知', + ], + // 售后状态通知 + 'refund' => [ + 'template_id' => '', + 'keywords' => ['phrase1', 'thing6', 'character_string2', 'date3', 'thing4'], + 'title' => '售后状态通知', + ], + ], + // 拼团消息 + 'sharing' => [ + // 拼团进度通知 + 'active_status' => [ + 'template_id' => '', + 'keywords' => ['thing1', 'amount5', 'number7', 'thing3', 'thing6'], + 'title' => '拼团进度通知', + ], + ], + // 分销商消息 + 'dealer' => [ + // 分销商入驻审核通知 + 'apply' => [ + 'template_id' => '', + 'keywords' => ['date1', 'phrase2', 'date3', 'thing4'], + 'title' => '代理商入驻审核通知', + ], + // 提现成功通知 + 'withdraw_01' => [ + 'template_id' => '', + 'keywords' => ['amount1', 'thing3', 'thing4'], + 'title' => '提现成功通知', + ], + // 提现失败通知 + 'withdraw_02' => [ + 'template_id' => '', + 'keywords' => ['amount1', 'time3', 'thing4'], + 'title' => '提现失败通知', + ], + ], + ], + ], ]; } diff --git a/source/application/common/model/Wxapp.php b/source/application/common/model/Wxapp.php index 800f85e..e3d59e9 100644 --- a/source/application/common/model/Wxapp.php +++ b/source/application/common/model/Wxapp.php @@ -25,13 +25,13 @@ class Wxapp extends BaseModel /** * 获取小程序信息 - * @param null $wxapp_id + * @param int|null $wxappId * @return static|null * @throws \think\exception\DbException */ - public static function detail($wxapp_id = null) + public static function detail($wxappId = null) { - return static::get($wxapp_id ?: []); + return static::get($wxappId ?: []); } /** diff --git a/source/application/common/model/bargain/Setting.php b/source/application/common/model/bargain/Setting.php index 1b69c2e..7111a76 100644 --- a/source/application/common/model/bargain/Setting.php +++ b/source/application/common/model/bargain/Setting.php @@ -93,8 +93,6 @@ class Setting extends BaseModel "每次砍价金额随机,可砍出最高商品日常价内的随机金额,参与好友越多越容易成功。\n\n" . "以最终砍价后的优惠价格购买该商品,且用户须在活动时间结束之前进行支付购买,否则砍价商品价格将过期失效。\n\n" . "商品库存有限,以前台展示的库存数量为准,先到先得。", - // 模板消息 - 'template_msg' => [] ] ] ]; diff --git a/source/application/common/model/dealer/Apply.php b/source/application/common/model/dealer/Apply.php index f8e90c0..33abba9 100644 --- a/source/application/common/model/dealer/Apply.php +++ b/source/application/common/model/dealer/Apply.php @@ -13,16 +13,6 @@ class Apply extends BaseModel { protected $name = 'dealer_apply'; - /** - * 申请状态 - * @var array - */ - public $applyStatus = [ - 10 => '待审核', - 20 => '审核通过', - 30 => '驳回', - ]; - /** * 获取器:申请时间 * @param $value @@ -44,7 +34,7 @@ class Apply extends BaseModel } /** - * 关联推荐人表 + * 关联用户表 * @return \think\model\relation\BelongsTo */ public function referee() @@ -53,6 +43,16 @@ class Apply extends BaseModel ->field(['user_id', 'nickName']); } + /** + * 关联会员记录表 + * @return \think\model\relation\BelongsTo + */ + public function user() + { + $module = self::getCalledModule() ?: 'common'; + return $this->belongsTo("app\\{$module}\\model\\User"); + } + /** * 销商申请记录详情 * @param $where diff --git a/source/application/common/model/dealer/Setting.php b/source/application/common/model/dealer/Setting.php index 40c0e40..b030971 100644 --- a/source/application/common/model/dealer/Setting.php +++ b/source/application/common/model/dealer/Setting.php @@ -348,14 +348,6 @@ class Setting extends BaseModel 'withdraw_apply' => self::$base_url . 'assets/api/dealer-bg.png', ], ], - 'template_msg' => [ - 'key' => 'template_msg', - 'describe' => '模板消息', - 'values' => [ - 'apply_tpl' => '', // 分销商审核通知 - 'withdraw_tpl' => '', // 提现状态通知 - ] - ], 'qrcode' => [ 'key' => 'template_msg', 'describe' => '分销海报', diff --git a/source/application/common/model/dealer/Withdraw.php b/source/application/common/model/dealer/Withdraw.php index 9a80793..be53ab4 100644 --- a/source/application/common/model/dealer/Withdraw.php +++ b/source/application/common/model/dealer/Withdraw.php @@ -13,27 +13,6 @@ class Withdraw extends BaseModel { protected $name = 'dealer_withdraw'; - /** - * 打款方式 - * @var array - */ - public $payType = [ - 10 => '微信', - 20 => '支付宝', - 30 => '银行卡', - ]; - - /** - * 申请状态 - * @var array - */ - public $applyStatus = [ - 10 => '待审核', - 20 => '审核通过', - 30 => '驳回', - 40 => '已打款', - ]; - /** * 关联分销商用户表 * @return \think\model\relation\BelongsTo diff --git a/source/application/common/model/sharing/Active.php b/source/application/common/model/sharing/Active.php index 64347d6..87df623 100644 --- a/source/application/common/model/sharing/Active.php +++ b/source/application/common/model/sharing/Active.php @@ -5,6 +5,7 @@ namespace app\common\model\sharing; use think\Hook; use app\common\model\BaseModel; use app\common\service\Message as MessageService; +use app\common\enum\sharing\ActiveStatus as ActiveStatusEnum; /** * 拼团拼单模型 @@ -34,13 +35,7 @@ class Active extends BaseModel */ public function getStatusAttr($value) { - $state = [ - 0 => '未拼单', - 10 => '拼单中', - 20 => '拼单成功', - 30 => '拼单失败', - ]; - return ['text' => $state[$value], 'value' => $value]; + return ['text' => ActiveStatusEnum::data()[$value]['name'], 'value' => $value]; } /** @@ -157,13 +152,12 @@ class Active extends BaseModel /** * 更新拼单记录 - * @param $user_id - * @param $order_id + * @param $userId + * @param $orderId * @return bool - * @throws \app\common\exception\BaseException * @throws \think\exception\DbException */ - public function onUpdate($user_id, $order_id) + public function onUpdate($userId, $orderId) { // 验证当前拼单是否允许加入新成员 if (!$this->checkAllowJoin()) { @@ -172,8 +166,8 @@ class Active extends BaseModel // 新增拼单成员记录 ActiveUsers::add([ 'active_id' => $this['active_id'], - 'order_id' => $order_id, - 'user_id' => $user_id, + 'order_id' => $orderId, + 'user_id' => $userId, 'is_creator' => 0, 'wxapp_id' => $this['wxapp_id'] ]); @@ -185,10 +179,13 @@ class Active extends BaseModel 'actual_people' => $actual_people, 'status' => $status ]); - // 拼单成功, 发送模板消息 + // 拼单成功, 发送订阅消息 if ($status == 20) { $model = static::detail($this['active_id']); - (new MessageService)->sharingActive($model, '拼团成功'); + MessageService::send('sharing.active_status', [ + 'active' => $model, + 'status' => ActiveStatusEnum::ACTIVE_STATE_SUCCESS, + ]); } return true; } diff --git a/source/application/common/model/sharing/Setting.php b/source/application/common/model/sharing/Setting.php index be1ddc4..dce6ac2 100644 --- a/source/application/common/model/sharing/Setting.php +++ b/source/application/common/model/sharing/Setting.php @@ -95,8 +95,6 @@ class Setting extends BaseModel 'rule_brief' => '好友拼单 · 人满发货 · 人不满退款', // 拼团规则 详述 'rule_detail' => "开团:选择商品,点击“发起拼单”按钮,付款完成后即开团成功,就可以邀请小伙伴一起拼团啦;\n\n参团:进入朋友分享的页面,点击“立即参团”按钮,付款完成后参团成功,在有效时间内凑齐人数即成团,就可以等待收货喽;\n\n成团:在开团或参团成功后,点击“立即分享”将页面分享给好友,在有效时间内凑齐人数即成团,成团后商家开始发货;\n\n组团失败:在有效时间内未凑齐人数,即组团失败,组团失败后订单所付款将原路退回到支付账户。", - // 拼单状态模板消息id - 'tpl_msg_id' => '', ] ] ]; diff --git a/source/application/common/service/Message.php b/source/application/common/service/Message.php index c2a2508..c163d2e 100644 --- a/source/application/common/service/Message.php +++ b/source/application/common/service/Message.php @@ -2,351 +2,47 @@ namespace app\common\service; -//use app\common\model\User as UserModel; -use app\common\model\Wxapp as WxappModel; -use app\common\model\Setting as SettingModel; -//use app\common\model\dealer\Setting as DealerSettingModel; -//use app\common\model\sharing\Setting as SharingSettingModel; -//use app\common\service\wxapp\FormId as FormIdService; -use app\common\enum\OrderType as OrderTypeEnum; -use app\common\library\wechat\WxTplMsg; -use app\common\library\sms\Driver as SmsDriver; - /** * 消息通知服务 * Class Message * @package app\common\service */ -class Message +class Message extends Basics { /** - * 订单支付成功后通知 - * @param \think\Model $order - * @param int $orderType 订单类型 (10商城订单 20拼团订单) - * @return bool -// * @throws \app\common\exception\BaseException - * @throws \think\Exception -// * @throws \think\exception\DbException + * 场景列表 + * [场景名称] => [场景类] + * @var array */ - public function payment($order, $orderType = OrderTypeEnum::MASTER) - { - // // 1. 微信模板消息 - // $template = SettingModel::getItem('tplMsg', $order['wxapp_id'])['payment']; - // if (!$template['is_enable'] || empty($template['template_id'])) { - // return false; - // } - // // 获取可用的formid - // if (!$formId = FormIdService::getAvailableFormId($order['user_id'])) { - // return false; - // } - // // 页面链接 - // $urls = [ - // OrderTypeEnum::MASTER => 'pages/order/detail', - // OrderTypeEnum::SHARING => 'pages/sharing/order/detail/detail', - // ]; - // // 发送模板消息 - // $status = $this->sendTemplateMessage($order['wxapp_id'], [ - // 'touser' => $order['user']['open_id'], - // 'template_id' => $template['template_id'], - // 'page' => $urls[$orderType] . '?order_id=' . $order['order_id'], - // 'form_id' => $formId['form_id'], - // 'data' => [ - // // 订单编号 - // 'keyword1' => $order['order_no'], - // // 支付时间 - // 'keyword2' => date('Y-m-d H:i:s', $order['pay_time']), - // // 订单金额 - // 'keyword3' => $order['pay_price'], - // // 商品名称 - // 'keyword4' => $this->formatGoodsName($order['goods']), - // ] - // ]); - // // 标记formid已使用 - // $status === true && FormIdService::setIsUsed($formId['id']); + private static $sceneList = [ + // 订单支付成功 + 'order.payment' => 'app\common\service\message\order\Payment', + // 订单发货 + 'order.delivery' => 'app\common\service\message\order\Delivery', + // 订单退款 + 'order.refund' => 'app\common\service\message\order\Refund', - // 2. 商家短信通知 - $smsConfig = SettingModel::getItem('sms', $order['wxapp_id']); - $SmsDriver = new SmsDriver($smsConfig); - return $SmsDriver->sendSms('order_pay', ['order_no' => $order['order_no']]); - } + // 拼团进度通知 + 'sharing.active_status' => 'app\common\service\message\sharing\ActiveStatus', + + // 分销商入驻通知 + 'dealer.apply' => 'app\common\service\message\dealer\Apply', + // 分销商提现通知 + 'dealer.withdraw' => 'app\common\service\message\dealer\Withdraw', + ]; /** - * 后台发货通知 - * @param \think\Model $order - * @param int $orderType 订单类型 (10商城订单 20拼团订单) + * 发送消息通知 + * @param string $sceneName 场景名称 + * @param array $param 参数 * @return bool -// * @throws \app\common\exception\BaseException -// * @throws \think\Exception -// * @throws \think\exception\DbException */ - public function delivery($order, $orderType = OrderTypeEnum::MASTER) + public static function send($sceneName, $param) { - return true; -// // 微信模板消息 -// $template = SettingModel::getItem('tplMsg', $order['wxapp_id'])['delivery']; -// if (!$template['is_enable'] || empty($template['template_id'])) { -// return false; -// } -// // 获取可用的formid -// if (!$formId = FormIdService::getAvailableFormId($order['user_id'])) { -// return false; -// } -// // 页面链接 -// $urls = [ -// OrderTypeEnum::MASTER => 'pages/order/detail', -// OrderTypeEnum::SHARING => 'pages/sharing/order/detail/detail', -// ]; -// // 发送模板消息 -// $status = $this->sendTemplateMessage($order['wxapp_id'], [ -// 'touser' => $order['user']['open_id'], -// 'template_id' => $template['template_id'], -// 'page' => $urls[$orderType] . '?order_id=' . $order['order_id'], -// 'form_id' => $formId['form_id'], -// 'data' => [ -// // 订单编号 -// 'keyword1' => $order['order_no'], -// // 商品信息 -// 'keyword2' => $this->formatGoodsName($order['goods']), -// // 收货人 -// 'keyword3' => $order['address']['name'], -// // 收货地址 -// 'keyword4' => implode('', $order['address']['region']) . $order['address']['detail'], -// // 物流公司 -// 'keyword5' => $order['express']['express_name'], -// // 物流单号 -// 'keyword6' => $order['express_no'], -// ] -// ]); -// // 标记formid已使用 -// $status === true && FormIdService::setIsUsed($formId['id']); -// return $status; - } - - /** - * 后台售后单状态通知 - * @param \think\Model $refund - * @param $order_no - * @param int $orderType 订单类型 (10商城订单 20拼团订单) - * @return bool -// * @throws \app\common\exception\BaseException -// * @throws \think\Exception -// * @throws \think\exception\DbException - */ - public function refund($refund, $order_no, $orderType = OrderTypeEnum::MASTER) - { - return true; -// // 微信模板消息 -// $template = SettingModel::getItem('tplMsg', $refund['wxapp_id'])['refund']; -// if (!$template['is_enable'] || empty($template['template_id'])) { -// return false; -// } -// // 获取可用的formid -// if (!$formId = FormIdService::getAvailableFormId($refund['user_id'])) { -// return false; -// } -// // 页面链接 -// $urls = [ -// OrderTypeEnum::MASTER => 'pages/order/refund/index', -// OrderTypeEnum::SHARING => 'pages/sharing/order/refund/index', -// ]; -// // 发送模板消息 -// $status = $this->sendTemplateMessage($refund['wxapp_id'], [ -// 'touser' => $refund['user']['open_id'], -// 'template_id' => $template['template_id'], -// 'page' => $urls[$orderType], -// 'form_id' => $formId['form_id'], -// 'data' => [ -// // 售后类型 -// 'keyword1' => $refund['type']['text'], -// // 状态 -// 'keyword2' => $refund['status']['text'], -// // 订单号 -// 'keyword3' => $order_no, -// // 商品名称 -// 'keyword4' => $refund['order_goods']['goods_name'], -// // 申请时间 -// 'keyword5' => $refund['create_time'], -// // 申请原因 -// 'keyword6' => $refund['apply_desc'], -// ] -// ]); -// // 标记formid已使用 -// FormIdService::setIsUsed($formId['id']); -// return $status; - } - - /** - * 拼团拼单状态通知 - * @param \app\common\model\sharing\Active $active - * @param string $status_text - * @return bool -// * @throws \app\common\exception\BaseException -// * @throws \think\exception\DbException - */ - public function sharingActive($active, $status_text) - { - return true; -// // 微信模板消息 -// $config = SharingSettingModel::getItem('basic', $active['wxapp_id']); -// if (empty($config['tpl_msg_id'])) { -// return false; -// } -// foreach ($active['users'] as $item) { -// // 获取可用的formid -// if (!$formId = FormIdService::getAvailableFormId($item['user']['user_id'])) { -// continue; -// } -// // 发送模板消息 -// $this->sendTemplateMessage($active['wxapp_id'], [ -// 'touser' => $item['user']['open_id'], -// 'template_id' => $config['tpl_msg_id'], -// 'page' => 'pages/sharing/active/index?active_id=' . $active['active_id'], -// 'form_id' => $formId['form_id'], -// 'data' => [ -// // 订单编号 -// 'keyword1' => $item['sharing_order']['order_no'], -// // 商品名称 -// 'keyword2' => $active['goods']['goods_name'], -// // 拼团价格 -// 'keyword3' => $item['sharing_order']['pay_price'], -// // 拼团人数 -// 'keyword4' => $active['people'], -// // 拼团时间 -// 'keyword5' => $item['create_time'], -// // 拼团结果 -// 'keyword6' => $status_text, -// ] -// ]); -// // 标记formid已使用 -// FormIdService::setIsUsed($formId['id']); -// } -// return true; - } - - /** - * 分销商提现审核通知 - * @param \app\common\model\dealer\Withdraw $withdraw - * @return bool -// * @throws \app\common\exception\BaseException -// * @throws \think\exception\DbException - */ - public function withdraw($withdraw) - { - return true; -// // 模板消息id -// $template = DealerSettingModel::getItem('template_msg', $withdraw['wxapp_id']); -// if (empty($template['withdraw_tpl'])) { -// return false; -// } -// // 获取可用的formid -// if (!$formId = FormIdService::getAvailableFormId($withdraw['user_id'])) { -// return false; -// } -// // 获取用户信息 -// $user = UserModel::detail($withdraw['user_id']); -// // 发送模板消息 -// $remark = '无'; -// if ($withdraw['apply_status'] == 30) { -// $remark = $withdraw['reject_reason']; -// } -// $status = $this->sendTemplateMessage($withdraw['wxapp_id'], [ -// 'touser' => $user['open_id'], -// 'template_id' => $template['withdraw_tpl'], -// 'page' => 'pages/dealer/withdraw/list/list', -// 'form_id' => $formId['form_id'], -// 'data' => [ -// // 提现时间 -// 'keyword1' => $withdraw['create_time'], -// // 提现方式 -// 'keyword2' => $withdraw['pay_type']['text'], -// // 提现金额 -// 'keyword3' => $withdraw['money'], -// // 提现状态 -// 'keyword4' => $withdraw->applyStatus[$withdraw['apply_status']], -// // 备注 -// 'keyword5' => $remark, -// ] -// ]); -// // 标记formid已使用 -// FormIdService::setIsUsed($formId['id']); -// return $status; - } - - /** - * 分销商入驻审核通知 - * @param \app\common\model\dealer\Apply $dealer - * @return bool -// * @throws \app\common\exception\BaseException -// * @throws \think\exception\DbException - */ - public function dealer($dealer) - { - return true; -// // 模板消息id -// $template = DealerSettingModel::getItem('template_msg', $dealer['wxapp_id']); -// if (empty($template['apply_tpl'])) { -// return false; -// } -// // 获取可用的formid -// if (!$formId = FormIdService::getAvailableFormId($dealer['user_id'])) { -// return false; -// } -// // 获取用户信息 -// $user = UserModel::detail($dealer['user_id']); -// // 发送模板消息 -// $remark = '分销商入驻审核通知'; -// if ($dealer['apply_status'] == 30) { -// $remark .= "\n\n驳回原因:" . $dealer['reject_reason']; -// } -// $status = $this->sendTemplateMessage($dealer['wxapp_id'], [ -// 'touser' => $user['open_id'], -// 'template_id' => $template['apply_tpl'], -// 'page' => 'pages/dealer/index/index', -// 'form_id' => $formId['form_id'], -// 'data' => [ -// // 申请时间 -// 'keyword1' => $dealer['apply_time'], -// // 审核状态 -// 'keyword2' => $dealer->applyStatus[$dealer['apply_status']], -// // 审核时间 -// 'keyword3' => $dealer['audit_time'], -// // 备注信息 -// 'keyword4' => $remark, -// ] -// ]); -// // 标记formid已使用 -// FormIdService::setIsUsed($formId['id']); -// return $status; - } - - /** - * 发送模板消息 - * @param $wxappId - * @param $params - * @return bool - * @throws \app\common\exception\BaseException - * @throws \think\exception\DbException - */ - private function sendTemplateMessage($wxappId, $params) - { - // 微信模板消息 - $wxConfig = WxappModel::getWxappCache($wxappId); - $WxTplMsg = new WxTplMsg($wxConfig['app_id'], $wxConfig['app_secret']); - return $WxTplMsg->sendTemplateMessage($params); - } - - /** - * 格式化商品名称 - * @param $goodsData - * @return string - */ - private function formatGoodsName($goodsData) - { - $str = ''; - foreach ($goodsData as $goods) { - $str .= $goods['goods_name'] . ' '; - } - return $str; + if (!isset(self::$sceneList[$sceneName])) + return false; + $className = self::$sceneList[$sceneName]; + return class_exists($className) ? (new $className)->send($param) : false; } } \ No newline at end of file diff --git a/source/application/common/service/message/Basics.php b/source/application/common/service/message/Basics.php new file mode 100644 index 0000000..e53c65d --- /dev/null +++ b/source/application/common/service/message/Basics.php @@ -0,0 +1,71 @@ +sendSms($msgType, $templateParams); + } + + /** + * 发送微信订阅消息 + * @param $wxappId + * @param $params + * @return mixed + * @throws \app\common\exception\BaseException + * @throws \think\Exception + * @throws \think\exception\DbException + */ + protected function sendWxSubMsg($wxappId, $params) + { + // 获取小程序配置 + $wxConfig = WxappModel::getWxappCache($wxappId); + // 请求微信api执行发送 + $WxSubMsg = new WxSubMsg($wxConfig['app_id'], $wxConfig['app_secret']); + return $WxSubMsg->sendTemplateMessage($params); + } + + /** + * 字符串截取前20字符 + * [用于兼容thing数据类型] + * @param $content + * @param int $length + * @return bool|string + */ + protected function getSubstr($content, $length = 20) + { + return str_substr($content, $length); + } + +} \ No newline at end of file diff --git a/source/application/common/service/message/dealer/Apply.php b/source/application/common/service/message/dealer/Apply.php new file mode 100644 index 0000000..e32a9bd --- /dev/null +++ b/source/application/common/service/message/dealer/Apply.php @@ -0,0 +1,90 @@ + [], // 申请记录 + 'user' => [], // 用户信息 + ]; + + /** + * 发送消息通知 + * @param array $param + * @return mixed|void + * @throws \think\Exception + */ + public function send($param) + { + // 记录参数 + $this->param = $param; + // 微信订阅消息通知用户 + $this->onSendWxSubMsg(); + } + + /** + * 微信订阅消息通知用户 + * @return bool|mixed + * @throws \app\common\exception\BaseException + * @throws \think\Exception + * @throws \think\exception\DbException + */ + private function onSendWxSubMsg() + { + $applyInfo = $this->param['apply']; + $userInfo = $this->param['user']; + $wxappId = $applyInfo['wxapp_id']; + + // 获取订阅消息配置 + $template = SettingModel::getItem('submsg', $wxappId)['dealer']['apply']; + if (empty($template['template_id'])) { + return false; + } + + // 发送订阅消息 + return $this->sendWxSubMsg($wxappId, [ + 'touser' => $userInfo['open_id'], + 'template_id' => $template['template_id'], + 'page' => 'pages/dealer/index/index', + 'data' => [ + // 申请时间 + $template['keywords'][0] => ['value' => $applyInfo['apply_time']], + // 审核状态 + $template['keywords'][1] => ['value' => ApplyStatusEnum::data()[$applyInfo['apply_status']]['name']], + // 审核时间 + $template['keywords'][2] => ['value' => $applyInfo['audit_time']], + // 备注信息 + $template['keywords'][3] => ['value' => $this->getRemarkValue($applyInfo)], + ] + ]); + } + + /** + * 备注信息 + * @param $applyInfo + * @return string + */ + private function getRemarkValue($applyInfo) + { + $remark = '分销商入驻审核通知'; + if ($applyInfo['apply_status'] == 30) { + $remark .= "\n驳回原因:{$applyInfo['reject_reason']}"; + } + return $this->getSubstr($remark); + } + +} \ No newline at end of file diff --git a/source/application/common/service/message/dealer/Withdraw.php b/source/application/common/service/message/dealer/Withdraw.php new file mode 100644 index 0000000..ced5e48 --- /dev/null +++ b/source/application/common/service/message/dealer/Withdraw.php @@ -0,0 +1,122 @@ + [], // 提现记录 + ]; + + /** + * 发送消息通知 + * @param array $param + * @return mixed|void + * @throws \think\Exception + */ + public function send($param) + { + // 记录参数 + $this->param = $param; + // 微信订阅消息通知用户 + $this->onSendWxSubMsg(); + } + + /** + * 微信订阅消息通知用户 + * @return bool|mixed + * @throws \app\common\exception\BaseException + * @throws \think\Exception + * @throws \think\exception\DbException + */ + private function onSendWxSubMsg() + { + $withdrawInfo = $this->param['withdraw']; + $userInfo = $this->param['user']; + $wxappId = $withdrawInfo['wxapp_id']; + + // 根据提现状态获取对应的消息模板 + $template = $this->getTemplateByStatus($withdrawInfo); + if ($template === false) { + return false; + } + + // 发送订阅消息 + return $this->sendWxSubMsg($wxappId, [ + 'touser' => $userInfo['open_id'], + 'template_id' => $template['template_id'], + 'page' => 'pages/dealer/index/index', + 'data' => $this->getTemplateData($withdrawInfo, $template) + ]); + } + + /** + * 生成消息内容 + * @param $withdrawInfo + * @param $template + * @return array + */ + private function getTemplateData($withdrawInfo, $template) + { + if ($withdrawInfo['apply_status'] == ApplyStatusEnum::AUDIT_PASS) { + return [ + // 提现金额 + $template['keywords'][0] => ['value' => $withdrawInfo['money']], + // 打款方式 + $template['keywords'][1] => ['value' => $withdrawInfo['pay_type']['text']], + // 打款原因 + $template['keywords'][2] => ['value' => '分销商提现'], + ]; + } + if ($withdrawInfo['apply_status'] == ApplyStatusEnum::AUDIT_REJECT) { + return [ + // 提现金额 + $template['keywords'][0] => ['value' => $withdrawInfo['money']], + // 申请时间 + $template['keywords'][1] => ['value' => $withdrawInfo['create_time']], + // 原因 + $template['keywords'][2] => ['value' => $this->getSubstr($withdrawInfo['reject_reason'])], + ]; + } + return []; + } + + /** + * 根据提现状态获取对应的消息模板 + * @param $withdrawInfo + * @return bool + */ + private function getTemplateByStatus($withdrawInfo) + { + $wxappId = $withdrawInfo['wxapp_id']; + // 获取订阅消息配置 + $templateGroup = SettingModel::getItem('submsg', $wxappId)['dealer']; + if ( + $withdrawInfo['apply_status'] == ApplyStatusEnum::AUDIT_PASS + && !empty($templateGroup['withdraw_01']['template_id']) + ) { + return $templateGroup['withdraw_01']; + } + if ( + $withdrawInfo['apply_status'] == ApplyStatusEnum::AUDIT_REJECT + && !empty($templateGroup['withdraw_02']['template_id']) + ) { + return $templateGroup['withdraw_02']; + } + return false; + } + +} \ No newline at end of file diff --git a/source/application/common/service/message/order/Delivery.php b/source/application/common/service/message/order/Delivery.php new file mode 100644 index 0000000..de0bb2d --- /dev/null +++ b/source/application/common/service/message/order/Delivery.php @@ -0,0 +1,116 @@ + [], + 'order_type' => OrderTypeEnum::MASTER, + ]; + + /** + * 订单页面链接 + * @var array + */ + private $pageUrl = [ + OrderTypeEnum::MASTER => 'pages/order/detail', + OrderTypeEnum::SHARING => 'pages/sharing/order/detail/detail', + ]; + + /** + * 发送消息通知 + * @param array $param + * @return mixed|void + * @throws \think\Exception + */ + public function send($param) + { + // 记录参数 + $this->param = $param; + // 微信订阅消息通知用户 + $this->onSendWxSubMsg(); + } + + /** + * 微信订阅消息通知用户 + * @return bool|mixed + * @throws \app\common\exception\BaseException + * @throws \think\Exception + * @throws \think\exception\DbException + */ + private function onSendWxSubMsg() + { + $orderInfo = $this->param['order']; + $orderType = $this->param['order_type']; + $wxappId = $orderInfo['wxapp_id']; + + // 获取订阅消息配置 + $template = SettingModel::getItem('submsg', $wxappId)['order']['delivery']; + if (empty($template['template_id'])) { + return false; + } + + // 发送订阅消息 + return $this->sendWxSubMsg($wxappId, [ + 'touser' => $orderInfo['user']['open_id'], + 'template_id' => $template['template_id'], + 'page' => "{$this->pageUrl[$orderType]}?order_id={$orderInfo['order_id']}", + 'data' => [ + // 订单号 + $template['keywords'][0] => ['value' => $orderInfo['order_no']], + // 商品名称 + $template['keywords'][1] => ['value' => $this->getFormatGoodsName($orderInfo['goods'])], + // 收货人 + $template['keywords'][2] => ['value' => $orderInfo['address']['name']], + // 收货地址 + $template['keywords'][3] => ['value' => $this->getFormatAddress($orderInfo)], + // 物流公司 + $template['keywords'][4] => ['value' => $this->getFormatExpressName($orderInfo)], + ] + ]); + } + + /** + * 格式化物流公司 + * @param $orderInfo + * @return mixed + */ + private function getFormatExpressName($orderInfo) + { + return $this->getSubstr($orderInfo['express']['express_name']); + } + + /** + * 格式化用户收货地址 + * @param $orderInfo + * @return string + */ + private function getFormatAddress($orderInfo) + { + return implode('', $orderInfo['address']['region']) . $orderInfo['address']['detail']; + } + + /** + * 格式化商品名称 + * @param $goodsData + * @return string + */ + private function getFormatGoodsName($goodsData) + { + return $this->getSubstr($goodsData[0]['goods_name']); + } +} \ No newline at end of file diff --git a/source/application/common/service/message/order/Payment.php b/source/application/common/service/message/order/Payment.php new file mode 100644 index 0000000..34ee5f8 --- /dev/null +++ b/source/application/common/service/message/order/Payment.php @@ -0,0 +1,107 @@ + [], + 'order_type' => OrderTypeEnum::MASTER, + ]; + + /** + * 订单页面链接 + * @var array + */ + private $pageUrl = [ + OrderTypeEnum::MASTER => 'pages/order/detail', + OrderTypeEnum::SHARING => 'pages/sharing/order/detail/detail', + ]; + + /** + * 发送消息通知 + * @param array $param + * @return mixed|void + * @throws \think\Exception + */ + public function send($param) + { + // 记录参数 + $this->param = $param; + // 短信通知商家 + $this->onSendSms(); + // 微信订阅消息通知用户 + $this->onSendWxSubMsg(); + } + + /** + * 短信通知商家 + * @return bool + * @throws \think\Exception + */ + private function onSendSms() + { + $orderInfo = $this->param['order']; + $wxappId = $orderInfo['wxapp_id']; + return $this->sendSms('order_pay', ['order_no' => $orderInfo['order_no']], $wxappId); + } + + /** + * 微信订阅消息通知用户 + * @return bool|mixed + * @throws \app\common\exception\BaseException + * @throws \think\Exception + * @throws \think\exception\DbException + */ + private function onSendWxSubMsg() + { + $orderInfo = $this->param['order']; + $orderType = $this->param['order_type']; + $wxappId = $orderInfo['wxapp_id']; + + // 获取订阅消息配置 + $template = SettingModel::getItem('submsg', $wxappId)['order']['payment']; + if (empty($template['template_id'])) { + return false; + } + // 发送订阅消息 + return $this->sendWxSubMsg($wxappId, [ + 'touser' => $orderInfo['user']['open_id'], + 'template_id' => $template['template_id'], + 'page' => "{$this->pageUrl[$orderType]}?order_id={$orderInfo['order_id']}", + 'data' => [ + // 订单编号 + $template['keywords'][0] => ['value' => $orderInfo['order_no']], + // 下单时间 + $template['keywords'][1] => ['value' => format_time($orderInfo['pay_time'])], + // 订单金额 + $template['keywords'][2] => ['value' => $orderInfo['pay_price']], + // 商品名称 + $template['keywords'][3] => ['value' => $this->getFormatGoodsName($orderInfo['goods'])], + ] + ]); + } + + /** + * 格式化商品名称 + * @param $goodsData + * @return string + */ + private function getFormatGoodsName($goodsData) + { + return $this->getSubstr($goodsData[0]['goods_name']); + } +} \ No newline at end of file diff --git a/source/application/common/service/message/order/Refund.php b/source/application/common/service/message/order/Refund.php new file mode 100644 index 0000000..265f2cf --- /dev/null +++ b/source/application/common/service/message/order/Refund.php @@ -0,0 +1,89 @@ + [], // 退款单信息 + 'order_no' => [], // 订单信息 + 'order_type' => OrderTypeEnum::MASTER, // 订单类型 + ]; + + /** + * 订单页面链接 + * @var array + */ + private $pageUrl = [ + OrderTypeEnum::MASTER => 'pages/order/refund/index', + OrderTypeEnum::SHARING => 'pages/sharing/order/refund/index', + ]; + + /** + * 发送消息通知 + * @param array $param + * @return mixed|void + * @throws \think\Exception + */ + public function send($param) + { + // 记录参数 + $this->param = $param; + // 微信订阅消息通知用户 + $this->onSendWxSubMsg(); + } + + /** + * 微信订阅消息通知用户 + * @return bool|mixed + * @throws \app\common\exception\BaseException + * @throws \think\Exception + * @throws \think\exception\DbException + */ + private function onSendWxSubMsg() + { + $refundInfo = $this->param['refund']; + $orderNo = $this->param['order_no']; + $orderType = $this->param['order_type']; + $wxappId = $refundInfo['wxapp_id']; + + // 获取订阅消息配置 + $template = SettingModel::getItem('submsg', $wxappId)['order']['refund']; + if (empty($template['template_id'])) { + return false; + } + + // 发送订阅消息 + return $this->sendWxSubMsg($wxappId, [ + 'touser' => $refundInfo['user']['open_id'], + 'template_id' => $template['template_id'], + 'page' => "{$this->pageUrl[$orderType]}", + 'data' => [ + // 售后类型 + $template['keywords'][0] => ['value' => $refundInfo['type']['text']], + // 状态 + $template['keywords'][1] => ['value' => $refundInfo['status']['text']], + // 订单编号 + $template['keywords'][2] => ['value' => $orderNo], + // 申请时间 + $template['keywords'][3] => ['value' => $refundInfo['create_time']], + // 申请原因 + $template['keywords'][4] => ['value' => $this->getSubstr($refundInfo['apply_desc'])], + ] + ]); + } + +} \ No newline at end of file diff --git a/source/application/common/service/message/sharing/ActiveStatus.php b/source/application/common/service/message/sharing/ActiveStatus.php new file mode 100644 index 0000000..636f418 --- /dev/null +++ b/source/application/common/service/message/sharing/ActiveStatus.php @@ -0,0 +1,82 @@ + [], // 拼单详情 + 'status' => false, // 拼单状态 + ]; + + /** + * 发送消息通知 + * @param array $param + * @return mixed|void + * @throws \think\Exception + */ + public function send($param) + { + // 记录参数 + $this->param = $param; + // 微信订阅消息通知用户 + $this->onSendWxSubMsg(); + } + + /** + * 微信订阅消息通知用户 + * @return bool + * @throws \app\common\exception\BaseException + * @throws \think\Exception + * @throws \think\exception\DbException + */ + private function onSendWxSubMsg() + { + // 拼单详情 + $activeInfo = $this->param['active']; + $status = $this->param['status']; + $wxappId = $activeInfo['wxapp_id']; + + // 获取订阅消息配置 + $template = SettingModel::getItem('submsg', $wxappId)['sharing']['active_status']; + if (empty($template['template_id'])) { + return false; + } + // 发送订阅消息 + foreach ($activeInfo['users'] as $item) { + $this->sendWxSubMsg($wxappId, [ + 'touser' => $item['user']['open_id'], + 'template_id' => $template['template_id'], + 'page' => "pages/sharing/active/index?active_id={$activeInfo['active_id']}", + 'data' => [ + // 拼团商品 + $template['keywords'][0] => ['value' => str_substr($activeInfo['goods']['goods_name'], 20)], + // 拼团价格 + $template['keywords'][1] => ['value' => $item['sharing_order']['pay_price']], + // 成团人数 + $template['keywords'][2] => ['value' => $activeInfo['people']], + // 拼团进度 + $template['keywords'][3] => ['value' => "已有{$activeInfo['actual_people']}人参与"], + // 温馨提示 + $template['keywords'][4] => ['value' => ActiveStatusEnum::data()[$status]['name']], + ] + ]); + } + return true; + } + + +} \ No newline at end of file diff --git a/source/application/common/service/order/Refund.php b/source/application/common/service/order/Refund.php index bca0f37..53492db 100644 --- a/source/application/common/service/order/Refund.php +++ b/source/application/common/service/order/Refund.php @@ -25,7 +25,7 @@ class Refund * @throws \think\exception\DbException * @throws \app\common\exception\BaseException */ - public function execute(&$order, $money = null) + public function execute($order, $money = null) { // 退款金额,如不指定则默认为订单实付款金额 is_null($money) && $money = $order['pay_price']; diff --git a/source/application/store/controller/Setting.php b/source/application/store/controller/Setting.php index 1367206..45ddc1d 100644 --- a/source/application/store/controller/Setting.php +++ b/source/application/store/controller/Setting.php @@ -44,7 +44,7 @@ class Setting extends Controller } /** - * 模板消息 + * 发送订阅消息 * @return mixed * @throws \think\exception\DbException */ diff --git a/source/application/store/controller/apps/dealer/Apply.php b/source/application/store/controller/apps/dealer/Apply.php index bfbefb5..0c4e42f 100644 --- a/source/application/store/controller/apps/dealer/Apply.php +++ b/source/application/store/controller/apps/dealer/Apply.php @@ -29,10 +29,8 @@ class Apply extends Controller /** * 分销商审核 * @param $apply_id - * @return array - * @throws \app\common\exception\BaseException + * @return array|bool * @throws \think\exception\DbException - * @throws \think\exception\PDOException */ public function submit($apply_id) { diff --git a/source/application/store/controller/apps/dealer/Withdraw.php b/source/application/store/controller/apps/dealer/Withdraw.php index 4aa53d4..0070d97 100644 --- a/source/application/store/controller/apps/dealer/Withdraw.php +++ b/source/application/store/controller/apps/dealer/Withdraw.php @@ -33,7 +33,6 @@ class Withdraw extends Controller * 提现审核 * @param $id * @return array - * @throws \app\common\exception\BaseException * @throws \think\exception\DbException */ public function submit($id) @@ -65,6 +64,7 @@ class Withdraw extends Controller * @param $id * @return array|bool * @throws \app\common\exception\BaseException + * @throws \think\Exception * @throws \think\exception\DbException */ public function wechat_pay($id) diff --git a/source/application/store/controller/apps/live/Room.php b/source/application/store/controller/apps/live/Room.php index 3032933..f5dd0b8 100644 --- a/source/application/store/controller/apps/live/Room.php +++ b/source/application/store/controller/apps/live/Room.php @@ -49,7 +49,7 @@ class Room extends Controller */ public function settop($room_id, $is_top) { - // 商品详情 + // 直播间详情 $model = LiveRoomModel::detail($room_id); if (!$model->setIsTop($is_top)) { return $this->renderError('操作失败'); diff --git a/source/application/store/controller/market/Push.php b/source/application/store/controller/market/Push.php index 896efc3..afa00b9 100644 --- a/source/application/store/controller/market/Push.php +++ b/source/application/store/controller/market/Push.php @@ -7,7 +7,7 @@ use app\store\model\wxapp\Formid as FormidModel; use app\store\service\wxapp\Message as MessageService; /** - * 消息推送 + * 消息推送 (废弃) * Class Push * @package app\store\controller\market */ @@ -17,6 +17,7 @@ class Push extends Controller * 发送消息 * @return array|mixed * @throws \app\common\exception\BaseException + * @throws \think\Exception * @throws \think\exception\DbException */ public function send() diff --git a/source/application/store/controller/wxapp/Submsg.php b/source/application/store/controller/wxapp/Submsg.php new file mode 100644 index 0000000..7f172f0 --- /dev/null +++ b/source/application/store/controller/wxapp/Submsg.php @@ -0,0 +1,50 @@ +request->isAjax()) { + $values = SettingModel::getItem('submsg'); + return $this->fetch('index', compact('values')); + } + $model = new SettingModel; + if ($model->edit('submsg', $this->postData('submsg'))) { + return $this->renderSuccess('操作成功'); + } + return $this->renderError($model->getError() ?: '操作失败'); + } + + /** + * 一键添加订阅消息 + * @return array + * @throws \app\common\exception\BaseException + * @throws \think\Exception + * @throws \think\exception\DbException + */ + public function shuttle() + { + $SubMsgService = new SubMsgService; + if ($SubMsgService->shuttle()) { + return $this->renderSuccess('操作成功'); + } + return $this->renderError($SubMsgService->getError() ?: '操作失败'); + } + +} \ No newline at end of file diff --git a/source/application/store/extra/menus.php b/source/application/store/extra/menus.php index 5767a97..f053b92 100644 --- a/source/application/store/extra/menus.php +++ b/source/application/store/extra/menus.php @@ -360,6 +360,13 @@ return [ ] ] ], + [ + 'name' => '订阅消息', + 'index' => 'wxapp.submsg/index', + 'uris' => [ + 'wxapp.submsg/index', + ] + ], [ 'name' => '帮助中心', 'index' => 'wxapp.help/index', @@ -607,15 +614,15 @@ return [ 'name' => '短信通知', 'index' => 'setting/sms' ], - [ - 'name' => '模板消息', - 'index' => 'setting/tplmsg', - 'uris' => [ - 'setting/tplmsg', - 'setting.help/tplmsg' - - ], - ], + // [ + // 'name' => '模板消息', + // 'index' => 'setting/tplmsg', + // 'uris' => [ + // 'setting/tplmsg', + // 'setting.help/tplmsg' + // + // ], + // ], [ 'name' => '退货地址', 'index' => 'setting.address/index', diff --git a/source/application/store/model/Order.php b/source/application/store/model/Order.php index 70ded0e..9656a5e 100644 --- a/source/application/store/model/Order.php +++ b/source/application/store/model/Order.php @@ -249,19 +249,17 @@ class Order extends OrderModel /** * 确认发货后发送消息通知 - * @param array|\think\Collection $orderList + * @param $orderList * @return bool - * @throws \app\common\exception\BaseException - * @throws \think\Exception - * @throws \think\exception\DbException */ private function sendDeliveryMessage($orderList) { - // 实例化消息通知服务类 - $Service = new MessageService; + // 发送消息通知 foreach ($orderList as $item) { - // 发送消息通知 - $Service->delivery($item, OrderTypeEnum::MASTER); + MessageService::send('order.delivery', [ + 'order' => $item, + 'order_type' => OrderTypeEnum::MASTER, + ]); } return true; } diff --git a/source/application/store/model/OrderRefund.php b/source/application/store/model/OrderRefund.php index 2b9485b..b3de871 100644 --- a/source/application/store/model/OrderRefund.php +++ b/source/application/store/model/OrderRefund.php @@ -59,7 +59,6 @@ class OrderRefund extends OrderRefundModel * 商家审核 * @param $data * @return bool - * @throws \think\exception\PDOException */ public function audit($data) { @@ -71,8 +70,7 @@ class OrderRefund extends OrderRefundModel $this->error = '请选择退货地址'; return false; } - $this->startTrans(); - try { + $this->transaction(function () use ($data) { // 拒绝申请, 标记售后单状态为已拒绝 $data['is_agree'] == 20 && $data['status'] = 10; // 同意换货申请, 标记售后单状态为已完成 @@ -81,21 +79,18 @@ class OrderRefund extends OrderRefundModel $this->allowField(true)->save($data); // 同意售后申请, 记录退货地址 if ($data['is_agree'] == 10) { - $model = new OrderRefundAddress; - $model->add($this['order_refund_id'], $data['address_id']); + (new OrderRefundAddress)->add($this['order_refund_id'], $data['address_id']); } // 订单详情 $order = Order::detail($this['order_id']); - // 发送模板消息 - (new MessageService)->refund(self::detail($this['order_refund_id']), $order['order_no'], OrderTypeEnum::MASTER); - // 事务提交 - $this->commit(); - return true; - } catch (\Exception $e) { - $this->error = $e->getMessage(); - $this->rollback(); - return false; - } + // 发送消息通知 + MessageService::send('order.refund', [ + 'refund' => $this, // 退款单信息 + 'order_no' => $order['order_no'], // 订单信息 + 'order_type' => OrderTypeEnum::MASTER, // 订单类型 + ]); + }); + return true; } /** @@ -126,8 +121,12 @@ class OrderRefund extends OrderRefundModel } // 执行原路退款 (new RefundService)->execute($order, $data['refund_money']); - // 发送模板消息 - (new MessageService)->refund(self::detail($this['order_refund_id']), $order['order_no'], OrderTypeEnum::MASTER); + // 发送消息通知 + MessageService::send('order.refund', [ + 'refund' => $this, // 退款单信息 + 'order_no' => $order['order_no'], // 订单信息 + 'order_type' => OrderTypeEnum::MASTER, // 订单类型 + ]); }); return true; } diff --git a/source/application/store/model/Wxapp.php b/source/application/store/model/Wxapp.php index 9c99b24..e52212c 100644 --- a/source/application/store/model/Wxapp.php +++ b/source/application/store/model/Wxapp.php @@ -2,8 +2,8 @@ namespace app\store\model; -use app\common\model\Wxapp as WxappModel; use think\Cache; +use app\common\model\Wxapp as WxappModel; /** * 微信小程序模型 @@ -65,40 +65,6 @@ class Wxapp extends WxappModel return true; } - /** - * 记录图片信息 - * @param $wxapp_id - * @param $oldFileId - * @param $newFileName - * @param $fromType - * @return int|mixed - */ - private function uploadImage($wxapp_id, $oldFileId, $newFileName, $fromType) - { -// $UploadFile = new UploadFile; - $UploadFileUsed = new UploadFileUsed; - if ($oldFileId > 0) { - // 获取原图片path - $oldFileName = UploadFile::getFileName($oldFileId); - // 新文件与原来路径一致, 代表用户未修改, 不做更新 - if ($newFileName === $oldFileName) - return $oldFileId; - // 删除原文件使用记录 - $UploadFileUsed->remove('service', $oldFileId); - } - // 删除图片 - if (empty($newFileName)) return 0; - // 查询新文件file_id - $fileId = UploadFile::getFildIdByName($newFileName); - // 添加文件使用记录 - $UploadFileUsed->add([ - 'file_id' => $fileId, - 'wxapp_id' => $wxapp_id, - 'from_type' => $fromType - ]); - return $fileId; - } - /** * 删除wxapp缓存 * @return bool diff --git a/source/application/store/model/dealer/Apply.php b/source/application/store/model/dealer/Apply.php index af7bb44..67160c9 100644 --- a/source/application/store/model/dealer/Apply.php +++ b/source/application/store/model/dealer/Apply.php @@ -3,7 +3,8 @@ namespace app\store\model\dealer; use app\common\model\dealer\Apply as ApplyModel; -use app\common\service\Message; +use app\common\service\Message as MessageService; +use app\common\enum\dealer\ApplyStatus as ApplyStatusEnum; /** * 分销商入驻申请模型 @@ -38,31 +39,31 @@ class Apply extends ApplyModel * 分销商入驻审核 * @param $data * @return bool - * @throws \app\common\exception\BaseException - * @throws \think\exception\DbException - * @throws \think\exception\PDOException */ public function submit($data) { - if ($data['apply_status'] == '30' && empty($data['reject_reason'])) { + if ($data['apply_status'] == ApplyStatusEnum::AUDIT_REJECT && empty($data['reject_reason'])) { $this->error = '请填写驳回原因'; return false; } - $this->startTrans(); - if ($data['apply_status'] == '20') { - // 新增分销商用户 - User::add($this['user_id'], [ - 'real_name' => $this['real_name'], - 'mobile' => $this['mobile'], - 'referee_id' => $this['referee_id'], + $this->transaction(function () use ($data) { + if ($data['apply_status'] == ApplyStatusEnum::AUDIT_PASS) { + // 新增分销商用户 + User::add($this['user_id'], [ + 'real_name' => $this['real_name'], + 'mobile' => $this['mobile'], + 'referee_id' => $this['referee_id'], + ]); + } + // 更新申请记录 + $data['audit_time'] = time(); + $this->allowField(true)->save($data); + // 发送订阅消息 + MessageService::send('dealer.apply', [ + 'apply' => $this, // 申请记录 + 'user' => $this['user'], // 用户信息 ]); - } - // 更新申请记录 - $data['audit_time'] = time(); - $this->allowField(true)->save($data); - // 发送模板消息 - (new Message)->dealer($this); - $this->commit(); + }); return true; } diff --git a/source/application/store/model/dealer/Setting.php b/source/application/store/model/dealer/Setting.php index 237ffbf..20b3218 100644 --- a/source/application/store/model/dealer/Setting.php +++ b/source/application/store/model/dealer/Setting.php @@ -25,7 +25,6 @@ class Setting extends SettingModel 'words' => '自定义文字', 'license' => '申请协议', 'background' => '页面背景图', - 'template_msg' => '模板消息', 'qrcode' => '分销海报', ]; diff --git a/source/application/store/model/dealer/Withdraw.php b/source/application/store/model/dealer/Withdraw.php index a9c591a..72dcfe5 100644 --- a/source/application/store/model/dealer/Withdraw.php +++ b/source/application/store/model/dealer/Withdraw.php @@ -2,11 +2,13 @@ namespace app\store\model\dealer; -use app\common\service\Message; -use app\common\service\Order as OrderService; -use app\common\library\wechat\WxPay; +use app\store\model\User as UserModel; use app\store\model\Wxapp as WxappModel; use app\common\model\dealer\Withdraw as WithdrawModel; +use app\common\library\wechat\WxPay; +use app\common\service\Order as OrderService; +use app\common\service\Message as MessageService; +use app\common\enum\dealer\withdraw\ApplyStatus as ApplyStatusEnum; /** * 分销商提现明细模型 @@ -32,7 +34,7 @@ class Withdraw extends WithdrawModel */ public function getPayTypeAttr($value) { - return ['text' => $this->payType[$value], 'value' => $value]; + return ['text' => ApplyStatusEnum::data()[$value]['name'], 'value' => $value]; } /** @@ -68,34 +70,40 @@ class Withdraw extends WithdrawModel * 分销商提现审核 * @param $data * @return bool - * @throws \app\common\exception\BaseException - * @throws \think\exception\DbException */ public function submit($data) { - if ($data['apply_status'] == '30' && empty($data['reject_reason'])) { + if ( + $data['apply_status'] == ApplyStatusEnum::AUDIT_REJECT + && empty($data['reject_reason']) + ) { $this->error = '请填写驳回原因'; return false; } - // 更新申请记录 - $data['audit_time'] = time(); - $this->allowField(true)->save($data); - // 提现驳回:解冻分销商资金 - $data['apply_status'] == '30' && User::backFreezeMoney($this['user_id'], $this['money']); - // 发送模板消息 - (new Message)->withdraw($this); + $this->transaction(function () use ($data) { + // 更新申请记录 + $data['audit_time'] = time(); + $this->allowField(true)->save($data); + // 提现驳回:解冻分销商资金 + if ($data['apply_status'] == ApplyStatusEnum::AUDIT_REJECT) { + User::backFreezeMoney($this['user_id'], $this['money']); + } + // 发送消息通知 + MessageService::send('dealer.withdraw', [ + 'withdraw' => $this, + 'user' => UserModel::detail($this['user_id']), + ]); + }); return true; } /** * 确认已打款 * @return bool - * @throws \think\exception\PDOException */ public function money() { - $this->startTrans(); - try { + $this->transaction(function () { // 更新申请状态 $this->allowField(true)->save([ 'apply_status' => 40, @@ -110,24 +118,16 @@ class Withdraw extends WithdrawModel 'money' => -$this['money'], 'describe' => '申请提现', ]); - // 发送模板消息 - (new Message)->withdraw($this); - // 事务提交 - $this->commit(); - return true; - } catch (\Exception $e) { - $this->error = $e->getMessage(); - $this->rollback(); - return false; - } + }); + return true; } /** * 分销商提现:微信支付企业付款 * @return bool * @throws \app\common\exception\BaseException + * @throws \think\Exception * @throws \think\exception\DbException - * @throws \think\exception\PDOException */ public function wechatPay() { diff --git a/source/application/store/model/sharing/Order.php b/source/application/store/model/sharing/Order.php index 6cb7e15..53d8788 100644 --- a/source/application/store/model/sharing/Order.php +++ b/source/application/store/model/sharing/Order.php @@ -183,7 +183,6 @@ class Order extends OrderModel * 确认发货(单独订单) * @param $data * @return array|bool|false - * @throws \app\common\exception\BaseException * @throws \think\Exception * @throws \think\exception\DbException * @throws \Exception @@ -262,19 +261,17 @@ class Order extends OrderModel /** * 确认发货后发送消息通知 - * @param array|\think\Collection $orderList + * @param $orderList * @return bool - * @throws \app\common\exception\BaseException - * @throws \think\Exception - * @throws \think\exception\DbException */ private function sendDeliveryMessage($orderList) { - // 实例化消息通知服务类 - $Service = new MessageService; + // 发送消息通知 foreach ($orderList as $item) { - // 发送消息通知 - $Service->delivery($item, OrderTypeEnum::SHARING); + MessageService::send('order.delivery', [ + 'order' => $item, + 'order_type' => OrderTypeEnum::SHARING, + ]); } return true; } diff --git a/source/application/store/model/sharing/OrderRefund.php b/source/application/store/model/sharing/OrderRefund.php index aff53af..cf6cbeb 100644 --- a/source/application/store/model/sharing/OrderRefund.php +++ b/source/application/store/model/sharing/OrderRefund.php @@ -59,7 +59,6 @@ class OrderRefund extends OrderRefundModel * 商家审核 * @param $data * @return bool - * @throws \think\exception\PDOException */ public function audit($data) { @@ -71,8 +70,7 @@ class OrderRefund extends OrderRefundModel $this->error = '请选择退货地址'; return false; } - $this->startTrans(); - try { + $this->transaction(function ($data) { // 拒绝申请, 标记售后单状态为已拒绝 $data['is_agree'] == 20 && $data['status'] = 10; // 同意换货申请, 标记售后单状态为已完成 @@ -81,21 +79,18 @@ class OrderRefund extends OrderRefundModel $this->allowField(true)->save($data); // 同意售后申请, 记录退货地址 if ($data['is_agree'] == 10) { - $model = new OrderRefundAddress; - $model->add($this['order_refund_id'], $data['address_id']); + (new OrderRefundAddress)->add($this['order_refund_id'], $data['address_id']); } // 订单详情 $order = Order::detail($this['order_id']); - // 发送模板消息 - (new MessageService)->refund(static::detail($this['order_refund_id']), $order['order_no'], OrderTypeEnum::SHARING); - // 事务提交 - $this->commit(); - return true; - } catch (\Exception $e) { - $this->error = $e->getMessage(); - $this->rollback(); - return false; - } + // 发送消息通知 + MessageService::send('order.refund', [ + 'refund' => $this, // 退款单信息 + 'order_no' => $order['order_no'], // 订单信息 + 'order_type' => OrderTypeEnum::SHARING, // 订单类型 + ]); + }); + return true; } /** @@ -126,8 +121,12 @@ class OrderRefund extends OrderRefundModel } // 执行原路退款 (new RefundService)->execute($order, $data['refund_money']); - // 发送模板消息 - (new MessageService)->refund(self::detail($this['order_refund_id']), $order['order_no'], OrderTypeEnum::SHARING); + // 发送消息通知 + MessageService::send('order.refund', [ + 'refund' => $this, // 退款单信息 + 'order_no' => $order['order_no'], // 订单信息 + 'order_type' => OrderTypeEnum::SHARING, // 订单类型 + ]); }); return true; } diff --git a/source/application/store/model/wxapp/LiveRoom.php b/source/application/store/model/wxapp/LiveRoom.php index 7a94579..95509c0 100644 --- a/source/application/store/model/wxapp/LiveRoom.php +++ b/source/application/store/model/wxapp/LiveRoom.php @@ -113,7 +113,7 @@ class LiveRoom extends LiveRoomModel */ private function getLocalRoomIds() { - return $this->where('is_delete', '=', 0)->column('room_id'); + return $this->where('is_delete', '=', 0)->column('room_id', 'id'); } /** @@ -162,11 +162,14 @@ class LiveRoom extends LiveRoomModel // 需要新增的直播间ID $updatedLiveRoomIds = array_values(array_intersect($originRoomIds, $localRoomIds)); if (empty($updatedLiveRoomIds)) return true; + // 根据直播间id获取主键id + $idArr = $this->getLocalIdsByRoomIds($localRoomIds); // 整理新增数据 $saveData = []; foreach ($updatedLiveRoomIds as $roomId) { $item = $originRoomList[$roomId]; $saveData[] = [ + 'id' => $idArr[$roomId], 'room_id' => $roomId, 'room_name' => $item['name'], 'cover_img' => $item['cover_img'], @@ -191,11 +194,30 @@ class LiveRoom extends LiveRoomModel */ private function refreshLiveRemove($localRoomIds, $originRoomIds) { - // 需要新增的直播间ID + // 需要删除的直播间ID $removedLiveRoomIds = array_values(array_diff($localRoomIds, $originRoomIds)); if (empty($removedLiveRoomIds)) return true; + // 根据直播间id获取主键id + $removedIds = $this->getLocalIdsByRoomIds($localRoomIds, $removedLiveRoomIds); // 批量删除直播间 - return self::destroy($removedLiveRoomIds); + return self::destroy(array_values($removedIds)); + } + + /** + * 根据直播间id获取主键id + * @param array $localRoomIds + * @param array $searchRoomIds + * @return array + */ + private function getLocalIdsByRoomIds($localRoomIds, $searchRoomIds = []) + { + $data = []; + foreach ($localRoomIds as $id => $roomId) { + if (empty($searchRoomIds) || in_array($roomId, $searchRoomIds)) { + $data[$roomId] = $id; + } + } + return $data; } } \ No newline at end of file diff --git a/source/application/store/service/Auth.php b/source/application/store/service/Auth.php index e671afc..c2a58c2 100644 --- a/source/application/store/service/Auth.php +++ b/source/application/store/service/Auth.php @@ -80,7 +80,9 @@ class Auth // 商家登录信息 $this->store = Session::get('yoshop_store'); // 当前用户信息 - $this->user = User::detail($this->store['user']['store_user_id']); + if (!empty($this->store)) { + $this->user = User::detail($this->store['user']['store_user_id']); + } } /** @@ -117,6 +119,7 @@ class Auth } /** + * 验证url的权限 * @param string $url * @return bool * @throws \think\db\exception\DataNotFoundException @@ -126,7 +129,7 @@ class Auth private function checkAccess($url) { // 超级管理员无需验证 - if ($this->user['is_super']) { + if (!empty($this->user) && $this->user['is_super']) { return true; } // 验证当前请求是否在白名单 diff --git a/source/application/store/service/wxapp/Message.php b/source/application/store/service/wxapp/Message.php index 0a8ed64..f46b9ef 100644 --- a/source/application/store/service/wxapp/Message.php +++ b/source/application/store/service/wxapp/Message.php @@ -8,7 +8,7 @@ use app\common\library\wechat\WxTplMsg; use app\common\service\wxapp\FormId as FormIdService; /** - * 推送模板消息服务类 + * 推送模板消息服务类 (已废弃) * Class Message * @package app\store\service\wxapp */ @@ -27,6 +27,7 @@ class Message * 构造方法 * Message constructor. * @throws \app\common\exception\BaseException + * @throws \think\Exception * @throws \think\exception\DbException */ public function __construct() diff --git a/source/application/store/service/wxapp/SubMsg.php b/source/application/store/service/wxapp/SubMsg.php new file mode 100644 index 0000000..92a4624 --- /dev/null +++ b/source/application/store/service/wxapp/SubMsg.php @@ -0,0 +1,194 @@ +WxSubMsg = new WxSubMsg($wxConfig['app_id'], $wxConfig['app_secret']); + } + + /** + * 一键添加订阅消息 + * @return bool + * @throws BaseException + * @throws \think\exception\DbException + */ + public function shuttle() + { + // 拉取我的模板列表 + $myList = $this->getMyTemplateList(); + // 筛选出未添加的模板 + $addedList = $this->getNotAddedTemplates($myList); + // 批量添加订阅消息模板 + $newList = $this->onBatchAdd($addedList); + // 全部模板列表 + $tplList = array_merge($newList, $myList); + // 保存全部模板id + return $this->saveAll($tplList); + + } + + /** + * 保存全部模板id + * @param $tplList + * @return bool + * @throws \think\exception\DbException + */ + private function saveAll($tplList) + { + // 整理模板id + $data = SettingModel::getItem('submsg'); + foreach ($data as &$group) { + foreach ($group as &$item) { + if (!isset($item['title'])) continue; + $tpl = helper::arraySearch($tplList, 'title', $item['title']); + $tpl != false && $item['template_id'] = $tpl['priTmplId']; + } + } + // 保存数据 + return (new SettingModel)->edit('submsg', $data); + } + + /** + * 批量添加订阅消息模板 + * [并且记录返回的priTmplId] + * @param $newList + * @return array + * @throws BaseException + */ + private function onBatchAdd($newList) + { + foreach ($newList as &$item) { + // 请求微信api, 添加模板记录 + $response = $this->WxSubMsg->addTemplate($item['tid'], $item['kidList'], $item['sceneDesc']); + if ($response === false) { + throw new BaseException(['msg' => "添加模板[{$item['sceneDesc']}]失败:" . $this->WxSubMsg->getError()]); + } + // 记录template_id + $item['priTmplId'] = $response['priTmplId']; + } + return $newList; + } + + /** + * 筛选出未添加的模板 + * @param $myList + * @return array + */ + private function getNotAddedTemplates($myList) + { + // 所有订阅消息模板列表 + $templateLists = $this->getTemplates(); + if (empty($myList)) return $templateLists; + // 整理未添加的 + $data = []; + foreach ($templateLists as $item) { + if (helper::arraySearch($myList, 'title', $item['title']) === false) { + $data[] = $item; + } + } + return $data; + } + + /** + * 所有订阅消息模板列表 + * @return array + */ + private function getTemplates() + { + return [ + // 支付成功通知 + [ + 'tid' => 9344, + 'title' => '新订单提醒', + 'kidList' => [1, 2, 4, 3], + 'sceneDesc' => '新订单提醒', + ], + // 订单发货通知 + [ + 'tid' => 855, + 'title' => '订单发货通知', + 'kidList' => [1, 2, 12, 11, 17], + 'sceneDesc' => '订单发货通知', + ], + // 售后状态通知 + [ + 'tid' => 5049, + 'title' => '售后状态通知', + 'kidList' => [1, 6, 2, 3, 4], + 'sceneDesc' => '售后状态通知', + ], + // 拼团进度通知 + [ + 'tid' => 5008, + 'title' => '拼团进度通知', + 'kidList' => [1, 5, 7, 3, 6], + 'sceneDesc' => '拼团进度通知', + ], + // 分销商入驻审核通知 + [ + 'tid' => 4050, + 'title' => '代理商入驻审核通知', + 'kidList' => [1, 2, 3, 4], + 'sceneDesc' => '分销商入驻审核通知', + ], + // 提现成功通知 + [ + 'tid' => 2001, + 'title' => '提现成功通知', + 'kidList' => [1, 3, 4], + 'sceneDesc' => '提现成功通知', + ], + // 提现失败通知 + [ + 'tid' => 3173, + 'title' => '提现失败通知', + 'kidList' => [1, 3, 4], + 'sceneDesc' => '提现失败通知', + ], + + ]; + } + + /** + * 拉取我的模板列表 + * @return mixed + * @throws BaseException + */ + private function getMyTemplateList() + { + $response = $this->WxSubMsg->getTemplateList(); + if ($response === false) { + throw new BaseException(['msg' => '拉取模板列表失败:' . $this->WxSubMsg->getError()]); + } + return $response['data']; + } + +} \ No newline at end of file diff --git a/source/application/store/view/apps/dealer/setting/index.php b/source/application/store/view/apps/dealer/setting/index.php index 1414dbe..98f76ee 100644 --- a/source/application/store/view/apps/dealer/setting/index.php +++ b/source/application/store/view/apps/dealer/setting/index.php @@ -13,7 +13,6 @@
  • 自定义文字
  • 申请协议
  • 页面背景图
  • -
  • 模板消息
  • @@ -786,38 +785,6 @@
    -
    -
    - -
    - - 模板编号AT0674,关键词 (申请时间、审核状态、审核时间、备注信息) - - 如何获取模板消息ID? - -
    -
    -
    - -
    - - 模板编号AT0324,关键词 (提现时间、提现方式、提现金额、提现状态、备注) - - 如何获取模板消息ID? - -
    -
    -
    diff --git a/source/application/store/view/apps/sharing/setting/index.php b/source/application/store/view/apps/sharing/setting/index.php index f02c3fd..10c396d 100644 --- a/source/application/store/view/apps/sharing/setting/index.php +++ b/source/application/store/view/apps/sharing/setting/index.php @@ -87,22 +87,6 @@
    -
    -
    模板消息
    -
    -
    - -
    - - 模板编号AT1814,关键词 (订单编号、商品名称、拼团价格、拼团人数、拼团时间、拼团结果) - - 如何获取模板消息ID? - -
    -
    -
    + +
    +
    + + + + + + + + diff --git a/source/application/task/behavior/sharing/Active.php b/source/application/task/behavior/sharing/Active.php index d1bca21..37ec54d 100644 --- a/source/application/task/behavior/sharing/Active.php +++ b/source/application/task/behavior/sharing/Active.php @@ -3,10 +3,11 @@ namespace app\task\behavior\sharing; use think\Cache; -use app\common\service\Message; -use app\task\model\sharing\Setting; -use app\task\model\sharing\Active as ActiveModel; use app\task\model\sharing\Order as OrderModel; +use app\task\model\sharing\Active as ActiveModel; +use app\task\model\sharing\Setting as SettingModel; +use app\common\service\Message as MessageService; +use app\common\enum\sharing\ActiveStatus as ActiveStatusEnum; /** * 拼团订单行为管理 @@ -35,7 +36,7 @@ class Active if (!Cache::has('__task_space__sharing_active__' . $model::$wxapp_id)) { try { // 拼团设置 - $config = Setting::getItem('basic'); + $config = SettingModel::getItem('basic'); // 已过期的拼单更新状态(拼单失败) $this->onUpdateActiveEnd(); // 更新拼团失败的订单并退款 @@ -44,7 +45,7 @@ class Active } } catch (\Exception $e) { } - Cache::set('__task_space__sharing_active__' . $model::$wxapp_id, time(), 10); + Cache::set('__task_space__sharing_active__' . $model::$wxapp_id, time(), 1); } return true; } @@ -52,7 +53,6 @@ class Active /** * 已过期的拼单更新状态 * @return false|int - * @throws \app\common\exception\BaseException * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException @@ -70,10 +70,12 @@ class Active $this->dologs('onSetActiveEnd', [ 'activeIds' => json_encode($activeIds), ]); - // 发送拼团失败模板消息 - $Message = new Message; + // 发送拼团失败订阅消息 foreach ($list as $item) { - $Message->sharingActive($item, '拼团失败'); + MessageService::send('sharing.active_status', [ + 'active' => $item, + 'status' => ActiveStatusEnum::ACTIVE_STATE_FAIL + ]); } // 更新已过期状态 return $this->model->updateEndedStatus($activeIds); @@ -82,7 +84,6 @@ class Active /** * 更新拼团失败的订单并退款 * @return bool - * @throws \app\common\exception\BaseException * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException diff --git a/version.json b/version.json index 15219ec..53f36d4 100644 --- a/version.json +++ b/version.json @@ -1,3 +1,3 @@ { - "version": "1.1.40" + "version": "1.1.41" }