User.php 8.9 KB

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