s-code">
+ model_name='saleclerkinfo',
+ name='user_id',
+ field=models.CharField(blank=True, db_index=True, help_text='\u7528\u6237\u552f\u4e00\u6807\u8bc6', max_length=32, null=True, verbose_name='user_id'),
+ ),
+ migrations.AlterField(
+ model_name='saleclerkinfo',
+ name='clerk_phone',
+ field=models.CharField(blank=True, help_text='\u5e97\u5458\u8054\u7cfb\u7535\u8bdd', max_length=11, null=True, unique=True, verbose_name='clerk_phone'),
+ ),
+ migrations.AlterUniqueTogether(
+ name='saleclerkinfo',
+ unique_together=set([('clerk_phone', 'brand_id')]),
+ ),
+ migrations.AlterUniqueTogether(
+ name='maintenancemaninfo',
+ unique_together=set([('maintenance_phone', 'brand_id')]),
+ ),
+ ]
@@ -426,8 +426,9 @@ class SaleclerkInfo(BaseModelMixin, SexModelMixin): |
||
| 426 | 426 |
clerk_id = ShortUUIDField(_(u'clerk_id'), max_length=32, help_text=u'店员唯一标识', db_index=True, unique=True) |
| 427 | 427 |
clerk_name = models.CharField(_(u'clerk_name'), max_length=32, blank=True, null=True, help_text=u'店员名称') |
| 428 | 428 |
clerk_sex = models.IntegerField(_(u'clerk_sex'), choices=SexModelMixin.SEX_TUPLE, default=SexModelMixin.MALE, help_text=u'店员性别', db_index=True) |
| 429 |
- clerk_phone = models.CharField(_(u'clerk_phone'), max_length=11, blank=True, null=True, help_text=u'店员联系电话') |
|
| 429 |
+ clerk_phone = models.CharField(_(u'clerk_phone'), max_length=11, blank=True, null=True, help_text=u'店员联系电话', unique=True) |
|
| 430 | 430 |
|
| 431 |
+ user_id = models.CharField(_(u'user_id'), max_length=32, blank=True, null=True, help_text=u'用户唯一标识', db_index=True) |
|
| 431 | 432 |
unionid = models.CharField(_(u'unionid'), max_length=32, blank=True, null=True, help_text=u'微信 UnionID', db_index=True) |
| 432 | 433 |
openid = models.CharField(_(u'openid'), max_length=32, blank=True, null=True, help_text=u'微信 OpenID', db_index=True) |
| 433 | 434 |
wx_userid = models.CharField(_(u'wx_userid'), max_length=32, blank=True, null=True, help_text=u'企业微信 user_id', db_index=True) |
@@ -451,7 +452,7 @@ class SaleclerkInfo(BaseModelMixin, SexModelMixin): |
||
| 451 | 452 |
verbose_name_plural = _(u'经销商销售员信息') |
| 452 | 453 |
|
| 453 | 454 |
unique_together = ( |
| 454 |
- ('unionid', 'brand_id'),
|
|
| 455 |
+ ('clerk_phone', 'brand_id'),
|
|
| 455 | 456 |
) |
| 456 | 457 |
|
| 457 | 458 |
def __unicode__(self): |
@@ -477,6 +478,36 @@ class SaleclerkInfo(BaseModelMixin, SexModelMixin): |
||
| 477 | 478 |
|
| 478 | 479 |
data = admindata |
| 479 | 480 |
|
| 481 |
+class MaintenancemanInfo(BaseModelMixin, SexModelMixin): |
|
| 482 |
+ brand_id = models.CharField(_(u'brand_id'), max_length=32, blank=True, null=True, help_text=u'品牌唯一标识', db_index=True) |
|
| 483 |
+ brand_name = models.CharField(_(u'brand_name'), max_length=255, blank=True, null=True, help_text=u'品牌名称') |
|
| 484 |
+ |
|
| 485 |
+ user_id = models.CharField(_(u'user_id'), max_length=32, blank=True, null=True, help_text=u'用户唯一标识', db_index=True, unique=True) |
|
| 486 |
+ wx_userid = models.CharField(_(u'wx_userid'), max_length=32, blank=True, null=True, help_text=u'企业微信 user_id', db_index=True) |
|
| 487 |
+ |
|
| 488 |
+ maintenance_id = ShortUUIDField(_(u'maintenance_id'), max_length=32, help_text=u'维修员唯一标识', db_index=True, unique=True) |
|
| 489 |
+ maintenance_name = models.CharField(_(u'maintenance_name'), max_length=32, blank=True, null=True, help_text=u'维修员名称') |
|
| 490 |
+ maintenance_sex = models.IntegerField(_(u'maintenance_sex'), choices=SexModelMixin.SEX_TUPLE, default=SexModelMixin.MALE, help_text=u'维修员性别', db_index=True) |
|
| 491 |
+ maintenance_phone = models.CharField(_(u'maintenance_phone'), max_length=11, blank=True, null=True, help_text=u'维修员联系电话', unique=True) |
|
| 492 |
+ |
|
| 493 |
+ class Meta: |
|
| 494 |
+ verbose_name = _(u'维修员信息') |
|
| 495 |
+ verbose_name_plural = _(u'维修员信息信息') |
|
| 496 |
+ |
|
| 497 |
+ unique_together = ( |
|
| 498 |
+ ('maintenance_phone', 'brand_id'),
|
|
| 499 |
+ ) |
|
| 500 |
+ |
|
| 501 |
+ def __unicode__(self): |
|
| 502 |
+ return unicode(self.pk) |
|
| 503 |
+ |
|
| 504 |
+ @property |
|
| 505 |
+ def data(self): |
|
| 506 |
+ return {
|
|
| 507 |
+ 'maintenance_id': self.maintenance_id, |
|
| 508 |
+ 'maintenance_name': self.maintenance_name, |
|
| 509 |
+ 'maintenance_phone': self.maintenance_phone, |
|
| 510 |
+ } |
|
| 480 | 511 |
|
| 481 | 512 |
class BrandModelDistributorPriceInfo(BaseModelMixin): |
| 482 | 513 |
brand_id = models.CharField(_(u'brand_id'), max_length=32, blank=True, null=True, help_text=u'品牌唯一标识', db_index=True) |
@@ -1,6 +1,8 @@ |
||
| 1 | 1 |
# -*- coding: utf-8 -*- |
| 2 | 2 |
|
| 3 | 3 |
import logging |
| 4 |
+import requests |
|
| 5 |
+import json |
|
| 4 | 6 |
|
| 5 | 7 |
from django.conf import settings |
| 6 | 8 |
from django.db import transaction |
@@ -9,16 +11,17 @@ from django_logit import logit |
||
| 9 | 11 |
from django_response import response |
| 10 | 12 |
from ipaddr import client_ip |
| 11 | 13 |
from pyqywe_miniapp import get_userid |
| 14 |
+from pyqywe_token import access_token |
|
| 12 | 15 |
from pywe_storage import RedisStorage |
| 13 | 16 |
from TimeConvert import TimeConvert as tc |
| 14 | 17 |
|
| 15 | 18 |
from account.models import UserInfo |
| 19 |
+from mch.models import SaleclerkInfo, DistributorInfo, MaintenancemanInfo |
|
| 16 | 20 |
from statistic.models import RegisterStatisticInfo |
| 17 |
-from utils.error.errno_utils import ProductBrandStatusCode |
|
| 21 |
+from utils.error.errno_utils import ProductBrandStatusCode, ProductDistributorStatusCode |
|
| 18 | 22 |
from utils.redis.connect import r |
| 19 | 23 |
from utils.redis.rprofile import set_profile_info |
| 20 | 24 |
|
| 21 |
- |
|
| 22 | 25 |
WECHAT = settings.WECHAT |
| 23 | 26 |
logger = logging.getLogger('logit')
|
| 24 | 27 |
|
@@ -41,6 +44,13 @@ def qy_login_api(request): |
||
| 41 | 44 |
|
| 42 | 45 |
userid = get_userid(appid=appid, secret=secret, code=code, storage=RedisStorage(r)) |
| 43 | 46 |
|
| 47 |
+ token = access_token(appid=appid, secret=secret, storage=RedisStorage(r)) |
|
| 48 |
+ |
|
| 49 |
+ userinfo = requests.post(url='https://qyapi.weixin.qq.com/cgi-bin/user/get?access_token='+token+'&userid='+userid).text |
|
| 50 |
+ userinfo = json.loads(userinfo) |
|
| 51 |
+ |
|
| 52 |
+ mobile = userinfo.get('mobile', '')
|
|
| 53 |
+ |
|
| 44 | 54 |
# Get or Create User |
| 45 | 55 |
user, created = UserInfo.objects.select_for_update().get_or_create(appid=appid, userid=userid) |
| 46 | 56 |
|
@@ -61,10 +71,42 @@ def qy_login_api(request): |
||
| 61 | 71 |
user.user_status = UserInfo.ACTIVATED |
| 62 | 72 |
user.signup_ip = client_ip(request) |
| 63 | 73 |
user.signup_at = tc.utc_datetime() |
| 64 |
- user.is_maintenance = userid in settings.QY_MAINTENANCE_USERID |
|
| 74 |
+ user.phone = mobile |
|
| 65 | 75 |
user.save() |
| 66 | 76 |
|
| 67 | 77 |
# Store Userinfo |
| 68 | 78 |
set_profile_info(user) |
| 69 | 79 |
|
| 70 |
- return response(200, 'Mini App Login Success', u'微信小程序登录成功', user.brandata(brand_id=brand_id)) |
|
| 80 |
+ # 维修员登录 (122 维修部部门ID) |
|
| 81 |
+ if 122 in userinfo.get('department', []):
|
|
| 82 |
+ maintenance, created = MaintenancemanInfo.objects.get_or_create(brand_id=brand_id, maintenance_phone=mobile, status=True) |
|
| 83 |
+ |
|
| 84 |
+ if created: |
|
| 85 |
+ maintenance.maintenance_name = userinfo.get('name', '')
|
|
| 86 |
+ maintenance.maintenance_sex = userinfo.get('gender', 0)
|
|
| 87 |
+ maintenance.maintenance_phone = mobile |
|
| 88 |
+ maintenance.user_id = user.user_id |
|
| 89 |
+ maintenance.save() |
|
| 90 |
+ else: |
|
| 91 |
+ # 销售员登录 |
|
| 92 |
+ saleclerk, created = SaleclerkInfo.objects.get_or_create(brand_id=brand_id, clerk_phone=mobile, status=True) |
|
| 93 |
+ |
|
| 94 |
+ if created: |
|
| 95 |
+ try: |
|
| 96 |
+ distributor = DistributorInfo.objects.get(department_id__in=userinfo.get('department', []))
|
|
| 97 |
+ except: |
|
| 98 |
+ return response(ProductDistributorStatusCode.DISTRIBUTOR_NOT_FOUND) |
|
| 99 |
+ |
|
| 100 |
+ saleclerk.brand_id = brand_id |
|
| 101 |
+ saleclerk.distributor_id = distributor.distributor_id |
|
| 102 |
+ saleclerk.distributor_name = distributor.distributor_name |
|
| 103 |
+ saleclerk.clerk_name = userinfo.get('name', '')
|
|
| 104 |
+ saleclerk.sex = userinfo.get('gender', 0)
|
|
| 105 |
+ saleclerk.clerk_phone = userinfo.get('mobile', '')
|
|
| 106 |
+ saleclerk.user_id = user.user_id |
|
| 107 |
+ saleclerk.wx_userid = userid |
|
| 108 |
+ saleclerk.user_status = SaleclerkInfo.ACTIVATED |
|
| 109 |
+ saleclerk.is_auth = True |
|
| 110 |
+ saleclerk.save() |
|
| 111 |
+ |
|
| 112 |
+ return response(200, 'Mini App Login Success', u'微信小程序登录成功', user.brand_qydata(brand_id=brand_id)) |