public function view_categoryListAli() { /* ----- 获取全部的分类列表 -----*/ $msgcat_obj = new messagecategoryModel(); $lp_ojb = new LocalPowerModel(); $powerlist = $lp_ojb->getAliPowerlist($_SESSION['userId']); // print_r($powerlist);exit; if (empty($powerlist['field'])) { $filsql = '0'; } else { $filsql = implode(', ', $powerlist['field']); } //echo $filsql;exit; $arrlist = $msgcat_obj->getAllCategoryInfoList(' and id in (' . $filsql . ') and platform=2 order by category_name'); $msg_obj = new AliOderMessageModel(); foreach ($arrlist as &$listval) { /* ---- 计算某个分类下已经读取的数量 <订单留言> ---- */ $replyed_num_order = $msg_obj->culculateNumberOrder(" and fieldId={$listval['id']} and hasread=1"); $listval['replyed_order'] = $replyed_num_order; /* ---- 计算某个分类下未读的数量 <订单留言>---- */ $noreply_num_order = $msg_obj->culculateNumberOrder(" and fieldId={$listval['id']} and hasread=0"); $listval['noreply_order'] = $noreply_num_order; /* ---- 计算某个分类下已读的数量 <站内信> ---- */ $replyed_num_site = $msg_obj->culculateNumberSite(" and fieldId={$listval['id']} and hasread=1"); $listval['replyed_site'] = $replyed_num_site; /* ---- 计算某个分类下未读的数量 <站内信>---- */ $noreply_num_site = $msg_obj->culculateNumberSite(" and fieldId={$listval['id']} and hasread=0"); $listval['noreply_site'] = $noreply_num_site; } $this->smarty->assign('sec_menue', 2); $this->smarty->assign('toplevel', 1); $this->smarty->assign('categorylist', $arrlist); $this->smarty->assign('toptitle', 'message类别列表-速卖通'); $this->smarty->display('msgcategorylistAli.htm'); }
public function view_fetchAliOrderDetailByOrderId() { $orderid = isset($_GET['orid']) ? trim($_GET['orid']) : FALSE; $account = isset($_GET['account']) ? trim($_GET['account']) : FALSE; $receiverid = $account; if (empty($receiverid)) { $returndata['errCode'] = 3; $returndata['errMsg'] = '缺少卖家账号!'; echo json_encode($returndata); exit; } if (empty($orderid)) { //订单号不存在 $returndata['errCode'] = 3; $returndata['errMsg'] = '缺少订单号!'; echo json_encode($returndata); exit; } $tokenfilepath = WEB_PATH . "lib/ali_keys/config_{$receiverid}.php"; if (!file_exists($tokenfilepath)) { $returndata['errCode'] = 2; $returndata['errMsg'] = '没找到messsage信息!'; echo json_encode($returndata); exit; } include_once '' . $tokenfilepath; include_once WEB_PATH . 'lib/AliMessage.class.php'; $ali_obj = new AliMessage(); $ali_obj->setConfig($appKey, $appSecret, $refresh_token); $ali_obj->doInit(); //$orderid = '60637623549259'; $detail = $ali_obj->fetchOrderdetail($orderid); if ($detail == FALSE) { //获取消息失败 $returndata['errCode'] = 4; $returndata['errMsg'] = '获取订单详情失败!'; echo json_encode($returndata); exit; } //print_r($detail);exit; $alimsg_obj = new AliOderMessageModel(); $time = $detail['gmtCreate']; $year = substr($time, 0, 4); //年 $month = substr($time, 4, 2); //月 $day = substr($time, 6, 2); //日 $time = $month . '/' . $day . '/' . $year; $timeend = $month . '/' . (intval($day) + 1) . '/' . $year; $skustr = ''; foreach ($detail['childOrderList'] as $sku) { $skucode = substr($sku['skuCode'], 0, strlen($sku['skuCode']) - 1); $tmpstr = $skucode; $hstr = strrchr($tmpstr, '*'); //处理组合料号 $tmpstr = $hstr === FALSE ? $tmpstr : ltrim($hstr, '*'); $spu = explode('_', $tmpstr); $spu = $spu[0]; $attr = json_decode($sku[productAttributes], TRUE); $skuimgurl = getSkuImg($spu, $tmpstr, 'G'); $attrinfo = json_decode($sku['productAttributes'], TRUE); $attrstr = array(); if (isset($sku['productAttributes']) && !empty($attrinfo['sku'])) { foreach ($attrinfo['sku'] as $attrval) { $attrstr[] = $attrval['pName'] . ':' . $attrval['pValue']; } } $attrstr = implode('<br>', $attrstr); $skustr .= <<<EOF \t\t\t\t<tr> \t\t\t\t\t\t<td> \t\t\t\t\t\t\t<img src="{$skuimgurl}" width="50" height="50"> \t\t\t\t\t\t</td> \t\t\t\t\t\t<td align="left"> \t\t\t\t\t\t<a href="http://www.aliexpress.com/item/something/{$sku['productId']}.html" target="_blank">{$sku['productName']}</a> \t\t\t\t\t\t</td> \t\t\t\t\t\t<td> \t\t\t\t\t\t {$attrstr} \t\t\t\t\t\t</td> \t\t\t\t\t\t<td> \t\t\t\t\t\t {$skucode} \t\t\t\t\t\t</td> \t\t\t\t\t\t<td> \t\t\t\t\t\t {$sku['productCount']} \t\t\t\t\t\t</td> \t\t\t\t\t\t<td> \t\t\t\t\t {$sku[productPrice][currency][symbol]}{$sku[productPrice][amount]} \t\t\t\t\t\t</td> \t\t\t\t\t</tr> EOF; } $skulist = <<<EOF \t\t\t\t\t<tr class="title"> \t\t\t\t\t\t<td> \t\t\t\t\t\t\t图片 \t\t\t\t\t\t</td> \t\t\t\t\t\t<td> \t\t\t\t\t\t\t标题 \t\t\t\t\t\t</td> \t\t\t\t\t\t<td style="width:60px;"> \t\t\t\t\t\t\t属性 \t\t\t\t\t\t</td> \t\t\t\t\t\t<td> \t\t\t\t\t\t\tSKU \t\t\t\t\t\t</td> \t\t\t\t\t\t<td style="width:60px;"> \t\t\t\t\t\t\t数量 \t\t\t\t\t\t</td> \t\t\t\t\t\t<td> \t\t\t\t\t\t\t单价 \t\t\t\t\t\t</td> \t\t\t\t\t</tr> {$skustr} EOF; //计算倒计时 $timeStr = ''; if ($detail['orderStatus'] == 'RISK_CONTROL') { //计算风控倒计时 $paytimestamp = aliTranslateTime($detail['gmtPaySuccess']); //付款时间戳 $riskendtime = $paytimestamp + 86400; $timeStr = date('m/d/Y H:i:s', $riskendtime); //风控结束时间字符串表示 $timeStr = $riskendtime; } elseif ($detail['logisticsStatus'] == 'SELLER_SEND_GOODS' && $detail['orderStatus'] != 'FINISH') { $sendTimeStamp = aliTranslateTime($detail['logisticInfoList'][0]['gmtSend']); //发货时间戳 $days = $alimsg_obj->culculateCountdown($receiverid, $detail['logisticInfoList'][0]['logisticsTypeCode'], $detail['receiptAddress']['country']); if ($days === FALSE) { $timeStr = AliOderMessageModel::$errMsg; } else { $endtime = $sendTimeStamp + $days * 86400; $timeStr = $endtime; } } //物流信息 $shipstr = ''; if (isset($detail['logisticInfoList'][0])) { $shipstr .= '运输方式:' . $detail['logisticInfoList'][0]['logisticsTypeCode'] . '<br>'; $carrier = $detail['logisticInfoList'][0]['logisticsTypeCode']; $tracksn = $detail['logisticInfoList'][0]['logisticsNo']; $trackstr = <<<EOF <a href="javascript:queryExpressInfo('aliexpress', '{$carrier}', '{$tracksn}', 'zh')">{$tracksn}</a> EOF; $shipstr .= '跟踪号:' . $trackstr . '<br>'; } $returndata['errCode'] = 5; $returndata['errMsg'] = '成功!'; $returndata['data'] = array('buyer' => $detail['buyerInfo']['firstName'] . $detail['buyerInfo']['lastName'], 'seller' => $detail['sellerOperatorLoginId'], 'orderId' => $orderid, 'createtime' => formateAliTime($detail['gmtCreate']), 'paytime' => !empty($detail['gmtPaySuccess']) ? formateAliTime($detail['gmtPaySuccess']) : '未付款', 'initOderAmount' => $detail['initOderAmount']['currency']['symbol'] . $detail['initOderAmount']['amount'], 'OderAmount' => $detail['orderAmount']['currency']['symbol'] . $detail['orderAmount']['amount'], 'paytype' => '-----', 'fundStatus' => $this->status2str($detail['fundStatus']), 'loanStatus' => $this->status2str($detail['loanStatus']), 'issueStatus' => $this->status2str($detail['issueStatus']), 'issuscolor' => $detail['issueStatus'] == 'NO_ISSUE' ? 'green' : 'red', 'orderstatus' => $this->status2str($detail['orderStatus']), 'logisticsStatus' => $this->status2str($detail['logisticsStatus']), 'logisticsMoney' => $detail['logisticsAmount']['amount'], 'mobileNo' => $detail['receiptAddress']['mobileNo'], 'phoneNumber' => $detail['receiptAddress']['phoneArea'] . '-' . $detail['receiptAddress']['phoneNumber'], 'address' => $detail['receiptAddress']['detailAddress'] . ' ' . $detail['receiptAddress']['city'] . ' ' . $detail['receiptAddress']['province'] . ' ' . $detail['receiptAddress']['country'], 'skulist' => $skulist, 'refund' => isset($detail['refundInfo']) ? '退款状态' . $detail['refundInfo']['refundStatus'] . '<br>' . '退款类型' . $detail['refundInfo']['refundType'] : '', 'logisticInfo' => $shipstr, 'buyerSignerFullname' => isset($detail['buyerSignerFullname']) ? $detail['buyerSignerFullname'] : '', 'zip' => isset($detail['receiptAddress']['zip']) ? $detail['receiptAddress']['zip'] : '', 'email' => isset($detail['buyerInfo']['email']) ? $detail['buyerInfo']['email'] : '', 'timestr' => $timeStr, 'commission' => '$' . round($detail['orderAmount']['amount'] * 0.05, 2), 'profit' => '$' . round($detail['orderAmount']['amount'] * 0.95, 2)); if (isset($detail['logisticInfoList'][0]['gmtSend'])) { $timeinfo = extractAliTimeInfo($detail['logisticInfoList'][0]['gmtSend']); $returndata['data']['shippedtime'] = $timeinfo['year'] . '-' . $timeinfo['month'] . '-' . $timeinfo['day'] . ' ' . $timeinfo['hour'] . ':' . $timeinfo['minit'] . ':' . $timeinfo['second']; } else { $returndata['data']['shippedtime'] = ''; } $accountname = aliAccountf2Name($detail['sellerOperatorLoginId']); if ($accountname == FALSE) { //没找到对应关系 $accountname == ''; } $accountname = aliAccountf2Name($account); if ($accountname == FALSE) { //没找到对应关系 $accountname == ''; } $result_sys = getOpenSysApi('aliExpressOrderInfo', array('type' => 'orderinfo', 'recordnumber' => $orderid, 'selleraccount' => $accountname)); if (!empty($result_sys['data'])) { $returndata['data']['systemnum'] = $result_sys['data'][0]['ebay_id']; //系统编号 $returndata['data']['syscarrer'] = $result_sys['data'][0]['ebay_carrier']; //运输方式 $returndata['data']['systracknumber'] = $result_sys['data'][0]['ebay_tracknumber']; //跟踪号 // $returndata['data']['shippedtime'] = empty($result_sys['data'][0]['ShippedTime']) ? '' : date('Y-m-d H:i:s', $result_sys['data'][0]['ShippedTime']); //发货时间 $returndata['data']['status'] = $result_sys['data'][0]['catename']; //发货状态 $returndata['data']['ebay_note'] = $result_sys['data'][0]['note']; //订单留言 } else { $returndata['data']['systemnum'] = ''; //系统编号 $returndata['data']['syscarrer'] = ''; //运输方式 $returndata['data']['systracknumber'] = ''; //跟踪号 // $returndata['data']['shippedtime'] = ''; //发货时间 $returndata['data']['status'] = ''; //发货状态 $returndata['data']['ebay_note'] = ''; } // print_r($returndata);exit; echo json_encode($returndata); }
public function getSiteMessage($starttime, $endtime) { global $ali_user; $currentpage = 1; //当前页码 默认为一 $aliorder_obj = new AliOderMessageModel(); //message数据库处理类 $roundtimes = 1; $pageindex = 1; while ($roundtimes++ <= 50) { //一次最多抓50次 echo "\ncurrent page number : {$pageindex}\n"; $data = array('access_token' => $this->access_token, 'currentPage' => $pageindex, 'pageSize' => ALI_PAGESIZE, 'startTime' => $starttime, 'endTime' => $endtime); $url = "{$this->server}/{$this->rootpath}/{$this->protocol}/{$this->version}/{$this->ns}/api.queryMessageList/{$this->appKey}"; $result = $this->Curl($url, $data); $List = json_decode($result, true); if ($List === FALSE) { //返回数据个格式错误 则跳出重来 <防止网络故障> writeLog(ALI_LOGPATH, '返回数据格式错误 --- ' . $result . "\n" . var_export($data, TRUE)); continue; } if (isset($List['error_code'])) { //返回报错信息 writeLog(ALI_LOGPATH, '返回数据格式错误 --- ' . $result . "\n" . var_export($data, TRUE)); continue; } // print_r($List); exit; $msg_list = $List['msgList']; if (empty($msg_list)) { //抓取的消息为空 则说明该时间段的数据已经抓取完成了 则跳出 break; } foreach ($msg_list as $msgval) { $data = array(); $data['message_id'] = $msgval['id']; $exists = $aliorder_obj->checkIfExistsBySiteMsgId($data['message_id']); if ($exists) { // 改消息已经抓取过了 <防止重复抓取> echo "message has exists! --- ID : {$data['message_id']}\n"; continue; } $data['relationId'] = $msgval['relationId']; // 关系id $data['senderid'] = $msgval['senderLoginId']; // 发送人登陆id // echo "sender => ", $data['senderid'],"\n"; if ($this->isWorker($data['senderid'])) { $data['role'] = 0; //0表示工作人员回复的 } else { $data['role'] = 1; //1表示客户回复的 } // print_r($data);continue; $data['sendername'] = $msgval['senderName']; // 发送人名称 $data['receiverid'] = $msgval['receiverLoginId']; // 接收人登陆id $data['receivername'] = $msgval['receiverName']; // 接收名称 $data['productUrl'] = $msgval['productUrl']; // 产品url $data['productName'] = $msgval['productName']; // 产品名称 $data['productId'] = $msgval['productId']; // 产品id $data['typeId'] = $msgval['typeId']; // 类型id $data['addtime'] = time(); // 抓单时间 $data['orderUrl'] = trim($msgval['orderUrl']); // 订单url $data['orderId'] = trim($msgval['orderId']); // 订单id $data['gmtCreate'] = $msgval['gmtCreate']; // message产生时间 $data['createtimestamp'] = aliTranslateTime($msgval['gmtCreate']); //转换时间戳 $data['content'] = $msgval['content']; // 消息内容 $data['isRead'] = $msgval['isRead']; // 是否已读取 $data['haveFile'] = $msgval['haveFile']; // 是否有附件 $data['fileUrl'] = $msgval['fileUrl']; // 附件地址 if ($data['role'] == 1) { //客户留言则分配文件夹 工作人员回复不分配文件夹 $data['fieldid'] = $this->getFiledId($data['senderid'], $data['receiverid']); //获得分类id信息 } else { $data['fieldid'] = 0; } // echo $data['fieldid'],"\n\n";continue; if (!empty($data['orderId']) && !empty($data['orderUrl'])) { //该留言与订单绑定 $orderDetail = $this->fetchOrderdetail($data['orderId']); // print_r($orderDetail);exit; if (isset($orderDetail['frozenStatus']) && $orderDetail['frozenStatus'] == 'IN_FROZEN') { //冻结中订单 $data['orderstatus'] = strtoupper($orderDetail['frozenStatus']); } elseif (isset($orderDetail['issueStatus']) && $orderDetail['issueStatus'] == 'IN_ISSUE') { $data['orderstatus'] = strtoupper($orderDetail['issueStatus']); } elseif (isset($orderDetail['orderStatus'])) { $data['orderstatus'] = strtoupper($orderDetail['orderStatus']); } else { $data['orderstatus'] = ''; } } $insert_result = $aliorder_obj->insertNewSiteMsgRecords($data); // 存入数据库 if ($insert_result == FALSE) { // 插入失败 写日志 writeLog(ALI_LOGPATH, AliOderMessageModel::$errMsg); continue; } else { echo 'add success ! ', $data['message_id'], "\n"; } } $pageindex++; //$roundtimes++; } unset($List); return TRUE; }
public function culculateCountdown($account, $shippingType, $country) { $country_obj = new CountryNameManageModel(); $countryInfo = $country_obj->getRealCountryNameWithCountryCode($country); if (empty($countryInfo)) { self::$errMsg = 'no exists!'; return FALSE; } //var_dump($countryInfo);exit; $realCountryName = $countryInfo['countryname']; //国家全称 //echo $realCountryName;exit; $aliship_obj = new AliShipTemplateModel(); $tplsetinfo = $aliship_obj->getAccountSetInfo($account); if (empty($tplsetinfo)) { self::$errMsg = 'no setting'; return FALSE; } $tplinfo = $aliship_obj->getTplInfoById($tplsetinfo['tplid']); if ($tplinfo == FALSE) { //不存在的模板 self::$errMsg = 'tpl not exists'; return FALSE; } $tplFilePath = $tplinfo['filepath']; $fileName = basename($tplFilePath); //文件名 $dirName = dirname($tplFilePath); //目录 $exdirName = substr($fileName, 0, strlen($fileName) - 4); //解压目录的名称 $exFullPath = $dirName . '/' . $exdirName; if (!is_dir($exFullPath)) { self::$errMsg = 'data not exists'; return FALSE; } $days = FALSE; $fileEnties = scandir($exFullPath); foreach ($fileEnties as $val) { $entry = $exFullPath . '/' . $val; if (is_dir($entry)) { continue; } if (strrchr($val, '.') != '.txt') { //必须是txt文件 continue; } $shippingType = strtolower($shippingType); // echo $realCountryName; // $country = strtolower($country); if (strpos($val, $shippingType) !== FALSE) { $content = file_get_contents($entry); if (strpos($content, $realCountryName) !== FALSE) { $days = strrchr($val, '_'); $days = intval(ltrim($days, '_')); break; } } } if ($days === FALSE) { //没找到 $default = $exFullPath . '/' . $shippingType . '_def.txt'; if (is_file($default)) { $days = file_get_contents($default); $days = intval($days); } else { $fixfile = $exFullPath . '/' . 'fix.txt'; if (is_file($fixfile)) { $fp = fopen($fixfile, 'r'); if ($fp !== FALSE) { while (!feof($fp)) { $buffer = fgets($fp); $buffer = trim($buffer); $buffer = strtolower($buffer); if (strpos($shippingType, $buffer) !== FALSE) { $buffer = str_replace($shippingType, '', $buffer); $buffer = trim($buffer); $days = intval($days); } } fclose($fp); } } } } //echo $days, 'xx';exit; self::$errMsg = 'not found'; return $days; }
public function view_changeReadStatus_site() { $status = isset($_GET['status']) ? intval($_GET['status']) : FALSE; //状态 $msgdata = array('errCode' => 0, 'errMsg' => ''); if ($status === FALSE) { $msgdata = array('errCode' => 0, 'errMsg' => '未指定状态!'); echo json_encode($msgdata); exit; } $ids = isset($_GET['ids']) ? trim($_GET['ids']) : FALSE; $idar = clearData($ids); if (empty($idar)) { $msgdata = array('errCode' => 0, 'errMsg' => '为指定id!'); echo json_encode($msgdata); exit; } $status = $status == 0 ? 0 : 1; $orerMessage_obj = new AliOderMessageModel(); $result = $orerMessage_obj->markAliSiteOrderMessageReadStatus($idar, $status); if ($result) { $msgdata = array('errCode' => 1, 'errMsg' => '成功!'); echo json_encode($msgdata); exit; } else { $msgdata = array('errCode' => 0, 'errMsg' => '失败!'); echo json_encode($msgdata); exit; } }