ClearController.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php
  2. namespace console\controllers;
  3. use biz\ghs\classes\GhsBackClass;
  4. use bizGhs\clear\classes\OrderCgClearClass;
  5. use bizGhs\clear\models\Clear;
  6. use bizGhs\custom\classes\CustomClass;
  7. use bizGhs\ghs\classes\GhsClass;
  8. use bizGhs\ghs\models\Ghs;
  9. use bizGhs\order\classes\OrderClass;
  10. use bizGhs\order\classes\PurchaseOrderClass;
  11. use bizHd\purchase\classes\PurchaseClass;
  12. use yii\console\Controller;
  13. use Yii;
  14. class ClearController extends Controller
  15. {
  16. //补回 xhOrderCgClear
  17. public function actionBc()
  18. {
  19. ini_set('memory_limit', '2045M');
  20. set_time_limit(0);
  21. if (getenv('YII_ENV') == 'production') {
  22. $autoId = 817342;
  23. } else {
  24. $autoId = 1426;
  25. }
  26. $query = new \yii\db\Query();
  27. $query->from(Clear::tableName());
  28. $query->where(['>', 'id', $autoId]);
  29. foreach ($query->batch(500) as $changeList) {
  30. $ids = array_column($changeList, 'id');
  31. $relate = OrderCgClearClass::getAllByCondition(['clearId' => ['in', $ids]], null, '*', 'clearId');
  32. $connection = Yii::$app->db;
  33. $transaction = $connection->beginTransaction();
  34. try {
  35. foreach ($changeList as $clear) {
  36. $clearId = $clear['id'] ?? 0;
  37. $clearSn = $clear['orderSn'] ?? '';
  38. $status = $clear['status'] ?? 1;
  39. $clearAmount = $clear['actPrice'] ?? 0;
  40. $purchaseIds = $clear['purchaseIds'] ?? '';
  41. $saleIds = $clear['saleIds'] ?? '';
  42. $clearStyle = $clear['clearStyle'] ?? 1;
  43. if (!isset($relate[$clearId])) {
  44. if ($clearStyle == 3) {
  45. if (!empty($purchaseIds)) {
  46. $purchaseIdList = explode(',', $purchaseIds);
  47. $purchaseInfo = PurchaseOrderClass::getAllByCondition(['id' => ['in', $purchaseIdList]], null, 'id,orderSn', 'id');
  48. foreach ($purchaseInfo as $purchase) {
  49. $purchaseId = $purchase['id'] ?? 0;
  50. $purchaseOrderSn = $purchase['orderSn'] ?? 0;
  51. $addData = ['orderId' => 0, 'orderSn' => '', 'cgId' => $purchaseId, 'cgSn' => $purchaseOrderSn,
  52. 'clearId' => $clearId, 'clearSn' => $clearSn, 'amount' => $clearAmount, 'status' => $status];
  53. OrderCgClearClass::add($addData);
  54. echo "ghs cg clearId {$clearId} OK ### \n";
  55. }
  56. } else {
  57. echo "供货商采购 clearId {$clearId} 有缺数据 \n";
  58. }
  59. } else {
  60. if (!empty($saleIds) && !empty($purchaseIds)) {
  61. $saleIdList = explode(',', $saleIds);
  62. $purchaseIdList = explode(',', $purchaseIds);
  63. $saleInfo = OrderClass::getAllByCondition(['id' => ['in', $saleIdList]], null, 'id,orderSn,purchaseId');
  64. $purchaseInfo = PurchaseClass::getAllByCondition(['id' => ['in', $purchaseIdList]], null, 'id,orderSn', 'id');
  65. if (!empty($saleInfo)) {
  66. foreach ($saleInfo as $sale) {
  67. $saleId = $sale['id'] ?? 0;
  68. $purchaseId = $sale['purchaseId'] ?? 0;
  69. $saleOrderSn = $sale['orderSn'] ?? '';
  70. $purchase = $purchaseInfo[$purchaseId] ?? [];
  71. if (empty($purchase)) {
  72. echo "purchase {$purchaseId} 没有找到 \n";
  73. exit();
  74. }
  75. $purchaseOrderSn = $purchase['orderSn'] ?? '';
  76. $addData = ['orderId' => $saleId, 'orderSn' => $saleOrderSn, 'cgId' => $purchaseId, 'cgSn' => $purchaseOrderSn,
  77. 'clearId' => $clearId, 'clearSn' => $clearSn, 'amount' => $clearAmount, 'status' => $status];
  78. OrderCgClearClass::add($addData);
  79. }
  80. echo "hd cg clearId {$clearId} OK *** \n";
  81. }
  82. } else {
  83. echo "花店采购 clearId {$clearId} 有缺数据 \n";
  84. }
  85. }
  86. } else {
  87. echo "有记录 {$clearId} \n";
  88. }
  89. }
  90. $transaction->commit();
  91. } catch (\Exception $e) {
  92. $transaction->rollBack();
  93. $msg = $e->getMessage();
  94. echo "报错了:" . $msg . "\n";
  95. }
  96. }
  97. }
  98. public function actionBalance()
  99. {
  100. ini_set('memory_limit', '2045M');
  101. set_time_limit(0);
  102. //$sql = "delete from xhGhsBack";
  103. //Yii::$app->db->createCommand($sql)->execute();
  104. $query = new \yii\db\Query();
  105. $query->from(Ghs::tableName());
  106. $query->where(['ownPtStyle' => 1]);
  107. $query->andWhere(['>', 'balance', 0]);
  108. foreach ($query->batch(500) as $ghsList) {
  109. $connection = Yii::$app->db;
  110. $transaction = $connection->beginTransaction();
  111. try {
  112. foreach ($ghsList as $ghs) {
  113. GhsBackClass::add($ghs);
  114. }
  115. $transaction->commit();
  116. } catch (\Exception $e) {
  117. $transaction->rollBack();
  118. $msg = $e->getMessage();
  119. echo "报错了:" . $msg . "\n";
  120. }
  121. }
  122. }
  123. public function actionGhsGhs()
  124. {
  125. ini_set('memory_limit', '2045M');
  126. set_time_limit(0);
  127. $query = new \yii\db\Query();
  128. $query->from(Ghs::tableName());
  129. $query->where(['ownPtStyle' => 2]);
  130. foreach ($query->batch(500) as $ghsList) {
  131. $connection = Yii::$app->db;
  132. $transaction = $connection->beginTransaction();
  133. try {
  134. foreach ($ghsList as $ghs) {
  135. $ghsId = $ghs['id'] ?? 0;
  136. $balance = PurchaseOrderClass::sum(['ghsId' => $ghsId, 'debt' => 1], 'actPrice');
  137. $debtNum = PurchaseOrderClass::getCount(['ghsId' => $ghsId, 'debt' => 1]);
  138. GhsClass::updateById($ghsId, ['balance' => -$balance, 'debtNum' => $debtNum]);
  139. $customId = $ghs['customId'] ?? 0;
  140. CustomClass::updateById($customId, ['balance' => -$balance, 'debtNum' => $debtNum]);
  141. }
  142. $transaction->commit();
  143. } catch (\Exception $e) {
  144. $transaction->rollBack();
  145. $msg = $e->getMessage();
  146. echo "报错了:" . $msg . "\n";
  147. }
  148. }
  149. }
  150. }