User.php 7.2 KB

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