| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- <?php
- namespace backend\modules\mall\services;
- use common\enums\AssetsType;
- use common\enums\PayTypeEnum;
- use common\enums\RedisKeyEnum;
- use common\enums\StatusEnum;
- use common\enums\UserWalletEnum;
- use common\globals\GlobalInvoke;
- use common\helpers\LockHelper;
- use common\models\common\PaymentTransfer;
- use common\models\user\User;
- use common\models\user\UserInfo;
- use common\models\user\UserWithdrawLog as Withdraw;
- use common\models\user\UserWithdrawLog;
- use services\common\PayService;
- use services\common\UserWalletService;
- use yii\helpers\Json;
- class WithdrawalService extends \yii\base\BaseObject
- {
- public $log_id; // 提现记录id
- public $mall_id; // mall_id
- public $status; // 提现操作类型 1 审核通过 2 打款 3拒绝
- public $content = ''; // 备注
- public $topay_way = ''; // 打款渠道
- public $error = '';
- public function error($msg){
- $this->error = $msg;
- return false;
- }
- public function __construct ($config = [])
- {
- if(empty($config['mall_id'])){
- throw new \Exception('WithdrawalService mall_id Must have method property');
- }
- if(empty($config['log_id'])){
- throw new \Exception('WithdrawalService log_id Must have method property');
- }
- foreach ($config as $index=>$name) {
- if(!property_exists($this,$index)){
- unset($config[$index]);
- };
- }
- parent::__construct($config);
- }
- public function aliToPay()
- {
- $list = Withdraw::find()->where(['mall_id'=>$this->mall_id,'id'=>$this->log_id])->all();
- if(empty($list)) return $this->error("记录不存在");
- foreach ($list as $cash) {
- if ( $cash['status'] != 1) return $this->error("{$cash['order_no']}记录状态不正确");
- }
- $lock_key = RedisKeyEnum::suffix(RedisKeyEnum::LOCK_USER_CASH , 'alitopay_'.$this->mall_id);
- $uniqid = uniqid();
- // if (!LockHelper::lock($lock_key, $uniqid, 100, 100)) {
- // \Yii::error('cashForm 获取锁(' . $lock_key . ')失败阻塞,提现打款:cash,操作:save,金额:' . $cash->id);
- // return $this->error("操作频繁,请稍后重试~");
- // }
- $ids = array_column($list,'id');
- $pay_res = GlobalInvoke::exec(GlobalInvoke::INVOKE_WITHDRAW_ALITOPAY_PAY,$cash->mall_id,[
- 'ids'=>$ids,
- 'mall_id'=>$this->mall_id
- ]);
- if(!$pay_res['res']){
- return $this->error($pay_res['data']);
- }
- // 创建打款订单成功,修改成打款中状态
- foreach ($list as $cash) {
- // Withdraw::remit_wait($cash,'支付宝打款中...');
- // $res = Withdraw::updateAll(['content'=>Json::encode($content),'status'=>5],['id'=>$cash['id']]);
- }
- return $pay_res["data"];
- }
- // 代税宝
- public function avoidtaxToPay()
- {
- $list = Withdraw::find()->where(['mall_id'=>$this->mall_id,'id'=>$this->log_id])->all();
- if(empty($list)) return $this->error("记录不存在");
- foreach ($list as $cash) {
- if ( $cash['status'] != 1) return $this->error("{$cash['order_no']}记录状态不正确");
- }
- // $lock_key = RedisKeyEnum::suffix(RedisKeyEnum::LOCK_USER_CASH , 'avoidtax_'.$this->mall_id);
- // $uniqid = uniqid();
- // if (!LockHelper::lock($lock_key, $uniqid, 100, 100)) {
- // return $this->error("操作频繁,请稍后重试~");
- // }
- /* 代税宝 业务 start */
- $ids = array_column($list,'id');
- // addons\AvoidTax\common\service\OrderService
- $pay_res = GlobalInvoke::exec(GlobalInvoke::INVOKE_WITHDRAW_AVOIDTAX_PAY,$cash->mall_id,[
- 'ids'=>$ids,
- 'mall_id'=>$this->mall_id
- ]);
- if(!$pay_res['res']){
- return $this->error($pay_res['data']);
- }
- /* 代税宝 业务 end */
- // 创建打款订单成功,修改成打款中状态
- foreach ($list as $cash) {
- Withdraw::remit_wait($cash,'代税宝打款中...');
- }
- return $pay_res["data"];
- }
- /**
- * 银典代付
- *
- * @return false|array
- */
- public function yunfastPay()
- {
- $list = Withdraw::find()->where(['mall_id' => $this->mall_id, 'id' => $this->log_id])->all();
- if(empty($list)) return $this->error('记录不存在');
- foreach ($list as $cash) {
- if ($cash['status'] != 1) return $this->error("{$cash['order_no']}记录状态不正确");
- }
- $ids = array_column($list, 'id');
- $success_ids = GlobalInvoke::exec(GlobalInvoke::INVOKE_WITHDRAW_YUNFAST_PAY, $cash->mall_id, [
- 'ids' => $ids,
- 'mall_id' => $this->mall_id
- ]);
- return $success_ids;
- }
- /**
- * 银企直联
- *
- * @return void
- */
- public function banktaxToPay()
- {
- $list = Withdraw::find()
- ->where([
- 'mall_id' => $this->mall_id,
- 'id' => $this->log_id,
- 'type' => 'bank_tax',
- 'status' => UserWithdrawLog::STATUS_AGREE,
- ])
- ->all();
- if (empty($list)) {
- return $this->error('记录不存在');
- }
- // 合规提现业务
- $ids = array_column($list, 'id');
- $pay_res = GlobalInvoke::exec(GlobalInvoke::INVOKE_WITHDRAW_BANKTAX_PAY, $this->mall_id, [
- 'ids' => $ids,
- 'mall_id' => $this->mall_id,
- ]);
- if (!$pay_res['res']) {
- return $this->error($pay_res['data']);
- }
- // 创建打款订单成功,修改成打款中状态
- foreach ($list as $cash) {
- Withdraw::remit_wait($cash, '银企直联打款中...');
- }
- return $pay_res['data'];
- }
- /**
- * 点薪灵工
- *
- * @return void
- */
- public function linggongToPay($params)
- {
- $list = Withdraw::find()
- ->where([
- 'mall_id' => $this->mall_id,
- 'id' => $this->log_id,
- 'type' => 'linggong',
- 'status' => [UserWithdrawLog::STATUS_AGREE, UserWithdrawLog::STATUS_APPLY],
- ])
- ->all();
- if (empty($list)) {
- return $this->error('记录不存在');
- }
- // 合规提现业务
- $ids = array_column($list, 'id');
- $pay_res = GlobalInvoke::exec(GlobalInvoke::INVOKE_WITHDRAW_LINGGONG_PAY, $this->mall_id, [
- 'ids' => $ids,
- 'mall_id' => $this->mall_id,
- 'task_id' => $params['task_id'],
- ]);
- if (!$pay_res['res']) {
- return $this->error($pay_res['data']);
- }
- // 创建打款订单成功,修改成打款中状态
- foreach ($list as $cash) {
- Withdraw::remit_wait($cash, '点薪灵工打款中...');
- }
- return $pay_res['data'];
- }
- }
|