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; }
/** * Import Orders * * @param string $lastUpdatedTime The datatime string * * @return B2BConnector */ public function importOrders($lastUpdatedTime = '') { $totalItems = 0; $this->_log(0, get_class($this), 'starting ...', self::LOG_TYPE, 'start', __FUNCTION__); if (($lastUpdatedTime = trim($lastUpdatedTime)) === '') { $this->_log(0, get_class($this), 'Getting the last updated time', self::LOG_TYPE, '$lastUpdatedTime is blank', __FUNCTION__); // $lastImportTime = new UDate(SystemSettings::getSettings(SystemSettings::TYPE_B2B_SOAP_LAST_IMPORT_TIME), SystemSettings::getSettings(SystemSettings::TYPE_B2B_SOAP_TIMEZONE)); $lastUpdatedTime = trim(SystemSettings::getSettings(SystemSettings::TYPE_B2B_SOAP_LAST_IMPORT_TIME)); } //getting the lastest order since last updated time $orders = $this->getlastestOrders($lastUpdatedTime); $this->_log(0, get_class($this), 'Found ' . count($orders) . ' order(s) since "' . $lastUpdatedTime . '".', self::LOG_TYPE, '', __FUNCTION__); if (is_array($orders) && count($orders) > 0) { $transStarted = false; try { try { Dao::beginTransaction(); } catch (Exception $e) { $transStarted = true; } foreach ($orders as $index => $order) { $this->_log(0, get_class($this), 'Found order from Magento with orderNo = ' . trim($order->increment_id) . '.', self::LOG_TYPE, '', __FUNCTION__); $order = $this->getOrderInfo(trim($order->increment_id)); if (!is_object($order)) { $this->_log(0, get_class($this), 'Found no object from $order, next element!', self::LOG_TYPE, '$index = ' . $index, __FUNCTION__); continue; } if (($status = trim($order->state)) === '') { $this->_log(0, get_class($this), 'Found no state Elment from $order, next element!', self::LOG_TYPE, '$index = ' . $index, __FUNCTION__); continue; } //saving the order $orderDate = new UDate(trim($order->created_at), SystemSettings::getSettings(SystemSettings::TYPE_B2B_SOAP_TIMEZONE)); $orderDate->setTimeZone('UTC'); // $totalPaid = (!isset($order->total_paid) ? 0 : trim($order->total_paid)); $shippingAddr = $billingAddr = null; if (($o = Order::getByOrderNo(trim($order->increment_id))) instanceof Order) { //skip, if order exsits $this->_log(0, get_class($this), 'Found order from DB, ID = ' . $o->getId(), self::LOG_TYPE, '$index = ' . $index, __FUNCTION__); continue; // $shippingAddr = $o->getShippingAddr(); // $billingAddr = $o->getBillingAddr(); } $o = new Order(); $this->_log(0, get_class($this), 'Found no order from DB, create new', self::LOG_TYPE, '$index = ' . $index, __FUNCTION__); $customer = Customer::create(isset($order->billing_address) && isset($order->billing_address->company) && trim($order->billing_address->company) !== '' ? trim($order->billing_address->company) : (isset($order->customer_firstname) ? trim($order->customer_firstname) . ' ' . trim($order->customer_lastname) : ''), '', trim($order->customer_email), $this->_createAddr($order->billing_address, $billingAddr), true, '', $this->_createAddr($order->shipping_address, $shippingAddr), isset($order->customer_id) ? trim($order->customer_id) : 0); $o->setOrderNo(trim($order->increment_id))->setOrderDate(trim($orderDate))->setTotalAmount(trim($order->grand_total))->setStatus(strtolower($status) === 'canceled' ? OrderStatus::get(OrderStatus::ID_CANCELLED) : OrderStatus::get(OrderStatus::ID_NEW))->setIsFromB2B(true)->setShippingAddr($customer->getShippingAddress())->setBillingAddr($customer->getBillingAddress())->setCustomer($customer)->save(); $this->_log(0, get_class($this), 'Saved the order, ID = ' . $o->getId(), self::LOG_TYPE, '$index = ' . $index, __FUNCTION__); $totalShippingCost = StringUtilsAbstract::getValueFromCurrency(trim($order->shipping_amount)) * 1.1; //create order info $this->_createOrderInfo($o, OrderInfoType::get(OrderInfoType::ID_CUS_NAME), trim($customer->getName()))->_createOrderInfo($o, OrderInfoType::get(OrderInfoType::ID_CUS_EMAIL), trim($customer->getEmail()))->_createOrderInfo($o, OrderInfoType::get(OrderInfoType::ID_QTY_ORDERED), intval(trim($order->total_qty_ordered)))->_createOrderInfo($o, OrderInfoType::get(OrderInfoType::ID_MAGE_ORDER_STATUS), trim($order->status))->_createOrderInfo($o, OrderInfoType::get(OrderInfoType::ID_MAGE_ORDER_STATE), trim($order->state))->_createOrderInfo($o, OrderInfoType::get(OrderInfoType::ID_MAGE_ORDER_TOTAL_AMOUNT), trim($order->grand_total))->_createOrderInfo($o, OrderInfoType::get(OrderInfoType::ID_MAGE_ORDER_SHIPPING_METHOD), trim($order->shipping_description))->_createOrderInfo($o, OrderInfoType::get(OrderInfoType::ID_MAGE_ORDER_SHIPPING_COST), $totalShippingCost)->_createOrderInfo($o, OrderInfoType::get(OrderInfoType::ID_MAGE_ORDER_PAYMENT_METHOD), !isset($order->payment) ? '' : (!isset($order->payment->method) ? '' : trim($order->payment->method))); $this->_log(0, get_class($this), 'Updated order info', self::LOG_TYPE, '$index = ' . $index, __FUNCTION__); //saving the order item $totalItemCost = 0; foreach ($order->items as $item) { $this->_createItem($o, $item); $totalItemCost = $totalItemCost * 1 + StringUtilsAbstract::getValueFromCurrency($item->row_total) * 1.1; } if (($possibleSurchargeAmount = $o->getTotalAmount() - $totalShippingCost - $totalItemCost) > 0 && ($product = Product::getBySku('surcharge')) instanceof Product) { OrderItem::create($o, $product, $possibleSurchargeAmount, 1, $possibleSurchargeAmount); } //record the last imported time for this import process SystemSettings::addSettings(SystemSettings::TYPE_B2B_SOAP_LAST_IMPORT_TIME, trim($order->created_at)); $this->_log(0, get_class($this), 'Updating the last updated time :' . trim($order->created_at), self::LOG_TYPE, '', __FUNCTION__); $totalItems++; } if ($transStarted === false) { Dao::commitTransaction(); } } catch (Exception $e) { if ($transStarted === false) { Dao::rollbackTransaction(); } throw $e; } } $this->_log(0, get_class($this), $lastUpdatedTime . " => " . SystemSettings::getSettings(SystemSettings::TYPE_B2B_SOAP_LAST_IMPORT_TIME) . ' => ' . $totalItems, self::LOG_TYPE, '', __FUNCTION__); return $this; }
$db->query($sql); if ($sends > 0) { $sql = "INSERT INTO " . $ecs->table('order_goods') . "( " . "order_id, goods_id, goods_name, goods_sn, goods_number, " . "goods_price, goods_attr, goods_discount,is_integral) " . " values('{$new_order_id}', 60, '餐具套装', '00', '{$sends}','0', '',1,0) "; $db->query($sql); } if (isset($_COOKIE['emar'])) { include_once 'api/advertiser/Sender.php'; include_once 'api/advertiser/Order.php'; include_once 'api/advertiser/OrderStatus.php'; include_once 'api/advertiser/Product.php'; include_once 'api/advertiser/Service.php'; include_once 'api/util/Config.php'; $value = urldecode($_COOKIE['emar']); $arr = explode(":", $value); $cps = new Order(); $cps->setOrderNo($order['order_sn']); $add_time = date("Y-m-d H:i:s", $order['add_time'] + 8 * 3600); $cps->setOrderTime($add_time); // 设置下单时间 $cps->setUpdateTime($add_time); // 设置订单更新时间,如果没有下单时间,要提前对接人提前说明 $cps->setCampaignId($arr[2]); // 测试时使用"101",正式上线之后活动id必须要从cookie中获取 $cps->setFeedback($arr[3]); // 测试时使用"101",正式上线之后活动id必须要从cookie中获取 $cps->setFare($order['shipping_fee']); $cps->setFavorable($order['bonus'] + $order['surplus']); // 设置优惠券 $cps->setOrderStatus($order['order_status']); // 设置订单状态 $cps->setPaymentStatus($order['pay_status']);
/** * 接口测试类 * * 正式调用时订单、商品信息必须要严格填写。 * 这个页面编码格式GBK的,跟配置文件中页面的编码是一致的,所以如果调用这个文件的话 * @var */ // $service = new Service(); $order = new Order(); //$order -> setOrderNo($_POST["orderNo"]); // 设置订单编号 //$order -> setOrderNo($_GET["orderNo"]); $a = rand(0, 999999); $b = rand(1, 100000); $c = rand(0, 999999); $orderno = $a + $b . $c; $order->setOrderNo("000000"); $order->setOrderTime("2012-04-05 10:09:09"); // 设置下单时间 $order->setUpdateTime("2012-04-05 20:09:09"); // 设置订单更新时间,如果没有下单时间,要提前对接人提前说明 $order->setCampaignId("101"); // 测试时使用"101",正式上线之后活动id必须要从cookie中获取 $order->setFeedback("NDgwMDB8dGVzdA=="); // 测试时使用"101",正式上线之后活动id必须要从cookie中获取 $order->setFare("10"); // 设置邮费 $order->setFavorable("30"); // 设置优惠券 $order->setFavorableCode("30YHM"); $order->setOrderStatus("active"); // 设置订单状态
/** * * @param Customer $customer * @param string $orderNo * @param OrderStatus $status * @param string $orderDate * @param string $type * @param string $isFromB2B * @param Address $shipAddr * @param Address $billAddr */ public static function create(Customer $customer, $type = self::TYPE_ORDER, $orderNo = null, $comments = '', OrderStatus $status = null, $orderDate = null, $isFromB2B = false, Address $shipAddr = null, Address $billAddr = null, $passPaymentCheck = false, $poNo = '', Order $cloneFrom = null) { $order = new Order(); $order->setOrderNo(trim($orderNo))->setCustomer($customer)->setStatus($status instanceof OrderStatus ? $status : OrderStatus::get(OrderStatus::ID_NEW))->setOrderDate(trim($orderDate) === '' ? trim(new UDate()) : trim($orderDate))->setIsFromB2B($isFromB2B)->setType(trim($type) === '' ? self::TYPE_ORDER : trim($type))->setShippingAddr($shipAddr instanceof Address ? $shipAddr : $customer->getShippingAddress())->setBillingAddr($billAddr instanceof Address ? $billAddr : $customer->getBillingAddress())->setPassPaymentCheck($passPaymentCheck)->setPONo(trim($poNo)); if ($cloneFrom instanceof Order) { $counts = intval(OrderInfo::countByCriteria('value = ? and typeId = ?', array($cloneFrom->getOrderNo(), OrderInfoType::ID_CLONED_FROM_ORDER_NO))); $newOrderNo = $cloneFrom->getOrderNo() . '-' . ($counts + 1); $order->setOrderNo($newOrderNo); $cloneFrom->addComment($msg = 'A new order has been clone from this order:' . $newOrderNo, Comments::TYPE_SYSTEM)->addLog($msg, Log::TYPE_SYSTEM); } $order->save(); if ($cloneFrom instanceof Order) { $order->addInfo(OrderInfoType::ID_CLONED_FROM_ORDER_NO, $cloneFrom->getOrderNo(), true)->addComment($msg = 'Cloned from Order:' . $cloneFrom->getOrderNo(), Comments::TYPE_SYSTEM)->addLog($msg, Comments::TYPE_SYSTEM); } $order->addComment($comments, Comments::TYPE_NORMAL)->addInfo(OrderInfoType::ID_CUS_EMAIL, $customer->getEmail())->addInfo(OrderInfoType::ID_CUS_NAME, $customer->getName())->addLog('Order (OrderNo.=' . $order->getOrderNo() . ') created with status: ' . $order->getStatus()->getName(), Log::TYPE_SYSTEM, 'Auto Log', __CLASS__ . '::' . __FUNCTION__); return $order; }