| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480 |
- <?php
- namespace console\controllers;
- use biz\ghs\classes\GhsClass;
- use biz\item\classes\PtItemClass;
- use biz\item\classes\PtItemClassClass;
- use biz\sj\classes\SjClass;
- use bizGhs\custom\classes\CustomClass;
- use biz\shop\classes\ShopClass;
- use bizHd\saas\classes\ApplyClass;
- use bizHd\saas\models\Apply;
- use bizHd\saas\services\ApplyService;
- use common\components\dict;
- use common\components\imgUtil;
- use common\components\pushNotice;
- use common\components\stringUtil;
- use yii\console\Controller;
- use Yii;
- use bizGhs\product\classes\ProductClass;
- /**
- * 花材初始化 ssh 2021.2.18
- */
- class ItemController extends Controller
- {
- public $sjId, $shopId, $sj;
- //拼音更新 ./yii item/update-py
- public function actionUpdatePy()
- {
- $list = ProductClass::getAllByCondition([], null, '*', null, true);
- if (!empty($list)) {
- foreach ($list as $product) {
- $name = $product->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');
- }
- }
|