Authored by whb

添加修改订单价格接口

... ... @@ -9,4 +9,164 @@
class YHMApi_App_V2_Shopping extends YHMApi_App_V1_Shopping
{
use YHMApi_App_V2_Base;
/**
* 提交订单
*
* @param array $params
* @param string $fields
* @return array
*/
public static function commit(array $params, $fields = '*')
{
if (empty($params['product_sku'])) {
return self::result(YHMConfig_Mobile::WARING_CODE, '请选择购买商品.');
}
if (empty($params['buyer_uid'])) {
return self::result(YHMConfig_Mobile::WARING_CODE, '购买者不明确.');
}
if (empty($params['delivery_info_id'])) {
return self::result(YHMConfig_Mobile::WARING_CODE, '送货信息不能为空.');
}
$goodsInfo = YHMProduct_Models_Goods_Client::getOneByProductSkc($params['product_sku']);
$orderRemark = (empty($params['order_remark']) ? '' : $params['order_remark']);
$productSku = $params['product_sku'];
$buyerUid = $params['buyer_uid'];
$paymentID = empty($params['payment_id']) ? 1 : $params['payment_id'];
$shippingFee = empty($params['shipping_fee']) ? 0 : $params['shipping_fee'];
$deliveryInfoID = $params['delivery_info_id'];
$buyNumber = empty($params['buy_number']) ? 1 : $params['buy_number'];
$orderData = array(
'buyer_uid' => $buyerUid,
'buying_way' => 1,
'shipping_fee' => $shippingFee,
'last_shipping_fee' => $shippingFee,
'payment_id' => $paymentID,
'order_remark' => $orderRemark,
'goods_list' => array(
array(
'product_sku' => $productSku,
'buy_number' => $buyNumber
)
)
);
$deliveryInfo = YHMDelivery_Models_Delivery_Client::getDeliveryById($deliveryInfoID);
if (empty($deliveryInfo)) {
return self::result(YHMConfig_Mobile::NOTICE_CODE, '送货信息不能为空.');
}
$resultData = array();
try {
$ordinary = new YHMCart_Orders_Ordinary($buyerUid);
$_orderData = $ordinary->initOrdersData($orderData);
print_r($_orderData);
exit();
foreach ($_orderData as $orderKey => $lastOrderData) {
$returnOrder = $ordinary->create($lastOrderData);
$resultData['order_data'][] = array(
'order_code' => $returnOrder['order_code'],
'last_order_amount' => $returnOrder['last_order_amount']
);
YHMOrders_Models_Delivery_Client::addDelivery($returnOrder['order_code'], $deliveryInfo['delivery_name'], $deliveryInfo['mobile'], $deliveryInfo['area_code'], $deliveryInfo['address'], $deliveryInfo['zip_code']);
}
} catch (Exception $e) {
return self::result(YHMConfig_Mobile::NOTICE_CODE, $e->getMessage());
}
return self::result(YHMConfig_Mobile::SUCCESS_CODE, '订单成功.', $resultData);
}
/**
* 改价订单确认操作
*
* @param array $params
* @param string $fields
* @return array
*/
public static function confirm(array $params, $fields = '*')
{
return self::result(YHMConfig_Mobile::NOTICE_CODE, '改价订单确认操作废弃');
}
/**
* 修改价格
*
* @param array $params
* @param string $fields
* @return multitype:Integer String mixed string
*/
public static function change(array $params, $fields = '*')
{
if (empty($params['buyer_uid'])) {
return self::result(YHMConfig_Mobile::WARING_CODE, '缺少购买者.');
}
if (empty($params['product_skc'])) {
return self::result(YHMConfig_Mobile::WARING_CODE, '缺少购买商品.');
}
if (empty($params['seller_uid'])) {
return self::result(YHMConfig_Mobile::WARING_CODE, '缺少售卖者.');
}
if(empty($params['order_code'])) {
return self::result(YHMConfig_Mobile::WARING_CODE, '缺少订单号.');
}
if (empty($params['agreement_price'])) {
return self::result(YHMConfig_Mobile::WARING_CODE, '缺少修改后的价格.');
}
if ($params['agreement_price'] < 0) {
return self::result(YHMConfig_Mobile::WARING_CODE, '修改价格不能小于0');
}
if (!isset($params['agreement_shipping_fee'])) {
return self::result(YHMConfig_Mobile::WARING_CODE, '缺少修改后的运费价格.');
}
if ($params['agreement_shipping_fee'] < 0) {
return self::result(YHMConfig_Mobile::WARING_CODE, '修改运费价格不能小于0');
}
//订单信息
$order_info = YHMOrders_Models_Orders_Client::getOrdersInfoByOrderCode($params['order_code']);
if (empty($order_info)) {
return self::result(YHMConfig_Mobile::NOTICE_CODE, '没有这个订单');
}
// 目前一个订单只有一个商品,所以取出一条数据
$order_goods = current(YHMOrders_Models_Orders_Client::getGoodsInfoByOrderCode ( $params['order_code']));
if ($order_goods['product_skc'] != $params['product_skc']) {
return self::result(YHMConfig_Mobile::NOTICE_CODE, '没有这个订单商品.');
}
if ($order_info['seller_uid'] != $params['seller_uid']) {
return self::result(YHMConfig_Mobile::WARING_CODE, '此商品不是这个卖家的.');
}
try {
$package = array(
'buyer_uid' => $params['buyer_uid'],
'store_id' => $order_info['store_id'],
'seller_uid' => $order_info['seller_uid'],
'product_skc' => $order_goods['product_skc'],
'sale_price' => $order_goods['sale_price'],
'agreement_shipping_fee' => $params['agreement_shipping_fee'],
'order_shipping_fee' => $order_info['shipping_fee'],
'order_last_shipping_fee' => $order_info['last_shipping_fee'],
'order_amount' => $order_info['order_amount'],
'agreement_price' => $params['agreement_price'],
'buy_number' => $order_goods['buy_number'],
'goods_type' => YHMConfig_Orderstatus::ORDER_GOODS_TYPE_MAIN,
'order_code' =>$params['order_code'],
);
$agreementKey = YHMUtils_Tools::makeAgreementKey($package);
$package['agreement_key'] = $agreementKey;
$agreementID = YHMOrders_Models_Shopping_Client::addShoppingOrderChangePrice($package);
$status = false;
$agreementData = array (
'agreement_key' => $agreementKey,
'agreement_id' => $agreementID
);
if (! empty ( $agreementID )) {
$status = YHMOrders_Models_Orders_Client::updateOrderPrice ( $params ['order_code'], $params ['agreement_price'], $params ['agreement_shipping_fee'], $params ['agreement_shipping_fee'] );
}
if (empty ( $agreementID ) || ! empty ( $status )) {
return self::result(YHMConfig_Mobile::NOTICE_CODE, '改价失败');
}
} catch(Exception $e) {
return self::result(YHMConfig_Mobile::NOTICE_CODE, $e->getMessage());
}
return self::result(YHMConfig_Mobile::SUCCESS_CODE, '改价成功.', $agreementData);
}
}
\ No newline at end of file
... ...
... ... @@ -410,4 +410,17 @@ class YHMOrders_Models_Orders_Client {
return self::dao()->getBuyOrderTotalBySortOrderStatus($buyer_uid, $order_status);
}
/**
* 更新订单价格
*
* @param int $order_code
* @param float $order_amount
* @param float $shipping_fee
* @param float $last_shipping_fee
* @return boolean
*/
public static function updateOrderPrice($order_code, $order_amount, $shipping_fee, $last_shipping_fee)
{
return self::dao()->updateOrderPrice($order_code, $order_amount, $shipping_fee, $last_shipping_fee);
}
}
... ...
... ... @@ -513,4 +513,24 @@ class YHMOrders_Models_Orders_Dao extends YHMOrders_Dao {
$replaces = array('order_status' => implode(',', $order_status));
return $this->dao()->cache(false)->fetchOne(Orders\Order::GET_BUY_ORDER_TOTAL_BY_SORT_ORDER_STATUS, $params, $replaces);
}
/**
* 更新订单价格
*
* @param int $order_code
* @param float $order_amount
* @param float $shipping_fee
* @param float $last_shipping_fee
* @return boolean
*/
public function updateOrderPrice($order_code, $order_amount, $shipping_fee, $last_shipping_fee)
{
if(is_numeric($order_code) && is_numeric($order_amount) && is_numeric($shipping_fee) && is_numeric($last_shipping_fee))
{
$params = array('order_code' => $order_code, 'order_amount' => $order_amount,
'shipping_fee' => $shipping_fee, 'last_shipping_fee'=> $last_shipping_fee);
return $this->dao(false)->update(Orders\Order::UPDATE_ORDER_PRICE, $params)->rowCount();
}
return false;
}
}
... ...
<?php
/**
* Created by JetBrains PhpStorm.
* User: elkan
* Date: 14-8-5
* Time: 下午6:04
* To change this template use File | Settings | File Templates.
* 购物相关
*
*/
class YHMOrders_Models_Shopping_Client
{
... ... @@ -28,29 +24,40 @@ class YHMOrders_Models_Shopping_Client
return self::$dao;
}
static function create(array $orderData)
public static function create(array $orderData)
{
return self::dao()->create($orderData);
}
/**
* 修改价格
*
* @param array $package
* @return int
* @throws Exception
*/
static function addShoppingChangePrice(array $package)
public static function addShoppingChangePrice(array $package)
{
return self::dao()->addShoppingChangePrice($package);
}
/**
* 修改订单价格
*
* @param array $package
* @return int
*/
public static function addShoppingOrderChangePrice(array $package)
{
return self::dao()->addShoppingOrderChangePrice($package);
}
/**
* 获取购物改价
* @param $agreementKey
* @param $buyerUid
* @return Array
*/
static function getShoppingChangePrice($agreementKey, $buyerUid)
public static function getShoppingChangePrice($agreementKey, $buyerUid)
{
return self::dao()->getShoppingChangePrice($agreementKey, $buyerUid);
}
... ... @@ -61,7 +68,7 @@ class YHMOrders_Models_Shopping_Client
* @param $isBuyer
* @return int
*/
static function updateShoppingChange($agreementKey, $orderCode, $isBuyer = 'Y')
public static function updateShoppingChange($agreementKey, $orderCode, $isBuyer = 'Y')
{
return self::dao()->updateShoppingChange($agreementKey, $orderCode, $isBuyer);
}
... ... @@ -72,16 +79,17 @@ class YHMOrders_Models_Shopping_Client
* @param $orderStatus
* @return Array
*/
static function getBuyGoodsNumber($productSku, $orderStatus = 900)
public static function getBuyGoodsNumber($productSku, $orderStatus = 900)
{
return self::dao()->getBuyGoodsNumber((int)$productSku, (int)$orderStatus);
}
/**
/**
* 插入订单镜像表
* @param $storeID
* @return mixed
*/
static function setBuyGoodsInfo($data)
public static function setBuyGoodsInfo($data)
{
return self::dao()->setBuyGoodsInfo($data);
}
... ...
... ... @@ -146,7 +146,30 @@ class YHMOrders_Models_Shopping_Dao extends YHMOrders_Dao
}
/**
* 修改订单价格
*
* @param array $package
* @return int
*/
public function addShoppingOrderChangePrice(array $package)
{
$changeParameters = array(
'agreement_key', 'buyer_uid', 'store_id', 'seller_uid', 'product_skc', 'sale_price', 'agreement_price', 'buy_number', 'goods_type',
'agreement_shipping_fee','order_shipping_fee','order_amount','order_code','order_last_shipping_fee'
);
$parameter = array();
foreach ($changeParameters as $key) {
if (!isset($package[$key])) {
throw new Exception('改价异常,缺少字段:' . $key);
}
$parameter[$key] = $package[$key];
}
return $this->daoObject->insert(Shopping::INSERT_SHIPPING_ORDER_CHANGE_PRICE, $parameter)->lastInsertId();
}
/**
* 获取购物改价
*
* @param $agreementKey
* @param $buyerUid
* @return Array
... ...
... ... @@ -55,4 +55,6 @@ class Order
const GET_BUY_ORDER_BY_SORT_ORDER_STATUS = "SELECT order_code,buyer_uid,seller_uid, store_id,order_status,create_time,order_remark, order_status,shipping_fee,last_shipping_fee,last_order_amount FROM orders WHERE buyer_uid=:buyer_uid AND order_status IN(#order_status#) ORDER BY FIELD(order_status, #order_status#), create_time DESC LIMIT :offset, :limit";
const GET_BUY_ORDER_TOTAL_BY_SORT_ORDER_STATUS = "SELECT COUNT(*) FROM orders WHERE buyer_uid=:buyer_uid AND order_status IN(#order_status#)";
const GET_SELLER_ORDER_TOTAL_BY_SORT_ORDER_STATUS = "SELECT COUNT(*) FROM orders WHERE seller_uid=:seller_uid AND order_status IN(#order_status#)";
const UPDATE_ORDER_PRICE = 'UPDATE orders SET order_amount = :order_amount, last_shipping_fee = :last_shipping_fee, shipping_fee = :shipping_fee, last_order_amount = (:order_amount) + (:last_shipping_fee) WHERE order_code = :order_code';
}
... ...
... ... @@ -16,4 +16,7 @@ class Shopping
const SELECT_CHANGE_PRICE_BY_KEY = 'select * from `shopping_change_price` where buyer_uid=:buyer_uid and agreement_key=:agreement_key';
const UPDATE_AGREEMENT_STATUS = 'update shopping_change_price set is_buyer=:is_buyer,order_code=:order_code where agreement_key=:agreement_key';
const INSERT_SHIPPING_ORDER_CHANGE_PRICE = 'INSERT INTO shopping_change_price(agreement_key,buyer_uid,store_id,seller_uid,product_skc,sale_price,agreement_price,agreement_shipping_fee, order_shipping_fee, order_last_shipping_fee, order_amount, order_code,buy_number,goods_type,create_time) VALUES
(:agreement_key,:buyer_uid,:store_id,:seller_uid,:product_skc,:sale_price,:agreement_price,:agreement_shipping_fee,:order_shipping_fee,:order_last_shipping_fee,:order_amount,:order_code, :buy_number,:goods_type,UNIX_TIMESTAMP())';
}
\ No newline at end of file
... ...
... ... @@ -5,4 +5,7 @@ ALTER TABLE `orders_goods`
MODIFY COLUMN `product_sku` int(11) UNSIGNED NOT NULL COMMENT '商品sku' AFTER `product_skc`;
ALTER TABLE `yhm_orders`.`orders` CHANGE `last_order_amount` `last_order_amount` DECIMAL(10,2) UNSIGNED NULL COMMENT '订单成交价: 订单成交价 = 订单原价 + 最终运费';
ALTER TABLE `yhm_orders`.`orders_goods_info` ADD COLUMN `shipping_fee` DECIMAL(10,2) NULL COMMENT '订单运费' AFTER `last_price`;
\ No newline at end of file
ALTER TABLE `yhm_orders`.`orders_goods_info` ADD COLUMN `shipping_fee` DECIMAL(10,2) NULL COMMENT '订单运费' AFTER `last_price`;
ALTER TABLE `yhm_orders`.`shopping_change_price` ADD COLUMN `agreement_shipping_fee` DECIMAL(10,2) DEFAULT '0' NULL COMMENT '商品运费价格' AFTER `buy_number`, ADD COLUMN `order_shipping_fee` DECIMAL(10,2) DEFAULT '0' NULL COMMENT '订单运费价格' AFTER `agreement_shipping_fee`, ADD COLUMN `order_amount` DECIMAL(10,2) DEFAULT '0' NULL COMMENT '订单单价' AFTER `order_shipping_fee`, CHANGE `agreement_price` `agreement_price` DECIMAL(10,2) NULL COMMENT '商品成交价';
ALTER TABLE `yhm_orders`.`shopping_change_price` ADD COLUMN `order_last_shipping_fee` DECIMAL(10,2) DEFAULT '0' NULL COMMENT '订单运费价格' AFTER `agreement_shipping_fee`;
... ...