#!/usr/bin/env python
# -*- coding: utf-8 -*-

import pymysql
import json
from flask import Flask, render_template, request
from flask_cors import CORS





def getData(sql):
    connection = pymysql.connect(host='47.95.76.74', port=3306, user='root', passwd='Gongsibao2018', db='gsb_license',charset='utf8')
    cur = connection.cursor()
    cur.execute(sql)
    connection.commit()
    connection.close()
    return

# 服务器接口API
def phone(app):
    @app.route('/gsb/api/phone_number', methods = ['POST'])
    #写入支付表和订单详情表
    def Ent_mobile():
        try:
            ent_company_mobile_data = request.get_json()
            print(ent_company_mobile_data)
            phone= ent_company_mobile_data['mobile']
            company = ent_company_mobile_data['enterprise']
            id = ent_company_mobile_data['id']
            ent_company_mobile_sql='insert into ent_company_mobile (\
            server_id, \
            mobile, \
            company_name ) values ("%s","%s","%s")'\
                    %(id,phone,company)
            getData(ent_company_mobile_sql)
            if True:
                return json.dumps({"status": 0, "msg": "成功", "data": {}}, ensure_ascii=False)
            else:
                return json.dumps({"status": -1, "msg": "返回数据为空", "data": {}}, ensure_ascii=False)
        except Exception as e:
            return json.dumps({"status": -1, "msg":"调用服务出错","data": {e}}, ensure_ascii=False)

