diff --git a/.env b/.env index cb3a8ac..f76b5e8 100644 --- a/.env +++ b/.env @@ -1,4 +1,4 @@ -APP_DEBUG =true +APP_DEBUG = true [APP] DEFAULT_TIMEZONE = Asia/Shanghai @@ -6,7 +6,7 @@ CROSS_ORIGIN = true [DATABASE] TYPE = mysql -HOSTNAME = 127.0.0.1 +HOSTNAME = 206.168.191.15 DATABASE = bourse USERNAME = root PASSWORD = Meetingyou0))2024$ @@ -19,7 +19,7 @@ prefix = bot_ default_lang = zh-cn [REDIS] -HOST = 127.0.0.1 +HOST = 206.168.191.15 PORT = 26379 SELECT = 0 PASSWORD = 7d00cb62-1d1c-4c86-b50a-ebf9f00cc9fd @@ -57,10 +57,8 @@ BASE_URL=http://testmg.coincosmic.net AGENT_GROUP_ID=6 [QUOTE] -BASE_URL=10.154.0.8:88 -DEAL_BASE_URL=http://10.154.0.7:8000 - - +BASE_URL = 127.0.0.1:88 +DEAL_BASE_URL = 127.0.0.1:8024 [FEATURE] HAS_TEAM = true @@ -97,3 +95,6 @@ NO_APPLY=1 [ACCOUT_TYPE] ALL_IN_ONE=1 + +[CHAT_SERVER] +BASE_URL = https://chat.jblmgzq.com \ No newline at end of file diff --git a/app/admin/controller/Init.php b/app/admin/controller/Init.php new file mode 100644 index 0000000..e8f2268 --- /dev/null +++ b/app/admin/controller/Init.php @@ -0,0 +1,24 @@ +initAdminChatInfo(); + return json($result); + } + + // 获取已注册的用户,遍历每个用户去注册聊天账号,然后与管理员添加聊天好友,并加入到管理员的群聊中 + public function initUserChatInfo() + { + $initService = new InitService(); + $result = $initService->initUserChatInfo($this->request->param()); + return json($result); + } +} \ No newline at end of file diff --git a/app/admin/route/app.php b/app/admin/route/app.php index d97a334..93d9e2f 100644 --- a/app/admin/route/app.php +++ b/app/admin/route/app.php @@ -647,3 +647,7 @@ Route::get('/setting/in_option_refresh', 'setting.Option/refresh'); // 修改 印度股-source Route::post('/update_source', 'Index/updateSource'); +// P1项目初始化管理员注册chat信息,用户注册chat信息,用户加入管理员的聊天群组 +Route::get('/init_admin_chat_info', 'Init/initAdminChatInfo'); //管理员注册chat账号,创建聊天群组 +Route::get('/init_user_Chat_info', 'Init/initUserChatInfo'); // 用户注册chat信息,用户添加管理员chat好友,用户加入管理员聊天群组 + diff --git a/app/admin/service/AdminBaseService-pro.php b/app/admin/service/AdminBaseService-pro.php deleted file mode 100644 index 5b78c09..0000000 --- a/app/admin/service/AdminBaseService-pro.php +++ /dev/null @@ -1,927 +0,0 @@ -connect($config['host'], $config['port'], 10); - } catch (\Exception $exception) { - echo 'redis连接失败'; - } - if (!empty($config['password'])) { - $redis->auth($config['password']); - } - - $redis->select($config['select']); - return $redis; - } - - - /** - * @param string $code // 状态码 - * @param string $msg // 提示信息 - * @param array $result // 返回结果 - * @return array - */ - public function toData(string $code = '', string $msg = '', array $result = []): array - { - return [ - 'code' => $code, - 'message' => $msg, - 'data' => $result - ]; - } - - // 根据是否是代理 以及用户id 获取where条件 - public function getWhereByIsAgentAndUserId($adminId, $where, $userId) - { - // 判断是否是代理 - $isAgent = AdminModel::checkUserIsAgent($adminId); - // 不是代理 - if (!$isAgent) { - if ($userId > 0) { - $where[] = ['user_id', '=', $userId]; - } - return $where; - } - - // 获取管理用户 - $userIds = AdminModel::getUserIdsByAgentId($adminId); - if (empty($userIds)) { - return false; - } - - // 如果用户搜索 - if ($userId > 0) { - $where[] = ['user_id', 'in', $userIds]; - $where[] = ['user_id', '=', $userId]; - return $where; - } - - // 没有用户搜索 - $where[] = ['user_id', 'in', $userIds]; - return $where; - } - - // 校验admin_id 是否可以管理 userId - public function checkUserIdInAgent($adminId, $userId) - { - // 判断是否是代理 - $isAgent = AdminModel::checkUserIsAgent($adminId); - // 不是代理 - if (!$isAgent) { - return true; - } - - $userIds = AdminModel::getUserIdsByAgentId($adminId); - if (in_array($userId, $userIds)) { - return true; - } - - return false; - - } - - - /** - * @param $user_id - * @param $account_type - * @param $change_usable_num - * @param $change_frozen_num - * @param $change_type 变动类型:1-充值,2-提现,3-买入,4-卖出,5-冻结,6-解冻,7-账户转出,8-账户转入 ,9-注册返佣,10-开仓返佣 ,11-平仓返佣,12-调账加钱 13-调账减钱 19-基金返息 20-IPO订单退款 - */ - public function updateUserAsset($user_id, $account_type, $change_type, $change_usable_num, $change_frozen_num = 0, $order_no = "", $change_log_admin_id = 0, $rate = 0) - { - $prefix = env('database.prefix'); - $where['user_id'] = $user_id; - switch ($account_type) { - case 1: - $where['digital_id'] = 'USDT'; - $table = $prefix . 'user_digital'; - $log_table = $prefix . 'user_digital_log'; - $log_data['digital_id'] = 'USDT'; - break; - case 2: - $where['contract_id'] = 'USDT'; - $table = $prefix . 'user_contract'; - $log_table = $prefix . 'user_contract_log'; - $log_data['contract_id'] = 'USDT'; - break; - case 3: - $where['stock_id'] = 'USD'; - $table = $prefix . 'user_stock'; - $log_table = $prefix . 'user_stock_log'; - $log_data['stock_id'] = 'USD'; - break; - case 4: - $where['stock_id'] = 'IDR'; - $table = $prefix . 'user_stock_idn'; - $log_table = $prefix . 'user_stock_idn_log'; - $log_data['stock_id'] = 'IDR'; - break; - case 5: - $where['stock_id'] = 'MYR'; - $table = $prefix . 'user_stock_mys'; - $log_table = $prefix . 'user_stock_mys_log'; - $log_data['stock_id'] = 'MYR'; - break; - case 6: - $where['stock_id'] = 'THB'; - $table = $prefix . 'user_stock_tha'; - $log_table = $prefix . 'user_stock_tha_log'; - $log_data['stock_id'] = 'THB'; - break; - case 7: - $where['stock_id'] = 'INR'; - $table = $prefix . 'user_stock_in'; - $log_table = $prefix . 'user_stock_in_log'; - $log_data['stock_id'] = 'INR'; - break; - case 8: - $where['contract_id'] = 'USDT'; - $table = $prefix . 'user_contract_sec'; - $log_table = $prefix . 'user_contract_sec_log'; - $log_data['contract_id'] = 'USDT'; - break; - case 9: - $where['stock_id'] = 'SGD'; - $table = $prefix . 'user_stock_sgd'; - $log_table = $prefix . 'user_stock_sgd_log'; - $log_data['stock_id'] = 'SGD'; - break; - case 10: - $where['stock_id'] = 'USD'; - $table = $prefix . 'user_stock_fund'; - $log_table = $prefix . 'user_stock_fund_log'; - $log_data['stock_id'] = 'USD'; - break; - case 11: - $where['stock_id'] = 'INR'; - $table = $prefix . 'user_stock_option_inr'; - $log_table = $prefix . 'user_stock_option_inr_log'; - $log_data['stock_id'] = 'INR'; - break; - case 12: - $where['stock_id'] = 'HKD'; - $table = $prefix . 'user_stock_hkd'; - $log_table = $prefix . 'user_stock_hkd_log'; - $log_data['stock_id'] = 'HKD'; - break; - case 14: - $where['stock_id'] = 'GBX'; - $table = $prefix . 'user_stock_gbx'; - $log_table = $prefix . 'user_stock_gbx_log'; - $log_data['stock_id'] = 'GBX'; - break; - case 15: - $where['stock_id'] = 'EUR'; - $table = $prefix . 'user_stock_fur'; - $log_table = $prefix . 'user_stock_fur_log'; - $log_data['stock_id'] = 'EUR'; - break; - case 16: - $where['stock_id'] = 'EUR'; - $table = $prefix . 'user_stock_eur'; - $log_table = $prefix . 'user_stock_eur_log'; - $log_data['stock_id'] = 'EUR'; - break; - case 17: - $where['stock_id'] = 'BRL'; - $table = $prefix . 'user_stock_brl'; - $log_table = $prefix . 'user_stock_brl_log'; - $log_data['stock_id'] = 'BRL'; - break; - case 18: - $where['stock_id'] = 'JPY'; - $table = $prefix . 'user_stock_jp'; - $log_table = $prefix . 'user_stock_jp_log'; - $log_data['stock_id'] = 'JPY'; - break; - case 19: - $where['contract_id'] = 'USD'; - $table = $prefix . 'user_forex'; - $log_table = $prefix . 'user_forex_log'; - $log_data['contract_id'] = 'USD'; - break; - default: - return [ - 'status' => 100, - 'msg' => '账户类型错误' - ]; - break; - } - Db::startTrans(); - try { - //user_stock USD - $account_info = Db::table($table)->where($where)->lock(true)->find(); - if (empty($account_info)) { - $insert_data = [ - 'user_id' => $user_id, - 'usable_num' => 0, - 'frozen_num' => 0, - 'create_time' => date('Y-m-d H:i:s'), - 'update_time' => date('Y-m-d H:i:s') - ]; - if (in_array($account_type, [1, 2, 8,19])) { - $insert_data['contract_id'] = $where['contract_id']; - } else { - $insert_data['stock_id'] = $where['stock_id']; - - } - // 不存在 则新增 - Db::table($table)->insert($insert_data); - - $account_info = Db::table($table)->where($where)->lock(true)->find(); - if (empty($account_info)) { - Db::rollback(); - return [ - 'status' => 300, - 'msg' => '用户资金账号不存在' - ]; - } - - } - - $last_usable_num = bcadd($account_info['usable_num'], $change_usable_num, 18); - $last_frozen_num = bcadd($account_info['frozen_num'], $change_frozen_num, 18); - if ($last_usable_num < 0) { - Db::rollback(); - return [ - 'status' => 400, - 'msg' => '可用资金不能为负' - ]; - } - - if ($change_type == 6) { - if ($last_frozen_num < 0 && abs($last_frozen_num) > 0.01) { - Db::rollback(); - return [ - 'status' => 400, - 'msg' => '冻结资金不能为负' - ]; - } elseif (abs($last_frozen_num) < 0.01) { - $last_frozen_num = 0; - } - } else { - if ($last_frozen_num < 0) { - Db::rollback(); - return [ - 'status' => 400, - 'msg' => '冻结资金不能为负' - ]; - } - } - - $change_data['usable_num'] = $last_usable_num; - $change_data['frozen_num'] = $last_frozen_num; - $change_data['update_time'] = date('Y-m-d H:i:s'); - $change_bool = Db::table($table)->where($where)->update($change_data); - if ($change_bool == 0) { - Db::rollback(); - return [ - 'status' => 100, - 'msg' => '账户修改失败' - ]; - } - - //echo Db::table($table)->where($where)->getLastSql(); - $log_data['user_id'] = $user_id; - $log_data['change_type'] = $change_type; - $log_data['before_num'] = $account_info['usable_num']; - $log_data['change_num'] = $change_usable_num; - $log_data['create_time'] = date('Y-m-d H:i:s'); - $log_data['update_time'] = date('Y-m-d H:i:s'); - if (!empty($order_no)) { - $log_data['order_id'] = $order_no; - } - $log_bool = Db::table($log_table)->insert($log_data); - if (!$log_bool) { - Db::rollback(); - return [ - 'status' => 100, - 'msg' => '账户流水插入失败' - ]; - } - - //后台系统 变更用户余额 - //需要录入变更日志 bot_user_balance_change_log - if (in_array($change_type, [12, 13]) && $change_log_admin_id > 0 && $rate != 0) { - $balance_change_log["user_id"] = $user_id; - $balance_change_log["type"] = $account_type; - $balance_change_log['before_num'] = bcdiv($account_info['usable_num'], $rate, 18); - $balance_change_log["change_num"] = bcdiv($change_usable_num, $rate, 18); - $balance_change_log["currency_rate"] = $rate; - $balance_change_log["admin_id"] = $change_log_admin_id; - $balance_change_log["create_time"] = date('Y-m-d H:i:s'); - $balance_log_bool = Db::table('bot_user_balance_change_log')->insert($balance_change_log); - if (!$balance_log_bool) { - Db::rollback(); - return [ - 'status' => 100, - 'msg' => '上分 - 账户流水插入失败' - ]; - } - } - - Db::commit(); - return [ - 'status' => 200, - 'msg' => 'ok' - ]; - } catch (ValidateException|PDOException|\Exception $e) { - Db::rollback(); - return [ - 'status' => 100, - 'msg' => $e->getMessage(), - 'data'=>[$e->getTrace()] - ]; - } - } - public function updateUserAssetNew($user_id,$change_type,$change_usable_num,$change_frozen_num = 0, $order_no = ""){ - Db::startTrans(); - try{ - $account_info = UserMoneyModel::where('user_id',$user_id)->where('stock_id','USD')->lock(true)->find(); - if (empty($account_info)) { - UserMoneyModel::InsertUserMoneyk([ - 'user_id' => $user_id, - 'stock_id' => 'USD', - 'usable_num' => 0, - 'frozen_num' => 0, - ]); - $account_info = UserMoneyModel::where('user_id', $user_id)->where('stock_id', 'USD')->lock(true)->find(); - if (empty($account_info)) { - Db::rollback(); - return [ - 'status' => 300, - 'msg' => '用户资金账号不存在' - ]; - } - } - - $last_usable_num = bcadd($account_info['usable_num'], $change_usable_num, 18); - $last_frozen_num = bcadd($account_info['frozen_num'], $change_frozen_num, 18); - - if ($last_usable_num < 0) { - Db::rollback(); - return [ - 'status' => 400, - 'msg' => '可用资金不能为负' - ]; - } - if ($change_type == 6) { - if ($last_frozen_num < 0 && abs($last_frozen_num) > 0.01) { - Db::rollback(); - return [ - 'status' => 400, - 'msg' => '冻结资金不能为负' - ]; - } elseif (abs($last_frozen_num) < 0.01) { - $last_frozen_num = 0; - } - } else { - if ($last_frozen_num < 0) { - Db::rollback(); - return [ - 'status' => 400, - 'msg' => '冻结资金不能为负' - ]; - } - } - - $res=UserMoneyModel::where('user_id',$user_id)->where('stock_id','USD')->update([ - 'usable_num'=>$last_usable_num, - 'frozen_num'=>$last_frozen_num, - 'update_time'=>date('Y-m-d H:i:s'), - ]); - if(!$res){ - Db::rollback(); - return [ - 'status' => 400, - 'msg' => '资金操作异常' - ]; - } - $log_bool=UserMoneyLogModel::InsertUserBalanceLog([ - 'user_id'=>$user_id, - 'change_type'=>$change_type, - 'stock_id'=>'USD', - 'martket_type'=>0, - 'before_num'=>$account_info['usable_num'], - 'change_num'=>$change_usable_num, - 'create_time'=>date('Y-m-d H:i:s'), - 'update_time'=>date('Y-m-d H:i:s'), - ]); - if (!$log_bool) { - Db::rollback(); - return [ - 'status' => 100, - 'msg' => '账户流水插入失败' - ]; - } - Db::commit(); - return [ - 'status' => 200, - 'msg' => 'ok' - ]; - - } catch (ValidateException|PDOException|\Exception $e) { - Db::rollback(); - return [ - 'status' => 100, - 'msg' => $e->getMessage(), - 'data' => [$e->getTrace()] - ]; - } - } - - // 合约插针缓存 - public function initContractHqData() - { - $now = date('Y-m-d H:i:s'); - $list = ContractMarketModel::where('type', 0) - ->whereTime('begin_time', '>', $now) - ->field('trade_name as selfContractCode,begin_time as BeginTime,step as Step ,end_time as EndTime,max_price as Price') - ->order('id', 'desc') - ->select(); - $rows = []; - $redis = $this->getRedis(); - if (!$list->isEmpty()) { - $rows = $list->toArray(); - foreach ($rows as $key => $val) { - $keep_decimal = $redis->hget('CONTRACT:LIST:' . $val['selfContractCode'], 'keep_decimal'); - $list[$key]['Digits'] = $keep_decimal; - } - } - - $reds_key = "contract_hq_setting"; - $redis->del($reds_key); - $redis->set($reds_key, json_encode($rows)); - } - - // 外汇插针缓存 - public function initForexHqData() - { - $now = date('Y-m-d H:i:s'); - $list = ForexMarketModel::where('type', 0) - ->whereTime('begin_time', '>', $now) - ->field('trade_name as selfContractCode,begin_time as BeginTime,step as Step ,end_time as EndTime,max_price as Price') - ->order('id', 'desc') - ->select(); - $rows = []; - $redis = $this->getRedis(); - if (!$list->isEmpty()) { - $rows = $list->toArray(); - foreach ($rows as $key => $val) { - $keep_decimal = $redis->hget('FOREX:LIST:' . $val['selfContractCode'], 'keep_decimal'); - $list[$key]['Digits'] = $keep_decimal; - } - } - - $reds_key = "forex_hq_setting"; - $redis->del($reds_key); - $redis->set($reds_key, json_encode($rows)); - } - - public function initContractSetting() - { - $list = ContractSettingModel::getSettingList(); - $redis_key = "contract_time_setting"; - $redis = $this->getRedis(); - $redis->del($redis_key); - $redis->set($redis_key, json_encode($list, JSON_NUMERIC_CHECK)); - } - - // 合约自发行情缓存 - public function initContractMarketData() - { - $redis = $this->getRedis(); - $now = date('Y-m-d H:i:s'); - $list = ContractMarketModel::where('type', 1) - ->whereTime('begin_time', '>', $now) - ->field('trade_name as selfContractCode,end_time as endTime,max_price as maxPrice') - ->order('id', 'desc') - ->select(); - $rows = []; - if (!$list->isEmpty()) { - $rows = $list->toArray(); - } - - $key = "contract_market_setting"; - $redis->set($key, json_encode($rows)); - } - - public function getBrokerageKey($type) - { - switch ($type) { - case 1: - //平仓返佣 - $brokerage_key = 'BROKERAGE:SALE:SETTING'; - break; - case 2: - //开仓返佣 - $brokerage_key = 'BROKERAGE:BUY:SETTING'; - break; - default: - //注册返佣 - $brokerage_key = 'BROKERAGE:REG:SETTING'; - break; - } - return $brokerage_key; - } - - public function getTradeFeeKey($market_type) - { - switch ($market_type) { - case 1: - $fee_key = 'TRADE:FEE:DIGITAL'; - break; - case 2: - $fee_key = 'TRADE:FEE:CONTRACT'; - break; - case 3: - $fee_key = 'TRADE:FEE:US_STOCK'; - break; - case 4: - $fee_key = 'TRADE:FEE:IDN_STOCK'; - break; - case 5: - $fee_key = 'TRADE:FEE:MYS_STOCK'; - break; - case 6: - $fee_key = 'TRADE:FEE:THA_STOCK'; - break; - case 7: - $fee_key = 'TRADE:FEE:IN_STOCK'; - break; - case 8: - $fee_key = 'TRADE:FEE:CONTRACT_SEC'; - break; - case 9: - $fee_key = 'TRADE:FEE:SGD_STOCK'; - break; - case 12: - $fee_key = 'TRADE:FEE:HK_STOCK'; - break; - case 14: - $fee_key = 'TRADE:FEE:UK_STOCK'; - break; - case 15: - $fee_key = 'TRADE:FEE:FUR_STOCK'; - break; - case 16: - $fee_key = 'TRADE:FEE:EUR_STOCK'; - break; - case 17: - $fee_key = 'TRADE:FEE:BR_STOCK'; - break; - case 18: - $fee_key = 'TRADE:FEE:JP_STOCK'; - break; - case 19: - $fee_key = 'TRADE:FEE:FOREX'; - break; - default: - $fee_key = ''; - break; - } - return $fee_key; - } - - /** - * @param $menus - * @param $pid - * @param $showParentName - * @return array|string - */ - function getTreeMenu($menus, $pid = 0, $showParentName = false) - { - $arr = []; - if (empty($menus)) { - return ''; - } - if ($showParentName) { - for ($i = 0; $i < count($menus); $i++) { - $parentId = $menus[$i]['pid']; - if ($parentId == '0') { - $menus[$i]['parent_name'] = ""; - } else { - $parent = array_filter($menus, function ($item) use ($parentId) { - return $item['id'] == $parentId; - }); - - if ($parent) { - $parent = array_values($parent); - if ($parent[0]['name']) { - $menus[$i]['parent_name'] = $parent[0]['name']; - } else if ($parent[0]['title']) { - $menus[$i]['parent_name'] = $parent[0]['title']; - } - } - } - } - } - foreach ($menus as $key => $value) { - if ($value['pid'] == $pid) { - $children = $this->getTreeMenu($menus, $value['id']); - if (!empty($children)) { - $value['children'] = $children; - } - //pid=0为顶级菜单,前端不显示 - if ($pid == '0') { - unset($value['pid']); - } - $arr[] = $value; - } - } - - return $arr; - } - - function getSortTreeMenu($menus, $sort = 'order', $pid = 0) - { - $menuList = getTreeMenu($menus, $pid = 0); - foreach ($menuList as $key => $value) { - if (!empty($value['children'])) { - $sort = array_column($value['children'], $sort); - array_multisort($sort, SORT_DESC, $value['children']); - } - } - return $menuList; - } - - // 给 go 行情 发送 新增的股票 - public function sendNewStockToGo($country, $newStockCode, $oldStockCode, $stockName, $tape, $price = 0, $isReal = 1, $intro = '', $source = 0, $numericCode = 0) - { - try { - switch ($country) { - case 'India': - case 'Thailand': - case 'US': - case 'HongKong': - $price = bcadd($price, 0, 2); - break; - case 'Indonesia': - $price = bcadd($price, 0, 0); - break; - case 'Malaysia': - $price = bcadd($price, 0, 3); - break; - default: - $price = bcadd($price, 0, 2); - } - - $responseArr = [ - 'old_ticker' => $oldStockCode, //新的股票代码 - 'new_ticker' => $newStockCode, //旧的股票代码 (新增的话 ,两个字段都是一样的值) - 'token' => 'asdfsnl123jlknl3nksdf32345ln98sdfsfs8891232nsdfsdfsdfsdxcfvbhnfgh', - 'locale' => $country, //国家 - 'yesterday_close' => $price, //价格 - 'name' => $stockName, //股票name - 'primary_exchange' => $tape, //交易所 - 'is_real' => $isReal, //1正式股票 2测试股票 - 'intro' => $intro //股票简介 - ]; - - if ($source > 0) { - $responseArr['source'] = $source; - } - - if ($country == 'Malaysia') { - $responseArr['numeric_code'] = $numericCode . ''; - } - - $client = new Client(); - $url = env('QUOTE.BASE_URL') . '/spots/list/new/add'; - $response = $client->request("POST", $url, [ - 'json' => $responseArr - ]); - - $body = $response->getBody()->getContents(); - $res = json_decode($body, true); - - $responseArr['url'] = $url; - trace('---给行情推送数据---' . json_encode([$res, $responseArr]), 'error'); - - if (isset($res['code']) && $res['code'] == 200) { - return true; - } - - trace('---给行情推送数据异常---' . json_encode([$res, $responseArr]), 'error'); - return false; - } catch (\Exception $exception) { - trace('---给行情推送数据异常1---' . $exception->getMessage(), 'error'); - - } catch (GuzzleException $e) { - trace('---给行情推送数据异常2---' . $e->getMessage(), 'error'); - } - - return false; - } - - // 给 go 行情 发送股票小数位数 - public function sendDecimalToGo($country, $stockCode, int $decimal) - { - try { - $client = new Client(); - $url = env('QUOTE.BASE_URL') . '/spots/update/keep'; - $response = $client->request("POST", $url, [ - 'json' => [ - 'currency' => $country, - 'stockCode' => $stockCode, - 'keepDecimal' => $decimal, - ], - ]); - - $body = $response->getBody()->getContents(); - $res = json_decode($body, true); - if (isset($res['code']) && $res['code'] == 200) { - return true; - } - - Log::error('给行情推送数据异常 ' . json_encode([$res])); - return false; - } catch (\Exception $exception) { - Log::error('给行情推送数据异常1 ' . $exception->getMessage()); - } catch (GuzzleException $e) { - Log::error('给行情推送数据异常2 ' . $e->getMessage()); - } - - return false; - } - - // 给 go 交易 发送股票小数位数 // $preStockId $marketType $stockCode - public function sendStockToGo($preStockId, $stockCode, $marketType) - { - try { - $marketType = $marketType + 0; // 转成数字 - $preStockId = $preStockId . ''; - $client = new Client(); - $url = env('QUOTE.DEAL_BASE_URL') . '/order_sharepre/share_pre_trade'; - $response = $client->request("POST", $url, [ - 'json' => [ - 'code' => $stockCode, - 'id' => $preStockId, - 'stock' => $marketType, - ], - ]); - - $body = $response->getBody()->getContents(); - $res = json_decode($body, true); - - trace('---给交易推送数据---' . json_encode([$res, [ - 'url' => $url, - 'code' => $stockCode, - 'id' => $preStockId, - 'stock' => $marketType,]]), 'error'); - if (isset($res['code']) && $res['code'] == 200) { - return true; - } - return false; - } catch (\Exception $exception) { - trace('---通知交易异常1---' . $exception->getMessage(), 'error'); - } catch (GuzzleException $e) { - trace('---通知交易异常1---' . $e->getMessage(), 'error'); - } - return false; - } - - public function sendStockToTrade($order_no, $stockCode, $marketType) - { - try { - $marketType = $marketType + 0; // 转成数字 - $order_no = $order_no . ''; - $client = new Client(); - $url = env('QUOTE.DEAL_BASE_URL') . '/order_sharepre/share_pre_trade_by_order_no'; - $response = $client->request("POST", $url, [ - 'json' => [ - 'code' => $stockCode, - 'id' => $order_no, - 'stock' => $marketType, - ], - ]); - - $body = $response->getBody()->getContents(); - $res = json_decode($body, true); - - trace('---单个订单给交易推送数据---' . json_encode([$res, [ - 'url' => $url, - 'code' => $stockCode, - 'id' => $order_no, - 'stock' => $marketType,]]), 'error'); - if (isset($res['code']) && $res['code'] == 200) { - return true; - } - return false; - } catch (\Exception $exception) { - trace('---通知交易异常1---' . $exception->getMessage(), 'error'); - } catch (GuzzleException $e) { - trace('---通知交易异常1---' . $e->getMessage(), 'error'); - } - return false; - } - - public function sendUpdateCodeGo($newCode, $oldCode, $marketType) - { - try { - $marketType = $marketType + 0; // 转成数字 - $client = new Client(); - $url = env('QUOTE.DEAL_BASE_URL') . '/order_sharepre/update_stock_id'; - $response = $client->request("POST", $url, [ - 'json' => [ - 'code' => $newCode, - 'codeOld' => $oldCode, - 'stock' => $marketType, - ], - ]); - - $body = $response->getBody()->getContents(); - $res = json_decode($body, true); - - Log::info('给交易推送数据 ' . json_encode([$res, [ - 'url' => $url, - 'code' => $newCode, - 'codeOld' => $oldCode, - 'stock' => $marketType,]])); - - - if (isset($res['code']) && $res['code'] == 200) { - return true; - } - return false; - } catch (\Exception $exception) { - Log::error('给行情推送数据异常1 ' . $exception->getMessage()); - } catch (GuzzleException $e) { - Log::error('给行情推送数据异常2 ' . $e->getMessage()); - } - - return false; - } - - /** - * 给go推送股票指数代码 - * @param $code - * @param $country - * @param $sort - * @param $status - * @return bool - */ - public function sendStockIndexToGo($code, $country, $sort, $status) - { - try { - $client = new Client(); - $url = env('QUOTE.BASE_URL') . '/spots/index/list/new/add'; - $response = $client->request("POST", $url, [ - 'json' => [ - 'ticker' => $code, - 'locale' => $country, - 'state' => $status, - 'sort' => $sort, - ], - ]); - - $body = $response->getBody()->getContents(); - $res = json_decode($body, true); - - Log::info('给交易推送数据 ' . json_encode([$res, [ - 'url' => $url, - 'ticker' => $code, - 'locale' => $country, - 'state' => $status, - 'sort' => $sort, - ]])); - - - if (isset($res['code']) && $res['code'] == 200) { - return true; - } - return false; - } catch (\Exception $exception) { - Log::error('给行情推送股票指数数据异常1 ' . $exception->getMessage()); - } catch (GuzzleException $e) { - Log::error('给行情推送股票指数数据异常2 ' . $e->getMessage()); - } - - return false; - } - - -} \ No newline at end of file diff --git a/app/admin/service/InitService.php b/app/admin/service/InitService.php new file mode 100644 index 0000000..8c5ad78 --- /dev/null +++ b/app/admin/service/InitService.php @@ -0,0 +1,147 @@ +$adminID, 'user_type'=>UserChatLinkModel::USER_CHAT_LINK_USER_TYPE_ADMIN])->find(); + if (empty($adminChatInfo)) { + $adminChatData = [ + 'Username' => $adminID."_admin", //用account.id + account.user_name 拼接作为聊天账号注册的Username, + 'Password' => '123456', + 'Nickname' => "admin", + 'Avatar' => env('USER.DEFAULT_HEAD_IMG_PATH'), + ]; + $chatUrl = env('CHAT_SERVER.BASE_URL') . '/api/user/register'; + $adminChatRes = (new \app\utility\RequestChatServer())->ReqChatServer($chatUrl, $adminChatData); + if (!isset($adminChatRes['data']['uuid'])) { + return $this->toData('500', 'admin注册聊天账号失败,请稍后再试'); + } + $adminChatInfo = UserChatLinkModel::create([ + 'user_id' => $adminID, + 'user_type' => UserChatLinkModel::USER_CHAT_LINK_USER_TYPE_ADMIN, + 'chat_uuid' => $adminChatRes['data']['uuid'], + 'chat_name' => $adminChatRes['data']['username'] + ]); + if (!isset($adminChatInfo->chat_uuid)) { + return $this->toData('500', 'admin聊天账号创建失败,请稍后再试'); + } + } + // 查询管理员的聊天群组, 如果不存在则创建 + $adminGroup = UserChatGroupModel::where(['user_id'=>$adminID, 'remark'=>UserChatGroupModel::USER_CHAT_GROUP_REMARK_ADMIN_INIT])->find(); + if (empty($adminGroup)) { + $groupName = 'ivs-group'.$adminID; + $chatGroupData = [ + 'Name' => $groupName, + ]; + $chatGroupUrl = env('CHAT_SERVER.BASE_URL') . '/api/group/'.$adminChatInfo->chat_uuid; + $chatGroupRes = (new \app\utility\RequestChatServer())->ReqChatServer($chatGroupUrl, $chatGroupData); + if (!isset($chatGroupRes['data']['group_uuid'])) { + return $this->toData('500', '管理员创建聊天群组失败'); + } + $adminGroup = UserChatGroupModel::create([ + 'user_id' => $adminID, + 'user_chat_uuid' => $adminChatInfo->chat_uuid, + 'group_name' => $groupName, + 'group_uuid' => $chatGroupRes['data']['group_uuid'], + 'remark' => UserChatGroupModel::USER_CHAT_GROUP_REMARK_ADMIN_INIT, + ]); + if (!isset($adminGroup->group_uuid)) { + return $this->toData('500', '管理员聊天群组创建失败'); + } + } + return $this->toData('0', 'ok'); + } catch (\Exception $e) { + return $this->toData('500', 'system error', [$e->getMessage(), $e->getTrace()]); + } + } + + // 获取已注册用户,遍历用户注册chat信息,添加管理员chat好友,加入管理员聊天群组 + public function initUserChatInfo($param) + { + try { + $limit = 200; + $offset = 0; + if (isset($param['page']) && $param['page'] > 1) { + $offset = ($param['page'] - 1) * 200; + } + $userList = UserModel::limit($offset, $limit)->select(); + if ($userList->isEmpty()) { + return $this->toData('0', '本次获取用户列表为空, page='.$param['page']. ' limit='.$limit); + } + + // 遍历用户创建chat信息,添加管理员chat好友,加入管理员聊天群组 + foreach ($userList as $user) { + // 注册chat信息 + $userChatInfo = UserChatLinkModel::where(['user_id'=>$user['user_id'], 'user_type'=>UserChatLinkModel::USER_CHAT_LINK_USER_TYPE_PC])->find(); + if (empty($userChatInfo)) { + $nickName = 'user_'.$user['user_id']; + if (!empty($user['email'])) { + $nickName = 'user_'.explode('@', $user['email'])[0]; + } + if (!empty($user['phone_number'])) { + $nickName = 'user_'.substr($user['phone_number'], -4); + } + $userChatData = [ + 'Username' => $user["user_no"], + 'Password' => '123456', + 'Nickname' => $nickName, + 'Avatar' => env('USER.DEFAULT_HEAD_IMG_PATH'), + ]; + $chatUrl = env('CHAT_SERVER.BASE_URL') . '/api/user/register'; + $userChatRes = (new \app\utility\RequestChatServer())->ReqChatServer($chatUrl, $userChatData); + if (!isset($userChatRes['data']['uuid'])) { + return $this->toData('500', '用户注册聊天账号失败'); + } + $userChatInfo = UserChatLinkModel::create([ + 'user_id' => $user['user_id'], + 'user_type' => UserChatLinkModel::USER_CHAT_LINK_USER_TYPE_PC, + 'chat_uuid' => $userChatRes['data']['uuid'], + 'chat_name' => $userChatRes['data']['username'] + ]); + if (!isset($userChatInfo->chat_uuid)) { + return $this->toData('500', 'admin聊天账号创建失败'); + } + } + + // 添加管理员chat好友 + $adminID = 1; + $adminChatInfo = UserChatLinkModel::where(['user_id'=>$adminID, 'user_type'=>UserChatLinkModel::USER_CHAT_LINK_USER_TYPE_ADMIN])->find(); //查询管理员的chat信息 + if (empty($adminChatInfo)) { + return $this->toData('500', '管理员的chat信息为空,请先创建管理员的chat信息'); + } + $chatFriendsData = [ + 'UserUuid' => $userChatInfo->chat_uuid, + 'CustomerUuid' => $adminChatInfo->chat_uuid, + ]; + $chatFriendsUrl = env('CHAT_SERVER.BASE_URL') . '/api/eachOtherFriends'; + $chatFriendsRes = (new \app\utility\RequestChatServer())->ReqChatServer($chatFriendsUrl, $chatFriendsData); + Log::info("用户与管理员加好友结果:".json_encode($chatFriendsRes)); + + // 将用户添加到管理员的群聊中 + $adminGroup = UserChatGroupModel::where(['user_id'=>$adminID, 'remark'=>UserChatGroupModel::USER_CHAT_GROUP_REMARK_ADMIN_INIT])->find(); + if (empty($adminGroup)) { + return $this->toData('500', '管理员的聊天群组信息为空,请先创建管理员的聊天群组信息'); + } + $joinChatGroupUrl = env('CHAT_SERVER.BASE_URL') . '/api/group/join/'.$userChatInfo->chat_uuid.'/'.$adminGroup->group_uuid; + $joinChatGroupRes = (new \app\utility\RequestChatServer())->ReqChatServer($joinChatGroupUrl, []); + Log::info("用户加入聊天群组结果:".json_encode($joinChatGroupRes)); + } + + return $this->toData('0', 'ok'); + } catch (\Exception $e) { + return $this->toData('500', 'system error', [$e->getMessage(), $e->getTrace()]); + } + } +} \ No newline at end of file diff --git a/app/admin/service/WithdrawService-pro.php b/app/admin/service/WithdrawService-pro.php deleted file mode 100644 index 5e9a6ff..0000000 --- a/app/admin/service/WithdrawService-pro.php +++ /dev/null @@ -1,346 +0,0 @@ -scene('index')->check($param); - $where = []; - $userId = 0; - // 用户号精确搜索 - if (!empty($param['user_no'])) { - $user = UserModel::where('user_no', $param['user_no'])->find(); - if (empty($user)) { - return $this->toData('0', 'SUCCESS', ['total' => 0, 'list' => [], 'extend' => UserWithdrawalModel::$statusList]); - } - $userId = $user['user_id']; - } - // 判断是否是代理 如果是代理 只能看他自己管理的用户 - $whereU = $this->getWhereByIsAgentAndUserId($adminId, $where, $userId); - if (!is_array($whereU)) { - return $this->toData('0', 'SUCCESS', ['total' => 0, 'list' => [], 'extend' => UserWithdrawalModel::$statusList]); - } - // 订单号 - if (!empty($param['order_id'])) { - $where['order_no'] = $param['order_id']; - } - if (isset($param['status'])) { - $where['status'] = $param['status']; - } - - if (!empty($param['start_time']) && !empty($param['end_time'])) { - $where['update_time'] = ['between time', [$param['start_time'], $param['end_time']]]; - } - - // 列表 - $list = UserWithdrawalModel::where($where)->where($whereU)->order('id', 'desc')->page($param['page'], $param['limit'])->select(); - // 总数 - $total = UserWithdrawalModel::where($where)->where($whereU)->count(); - // 统计 提现成功 - $sum = UserWithdrawalModel::where($where)->where($whereU)->where('status', 4)->sum('apply_num'); - - $rows = []; - if (!$list->isEmpty()) { - // 获取用户号 - $userIdArr = []; - foreach ($list as $idItem) { - $userIdArr[] = $idItem['user_id']; - } - - $userNoArr = UserModel::where('user_id', 'in', $userIdArr)->column('user_no', 'user_id'); - $ifscArr = UserBankModel::where('user_id', 'in', $userIdArr)->column('ifsc', 'user_id'); - - $rows = $list->toArray(); - foreach ($rows as $key => $item) { - $rows[$key]['user_no'] = $userNoArr[$item['user_id']] ?? '-'; // 用户号. - $rows[$key]['ifsc'] = $ifscArr[$item['user_id']] ?? '-'; // ifsc - $rows[$key]['order_id'] = $item['order_no']; - $rows[$key]['status_text'] = UserWithdrawalModel::$statusList[$item['status']]; - //$rows[$key]['pay_info'] = json_decode($item['pay_info'],true); - } - } - return $this->toData('0', 'SUCCESS', ['total' => $total, 'list' => $rows, 'sum' => $sum . 'USD', 'extend' => UserWithdrawalModel::$statusList]); - } catch (\Exception $exception) { - return $this->toData('1', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]); - } - } - - public function info($param, $adminId) - { - try { - // 参数校验 - validate(WithdrawValidate::class)->scene('info')->check($param); - $where = [ - 'id' => $param['id'] - ]; - - $userId = 0; - $where = $this->getWhereByIsAgentAndUserId($adminId, $where, $userId); - if (!is_array($where)) { - return $this->toData('0', 'SUCCESS', []); - } - - $order_info = []; - $info = UserWithdrawalModel::where($where)->find(); - $ifsc = UserBankModel::where('user_id', $info->user_id)->value('ifsc'); - - if (!$info->isEmpty()) { - $order_info = $info->toArray(); - $order_info['pay_info'] = json_decode($order_info['pay_info'], true); - $channel = PaymentListModel::getPaymentInfo([ - 'id' => intval($order_info['channel_id']) - ]); - $order_info['channel_name'] = isset($channel['channel']) ? $channel['channel'] : ''; - $order_info['ifsc'] = $ifsc ?? '-'; - } - return $this->toData('0', 'SUCCESS', $order_info); - } catch (\Exception $exception) { - return $this->toData('1', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]); - } - - } - - public function change_status($param, $adminId) - { - try { - // 参数校验 - validate(WithdrawValidate::class)->scene('status')->check($param); - $isAgent = AdminModel::checkUserIsAgent($adminId); - if ($isAgent) { - return $this->toData('10040', '代理无权限操作'); - } - $where = [ - 'id' => $param['id'] - ]; - $userId = 0; - $where = $this->getWhereByIsAgentAndUserId($adminId, $where, $userId); - if (!is_array($where)) { - return $this->toData('0', 'SUCCESS', ['total' => 0, 'list' => []]); - } - - $order_info = []; - $info = UserWithdrawalModel::where($where)->find(); - if (empty($info)) { - return $this->toData('1004', '订单不存在'); - } - $order_info = $info->toArray(); - $change_flag = false; - if ($order_info['status'] == 0 && $param['status'] < 3) { - $change_flag = true; - } - if ($order_info['status'] = 1 && ($param['status'] == 3 || $param['status'] == 2)) { - $change_flag = true; - } - if ($order_info['status'] = 3 && $param['status'] == 4) { - $change_flag = true; - } - $pay_flag = false; - $msg = ""; - $content = ""; - if ($change_flag) { - $update_data['status'] = $param['status']; - $update_data['update_time'] = date('Y-m-d H:i:s'); - //拒绝 - if ($param['status'] == 2) { - $updateStatus = $this->updateUserAsset($order_info['user_id'], $order_info['account_type'], 6, $order_info['market_amount'], -$order_info['market_amount'], $order_info['order_no']); - } - - //代付 - if ($param['status'] == 3) { - //解冻资金 ,扣除提现 - $updateOne = $this->updateUserAsset($order_info['user_id'], $order_info['account_type'], 6, $order_info['market_amount'], -$order_info['market_amount'], $order_info['order_no']); - if (!empty($updateOne) && $updateOne['status'] == 200) { - $updateStatus = $this->updateUserAsset($order_info['user_id'], $order_info['account_type'], 2, -$order_info['market_amount'], 0, $order_info['order_no']); - } else { - //提现事务回滚... -// $updateOne = $this->updateUserAsset($order_info['user_id'], $order_info['account_type'], 5, -$order_info['market_amount'], +$order_info['market_amount'], $order_info['order_no']); - trace("提现失败1 - change_status - order_no=" . $order_info['order_no'] . "---user_id= " . $order_info['user_id'] . "---account_type= " . $order_info['account_type'] . "---market_amount= " . $order_info['market_amount']); - return $this->toData($updateOne['status'] ?? '3251', $updateOne['msg'] ?? $msg, [$content]); - } - - if (!empty($updateStatus) && $updateStatus['status'] == 200) { - $channel = PaymentListModel::getPaymentInfo([ - 'id' => $param['channel'] - ]); - if ($channel) { - $result = $this->payToUser($order_info, $channel); - if ($result['code'] == 200) { - $update_data['order_idx'] = $result['order_idx']; - $update_data['channel_id'] = $param['channel']; - } else { - $update_data['status'] = 1; //代付失败 - $pay_flag = true; - $content = $result['content']; - $msg = $result['msg']; - } - } - //手动支付完成 - if ($param['channel'] == 0) { - $update_data['status'] = 4; - $update_data['channel_id'] = $param['channel']; - } - } - } - - $update_data['beizhu'] = $param['beizhu'] ?? ""; - - if ($param['status'] == 1 || (!empty($updateStatus) && $updateStatus['status'] == 200)) { - UserWithdrawalModel::where($where)->update($update_data); - } else { - trace("提现失败2 - change_status - order_no=" . $order_info['order_no'] . "---user_id= " . $order_info['user_id'] . "---account_type= " . $order_info['account_type'] . "---market_amount= " . $order_info['market_amount']); - return $this->toData($updateStatus['status'] ?? '3251', $updateStatus['msg'] ?? $msg, [$content]); - } - - if ($pay_flag) { - return $this->toData('3250', $msg, [$content]); - } else { - return $this->toData('0', 'SUCCESS'); - } - - } else { - return $this->toData('10040', '操作流程不合法'); - } - - } catch (\Exception $exception) { - return $this->toData('1', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]); - } - } - - private function payToUser($order, $channel) - { - //货币单位换算 - $order['total_amount'] = $order['apply_num'] * $channel['exchange_rate']; - $address_info = json_decode($order['pay_info'], true); - - switch ($channel['type']) { - //印尼支付 - case 2: - return (new IndPayService())->singleIndOrder($order); - break; - //TRC - case 3: - return (new MoPayService())->apply_pay($order['order_no'], $order['total_amount'], $address_info['bank_code'], $address_info['bank_card'], $address_info['true_name'], $address_info['bank_phone'], $address_info['ifsc']); - break; - //合泰 - case 4: - return (new HTPayService())->arPay($order['order_no'], $order['total_amount'], $address_info['bank_code'], $address_info['bank_card'], $address_info['true_name']); - break; - //合泰 - case 5: - return (new XdPayService())->apply_pay($order['order_no'], $order['total_amount'], $address_info['ifsc'], $address_info['bank_card'], $address_info['true_name']); - break; - //QEAE - case 6: - return (new QeaePayService())->apply_pay($order['order_no'], $order['total_amount'], $address_info['bank_card'], $address_info['true_name'], $address_info['ifsc'], $address_info['bank_code']); - break; - //合泰 - case 7: - return (new NicePayService())->apply_pay($order['order_no'], $order['total_amount'], $address_info['bank_card'], $address_info['true_name'], $address_info['ifsc']); - break; - //ClickPay - case 8: - return (new ClickPayService())->apply_pay($order['order_no'], $order['total_amount'], $address_info['bank_card'], $address_info['true_name'], $address_info['ifsc'], $address_info['bank_code']); - break; - default: - - break; - } - } - - public function get_balance($param, $adminId) - { - $channel = PaymentListModel::getPaymentInfo([ - 'id' => intval($param['id']) - ]); - if ($channel) { - switch ($channel['type']) { - case 1: - //$result=(new IndPayService())->getIndBalance(); - $result = [ - 'amount' => 0 - ]; - break; - case 2: - $result = (new TrcPayService())->getTrcBalance(); - break; - case 4: - $result = (new HTPayService())->getHtBalance(); - break; - case 5: - $result = (new XdPayService())->getBalance(); - break; - case 6: - $result = (new QeaePayService())->getBalance(); - break; - case 8: - $result = (new ClickPayService())->getBalance(); - break; - default: - $result = [ - 'amount' => 0 - ]; - break; - } - - return $this->toData('0', '请求成功', $result); - - } else { - return $this->toData('1', '参数错误,通道不存在', []); - } - } - - public function channel_list($param, $adminId) - { - try { - // 参数校验 - validate(WithdrawValidate::class)->scene('info')->check($param); - $where = [ - 'id' => $param['id'] - ]; - - $userId = 0; - $where = $this->getWhereByIsAgentAndUserId($adminId, $where, $userId); - if (!is_array($where)) { - return $this->toData('0', 'SUCCESS', ['total' => 0, 'list' => []]); - } - - $order_info = UserWithdrawalModel::getUserDrawalInfo($where); - if ($order_info) { - $channel_list = PaymentListModel::getPaymentList([ - 'is_withdrawal' => 1, - 'status' => 1, - 'channel_type' => $order_info['apply_type'] - ]); - } else { - $channel_list = []; - } - return $this->toData('0', '请求成功', $channel_list); - } catch (\Exception $exception) { - return $this->toData('1', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]); - } - } - - -} \ No newline at end of file diff --git a/app/admin/service/WithdrawService.php b/app/admin/service/WithdrawService.php index f4a98f7..422cb1e 100644 --- a/app/admin/service/WithdrawService.php +++ b/app/admin/service/WithdrawService.php @@ -26,7 +26,6 @@ class WithdrawService extends AdminBaseService public function index($param, $adminId) { try { - // 参数校验 validate(WithdrawValidate::class)->scene('index')->check($param); Cache::store('redis')->set('Withdraw_Read_Time'.$adminId,time()); @@ -64,8 +63,6 @@ class WithdrawService extends AdminBaseService // 统计 提现成功 $sum = UserWithdrawalModel::where($where)->where($whereU)->where('status', 4)->sum('apply_num'); - - $rows = []; if (!$list->isEmpty()) { // 获取用户号 diff --git a/app/home/service/LoginService.php b/app/home/service/LoginService.php index b995dae..2ac8748 100644 --- a/app/home/service/LoginService.php +++ b/app/home/service/LoginService.php @@ -6,6 +6,8 @@ use app\home\controller\User; use app\home\validate\LoginValidate; use app\model\AdminModel; use app\model\CountryModel; +use app\model\UserChatGroupModel; +use app\model\UserChatLinkModel; use app\model\UserModel; use app\utility\Jwt; use app\utility\SendSms; @@ -13,6 +15,7 @@ use app\utility\UnqId; use Psr\SimpleCache\InvalidArgumentException; use think\exception\ValidateException; use think\facade\Cache; +use think\facade\Log; use think\facade\Queue; use think\queue\Job; use GeoIp2\Database\Reader; @@ -167,6 +170,77 @@ class LoginService extends BaseHomeService $userId = UserModel::emailRegister($email, $userNo, $userInviteCode, $parentUserId, $password, $ip, $salt, 1, $agentId); // 生成钱包地址 (new UserService())->doRegInitUserInfo($userId, $parentUserId); + // 用户注册聊天账号 + $userChatData = [ + 'Username' => $userNo, + 'Password' => '123456', + 'Nickname' => 'user_'.explode('@', $email)[0], + 'Avatar' => env('USER.DEFAULT_HEAD_IMG_PATH'), + 'Email' => $email, + ]; + $chatUrl = env('CHAT_SERVER.BASE_URL') . '/api/user/register'; + $chatRes = (new \app\utility\RequestChatServer())->ReqChatServer($chatUrl, $userChatData); + if (!isset($chatRes['data']['uuid'])) { + return $this->toData('500', '用户注册聊天账号失败,请稍后再试'); + } + UserChatLinkModel::create([ + 'user_id' => $userId, + 'user_type' => UserChatLinkModel::USER_CHAT_LINK_USER_TYPE_PC, + 'chat_uuid' => $chatRes['data']['uuid'], + 'chat_name' => $chatRes['data']['username'] + ]); + // 用户与管理员添加聊天好友 + $adminID = 1; // p1项目中admin的账号ID是1 + $adminChatInfo = UserChatLinkModel::where(['user_id'=>$adminID, 'user_type'=>UserChatLinkModel::USER_CHAT_LINK_USER_TYPE_ADMIN])->find(); //查询管理员的chat信息 + if (empty($adminChatInfo)) { // 如果不存在管理员的chat信息,则为管理员创建一个chat信息 + $adminChatData = [ + 'Username' => $adminID."_admin", //用account.id + account.user_name 拼接作为聊天账号注册的Username, + 'Password' => '123456', + 'Nickname' => "admin", + 'Avatar' => env('USER.DEFAULT_HEAD_IMG_PATH'), + ]; + $adminChatRes = (new \app\utility\RequestChatServer())->ReqChatServer($chatUrl, $adminChatData); + if (!isset($adminChatRes['data']['uuid'])) { + return $this->toData('500', 'admin注册聊天账号失败,请稍后再试'); + } + $adminChatInfo = UserChatLinkModel::create([ + 'user_id' => $adminID, + 'user_type' => UserChatLinkModel::USER_CHAT_LINK_USER_TYPE_ADMIN, + 'chat_uuid' => $adminChatRes['data']['uuid'], + 'chat_name' => $adminChatRes['data']['username'] + ]); + } + $chatFriendsData = [ + 'UserUuid' => $chatRes['data']['uuid'], + 'CustomerUuid' => $adminChatInfo->chat_uuid, + ]; + $chatFriendsUrl = env('CHAT_SERVER.BASE_URL') . '/api/eachOtherFriends'; + $chatFriendsRes = (new \app\utility\RequestChatServer())->ReqChatServer($chatFriendsUrl, $chatFriendsData); + Log::info("邮箱注册 - 用户与管理员加好友结果:".json_encode($chatFriendsRes)); + // 将用户添加到管理员的群聊中 + $adminGroup = UserChatGroupModel::where(['user_id'=>$adminID, 'remark'=>UserChatGroupModel::USER_CHAT_GROUP_REMARK_ADMIN_INIT])->find(); + if (empty($adminGroup)) { + // 创建管理员的聊天群组 + $groupName = 'ivs-group'.$adminID; + $chatGroupData = [ + 'Name' => $groupName, + ]; + $chatGroupUrl = env('CHAT_SERVER.BASE_URL') . '/api/group/'.$adminChatInfo->chat_uuid; + $chatGroupRes = (new \app\utility\RequestChatServer())->ReqChatServer($chatGroupUrl, $chatGroupData); + if (!isset($chatGroupRes['data']['group_uuid'])) { + return $this->toData('500', '管理员创建聊天群组失败'); + } + $adminGroup = UserChatGroupModel::create([ + 'user_id' => $adminID, + 'user_chat_uuid' => $adminChatInfo->chat_uuid, + 'group_name' => $groupName, + 'group_uuid' => $chatGroupRes['data']['group_uuid'], + 'remark' => UserChatGroupModel::USER_CHAT_GROUP_REMARK_ADMIN_INIT, + ]); + } + $joinChatGroupUrl = env('CHAT_SERVER.BASE_URL') . '/api/group/join/'.$chatRes['data']['uuid'].'/'.$adminGroup->group_uuid; + $joinChatGroupRes = (new \app\utility\RequestChatServer())->ReqChatServer($joinChatGroupUrl, []); + Log::info("邮箱注册 - 用户加入群组结果:".json_encode($joinChatGroupRes)); }); // 删除缓存 $this->delCache($emailKey); @@ -413,6 +487,76 @@ class LoginService extends BaseHomeService $userId = UserModel::phoneRegister($param['nation'], $param['phone'], $userNo, $userInviteCode, $parentUserId, $password, $ip, $salt, 1, $agentId); // 生成钱包地址 (new UserService())->doRegInitUserInfo($userId, $parentUserId); + // 用户注册聊天账号 + $userChatData = [ + 'Username' => $userNo, + 'Password' => '123456', + 'Nickname' => 'user_'.substr($param['phone'], -4), + 'Avatar' => env('USER.DEFAULT_HEAD_IMG_PATH'), + ]; + $chatUrl = env('CHAT_SERVER.BASE_URL') . '/api/user/register'; + $chatRes = (new \app\utility\RequestChatServer())->ReqChatServer($chatUrl, $userChatData); + if (!isset($chatRes['data']['uuid'])) { + return $this->toData('500', '用户注册聊天账号失败,请稍后再试'); + } + UserChatLinkModel::create([ + 'user_id' => $userId, + 'user_type' => UserChatLinkModel::USER_CHAT_LINK_USER_TYPE_PC, + 'chat_uuid' => $chatRes['data']['uuid'], + 'chat_name' => $chatRes['data']['username'] + ]); + // 用户与管理员添加聊天好友 + $adminID = 1; // p1项目中admin的账号ID是1 + $adminChatInfo = UserChatLinkModel::where(['user_id'=>$adminID, 'user_type'=>UserChatLinkModel::USER_CHAT_LINK_USER_TYPE_ADMIN])->find(); //查询管理员的chat信息 + if (empty($adminChatInfo)) { // 如果不存在管理员的chat信息,则为管理员创建一个chat信息 + $adminChatData = [ + 'Username' => $adminID."_admin", //用account.id + account.user_name 拼接作为聊天账号注册的Username, + 'Password' => '123456', + 'Nickname' => "admin", + 'Avatar' => env('USER.DEFAULT_HEAD_IMG_PATH'), + ]; + $adminChatRes = (new \app\utility\RequestChatServer())->ReqChatServer($chatUrl, $adminChatData); + if (!isset($adminChatRes['data']['uuid'])) { + return $this->toData('500', 'admin注册聊天账号失败,请稍后再试'); + } + $adminChatInfo = UserChatLinkModel::create([ + 'user_id' => $adminID, + 'user_type' => UserChatLinkModel::USER_CHAT_LINK_USER_TYPE_ADMIN, + 'chat_uuid' => $adminChatRes['data']['uuid'], + 'chat_name' => $adminChatRes['data']['username'] + ]); + } + $chatFriendsData = [ + 'UserUuid' => $chatRes['data']['uuid'], + 'CustomerUuid' => $adminChatInfo->chat_uuid, + ]; + $chatFriendsUrl = env('CHAT_SERVER.BASE_URL') . '/api/eachOtherFriends'; + $chatFriendsRes = (new \app\utility\RequestChatServer())->ReqChatServer($chatFriendsUrl, $chatFriendsData); + Log::info("短信注册 - 用户与管理员加好友结果:".json_encode($chatFriendsRes)); + // 将用户添加到管理员的群聊中 + $adminGroup = UserChatGroupModel::where(['user_id'=>$adminID, 'remark'=>UserChatGroupModel::USER_CHAT_GROUP_REMARK_ADMIN_INIT])->find(); + if (empty($adminGroup)) { + // 创建管理员的聊天群组 + $groupName = 'ivs-group'.$adminID; + $chatGroupData = [ + 'Name' => $groupName, + ]; + $chatGroupUrl = env('CHAT_SERVER.BASE_URL') . '/api/group/'.$adminChatInfo->chat_uuid; + $chatGroupRes = (new \app\utility\RequestChatServer())->ReqChatServer($chatGroupUrl, $chatGroupData); + if (!isset($chatGroupRes['data']['group_uuid'])) { + return $this->toData('500', '管理员创建聊天群组失败'); + } + $adminGroup = UserChatGroupModel::create([ + 'user_id' => $adminID, + 'user_chat_uuid' => $adminChatInfo->chat_uuid, + 'group_name' => $groupName, + 'group_uuid' => $chatGroupRes['data']['group_uuid'], + 'remark' => UserChatGroupModel::USER_CHAT_GROUP_REMARK_ADMIN_INIT, + ]); + } + $joinChatGroupUrl = env('CHAT_SERVER.BASE_URL') . '/api/group/join/'.$chatRes['data']['uuid'].'/'.$adminGroup->group_uuid; + $joinChatGroupRes = (new \app\utility\RequestChatServer())->ReqChatServer($joinChatGroupUrl, []); + Log::info("短信注册 - 用户与管理员加好友结果:".json_encode($joinChatGroupRes)); }); // 删除缓存 diff --git a/app/model/UserChatGroupModel.php b/app/model/UserChatGroupModel.php new file mode 100644 index 0000000..519d692 --- /dev/null +++ b/app/model/UserChatGroupModel.php @@ -0,0 +1,8 @@ +toData('500', '请求方法不在支持列表中'); + } + Log::info("Guzzle请求: URL==".$url." 请求Param==".json_encode($data)); + $resBody = []; + $client = new Client(); + if ($method == 'PUT') { + $response = $client->put($url, [ + 'json' => $data, + ]); + } else { + $response = $client->post($url, [ + 'json' => $data, + ]); + } + $statusCode = $response->getStatusCode(); + Log::error("Guzzle请求响应:code==".$statusCode." body==". $response->getBody()); + if ($statusCode == 200) { + $resBody = json_decode($response->getBody(), true); // 转换为数组 + } + return $resBody; + } catch (GuzzleException $e) { + Log::error("Guzzle请求异常 - guzzle: " . $e->getMessage()); + return $this->toData('500', $e->getMessage()); + } catch (\Exception $exception) { + Log::error("Guzzle请求异常 - exception: " . $exception->getMessage()); + return $this->toData('500', $exception->getMessage()); + } + } +} \ No newline at end of file