InitController.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace console\controllers;
  3. use biz\item\classes\UnitClass;
  4. use biz\product\classes\ProductClass;
  5. use yii\console\Controller;
  6. class InitController extends Controller
  7. {
  8. public function actionUnit()
  9. {
  10. ini_set('memory_limit', '2045M');
  11. set_time_limit(0);
  12. $arr = UnitClass::getAllByCondition(['id>' => 0], null, '*', 'id');
  13. $data = [];
  14. foreach ($arr as $item) {
  15. $id = $item['id'] ?? 0;
  16. $name = $item['name'] ?? '';
  17. $data[$id] = $name;
  18. }
  19. $itemList = ProductClass::getAllByCondition(['id>'=>0], null, '*', null, true);
  20. if (!empty($itemList)) {
  21. foreach ($itemList as $item) {
  22. $bigUnitId = $item->bigUnitId ?? 1;
  23. $smallUnitId = $item->smallUnitId ?? 1;
  24. $bigUnit = $data[$bigUnitId] ?? '扎';
  25. $smallUnit = $data[$smallUnitId] ?? '支';
  26. $item->bigUnit = $bigUnit;
  27. $item->smallUnit = $smallUnit;
  28. $item->save();
  29. }
  30. }
  31. }
  32. }