예제 #1
0
 def __init__(self):
     from SharpGoods.service.SCarts import SCarts
     self.scarts = SCarts()
     from SharpGoods.service.SProduct import SProduct
     self.sproduct = SProduct()
     from SharpGoods.service.SUsers import SUsers
     self.suser = SUsers()
예제 #2
0
 def __init__(self):
     self.service_review = SReview()
     from SharpGoods.service.SOrders import SOrders
     self.sorder = SOrders()
     from SharpGoods.service.SProduct import SProduct
     self.sproduct = SProduct()
     from SharpGoods.service.SUsers import SUsers
     self.suser = SUsers()
예제 #3
0
 def __init__(self):
     from SharpGoods.service.SOrders import SOrders
     self.sorder = SOrders()
     from SharpGoods.service.SUsers import SUsers
     self.suser = SUsers()
     from SharpGoods.service.SLocations import SLocations
     self.sloc = SLocations()
     self.title = "==========={0}==========="
     self.exceltitle = [
         "LOname", "LOtelphone", "LOno", "LOprovince", "LOcity", "LOarea",
         "LOdetail", "OMabo", "OMtime"
     ]
예제 #4
0
 def __init__(self):
     from SharpGoods.service.SUsers import SUsers
     self.users = SUsers()
예제 #5
0
class CCarts():
    def __init__(self):
        from SharpGoods.service.SCarts import SCarts
        self.scarts = SCarts()
        from SharpGoods.service.SProduct import SProduct
        self.sproduct = SProduct()
        from SharpGoods.service.SUsers import SUsers
        self.suser = SUsers()

    def del_cart(self):
        args = request.args.to_dict()
        print "=================args================="
        print args
        print "=================args================="
        data = json.loads(request.data)
        print "=================data================="
        print data
        print "=================data================="
        if "token" not in args:
            return PARAMS_MISS
        uid = args.get("token")
        user = self.suser.get_usname_by_usid(get_str(args, "token"))
        if not user:
            return TOKEN_ERROR

        pbid = data.get("PBid")
        try:
            cart = self.scarts.get_cart_by_uid_pid(uid, pbid)
            print "=================cart================="
            print cart
            print "=================cart================="
            if not cart:
                return import_status("ERROR_MESSAGE_NONE_PRODUCT",
                                     "SHARPGOODS_ERROR", "ERROR_NONE_PRODUCT")
            self.scarts.del_carts(cart.CAid)
            return import_status("SUCCESS_MESSAGE_DEL_CART", "OK")
        except Exception as e:
            print(e.message)
            return SYSTEM_ERROR

    def add_or_update_cart(self):
        args = request.args.to_dict()
        print "=================args================="
        print args
        print "=================args================="
        data = json.loads(request.data)
        print "=================data================="
        print data
        print "=================data================="

        if "token" not in args:
            return PARAMS_MISS
        uid = args.get("token")
        pbid = data.get("PBid")
        CAnumber = data.get("CAnumber")
        if CAnumber <= 0:
            PBnumber = self.scarts.get_pbnumber_by_pbid_and_usid(pbid, uid)
            pnum = int(CAnumber) + int(PBnumber)
            if pnum <= 0:
                return self.del_cart()
        try:
            if not self.sproduct.get_product_by_pbid(pbid):
                return import_status("ERROR_MESSAGE_NONE_PRODUCT",
                                     "SHARPGOODS_ERROR", "ERROR_NONE_PRODUCT")
            cart = self.scarts.get_cart_by_uid_pid(uid, pbid)
            print "=================cart================="
            print cart
            print "=================cart================="
            if cart:
                PBnumber = self.scarts.get_pbnumber_by_pbid_and_usid(pbid, uid)
                pnum = int(CAnumber) + int(PBnumber)
                self.scarts.update_num_cart(pnum, cart.CAid)
            else:
                self.scarts.add_model(
                    "Cart", **{
                        "CAid": str(uuid.uuid4()),
                        "CAnumber": CAnumber,
                        "USid": uid,
                        "CAstatus": 1,
                        "PBid": pbid
                    })
        except dberror:
            return SYSTEM_ERROR
        except Exception as e:
            print(e.message)
            return SYSTEM_ERROR

        add_update_cart_ok = import_status("SUCCESS_MESSAGE_ADD_UPDATE_CART",
                                           "OK")
        return add_update_cart_ok

    def get_carts_by_uid(self):
        args = request.args.to_dict()
        print "=================args================="
        print args
        print "=================args================="
        if "token" not in args:
            return PARAMS_MISS

        # todo uid 验证未实现
        uid = args["token"]
        # res_get_all = {}

        cart_info_list = []
        cart_list = self.scarts.get_carts_by_Uid(uid)
        print "=================cart_list================="
        print cart_list
        print "=================cart_list================="
        for cart in cart_list:
            if cart.CAstatus != 1:
                continue
            cart_service_info = self.sproduct.get_product_by_pbid(cart.PBid)
            print "=================cart_service_info================="
            print cart_service_info
            print "=================cart_service_info================="
            if not cart_service_info:
                return SYSTEM_ERROR
            PRid = cart_service_info.PRid
            BRid = cart_service_info.BRid
            product = self.sproduct.get_product_by_prid(PRid)
            print "=================product================="
            print product
            print "=================product================="
            if not product:
                return SYSTEM_ERROR
            cart_info = {}
            cart_info["PRquality"] = {}
            quality_list = self.sproduct.get_all_brand_by_brid_last(BRid)
            #cart_info["PRquality"] = self.sproduct.get_all_brand_by_brid_last(BRid)
            for key in quality_list.keys():
                cart_info["PRquality"][key] = {}
                cart_info["PRquality"][key]["name"] = self.choose_key(key)
                cart_info["PRquality"][key]["choice"] = []
                cart_info["PRquality"][key]["choice"].append(quality_list[key])
            cart_info["PBid"] = cart.PBid
            cart_info["PBimage"] = cart_service_info.PBimage
            cart_info["PBsalesvolume"] = cart_service_info.PBsalesvolume
            cart_info["PBprice"] = cart_service_info.PBprice
            cart_info["CAid"] = cart.CAid
            PBunit = cart_service_info.PBunit
            if PBunit == 401:
                cart_info["PBunit"] = "$"
            elif PBunit == 402:
                cart_info["PBunit"] = "¥"
            elif PBunit == 403:
                cart_info["PBunit"] = "欧元"
            elif PBunit == 404:
                cart_info["PBunit"] = "英镑"
            else:
                cart_info["PBunit"] = "其他币种"
            cart_info["PBscore"] = cart_service_info.PBscore
            cart_info["CAnumber"] = cart.CAnumber
            cart_info["PRname"] = product.PRname
            cart_info["PRinfo"] = product.PRinfo
            PRbrand = product.PRbrand
            if PRbrand == 601:
                cart_info["PRbrand"] = "美妆类"
            elif PRbrand == 602:
                cart_info["PRbrand"] = "3C类"
            else:
                cart_info["PRbrand"] = "其他"
            cart_info["PRvideo"] = product.PRvideo
            PRtype = product.PRtype
            if PRtype == 501:
                cart_info["PRtype"] = "自营"
            elif PRtype == 502:
                cart_info["PRtype"] = "非自营"
            else:
                cart_info["PRtype"] = "未知商品"
            cart_info_list.append(cart_info)
        res_get_all = import_status("SUCCESS_MESSAGE_GET_INFO", "OK")
        res_get_all["data"] = cart_info_list
        return res_get_all

    def get_carts_by_uid_caid(self):
        args = request.args.to_dict()
        print "=================args================="
        print args
        print "=================args================="
        if "token" not in args:
            return PARAMS_MISS

        data = json.loads(request.data, encoding="utf8")
        caidlist = data.get("CAid")

        # todo uid 验证未实现
        uid = args["token"]
        # res_get_all = {}

        cart_info_list = []
        cart_list = self.scarts.get_carts_by_Uid(uid)
        print "=================cart_list================="
        print cart_list
        print "=================cart_list================="
        for cart in cart_list:
            if cart.CAstatus != 1:
                continue
            if caidlist and cart.CAid not in caidlist:
                continue
            cart_service_info = self.sproduct.get_product_by_pbid(cart.PBid)
            print "=================cart_service_info================="
            print cart_service_info
            print "=================cart_service_info================="
            if not cart_service_info:
                return SYSTEM_ERROR
            PRid = cart_service_info.PRid
            BRid = cart_service_info.BRid
            product = self.sproduct.get_product_by_prid(PRid)
            print "=================product================="
            print product
            print "=================product================="
            if not product:
                return SYSTEM_ERROR
            cart_info = {}
            cart_info["PRquality"] = {}
            quality_list = self.sproduct.get_all_brand_by_brid_last(BRid)

            for key in quality_list.keys():
                cart_info["PRquality"][key] = {}
                cart_info["PRquality"][key]["name"] = self.choose_key(key)
                cart_info["PRquality"][key]["choice"] = []
                cart_info["PRquality"][key]["choice"].append(quality_list[key])
            cart_info["PBid"] = cart.PBid
            cart_info["PBimage"] = cart_service_info.PBimage
            cart_info["PBsalesvolume"] = cart_service_info.PBsalesvolume
            cart_info["PBprice"] = cart_service_info.PBprice
            PBunit = cart_service_info.PBunit
            if PBunit == 401:
                cart_info["PBunit"] = "$"
            elif PBunit == 402:
                cart_info["PBunit"] = "¥"
            elif PBunit == 403:
                cart_info["PBunit"] = "欧元"
            elif PBunit == 404:
                cart_info["PBunit"] = "英镑"
            else:
                cart_info["PBunit"] = "其他币种"
            cart_info["PBscore"] = cart_service_info.PBscore
            cart_info["CAnumber"] = cart.CAnumber
            cart_info["PRname"] = product.PRname
            cart_info["PRinfo"] = product.PRinfo
            PRbrand = product.PRbrand
            if PRbrand == 601:
                cart_info["PRbrand"] = "美妆类"
            elif PRbrand == 602:
                cart_info["PRbrand"] = "3C类"
            else:
                cart_info["PRbrand"] = "其他"
            cart_info["PRvideo"] = product.PRvideo
            PRtype = product.PRtype
            if PRtype == 501:
                cart_info["PRtype"] = "自营"
            elif PRtype == 502:
                cart_info["PRtype"] = "非自营"
            else:
                cart_info["PRtype"] = "未知商品"
            cart_info_list.append(cart_info)
        res_get_all = import_status("SUCCESS_MESSAGE_GET_INFO", "OK")
        res_get_all["data"] = cart_info_list
        return res_get_all

    def choose_key(self, BRkey):
        if BRkey == "BRno":
            return "版本选择"
        elif BRkey == "BRcolor":
            return "颜色选择"
        else:
            return "未知类目"
예제 #6
0
class CReview():
    def __init__(self):
        self.service_review = SReview()
        from SharpGoods.service.SOrders import SOrders
        self.sorder = SOrders()
        from SharpGoods.service.SProduct import SProduct
        self.sproduct = SProduct()
        from SharpGoods.service.SUsers import SUsers
        self.suser = SUsers()

    #  创建评论
    def create_review(self):
        args = request.args.to_dict()  # 捕获前端的URL参数,以字典形式呈现
        print "=================args================="
        print args
        print "=================args================="
        # 判断url参数是否异常
        if "token" not in args and "OMid" not in args:
            return PARAMS_MISS
        Uid = args["token"]
        OMid = args["OMid"]

        uid = self.sorder.get_uid_by_omid(OMid)
        print "=================uid================="
        print uid
        print "=================uid================="
        omstatus = self.sorder.get_omstatus_by_omid(OMid)
        print "=================omstatus================="
        print omstatus
        print "=================omstatus================="
        if uid != Uid:
            return import_status("ERROR_MESSAGE_NONE_PERMISSION",
                                 "SHARPGOODS_ERROR", "ERROR_NONE_PERMISSION")
        if omstatus != 42:
            return import_status("ERROR_MESSAGE_WRONG_STATUS",
                                 "SHARPGOODS_ERROR", "ERROR_WRONG_STATUS")

        data = json.loads(request.data)
        print "=================data================="
        print data
        print "=================data================="
        if data == []:
            return PARAMS_MISS
        for review in data:
            if "PBid" not in review or "REcontent" not in review or "REscore" not in review:
                return PARAMS_MISS
            PRid = self.sproduct.get_prid_by_pbid(review["PBid"])
            print "=================PRid================="
            print PRid
            print "=================PRid================="
            REcontent = review["REcontent"]
            add_review = self.service_review.new_review(PRid, uid, REcontent)
            if not add_review:
                return SYSTEM_ERROR
            product = self.sproduct.get_volue_score_by_pbid(review["PBid"])
            print "=================product================="
            print product
            print "=================product================="
            PBscore, PBvolue = product.PBscore, product.PBsalesvolume
            score = (review["REscore"] + PBscore * PBvolue) / PBvolue
            product_brand = {}
            product_brand["PBid"] = review["PBid"]
            product_brand["PBscore"] = score
            update_product = self.sproduct.update_score_by_pbid(
                review["PBid"], product_brand)
            if not update_product:
                return SYSTEM_ERROR
        order_main = {}
        order_main["OMstatus"] = 49
        update_order_status = self.sorder.update_omstatus_by_omid(
            OMid, order_main)
        if not update_order_status:
            return SYSTEM_ERROR
        return import_status("SUCCESS_MESSAGE_NEW_REVIEW", "OK")

    # 根据Oid获取商品评论
    def get_review(self):
        args = request.args.to_dict()  # 捕获前端的URL参数,以字典形式呈现
        print "=================args================="
        print args
        print "=================args================="
        # 判断url参数是否异常
        if "PRid" not in args:
            return PARAMS_MISS
        PRid = args["PRid"]
        PBid_list = self.sproduct.get_pbid_by_prid(PRid)
        review_list = []
        all_review = self.service_review.get_review_by_pbid(PRid)
        print "=================all_review================="
        print all_review
        print "=================all_review================="
        if all_review:
            for review in all_review:
                reviews = {}
                REid = review.REid
                REtime = review.REtime
                REtime = get_web_time_str(REtime)
                USid = review.USid
                REcontent = review.REcontent
                USname = self.suser.get_usname_by_usid(USid)
                print "=================USname================="
                print USname
                print "=================USname================="
                reviews["REid"] = REid
                reviews["REtime"] = REtime
                reviews["USname"] = USname
                reviews["REcontent"] = REcontent
                review_list.append(reviews)
        response = import_status("SUCCESS_MESSAGE_GET_REVIEW", "OK")
        response["data"] = review_list
        return response

    # def get_user_review(self):
    #     args = request.args.to_dict()  # 捕获前端的URL参数,以字典形式呈现
    #     # 判断url参数是否异常
    #     if len(args) != 1 or "Uid" not in args.keys():
    #         message, status, statuscode = import_status("URL_PARAM_WRONG", "response_error", "URL_PARAM_WRONG")
    #         return {
    #             "message": message,
    #             "status": status,
    #             "statuscode": statuscode,
    #         }
    #     uid_to_str = get_str(args, "Uid")
    #     uid_list = []
    #     if uid_to_str not in uid_list:
    #         message, status, statuscode = import_status("URL_PARAM_WRONG", "response_error", "URL_PARAM_WRONG")
    #         return {
    #             "message": message,
    #             "status": status,
    #             "statuscode": statuscode,
    #         }
    #     review_of_control = self.service_review.get_user_review(uid_to_str)
    #     review_list = []
    #     for i in range(len(review_of_control)):
    #         dict_of_review = {}
    #         dict_of_review["Rid"] = review_of_control[i].get("Rid")
    #         dict_of_review["Rpname"] = review_of_control[i].get("Rpname")
    #         dict_of_review["Rpimage"] = review_of_control[i].get("Rpimage")
    #         dict_of_review["Rscore"] = review_of_control[i].get("Rscore")
    #         dict_of_review["Rcontent"] = review_of_control[i].get("Rcontent")
    #         review_list.append(dict_of_review)
    #     return {
    #         "message": "get user revirew success !",
    #         "status": 200,
    #         "statuscode": review_list
    #     }

    def delete_user_review(self):
        args = request.args.to_dict()  # 捕获前端的URL参数,以字典形式呈现
        # 判断url参数是否异常
        if len(args) != 1 or "Uid" not in args.keys(
        ) or "Rid" not in args.keys():
            message, status, statuscode = import_status(
                "URL_PARAM_WRONG", "response_error", "URL_PARAM_WRONG")
            return {
                "message": message,
                "status": status,
                "statuscode": statuscode,
            }
        uid_to_str = get_str(args, "Uid")
        uid_list = []
        if uid_to_str not in uid_list:
            message, status, statuscode = import_status(
                "URL_PARAM_WRONG", "response_error", "URL_PARAM_WRONG")
            return {
                "message": message,
                "status": status,
                "statuscode": statuscode,
            }
        rid_to_str = get_str(args, "Rid")
        rid_list = self.service_review.get_rid_by_uid(uid_to_str)
        if rid_to_str not in rid_list:
            message, status, statuscode = import_status(
                "NO_THIS_REVIEW", "response_error", "NO_THIS_REVIEW")
            return {
                "message": message,
                "status": status,
                "statuscode": statuscode,
            }
        result = self.service_review.delete_user_review(rid_to_str)
        print(request)
        return {
            "message": "delete review success !",
            "status": 200,
        }
예제 #7
0
class CUsers():
    def __init__(self):
        from SharpGoods.service.SUsers import SUsers
        self.susers = SUsers()

    def register(self):
        data = request.data
        data = json.loads(data)
        print "=================data================="
        print data
        print "=================data================="
        if "UStelphone" not in data or "USpassword" not in data or "UScode" not in data:
            return PARAMS_MISS

        list_utel = self.susers.get_all_user_tel()
        print "=================list_utel================="
        print list_utel
        print "=================list_utel================="
        if list_utel == False:
            return SYSTEM_ERROR
        if data["UStelphone"] in list_utel:
            return import_status("ERROR_MESSAGE_REPEAT_TELPHONE",
                                 "SHARPGOODS_ERROR", "ERROR_REPEAT_TELPHONE")

        code_in_db = self.susers.get_code_by_utel(data["UStelphone"])
        print "=================code_in_db================="
        print code_in_db
        print "=================code_in_db================="
        if not code_in_db:
            return import_status("ERROR_MESSAGE_WRONG_TELCODE",
                                 "SHARPGOODS_ERROR", "ERROR_WRONG_TELCODE")
        if code_in_db.ICcode != data["UScode"]:
            return import_status("ERROR_MESSAGE_WRONG_TELCODE",
                                 "SHARPGOODS_ERROR", "ERROR_WRONG_TELCODE")

        if "USinvate" in data:
            USinvate = data["USinvate"]
            #TODO 优惠券发放

        USinvatecode = self.make_invate_code()
        is_register = self.susers.login_users(data["UStelphone"],
                                              data["USpassword"], USinvatecode)
        print "=================is_register================="
        print is_register
        print "=================is_register================="
        if is_register:
            return import_status("SUCCESS_MESSAGE_REGISTER", "OK")
        else:
            return SYSTEM_ERROR

    def login(self):
        args = request.args.to_dict()
        print "=================args================="
        print args
        print "=================args================="
        data = request.data
        data = json.loads(data)
        print "=================data================="
        print data
        print "=================data================="
        if "UStelphone" not in data or "USpassword" not in data:
            return PARAMS_MISS
        Utel = data["UStelphone"]
        list_utel = self.susers.get_all_user_tel()
        print "=================list_utel================="
        print list_utel
        print "=================list_utel================="
        if list_utel == False:
            return SYSTEM_ERROR

        if Utel not in list_utel:
            return import_status("ERROR_MESSAGE_NONE_TELPHONE",
                                 "SHARPGOODS_ERROR", "ERROR_NONE_TELPHONE")

        upwd = self.susers.get_upwd_by_utel(Utel)
        print "=================USpassword================="
        print upwd
        print "=================USpassword================="
        if upwd != data["USpassword"]:
            return import_status("ERROR_MESSAGE_WRONG_PASSWORD",
                                 "SHARPGOODS_ERROR", "ERROR_WRONG_PASSWORD")

        Uid = self.susers.get_uid_by_utel(Utel)
        print "=================USid================="
        print Uid
        print "=================USid================="
        login_success = import_status("SUCCESS_MESSAGE_LOGIN", "OK")
        login_success["data"] = {}
        login_success["data"]["token"] = Uid

        return login_success

    def update_info(self):
        args = request.args.to_dict()
        print "=================args================="
        print args
        print "=================args================="
        data = request.data
        data = json.loads(data)
        print "=================data================="
        print data
        print "=================data================="
        if "token" not in args or data in ["", "{}"]:
            return PARAMS_MISS

        users = {}
        if "USname" in data:
            Uname = data["USname"]
            users["USname"] = Uname
        if "USsex" in data:
            Usex = data["USsex"]
            if Usex == "男".decode("UTF-8"):
                Usex = 101
            elif Usex == "女".decode("UTF-8"):
                Usex = 102
            users["USsex"] = Usex
        if users == {}:
            return PARAMS_MISS

        Uid = args["token"]
        update_info = self.susers.update_users_by_uid(Uid, users)
        print "=================update_info================="
        print update_info
        print "=================update_info================="
        if not update_info:
            return SYSTEM_ERROR

        response_of_update_users = import_status(
            "SUCCESS_MESSAGE_UPDATE_PERSONAL", "OK")
        return response_of_update_users

    def update_pwd(self):
        data = request.data
        data = json.loads(data)
        print "=================data================="
        print data
        print "=================data================="
        if "USpasswordold" not in data or "USpasswordnew" not in data or "UStelphone" not in data:
            return SYSTEM_ERROR

        Utel = data["UStelphone"]
        list_utel = self.susers.get_all_user_tel()
        print "=================list_utel================="
        print list_utel
        print "=================list_utel================="
        if list_utel == False:
            return SYSTEM_ERROR

        if Utel not in list_utel:
            return import_status("ERROR_MESSAGE_NONE_TELPHONE",
                                 "SHARPGOODS_ERROR", "ERROR_NONE_TELPHONE")

        upwd = self.susers.get_upwd_by_utel(Utel)
        print "=================USpassword================="
        print upwd
        print "=================USpassword================="
        if upwd != data["USpasswordold"]:
            return import_status("ERROR_MESSAGE_WRONG_PASSWORD",
                                 "SHARPGOODS_ERROR", "ERROR_WRONG_PASSWORD")
        users = {}
        Upwd = data["USpasswordnew"]
        users["USpassword"] = Upwd
        Uid = self.susers.get_uid_by_utel(Utel)
        update_info = self.susers.update_users_by_uid(Uid, users)
        print "=================update_info================="
        print update_info
        print "=================update_info================="
        if not update_info:
            return SYSTEM_ERROR

        response_of_update_users = import_status(
            "SUCCESS_MESSAGE_UPDATE_PASSWORD", "OK")
        return response_of_update_users

    def forget_pwd(self):
        data = request.data
        data = json.loads(data)
        print "=================data================="
        print data
        print "=================data================="
        if "USpasswordnew" not in data or "USpasswordnewrepeat" not in data or "UStelphone" not in data or "UScode" not in data:
            return SYSTEM_ERROR

        Utel = data["UStelphone"]
        list_utel = self.susers.get_all_user_tel()
        print "=================list_utel================="
        print list_utel
        print "=================list_utel================="
        if list_utel == False:
            return SYSTEM_ERROR

        if Utel not in list_utel:
            return import_status("ERROR_MESSAGE_NONE_TELPHONE",
                                 "SHARPGOODS_ERROR", "ERROR_NONE_TELPHONE")

        code_in_db = self.susers.get_code_by_utel(data["UStelphone"])
        print "=================code_in_db================="
        print code_in_db
        print "=================code_in_db================="
        if not code_in_db:
            return import_status("ERROR_MESSAGE_WRONG_TELCODE",
                                 "SHARPGOODS_ERROR", "ERROR_WRONG_TELCODE")
        if code_in_db.ICcode != data["UScode"]:
            return import_status("ERROR_MESSAGE_WRONG_TELCODE",
                                 "SHARPGOODS_ERROR", "ERROR_WRONG_TELCODE")

        if data["USpasswordnew"] != data["USpasswordnewrepeat"]:
            return import_status("ERROR_MESSAGE_WRONG_REPEAT_PASSWORD",
                                 "SHARPGOODS_ERROR",
                                 "ERROR_CODE_WRONG_REPEAT_PASSWORD")

        users = {}
        Upwd = data["USpasswordnew"]
        users["USpassword"] = Upwd
        Uid = self.susers.get_uid_by_utel(Utel)
        update_info = self.susers.update_users_by_uid(Uid, users)
        print "=================update_info================="
        print update_info
        print "=================update_info================="
        if not update_info:
            return SYSTEM_ERROR

        response_of_update_users = import_status(
            "SUCCESS_MESSAGE_UPDATE_PASSWORD", "OK")
        return response_of_update_users

    def get_inforcode(self):
        data = request.data
        data = json.loads(data)
        print("=====================data=================")
        print(data)
        print("=====================data=================")
        if "UStelphone" not in data:
            return SYSTEM_ERROR
        Utel = data["UStelphone"]
        # 拼接验证码字符串(6位)
        code = ""
        while len(code) < 6:
            import random
            item = random.randint(1, 9)
            code = code + str(item)

        print("=====================code=================")
        print code
        print("=====================code=================")
        # 获取当前时间,与上一次获取的时间进行比较,小于60秒的获取直接报错
        import datetime
        time_time = datetime.datetime.now()
        time_str = datetime.datetime.strftime(time_time, "%Y%m%d%H%M%S")
        # 根据电话号码获取时间
        # utel_list = self.susers.get_all_user_tel()
        # print("=====================utel_list=================")
        # print utel_list
        # print("=====================utel_list=================")
        # if Utel in utel_list:
        #     return import_status("ERROR_MESSAGE_REGISTED_TELPHONE", "SHARPGOODS_ERROR", "ERROR_REGISTED_TELPHONE")
        time_up = self.susers.get_uptime_by_utel(Utel)
        print("=====================time_up=================")
        print time_up
        print("=====================time_up=================")
        if time_up:
            time_up_time = datetime.datetime.strptime(time_up.ICtime,
                                                      "%Y%m%d%H%M%S")
            delta = time_time - time_up_time
            if delta.seconds < 60:
                return import_status("ERROR_MESSAGE_FAST_GET",
                                     "SHARPGOODS_ERROR", "ERROR_FAST_GET")

        new_inforcode = self.susers.add_inforcode(Utel, code, time_str)
        print("=====================new_inforcode=================")
        print new_inforcode
        print("=====================new_inforcode=================")
        if not new_inforcode:
            return SYSTEM_ERROR
        from SharpGoods.config.Inforcode import SignName, TemplateCode
        from SharpGoods.common.Inforsend import send_sms
        params = '{\"code\":\"' + code + '\",\"product\":\"etech\"}'

        # params = u'{"name":"wqb","code":"12345678","address":"bz","phone":"13000000000"}'
        import uuid
        __business_id = uuid.uuid1()
        response_send_message = send_sms(__business_id, Utel, SignName,
                                         TemplateCode, params)
        print("=====================response_send_message=================")
        print response_send_message
        print("=====================response_send_message=================")
        response_send_message = json.loads(response_send_message)

        if response_send_message["Code"] == "OK":
            status = 200
            message = "获取成功"
        else:
            status = 405
            message = "获取验证码失败"
        response_ok = {}
        response_ok["status"] = status
        response_ok["message"] = message

        return response_ok

    def all_info(self):
        args = request.args.to_dict()
        print "=================args================="
        print args
        print "=================args================="
        if "token" not in args:
            return PARAMS_MISS
        Uid = args["token"]
        users_info = self.susers.get_all_users_info(Uid)
        print "=================users_info================="
        print users_info
        print "=================users_info================="
        if not users_info:
            return SYSTEM_ERROR

        response_user_info = {}
        Utel = users_info.UStelphone
        response_user_info["UStelphone"] = Utel
        if users_info.USname not in ["", None]:
            Uname = users_info.USname
            response_user_info["USname"] = Uname
        else:
            response_user_info["USname"] = None
        if users_info.USsex not in ["", None]:
            Usex = users_info.USsex
            if Usex == 101:
                response_user_info["USsex"] = "男"
            elif Usex == 102:
                response_user_info["USsex"] = "女"
            else:
                response_user_info["USsex"] = "未知性别"
        else:
            response_user_info["USsex"] = None
        response_user_info["UScoin"] = users_info.UScoin
        response_user_info["USinvate"] = users_info.USinvate

        response_of_get_all = import_status("SUCCESS_MESSAGE_GET_INFO", "OK")
        response_of_get_all["data"] = response_user_info
        return response_of_get_all

    def make_invate_code(self):
        USinvate = self.susers.get_all_invate_code()
        while True:
            invate_code = self.make_random_code()
            if invate_code not in USinvate:
                break
        return invate_code

    def make_random_code(self):
        import random
        random_code = ""
        while len(random_code) < 2:
            a = random.randint(97, 122)
            a = chr(a)
            random_code = random_code + a
        while len(random_code) < 6:
            a = random.randint(0, 9)
            random_code = random_code + str(a)
        return random_code