ShopController.php 6.3 KB

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