lvhao 1 mesiac pred
rodič
commit
f8e6de70e8
1 zmenil súbory, kde vykonal 224 pridanie a 194 odobranie
  1. 224 194
      core/CoreApp/models/Model_api.php

+ 224 - 194
core/CoreApp/models/Model_api.php

@@ -112,197 +112,206 @@ function __construct(){
 			}
    	    	return $thatDayOrder;
 		}
-		if($name == 'alipearlstore' || $name == 'finsahair' || $name == 'baddiebeautyshop')
+		if(in_array($name,['alipearlstore','finsahair','baddiebeautyshop','yolissahair']))
 		{
-			$ch = curl_init();
-        	curl_setopt($ch, CURLOPT_URL,$shopapi);//?status=any所有订单 &limit=200每页多少单
-        	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
-        	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); 
-        	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
-        	$res = curl_exec($ch);
-        	//$this->logic_ding->sendToDing("测试获取自建站订单".$res);
-        	curl_close($ch);
-        	$res = json_decode($res,true);
-			$thatDayOrder = array();
-        	if(isset($res['orders']))
-			{
-				foreach ($res['orders'] as $v)
+			if(!empty($shop['shopadmin'])){
+				$post['shopify'] = $shopapi.'?status=any&limit=200';//?status=any所有订单 &limit=200每页多少单
+				$ch = curl_init();
+				curl_setopt($ch,CURLOPT_URL,'https://edm.alipearl.net/soapapi.php');
+				curl_setopt($ch, CURLOPT_POST, 1);
+				curl_setopt($ch, CURLOPT_HEADER, 0);
+				curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
+				curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
+				curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
+				curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
+				curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+				curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,1800000);
+				$res = curl_exec($ch);
+				curl_close($ch);
+				$res = json_decode($res,true);
+				$thatDayOrder = array();
+				$thatDayOrder = array();
+				if(isset($res['orders']))
 				{
-					$productNames = '';
-					$parameters = array();
-					$skus = '';
-					$quantity = '';
-					$thislink = '';
-					foreach($v['line_items'] as $key=>$val)
-					{
-		   				$productNames .= ($key > 0)?','.$val['name']:$val['name'];
-		   		    	$skus .= ($key > 0)?','.$val['sku']:$val['sku'];
-						$quantity .= floor($val['quantity']).';';
-	     			}
-					if(stripos($v['gateway'],'shopify_') !== false)
-					{
-						$pay = 'shopifypay';
-					}
-					else if(stripos($v['gateway'],'paypal') !== false)
-					{
-						$pay = 'paypal_express';
-					}
-					else if(stripos($v['gateway'],'gift_card') !== false)
-					{
-						$pay = 'gift_card';
-					}
-					else if(stripos($v['gateway'],'shop_cash') !== false)
-					{
-						$pay = 'shop_cash';
-					}
-					else
-					{
-						$pay = $v['gateway'];
-					}
-					$khbz = '';
-					if(!isset($v['shipping_address']['country_code']))
+					foreach ($res['orders'] as $v)
 					{
-						$v['shipping_address'] = $v['billing_address'];
-						$khbz = '客户自提订单; ';
-					}
-			    	$shipping_address = $v['shipping_address']['address2'].' '.$v['shipping_address']['address1'] . ',' . $v['shipping_address']['city'] . ',' . $v['shipping_address']['province'] . ',' . $v['shipping_address']['zip'] . ',' . $v['shipping_address']['country_code'] . ',' . $v['shipping_address']['phone'];
-			    	@$billing_address = $v['billing_address']['address2'].' '.$v['billing_address']['address1'] . ',' . $v['billing_address']['city'] . ',' . $v['billing_address']['province'] . ',' . $v['billing_address']['zip'] . ',' . $v['billing_address']['country_code'] . ',' . $v['billing_address']['phone'];
-					$created_at = explode('T',$v['created_at']);
-					$created_at_hi = explode('-',$created_at[1]);
-					$created_at = $created_at[0].' '.$created_at_hi[0];
-					$paypal = '';
-					$d = $this->authorization($shop,$v['id']);
-					if($d['g'] == 1)
-					{
-						$paypal = $d['d'];
-					}
-					if($name == 'baddiebeautyshop')
-					{
-						$wcsku = '';
-						$wcquantity = '';
-						$ztsku = explode(',',rtrim($skus,','));
-						$ztquantity = explode(';',rtrim($quantity,';'));
-						foreach ($ztsku as $txk=>$txval)
-		        		{
-						    $skupx = array(13=>'',22=>'',8=>'',15=>'',18=>'','100'=>'',33=>'',34=>'',35=>'',7=>'','dc'=>'','c'=>'',14=>'',12=>'',25=>'',26=>'',27=>'',10=>'',6=>'',9=>'',999=>'',9999=>'');
-						    $w = $this->whlabel->get_sku($txval);
-						    if(isset($w['features']))
-						    {
-							    $features = explode('-',trim($w['features'],'-'));
-							    foreach ($features as $val)
-		        			    {
-								    $t = $this->typeclass->read($val);
-								    if(isset($t['spare']))
-								    {
-									    if(stripos($t['spare'],'|') !== false)
-									    {
-										    $t['spare'] = explode('|',trim($t['spare'],'|'));
-										    $t['spare'] = $t['spare'][0];
-									    }
-									    $skupx[$t['classid']] = $t['spare'];
-								    }
-							    }
-							    $skupx = implode("-",$skupx);
-							    $skupx = str_replace('- ','-',trim($skupx,'-'));
-							    $skupx = str_replace(array('--------','-------','------','-----','----','---','--'),'-',$skupx);
-							    $wcsku .= $skupx.',';
-								$wcquantity .= $ztquantity[$txk].',';
-						    }
-						    else
-						    {
-						        continue;
-						    }
+						$productNames = '';
+						$parameters = array();
+						$skus = '';
+						$quantity = '';
+						$thislink = '';
+						foreach($v['line_items'] as $key=>$val)
+						{
+							$productNames .= ($key > 0)?','.$val['name']:$val['name'];
+							$skus .= ($key > 0)?','.$val['sku']:$val['sku'];
+							$quantity .= floor($val['quantity']).';';
+						}
+						if(stripos($v['gateway'],'shopify_') !== false)
+						{
+							$pay = 'shopifypay';
 						}
-						if($wcsku == '')
+						else if(stripos($v['gateway'],'paypal') !== false)
 						{
-							continue;
+							$pay = 'paypal_express';
+						}
+						else if(stripos($v['gateway'],'gift_card') !== false)
+						{
+							$pay = 'gift_card';
+						}
+						else if(stripos($v['gateway'],'shop_cash') !== false)
+						{
+							$pay = 'shop_cash';
 						}
 						else
 						{
-						    $skus = rtrim($wcsku,',');
-						    $quantity = rtrim($wcquantity,',');
+							$pay = $v['gateway'];
 						}
-					}
-					$authorid = '';
-					$wjauthorid = '';
-					$sourcecontentid = '';
-					$link = '';
-					if($shop['tweak'] !='' && stripos($v['referring_site'],'author_id') !== false)
-					{
-						$geturl = explode('&',$v['referring_site']);
-						foreach ($geturl as $hqid)
-		        		{
-							if(stripos($hqid,'author_id') !== false)
+						$khbz = '';
+						if(!isset($v['shipping_address']['country_code']))
+						{
+							$v['shipping_address'] = $v['billing_address'];
+							$khbz = '客户自提订单; ';
+						}
+						$shipping_address = $v['shipping_address']['address2'].' '.$v['shipping_address']['address1'] . ',' . $v['shipping_address']['city'] . ',' . $v['shipping_address']['province'] . ',' . $v['shipping_address']['zip'] . ',' . $v['shipping_address']['country_code'] . ',' . $v['shipping_address']['phone'];
+						@$billing_address = $v['billing_address']['address2'].' '.$v['billing_address']['address1'] . ',' . $v['billing_address']['city'] . ',' . $v['billing_address']['province'] . ',' . $v['billing_address']['zip'] . ',' . $v['billing_address']['country_code'] . ',' . $v['billing_address']['phone'];
+						$created_at = explode('T',$v['created_at']);
+						$created_at_hi = explode('-',$created_at[1]);
+						$created_at = $created_at[0].' '.$created_at_hi[0];
+						$paypal = '';
+						$d = $this->authorization($shop,$v['id']);
+						if($d['g'] == 1)
+						{
+							$paypal = $d['d'];
+						}
+						if($name == 'baddiebeautyshop')
+						{
+							$wcsku = '';
+							$wcquantity = '';
+							$ztsku = explode(',',rtrim($skus,','));
+							$ztquantity = explode(';',rtrim($quantity,';'));
+							foreach ($ztsku as $txk=>$txval)
 							{
-								$wjauthorid = str_replace('author_id=','',$hqid);
+								$skupx = array(13=>'',22=>'',8=>'',15=>'',18=>'','100'=>'',33=>'',34=>'',35=>'',7=>'','dc'=>'','c'=>'',14=>'',12=>'',25=>'',26=>'',27=>'',10=>'',6=>'',9=>'',999=>'',9999=>'');
+								$w = $this->whlabel->get_sku($txval);
+								if(isset($w['features']))
+								{
+									$features = explode('-',trim($w['features'],'-'));
+									foreach ($features as $val)
+									{
+										$t = $this->typeclass->read($val);
+										if(isset($t['spare']))
+										{
+											if(stripos($t['spare'],'|') !== false)
+											{
+												$t['spare'] = explode('|',trim($t['spare'],'|'));
+												$t['spare'] = $t['spare'][0];
+											}
+											$skupx[$t['classid']] = $t['spare'];
+										}
+									}
+									$skupx = implode("-",$skupx);
+									$skupx = str_replace('- ','-',trim($skupx,'-'));
+									$skupx = str_replace(array('--------','-------','------','-----','----','---','--'),'-',$skupx);
+									$wcsku .= $skupx.',';
+									$wcquantity .= $ztquantity[$txk].',';
+								}
+								else
+								{
+									continue;
+								}
 							}
-							if(stripos($hqid,'source_content_id') !== false)
+							if($wcsku == '')
 							{
-								$sourcecontentid = str_replace('source_content_id=','',$hqid);
+								continue;
+							}
+							else
+							{
+								$skus = rtrim($wcsku,',');
+								$quantity = rtrim($wcquantity,',');
 							}
-							
 						}
-						$link = str_replace($shop['thurl'],$shop['url'],$v['referring_site']);
-					}
-					else if($shop['tweak'] !='' && stripos($v['landing_site'],'author_id') !== false)
-					{
-						$geturl = explode('&',$v['landing_site']);
-						foreach ($geturl as $hqid)
-		        		{
-							if(stripos($hqid,'author_id') !== false)
+						$authorid = '';
+						$wjauthorid = '';
+						$sourcecontentid = '';
+						$link = '';
+						if($shop['tweak'] !='' && stripos($v['referring_site'],'author_id') !== false)
+						{
+							$geturl = explode('&',$v['referring_site']);
+							foreach ($geturl as $hqid)
 							{
-								$wjauthorid = str_replace('author_id=','',$hqid);
+								if(stripos($hqid,'author_id') !== false)
+								{
+									$wjauthorid = str_replace('author_id=','',$hqid);
+								}
+								if(stripos($hqid,'source_content_id') !== false)
+								{
+									$sourcecontentid = str_replace('source_content_id=','',$hqid);
+								}
+								
 							}
-							if(stripos($hqid,'source_content_id') !== false)
+							$link = str_replace($shop['thurl'],$shop['url'],$v['referring_site']);
+						}
+						else if($shop['tweak'] !='' && stripos($v['landing_site'],'author_id') !== false)
+						{
+							$geturl = explode('&',$v['landing_site']);
+							foreach ($geturl as $hqid)
 							{
-								$sourcecontentid = str_replace('source_content_id=','',$hqid);
+								if(stripos($hqid,'author_id') !== false)
+								{
+									$wjauthorid = str_replace('author_id=','',$hqid);
+								}
+								if(stripos($hqid,'source_content_id') !== false)
+								{
+									$sourcecontentid = str_replace('source_content_id=','',$hqid);
+								}
+								
 							}
-							
+							$link = $shop['url'].$v['landing_site'];
 						}
-						$link = $shop['url'].$v['landing_site'];
-					}
-					if($link != '')
-					{
-						$authorid = $this->authorid($link,$shop['tweak']);
+						if($link != '')
+						{
+							$authorid = $this->authorid($link,$shop['tweak']);
+						}
+						$thatDayOrder[] = array(
+						'order_id' => $v['order_number'],//订单号
+						'product_name' => $productNames,//产品标题
+						'purchased_on' => strtotime($created_at),//订单时间
+						'name' => $v['shipping_address']['name'],//收货人
+						'bill_to_name' => $v['billing_address']['name'],//账单人名称
+						'ship_to_name' => $v['shipping_address']['name'],//收货人名称
+						'shipping_address' => $shipping_address,
+						'billing_address' => $billing_address,
+						'country' => $v['shipping_address']['country_code'],//收货国家二字码
+						'region' => $v['shipping_address']['province_code'],//收货省/州
+						'city' => $v['shipping_address']['city'],//收货城市
+						'street' => $v['shipping_address']['address2'].' '.$v['shipping_address']['address1'],//收货地址
+						'telephone' => $v['shipping_address']['phone'],//收货人手机
+						'postcode' => $v['shipping_address']['zip'],//收货人邮政编码
+						'email' => $v['customer']['email'],//收货人邮箱
+						'global_currency_code' => $v['currency'],//币种
+						'base_grand_total' => $v['total_price'],//应收金额
+						'grand_total' => $v['total_price_set']['shop_money']['amount'],//币种支付金额
+						'isstatus' => 'processing',//$v['order_status'],//默认processing待发货状态
+						'isparameter' => implode(';',$parameters),
+						'sku' => $skus,
+						'order_quantity' => $quantity,
+						'order_comment' => $khbz.addslashes($v['note']),//客户备注
+						'pay' => $pay,
+						'paypal_num' => $paypal,
+						'insurance' => 0,
+						'paypal_protection_eligibility' => '',
+						'shippingmethod'=>'',
+						'link'=>$link,//产品链接
+						'shopify'=>$v['id'],
+						'authorid'=>$authorid,
+						'wjauthorid'=>$wjauthorid,
+						'sourcecontentid'=>$sourcecontentid
+						);
 					}
-			    	$thatDayOrder[] = array(
-			    	'order_id' => $v['order_number'],//订单号
-			    	'product_name' => $productNames,//产品标题
-			    	'purchased_on' => strtotime($created_at),//订单时间
-			    	'name' => $v['shipping_address']['name'],//收货人
-			    	'bill_to_name' => $v['billing_address']['name'],//账单人名称
-			    	'ship_to_name' => $v['shipping_address']['name'],//收货人名称
-			    	'shipping_address' => $shipping_address,
-			    	'billing_address' => $billing_address,
-			    	'country' => $v['shipping_address']['country_code'],//收货国家二字码
-			    	'region' => $v['shipping_address']['province_code'],//收货省/州
-			    	'city' => $v['shipping_address']['city'],//收货城市
-			    	'street' => $v['shipping_address']['address2'].' '.$v['shipping_address']['address1'],//收货地址
-			    	'telephone' => $v['shipping_address']['phone'],//收货人手机
-			    	'postcode' => $v['shipping_address']['zip'],//收货人邮政编码
-			    	'email' => $v['customer']['email'],//收货人邮箱
-			    	'global_currency_code' => $v['currency'],//币种
-			    	'base_grand_total' => $v['total_price'],//应收金额
-			    	'grand_total' => $v['total_price_set']['shop_money']['amount'],//币种支付金额
-			    	'isstatus' => 'processing',//$v['order_status'],//默认processing待发货状态
-			    	'isparameter' => implode(';',$parameters),
-			    	'sku' => $skus,
-			    	'order_quantity' => $quantity,
-			    	'order_comment' => $khbz.addslashes($v['note']),//客户备注
-					'pay' => $pay,
-					'paypal_num' => $paypal,
-					'insurance' => 0,
-			    	'paypal_protection_eligibility' => '',
-			    	'shippingmethod'=>'',
-			    	'link'=>$link,//产品链接
-					'shopify'=>$v['id'],
-					'authorid'=>$authorid,
-					'wjauthorid'=>$wjauthorid,
-					'sourcecontentid'=>$sourcecontentid
-					);
+					return array_reverse($thatDayOrder);
 				}
-				return array_reverse($thatDayOrder);
 			}
+			
 		}
 		else if($name == '123')
 		{
@@ -485,31 +494,52 @@ function __construct(){
 	}
 	public function authorization($shop,$shopifyid)//shopify获取交易号
     {
-		$shopifyid = $shopifyid;
-		$url = 'https://'.$shop['shopname'].'.myshopify.com/admin/api/2022-10/orders/'.$shopifyid.'/transactions.json';
-        	$headerA[] = "X-Shopify-Access-Token: ".$shop['token'];
-        	$ch = curl_init();
-        	curl_setopt($ch, CURLOPT_URL, $url);
-        	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
-        	curl_setopt($ch, CURLOPT_HTTPHEADER, $headerA);
-        	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
-        	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
-        	$res = curl_exec($ch);
-			$headerA = curl_getinfo($ch);
-			$a = json_decode($res,true);
-			if(!isset($a['transactions']))
-			{
-				return array('g'=>0);exit;
-			}
-			$a['transactions'] = array_reverse($a['transactions']);
-			if(isset($a['transactions'][0]['authorization']))
-			{
-				return array('g'=>1,'d'=>$a['transactions'][0]['authorization']);
-			}
-			else
-			{
-				return array('g'=>0);
-			}
+		if($shop['name'] == 'yolissahair'){
+			$shopname = 'xxu7p0-3q';
+		}
+		$post = [];
+		$post['shopify_pay'] = [
+			"url"=> 'https://'.$shopname.'.myshopify.com/admin/api/2022-10/orders/'.$shopifyid.'/transactions.json',
+			"token"=>"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",
+		];
+		$ch = curl_init();
+		curl_setopt($ch,CURLOPT_URL,'https://edm.alipearl.net/soapapi.php');
+		curl_setopt($ch, CURLOPT_POST, 1);
+		curl_setopt($ch, CURLOPT_HEADER, 0);
+		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
+		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
+		curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
+		curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
+		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+		curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,1800000);
+		$res = curl_exec($ch);
+		curl_close($ch);
+		$a = json_decode($res,true);
+
+		// $shopifyid = $shopifyid;
+		// $url = 'https://'.$shop['shopname'].'.myshopify.com/admin/api/2022-10/orders/'.$shopifyid.'/transactions.json';
+        // 	$headerA[] = "X-Shopify-Access-Token: ".$shop['token'];
+        // 	$ch = curl_init();
+        // 	curl_setopt($ch, CURLOPT_URL, $url);
+        // 	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+        // 	curl_setopt($ch, CURLOPT_HTTPHEADER, $headerA);
+        // 	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
+        // 	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
+        // 	$res = curl_exec($ch);
+		// 	$headerA = curl_getinfo($ch)
+		if(!isset($a['transactions']))
+		{
+			return array('g'=>0);exit;
+		}
+		$a['transactions'] = array_reverse($a['transactions']);
+		if(isset($a['transactions'][0]['authorization']))
+		{
+			return array('g'=>1,'d'=>$a['transactions'][0]['authorization']);
+		}
+		else
+		{
+			return array('g'=>0);
+		}
 	}
 	
 	public function su_curl($data,$url,$header=array(),$date_type='json',$timeout=300,$httptype="POST",$userpwd='')