123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436 |
- <?php
- // +----------------------------------------------------------------------
- // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
- // +----------------------------------------------------------------------
- // | Author: CRMEB Team <admin@crmeb.com>
- // +----------------------------------------------------------------------
- namespace app\controller\api\v1\user;
- use app\jobs\integral\IntegralJob;
- use app\model\user\UserBill;
- use app\Request;
- use app\services\product\product\StoreProductLogServices;
- use app\services\user\AwardIntegralServices;
- use app\services\user\UserAwardIntegralServices;
- use app\services\user\UserBillServices;
- use app\services\user\UserServices;
- use app\services\wechat\WechatUserServices;
- use crmeb\services\AliAuthService;
- use crmeb\services\CacheService;
- use crmeb\services\WithdrawService;
- use function Swoole\Coroutine\Http\get;
- /**
- * 用户类
- * Class UserController
- * @package app\controller\api\store
- */
- class UserController
- {
- protected $services = NUll;
- /**
- * UserController constructor.
- * @param UserServices $services
- */
- public function __construct(UserServices $services)
- {
- $this->services = $services;
- }
- /**
- * 获取用户信息
- * @param Request $request
- * @return mixed
- */
- public function userInfo(Request $request)
- {
- $info = $request->user()->toArray();
- return app('json')->success($this->services->userInfo($info));
- }
- /**
- * 用户资金统计
- * @param Request $request
- * @return mixed
- * @throws \think\Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function balance(Request $request)
- {
- $uid = (int)$request->uid();
- return app('json')->successful($this->services->balance($uid));
- }
- /**
- * 个人中心
- * @param Request $request
- * @return mixed
- */
- public function user(Request $request)
- {
- $user = $request->user()->toArray();
- return app('json')->success($this->services->personalHome($user, $request->tokenData()));
- }
- public function bankInfo(Request $request)
- {
- $user = $request->uid();
- return app('json')->success($this->services->bankInfo($user));
- }
- /**
- * 获取活动状态
- * @return mixed
- */
- public function activity()
- {
- return app('json')->successful($this->services->activity());
- }
- /**
- * 用户修改信息
- * @param Request $request
- * @return mixed
- */
- public function edit(Request $request)
- {
- [$avatar, $nickname, $extend_info] = $request->postMore([
- ['avatar', ''],
- ['nickname', ''],
- ['extend_info', []]
- ], true);
- if (!$avatar && $nickname == '') {
- return app('json')->fail('请输入昵称或者选择头像');
- }
- $uid = (int)$request->uid();
- $this->services->saveExtendForm($uid, $extend_info, ['avatar' => $avatar, 'nickname' => $nickname], true);
- return app('json')->success('修改成功');
- }
- /**
- * 推广人排行
- * @param Request $request
- * @return mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function rank(Request $request)
- {
- $data = $request->getMore([
- ['page', ''],
- ['limit', ''],
- ['type', '']
- ]);
- $data['uid'] = $request->uid();
- $info = $this->services->getRankList($data);
- $info['avatar'] = $request->user()['avatar'];
- return app('json')->success($info);
- }
- /**
- * 添加访问记录
- * @param Request $request
- * @return mixed
- */
- public function set_visit(Request $request)
- {
- $data = $request->postMore([
- ['url', ''],
- ['stay_time', 0]
- ]);
- if ($data['url'] == '') return app('json')->fail('未获取页面路径');
- $data['uid'] = (int)$request->uid();
- $data['ip'] = $request->ip();
- if ($this->services->setVisit($data)) {
- return app('json')->success('添加访问记录成功');
- } else {
- return app('json')->fail('添加访问记录失败');
- }
- }
- /**
- * 静默绑定推广人
- * @param Request $request
- * @return mixed
- */
- public function spread(Request $request)
- {
- [$spreadUid, $code] = $request->postMore([
- ['puid', 0],
- ['code', 0]
- ], true);
- $uid = (int)$request->uid();
- $this->services->spread($uid, (int)$spreadUid, $code);
- return app('json')->success();
- }
- /**
- * 推荐用户
- * @param Request $request
- * @return mixed
- *
- * grade == 0 获取一级推荐人
- * grade == 1 获取二级推荐人
- *
- * keyword 会员名称查询
- *
- * sort childCount ASC/DESC 团队排序 numberCount ASC/DESC 金额排序 orderCount ASC/DESC 订单排序
- */
- public function spread_people(Request $request)
- {
- $spreadInfo = $request->postMore([
- ['grade', 0],
- ['keyword', ''],
- ['sort', ''],
- ['start', 0],
- ['stop', 0],
- ]);
- if (!in_array($spreadInfo['grade'], [0, 1])) {
- return app('json')->fail('等级错误');
- }
- $spreadInfo['time'] = [$spreadInfo['start'], $spreadInfo['stop']];
- $uid = $request->uid();
- return app('json')->successful($this->services->getUserSpreadGrade($uid, $spreadInfo['grade'], $spreadInfo['sort'], $spreadInfo['keyword'], $spreadInfo['time']));
- }
- /**
- * 是否关注
- * @param Request $request
- * @return mixed
- */
- public function subscribe(Request $request)
- {
- if ($request->uid()) {
- /** @var WechatUserServices $wechatUserService */
- $wechatUserService = app()->make(WechatUserServices::class);
- $subscribe = (bool)$wechatUserService->value(['uid' => $request->uid()], 'subscribe');
- return app('json')->success(['subscribe' => $subscribe]);
- } else {
- return app('json')->success(['subscribe' => true]);
- }
- }
- /**
- * 用户付款code
- * @param Request $request
- * @return mixed
- */
- public function randCode(Request $request)
- {
- $uid = (int)$request->uid();
- $code = $this->services->getRandCode((int)$uid);
- return app('json')->success(['code' => $code]);
- }
- /**
- * 商品浏览记录
- * @param Request $request
- * @param StoreProductLogServices $services
- * @return mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function visitList(Request $request, StoreProductLogServices $services)
- {
- $where['uid'] = (int)$request->uid();
- $where['type'] = 'visit';
- $result = $services->getList($where, 'product_id', 'id,product_id,max(add_time) as add_time');
- $time_data = [];
- if ($result['list']) {
- foreach ($result['list'] as $key => &$item) {
- $add_time = strtotime($item['add_time']);
- if (date('Y') == date('Y', $add_time)) {//今年
- $item['time_key'] = date('m月d日', $add_time);
- } else {
- $item['time_key'] = date('Y年m月d日', $add_time);
- }
- }
- $time_data = array_merge(array_unique(array_column($result['list'], 'time_key')));
- }
- $result['time'] = $time_data;
- return app('json')->success($result);
- }
- /**
- * 商品浏览记录删除
- * @param Request $request
- * @param StoreProductLogServices $services
- * @return mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function visitDelete(Request $request, StoreProductLogServices $services)
- {
- $uid = (int)$request->uid();
- [$ids] = $request->postMore([
- ['ids', []],
- ], true);
- if ($ids) {
- $where = ['uid' => $uid, 'product_id' => $ids];
- $services->destroy($where);
- }
- return app('json')->success('删除成功');
- }
- public function awardIntegralList(Request $request, AwardIntegralServices $services)
- {
- $where = ['uid' => $request->uid()];
- // if ($type <= 1) {
- // $where['type'] = ($type == 1 ? 1 : 0);
- // }
- return app('json')->success($services->getIntegralList($where));
- }
- public function extractIntegral(Request $request, AwardIntegralServices $services, $id)
- {
- return app('json')->fail('暂不支持');
- $info = $services->getIntegral($id);
- $password = $request->post('password', '');
- $num = $request->post('num', 0);
- $user = $this->services->get($request->uid());
- if ($user->pwd !== md5((string)$password))
- return app('json')->fail('密码错误');
- if (!$info || $info['uid'] != $request->uid()) {
- return app('json')->fail('记录不存在');
- }
- if ($info['status'] != 0) {
- return app('json')->fail('记录已出局');
- }
- $res = $services->transaction(function () use ($services, $id, $num) {
- return $services->extract($id, $num);
- });
- // $res = $services->update($id, ['handle' => 1]);
- if ($res) {
- return app('json')->success('已提取');
- } else {
- return app('json')->fail('提取失败');
- }
- }
- public function addEmployee(Request $request)
- {
- $user = $this->services->get($request->uid());
- list($name, $id_card, $bank_code, $mobile, $front_image, $back_image) = $request->postMore([
- ['name', ''],
- ['id_card', ''],
- ['bank_code', ''],
- ['mobile', ''],
- ['front_image', ''],
- ['back_image', ''],
- ], true);
- if ($user['enterprise_professional_facilitator_id']) {
- $bank_info = WithdrawService::init()::contractInfo($user['enterprise_professional_facilitator_id']);
- return app('json')->success('已添加用户', ["enterprise_professional_facilitator_id" => $user['enterprise_professional_facilitator_id'],
- "professional_id" => $user['professional_id'], 'info' => $bank_info]);
- } else {
- $res = WithdrawService::init()::addEmployee($name, $id_card, $bank_code, $mobile, $front_image, $back_image);
- $this->services->update($request->uid(), ["enterprise_professional_facilitator_id" => $res['enterprise_professional_facilitator_id'],
- "professional_id" => $res['professional_id']], 'uid');
- return app('json')->success('已添加用户', $res);
- }
- }
- public function applySignUrl(Request $request)
- {
- $user = $this->services->get($request->uid());
- if ($user['professional_id']) {
- $bank_info = WithdrawService::init()::contractInfo($user['enterprise_professional_facilitator_id']);
- if ($bank_info['sign_img']) {
- return app('json')->fail('签约已完成');
- }
- return app('json')->success('ok', WithdrawService::init()::applySignUrl($user['professional_id']));
- } else {
- return app('json')->fail('请先添加收款信息');
- }
- }
- /**
- * 实名信息提交认证
- * @param Request $request
- * @return mixed
- */
- public function rname(Request $request)
- {
- $info = $request->postMore([
- ['rname', ''],
- ['cid', ''],
- ]);
- if (!$info['rname'] || !$info['cid']) return app('json')->fail('请输入身份证号码和真实姓名');
- $ress = $this->services->search()->where('uid', $request->uid())->find();
- if ($ress['is_auth'] == 1 || $ress['is_auth'] == 2) {
- return app('json')->fail('您已提交认证,不可重复提交');
- }
- $res = $this->services->cidUser($info['rname'], $info['cid'], $request->uid());
- if ($res) return app('json')->success('上传成功');
- return app('json')->fail('上传失败');
- }
- public function check(Request $request)
- {
- // 查询是否已审核
- $res1 = $this->services->getUserInfo($request->uid());
- if ($res1['is_auth'] == 0) {
- return app('json')->fail('请填写真实姓名和身份证');
- }
- if ($res1['is_auth'] == 2 || $res1['is_auth'] == 3) {
- return app('json')->fail('该信息已审核!不可操作');
- }
- $metaInfo = $request->post('metaInfo', '');
- $url = $request->post('url', '');
- if (!$metaInfo) app('json')->fail('请传入环境信息');
- $res = AliAuthService::check($request->uid(), $metaInfo, $url);
- if ($res) {
- return app('json')->success('ok', $res);
- } else {
- $this->services->update($request->uid(), ['is_auth' => 3, 'off' => AliAuthService::getError()], 'uid');
- return app('json')->fail(AliAuthService::getError());
- }
- }
- /**
- * 实名信息查询
- * @param Request $request
- * @return mixed
- */
- public function rate(Request $request)
- {
- $res = $this->services->get($request->uid());
- $data = [
- 'is_auth' => $res['is_auth'],
- 'off' => $res['off']
- ];
- return app('json')->success($data);
- }
- public function trade(Request $request, UserBillServices $server)
- {
- [$to_uid, $num] = $request->postMore([
- ['to_uid', 0],
- ['num', 0],
- ], true);
- $uid = (int)$request->uid();
- if ($server->shop_integral_trade($uid, $to_uid, $num))
- return app('json')->successful('转账成功!');
- else
- return app('json')->fail('转账失败');
- }
- }
|