User.php 11 KB

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