兑换转让接口

main
fengxinyhyl 8 months ago
parent ef3d60b65f
commit facf77ee3e
  1. 5
      app/common/dao/user/UserDao.php
  2. 8
      app/common/repositories/user/UserAssetsLogRepository.php
  3. 75
      app/common/repositories/user/UserAssetsRepository.php
  4. 14
      app/common/repositories/user/UserRepository.php
  5. 42
      app/controller/api/Auth.php
  6. 44
      app/controller/api/user/User.php
  7. 4
      crmeb/services/SmsService.php
  8. 9
      route/api.php

@ -131,6 +131,11 @@ class UserDao extends BaseDao
return $query;
}
public function getUserByPhone($phone){
return User::where('phone', $phone)->find();
}
/**
* @param $keyword
* @return BaseQuery

@ -39,13 +39,13 @@ class UserAssetsLogRepository extends BaseRepository
const CHANGE_TYPE_ORDER = 1; // 个人下单
const CHANGE_TYPE_SIGN = 2; // 签到
const CHANGE_TYPE_SHARE = 3; // 消费积分兑换分红点
const CHANGE_TYPE_SHARE_EXCHANGE = 3; // 消费积分兑换分红点
const CHANGE_TYPE_SHARE_GET = 4; // 分红点返佣
const CHANGE_TYPE_SPREAD_GET = 5; // 推广返佣
const CHANGE_TYPE_CULTIVATE = 6; // 培育奖
const CHANGE_TYPE_AGENT = 7; // 区域代理奖
const CHANGE_TYPE_HUITONG = 8; // 惠通宝兑换消费积分
const CHANGE_TYPE_HUITONG_TO = 9; // 转让他人
const CHANGE_TYPE_HUITONG_SEND = 9; // 转让他人
const CHANGE_TYPE_HUITONG_GET = 10; // 他人转让
const STATUS_FROZEN = 0; // 冻结
@ -74,13 +74,13 @@ class UserAssetsLogRepository extends BaseRepository
return array(
self::CHANGE_TYPE_ORDER => '个人下单',
self::CHANGE_TYPE_SIGN => '签到',
self::CHANGE_TYPE_SHARE => '消费积分兑换分红点',
self::CHANGE_TYPE_SHARE_EXCHANGE => '消费积分兑换分红点',
self::CHANGE_TYPE_SHARE_GET => '分红点返佣',
self::CHANGE_TYPE_SPREAD_GET => '推广返佣',
self::CHANGE_TYPE_CULTIVATE => '培育奖',
self::CHANGE_TYPE_AGENT => '区域代理奖',
self::CHANGE_TYPE_HUITONG => '惠通宝兑换消费积分',
self::CHANGE_TYPE_HUITONG_TO => '转让他人',
self::CHANGE_TYPE_HUITONG_SEND => '转让他人',
self::CHANGE_TYPE_HUITONG_GET => '他人转让',
);
}

@ -198,4 +198,79 @@ class UserAssetsRepository extends BaseRepository
$logRepository->addLog($logList);
}
/**
* notes
* @param $uid
* @param $count
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @create 2024/3/19 22:33
* @update 2024/3/19 22:33
* @author zhangkxiang
* @editor
*/
public function consumeToShare($uid, $count){
$config = $this->getConfig();
$assets = $this->assets($uid);
if($assets['consume'] < $config['consume_to_share'] * $count){
throw new \Exception('消费积分不足');
}
$logList = array();
$consume = -1 * $config['consume_to_share'] * $count;
$logList[] = array(
'uid' => $uid,
'asset_type' => UserAssetsLogRepository::ASSET_TYPE_CONSUME,
'type' => UserAssetsLogRepository::CHANGE_TYPE_SHARE_EXCHANGE,
'status' => UserAssetsLogRepository::STATUS_SUCCESS,
'count' => $consume,
);
$logList[] = array(
'uid' => $uid,
'asset_type' => UserAssetsLogRepository::ASSET_TYPE_SHARE_POINT,
'type' => UserAssetsLogRepository::CHANGE_TYPE_SHARE_EXCHANGE,
'status' => UserAssetsLogRepository::STATUS_SUCCESS,
'count' => $count,
);
app()->make(UserAssetsLogRepository::class)->addLog($logList);
$this->changeEvent($uid, UserAssetsLogRepository::STATUS_SUCCESS, array('consume' => $consume));
$this->dao->update($uid, array('share_point' => $assets['share_point'] + $count, 'share_point_time' => time()));
}
public function sendHuitong($uid, $phone, $count){
$assets = $this->assets($uid);
if($assets['huitong'] < $count){
throw new \Exception('惠通宝不足');
}
/**
* @var UserRepository $userRepository
*/
$userRepository = app()->make(UserRepository::class);
$toUser = $userRepository->getUserByPhone($phone);
if(!$toUser){
throw new \Exception('用户不存在');
}
$logList[] = array(
'uid' => $toUser['uid'],
'asset_type' => UserAssetsLogRepository::ASSET_TYPE_HUITONG,
'type' => UserAssetsLogRepository::CHANGE_TYPE_HUITONG_GET,
'status' => UserAssetsLogRepository::STATUS_SUCCESS,
'count' => $count,
);
$logList[] = array(
'uid' => $uid,
'asset_type' => UserAssetsLogRepository::ASSET_TYPE_HUITONG,
'type' => UserAssetsLogRepository::CHANGE_TYPE_HUITONG_SEND,
'status' => UserAssetsLogRepository::STATUS_SUCCESS,
'count' => -1 * $count,
);
app()->make(UserAssetsLogRepository::class)->addLog($logList);
$this->changeEvent($uid, UserAssetsLogRepository::STATUS_SUCCESS, array('huitong' => -1 * $count));
$toAssets = $this->assets($toUser['uid']);
$this->dao->update($toUser['uid'], array('huitong' => $toAssets['huitong'] + $count));
}
}

@ -196,6 +196,20 @@ class UserRepository extends BaseRepository
return $query->find();
}
/**
* notes
* @param $phone
* @return array|Model|null
* @create 2024/3/19 23:13
* @update 2024/3/19 23:13
* @author zhangkxiang
* @editor
*/
public function getUserByPhone($phone){
return $this->dao->getUserByPhone($phone);
}
public function getPulbicLst(array $where, $page, $limit)
{
$query = $this->dao->search($where);

@ -184,6 +184,14 @@ class Auth extends BaseController
return app('json')->success($data);
}
/**
* notes 兑换配置
* @return mixed
* @create 2024/3/19 22:20
* @update 2024/3/19 22:20
* @author zhangkxiang
* @editor
*/
public function exchangeConfig(){
$config = app(UserAssetsRepository::class)->getConfig();
$huitong = app(HuitongRepository::class)->getCurrent();
@ -195,6 +203,39 @@ class Auth extends BaseController
return app('json')->success($data);
}
public function toShare(){
$count = $this->request->param('count', 1);
$uid = 3;
try {
app(UserAssetsRepository::class)->consumeToShare($uid, $count);
}catch (\Exception $e){
return app('json')->fail($e->getMessage());
}
return app('json')->success();
}
public function toHuitong(){
$count = $this->request->param('count', 1);
$phone = $this->request->param('phoneTo', "13166665555");
$smsCode = $this->request->param('smsCode', 0156);
$type = $this->request->param('type', 'intention');
$uid = 3;
Log::info("code: {$smsCode}, type: {$type}");
// $checkSms = app()->make(SmsService::class)->checkSmsCode('18362705640', $smsCode, $type);
// if (!$smsCode || !$checkSms)
// return app('json')->fail('验证码不正确');
try {
app(UserAssetsRepository::class)->sendHuitong($uid, $phone, $count);
}catch (\Exception $e){
return app('json')->fail($e->getMessage());
}
return app('json')->success();
}
/**
* @param UserRepository $repository
* @return mixed
@ -361,6 +402,7 @@ class Auth extends BaseController
try {
$sms_code = str_pad(random_int(1, 9999), 4, 0, STR_PAD_LEFT);
$sms_time = systemConfig('sms_time') ? systemConfig('sms_time') : 30;
Log::info("{$data['phone']} send {$sms_code} with {$data['type']} ");
SmsService::create()->send($data['phone'], 'VERIFICATION_CODE', ['code' => $sms_code, 'time' => $sms_time]);
} catch (Exception $e) {
return app('json')->fail($e->getMessage());

@ -19,6 +19,7 @@ use app\common\repositories\store\service\StoreServiceRepository;
use app\common\repositories\system\CacheRepository;
use app\common\repositories\user\MemberinterestsRepository;
use app\common\repositories\user\UserAssetsLogRepository;
use app\common\repositories\user\UserAssetsRepository;
use app\common\repositories\user\UserBillRepository;
use app\common\repositories\user\UserBrokerageRepository;
use app\common\repositories\user\UserRepository;
@ -31,6 +32,7 @@ use think\App;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\facade\Log;
class User extends BaseController
{
@ -61,6 +63,48 @@ class User extends BaseController
}
/**
* notes 消费积分兑分红点
* @return mixed
* @create 2024/3/19 22:39
* @update 2024/3/19 22:39
* @author zhangkxiang
* @editor
*/
public function consumeToShare(){
$count = $this->request->param('count', 1);
$uid = $this->user->uid;
try {
app(UserAssetsRepository::class)->consumeToShare($uid, $count);
}catch (\Exception $e){
return app('json')->fail($e->getMessage());
}
return app('json')->success();
}
public function sendHuitong(){
$count = $this->request->param('count', 1);
$phone = $this->request->param('phoneTo');
$smsCode = $this->request->param('smsCode');
$type = $this->request->param('type', 'intention');
$uid = $this->user->uid;
Log::info("code: {$smsCode}, type: {$type}");
$checkSms = app()->make(SmsService::class)->checkSmsCode('18362705640', $smsCode, $type);
if (!$smsCode || !$checkSms)
return app('json')->fail('验证码不正确');
try {
app(UserAssetsRepository::class)->sendHuitong($uid, $phone, $count);
}catch (\Exception $e){
return app('json')->fail($e->getMessage());
}
return app('json')->success();
}
/**

@ -57,7 +57,9 @@ class SmsService
{
if (!env('DEVELOPMENT',false)) {
$sms_key = $this->sendSmsKey($phone, $type);
if (!$cache_code = Cache::get($sms_key)) return false;
$cache_code = Cache::get($sms_key);
if (!$cache_code) return false;
\think\facade\Log::info('sms_key:'.$sms_key." and cache_code:".$cache_code." and code:".$code);
if ($code != $cache_code) return false;
Cache::delete($sms_key);
}

@ -21,9 +21,13 @@ use think\facade\Route;
Route::group('api/', function () {
Route::any('test', 'api.Auth/test');
Route::get('toshare', 'api.Auth/toShare');
Route::get('tohuitong', 'api.Auth/toHuitong');
//兑换配置
Route::get('exchangeConfig', 'api.Auth/exchangeConfig');
Route::get('exchange/config', 'api.Auth/exchangeConfig');
//强制登录
Route::group(function () {
@ -110,6 +114,9 @@ Route::group('api/', function () {
Route::group('user', function () {
//用户资产明细
Route::get('assetsLog', 'User/assetsLog');
//消费积分兑分红点
Route::post('exchange/share', 'User/consumeToShare');
Route::post('send/huitong', 'User/sendHuitong');
//切换账号
Route::get('account', 'User/account');

Loading…
Cancel
Save