---
# System prepended metadata

title: Untitled

---

## Rollback hệ thống
Ngày 12/6/2019, ThuyVM yêu cầu rollback lại 21 order variant đã được paid trong các masspay khác nhau.

![](https://i.imgur.com/950c0Lt.png)


**Solutions**
Các Order ID cần xử lý 
format: `<orders.id>_<order_variants.id>_<admin_order_variants.id>`
```
1564860_1717794_422953
1564882_1717815_422951
1561014_1714404_422889
1561027_1714415_422888
1561364_1714708_422869
1561437_1714767_422868
1561539_1714860_422860
1561604_1714918_422855
1553986_1708221_422673
1554345_1708554_422654
1554432_1708637_422647
1554750_1708920_422639
1555032_1709202_422637
1553048_1707388_422622
1553458_1707739_422600
1553507_1707784_422594
1553549_1707820_422591
1552083_1706506_422553
1552431_1706802_422530
1552765_1707109_422518
1551718_1706185_422501

```

- [x] Xóa foreign key admin_order_variant_id trên các order_variants và cập nhập trạng thái về TO_ORDER
```sql
update order_variants set admin_order_variant_id=null, status=0 where admin_order_variant_id in (422953, 422951, 422889, 422888, 422869, 422868, 422860, 422855, 422673, 422654, 422647, 422639, 422637, 422622, 422600, 422594, 422591, 422553, 422530, 422518, 422501)
```
- [x] Làm đúng lại `orders.status` 
```sql
update orders set status = 0 where id in ();
```

- [x] Xóa các masspay_order_variants được tạo ra khi tạo masspays (SRF)
```sql
delete from masspay_order_variants where admin_order_variant_id in (422953, 422951, 422889, 422888, 422869, 422868, 422860, 422855, 422673, 422654, 422647, 422639, 422637, 422622, 422600, 422594, 422591, 422553, 422530, 422518, 422501);
```

- [x]Lấy số lượng stock cần cộng lại cho seller
```sql
select s.seller_id, sku_code, count(quantity) from admin_order_variants
join upinus_variants uv on admin_order_variants.upinus_variant_id = uv.id
join admin_orders ao on admin_order_variants.admin_order_id = ao.id
join shops s on ao.shop_id = s.id
where admin_order_variants.id in (493633, 493413, 493359, 493330, 493308, 493305, 493477)
group by s.seller_id, sku_code;

```
```
51,01DMIC_RDXM601G0,3
51,01DMIC_BKXR601G0,3
51,01DMIC_BK7P601G0,1
```

- [x] Xóa các admin_order_variants được tạo ra khi paid masspays (SRF)
```sql
delete from admin_order_variants where id in (422953, 422951, 422889, 422888, 422869, 422868, 422860, 422855, 422673, 422654, 422647, 422639, 422637, 422622, 422600, 422594, 422591, 422553, 422530, 422518, 422501)
```


- [x] Cộng lại stock cho Seller
```sql
select * from stocks where seller_id=51 and usku='01DMIC_BK7P601G0';

insert into stock_histories (quantity, stock_id, sri_id, ffri_id, created_at, updated_at)
values (1, 1916, 'ROLLBACK_RF', 'ROLLBACL_RF', 1567756215, 1567756215);
```