dealData($result); if ($return){ $arr = array( 'return_code' => 'SUCCESS', 'return_msg' => 'OK', ); return $this->arrayToXml($arr); }else{ file_put_contents("order_pay_error.txt", file_get_contents("php://input") . "\n" . json_encode($result) . "\n" . "\n", FILE_APPEND); } } } /** * 支付宝支付--支付成功回调订单 */ public function alipayOrderNotify(){ $result = input('post.'); if ($result['trade_status'] == 'TRADE_SUCCESS' || $result['trade_status'] == 'TRADE_FINISHED') { $return = $this->dealData($result); if ($return){ echo 'success'; }else{ file_put_contents("order_alipay_error.txt", file_get_contents("php://input") . "\n" . json_encode($result) . "\n" . "\n", FILE_APPEND); } } } /** * 处理数据库信息 * @param $result * @return bool */ function dealData($result){ Db::startTrans(); try { $order = Db::name('store_order')->where('order_no',$result['out_trade_no'])->find(); Db::name('store_order') ->where('order_no',$result['out_trade_no']) ->update(['status'=>1,'pay_at'=>date('Y-m-d H:i:s'),'return_success_info'=>json_encode($result,true)]); $array = []; $pro_info = json_decode($order['pro_info'],true); for ($i=0;$i<$order['num'];$i++){ //获取排名 $rank = getRanking($order['c_id']); $tag = getTag($order['c_id'],$rank,$order['inventory']); saveRanking($order['c_id']); $company = '象寻数字科技(上海)有限公司'; $hash = getCompanyHash($order['c_id']); $company_hash = $hash['hash']; $ddcid = Db::name('hash')->where('hash',$hash['hash'])->value('ddcid'); $company_hash_time = $hash['create_at'] ? $hash['create_at'] : date('Y-m-d H:i:s'); Db::name('hash')->where('hash',$hash['hash'])->update(['status'=>1]); $collectors_hash = ''; $date = [ 'order_id'=>$order['id'], 'order_no'=>get_order_sn(), 'tag'=>$tag, 'mid'=>$order['mid'], 'c_id'=>$order['c_id'], 'name'=>$pro_info['name'], 'cover'=>$pro_info['cover'], 'pro_info'=>$order['pro_info'], 'company'=>$company, 'company_hash'=>$company_hash, 'company_hash_time'=>$company_hash_time, 'ddcid'=>$ddcid, 'collectors_hash'=>$collectors_hash, 'collectors_hash_time'=>'' ]; $array[] = $date; } Db::name('store_order_info')->insertAll($array); //送积分 $by_collection_integral = getConfigValue('by_collection_integral'); if ($by_collection_integral){ $by_collection_integral = bcmul($by_collection_integral,$order['num']); memberMoneyChange($by_collection_integral,1,$order['mid'],'购买藏品',1,$order['id']); } Db::commit(); return true; } catch (\Exception $e){ Db::rollback(); return false; } } /** * 微信支付--充值盲盒成功回调订单 */ public function BlindRechargeNotify(){ $payXml = file_get_contents("php://input"); //将xml格式转化为json格式 $jsonXml = json_encode(simplexml_load_string($payXml, 'SimpleXMLElement', LIBXML_NOCDATA)); //将json格式转成数组格式 $result['out_trade_no'] $result = json_decode($jsonXml, true); if ($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS') { $return = $this->dealBox($result); if ($return){ $arr = array( 'return_code' => 'SUCCESS', 'return_msg' => 'OK', ); return $this->arrayToXml($arr); }else{ file_put_contents("order_pay_error.txt", file_get_contents("php://input") . "\n" . json_encode($result) . "\n" . "\n", FILE_APPEND); } } } /** * 支付宝支付--充值盲盒回调订单 */ public function alipayBlindRechargeNotify(){ $result = input('post.'); if ($result['trade_status'] == 'TRADE_SUCCESS' || $result['trade_status'] == 'TRADE_FINISHED') { $return = $this->dealBox($result); if ($return){ echo 'success'; }else{ file_put_contents("order_alipay_error.txt", file_get_contents("php://input") . "\n" . json_encode($result) . "\n" . "\n", FILE_APPEND); } } } /** * 盲盒充值次数处理数据库信息 * @param $result * @return bool */ function dealBox($result){ Db::startTrans(); try { $order = Db::name('store_blind_recharge')->where('order_no',$result['out_trade_no'])->find(); if ($order['status']==1) return true; Db::name('store_blind_recharge') ->where('order_no',$result['out_trade_no']) ->update(['status'=>1,'pay_at'=>date('Y-m-d H:i:s'),'return_success_info'=>json_encode($result,true)]); //用户加次数 Db::name('store_member')->where('id',$order['m_id'])->setInc('lottery_number',$order['num']); Db::commit(); return true; } catch (\Exception $e){ Db::rollback(); return false; } } /** * 数组转xml * @ApiInternal */ public function arrayToXml($arr) { $xml = ""; foreach ($arr as $key => $val) { if (is_numeric($val)) { $xml .= "<" . $key . ">" . $val . ""; } else $xml .= "<" . $key . ">"; } $xml .= ""; return $xml; } }