public function store() { try { $createOrder = Input::json()->all(); $addOrder = new Order(); $addOrder->status = 1; $addOrder->save(); $addOrderId = $addOrder->id; $numberOfItems = 0; foreach ($createOrder['items'] as $OrderItem) { $newOrderItem = new Order_Item(); $newOrderItem->order_id = $addOrderId; $newOrderItem->item_id = $OrderItem['item_id']; $newOrderItem->order_qty = $OrderItem['order_qty']; $newOrderItem->save(); $numberOfItems = $numberOfItems + 1; } $addOrder->items = $createOrder['items']; $addOrder->open = 'yes'; $vendorId = $createOrder['vendor_id']; $addOrder->vendor_id = $vendorId; $vendorName = Vendor::find($vendorId); $addOrder->vendor_name = $vendorName->name; $addOrder->item_count = $numberOfItems; $this->addOrderToEmail($addOrder); return $addOrder->toJson(); } catch (Exception $e) { return '{"error":{"text":' . $e->getMessage() . '}}'; } }
/** * 订单商品添加 */ public function actionAddOrderItem($ord_id, $item_id) { $comm_model = Commodity::model(); if ($item_id != 0) { //已经选择了item $ord_item_model = new Order_Item(); //为了这个奇葩的id(要用ord_id来算,还要从0开始计数) $ord_item_model->pk_ord_itm_id = ($ord_id - 80000000) * 1000; $query = 'select * from tbl_order_item where pk_ord_itm_ord_id = ' . $ord_id; $ord_item_info = $ord_item_model->findAllBySql($query); $ord_item_model->pk_ord_itm_id += count($ord_item_info); $ord_item_model->pk_ord_itm_ord_id = $ord_id; $ord_item_model->ord_item_comm_id = $item_id; $ord_item_model->ord_item_num = 1; $comm_info = $comm_model->findByPk($item_id); if ($comm_info) { $ord_item_model->ord_item_price = $comm_info->comm_price; } if ($ord_item_model->save()) { $this->redirect("./index.php?r=order/detail&id={$ord_id}"); } else { //var_dump($user_info->getErrors()); //var_dump($customer_info->getErrors()); echo "<script>alert('出错啦003!');</script>"; } } $comm_info = $comm_model->findAll(); $this->renderPartial('addOrderItem', array('ord_id' => $ord_id, 'comm_info' => $comm_info)); }