request; $id = $request->post('id', 0); if ($id) { $ret = CoinBusiness::getCoinAllById($id); if ($ret) { $data = $ret[0]; $nickname = json_decode($data['nickname'], true); $introduce = json_decode($data['introduce'], true); $data['nickname'] = $nickname[$this->lang]; $data['introduce'] = $introduce[$this->lang]; return $data; } } return []; } /** * 获取推介币种列表 */ public function actionGetRecList() { $request = Yii::$app->request; $page = $request->post('page', 1); $limit = $request->post('limit', 999); $platform_id = $request->post('platform_id', 2);//默认币钱包 if ($platform_id == 1) { $platform_id = 3; } elseif ($platform_id == 2) { $platform_id = 1; } elseif ($platform_id == 3) { $platform_id = 2; } $recommend = $request->post('recommend', ''); $condition = ['platform_id' => $platform_id, 'type' => 1]; if ($recommend) { $condition['recommend'] = $recommend; } $select = ['id', 'sid', 'icon', 'name', 'nickname', 'platform', 'chain']; $datas = CoinRecommend::getList($page, $limit, $condition, [], $select); //获取详细信息 $coin_recommends = &$datas['data']; if (!empty($coin_recommends)) { $coin_ids = array_column($coin_recommends, 'cid'); //获取币种信息 $coin_infos = Coin::getCoinInfoByIds($coin_ids, $select, 'id'); //获取行情信息 $coin_names = array_column($coin_infos, 'name'); $coin_names = array_merge($coin_names, array_column($coin_infos, 'chain')); $coin_quotations = ExchangeBusiness::getQuatationByNames($coin_names); if ($coin_infos) { array_shift($select); foreach ($coin_recommends as $key => &$value) { $temp_key = $coin_infos[$value['cid']]['name']; foreach ($select as $item) { $value[$item] = $coin_infos[$value['cid']][$item]; if ($value['platform_id'] != 2) { //国盾币不需要行情 $value['low'] = $coin_quotations[$temp_key]['low']; $value['high'] = $coin_quotations[$temp_key]['high']; $value['last'] = $coin_quotations[$temp_key]['last']; $value['rmb'] = $coin_quotations[$temp_key]['rmb']; } else { $value['low'] = 0; $value['high'] = 0; $value['last'] = 0; $value['rmb'] = 0; } } $value['id'] = $value['cid']; $value['sid'] = ucfirst($value['sid']); $value['chain_quotation'] = $coin_quotations[$coin_infos[$value['cid']]['chain']]; unset($value['create_time'], $value['update_time'], $value['cid']); } unset($key, $value); } } return $datas; } /** * 获取推介币种列表(新) */ public function actionGetNewRecList() { $request = Yii::$app->request; $page = $request->post('page', 1); $limit = $request->post('limit', 999); $platform_id = $request->post('platform_id', 1);//默认币钱包 $recommend = $request->post('recommend', ''); $condition = ['platform_id' => $platform_id, 'type' => 1]; if ($recommend) { $condition['recommend'] = $recommend; } $select = ['id', 'sid', 'icon', 'name', 'nickname', 'platform', 'chain', 'treaty']; $order_by = ['sort' => SORT_ASC]; $datas = CoinRecommend::getList($page, $limit, $condition, $order_by, $select); //获取详细信息 $coin_recommends = &$datas['data']; if (!empty($coin_recommends)) { $coin_ids = array_column($coin_recommends, 'cid'); //获取币种信息 $coin_infos = Coin::getCoinInfoByIds($coin_ids, $select, 'id'); foreach ($coin_infos as $key => &$val){ $nickname = json_decode($val['nickname'], true); $val['nickname'] = $nickname[$this->lang]; } //获取行情信息 $coin_names = array_column($coin_infos, 'name'); $coin_names = array_merge($coin_names, array_column($coin_infos, 'chain')); $coin_quotations = ExchangeBusiness::getQuatationByNames($coin_names); if ($coin_infos) { array_shift($select); foreach ($coin_recommends as $key => &$value) { $temp_key = $coin_infos[$value['cid']]['name']; foreach ($select as $item) { $value[$item] = $coin_infos[$value['cid']][$item]; if ($value['platform_id'] != 2) { //国盾币不需要行情 $value['low'] = $coin_quotations[$temp_key]['low']; $value['high'] = $coin_quotations[$temp_key]['high']; $value['last'] = $coin_quotations[$temp_key]['last']; $value['rmb'] = $coin_quotations[$temp_key]['rmb']; $value['usd'] = $coin_quotations[$temp_key]['usd'] ?? 0; } else { $value['low'] = 0; $value['high'] = 0; $value['last'] = 0; $value['rmb'] = 0; $value['usd'] = 0; } } $value['id'] = $value['cid']; $value['sid'] = ucfirst($value['sid']); $value['chain_quotation'] = $coin_quotations[$coin_infos[$value['cid']]['chain']]; unset($value['create_time'], $value['update_time'], $value['cid']); } unset($key, $value); } } if(!$datas['data']){ $datas['data'] = null; } return $datas; } /** * 矿工费获取 * * 根据name获取 * * @throws Exception */ public function actionGetMinerFeeByName() { $names = Yii::$app->request->post('name'); $coin = Coin::findOne(['name' => $names]); if ($coin) { $chain = $coin->chain; $miner_fee = MinerFee::find()->where(['platform' => $chain,'type' => 1])->one(); if(!$miner_fee){ throw new Exception('8', '旷工费未设置'); } } else { //如果coin为null,$coin->minerFee会抛出Trying to get property 'minerFee' of non-object",code=>8 throw new Exception('8', '币种不存在'); } $result = (array)$miner_fee->getAttributes(); $result['min'] = number_format($result['min'],6); $result['max'] = number_format($result['max'],6); return $result; } /** * app首页接口V2 */ public function actionCoinIndex() { $names = Yii::$app->request->post('names'); $platforms = []; $newNames = []; if(!$names){ return ['code' => 0,'data' => []]; } foreach($names as $item){ $item_array = explode(',',$item); $newNames [] = $item_array[0]; if(isset($item_array[1])){ if(!in_array($item_array[1],$platforms)){ $platforms [] = $item_array[1]; } } } $condition = [['in', 'name', $newNames]]; if($platforms){ $condition[] = ['in', 'platform', $platforms]; } $result = ExchangeBusiness::getApiListForIndex(1, 999, $condition); if ($result) { $chains = array_unique(array_column($result['data'], 'chain')); $chain_quotation = []; foreach ($chains as $key => $value) { $chain_quotation[$value] = ExchangeBusiness::getquatation($value); } foreach ($result['data'] as $key => &$value) { $nickname = json_decode($value['nickname'], true); $value['nickname'] = $nickname[$this->lang]; $value['chain_quotation'] = $chain_quotation[$value['chain']] ?: null; } return $result; } } /** * 按照名称搜索币种 * * @return array */ public function actionSearchCoinByName() { $request = Yii::$app->request; $name = $request->post('name', ''); $page = $request->post('page', 1); $limit = $request->post('limit', 10); $platform_ids = $request->post('platform_id', null); $condition = [['in', 'chain', ['ETH','DCR','BTC','BTY']]]; if (!empty($name)) { $condition[] = ['or',['address' => $name],['or', ['like', 'name', $name], ['like', 'nickname', $name]]]; } if ($platform_ids) { /* $platform_id_arr = explode(',', $platform_ids); $condition_arr = ['OR']; foreach ($platform_id_arr as $key => $value) { array_push($condition_arr, ['=', 'platform_id', $value]); } $condition[] = $condition_arr;*/ $condition[] = ['>', "find_in_set($platform_ids, platform_id)", 0]; } $result = ExchangeBusiness::SearchByName($page, $limit, $condition); if (empty($result)) { return ['code' => 0, 'count' => 0, 'data' => []]; } $total = $result['total']; $result = $result['data']; if ($result) { $chains = array_unique(array_column($result, 'chain')); $chain_quotation = []; foreach ($chains as $key => $value) { $chain_quotation[$value] = ExchangeBusiness::getquatation($value); } foreach ($result as $key => $value) { $result[$key]['chain_quotation'] = $chain_quotation[$value['chain']] ?: null; } foreach ($result as $key => &$value) { $nickname = json_decode($value['nickname'], true); $value['nickname'] = $nickname[$this->lang]; } return ['code' => 0, 'count' => $total, 'data' => $result]; } } /** * 返回交易状态 * * @return mixed */ public function actionTransaction() { $request = Yii::$app->request; $name = $request->post('name', ''); $txhash = $request->post('txhash', ''); if ($name && $txhash) { return BrowerBusiness::getTransStatus($name, $txhash); } return false; } /** * @return array * 获取平台币图标、区块链地址 */ public function actionGetBrowerByPlatform() { $request = Yii::$app->request; $platform = $request->post('platform', ''); if($platform){ $brower_url = Yii::$app->redis->hget('platform_brower_info',$platform); return ['code' => 0,'data' => $brower_url]; }else{ return ['code' => 1,'data' => [],'msg' => '平台参数不能为空']; } } /** *获取代扣信息 */ public function actionGetWithHold() { $request = Yii::$app->request; $platform = $request->get('platform', ''); if($platform){ $platform_with_hold = CoinPlatformWithHold::getRecord($platform); if($platform_with_hold){ $des = Yii::$app->des; $platform_with_hold['private_key'] = $des->encrypt($platform_with_hold['private_key']); return ['code' => 0,'data' => $platform_with_hold]; }else{ $data = [ 'id' => 0, 'platform' => '', 'address' => '', 'private_key' => '', 'exer' => '' ]; return ['code' => 0, 'data' => $data]; } }else{ return ['code' => 1,'data' => [],'msg' => '平台参数不能为空']; } } }