Пример #1
0
 /**
  * 模糊循环匹配配件信息(配件查询会用到)
  */
 public static function getGoodsByPartsOENO($oe)
 {
     $sql = "select * from `pap_goods` where  IsSale = 1 and ISdelete = 1";
     if (!empty($oe) && is_array($oe)) {
         // OE号不为空,并且是数组
         $oearr = array_unique($oe);
         $oesql = 'select DISTINCT GoodsID from pap_goods_oe_relation where ';
         foreach ($oearr as $v) {
             $oesql .= 'OENO = "' . $v . '" or ';
         }
         $oesql = rtrim($oesql, 'or ');
     } elseif (!empty($oe) && !is_array($oe)) {
         // OE号不为空,并且不是数组
         $oesql = 'select DISTINCT GoodsID from pap_goods_oe_relation where OENO = "' . $oe . '"';
     }
     $oedatas = Yii::app()->papdb->createCommand($oesql)->queryAll();
     $ids = array();
     foreach ($oedatas as $v) {
         $ids[] = $v['GoodsID'];
     }
     $idstr = implode(',', $ids);
     if ($idstr) {
         $where .= ' and ID in (' . $idstr . ')';
     } else {
         $where .= ' and ID in (0)';
     }
     $sql .= $where . ' order by ID desc limit 3';
     $goodses = Yii::app()->papdb->createCommand($sql)->queryAll();
     $data = array();
     //判断当前登录角色(修理厂/经销商)
     $Identity = Yii::app()->user->getIdentity();
     if ($Identity == 'servicer') {
         $Identity = 3;
     } else {
         $Identity = 2;
     }
     $OrganID = Yii::app()->user->getOrganID();
     foreach ($goodses as $key => $goods) {
         $data[$key]['ImageUrl'] = self::getGoodsImage($goods['ID']);
         $data[$key]['ID'] = $goods['ID'];
         $data[$key]['OENO'] = QuotationService::getoebygoodsid($goods['ID']);
         $data[$key]['OrganID'] = $goods['OrganID'];
         $data[$key]['Name'] = $goods['Name'];
         $data[$key]['OrganName'] = self::getnamebyorganid($goods['OrganID']);
         $data[$key]['ListPrice'] = $goods['Price'];
         $data[$key]['Identity'] = $Identity;
         //当前登录用户觉角色
         //折扣率
         if ($Identity == 3) {
             //修理厂
             $discount = QuotationService::getpriceratio($goods['OrganID'], $OrganID);
             $data[$key]['PriceRatio'] = $discount['discount'] ? $discount['discount'] . '%' : "100%";
             $DisPrice = sprintf("%.2f", $goods['Price'] * $data[$key]['PriceRatio'] / 100);
             // 折扣价,小数点后面保留两位
             if ($goods['IsPro'] == 1) {
                 //促销商品
                 $ProPrice = empty($goods['ProPrice']) || $goods['ProPrice'] == 0 ? $DisPrice : $goods['ProPrice'];
                 // 促销价
                 $data[$key]['Price'] = $ProPrice < $DisPrice ? $ProPrice : $DisPrice;
             } else {
                 //非促销商品
                 $data[$key]['Price'] = $DisPrice;
                 //折扣价
             }
         } elseif ($Identity == 2) {
             //经销商
             $data[$key]['Price'] = $goods['Price'];
             //参考价
         }
     }
     return $data;
 }