Exemplo n.º 1
0
 public function view_dresslinkOrderImport()
 {
     include_once WEB_PATH . "lib/PHPExcel.php";
     //phpexcel
     include_once WEB_PATH . "conf/scripts/script.ebay.config.php";
     $toptitle = 'dresslink线下订单导入';
     //头部title
     $this->smarty->assign('toptitle', $toptitle);
     $this->smarty->assign('toplevel', 2);
     $this->smarty->assign('secondlevel', 210);
     $OmAccountAct = new OmAccountAct();
     $dresslinkAccountList = $OmAccountAct->act_dresslinkaccountAllList();
     //$dresslinkAccountList = array(array('id'=>8,'account'=>'dresslink.com'),array('id'=>10,'account'=>'cndirect.com'));
     $this->smarty->assign("dresslinkAccountList", $dresslinkAccountList);
     if (isset($_FILES['cndlFile']['tmp_name']) && isset($_POST['cndlAccount'])) {
         $filePath = $_FILES['cndlFile']['tmp_name'];
         $account = $_POST['cndlAccount'];
         $PHPExcel = new PHPExcel();
         $PHPReader = new PHPExcel_Reader_Excel2007();
         if (!$PHPReader->canRead($filePath)) {
             $PHPReader = new PHPExcel_Reader_Excel5();
             if (!$PHPReader->canRead($filePath)) {
                 echo 'no Excel';
                 return;
             }
         }
         $PHPExcel = $PHPReader->load($filePath);
         $currentSheet = $PHPExcel->getSheet(0);
         $allRow = $currentSheet->getHighestRow();
         /**从第二行开始输出,因为excel表中第一行为列名*/
         /**取得最大的列号*/
         $allColumn = $currentSheet->getHighestColumn();
         $orderData = array();
         $cndlAccounts = array();
         $transportation = CommonModel::getCarrierList();
         //所有的
         $transportationList = array();
         foreach ($transportation as $tranValue) {
             $transportationList[$tranValue['id']] = $tranValue['carrierNameCn'];
         }
         //账号对应
         foreach ($dresslinkAccountList as $accounts) {
             $cndlAccounts[$accounts['id']] = $accounts['account'];
         }
         $c = 2;
         $dresslinks = array();
         $ebay_fedex_remark = array();
         $ChineseDescs = array();
         for ($c = 2; $c <= $allRow; $c++) {
             $aa = 'A' . $c;
             $bb = 'B' . $c;
             $cc = 'C' . $c;
             $dd = 'D' . $c;
             $ee = 'E' . $c;
             $ff = 'F' . $c;
             $gg = 'G' . $c;
             $hh = 'H' . $c;
             $ii = 'I' . $c;
             $jj = 'J' . $c;
             $kk = 'K' . $c;
             $ll = 'L' . $c;
             $mm = 'M' . $c;
             $nn = 'N' . $c;
             $oo = 'O' . $c;
             $pp = 'P' . $c;
             $qq = 'Q' . $c;
             $rr = 'R' . $c;
             $ss = 'S' . $c;
             $tt = 'T' . $c;
             $uu = 'U' . $c;
             $vv = 'V' . $c;
             $ww = 'W' . $c;
             $xx = 'X' . $c;
             $yy = 'Y' . $c;
             $zz = 'Z' . $c;
             $aaa = 'AA' . $c;
             $abb = 'AB' . $c;
             $acc = 'AC' . $c;
             $add = 'AD' . $c;
             $aee = 'AE' . $c;
             $aff = 'AF' . $c;
             $agg = 'AG' . $c;
             $ahh = 'AH' . $c;
             $aii = 'AI' . $c;
             $ajj = 'AJ' . $c;
             $akk = 'AK' . $c;
             $all = 'AL' . $c;
             $amm = 'AM' . $c;
             $ann = 'AN' . $c;
             $aww = 'AW' . $c;
             $recordnumber = trim($currentSheet->getCell($aa)->getValue());
             //订单号
             $recordNumber = $recordnumber;
             $is_order = intval($currentSheet->getCell($bb)->getValue());
             //1代表为订单,0代表订单明细
             if (empty($recordnumber)) {
                 $message .= "<font color=red> 第{$c}行recordnumber为空!</font><br>";
                 break;
             }
             /***************判断订单是否已存在***************/
             $where = "where recordnumber='{$recordnumber}'";
             $orderinfo = cndlModel::selectOrder($where);
             if ($orderinfo) {
                 if ($is_order != 0) {
                     $message .= "<font color='blue'>订单 {$recordnumber}已存在!</font><br>";
                 }
                 continue;
             }
             /**************/
             if ($is_order != 0) {
                 if ($cndlAccounts[$account] == "dresslink.com") {
                     $str = substr($recordnumber, 0, 2);
                     if ($str !== "DL") {
                         $message .= "<font color=red> {$recordnumber}不在账号{$cndlAccounts[$account]}中!</font><br>";
                         continue;
                     }
                 } elseif ($cndlAccounts[$account] == "cndirect.com") {
                     $str = substr($recordnumber, 0, 2);
                     if ($str !== "CN") {
                         $message .= "<font color=red> {$recordnumber}不在账号{$cndlAccounts[$account]}中!</font><br>";
                         continue;
                     }
                 }
                 $platformUsername = mysql_real_escape_string(trim($currentSheet->getCell($cc)->getValue()));
                 $email = mysql_real_escape_string(trim($currentSheet->getCell($dd)->getValue()));
                 $transId = mysql_real_escape_string(trim($currentSheet->getCell($ee)->getValue()));
                 $ordersTime = (array) PHPExcel_Shared_Date::ExcelToPHPObject(trim($currentSheet->getCell($ll)->getValue()));
                 $paymentTime = (array) PHPExcel_Shared_Date::ExcelToPHPObject(trim($currentSheet->getCell($mm)->getValue()));
                 $shippingFee = round_num(trim($currentSheet->getCell($oo)->getValue()), 2);
                 $calcWeight = round_num(trim($currentSheet->getCell($ahh)->getValue()), 3);
                 $actualTotal = round_num(trim($currentSheet->getCell($pp)->getValue()), 2);
                 $onlineTotal = round_num(trim($currentSheet->getCell($aff)->getValue()), 2);
                 $currency = mysql_real_escape_string(trim($currentSheet->getCell($qq)->getValue()));
                 //$orders['ebay_orderqk'] = round_num(trim($currentSheet->getCell($rr)->getValue()), 2);
                 $note = mysql_real_escape_string(trim($currentSheet->getCell($ss)->getValue()));
                 $username = mysql_real_escape_string(trim($currentSheet->getCell($tt)->getValue()));
                 $countryName = mysql_real_escape_string(trim($currentSheet->getCell($uu)->getValue()));
                 $state = mysql_real_escape_string(trim($currentSheet->getCell($vv)->getValue()));
                 $city = mysql_real_escape_string(trim($currentSheet->getCell($ww)->getValue()));
                 $street = mysql_real_escape_string(trim($currentSheet->getCell($xx)->getValue()));
                 $address2 = mysql_real_escape_string(trim($currentSheet->getCell($yy)->getValue()));
                 $zipCode = mysql_real_escape_string(trim($currentSheet->getCell($zz)->getValue()));
                 $phone = mysql_real_escape_string(trim($currentSheet->getCell($abb)->getValue()));
                 $landline = mysql_real_escape_string(trim($currentSheet->getCell($aaa)->getValue()));
                 if ($account == "dresslink.com") {
                     $feedback = mysql_real_escape_string(trim($currentSheet->getCell($ann)->getValue()));
                 } elseif ($account == "cndirect.com") {
                     $feedback = mysql_real_escape_string(trim($currentSheet->getCell($akk)->getValue()));
                 }
                 $carrierNameCn = strtolower(mysql_real_escape_string(trim($currentSheet->getCell($kk)->getValue())));
                 $carrierNameCn = cndlModel::carrier($carrierNameCn);
                 $payment_method = mysql_real_escape_string(trim($currentSheet->getCell($ff)->getValue()));
                 $payment_module = mysql_real_escape_string(trim($currentSheet->getCell($gg)->getValue()));
                 $bank_account = mysql_real_escape_string(trim($currentSheet->getCell($hh)->getValue()));
                 $bank_country = mysql_real_escape_string(trim($currentSheet->getCell($ii)->getValue()));
                 $shipping_method = mysql_real_escape_string(trim($currentSheet->getCell($jj)->getValue()));
                 $shipping_module = mysql_real_escape_string(trim($currentSheet->getCell($kk)->getValue()));
                 $dresslinks['payment_method'] = $payment_method;
                 $dresslinks['payment_module'] = $payment_module;
                 $dresslinks['bank_account'] = $bank_account;
                 $dresslinks['bank_country'] = $bank_country;
                 $dresslinks['shipping_method'] = $shipping_method;
                 $dresslinks['shipping_module'] = $shipping_module;
                 $PayPalPaymentId = $transId;
                 /***************BEGIN 订单表数据***************/
                 $orderData[$recordNumber]['orderData']['recordNumber'] = $recordnumber;
                 if ($cndlAccounts[$account] == "dresslink.com") {
                     $orderData[$recordNumber]['orderData']['platformId'] = 10;
                     $orderData[$recordNumber]['orderData']['accountId'] = $account;
                 } elseif ($cndlAccounts[$account] == "cndirect.com") {
                     $orderData[$recordNumber]['orderData']['platformId'] = 8;
                     $orderData[$recordNumber]['orderData']['accountId'] = $account;
                 }
                 $orderData[$recordNumber]['orderData']['orderStatus'] = C('STATEPENDING');
                 $orderData[$recordNumber]['orderData']['orderType'] = C('STATEPENDING_INITIAL');
                 $orderData[$recordNumber]['orderData']['ordersTime'] = strtotime($ordersTime['date']);
                 //平台下单时间
                 $orderData[$recordNumber]['orderData']['paymentTime'] = strtotime($paymentTime['date']);
                 $orderData[$recordNumber]['orderData']['onlineTotal'] = $onlineTotal;
                 //线上总金额
                 $orderData[$recordNumber]['orderData']['actualTotal'] = $actualTotal;
                 //付款总金额
                 $orderData[$recordNumber]['orderData']['isFixed'] = 1;
                 $orderData[$recordNumber]['orderData']['calcShipping'] = $shippingFee;
                 //物流费用
                 $orderData[$recordNumber]['orderData']['orderAddTime'] = time();
                 $orderData[$recordNumber]['orderData']['isNote'] = empty($note) ? 0 : 1;
                 foreach ($transportation as $tranValue) {
                     if ($tranValue['carrierNameCn'] == $carrierNameCn) {
                         $orderData[$recordNumber]['orderData']['transportId'] = $tranValue['id'];
                         //运输方式id
                         break;
                     }
                 }
                 /***************END 订单表数据***************/
                 /***************BEGIN 订单扩展表数据***************/
                 $orderData[$recordNumber]['orderExtenData']['paymentStatus'] = "Complete";
                 $orderData[$recordNumber]['orderExtenData']['transId'] = $transId;
                 $orderData[$recordNumber]['orderExtenData']['PayPalPaymentId'] = $PayPalPaymentId;
                 $orderData[$recordNumber]['orderExtenData']['paymentMethod'] = $payment_method;
                 $orderData[$recordNumber]['orderExtenData']['paymentModule'] = $payment_module;
                 $orderData[$recordNumber]['orderExtenData']['shippingMethod'] = $shipping_method;
                 $orderData[$recordNumber]['orderExtenData']['ShippingModule'] = $shipping_module;
                 $orderData[$recordNumber]['orderExtenData']['currency'] = $currency;
                 $orderData[$recordNumber]['orderExtenData']['feedback'] = $feedback;
                 //客户留言
                 /***************END 订单扩展表数据***************/
                 /***************BEGIN 订单用户表数据***************/
                 $orderData[$recordNumber]['orderUserInfoData']['username'] = $username;
                 $orderData[$recordNumber]['orderUserInfoData']['platformUsername'] = $platformUsername;
                 $orderData[$recordNumber]['orderUserInfoData']['email'] = $email;
                 $orderData[$recordNumber]['orderUserInfoData']['countryName'] = $countryName;
                 $orderData[$recordNumber]['orderUserInfoData']['currency'] = $currency;
                 $orderData[$recordNumber]['orderUserInfoData']['state'] = $state;
                 // 省
                 $orderData[$recordNumber]['orderUserInfoData']['city'] = $city;
                 // 市
                 $orderData[$recordNumber]['orderUserInfoData']['street'] = $street;
                 $orderData[$recordNumber]['orderUserInfoData']['address2'] = $address2;
                 $orderData[$recordNumber]['orderUserInfoData']['landline'] = $landline;
                 // 座机电话
                 $orderData[$recordNumber]['orderUserInfoData']['phone'] = $phone;
                 // 手机
                 $orderData[$recordNumber]['orderUserInfoData']['zipCode'] = $zipCode;
                 // 邮编
                 /*************END 订单用户表数据***************/
                 //note信息
                 if (!empty($note)) {
                     $orderData[$recordNumber]['orderNote'][$c]['content'] = $note;
                     $orderData[$recordNumber]['orderNote'][$c]['userId'] = $_SESSION['sysUserId'];
                 }
             } else {
                 $sku = mysql_real_escape_string(trim($currentSheet->getCell($acc)->getValue()));
                 $itemTitle = mysql_real_escape_string(trim($currentSheet->getCell($add)->getValue()));
                 $itemPrice = round_num(trim($currentSheet->getCell($aff)->getValue()), 2);
                 $amount = intval(trim($currentSheet->getCell($agg)->getValue()));
                 $shipingfee = round_num(trim($currentSheet->getCell($ahh)->getValue()), 2);
                 /***************BEGIN 订单详细数据***************/
                 $orderData[$recordNumber]['orderDetail'][$c]['orderDetailData']['recordNumber'] = $recordnumber;
                 $orderData[$recordNumber]['orderDetail'][$c]['orderDetailData']['sku'] = $sku;
                 $orderData[$recordNumber]['orderDetail'][$c]['orderDetailData']['itemPrice'] = $itemPrice;
                 $orderData[$recordNumber]['orderDetail'][$c]['orderDetailData']['amount'] = $amount;
                 $orderData[$recordNumber]['orderDetail'][$c]['orderDetailData']["shippingFee"] = $shipingfee;
                 $orderData[$recordNumber]['orderDetail'][$c]['orderDetailData']['createdTime'] = time();
                 /*************END 订单详细数据***************/
                 /***************BEGIN 订单详细扩展表数据***************/
                 $orderData[$recordNumber]['orderDetail'][$c]['orderDetailExtenData']['itemTitle'] = $itemTitle;
                 $orderData[$recordNumber]['orderDetail'][$c]['orderDetailExtenData']['transId'] = $transId;
                 //$orderData['orderDetail']['orderDetailExtenData']['note'] = $value[10];
                 $categoryName = trim($currentSheet->getCell($ajj)->getValue());
                 $customCode = trim($currentSheet->getCell($akk)->getValue());
                 $material = trim($currentSheet->getCell($all)->getValue());
                 $ShenBaoQuantity = trim($currentSheet->getCell($amm)->getValue());
                 $ShenBaoUnitPrice = trim($currentSheet->getCell($ann)->getValue());
                 $ChineseDesc = trim($currentSheet->getCell($aww)->getValue());
                 //$salePrice						   =	round_num(mysql_real_escape_string(trim($detail['SalePrice'])), 2);	//实际SKU付款价
                 /*************END 订单详细扩展表数据***************/
                 $ebay_fedex_remark[$recordNumber][$categoryName][] = array('real_price' => $ShenBaoUnitPrice, 'qty' => $ShenBaoQuantity, 'hamcodes' => $customCode, 'detail' => $material);
                 $orderData[$recordNumber]['fedexRemark'] = $ebay_fedex_remark[$recordNumber];
                 $orderData[$recordNumber]['dresslinkInfo'] = $dresslinks;
                 $ChineseDescs[$recordNumber][$categoryName] = $ChineseDesc;
             }
         }
         if ($orderData) {
             foreach ($orderData as $id => $order) {
                 $msg = commonModel::checkOrder($id);
                 if ($msg) {
                     $message .= "<font color='red'>订单{$id}已存在!</font><br>";
                     continue;
                 }
                 //计算订单属性
                 if (count($order['orderDetail']) == 1) {
                     $detail = current($order['orderDetail']);
                     if ($detail['orderDetailData']['amount'] == 1) {
                         $orderData[$id]['orderData']['orderAttribute'] = 1;
                     } else {
                         $orderData[$id]['orderData']['orderAttribute'] = 2;
                     }
                 } else {
                     $orderData[$id]['orderData']['orderAttribute'] = 3;
                 }
                 //计算订单重量及包材
                 $obj_order_detail_data = array();
                 foreach ($order['orderDetail'] as $sku => $detail) {
                     $obj_order_detail_data[] = $detail['orderDetailData'];
                 }
                 $weightfee = commonModel::calcOrderWeight($obj_order_detail_data);
                 $orderData[$id]['orderData']['calcWeight'] = $weightfee[0];
                 $orderData[$id]['orderData']['pmId'] = $weightfee[1];
                 //计算运费
                 $calcShippingInfo = CommonModel::calcAddOrderShippingFee($insertOrder, $orderData[$id]['orderData']['isFixed']);
                 //计算运费
                 $orderData[$id]['orderData']['channelId'] = $calcShippingInfo['fee']['channelId'];
                 $orderData[$id]['orderData']['calcShipping'] = $calcShippingInfo['fee'];
                 $ChineseDescs_arr = array_filter(array_unique($ChineseDescs[$id]));
                 $orderData[$id]['orderNote'] = array('content' => join(' ', $ChineseDescs_arr), 'userId' => $_SESSION['sysUserId'], 'createdTime' => time());
                 /*//缺货拦截
                 		$orderData[$id] = AutoModel :: auto_contrast_intercept($orderData[$id]);
                 		//$orderData[$id] = cndlModel :: auto_contrast_intercept($orderData[$id]);*/
                 //插入订单OrderAddModel::insertAllOrderRow($orderData[$id],'cndl');
                 //调用旧系统接口,先插入数据到旧系统
                 //echo "<pre>"; var_dump($orderData[$id]); exit;
                 $rtn = OldsystemModel::orderErpInsertorder($orderData[$id]);
                 //echo "<pre>";print_r($rtn);exit;
                 $insertData = array();
                 if (empty($rtn)) {
                     $message .= "<font color='red'>订单{$id}同步ERP发生异常,跳过!</font><br>";
                     continue;
                 }
                 if ($rtn['errcode'] == 200) {
                     $rtn_data = $rtn['data'];
                     $orderId = $rtn_data['orderId'];
                     $message .= "<font color='green'>插入老系统成功,订单编号 [{$orderId}]</font><br>";
                     $pmId = $rtn_data['pmId'];
                     $totalweight = $rtn_data['totalweight'];
                     $shipfee = $rtn_data['shipfee'];
                     $carrier = $rtn_data['carrier'];
                     $carrierId = $rtn_data['carrierId'];
                     $status = $rtn_data['status'];
                     $orderData[$id]['orderData']['id'] = $orderId;
                     //赋予新系统订单编号,一切数据已老系统返回的为准
                     if ($orderData[$id]['orderData']['calcWeight'] != $totalweight) {
                         $insertData['old_totalweight'] = $totalweight;
                         $insertData['new_totalweight'] = $orderData[$id]['orderData']['calcWeight'];
                         $orderData[$id]['orderData']['calcWeight'] = $totalweight;
                     }
                     if ($orderData[$id]['orderData']['pmId'] != $pmId) {
                         $insertData['old_pmId'] = $pmId;
                         $insertData['new_pmId'] = $orderData[$id]['orderData']['pmId'];
                         $orderData[$id]['orderData']['pmId'] = $pmId;
                     }
                     if ($orderData[$id]['orderData']['calcShipping'] != $shipfee) {
                         $insertData['old_shippfee'] = $shipfee;
                         $insertData['new_shippfee'] = $orderData[$id]['orderData']['calcShipping'];
                         $orderData[$id]['orderData']['calcShipping'] = $shipfee;
                     }
                     if ($orderData[$id]['orderData']['transportId'] != $carrierId) {
                         $insertData['old_carrierId'] = $carrierId;
                         $insertData['new_carrierId'] = $orderData[$id]['orderData']['transportId'];
                         $orderData[$id]['orderData']['transportId'] = $carrierId;
                     }
                     if (!empty($insertData)) {
                         $insertData['ebay_id'] = $orderId;
                         $insertData['addtime'] = time();
                         OldsystemModel::insertTempSyncRecords($insertData);
                         // 插入临时对比记录表
                     }
                     //缺货拦截
                     $orderData[$id] = AutoModel::auto_contrast_intercept($orderData[$id]);
                     //插入订单
                     $info = OrderAddModel::insertAllOrderRowNoEvent($orderData[$id]);
                     if ($info) {
                         $dresslinkinfos = $orderData[$id]['dresslinkInfo'];
                         $dresslinkinfos['omOrderId'] = $orderId;
                         if (DresslinkinfoModel::insertDresslinkinfoList($dresslinkinfos)) {
                             $message .= "<font color='green'>订单{$id}上传dresslinkInfo成功!</font><br>";
                         } else {
                             $message .= "<font color='red'>订单{$id}上传dresslinkInfo失败!</font><br>";
                         }
                         $message .= "<font color='green'>新系统订单{$id}添加成功!</font><br>";
                     } else {
                         $message .= "<font color='red'>新系统订单{$id}添加失败!</font><br>";
                     }
                 } else {
                     $message .= "<font color='red'>添加失败,原因为:{$rtn['msg']}!</font><br>";
                 }
                 if ($orderId) {
                     foreach ($ebay_fedex_remark[$id] as $k => $v) {
                         $fedex_remark = array();
                         $fedex_remark['description'] = trim("[No Brand]" . $k . "{$v[0]['detail']}");
                         if (in_array($transportationList[$order['orderData']['transportId']], array('FedEx'))) {
                             //$fedex_remark['description'] = "[No Brand]". $k."({$v[0]['detail']})";
                             $fedex_remark['type'] = 1;
                         } else {
                             if (in_array($transportationList[$order['orderData']['transportId']], array('DHL', 'EMS', 'UPS美国专线'))) {
                                 //$fedex_remark['description'] = trim($k);
                                 $fedex_remark['type'] = 2;
                             } else {
                                 continue;
                             }
                         }
                         $sku_price = 0;
                         $qty = 0;
                         foreach ($v as $v0) {
                             $sku_price += $v0['real_price'];
                             $qty += $v0['qty'];
                         }
                         //$fedex_remark['ebay_ordersn'] 	= $order['ebay_ordersn'];
                         $fedex_remark['price'] = round($sku_price / $qty, 2);
                         $fedex_remark['amount'] = $qty;
                         $fedex_remark['hamcodes'] = $v[0]['hamcodes'];
                         if (in_array($transportationList[$order['orderData']['transportId']], array('DHL', 'EMS', 'UPS美国专线'))) {
                             $fedex_remark['price'] = round($sku_price, 2);
                         }
                         $fedex_remark['createdTime'] = time();
                         $fedex_remark['omOrderId'] = $orderId;
                         $fedex_remark['creatorId'] = $_SESSION['sysUserId'];
                         //$insert_fedex_sql = "INSERT INTO fedex_remark set ".array2sql($fedex_remark);
                         $info = OmAvailableModel::insertRow("om_express_remark", " set " . array2sql_bak($fedex_remark));
                         if ($info) {
                             $message .= "<font color=green> {$id} 导入海关记录成功!</font><br>";
                             //echo "----<font color=green> {$order['recordnumber']} 导入海关记录成功!</font><br>";
                         } else {
                             //echo $insert_fedex_sql; echo "<br>";
                             $message .= "<font color=green> {$id} 导入海关记录失败!</font><br>";
                             //echo "----<font color=red>{$order['recordnumber']} 导入海关记录失败!</font><br>";
                             //$fail_order[] = $order['orderData']['recordnumber'];
                         }
                     }
                 }
             }
         }
         $this->smarty->assign("showerrorinfo", $message);
     }
     $this->smarty->display('dresslinkOrderImport.htm');
 }
Exemplo n.º 2
0
 function act_sureAddOrder()
 {
     $order_data = array();
     $detail_data = array();
     $exten_data = array();
     $userinfo_data = array();
     $buyer_data = array();
     $time = time();
     $platform_id = trim($_POST['platform']);
     $username = trim($_POST['fullname']);
     $account_id = trim($_POST['account']);
     $street1 = trim($_POST['street1']);
     $platformUsername = trim($_POST['userid']);
     $email = trim($_POST['ebay_usermail1']);
     $street2 = trim($_POST['street2']);
     $recordNumber = trim($_POST['orderid']);
     $city = trim($_POST['city']);
     $ordersTime = strtotime(trim($_POST['ebay_createdtime']));
     $state = trim($_POST['state']);
     $paymentTime = strtotime(trim($_POST['ebay_paidtime']));
     $countryname = trim($_POST['country']);
     $ebay_itemprice = trim($_POST['ebay_itemprice']);
     $zipCode = trim($_POST['zip']);
     $shippingFee = trim($_POST['ebay_shipfee']);
     $ebay_tel1 = trim($_POST['tel1']);
     $actualTotal = trim($_POST['ebay_total']);
     $ebay_tel2 = trim($_POST['tel2']);
     $ebay_tel3 = trim($_POST['tel3']);
     $currency = trim($_POST['ebay_currency']);
     $other_currency = trim($_POST['other_currency']);
     $isCheckOrder = self::act_checkOrder();
     $returnArr = array();
     //返回的数组信息
     if (!$isCheckOrder) {
         $returnArr['errCode'] = self::$errCode;
         $returnArr['errMsg'] = self::$errMsg;
         return $returnArr;
     }
     if ($currency == '其他') {
         $currency = $other_currency;
     }
     $phone = trim($_POST['tel1']);
     $transId = trim($_POST['ebay_ptid']);
     $other_ptid = trim($_POST['other_ptid']);
     if ($transId == 'paypal' || $transId == 'Escrow' || $transId == '其他') {
         $transId = $other_ptid;
     }
     $PayPalPaymentId = $transId;
     $orderweight = trim($_POST['orderweight']);
     $ebay_usermail2 = trim($_POST['ebay_usermail2']);
     $ebay_carrier = trim($_POST['ebay_carrier']);
     $ebay_usermail3 = trim($_POST['ebay_usermail3']);
     $ebay_tracknumber = trim($_POST['ebay_tracknumber']);
     $ebay_noteb = trim($_POST['ebay_noteb']);
     $orderStatus = 100;
     $orderType = 101;
     $tracknumber = trim($_POST['ebay_tracknumber']);
     //order信息
     $orderData[$recordNumber]['orderData']['recordNumber'] = $recordNumber;
     $orderData[$recordNumber]['orderData']['ordersTime'] = $ordersTime;
     $orderData[$recordNumber]['orderData']['paymentTime'] = $paymentTime;
     $orderData[$recordNumber]['orderData']['actualTotal'] = $actualTotal;
     $orderData[$recordNumber]['orderData']['onlineTotal'] = $actualTotal;
     //默认线上总价和实际总价一样
     $orderData[$recordNumber]['orderData']['orderAddTime'] = time();
     //$orderData[$recordNumber]['orderData']['calcWeight'] = $orderweight;//估算重量
     $orderData[$recordNumber]['orderData']['accountId'] = $account_id;
     $orderData[$recordNumber]['orderData']['platformId'] = $platform_id;
     //添加状态信息
     $orderData[$recordNumber]['orderData']['orderStatus'] = 100;
     $orderData[$recordNumber]['orderData']['orderType'] = 101;
     $SYS_ACCOUNTS = OmAvailableModel::getPlatformAccount();
     foreach ($SYS_ACCOUNTS as $platform => $accounts) {
         foreach ($accounts as $accountId => $accountname) {
             if ($account_id == $accountId) {
                 if ($platform == 'ebay') {
                     //为ebay平台
                     $orderData[$recordNumber]['orderData']['isFixed'] = 2;
                 } else {
                     $orderData[$recordNumber]['orderData']['isFixed'] = 1;
                 }
             }
         }
     }
     $transportation = CommonModel::getCarrierList();
     //所有的
     foreach ($transportation as $tranValue) {
         if ($tranValue['id'] == $ebay_carrier) {
             $orderData[$recordNumber]['orderData']['transportId'] = $tranValue['id'];
             break;
         }
     }
     //order扩展信息
     $orderData[$recordNumber]['orderExtenData']['currency'] = $currency;
     $orderData[$recordNumber]['orderExtenData']['paymentStatus'] = "PAY_SUCCESS";
     //$orderData[$recordNumber]['orderExtenData']['transId']			    =	$transId;
     $orderData[$recordNumber]['orderExtenData']['PayPalPaymentId'] = $PayPalPaymentId;
     $orderData[$recordNumber]['orderExtenData']['platformUsername'] = $platformUsername;
     //user信息
     $orderData[$recordNumber]['orderUserInfoData']['platformUsername'] = $platformUsername;
     $orderData[$recordNumber]['orderUserInfoData']['username'] = $username;
     $orderData[$recordNumber]['orderUserInfoData']['email'] = $email;
     $orderData[$recordNumber]['orderUserInfoData']['street'] = $street1;
     $orderData[$recordNumber]['orderUserInfoData']['currency'] = $currency;
     $orderData[$recordNumber]['orderUserInfoData']['address2'] = $street2;
     $orderData[$recordNumber]['orderUserInfoData']['city'] = $city;
     $orderData[$recordNumber]['orderUserInfoData']['state'] = $state;
     $orderData[$recordNumber]['orderUserInfoData']['zipCode'] = $zipCode;
     $orderData[$recordNumber]['orderUserInfoData']['countryName'] = $countryname;
     $orderData[$recordNumber]['orderUserInfoData']['landline'] = !empty($ebay_tel2) ? $ebay_tel2 : $ebay_tel3;
     $orderData[$recordNumber]['orderUserInfoData']['phone'] = $phone;
     //note信息
     if (!empty($ebay_noteb)) {
         $orderData[$recordNumber]['orderNote']['content'] = $ebay_noteb;
         $orderData[$recordNumber]['orderNote']['userId'] = $_SESSION['sysUserId'];
         $orderData[$recordNumber]['orderNote']['createdTime'] = time();
     }
     //tracknumer信息
     $orderData[$recordNumber]['orderTrack']['tracknumber'] = $tracknumber;
     $sku_list = $_POST['sku'];
     $sku_count = $_POST['qty'];
     $ebay_itemtitle = $_POST['name'];
     $count = count($sku_list);
     for ($i = 0; $i < $count; $i++) {
         //detail信息
         $sku = $sku_list[$i];
         $orderData[$recordNumber]['orderDetail'][$sku]['orderDetailData']['sku'] = $sku_list[$i];
         $orderData[$recordNumber]['orderDetail'][$sku]['orderDetailData']['amount'] += $sku_count[$i];
         //累加
         $orderData[$recordNumber]['orderDetail'][$sku]['orderDetailData']['recordNumber'] = $recordNumber;
         $orderData[$recordNumber]['orderDetail'][$sku]['orderDetailData']['createdTime'] = time();
         $orderData[$recordNumber]['orderDetail'][$sku]['orderDetailExtenData']['itemTitle'] = $ebay_itemtitle[$i];
     }
     foreach ($orderData as $id => $order) {
         //$orderData 中第一维只有一个元素,方便起见这里用foreach,虽然只循环一次
         $ret = commonModel::checkOrder($recordNumber);
         if ($ret) {
             $returnArr['errCode'] = 101;
             $returnArr['errMsg'] = "订单{$recordNumber}已存在!";
             return $returnArr;
         }
         //计算订单属性
         if (count($order['orderDetail']) == 1) {
             $detail = current($order['orderDetail']);
             if ($detail['orderDetailData']['amount'] == 1) {
                 $orderData[$id]['orderData']['orderAttribute'] = 1;
             } else {
                 $orderData[$id]['orderData']['orderAttribute'] = 2;
             }
         } else {
             $orderData[$id]['orderData']['orderAttribute'] = 3;
         }
         //计算订单重量及包材
         $obj_order_detail_data = array();
         foreach ($order['orderDetail'] as $sku => $detail) {
             $obj_order_detail_data[] = $detail['orderDetailData'];
         }
         $weightfee = commonModel::calcOrderWeight($obj_order_detail_data);
         $orderData[$id]['orderData']['calcWeight'] = $weightfee[0];
         $orderData[$id]['orderData']['pmId'] = $weightfee[1];
         $calcShippingInfo = CommonModel::calcAddOrderShippingFee($orderData[$id], $orderData[$id]['orderData']['isFixed']);
         //计算运费
         $orderData[$id]['orderData']['channelId'] = $calcShippingInfo['channelId'];
         $orderData[$id]['orderData']['calcShipping'] = $calcShippingInfo['fee'];
         //调用旧系统接口,先插入数据到旧系统
         $rtn = OldsystemModel::orderErpInsertorder($orderData[$id]);
         $insertData = array();
         if (empty($rtn)) {
             $returnArr['errCode'] = 102;
             $returnArr['errMsg'] = "接口返回异常,请重试!";
             return $returnArr;
         }
         if ($rtn['errcode'] == 200) {
             $rtn_data = $rtn['data'];
             $orderId = $rtn_data['orderId'];
             //echo "插入老系统成功,订单编号 [$orderId] \n";
             $pmId = $rtn_data['pmId'];
             $totalweight = $rtn_data['totalweight'];
             $shipfee = $rtn_data['shipfee'];
             $carrier = $rtn_data['carrier'];
             $carrierId = $rtn_data['carrierId'];
             $status = $rtn_data['status'];
             $orderData[$id]['orderData']['id'] = $orderId;
             //赋予新系统订单编号
             if ($orderData['orderData']['calcWeight'] != $totalweight) {
                 $insertData['old_totalweight'] = $totalweight;
                 $insertData['new_totalweight'] = $orderData[$id]['orderData']['calcWeight'];
                 $orderData[$id]['orderData']['calcWeight'] = $totalweight;
             }
             if ($orderData['orderData']['pmId'] != $pmId) {
                 $insertData['old_pmId'] = $pmId;
                 $insertData['new_pmId'] = $orderData[$id]['orderData']['pmId'];
                 $orderData[$id]['orderData']['pmId'] = $pmId;
             }
             if ($orderData['orderData']['calcShipping'] != $shipfee) {
                 $insertData['old_shippfee'] = $shipfee;
                 $insertData['new_shippfee'] = $orderData[$id]['orderData']['calcShipping'];
                 $orderData[$id]['orderData']['calcShipping'] = $shipfee;
             }
             if ($orderData['orderData']['transportId'] != $carrierId) {
                 $insertData['old_carrierId'] = $carrierId;
                 $insertData['new_carrierId'] = $orderData[$id]['orderData']['transportId'];
                 $orderData[$id]['orderData']['transportId'] = $carrierId;
             }
             if (!empty($insertData)) {
                 $insertData['ebay_id'] = $orderId;
                 $insertData['addtime'] = time();
                 //var_dump($insertData);
                 OldsystemModel::insertTempSyncRecords($insertData);
                 // 插入临时对比记录表
             }
             //缺货拦截
             $orderData[$id] = AutoModel::auto_contrast_intercept($orderData[$id]);
             //插入订单
             $info = OrderAddModel::insertAllOrderRowNoEvent($orderData[$id]);
             if ($info) {
                 $returnArr['errCode'] = 200;
                 $returnArr['errMsg'] = "订单{$id}上传成功!";
             } else {
                 $returnArr['errCode'] = 404;
                 $returnArr['errMsg'] = "订单{$id}上传失败!";
             }
         } else {
             $returnArr['errCode'] = 400;
             $returnArr['errMsg'] = "添加失败,原因为:{$rtn['msg']}!";
         }
     }
     return $returnArr;
 }
Exemplo n.º 3
0
 public function view_aliexpressimport()
 {
     $this->smarty->assign('toplevel', 2);
     $this->smarty->assign('secondlevel', 24);
     $OmAccountAct = new OmAccountAct();
     //$aliexpressAccountList = $OmAccountAct->act_getAccountListByPid(2);
     $aliexpressAccountList = $OmAccountAct->act_getAccountListAliexpress();
     var_dump($aliexpressAccountList);
     $aliexpressAccountList = json_decode($aliexpressAccountList, true);
     $this->smarty->assign("aliexpressAccountList", $aliexpressAccountList);
     $this->smarty->display('aliexpressImport.htm');
     include_once WEB_PATH . "lib/PHPExcel.php";
     //phpexcel
     $toptitle = 'underLineOrderImport';
     //头部title
     $this->smarty->assign('toptitle', $toptitle);
     $this->smarty->assign('toplevel', 2);
     $this->smarty->assign('secondlevel', 22);
     if (isset($_FILES['orderUpfile']['tmp_name'])) {
         $filePath = $_FILES['orderUpfile']['tmp_name'];
         $PHPExcel = new PHPExcel();
         $PHPReader = new PHPExcel_Reader_Excel2007();
         if (!$PHPReader->canRead($filePath)) {
             $PHPReader = new PHPExcel_Reader_Excel5();
             if (!$PHPReader->canRead($filePath)) {
                 echo 'no Excel';
                 return;
             }
         }
         $PHPExcel = $PHPReader->load($filePath);
         $currentSheet = $PHPExcel->getSheet(0);
         //$excellists    = excel2array($PHPExcel, $filePath, 0, 0);
         //print_r($excellists);print_r($_SESSION);
         $orderid = array();
         $orderData = array();
         //$orderarr = OrderindexModel::showSearchOrderList("om_unshipped_order","where da.id=14448");
         //echo "<pre>";print_r($orderarr);
         $c = 2;
         while (true) {
             $aa = 'A' . $c;
             $bb = 'B' . $c;
             $cc = 'C' . $c;
             $dd = 'D' . $c;
             $ee = 'E' . $c;
             $ff = 'F' . $c;
             $gg = 'G' . $c;
             $hh = 'H' . $c;
             $ii = 'I' . $c;
             $jj = 'J' . $c;
             $kk = 'K' . $c;
             $ll = 'L' . $c;
             $mm = 'M' . $c;
             $nn = 'N' . $c;
             $oo = 'O' . $c;
             $pp = 'P' . $c;
             $qq = 'Q' . $c;
             $rr = 'R' . $c;
             $ss = 'S' . $c;
             $tt = 'T' . $c;
             $uu = 'U' . $c;
             $vv = 'V' . $c;
             $ww = 'W' . $c;
             $xx = 'X' . $c;
             $yy = 'Y' . $c;
             $zz = 'Z' . $c;
             $c++;
             $account = trim($currentSheet->getCell($aa)->getValue());
             $recordNumber = trim($currentSheet->getCell($bb)->getValue());
             $platformUsername = trim($currentSheet->getCell($cc)->getValue());
             $email = trim($currentSheet->getCell($dd)->getValue());
             $ordersTime = trim($currentSheet->getCell($ee)->getValue());
             $paymentTime = trim($currentSheet->getCell($ff)->getValue());
             $sku = trim($currentSheet->getCell($gg)->getValue());
             $amount = trim($currentSheet->getCell($hh)->getValue());
             $itemTitle = trim($currentSheet->getCell($ii)->getValue());
             $note = trim($currentSheet->getCell($jj)->getValue());
             $itemPrice = trim($currentSheet->getCell($kk)->getValue());
             $shippingFee = trim($currentSheet->getCell($ll)->getValue());
             $actualTotal = trim($currentSheet->getCell($mm)->getValue());
             $currency = trim($currentSheet->getCell($nn)->getValue());
             $transId = trim($currentSheet->getCell($oo)->getValue());
             $username = trim($currentSheet->getCell($pp)->getValue());
             $street = trim($currentSheet->getCell($qq)->getValue());
             $address2 = trim($currentSheet->getCell($rr)->getValue());
             $address3 = trim($currentSheet->getCell($ss)->getValue());
             $city = trim($currentSheet->getCell($tt)->getValue());
             $state = trim($currentSheet->getCell($uu)->getValue());
             $zipCode = trim($currentSheet->getCell($vv)->getValue());
             $countryName = trim($currentSheet->getCell($ww)->getValue());
             $landline = trim($currentSheet->getCell($xx)->getValue());
             $carrierNameCn = trim($currentSheet->getCell($yy)->getValue());
             if (empty($account)) {
                 break;
             }
             if (in_array($recordNumber, $orderid)) {
                 $orderData[$recordNumber]['orderDetail'][$sku]['orderDetailData']['sku'] = $sku;
                 $orderData[$recordNumber]['orderDetail'][$sku]['orderDetailData']['amount'] = $amount;
                 $orderData[$recordNumber]['orderDetail'][$sku]['orderDetailData']['itemPrice'] = $itemPrice;
                 $orderData[$recordNumber]['orderDetail'][$sku]['orderDetailData']['shippingFee'] = $shippingFee;
                 $orderData[$recordNumber]['orderDetail'][$sku]['orderDetailExtenData']['itemTitle'] = $itemTitle;
                 //$orderData['orderDetail']['orderDetailExtenData']['note'] = $value[10];
                 $orderData[$recordNumber]['orderDetail'][$sku]['orderDetailExtenData']['transId'] = $transId;
                 if (!empty($note)) {
                     $orderData[$recordNumber]['orderNote'][$c]['content'] = $note;
                     $orderData[$recordNumber]['orderNote'][$c]['userId'] = $_SESSION['sysUserId'];
                 }
             } else {
                 $orderid[] = $recordNumber;
                 //order信息
                 $orderData[$recordNumber]['orderData']['recordNumber'] = $recordNumber;
                 $orderData[$recordNumber]['orderData']['ordersTime'] = strtotime($ordersTime);
                 $orderData[$recordNumber]['orderData']['paymentTime'] = strtotime($paymentTime);
                 $orderData[$recordNumber]['orderData']['actualTotal'] = $actualTotal;
                 $orderData[$recordNumber]['orderData']['orderAddTime'] = time();
                 $SYSTEM_ACCOUNTS = OmAvailableModel::getTNameList("om_account", "*", " where account='{$account}'");
                 $orderData[$recordNumber]['orderData']['accountId'] = $SYSTEM_ACCOUNTS[0]['id'];
                 $orderData[$recordNumber]['orderData']['platformId'] = $SYSTEM_ACCOUNTS[0]['platformId'];
                 $SYSTEM_ACCOUNTS = OmAvailableModel::getPlatformAccount();
                 foreach ($SYSTEM_ACCOUNTS as $platform => $accounts) {
                     foreach ($accounts as $accountId => $accountname) {
                         if ($account == $accountname) {
                             if ($platform == "ebay") {
                                 $orderData[$recordNumber]['orderData']['isFixed'] = 2;
                             } else {
                                 $orderData[$recordNumber]['orderData']['isFixed'] = 1;
                             }
                         }
                     }
                 }
                 $transportation = CommonModel::getCarrierList();
                 //所有的
                 foreach ($transportation as $tranValue) {
                     if ($tranValue['carrierNameCn'] == $carrierNameCn) {
                         $orderData[$recordNumber]['orderData']['transportId'] = $tranValue['id'];
                         break;
                     }
                     //$transportationList[$tranValue['id']] = $tranValue['carrierNameCn'];
                 }
                 //order扩展信息
                 $orderData[$recordNumber]['orderExtenData']['currency'] = $currency;
                 $orderData[$recordNumber]['orderExtenData']['paymentStatus'] = "PAY_SUCCESS";
                 $orderData[$recordNumber]['orderExtenData']['transId'] = $recordNumber;
                 // 交易id;;
                 $orderData[$recordNumber]['orderExtenData']['platformUsername'] = $platformUsername;
                 //$orderData[$recordNumber]['orderExtenData']['currency']				=	$currency;
                 //user信息
                 $orderData[$recordNumber]['orderUserInfoData']['platformUsername'] = $platformUsername;
                 $orderData[$recordNumber]['orderUserInfoData']['username'] = $username;
                 $orderData[$recordNumber]['orderUserInfoData']['email'] = $email;
                 $orderData[$recordNumber]['orderUserInfoData']['street'] = $street;
                 $orderData[$recordNumber]['orderUserInfoData']['currency'] = $currency;
                 $orderData[$recordNumber]['orderUserInfoData']['address2'] = $address2;
                 $orderData[$recordNumber]['orderUserInfoData']['address3'] = $address3;
                 $orderData[$recordNumber]['orderUserInfoData']['city'] = $city;
                 $orderData[$recordNumber]['orderUserInfoData']['state'] = $state;
                 $orderData[$recordNumber]['orderUserInfoData']['zipCode'] = $zipCode;
                 $orderData[$recordNumber]['orderUserInfoData']['countryName'] = $countryName;
                 $orderData[$recordNumber]['orderUserInfoData']['landline'] = $landline;
                 //detail信息
                 $orderData[$recordNumber]['orderDetail'][$sku]['orderDetailData']['sku'] = $sku;
                 $orderData[$recordNumber]['orderDetail'][$sku]['orderDetailData']['amount'] = $amount;
                 $orderData[$recordNumber]['orderDetail'][$sku]['orderDetailData']['itemPrice'] = $itemPrice;
                 $orderData[$recordNumber]['orderDetail'][$sku]['orderDetailData']['shippingFee'] = $shippingFee;
                 $orderData[$recordNumber]['orderDetail'][$sku]['orderDetailData']['recordNumber'] = $recordNumber;
                 $orderData[$recordNumber]['orderDetail'][$sku]['orderDetailData']['createdTime'] = time();
                 $orderData[$recordNumber]['orderDetail'][$sku]['orderDetailExtenData']['itemTitle'] = $itemTitle;
                 //$orderData['orderDetail']['orderDetailExtenData']['note'] = $value[10];
                 $orderData[$recordNumber]['orderDetail'][$sku]['orderDetailExtenData']['transId'] = $transId;
                 //note信息
                 if (!empty($note)) {
                     $orderData[$recordNumber]['orderNote'][$c]['content'] = $note;
                     $orderData[$recordNumber]['orderNote'][$c]['userId'] = $_SESSION['sysUserId'];
                 }
             }
         }
         //echo "<pre>";print_r($orderData);
         $message = "";
         foreach ($orderData as $id => $order) {
             $msg = commonModel::checkOrder($id);
             if ($msg) {
                 $message .= "<font color='red'>订单{$id}已存在!</font><br>";
                 continue;
             }
             //计算订单属性
             if (count($order['orderDetail']) == 1) {
                 $detail = current($order['orderDetail']);
                 if ($detail['orderDetailData']['amount'] == 1) {
                     $orderData[id]['orderData']['orderAttribute'] = 1;
                 } else {
                     $orderData[id]['orderData']['orderAttribute'] = 2;
                 }
             } else {
                 $orderData[id]['orderData']['orderAttribute'] = 3;
             }
             //计算订单重量及包材
             $obj_order_detail_data = array();
             foreach ($order['orderDetail'] as $sku => $detail) {
                 $obj_order_detail_data[] = $detail['orderDetailData'];
             }
             $weightfee = commonModel::calcOrderWeight($obj_order_detail_data);
             $orderData[$id]['orderData']['calcWeight'] = $weightfee[0];
             //$orderData[$value[0]]['orderData']['calcShipping'] = $weightfee[3];
             $orderData[$id]['orderData']['pmId'] = $weightfee[1];
             //计算运费
             $calcShippingInfo = CommonModel::calcAddOrderShippingFee($insertOrder, $orderData[$id]['orderData']['isFixed']);
             //计算运费
             $orderData[$id]['orderData']['channelId'] = $calcShippingInfo['fee']['channelId'];
             //缺货拦截
             $status = commonModel::auto_contrast_intercept($orderData[$id]);
             $orderData[$id]['orderData']['orderStatus'] = $status['orderStatus'];
             $orderData[$id]['orderData']['orderType'] = $status['orderType'];
             //print_r($order);
             //插入订单
             $info = OrderAddModel::insertAllOrderRowNoEvent($order);
             if ($info) {
                 $message .= "<font color='green'>订单{$id}上传成功!</font><br>";
             } else {
                 $message .= "<font color='red'>订单{$id}上传失败!</font><br>";
             }
         }
         $this->smarty->assign("showerrorinfo", $message);
         //header("location:index.php?mod=underLineOrderImport&act=importOrder");
     }
     $this->smarty->display('underLineOrderImport.htm');
 }