User.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. * 获取用户信息
  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['is_super'], // 新人福利标识
  58. 'direct_super' => ['one'=>3, 'two'=>10,'direct_super'=>$user['direct_super'], 'address_level'=>$user['address_level']], // 推广新人福等级标识
  59. 'is_ecology' => $user['is_ecology'], // 生态标识
  60. 'avatar' => isHttpOrHttps($user['avatar'])? $user['avatar']: $this->request->domain().'/assets/img/logo.png', // 头像
  61. 'parent_address' => '', // 上级的地址
  62. 'team_level_id' => $user['team_level_id'], // 团队等级
  63. 'invite_link' => config('rental.invite_domain') . '/?inviteCode=' . $user['address'],
  64. 'take_address' => $userArea::getUserDefaultAdders($user['id']), // 用户地址
  65. ];
  66. $this->success('', $resp);
  67. }
  68. /**
  69. * 获取我的查询列表
  70. * param int $type_id 0总览 1转让中 2已转让 3存储中 4已赠送 5已提货
  71. * @return void
  72. */
  73. public function getNftList(ProductOrder $productOrder, ProductTransfer $productTransfer, UserLogic $userLogic)
  74. {
  75. $typeId = $this->request->post('type_id/d', 0);
  76. $productId = $this->request->post('product_id/d', 0);
  77. //搜索条件
  78. $where = $userLogic::getNftWhere($typeId, $productId, $productOrder);
  79. //查询
  80. $list = $userLogic::getUserNftList($productOrder, $productTransfer, $this->lan, $this->auth->id, $this->pageSize, $where);
  81. $this->success('', $list);
  82. }
  83. /**
  84. * 获取我的查询详情
  85. * param int $type_id 0总览 1转让中 2已转让 3存储中 4已赠送 5已提货
  86. * @return void
  87. */
  88. public function getMyNftList(ProductOrder $productOrder, UserLogic $userLogic)
  89. {
  90. $typeId = $this->request->post('type_id/d', 0);
  91. //搜索条件
  92. $where = $userLogic::getNftWhere($typeId, 0, $productOrder);
  93. //查询
  94. $list = $userLogic::getMyUserNftList($productOrder, $this->auth->id, $this->lan, $where, $this->pageSize);
  95. $this->success('', $list);
  96. }
  97. /**
  98. * 余额记录信息
  99. * @return void
  100. */
  101. public function getUserBalanceLog(LedgerTokenChangeModel $ledgerTokenChangeModel, UserLogic $userLogic)
  102. {
  103. $list = $userLogic::getUserBalanceLog($ledgerTokenChangeModel, $this->auth->id, $this->pageSize);
  104. $this->success('', $list);
  105. }
  106. /**
  107. * 我的茶友
  108. * @return void
  109. */
  110. public function getChaList(UserModel $userModel, UserLogic $userLogic)
  111. {
  112. $list = $userLogic::getUserChaList($userModel, $this->auth->id, $this->pageSize);
  113. $this->success('', $list);
  114. }
  115. //求购列表
  116. public function getBuyingList(ProductBuying $productBuying)
  117. {
  118. $this->success('ok', $productBuying::getUserBuyingList($this->auth->id, $this->lan, $this->pageSize));
  119. }
  120. /**
  121. * 修改个人信息
  122. * @return void
  123. */
  124. public function setUserInfo(UserModel $userModel, UserArea $userArea)
  125. {
  126. // 启动事务
  127. Db::startTrans();
  128. try {
  129. $param = $this->request->post();
  130. $validate = \think\Loader::validate('User');
  131. if(!$validate->scene(key($param))->check($param) || count($param) > 2 || empty($param)) $this->error(__("Invalid parameters"));
  132. if(!empty($param['area_code']) && !empty($param['address'])){
  133. $resp = $userArea::setUserAddress($this->auth->id, $param['area_code'], $param['address']);
  134. }else{
  135. $resp = $userModel::where('id', $this->auth->id)->update($param);
  136. }
  137. // 提交事务
  138. Db::commit();
  139. } catch (Exception $e) {
  140. // 回滚事务
  141. Db::rollback();
  142. $this->error( $e->getMessage());
  143. }
  144. $this->success('', $resp);
  145. }
  146. /**
  147. * 获取操作信息 购买、赠送、提货、转让
  148. * @return void
  149. */
  150. public function getOperateLog(ProductOrder $productOrder, UserLogic $userLogic)
  151. {
  152. $typeId = $this->request->post('type_id/d', 0);
  153. $status = $this->request->post('status/d', 0);
  154. $areaId = $this->request->post('area_id/s', 0);
  155. //搜索条件
  156. $where = $userLogic::getOperateWhere($typeId, $status, $areaId);
  157. //查询
  158. $list = $userLogic::getUserOperateLog($productOrder, $this->lan, $this->auth->id, $this->pageSize, $where);
  159. $this->success('', $list);
  160. }
  161. //获取用户待支付订单数量
  162. public function getWaitPayOrderCount(OrderLogic $orderLogic)
  163. {
  164. $count = $orderLogic::getWaitPayOrderCount($this->auth->id, config('market_transfer.lock_time'));
  165. $this->success('', $count);
  166. }
  167. //获取用户待支付订单
  168. public function getWaitPayOrderList(OrderLogic $orderLogic)
  169. {
  170. $list = $orderLogic::getWaitPayOrderList($this->auth->id, config('market_transfer.lock_time'), $this->pageSize, $this->lan);
  171. $this->success('', $list);
  172. }
  173. //取消用户待支付订单
  174. public function setCancelWaitPayOrder(OrderLogic $orderLogic)
  175. {
  176. $transfer_id = $this->request->post('transfer_id/d', 0);
  177. if(empty($transfer_id)) $this->error(__('Invalid parameters'));
  178. $list = $orderLogic::setCancelWaitPayOrder($this->auth->id, $transfer_id);
  179. $this->success('ok', $list);
  180. }
  181. }