CashController.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. namespace console\controllers;
  3. use biz\main\classes\MainClass;
  4. use biz\shop\classes\ShopAdminClass;
  5. use biz\shop\classes\ShopClass;
  6. use common\components\dict;
  7. use common\components\noticeUtil;
  8. use yii\console\Controller;
  9. use biz\sj\classes\CashClass;
  10. use Yii;
  11. class CashController extends Controller
  12. {
  13. //提现审核通过 ssh 20231016
  14. public function actionPass()
  15. {
  16. $cashList = CashClass::getAllByCondition(['status' => 1], null, '*', null, true);
  17. if (empty($cashList)) {
  18. return false;
  19. }
  20. foreach ($cashList as $cash) {
  21. //事务处理
  22. $connection = Yii::$app->db;
  23. $transaction = $connection->beginTransaction();
  24. try {
  25. $remark = '系统自动提现';
  26. $shopId = $cash->shopId;
  27. $orderSn = $cash->orderSn ?? '';
  28. $shop = ShopClass::getLockById($shopId);
  29. if (empty($shop)) {
  30. noticeUtil::push("提现审核失败,没有找到门店,orderSn:" . $orderSn, '15280215347');
  31. continue;
  32. }
  33. $mainId = $shop->mainId ?? 0;
  34. $main = MainClass::getLockById($mainId);
  35. if (empty($main)) {
  36. noticeUtil::push("提现审核失败,没有main信息,orderSn:" . $orderSn, '15280215347');
  37. continue;
  38. }
  39. $cashAmount = isset($cash->amount) ? floatval($cash->amount) : 0;
  40. if ($cashAmount <= 0) {
  41. CashClass::rollback($cash, $shop, $transaction, $cashAmount, $remark);
  42. noticeUtil::push("提现金额有问题,已回滚,orderSn:" . $orderSn, '15280215347');
  43. continue;
  44. }
  45. $miniCashAmount = dict::getDict('miniCashAmount');
  46. if ($cashAmount < $miniCashAmount) {
  47. if (getenv('YII_ENV') == 'production') {
  48. CashClass::rollback($cash, $shop, $transaction, $cashAmount, $remark);
  49. noticeUtil::push("余额不足{$miniCashAmount}元,已回滚,orderSn:" . $orderSn, '15280215347');
  50. continue;
  51. }
  52. }
  53. $getAmount = $cash->beAmount;
  54. $cashAccount = $main->cashAccount ?? '';
  55. $cashName = $main->cashName ?? '';
  56. $cashSn = $cash->orderSn;
  57. if (empty($cashSn)) {
  58. CashClass::rollback($cash, $shop, $transaction, $cashAmount, $remark);
  59. noticeUtil::push("没有找到订单号,已回滚,orderSn:" . $orderSn, '15280215347');
  60. continue;
  61. }
  62. if (bccomp($cashAmount, $main->freezeBalance) == 1) {
  63. CashClass::rollback($cash, $shop, $transaction, $cashAmount, $remark);
  64. noticeUtil::push("冻结金额不足提现,已回滚,orderSn:" . $orderSn, '15280215347');
  65. continue;
  66. }
  67. $cash->status = CashClass::STATUS_CHECK_YES;
  68. $cash->remark = $remark;
  69. $cash->getAmount = $getAmount;
  70. $cash->cashName = $cashName;
  71. $cash->cashAccount = $cashAccount;
  72. $cash->save();
  73. //扣掉冻结的金额
  74. $main->freezeBalance = bcsub($main->freezeBalance, $cashAmount, 2);
  75. $main->save();
  76. $transaction->commit();
  77. noticeUtil::push("orderSn:" . $orderSn . " 提现审核通过 OK", '15280215347');
  78. } catch (\Exception $exception) {
  79. $transaction->rollBack();
  80. $msg = $exception->getMessage();
  81. noticeUtil::push("审核失败,错误信息:" . $msg . ",orderSn:" . $orderSn, '15280215347');
  82. }
  83. }
  84. }
  85. //自动提现 ssh 2023116
  86. public function actionAuto()
  87. {
  88. ini_set('memory_limit', '2045M');
  89. set_time_limit(0);
  90. $mainList = MainClass::getAllByCondition(['txBalance>' => 0], null, 'id,txBalance', null, true);
  91. if (empty($mainList)) {
  92. return false;
  93. }
  94. foreach ($mainList as $info) {
  95. $connection = Yii::$app->db;
  96. $transaction = $connection->beginTransaction();
  97. try {
  98. $mainId = $info->id;
  99. $shop = ShopClass::getByCondition(['mainId' => $mainId], true);
  100. if (empty($shop)) {
  101. $transaction->rollBack();
  102. noticeUtil::push("提现申请失败,没有找到门店,mainId:" . $mainId, '15280215347');
  103. continue;
  104. }
  105. $shopAdmin = ShopAdminClass::getByCondition(['mainId' => $mainId], true);
  106. if (empty($shopAdmin)) {
  107. $transaction->rollBack();
  108. noticeUtil::push("提现申请失败,没有找到员工,mainId:" . $mainId, '15280215347');
  109. continue;
  110. }
  111. $shopId = $shop->id ?? 0;
  112. $sjId = $shop->sjId ?? 0;
  113. $ptStyle = $shop->ptStyle ?? 1;
  114. $staffName = $shopAdmin->name ?? '';
  115. $params['shopAdminName'] = $staffName;
  116. $params['shopId'] = $shopId;
  117. $params['sjId'] = $sjId;
  118. $params['ptStyle'] = $ptStyle;
  119. CashClass::addApply($params);
  120. $transaction->commit();
  121. noticeUtil::push("mainId:" . $mainId . " 申请提现 OK", '15280215347');
  122. } catch (\Exception $exception) {
  123. $transaction->rollBack();
  124. $msg = $exception->getMessage();
  125. noticeUtil::push("提现申请失败,报错:" . $msg . ",mainId:" . $mainId, '15280215347');
  126. }
  127. }
  128. }
  129. }