CustomController.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. namespace console\controllers;
  3. use biz\ghs\classes\GhsClass;
  4. use biz\shop\classes\ShopClass;
  5. use bizGhs\custom\classes\CustomClass;
  6. use bizGhs\custom\models\Custom;
  7. use bizGhs\order\classes\OrderClass;
  8. use bizHd\purchase\classes\PurchaseClass;
  9. use common\components\noticeUtil;
  10. use common\components\util;
  11. use yii\console\Controller;
  12. use Yii;
  13. class CustomController extends Controller
  14. {
  15. //黑名单设置 ./yii custom/black
  16. public function actionBlack()
  17. {
  18. $list = CustomClass::getAllByCondition(['black' => 2], null, '*', null, true);
  19. if (!empty($list)) {
  20. foreach ($list as $c) {
  21. $ghsId = $c->ghsId ?? 0;
  22. $ghs = GhsClass::getById($ghsId, true);
  23. if (!empty($ghs)) {
  24. $ghs->black = 2;
  25. $ghs->save();
  26. echo $ghs->name . " id:{$ghs->id} 已经黑了\n";
  27. }
  28. }
  29. }
  30. }
  31. //欠款信息不一致跟踪 shish 20220307 ./yii custom/adjust-debt
  32. public function actionAdjustDebt()
  33. {
  34. $shopList = ShopClass::getAllByCondition(['ptStyle' => 2], null, '*', null, true);
  35. if (empty($shopList)) {
  36. return false;
  37. }
  38. foreach ($shopList as $key => $shop) {
  39. $shopId = $shop->id ?? 0;
  40. $shopName = $shop->shopName ?? '';
  41. $merchantName = $shop->merchantName ?? '';
  42. echo "{$merchantName}-{$shopName}的客户: \n";
  43. $query = new \yii\db\Query();
  44. $query->from(Custom::tableName());
  45. $query->where(['ownShopId' => $shopId]);
  46. $query->orderBy('addTime ASC');
  47. foreach ($query->batch(50) as $customList) {
  48. if (!empty($customList)) {
  49. foreach ($customList as $custom) {
  50. $customName = $custom['name'] ?? '';
  51. echo $customName . "\n";
  52. continue;
  53. $customId = $custom['id'] ?? 0;
  54. $where = ['customId' => $customId, 'debt' => 1];
  55. $orderList = OrderClass::getAllByCondition($where, 'addTime DESC', '*');
  56. $ghsOrderDebtAmount = 0;
  57. if (!empty($orderList)) {
  58. foreach ($orderList as $order) {
  59. $actPrice = $order['actPrice'] ?? 0;
  60. $ghsOrderDebtAmount = bcadd($ghsOrderDebtAmount, $actPrice, 2);
  61. }
  62. }
  63. $ghsId = $custom['ghsId'] ?? 0;
  64. $ghs = \bizHd\ghs\classes\GhsClass::getById($ghsId);
  65. $where = ['ghsId' => $ghsId, 'debt' => PurchaseClass::DEBT_YES];
  66. $cgList = PurchaseClass::getAllByCondition($where, 'addTime DESC', '*');
  67. $hdCgOrderDebtAmount = 0;
  68. if (!empty($cgList)) {
  69. foreach ($cgList as $cg) {
  70. $actPrice = $cg['actPrice'] ?? 0;
  71. $hdCgOrderDebtAmount = bcadd($hdCgOrderDebtAmount, $actPrice, 2);
  72. }
  73. }
  74. if ($ghsOrderDebtAmount < 0 || $hdCgOrderDebtAmount < 0) {
  75. //noticeUtil::push("!!!!!!!供应商 {$ghsId} 客户id {$customId} 出现负数 $ghsOrderDebtAmount $hdCgOrderDebtAmount", '15280215347');
  76. echo "@@@@@@@@@@@@@供应商 {$ghsId} 客户id {$customId} 出现负数 $ghsOrderDebtAmount $hdCgOrderDebtAmount \n";
  77. }
  78. $ghsOrderDebtAmount = floatval($ghsOrderDebtAmount);
  79. $hdCgOrderDebtAmount = floatval($hdCgOrderDebtAmount);
  80. if ($ghsOrderDebtAmount != $hdCgOrderDebtAmount) {
  81. //noticeUtil::push("!!!!!!!供应商 {$ghsId} 客户id {$customId} 二边欠款单总金额不一致", '15280215347');
  82. echo "---------供应商 {$ghsId} 客户id {$customId} 二边 欠款单 总金额 不一致 {$ghsOrderDebtAmount} {$hdCgOrderDebtAmount} \n";
  83. continue;
  84. }
  85. $customSaveDebtAmount = $custom['debtAmount'] ? floatval($custom['debtAmount']) : 0;
  86. $ghsSaveDebtAmount = $ghs['debtAmount'] ? floatval($ghs['debtAmount']) : 0;
  87. if ($customSaveDebtAmount != $ghsOrderDebtAmount) {
  88. echo "*********客户 {$customId} 欠款总金额 和 订单总合 不一致 $customSaveDebtAmount $ghsOrderDebtAmount \n";
  89. //noticeUtil::push("*********客户 {$customId} 欠款总金额 和 订单总合 不一致 $customSaveDebtAmount $ghsOrderDebtAmount ", '15280215347');
  90. // echo "已更:".$hdCgOrderDebtAmount.' '.$ghsOrderDebtAmount."\n";
  91. // \bizHd\ghs\classes\GhsClass::updateById($ghsId, ['debtAmount' => $hdCgOrderDebtAmount]);
  92. // CustomClass::updateById($customId, ['debtAmount' => $ghsOrderDebtAmount]);
  93. continue;
  94. }
  95. if ($ghsSaveDebtAmount != $hdCgOrderDebtAmount) {
  96. echo "#########欠供应商 {$ghsId} 金额 和 订单总合 不一致 $ghsSaveDebtAmount $hdCgOrderDebtAmount \n";
  97. //noticeUtil::push("#########欠供应商 {$ghsId} 金额 和 订单总合 不一致 $ghsSaveDebtAmount $hdCgOrderDebtAmount ", '15280215347');
  98. // echo "已更:".$hdCgOrderDebtAmount.' '.$ghsOrderDebtAmount."\n";
  99. // \bizHd\ghs\classes\GhsClass::updateById($ghsId, ['debtAmount' => $hdCgOrderDebtAmount]);
  100. // CustomClass::updateById($customId, ['debtAmount' => $ghsOrderDebtAmount]);
  101. continue;
  102. }
  103. }
  104. }
  105. }
  106. }
  107. }
  108. }