def __get_approvalcontent(self, pt, startid, avcontentid, **kwargs): start, content = self.__fill_approval(pt, startid, avcontentid, **kwargs) gennerc_log('get start {0} content {1}'.format(start, content)) if not (start or content): raise ParamsError('审批流创建失败,发起人或需审批内容已被删除') return start, content
def _get_logistics(self, order_logistics): # http查询 l = Logistics() response = l.get_logistic(order_logistics.OLexpressNo, order_logistics.OLcompany) current_app.logger.info("物流记录OLid--> {} ;快递response --> {}".format( order_logistics.OLid, response)) if response: # 插入数据库 code = response.get('status') if code == '0': result = response.get('result') OrderLogisticsDict = { 'OLsignStatus': int(result.get('deliverystatus')), 'OLdata': json.dumps(result), # 快递结果原字符串 'OLlastresult': json.dumps(result.get('list')[0]) # 最新物流 } # elif code == '205': # 205 暂时没有信息,可能在揽件过程中 OrderLogisticsDict = { 'OLsignStatus': 0, # 签收状态 0:快递收件(揽件) 1.在途中 2.正在派件 3.已签收 4.派送失败 -1 异常数据' 'OLdata': json.dumps(response), # 整体结果原字符串 'OLlastresult': '{}' } else: OrderLogisticsDict = { 'OLsignStatus': -1, 'OLdata': json.dumps(response), # 结果原字符串 'OLlastresult': '{}' } order_main = OrderMain.query.filter( OrderMain.OMid == order_logistics.OMid, OrderMain.isdelete == False).first() order_main.update( {'OMstatus': OrderMainStatus.wait_send.value}) db.session.add(order_main) # s_list.append(order_logistics) else: # 无信息 todo OrderLogisticsDict = { 'OLsignStatus': -1, 'OLdata': "[]", # 结果原字符串 'OLlastresult': '{}' } order_main = OrderMain.query.filter( OrderMain.OMid == order_logistics.OMid, OrderMain.isdelete == False).first() order_main.update({'OMstatus': OrderMainStatus.wait_send.value}) db.session.add(order_main) gennerc_log('物流信息出错') order_logistics.update(OrderLogisticsDict) db.session.add(order_logistics) return order_logistics
def save_avatar(self, filepath): time_now = datetime.now() year = str(time_now.year) month = str(time_now.month) day = str(time_now.day) img = self._get_avatar_data() newPath = os.path.join(current_app.config['BASEDIR'], 'img', 'defaulthead', year, month, day) if not os.path.isdir(newPath): os.makedirs(newPath) # newPath = newPath + filepath + '.png' newPath = os.path.join(newPath, filepath + '.png') gennerc_log(newPath) cv2.imwrite(newPath, img) data = '/img/defaulthead/{}/{}/{}/{}'.format(year, month, day, filepath + '.png') return data
def _send_sms_ali(self, mobiles, tpl_params, sign_name, templatecode): params_lst = self.params(mobiles, tpl_params, sign_name, templatecode) eps = self.encode_params(params_lst) prepare_str = self.prepare_sign(eps) sign_str = self.sign(prepare_str) url = "{0}Signature={1}&{2}".format(self.prefix_url, sign_str, eps) r = requests.get(url) if r.status_code != 200: raise ParamsError('短信验证获取失败') else: jn = json.loads(r.text) gennerc_log('get sms response : {0}'.format(jn)) if jn.get("Code") == "OK": return True else: raise ParamsError('短信验证获取失败')
def create_approval(self, avtype, startid, avcontentid, applyfrom=None, **kwargs): gennerc_log('start create approval ptid = {0}'.format(avtype)) pt = PermissionType.query.filter_by_(PTid=avtype).first_('参数异常') start, content = self.__get_approvalcontent(pt, startid, avcontentid, applyfrom=applyfrom, **kwargs) db.session.expunge_all() av = Approval.create({ "AVid": str(uuid.uuid1()), "AVname": avtype + datetime.now().strftime('%Y%m%d%H%M%S'), "PTid": avtype, "AVstartid": startid, "AVlevel": 1, "AVstatus": ApplyStatus.wait_check.value, "AVcontent": avcontentid, 'AVstartdetail': json.dumps(start, cls=JSONEncoder), 'AVcontentdetail': json.dumps(content, cls=JSONEncoder), }) with self.sapproval.auto_commit() as s: if applyfrom == ApplyFrom.supplizer.value: sup = Supplizer.query.filter_by_(SUid=startid).first() name = getattr(sup, 'SUname', '') elif applyfrom == ApplyFrom.platform.value: admin = Admin.query.filter_by_(ADid=startid).first() name = getattr(admin, 'ADname', '') else: user = User.query.filter_by_(USid=startid).first() name = getattr(user, 'USname', '') aninstance = ApprovalNotes.create({ "ANid": str(uuid.uuid1()), "AVid": av.AVid, "ADid": startid, "ANaction": ApprovalAction.submit.value, "AVadname": name, "ANabo": "发起申请", "ANfrom": applyfrom }) s.add(av) s.add(aninstance) return av.AVid
def get_answer(self): """通过问题id 获取答案""" if is_supplizer(): user = Supplizer.query.filter(Supplizer.SUid == request.user.id).first() else: user = User.query.filter_(User.USid == request.user.id).first_('用户不存在') data = parameter_required(('quid',)) answer_model = Answer.query.filter_(Answer.QUid == data.get('quid'), Answer.isdelete == False).first() answer_model.fields = self.AnswerFields[:] qu_model = Quest.query.filter_(Quest.QUid == data.get('quid'), Quest.isdelete == False).first() if not qu_model: gennerc_log('可以获取到答案, 但是获取不到问题,id为{0}'.format(data.get('quid'))) raise SystemError('数据异常') answer_model.fill('ququest', qu_model.QUquest) an_instance = AnswerUser.create({ 'QAUid': str(uuid.uuid1()), 'QAid': answer_model.QAid, 'USid': user.USid }) db.session.add(an_instance) return Success('获取回答成功', data=answer_model)