lan = $this->request->getLan(); } /** * 获取用户信息 * @return void */ public function userInfo(UserArea $userArea,UserModel $userModel, LedgerWalletModel $ledgerWalletModel) { $user = $this->auth->getUser(); $resp = [ 'id' => $user['id'], 'nickname' => $user['nickname'], 'heading' => $user['heading'], 'address' => $user['address'],// 地址 'usdt' => '0', //USDT余额 'token' => '0', // 平台币余额 'name' => $user['name'], // 姓名 'phone' => $user['phone'], // 手机号 'rental_power' => '0', // 自己购买的算力22 'team_power' => '0', // 团队总算里 'balance' => $ledgerWalletModel::getWalletChaBao($this->auth->id), // 余额 'rwa_num' => $user['rwa_num'], // 总茶权 'parent_id' => $user['parent_id'], // 上级ID 'is_super' => $user['is_super'], // 新人福利标识 'direct_super' => ['one'=>3, 'two'=>10,'direct_super'=>$user['direct_super']], // 推广新人福等级标识 'direct_gold' => $userModel::getDirectGoldNum($user['id']), // 推广黄金地址标识数量 'avatar' => !empty($user['avatar'])? $user['avatar']:$this->request->domain().'/assets/img/logo.png', // 头像 '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); $productId = $this->request->post('product_id/d', 0); $where = self::getNftWhere($typeId, $productId, $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.order_no,a.type_id,c.'.$this->lan.'_title as title, 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') ->where('a.user_id', $this->auth->id) ->where($where) ->order('a.id DESC') ->paginate($this->pageSize); $this->success('', $list); } /** * 获取我的Nft列表 * param int $type_id 0总览 1转让中 2已转让 3存储中 4已赠送 5已提货 * @return void */ public function getMyNftList(ProductOrder $productOrder) { $typeId = $this->request->post('type_id/d', 0); $where = self::getNftWhere($typeId, 0, $productOrder); $list = $productOrder->alias('a') ->join("product_list b", "b.id = a.product_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, count(a.num) as hold_num') ->where('a.user_id', $this->auth->id) ->group('a.product_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['direct_gold'] = $userModel::getDirectGoldAddress($this->auth->id); // 直推列表 $list['data'] = $userModel::where('parent_id', $this->auth->id) ->field("address,create_time,nickname,is_super,direct_super,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, int $productId , object $productOrder): array { $where = []; switch ($typeId) { case 0: $where['a.status'] = ['=' , $productOrder::Paid]; 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; } if($productId > 0) $where['a.product_id'] = ['=' , $productId]; 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; } }