ProductController.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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-price
  45. public function actionUpdatePrice()
  46. {
  47. $list = ProductClass::getAllByCondition(['shopId' => 10], null, '*', null, true);
  48. if (empty($list)) {
  49. return false;
  50. }
  51. foreach ($list as $product) {
  52. $ptItemId = $product->itemId ?? 0;
  53. $weight = $product->weight ?? 0;
  54. $addPrice = $product->addPrice ?? 0;
  55. $p = ProductClass::getByCondition(['shopId' => 214, 'itemId' => $ptItemId], true);
  56. if (!empty($p)) {
  57. $p->addPrice = $addPrice;
  58. $p->weight = $weight;
  59. $p->save();
  60. echo "productId {$p->id} 加价改成了:{$addPrice} 重量改成了:{$weight} \n";
  61. }
  62. }
  63. }
  64. }