ItemController.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  1. <?php
  2. namespace console\controllers;
  3. use biz\ghs\classes\GhsClass;
  4. use biz\item\classes\PtItemClass;
  5. use biz\item\classes\PtItemClassClass;
  6. use biz\sj\classes\SjClass;
  7. use bizGhs\custom\classes\CustomClass;
  8. use biz\shop\classes\ShopClass;
  9. use bizGhs\item\classes\ItemClass;
  10. use bizGhs\item\classes\ItemClassClass;
  11. use bizGhs\order\classes\StockWastageOrderClass;
  12. use bizGhs\order\classes\StockWastageOrderItemClass;
  13. use bizHd\saas\classes\ApplyClass;
  14. use bizHd\saas\models\Apply;
  15. use bizHd\saas\services\ApplyService;
  16. use common\components\dict;
  17. use common\components\imgUtil;
  18. use common\components\stringUtil;
  19. use common\components\util;
  20. use yii\console\Controller;
  21. use Yii;
  22. use bizGhs\product\classes\ProductClass;
  23. /**
  24. * 花材同步脚本 ssh 20230619
  25. */
  26. class ItemController extends Controller
  27. {
  28. public $sjId, $shopId, $sj;
  29. //包装纸丝带同步 ssh 20230525
  30. public function actionPaperSync()
  31. {
  32. $connection = Yii::$app->db;
  33. $transaction = $connection->beginTransaction();
  34. try {
  35. $oldItemList = ItemClass::getAllByCondition(['classId' => 26013, 'delStatus' => 0], null, '*');
  36. foreach ($oldItemList as $oldItem) {
  37. unset($oldItem['id']);
  38. $oldItem['classId'] = 31106;
  39. $oldItem['stock'] = 0;
  40. $oldItem['status'] = 2;
  41. $oldItem['mainId'] = 4553;
  42. $oldItem['sjId'] = 16936;
  43. $oldItem['shopId'] = 0;
  44. ItemClass::add($oldItem);
  45. }
  46. $transaction->commit();
  47. } catch (\Exception $e) {
  48. $transaction->rollBack();
  49. $msg = $e->getMessage();
  50. echo "报错了:" . $msg;
  51. }
  52. }
  53. public function actionWaste()
  54. {
  55. ini_set('memory_limit', '2045M');
  56. set_time_limit(0);
  57. $list = StockWastageOrderClass::getAllByCondition(['id>' => 0], null, '*', null, true);
  58. if (!empty($list)) {
  59. foreach ($list as $order) {
  60. $orderSn = $order->orderSn ?? '';
  61. $itemList = StockWastageOrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
  62. $totalCost = 0;
  63. if (!empty($itemList)) {
  64. foreach ($itemList as $v) {
  65. $num = $v->itemNum ?? 0;
  66. $itemCost = $v->itemCost ?? 0;
  67. $totalCost = bcadd($totalCost, bcmul($num, $itemCost, 2), 2);
  68. }
  69. }
  70. $order->cost = $totalCost;
  71. $order->save();
  72. }
  73. }
  74. }
  75. public function actionWastage()
  76. {
  77. ini_set('memory_limit', '2045M');
  78. set_time_limit(0);
  79. $list = StockWastageOrderClass::getAllByCondition(['id>' => 0], null, '*', null, true);
  80. if (!empty($list)) {
  81. foreach ($list as $order) {
  82. $orderSn = $order->orderSn ?? '';
  83. $itemList = StockWastageOrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
  84. $totalPrice = 0;
  85. if (!empty($itemList)) {
  86. foreach ($itemList as $v) {
  87. $num = $v->itemNum ?? 0;
  88. $itemPrice = $v->itemPrice ?? 0;
  89. $totalPrice = bcadd($totalPrice, bcmul($num, $itemPrice, 2), 2);
  90. }
  91. }
  92. $order->price = $totalPrice;
  93. $order->save();
  94. }
  95. }
  96. }
  97. //初见花季 ssh 20230223
  98. public function actionCj()
  99. {
  100. if (getenv('YII_ENV') == 'production') {
  101. $mtMainId = 7756;
  102. $ttMainId = 7615;
  103. } else {
  104. $mtMainId = 703;
  105. $ttMainId = 644;
  106. util::stop('已取消');
  107. }
  108. $list = ItemClass::getAllByCondition(['mainId' => $mtMainId], null, '*');
  109. if (!empty($list)) {
  110. echo '已经有花材了';
  111. exit();
  112. }
  113. $classList = ItemClassClass::getAllByCondition(['mainId' => $ttMainId], null, '*', null, true);
  114. if (empty($classList)) {
  115. echo '没有找到目标门店的分类';
  116. exit();
  117. }
  118. $connection = Yii::$app->db;
  119. $transaction = $connection->beginTransaction();
  120. try {
  121. foreach ($classList as $class) {
  122. $oldId = $class->id ?? 0;
  123. $cover = $class->cover ?? '';
  124. $name = $class->name ?? '';
  125. $inTurn = $class->inTurn ?? 0;
  126. $isDefault = $class->isDefault ?? 0;
  127. $newClass = [
  128. 'mainId' => $mtMainId,
  129. 'cover' => $cover,
  130. 'name' => $name,
  131. 'inTurn' => $inTurn,
  132. 'isDefault' => $isDefault,
  133. ];
  134. $newRespond = ItemClassClass::add($newClass, true);
  135. $newClassId = $newRespond->id ?? 0;
  136. $oldItemList = ItemClass::getAllByCondition(['classId' => $oldId, 'delStatus' => 0], null, '*');
  137. foreach ($oldItemList as $oldItem) {
  138. unset($oldItem['id']);
  139. $oldItem['classId'] = $newClassId;
  140. $oldItem['stock'] = 0;
  141. $oldItem['status'] = 2;
  142. $oldItem['mainId'] = $mtMainId;
  143. $oldItem['sjId'] = 16300;
  144. $oldItem['shopId'] = 0;
  145. ItemClass::add($oldItem);
  146. }
  147. }
  148. $transaction->commit();
  149. } catch (\Exception $e) {
  150. $transaction->rollBack();
  151. $msg = $e->getMessage();
  152. echo "报错了:" . $msg;
  153. }
  154. }
  155. //美天鲜花 ssh 20230223
  156. public function actionMt()
  157. {
  158. if (getenv('YII_ENV') == 'production') {
  159. $mtMainId = 3923;
  160. $ttMainId = 742;
  161. } else {
  162. $mtMainId = 703;
  163. $ttMainId = 644;
  164. }
  165. $list = ItemClass::getAllByCondition(['mainId' => $mtMainId], null, '*');
  166. if (!empty($list)) {
  167. echo '已经有花材了';
  168. exit();
  169. }
  170. $classList = ItemClassClass::getAllByCondition(['mainId' => $ttMainId], null, '*', null, true);
  171. if (empty($classList)) {
  172. echo '没有找到天天鲜花的分类';
  173. exit();
  174. }
  175. $connection = Yii::$app->db;
  176. $transaction = $connection->beginTransaction();
  177. try {
  178. foreach ($classList as $class) {
  179. $oldId = $class->id ?? 0;
  180. $cover = $class->cover ?? '';
  181. $name = $class->name ?? '';
  182. $inTurn = $class->inTurn ?? 0;
  183. $isDefault = $class->isDefault ?? 0;
  184. $newClass = [
  185. 'mainId' => $mtMainId,
  186. 'cover' => $cover,
  187. 'name' => $name,
  188. 'inTurn' => $inTurn,
  189. 'isDefault' => $isDefault,
  190. ];
  191. $newRespond = ItemClassClass::add($newClass, true);
  192. $newClassId = $newRespond->id ?? 0;
  193. $oldItemList = ItemClass::getAllByCondition(['classId' => $oldId, 'delStatus' => 0], null, '*');
  194. foreach ($oldItemList as $oldItem) {
  195. unset($oldItem['id']);
  196. $oldItem['classId'] = $newClassId;
  197. $oldItem['stock'] = 0;
  198. $oldItem['status'] = 2;
  199. $oldItem['mainId'] = $mtMainId;
  200. $oldItem['sjId'] = 16300;
  201. $oldItem['shopId'] = 0;
  202. ItemClass::add($oldItem);
  203. }
  204. }
  205. $transaction->commit();
  206. } catch (\Exception $e) {
  207. $transaction->rollBack();
  208. $msg = $e->getMessage();
  209. echo "报错了:" . $msg;
  210. }
  211. }
  212. //花材反向更新 ./yii item/reverse-update
  213. public function actionReverseUpdate()
  214. {
  215. $shopId = 10;
  216. if (getenv('YII_ENV') != 'production') {
  217. $shopId = 36225;
  218. }
  219. $list = ProductClass::getAllByCondition(['shopId' => $shopId], null, '*', null, true);
  220. if (empty($list)) {
  221. return false;
  222. }
  223. foreach ($list as $cKey => $product) {
  224. $ptItemId = $product->itemId ?? 0;
  225. $ptItem = PtItemClass::getById($ptItemId, true);
  226. if (empty($ptItem)) {
  227. continue;
  228. }
  229. $ptItem->name = $product->name ?? '';
  230. $ptItem->py = $product->py ?? '';
  231. $ptItem->cover = $product->cover ?? '';
  232. $ptItem->ratio = $product->ratio ?? 1;
  233. $ptItem->shelfLife = $product->shelfLife ?? 7;
  234. $ptItem->weight = $product->weight ?? 0.1;
  235. $ptItem->stockWarning = $product->stockWarning ?? 5;;
  236. $ptItem->cost = $product->cost ?? 1;
  237. $ptItem->addPrice = 5;
  238. $ptItem->bigUnit = $product->bigUnit;
  239. $ptItem->smallUnit = $product->smallUnit;
  240. $ptItem->bigUnitId = $product->bigUnitId;
  241. $ptItem->smallUnitId = $product->smallUnitId;
  242. $ptItem->save();
  243. echo $product->id . " " . $product->name . " 已同步\n";
  244. }
  245. }
  246. //命令: ./yii item/sync name,cover 同步name 和cover
  247. //同步item, ptItem更新,同步到 ghsItem, ghsProduct, 同步字段(name,alias,py,cover,ratio,cover等)
  248. public function actionSync($field)
  249. {
  250. $allFiled = ['name', 'alias', 'cover', 'py', 'ratio', 'weight', 'bigUnit', 'smallUnit', 'bigUnitId', 'smallUnitId', 'stockWarning'];
  251. $fields = explode(",", $field);
  252. $syncFields = array_intersect($allFiled, $fields);
  253. if (empty($syncFields)) {
  254. echo "参数不支持";
  255. die;
  256. }
  257. $item = PtItemClass::getAllList("id", "");
  258. $itemIds = [];
  259. foreach ($item as $v) {
  260. $itemIds[] = $v['id'];
  261. }
  262. if (!empty($itemIds)) {
  263. foreach ($itemIds as $v) {
  264. $itemInfo = PtItemClass::getById($v);
  265. $data = [];
  266. foreach ($syncFields as $f) {
  267. $data[$f] = $itemInfo[$f];
  268. }
  269. ProductClass::updateByCondition(['itemId' => $v], $data);
  270. \bizGhs\item\classes\ItemClass::updateByCondition(['itemId' => $v], $data);
  271. }
  272. }
  273. echo "done";
  274. }
  275. //平台花材初始化导入 lqh 2021-05-08
  276. //命令: ./yii item/init-pt-item
  277. public function actionInitPtItem($clear = false)
  278. {
  279. $phpExcelFile = Yii::getAlias("@vendor/phpoffice/phpexcel/");
  280. require_once($phpExcelFile . 'Classes/PHPExcel/IOFactory.php');//查询接口
  281. $dir = Yii::$app->basePath;
  282. $filename = $dir . '/item.xls';
  283. $fileType = \PHPExcel_IOFactory::identify($filename); //文件名自动判断文件类型
  284. $excelReader = \PHPExcel_IOFactory::createReader($fileType);
  285. $objPHPExcel = $excelReader->load($filename);//$file_url即Excel文件的路径
  286. $sheet = $objPHPExcel->getSheet(0);//获取第一个工作表
  287. $highestRow = $sheet->getHighestRow();//取得总行数
  288. $highestColumn = $sheet->getHighestColumn(); //取得总列数
  289. $classData = [];
  290. $itemData = [];
  291. $classIdMap = [];
  292. for ($j = 2; $j <= $highestRow; $j++) {
  293. $str = '';
  294. for ($k = 'A'; $k <= $highestColumn; $k++) {
  295. $str .= $objPHPExcel->getActiveSheet()->getCell("$k$j")->getValue() . '\\';
  296. }
  297. //explode:函数把字符串分割为数组。
  298. $string = explode("\\", $str);
  299. array_pop($string);
  300. $itemName = $string[0] ?? ''; //花材名称
  301. $className = $string[1] ?? ''; //分类名称
  302. $weight = $string[2] ?? 0; //重量 kg
  303. $bigUnit = $string[3] ?? ''; //大单位名称
  304. $smallUnit = $string[4] ?? ''; //小单位名称
  305. $ratio = $string[5] ?? 0; //比例
  306. $cost = $string[6] ?? 0;//成本价
  307. $addPrice = $string[7] ?? 0; //加价
  308. $stockWarning = $string[8] ?? 0;
  309. $alias = $string[9] ?? '';
  310. $cover = $string[10] ?? '';
  311. $inTurn = $string[11] ?? 0;
  312. if ($itemName) {
  313. $py = stringUtil::py($itemName);
  314. $item = [
  315. 'name' => $itemName,
  316. 'alias' => $alias,
  317. 'py' => $py,
  318. 'cover' => $cover,
  319. 'classId' => 0,
  320. 'ratio' => $ratio,
  321. 'weight' => $weight,
  322. 'stockWarning' => $stockWarning,
  323. 'cost' => $cost,
  324. 'addPrice' => $addPrice,
  325. 'bigUnit' => $bigUnit,
  326. 'smallUnit' => $smallUnit,
  327. 'inTurn' => $inTurn,
  328. ];
  329. $itemData[$className][] = $item;
  330. $classData[] = $className;
  331. }
  332. }
  333. $classData = array_unique($classData);
  334. //写入class
  335. if ($clear) {
  336. //清空数据
  337. Yii::$app->db->createCommand()->truncateTable('xhPtItemClass')->execute();
  338. Yii::$app->db->createCommand()->truncateTable('xhPtItem')->execute();
  339. }
  340. foreach ($classData as $v) {
  341. $addClass = PtItemClassClass::add(['name' => $v, 'inTurn' => 0, 'group' => 0]);
  342. $classIdMap[$v] = $addClass['id'];
  343. }
  344. $insertItemData = [];
  345. foreach ($itemData as $k => $v) {
  346. $classId = $classIdMap[$k] ?? 0;
  347. if ($classId) {
  348. foreach ($v as $i) {
  349. $i['classId'] = $classId;
  350. $insertItemData[] = $i;
  351. }
  352. }
  353. }
  354. if (!empty($insertItemData)) {
  355. PtItemClass::batchAdd($insertItemData);
  356. }
  357. echo "done";
  358. }
  359. //供货商初始化 ./yii item/gys ./yii.bat item/gys
  360. public function actionGys()
  361. {
  362. $phpExcelFile = Yii::getAlias("@vendor/phpoffice/phpexcel/");
  363. require_once($phpExcelFile . 'Classes/PHPExcel/IOFactory.php');//查询接口
  364. $dir = Yii::$app->basePath;
  365. $filename = $dir . '/gys.xls';
  366. $fileType = \PHPExcel_IOFactory::identify($filename); //文件名自动判断文件类型
  367. $excelReader = \PHPExcel_IOFactory::createReader($fileType);
  368. $objPHPExcel = $excelReader->load($filename);//$file_url即Excel文件的路径
  369. $sheet = $objPHPExcel->getSheet(0);//获取第一个工作表
  370. $highestRow = $sheet->getHighestRow();//取得总行数
  371. $highestColumn = $sheet->getHighestColumn(); //取得总列数
  372. $changeData = [];
  373. for ($j = 2; $j <= $highestRow; $j++) {
  374. $str = '';
  375. for ($k = 'A'; $k <= $highestColumn; $k++) {
  376. $str .= $objPHPExcel->getActiveSheet()->getCell("$k$j")->getValue() . '\\';
  377. }
  378. //explode:函数把字符串分割为数组。
  379. $string = explode("\\", $str);
  380. array_pop($string);
  381. array_push($changeData, $string);
  382. }
  383. if (!empty($changeData)) {
  384. $mobileList = array_values(array_column($changeData, 1));
  385. $ptStyle = dict::getDict('ptStyle', 'kmGhs');
  386. Yii::$app->params['ptStyle'] = $ptStyle;
  387. $has = Apply::find()->where(['in', 'mobile', $mobileList])->andWhere(['style' => $ptStyle])->all();
  388. if (!empty($has)) {
  389. echo "这些已经添加过了,请先删除:\n";
  390. foreach ($has as $item) {
  391. echo $item->name . ' ' . $item->mobile . "\n";
  392. }
  393. exit();
  394. }
  395. if (getenv('YII_ENV') == 'production') {
  396. $this->sjId = 12367;
  397. $this->shopId = 10;
  398. } else {
  399. $this->sjId = 12615;
  400. $this->shopId = 36119;
  401. }
  402. foreach ($changeData as $currentKey => $currentData) {
  403. $mobile = $currentData[1] ?? '';
  404. $name = $currentData[0] ?? '';
  405. $address = $currentData[2] ?? '';
  406. if (stringUtil::isMobile($mobile) == false) {
  407. echo "请填写正确的手机号 \n";
  408. continue;
  409. }
  410. if (empty($name)) {
  411. echo "{$mobile} 名称不能为空 \n";
  412. continue;
  413. }
  414. if (stringUtil::getWordNum($name) > 8) {
  415. echo "{$mobile} 名称不能超过8个汉字 \n";
  416. continue;
  417. }
  418. $has = ApplyClass::getByCondition(['name' => $name, 'style' => SjClass::STYLE_KM_SUPPLIER]);
  419. if (!empty($has)) {
  420. echo "{$mobile} 名称已经存在 \n";
  421. continue;
  422. }
  423. $has = ApplyClass::getByCondition(['mobile' => $mobile, 'style' => SjClass::STYLE_KM_SUPPLIER]);
  424. if (!empty($has)) {
  425. echo "{$mobile} 手机号已经添加过 \n";
  426. continue;
  427. }
  428. $connection = Yii::$app->db;
  429. $transaction = $connection->beginTransaction();
  430. try {
  431. $sjId = $this->sjId;
  432. $shopId = $this->shopId;
  433. $sjName = $this->sj->name ?? '';
  434. $applyData = [
  435. 'name' => $name,
  436. 'licenseNo' => $mobile,
  437. 'certType' => ApplyClass::CERT_TYPE_MOBILE,
  438. 'mobile' => $mobile,
  439. 'introSjId' => $sjId,
  440. 'introSjName' => $sjName,
  441. 'introShopId' => $shopId,
  442. 'introStyle' => SjClass::STYLE_SUPPLIER,
  443. 'from' => ApplyClass::FROM_GHS,
  444. 'style' => dict::getDict('ptStyle', 'kmGhs'),
  445. 'address' => $address,
  446. 'status' => ApplyClass::STATUS_PASS,
  447. 'replace' => 1,//1表示供货商添加的客户或供货商
  448. ];
  449. $apply = ApplyService::replaceKmGhs($applyData);
  450. $id = $apply['id'] ?? 0;
  451. $respond = ApplyService::pass($id);
  452. $currentShop = $respond['shop'] ?? [];
  453. $sj = $respond['sj'] ?? [];
  454. $currentSjId = $sj['id'] ?? 0;
  455. $currentShopId = $currentShop->id ?? 0;
  456. ApplyClass::updateById($id, ['sjId' => $currentSjId, 'shopId' => $currentShopId]);
  457. if (empty($currentShopId)) {
  458. echo "{$mobile} 供货商添加失败 \n ";
  459. continue;
  460. }
  461. GhsClass::build($currentShopId, $shopId, 1);
  462. $transaction->commit();
  463. echo "{$mobile} 供货商添加成功!\n";
  464. } catch (\Exception $exception) {
  465. $transaction->rollBack();
  466. echo "{$mobile} 供货商添加失败,原因:" . $exception->getMessage() . "\n";
  467. }
  468. }
  469. }
  470. }
  471. //客户初始化 ./yii item/custom ./yii.bat item/custom
  472. public function actionCustom()
  473. {
  474. $phpExcelFile = Yii::getAlias("@vendor/phpoffice/phpexcel/");
  475. require_once($phpExcelFile . 'Classes/PHPExcel/IOFactory.php');//查询接口
  476. $dir = Yii::$app->basePath;
  477. $filename = $dir . '/custom.xls';
  478. $fileType = \PHPExcel_IOFactory::identify($filename); //文件名自动判断文件类型
  479. $excelReader = \PHPExcel_IOFactory::createReader($fileType);
  480. $objPHPExcel = $excelReader->load($filename);//$file_url即Excel文件的路径
  481. $sheet = $objPHPExcel->getSheet(0);//获取第一个工作表
  482. $highestRow = $sheet->getHighestRow();//取得总行数
  483. $highestColumn = $sheet->getHighestColumn(); //取得总列数
  484. $changeData = [];
  485. for ($j = 2; $j <= $highestRow; $j++) {
  486. $str = '';
  487. for ($k = 'A'; $k <= $highestColumn; $k++) {
  488. $str .= $objPHPExcel->getActiveSheet()->getCell("$k$j")->getValue() . '\\';
  489. }
  490. //explode:函数把字符串分割为数组。
  491. $string = explode("\\", $str);
  492. array_pop($string);
  493. array_push($changeData, $string);
  494. }
  495. if (!empty($changeData)) {
  496. $mobileList = array_values(array_column($changeData, 1));
  497. $ptStyle = dict::getDict('ptStyle', 'hd');
  498. Yii::$app->params['ptStyle'] = $ptStyle;
  499. $has = Apply::find()->where(['in', 'mobile', $mobileList])->andWhere(['style' => $ptStyle])->all();
  500. if (!empty($has)) {
  501. echo "这些已经添加过了,请先删除:\n";
  502. foreach ($has as $item) {
  503. echo $item->name . ' ' . $item->mobile . "\n";
  504. }
  505. exit();
  506. }
  507. if (getenv('YII_ENV') == 'production') {
  508. $this->sjId = 12367;
  509. $this->shopId = 10;
  510. } else {
  511. $this->sjId = 12615;
  512. $this->shopId = 36119;
  513. }
  514. $shop = ShopClass::getById($this->shopId, true);
  515. $sj = SjClass::getById($this->sjId, true);
  516. $this->sj = $sj;
  517. foreach ($changeData as $currentKey => $currentData) {
  518. $mobile = $currentData[1] ?? '';
  519. $name = $currentData[0] ?? '';
  520. $address = $currentData[2] ?? '';
  521. if (empty($name)) {
  522. echo "{$mobile} 名称不能为空 \n";
  523. continue;
  524. }
  525. if (stringUtil::getWordNum($name) > 8) {
  526. echo "{$mobile} 名称不能超过8个汉字 \n";
  527. continue;
  528. }
  529. if (stringUtil::isMobile($mobile) == false) {
  530. echo "{$mobile} 手机号错误 \n";
  531. continue;
  532. }
  533. $has = SjClass::getByCondition(['name' => $name, 'style' => SjClass::STYLE_RETAIL]);
  534. if (!empty($has)) {
  535. echo "{$mobile} 名称已经存在 \n";
  536. continue;
  537. }
  538. $has = ApplyClass::getByCondition(['mobile' => $mobile, 'style' => SjClass::STYLE_RETAIL]);
  539. if (!empty($has)) {
  540. echo "{$mobile} 手机号已经添加过 \n";
  541. continue;
  542. }
  543. $connection = Yii::$app->db;
  544. $transaction = $connection->beginTransaction();
  545. try {
  546. $sjId = $this->sjId;
  547. $shopId = $this->shopId;
  548. $sjName = $this->sj->name ?? '';
  549. $city = $shop->city ?? '';
  550. $dist = $shop->dist ?? '';
  551. $applyData = [
  552. 'name' => $name,
  553. 'licenseNo' => $mobile,
  554. 'certType' => ApplyClass::CERT_TYPE_MOBILE,
  555. 'mobile' => $mobile,
  556. 'introSjId' => $sjId,
  557. 'introSjName' => $sjName,
  558. 'introShopId' => $shopId,
  559. 'introStyle' => SjClass::STYLE_SUPPLIER,
  560. 'from' => ApplyClass::FROM_GHS,
  561. 'style' => SjClass::STYLE_RETAIL,
  562. 'province' => $shop->province ?? '',
  563. 'city' => $city,
  564. 'dist' => $dist,
  565. 'address' => $address,
  566. 'status' => ApplyClass::STATUS_PASS,
  567. 'replace' => 1,//1表示供货商添加的客户
  568. ];
  569. $apply = ApplyService::replaceRetail($applyData);
  570. $id = $apply['id'] ?? 0;
  571. $respond = ApplyService::pass($id);
  572. $currentShop = $respond['shop'] ?? [];
  573. $sj = $respond['sj'] ?? [];
  574. $hdSjId = $sj['id'] ?? 0;
  575. $hdShopId = $currentShop->id ?? 0;
  576. ApplyClass::updateById($id, ['sjId' => $hdSjId, 'shopId' => $hdShopId]);
  577. if (empty($hdShopId)) {
  578. echo "{$mobile} 客户添加失败 \n";
  579. continue;
  580. }
  581. $custom = CustomClass::build($this->shopId, $hdShopId);
  582. $custom['avatar'] = imgUtil::groupImg($custom['avatar']);
  583. $transaction->commit();
  584. echo "{$mobile} 添加成功! \n";
  585. } catch (\Exception $exception) {
  586. $transaction->rollBack();
  587. echo "{$mobile} 添加失败,报错:" . $exception->getMessage() . "\n";
  588. }
  589. }
  590. }
  591. }
  592. //更新特价 ssh 20230630
  593. public function actionDiscount()
  594. {
  595. ini_set('memory_limit', '2045M');
  596. set_time_limit(0);
  597. $list = ItemClass::getAllByCondition(['discountPrice>' => 0,], null, '*', null, true);
  598. if (!empty($list)) {
  599. foreach ($list as $item) {
  600. $discountPrice = $item->discountPrice ?? 0;
  601. $skMore = $item->skMore ?? 0;
  602. $addPrice = $item->addPrice ?? 0;
  603. $diff = bcsub($skMore, $addPrice, 2);
  604. if ($diff > 0) {
  605. $item->skDiscountPrice = bcadd($discountPrice, $diff, 2);
  606. } else {
  607. $item->skDiscountPrice = $discountPrice;
  608. }
  609. $item->hjDiscountPrice = $discountPrice;
  610. $item->save();
  611. }
  612. }
  613. }
  614. }