thinkphp: データベースの特定のフィールドの値を増減します (dec, inc の使用)

例: フィールド po_num の値が配列 list_info の po_num の値と等しい場合、データベース テーブル po_rcv_receipt_line 内の一部の情報を変更します。

1. データベースのdelivery_quantityフィールドの値 = データベースのdelivery_quantityの値 + 変数$list_info['write_quantity']

->inc('配達数量', $list_info['書き込み数量'])

2. データベースの wait_delivery_quantity フィールドの値 = データベースの wait_delivery_quantity の値 - 変数 $list_info['write_quantity']

->dec('納品待ち', $list_info['書き込み数量'])

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,
]);

おすすめ

転載: blog.csdn.net/weixin_46001736/article/details/132235243