KindController.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. namespace console\controllers;
  3. use bizHd\goods\classes\GoodsCategoryClass;
  4. use bizHd\goods\classes\GoodsClass;
  5. use bizHd\goods\classes\KindClass;
  6. use bizHd\order\classes\OrderGoodsClass;
  7. use bizHd\shop\classes\ShopClass;
  8. use bizHd\work\classes\WorkClass;
  9. use yii\console\Controller;
  10. use Yii;
  11. class KindController extends Controller
  12. {
  13. public function actionCs()
  14. {
  15. echo 123;
  16. }
  17. //品类更新 ssh 20230320
  18. public function actionUpdate()
  19. {
  20. ini_set('memory_limit', '2045M');
  21. set_time_limit(0);
  22. $shopList = ShopClass::getAllByCondition(['ptStyle' => 1], null, '*', null, true);
  23. if (!empty($shopList)) {
  24. foreach ($shopList as $shop) {
  25. $mainId = $shop->mainId ?? 0;
  26. $kindList = KindClass::getAllByCondition(['mainId' => $mainId], null, '*');
  27. $lzKindId = 0;
  28. $lzName = '';
  29. $hsKindId = 0;
  30. $hsName = '';
  31. if (!empty($kindList)) {
  32. foreach ($kindList as $kindInfo) {
  33. $name = $kindInfo['name'] ?? '';
  34. $kId = $kindInfo['id'] ?? 0;
  35. if ($name == '绿植') {
  36. $lzKindId = $kId;
  37. $lzName = $name;
  38. }
  39. if ($name == '花束') {
  40. $hsKindId = $kId;
  41. $hsName = $name;
  42. }
  43. }
  44. }
  45. if (empty($lzKindId) || empty($hsKindId)) {
  46. echo '有品类id没有 ' . $shop->merchantName . ' ' . $shop->shopName;
  47. Yii::$app->end();
  48. }
  49. GoodsClass::updateByCondition(['mainId' => $mainId, 'flower' => 1], ['kindId' => $hsKindId, 'kindName' => $hsName]);
  50. GoodsCategoryClass::updateByCondition(['mainId' => $mainId, 'flower' => 1], ['kindId' => $hsKindId, 'kindName' => $hsName]);
  51. GoodsClass::updateByCondition(['mainId' => $mainId, 'flower' => 0], ['kindId' => $lzKindId, 'kindName' => $lzName]);
  52. GoodsCategoryClass::updateByCondition(['mainId' => $mainId, 'flower' => 0], ['kindId' => $lzKindId, 'kindName' => $lzName]);
  53. $workList = WorkClass::getAllByCondition(['mainId' => $mainId], null, '*', null, true);
  54. if (!empty($workList)) {
  55. foreach ($workList as $work) {
  56. $goodsId = $work->goodsId ?? 0;
  57. $goodsInfo = GoodsClass::getById($goodsId, true);
  58. if (!empty($goodsInfo)) {
  59. $thisKindId = $goodsInfo->kindId ?? 0;
  60. $thisKindName = $goodsInfo->kindName ?? '';
  61. $work->kindId = $thisKindId;
  62. $work->kindName = $thisKindName;
  63. $work->save();
  64. }
  65. }
  66. }
  67. $arr = OrderGoodsClass::getAllByCondition(['id>' => 0], null, '*', null, true);
  68. if (!empty($arr)) {
  69. foreach ($arr as $in) {
  70. $goodsId = $in->goodsId ?? 0;
  71. $goodsInfo = GoodsClass::getById($goodsId, true);
  72. if (!empty($goodsInfo)) {
  73. $thisKindId = $goodsInfo->kindId ?? 0;
  74. $thisKindName = $goodsInfo->kindName ?? '';
  75. $in->kindId = $thisKindId;
  76. $in->kindName = $thisKindName;
  77. $in->save();
  78. }
  79. }
  80. }
  81. }
  82. }
  83. }
  84. //种类初始化 ssh 20230301
  85. public function actionInit()
  86. {
  87. ini_set('memory_limit', '2045M');
  88. set_time_limit(0);
  89. $shopList = ShopClass::getAllByCondition(['ptStyle' => 1], null, '*', null, true);
  90. if (!empty($shopList)) {
  91. foreach ($shopList as $shop) {
  92. $mainId = $shop->mainId ?? 0;
  93. $sjId = $shop->sjId ?? 0;
  94. $has = KindClass::getByCondition(['mainId' => $mainId], true);
  95. if (!empty($has)) {
  96. continue;
  97. }
  98. $data = [
  99. 'mainId' => $mainId,
  100. 'sjId' => $sjId,
  101. ];
  102. KindClass::initKind($data);
  103. }
  104. }
  105. }
  106. }