| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- <?php
- namespace console\controllers;
- use biz\item\classes\UnitClass;
- use biz\product\classes\ProductClass;
- use yii\console\Controller;
- class InitController extends Controller
- {
- public function actionUnit()
- {
- ini_set('memory_limit', '2045M');
- set_time_limit(0);
- $arr = UnitClass::getAllByCondition(['id>' => 0], null, '*', 'id');
- $data = [];
- foreach ($arr as $item) {
- $id = $item['id'] ?? 0;
- $name = $item['name'] ?? '';
- $data[$id] = $name;
- }
- $itemList = ProductClass::getAllByCondition(['id>'=>0], null, '*', null, true);
- if (!empty($itemList)) {
- foreach ($itemList as $item) {
- $bigUnitId = $item->bigUnitId ?? 1;
- $smallUnitId = $item->smallUnitId ?? 1;
- $bigUnit = $data[$bigUnitId] ?? '扎';
- $smallUnit = $data[$smallUnitId] ?? '支';
- $item->bigUnit = $bigUnit;
- $item->smallUnit = $smallUnit;
- $item->save();
- }
- }
- }
- }
|