|
|
@@ -15,6 +15,7 @@ use app\common\model\ParametersModel;
|
|
|
use fast\Action;
|
|
|
use fast\Asset;
|
|
|
use fast\Random;
|
|
|
+use Google\Service\Storage\Resource\Objects;
|
|
|
use think\Config;
|
|
|
use think\Db;
|
|
|
use think\Exception;
|
|
|
@@ -66,28 +67,8 @@ class User extends Api
|
|
|
*/
|
|
|
public function getNftList(ProductOrder $productOrder)
|
|
|
{
|
|
|
- $where = [];
|
|
|
$typeId = $this->request->post('type_id/d', 0);
|
|
|
- switch ($typeId) {
|
|
|
- case 0:
|
|
|
- $where['a.status'] = ['<' , $productOrder::Shipped];
|
|
|
- break;
|
|
|
- case 1:
|
|
|
- $where = ['a.type_id' => $productOrder::Transfer, 'a.status' => $productOrder::Transferred];
|
|
|
- break;
|
|
|
- case 2:
|
|
|
- $where = ['a.type_id' => $productOrder::Transfer, 'a.status' => $productOrder::Closure];
|
|
|
- break;
|
|
|
- case 3:
|
|
|
- $where = ['a.type_id' => $productOrder::Popular, 'a.status' => $productOrder::Cancelled];
|
|
|
- break;
|
|
|
- case 4:
|
|
|
- $where = ['a.type_id' => $productOrder::Giveaway, 'a.status' => $productOrder::Closure];
|
|
|
- break;
|
|
|
- case 5:
|
|
|
- $where = ['a.type_id' => $productOrder::Popular, 'a.status' => $productOrder::Shipped];
|
|
|
- break;
|
|
|
- }
|
|
|
+ $where = self::getNftWhere($typeId, $productOrder);
|
|
|
$list = $productOrder->alias('a')
|
|
|
->join("product_list b", "b.id = a.product_id", "left")
|
|
|
->join("products c", "c.id = b.type_id", "left")
|
|
|
@@ -138,10 +119,8 @@ class User extends Api
|
|
|
*/
|
|
|
public function getChaList(UserModel $userModel)
|
|
|
{
|
|
|
-
|
|
|
// 总推荐数
|
|
|
$list['total'] = $userModel::where('parent_id', $this->auth->id)->count();
|
|
|
-
|
|
|
// 直推列表
|
|
|
$list['data'] = $userModel::where('parent_id', $this->auth->id)
|
|
|
->field("address,create_time,nickname, REPLACE(phone, SUBSTRING(phone, 4, 4), '****') as phone")
|
|
|
@@ -178,12 +157,18 @@ class User extends Api
|
|
|
* @return void
|
|
|
*/
|
|
|
public function getOperateLog(ProductOrder $productOrder)
|
|
|
- {
|
|
|
+ {
|
|
|
+
|
|
|
+ $typeId = $this->request->post('type_id/d', 0);
|
|
|
+ $status = $this->request->post('status/d', 0);
|
|
|
+ $areaId = $this->request->post('area_id/s', 0);
|
|
|
+ $where = self::getOperateWhere($typeId, $status, $areaId);
|
|
|
$list['data'] = $productOrder->alias('a')
|
|
|
->join("product_list b", "b.id = a.product_id", "left")
|
|
|
->join("product_area d", "d.id = a.area_id", "left") //地区
|
|
|
->field('a.id as order_id,a.product_id,'.'b.'.$this->lan.'_name as name,b.thum as img_url,a.price,a.status,a.type_id,a.create_time,d.province,d.city,d.area,d.county')
|
|
|
->where('a.user_id', $this->auth->id)
|
|
|
+ ->where($where)
|
|
|
->order('a.id DESC')
|
|
|
->paginate($this->pageSize);
|
|
|
foreach ($list['data'] as &$item) {
|
|
|
@@ -197,274 +182,61 @@ class User extends Api
|
|
|
$this->success('', $list);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 提交出款信息
|
|
|
- * @return void
|
|
|
- */
|
|
|
- public function smhSubmit()
|
|
|
- {
|
|
|
- $amount = $this->request->post('amount'); // 金额
|
|
|
- $sign = $this->request->post('sign'); // 签名信
|
|
|
- $address = $this->request->post('address'); // 提现地址
|
|
|
- if(empty($sign)){
|
|
|
- $this->error('参数错误');
|
|
|
- }
|
|
|
- $real = $amount; // 实际到账
|
|
|
- $min = (new ParametersModel)->getValue('smhMinAmount') ?? '0';
|
|
|
- if ($amount <= 0) {
|
|
|
- $this->error('提现金额必须大于0');
|
|
|
- } else if ($amount < $min) {
|
|
|
- $this->error('提现金额不能小于' . $min);
|
|
|
- }
|
|
|
- $uid = $this->auth->getTokenUserID();
|
|
|
- // 用户信息
|
|
|
- $user = (new UserModel())->getById($uid);
|
|
|
- if (empty($user)) {
|
|
|
- $this->error('用户不存在');
|
|
|
- }
|
|
|
-
|
|
|
- $wallet = (new LedgerWalletModel())->getWallet($user['id']);
|
|
|
- if (empty($wallet)) {
|
|
|
- $this->error('用户不存在');
|
|
|
- }
|
|
|
- if($amount > $wallet['smh']){
|
|
|
- $this->error('SMH余额不足');
|
|
|
- }
|
|
|
- $rate = (new ParametersModel)->getValue('smhFeeRate') ?? '0';
|
|
|
- // 扣除手续费后
|
|
|
- if ($rate >= 0 && $rate < 1) { // 比例范围只在0-1之间
|
|
|
- $real = bcmul($amount, bcsub(1, $rate, 6), 6);
|
|
|
- }else{
|
|
|
- $this->error('手续费设置错误:' . $rate);
|
|
|
- }
|
|
|
- // 验签
|
|
|
- $signMsg = "EtcWithdraw"; // 与前端约定的固定值
|
|
|
- if (!checkSign($signMsg, $sign, $user['address'])) {
|
|
|
- $this->error('签名校验失败');
|
|
|
- }
|
|
|
-
|
|
|
- //有过出款记录,则不能修改出款钱包地址
|
|
|
- $wallet = (new OfflineWithdrawRecordModel())
|
|
|
- ->where('user_id', $user['id'])
|
|
|
- ->where('symbol', 'smh')
|
|
|
- ->where('status', OfflineWithdrawRecordModel::StatusSuccess)
|
|
|
- ->find();
|
|
|
- if (!empty($wallet)) {
|
|
|
- $address = $wallet['to_address'];
|
|
|
- }
|
|
|
-
|
|
|
- // 启动事务
|
|
|
- Db::startTrans();
|
|
|
- try {
|
|
|
- // 更新USDT和账变
|
|
|
- (new LedgerWalletModel())->changeWalletAccount($uid, Asset::SMH, -$amount, LedgerSmhChangeModel::WithdrawCash);
|
|
|
-
|
|
|
- // 创建提现记录
|
|
|
- $txHash = Random::uuid();
|
|
|
- (new OfflineWithdrawRecordModel())->createWithdraw($txHash, $uid, $amount, $real, $address, 'smh');
|
|
|
-
|
|
|
- // 提交事务
|
|
|
- Db::commit();
|
|
|
- } catch (Exception $e) {
|
|
|
- // 回滚事务
|
|
|
- Db::rollback();
|
|
|
- $this->error('提交失败:' . $e->getMessage());
|
|
|
- }
|
|
|
-
|
|
|
- $this->success('提现申请已提交');
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
- * 提交出款信息
|
|
|
- * @return void
|
|
|
+ * Nft搜索条件
|
|
|
+ * @return array
|
|
|
*/
|
|
|
- public function smhExchange()
|
|
|
- {
|
|
|
- $amount = $this->request->post('amount'); // 金额
|
|
|
-
|
|
|
- if($amount < 0.01){
|
|
|
- $this->error('兑换数量太少');
|
|
|
- }
|
|
|
-
|
|
|
- $uid = $this->auth->getTokenUserID();
|
|
|
-
|
|
|
- // 用户信息
|
|
|
- $user = (new UserModel())->getById($uid);
|
|
|
- if (empty($user)) {
|
|
|
- $this->error('用户不存在');
|
|
|
- }
|
|
|
-
|
|
|
- $wallet = (new LedgerWalletModel())->getWallet($user['id']);
|
|
|
- if (empty($wallet)) {
|
|
|
- $this->error('用户不存在');
|
|
|
- }
|
|
|
-
|
|
|
- if($amount > $wallet['smh']){
|
|
|
- $this->error('SMH余额不足');
|
|
|
- }
|
|
|
-
|
|
|
- $etc_ratio = (new ParametersModel())->getValue('smhExchangeRatio');//兑换手续费
|
|
|
- $etc_price = (new SmhWithdrawRecordModel())->getEtcPrice(); //ETC价格
|
|
|
-
|
|
|
- if($etc_ratio > 0.9){
|
|
|
- $this->error('兑换手续费异常');
|
|
|
- }
|
|
|
-
|
|
|
- $usdt_amount = $amount * $etc_price * (1 - $etc_ratio);
|
|
|
-
|
|
|
- // 启动事务
|
|
|
- Db::startTrans();
|
|
|
- try {
|
|
|
- // 更新ETC和账变
|
|
|
- (new LedgerWalletModel())->changeWalletAccount($uid, Asset::SMH, -$amount, LedgerSmhChangeModel::Exchange);
|
|
|
-
|
|
|
- // 更新USDT和账变
|
|
|
- (new LedgerWalletModel())->changeWalletAccount($uid, Asset::USDT, $usdt_amount, Action::EtcExchange);
|
|
|
-
|
|
|
- // 提交事务
|
|
|
- Db::commit();
|
|
|
- } catch (Exception $e) {
|
|
|
- // 回滚事务
|
|
|
- Db::rollback();
|
|
|
- $this->error('提交失败:' . $e->getMessage());
|
|
|
+ private static function getNftWhere(int $typeId, object $productOrder): array
|
|
|
+ {
|
|
|
+ $where = [];
|
|
|
+ switch ($typeId) {
|
|
|
+ case 0:
|
|
|
+ $where['a.status'] = ['<' , $productOrder::Shipped];
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ $where = ['a.type_id' => $productOrder::Transfer, 'a.status' => $productOrder::Transferred];
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ $where = ['a.type_id' => $productOrder::Transfer, 'a.status' => $productOrder::Closure];
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ $where = ['a.type_id' => $productOrder::Popular, 'a.status' => $productOrder::Cancelled];
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ $where = ['a.type_id' => $productOrder::Giveaway, 'a.status' => $productOrder::Closure];
|
|
|
+ break;
|
|
|
+ case 5:
|
|
|
+ $where = ['a.type_id' => $productOrder::Popular, 'a.status' => $productOrder::Shipped];
|
|
|
+ break;
|
|
|
}
|
|
|
-
|
|
|
- $this->success('提现申请已提交');
|
|
|
+ return $where;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
- * 获取aleo出款信息
|
|
|
- * @return void
|
|
|
+ * 操作记录搜索条件
|
|
|
+ * @return array
|
|
|
*/
|
|
|
- public function aleoInfo()
|
|
|
+ private static function getOperateWhere(int $typeId, int $status, string $areaId)
|
|
|
{
|
|
|
- $user = $this->auth->getUser();
|
|
|
- if (empty($user)) {
|
|
|
- $this->error('用户信息不存在');
|
|
|
- }
|
|
|
-
|
|
|
- $resp = [
|
|
|
- 'aleo' => '0', // 平台币余额
|
|
|
- 'aleo_min_amount' => 0, // 最低提现U数量
|
|
|
- 'tips' => "", //提现提示信息
|
|
|
- 'address' => "", // 出款地址,此地址有值时,前台不允许重新输入
|
|
|
- //'smh_price' => (new SmhWithdrawRecordModel())->getEtcPrice(), //smh价格
|
|
|
- //'smh_exchange_ratio' => (new ParametersModel())->getValue('smhExchangeRatio'), // smh兑换USDT手续费
|
|
|
- 'aleo_fee_rate' => (new ParametersModel())->getValue('aleoFeeRate'), // smh提现手续费
|
|
|
- ];
|
|
|
-
|
|
|
- $wallet = (new LedgerWalletModel())->getWallet($user['id']);
|
|
|
- if (!empty($wallet)) {
|
|
|
- $resp['aleo'] = $wallet['token'];
|
|
|
- }
|
|
|
-
|
|
|
- $config = (new ParametersModel)
|
|
|
- ->where('name', '=', 'aleoMinAmount')
|
|
|
- ->find();
|
|
|
- if(empty($config)){
|
|
|
- $this->error('未配置Aleo出款参数');
|
|
|
- }
|
|
|
- $resp['aleo_min_amount'] = $config['value'];
|
|
|
- $resp['tips'] = $config['tip'];
|
|
|
-
|
|
|
- $wallet = (new OfflineWithdrawRecordModel())
|
|
|
- ->where('user_id', $user['id'])
|
|
|
- ->where('symbol', 'aleo')
|
|
|
- ->where('status', OfflineWithdrawRecordModel::StatusSuccess)
|
|
|
- ->find();
|
|
|
- if (!empty($wallet)) {
|
|
|
- $resp['address'] = $wallet['to_address'];
|
|
|
- }
|
|
|
-
|
|
|
- $this->success('', $resp);
|
|
|
+ $where = [];
|
|
|
+ //类型
|
|
|
+ if($typeId > 0 || $status > 0) $where = ['a.type_id' => $typeId, 'a.status' => $status];
|
|
|
+ //编号Id
|
|
|
+ if(!empty($areaId)){
|
|
|
+ $arr = explode('-', $areaId);
|
|
|
+ if(count($arr) > 0) {
|
|
|
+ if(isset($arr[0])) $where['d.province'] = [ '=' , $arr[0]];
|
|
|
+ if(isset($arr[1])) $where['d.city'] = ['=', $arr[1]];
|
|
|
+ if(isset($arr[2])) $where['d.area'] = ['=', $arr[2]];
|
|
|
+ if(isset($arr[3])) $where['d.county'] = ['=', $arr[3]];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return $where;
|
|
|
}
|
|
|
- /**
|
|
|
- * 提交出款信息
|
|
|
- * @return void
|
|
|
- */
|
|
|
- public function aleoSubmit()
|
|
|
- {
|
|
|
- $amount = $this->request->post('amount'); // 金额
|
|
|
- $sign = $this->request->post('sign'); // 签名信
|
|
|
- $address = $this->request->post('address'); // 提现地址
|
|
|
-// $sign = 'test';
|
|
|
- if(empty($sign)){
|
|
|
- $this->error('参数错误');
|
|
|
- }
|
|
|
-
|
|
|
- $real = $amount; // 实际到账
|
|
|
- $min = (new ParametersModel)->getValue('aleoMinAmount') ?? '0';
|
|
|
- if ($amount <= 0) {
|
|
|
- $this->error('提现金额必须大于0');
|
|
|
- } else if ($amount < $min) {
|
|
|
- $this->error('提现金额不能小于' . $min);
|
|
|
- }
|
|
|
-
|
|
|
- $uid = $this->auth->getTokenUserID();
|
|
|
-
|
|
|
- // 用户信息
|
|
|
- $user = (new UserModel())->getById($uid);
|
|
|
- if (empty($user)) {
|
|
|
- $this->error('用户不存在');
|
|
|
- }
|
|
|
-
|
|
|
- $wallet = (new LedgerWalletModel())->getWallet($user['id']);
|
|
|
- if (empty($wallet)) {
|
|
|
- $this->error('用户不存在');
|
|
|
- }
|
|
|
|
|
|
- if($amount > $wallet['token']){
|
|
|
- $this->error('Aleo余额不足');
|
|
|
- }
|
|
|
-
|
|
|
- $rate = (new ParametersModel)->getValue('aleoFeeRate') ?? '0';
|
|
|
-
|
|
|
- // 扣除手续费后
|
|
|
- if ($rate >= 0 && $rate < 1) { // 比例范围只在0-1之间
|
|
|
- $real = bcmul($amount, bcsub(1, $rate, 6), 6);
|
|
|
- }else{
|
|
|
- $this->error('手续费设置错误:' . $rate);
|
|
|
- }
|
|
|
-
|
|
|
- // 验签
|
|
|
- $signMsg = "EtcWithdraw"; // 与前端约定的固定值
|
|
|
- if (!checkSign($signMsg, $sign, $user['address'])) {
|
|
|
- $this->error('签名校验失败');
|
|
|
- }
|
|
|
|
|
|
- //有过出款记录,则不能修改出款钱包地址
|
|
|
- $wallet = (new OfflineWithdrawRecordModel())
|
|
|
- ->where('user_id', $user['id'])
|
|
|
- ->where('symbol', 'aleo')
|
|
|
- ->where('status', OfflineWithdrawRecordModel::StatusSuccess)
|
|
|
- ->find();
|
|
|
- if (!empty($wallet)) {
|
|
|
- $address = $wallet['to_address'];
|
|
|
- }
|
|
|
|
|
|
- // 启动事务
|
|
|
- Db::startTrans();
|
|
|
- try {
|
|
|
- // 更新USDT和账变
|
|
|
- (new LedgerWalletModel())->changeWalletAccount($uid, Asset::TOKEN, -$amount, LedgerTokenChangeModel::WithdrawCash);
|
|
|
|
|
|
- // 创建提现记录
|
|
|
- $txHash = Random::uuid();
|
|
|
- (new OfflineWithdrawRecordModel())->createWithdraw($txHash, $uid, $amount, $real, $address, 'aleo');
|
|
|
-
|
|
|
- // 提交事务
|
|
|
- Db::commit();
|
|
|
- } catch (Exception $e) {
|
|
|
- // 回滚事务
|
|
|
- Db::rollback();
|
|
|
- $this->error('提交失败:' . $e->getMessage());
|
|
|
- }
|
|
|
-
|
|
|
- $this->success('提现申请已提交');
|
|
|
- }
|
|
|
+
|
|
|
+
|
|
|
}
|