Ver Fonte

添加用户导入代发客户数据

lvhao há 3 meses atrás
pai
commit
b4fc91cdb8
2 ficheiros alterados com 97 adições e 22 exclusões
  1. 50 22
      core/CoreApp/controllers/Customer.php
  2. 47 0
      template/erp/customer.html

+ 50 - 22
core/CoreApp/controllers/Customer.php

@@ -61,6 +61,11 @@ class Customer extends Start_Controller {
         {
              $this->_temuexcel();
         }
+		else if($arg == 'daifakehuexcel')
+        {
+             $this->_daifakehuexcel();
+        }
+
 		else if($arg == 'excel')//下载excel
         {
              $this->_excel();
@@ -1795,6 +1800,7 @@ class Customer extends Start_Controller {
 				$ddpost['type'] = 17;
 				$this->fullorder->insert($ddpost);
 			}
+			
 			if ($this->db->trans_status() === FALSE)
             {
 				$this->db->trans_commit();
@@ -1825,8 +1831,24 @@ class Customer extends Start_Controller {
     }
 	
 	//代发客户导入
-	public function _dafakehuexcel()
+	public function _daifakehuexcel()
 	{
+		$shopid = 0;
+		$user = $this->user->get_api($_SESSION['api']);
+		if($user)
+		{
+		    $users = explode('|',trim($user['shop'],'|'));
+			if(count($users) == 1){
+				$shopid = $users[0];
+			}else{
+				echo json_encode(array('msg'=>"此账号不能用于该功能!",'success'=>true));exit;
+			}
+		}
+		
+		if(empty($shopid)){
+			echo json_encode(array('msg'=>"系统无法识别店铺!",'success'=>true));exit;
+		}
+		
 		$dir = '/data/excel/'.date('Ymd',time()).'/';
 		$config['upload_path'] = '.'.$dir ;
 		$config['file_name'] = date('Ymd_His_',time()).rand(1000,9999);
@@ -1937,27 +1959,32 @@ class Customer extends Start_Controller {
 		    $this->db->trans_begin();
 		    foreach ($list as $key=>$value)
 		    {
-				$addtess = ($value['15']!='--'?$value['15'].' ':'').($value['14']!='--'?$value['14'].' ':'').$value['13'];
+				$addtess = $value[7].$value[6];
 				$addtess = str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$addtess);
-				$repeat = $this->customer->find_all('phone = "'.$value[11].'" and address = "'.($value['15']!='--'?$value['15'].' ':'').($value['14']!='--'?$value['14'].' ':'').$value['13'].'" and shop = 19');//判断电话地址
-				$sku = $value['8'];
-				$je = (isset($value['28']))?$value['28']:0;
-				$value['29'] = str_replace('/','-',$value['29']);
-				$dtime = strtotime($value['29']);
-				$post['name'] = ($value['10'] && $value['10'] != 'NULL')?str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$value['10']):'';
-				$post['email'] = $value['12'];
-				if($value['20'] != '')
+				$repeat = $this->customer->find_all('phone = "'.$value[4].'" and address = "'.$addtess.'" and shop = '.$shopid);//判断电话地址
+				$sku = $value['2'];
+				$je = (isset($value['12']))?$value['12']:0;
+				if(!empty($value[13])){
+					$value['13'] = str_replace('/','-',$value['13']);
+					$dtime = strtotime($value['13']);
+				}else{
+					$dtime = time();
+				}
+				
+				$post['name'] = (!empty($value[3]))?str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$value['3']):'';
+				$post['email'] = $value['5'];
+				if($value['11'] != '')
 				{
-					$country = $this->country->get_ename(str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$value['20']));
+					$country = $this->country->get_ename(str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$value['11']));
 					$post['country'] = $country['id'];
 				}
 				$post['level'] = 4;
-				$post['phone'] = $value['11']?$value['11']:'';
-				$post['province'] = $value['18']?$value['18']:'';
-				$post['city'] = $value['17']?$value['17']:'';
+				$post['phone'] = $value['4']?$value['4']:'';
+				$post['province'] = $value['9']?$value['9']:'';
+				$post['city'] = $value['8']?$value['8']:'';
 				$post['address'] = $addtess;
-				$post['zipcode'] = $value['19']?$value['19']:'';
-				$post['shop'] = 19;
+				$post['zipcode'] = $value['10']?$value['10']:'';
+				$post['shop'] = $shopid;
 				$post['source'] = 2;
 				$post['type'] = 1;
 				$post['count'] = '';
@@ -1989,8 +2016,8 @@ class Customer extends Start_Controller {
 				}
 				$sbsku = trim($sbsku,'-');
 				$time = time();
-				$shop = $this->shop->read(19);
-				$ddpost['orderremarks'] = isset($value['30'])?$value['30']:'';
+				$shop = $this->shop->read($shopid);
+				$ddpost['orderremarks'] = '';
 				$ddpost['shop'] = $shop['id'];//店铺ID
 				$ddpost['user'] = $shop['shopuser'];//店铺负责人
 				$orderid = 0;
@@ -1998,16 +2025,15 @@ class Customer extends Start_Controller {
 				$ddpost['product'] = '';//产品名称
 				$ddpost['link'] = '';//产品链接
 				$ddpost['issku'] = $sku;
-				$ddpost['quantity'] = rtrim($value['3'],';');
+				$ddpost['quantity'] = rtrim($value['1'],';');
 				$ddpost['clientremarks'] = '';//客户备注
-				$ddpost['paypal'] = '';//交易号
 				$ddpost['guarantee'] = '';//卖家保障
 				$ddpost['parameter'] = '';//属性
 				$ddpost['shippingmethod'] = '';//用户选择快递方式及运费金额
 				$ddpost['source'] = 2;//订单类型
 				$ddpost['type'] = 1;//发货仓库
 				$ddpost['capital'] = 3;//资金支付状况,全部付款
-				$num = $this->fullorder->find_count('gtime = "'.date('Ymd',$dtime).'" and shop = 19');
+				$num = $this->fullorder->find_count('gtime = "'.date('Ymd',$dtime).'" and shop = '.$shopid);
 				$ddpost['number'] = $shop['shortname'].'-'.substr(date('ymd',$dtime),1).'-'.(substr(strval($num+1+1000),1,3));//编号
 				$ddpost['orderinfo'] =  preg_replace('/[^0-9]/', '', $value['0']);//订单号
 				$d = $this->fullorder->get_orderinfo($ddpost['orderinfo']);
@@ -2016,6 +2042,7 @@ class Customer extends Start_Controller {
 					$i++;
 					continue;
 				}
+				$ddpost['paypal'] = $ddpost['orderinfo'];//交易号
 				$ddpost['insurance'] = 0;//运输保险费用
 				$ddpost['baddress'] = '';
 				$ddpost['saddress'] = '';
@@ -2052,7 +2079,8 @@ class Customer extends Start_Controller {
 				$ddpost['whlabel'] = $matching['whlabel'];
 				$ddpost['slpx'] = $matching['wcslpx'];
 				$ddpost['state'] = 207;
-				$ddpost['type'] = 17;
+				$ddpost['type'] = 13;
+
 				$this->fullorder->insert($ddpost);
 			}
 			if ($this->db->trans_status() === FALSE)

+ 47 - 0
template/erp/customer.html

@@ -59,6 +59,7 @@
 <a href="javascript:void(0);" class="indexexcel">按条件导出</a>
 {/if}
 <a href="javascript:void(0);" id="temuexcel">导入TEMU客户</a>
+<a href="javascript:void(0);" id="daifakehuexcel">导入代发客户</a>
 </div>
 <table class="datatitle data" border="0" style="border-collapse:collapse;">
 <tr>
@@ -147,6 +148,52 @@ $(document).ready(function() {
 
 
 
+    //var button = $("#temuexcel"), interval;
+    var fileType = "pic", fileNum = "one";
+    new AjaxUpload($("#daifakehuexcel"), {
+        action: dataurl+"/daifakehuexcel",
+        name: "userfile",
+        onSubmit: function(file, ext) {
+            if (fileType == "pic") {
+                if (ext && /^(xls|xlsx)$/.test(ext)) {
+                    this.setData({
+                        info: "文件类型为xls"
+                    });
+                } else {
+                $(".ts p").html("上传的文件类型不正确");
+                $(".ts").fadeIn();
+                setTimeout('$(".ts").fadeOut()', 700);
+				return false;
+                }
+            }
+			$(".express p:eq(0)").html("<i class='fa fa-2x fa-cog fa-spin'></i> &nbsp; 正在处理中,请稍后...");
+			$(".express p:eq(1)").html("");
+            $(".express").show();
+            if (fileNum == "one") {
+                this.disable();
+            }
+        },
+        onComplete: function(file, response) {
+            eval("var obj=" + response);
+            if (obj.success) {
+				$(".express").hide();
+               $(".express p:eq(0)").html("<i class='fa fa-2x fa-check-square-o'></i> &nbsp; "+obj.msg);
+			   $(".express p:eq(1)").html("<font class='sx'>确 定</font><font class='sx'>取 消</font>");
+            $(".express").show();
+            } else {
+				$(".express").hide();
+                $(".ts p").html(obj.msg);
+                $(".ts").fadeIn();
+                setTimeout('$(".ts").fadeOut()', 700);
+				return false;
+            }
+            window.clearInterval(interval);
+            this.enable();
+        }
+    });
+
+
+
 var button = $("#excel"), interval;
     var fileType = "pic", fileNum = "one";
     new AjaxUpload(button, {