KindController.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. print_r($kindList);
  42. if (empty($lzKindId) || empty($hsKindId)) {
  43. echo '有品类id没有 ' . $shop->merchantName . ' ' . $shop->shopName;
  44. Yii::$app->end();
  45. }
  46. GoodsClass::updateByCondition(['mainId' => $mainId, 'flower' => 1], ['kindId' => $hsKindId, 'kindName' => $hsName]);
  47. GoodsCategoryClass::updateByCondition(['mainId' => $mainId, 'flower' => 1], ['kindId' => $hsKindId, 'kindName' => $hsName]);
  48. GoodsClass::updateByCondition(['mainId' => $mainId, 'flower' => 0], ['kindId' => $lzKindId, 'kindName' => $lzName]);
  49. GoodsCategoryClass::updateByCondition(['mainId' => $mainId, 'flower' => 0], ['kindId' => $lzKindId, 'kindName' => $lzName]);
  50. $workList = WorkClass::getAllByCondition(['mainId' => $mainId], null, '*', null, true);
  51. if (!empty($workList)) {
  52. foreach ($workList as $work) {
  53. $goodsId = $work->goodsId ?? 0;
  54. $goodsInfo = GoodsClass::getById($goodsId, true);
  55. if (!empty($goodsInfo)) {
  56. $thisKindId = $goodsInfo->kindId ?? 0;
  57. $thisKindName = $goodsInfo->kindName ?? '';
  58. $work->kindId = $thisKindId;
  59. $work->kindName = $thisKindName;
  60. $work->save();
  61. }
  62. }
  63. }
  64. $arr = OrderGoodsClass::getAllByCondition(['id>' => 0], null, '*', null, true);
  65. if (!empty($arr)) {
  66. foreach ($arr as $in) {
  67. $goodsId = $in->goodsId ?? 0;
  68. $goodsInfo = GoodsClass::getById($goodsId, true);
  69. if (!empty($goodsInfo)) {
  70. $thisKindId = $goodsInfo->kindId ?? 0;
  71. $thisKindName = $goodsInfo->kindName ?? '';
  72. $in->kindId = $thisKindId;
  73. $in->kindName = $thisKindName;
  74. $in->save();
  75. }
  76. }
  77. }
  78. }
  79. }
  80. }
  81. //种类初始化 ssh 20230301
  82. public function actionInit()
  83. {
  84. ini_set('memory_limit', '2045M');
  85. set_time_limit(0);
  86. $shopList = ShopClass::getAllByCondition(['ptStyle' => 1], null, '*', null, true);
  87. if (!empty($shopList)) {
  88. foreach ($shopList as $shop) {
  89. $mainId = $shop->mainId ?? 0;
  90. $sjId = $shop->sjId ?? 0;
  91. $has = KindClass::getByCondition(['mainId' => $mainId], true);
  92. if (!empty($has)) {
  93. continue;
  94. }
  95. $data = [
  96. 'mainId' => $mainId,
  97. 'sjId' => $sjId,
  98. ];
  99. KindClass::initKind($data);
  100. }
  101. }
  102. }
  103. }