$newMainId], null, '*'); if (!empty($list)) { echo '已经有花材了'; exit(); } $classList = ItemClassClass::getAllByCondition(['mainId' => $oldMainId], null, '*', null, true); if (empty($classList)) { echo '没有找到老店的分类'; exit(); } $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); try { foreach ($classList as $class) { $oldId = $class->id ?? 0; $cover = $class->cover ?? ''; $name = $class->name ?? ''; $inTurn = $class->inTurn ?? 0; $isDefault = $class->isDefault ?? 0; $newClass = [ 'mainId' => $newMainId, 'cover' => $cover, 'name' => $name, 'inTurn' => $inTurn, 'isDefault' => $isDefault, ]; $newRespond = ItemClassClass::add($newClass, true); $newClassId = $newRespond->id ?? 0; $oldItemList = ItemClass::getAllByCondition(['classId' => $oldId, 'delStatus' => 0], null, '*'); foreach ($oldItemList as $oldItem) { $oldItemId = $oldItem['id']; unset($oldItem['id']); $oldItem['classId'] = $newClassId; $oldItem['stock'] = 0; $oldItem['onStock'] = 0; $oldItem['status'] = 2; $oldItem['mainId'] = $newMainId; $oldItem['sjId'] = 0; $oldItem['shopId'] = 0; $new = ItemClass::add($oldItem, true); if (isset($oldItem['variety']) && $oldItem['variety'] == 1) { $xjList = XjClass::getAllByCondition(['itemId' => $oldItemId], null, '*'); if (!empty($xjList)) { foreach ($xjList as $oneXj) { unset($oneXj['id']); unset($oneXj['sjId']); unset($oneXj['shopId']); unset($oneXj['mainId']); unset($oneXj['itemId']); unset($oneXj['ptItemId']); unset($oneXj['addTime']); unset($oneXj['updateTime']); $oneXj['mainId'] = $newMainId; $oneXj['itemId'] = $new->id ?? 0; $oneXj['ptItemId'] = $new->itemId ?? 0; XjClass::add($oneXj); } } } } } $transaction->commit(); } catch (\Exception $e) { $transaction->rollBack(); $msg = $e->getMessage(); echo "报错了:" . $msg; } } public function actionCQ() { $itemList = ItemClass::getAllByCondition(['mainId' => 14128], null, '*', null, true); if (!empty($itemList)) { foreach ($itemList as $item) { $classId = $item->classId; if (!empty($classId)) { $class = ItemClassClass::getById($classId, true); if ($class->mainId != 14128) { echo $item->name . "\n"; } } } } } //花材修改分类同步 ssh 20240523 public function actionModifyItemClassSync() { ini_set('memory_limit', '5045M'); set_time_limit(0); $productIdCachedKey = 'item_class_modify_sync'; $idList = []; while ($count = Yii::$app->redis->executeCommand('LLEN', [$productIdCachedKey])) { if (count($idList) > 20) { break; } $currentId = Yii::$app->redis->executeCommand('RPOP', [$productIdCachedKey]); $idList[] = $currentId; } if (empty($idList)) { return false; } $list = ProductClass::getAllByCondition(['id' => ['in', $idList]], null, '*', null, true); if (!empty($list)) { foreach ($list as $info) { $classId = $info->classId ?? 0; $productId = $info->id ?? 0; OrderItemClass::updateByCondition(['productId' => $productId], ['classId' => $classId]); \bizHd\order\classes\OrderItemClass::updateByCondition(['itemId' => $productId], ['classId' => $classId]); PurchaseOrderItemClass::updateByCondition(['productId' => $productId], ['classId' => $classId]); //noticeUtil::push("productId:{$productId} classId:{$classId}", '15280215347'); } } //noticeUtil::push(implode(',', $idList) . ' 这些花材ID修改了分类,已同步到订单和采购单', '15280215347'); } //【重要】将花材的分类id同步到批发销售单、批发采购单和零售销售单【小丽优先】 public function actionSyncClass() { ini_set('memory_limit', '5120M'); set_time_limit(0); $itemList = ItemClass::getAllByCondition(['mainId' => 10975], null, '*', null, true); if (empty($itemList)) { util::stop('没有找到花材'); } foreach ($itemList as $item) { $classId = $item->classId ?? 0; $productId = $item->id ?? 0; if (!empty($classId) && !empty($productId)) { OrderItemClass::updateByCondition(['productId' => $productId], ['classId' => $classId]); \bizHd\order\classes\OrderItemClass::updateByCondition(['itemId' => $productId], ['classId' => $classId]); PurchaseOrderItemClass::updateByCondition(['productId' => $productId], ['classId' => $classId]); } } echo "ok\n"; } //包装纸丝带同步 ssh 20230525 public function actionPaperSync() { $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); try { $oldItemList = ItemClass::getAllByCondition(['classId' => 26013, 'delStatus' => 0], null, '*'); foreach ($oldItemList as $oldItem) { unset($oldItem['id']); $oldItem['classId'] = 31106; $oldItem['stock'] = 0; $oldItem['status'] = 2; $oldItem['mainId'] = 4553; $oldItem['sjId'] = 16936; $oldItem['shopId'] = 0; ItemClass::add($oldItem); } $transaction->commit(); } catch (\Exception $e) { $transaction->rollBack(); $msg = $e->getMessage(); echo "报错了:" . $msg; } } public function actionWaste() { ini_set('memory_limit', '2045M'); set_time_limit(0); $list = StockWastageOrderClass::getAllByCondition(['id>' => 0], null, '*', null, true); if (!empty($list)) { foreach ($list as $order) { $orderSn = $order->orderSn ?? ''; $itemList = StockWastageOrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true); $totalCost = 0; if (!empty($itemList)) { foreach ($itemList as $v) { $num = $v->itemNum ?? 0; $itemCost = $v->itemCost ?? 0; $totalCost = bcadd($totalCost, bcmul($num, $itemCost, 2), 2); } } $order->cost = $totalCost; $order->save(); } } } public function actionWastage() { ini_set('memory_limit', '2045M'); set_time_limit(0); $list = StockWastageOrderClass::getAllByCondition(['id>' => 0], null, '*', null, true); if (!empty($list)) { foreach ($list as $order) { $orderSn = $order->orderSn ?? ''; $itemList = StockWastageOrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true); $totalPrice = 0; if (!empty($itemList)) { foreach ($itemList as $v) { $num = $v->itemNum ?? 0; $itemPrice = $v->itemPrice ?? 0; $totalPrice = bcadd($totalPrice, bcmul($num, $itemPrice, 2), 2); } } $order->price = $totalPrice; $order->save(); } } } //小向花材迁移 ssh 20250215 public function actionXx() { if (getenv('YII_ENV') == 'production') { $newMainId = 49988; $oldMainId = 23390; } else { $newMainId = 762; $oldMainId = 644; util::stop('已取消'); } $list = ItemClass::getAllByCondition(['mainId' => $newMainId], null, '*'); if (!empty($list)) { echo '已经有花材了'; exit(); } $classList = ItemClassClass::getAllByCondition(['mainId' => $oldMainId], null, '*', null, true); if (empty($classList)) { echo '没有找到目标门店的分类'; exit(); } $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); try { foreach ($classList as $class) { $oldId = $class->id ?? 0; $cover = $class->cover ?? ''; $name = $class->name ?? ''; $inTurn = $class->inTurn ?? 0; $isDefault = $class->isDefault ?? 0; $newClass = [ 'mainId' => $newMainId, 'cover' => $cover, 'name' => $name, 'inTurn' => $inTurn, 'isDefault' => $isDefault, ]; $newRespond = ItemClassClass::add($newClass, true); $newClassId = $newRespond->id ?? 0; $oldItemList = ItemClass::getAllByCondition(['classId' => $oldId, 'delStatus' => 0], null, '*'); foreach ($oldItemList as $oldItem) { $oldItemId = $oldItem['id']; unset($oldItem['id']); $oldItem['classId'] = $newClassId; $oldItem['stock'] = 0; $oldItem['status'] = 2; $oldItem['mainId'] = $newMainId; $oldItem['sjId'] = 0; $oldItem['shopId'] = 0; $new = ItemClass::add($oldItem, true); if (isset($oldItem['variety']) && $oldItem['variety'] == 1) { $xjList = XjClass::getAllByCondition(['itemId' => $oldItemId], null, '*'); if (!empty($xjList)) { foreach ($xjList as $oneXj) { unset($oneXj['id']); unset($oneXj['sjId']); unset($oneXj['shopId']); unset($oneXj['mainId']); unset($oneXj['itemId']); unset($oneXj['ptItemId']); unset($oneXj['addTime']); unset($oneXj['updateTime']); $oneXj['mainId'] = $newMainId; $oneXj['itemId'] = $new->id ?? 0; $oneXj['ptItemId'] = $new->itemId ?? 0; XjClass::add($oneXj); } } } } } $transaction->commit(); } catch (\Exception $e) { $transaction->rollBack(); $msg = $e->getMessage(); echo "报错了:" . $msg; } } //花材反向更新 ./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/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"; } } } } //更新特价 ssh 20230630 public function actionDiscount() { ini_set('memory_limit', '2045M'); set_time_limit(0); $list = ItemClass::getAllByCondition(['discountPrice>' => 0,], null, '*', null, true); if (!empty($list)) { foreach ($list as $item) { $discountPrice = $item->discountPrice ?? 0; $skMore = $item->skMore ?? 0; $addPrice = $item->addPrice ?? 0; $diff = bcsub($skMore, $addPrice, 2); if ($diff > 0) { $item->skDiscountPrice = bcadd($discountPrice, $diff, 2); } else { $item->skDiscountPrice = $discountPrice; } $item->hjDiscountPrice = $discountPrice; $item->save(); } } } }