コード例 #1
0
ファイル: InquiryorderService.php プロジェクト: zwq/unpei
 public static function createorder($quoID, $schID, $payment, $address, $ordertype, $goodsids, $nums, $CouponSn)
 {
     $opration = array();
     //错误时执行操作
     $sql_findQuo = 'select * from pap_quotation where QuoID=' . $quoID;
     $Quoinfo = Yii::app()->papdb->createCommand($sql_findQuo)->queryRow();
     //获取方案对应的商品
     $sql_goods = 'select * from pap_quotation_goods where SchID=' . $schID . ' and GoodsID in(' . $goodsids . ') ';
     $goodsinfo = self::excutesql(array('sql' => $sql_goods, 'db' => 'pap'));
     //获取经销商最小价格
     $min_price = PapOrderMinTurnover::model()->find('OrganID=:OrganID', array(':OrganID' => $Quoinfo['DealerID']));
     $min_price = $min_price['MinTurnover'];
     //获取经销商信息
     $sql_dealer = 'select ID,OrganName from jpd_organ where ID=' . $Quoinfo['DealerID'];
     $dealerinfo = Yii::app()->jpdb->createCommand($sql_dealer)->queryRow();
     //获取修理厂信息
     $find_lsm_orgname = 'select OrganName from jpd_organ where ID=' . $Quoinfo['ServiceID'];
     $serviceinfo = Yii::app()->jpdb->createCommand($find_lsm_orgname)->queryRow();
     //调用商城生成订单方法
     $carts = array();
     $carts['SellerID'] = $Quoinfo['DealerID'];
     $carts['BuyerID'] = $Quoinfo['ServiceID'];
     $carts['SellerName'] = $dealerinfo['OrganName'];
     $carts['BuyerName'] = $serviceinfo['OrganName'];
     $carts['MinTurnover'] = $min_price ? $min_price : '0';
     //获取经销商订单折扣率--询报价订单
     $dis = 100;
     $discount = PapOrderDiscount::model()->find(array("condition" => " OrderType = 2"));
     if ($discount) {
         if ($payment == 1 && $discount['OrderAlipay']) {
             $dis = $discount['OrderAlipay'];
         } else {
             if ($payment == 2 && $discount['OrderLogis']) {
                 $dis = $discount['OrderLogis'];
             } else {
                 $dis = 100;
             }
         }
     } else {
         $dis = 100;
     }
     $carts['discount'] = $dis;
     $totalgoods;
     $nums = explode(',', $nums);
     foreach ($goodsinfo as $kk => $value) {
         $goodsbyid = DealergoodsService::getmongoversion($value['GoodsID'], $value['Version']);
         if ($goodsbyid) {
             $totalgoods[$kk] = array('BuyerID' => $Quoinfo['ServiceID'], 'BuyerName' => $serviceinfo['OrganName'], 'SellerID' => $dealerinfo['ID'], 'SellerName' => $dealerinfo['OrganName'], "GoodsID" => $value['GoodsID'], "GoodsNum" => $goodsbyid['GoodsInfo']['GoodsNO'], "GoodsOE" => is_array($goodsbyid['GoodsInfo']['oeno']) ? implode(',', $goodsbyid['GoodsInfo']['oeno']) : (is_string($goodsbyid['GoodsInfo']['oeno']) ? ['GoodsInfo']['oeno'] : ''), "GoodsName" => $goodsbyid['GoodsInfo']['Name'], "CpName" => $goodsbyid['GoodsInfo']['StandCode'] ? self::getCpName($goodsbyid['GoodsInfo']['StandCode']) : '', "Brand" => $goodsbyid['GoodsInfo']['Brand'], "Price" => $goodsbyid['GoodsInfo']['Price'], "ProPrice" => $value['Price'], "Quantity" => $nums[$kk], "ShipCost" => null, "CreateTime" => time(), "UpdateTime" => time(), "Version" => $goodsbyid['Version']);
         }
     }
     $carts['GoodsList'] = $totalgoods;
     if ($ordertype == 2) {
         //如果是由询价单生成的订单
         //获取询价单信息
         $sql = 'select * from pap_inquiry where InquiryID=' . $Quoinfo['InquiryID'];
         $Inquiryinfo = Yii::app()->papdb->createCommand($sql)->queryRow();
         if (!$Inquiryinfo) {
             return json_encode(array('success' => false, 'message' => '确认失败,该询价单不存在'));
         }
         if ($Inquiryinfo['Status'] == 2) {
             return json_encode(array('success' => false, 'message' => '确认失败,该询价单已确认'));
         }
         if ($Inquiryinfo['Status'] == 3) {
             return json_encode(array('success' => false, 'message' => '确认失败,该询价单已撤销'));
         }
         // 修改询价单状态
         $updateinquiry = PapInquiry::model()->updateByPK($Quoinfo['InquiryID'], array('Status' => 2));
         if ($updateinquiry != 1) {
             return json_encode(array('success' => false, 'message' => '确认询价单失败', 'msg' => 'check inquiry fail', 'QuoID' => $quoID, 'data' => '确认询价单失败'));
         } else {
             //成功时插入return的SQL
             $opration[1] = 'update pap_inquiry set Status=1 where InquiryID=' . $Quoinfo['InquiryID'];
         }
     }
     //修改方案状态
     $updateschem = InquiryorderService::changeschstatus(array('status' => 2, 'SchID' => $schID));
     if ($updateschem != 1) {
         self::returnint($opration);
         return json_encode(array('success' => false, 'message' => '确认方案失败', 'msg' => 'check scheme fail', 'QuoID' => $quoID, 'data' => '确认方案失败'));
     } else {
         $opration[2] = 'update pap_quotation_scheme set Status="1" where SchID=' . $schID;
     }
     // 修改报价单状态
     $discountdesc = QuotationService::getpriceratio($Quoinfo['DealerID'], $Quoinfo['ServiceID']);
     $updateQuo = PapQuotation::model()->updateByPK($quoID, array('Status' => '2', 'Discount' => $discountdesc['type'] . ',' . $discountdesc['discount']));
     if ($updateQuo != 1) {
         self::returnint($opration);
         return json_encode(array('success' => false, 'message' => '确认报价单失败', 'msg' => 'check quo scheme fail', 'QuoID' => $quoID, 'data' => '确认报价单方案失败'));
     } else {
         $opration[3] = 'update pap_quotation set Status=1 where QuoID=' . $quoID;
     }
     $adressinfo = self::getaddressbypk($address);
     $params = array('payment' => $payment, 'ship' => $adressinfo, 'ordertype' => $ordertype, 'cartsGoods' => array($carts));
     //根据优惠券编号查询优惠券金额
     if ($CouponSn) {
         $copinfo = BuyGoodsService::couponbysn(array('couponsn' => $CouponSn));
         if ($copinfo) {
             $params['coupon'] = $copinfo['Amount'];
             $params['couponsn'] = $copinfo['CouponSn'];
             $params['usecouponID'] = $copinfo['CouponID'];
         }
     }
     //self::returnint($opration);
     $orderID = BuyGoodsService::createorder($params);
     //        exit;
     $orderID = intval($orderID);
     //获取订单编号
     $sql_order = 'select OrderSN from pap_order where ID=' . $orderID;
     $res = Yii::app()->papdb->createCommand($sql_order)->queryRow();
     $order_sn = $res['OrderSN'];
     if (!$orderID) {
         self::returnint($opration);
         return json_encode(array('success' => false, 'message' => '生成订单失败', 'msg' => 'create order fail', 'QuoID' => $quoID, 'data' => '创建订单失败'));
     }
     //保存订单编号到询价单表
     if ($ordertype == 2) {
         PapInquiry::model()->updateByPK($Quoinfo['InquiryID'], array('OrderSn' => $order_sn));
     }
     //保存订单ID到报价单表
     PapQuotation::model()->updateByPK($quoID, array('OrderID' => $orderID));
     //更改报价单待确认状态为已处理
     $sql = 'update pap_remind_business set HandleStatus=2 where HandleID=' . $quoID . ' and OrganID=' . $Quoinfo['ServiceID'];
     Yii::app()->papdb->createCommand($sql)->execute();
     return json_encode(array('success' => true, 'message' => '生成订单成功,点击跳转', 'msg' => 'carate order success', 'QuoID' => $quoID, 'data' => '创建订单成功', 'orderID' => $orderID, 'ordersn' => $order_sn));
 }
コード例 #2
0
ファイル: DealergoodsService.php プロジェクト: zwq/unpei
 /**
  * 模糊循环匹配配件信息(配件查询会用到)
  */
 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;
 }