|
@@ -23,13 +23,14 @@ class UserService extends CrudService {
|
|
|
async beforeCreate(data) {
|
|
|
const openid = _.get(data, 'openid');
|
|
|
const phone = _.get(data, 'phone');
|
|
|
+ const shop = _.get(data, 'shop');
|
|
|
if (!openid && phone) {
|
|
|
const num = await this.model.count({ phone });
|
|
|
if (num > 0) throw new BusinessError(ErrorCode.DATA_EXISTED, '该手机号已注册');
|
|
|
- } else if (openid) {
|
|
|
- const num = await this.model.count({ openid });
|
|
|
+ } else if (openid && shop) {
|
|
|
+ const num = await this.model.count({ openid, shop });
|
|
|
if (num > 0) throw new BusinessError(ErrorCode.DATA_EXISTED, '该微信号已注册');
|
|
|
- }
|
|
|
+ } else throw new BusinessError(ErrorCode.BADPARAM, '参数不正确');
|
|
|
return data;
|
|
|
}
|
|
|
|
|
@@ -67,10 +68,11 @@ class UserService extends CrudService {
|
|
|
* 微信登录
|
|
|
* @param {Object} body 登陆参数
|
|
|
* @param body.openid 微信小程序的openid
|
|
|
+ * @param body.shop 店铺id
|
|
|
*/
|
|
|
- async wxLogin({ openid }) {
|
|
|
+ async wxLogin({ openid, shop }) {
|
|
|
const { populate } = this.getRefMods();
|
|
|
- const user = await this.model.findOne({ openid }).populate(populate);
|
|
|
+ const user = await this.model.findOne({ openid, shop }).populate(populate);
|
|
|
if (!user) throw new BusinessError(ErrorCode.USER_NOT_EXIST);
|
|
|
const { status } = user;
|
|
|
if (status !== '0') throw new BusinessError(ErrorCode.USER_NOT_BIND, '该账号处于禁止使用状态');
|