public function getOrderByOrderTime($campaignId, $orderStatTime, $orderEndTime) { if (empty($campaignId) || empty($orderStatTime) || empty($orderEndTime)) { echo "campaignId ,orderStatTime or orderEndTime is null"; exit; } $sql = "SELECT p.order_id,order_sn,add_time,order_status,pay_status,pay_name,order_time,cid,wi,order_status,pay_status,pay_name,shipping_fee,surplus,bonus,order_amount FROM `cps` as p LEFT OUTER JOIN ecs_order_info as i on i.order_id=p.order_id where p.cid=" . $campaignId . " and order_time>" . $orderStatTime . " and order_time<" . $orderEndTime; $dborder = $GLOBALS['db']->getAll($sql); if (empty($dborder)) { return NULL; } foreach ($dborder as $k => $v) { $order = new Order(); $order->setOrderNo($v['order_sn']); $order_time = date('Y-m-d H:i:s', $v['order_time']); $order->setOrderTime($order_time); // 设置下单时间 $order->setUpdateTime($order_time); // 设置订单更新时间,如果没有下单时间,要提前对接人提前说明 $order->setCampaignId($v['cid']); // 测试时使用"101",正式上线之后活动id必须要从数据库里面取 $order->setFeedback($v['wi']); $order->setFare($v['shipping_fee']); $order->setFavorable($v['bonus'] + $v['surplus']); //$orderStatus = new OrderStatus(); //$orderStatus -> setOrderNo($order -> getOrderNo()); $order->setOrderStatus($v['order_status']); // 设置订单状态 $order->setPaymentStatus($v['pay_status']); // 设置支付状态 $order->setPaymentType($v['pay_name']); // 支付方式 $sql = "select * from ecs_order_goods where order_id=" . $v['order_id'] . " and goods_price>100"; $order_goods = $GLOBALS['db']->getAll($sql); //echo "<pre>";print_r($order_goods); foreach ($order_goods as $k1 => $v1) { $pro = new Product(); //$pro -> setOrderNo($order -> getOrderNo()); $pro->setProductNo($v1['goods_sn']); $pro->setName($v1['goods_name']); $pro->setCategory("蛋糕"); $pro->setCommissionType(""); $pro->setAmount($v1['goods_number']); $a = number_format($v1['goods_price'] * (1 - ($v['bonus'] + $v['surplus']) / ($v['bonus'] + $v['surplus'] + $v['order_amount'])), 2, ".", ""); $pro->setPrice($a); $products[] = $pro; } $order->setProducts($products); $orderlist[] = $order; $products = array(); } //print_r($orderlist); //echo json_encode($orderlist); return $orderlist; }
public function getProduct($product_id) { $db = Database::getDB(); $query = "SELECT * FROM products\n WHERE productID = '{$product_id}'"; $result = $db->query($query); $row = $result->fetch(); $category = CategoryDB::getCategory($row['categoryID']); $product = new Product(); $product->setCategory($category); $product->setId($row['productID']); $product->setCode($row['productCode']); $product->setName($row['productName']); $product->setPrice($row['listPrice']); return $product; }
header("Location: .?category_id={$category_id}"); } else { if ($action == 'show_add_form') { $categories = $categoryDB->getCategories(); include 'product_add.php'; } else { if ($action == 'add_product') { $category_id = filter_input(INPUT_POST, 'category_id', FILTER_VALIDATE_INT); $code = filter_input(INPUT_POST, 'code'); $name = filter_input(INPUT_POST, 'name'); $price = filter_input(INPUT_POST, 'price'); if ($category_id == NULL || $category_id == FALSE || $code == NULL || $name == NULL || $price == NULL || $price == FALSE) { $error = "Invalid product data. Check all fields and try again."; include '../errors/error.php'; } else { $current_category = $categoryDB->getCategory($category_id); // Create the Product object $product = new Product(); $product->setCategory($current_category); $product->setCode($code); $product->setName($name); $product->setPrice($price); // Add the Product object to the database $productDB->addProduct($product); // Display the Product List page for the current category header("Location: .?category_id={$category_id}"); } } } } }
$cps->setFare($order['shipping_fee']); $cps->setFavorable($order['bonus'] + $order['surplus']); // 设置优惠券 $cps->setOrderStatus($order['order_status']); // 设置订单状态 $cps->setPaymentStatus($order['pay_status']); // 设置支付状态 $cps->setPaymentType($order['pay_name']); // 支付方式 foreach ($cart_goods as $k => $v) { if ($v['goods_price'] > 0) { $pro = new Product(); // $pro2 -> setOrderNo($order -> getOrderNo()); $pro->setProductNo($v['goods_sn']); $pro->setName($v['goods_name']); $pro->setCategory("蛋糕"); $pro->setCommissionType(""); $pro->setAmount($v['goods_number']); $a = number_format($v['goods_price'] * (1 - ($order['bonus'] + $order['surplus']) / ($order['bonus'] + $order['surplus'] + $order['order_amount'])), 2, ".", ""); $pro->setPrice($a); $products[] = $pro; } } $cps->setProducts($products); //var_dump(get_object_vars($cps)); $sender = new Sender(); $sender->setOrder($cps); $sender->sendOrder(); $ordertime = $order['add_time'] + 8 * 3600; $sql = "INSERT INTO cps ( " . "order_id,src,channel,cid,wi,order_time)" . " values('{$new_order_id}','emar','cps'," . $arr[2] . ",'" . $arr[3] . "','" . $ordertime . "') "; $db->query($sql);
/** * @param Product $product The product object to add. */ protected function doAddProduct($product) { $this->collProducts[] = $product; $product->setCategory($this); }
public function importProducts(Import $entity, $output) { $sql = ' SELECT p.*, o.nombre as opticName, m.nombre as brand, mo.nombre as model, s.nombre as category FROM `producto` AS p ' . ' LEFT JOIN optica AS o ON o.id = p.id_optica ' . ' LEFT JOIN servicio AS s ON s.id = p.id_servicio ' . ' LEFT JOIN marca AS m ON m.id_marca = p.id_marca ' . ' LEFT JOIN modelo AS mo ON mo.id_modelo = p.id_modelo ' . ' ORDER BY p.id ' . ' LIMIT ' . $entity->getLimitStart() . ', ' . $entity->getLimitEnd(); $link = mysqli_connect($entity->getServer(), $entity->getUsername(), $entity->getPassword(), $entity->getDbname()) or die('No se pudo conectar: ' . mysqli_error($link)); $resultado = $link->query($sql); $x = 0; if (mysqli_num_rows($resultado) > 0) { while ($fila = mysqli_fetch_assoc($resultado)) { $x++; print_r($x . '-' . utf8_encode($fila['nombre'])); echo PHP_EOL; $em = $this->container->get('doctrine')->getManager(); $optic = $em->getRepository('CoreBundle:Optic')->findOneByName(utf8_encode($fila['opticName'])); $category = $em->getRepository('EcommerceBundle:Category')->findOneByName(utf8_encode($fila['category'])); $brand = $em->getRepository('EcommerceBundle:Brand')->findOneByName(utf8_encode($fila['brand'])); $model = $em->getRepository('EcommerceBundle:BrandModel')->findOneByName(utf8_encode($fila['model'])); //Create Products if ($optic instanceof Optic && $fila['id'] != 746 && $fila['id'] != 747 && $fila['id'] != 748 && $fila['id'] != 749 && $fila['id'] != 750 && $fila['id'] != 751 && $fila['id'] != 752 && $fila['id'] != 753) { $product = new Product(); $product->setName(utf8_encode($fila['nombre'])); $product->setDescription(utf8_encode($fila['descripcion'])); if ($fila['precio_original'] != '') { $product->setInitPrice($fila['precio_original']); } else { $product->setInitPrice(0); } $product->setPrice($fila['precio']); if ($fila['tipo_precio'] != '') { $product->setPriceType($fila['tipo_precio']); } else { $product->setPriceType(0); } $product->setDiscount($fila['descuento']); $product->setDiscountType($fila['tipo_descuento']); if ($fila['stock'] != '') { $product->setStock($fila['stock']); } else { $product->setStock(0); } $product->setWeight($fila['kilos']); $product->setOutlet($fila['outlet']); $product->setPublic($fila['publicado']); if ($fila['recoger_tienda'] != '') { $product->setStorePickup($fila['recoger_tienda']); } else { $product->setStorePickup(0); } $product->setMetaTitle(utf8_encode($fila['meta_titulo'])); $product->setMetaDescription(utf8_encode($fila['meta_descripcion'])); $product->setMetaTags(utf8_encode($fila['meta_keywords'])); $product->setOptic($optic); $product->setBrand($brand); $product->setModel($model); $product->setCategory($category); $product->setActive(true); $product->setAvailable(true); $product->setHighlighted(false); $product->setFreeTransport(false); $slug = $this->slugify(utf8_encode($fila['nombre'] . '-' . $optic->getCity())); // $p = $em->getRepository('EcommerceBundle:Product')->findOneBySlug($slug); // if($p instanceof Product) $slug = $slug.'_'.rand(1000,9999); $product->setSlug($slug); $em->persist($product); $em->flush(); //image if ($fila['imagen'] != '') { $imagePath = ''; $dir = '/home/sebastian/www/src/Symfony/web/uploads/documents'; $absoluteImagePath = $dir . '/' . utf8_encode($fila['imagen']); if (file_exists($absoluteImagePath . '.jpeg')) { $imagePath = utf8_encode($fila['imagen']) . '.jpeg'; } if (file_exists($absoluteImagePath . '.jpg')) { $imagePath = utf8_encode($fila['imagen']) . '.jpg'; } if (file_exists($absoluteImagePath . '.gif')) { $imagePath = utf8_encode($fila['imagen']) . '.gif'; } if (file_exists($absoluteImagePath . '.png')) { $imagePath = utf8_encode($fila['imagen']) . '.png'; } //Thumb $imagePathThumb = ''; $absoluteImagePathThumb = $dir . '/' . utf8_encode($fila['imagen']) . '_260.jpg'; if (file_exists($absoluteImagePathThumb)) { $imagePathThumb = utf8_encode($fila['imagen']) . '_260.jpg'; } $imagePathThumb2 = ''; $absoluteImagePathThumb2 = $dir . '/' . utf8_encode($fila['imagen']) . '_142.jpg'; if (file_exists($absoluteImagePathThumb2)) { $imagePathThumb2 = utf8_encode($fila['imagen']) . '_142.jpg'; } if ($imagePath == '') { $dir = 'http://web.com/uploads/documents/'; $imagePath = $fila['imagen'] . '.' . $fila['extension_img']; } print_r($dir . '/' . $imagePath); echo PHP_EOL; @mkdir(__DIR__ . '/../../../../../web/uploads/images/product'); @mkdir(__DIR__ . '/../../../../../web/uploads/images/product/' . $product->getId()); @mkdir(__DIR__ . '/../../../../../web/uploads/images/product/' . $product->getId() . '/thumbnail'); copy($dir . '/' . $imagePath, __DIR__ . '/../../../../../web/uploads/images/product/' . $product->getId() . '/' . $imagePath); if ($imagePathThumb != '') { copy($dir . '/' . $imagePathThumb, __DIR__ . '/../../../../../web/uploads/images/product/' . $product->getId() . '/thumbnail/' . $imagePathThumb); } if ($imagePathThumb2 != '') { copy($dir . '/' . $imagePathThumb2, __DIR__ . '/../../../../../web/uploads/images/product/' . $product->getId() . '/thumbnail/' . $imagePathThumb2); } $image0 = new Image(); $image0->setPath($imagePath); $product->addImage($image0); $em->persist($image0); } $em->flush(); } } } }
$pro->setCategory("asdf"); // 设置商品类型 $pro->setCommissionType("A"); // 设置佣金类型,如:普通商品 佣金比例是10%、佣金编号(可自行定义然后通知双方商务)A $pro->setAmount("1"); // 设置商品数量 $pro->setPrice("3000"); // 设置商品价格 $pro1 = new Product(); // $pro1 -> setOrderNo($order -> getOrderNo()); $pro1->setProductNo("1002"); $pro1->setName("测试商品5"); $pro1->setCategory("a"); $pro1->setCommissionType("B"); $pro1->setAmount("3"); $pro1->setPrice("100"); $pro2 = new Product(); // $pro2 -> setOrderNo($order -> getOrderNo()); $pro2->setProductNo("1003"); $pro2->setName("测试商品4"); $pro2->setCategory("2"); $pro2->setCommissionType("B"); $pro2->setAmount("5"); $pro2->setPrice("500"); $products = array($pro, $pro1, $pro2); // 实现商品信息集合 $order->setProducts($products); //var_dump(get_object_vars($order)); $sender = new Sender(); $sender->setOrder($order); $sender->sendOrder();