예제 #1
0
 /**
  * 添加一个商品到订单商品明细表中
  * @param $goods   商品ActiveRecord 或 商品id
  * @param $number  商品数量
  * @param $orderid 订单id
  * @return OrderItem|bool
  */
 public function addOne($goods = 0, $number = 1, $orderid = null)
 {
     $orderItem = new OrderItem();
     if (is_integer($goods)) {
         $goods = Goods::findOne(['goods_id' => $goods]);
     }
     $orderItem->item_name = $goods['goods_name'];
     $orderItem->item_price = $goods['goods_price'];
     $orderItem->item_unit = $goods['goods_unit'];
     $orderItem->goods_id = $goods['goods_id'];
     $orderItem->item_number = $number;
     $orderItem->subtotal = $goods['goods_price'] * $number;
     $orderItem->order_id = $orderid;
     return $orderItem->save() ? $orderItem : false;
 }