get_all("select * from tb_company where jd_wg_key is not null and jd_wg_key != ''"); $data = ''; $companyId = 0; $supply_id = 0; foreach($companyList as $item) { $jd_wg_key = $item['jd_wg_key']; $a = explode("##", $jd_wg_key); if(count($a) != 3) continue; $publickeyData = "-----BEGIN PUBLIC KEY-----\n".implode("\n", str_split($a[0], 70))."\n-----END PUBLIC KEY-----\n"; $privatekeyData = "-----BEGIN PRIVATE KEY-----\n".implode("\n", str_split($a[1], 70))."\n-----END PRIVATE KEY-----\n"; $accessKey = $a[2]; $data = jd_verify($_POST); if($data) { $companyId = $item['id']; $supply_id = $item['jd_wg_supply_id']; break; } } $data = jd_verify($_POST); if(!$data) { echoRs(0, '签名错误!'); } $supplyInfo = $db->get_one("select * from tb_goods_supply where id = '{$supply_id}'"); $supplier_id = $supplyInfo['supplier_id']; $uid = trim($data['uid']); $orderId = trim($data['orderId']); $totalMoney = floatval($data['totalMoney']); $freight = floatval($data['freight']); //$totalMoney = 100000; $s1 = print_r($_POST, 1); $s2 = print_r($data, 1); file_put_contents("wg_log.txt", $uid."_".$orderId.": ".$s1."\n\n".$s2."\n\n\n\n", FILE_APPEND); if(strpos($uid, "yzmsdc_") === 0) $uid = str_replace('yzmsdc_', '', $uid); $uid = intval($uid); $user = $db->get_one("select * from tb_user where id = {$uid} and enabled != 0"); if(!$user) { echoRs(0, '用户不存在!'); } $wgOrderInfo = $db->get_one("select * from tb_goods_wg_order where orderId = '{$orderId}'"); if($wgOrderInfo) { $order_id = $wgOrderInfo['id']; $status = $wgOrderInfo['status']; $totalMoney2 = $wgOrderInfo['totalMoney']; if($status == 1) { echoRs(0, '该订单已支付!'); } else if($status == 2) { echoRs(0, '该订单已取消!'); } else if($status != 0) { echoRs(0, '出错!'); } if(!money_equal($totalMoney, $totalMoney2)) { echoRs(0, '出错2!'); } } else { $orderDetail = jd_get_order_detail($orderId); if(!$orderDetail) { echoRs(0, '查询订单错误!'); } //print_r($orderDetail);exit; $skuList = $orderDetail['skuList']; $childOrderList = $orderDetail['childOrderList']; $total_num = 0; foreach($skuList as $item) { $total_num += intval($item['num']); } $db->query("insert into tb_goods_wg_order set uid = {$uid}, orderId = '{$orderId}', totalMoney = {$totalMoney}, freight = {$freight}, total_num = {$total_num}, status = '0', jd_state = '".addslashes($orderDetail['state'])."', jd_orderState = '".addslashes($orderDetail['orderState'])."', submitState = '".addslashes($orderDetail['submitState'])."', submitType = '".addslashes($orderDetail['submitType'])."', name = '".addslashes($orderDetail['name'])."', address = '".addslashes($orderDetail['address'])."', phone = '".addslashes($orderDetail['phone'])."', mobile = '".addslashes($orderDetail['mobile'])."', created = '".addslashes($orderDetail['created'])."', jdOrderState = '".addslashes($orderDetail['jdOrderState'])."', provinceName = '".addslashes($orderDetail['provinceName'])."', cityName = '".addslashes($orderDetail['cityName'])."', countyName = '".addslashes($orderDetail['countyName'])."', townName = '".addslashes($orderDetail['townName'])."', addtime = now()", 'SILENT'); if($db->affected_rows() != 1) { echoRs(0, '下单失败!'); } $order_id = $db->insert_id(); $wgOrderInfo = $db->get_one("select * from tb_goods_wg_order where id = ".$order_id); foreach($skuList as $item) { $db->query("insert into tb_goods_wg_order_skus set order_id = {$order_id}, orderId = '{$orderId}', childOrderId = '{$childOrderId}', skuId = '".addslashes($item['skuId'])."', num = ".intval($item['num']).", price = ".floatval($item['price']).", name = '".addslashes($item['name'])."', imgUrl = '".addslashes($item['imgUrl'])."', addtime = now()"); } } $row = $db->get_one("select sum( account ) as c from tb_account where user_id = '{$uid}' and (supplier_id = {$supplier_id} or supplier_id=0)"); $checkye = floatval($row['c']); if(round($checkye*100) < round($totalMoney*100)) { echoRs(0, '余额不足!'); } $row = $db->get_one("select * from tb_goods_order where uid = {$uid} and jdwg_id = {$order_id}"); if($row) { $oid = $row['id']; if($row['state'] != 0) { echoRs(0, '确认订单失败!'); } } else { $code = get_code("tb_goods_order", "code", 5, 'num', date("Ymd")."M"); $db->query("insert into tb_goods_order set code = '{$code}', state = '0', uid = {$uid}, total_num = ".$wgOrderInfo['total_num'].", total_price = ".($totalMoney-$wgOrderInfo['freight']).", `addtime` = now(), deliver_type = '2', link_user = '".addslashes($wgOrderInfo['name'])."', link_phone = '".dbenc(addslashes($wgOrderInfo['mobile']))."', link_province = '".addslashes($wgOrderInfo['provinceName'])."', link_city = '".addslashes($wgOrderInfo['cityName'])."', link_area = '".addslashes($wgOrderInfo['countyName'])."', link_addr = '".dbenc(addslashes($wgOrderInfo['address']))."', confirm_id = '0', mailfee = ".$wgOrderInfo['freight'].", take_place_id = '0', supply_id = '".$supply_id."', tip_count = '0', notes = null, is_print = '0', jdwg_id={$order_id}", 'SILENT'); if($db->affected_rows() != 1) { echoRs(0, '支付失败,请重试!'); } $oid = $db->insert_id(); } if(isset($user) && $user['company_id'] != '30'){ require_once("../show/include/pay.inc.php"); } $rList = array(); $kkfrom = ''; $rList[] = array('ac' => $totalMoney, 'rtype' => 7, 'oid' => $oid, 'supplier_id' => $supplier_id, 'kkfrom' => $kkfrom, 'consume_source' => 'mall'); $r = gpay_pay_user_account($uid, $rList, $updateInfo); if($r != 'suc') { $db->query("delete from tb_goods_order where id=".$oid); echoRs(0, '扣款失败!'); } $db->query("update tb_goods_order set state=1 where id=".$oid); $rs = jd_confirm_order($orderId); if(!$rs) { echoRs(0, '确认订单失败,请重试!'); } if($rs['success']) { $db->query("update tb_goods_wg_order set status=1 where id=".$order_id); } else { echoRs(0, '确认订单失败:'.$rs['resultMessage']); } $data = array( 'type' => '1', 'wg_order_id' => $order_id, 'order_id' => $oid, ); //$sms = "[佛山电信商城系统]你好,你的商城订单{$code}已经下单成功,货物会以快递方式邮寄给你,".($freight>0?("邮费".$freight."元,"):"")."请留意短信息提醒。"; //send_sms($user['cellphone'], $sms); echoRs(1, '下单成功!', array('data' => $data)); function jdGetHTML() { ?> test