|
|
@@ -2,13 +2,21 @@
|
|
|
|
|
|
namespace console\controllers;
|
|
|
|
|
|
+use biz\ghs\classes\GhsClass;
|
|
|
use biz\item\classes\ItemClass;
|
|
|
use biz\item\classes\ItemClassClass;
|
|
|
use biz\item\classes\PtItemClass;
|
|
|
use biz\item\classes\PtItemClassClass;
|
|
|
use biz\item\classes\UnitClass;
|
|
|
+use biz\sj\classes\SjClass;
|
|
|
+use bizGhs\custom\classes\CustomClass;
|
|
|
use bizGhs\item\services\ItemService;
|
|
|
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\stringUtil;
|
|
|
use common\components\util;
|
|
|
use yii\console\Controller;
|
|
|
@@ -21,6 +29,8 @@ use bizGhs\product\classes\ProductClass;
|
|
|
class ItemController extends Controller
|
|
|
{
|
|
|
|
|
|
+ public $sjId, $shopId, $sj;
|
|
|
+
|
|
|
//花材初始化 ./yii item/init
|
|
|
public function actionInit()
|
|
|
{
|
|
|
@@ -230,4 +240,240 @@ class ItemController extends Controller
|
|
|
ItemService::initItem($sjId, $id);
|
|
|
}
|
|
|
|
|
|
+ //供应商初始化 ./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');
|
|
|
+ $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();
|
|
|
+ }
|
|
|
+
|
|
|
+ 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');
|
|
|
+
|
|
|
+ $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' => ApplyClass::FROM_GHS]);
|
|
|
+ if (!empty($has)) {
|
|
|
+ echo "{$mobile} 名称已经存在 \n";
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $has = ApplyClass::getByCondition(['mobile' => $mobile, 'style' => ApplyClass::FROM_GHS]);
|
|
|
+ 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";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|