Ejemplo n.º 1
0
 public static function getpurchase($purchaseids = array(), $payment)
 {
     $BuyerID = Yii::app()->user->getOrganID();
     $purchaseids = implode(',', $purchaseids);
     $cartArr = array();
     $sql = "select distinct jo1.ID as SellerID,jo1.OrganName as SellerName,jo2.ID as BuyerID,\n        \t\tjo2.OrganName as BuyerName from \n\t\t\t\tpap_reserve_purchase as prp, pap_goods as pg, jpd.jpd_organ as jo1, jpd.jpd_organ as jo2\n\t\t\t\twhere prp.ID in ({$purchaseids}) AND prp.GoodsID = pg.ID AND pg.OrganID = jo1.ID \n\t\t\t\tAND prp.OrganID = jo2.ID AND prp.OrganID = '{$BuyerID}'";
     $purchase = Yii::app()->papdb->createCommand($sql)->queryAll();
     if ($purchase) {
         foreach ($purchase as $key => $val) {
             $cartArr[$key]["SellerID"] = $val['SellerID'];
             //卖家ID
             $cartArr[$key]["SellerName"] = $val['SellerName'];
             //卖家名称
             $cartArr[$key]["BuyerName"] = $val['BuyerName'];
             //买家名称
             //获取经销商订单折扣率--商城订单
             $sellerID = $val['SellerID'];
             $discount = PapOrderDiscount::model()->find(array("condition" => "OrderType = 1"));
             if (isset($discount) && !empty($discount)) {
                 if ($payment == 1) {
                     $dis = $discount['OrderAlipay'];
                 } else {
                     if ($payment == 2) {
                         $dis = $discount['OrderLogis'];
                     }
                 }
                 if (isset($dis) && !empty($dis)) {
                     $cartArr[$key]["discount"] = $dis;
                 } else {
                     $cartArr[$key]["discount"] = 100;
                 }
             } else {
                 $cartArr[$key]["discount"] = 100;
             }
             //获取经销商订单最小交易额
             $turnover = PapOrderMinTurnover::model()->find("OrganID=:ID", array(":ID" => $val['SellerID']));
             if ($turnover) {
                 $cartArr[$key]["MinTurnover"] = $turnover['MinTurnover'];
                 //订单最小交易额
             }
             //将经销商的商品添加到经销商的组中
             $sql = "SELECT distinct  prp.ID as purchaseID, pg.ID as GoodsID, pg.Price, pg.ProPrice, \n    \t\t\tpg.IsPro, prp.Num as Quantity, pg.Name as GoodsName, pg.GoodsNO as GoodsNum, \n    \t\t\tpg.Brand, jg.Name as CpName, prp.CreateTime, pg.OrganID, pg.Version\n\t\t    \tFROM pap_reserve_purchase AS prp , jpd.jpd_gcategory AS jg, \n\t\t    \tpap_goods AS pg\n\t\t        WHERE prp.GoodsID = pg.ID AND prp.GcategoryCode = jg.Code \n\t\t        AND prp.OrganID = '{$BuyerID}' AND pg.OrganID = '{$val['SellerID']}' AND  prp.ID in ({$purchaseids})\n        \t\t";
             $cartArr[$key]["GoodsList"] = Yii::app()->papdb->CreateCommand($sql)->queryAll();
             foreach ($cartArr[$key]["GoodsList"] as $k => $value) {
                 $ispro = PapGoods::model()->findBypk($value['GoodsID']);
                 if (!$ispro->IsPro) {
                     $goodsinfo = MallService::getDealerGoodByID($value['GoodsID']);
                     $cartArr[$key]["GoodsList"][$k]['Price'] = $goodsinfo['Price'];
                     $cartArr[$key]["GoodsList"][$k]['ProPrice'] = $goodsinfo['DisPrice'];
                 }
                 if ($ispro->IsPro == 1) {
                     $cartArr[$key]["GoodsList"][$k]['ProPrice'] = $ispro['ProPrice'];
                 }
             }
         }
     }
     return $cartArr;
 }