Exemple #1
0
 def generator_order(uid, order_info):
     address = UserAddress.get_user_address(uid)
     address = UserAddress.json_address(address)
     if len(order_info['pStatusArray']) > 1:
         snap_name = order_info['pStatusArray'][0]['name'] + '等'
     else:
         snap_name = order_info['pStatusArray'][0]['name']
     with db.auto_commit():
         order = Order()
         order.order_no = generator_order_no()
         order.user_id = uid
         order.total_price = order_info['orderPrice']
         order.snap_img = order_info['pStatusArray'][0]['mainImgUrl']
         order.snap_name = snap_name
         order.total_count = order_info['totalCount']
         order.snap_items = json.dumps(order_info['pStatusArray'])
         order.snap_address = json.dumps(address)
         db.session.add(order)
     create_time = timestamp_to_localtime(order.create_time)
     return {
         'pass': True,
         'order_id': order.id,
         'order_no': order.order_no,
         'create_time': create_time
     }
Exemple #2
0
 def save_address(self, address_info):
     with db.auto_commit():
         # address = UserAddress.query.filter_by(user_id=self.id).first()
         address = self.user_address
         if not address:
             address = UserAddress(author=self)
         address.update(commit=True, **address_info)
         db.session.add(address)
Exemple #3
0
def delete_one():
    '''删除「配送信息」'''
    uid = g.user.uid
    validator = BaseValidator().get_all_json()
    user_address = UserAddress.get_or_404(user_id=uid, id=validator.address_id)
    user_address.delete()
    return Success(error_code=2)
Exemple #4
0
def get_one():
    '''获取「配送信息」'''
    uid = g.user.uid
    user_address = UserAddress.get_or_404(user_id=uid,
                                          error_code=6001,
                                          msg='配送地址不存在')
    return Success(user_address)
Exemple #5
0
 def save_address(self, address_info):
     with db.auto_commit():
         address = UserAddress.query.filter_by(user_id=self.id).first()
         if not address:
             address = UserAddress()
         address.user_id = self.id
         address.name = address_info.name
         address.mobile = address_info.mobile
         address.province = address_info.province
         address.city = address_info.city
         address.country = address_info.country
         address.detail = address_info.detail
         db.session.add(address)
Exemple #6
0
	def save_address(self, address_info):
		with db.auto_commit():
			address = UserAddress.query.filter_by(user_id=self.id).first()
			if not address:
				address = UserAddress()
			address.user_id = self.id
			address.name = address_info.name
			address.mobile = address_info.mobile
			address.province = address_info.province
			address.city = address_info.city
			address.country = address_info.country
			address.detail = address_info.detail
			db.session.add(address)
Exemple #7
0
 def save_address(self, address_info, uid):
     with db.auto_commit():
         address = self._user_address.first()
         if not address:
             address = UserAddress()
         address.name = address_info.name
         address.mobile = address_info.mobile
         address.detail = address_info.detail
         address.user_id = uid
         db.session.add(address)
Exemple #8
0
 def save_address(self, address_info):
     address = self.user_address
     if not address:
         address = UserAddress(author=self)
     return address.update(**address_info)
Exemple #9
0
def get_address():
    uid = g.user.uid
    address = UserAddress.get_user_address(uid)
    return jsonify(address)
Exemple #10
0
def update_address():
    uid = g.user.uid
    form = AddressForm().validate_for_api()
    UserAddress.update_user_address(uid, form)
    return Success()