name; $py = stringUtil::py($name); $product->py = $py; $product->save(); echo $name.' '.$py."\n"; } } $item = PtItemClass::getAllByCondition([], null, '*', null, true); if (!empty($item)) { foreach ($item as $it) { $name = $it->name; if (!empty($name)) { $py = stringUtil::py($name); $it->py = $py; $it->save(); echo $name.' '.$py."\n"; } } } } //花材反向更新 ./yii item/reverse-update public function actionReverseUpdate() { $shopId = 10; if (getenv('YII_ENV') != 'production') { $shopId = 36225; } $list = ProductClass::getAllByCondition(['shopId' => $shopId], null, '*', null, true); if (empty($list)) { return false; } foreach ($list as $cKey => $product) { $ptItemId = $product->itemId ?? 0; $ptItem = PtItemClass::getById($ptItemId, true); if (empty($ptItem)) { continue; } $ptItem->name = $product->name ?? ''; $ptItem->py = $product->py ?? ''; $ptItem->cover = $product->cover ?? ''; $ptItem->ratio = $product->ratio ?? 1; $ptItem->shelfLife = $product->shelfLife ?? 7; $ptItem->weight = $product->weight ?? 0.1; $ptItem->stockWarning = $product->stockWarning ?? 5;; $ptItem->cost = $product->cost ?? 1; $ptItem->addPrice = 5; $ptItem->bigUnit = $product->bigUnit; $ptItem->smallUnit = $product->smallUnit; $ptItem->bigUnitId = $product->bigUnitId; $ptItem->smallUnitId = $product->smallUnitId; $ptItem->save(); echo $product->id . " " . $product->name . " 已同步\n"; } } //花材初始化 ./yii item/init public function actionInit() { } //命令: ./yii item/sync name,cover 同步name 和cover //同步item, ptItem更新,同步到 ghsItem, ghsProduct, 同步字段(name,alias,py,cover,ratio,cover等) public function actionSync($field) { $allFiled = ['name', 'alias', 'cover', 'py', 'ratio', 'weight', 'bigUnit', 'smallUnit', 'bigUnitId', 'smallUnitId', 'stockWarning']; $fields = explode(",", $field); $syncFields = array_intersect($allFiled, $fields); if (empty($syncFields)) { echo "参数不支持"; die; } $item = PtItemClass::getAllList("id", ""); $itemIds = []; foreach ($item as $v) { $itemIds[] = $v['id']; } if (!empty($itemIds)) { foreach ($itemIds as $v) { $itemInfo = PtItemClass::getById($v); $data = []; foreach ($syncFields as $f) { $data[$f] = $itemInfo[$f]; } ProductClass::updateByCondition(['itemId' => $v], $data); \bizGhs\item\classes\ItemClass::updateByCondition(['itemId' => $v], $data); } } echo "done"; } //平台花材初始化导入 lqh 2021-05-08 //命令: ./yii item/init-pt-item public function actionInitPtItem($clear = false) { $phpExcelFile = Yii::getAlias("@vendor/phpoffice/phpexcel/"); require_once($phpExcelFile . 'Classes/PHPExcel/IOFactory.php');//查询接口 $dir = Yii::$app->basePath; $filename = $dir . '/item.xls'; $fileType = \PHPExcel_IOFactory::identify($filename); //文件名自动判断文件类型 $excelReader = \PHPExcel_IOFactory::createReader($fileType); $objPHPExcel = $excelReader->load($filename);//$file_url即Excel文件的路径 $sheet = $objPHPExcel->getSheet(0);//获取第一个工作表 $highestRow = $sheet->getHighestRow();//取得总行数 $highestColumn = $sheet->getHighestColumn(); //取得总列数 $classData = []; $itemData = []; $classIdMap = []; for ($j = 2; $j <= $highestRow; $j++) { $str = ''; for ($k = 'A'; $k <= $highestColumn; $k++) { $str .= $objPHPExcel->getActiveSheet()->getCell("$k$j")->getValue() . '\\'; } //explode:函数把字符串分割为数组。 $string = explode("\\", $str); array_pop($string); $itemName = $string[0] ?? ''; //花材名称 $className = $string[1] ?? ''; //分类名称 $weight = $string[2] ?? 0; //重量 kg $bigUnit = $string[3] ?? ''; //大单位名称 $smallUnit = $string[4] ?? ''; //小单位名称 $ratio = $string[5] ?? 0; //比例 $cost = $string[6] ?? 0;//成本价 $addPrice = $string[7] ?? 0; //加价 $stockWarning = $string[8] ?? 0; $alias = $string[9] ?? ''; $cover = $string[10] ?? ''; $inTurn = $string[11] ?? 0; if ($itemName) { $py = stringUtil::py($itemName); $item = [ 'name' => $itemName, 'alias' => $alias, 'py' => $py, 'cover' => $cover, 'classId' => 0, 'ratio' => $ratio, 'weight' => $weight, 'stockWarning' => $stockWarning, 'cost' => $cost, 'addPrice' => $addPrice, 'bigUnit' => $bigUnit, 'smallUnit' => $smallUnit, 'inTurn' => $inTurn, ]; $itemData[$className][] = $item; $classData[] = $className; } } $classData = array_unique($classData); //写入class if ($clear) { //清空数据 Yii::$app->db->createCommand()->truncateTable('xhPtItemClass')->execute(); Yii::$app->db->createCommand()->truncateTable('xhPtItem')->execute(); } foreach ($classData as $v) { $addClass = PtItemClassClass::add(['name' => $v, 'inTurn' => 0, 'group' => 0]); $classIdMap[$v] = $addClass['id']; } $insertItemData = []; foreach ($itemData as $k => $v) { $classId = $classIdMap[$k] ?? 0; if ($classId) { foreach ($v as $i) { $i['classId'] = $classId; $insertItemData[] = $i; } } } if (!empty($insertItemData)) { PtItemClass::batchAdd($insertItemData); } echo "done"; } //供应商初始化 ./yii item/gys ./yii.bat item/gys public function actionGys() { $phpExcelFile = Yii::getAlias("@vendor/phpoffice/phpexcel/"); require_once($phpExcelFile . 'Classes/PHPExcel/IOFactory.php');//查询接口 $dir = Yii::$app->basePath; $filename = $dir . '/gys.xls'; $fileType = \PHPExcel_IOFactory::identify($filename); //文件名自动判断文件类型 $excelReader = \PHPExcel_IOFactory::createReader($fileType); $objPHPExcel = $excelReader->load($filename);//$file_url即Excel文件的路径 $sheet = $objPHPExcel->getSheet(0);//获取第一个工作表 $highestRow = $sheet->getHighestRow();//取得总行数 $highestColumn = $sheet->getHighestColumn(); //取得总列数 $changeData = []; for ($j = 2; $j <= $highestRow; $j++) { $str = ''; for ($k = 'A'; $k <= $highestColumn; $k++) { $str .= $objPHPExcel->getActiveSheet()->getCell("$k$j")->getValue() . '\\'; } //explode:函数把字符串分割为数组。 $string = explode("\\", $str); array_pop($string); array_push($changeData, $string); } if (!empty($changeData)) { $mobileList = array_values(array_column($changeData, 1)); $ptStyle = dict::getDict('ptStyle', 'kmGhs'); Yii::$app->params['ptStyle'] = $ptStyle; $has = Apply::find()->where(['in', 'mobile', $mobileList])->andWhere(['style' => $ptStyle])->all(); if (!empty($has)) { echo "这些已经添加过了,请先删除:\n"; foreach ($has as $item) { echo $item->name . ' ' . $item->mobile . "\n"; } exit(); } if (getenv('YII_ENV') == 'production') { $this->sjId = 12367; $this->shopId = 10; } else { $this->sjId = 12615; $this->shopId = 36119; } foreach ($changeData as $currentKey => $currentData) { $mobile = $currentData[1] ?? ''; $name = $currentData[0] ?? ''; $address = $currentData[2] ?? ''; if (stringUtil::isMobile($mobile) == false) { echo "请填写正确的手机号 \n"; continue; } if (empty($name)) { echo "{$mobile} 名称不能为空 \n"; continue; } if (stringUtil::getWordNum($name) > 8) { echo "{$mobile} 名称不能超过8个汉字 \n"; continue; } $has = ApplyClass::getByCondition(['name' => $name, 'style' => SjClass::STYLE_KM_SUPPLIER]); if (!empty($has)) { echo "{$mobile} 名称已经存在 \n"; continue; } $has = ApplyClass::getByCondition(['mobile' => $mobile, 'style' => SjClass::STYLE_KM_SUPPLIER]); if (!empty($has)) { echo "{$mobile} 手机号已经添加过 \n"; continue; } $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); try { $sjId = $this->sjId; $shopId = $this->shopId; $sjName = $this->sj->name ?? ''; $applyData = [ 'name' => $name, 'licenseNo' => $mobile, 'certType' => ApplyClass::CERT_TYPE_MOBILE, 'mobile' => $mobile, 'introSjId' => $sjId, 'introSjName' => $sjName, 'introShopId' => $shopId, 'introStyle' => SjClass::STYLE_SUPPLIER, 'from' => ApplyClass::FROM_GHS, 'style' => dict::getDict('ptStyle', 'kmGhs'), 'address' => $address, 'status' => ApplyClass::STATUS_PASS, 'replace' => 1,//1表示供应商添加的客户或供应商 ]; $apply = ApplyService::replaceKmGhs($applyData); $id = $apply['id'] ?? 0; $respond = ApplyService::pass($id); $currentShop = $respond['shop'] ?? []; $sj = $respond['sj'] ?? []; $currentSjId = $sj['id'] ?? 0; $currentShopId = $currentShop->id ?? 0; ApplyClass::updateById($id, ['sjId' => $currentSjId, 'shopId' => $currentShopId]); if (empty($currentShopId)) { echo "{$mobile} 供应商添加失败 \n "; continue; } GhsClass::build($currentShopId, $shopId, 1); $transaction->commit(); echo "{$mobile} 供应商添加成功!\n"; } catch (\Exception $exception) { $transaction->rollBack(); echo "{$mobile} 供应商添加失败,原因:" . $exception->getMessage() . "\n"; } } } } //客户初始化 ./yii item/custom ./yii.bat item/custom public function actionCustom() { $phpExcelFile = Yii::getAlias("@vendor/phpoffice/phpexcel/"); require_once($phpExcelFile . 'Classes/PHPExcel/IOFactory.php');//查询接口 $dir = Yii::$app->basePath; $filename = $dir . '/custom.xls'; $fileType = \PHPExcel_IOFactory::identify($filename); //文件名自动判断文件类型 $excelReader = \PHPExcel_IOFactory::createReader($fileType); $objPHPExcel = $excelReader->load($filename);//$file_url即Excel文件的路径 $sheet = $objPHPExcel->getSheet(0);//获取第一个工作表 $highestRow = $sheet->getHighestRow();//取得总行数 $highestColumn = $sheet->getHighestColumn(); //取得总列数 $changeData = []; for ($j = 2; $j <= $highestRow; $j++) { $str = ''; for ($k = 'A'; $k <= $highestColumn; $k++) { $str .= $objPHPExcel->getActiveSheet()->getCell("$k$j")->getValue() . '\\'; } //explode:函数把字符串分割为数组。 $string = explode("\\", $str); array_pop($string); array_push($changeData, $string); } if (!empty($changeData)) { $mobileList = array_values(array_column($changeData, 1)); $ptStyle = dict::getDict('ptStyle', 'hd'); Yii::$app->params['ptStyle'] = $ptStyle; $has = Apply::find()->where(['in', 'mobile', $mobileList])->andWhere(['style' => $ptStyle])->all(); if (!empty($has)) { echo "这些已经添加过了,请先删除:\n"; foreach ($has as $item) { echo $item->name . ' ' . $item->mobile . "\n"; } exit(); } if (getenv('YII_ENV') == 'production') { $this->sjId = 12367; $this->shopId = 10; } else { $this->sjId = 12615; $this->shopId = 36119; } $shop = ShopClass::getById($this->shopId, true); $sj = SjClass::getById($this->sjId, true); $this->sj = $sj; foreach ($changeData as $currentKey => $currentData) { $mobile = $currentData[1] ?? ''; $name = $currentData[0] ?? ''; $address = $currentData[2] ?? ''; if (empty($name)) { echo "{$mobile} 名称不能为空 \n"; continue; } if (stringUtil::getWordNum($name) > 8) { echo "{$mobile} 名称不能超过8个汉字 \n"; continue; } if (stringUtil::isMobile($mobile) == false) { echo "{$mobile} 手机号错误 \n"; continue; } $has = SjClass::getByCondition(['name' => $name, 'style' => SjClass::STYLE_RETAIL]); if (!empty($has)) { echo "{$mobile} 名称已经存在 \n"; continue; } $has = ApplyClass::getByCondition(['mobile' => $mobile, 'style' => SjClass::STYLE_RETAIL]); if (!empty($has)) { echo "{$mobile} 手机号已经添加过 \n"; continue; } $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); try { $sjId = $this->sjId; $shopId = $this->shopId; $sjName = $this->sj->name ?? ''; $city = $shop->city ?? ''; $dist = $shop->dist ?? ''; $applyData = [ 'name' => $name, 'licenseNo' => $mobile, 'certType' => ApplyClass::CERT_TYPE_MOBILE, 'mobile' => $mobile, 'introSjId' => $sjId, 'introSjName' => $sjName, 'introShopId' => $shopId, 'introStyle' => SjClass::STYLE_SUPPLIER, 'from' => ApplyClass::FROM_GHS, 'style' => SjClass::STYLE_RETAIL, 'province' => $shop->province ?? '', 'city' => $city, 'dist' => $dist, 'address' => $address, 'status' => ApplyClass::STATUS_PASS, 'replace' => 1,//1表示供应商添加的客户 ]; $apply = ApplyService::replaceRetail($applyData); $id = $apply['id'] ?? 0; $respond = ApplyService::pass($id); $currentShop = $respond['shop'] ?? []; $sj = $respond['sj'] ?? []; $hdSjId = $sj['id'] ?? 0; $hdShopId = $currentShop->id ?? 0; ApplyClass::updateById($id, ['sjId' => $hdSjId, 'shopId' => $hdShopId]); if (empty($hdShopId)) { echo "{$mobile} 客户添加失败 \n"; continue; } $custom = CustomClass::build($this->shopId, $hdShopId); $custom['avatar'] = imgUtil::groupImg($custom['avatar']); $transaction->commit(); echo "{$mobile} 添加成功! \n"; } catch (\Exception $exception) { $transaction->rollBack(); echo "{$mobile} 添加失败,报错:" . $exception->getMessage() . "\n"; } } } } // TODO 测试用的,可删除 public function actionTestGt() { Yii::$app->params['ptStyle'] = dict::getDict('ptStyle', 'ghs'); //指定当前环境为批发商 pushNotice::gtPush('07307c3fd79969d983db648de9b3bb11', '新客户加入', '测试内容体111'); pushNotice::gtPush('114c4e00a2ccdb60080c270d14ad3705', '新客户加入', '测试内容体222'); } }