| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use app\common\model\ProductOrder;
- use app\common\model\LedgerSmhChangeModel;
- use app\common\model\LedgerTokenChangeModel;
- use app\common\model\LedgerWalletModel;
- use app\common\model\OfflineWithdrawRecordModel;
- use app\common\model\TeamLevelModel;
- use app\common\model\UserModel;
- use app\common\model\ParametersModel;
- use app\common\model\UserArea;
- use fast\Action;
- use fast\Asset;
- use fast\Random;
- use Google\Service\Storage\Resource\Objects;
- use think\Config;
- use think\Db;
- use think\Exception;
- /**
- * 会员接口
- */
- class User extends Api
- {
- protected string $lan = '';
- public function _initialize()
- {
- parent::_initialize();
- $this->lan = $this->request->getLan();
- }
- /**
- * 获取用户信息
- * @return void
- */
- public function userInfo(UserArea $userArea, LedgerWalletModel $ledgerWalletModel)
- {
- $user = $this->auth->getUser();
- $resp = [
- 'id' => $user['id'],
- 'nickname' => $user['nickname'],
- 'address' => $user['address'],// 地址
- 'usdt' => '0', //USDT余额
- 'token' => '0', // 平台币余额
- 'name' => $user['name'], // 姓名
- 'phone' => $user['phone'], // 手机号
- 'rental_power' => '0', // 自己购买的算力
- 'team_power' => '0', // 团队总算里
- 'balance' => $ledgerWalletModel::getWalletChaBao($this->auth->id), // 余额
- 'rwa_num' => $user['rwa_num'], // 总茶权
- 'parent_id' => $user['parent_id'], // 上级ID
- 'parent_address' => '', // 上级的地址
- 'invite_link' => config('rental.invite_domain') . '/?inviteCode=' . $user['address'],
- 'take_address' => $userArea::getUserDefaultAdders($user['id']), // 用户地址
- ];
- $this->success('', $resp);
- }
- /**
- * 获取Nft列表
- * param int $type_id 0总览 1转让中 2已转让 3存储中 4已赠送 5已提货
- * @return void
- */
- public function getNftList(ProductOrder $productOrder)
- {
- $typeId = $this->request->post('type_id/d', 0);
- $where = self::getNftWhere($typeId, $productOrder);
- $list = $productOrder->alias('a')
- ->join("product_list b", "b.id = a.product_id", "left")
- ->join("products c", "c.id = b.type_id", "left")
- ->join("product_transfer z", "a.id = z.order_id AND a.status=2", "left") //转让
- ->join("product_area d", "d.id = a.area_id", "left") //地区
- ->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')
- ->where('a.user_id', $this->auth->id)
- ->where($where)
- ->order('a.id DESC')
- ->paginate($this->pageSize);
- $this->success('', $list);
- }
- /**
- * 余额记录信息
- * @return void
- */
- public function getUserBalanceLog(LedgerTokenChangeModel $ledgerTokenChangeModel, LedgerWalletModel $ledgerWalletModel)
- {
- // 启动事务
- Db::startTrans();
- try {
- $list['total'] = $ledgerTokenChangeModel::where('user_id', $this->auth->id)
- ->where('action', $ledgerWalletModel::Share)
- ->sum("change_amount");
- $list['data'] = $ledgerTokenChangeModel::where('user_id', $this->auth->id)
- ->where('action', $ledgerWalletModel::Share)
- ->order('id desc')
- ->paginate($this->pageSize);
- $list['statusList'] = $ledgerWalletModel::getStatusList();
- // 提交事务
- Db::commit();
- } catch (Exception $e) {
- // 回滚事务
- Db::rollback();
- $this->error($e->getMessage());
- }
- $this->success('', $list);
- }
- /**
- * 我的茶友
- * @return void
- */
- public function getChaList(UserModel $userModel)
- {
- // 总推荐数
- $list['total'] = $userModel::where('parent_id', $this->auth->id)->count();
- // 直推列表
- $list['data'] = $userModel::where('parent_id', $this->auth->id)
- ->field("address,create_time,nickname, REPLACE(phone, SUBSTRING(phone, 4, 4), '****') as phone")
- ->order('id desc')
- ->paginate($this->pageSize);
- $this->success('', $list);
- }
- /**
- * 修改个人信息
- * @return void
- */
- public function setUserInfo(UserModel $userModel, UserArea $userArea)
- {
- // 启动事务
- Db::startTrans();
- try {
- $param = $this->request->post();
- $validate = \think\Loader::validate('User');
- if(!$validate->scene(key($param))->check($param) || count($param) > 2 || empty($param)) $this->error(__("Invalid parameters"));
- if(!empty($param['area_code']) && !empty($param['address'])){
- $resp = $userArea::setUserAddress($this->auth->id, $param['area_code'], $param['address']);
- }else{
- $resp = $userModel::where('id', $this->auth->id)->update($param);
- }
- // 提交事务
- Db::commit();
- } catch (Exception $e) {
- // 回滚事务
- Db::rollback();
- $this->error( $e->getMessage());
- }
- $this->success('', $resp);
- }
- /**
- * 获取操作信息 购买、赠送、提货、转让
- * @return void
- */
- public function getOperateLog(ProductOrder $productOrder)
- {
- $typeId = $this->request->post('type_id/d', 0);
- $status = $this->request->post('status/d', 0);
- $areaId = $this->request->post('area_id/s', 0);
- $where = self::getOperateWhere($typeId, $status, $areaId);
- $list['data'] = $productOrder->alias('a')
- ->join("product_list b", "b.id = a.product_id", "left")
- ->join("product_area d", "d.id = a.area_id", "left") //地区
- ->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')
- ->where('a.user_id', $this->auth->id)
- ->where($where)
- ->order('a.id DESC')
- ->paginate($this->pageSize);
- foreach ($list['data'] as &$item) {
- $item->address_id = '';
- if($item->province > 0) $item->address_id .= $item->province.'-';
- if($item->city > 0) $item->address_id .= $item->city.'-';
- if($item->area > 0) $item->address_id .= $item->area.'-';
- if($item->county > 0) $item->address_id .= $item->county.'-';
- $item->address_id = rtrim($item->address_id, '-');
- }
- $list['statusList'] = $productOrder::getStatusAll();
- $this->success('', $list);
- }
- /**
- * Nft搜索条件
- * @return array
- */
- private static function getNftWhere(int $typeId, object $productOrder): array
- {
- $where = [];
- switch ($typeId) {
- case 0:
- $where['a.status'] = ['<' , $productOrder::Shipped];
- break;
- case 1:
- $where = ['a.type_id' => $productOrder::Transfer, 'a.status' => $productOrder::Transferred];
- break;
- case 2:
- $where = ['a.type_id' => $productOrder::Transfer, 'a.status' => $productOrder::Closure];
- break;
- case 3:
- $where = ['a.type_id' => $productOrder::Popular, 'a.status' => $productOrder::Cancelled];
- break;
- case 4:
- $where = ['a.type_id' => $productOrder::Giveaway, 'a.status' => $productOrder::Closure];
- break;
- case 5:
- $where = ['a.type_id' => $productOrder::Popular, 'a.status' => $productOrder::Shipped];
- break;
- }
- return $where;
- }
- /**
- * 操作记录搜索条件
- * @return array
- */
- private static function getOperateWhere(int $typeId, int $status, string $areaId)
- {
- $where = [];
- //类型
- if($typeId > 0 || $status > 0) $where = ['a.type_id' => $typeId, 'a.status' => $status];
- //编号Id
- if(!empty($areaId)){
- $arr = explode('-', $areaId);
- if(count($arr) > 0) {
- if(isset($arr[0])) $where['d.province'] = [ '=' , $arr[0]];
- if(isset($arr[1])) $where['d.city'] = ['=', $arr[1]];
- if(isset($arr[2])) $where['d.area'] = ['=', $arr[2]];
- if(isset($arr[3])) $where['d.county'] = ['=', $arr[3]];
- }
- }
- return $where;
- }
-
-
- }
|