thinkphp:对数据库减少增加某个字段的值(dec、inc的用法)

例子:当字段po_num的值等于数组list_info中的po_num的值时修改数据库表po_rcv_receipt_line中某些信息:

1、数据库delivery_quantity字段的值 = 数据库中delivery_quantity的值+变量$list_info['write_quantity']

->inc('delivery_quantity',  $list_info['write_quantity'])

2、数据库wait_delivery_quantity字段的值 = 数据库中wait_delivery_quantity的值-变量$list_info['write_quantity']

->dec('wait_delivery_quantity', $list_info['write_quantity'])

3、数据库last_update_date字段的值 = 当前时间戳

4、last_updated_by字段的值 = 变量$username

Db::table('po_rcv_receipt_line')
->where([
    'po_num' => $list_info['po_num'],
 ])
->inc('delivery_quantity',  $list_info['write_quantity'])
->dec('wait_delivery_quantity', $list_info['write_quantity'])
 ->update([
    'last_update_date' => time(),
    'last_updated_by' => $username,
]);

你可能感兴趣的:(thinkphp,windows,服务器,后端,php)