$mainId, 'delStatus' => 0], null, '*', null, true); if (!empty($list)) { foreach ($list as $item) { $name = $item->name ?? ''; $has = false; if (strstr($name, '100支') != false) { $ptItemId = $item->itemId ?? 0; $ptItem = PtItemClass::getById($ptItemId, true); if (!empty($ptItem)) { $item->ratio = 100; $item->smallUnit = '支'; $item->smallUnitId = 2; $item->save(); $ptItem->ratio = 100; $ptItem->smallUnit = '支'; $ptItem->smallUnitId = 2; $ptItem->save(); $has = true; } } if (strstr($name, '200支') != false) { $ptItemId = $item->itemId ?? 0; $ptItem = PtItemClass::getById($ptItemId, true); if (!empty($ptItem)) { $item->ratio = 200; $item->smallUnit = '支'; $item->smallUnitId = 2; $item->save(); $ptItem->ratio = 200; $ptItem->smallUnit = '支'; $ptItem->smallUnitId = 2; $ptItem->save(); $has = true; } } if ($has) { echo $name . "\n"; } } } } public function actionItem() { $list = PtItemCatRelateClass::getAllByCondition(['id>' => 0], 'id asc', '*', null, true); if (!empty($list)) { foreach ($list as $item) { $ptItemId = $item->itemId ?? 0; $ptItem = PtItemClass::getById($ptItemId, true); echo $ptItem->name . "\n"; } } } public function actionCp() { $list = PtCpItemClass::getAllByCondition(['id>' => 0], 'id asc', '*', null, true); foreach ($list as $cp) { $ptItemId = $cp->itemId ?? 0; $ptItem = PtItemClass::getById($ptItemId, true); $ptItem->hasCpId = 1; $ptItem->save(); } } }