User.php 7.8 KB

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