CashController.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. $status = $cash->status;
  27. $shopId = $cash->shopId;
  28. $orderSn = $cash->orderSn ?? '';
  29. $shop = ShopClass::getLockById($shopId);
  30. if (empty($shop)) {
  31. noticeUtil::push("提现审核失败,没有找到门店,orderSn:" . $orderSn, '15280215347');
  32. break;
  33. }
  34. $mainId = $shop->mainId ?? 0;
  35. $main = MainClass::getLockById($mainId);
  36. if (empty($main)) {
  37. noticeUtil::push("提现审核失败,没有main信息,orderSn:" . $orderSn, '15280215347');
  38. break;
  39. }
  40. $cashAmount = isset($cash->amount) ? floatval($cash->amount) : 0;
  41. if ($cashAmount <= 0) {
  42. CashClass::rollback($cash, $shop, $transaction, $cashAmount, $remark);
  43. noticeUtil::push("提现金额有问题,已回滚,orderSn:" . $orderSn, '15280215347');
  44. break;
  45. }
  46. $miniCashAmount = dict::getDict('miniCashAmount');
  47. if ($cashAmount < $miniCashAmount) {
  48. if (getenv('YII_ENV') == 'production') {
  49. CashClass::rollback($cash, $shop, $transaction, $cashAmount, $remark);
  50. noticeUtil::push("余额不足{$miniCashAmount}元,已回滚,orderSn:" . $orderSn, '15280215347');
  51. break;
  52. }
  53. }
  54. $getAmount = $cash->beAmount;
  55. if ($status != CashClass::STATUS_CHECK_YES) {
  56. CashClass::rollback($cash, $shop, $transaction, $cashAmount, $remark);
  57. noticeUtil::push("已审核过,已回滚,orderSn:" . $orderSn, '15280215347');
  58. break;
  59. }
  60. $cashAccount = $main->cashAccount ?? '';
  61. $cashName = $main->cashName ?? '';
  62. $cashSn = $cash->orderSn;
  63. if (empty($cashSn)) {
  64. CashClass::rollback($cash, $shop, $transaction, $cashAmount, $remark);
  65. noticeUtil::push("没有找到订单号,已回滚,orderSn:" . $orderSn, '15280215347');
  66. break;
  67. }
  68. if (bccomp($cashAmount, $main->freezeBalance) == 1) {
  69. CashClass::rollback($cash, $shop, $transaction, $cashAmount, $remark);
  70. noticeUtil::push("冻结金额不足提现,已回滚,orderSn:" . $orderSn, '15280215347');
  71. break;
  72. }
  73. $cash->status = CashClass::STATUS_CHECK_YES;
  74. $cash->remark = $remark;
  75. $cash->getAmount = $getAmount;
  76. $cash->cashName = $cashName;
  77. $cash->cashAccount = $cashAccount;
  78. $cash->save();
  79. //扣掉冻结的金额
  80. $main->freezeBalance = bcsub($main->freezeBalance, $cashAmount, 2);
  81. $main->save();
  82. $transaction->commit();
  83. } catch (\Exception $exception) {
  84. $transaction->rollBack();
  85. $msg = $exception->getMessage();
  86. noticeUtil::push("审核失败,错误信息:" . $msg . ",orderSn:" . $orderSn, '15280215347');
  87. }
  88. }
  89. }
  90. //自动提现 ssh 2023116
  91. public function actionAuto()
  92. {
  93. ini_set('memory_limit', '2045M');
  94. set_time_limit(0);
  95. $mainList = MainClass::getAllByCondition(['txBalance>' => 0], null, 'id,txBalance', null, true);
  96. if (empty($mainList)) {
  97. return false;
  98. }
  99. foreach ($mainList as $info) {
  100. $connection = Yii::$app->db;
  101. $transaction = $connection->beginTransaction();
  102. try {
  103. $mainId = $info->id;
  104. $shop = ShopClass::getByCondition(['mainId' => $mainId], true);
  105. if (empty($shop)) {
  106. $transaction->rollBack();
  107. noticeUtil::push("提现申请失败,没有找到门店,mainId:" . $mainId, '15280215347');
  108. break;
  109. }
  110. $shopAdmin = ShopAdminClass::getByCondition(['mainId' => $mainId], true);
  111. if (empty($shopAdmin)) {
  112. $transaction->rollBack();
  113. noticeUtil::push("提现申请失败,没有找到员工,mainId:" . $mainId, '15280215347');
  114. break;
  115. }
  116. $shopId = $shop->id ?? 0;
  117. $sjId = $shop->sjId ?? 0;
  118. $ptStyle = $shop->ptStyle ?? 1;
  119. $staffName = $shopAdmin->name ?? '';
  120. $params['shopAdminName'] = $staffName;
  121. $params['shopId'] = $shopId;
  122. $params['sjId'] = $sjId;
  123. $params['ptStyle'] = $ptStyle;
  124. CashClass::addApply($params);
  125. $transaction->commit();
  126. echo $mainId . " OK \n";
  127. } catch (\Exception $exception) {
  128. $transaction->rollBack();
  129. $msg = $exception->getMessage();
  130. noticeUtil::push("提现申请失败,报错:" . $msg . ",mainId:" . $mainId, '15280215347');
  131. }
  132. }
  133. }
  134. }