Browse Source

修改信息

lvhao 6 days ago
parent
commit
454e936148
1 changed files with 97 additions and 37 deletions
  1. 97 37
      core/CoreApp/controllers/Fullordersmt.php

+ 97 - 37
core/CoreApp/controllers/Fullordersmt.php

@@ -2354,26 +2354,27 @@ class Fullordersmt extends Start_Controller {
 	public function _merge()
 	{
 		$user = $this->user->get_api($_SESSION['api']);
-		if($user)
+		if(!$user)
 		{
-		    $fgshop = "";$sid = "";
-		    $user = explode('|',trim($user['shop'],'|'));
-			foreach ($user as $value) 
-		    {
-				$fgshop .= " shop = ".$value." or";
-				$sid .= " id = ".$value." or";
-			}
+			echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
 		}
 		$post = $this->input->post(NULL, TRUE);
-		if(isset($post['type']))  
+		if(isset($post['s']))  
 		{
-			$post = array();
-			$type = $this->input->post('type');
-			$id = $this->input->post('id');
-			$u = $this->fullordersmt->read($id);
-			$rows =  $this->fullordersmt->find_all('name = "'.$u['name'].'" and userid = "'.$u['userid'].'" and address = "'.$u['address'].'" and state = "207" and print != "3" and review = "1" and type = "'.$u['type'].'" and merge = "0" and ('.rtrim($fgshop,"or").')','*','id desc');
-			if(count($rows)>1)
+            $id_arr = $this->input->post('s');
+            $id_arr =  explode(',',trim( $id_arr,','));
+			$id_arr = array_reverse($id_arr);
+            if(!$id_arr)
+            {
+                echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
+            }
+			if(count($id_arr) < 2)
 			{
+				echo json_encode(array('msg'=>'缺少可合并单!','success'=>false));exit;
+			}
+			$post = array();
+			$u = $this->fullordersmt->read($id_arr[0]);
+			unset($id_arr[0]);
 				$this->db->trans_begin();
 				$hd = $this->fullordersmthb->get_orderinfo($u['orderinfo']);
 				if(!$hd)
@@ -2406,18 +2407,23 @@ class Fullordersmt extends Start_Controller {
 				$post['whlabel'] = $u['whlabel'];//产品对应库存码
 				
 				$merge = $u['id'];
-				$d = array($id);$order = '';
+				$d = array($u['id']);$order = '';
 				$zsl = 0;$zccsl = 0;
-				foreach ($rows as $v) 
+				foreach ($id_arr as $v) 
 		        {
-					if($v['id'] != $id && $v['shop'] = $u['shop'])
+					$v = $this->fullordersmt->read($v);
+					if($u['type'] != $v['type'])
+					{
+						echo json_encode(array('msg'=>'仓库不一致,无法合并!','success'=>false));exit;
+					}
+					if($v['shop'] = $u['shop'])
 					{
 						$hd = $this->fullordersmthb->get_orderinfo($v['orderinfo']);
 						if(!$hd)
 						{
 							$this->fullordersmthb->insert($v);
 						}
-				       $post['shouldmoney'] += $v['shouldmoney'];//购买应收金额
+				        $post['shouldmoney'] += $v['shouldmoney'];//购买应收金额
 				        $post['budget'] += $v['budget'];//预估到帐金额
 				        $post['expressmoney'] += $v['expressmoney'];//物流金额
 				        //$post['refundy'] += $v['refundy'];//补/退原额
@@ -2438,7 +2444,7 @@ class Fullordersmt extends Start_Controller {
 						$post['shipremarks'] .= $v['shipremarks'];//仓库品名
 						
 						$post['fpdata'] .= $v['fpdata'];//产品内容
-						$post['whlabel'] .= $v['whlabel'];//产品对应库存码
+						$post['whlabel'] .= ltrim($v['whlabel'],'|');//产品对应库存码
 						
 					    $d[] = $v['id'];
 						$order .= $v['orderinfo'].'('.$v['number'].')、';
@@ -2447,43 +2453,102 @@ class Fullordersmt extends Start_Controller {
 						$i = 0;
 						if($wl)//如果有那么清除所有占用
 						{
-							foreach ($wl as $v)
+							foreach ($wl as $val)
 			   			    {
-								if($v['sku'] == 'Preset' && $v['state'] == '9')
+								if($val['sku'] == 'Preset' && $val['state'] == '9')
 								{
-									$this->whlabel->remove($v['id']);//删除预设
+									$this->whlabel->remove($val['id']);//删除预设
 									$i++;
 								}
 								else
 								{
-					    			$this->whlabel->save(array('zd'=>''),$v['id']);//专属
+					    			$this->whlabel->save(array('zd'=>''),$val['id']);//专属
 									$i++;
 								}
 							}
 						}
 						$zsl += count($wl);
 						$zccsl += $i;
-					    $this->fullordersmt->save(array('merge'=>$id,'mergeid'=>1,'orderremarks'=>' 《合并信息》:'.'已合并到'.$u['orderinfo'].'('.$u['number'].')中; '.$v['orderremarks'],'shouldmoney'=>0,'print'=>1,'libraryconfirm'=>1,'shouldmoney'=>0,'budget'=>0,'whlabel'=>'','fpdata'=>'','shipremarks'=>''),$v['id']);
+					    $this->fullordersmt->save(array('merge'=>$u['id'],'mergeid'=>1,'orderremarks'=>' 《合并信息》:'.'已合并到'.$u['orderinfo'].'('.$u['number'].')中; '.$v['orderremarks'],'shouldmoney'=>0,'print'=>1,'libraryconfirm'=>1,'shouldmoney'=>0,'budget'=>0,'whlabel'=>'','fpdata'=>'','shipremarks'=>''),$v['id']);
 					}
 				}
 				//计算出单条价值
 				/**
 				if($post['zsbjz'] < 1 || $post['ts'] < 1)
 				{
-					$post['dtsbjz'] = 0;
+					//$post['dtsbjz'] = 0;
 				}
 				else
 				{
-				    $post['dtsbjz']  = $post['zsbjz']/$post['ts'];//单条申报价
+				    //$post['dtsbjz']  = $post['zsbjz']/$post['ts'];//单条申报价
 				}
 				**/
 				$post['orderremarks'] = '  《合并信息》:由'.rtrim($order,'、').'合并而来; '.$u['orderremarks'];;
 				
-				$post['merge'] = $id;
+				$post['merge'] = $u['id'];
 				
 				//$post['mergeid'] = 1;
-				$this->fullordersmt->save($post,$id);
-				if ($this->db->trans_status() === FALSE || $zsl != $zccsl)
+				
+				//合并重复项
+				$hbcfw = explode('|',trim($post['whlabel'],'|'));
+				$hbcff = explode(';',trim($post['fpdata'],';'));
+				$c = 0;
+				$hbw = array();
+				$hbf = array();
+				for($i=0;$i<count($hbcfw);$i++)
+				{
+					$w = explode('-',$hbcfw[$i]);
+					$f = explode('|',$hbcff[$i]);
+					if(isset($w[2]))
+					{
+					   $w2 = ($w[2]==0)?0:'';
+					}
+					else
+					{
+						$w2 = '';
+					}
+					if(!isset($hbw[$w[0].$w2]))
+					{
+						$hbw[$w[0].$w2] = $hbcfw[$i];
+						$hbf[$w[0].$w2] = $hbcff[$i];
+					}
+					else
+					{
+						$c++;
+						$cw = explode('-',$hbw[$w[0].$w2]);
+						$cf = explode('|',$hbf[$w[0].$w2]);
+						if($cw[2] != 0 && $w[2] != 0)
+						{
+							$cf[2] += $f[2];
+							$cf[9] .= '~'.$f[9];
+						    $hbf[$w[0].$w2] = implode("|",$cf);
+						    $cw[1] += $f[2];
+							$cw[2] .= '~'.$f[9];
+						    $hbw[$w[0].$w2] = implode("-",$cw);
+						}
+						else if($cw[2] == 0 && $w[2] == 0)
+						{
+						    $cf[2] += $f[2];
+						    $hbf[$w[0].$w2] = implode("|",$cf);
+						    $cw[1] += $f[2];
+						    $hbw[$w[0].$w2] = implode("-",$cw);
+						}
+						else
+						{
+							$hbw[] = $hbcfw[$i];
+						    $hbf[] = $hbcff[$i];
+						}
+					}
+				}
+				if($c > 0)
+				{
+					$post['fpdata'] = implode(";",$hbf).';';
+					$post['whlabel'] = '|'.implode("|",$hbw).'|';
+				}
+				//合并重复项结束
+							
+				$this->fullordersmt->save($post,$u['id']);
+				if ($this->db->trans_status() === FALSE)
 				{
 				    $this->db->trans_commit();
 				     echo json_encode(array('msg'=>'操作失败,请重试','success'=>false));exit;
@@ -2491,15 +2556,10 @@ class Fullordersmt extends Start_Controller {
 				else
 				{
 				    $this->db->trans_commit();
-					echo json_encode(array('msg'=>'操作成功','d'=>($d),'b'=>$id,'success'=>true));
+					echo json_encode(array('msg'=>'操作成功','d'=>($d),'b'=>$u['id'],'success'=>true));
 				}
-					
-			}
-			else
-			{
-				echo json_encode(array('msg'=>'缺少可合并单','success'=>false));exit;
-			}
 		}
+		
 	}
 	
 	public function _split()