CustomController.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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\n\n\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. $customId = $custom['id'] ?? 0;
  52. $where = ['customId' => $customId, 'debt' => 1];
  53. $orderList = OrderClass::getAllByCondition($where, 'addTime DESC', '*');
  54. $ghsOrderDebtAmount = 0;
  55. if (!empty($orderList)) {
  56. foreach ($orderList as $order) {
  57. $actPrice = $order['actPrice'] ?? 0;
  58. $ghsOrderDebtAmount = bcadd($ghsOrderDebtAmount, $actPrice, 2);
  59. }
  60. }
  61. $ghsId = $custom['ghsId'] ?? 0;
  62. $ghs = \bizHd\ghs\classes\GhsClass::getById($ghsId);
  63. $where = ['ghsId' => $ghsId, 'debt' => PurchaseClass::DEBT_YES];
  64. $cgList = PurchaseClass::getAllByCondition($where, 'addTime DESC', '*');
  65. $hdCgOrderDebtAmount = 0;
  66. if (!empty($cgList)) {
  67. foreach ($cgList as $cg) {
  68. $actPrice = $cg['actPrice'] ?? 0;
  69. $hdCgOrderDebtAmount = bcadd($hdCgOrderDebtAmount, $actPrice, 2);
  70. }
  71. }
  72. if ($ghsOrderDebtAmount < 0 || $hdCgOrderDebtAmount < 0) {
  73. //noticeUtil::push("!!!!!!!供应商 {$ghsId} 客户id {$customId} 出现负数 $ghsOrderDebtAmount $hdCgOrderDebtAmount", '15280215347');
  74. echo "@@@@@@@@@@@@@供应商 {$ghsId} 客户id {$customId} 出现负数 $ghsOrderDebtAmount $hdCgOrderDebtAmount \n";
  75. }
  76. $ghsOrderDebtAmount = floatval($ghsOrderDebtAmount);
  77. $hdCgOrderDebtAmount = floatval($hdCgOrderDebtAmount);
  78. if ($ghsOrderDebtAmount != $hdCgOrderDebtAmount) {
  79. //noticeUtil::push("!!!!!!!供应商 {$ghsId} 客户id {$customId} 二边欠款单总金额不一致", '15280215347');
  80. echo "---------供应商 {$ghsId} 客户id {$customId} 二边 欠款单 总金额 不一致 {$ghsOrderDebtAmount} {$hdCgOrderDebtAmount} \n";
  81. continue;
  82. }
  83. $customSaveDebtAmount = $custom['debtAmount'] ? floatval($custom['debtAmount']) : 0;
  84. $ghsSaveDebtAmount = $ghs['debtAmount'] ? floatval($ghs['debtAmount']) : 0;
  85. if ($customSaveDebtAmount != $ghsOrderDebtAmount) {
  86. echo "*********客户 {$customId} 欠款 和 订单总额 不一致 $customSaveDebtAmount $ghsOrderDebtAmount \n";
  87. //noticeUtil::push("*********客户 {$customId} 欠款总金额 和 订单总合 不一致 $customSaveDebtAmount $ghsOrderDebtAmount ", '15280215347');
  88. echo "已更:".$hdCgOrderDebtAmount.' '.$ghsOrderDebtAmount."\n";
  89. \bizHd\ghs\classes\GhsClass::updateById($ghsId, ['debtAmount' => $hdCgOrderDebtAmount]);
  90. CustomClass::updateById($customId, ['debtAmount' => $ghsOrderDebtAmount]);
  91. continue;
  92. }
  93. if ($ghsSaveDebtAmount != $hdCgOrderDebtAmount) {
  94. echo "#########欠供应商 {$ghsId} 和 订单总额 不一致 $ghsSaveDebtAmount $hdCgOrderDebtAmount \n";
  95. //noticeUtil::push("#########欠供应商 {$ghsId} 金额 和 订单总合 不一致 $ghsSaveDebtAmount $hdCgOrderDebtAmount ", '15280215347');
  96. echo "已更:".$hdCgOrderDebtAmount.' '.$ghsOrderDebtAmount."\n";
  97. \bizHd\ghs\classes\GhsClass::updateById($ghsId, ['debtAmount' => $hdCgOrderDebtAmount]);
  98. CustomClass::updateById($customId, ['debtAmount' => $ghsOrderDebtAmount]);
  99. continue;
  100. }
  101. }
  102. }
  103. }
  104. }
  105. }
  106. }