| 123456789101112131415161718192021222324252627282930313233343536373839 |
- <?php
- namespace console\controllers;
- use biz\item\classes\PtItemClass;
- use biz\product\classes\ProductClass;
- use biz\product\models\Product;
- use yii\console\Controller;
- use Yii;
- class ProductController extends Controller
- {
- // ./yii product/reset-cover
- public function actionResetCover()
- {
- $sql = "SELECT * FROM `" . Product::tableName() . "` WHERE cover not like '%.%'";
- $command = Yii::$app->db->createCommand($sql);
- $data = $command->queryAll();
- if (empty($data)) {
- return false;
- }
- foreach ($data as $item) {
- $id = $item['id'] ?? 0;
- $ptItemId = $item['itemId'] ?? 0;
- $preCover = $item['cover'] ?? '';
- $ptItem = PtItemClass::getById($ptItemId, true);
- $cover = $ptItem->cover ?? '';
- if (!empty($cover)) {
- ProductClass::updateById($id, ['cover' => $cover]);
- echo "productId:" . $id . "原图:{$preCover}, 恢复图片:" . $cover . "\n";
- } else {
- echo "productId:" . $id . " 恢复图片没有成功-----------------\n";
- }
- }
- }
- }
|