| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- <?php
- namespace console\controllers;
- use biz\main\classes\MainClass;
- use biz\shop\classes\ShopAdminClass;
- use biz\shop\classes\ShopClass;
- use common\components\dict;
- use common\components\noticeUtil;
- use yii\console\Controller;
- use biz\sj\classes\CashClass;
- use Yii;
- class CashController extends Controller
- {
- //提现审核通过 ssh 20231016
- public function actionPass()
- {
- $cashList = CashClass::getAllByCondition(['status' => 1], null, '*', null, true);
- if (empty($cashList)) {
- return false;
- }
- foreach ($cashList as $cash) {
- //事务处理
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- $remark = '系统自动提现';
- $shopId = $cash->shopId;
- $orderSn = $cash->orderSn ?? '';
- $shop = ShopClass::getLockById($shopId);
- if (empty($shop)) {
- noticeUtil::push("提现审核失败,没有找到门店77,orderSn:" . $orderSn, '15280215347');
- continue;
- }
- $mainId = $shop->mainId ?? 0;
- $main = MainClass::getLockById($mainId);
- if (empty($main)) {
- noticeUtil::push("提现审核失败,没有main信息32,orderSn:" . $orderSn, '15280215347');
- continue;
- }
- $cashAmount = isset($cash->amount) ? floatval($cash->amount) : 0;
- if ($cashAmount <= 0) {
- CashClass::rollback($cash, $shop, $transaction, $cashAmount, $remark);
- noticeUtil::push("提现金额有问题,已回滚,orderSn:" . $orderSn, '15280215347');
- continue;
- }
- $getAmount = $cash->beAmount;
- $cashAccount = $main->cashAccount ?? '';
- $cashName = $main->cashName ?? '';
- $cashSn = $cash->orderSn;
- if (empty($cashSn)) {
- CashClass::rollback($cash, $shop, $transaction, $cashAmount, $remark);
- noticeUtil::push("没有找到订单号,已回滚,orderSn:" . $orderSn, '15280215347');
- continue;
- }
- if (bccomp($cashAmount, $main->freezeBalance) == 1) {
- CashClass::rollback($cash, $shop, $transaction, $cashAmount, $remark);
- noticeUtil::push("冻结金额不足提现,已回滚,orderSn:" . $orderSn, '15280215347');
- continue;
- }
- $cash->status = CashClass::STATUS_CHECK_YES;
- $cash->remark = $remark;
- $cash->getAmount = $getAmount;
- $cash->cashName = $cashName;
- $cash->cashAccount = $cashAccount;
- $cash->save();
- //扣掉冻结的金额
- $main->freezeBalance = bcsub($main->freezeBalance, $cashAmount, 2);
- $main->save();
- $transaction->commit();
- //noticeUtil::push("orderSn:" . $orderSn . " 提现审核通过 OK", '15280215347');
- } catch (\Exception $exception) {
- $transaction->rollBack();
- $msg = $exception->getMessage();
- noticeUtil::push("审核失败,错误信息:" . $msg . ",orderSn:" . $orderSn, '15280215347');
- }
- }
- }
- //自动提现 ssh 2023116
- public function actionAuto()
- {
- ini_set('memory_limit', '2045M');
- set_time_limit(0);
- $mainList = MainClass::getAllByCondition(['txBalance>' => 0], null, 'id,txBalance', null, true);
- if (empty($mainList)) {
- return false;
- }
- foreach ($mainList as $info) {
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- $mainId = $info->id;
- $shop = ShopClass::getByCondition(['mainId' => $mainId], true);
- if (empty($shop)) {
- $transaction->rollBack();
- noticeUtil::push("提现申请失败,没有找到门店78,mainId:" . $mainId, '15280215347');
- continue;
- }
- $shopAdmin = ShopAdminClass::getByCondition(['mainId' => $mainId], true);
- if (empty($shopAdmin)) {
- $transaction->rollBack();
- noticeUtil::push("提现申请失败,没有找到员工,mainId:" . $mainId, '15280215347');
- continue;
- }
- $shopId = $shop->id ?? 0;
- $sjId = $shop->sjId ?? 0;
- $ptStyle = $shop->ptStyle ?? 1;
- $staffName = $shopAdmin->name ?? '';
- $params['shopAdminName'] = $staffName;
- $params['shopId'] = $shopId;
- $params['sjId'] = $sjId;
- $params['ptStyle'] = $ptStyle;
- CashClass::addApply($params);
- $transaction->commit();
- //noticeUtil::push("mainId:" . $mainId . " 申请提现 OK", '15280215347');
- } catch (\Exception $exception) {
- $transaction->rollBack();
- $msg = $exception->getMessage();
- noticeUtil::push("提现申请失败,报错:" . $msg . ",mainId:" . $mainId, '15280215347');
- }
- }
- }
- }
|