KindController.php 3.3 KB

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