User.php 11 KB

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