ShopController.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <?php
  2. namespace console\controllers;
  3. use biz\ghs\classes\GhsClass;
  4. use biz\shop\classes\MainClass;
  5. use biz\shop\classes\ShopClass;
  6. use biz\shop\models\Shop;
  7. use bizGhs\custom\classes\CustomClass;
  8. use bizGhs\order\classes\OrderClass;
  9. use bizGhs\order\models\Order;
  10. use bizHd\purchase\classes\PurchaseClass;
  11. use common\components\noticeUtil;
  12. use common\components\util;
  13. use yii\console\Controller;
  14. use Yii;
  15. class ShopController extends Controller
  16. {
  17. //【有用的脚本】总欠款变动记录跟踪 ./yii shop/total-debt-check ssh 20220909
  18. public function actionTotalDebtCheck()
  19. {
  20. //感觉好像没有用了,可以停了 ssh 20250724
  21. util::stop();
  22. ini_set('memory_limit', '2045M');
  23. set_time_limit(0);
  24. $list = ShopClass::getAllByCondition(['ptStyle' => 2], null, '*', null, true);
  25. if (!empty($list)) {
  26. foreach ($list as $shop) {
  27. $sjName = $shop->merchantName ?? '';
  28. $shopName = $shop->shopName ?? '';
  29. $mainId = $shop->mainId ?? 0;
  30. $main = MainClass::getById($mainId, true);
  31. if (empty($main)) {
  32. continue;
  33. }
  34. $customList = CustomClass::getAllByCondition(['ownMainId' => $mainId], null, '*', null, true);
  35. $ghsCustomDebt = 0;
  36. if (!empty($customList)) {
  37. foreach ($customList as $custom) {
  38. $debtAmount = $custom->debtAmount ?? 0;
  39. $ghsCustomDebt = bcadd($ghsCustomDebt, $debtAmount, 2);
  40. }
  41. }
  42. $hdCustomDebt = 0;
  43. $lsShopId = $shop->lsShopId ?? 0;
  44. $customList = \bizHd\custom\classes\CustomClass::getAllByCondition(['shopId' => $lsShopId], null, '*', null, true);
  45. if (!empty($customList)) {
  46. foreach ($customList as $custom) {
  47. $currentDebt = $custom->debtAmount ?? 0;
  48. $hdCustomDebt = bcadd($currentDebt, $hdCustomDebt, 2);
  49. }
  50. }
  51. $totalDebt = bcadd($ghsCustomDebt, $hdCustomDebt, 2);
  52. if (floatval($totalDebt) != floatval($main->debt)) {
  53. noticeUtil::push("{$sjName} {$shopName}的批零客户欠款总和跟main里的欠款不一致 总和欠款:{$totalDebt} main欠款:{$main->debt} mainId:{$mainId} | 批发:{$ghsCustomDebt} 零售:{$hdCustomDebt}", '15280215347');
  54. }
  55. }
  56. }
  57. }
  58. public function actionHasGhs()
  59. {
  60. $query = new \yii\db\Query();
  61. $query->from(Shop::tableName());
  62. $query->where(['ptStyle' => 1]);
  63. foreach ($query->batch() as $shopList) {
  64. foreach ($shopList as $shop) {
  65. $shopId = $shop['id'] ?? 0;
  66. $where = ['ownShopId' => $shopId];
  67. $count = GhsClass::getCount($where);
  68. if ($count == 0) {
  69. //无操作
  70. } elseif ($count == 1) {
  71. $ghs = GhsClass::getByCondition($where, true);
  72. $ghsId = $ghs->id ?? 0;
  73. if (!empty($ghsId)) {
  74. ShopClass::updateById($shopId, ['uniGhsId' => $ghsId]);
  75. }
  76. } else {
  77. ShopClass::updateById($shopId, ['hasManyGhs' => 1]);
  78. }
  79. }
  80. }
  81. }
  82. public function actionOrder()
  83. {
  84. $query = new \yii\db\Query();
  85. $query->from(Order::tableName());
  86. $query->where(['>', 'id', 0]);
  87. foreach ($query->batch() as $orderList) {
  88. foreach ($orderList as $order) {
  89. $payTime = $order['payTime'] ?? '';
  90. if (!empty($payTime) && $payTime != '0000-00-00 00:00:00') {
  91. $addTime = $order['addTime'] ?? '';
  92. if ($payTime > $addTime) {
  93. echo "id:{$order['id']} {$payTime} {$addTime}\n";
  94. OrderClass::updateById($order['id'], ['addTime' => $payTime]);
  95. $purchaseId = $order['purchaseId'] ?? 0;
  96. $cg = PurchaseClass::getById($purchaseId, true);
  97. if (!empty($cg)) {
  98. $cg->addTime = $payTime;
  99. $cg->save();
  100. }
  101. }
  102. }
  103. }
  104. }
  105. }
  106. public function actionCustom()
  107. {
  108. $custom = CustomClass::getAllByCondition(['id>' => 0], null, '*', null, true);
  109. if (empty($custom)) {
  110. echo '空';
  111. return false;
  112. }
  113. foreach ($custom as $item) {
  114. $shopId = $item->shopId ?? 0;
  115. $shop = ShopClass::getById($shopId, true);
  116. if ($shop->mainId != $item->mainId) {
  117. echo "客户id:{$item->id} {$shop->mainId} {$item->mainId}\n";
  118. if (!empty($shop->mainId)) {
  119. $item->mainId = $shop->mainId;
  120. $item->save();
  121. }
  122. }
  123. $ownShopId = $item->ownShopId ?? 0;
  124. $ownShop = ShopClass::getById($ownShopId, true);
  125. if ($ownShop->mainId != $item->ownMainId) {
  126. echo "客户own {$item->id} {$item->ownMainId} {$ownShop->mainId}\n";
  127. if (!empty($ownShop->mainId)) {
  128. $item->ownMainId = $ownShop->mainId;
  129. $item->save();
  130. }
  131. }
  132. }
  133. }
  134. public function actionGhs()
  135. {
  136. $ghs = GhsClass::getAllByCondition(['id>' => 0], null, '*', null, true);
  137. if (empty($ghs)) {
  138. echo '空';
  139. return false;
  140. }
  141. foreach ($ghs as $item) {
  142. $shopId = $item->shopId ?? 0;
  143. $mainId = $item->mainId ?? 0;
  144. $shop = ShopClass::getById($shopId, true);
  145. if ($shop->mainId != $mainId) {
  146. echo "ghs {$item->id} {$mainId} {$shop->mainId} \n";
  147. }
  148. $ownShopId = $item->ownShopId ?? 0;
  149. $ownMainId = $item->ownMainId ?? 0;
  150. $ownShop = ShopClass::getById($ownShopId, true);
  151. if ($ownShop->mainId != $ownMainId) {
  152. echo "ghs own {$item->id} {$ownMainId} {$ownShop->mainId} \n";
  153. if (!empty($ownShop->mainId)) {
  154. $item->ownMainId = $ownShop->mainId;
  155. $item->save();
  156. }
  157. }
  158. }
  159. }
  160. }