CashController.php 5.4 KB

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