diff --git a/application/api/controller/Merchant.php b/application/api/controller/Merchant.php new file mode 100644 index 0000000..1496894 --- /dev/null +++ b/application/api/controller/Merchant.php @@ -0,0 +1,218 @@ +routeId(); + if ($id <= 0) { + $id = (int)$this->input('id', 0) ?: (int)$this->input('userId', 0); + } + if ($id <= 0) { + $this->fail('缺少商家参数', 400); + } + + // 优先按 merchant.id 查,若未命中再按 user_id 查 + $m = Db::name('fc_merchant')->where('id', $id)->find(); + if (!$m) { + $m = Db::name('fc_merchant')->where('user_id', $id)->find(); + } + if (!$m) { + $this->fail('商家门店不存在', 404); + } + + // 关联发布者基础信息 + $user = Db::name('user')->where('id', $m['user_id'])->find(); + $userNickname = $user ? (string)$user['nickname'] : ''; + $userAvatar = $user ? (string)$user['avatar'] : ''; + + // 统计真实有效发布数量 + $postCount = (int)Db::name('fc_post') + ->where('user_id', $m['user_id']) + ->where('status', 1) + ->where('audit_status', 1) + ->whereNull('deletetime') + ->count(); + + // 计算用户与门店之间的物理距离(km) + $clientLat = $this->coord('lat', 90); + $clientLng = $this->coord('lng', 180); + $distance = null; + if ($clientLat !== null && $clientLng !== null && !empty($m['lat']) && !empty($m['lng'])) { + $distance = $this->calcDistance($clientLat, $clientLng, (float)$m['lat'], (float)$m['lng']); + } + + // 首屏拉取前 6 条该商家的有效发帖 + $posts = $this->fetchMerchantPosts($m['user_id'], 1, 6); + + $data = [ + 'id' => (int)$m['id'], + 'userId' => (int)$m['user_id'], + 'name' => (string)$m['name'], + 'logo' => (string)(isset($m['logo']) ? $m['logo'] : ''), + 'banner' => (string)(isset($m['banner']) ? $m['banner'] : ''), + 'address' => (string)(isset($m['address']) ? $m['address'] : ''), + 'lat' => (isset($m['lat']) && $m['lat'] !== null && $m['lat'] !== '') ? (float)$m['lat'] : null, + 'lng' => (isset($m['lng']) && $m['lng'] !== null && $m['lng'] !== '') ? (float)$m['lng'] : null, + 'contact' => (string)(isset($m['contact']) ? $m['contact'] : ''), + 'category' => (string)(isset($m['category']) ? $m['category'] : ''), + 'notice' => (string)(isset($m['notice']) ? $m['notice'] : ''), + 'auditStatus' => (int)$m['audit_status'], + 'verified' => (int)$m['audit_status'] === 1, + 'licenseVerified' => !empty($m['license']) && (int)$m['audit_status'] === 1, + 'postCount' => $postCount, + 'distance' => $distance, + 'userNickname' => $userNickname, + 'userAvatar' => $userAvatar, + 'createdAt' => isset($m['createtime']) ? $this->iso($m['createtime']) : '', + 'posts' => $posts['list'], + 'hasMorePosts' => $posts['hasMore'], + ]; + + $this->ok($data); + } + + /** + * M2 获取商家名下的信息列表(支持分页) + * GET /api/v1/merchant/:id/posts + * + * @return void + */ + public function posts() + { + $id = (int)$this->routeId(); + if ($id <= 0) { + $id = (int)$this->input('id', 0) ?: (int)$this->input('userId', 0); + } + if ($id <= 0) { + $this->fail('缺少商家参数', 400); + } + + $userId = $id; + $m = Db::name('fc_merchant')->where('id', $id)->find(); + if ($m) { + $userId = (int)$m['user_id']; + } + + list($page, $size) = $this->pager(10, 30); + $res = $this->fetchMerchantPosts($userId, $page, $size); + $this->ok($res); + } + + /** + * 查询指定商家的发帖列表统一组装 + * + * @param int $userId 发布者用户ID + * @param int $page 页码 + * @param int $size 每页数量 + * @return array + */ + protected function fetchMerchantPosts($userId, $page, $size) + { + $q = Db::name('fc_post') + ->where('user_id', $userId) + ->where('status', 1) + ->where('audit_status', 1) + ->whereNull('deletetime'); + + $total = (int)$q->count(); + $rows = Db::name('fc_post') + ->where('user_id', $userId) + ->where('status', 1) + ->where('audit_status', 1) + ->whereNull('deletetime') + ->order('is_top desc, id desc') + ->page($page, $size) + ->select(); + + $list = []; + foreach ($rows as $r) { + $catName = ''; + if (!empty($r['category_id'])) { + $cat = Db::name('fc_category')->where('id', $r['category_id'])->value('name'); + $catName = $cat ? (string)$cat : ''; + } + + $cover = (string)$r['cover']; + $mediaArr = $this->jsonArr($r['media']); + if ($cover === '' && !empty($mediaArr)) { + $cover = $mediaArr[0]; + } + + $tags = []; + if (!empty($r['tags'])) { + foreach (explode(',', (string)$r['tags']) as $t) { + $t = trim($t); + if ($t !== '') { + $tags[] = $t; + } + } + } + + $list[] = [ + 'id' => (int)$r['id'], + 'title' => (string)$r['title'], + 'content' => (string)$r['content'], + 'price' => (float)$r['price'], + 'priceUnit' => (string)$r['price_unit'], + 'cover' => $cover, + 'media' => $mediaArr, + 'area' => (string)$r['area'], + 'address' => (string)$r['address'], + 'categoryId' => (int)$r['category_id'], + 'categoryName' => $catName, + 'isTop' => (int)$r['is_top'] === 1, + 'views' => (int)$r['views'], + 'commentCount' => (int)$r['comment_count'], + 'createdAt' => $this->iso($r['createtime']), + 'tags' => $tags, + ]; + } + + return [ + 'list' => $list, + 'total' => $total, + 'page' => $page, + 'size' => $size, + 'hasMore' => ($page * $size) < $total, + ]; + } + + /** + * 计算两点大地距离(单位 km,保留 1 位小数) + * + * @param float $lat1 纬度1 + * @param float $lng1 经度1 + * @param float $lat2 纬度2 + * @param float $lng2 经度2 + * @return float + */ + protected function calcDistance($lat1, $lng1, $lat2, $lng2) + { + $earthRadius = 6378.137; + $radLat1 = deg2rad($lat1); + $radLat2 = deg2rad($lat2); + $a = $radLat1 - $radLat2; + $b = deg2rad($lng1) - deg2rad($lng2); + $s = 2 * asin(sqrt(pow(sin($a / 2), 2) + cos($radLat1) * cos($radLat2) * pow(sin($b / 2), 2))); + $s = $s * $earthRadius; + return round($s, 1); + } +} diff --git a/application/route.php b/application/route.php index 91e6db6..09be2da 100755 --- a/application/route.php +++ b/application/route.php @@ -65,6 +65,10 @@ return [ 'api/v1/post/upload' => 'api/Post/uploadMedia', 'api/v1/post/:id' => 'api/Post/detail', + /* =============== 三·A、用户端 · 商家主页与门店详情 =============== */ + 'api/v1/merchant/:id/posts' => 'api/Merchant/posts', + 'api/v1/merchant/:id' => 'api/Merchant/detail', + /* =============== 三·B、用户端 · 互动(举报 / 收藏 / 关注) =============== * 顺序说明:本组全部是「同前缀、不同后缀」的静态路径(favorite/list、favorite/toggle、 * favorite/status、follow/toggle),彼此不构成前缀包含关系,注册顺序互不吞并; diff --git a/uniapp/common/api/coupon.js b/uniapp/common/api/coupon.js index 5f93647..ef45459 100644 --- a/uniapp/common/api/coupon.js +++ b/uniapp/common/api/coupon.js @@ -3,14 +3,27 @@ * 对应契约 §2.1: * GET /coupon/list {page,size} → 分页(可领取 + 已领取标记 received) * POST /coupon/receive {couponId} → {userCouponId} + * GET /member/assets → {coupons,couponCount,...} */ import { get, post } from '../utils/request.js' export const couponApi = { - /** 可领取优惠券列表(含 received 已领取标记) */ + /** + * 可领取优惠券列表(含 received 已领取标记) + * @param {Object} params {page, size} + */ list: (params = {}) => get('/coupon/list', params, { silent: true }), - /** 领取优惠券 */ + + /** + * 领取优惠券 + * @param {number|string} couponId 优惠券模板ID + */ receive: (couponId) => post('/coupon/receive', { couponId }, { silent: true }), + + /** + * 我的优惠券与资产 + */ + my: () => get('/member/assets', {}, { silent: true }), } export default couponApi diff --git a/uniapp/common/api/index.js b/uniapp/common/api/index.js index 2c71cd4..abbdc1d 100644 --- a/uniapp/common/api/index.js +++ b/uniapp/common/api/index.js @@ -16,3 +16,4 @@ export { reportApi } from './report.js' export { orderApi } from './order.js' export { payApi } from './pay.js' export { couponApi } from './coupon.js' +export { merchantApi } from './merchant.js' diff --git a/uniapp/common/api/merchant.js b/uniapp/common/api/merchant.js new file mode 100644 index 0000000..d34f508 --- /dev/null +++ b/uniapp/common/api/merchant.js @@ -0,0 +1,27 @@ +/** + * 接口模块 · 商家门店与主页(用户端) + * 对应路由: + * GET /api/v1/merchant/:id 获取商家门店公开主页与档案 + * GET /api/v1/merchant/:id/posts 获取商家名下发布的信息列表 + */ +import { get } from '../utils/request.js' + +export const merchantApi = { + /** + * 获取商家门店公开主页 + * @param {number|string} id 商家ID或用户ID + * @param {Object} params 可选参数 {lat, lng} + * @returns {Promise} + */ + detail: (id, params = {}) => get(`/merchant/${id}`, params, { silent: true }), + + /** + * 获取商家发布的信息流(分页) + * @param {number|string} id 商家ID或用户ID + * @param {Object} params {page, size} + * @returns {Promise<{list:Array, total:number, hasMore:boolean}>} + */ + posts: (id, params = {}) => get(`/merchant/${id}/posts`, params, { silent: true }), +} + +export default merchantApi diff --git a/uniapp/common/mock/index.js b/uniapp/common/mock/index.js index 49c35f3..6780985 100644 --- a/uniapp/common/mock/index.js +++ b/uniapp/common/mock/index.js @@ -447,6 +447,40 @@ export const mockRoutes = { })) ), + // ==================== 用户端 · 商家主页与门店详情 ==================== + 'GET /merchant/:id': ({ params }) => { + const id = params && params.id + const m = (datasets.merchants || []).find((x) => String(x.id) === String(id) || String(x.user_id) === String(id)) || datasets.merchants[0] + if (!m) fail('商家门店不存在', 404) + const posts = (datasets.posts || []).filter((p) => p.publisher && (String(p.publisher.id) === String(m.id) || String(p.publisher.name) === String(m.name))) + return ok({ + id: m.id, + userId: m.user_id || m.id, + name: m.name, + logo: m.logo || '', + banner: m.banner || '', + address: m.address || '同城便民服务实体店', + lat: m.lat || 26.5716, + lng: m.lng || 106.7314, + contact: m.contact || '13566666666', + category: m.category || '综合便民', + notice: m.notice || '诚信经营,品质保障,欢迎新老顾客垂询!', + auditStatus: m.auditStatus != null ? m.auditStatus : 1, + verified: true, + licenseVerified: true, + postCount: posts.length || m.postCount || 12, + distance: 1.2, + posts: posts.slice(0, 6), + hasMorePosts: posts.length > 6, + }) + }, + 'GET /merchant/:id/posts': ({ params, data }) => { + const id = params && params.id + const m = (datasets.merchants || []).find((x) => String(x.id) === String(id) || String(x.user_id) === String(id)) || datasets.merchants[0] + const posts = (datasets.posts || []).filter((p) => p.publisher && (String(p.publisher.id) === String(m.id) || String(p.publisher.name) === String(m.name))) + return ok(paginate(posts, data && data.page, data && data.size)) + }, + // ==================== 用户端 · 会员中心 ==================== 'GET /member/plans': () => ok(datasets.memberPlans), 'GET /member/benefits': () => ok(datasets.memberBenefits), diff --git a/uniapp/pages.json b/uniapp/pages.json index 3aaa264..470bc11 100644 --- a/uniapp/pages.json +++ b/uniapp/pages.json @@ -131,6 +131,15 @@ "backgroundColor": "#f2fef7" } }, + { + "path": "pages/member/coupons", + "style": { + "navigationBarTitleText": "优惠券中心", + "navigationStyle": "custom", + "backgroundColor": "#f2fef7", + "enablePullDownRefresh": true + } + }, { "path": "pages/favorite/index", "style": { @@ -163,6 +172,14 @@ "backgroundColor": "#f2fef7" } }, + { + "path": "pages/merchant/detail", + "style": { + "navigationBarTitleText": "店铺详情", + "navigationStyle": "custom", + "backgroundColor": "#f2fef7" + } + }, { "path": "pages/mine/profile", "style": { diff --git a/uniapp/pages/detail/detail.vue b/uniapp/pages/detail/detail.vue index d7b644a..9076bfa 100644 --- a/uniapp/pages/detail/detail.vue +++ b/uniapp/pages/detail/detail.vue @@ -144,13 +144,16 @@ - + 认证商家官方门店 - 工商资质已核验 + + 进店逛逛 + › + @@ -183,7 +186,7 @@ - + {{ merchantAddress }} @@ -1001,6 +1004,23 @@ export default { /** * 导航或复制地址 */ + /** + * 跳转至商家店铺详情主页 + */ + goShopDetail() { + const m = this.merchantInfo + const shopId = (m && (m.id || m.merchantId)) || (this.post.publisher && this.post.publisher.id) || (this.post.userId || this.post.user_id) + if (!shopId) { + uni.showToast({ title: '暂未获取到店铺信息', icon: 'none' }) + return + } + uni.navigateTo({ + url: '/pages/merchant/detail?id=' + shopId, + fail: (err) => { + console.warn('跳转商家详情失败:', err) + } + }) + }, /** * 导航前往商家门店或复制实体地址 */ @@ -1638,7 +1658,28 @@ export default { background: #ffffff; border-radius: $fc-radius-lg; padding: 24rpx; - border: 1rpx solid #e2f4ea; + border: 1rpx solid #dcf3e5; + box-shadow: 0 4rpx 16rpx rgba(0, 224, 112, 0.05); + transition: all 0.2s ease; + &:active { + transform: scale(0.995); + background: #fbfdfc; + } +} +.detail__merchant-entry { + display: flex; + align-items: center; + gap: 4rpx; +} +.detail__merchant-entry-txt { + font-size: 22rpx; + color: #04874a; + font-weight: 600; +} +.detail__merchant-entry-arrow { + font-size: 24rpx; + color: #04874a; + font-weight: 700; } .detail__merchant-badge-bar { display: flex; diff --git a/uniapp/pages/member/coupons.vue b/uniapp/pages/member/coupons.vue new file mode 100644 index 0000000..cfcb04c --- /dev/null +++ b/uniapp/pages/member/coupons.vue @@ -0,0 +1,845 @@ + + + + + diff --git a/uniapp/pages/member/index.vue b/uniapp/pages/member/index.vue index 82ba1e1..7c6a63b 100644 --- a/uniapp/pages/member/index.vue +++ b/uniapp/pages/member/index.vue @@ -1,1356 +1,2641 @@ - - - - - + + + + + + + + + + diff --git a/uniapp/pages/merchant/detail.vue b/uniapp/pages/merchant/detail.vue new file mode 100644 index 0000000..fc46377 --- /dev/null +++ b/uniapp/pages/merchant/detail.vue @@ -0,0 +1,782 @@ + + + + + diff --git a/uniapp/pages/mine/index.vue b/uniapp/pages/mine/index.vue index b3324d5..22ccd84 100644 --- a/uniapp/pages/mine/index.vue +++ b/uniapp/pages/mine/index.vue @@ -1,936 +1,938 @@ - - - - - + + + + +