def save(self, account: Account): customer = self.findCustomerDBObjectById(account.idCustomer) account_db = AccountDb() account_db.account_id = account.id account_db.customer = customer account_db.opening_date = account.OpeningDate.date account_db.status = int(account.status) account_db.balance = account.balance account_db.save()
def customer_create(request): params = json.loads(request.body.decode("utf-8")) data = {} blacklist = Blacklist.objects.all() for man in blacklist: nameRatio = fuzz.partial_ratio(man.name, params['name']) nationRatio = fuzz.partial_ratio(man.nationality, params['nation']) addrRatio = fuzz.partial_ratio(man.address, params['address']) print(nameRatio, addrRatio, nationRatio) if (nameRatio > 70 or addrRatio > 80 or (nameRatio + nationRatio) > 170): log = AlertLog() log.name = params['name'] log.operate = '開戶' log.reason = '疑似為高風險或黑名單人物' log.save() return common_response(data, message='黑名單人物') try: with transaction.atomic(): distrcit = District.objects.get(id=params['district']['id']) customer = Customer() customer.name = params['name'] customer.roc_id = params['roc_id'] customer.gender = params['gender'] customer.birthday = params['birthday'] customer.cell_phone = params['cell_phone'] customer.address = params['address'] customer.district = distrcit customer.password = get_sha256_value(params['cell_phone']) customer.email = params['email'] customer.save() data['id'] = customer.id # 產生帳戶號碼 code = generate_16_digits_code() exist_codes = [account.code for account in Account.objects.all()] while code in exist_codes: code = generate_16_digits_code() # 新增帳戶 account = Account() account.code = code account.customer = Customer.objects.get(id=customer.id) # 預設第1筆(新台幣) currency_list = Currency.objects.filter(id=1) if len(currency_list) != 0: account.currency = currency_list[0] account.save() return common_response(data) except Exception as e: return common_response(data, message=str(e))