request->post(); $res = Yii::$app->services->validate->validate($params, [ [['mobile', 'transfer_num'], 'required'], [[ 'transfer_num'], 'number'], ]); if ($res === false) throw new \Exception(Yii::$app->services->validate->getErrorMessage()); if($params['transfer_num'] < 0 ) throw new \Exception('转让数量错误'); //查询用户是否存在 $to_user = User::getUser([['=', 'mobile', $params['mobile']], ['=', 'mall_id', $this->mall_id]]); if(!$to_user) throw new \Exception('目标用户不存在'); if($to_user['id'] == $this->user_id) throw new \Exception('请选择目标用户'); $user_wallet = HigoWallet::getUserWallet($this->mall_id,$this->user_id); if (!$user_wallet || bccomp($user_wallet['hi_bei'], $params['transfer_num'], 10) < 0) { throw new \Exception('用户' . WalletLogic::getWalletTypeMsg($this->mall_id, HiGoEnum::WALLET_TYPE_HI_BEI) . '不足'); } //执行转让 $setting = \Yii::$app->services->setting->addons->get($this->mall_id, HiGoEnum::ADDONS_NAME, 'basic'); $hi_bei_transfer_enable = $setting['hi_bei_transfer_enable'] ?? 0; if(!$hi_bei_transfer_enable) throw new \Exception('系统不支持转让'); $name = $setting['hi_bei_name'] ?? '嗨贝'; //1. 扣除当前用户 嗨呗数量 $wallet_log = [ 'mall_id' => $this->mall_id, 'user_id' => $this->user_id, 'change_type' => CapitalLog::CHANGE_TYPE_SUB, 'change_num' => $params['transfer_num'] * -1, 'desc' => '转让'.$name.' 到'.$params['mobile'], 'source_table' => User::tableName(), 'source_table_id' => $to_user['id'], 'from_type' => HiGoEnum::FROM_TYPE_TRANSFER_HI_BEI, 'wallet_type' => HiGoEnum::WALLET_TYPE_HI_BEI, 'is_send' => false ]; $res = WalletLogic::handleInQueue($wallet_log,true); if(!$res){ throw new \Exception('转让失败:'.WalletLogic::getStaticError()); } //插入队列处理 $wallet_log['to_user_id'] = $to_user['id']; $wallet_log['to_user_mobile'] = $params['mobile']; $wallet_log['log_id'] = $res; $event = new \addons\HiGo\common\events\TransferEvent($this->mall_id); \Yii::$app->services->events->dispatch($event, $wallet_log, $event->listeners); return $this->success(); }catch (\Exception $e){ return $this->error($e->getMessage()); } } /** * 获取用户账户信息 */ public function actionGetUser() { try{ $higo_wallet = HigoWallet::getOne([['mall_id' => $this->mall_id, 'user_id' => $this->user_id, 'status' => StatusEnum::ENABLED]], true); $basic = Yii::$app->services->setting->addons->get($this->mall_id, HiGoEnum::ADDONS_NAME, 'basic'); $hi_bei_transfer_fee = $basic['hi_bei_transfer_fee'] ?? 0; $data = [ 'hi_bei' => $higo_wallet['hi_bei'] ?? 0, 'hi_bei_name' => $basic['hi_bei_name'] ?? '嗨贝', 'hi_value' => $higo_wallet['hi_value'] ?? 0, 'hi_value_name' => $basic['hi_value_name'] ?? '嗨值', 'freeze_hi_bei' => $higo_wallet['freeze_hi_bei'] ?? 0, 'freeze_hi_value' => $higo_wallet['freeze_hi_value'] ?? 0, 'hi_bei_transfer_fee' => $hi_bei_transfer_fee.'%' ]; return $this->success('success',$data); }catch (\Exception $e){ return $this->error($e->getMessage()); } } }