/**
  * Create a resource
  *
  * @param  mixed $data
  * @return ApiProblem|mixed
  */
 public function create($data)
 {
     $result = $this->service->create($data);
     if ($result == 'error') {
         return new ApiProblem(405, 'Error processing order');
     }
     return $result;
 }
示例#2
0
 public static function createbuynoworder($params)
 {
     $goods = $params['goods'];
     $payment = $params['payment'];
     $ShipLogis = $params['shiplogis'];
     $ship = $params['ship'];
     $quantity = $params['quantity'];
     $locate = $params['locate'];
     $BuyerID = Yii::app()->user->getOrganID();
     $organ = Organ::model()->findByPk($BuyerID)->attributes;
     $BuyName = $organ['OrganName'];
     $usecouponID = $params['usecouponID'];
     //获取订单最小交易额
     $turnover = PapOrderMinTurnover::model()->find("OrganID=:ID", array(":ID" => $goods['SellerID']));
     $min_price = $turnover['MinTurnover'] ? $turnover['MinTurnover'] : 0;
     //获取经销商订单折扣率--商城订单
     $discount = PapOrderDiscount::model()->find(array("condition" => " OrderType = 1"));
     if ($discount) {
         if ($payment == 1) {
             $dis = $discount['OrderAlipay'];
         } else {
             if ($payment == 2) {
                 $dis = $discount['OrderLogis'];
             }
         }
         if (isset($dis) && !empty($dis)) {
             $dis = $dis;
         } else {
             $dis = 100;
         }
     } else {
         $dis = 100;
     }
     $orderArr = array();
     $order_sn = self::gen_order_sn();
     //array("order"=>array(),"goodsList"=> array())
     $orderArr["order"] = array("OrderSN" => "DD" . $order_sn, "OrderName" => "嘉配订单:DD" . $order_sn, "SellerID" => $goods["SellerID"], "SellerName" => $goods["OrganName"], "BuyerID" => $BuyerID, "BuyerName" => $BuyName, "Payment" => $payment, "OrderType" => 1, "Discount" => $dis, "ShipLogis" => $ShipLogis['0'], "Status" => $payment == 1 ? 1 : 2, "CreateTime" => time(), "UpdateTime" => time());
     //收货地址
     $orderArr["address"] = array("ShippingName" => $ship['ContactName'], "ZipCode" => $ship['ZipCode'], "Mobile" => $ship['Phone'], "Province" => $ship['State'], "City" => $ship['City'], "Area" => $ship['District'], "Address" => $ship['Address'], "CreateTime" => time());
     $SellPrice = $goods["ProPrice"] ? $goods["ProPrice"] : $goods["DisPrice"];
     //生成平摊金额
     $amount = round($SellPrice * $dis / 100, 2) * $quantity;
     $GoodsAmount = $amount;
     //$GoodsAmount = round($amount * $dis / 100, 2);
     $avg = 0;
     $SellPrice = round($SellPrice * $dis / 100, 2);
     //定位车系
     $locate = explode('_', $locate);
     $data[] = array("GoodsID" => $goods['GoodsID'], "GoodsNum" => $goods['GoodsNO'], "GoodsOE" => $goods['OENO'], "GoodsName" => $goods['Name'], "CpName" => $goods['CpName'], "Brand" => $goods['BrandName'], "Price" => $goods['Price'], "ProPrice" => $SellPrice, "Quantity" => $quantity, "ShipCost" => $goods['LogisticsPrice'] * $quantity, "GoodsAmount" => $GoodsAmount, "Version" => $goods['Version'], "CreateTime" => time(), "UpdateTime" => time(), "MakeID" => $locate[0], "CarID" => $locate[1], "Year" => $locate[2], "ModelID" => $locate[3]);
     $goodsPrice = $data['0']["GoodsAmount"];
     $shipCost = $data['0']["ShipCost"];
     $totalPrice = $goodsPrice + $shipCost;
     //订单总价
     //订单实付金额折扣率
     $amountPrice = $GoodsAmount;
     //商品总价
     $realPrice = $amountPrice + $shipCost;
     //实付金额:折后价+物流费
     $orderArr["goodsList"] = $data;
     $orderArr["order"]["GoodsAmount"] = $goodsPrice;
     $orderArr["order"]["ShipCost"] = $shipCost;
     $orderArr["order"]["TotalAmount"] = $totalPrice;
     //实付金额
     $orderArr["order"]["RealPrice"] = $realPrice;
     $actparam = array('total' => $totalPrice, 'payment' => $payment);
     $act_res = self::activedecre($actparam);
     if (!empty($act_res) && is_array($act_res)) {
         $orderArr["order"]['PromoID'] = intval($act_res['PromoID']);
         $orderArr["order"]['DecrAmount'] = floatval($act_res["DecrAmount"]);
         $orderArr["order"]['DecrTotal'] = floatval($act_res["DecrTotal"]);
         $orderArr['order']['Type'] = $act_res['Type'];
         $orderArr["order"]["RealPrice"] = floatval($act_res['RealPrice']);
         $orderArr["order"]["TotalAmount"] = floatval($act_res['RealPrice']);
         $orderArr["order"]['CouponID'] = $act_res['CouponID'];
     }
     /*优惠活动 使用优惠券
      * params $decoupon 优惠券内容,$totalPrice订单金额 $orderArr订单数组
      */
     if (isset($usecouponID) && !empty($usecouponID)) {
         $decoupon = self::couponbyID($usecouponID);
         $orderArr = self::usecoupon($decoupon, $totalPrice, $orderArr);
     }
     $orderId = OrderService::create($orderArr);
     return $orderId;
 }