function _xt_report_yiqifa_page($start, $end, $page = 1, $action_id = '', $order_no = '', $status = '') { $app = xt_get_app_yiqifa(); if (empty($app) || empty($app['account']) || empty($app['sid']) || empty($app['syncSecret'])) { wp_die('尚未配置亿起发账号,网站主ID,密钥!'); } //$url = 'http://o.yiqifa.com/servlet/queryCpsMultiRow?sid=' . urlencode($app['sid']) . '&username='******'account']) . '&privatekey=' . urlencode($app['syncSecret']) . '&st=' . urlencode($start) . '&ed=' . urlencode($end); $url = 'http://o.yiqifa.com/servlet/queryCpsMultiRow?sid=' . $app['sid'] . '&username='******'account']) . '&privatekey=' . urlencode($app['syncSecret']) . '&ed=' . urlencode($end) . '&st=' . urlencode($start) . '&action_id=' . urlencode($action_id) . '&order_no=' . urlencode($order_no) . '&status=' . urlencode($status); $body = file_get_contents($url); if (!empty($body)) { $body = xt_iconv($body, 'GBK', 'UTF-8'); $lines = explode("\n", $body); if (!empty($lines)) { foreach ($lines as $line) { $line = trim($line); if (!empty($line)) { $params = explode("||", $line); if (!empty($params) && count($params) > 17) { $yiqifaId = $params[0]; // 亿起发唯一编号 $actionId = $params[1]; // 联盟活动编号 $sid = $params[2]; // 网营商ID(商城) $wid = $params[3]; // 网站编号 $orderTime = $params[4]; // 下单时间 $orderNo = $params[5]; // 订单编号 $commissionType = $params[6]; //佣金分类 $itemId = $params[7]; //商品编号 $itemNums = $params[8]; //订单商品件数 $itemPrice = $params[9]; //订单商品价格 $outerCode = $params[10]; //反馈标签(返利标识) $orderStatus = $params[11]; //订单状态 $commission = $params[12]; //网站主佣金 $cid = $params[13]; //商品分类 //14 未知 $itemTitle = $params[15]; //商品标题 $actionName = $params[16]; //商城活动标题 //17 ?时间 //18无 //19无 //20 ?价格 //21无 //22无 global $xt_report_total; $xt_report_total++; global $wpdb; $count = $wpdb->get_var("SELECT COUNT(*) FROM " . XT_TABLE_YIQIFA_REPORT . " WHERE yiqifaId={$yiqifaId}"); $_user_id = ''; $_user_name = ''; $users = xt_report_fanxian_member('yiqifa', $outerCode); $buyer = $users['buyer']; $sharer = $users['sharer']; $adser = $users['adser']; if ($buyer->exists()) { $_user_id = $buyer->ID; $_user_name = $buyer->user_login; } if ($count == 0) { $wpdb->insert(XT_TABLE_YIQIFA_REPORT, array('yiqifaId' => $yiqifaId, 'actionId' => $actionId, 'actionName' => $actionName, 'cid' => $cid, 'cname' => $cid, 'commission' => $commission, 'commissionType' => $commissionType, 'itemId' => $itemId, 'itemNums' => $itemNums, 'itemPrice' => $itemPrice, 'itemTitle' => $itemTitle, 'orderNo' => $orderNo, 'orderStatus' => $orderStatus, 'orderTime' => $orderTime, 'outerCode' => $outerCode, 'sid' => $sid, 'wid' => $wid, 'user_id' => $_user_id, 'user_name' => $_user_name)); global $xt_report_insert; $xt_report_insert++; } else { $wpdb->update(XT_TABLE_YIQIFA_REPORT, array('actionId' => $actionId, 'actionName' => $actionName, 'cid' => $cid, 'cname' => $cid, 'commission' => $commission, 'commissionType' => $commissionType, 'itemId' => $itemId, 'itemNums' => $itemNums, 'itemPrice' => $itemPrice, 'itemTitle' => $itemTitle, 'orderNo' => $orderNo, 'orderStatus' => $orderStatus, 'orderTime' => $orderTime, 'outerCode' => $outerCode, 'sid' => $sid, 'wid' => $wid), array('yiqifaId' => $yiqifaId)); } if ($orderStatus == 'A' && xt_is_fanxian()) { //订单状态已确认 xt_report_fanxian_save('yiqifa', $buyer, $sharer, $adser, $yiqifaId, $commission, $orderTime); } } } } } } }
function xt_ajax_unorder() { $result = array('code' => 0, 'msg' => '', 'result' => array()); if (!isset($_POST['id']) || empty($_POST['id'])) { $result['code'] = 500; $result['msg'] = '未指定要找回的订单'; exit(json_encode($result)); } if (!isset($_POST['platform']) || empty($_POST['platform'])) { $result['code'] = 500; $result['msg'] = '未指定要找回的订单的类型'; exit(json_encode($result)); } if (!isset($_POST['tradeId']) || empty($_POST['tradeId'])) { $result['code'] = 500; $result['msg'] = '未指定要找回的订单的订单号'; exit(json_encode($result)); } $table = ''; $field_tradeId = ''; $field_commission = ''; $field_payTime = ''; $field_outer = 'outInfo'; switch ($_POST['platform']) { case 'taobao': $table = XT_TABLE_TAOBAO_REPORT; $field_tradeId = 'trade_id'; $field_commission = 'commission'; $field_payTime = 'pay_time'; $field_outer = 'outer_code'; break; case 'paipai': $table = XT_TABLE_PAIPAI_REPORT; $field_tradeId = 'dealId'; $field_commission = 'brokeragePrice'; $field_payTime = 'chargeTime'; $field_outer = 'outInfo'; break; case 'yiqifa': $table = XT_TABLE_YIQIFA_REPORT; $field_tradeId = 'orderNo'; $field_commission = 'commission'; $field_payTime = 'orderTime'; $field_outer = 'outerCode'; break; } if (empty($table)) { $result['code'] = 500; $result['msg'] = '订单类型不正确'; exit(json_encode($result)); } $user = wp_get_current_user(); if ($user->exists()) { global $wpdb; $order = $wpdb->get_row('SELECT * FROM ' . $table . ' WHERE id=' . intval($_POST['id'])); if (empty($order)) { $result['code'] = 500; $result['msg'] = '未找到指定的订单'; exit(json_encode($result)); } if ($order->user_id > 0) { $result['code'] = 500; $result['msg'] = '该订单已被[' . $order->user_name . ']找回'; exit(json_encode($result)); } if ($order->{$field_tradeId} == $_POST['tradeId']) { if ($wpdb->update($table, array('user_id' => $user->ID, 'user_name' => $user->user_login), array('id' => intval($_POST['id'])))) { $needFanxian = false; $commission = $order->{$field_commission}; if ($_POST['platform'] == 'paipai') { $commission = round($commission / 100, 2); $needFanxian = $order->bargainState == 0 && xt_is_fanxian(); } elseif ($_POST['platform'] == 'yiqifa') { $needFanxian = $order->orderStatus == 'A' && xt_is_fanxian(); } elseif ($_POST['platform'] == 'taobao') { $needFanxian = true; } if ($needFanxian) { if (!empty($order->{$field_outer}) && preg_match("/^([a-zA-Z]{4})8\$/", str_replace(XT_FANXIAN_PRE, '', $order->{$field_outer}), $guids)) { $users = xt_report_fanxian_member($_POST['platform'], $order->{$field_outer} . xt_user_guid($user->ID)); $buyer = $users['buyer']; $sharer = $users['sharer']; $adser = $users['adser']; xt_report_fanxian_save($_POST['platform'], $buyer, $sharer, $adser, $_POST['tradeId'], $commission, $order->{$field_payTime}); } else { $users = xt_report_fanxian_member($_POST['platform'], XT_FANXIAN_PRE . $user->ID); $buyer = $users['buyer']; $sharer = $users['sharer']; $adser = $users['adser']; xt_report_fanxian_save($_POST['platform'], $buyer, $sharer, $adser, $_POST['tradeId'], $commission, $order->{$field_payTime}); } } } } else { $result['code'] = 500; $result['msg'] = '订单号不正确'; } } else { $result['code'] = 500; $result['msg'] = '未登录'; } exit(json_encode($result)); }