public function create($product, $count) { $number = new_ticket_number($product); $product = $this->db->get_where('product', array('id' => $product))->row_array(); $this->db->insert('ticket', array("number" => $number, "create_time" => time(), "credit" => $product['norm_value'] * $count, "product_id" => $product['id'], "count" => $count, "state" => 0, "fulfill_time" => 0, "agent" => 0)); echo json_encode(array('product' => $product, 'number' => $number)); }
public function create($product, $product_count, $ticket_count) { $product = $this->db->get_where('product', array('id' => $product))->row_array(); if ($product_count > $product['count_max'] || $product_count < $product['count_min']) { echo json_encode(array('success' => 0, 'max' => $product['count_max'], 'min' => $product['count_min'])); return; } $tickets = array(); for ($i = 0; $i < $ticket_count; $i++) { $number = new_ticket_number($product['id']); $price = get_price($product['id'], $this->user['level']); $this->db->insert('ticket', array("number" => $number, "create_time" => time(), "credit" => $price * $product_count, "product_id" => $product['id'], "count" => $product_count, "state" => 0, "fulfill_time" => 0, "agent" => $this->user['id'])); $tickets[] = $number; } echo json_encode(array('success' => 1, 'tickets' => $tickets)); }