ProductController.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace console\controllers;
  3. use biz\item\classes\PtItemClass;
  4. use bizGhs\product\classes\ProductClass;
  5. use yii\console\Controller;
  6. class ProductController extends Controller
  7. {
  8. //上下架 ./yii product/update-status
  9. public function actionUpdateStatus()
  10. {
  11. $list = ProductClass::getAllByCondition([], null, '*', null, true);
  12. if (empty($list)) {
  13. return false;
  14. }
  15. foreach ($list as $product) {
  16. $delStatus = $product->delStatus;
  17. //已经下架的商品
  18. if ($delStatus == 1) {
  19. $product->status = 2;
  20. $product->delStatus = 0;
  21. $product->save();
  22. echo $product->name . " {$product->id} 已经下架 status 变成 2 delStatus 变成 0\n";
  23. }
  24. }
  25. }
  26. //更新封面 ./yii product/update-cover
  27. public function actionUpdateCover()
  28. {
  29. $list = ProductClass::getAllByCondition([], null, '*', null, true);
  30. if (empty($list)) {
  31. return false;
  32. }
  33. foreach ($list as $product) {
  34. $itemId = $product->itemId ?? 0;
  35. $ptItem = PtItemClass::getById($itemId, true);
  36. $ptCover = $ptItem->cover ?? '';
  37. if (!empty($ptCover)) {
  38. $product->cover = $ptCover;
  39. $product->save();
  40. echo "{$product->id} 已更新为{$ptCover} \n";
  41. }
  42. }
  43. }
  44. //更新重量 ./yii product/update-weight
  45. public function actionUpdateWeight()
  46. {
  47. $list = ProductClass::getAllByCondition(['shopId' => 10], null, '*', null, true);
  48. if (empty($list)) {
  49. return false;
  50. }
  51. foreach ($list as $product) {
  52. $itemId = $product->itemId ?? 0;
  53. $ptItem = PtItemClass::getById($itemId, true);
  54. $weight = $product->weight ?? 0;
  55. if (!empty($weight)) {
  56. $preWeight = $ptItem->weight ?? 0;
  57. $ptItem->weight = $weight;
  58. $ptItem->save();
  59. echo "平台花材{$ptItem->id} 重量由{$preWeight}更新为{$weight} \n";
  60. }
  61. }
  62. }
  63. }