ProductController.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. $ratio = $product->ratio ?? 20;
  56. $p = ProductClass::getByCondition(['shopId' => 214, 'itemId' => $ptItemId], true);
  57. if (!empty($p)) {
  58. //$p->addPrice = $addPrice;
  59. //$p->weight = $weight;
  60. $p->ratio = $ratio;
  61. $p->save();
  62. echo "productId {$p->id} 加价改成了:{$addPrice} 重量改成了:{$weight} 比例修改为 {$ratio} \n";
  63. }
  64. }
  65. }
  66. }