CustomController.php 5.2 KB

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