Authored by whb

添加修改订单价格接口

@@ -9,4 +9,164 @@ @@ -9,4 +9,164 @@
9 class YHMApi_App_V2_Shopping extends YHMApi_App_V1_Shopping 9 class YHMApi_App_V2_Shopping extends YHMApi_App_V1_Shopping
10 { 10 {
11 use YHMApi_App_V2_Base; 11 use YHMApi_App_V2_Base;
  12 +
  13 + /**
  14 + * 提交订单
  15 + *
  16 + * @param array $params
  17 + * @param string $fields
  18 + * @return array
  19 + */
  20 + public static function commit(array $params, $fields = '*')
  21 + {
  22 + if (empty($params['product_sku'])) {
  23 + return self::result(YHMConfig_Mobile::WARING_CODE, '请选择购买商品.');
  24 + }
  25 + if (empty($params['buyer_uid'])) {
  26 + return self::result(YHMConfig_Mobile::WARING_CODE, '购买者不明确.');
  27 + }
  28 + if (empty($params['delivery_info_id'])) {
  29 + return self::result(YHMConfig_Mobile::WARING_CODE, '送货信息不能为空.');
  30 + }
  31 + $goodsInfo = YHMProduct_Models_Goods_Client::getOneByProductSkc($params['product_sku']);
  32 + $orderRemark = (empty($params['order_remark']) ? '' : $params['order_remark']);
  33 + $productSku = $params['product_sku'];
  34 +
  35 + $buyerUid = $params['buyer_uid'];
  36 + $paymentID = empty($params['payment_id']) ? 1 : $params['payment_id'];
  37 + $shippingFee = empty($params['shipping_fee']) ? 0 : $params['shipping_fee'];
  38 + $deliveryInfoID = $params['delivery_info_id'];
  39 + $buyNumber = empty($params['buy_number']) ? 1 : $params['buy_number'];
  40 + $orderData = array(
  41 + 'buyer_uid' => $buyerUid,
  42 + 'buying_way' => 1,
  43 + 'shipping_fee' => $shippingFee,
  44 + 'last_shipping_fee' => $shippingFee,
  45 + 'payment_id' => $paymentID,
  46 + 'order_remark' => $orderRemark,
  47 + 'goods_list' => array(
  48 + array(
  49 + 'product_sku' => $productSku,
  50 + 'buy_number' => $buyNumber
  51 + )
  52 + )
  53 + );
  54 + $deliveryInfo = YHMDelivery_Models_Delivery_Client::getDeliveryById($deliveryInfoID);
  55 + if (empty($deliveryInfo)) {
  56 + return self::result(YHMConfig_Mobile::NOTICE_CODE, '送货信息不能为空.');
  57 + }
  58 +
  59 + $resultData = array();
  60 + try {
  61 + $ordinary = new YHMCart_Orders_Ordinary($buyerUid);
  62 + $_orderData = $ordinary->initOrdersData($orderData);
  63 + print_r($_orderData);
  64 + exit();
  65 + foreach ($_orderData as $orderKey => $lastOrderData) {
  66 + $returnOrder = $ordinary->create($lastOrderData);
  67 + $resultData['order_data'][] = array(
  68 + 'order_code' => $returnOrder['order_code'],
  69 + 'last_order_amount' => $returnOrder['last_order_amount']
  70 + );
  71 + YHMOrders_Models_Delivery_Client::addDelivery($returnOrder['order_code'], $deliveryInfo['delivery_name'], $deliveryInfo['mobile'], $deliveryInfo['area_code'], $deliveryInfo['address'], $deliveryInfo['zip_code']);
  72 + }
  73 + } catch (Exception $e) {
  74 + return self::result(YHMConfig_Mobile::NOTICE_CODE, $e->getMessage());
  75 + }
  76 + return self::result(YHMConfig_Mobile::SUCCESS_CODE, '订单成功.', $resultData);
  77 + }
  78 +
  79 + /**
  80 + * 改价订单确认操作
  81 + *
  82 + * @param array $params
  83 + * @param string $fields
  84 + * @return array
  85 + */
  86 + public static function confirm(array $params, $fields = '*')
  87 + {
  88 + return self::result(YHMConfig_Mobile::NOTICE_CODE, '改价订单确认操作废弃');
  89 + }
  90 +
  91 + /**
  92 + * 修改价格
  93 + *
  94 + * @param array $params
  95 + * @param string $fields
  96 + * @return multitype:Integer String mixed string
  97 + */
  98 + public static function change(array $params, $fields = '*')
  99 + {
  100 + if (empty($params['buyer_uid'])) {
  101 + return self::result(YHMConfig_Mobile::WARING_CODE, '缺少购买者.');
  102 + }
  103 + if (empty($params['product_skc'])) {
  104 + return self::result(YHMConfig_Mobile::WARING_CODE, '缺少购买商品.');
  105 + }
  106 + if (empty($params['seller_uid'])) {
  107 + return self::result(YHMConfig_Mobile::WARING_CODE, '缺少售卖者.');
  108 + }
  109 + if(empty($params['order_code'])) {
  110 + return self::result(YHMConfig_Mobile::WARING_CODE, '缺少订单号.');
  111 + }
  112 + if (empty($params['agreement_price'])) {
  113 + return self::result(YHMConfig_Mobile::WARING_CODE, '缺少修改后的价格.');
  114 + }
  115 + if ($params['agreement_price'] < 0) {
  116 + return self::result(YHMConfig_Mobile::WARING_CODE, '修改价格不能小于0');
  117 + }
  118 + if (!isset($params['agreement_shipping_fee'])) {
  119 + return self::result(YHMConfig_Mobile::WARING_CODE, '缺少修改后的运费价格.');
  120 + }
  121 + if ($params['agreement_shipping_fee'] < 0) {
  122 + return self::result(YHMConfig_Mobile::WARING_CODE, '修改运费价格不能小于0');
  123 + }
  124 + //订单信息
  125 + $order_info = YHMOrders_Models_Orders_Client::getOrdersInfoByOrderCode($params['order_code']);
  126 + if (empty($order_info)) {
  127 + return self::result(YHMConfig_Mobile::NOTICE_CODE, '没有这个订单');
  128 + }
  129 + // 目前一个订单只有一个商品,所以取出一条数据
  130 + $order_goods = current(YHMOrders_Models_Orders_Client::getGoodsInfoByOrderCode ( $params['order_code']));
  131 + if ($order_goods['product_skc'] != $params['product_skc']) {
  132 + return self::result(YHMConfig_Mobile::NOTICE_CODE, '没有这个订单商品.');
  133 + }
  134 + if ($order_info['seller_uid'] != $params['seller_uid']) {
  135 + return self::result(YHMConfig_Mobile::WARING_CODE, '此商品不是这个卖家的.');
  136 + }
  137 + try {
  138 + $package = array(
  139 + 'buyer_uid' => $params['buyer_uid'],
  140 + 'store_id' => $order_info['store_id'],
  141 + 'seller_uid' => $order_info['seller_uid'],
  142 + 'product_skc' => $order_goods['product_skc'],
  143 + 'sale_price' => $order_goods['sale_price'],
  144 + 'agreement_shipping_fee' => $params['agreement_shipping_fee'],
  145 + 'order_shipping_fee' => $order_info['shipping_fee'],
  146 + 'order_last_shipping_fee' => $order_info['last_shipping_fee'],
  147 + 'order_amount' => $order_info['order_amount'],
  148 + 'agreement_price' => $params['agreement_price'],
  149 + 'buy_number' => $order_goods['buy_number'],
  150 + 'goods_type' => YHMConfig_Orderstatus::ORDER_GOODS_TYPE_MAIN,
  151 + 'order_code' =>$params['order_code'],
  152 + );
  153 + $agreementKey = YHMUtils_Tools::makeAgreementKey($package);
  154 + $package['agreement_key'] = $agreementKey;
  155 + $agreementID = YHMOrders_Models_Shopping_Client::addShoppingOrderChangePrice($package);
  156 + $status = false;
  157 + $agreementData = array (
  158 + 'agreement_key' => $agreementKey,
  159 + 'agreement_id' => $agreementID
  160 + );
  161 + if (! empty ( $agreementID )) {
  162 + $status = YHMOrders_Models_Orders_Client::updateOrderPrice ( $params ['order_code'], $params ['agreement_price'], $params ['agreement_shipping_fee'], $params ['agreement_shipping_fee'] );
  163 + }
  164 + if (empty ( $agreementID ) || ! empty ( $status )) {
  165 + return self::result(YHMConfig_Mobile::NOTICE_CODE, '改价失败');
  166 + }
  167 + } catch(Exception $e) {
  168 + return self::result(YHMConfig_Mobile::NOTICE_CODE, $e->getMessage());
  169 + }
  170 + return self::result(YHMConfig_Mobile::SUCCESS_CODE, '改价成功.', $agreementData);
  171 + }
12 } 172 }
@@ -410,4 +410,17 @@ class YHMOrders_Models_Orders_Client { @@ -410,4 +410,17 @@ class YHMOrders_Models_Orders_Client {
410 return self::dao()->getBuyOrderTotalBySortOrderStatus($buyer_uid, $order_status); 410 return self::dao()->getBuyOrderTotalBySortOrderStatus($buyer_uid, $order_status);
411 } 411 }
412 412
  413 + /**
  414 + * 更新订单价格
  415 + *
  416 + * @param int $order_code
  417 + * @param float $order_amount
  418 + * @param float $shipping_fee
  419 + * @param float $last_shipping_fee
  420 + * @return boolean
  421 + */
  422 + public static function updateOrderPrice($order_code, $order_amount, $shipping_fee, $last_shipping_fee)
  423 + {
  424 + return self::dao()->updateOrderPrice($order_code, $order_amount, $shipping_fee, $last_shipping_fee);
  425 + }
413 } 426 }
@@ -513,4 +513,24 @@ class YHMOrders_Models_Orders_Dao extends YHMOrders_Dao { @@ -513,4 +513,24 @@ class YHMOrders_Models_Orders_Dao extends YHMOrders_Dao {
513 $replaces = array('order_status' => implode(',', $order_status)); 513 $replaces = array('order_status' => implode(',', $order_status));
514 return $this->dao()->cache(false)->fetchOne(Orders\Order::GET_BUY_ORDER_TOTAL_BY_SORT_ORDER_STATUS, $params, $replaces); 514 return $this->dao()->cache(false)->fetchOne(Orders\Order::GET_BUY_ORDER_TOTAL_BY_SORT_ORDER_STATUS, $params, $replaces);
515 } 515 }
  516 +
  517 + /**
  518 + * 更新订单价格
  519 + *
  520 + * @param int $order_code
  521 + * @param float $order_amount
  522 + * @param float $shipping_fee
  523 + * @param float $last_shipping_fee
  524 + * @return boolean
  525 + */
  526 + public function updateOrderPrice($order_code, $order_amount, $shipping_fee, $last_shipping_fee)
  527 + {
  528 + if(is_numeric($order_code) && is_numeric($order_amount) && is_numeric($shipping_fee) && is_numeric($last_shipping_fee))
  529 + {
  530 + $params = array('order_code' => $order_code, 'order_amount' => $order_amount,
  531 + 'shipping_fee' => $shipping_fee, 'last_shipping_fee'=> $last_shipping_fee);
  532 + return $this->dao(false)->update(Orders\Order::UPDATE_ORDER_PRICE, $params)->rowCount();
  533 + }
  534 + return false;
  535 + }
516 } 536 }
1 <?php 1 <?php
2 -  
3 /** 2 /**
4 - * Created by JetBrains PhpStorm.  
5 - * User: elkan  
6 - * Date: 14-8-5  
7 - * Time: 下午6:04  
8 - * To change this template use File | Settings | File Templates. 3 + * 购物相关
  4 + *
9 */ 5 */
10 class YHMOrders_Models_Shopping_Client 6 class YHMOrders_Models_Shopping_Client
11 { 7 {
@@ -28,29 +24,40 @@ class YHMOrders_Models_Shopping_Client @@ -28,29 +24,40 @@ class YHMOrders_Models_Shopping_Client
28 return self::$dao; 24 return self::$dao;
29 } 25 }
30 26
31 - static function create(array $orderData) 27 + public static function create(array $orderData)
32 { 28 {
33 return self::dao()->create($orderData); 29 return self::dao()->create($orderData);
34 } 30 }
35 31
36 /** 32 /**
37 * 修改价格 33 * 修改价格
  34 + *
38 * @param array $package 35 * @param array $package
39 * @return int 36 * @return int
40 - * @throws Exception  
41 */ 37 */
42 - static function addShoppingChangePrice(array $package) 38 + public static function addShoppingChangePrice(array $package)
43 { 39 {
44 return self::dao()->addShoppingChangePrice($package); 40 return self::dao()->addShoppingChangePrice($package);
45 } 41 }
46 42
47 /** 43 /**
  44 + * 修改订单价格
  45 + *
  46 + * @param array $package
  47 + * @return int
  48 + */
  49 + public static function addShoppingOrderChangePrice(array $package)
  50 + {
  51 + return self::dao()->addShoppingOrderChangePrice($package);
  52 + }
  53 +
  54 + /**
48 * 获取购物改价 55 * 获取购物改价
49 * @param $agreementKey 56 * @param $agreementKey
50 * @param $buyerUid 57 * @param $buyerUid
51 * @return Array 58 * @return Array
52 */ 59 */
53 - static function getShoppingChangePrice($agreementKey, $buyerUid) 60 + public static function getShoppingChangePrice($agreementKey, $buyerUid)
54 { 61 {
55 return self::dao()->getShoppingChangePrice($agreementKey, $buyerUid); 62 return self::dao()->getShoppingChangePrice($agreementKey, $buyerUid);
56 } 63 }
@@ -61,7 +68,7 @@ class YHMOrders_Models_Shopping_Client @@ -61,7 +68,7 @@ class YHMOrders_Models_Shopping_Client
61 * @param $isBuyer 68 * @param $isBuyer
62 * @return int 69 * @return int
63 */ 70 */
64 - static function updateShoppingChange($agreementKey, $orderCode, $isBuyer = 'Y') 71 + public static function updateShoppingChange($agreementKey, $orderCode, $isBuyer = 'Y')
65 { 72 {
66 return self::dao()->updateShoppingChange($agreementKey, $orderCode, $isBuyer); 73 return self::dao()->updateShoppingChange($agreementKey, $orderCode, $isBuyer);
67 } 74 }
@@ -72,16 +79,17 @@ class YHMOrders_Models_Shopping_Client @@ -72,16 +79,17 @@ class YHMOrders_Models_Shopping_Client
72 * @param $orderStatus 79 * @param $orderStatus
73 * @return Array 80 * @return Array
74 */ 81 */
75 - static function getBuyGoodsNumber($productSku, $orderStatus = 900) 82 + public static function getBuyGoodsNumber($productSku, $orderStatus = 900)
76 { 83 {
77 return self::dao()->getBuyGoodsNumber((int)$productSku, (int)$orderStatus); 84 return self::dao()->getBuyGoodsNumber((int)$productSku, (int)$orderStatus);
78 } 85 }
79 - /** 86 +
  87 + /**
80 * 插入订单镜像表 88 * 插入订单镜像表
81 * @param $storeID 89 * @param $storeID
82 * @return mixed 90 * @return mixed
83 */ 91 */
84 - static function setBuyGoodsInfo($data) 92 + public static function setBuyGoodsInfo($data)
85 { 93 {
86 return self::dao()->setBuyGoodsInfo($data); 94 return self::dao()->setBuyGoodsInfo($data);
87 } 95 }
@@ -146,7 +146,30 @@ class YHMOrders_Models_Shopping_Dao extends YHMOrders_Dao @@ -146,7 +146,30 @@ class YHMOrders_Models_Shopping_Dao extends YHMOrders_Dao
146 } 146 }
147 147
148 /** 148 /**
  149 + * 修改订单价格
  150 + *
  151 + * @param array $package
  152 + * @return int
  153 + */
  154 + public function addShoppingOrderChangePrice(array $package)
  155 + {
  156 + $changeParameters = array(
  157 + 'agreement_key', 'buyer_uid', 'store_id', 'seller_uid', 'product_skc', 'sale_price', 'agreement_price', 'buy_number', 'goods_type',
  158 + 'agreement_shipping_fee','order_shipping_fee','order_amount','order_code','order_last_shipping_fee'
  159 + );
  160 + $parameter = array();
  161 + foreach ($changeParameters as $key) {
  162 + if (!isset($package[$key])) {
  163 + throw new Exception('改价异常,缺少字段:' . $key);
  164 + }
  165 + $parameter[$key] = $package[$key];
  166 + }
  167 + return $this->daoObject->insert(Shopping::INSERT_SHIPPING_ORDER_CHANGE_PRICE, $parameter)->lastInsertId();
  168 + }
  169 +
  170 + /**
149 * 获取购物改价 171 * 获取购物改价
  172 + *
150 * @param $agreementKey 173 * @param $agreementKey
151 * @param $buyerUid 174 * @param $buyerUid
152 * @return Array 175 * @return Array
@@ -55,4 +55,6 @@ class Order @@ -55,4 +55,6 @@ class Order
55 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"; 55 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";
56 const GET_BUY_ORDER_TOTAL_BY_SORT_ORDER_STATUS = "SELECT COUNT(*) FROM orders WHERE buyer_uid=:buyer_uid AND order_status IN(#order_status#)"; 56 const GET_BUY_ORDER_TOTAL_BY_SORT_ORDER_STATUS = "SELECT COUNT(*) FROM orders WHERE buyer_uid=:buyer_uid AND order_status IN(#order_status#)";
57 const GET_SELLER_ORDER_TOTAL_BY_SORT_ORDER_STATUS = "SELECT COUNT(*) FROM orders WHERE seller_uid=:seller_uid AND order_status IN(#order_status#)"; 57 const GET_SELLER_ORDER_TOTAL_BY_SORT_ORDER_STATUS = "SELECT COUNT(*) FROM orders WHERE seller_uid=:seller_uid AND order_status IN(#order_status#)";
  58 +
  59 + 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';
58 } 60 }
@@ -16,4 +16,7 @@ class Shopping @@ -16,4 +16,7 @@ class Shopping
16 const SELECT_CHANGE_PRICE_BY_KEY = 'select * from `shopping_change_price` where buyer_uid=:buyer_uid and agreement_key=:agreement_key'; 16 const SELECT_CHANGE_PRICE_BY_KEY = 'select * from `shopping_change_price` where buyer_uid=:buyer_uid and agreement_key=:agreement_key';
17 17
18 const UPDATE_AGREEMENT_STATUS = 'update shopping_change_price set is_buyer=:is_buyer,order_code=:order_code where agreement_key=:agreement_key'; 18 const UPDATE_AGREEMENT_STATUS = 'update shopping_change_price set is_buyer=:is_buyer,order_code=:order_code where agreement_key=:agreement_key';
  19 +
  20 + 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
  21 + (: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())';
19 } 22 }
@@ -5,4 +5,7 @@ ALTER TABLE `orders_goods` @@ -5,4 +5,7 @@ ALTER TABLE `orders_goods`
5 MODIFY COLUMN `product_sku` int(11) UNSIGNED NOT NULL COMMENT '商品sku' AFTER `product_skc`; 5 MODIFY COLUMN `product_sku` int(11) UNSIGNED NOT NULL COMMENT '商品sku' AFTER `product_skc`;
6 6
7 ALTER TABLE `yhm_orders`.`orders` CHANGE `last_order_amount` `last_order_amount` DECIMAL(10,2) UNSIGNED NULL COMMENT '订单成交价: 订单成交价 = 订单原价 + 最终运费'; 7 ALTER TABLE `yhm_orders`.`orders` CHANGE `last_order_amount` `last_order_amount` DECIMAL(10,2) UNSIGNED NULL COMMENT '订单成交价: 订单成交价 = 订单原价 + 最终运费';
8 -ALTER TABLE `yhm_orders`.`orders_goods_info` ADD COLUMN `shipping_fee` DECIMAL(10,2) NULL COMMENT '订单运费' AFTER `last_price`;  
  8 +ALTER TABLE `yhm_orders`.`orders_goods_info` ADD COLUMN `shipping_fee` DECIMAL(10,2) NULL COMMENT '订单运费' AFTER `last_price`;
  9 +
  10 +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 '商品成交价';
  11 +ALTER TABLE `yhm_orders`.`shopping_change_price` ADD COLUMN `order_last_shipping_fee` DECIMAL(10,2) DEFAULT '0' NULL COMMENT '订单运费价格' AFTER `agreement_shipping_fee`;