ProductController.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. // ./yii product/sk-price
  34. public function actionSkPrice()
  35. {
  36. ini_set('memory_limit', '2045M');
  37. set_time_limit(0);
  38. $list = ProductClass::getAllByCondition([], null, '*', null, true);
  39. if (empty($list)) {
  40. return false;
  41. }
  42. foreach ($list as $key => $item) {
  43. $price = $item->price ?? 0;
  44. $skAddPrice = $item->skAddPrice ?? 0;
  45. $addPrice = $item->addPrice ?? 0;
  46. $diff = bcsub($skAddPrice, $addPrice, 2);
  47. $currentPrice = $price;
  48. if ($diff > 0) {
  49. $currentPrice = bcadd($price, $diff, 2);
  50. }
  51. $item->skPrice = $currentPrice;
  52. $item->save();
  53. }
  54. }
  55. }