User.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <?php
  2. namespace app\api\controller;
  3. use app\api\logic\OrderLogic;
  4. use app\api\logic\UserLogic;
  5. use app\common\controller\Api;
  6. use app\common\model\ProductOrder;
  7. use app\common\model\LedgerSmhChangeModel;
  8. use app\common\model\LedgerTokenChangeModel;
  9. use app\common\model\LedgerWalletModel;
  10. use app\common\model\ProductTransfer;
  11. use app\common\model\TeamLevelModel;
  12. use app\common\model\UserModel;
  13. use app\common\model\ProductBuying;
  14. use app\common\model\UserArea;
  15. use fast\Action;
  16. use fast\Asset;
  17. use fast\Random;
  18. use Google\Service\Storage\Resource\Objects;
  19. use think\Config;
  20. use think\Db;
  21. use think\Exception;
  22. /**
  23. * 会员接口
  24. */
  25. class User extends Api
  26. {
  27. protected string $lan = '';
  28. public function _initialize()
  29. {
  30. parent::_initialize();
  31. $this->lan = $this->request->getLan();
  32. }
  33. /**
  34. * 获取用户信息 *0.3
  35. * @return void
  36. */
  37. public function userInfo(UserArea $userArea,UserModel $userModel, LedgerWalletModel $ledgerWalletModel)
  38. {
  39. $user = $this->auth->getUser();
  40. if (!empty($user['is_super']) && empty($user['address_level'])) {
  41. $user['address_level'] = $userModel::updateUserAddresLevel($user['id'], $user['parent_id']);
  42. }
  43. $resp = [
  44. 'id' => $user['id'],
  45. 'nickname' => $user['nickname'],
  46. 'heading' => $user['heading'],
  47. 'address' => $user['address'],// 地址
  48. 'usdt' => '0', //USDT余额
  49. 'token' => '0', // 平台币余额
  50. 'name' => $user['name'], // 姓名
  51. 'phone' => $user['phone'], // 手机号
  52. 'rental_power' => '0', // 自己购买的算力
  53. 'team_power' => '0', // 团队总算里
  54. 'balance' => $ledgerWalletModel::getWalletChaBao($this->auth->id), // 余额
  55. 'rwa_num' => $user['rwa_num'], // 总茶权
  56. 'parent_id' => $user['parent_id'], // 上级ID
  57. 'is_super' => $user['address_level'], // 新人福利标识
  58. 'direct_super' => ['one'=>3, 'two'=>10,'direct_super'=>$user['direct_super']], // 推广新人福等级标识
  59. 'avatar' => !empty($user['avatar'])? $user['avatar']:$this->request->domain().'/assets/img/logo.png', // 头像
  60. 'parent_address' => '', // 上级的地址
  61. 'invite_link' => config('rental.invite_domain') . '/?inviteCode=' . $user['address'],
  62. 'take_address' => $userArea::getUserDefaultAdders($user['id']), // 用户地址
  63. ];
  64. $this->success('', $resp);
  65. }
  66. /**
  67. * 获取我的查询列表
  68. * param int $type_id 0总览 1转让中 2已转让 3存储中 4已赠送 5已提货
  69. * @return void
  70. */
  71. public function getNftList(ProductOrder $productOrder, ProductTransfer $productTransfer, UserLogic $userLogic)
  72. {
  73. $typeId = $this->request->post('type_id/d', 0);
  74. $productId = $this->request->post('product_id/d', 0);
  75. //搜索条件
  76. $where = $userLogic::getNftWhere($typeId, $productId, $productOrder);
  77. //查询
  78. $list = $userLogic::getUserNftList($productOrder, $productTransfer, $this->lan, $this->auth->id, $this->pageSize, $where);
  79. $this->success('', $list);
  80. }
  81. /**
  82. * 获取我的查询详情
  83. * param int $type_id 0总览 1转让中 2已转让 3存储中 4已赠送 5已提货
  84. * @return void
  85. */
  86. public function getMyNftList(ProductOrder $productOrder, UserLogic $userLogic)
  87. {
  88. $typeId = $this->request->post('type_id/d', 0);
  89. //搜索条件
  90. $where = $userLogic::getNftWhere($typeId, 0, $productOrder);
  91. //查询
  92. $list = $userLogic::getMyUserNftList($productOrder, $this->auth->id, $this->lan, $where, $this->pageSize);
  93. $this->success('', $list);
  94. }
  95. /**
  96. * 余额记录信息
  97. * @return void
  98. */
  99. public function getUserBalanceLog(LedgerTokenChangeModel $ledgerTokenChangeModel, UserLogic $userLogic)
  100. {
  101. $list = $userLogic::getUserBalanceLog($ledgerTokenChangeModel, $this->auth->id, $this->pageSize);
  102. $this->success('', $list);
  103. }
  104. /**
  105. * 我的茶友
  106. * @return void
  107. */
  108. public function getChaList(UserModel $userModel, UserLogic $userLogic)
  109. {
  110. $list = $userLogic::getUserChaList($userModel, $this->auth->id, $this->pageSize);
  111. $this->success('', $list);
  112. }
  113. //求购列表
  114. public function getBuyingList(ProductBuying $productBuying)
  115. {
  116. $this->success('ok', $productBuying::getUserBuyingList($this->auth->id, $this->lan, $this->pageSize));
  117. }
  118. /**
  119. * 修改个人信息
  120. * @return void
  121. */
  122. public function setUserInfo(UserModel $userModel, UserArea $userArea)
  123. {
  124. // 启动事务
  125. Db::startTrans();
  126. try {
  127. $param = $this->request->post();
  128. $validate = \think\Loader::validate('User');
  129. if(!$validate->scene(key($param))->check($param) || count($param) > 2 || empty($param)) $this->error(__("Invalid parameters"));
  130. if(!empty($param['area_code']) && !empty($param['address'])){
  131. $resp = $userArea::setUserAddress($this->auth->id, $param['area_code'], $param['address']);
  132. }else{
  133. $resp = $userModel::where('id', $this->auth->id)->update($param);
  134. }
  135. // 提交事务
  136. Db::commit();
  137. } catch (Exception $e) {
  138. // 回滚事务
  139. Db::rollback();
  140. $this->error( $e->getMessage());
  141. }
  142. $this->success('', $resp);
  143. }
  144. /**
  145. * 获取操作信息 购买、赠送、提货、转让
  146. * @return void
  147. */
  148. public function getOperateLog(ProductOrder $productOrder, UserLogic $userLogic)
  149. {
  150. $typeId = $this->request->post('type_id/d', 0);
  151. $status = $this->request->post('status/d', 0);
  152. $areaId = $this->request->post('area_id/s', 0);
  153. //搜索条件
  154. $where = $userLogic::getOperateWhere($typeId, $status, $areaId);
  155. //查询
  156. $list = $userLogic::getUserOperateLog($productOrder, $this->lan, $this->auth->id, $this->pageSize, $where);
  157. $this->success('', $list);
  158. }
  159. //获取用户待支付订单数量
  160. public function getWaitPayOrderCount(OrderLogic $orderLogic)
  161. {
  162. $count = $orderLogic::getWaitPayOrderCount($this->auth->id, config('market_transfer.lock_time'));
  163. $this->success('', $count);
  164. }
  165. //获取用户待支付订单
  166. public function getWaitPayOrderList(OrderLogic $orderLogic)
  167. {
  168. $list = $orderLogic::getWaitPayOrderList($this->auth->id, config('market_transfer.lock_time'), $this->pageSize, $this->lan);
  169. $this->success('', $list);
  170. }
  171. //取消用户待支付订单
  172. public function setCancelWaitPayOrder(OrderLogic $orderLogic)
  173. {
  174. $transfer_id = $this->request->post('transfer_id/d', 0);
  175. if(empty($transfer_id)) $this->error(__('Invalid parameters'));
  176. $list = $orderLogic::setCancelWaitPayOrder($this->auth->id, $transfer_id);
  177. $this->success('ok', $list);
  178. }
  179. }