User.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use app\common\model\ProductOrder;
  5. use app\common\model\LedgerSmhChangeModel;
  6. use app\common\model\LedgerTokenChangeModel;
  7. use app\common\model\LedgerWalletModel;
  8. use app\common\model\OfflineWithdrawRecordModel;
  9. use app\common\model\TeamLevelModel;
  10. use app\common\model\UserModel;
  11. use app\common\model\ParametersModel;
  12. use fast\Action;
  13. use fast\Asset;
  14. use fast\Random;
  15. use Google\Service\Storage\Resource\Objects;
  16. use think\Config;
  17. use think\Db;
  18. use think\Exception;
  19. /**
  20. * 会员接口
  21. */
  22. class User extends Api
  23. {
  24. protected string $lan = '';
  25. public function _initialize()
  26. {
  27. parent::_initialize();
  28. $this->lan = $this->request->getLan();
  29. }
  30. /**
  31. * 获取用户信息
  32. * @return void
  33. */
  34. public function userInfo()
  35. {
  36. $user = $this->auth->getUser();
  37. $resp = [
  38. 'id' => $user['id'],
  39. 'nickname' => $user['nickname'],
  40. 'address' => $user['address'],// 地址
  41. 'usdt' => '0', //USDT余额
  42. 'token' => '0', // 平台币余额
  43. 'name' => $user['name'], // 姓名
  44. 'phone' => $user['phone'], // 手机号
  45. 'rental_power' => '0', // 自己购买的算力
  46. 'team_power' => '0', // 团队总算里
  47. 'balance' => LedgerWalletModel::getWalletChaBao($this->auth->id), // 余额
  48. 'rwa_num' => $user['rwa_num'], // 总茶权
  49. 'parent_id' => $user['parent_id'], // 上级ID
  50. 'parent_address' => '', // 上级的地址
  51. 'invite_link' => Config::get('rental.invite_domain') . '/?inviteCode=' . $user['address'],
  52. ];
  53. $this->success('', $resp);
  54. }
  55. /**
  56. * 获取Nft列表
  57. * param int $type_id 0总览 1转让中 2已转让 3存储中 4已赠送 5已提货
  58. * @return void
  59. */
  60. public function getNftList(ProductOrder $productOrder)
  61. {
  62. $typeId = $this->request->post('type_id/d', 0);
  63. $where = self::getNftWhere($typeId, $productOrder);
  64. $list = $productOrder->alias('a')
  65. ->join("product_list b", "b.id = a.product_id", "left")
  66. ->join("products c", "c.id = b.type_id", "left")
  67. ->join("product_transfer z", "a.id = z.order_id AND a.status=2", "left") //转让
  68. ->join("product_area d", "d.id = a.area_id", "left") //地区
  69. ->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,c.'.$this->lan.'_title as title,z.price as transfer_price,d.address')
  70. ->where('a.user_id', $this->auth->id)
  71. ->where($where)
  72. ->order('a.id DESC')
  73. ->paginate($this->pageSize);
  74. $this->success('', $list);
  75. }
  76. /**
  77. * 余额记录信息
  78. * @return void
  79. */
  80. public function getUserBalanceLog(LedgerTokenChangeModel $ledgerTokenChangeModel, LedgerWalletModel $ledgerWalletModel)
  81. {
  82. // 启动事务
  83. Db::startTrans();
  84. try {
  85. $list['total'] = $ledgerTokenChangeModel::where('user_id', $this->auth->id)
  86. ->where('action', $ledgerWalletModel::Share)
  87. ->sum("change_amount");
  88. $list['data'] = $ledgerTokenChangeModel::where('user_id', $this->auth->id)
  89. ->where('action', $ledgerWalletModel::Share)
  90. ->order('id desc')
  91. ->paginate($this->pageSize);
  92. $list['statusList'] = $ledgerWalletModel::getStatusList();
  93. // 提交事务
  94. Db::commit();
  95. } catch (Exception $e) {
  96. // 回滚事务
  97. Db::rollback();
  98. $this->error($e->getMessage());
  99. }
  100. $this->success('', $list);
  101. }
  102. /**
  103. * 我的茶友
  104. * @return void
  105. */
  106. public function getChaList(UserModel $userModel)
  107. {
  108. // 总推荐数
  109. $list['total'] = $userModel::where('parent_id', $this->auth->id)->count();
  110. // 直推列表
  111. $list['data'] = $userModel::where('parent_id', $this->auth->id)
  112. ->field("address,create_time,nickname, REPLACE(phone, SUBSTRING(phone, 4, 4), '****') as phone")
  113. ->order('id desc')
  114. ->paginate($this->pageSize);
  115. $this->success('', $list);
  116. }
  117. /**
  118. * 修改个人信息
  119. * @return void
  120. */
  121. public function setUserInfo(UserModel $userModel)
  122. {
  123. // 启动事务
  124. Db::startTrans();
  125. try {
  126. $param = $this->request->post();
  127. if(!isset($param['name']) && !isset($param['nickname']) && !isset($param['phone'])) throw new Exception(__("Invalid parameters"));
  128. $resp = $userModel::where('id', $this->auth->id)->update($param);
  129. // 提交事务
  130. Db::commit();
  131. } catch (Exception $e) {
  132. // 回滚事务
  133. Db::rollback();
  134. $this->error( $e->getMessage());
  135. }
  136. $this->success('', $resp);
  137. }
  138. /**
  139. * 获取操作信息 购买、赠送、提货、转让
  140. * @return void
  141. */
  142. public function getOperateLog(ProductOrder $productOrder)
  143. {
  144. $typeId = $this->request->post('type_id/d', 0);
  145. $status = $this->request->post('status/d', 0);
  146. $areaId = $this->request->post('area_id/s', 0);
  147. $where = self::getOperateWhere($typeId, $status, $areaId);
  148. $list['data'] = $productOrder->alias('a')
  149. ->join("product_list b", "b.id = a.product_id", "left")
  150. ->join("product_area d", "d.id = a.area_id", "left") //地区
  151. ->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')
  152. ->where('a.user_id', $this->auth->id)
  153. ->where($where)
  154. ->order('a.id DESC')
  155. ->paginate($this->pageSize);
  156. foreach ($list['data'] as &$item) {
  157. if($item->province > 0) $item->address_id = $item->province.'-';
  158. if($item->city > 0) $item->address_id .= $item->city.'-';
  159. if($item->area > 0) $item->address_id .= $item->area.'-';
  160. if($item->county > 0) $item->address_id .= $item->county.'-';
  161. $item->address_id = rtrim($item->address_id, '-');
  162. }
  163. $list['statusList'] = $productOrder::getStatusAll();
  164. $this->success('', $list);
  165. }
  166. /**
  167. * Nft搜索条件
  168. * @return array
  169. */
  170. private static function getNftWhere(int $typeId, object $productOrder): array
  171. {
  172. $where = [];
  173. switch ($typeId) {
  174. case 0:
  175. $where['a.status'] = ['<' , $productOrder::Shipped];
  176. break;
  177. case 1:
  178. $where = ['a.type_id' => $productOrder::Transfer, 'a.status' => $productOrder::Transferred];
  179. break;
  180. case 2:
  181. $where = ['a.type_id' => $productOrder::Transfer, 'a.status' => $productOrder::Closure];
  182. break;
  183. case 3:
  184. $where = ['a.type_id' => $productOrder::Popular, 'a.status' => $productOrder::Cancelled];
  185. break;
  186. case 4:
  187. $where = ['a.type_id' => $productOrder::Giveaway, 'a.status' => $productOrder::Closure];
  188. break;
  189. case 5:
  190. $where = ['a.type_id' => $productOrder::Popular, 'a.status' => $productOrder::Shipped];
  191. break;
  192. }
  193. return $where;
  194. }
  195. /**
  196. * 操作记录搜索条件
  197. * @return array
  198. */
  199. private static function getOperateWhere(int $typeId, int $status, string $areaId)
  200. {
  201. $where = [];
  202. //类型
  203. if($typeId > 0 || $status > 0) $where = ['a.type_id' => $typeId, 'a.status' => $status];
  204. //编号Id
  205. if(!empty($areaId)){
  206. $arr = explode('-', $areaId);
  207. if(count($arr) > 0) {
  208. if(isset($arr[0])) $where['d.province'] = [ '=' , $arr[0]];
  209. if(isset($arr[1])) $where['d.city'] = ['=', $arr[1]];
  210. if(isset($arr[2])) $where['d.area'] = ['=', $arr[2]];
  211. if(isset($arr[3])) $where['d.county'] = ['=', $arr[3]];
  212. }
  213. }
  214. return $where;
  215. }
  216. }