StatItemController.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace console\controllers;
  3. use biz\shop\classes\ShopClass;
  4. use biz\stat\classes\StatItemClass;
  5. use biz\stat\classes\StatItemMonthClass;
  6. use yii\console\Controller;
  7. use Yii;
  8. class StatItemController extends Controller
  9. {
  10. // ./yii stat-item/bc
  11. public function actionBc()
  12. {
  13. ini_set('memory_limit', '2045M');
  14. set_time_limit(0);
  15. $list = ShopClass::getAllByCondition(['id>' => 0], null, '*', 'id');
  16. $map = [];
  17. if (!empty($list)) {
  18. foreach ($list as $shopId => $shop) {
  19. $mainId = $shop['mainId'] ?? 0;
  20. $map[$shopId] = $mainId;
  21. }
  22. }
  23. $statList = StatItemClass::getAllByCondition(['id>' => 0], null, '*', null, true);
  24. if (!empty($statList)) {
  25. foreach ($statList as $stat) {
  26. $currentMainId = $stat->mainId ?? 0;
  27. if (!empty($currentMainId)) {
  28. continue;
  29. }
  30. $currentShopId = $stat->shopId ?? 0;
  31. if (empty($currentShopId)) {
  32. continue;
  33. }
  34. $newMainId = $map[$currentShopId] ?? 0;
  35. $stat->mainId = $newMainId;
  36. $stat->save();
  37. }
  38. }
  39. $statList = StatItemMonthClass::getAllByCondition(['id>' => 0], null, '*', null, true);
  40. if (!empty($statList)) {
  41. foreach ($statList as $stat) {
  42. $currentMainId = $stat->mainId ?? 0;
  43. if (!empty($currentMainId)) {
  44. continue;
  45. }
  46. $currentShopId = $stat->shopId ?? 0;
  47. if (empty($currentShopId)) {
  48. continue;
  49. }
  50. $newMainId = $map[$currentShopId] ?? 0;
  51. $stat->mainId = $newMainId;
  52. $stat->save();
  53. }
  54. }
  55. }
  56. }