CustomController.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <?php
  2. namespace console\controllers;
  3. use biz\shop\classes\ShopClass;
  4. use bizGhs\custom\models\Custom;
  5. use bizGhs\order\classes\OrderClass;
  6. use bizHd\custom\classes\CustomClass;
  7. use bizHd\purchase\classes\PurchaseClass;
  8. use common\components\noticeUtil;
  9. use common\components\util;
  10. use bizHd\user\classes\UserClass;
  11. use Overtrue\ChineseCalendar\Calendar;
  12. use yii\console\Controller;
  13. class CustomController extends Controller
  14. {
  15. //欠款信息不一致跟踪 ssh 20220307 ./yii custom/adjust-debt
  16. public function actionAdjustDebt()
  17. {
  18. //感觉好像没有用了,可以停了 ssh 20250724
  19. util::stop();
  20. ini_set('memory_limit', '2045M');
  21. set_time_limit(0);
  22. $shopList = ShopClass::getAllByCondition(['ptStyle' => 2], null, '*', null, true);
  23. if (empty($shopList)) {
  24. return false;
  25. }
  26. foreach ($shopList as $key => $shop) {
  27. $shopId = $shop->id ?? 0;
  28. $query = new \yii\db\Query();
  29. $query->from(Custom::tableName());
  30. $query->where(['ownShopId' => $shopId]);
  31. $query->orderBy('addTime ASC');
  32. foreach ($query->batch(50) as $customList) {
  33. if (!empty($customList)) {
  34. foreach ($customList as $custom) {
  35. //$customName = $custom['name'] ?? '';
  36. $customId = $custom['id'] ?? 0;
  37. $where = ['customId' => $customId, 'debt' => 1];
  38. $orderList = OrderClass::getAllByCondition($where, 'addTime DESC', '*');
  39. $ghsOrderDebtAmount = 0;
  40. if (!empty($orderList)) {
  41. foreach ($orderList as $order) {
  42. $actPrice = $order['remainDebtPrice'] ?? 0;
  43. $ghsOrderDebtAmount = bcadd($ghsOrderDebtAmount, $actPrice, 2);
  44. }
  45. }
  46. $ghsId = $custom['ghsId'] ?? 0;
  47. $ghs = \bizHd\ghs\classes\GhsClass::getById($ghsId);
  48. $where = ['ghsId' => $ghsId, 'debt' => PurchaseClass::DEBT_YES];
  49. $cgList = PurchaseClass::getAllByCondition($where, 'addTime DESC', '*');
  50. $hdCgOrderDebtAmount = 0;
  51. if (!empty($cgList)) {
  52. foreach ($cgList as $cg) {
  53. $actPrice = $cg['remainDebtPrice'] ?? 0;
  54. $hdCgOrderDebtAmount = bcadd($hdCgOrderDebtAmount, $actPrice, 2);
  55. }
  56. }
  57. if ($ghsOrderDebtAmount < 0 || $hdCgOrderDebtAmount < 0) {
  58. noticeUtil::push("!!!!!!!供货商 {$ghsId} 客户id {$customId} 出现负数 $ghsOrderDebtAmount $hdCgOrderDebtAmount", '15280215347');
  59. echo "@@@@@@@@@@@@@供货商 {$ghsId} 客户id {$customId} 出现负数 $ghsOrderDebtAmount $hdCgOrderDebtAmount \n";
  60. }
  61. $ghsOrderDebtAmount = floatval($ghsOrderDebtAmount);
  62. $hdCgOrderDebtAmount = floatval($hdCgOrderDebtAmount);
  63. if ($ghsOrderDebtAmount != $hdCgOrderDebtAmount) {
  64. noticeUtil::push("!!!!!!!供货商 {$ghsId} 客户id {$customId} 二边欠款单总金额不一致", '15280215347');
  65. echo "---------供货商 {$ghsId} 客户id {$customId} 二边 欠款单 总金额 不一致 {$ghsOrderDebtAmount} {$hdCgOrderDebtAmount} \n";
  66. continue;
  67. }
  68. $customSaveDebtAmount = $custom['debtAmount'] ? floatval($custom['debtAmount']) : 0;
  69. $ghsSaveDebtAmount = $ghs['debtAmount'] ? floatval($ghs['debtAmount']) : 0;
  70. if ($customSaveDebtAmount != $ghsOrderDebtAmount) {
  71. echo "*********客户 {$customId} 欠款 和 订单总额 不一致 $customSaveDebtAmount $ghsOrderDebtAmount \n";
  72. noticeUtil::push("*********客户 {$customId} 欠款总金额 和 订单总合 不一致 $customSaveDebtAmount $ghsOrderDebtAmount ", '15280215347');
  73. continue;
  74. }
  75. if ($ghsSaveDebtAmount != $hdCgOrderDebtAmount) {
  76. echo "#########欠供货商 {$ghsId} 和 订单总额 不一致 $ghsSaveDebtAmount $hdCgOrderDebtAmount \n";
  77. noticeUtil::push("#########欠供货商 {$ghsId} 金额 和 订单总合 不一致 $ghsSaveDebtAmount $hdCgOrderDebtAmount ", '15280215347');
  78. continue;
  79. }
  80. }
  81. }
  82. }
  83. }
  84. }
  85. //每天凌晨2点执行,取出所有 lunar==1 的 且 birthdayTime 小于当前时间的客户,然后把他们的阴历转阳历,然后更新他们的 birthdayTime
  86. public function actionUpdateBirthday()
  87. {
  88. $calendar = new Calendar();
  89. $customList = CustomClass::getAllByCondition(['lunar' => 1, 'birthdayTime<' => time()], null, 'id, userId, birthday, birthdayTime, birthdayMonth, birthdayDate', null, true);
  90. foreach ($customList as $custom) {
  91. $birthdayMonth = $custom->birthdayMonth;
  92. $birthdayDate = $custom->birthdayDate;
  93. $year = date("Y");
  94. // 农历转公历
  95. $result = $calendar->lunar($year, $birthdayMonth, $birthdayDate);
  96. $month = $result['gregorian_month'];
  97. $day = $result['gregorian_day'];
  98. $birthday = $year . '-' . $month . '-' . $day;
  99. // 如果今年的生日已经过去,则计算明年的生日
  100. if (strtotime($birthday) < strtotime(date('Y-m-d'))) {
  101. $year++;
  102. $result = $calendar->lunar($year, $birthdayMonth, $birthdayDate);
  103. $month = $result['gregorian_month'];
  104. $day = $result['gregorian_day'];
  105. $birthday = $year . '-' . $month . '-' . $day;
  106. }
  107. $custom->birthday = $birthday;
  108. $custom->birthdayTime = strtotime($birthday);
  109. $custom->save();
  110. UserClass::updateById($custom->userId, [
  111. 'birthday' => $birthday,
  112. 'birthdayTime' => $custom->birthdayTime
  113. ]);
  114. }
  115. }
  116. //批量创建客户
  117. private function createCustomer()
  118. {
  119. //重新写这个方法,用rabbitMQ来实现
  120. }
  121. //批发端分店从首店同步客户
  122. private function copyCustomers()
  123. {
  124. //重新写这个方法,用rabbitMQ来实现
  125. }
  126. //从文件批量创建客户 ssh 20240426
  127. public function actionFileCreateCustom()
  128. {
  129. //重新写这个方法,用rabbitMQ来实现
  130. }
  131. }