示例#1
0
 /**
  * 导入单品Excel数据
  **/
 public function actionaddsuborder()
 {
     $ret = array('status' => 0, 'msg' => '', 'err_data' => array());
     $brandid = isset($_SESSION['brandid']) ? $_SESSION['brandid'] : 0;
     $description = "";
     //备注内容
     $ordername = "";
     //订单号
     $orderid = 0;
     $type = '';
     $uploadfile = '';
     try {
         if (Yii::app()->request->getParam('description')) {
             $description = Yii::app()->request->getParam('description');
             //备注
         }
         if (Yii::app()->request->getParam('ordername')) {
             $ordername = Yii::app()->request->getParam('ordername');
             //订单名
         }
         if (Yii::app()->request->getParam('orderid')) {
             $orderid = Yii::app()->request->getParam('orderid');
             //订单id
         }
         if (Yii::app()->request->getParam('type')) {
             $type = Yii::app()->request->getParam('type');
             //表格类型
         }
         //验证该订单是否上传过图片,如果传过禁止修改
         if ($orderid > 0 && !empty($ordername)) {
             $array = array('orderid' => $orderid);
             $clothesorderclass = new clothesorderclass();
             $orderclothes = $clothesorderclass->select_Single_clothes($brandid, $array);
             if (!empty($orderclothes)) {
                 throw new Exception('不可对该订单做操作');
             }
         }
         //echo $orderid."-----".$ordername."-----".$description;
         //exit();
         //获取上传的文件名
         $file = $_FILES['inputExcel']['name'];
         $file = md5($file) . '.xls';
         if (!empty($file)) {
             //上传到服务器上的临时文件名
             $filetempname = $_FILES['inputExcel']['tmp_name'];
             //自己设置的上传文件存放路径
             $filePath = 'uploads/saveexcel/';
             $uploadfile = $filePath . $file;
             //上传后的文件名地址
             //如果上传文件成功,就执行导入excel操作
             spl_autoload_unregister(array('YiiBase', 'autoload'));
             //取消YII自动加载
             require_once 'protected/extensions/PHPExcel.php';
             require_once 'protected/extensions/PHPExcel/IOFactory.php';
             require_once 'protected/extensions/PHPExcel/Reader/Excel5.php';
             spl_autoload_register(array('YiiBase', 'autoload'));
             // Enable Yii autoloader
             //move_uploaded_file() 函数将上传的文件移动到新位置。若成功,则返回 true,否则返回 false。
             $uploadfile = iconv("utf-8", "gb2312", $uploadfile);
             $result = move_uploaded_file($filetempname, $uploadfile);
             //假如上传到当前目录下
             if (!$result) {
                 throw new Exception('文件上传失败!');
             }
             $objReader = PHPExcel_IOFactory::createReader('Excel5');
             //use excel2007 for 2007 format
             $objPHPExcel = $objReader->load($uploadfile);
             $sheet = $objPHPExcel->getSheet(0);
             $highestRow = $sheet->getHighestRow();
             // 取得总行数
             $highestColumn = $sheet->getHighestColumn();
             // 取得总列数
             $srow = 2;
             //起始行
             $str = "";
             $brandnumber_array = array();
             $brandnumber_str = "";
             $code_array = array();
             //序号
             $code_str = "";
             $category_str = "";
             $category_array = array();
             //循环读取excel文件,读取一条,插入一条
             for ($j = 2; $j <= $highestRow; $j++) {
                 for ($k = 'A'; $k <= $highestColumn; $k++) {
                     $str .= $objPHPExcel->getSheet()->getCell("{$k}{$j}")->getValue() . '\\';
                     //读取单元格
                     if ($k == 'A') {
                         $brandnumber_str .= trim($objPHPExcel->getSheet()->getCell("{$k}{$j}")->getValue()) . '\\';
                     } else {
                         if ($k == 'B') {
                             $category_str .= trim($objPHPExcel->getSheet()->getCell("{$k}{$j}")->getValue()) . '\\';
                         } else {
                             if ($k == 'C') {
                                 $code_str .= trim($objPHPExcel->getSheet()->getCell("{$k}{$j}")->getValue()) . '\\';
                             } else {
                                 break;
                             }
                         }
                     }
                 }
             }
             $brandnumber_array1 = array();
             $brandnumber_array1 = explode("\\", $brandnumber_str);
             //款色号数组
             $code_array1 = array();
             $code_array1 = explode("\\", $code_str);
             //款色号数组
             foreach ($brandnumber_array1 as $value) {
                 if (!empty($value)) {
                     $brandnumber_array[] = $value;
                 }
             }
             foreach ($code_array1 as $key => $value) {
                 if (!empty($brandnumber_array1[$key])) {
                     $code_array[] = $value;
                 }
             }
             $category_array = explode("\\", $category_str);
             //防止重复字段
             $u_strs = array_unique($brandnumber_array);
             if (count($brandnumber_array) > count($u_strs)) {
                 @unlink($_SERVER['DOCUMENT_ROOT'] . '/' . $uploadfile);
                 throw new Exception('本表中款色号不能有重复');
             }
             if ($type != 'style') {
                 //图片管理 导表分类管理
                 $brandnumber_string = implode("','", $brandnumber_array);
                 $clothesorderclass = new clothesorderclass();
                 $clothesorder_obj = $clothesorderclass->selsectordernamebybrandnumber($brandid, $brandnumber_string, $orderid);
                 $ret['repeat_data'] = $clothesorder_obj;
                 $repeat_array = array();
                 foreach ($clothesorder_obj as $clothesorder_obj_value) {
                     $repeat_array[] = $clothesorder_obj_value['brandnumber'];
                     //将重复的加入数组
                 }
                 $brandnumber_array = array_diff($brandnumber_array, $repeat_array);
                 //将重复的款号删除
                 if (count($brandnumber_array) == 0) {
                     $ret['status'] = 1;
                     @unlink($_SERVER['DOCUMENT_ROOT'] . '/' . $uploadfile);
                     throw new Exception('订单内容与之前订单重复');
                 }
                 if (count($brandnumber_array) > 0 && count($repeat_array) > 0) {
                     $ret['msg'] = "订单已创建,发现有其他订单下的款色号";
                 }
                 if ($orderid > 0 && !empty($ordername)) {
                     $orderclass = new orderclass();
                     //删除该订单下的所有款号
                     $orderclass->deletebrandnumberbyorderid($brandid, $orderid);
                     $orderdir = $_SERVER['DOCUMENT_ROOT'] . '/orderlist/' . $ordername;
                     $orderclass->delFolder($orderdir);
                 }
             }
         }
         if ($type == 'style') {
             //图片管理 导表分类管理
             if (count(array_filter($brandnumber_array)) == 0) {
                 throw new Exception('款号为空!');
             }
             if (count(array_filter($category_array)) == 0) {
                 throw new Exception('分类为空!');
             }
             //获取品牌 SKU 规则
             $brand_ret = Brand::brandSelectById($_SESSION['brandid']);
             if (count($brand_ret) == 0) {
                 throw new Exception('');
             }
             $code_start = $brand_ret[0]['code_start'];
             $code_end = $brand_ret[0]['code_end'];
             //将SKC转为SKU
             $brandnumber_SKU_arr = array();
             $category_SKU_array = array();
             foreach ($brandnumber_array as $key => $value) {
                 $brandnumber_SKU = $value;
                 if ($code_start != 0 || $code_end != 0) {
                     //设置了款号规则后 按规则提取款号
                     $brandnumber_SKU = $this->SKCToSKU($code_start, $code_end, $value);
                 }
                 $brandnumber_key = array_search($brandnumber_SKU, $brandnumber_SKU_arr);
                 if ($brandnumber_key !== false) {
                     $category_SKU_array[$brandnumber_key] = $category_array[$key];
                 } else {
                     $brandnumber_SKU_arr[] = $brandnumber_SKU;
                     $category_SKU_array[] = $category_array[$key];
                 }
             }
             //获取品牌的所有分类
             $brandcategory = new brandcategoryclass();
             $category_ret = $brandcategory->select_category($brandid);
             if (count($category_ret) == 0) {
                 throw new Exception('品牌暂未设置分类!');
             }
             //提取已有款号到数组
             $category_data = array();
             foreach ($category_ret as $value) {
                 $category_data[$value->name] = $value->id;
             }
             $category_array_copy = array_unique($category_SKU_array);
             //清除重复的分类
             $category_array_copy = array_filter($category_array_copy);
             //清除空元素
             //不存在的分类
             $no_category = Comm::array_diff_fast($category_array_copy, array_keys($category_data));
             $no_category = array_values($no_category);
             //获取款号对应衣服
             $clothesorder = new clothesorderclass();
             $clothes_ret = $clothesorder->select_all_clothes($brandid, -1, array('sku' => $brandnumber_SKU_arr));
             $no_brandnumber = array();
             //不存在的款号
             foreach ($clothes_ret['data'] as $value) {
                 $brandnumber_copy_str = $value['sku'];
                 $no_brandnumber[] = $brandnumber_copy_str;
                 $brandnumber_key = array_search($brandnumber_copy_str, $brandnumber_SKU_arr);
                 if (isset($category_data[$category_SKU_array[$brandnumber_key]])) {
                     //当款号设置分类 已存在时才可以设置
                     $clothesorder->update_clothes($value['id'], array('brandcategoryid' => $category_data[$category_SKU_array[$brandnumber_key]]));
                 }
             }
             $ret['no_brandnumber'] = Comm::array_diff_fast($brandnumber_SKU_arr, $no_brandnumber);
             $ret['no_brandnumber'] = array_values($ret['no_brandnumber']);
             $ret['no_category'] = $no_category;
         } else {
             $user36 = $this->createBrandCode($brandid);
             //品牌号生成5位编码
             $order_id = 0;
             if (empty($ordername) && empty($orderid)) {
                 $ordername = '';
                 $orderobj = Yii::app()->db->createCommand()->select('ordername')->from('erp_order')->where("brandid={$brandid}")->andwhere("ordername<>' '")->order("id desc")->queryRow();
                 if (!empty($orderobj)) {
                     $ordername = $orderobj['ordername'];
                     $ordername = substr($ordername, 5) + 1;
                     if (strlen($ordername) == 1) {
                         $ordername = $user36 . "00" . $ordername;
                     } else {
                         if (strlen($ordername) == 2) {
                             $ordername = $user36 . "0" . $ordername;
                         }
                     }
                 } else {
                     $ordername = $user36 . '001';
                 }
                 $erp_order = new erp_order();
                 $erp_order->ordername = $ordername;
                 $erp_order->description = $description;
                 $erp_order->barcodecount = count($brandnumber_array);
                 $erp_order->addtime = date("Y-m-d H:i:s");
                 $erp_order->brandid = $brandid;
                 $count = $erp_order->insert();
                 $order_id = Yii::app()->db->getLastInsertID();
                 if ($count > 0) {
                 } else {
                     throw new Exception('插入数据失败');
                 }
             } else {
                 $order_id = $orderid;
                 $update_arr = array();
                 $update_arr['description'] = $description;
                 if (!empty($file)) {
                     $update_arr['barcodecount'] = count($brandnumber_array);
                 }
                 if ($orderid > 0) {
                     erp_order::model()->updateAll($update_arr, 'id=:textx', array(':textx' => $orderid));
                 }
             }
             $url = 'uploads/saveexcel/' . $brandid . '_' . $ordername . '.xls';
             rename($_SERVER['DOCUMENT_ROOT'] . "/" . $uploadfile, $_SERVER['DOCUMENT_ROOT'] . "/" . $url);
             //将款号插入到订单对应的款号表中
             foreach ($brandnumber_array as $key => $value) {
                 $erp_brandnumber_order = new erp_brandnumber_order();
                 $erp_brandnumber_order->brandnumber = $value;
                 $erp_brandnumber_order->orderid = $order_id;
                 $erp_brandnumber_order->brandid = $brandid;
                 $erp_brandnumber_order->snumber = $code_array[$key];
                 $count = $erp_brandnumber_order->insert();
             }
             $orderclass = new orderclass();
             $orderclass->create_order($brandid, $ordername, $brandnumber_array);
             //$bb=orderclass::create_order($ordername,$brandnumber_array);
         }
         $ret['status'] = 1;
     } catch (Exception $e) {
         $ret['msg'] = $e->getMessage();
     }
     if (count($ret['err_data']) == 0) {
         $ret['err_data'] = '';
     }
     echo '<script> parent.setsubclothes(' . json_encode($ret) . ');</script>';
 }
示例#2
0
 /**
  * 修改单品的主次关系
  * @parm clothes 衣服数组 键值对 键为衣服id 值为衣服即将修改的状态
  * @parm touchid 触摸屏id
  **/
 static function upmainClothes($clothes, $touchid)
 {
     $ret = array('status' => 0, 'msg' => '');
     try {
         $Display_status_num = 11;
         //上架显示状态
         $no_Display_status_num = 10;
         //上架不显示状态
         $out_status_num = 8;
         //下架状态
         $ForSale_status_num = 12;
         //待售状态
         $Logic_clothes_arr = array();
         //逻辑整理后的单品
         $Logic_clothes_arr[$Display_status_num] = array();
         $Logic_clothes_arr[$no_Display_status_num] = array();
         $Logic_clothes_arr[$out_status_num] = array();
         $Logic_clothes_arr[$ForSale_status_num] = array();
         $Related_arr = self::beuRelatedSelectByClothesid(implode(',', array_keys($clothes)));
         // 获取衣服的不同色
         //将衣服对应的每组不同色提取出来
         $Related_clothes_arr = array();
         //单品的不同色数组
         $Different_clothes_arr = array();
         //单品的不同穿数组
         $clothesid_arr = array();
         //衣服数组 用于查询其状态
         $clothes_status_arr = array();
         //衣服数组 用于查询其状态
         foreach ($Related_arr as $value) {
             $c_arr = array();
             foreach ($value as $v_key => $v_value) {
                 if ($v_key == 'id' || empty($v_value)) {
                     continue;
                 }
                 $c_arr[] = $v_value;
                 $clothesid_arr[] = $v_value;
             }
             if (count($c_arr) > 0) {
                 $Related_clothes_arr[] = $c_arr;
             }
         }
         $no_Related_arr = Comm::array_diff_fast(array_keys($clothes), $clothesid_arr);
         //获取还未做个SKU关联的单品
         $clothesid_arr = array_merge($clothesid_arr, $no_Related_arr);
         //将还未做个SKU关联的单品拼接进衣服数组做状态查询
         foreach ($no_Related_arr as $value) {
             $Related_clothes_arr[] = array($value);
         }
         //查询单品的状态
         $t_clothes_ret = self::getTouchclothesinfo('clothesid,status', array('touchid' => '=' . $touchid, 'clothesid' => ' in(' . implode(',', $clothesid_arr) . ')'));
         if ($t_clothes_ret['status'] == 0) {
             throw new Exception($t_clothes_ret['msg']);
         }
         //获取单品的不同穿
         $Different_arr = self::beuDifferentSelectByClothesid(implode(',', $clothesid_arr));
         $Diff_clothes = array();
         foreach ($Different_arr as $value) {
             $c_arr = array();
             foreach ($value as $v_key => $v_value) {
                 if ($v_key == 'id' || empty($v_value)) {
                     continue;
                 }
                 $c_arr[] = $v_value;
                 $Diff_clothes[] = $v_value;
             }
             if (count($c_arr) > 0) {
                 $Different_clothes_arr[] = $c_arr;
             }
         }
         $no_Different_arr = Comm::array_diff_fast(array_keys($clothes), $Diff_clothes);
         //获取还未做个SKC关联的单品
         foreach ($no_Different_arr as $value) {
             $Different_clothes_arr[] = array($value);
         }
         //将单品的状态进行归总
         foreach ($t_clothes_ret['data'] as $value) {
             $clothes_status_arr[$value['clothesid']] = $value['status'];
             if (in_array($value['clothesid'], $no_Different_arr)) {
                 //当前单品属于未做SKU关联的单品
                 $Logic_clothes_arr[$clothes[$value['clothesid']]][] = $value['clothesid'];
             }
         }
         //逻辑判断单品修改后的状态
         foreach ($Related_clothes_arr as $value) {
             $current_status = array();
             //当前SKU状态数组
             $up_status = array();
             //SKU修改状态数组
             $Display_clothes = array();
             //逻辑判断后的显示单品
             $no_Display_clothes = array();
             //逻辑判断后的不显示单品
             $out_clothes = array();
             //逻辑判断后的下架单品
             $ForSale_clothes = array();
             //逻辑判断后的待售单品
             $up_Related_clothes = array();
             //需要修改的SKU单品数组
             foreach ($value as $v_key => $v_value) {
                 $s_str = $clothes_status_arr[$v_value];
                 //获取单品的当前状态
                 if (!isset($current_status[$s_str])) {
                     //当前SKU状态数组 不存在此状态时对其添加
                     $current_status[$s_str] = array();
                 }
                 $current_status[$s_str][] = $v_value;
                 //将单品添加到 SKU状态数组对应状态下
                 $up_Related_clothes[] = $v_value;
                 if (isset($clothes[$v_value])) {
                     $up_s_str = $clothes[$v_value];
                     //获取单品修改状态
                     if (!isset($up_status[$up_s_str])) {
                         //SKU修改状态数组 不存在此状态时对其添加
                         $up_status[$up_s_str] = array();
                     }
                     $up_status[$up_s_str][] = $v_value;
                     //将单品添加到 SKU修改状态数组对应状态下
                 }
             }
             //显示单品
             if (isset($up_status[$Display_status_num])) {
                 //SKU修改状态数组里存在显示单品时 就将其第一个设为显示 其他设为不显示
                 $Display_clothes[0] = $up_status[$Display_status_num][0];
             }
             //下架单品
             if (isset($up_status[$out_status_num])) {
                 //SKU修改状态数组存在下架状态
                 $out_clothes = $up_status[$out_status_num];
             }
             //待售单品
             if (isset($up_status[$ForSale_status_num])) {
                 //SKU修改状态数组存在待售状态
                 $ForSale_clothes = $up_status[$ForSale_status_num];
             }
             if (isset($current_status[$Display_status_num])) {
                 //当前SKU状态数组存在显示单品时
                 $current_status[$Display_status_num] = Comm::array_diff_fast($current_status[$Display_status_num], array_merge($out_clothes, $ForSale_clothes));
                 //去除原有上架修改为下架或待售的单品
                 if (count($current_status[$Display_status_num]) > 0) {
                     if (isset($up_status[$Display_status_num])) {
                         $Display_intersect = Comm::array_intersect_fast($current_status[$Display_status_num], $up_status[$Display_status_num]);
                         //获取其同时存在显示状态的单品
                         if (count($Display_intersect) > 0) {
                             //SKU修改状态数组需要显示单品与当前SKU状态数组显示单品存在相同单品 就显示其第一个相同单品
                             $Display_clothes[0] = $Display_intersect[0];
                         }
                     } else {
                         $Display_clothes[0] = $current_status[$Display_status_num][0];
                     }
                 }
             }
             //获取未设置的单品
             $dirr_Related = Comm::array_diff_fast($value, array_merge($ForSale_clothes, $out_clothes, $Display_clothes));
             foreach ($dirr_Related as $dirr_value) {
                 if (isset($up_status[$Display_status_num]) && in_array($dirr_value, $up_status[$Display_status_num])) {
                     //暂未设置单品需设为上架,因已有单品上架 所以修改为上架不显示
                     $no_Display_clothes[] = $dirr_value;
                 } else {
                     if ($clothes_status_arr[$dirr_value] == $Display_status_num) {
                         $no_Display_clothes[] = $dirr_value;
                     } else {
                         if ($clothes_status_arr[$dirr_value] == $ForSale_status_num) {
                             $ForSale_clothes[] = $dirr_value;
                         } else {
                             if ($clothes_status_arr[$dirr_value] == $out_status_num) {
                                 $out_clothes[] = $dirr_value;
                             } else {
                                 $no_Display_clothes[] = $dirr_value;
                             }
                         }
                     }
                 }
             }
             //将SKU的下单品的按状态加入到数组
             $Logic_clothes_arr[$Display_status_num] = array_merge($Logic_clothes_arr[$Display_status_num], $Display_clothes);
             $Logic_clothes_arr[$no_Display_status_num] = array_merge($Logic_clothes_arr[$no_Display_status_num], $no_Display_clothes);
             $Logic_clothes_arr[$out_status_num] = array_merge($Logic_clothes_arr[$out_status_num], $out_clothes);
             $Logic_clothes_arr[$ForSale_status_num] = array_merge($Logic_clothes_arr[$ForSale_status_num], $ForSale_clothes);
         }
         //去除单品状态数组里的重复值和空值
         foreach ($Logic_clothes_arr as $key => $value) {
             $value = array_filter($value);
             $Logic_clothes_arr[$key] = array_unique($value);
         }
         //单品不同穿状态设置
         foreach ($Different_clothes_arr as $value) {
             $out_c_arr = Comm::array_intersect_fast($value, $Logic_clothes_arr[$out_status_num]);
             //获取当前不同穿关联 是否做下架处理
             $ForSale_c_arr = Comm::array_intersect_fast($value, $Logic_clothes_arr[$ForSale_status_num]);
             //获取当前不同穿关联 是否做待售处理
             if (count($out_c_arr) > 0) {
                 //当前单品状态为下架 那么其不同穿关联就做下架
                 $Logic_clothes_arr[$out_status_num] = array_merge($Logic_clothes_arr[$out_status_num], $value);
             } else {
                 if (count($ForSale_c_arr) > 0) {
                     //当前单品状态为待售 那么其不同穿关联就做待售
                     $Logic_clothes_arr[$ForSale_status_num] = array_merge($Logic_clothes_arr[$ForSale_status_num], $value);
                 } else {
                     $Display_c_arr = Comm::array_intersect_fast($value, $Logic_clothes_arr[$Display_status_num]);
                     //获取当前不同穿关联 是否做显示处理
                     $Display_clothes_id_arr = array();
                     $Display_c_arr_len = count($Display_c_arr);
                     if ($Display_c_arr_len > 0) {
                         $Display_clothes_id_arr = array(array_shift($Display_c_arr));
                     }
                     //当前单品状态为上架不显示
                     $no_Display_c_arr = Comm::array_diff_fast($value, array_merge($Display_clothes_id_arr, $Logic_clothes_arr[$ForSale_status_num], $Logic_clothes_arr[$out_status_num], $Logic_clothes_arr[$Display_status_num]));
                     $Logic_clothes_arr[$no_Display_status_num] = array_merge($Logic_clothes_arr[$no_Display_status_num], $no_Display_c_arr);
                     //上架单品数量大于1时 只取第一个做上架 其他做上架不显示
                     if ($Display_c_arr_len > 1) {
                         $Logic_clothes_arr[$Display_status_num] = Comm::array_diff_fast($Logic_clothes_arr[$Display_status_num], $Display_c_arr);
                     }
                 }
             }
             foreach ($Related_clothes_arr as $R_key => $R_value) {
                 if (count(Comm::array_intersect_fast($value, $R_value)) > 0) {
                     $R_value = array_merge($R_value, $value);
                     $R_value = array_unique($R_value);
                     $Related_clothes_arr[$R_key] = $R_value;
                     break;
                 }
             }
         }
         //检查关联单品 是否有上架单品存在
         /*foreach($Related_clothes_arr as $value){
         			$no_Display_v_arr=Comm::array_intersect_fast($value,$Logic_clothes_arr[$no_Display_status_num]);
         			$Display_v_arr=Comm::array_intersect_fast($value,$Logic_clothes_arr[$Display_status_num]);
         			if(count($Display_v_arr)==0 && count($no_Display_v_arr)>0){//当前关联单品组合是没有上架单品 将不显示单品提取一个改为上架
         				$s_vlue=array_shift($Display_c_arr);
         				$Logic_clothes_arr[$Display_status_num][]=$s_vlue;
         				unset($Logic_clothes_arr[$no_Display_status_num][array_search($s_vlue,$Logic_clothes_arr[$no_Display_status_num])]);
         			}
         		}
         		print_r($Logic_clothes_arr);*/
         //修改单品的状态
         foreach ($Logic_clothes_arr as $key => $value) {
             $value = array_filter($value);
             $value = array_unique($value);
             if (count($value) == 0) {
                 continue;
             }
             Yii::app()->db->createCommand('update touch_clothes set status=' . $key . ' where clothesid in(' . implode(',', $value) . ') and touchid=' . $touchid)->execute();
         }
         $ret['status'] = 1;
     } catch (Exception $e) {
         $ret['msg'] = $e->getMessage();
     }
     return $ret;
 }