sumByCode($orderCoinExchange)){ // 不存在新建 $this->add($orderCoinExchange); } return $this; } private function sumByCode(PreOrderCoinExchange $orderCoinExchange) { // 存在相同类型累加金额和数量 foreach ($this->items as &$item) { if ($item['code'] == $orderCoinExchange->code) { $item['amount'] = sprintf("%.2f",$item['amount'] + $orderCoinExchange->amount); $item['coin'] = sprintf("%.2f",$item['coin'] + $orderCoinExchange->coin); $item['use_money'] = sprintf("%.2f",$item['use_money'] + $orderCoinExchange->use_money); return true; } } return false; } }