KindController.php 4.4 KB

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