diff --git a/custom-tab-bar/index.js b/custom-tab-bar/index.js index a0fdcf1..a456b57 100644 --- a/custom-tab-bar/index.js +++ b/custom-tab-bar/index.js @@ -79,53 +79,8 @@ Component({ } } - // 特殊处理:点击货源页面时检查登录状态和入驻状态 - if (key === 'seller' && url === 'pages/seller/index') { - console.log('点击货源页面,开始检查登录状态和入驻状态...'); - - // 首先检查登录状态 - const userId = wx.getStorageSync('userId'); - const userInfo = wx.getStorageSync('userInfo'); - - if (!userId || !userInfo) { - console.log('用户未登录,跳转到登录或入驻页面'); - wx.navigateTo({ - url: '/pages/settlement/index', - success: (res) => { - console.log('跳转到入驻页面成功:', res); - }, - fail: (err) => { - console.error('跳转到入驻页面失败:', err); - this.navigateToTabPage(url); - } - }); - } else { - // 用户已登录,检查合作商状态 - const settlementStatus = wx.getStorageSync('settlement_status'); - console.log('检查合作商状态:', settlementStatus); - - if (!settlementStatus || settlementStatus === '') { - console.log('合作商状态不存在,用户未入驻'); - wx.navigateTo({ - url: '/pages/settlement/index' - }); - } else if (settlementStatus === 'underreview') { - console.log('合作商状态为审核中,跳转到货源页面显示审核中内容'); - this.navigateToTabPage(url); - } else if (settlementStatus === 'approved' || settlementStatus === 'incooperation') { - console.log('合作商状态为审核通过,正常跳转到货源页面'); - this.navigateToTabPage(url); - } else { - console.log('其他状态,跳转到入驻页面'); - wx.navigateTo({ - url: '/pages/settlement/index' - }); - } - } - } else { - // 其他tab页面正常跳转 - this.navigateToTabPage(url) - } + // 无论是否登录,直接跳转到对应页面 + this.navigateToTabPage(url) } catch (e) { console.error('switchTab方法执行错误:', e) } diff --git a/images/你有好蛋.png b/images/你有好蛋.png new file mode 100644 index 0000000..7fd1071 Binary files /dev/null and b/images/你有好蛋.png differ diff --git a/package-lock.json b/package-lock.json index 930d2fe..0b81a79 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,9 +13,40 @@ "cors": "^2.8.5", "express": "^5.1.0", "form-data": "^4.0.4", - "mysql2": "^3.15.2" + "mysql2": "^3.15.3", + "sequelize": "^6.37.7" } }, + "node_modules/@types/debug": { + "version": "4.1.12", + "resolved": "https://registry.npmjs.org/@types/debug/-/debug-4.1.12.tgz", + "integrity": "sha512-vIChWdVG3LG1SMxEvI/AK+FWJthlrqlTu7fbrlywTkkaONwk/UAGaULXRlf8vkzFBLVm0zkMdCquhL5aOjhXPQ==", + "license": "MIT", + "dependencies": { + "@types/ms": "*" + } + }, + "node_modules/@types/ms": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/@types/ms/-/ms-2.1.0.tgz", + "integrity": "sha512-GsCCIZDE/p3i96vtEqx+7dBUGXrc7zeSK3wwPHIaRThS+9OhWIXRqzs4d6k1SVU8g91DrNRWxWUGhp5KXQb2VA==", + "license": "MIT" + }, + "node_modules/@types/node": { + "version": "24.10.1", + "resolved": "https://registry.npmjs.org/@types/node/-/node-24.10.1.tgz", + "integrity": "sha512-GNWcUTRBgIRJD5zj+Tq0fKOJ5XZajIiBroOF0yvj2bSU1WvNdYS/dn9UxwsujGW4JX06dnHyjV2y9rRaybH0iQ==", + "license": "MIT", + "dependencies": { + "undici-types": "~7.16.0" + } + }, + "node_modules/@types/validator": { + "version": "13.15.10", + "resolved": "https://registry.npmjs.org/@types/validator/-/validator-13.15.10.tgz", + "integrity": "sha512-T8L6i7wCuyoK8A/ZeLYt1+q0ty3Zb9+qbSSvrIVitzT3YjZqkTZ40IbRsPanlB4h1QB3JVL1SYCdR6ngtFYcuA==", + "license": "MIT" + }, "node_modules/accepts": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/accepts/-/accepts-2.0.0.tgz", @@ -77,35 +108,27 @@ } }, "node_modules/body-parser": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-2.2.0.tgz", - "integrity": "sha512-02qvAaxv8tp7fBa/mw1ga98OGm+eCbqzJOKoRt70sLmfEEi+jyBYVTDGfCL/k06/4EMk/z01gCe7HoCH/f2LTg==", + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-2.2.1.tgz", + "integrity": "sha512-nfDwkulwiZYQIGwxdy0RUmowMhKcFVcYXUU7m4QlKYim1rUtg83xm2yjZ40QjDuc291AJjjeSc9b++AWHSgSHw==", "license": "MIT", "dependencies": { "bytes": "^3.1.2", "content-type": "^1.0.5", - "debug": "^4.4.0", + "debug": "^4.4.3", "http-errors": "^2.0.0", - "iconv-lite": "^0.6.3", + "iconv-lite": "^0.7.0", "on-finished": "^2.4.1", "qs": "^6.14.0", - "raw-body": "^3.0.0", - "type-is": "^2.0.0" + "raw-body": "^3.0.1", + "type-is": "^2.0.1" }, "engines": { "node": ">=18" - } - }, - "node_modules/body-parser/node_modules/iconv-lite": { - "version": "0.6.3", - "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", - "integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==", - "license": "MIT", - "dependencies": { - "safer-buffer": ">= 2.1.2 < 3.0.0" }, - "engines": { - "node": ">=0.10.0" + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" } }, "node_modules/bytes": { @@ -254,6 +277,12 @@ "node": ">= 0.8" } }, + "node_modules/dottie": { + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/dottie/-/dottie-2.0.6.tgz", + "integrity": "sha512-iGCHkfUc5kFekGiqhe8B/mdaurD+lakO9txNnTvKtA6PISrw86LgqHvRzWYPyoE2Ph5aMIrCw9/uko6XHTKCwA==", + "license": "MIT" + }, "node_modules/dunder-proto": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", @@ -344,18 +373,19 @@ } }, "node_modules/express": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/express/-/express-5.1.0.tgz", - "integrity": "sha512-DT9ck5YIRU+8GYzzU5kT3eHGA5iL+1Zd0EutOmTE9Dtk+Tvuzd23VBU+ec7HPNSTxXYO55gPV/hq4pSBJDjFpA==", + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/express/-/express-5.2.1.tgz", + "integrity": "sha512-hIS4idWWai69NezIdRt2xFVofaF4j+6INOpJlVOLDO8zXGpUVEVzIYk12UUi2JzjEzWL3IOAxcTubgz9Po0yXw==", "license": "MIT", "dependencies": { "accepts": "^2.0.0", - "body-parser": "^2.2.0", + "body-parser": "^2.2.1", "content-disposition": "^1.0.0", "content-type": "^1.0.5", "cookie": "^0.7.1", "cookie-signature": "^1.2.1", "debug": "^4.4.0", + "depd": "^2.0.0", "encodeurl": "^2.0.0", "escape-html": "^1.0.3", "etag": "^1.8.1", @@ -584,28 +614,23 @@ } }, "node_modules/http-errors": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.0.tgz", - "integrity": "sha512-FtwrG/euBzaEjYeRqOgly7G0qviiXoJWnvEH2Z1plBdXgbyjv34pHTSb9zoeHMyDy33+DWy5Wt9Wo+TURtOYSQ==", + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.1.tgz", + "integrity": "sha512-4FbRdAX+bSdmo4AUFuS0WNiPz8NgFt+r8ThgNWmlrjQjt1Q7ZR9+zTlce2859x4KSXrwIsaeTqDoKQmtP8pLmQ==", "license": "MIT", "dependencies": { - "depd": "2.0.0", - "inherits": "2.0.4", - "setprototypeof": "1.2.0", - "statuses": "2.0.1", - "toidentifier": "1.0.1" + "depd": "~2.0.0", + "inherits": "~2.0.4", + "setprototypeof": "~1.2.0", + "statuses": "~2.0.2", + "toidentifier": "~1.0.1" }, "engines": { "node": ">= 0.8" - } - }, - "node_modules/http-errors/node_modules/statuses": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz", - "integrity": "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==", - "license": "MIT", - "engines": { - "node": ">= 0.8" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" } }, "node_modules/iconv-lite": { @@ -624,6 +649,15 @@ "url": "https://opencollective.com/express" } }, + "node_modules/inflection": { + "version": "1.13.4", + "resolved": "https://registry.npmjs.org/inflection/-/inflection-1.13.4.tgz", + "integrity": "sha512-6I/HUDeYFfuNCVS3td055BaXBwKYuzw7K3ExVMStBowKo9oOAMJIXIHvdyR3iboTCp1b+1i5DSkIZTcwIktuDw==", + "engines": [ + "node >= 0.4.0" + ], + "license": "MIT" + }, "node_modules/inherits": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", @@ -651,6 +685,12 @@ "integrity": "sha512-Ks/IoX00TtClbGQr4TWXemAnktAQvYB7HzcCxDGqEZU6oCmb2INHuOoKxbtR+HFkmYWBKv/dOZtGRiAjDhj92g==", "license": "MIT" }, + "node_modules/lodash": { + "version": "4.17.21", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", + "license": "MIT" + }, "node_modules/long": { "version": "5.3.2", "resolved": "https://registry.npmjs.org/long/-/long-5.3.2.tgz", @@ -732,6 +772,27 @@ "node": ">= 0.6" } }, + "node_modules/moment": { + "version": "2.30.1", + "resolved": "https://registry.npmjs.org/moment/-/moment-2.30.1.tgz", + "integrity": "sha512-uEmtNhbDOrWPFS+hdjFCBfy9f2YoyzRpwcl+DqpC6taX21FzsTLQVbMV/W7PzNSX6x/bhC1zA3c2UQ5NzH6how==", + "license": "MIT", + "engines": { + "node": "*" + } + }, + "node_modules/moment-timezone": { + "version": "0.5.48", + "resolved": "https://registry.npmjs.org/moment-timezone/-/moment-timezone-0.5.48.tgz", + "integrity": "sha512-f22b8LV1gbTO2ms2j2z13MuPogNoh5UzxL3nzNAYKGraILnbGc9NEE6dyiiiLv46DGRb8A4kg8UKWLjPthxBHw==", + "license": "MIT", + "dependencies": { + "moment": "^2.29.4" + }, + "engines": { + "node": "*" + } + }, "node_modules/ms": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", @@ -739,9 +800,9 @@ "license": "MIT" }, "node_modules/mysql2": { - "version": "3.15.2", - "resolved": "https://registry.npmjs.org/mysql2/-/mysql2-3.15.2.tgz", - "integrity": "sha512-kFm5+jbwR5mC+lo+3Cy46eHiykWSpUtTLOH3GE+AR7GeLq8PgfJcvpMiyVWk9/O53DjQsqm6a3VOOfq7gYWFRg==", + "version": "3.15.3", + "resolved": "https://registry.npmjs.org/mysql2/-/mysql2-3.15.3.tgz", + "integrity": "sha512-FBrGau0IXmuqg4haEZRBfHNWB5mUARw6hNwPDXXGg0XzVJ50mr/9hb267lvpVMnhZ1FON3qNd4Xfcez1rbFwSg==", "license": "MIT", "dependencies": { "aws-ssl-profiles": "^1.1.1", @@ -840,6 +901,12 @@ "url": "https://opencollective.com/express" } }, + "node_modules/pg-connection-string": { + "version": "2.9.1", + "resolved": "https://registry.npmjs.org/pg-connection-string/-/pg-connection-string-2.9.1.tgz", + "integrity": "sha512-nkc6NpDcvPVpZXxrreI/FOtX3XemeLl8E0qFr6F2Lrm/I8WOnaWNhIPK2Z7OHpw7gh5XJThi6j6ppgNoaT1w4w==", + "license": "MIT" + }, "node_modules/proxy-addr": { "version": "2.0.7", "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz", @@ -884,20 +951,26 @@ } }, "node_modules/raw-body": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-3.0.1.tgz", - "integrity": "sha512-9G8cA+tuMS75+6G/TzW8OtLzmBDMo8p1JRxN5AZ+LAp8uxGA8V8GZm4GQ4/N5QNQEnLmg6SS7wyuSmbKepiKqA==", + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-3.0.2.tgz", + "integrity": "sha512-K5zQjDllxWkf7Z5xJdV0/B0WTNqx6vxG70zJE4N0kBs4LovmEYWJzQGxC9bS9RAKu3bgM40lrd5zoLJ12MQ5BA==", "license": "MIT", "dependencies": { - "bytes": "3.1.2", - "http-errors": "2.0.0", - "iconv-lite": "0.7.0", - "unpipe": "1.0.0" + "bytes": "~3.1.2", + "http-errors": "~2.0.1", + "iconv-lite": "~0.7.0", + "unpipe": "~1.0.0" }, "engines": { "node": ">= 0.10" } }, + "node_modules/retry-as-promised": { + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/retry-as-promised/-/retry-as-promised-7.1.1.tgz", + "integrity": "sha512-hMD7odLOt3LkTjcif8aRZqi/hybjpLNgSk5oF5FCowfCjok6LukpN2bDX7R5wDmbgBQFn7YoBxSagmtXHaJYJw==", + "license": "MIT" + }, "node_modules/router": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/router/-/router-2.2.0.tgz", @@ -940,6 +1013,18 @@ "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", "license": "MIT" }, + "node_modules/semver": { + "version": "7.7.3", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.3.tgz", + "integrity": "sha512-SdsKMrI9TdgjdweUSR9MweHA4EJ8YxHn8DFaDisvhVlUOe4BF1tLD7GAj0lIqWVl+dPb/rExr0Btby5loQm20Q==", + "license": "ISC", + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/send": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/send/-/send-1.2.0.tgz", @@ -988,6 +1073,77 @@ "resolved": "https://registry.npmjs.org/seq-queue/-/seq-queue-0.0.5.tgz", "integrity": "sha512-hr3Wtp/GZIc/6DAGPDcV4/9WoZhjrkXsi5B/07QgX8tsdc6ilr7BFM6PM6rbdAX1kFSDYeZGLipIZZKyQP0O5Q==" }, + "node_modules/sequelize": { + "version": "6.37.7", + "resolved": "https://registry.npmjs.org/sequelize/-/sequelize-6.37.7.tgz", + "integrity": "sha512-mCnh83zuz7kQxxJirtFD7q6Huy6liPanI67BSlbzSYgVNl5eXVdE2CN1FuAeZwG1SNpGsNRCV+bJAVVnykZAFA==", + "funding": [ + { + "type": "opencollective", + "url": "https://opencollective.com/sequelize" + } + ], + "license": "MIT", + "dependencies": { + "@types/debug": "^4.1.8", + "@types/validator": "^13.7.17", + "debug": "^4.3.4", + "dottie": "^2.0.6", + "inflection": "^1.13.4", + "lodash": "^4.17.21", + "moment": "^2.29.4", + "moment-timezone": "^0.5.43", + "pg-connection-string": "^2.6.1", + "retry-as-promised": "^7.0.4", + "semver": "^7.5.4", + "sequelize-pool": "^7.1.0", + "toposort-class": "^1.0.1", + "uuid": "^8.3.2", + "validator": "^13.9.0", + "wkx": "^0.5.0" + }, + "engines": { + "node": ">=10.0.0" + }, + "peerDependenciesMeta": { + "ibm_db": { + "optional": true + }, + "mariadb": { + "optional": true + }, + "mysql2": { + "optional": true + }, + "oracledb": { + "optional": true + }, + "pg": { + "optional": true + }, + "pg-hstore": { + "optional": true + }, + "snowflake-sdk": { + "optional": true + }, + "sqlite3": { + "optional": true + }, + "tedious": { + "optional": true + } + } + }, + "node_modules/sequelize-pool": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/sequelize-pool/-/sequelize-pool-7.1.0.tgz", + "integrity": "sha512-G9c0qlIWQSK29pR/5U2JF5dDQeqqHRragoyahj/Nx4KOOQ3CPPfzxnfqFPCSB7x5UgjOgnZ61nSxz+fjDpRlJg==", + "license": "MIT", + "engines": { + "node": ">= 10.0.0" + } + }, "node_modules/serve-static": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-2.2.0.tgz", @@ -1108,6 +1264,12 @@ "node": ">=0.6" } }, + "node_modules/toposort-class": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/toposort-class/-/toposort-class-1.0.1.tgz", + "integrity": "sha512-OsLcGGbYF3rMjPUf8oKktyvCiUxSbqMMS39m33MAjLTC1DVIH6x3WSt63/M77ihI09+Sdfk1AXvfhCEeUmC7mg==", + "license": "MIT" + }, "node_modules/type-is": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/type-is/-/type-is-2.0.1.tgz", @@ -1132,17 +1294,27 @@ } }, "node_modules/type-is/node_modules/mime-types": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-3.0.1.tgz", - "integrity": "sha512-xRc4oEhT6eaBpU1XF7AjpOFD+xQmXNB5OVKwp4tqCuBpHLS/ZbBDrc07mYTDqVMg6PfxUjjNp85O6Cd2Z/5HWA==", + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-3.0.2.tgz", + "integrity": "sha512-Lbgzdk0h4juoQ9fCKXW4by0UJqj+nOOrI9MJ1sSj4nI8aI2eo1qmvQEie4VD1glsS250n15LsWsYtCugiStS5A==", "license": "MIT", "dependencies": { "mime-db": "^1.54.0" }, "engines": { - "node": ">= 0.6" + "node": ">=18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" } }, + "node_modules/undici-types": { + "version": "7.16.0", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.16.0.tgz", + "integrity": "sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw==", + "license": "MIT" + }, "node_modules/unpipe": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", @@ -1152,6 +1324,24 @@ "node": ">= 0.8" } }, + "node_modules/uuid": { + "version": "8.3.2", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", + "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", + "license": "MIT", + "bin": { + "uuid": "dist/bin/uuid" + } + }, + "node_modules/validator": { + "version": "13.15.23", + "resolved": "https://registry.npmjs.org/validator/-/validator-13.15.23.tgz", + "integrity": "sha512-4yoz1kEWqUjzi5zsPbAS/903QXSYp0UOtHsPpp7p9rHAw/W+dkInskAE386Fat3oKRROwO98d9ZB0G4cObgUyw==", + "license": "MIT", + "engines": { + "node": ">= 0.10" + } + }, "node_modules/vary": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", @@ -1161,6 +1351,15 @@ "node": ">= 0.8" } }, + "node_modules/wkx": { + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/wkx/-/wkx-0.5.0.tgz", + "integrity": "sha512-Xng/d4Ichh8uN4l0FToV/258EjMGU9MGcA0HV2d9B/ZpZB3lqQm7nkOdZdm5GhKtLLhAE7PiVQwN4eN+2YJJUg==", + "license": "MIT", + "dependencies": { + "@types/node": "*" + } + }, "node_modules/wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", diff --git a/package.json b/package.json index 06b9da7..b287628 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "cors": "^2.8.5", "express": "^5.1.0", "form-data": "^4.0.4", - "mysql2": "^3.15.2" + "mysql2": "^3.15.3", + "sequelize": "^6.37.7" } } diff --git a/pages/index/index.js b/pages/index/index.js index fea4263..6c10b09 100644 --- a/pages/index/index.js +++ b/pages/index/index.js @@ -37,8 +37,8 @@ Page({ // 选择卖家身份 async chooseSeller() { - // 先检查是否登录 - this.checkLoginAndProceed('seller'); + this.finishSetUserType('seller'); + }, // 检查登录状态并继续操作 @@ -69,6 +69,8 @@ Page({ // 处理卖家路由逻辑 async handleSellerRoute() { try { + wx.switchTab({ url: '/pages/seller/index' }); + // 查询用户信息获取partnerstatus字段 const userInfo = await API.getUserInfo(); @@ -78,23 +80,15 @@ Page({ console.log('获取到的partnerstatus:', userInfo.data.partnerstatus); - // 根据partnerstatus值控制路由跳转 - if (userInfo.data.partnerstatus === 'approved') { - // 如果为approved,则进入seller/index页面 - wx.switchTab({ url: '/pages/seller/index' }); - } else { - // 否则进入pages/settlement/index页面 - wx.navigateTo({ url: '/pages/settlement/index' }); - } - } else { - // 如果没有获取到partnerstatus,默认进入settlement页面 - console.log('未获取到partnerstatus字段'); - wx.navigateTo({ url: '/pages/settlement/index' }); } + + // 无论partnerstatus是什么,都直接进入seller/index页面 + wx.switchTab({ url: '/pages/seller/index' }); + } catch (error) { console.error('获取用户信息失败:', error); - // 出错时也进入settlement页面 - wx.navigateTo({ url: '/pages/settlement/index' }); + // 出错时也直接进入seller/index页面 + wx.switchTab({ url: '/pages/seller/index' }); } }, @@ -925,45 +919,15 @@ Page({ // 完成用户类型设置并跳转 finishSetUserType(type) { - const userId = wx.getStorageSync('userId') - - // 更新用户类型 - let users = wx.getStorageSync('users') - // 检查users是否为对象,如果不是则重新初始化为空对象 - if (typeof users !== 'object' || users === null) { - users = {} - } - // 确保userId对应的用户对象存在 - if (!users[userId]) { - users[userId] = {} - } - users[userId].type = type - wx.setStorageSync('users', users) - - // 打标签 - let tags = wx.getStorageSync('tags') - // 检查tags是否为对象,如果不是则重新初始化为空对象 - if (typeof tags !== 'object' || tags === null) { - tags = {} - } - // 确保userId对应的标签数组存在 - tags[userId] = tags[userId] || [] - // 移除已有的身份标签 - tags[userId] = tags[userId].filter(tag => !tag.startsWith('身份:')) - // 添加新的身份标签 - tags[userId].push(`身份:${type}`) - wx.setStorageSync('tags', tags) - console.log('用户类型设置完成,准备跳转到', type === 'buyer' ? '买家页面' : '卖家页面') - // 添加小延迟确保所有异步操作都完成后再跳转 + // 无论是否登录,直接跳转到对应页面 setTimeout(() => { - // 跳转到对应页面 if (type === 'buyer') { wx.switchTab({ url: '/pages/buyer/index' }) } else { - // 卖家身份需要处理partnerstatus逻辑,调用专门的方法 - this.handleSellerRoute() + // 卖家身份直接跳转到卖家页面,不需要处理partnerstatus逻辑 + wx.switchTab({ url: '/pages/seller/index' }) } }, 500) }, diff --git a/pages/profile/index.js b/pages/profile/index.js index fa0ee99..1b4fda7 100644 --- a/pages/profile/index.js +++ b/pages/profile/index.js @@ -37,7 +37,7 @@ Page({ app.globalData.userInfo = localUserInfo this.setData({ userInfo: localUserInfo, - needPhoneAuth: !localUserInfo.phoneNumber || localUserInfo.phoneNumber === '13800138000' + needPhoneAuth: !localUserInfo.phoneNumber }) } @@ -133,15 +133,6 @@ Page({ if (res.success && res.data) { const serverUserInfo = res.data - // 检查手机号是否是临时手机号 - if (serverUserInfo.phoneNumber === '13800138000') { - console.warn('服务器返回的仍是临时手机号,用户可能需要重新授权手机号') - // 可以在这里显示提示,让用户重新授权手机号 - this.setData({ - needPhoneAuth: true - }) - } - // 更新本地用户信息 const app = getApp() const updatedUserInfo = { @@ -164,14 +155,6 @@ Page({ if (res.success && res.data) { const serverUserInfo = res.data - // 检查手机号是否是临时手机号 - if (serverUserInfo.phoneNumber === '13800138000') { - console.warn('服务器返回的仍是临时手机号,用户可能需要重新授权手机号') - this.setData({ - needPhoneAuth: true - }) - } - // 更新本地用户信息 const app = getApp() const updatedUserInfo = { @@ -413,15 +396,19 @@ Page({ const hasPhoneConflict = res.phoneNumberConflict || false const isNewPhone = res.isNewPhone || true const phoneNumber = res.phoneNumber || null - - // 如果有手机号冲突且没有返回手机号,使用临时手机号 - const finalPhoneNumber = hasPhoneConflict && !phoneNumber ? '13800138000' : phoneNumber - if (finalPhoneNumber) { + // 如果有手机号冲突,直接提示用户 + if (hasPhoneConflict) { + wx.showToast({ + title: '手机号已被其他账号绑定,请更换账号后重试', + icon: 'none', + duration: 3000 + }) + } else if (phoneNumber) { // 保存手机号到用户信息 const app = getApp() const userInfo = app.globalData.userInfo || wx.getStorageSync('userInfo') || {} - userInfo.phoneNumber = finalPhoneNumber + userInfo.phoneNumber = phoneNumber // 更新本地和全局用户信息 app.globalData.userInfo = userInfo @@ -437,26 +424,16 @@ Page({ // 更新页面状态 this.setData({ - needPhoneAuth: finalPhoneNumber === '13800138000' + needPhoneAuth: false }) // 重新加载用户信息以更新UI this.loadUserInfo() - } - // 根据服务器返回的结果显示不同的提示 - if (hasPhoneConflict) { wx.showToast({ - title: '获取成功,但手机号已被其他账号绑定', - icon: 'none', - duration: 3000 - }) - } else { - wx.showToast({ - title: '手机号绑定成功', - icon: 'success' - }) - } + title: '手机号绑定成功', + icon: 'success' + }) } else { console.error('获取手机号失败:', res) wx.showToast({ @@ -464,7 +441,8 @@ Page({ icon: 'none' }) } - }) + } + }) .catch(err => { wx.hideLoading() console.error('获取手机号失败:', err) diff --git a/pages/publish/index.js b/pages/publish/index.js index a731fec..d3aec9d 100644 --- a/pages/publish/index.js +++ b/pages/publish/index.js @@ -143,27 +143,7 @@ Page({ * 生命周期函数--监听页面加载 */ onLoad(options) { - // 检查用户是否已登录 - this.checkLoginStatus(); - }, - - /** - * 检查用户登录状态 - */ - checkLoginStatus() { - const openid = wx.getStorageSync('openid'); - if (!openid) { - wx.showModal({ - title: '提示', - content: '请先登录后再发布商品', - showCancel: false, - success: (res) => { - if (res.confirm) { - wx.navigateTo({ url: '/pages/index/index' }); - } - } - }); - } + // 移除登录检查,允许直接发布商品 }, /** @@ -257,29 +237,6 @@ Page({ onPublishTap() { console.log('发布按钮点击'); - // 检查用户登录状态 - const openid = wx.getStorageSync('openid'); - const userInfo = wx.getStorageSync('userInfo'); - const userId = wx.getStorageSync('userId'); - - console.log('检查用户授权状态 - openid:', !!openid, 'userInfo:', !!userInfo, 'userId:', !!userId); - - if (!openid || !userId || !userInfo) { - console.log('用户未登录或未授权,引导重新登录'); - wx.showModal({ - title: '登录过期', - content: '请先授权登录后再发布商品', - showCancel: false, - confirmText: '去登录', - success: (res) => { - if (res.confirm) { - wx.navigateTo({ url: '/pages/index/index' }); - } - } - }); - return; - } - if (!this.validateForm()) { console.log('表单验证失败'); return; @@ -333,6 +290,8 @@ Page({ // 【终极修复】使用全局上传管理器处理上传,完全脱离页面生命周期 // 将所有数据存储到全局对象中,防止被回收 console.log('【上传前检查】存储数据到全局对象'); + // 从本地存储获取userId,如果不存在则使用默认值 + const userId = wx.getStorageSync('userId') || 'anonymous'; global.tempUploadData = { formData: formDataCopy, images: imagesCopy, @@ -519,22 +478,8 @@ Page({ setTimeout(() => { wx.hideLoading(); - if (err.needRelogin) { - wx.showModal({ - title: '登录状态失效', - content: '请重新授权登录', - showCancel: false, - success: (res) => { - if (res.confirm) { - wx.removeStorageSync('openid'); - wx.removeStorageSync('userId'); - wx.navigateTo({ url: '/pages/login/index' }); - } - } - }); - } else { - wx.showToast({ title: err.message || '发布失败,请重试', icon: 'none' }); - } + // 直接显示错误提示,不进行登录验证 + wx.showToast({ title: err.message || '发布失败,请重试', icon: 'none' }); // 清理全局临时数据 if (global.tempUploadData) { diff --git a/pages/seller/index.js b/pages/seller/index.js index f692dd8..785d0dc 100644 --- a/pages/seller/index.js +++ b/pages/seller/index.js @@ -122,15 +122,14 @@ Page({ showAuthModal: false, // 控制未授权提示弹窗显示 showOneKeyLoginModal: false, // 控制一键登录弹窗显示 pendingUserType: 'seller', // 记录用户即将选择的身份类型 - avatarUrl: '/images/default-avatar.png' // 默认头像 + avatarUrl: '/images/default-avatar.png', // 默认头像 + partnerstatus: '' // 用户入驻状态,用于显示入驻/未入驻 }, onLoad() { console.log('卖家页面onLoad开始执行'); // 移除强制登录检查,允许用户浏览货源页面 - // 只有在创建新货源时才检查登录状态 this.loadSupplies(); - // 初始化规格搜索相关数据 this.setData({ specSearchKeyword: '', @@ -138,7 +137,6 @@ Page({ filteredSpecOptions: this.data.specOptions, filteredEditSpecOptions: this.data.specOptions }); - console.log('卖家页面onLoad执行完毕'); }, @@ -315,6 +313,8 @@ Page({ onShow() { console.log('seller页面onShow开始加载') + // 获取用户入驻状态 + this.getUserStatus(); // 检查页面是否是初次加载(onLoad已调用loadSupplies) // 避免在页面初次加载时重复加载数据 if (!this.data._hasLoadedOnShow) { @@ -342,6 +342,26 @@ Page({ app.updateCurrentTab('seller'); }, + // 获取用户入驻状态 + getUserStatus() { + const openid = wx.getStorageSync('openid'); + if (openid) { + API.getUserInfo(openid) + .then(response => { + console.log('获取到的用户信息响应:', response); + // 修复:访问data字段获取用户信息 + const userInfo = response.data || {}; + console.log('处理后的用户信息:', userInfo); + this.setData({ + partnerstatus: userInfo.partnerstatus || '' + }); + }) + .catch(err => { + console.error('获取用户信息失败:', err); + }); + } + }, + // 加载货源列表并分类 - 修改为分页加载 loadSupplies() { console.log('开始加载货源数据 - 分页模式'); @@ -1189,26 +1209,12 @@ Page({ showAddSupply(e) { console.log('点击创建新货源按钮'); - // 检查登录状态 - const openid = wx.getStorageSync('openid'); - const userId = wx.getStorageSync('userId'); - - if (!openid || !userId) { - console.log('用户未登录,触发授权登录流程'); - // 显示授权弹窗 - this.setData({ - showAuthModal: true, - pendingUserType: 'seller' - }); - return; - } - // 阻止事件冒泡,防止触发父元素的点击事件 if (e && e.stopPropagation) { e.stopPropagation(); } - // 已登录,继续原有逻辑 + // 直接显示创建货源弹窗,无需登录验证 this.setData({ showImagePreview: false, showModal: true, @@ -1336,6 +1342,32 @@ Page({ }, // 添加新货源 - 先创建商品再上传图片(修复版) addSupply() { + // 检查登录状态 + const userId = wx.getStorageSync('userId'); + const openid = wx.getStorageSync('openid'); + const userInfo = wx.getStorageSync('userInfo'); + + if (!userId || !openid || !userInfo) { + console.log('用户未登录,显示登录提示'); + // 用户未登录,显示未授权提示弹窗 + wx.showModal({ + title: '登录提示', + content: '请先登录再发布商品', + showCancel: true, + confirmText: '去登录', + success: (res) => { + if (res.confirm) { + // 用户点击确定,跳转到登录页面或显示登录弹窗 + this.setData({ + showAuthModal: true, + pendingUserType: 'seller' + }); + } + } + }); + return; + } + const { name, price, minOrder, yolk, spec, region, imageUrls } = this.data.newSupply if (!name || !price || !minOrder || !yolk) { wx.showToast({ title: '请填写完整信息', icon: 'none', duration: 2000 }) @@ -1343,53 +1375,44 @@ Page({ } // 显示加载中提示 - wx.showLoading({ title: '正在创建商品...', mask: true }) - - const openid = wx.getStorageSync('openid') - console.log('当前用户openid:', openid) - // 检查openid是否存在 - if (!openid) { - console.error('openid不存在,无法上传商品到服务器') - wx.hideLoading() - wx.showModal({ - title: '登录状态异常', - content: '您的登录状态已失效,请重新登录后再尝试发布商品', - showCancel: false, - success: () => { - wx.showToast({ - title: '创建失败,请先登录', - icon: 'none', - duration: 3000 - }) + wx.showLoading({ title: '正在验证权限...', mask: true }) + + // 检查用户的partnerstatus是否为approved + API.getUserInfo(openid) + .then(response => { + const userInfoRes = response.data; + console.log('获取用户信息成功:', userInfoRes) + + // 检查partnerstatus字段 + const partnerStatus = userInfoRes.partnerstatus || 'pending' + console.log('用户合作状态:', partnerStatus) + + if (partnerStatus !== 'approved') { + throw new Error('partnerstatus_not_approved') + } + + // 第一步:先创建商品(不带图片) + const productData = { + productName: name, + price: price, // 保留原始字符串,不进行数字转换 + quantity: Number(minOrder), + grossWeight: this.data.newSupply.grossWeight && this.data.newSupply.grossWeight !== '' ? this.data.newSupply.grossWeight : "", + + yolk: yolk, + specification: spec || '', + region: region || '', // 【新增】添加地区字段 + rejectReason: '', + imageUrls: [] // 明确设置为空数组 } - }) - - this.setData({ - showModal: false, - newSupply: { name: '', price: '', minOrder: '', yolk: '', spec: '', region: '', grossWeight: '', imageUrls: [] } - }) - this.enablePageScroll() - return - } - - // 第一步:先创建商品(不带图片) - const productData = { - productName: name, - price: price, // 保留原始字符串,不进行数字转换 - quantity: Number(minOrder), - grossWeight: this.data.newSupply.grossWeight && this.data.newSupply.grossWeight !== '' ? this.data.newSupply.grossWeight : "", - - yolk: yolk, - specification: spec || '', - region: region || '', // 【新增】添加地区字段 - rejectReason: '', - imageUrls: [] // 明确设置为空数组 - } - console.log('第一步:准备创建商品,数据:', productData) + console.log('第一步:准备创建商品,数据:', productData) + + // 更新加载提示 + wx.showLoading({ title: '正在创建商品...', mask: true }) - // 调用API创建商品(不带图片) - API.publishProduct(productData) + // 调用API创建商品(不带图片) + return API.publishProduct(productData) + }) .then(res => { console.log('商品创建成功:', res) @@ -1439,39 +1462,30 @@ Page({ console.error('商品创建或图片上传失败:', err) wx.hideLoading() - // 错误处理 - if (err.needRelogin) { - console.warn('检测到需要重新登录') + // 处理权限不足的情况 + if (err.message === 'partnerstatus_not_approved') { wx.showModal({ - title: '登录状态失效', - content: '您的登录已过期,请重新授权登录', + title: '权限不足', + content: '您的合作伙伴身份尚未通过审核,请等待审核通过后再发布商品', showCancel: false, - success: (res) => { - if (res.confirm) { - wx.removeStorageSync('openid') - wx.removeStorageSync('userId') - wx.navigateTo({ url: '/pages/login/index' }) - } - } - }) - } else { - let errorMsg = '上传服务器失败' - if (err.message && err.message.includes('用户不存在')) { - errorMsg = '用户未登录,请先登录' - } else if (err.message && err.message.includes('卖家才能发布商品')) { - errorMsg = '请先在个人资料中修改用户类型为卖家' - } else if (err.message && err.message.includes('商品不存在')) { - errorMsg = '商品创建失败,无法上传图片' - } - wx.showModal({ - title: '发布失败', - content: errorMsg + '\n\n错误详情: ' + (err.message || JSON.stringify(err)), - showCancel: false, - success: () => { - this.loadSupplies() - } + confirmText: '确定' }) + return + } + + // 其他错误处理:所有错误都显示通用提示,不再跳转登录 + let errorMsg = '上传服务器失败' + if (err.message && err.message.includes('商品不存在')) { + errorMsg = '商品创建失败,无法上传图片' } + wx.showModal({ + title: '发布失败', + content: errorMsg + '\n\n错误详情: ' + (err.message || JSON.stringify(err)), + showCancel: false, + success: () => { + this.loadSupplies() + } + }) }) }, @@ -1651,6 +1665,37 @@ Page({ return; } + // 检查用户合作状态 + API.getUserInfo(openid) + .then(response => { + const userInfo = response.data; + if (userInfo.partnerstatus !== 'approved') { + wx.hideLoading(); + wx.showToast({ + title: '权限不足,无法保存商品', + icon: 'none', + duration: 3000 + }); + this.setData({ showEditModal: false }); + this.enablePageScroll(); + return Promise.reject('partnerstatus not approved'); + } + return Promise.resolve(); + }) + .catch(err => { + if (err !== 'partnerstatus not approved') { + wx.hideLoading(); + wx.showToast({ + title: '获取用户信息失败', + icon: 'none', + duration: 3000 + }); + this.setData({ showEditModal: false }); + this.enablePageScroll(); + } + return Promise.reject(err); + }) + .then(() => { // 【关键修复】准备商品数据 - 确保包含地区字段 const productData = { productName: editSupply.name, @@ -1750,6 +1795,7 @@ Page({ } }); } + }); }, // 预览图片 @@ -2144,165 +2190,209 @@ Page({ showImagePreview: false }); - const id = e.currentTarget.dataset.id - // 优先使用编辑中的商品数据 - let supply = null - - // 检查是否存在编辑中的数据 - if (this.data.editSupply && this.data.editSupply.id === id) { - supply = { ...this.data.editSupply }; - } else { - // 否则从supplies中查找 - supply = this.data.supplies.find(s => s.id === id) - } - - if (!supply) { - wx.hideLoading(); - // 恢复页面滚动 - this.enablePageScroll(); - wx.showToast({ - title: '操作失败,货源不存在', - icon: 'none', - duration: 2000 + // 登录验证 + const userId = wx.getStorageSync('userId'); + const openid = wx.getStorageSync('openid'); + const userInfo = wx.getStorageSync('userInfo'); + + if (!userId || !openid || !userInfo) { + wx.showModal({ + title: '提示', + content: '请先登录再进行商品上架操作', + showCancel: false, + success: (res) => { + if (res.confirm) { + this.setData({ showAuthModal: true }); + } + } }); return; } + + // 检查用户合作状态 + API.getUserInfo(openid) + .then(response => { + const userInfo = response.data; + if (userInfo.partnerstatus !== 'approved') { + wx.hideLoading(); + this.enablePageScroll(); + wx.showModal({ + title: '权限不足', + content: '您的合作状态尚未通过审核,暂时无法进行商品上架操作', + showCancel: false + }); + return; + } + + const id = e.currentTarget.dataset.id + // 优先使用编辑中的商品数据 + let supply = null + + // 检查是否存在编辑中的数据 + if (this.data.editSupply && this.data.editSupply.id === id) { + supply = { ...this.data.editSupply }; + } else { + // 否则从supplies中查找 + supply = this.data.supplies.find(s => s.id === id) + } - wx.showLoading({ title: '处理中...', mask: true }); - - // 判断当前货源状态,决定设置什么状态 - // 重新提交的商品应该先进入审核中 - let newStatus = 'pending_review'; // 默认审核中 - if (supply.status === 'reviewed') { - newStatus = 'published'; // 已审核通过的货源可以直接上架 - } + if (!supply) { + wx.hideLoading(); + this.enablePageScroll(); + wx.showToast({ + title: '货源信息不存在', + icon: 'none', + duration: 2000 + }); + return; + } + + wx.showLoading({ title: '处理中...', mask: true }); + + // 判断当前货源状态,决定设置什么状态 + // 重新提交的商品应该先进入审核中 + let newStatus = 'pending_review'; // 默认审核中 + if (supply.status === 'reviewed') { + newStatus = 'published'; // 已审核通过的货源可以直接上架 + } - // 同步数据到服务器数据库 - // 仅当有serverProductId时才同步到服务器 - if (supply.serverProductId) { - const openid = wx.getStorageSync('openid'); - if (openid) { - // 审核失败、隐藏、审核中或下架的货源重新提交时,调用编辑接口同步商品内容和状态 - if (supply.status === 'rejected' || supply.status === 'hidden' || supply.status === 'pending_review' || supply.status === 'sold_out') { - console.log('审核失败、隐藏、审核中或下架货源重新提交,同步商品内容和状态到服务器'); - // 准备商品数据,转换为服务器需要的格式 - const productData = { - openid: openid, - productId: supply.serverProductId, - product: { - productName: supply.name, - price: supply.price, - quantity: supply.minOrder, - grossWeight: supply.grossWeight || "", - yolk: supply.yolk, - specification: supply.spec, - resubmit: true // 关键参数:告诉服务器这是重新提交审核 - }, - status: newStatus // 明确传递状态参数,确保变为审核中状态 - }; + // 同步数据到服务器数据库 + // 仅当有serverProductId时才同步到服务器 + if (supply.serverProductId) { + const openid = wx.getStorageSync('openid'); + if (openid) { + // 审核失败、隐藏、审核中或下架的货源重新提交时,调用编辑接口同步商品内容和状态 + if (supply.status === 'rejected' || supply.status === 'hidden' || supply.status === 'pending_review' || supply.status === 'sold_out') { + console.log('审核失败、隐藏、审核中或下架货源重新提交,同步商品内容和状态到服务器'); + // 准备商品数据,转换为服务器需要的格式 + const productData = { + openid: openid, + productId: supply.serverProductId, + product: { + productName: supply.name, + price: supply.price, + quantity: supply.minOrder, + grossWeight: supply.grossWeight || "", + yolk: supply.yolk, + specification: supply.spec, + resubmit: true // 关键参数:告诉服务器这是重新提交审核 + }, + status: newStatus // 明确传递状态参数,确保变为审核中状态 + }; - console.log('准备发送商品编辑请求 - URL:', API.BASE_URL + '/api/product/edit'); - console.log('准备发送的商品数据:', productData); - // 调用编辑商品接口,该接口会自动设置状态为pending_review - wx.request({ - url: API.BASE_URL + '/api/product/edit', - method: 'POST', - data: productData, - success: (res) => { - console.log('商品内容和状态同步成功:', res); - // 重新加载数据以更新UI - this.loadSupplies(); - }, - fail: (err) => { - console.error('商品内容和状态同步失败:', err); - // 重新加载数据以更新UI - this.loadSupplies(); - }, - complete: () => { - // 确保在请求完成后隐藏loading并显示提示 - try { - wx.hideLoading(); - // 恢复页面滚动 - this.enablePageScroll(); - wx.showToast({ - title: newStatus === 'published' ? '上架成功' : '重新提交成功,等待审核', - duration: 2000 - }); - } catch (e) { - console.error('显示提示时出错:', e); - // 确保即使在错误情况下也隐藏loading并恢复滚动 - try { - wx.hideLoading(); - this.enablePageScroll(); - } catch (innerErr) { - console.error('隐藏loading时出错:', innerErr); + console.log('准备发送商品编辑请求 - URL:', API.BASE_URL + '/api/product/edit'); + console.log('准备发送的商品数据:', productData); + // 调用编辑商品接口,该接口会自动设置状态为pending_review + wx.request({ + url: API.BASE_URL + '/api/product/edit', + method: 'POST', + data: productData, + success: (res) => { + console.log('商品内容和状态同步成功:', res); + // 重新加载数据以更新UI + this.loadSupplies(); + }, + fail: (err) => { + console.error('商品内容和状态同步失败:', err); + // 重新加载数据以更新UI + this.loadSupplies(); + }, + complete: () => { + // 确保在请求完成后隐藏loading并显示提示 + try { + wx.hideLoading(); + // 恢复页面滚动 + this.enablePageScroll(); + wx.showToast({ + title: newStatus === 'published' ? '上架成功' : '重新提交成功,等待审核', + duration: 2000 + }); + } catch (e) { + console.error('显示提示时出错:', e); + // 确保即使在错误情况下也隐藏loading并恢复滚动 + try { + wx.hideLoading(); + this.enablePageScroll(); + } catch (innerErr) { + console.error('隐藏loading时出错:', innerErr); + } + } } - } - } - }); - return; // 异步操作,稍后再继续执行 - } else { - // 其他情况只更新状态 - wx.request({ - url: API.BASE_URL + '/api/product/review', - method: 'POST', - data: { - openid: openid, - productId: supply.serverProductId, - status: newStatus - }, - success: () => { - this.loadSupplies(); - }, - fail: (err) => { - console.error('更新状态失败:', err); - this.loadSupplies(); - }, - complete: () => { - try { - wx.hideLoading(); - // 恢复页面滚动 - this.enablePageScroll(); - wx.showToast({ - title: newStatus === 'published' ? '上架成功' : '重新提交成功,等待审核', - duration: 2000 - }); - } catch (e) { - console.error('显示提示时出错:', e); - // 确保即使在错误情况下也隐藏loading并恢复滚动 - try { - wx.hideLoading(); - this.enablePageScroll(); - } catch (innerErr) { - console.error('隐藏loading时出错:', innerErr); + }); + return; // 异步操作,稍后再继续执行 + } else { + // 其他情况只更新状态 + wx.request({ + url: API.BASE_URL + '/api/product/review', + method: 'POST', + data: { + openid: openid, + productId: supply.serverProductId, + status: newStatus + }, + success: () => { + this.loadSupplies(); + }, + fail: (err) => { + console.error('更新状态失败:', err); + this.loadSupplies(); + }, + complete: () => { + try { + wx.hideLoading(); + // 恢复页面滚动 + this.enablePageScroll(); + wx.showToast({ + title: newStatus === 'published' ? '上架成功' : '重新提交成功,等待审核', + duration: 2000 + }); + } catch (e) { + console.error('显示提示时出错:', e); + // 确保即使在错误情况下也隐藏loading并恢复滚动 + try { + wx.hideLoading(); + this.enablePageScroll(); + } catch (innerErr) { + console.error('隐藏loading时出错:', innerErr); + } + } } - } + }); + return; // 异步操作,稍后再继续执行 } + } else { + // 没有openid时的处理 + wx.hideLoading(); + // 恢复页面滚动 + this.enablePageScroll(); + wx.showToast({ + title: '登录状态异常,请重新登录', + icon: 'none', + duration: 2000 + }); + } + } else { + // 如果没有serverProductId,提示用户 + wx.hideLoading(); + // 恢复页面滚动 + this.enablePageScroll(); + wx.showToast({ + title: '无法上架,商品未上传到服务器', + icon: 'none', + duration: 2000 }); - return; // 异步操作,稍后再继续执行 } - } else { - // 没有openid时的处理 + }) + .catch(err => { + console.error('获取用户信息失败:', err); wx.hideLoading(); - // 恢复页面滚动 this.enablePageScroll(); wx.showToast({ - title: '登录状态异常,请重新登录', + title: '获取用户信息失败', icon: 'none', duration: 2000 }); - } - } else { - // 如果没有serverProductId,提示用户 - wx.hideLoading(); - // 恢复页面滚动 - this.enablePageScroll(); - wx.showToast({ - title: '无法上架,商品未上传到服务器', - icon: 'none', - duration: 2000 }); - } }, // 下架货源 - 移除本地存储操作 @@ -3329,5 +3419,43 @@ Page({ } } }); + }, + + // 入驻申请 + applyForSettlement() { + const openid = wx.getStorageSync('openid'); + if (openid) { + API.getUserInfo(openid) + .then(response => { + console.log('获取到的用户信息:', response); + const userInfo = response.data; + const partnerstatus = userInfo.partnerstatus || ''; + if (partnerstatus === 'approved') { + // 如果已经审核通过,显示提示 + wx.showToast({ + title: '您已成功入驻', + icon: 'success', + duration: 2000 + }); + } else { + // 否则进入入驻页面 + wx.navigateTo({ + url: '/pages/settlement/index' + }); + } + }) + .catch(err => { + console.error('获取用户信息失败:', err); + // 获取失败时,默认进入入驻页面 + wx.navigateTo({ + url: '/pages/settlement/index' + }); + }); + } else { + // 未登录时,直接进入入驻页面 + wx.navigateTo({ + url: '/pages/settlement/index' + }); + } } }) diff --git a/pages/seller/index.wxml b/pages/seller/index.wxml index 8d86685..2c5cb80 100644 --- a/pages/seller/index.wxml +++ b/pages/seller/index.wxml @@ -2,13 +2,24 @@ style="align-items: flex-start; padding: 20rpx; width: 100%; max-width: 100vw; overflow-x: hidden; position: relative; box-sizing: border-box;" catchtouchmove="{{touchMoveBlocked ? 'preventTouchMove' : ''}}"> - 我的鸡蛋货源 - + 我的货源 + + + + {{partnerstatus === 'approved' ? '已入驻' : '未入驻'}} + + + diff --git a/pages/seller/index.wxss b/pages/seller/index.wxss index 88d76bd..7c08cb3 100644 --- a/pages/seller/index.wxss +++ b/pages/seller/index.wxss @@ -69,6 +69,40 @@ 0 1rpx 0 rgba(255, 255, 255, 0.3) inset; } +/* 服务区域容器 */ +.service-container { + display: flex; + align-items: center; + gap: 20rpx; +} + +/* 未入驻状态样式 */ +.no-settlement-status { + font-size: 24rpx; + color: #ff4d4f; + padding: 0 10rpx; +} + +/* 入驻按钮样式 */ +.apply-settlement-btn { + background: #1677ff; + color: white; + font-size: 28rpx; + padding: 10rpx 20rpx; + border-radius: 8rpx; + border: none; + box-shadow: none; + transition: all 0.2s ease; + min-width: 100rpx; + text-align: center; +} + +.apply-settlement-btn:active { + background: #4096ff; + transform: none; + box-shadow: none; +} + /* 登录授权弹窗样式 - 专门用于登录相关弹窗 */ .auth-modal-overlay { position: fixed; diff --git a/pages/settlement/index.js b/pages/settlement/index.js index 137250b..ddf62d8 100644 --- a/pages/settlement/index.js +++ b/pages/settlement/index.js @@ -1,4 +1,5 @@ // pages/settlement/settlement.js +const API = require('../../utils/api.js'); Page({ data: { // 是否显示引导页 @@ -56,6 +57,8 @@ Page({ currentStep: 3, partnerstatus: options.status }); + // 同步服务器状态,确保显示最新状态 + this.syncSettlementStatus(); return; // 直接返回,不执行后续逻辑 } } @@ -90,6 +93,9 @@ Page({ } }, 500); } + + // 同步服务器状态,确保显示最新的partnerstatus + this.syncSettlementStatus(); }, onUnload() { @@ -99,6 +105,7 @@ Page({ } }, + // 加载入驻进度 loadSettlementProgress() { const settlementData = wx.getStorageSync('settlement_data'); @@ -172,23 +179,8 @@ Page({ console.log('开始入驻流程'); try { - // 检查登录状态 - const userId = wx.getStorageSync('userId'); - const userInfo = wx.getStorageSync('userInfo'); - - if (!userId || !userInfo) { - console.log('用户未登录,显示登录弹窗'); - this.setData({ - showAuthModal: true, - loginModalTitle: '请先登录', - loginModalContent: '为了您的账户安全,请先完成手机号登录', - showLoginButton: true - }); - return; - } - // 检查数据库中是否存在入驻信息 - console.log('用户已登录,检查入驻信息'); + console.log('检查入驻信息'); await this.syncSettlementStatus(); // 根据入驻状态处理 @@ -504,13 +496,20 @@ Page({ // 检查用户是否已登录 const openid = wx.getStorageSync('openid'); const userId = wx.getStorageSync('userId'); - console.log('检查用户登录状态,openid:', openid); - if (!openid) { - console.log('用户未登录,调用首页授权登录'); - this.goToAuthLogin(); - return; + // 如果未登录,显示登录弹窗 + if (!openid || !userId) { + console.log('用户未登录,显示授权弹窗'); + // 保存当前表单数据 + this.saveSettlementProgress(); + // 显示登录弹窗 + this.setData({ + showAuthModal: true + }); + return; // 取消提交申请 } + + console.log('使用已登录用户信息提交申请:', openid, userId); // 先上传所有文件 wx.showLoading({ @@ -662,18 +661,10 @@ Page({ return; } + // 手机号为空时使用默认值,不再强制要求 if (!contactPhone) { - wx.showToast({ - title: '请先完成手机号授权', - icon: 'none' - }); - // 显示授权弹窗 - this.setData({ - showAuthModal: true, - loginModalTitle: '请完成手机号授权', - loginModalContent: '入驻申请需要您的手机号信息,请完成授权' - }); - return; + contactPhone = 'default_phone'; + console.log('使用默认手机号:', contactPhone); } // 验证省市区字段是否填写完整(用于构建region字段) @@ -747,20 +738,25 @@ Page({ wx.setStorageSync('applicationId', appId); } - this.setData({ - partnerstatus: 'underreview', // 使用数据库字段名 (原auditStatus) - applicationId: appId - }); - wx.showToast({ title: '提交成功,等待审核', icon: 'none', duration: 2000 }); - // 跳转到审核状态页面 + // 跳转到审核状态页面 - 立即执行 this.setData({ - currentStep: 3 // 设置为第4步(审核状态页面) + currentStep: 3, // 设置为第4步(审核状态页面) + partnerstatus: 'underreview', // 使用数据库字段名 (原auditStatus) + applicationId: appId + }); + + // 调用API获取用户完整数据 - 异步执行,不影响跳转 + const API = require('../../utils/api.js'); + API.getUserInfo().then(userRes => { + console.log('用户完整数据:', userRes.data); + }).catch(err => { + console.error('获取用户数据失败:', err); }); // 清除进度数据,因为已经提交了 @@ -962,23 +958,24 @@ Page({ // 撤回备案 async withdrawApplication() { + // 检查用户是否已登录 + const openid = wx.getStorageSync('openid'); + if (!openid) { + console.log('用户未登录,显示授权弹窗'); + // 显示登录弹窗 + this.setData({ + showAuthModal: true + }); + return; // 取消撤回申请 + } + wx.showModal({ title: '确认撤回', content: '确定要撤回备案申请吗?撤回后可以重新提交。', success: async (res) => { if (res.confirm) { try { - // 获取用户的openid - const openid = wx.getStorageSync('openid'); - console.log('准备撤回申请,openid:', openid); - - if (!openid) { - wx.showToast({ - title: '请先登录', - icon: 'none' - }); - return; - } + console.log('使用已登录用户openid撤回申请:', openid); // 调用API撤回申请,不再需要applicationId,只需要用户openid const API = require('../../utils/api.js'); @@ -1022,15 +1019,49 @@ Page({ // 审核中我知道了 knowAudit() { - // 直接返回首页,不显示提示 - wx.reLaunch({ - url: '/pages/index/index' + // 获取用户openid + const openid = wx.getStorageSync('openid'); + console.log('使用openid获取用户数据:', openid); + + // 调用API获取用户完整数据 + API.getUserInfo(openid).then(res => { + console.log('用户完整数据:', res.data); + + // 更新本地状态 + if (res.data && res.data.partnerstatus) { + wx.setStorageSync('settlementStatus', res.data.partnerstatus); + this.setData({ + partnerstatus: res.data.partnerstatus + }); + } + + // 跳转到seller页面,不显示提示 + wx.reLaunch({ + url: '/pages/seller/index' + }); + }).catch(err => { + console.error('获取用户数据失败:', err); + // 即使获取失败也跳转到seller页面 + wx.reLaunch({ + url: '/pages/seller/index' + }); }); }, // 重新提交备案 async resubmitApplication() { try { + // 检查用户是否已登录 + const openid = wx.getStorageSync('openid'); + if (!openid) { + console.log('用户未登录,显示授权弹窗'); + // 显示登录弹窗 + this.setData({ + showAuthModal: true + }); + return; // 取消重新提交申请 + } + const API = require('../../utils/api.js'); const applicationId = wx.getStorageSync('applicationId'); @@ -1055,7 +1086,9 @@ Page({ // 更新本地状态 wx.setStorageSync('settlementStatus', 'underreview'); + // 确保页面显示审核状态页面 this.setData({ + currentStep: 3, // 确保显示审核状态页面 partnerstatus: 'underreview' // 使用数据库字段名 (原auditStatus) }); @@ -1089,9 +1122,11 @@ Page({ icon: 'success' }); - // 延迟返回上一页 + // 延迟跳转到seller页面 setTimeout(() => { - wx.navigateBack(); + wx.reLaunch({ + url: '/pages/seller/index' + }); }, 1500); }, @@ -1127,35 +1162,39 @@ Page({ // 从服务器同步入驻状态 async syncSettlementStatus() { try { - const userId = wx.getStorageSync('userId'); - - if (!userId) { - console.log('用户未登录,跳过状态同步'); + // 获取用户openid + const openid = wx.getStorageSync('openid'); + if (!openid) { + console.log('未登录,无法同步入驻状态'); return; } + + console.log('使用openid同步状态:', openid); - const API = require('../../utils/api.js'); - const result = await API.getSettlementStatus(userId); + const result = await API.getUserInfo(openid); if (result && result.success && result.data) { - const serverData = result.data; + const userData = result.data; // 更新本地状态 wx.setStorageSync('hasSubmittedSettlement', true); // 只有在有实际状态值时才设置,避免空值时默认为审核中 - wx.setStorageSync('settlementStatus', serverData.partnerstatus || ''); - - if (serverData.id) { - wx.setStorageSync('applicationId', serverData.id); - } + wx.setStorageSync('settlementStatus', userData.partnerstatus || ''); // 更新页面状态 this.setData({ - partnerstatus: serverData.partnerstatus || '', // 使用数据库字段名 (原auditStatus),不设置默认值 - applicationId: serverData.id + partnerstatus: userData.partnerstatus || '', // 使用数据库字段名,不设置默认值 }); - console.log('已同步服务器入驻状态:', serverData.partnerstatus); + console.log('已同步服务器入驻状态:', userData.partnerstatus); + + // 根据partnerstatus更新页面步骤 + if (userData.partnerstatus === 'approved') { + this.setData({ + showGuidePage: false, + currentStep: 3 + }); + } } } catch (error) { console.error('同步入驻状态失败:', error); diff --git a/pages/settlement/index.wxml b/pages/settlement/index.wxml index d4de856..16e5bdb 100644 --- a/pages/settlement/index.wxml +++ b/pages/settlement/index.wxml @@ -1,17 +1,4 @@ - - - - - 已入住供应商 - - 四川又鸟蛋 - 蛋小满贸易 - ... - - 我们等待您的加入! - - diff --git a/pages/settlement/index.wxss b/pages/settlement/index.wxss index 7877adb..2eae155 100644 --- a/pages/settlement/index.wxss +++ b/pages/settlement/index.wxss @@ -1694,58 +1694,4 @@ picker { color: #999; margin-top: 24rpx; line-height: 1.4; -} - -/* 供应商展示区域样式 */ -.supplier-showcase { - background-color: #fff; - border-radius: 12rpx; - margin: 20rpx; - padding: 30rpx; - box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05); - display: flex; - flex-direction: column; - align-items: center; -} - -.supplier-image { - width: 600rpx; - height: 300rpx; - margin-bottom: 20rpx; - border-radius: 8rpx; -} - -.supplier-text { - text-align: center; - width: 100%; -} - -.supplier-title { - font-size: 32rpx; - font-weight: bold; - color: #333; - margin-bottom: 20rpx; -} - -.supplier-list { - display: flex; - justify-content: center; - flex-wrap: wrap; - margin-bottom: 20rpx; -} - -.supplier-item { - font-size: 28rpx; - color: #666; - margin: 0 20rpx 10rpx 0; - padding: 8rpx 20rpx; - background-color: #f0f0f0; - border-radius: 20rpx; -} - -.supplier-invite { - font-size: 30rpx; - color: #ff6b35; - font-weight: bold; - margin-top: 10rpx; } \ No newline at end of file