def multi_shop_balance(shop_id_list): """ 查一組商戶的餘額 :param shop_id_list: :return: """ if not shop_id_list: raise Return({}) url = IP_PORT_API + "/shop/flow_statistics/complex_query" data = { 'filter_col': ['balance', 'shop_id'], 'query': { 'op': 'AND', 'exprs': [ {'shop_id': {'in': shop_id_list}} ] } } response = yield async_requests.post(url=url, json=data) balances = {} if response.code == HTTP_200_OK: ret = json.loads(response.body) # 把返回列表变成形如{shop_id: balance}的字典 for r in ret: balances[r['shop_id']] = r['balance'] any_left = set(shop_id_list) - set(balances.keys()) for s in any_left: balances[s] = 0.0 raise Return(balances)
def shop_wxpay_code_url(shop_id, shop_name, shop_tel, cash): """ 由配送员生成给商户用微信APP扫码付款的二维码. { "shop": { "id": "57031774eed0934930609c53", "name": "霉霉", "tel": "132" }, "cash": 0.01 } """ url = IP_PORT_API + '/shop/native/wx_pay' data = { "shop": { "id": shop_id, "name": shop_name, "tel": shop_tel }, "cash": cash } resp_obj = yield async_requests.post(url=url, json=data, **wxpay_timeouts) if resp_obj.code == HTTP_200_OK: ret = json.loads(resp_obj.body) raise Return(ret) else: logging.error(resp_obj.body)
def shop_balance(shop_id): """ 查商户余额 :param shop_id: :return: """ if not shop_id: raise Return(0) url = IP_PORT_API + "/shop/flow_statistics/complex_query" data = { "filter_col": ["balance"], "query": { "op": "AND", "exprs": [ {"shop_id": {"=": shop_id}} ] } } response = yield async_requests.post(url=url, json=data) balance = 0.0 if response.code == HTTP_200_OK: ret = json.loads(response.body) if len(ret) == 1: balance = ret[0] raise Return(balance)
def create_channel(**kwargs): """ 创建频道 :param kwargs: :return: """ url = conf.WC_DAS_PREFIX + "/windchat/channel" resp = yield async_requests.post(url, json=kwargs) raise gen.Return(json.loads(resp.body))
def create_account(account_id, account_type): """ 创建聊天账户 """ url = conf.WC_DAS_PREFIX + "/windchat/das/account" yield async_requests.post(url, json={ "account_id": account_id, "account_type": account_type })
def query_account(account=None, client_id=None, full_resp=False): """ 查询账户信息 """ url = conf.WC_DAS_PREFIX + "/windchat/das/account/query" if account: resp = yield async_requests.post(url, json={ "account": account, "full_resp": full_resp }) elif client_id: resp = yield async_requests.post(url, json={ "client_id": client_id, "full_resp": full_resp }) else: resp = yield async_requests.post(url, json={"full_resp": full_resp}) raise gen.Return(json.loads(resp.body))
def shop_refund(shop_id, cash): """ 退款 :param shop_id: :param cash: :return: """ url = IP_PORT_API + "/shop/cash_flow" data = { "transact_type": "refund", "shop_id": shop_id, "cash": cash } response = yield async_requests.post(url=url, json=data) if response.code == HTTP_200_OK: raise Return(True) else: raise Return(False)
def send_message( self, from_peer, conv_id, message, to_peers=None, transient=False, no_sync=False, ): """ 发送消息 """ url = "https://leancloud.cn/1.1/rtm/messages" return async_requests.post(url=url, headers=self.master_key_headers, json={ "from_peer": from_peer, "conv_id": conv_id, "message": message, "to_peers": to_peers, "transient": transient, "no_sync": no_sync })
def shop_alipay_code_url(shop_id, shop_name, shop_tel, cash): """ 由配送员生成给商户用支付宝APP扫码付款的二维码. :param shop_id: :param shop_name: :param shop_tel: :param cash: :return: """ url = IP_PORT_API + '/shop/native/alipay' data = { "shop": { "id": shop_id, "name": shop_name, "tel": shop_tel }, "cash": cash } resp_obj = yield async_requests.post(url=url, json=data, **wxpay_timeouts) if resp_obj.code == HTTP_200_OK: ret = json.loads(resp_obj.body) raise Return(ret) else: logging.error(resp_obj.body)
def log_create(isVal=None, type="", # 日志创建者 creatorId="", creatorName="", creatorTel="", creatorRole="", createTime="", # 影响者 effectorId="", effectorName="", effectorTel="", effectorRole="", # 运单信息 orderId="", orderSum="", orderState=0, orderType="", orderAddress="", orderCreator="", orderLat=0.0, orderLng=0.0, # 客户信息 shopAddress="", shopLat=0.0, shopLng=0.0, shopId="", shopName="", shopTel="", # 资金 fondSum=0.0, fondType="", # 交通工具 vehicleId="", vehicleMile="", # 软件版本 softwareVersion="", # 地理信息 locationAddress="", locationLat=0.0, locationLng=0.0, # 其他 remark="", caseId="", caseType="", caseDetail="", amount=0, **kwargs): """新增参数请加到上面并归类, 未加入的参数会被忽略(warning提示)""" if kwargs: logging.warn("Got unprocessed params: " + repr(kwargs)) url = JAVA_DATA_PREFIX + "/WindCloud/log/create" d = dict( isVal=isVal, # 是否有效 type=type, # 日志类型 # 日志创建者 creatorId=creatorId, creatorName=creatorName, creatorTel=creatorTel, creatorRole=creatorRole, createTime=createTime, # 日志创建时间 # 影响者 effectorId=effectorId, effectorName=effectorName, effectorTel=effectorTel, effectorRole=effectorRole, # 运单信息 orderId=orderId, orderSum=orderSum, orderState=orderState, # 运单状态 orderType=orderType, orderAddress=orderAddress, orderCreator=orderCreator, orderLat=orderLat, orderLng=orderLng, # 客户信息 shopAddress=shopAddress, shopLat=shopLat, shopLng=shopLng, shopId=shopId, shopName=shopName, shopTel=shopTel, # 资金 fondSum=fondSum, # 资金总数 fondType=fondType, # 资金类型 # 交通工具 vehicleId=vehicleId, # 车辆牌号 vehicleMile=vehicleMile, # 里程数 # 软件版本 softwareVersion=softwareVersion, # 地理信息 locationAddress=locationAddress, locationLat=locationLat, locationLng=locationLng, # 其他 remark=remark, caseId=caseId, # 事件 id caseType=caseType, # 事件类型 caseDetail=caseDetail, # 事件详情 amount=amount # 数量 ) d = {i: d[i] for i in d if d[i]} logging.info("windlog.log_create: " + repr(d)) resp = yield async_requests.post(url, json=d) if not resp: logging.warn("Got empty windlog resp") if not http_code.is_success(resp.code): logging.warn("Windlog failed with code %s" % resp.code)