User.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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. 'heading' => $user['heading'],
  42. 'address' => $user['address'],// 地址
  43. 'usdt' => '0', //USDT余额
  44. 'token' => '0', // 平台币余额
  45. 'name' => $user['name'], // 姓名
  46. 'phone' => $user['phone'], // 手机号
  47. 'rental_power' => '0', // 自己购买的算力22
  48. 'team_power' => '0', // 团队总算里
  49. 'balance' => $ledgerWalletModel::getWalletChaBao($this->auth->id), // 余额
  50. 'rwa_num' => $user['rwa_num'], // 总茶权
  51. 'parent_id' => $user['parent_id'], // 上级ID
  52. 'avatar' => !empty($user['avatar'])? $user['avatar']:$this->request->domain().'/assets/img/logo.png', // 头像
  53. 'parent_address' => '', // 上级的地址
  54. 'invite_link' => config('rental.invite_domain') . '/?inviteCode=' . $user['address'],
  55. 'take_address' => $userArea::getUserDefaultAdders($user['id']), // 用户地址
  56. ];
  57. $this->success('', $resp);
  58. }
  59. /**
  60. * 获取Nft列表
  61. * param int $type_id 0总览 1转让中 2已转让 3存储中 4已赠送 5已提货
  62. * @return void
  63. */
  64. public function getNftList(ProductOrder $productOrder)
  65. {
  66. $typeId = $this->request->post('type_id/d', 0);
  67. $productId = $this->request->post('product_id/d', 0);
  68. $where = self::getNftWhere($typeId, $productId, $productOrder);
  69. $list = $productOrder->alias('a')
  70. ->join("product_list b", "b.id = a.product_id", "left")
  71. ->join("products c", "c.id = b.type_id", "left")
  72. ->join("product_transfer z", "a.id = z.order_id AND a.status=2", "left") //转让
  73. ->join("product_area d", "d.id = a.area_id", "left") //地区
  74. ->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,
  75. z.price as transfer_price,d.address,b.min_transfer_fee,b.max_transfer_fee,b.gift_fee,b.freight,b.is_transfer,b.is_gift,b.is_freight,b.is_storage,b.is_buying')
  76. ->where('a.user_id', $this->auth->id)
  77. ->where($where)
  78. ->order('a.id DESC')
  79. ->paginate($this->pageSize);
  80. $this->success('', $list);
  81. }
  82. /**
  83. * 获取我的Nft列表
  84. * param int $type_id 0总览 1转让中 2已转让 3存储中 4已赠送 5已提货
  85. * @return void
  86. */
  87. public function getMyNftList(ProductOrder $productOrder)
  88. {
  89. $typeId = $this->request->post('type_id/d', 0);
  90. $where = self::getNftWhere($typeId, 0, $productOrder);
  91. $list = $productOrder->alias('a')
  92. ->join("product_list b", "b.id = a.product_id", "left")
  93. ->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, count(a.num) as hold_num')
  94. ->where('a.user_id', $this->auth->id)
  95. ->group('a.product_id')
  96. ->where($where)
  97. ->order('a.id DESC')
  98. ->paginate($this->pageSize);
  99. $this->success('', $list);
  100. }
  101. /**
  102. * 余额记录信息
  103. * @return void
  104. */
  105. public function getUserBalanceLog(LedgerTokenChangeModel $ledgerTokenChangeModel, LedgerWalletModel $ledgerWalletModel)
  106. {
  107. // 启动事务
  108. Db::startTrans();
  109. try {
  110. $list['total'] = $ledgerTokenChangeModel::where('user_id', $this->auth->id)
  111. ->where('action', $ledgerWalletModel::Share)
  112. ->sum("change_amount");
  113. $list['data'] = $ledgerTokenChangeModel::where('user_id', $this->auth->id)
  114. ->where('action', $ledgerWalletModel::Share)
  115. ->order('id desc')
  116. ->paginate($this->pageSize);
  117. $list['statusList'] = $ledgerWalletModel::getStatusList();
  118. // 提交事务
  119. Db::commit();
  120. } catch (Exception $e) {
  121. // 回滚事务
  122. Db::rollback();
  123. $this->error($e->getMessage());
  124. }
  125. $this->success('', $list);
  126. }
  127. /**
  128. * 我的茶友
  129. * @return void
  130. */
  131. public function getChaList(UserModel $userModel)
  132. {
  133. // 总推荐数
  134. $list['total'] = $userModel::where('parent_id', $this->auth->id)->count();
  135. // 直推列表
  136. $list['data'] = $userModel::where('parent_id', $this->auth->id)
  137. ->field("address,create_time,nickname, REPLACE(phone, SUBSTRING(phone, 4, 4), '****') as phone")
  138. ->order('id desc')
  139. ->paginate($this->pageSize);
  140. $this->success('', $list);
  141. }
  142. /**
  143. * 修改个人信息
  144. * @return void
  145. */
  146. public function setUserInfo(UserModel $userModel, UserArea $userArea)
  147. {
  148. // 启动事务
  149. Db::startTrans();
  150. try {
  151. $param = $this->request->post();
  152. $validate = \think\Loader::validate('User');
  153. if(!$validate->scene(key($param))->check($param) || count($param) > 2 || empty($param)) $this->error(__("Invalid parameters"));
  154. if(!empty($param['area_code']) && !empty($param['address'])){
  155. $resp = $userArea::setUserAddress($this->auth->id, $param['area_code'], $param['address']);
  156. }else{
  157. $resp = $userModel::where('id', $this->auth->id)->update($param);
  158. }
  159. // 提交事务
  160. Db::commit();
  161. } catch (Exception $e) {
  162. // 回滚事务
  163. Db::rollback();
  164. $this->error( $e->getMessage());
  165. }
  166. $this->success('', $resp);
  167. }
  168. /**
  169. * 获取操作信息 购买、赠送、提货、转让
  170. * @return void
  171. */
  172. public function getOperateLog(ProductOrder $productOrder)
  173. {
  174. $typeId = $this->request->post('type_id/d', 0);
  175. $status = $this->request->post('status/d', 0);
  176. $areaId = $this->request->post('area_id/s', 0);
  177. $where = self::getOperateWhere($typeId, $status, $areaId);
  178. $list['data'] = $productOrder->alias('a')
  179. ->join("product_list b", "b.id = a.product_id", "left")
  180. ->join("product_area d", "d.id = a.area_id", "left") //地区
  181. ->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')
  182. ->where('a.user_id', $this->auth->id)
  183. ->where($where)
  184. ->order('a.id DESC')
  185. ->paginate($this->pageSize);
  186. foreach ($list['data'] as &$item) {
  187. $item->address_id = '';
  188. if($item->province > 0) $item->address_id .= $item->province.'-';
  189. if($item->city > 0) $item->address_id .= $item->city.'-';
  190. if($item->area > 0) $item->address_id .= $item->area.'-';
  191. if($item->county > 0) $item->address_id .= $item->county.'-';
  192. $item->address_id = rtrim($item->address_id, '-');
  193. }
  194. $list['statusList'] = $productOrder::getStatusAll();
  195. $this->success('', $list);
  196. }
  197. /**
  198. * Nft搜索条件
  199. * @return array
  200. */
  201. private static function getNftWhere(int $typeId, int $productId , object $productOrder): array
  202. {
  203. $where = [];
  204. switch ($typeId) {
  205. case 0:
  206. $where['a.status'] = ['=' , $productOrder::Paid];
  207. break;
  208. case 1:
  209. $where = ['a.type_id' => $productOrder::Transfer, 'a.status' => $productOrder::Transferred];
  210. break;
  211. case 2:
  212. $where = ['a.type_id' => $productOrder::Transfer, 'a.status' => $productOrder::Closure];
  213. break;
  214. case 3:
  215. $where = ['a.type_id' => $productOrder::Popular, 'a.status' => $productOrder::Cancelled];
  216. break;
  217. case 4:
  218. $where = ['a.type_id' => $productOrder::Giveaway, 'a.status' => $productOrder::Closure];
  219. break;
  220. case 5:
  221. $where = ['a.type_id' => $productOrder::Popular, 'a.status' => $productOrder::Shipped];
  222. break;
  223. }
  224. if($productId > 0) $where['a.product_id'] = ['=' , $productId];
  225. return $where;
  226. }
  227. /**
  228. * 操作记录搜索条件
  229. * @return array
  230. */
  231. private static function getOperateWhere(int $typeId, int $status, string $areaId)
  232. {
  233. $where = [];
  234. //类型
  235. if($typeId > 0 || $status > 0) $where = ['a.type_id' => $typeId, 'a.status' => $status];
  236. //编号Id
  237. if(!empty($areaId)){
  238. $arr = explode('-', $areaId);
  239. if(count($arr) > 0) {
  240. if(isset($arr[0])) $where['d.province'] = ['=', $arr[0]];
  241. if(isset($arr[1])) $where['d.city'] = ['=', $arr[1]];
  242. if(isset($arr[2])) $where['d.area'] = ['=', $arr[2]];
  243. if(isset($arr[3])) $where['d.county'] = ['=', $arr[3]];
  244. }
  245. }
  246. return $where;
  247. }
  248. }