ShopController.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. namespace console\controllers;
  3. use biz\ghs\classes\GhsClass;
  4. use biz\shop\classes\ShopClass;
  5. use biz\shop\models\Shop;
  6. use bizGhs\custom\classes\CustomClass;
  7. use bizGhs\order\classes\OrderClass;
  8. use bizGhs\order\models\Order;
  9. use bizHd\purchase\classes\PurchaseClass;
  10. use yii\console\Controller;
  11. use Yii;
  12. class ShopController extends Controller
  13. {
  14. public function actionHasGhs()
  15. {
  16. $query = new \yii\db\Query();
  17. $query->from(Shop::tableName());
  18. $query->where(['ptStyle' => 1]);
  19. foreach ($query->batch() as $shopList) {
  20. foreach ($shopList as $shop) {
  21. $shopId = $shop['id'] ?? 0;
  22. $where = ['ownShopId' => $shopId];
  23. $count = GhsClass::getCount($where);
  24. if ($count == 0) {
  25. //无操作
  26. } elseif ($count == 1) {
  27. $ghs = GhsClass::getByCondition($where, true);
  28. $ghsId = $ghs->id ?? 0;
  29. if (!empty($ghsId)) {
  30. ShopClass::updateById($shopId, ['uniGhsId' => $ghsId]);
  31. }
  32. } else {
  33. ShopClass::updateById($shopId, ['hasManyGhs' => 1]);
  34. }
  35. }
  36. }
  37. }
  38. public function actionOrder()
  39. {
  40. $query = new \yii\db\Query();
  41. $query->from(Order::tableName());
  42. $query->where(['>', 'id', 0]);
  43. foreach ($query->batch() as $orderList) {
  44. foreach ($orderList as $order) {
  45. $payTime = $order['payTime'] ?? '';
  46. if (!empty($payTime) && $payTime != '0000-00-00 00:00:00') {
  47. $addTime = $order['addTime'] ?? '';
  48. if ($payTime > $addTime) {
  49. echo "id:{$order['id']} {$payTime} {$addTime}\n";
  50. OrderClass::updateById($order['id'], ['addTime' => $payTime]);
  51. $purchaseId = $order['purchaseId'] ?? 0;
  52. $cg = PurchaseClass::getById($purchaseId, true);
  53. if (!empty($cg)) {
  54. $cg->addTime = $payTime;
  55. $cg->save();
  56. }
  57. }
  58. }
  59. }
  60. }
  61. }
  62. public function actionCustom()
  63. {
  64. $custom = CustomClass::getAllByCondition(['id>' => 0], null, '*', null, true);
  65. if (empty($custom)) {
  66. echo '空';
  67. return false;
  68. }
  69. foreach ($custom as $item) {
  70. $shopId = $item->shopId ?? 0;
  71. $shop = ShopClass::getById($shopId, true);
  72. if ($shop->mainId != $item->mainId) {
  73. echo "客户id:{$item->id} {$shop->mainId} {$item->mainId}\n";
  74. if (!empty($shop->mainId)) {
  75. $item->mainId = $shop->mainId;
  76. $item->save();
  77. }
  78. }
  79. $ownShopId = $item->ownShopId ?? 0;
  80. $ownShop = ShopClass::getById($ownShopId, true);
  81. if ($ownShop->mainId != $item->ownMainId) {
  82. echo "客户own {$item->id} {$item->ownMainId} {$ownShop->mainId}\n";
  83. if (!empty($ownShop->mainId)) {
  84. $item->ownMainId = $ownShop->mainId;
  85. $item->save();
  86. }
  87. }
  88. }
  89. }
  90. public function actionGhs()
  91. {
  92. $ghs = GhsClass::getAllByCondition(['id>' => 0], null, '*', null, true);
  93. if (empty($ghs)) {
  94. echo '空';
  95. return false;
  96. }
  97. foreach ($ghs as $item) {
  98. $shopId = $item->shopId ?? 0;
  99. $mainId = $item->mainId ?? 0;
  100. $shop = ShopClass::getById($shopId, true);
  101. if ($shop->mainId != $mainId) {
  102. echo "ghs {$item->id} {$mainId} {$shop->mainId} \n";
  103. }
  104. $ownShopId = $item->ownShopId ?? 0;
  105. $ownMainId = $item->ownMainId ?? 0;
  106. $ownShop = ShopClass::getById($ownShopId, true);
  107. if ($ownShop->mainId != $ownMainId) {
  108. echo "ghs own {$item->id} {$ownMainId} {$ownShop->mainId} \n";
  109. if (!empty($ownShop->mainId)) {
  110. $item->ownMainId = $ownShop->mainId;
  111. $item->save();
  112. }
  113. }
  114. }
  115. }
  116. }