This commit is contained in:
caoqianming 2020-12-24 21:51:29 +08:00
commit 2273912824
6 changed files with 73 additions and 24 deletions

View File

@ -35,20 +35,23 @@
:tree-props="{children: 'children', hasChildren: 'hasChildren'}" :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
@selection-change="handleSelectionChange" @selection-change="handleSelectionChange"
> >
<el-table-column type="selection" width="50"></el-table-column> <el-table-column type="selection" width="40"></el-table-column>
<el-table-column label="单位名称"> <el-table-column label="单位名称">
<template slot-scope="scope">{{ scope.row.name }}</template> <template slot-scope="scope">{{ scope.row.name }}</template>
</el-table-column> </el-table-column>
<el-table-column label="所在地区">
<template slot-scope="scope" v-if="scope.row.geo">
<span v-if="scope.row.geo.pname">{{ scope.row.geo.pname }}</span>
<span v-if="scope.row.geo.cityname">/{{ scope.row.geo.cityname }}</span>
<span v-if="scope.row.geo.adname">/{{ scope.row.geo.adname }}</span>
</template>
</el-table-column>
<el-table-column label="创建日期"> <el-table-column label="创建日期">
<template slot-scope="scope"> <template slot-scope="scope">
<span>{{ scope.row.create_time }}</span> <span>{{ scope.row.create_time }}</span>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="所在地区">
<template slot-scope="scope" v-if="scope.row.geo">
<span>{{ scope.row.geo.province }}</span>
</template>
</el-table-column>
<el-table-column label="所属"> <el-table-column label="所属">
<template slot-scope="scope"> <template slot-scope="scope">
<span>{{ scope.row.create_admin_name }}</span> <span>{{ scope.row.create_admin_name }}</span>

View File

@ -69,9 +69,9 @@ App({
globalData: { globalData: {
userInfo: {}, userInfo: {},
userinfo: {}, // 服务器传回的消费者信息 userinfo: {}, // 服务器传回的消费者信息
//host: 'https://apitest.ahctc.cn', host: 'https://apitest.ahctc.cn',
mediahost: 'https://apitest.ahctc.cn', mediahost: 'https://apitest.ahctc.cn',
host: 'http://127.0.0.1:8000', //host: 'http://127.0.0.1:8000',
//mediahost: 'http://127.0.0.1:8000', //mediahost: 'http://127.0.0.1:8000',
token : '', token : '',
} }

View File

@ -8,7 +8,8 @@
<span style="color:gray">({{tm_current.question.questioncat_name}})</span> <span style="color:gray">({{tm_current.question.questioncat_name}})</span>
</view> </view>
<view class="weui-article__title"> <view class="weui-article__title">
<parser html="{{tm_current.question.name}}" domain="{{domain}}" selectable/> <!-- <parser html="{{tm_current.question.name}}" domain="{{domain}}" selectable/> -->
<rich-text nodes="{{tm_current.question.name}}"></rich-text>
</view> </view>
<view wx:if="{{tm_current.img}}" style="text-align:center"><image src="{{tm_current.img}}" mode="aspectFit"></image></view> <view wx:if="{{tm_current.img}}" style="text-align:center"><image src="{{tm_current.img}}" mode="aspectFit"></image></view>
</view> </view>

View File

@ -25,7 +25,7 @@
"disablePlugins": [], "disablePlugins": [],
"outputPath": "" "outputPath": ""
}, },
"useCompilerModule": true, "useCompilerModule": false,
"userConfirmedUseCompilerModuleSwitch": false, "userConfirmedUseCompilerModuleSwitch": false,
"compileHotReLoad": false, "compileHotReLoad": false,
"useMultiFrameRuntime": false, "useMultiFrameRuntime": false,

View File

@ -101,9 +101,10 @@ class Companydis(APIView):
""" """
def get(self, request, format=None): def get(self, request, format=None):
ret = {'s':[], 't':'单位分布', 'max':300, 'min':0} ret = {'s':[], 't':'单位分布', 'max':300, 'min':0}
tmp = Company.objects.exclude(geo__isnull=True).values('geo__province').annotate(total=Count('geo__province')) tmp = Company.objects.exclude(geo__pname__isnull=True).values('geo__pname').annotate(total=Count('geo__pname'))
for i in tmp: for i in tmp:
ret['s'].append({'name':nameMap[i['geo__province']], 'value':i['total']}) if i['geo__pname'] in nameMap:
ret['s'].append({'name':nameMap[i['geo__pname']], 'value':i['total']})
return Response(ret) return Response(ret)
class Consumerdis(APIView): class Consumerdis(APIView):
@ -112,9 +113,10 @@ class Consumerdis(APIView):
""" """
def get(self, request, format=None): def get(self, request, format=None):
ret = {'s':[], 't':'学员分布', 'max':600, 'min':0} ret = {'s':[], 't':'学员分布', 'max':600, 'min':0}
tmp = Consumer.objects.exclude(company__geo__isnull=True).values('company__geo__province').annotate(total=Count('company__geo__province')) tmp = Consumer.objects.exclude(company__geo__pname__isnull=True).values('company__geo__pname').annotate(total=Count('company__geo__pname'))
for i in tmp: for i in tmp:
ret['s'].append({'name':nameMap[i['company__geo__province']], 'value':i['total']}) if i['company__geo__pname'] in nameMap:
ret['s'].append({'name':nameMap[i['company__geo__pname']], 'value':i['total']})
return Response(ret) return Response(ret)
class Quota(APIView): class Quota(APIView):
''' '''

View File

@ -91,14 +91,40 @@ class ConsumerPermViewSet(ModelViewSet):
ordering_fields = ['create_time'] ordering_fields = ['create_time']
ordering = ['-create_time'] ordering = ['-create_time']
keys1 = ['86e0993305a427ac2d0b5371ad97f242']
def getPosition(address): def getPosition(name):
url = 'http://restapi.amap.com/v3/geocode/geo' # 高德接口
par = {'address': address, 'key': '86e0993305a427ac2d0b5371ad97f242'} url = 'http://restapi.amap.com/v3/place/text'
par = {'keywords': name, 'key': keys1[0]}
res = requests.get(url, par) res = requests.get(url, par)
json_data = json.loads(res.text) json_data = json.loads(res.text)
fdata = {}
if json_data['status'] == '1' and int(json_data['count']) > 0: if json_data['status'] == '1' and int(json_data['count']) > 0:
return json_data['geocodes'][0] alldata = json_data['pois'][0]
fdata['cname'] = '中国'
fdata['pname'] = alldata['pname']
fdata['cityname'] = alldata['cityname']
fdata['adname'] = alldata['adname']
fdata['address'] = alldata['address']
return fdata
return None
keys2 = ['v31TjiNQoCCF1PwDVWU43yUjSoyQSdmj']
def getPosition2(name):
# 百度接口
url = 'http://api.map.baidu.com/place/v2/search'
par = {'query': name, 'ak': keys2[0], 'region':'全国', 'output':'json'}
res = requests.get(url, par)
json_data = json.loads(res.text)
fdata = {}
if len(json_data['results'])> 0 and 'province' in json_data['results'][0]:
alldata = json_data['results'][0]
fdata['cname'] = '中国'
fdata['pname'] = alldata['province']
fdata['cityname'] = alldata['city']
fdata['adname'] = alldata['area']
fdata['address'] = alldata['address'] if 'address' in alldata else ''
return fdata
return None return None
class CompanyViewSet(ModelViewSet): class CompanyViewSet(ModelViewSet):
@ -118,14 +144,22 @@ class CompanyViewSet(ModelViewSet):
def perform_create(self, serializer): def perform_create(self, serializer):
instance = serializer.save(create_admin=self.request.user) instance = serializer.save(create_admin=self.request.user)
geo = getPosition(instance.name) geo = None
try:
geo = getPosition2(instance.name)
except:
pass
if geo: if geo:
instance.geo = geo instance.geo = geo
instance.save() instance.save()
def perform_update(self, serializer): def perform_update(self, serializer):
instance = serializer.save() instance = serializer.save()
geo = getPosition(instance.name) geo = None
try:
geo = getPosition2(instance.name)
except:
pass
if geo: if geo:
instance.geo = geo instance.geo = geo
instance.save() instance.save()
@ -175,12 +209,17 @@ class CompanyViewSet(ModelViewSet):
""" """
地理位置 地理位置
""" """
companys = Company.objects.filter(geo__isnull=True).order_by('-create_time') companys = Company.objects.filter(geo__pname__isnull=True).order_by('-create_time')
for i in companys: for i in companys:
geo = getPosition(i.name) geo = None
try:
geo = getPosition2(i.name)
except:
pass
if geo: if geo:
i.geo = geo i.geo = geo
i.save() i.save()
print(str(i.id) + '-' + i.name + '-ok')
return Response(status=status.HTTP_200_OK) return Response(status=status.HTTP_200_OK)
@ -419,7 +458,11 @@ class ConsumerViewSet(ModelViewSet):
companyobj = Company.objects.get(name=companyname) companyobj = Company.objects.get(name=companyname)
else: else:
companyobj = Company.objects.create(name=companyname, create_admin=request.user) companyobj = Company.objects.create(name=companyname, create_admin=request.user)
geo = getPosition(companyobj.name) geo = None
try:
geo = getPosition2(companyobj.name)
except:
pass
if geo: if geo:
companyobj.geo = geo companyobj.geo = geo
companyobj.save() companyobj.save()