ProductController.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace console\controllers;
  3. use biz\item\classes\PtItemClass;
  4. use biz\product\classes\ProductClass;
  5. use biz\product\models\Product;
  6. use yii\console\Controller;
  7. use Yii;
  8. class ProductController extends Controller
  9. {
  10. // ./yii product/reset-cover
  11. public function actionResetCover()
  12. {
  13. $sql = "SELECT * FROM `" . Product::tableName() . "` WHERE cover not like '%.%'";
  14. $command = Yii::$app->db->createCommand($sql);
  15. $data = $command->queryAll();
  16. if (empty($data)) {
  17. return false;
  18. }
  19. foreach ($data as $item) {
  20. $id = $item['id'] ?? 0;
  21. $ptItemId = $item['itemId'] ?? 0;
  22. $preCover = $item['cover'] ?? '';
  23. $ptItem = PtItemClass::getById($ptItemId, true);
  24. $cover = $ptItem->cover ?? '';
  25. if (!empty($cover)) {
  26. ProductClass::updateById($id, ['cover' => $cover]);
  27. echo "productId:" . $id . "原图:{$preCover}, 恢复图片:" . $cover . "\n";
  28. } else {
  29. echo "productId:" . $id . " 恢复图片没有成功-----------------\n";
  30. }
  31. }
  32. }
  33. }