Пример #1
0
 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
 public function actionSurequotation()
 {
     if (Yii::app()->request->isAjaxRequest) {
         $quoID = Yii::app()->request->getParam('quoID');
         $address = Yii::app()->request->getParam('addressID');
         $payment = Yii::app()->request->getParam('payment');
         $schID = Yii::app()->request->getParam('SchID');
         $goodsids = Yii::app()->request->getParam('goodsid');
         $nums = Yii::app()->request->getParam('num');
         $CouponSn = Yii::app()->request->getParam('CouponSn');
         if ($quoID && $address && $payment && $schID) {
             //InquiryorderService::createorder(报价单ID,方案ID,支付方式,地址ID,'类型')
             $ordertype = 2;
             $result = InquiryorderService::createorder($quoID, $schID, $payment, $address, $ordertype, $goodsids, $nums, $CouponSn);
             echo $result;
         } else {
         }
     }
 }
Пример #3
0
 public static function QuoCreateOrder($params)
 {
     $sql = ' select QuoID,InquiryID from `pap_quotation` where CheckSn="' . $params['msg'] . '" and ServiceID=' . $params['ID'] . ' and Status="1"';
     $res = Yii::app()->papdb->createCommand($sql)->queryRow();
     if (!$res) {
         //没有符合条件的报价单  短信回复内容无效
         $msg = $params['ID'] . '  ' . $params['content'] . '  checksn void!';
         return array('success' => false, 'msg' => $msg);
     } else {
         //获取生成订单需要的参数
         $msg = $params['ID'] . '  ' . $params['content'] . '  checksn valid! start create order';
         $schemesql = ' select SchID from `pap_quotation_scheme` where  QuoID=' . $res['QuoID'];
         $scheme = Yii::app()->papdb->createCommand($schemesql)->queryRow();
         $inqsql = ' select AddressID,Payment,Status from `pap_inquiry` where InquiryID=' . $res['InquiryID'];
         $inqres = Yii::app()->papdb->createCommand($inqsql)->queryRow();
         if ($scheme && $inqres['Status'] == 1 && $params['operate'] == 'Y') {
             //创建订单
             $orderres = InquiryorderService::createorder($res['QuoID'], $scheme['SchID'], $inqres['Payment'], $inqres['AddressID'], 2);
             $orderres = json_decode($orderres, true);
             $orderres['msg'] = $params['ID'] . '  ' . $params['content'] . '  ' . $orderres['msg'];
             if ($orderres['success']) {
                 //                    $smsmsg='尊敬的'.$params['OrganName'].'客户,您短信确认的报价单方案生成订单成功,订单号为:'.$orderres['ordersn'].'!';
                 //                    $sms = F::sendSMS(array(
                 //                                'msg' => $smsmsg,
                 //                                'phone' => $params['Phone'])
                 //                    );
                 Yii::log(date('Y-m-d H:i:s') . " [SMSReply]  order create success", 'info', 'command');
             }
             //更改报价单确认表内容
             $order = $orderres['orderID'] ? $orderres['orderID'] : 0;
             $update = ' update pap_quotation_confirm set ReplyTime=' . $params['time'] . ',ReplyContent="' . $params['content'] . '",`Status`=1,`Desc`="' . $orderres['data'] . '",OrderID=' . $order . ' where QuoID=' . $res['QuoID'];
             Yii::app()->papdb->createCommand($update)->execute();
             return $orderres;
         } else {
             if ($scheme && $inqres['Status'] == 1 && $params['operate'] == 'N') {
                 //拒绝报价单
                 $updatesql = 'update pap_quotation set Status="4" where QuoID=' . $res['QuoID'];
                 $count = Yii::app()->papdb->createCommand($updatesql)->execute();
                 $updatesql = 'update pap_inquiry set Status="4" where InquiryID=' . $res['InquiryID'];
                 $count = Yii::app()->papdb->createCommand($updatesql)->execute();
                 $data = '修理厂拒绝';
                 //更改报价单确认表内容
                 $update = ' update pap_quotation_confirm set ReplyTime=' . $params['time'] . ',ReplyContent="' . $params['content'] . '",`Status`=2, `Desc`="' . $data . '" where QuoID=' . $res['QuoID'];
                 Yii::app()->papdb->createCommand($update)->execute();
                 $msg = $params['ID'] . '  ' . $params['content'] . ' refuse quotation';
                 return array('success' => false, 'msg' => $msg, 'QuoID' => $res['QuoID']);
             } else {
                 if (!$scheme) {
                     $msg = $params['ID'] . '  ' . $params['content'] . '  scheme not exist!';
                     $data = '报价单方案不存在';
                 }
                 $status = array('待报价', '已报价待确认', '已确认', '已撤销', '已拒绝');
                 if ($inqres['Status'] != 1) {
                     $msg = $params['ID'] . '  ' . $params['content'] . '  inquiry status is' . $status[$inqres['Status']];
                     $data = '询价单是' . $status[$inqres['Status']] . '状态';
                 }
                 if ($inqres['Status'] != 1 && !$scheme) {
                     $msg = $params['ID'] . '  ' . $params['content'] . '  scheme not exist! inquiry inquiry status is' . $status[$inqres['Status']];
                     $data = '报价单方案不存在,询价单是' . $status[$inqres['Status']] . '状态';
                 }
                 //更改报价单确认表内容
                 $update = ' update pap_quotation_confirm set ReplyTime=' . $params['time'] . ',ReplyContent="' . $params['content'] . '",`Status`=2,`Desc`="' . $data . ' where QuoID=' . $res['QuoID'];
                 Yii::app()->papdb->createCommand($update)->execute();
                 return array('success' => false, 'msg' => $msg, 'QuoID' => $res['QuoID']);
             }
         }
     }
 }
Пример #4
0
 public function actionSurequotation()
 {
     if (Yii::app()->request->isAjaxRequest) {
         $quoID = Yii::app()->request->getParam('quoID');
         $address = Yii::app()->request->getParam('addressID');
         $payment = Yii::app()->request->getParam('payment');
         $schID = Yii::app()->request->getParam('SchID');
         $goodsids = Yii::app()->request->getParam('goodsid');
         $nums = Yii::app()->request->getParam('num');
         $CouponSn = Yii::app()->request->getParam('CouponSn');
         if ($quoID && $address && $payment && $schID) {
             $sql_inquiry = 'select InquiryID from pap_quotation where QuoID=' . $quoID;
             $result_inquiry = Yii::app()->papdb->createCommand($sql_inquiry)->queryRow();
             //              InquiryorderService::createorder(报价单ID,方案ID,支付方式,地址ID,'类型')
             if ($result_inquiry && $result_inquiry['InquiryID'] > 0) {
                 $ordertype = 2;
             } else {
                 $ordertype = 3;
             }
             $result = InquiryorderService::createorder($quoID, $schID, $payment, $address, $ordertype, $goodsids, $nums, $CouponSn);
             echo $result;
         }
     }
 }