| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <?php
- /**
- * Created by PhpStorm.
- * User: wniu
- * Date: 2022/4/22
- * Time: 4:48 下午
- */
- namespace addons\JoinPay\common\global_func\withdraw_way;
- use common\components\payment\AlternativePay;
- use common\enums\PayTypeEnum;
- use common\models\common\PaymentTransfer;
- use services\common\PayService;
- class WithdrawWay
- {
- public static function getExtensionWithdrawWay()
- {
- $data = [
- 'joinpay' => '提现到银行卡-汇聚',
- ];
- return $data;
- }
- /**
- * 汇聚代付提现
- * User: wniu
- * Date: 2022/4/22
- * Time: 5:54 下午
- * * @param $cash
- * @throws \Exception
- */
- public static function extensionWithdrawPay($data): bool
- {
- $cash = $data['cash'];
- try {
- $paymentTransfer = new PaymentTransfer();
- $paymentTransfer->orderNo = PaymentTransfer::generate_order_no("TR");
- $paymentTransfer->title = $data['title']??'收益提现';
- $paymentTransfer->amount = $cash->actual_num;
- $paymentTransfer->transferType = PayTypeEnum::JOINPAY;
- $paymentTransfer->cashInfo = $cash;
- $paymentTransfer->source = $data['source']??1;
- $res = self::transfer($paymentTransfer);
- } catch (\Exception $e) {
- throw new \Exception($e->getMessage());
- }
- return $res;
- }
- public static function transfer($paymentTransfer): bool
- {
- $where = [
- 'order_no' => $paymentTransfer['orderNo'],
- 'user_id' => $paymentTransfer['user_id'],
- 'mall_id' => $paymentTransfer['mall_id']
- ];
- $model = PaymentTransfer::getOne([$where]);
- if (!$model) {
- $model = new PaymentTransfer();
- $model->transfer_order_no = $paymentTransfer->orderNo;
- $model->mall_id = $paymentTransfer->cashInfo->mall_id;
- $model->user_id = $paymentTransfer->cashInfo->user_id;
- $model->title = $paymentTransfer->title;
- $model->amount = $paymentTransfer->amount;
- $model->pay_type = $paymentTransfer->transferType;
- $model->is_pay = 0;
- $model->order_no = 'HM' . substr(md5($paymentTransfer->orderNo), 2);
- $model->created_at = time();
- $model->cashInfo = $paymentTransfer->cashInfo;
- $model->source = $paymentTransfer->source;
- }
- if ($model->is_pay == 1) {
- throw new \Exception('该订单号已经打款,请勿重复操作');
- }
- $t = \Yii::$app->db->beginTransaction();
- try {
- $obj = new AlternativePay([],$model->mall_id);
- $result =$obj->transfer($model, $paymentTransfer->user);
- if ($result) {
- $t->commit();
- return true;
- } else {
- throw new \Exception();
- }
- } catch (\Exception $e) {
- $t->rollBack();
- \Yii::error($e->getMessage());
- return false;
- }
- }
- }
|