完善用户资产相关接口

main
fengxinyhyl 12 months ago
parent facf77ee3e
commit 2c996210d0
  1. 18
      app/common/repositories/user/UserAssetsLogRepository.php
  2. 96
      app/common/repositories/user/UserAssetsRepository.php
  3. 21
      app/common/repositories/user/UserSignRepository.php
  4. 26
      app/controller/api/user/User.php
  5. 11
      crmeb/listens/AppEnd.php
  6. 2
      crmeb/listens/task/CustomizeTask.php
  7. 2
      crmeb/services/SmsService.php
  8. 7
      route/api.php

@ -208,7 +208,7 @@ class UserAssetsLogRepository extends BaseRepository
);
}
$this->addLog($logList);
$this->userAssetsRepository->changeEvent($user['uid'], self::STATUS_FROZEN, compact('consume', 'welfare', 'huitong', 'contribution'));
$this->userAssetsRepository->orderEvent($user['uid'], self::STATUS_FROZEN, compact('consume', 'welfare', 'huitong', 'contribution'));
}
@ -297,7 +297,7 @@ class UserAssetsLogRepository extends BaseRepository
$log['ext'] = $ext;
$this->addLog([$log]);
$this->userAssetsRepository->changeEvent($user['uid'], self::STATUS_FROZEN, compact('consume', 'welfare', 'huitong', 'contribution'));
$this->userAssetsRepository->orderEvent($user['uid'], self::STATUS_FROZEN, compact('consume', 'welfare', 'huitong', 'contribution'));
}
/**
@ -340,7 +340,7 @@ class UserAssetsLogRepository extends BaseRepository
);
$this->addLog($logList);
$this->userAssetsRepository->changeEvent($user['uid'], self::STATUS_FROZEN, compact('consume', 'welfare', 'huitong', 'contribution'));
$this->userAssetsRepository->orderEvent($user['uid'], self::STATUS_FROZEN, compact('consume', 'welfare', 'huitong', 'contribution'));
}
@ -408,7 +408,7 @@ class UserAssetsLogRepository extends BaseRepository
'count' => $contribution,
);
$this->addLog($logList);
$this->userAssetsRepository->changeEvent($userProject['uid'], self::STATUS_FROZEN, compact('consume', 'welfare', 'huitong', 'contribution'));
$this->userAssetsRepository->orderEvent($userProject['uid'], self::STATUS_FROZEN, compact('consume', 'welfare', 'huitong', 'contribution'));
}
@ -488,7 +488,7 @@ class UserAssetsLogRepository extends BaseRepository
'count' => $contribution,
);
$this->addLog($logList);
$this->userAssetsRepository->changeEvent($userProject['uid'], self::STATUS_FROZEN, compact('consume', 'welfare', 'huitong', 'contribution'));
$this->userAssetsRepository->orderEvent($userProject['uid'], self::STATUS_FROZEN, compact('consume', 'welfare', 'huitong', 'contribution'));
return $userProject['spread_uid'];
}
@ -561,7 +561,7 @@ class UserAssetsLogRepository extends BaseRepository
);
}
$this->addLog($logList);
$this->userAssetsRepository->changeEvent($orderItem['uid'], self::STATUS_FROZEN, compact('consume', 'welfare', 'huitong', 'contribution'));
$this->userAssetsRepository->orderEvent($orderItem['uid'], self::STATUS_FROZEN, compact('consume', 'welfare', 'huitong', 'contribution'));
// 5. 本人使用的福利积分
if ($orderItem['integral']) {
@ -574,7 +574,7 @@ class UserAssetsLogRepository extends BaseRepository
'count' => $orderItem['integral'],
);
$this->addLog([$log]);
$this->userAssetsRepository->changeEvent($orderItem['uid'], self::STATUS_USED, compact('consume', 'welfare', 'huitong', 'contribution'));
$this->userAssetsRepository->orderEvent($orderItem['uid'], self::STATUS_USED, compact('consume', 'welfare', 'huitong', 'contribution'));
}
}
@ -597,7 +597,7 @@ class UserAssetsLogRepository extends BaseRepository
$refundList = $this->_getOrderData($orderItem['order_id'], self::STATUS_FROZEN);
if ($refundList) {
foreach ($refundList as $refund) {
$this->userAssetsRepository->changeEvent($refund['uid'], self::STATUS_SUCCESS, $refund);
$this->userAssetsRepository->orderEvent($refund['uid'], self::STATUS_SUCCESS, $refund);
}
}
@ -622,7 +622,7 @@ class UserAssetsLogRepository extends BaseRepository
$refundList = $this->_getOrderData($orderItem['order_id'], self::STATUS_FROZEN);
if ($refundList) {
foreach ($refundList as $refund) {
$this->userAssetsRepository->changeEvent($refund['uid'], self::STATUS_REFUND, $refund);
$this->userAssetsRepository->orderEvent($refund['uid'], self::STATUS_REFUND, $refund);
}
}

@ -17,6 +17,7 @@ use app\common\dao\user\UserAssetsDao;
use app\common\repositories\BaseRepository;
use app\common\repositories\store\order\StoreOrderBaseRepository;
use app\common\repositories\system\groupData\GroupDataRepository;
use app\common\repositories\system\HuitongRepository;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
@ -76,7 +77,7 @@ class UserAssetsRepository extends BaseRepository
/**
* notes 用户资产变更
* notes 订单事件同步更新用户资产
* @param $uid
* @param $status
* @param $data
@ -88,7 +89,7 @@ class UserAssetsRepository extends BaseRepository
* @author zhangkxiang
* @editor
*/
public function changeEvent($uid, $status, $data = array())
public function orderEvent($uid, $status, $data = array())
{
$assets = array();
$info = $this->dao->get($uid);
@ -145,7 +146,7 @@ class UserAssetsRepository extends BaseRepository
/**
* notes 分红福利积分
* notes 分红福利积分定时任务
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
@ -154,7 +155,7 @@ class UserAssetsRepository extends BaseRepository
* @author zhangkxiang
* @editor
*/
public function sharePoint()
public function sharePointTask()
{
$config = $this->getConfig();
/**
@ -189,8 +190,8 @@ class UserAssetsRepository extends BaseRepository
'count' => $welfare,
);
// 增加福利积分
$this->changeEvent($item['uid'], UserAssetsLogRepository::STATUS_SUCCESS, array('welfare' => $welfare));
$assets = $this->assets($item['uid']);
$this->update($item['uid'], array('welfare' => $assets['welfare'] + $welfare));
}
// 增加记录
@ -235,11 +236,23 @@ class UserAssetsRepository extends BaseRepository
'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()));
$this->dao->update($uid, array('consume' => $assets['consume'] + $consume, 'share_point' => $assets['share_point'] + $count, 'share_point_time' => time()));
}
/**
* notes 惠通宝转账
* @param $uid
* @param $phone
* @param $count
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @create 2024/3/20 11:01
* @update 2024/3/20 11:01
* @author zhangkxiang
* @editor
*/
public function sendHuitong($uid, $phone, $count){
$assets = $this->assets($uid);
if($assets['huitong'] < $count){
@ -269,8 +282,73 @@ class UserAssetsRepository extends BaseRepository
'count' => -1 * $count,
);
app()->make(UserAssetsLogRepository::class)->addLog($logList);
$this->changeEvent($uid, UserAssetsLogRepository::STATUS_SUCCESS, array('huitong' => -1 * $count));
$this->dao->update($toUser['uid'], array('huitong' => $assets['huitong'] - $count));
$toAssets = $this->assets($toUser['uid']);
$this->dao->update($toUser['uid'], array('huitong' => $toAssets['huitong'] + $count));
}
/**
* 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 huitongToConsume($uid, $count){
$current = app(HuitongRepository::class)->getCurrent();
$assets = $this->assets($uid);
if($assets['huitong'] < $count){
throw new \Exception('惠通宝不足');
}
$logList = array();
$consume = $current * $count;
$logList[] = array(
'uid' => $uid,
'asset_type' => UserAssetsLogRepository::ASSET_TYPE_CONSUME,
'type' => UserAssetsLogRepository::CHANGE_TYPE_HUITONG,
'status' => UserAssetsLogRepository::STATUS_SUCCESS,
'count' => $consume,
);
$huitong = -1 * $count;
$logList[] = array(
'uid' => $uid,
'asset_type' => UserAssetsLogRepository::ASSET_TYPE_HUITONG,
'type' => UserAssetsLogRepository::CHANGE_TYPE_HUITONG,
'status' => UserAssetsLogRepository::STATUS_SUCCESS,
'count' => $huitong,
);
app()->make(UserAssetsLogRepository::class)->addLog($logList);
$this->dao->update($uid, array('consume' => $assets['consume'] + $consume, 'huitong' => $assets['huitong'] + $huitong));
}
/**
* notes
* @param $uid
* @param $consume
* @create 2024/3/20 16:36
* @update 2024/3/20 16:36
* @author zhangkxiang
* @editor
*/
public function sign($uid, $consume){
$logList = array();
$logList[] = array(
'uid' => $uid,
'asset_type' => UserAssetsLogRepository::ASSET_TYPE_CONSUME,
'type' => UserAssetsLogRepository::CHANGE_TYPE_SIGN,
'status' => UserAssetsLogRepository::STATUS_SUCCESS,
'count' => $consume,
);
app()->make(UserAssetsLogRepository::class)->addLog($logList);
$assets = $this->assets($uid);
$this->dao->update($uid, array('consume' => $assets['consume'] + $consume));
}
}

@ -15,11 +15,13 @@ namespace app\common\repositories\user;
use app\common\dao\user\UserSignDao;
use app\common\model\user\UserSign;
use app\common\repositories\BaseRepository;
use app\common\repositories\system\groupData\GroupDataRepository;
use app\common\repositories\system\groupData\GroupRepository;
use think\exception\ValidateException;
use think\facade\Db;
use think\facade\Log;
class UserSignRepository extends BaseRepository
@ -48,7 +50,9 @@ class UserSignRepository extends BaseRepository
*/
public function getSign(int $uid,string $day)
{
return $this->dao->getSearch(['uid' => $uid,'day' => $day])->value('sign_num');
$ret = $this->dao->getSearch(['uid' => $uid,'day' => $day])->value('sign_num');
Log::info(UserSign::getLastSql());
return $ret;
}
public function getDay(int $num)
@ -93,13 +97,13 @@ class UserSignRepository extends BaseRepository
$sign_task = $this->getDay($sign_num);
$user = app()->make(UserRepository::class)->get($uid);
$integral = $sign_task['sign_integral'];
if ($user->is_svip > 0) {
$makeInteres = app()->make(MemberinterestsRepository::class);
$integral = $integral * $makeInteres->getSvipInterestVal($makeInteres::HAS_TYPE_SIGN);;
}
// if ($user->is_svip > 0) {
// $makeInteres = app()->make(MemberinterestsRepository::class);
// $integral = $integral * $makeInteres->getSvipInterestVal($makeInteres::HAS_TYPE_SIGN);;
// }
$user_make = app()->make(UserRepository::class);
$user = $user_make->get($uid);
$integral_ = $user['integral'] + $integral;
$assets = app()->make(UserAssetsRepository::class)->assets($uid);
$integral_ = $assets['consume'] + $integral;
$data = [
'uid' => $uid,
'sign_num' => $sign_num,
@ -117,6 +121,7 @@ class UserSignRepository extends BaseRepository
return Db::transaction(function() use($uid,$data,$user_make,$sign_task,$arr,$integral){
$ret = $this->dao->create($data);
$user_make->incIntegral($uid,$integral,'签到'.$sign_task['sign_day'],'sign_integral',$arr);
app()->make(UserAssetsRepository::class)->sign($uid, $integral);
app()->make(UserBrokerageRepository::class)->incMemberValue($uid, 'member_sign_num', $ret->sign_id);
return compact('integral');
});
@ -143,6 +148,8 @@ class UserSignRepository extends BaseRepository
$sign_num = $ret['sign_num'];
$title = $this->signConfig();
$userInfo = app()->make(UserRepository::class)->getWhere(['uid' => $uid],'uid,avatar,nickname,integral');
$assets = app()->make(UserAssetsRepository::class)->assets($uid);
$userInfo['integral'] = $assets['consume'];
$count = $this->dao->getSearch(['uid' => $uid])->count('*');
return compact('userInfo','is_sign','sign_num','count','title');

@ -54,9 +54,11 @@ class User extends BaseController
$page = $this->request->param('page', 1);
$limit = $this->request->param('limit', 10);
$asset_type = $this->request->param('asset_type', 1);
$change_type = $this->request->param('change_type');
$where = array();
$where[] = array('asset_type','=',$asset_type);
if($change_type) $where[] = array('type','=',$change_type);
$where[] = array('status','in',[UserAssetsLogRepository::STATUS_FROZEN, UserAssetsLogRepository::STATUS_SUCCESS, UserAssetsLogRepository::STATUS_USED]);
return app('json')->success(app(UserAssetsLogRepository::class)->list($uid, $where, $page, $limit));
@ -84,7 +86,14 @@ class User extends BaseController
}
/**
* notes 赠送惠通宝
* @return mixed
* @create 2024/3/20 11:00
* @update 2024/3/20 11:00
* @author zhangkxiang
* @editor
*/
public function sendHuitong(){
$count = $this->request->param('count', 1);
$phone = $this->request->param('phoneTo');
@ -92,7 +101,7 @@ class User extends BaseController
$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);
$checkSms = app()->make(SmsService::class)->checkSmsCode($this->user->phone, $smsCode, $type);
if (!$smsCode || !$checkSms)
return app('json')->fail('验证码不正确');
@ -105,6 +114,19 @@ class User extends BaseController
}
public function huitongToConsume(){
$count = $this->request->param('count', 1);
$uid = $this->user->uid;
try {
app(UserAssetsRepository::class)->huitongToConsume($uid, $count);
}catch (\Exception $e){
return app('json')->fail($e->getMessage());
}
return app('json')->success();
}
/**

@ -18,10 +18,17 @@ class AppEnd
{
$params = Request::param();
$response = $response->getData();
if(is_array($response) or strpos($response, '<!DOCTYPE html>') === false) {
Log::info(Request::url(). ' params: ' . json_encode($params) ." response: " . json_encode($response));
$header = Request::header();
$token = '';
if(isset($header['x-token']) and $header['x-token']){
$token = $header['x-token'];
}
$jsonRes = json_encode($response, JSON_UNESCAPED_UNICODE);
if(is_array($response) and (strpos($jsonRes, '<!DOCTYPE html>') === false and strpos($jsonRes, '<span') === false)) {
Log::info(Request::url(). ' params: ' . json_encode($params) ." response: " . $jsonRes );
}else{
Log::info(Request::url(). ' params: ' . json_encode($params));
}
// Log::info(" token: " . $token);
}
}

@ -29,7 +29,7 @@ class CustomizeTask extends TimerService implements ListenerInterface
* @var UserAssetsRepository $userAssets
*/
$userAssets = app()->make(UserAssetsRepository::class);
$userAssets->sharePoint();
$userAssets->sharePointTask();
/**
* @var HuitongRepository $huitong

@ -58,8 +58,8 @@ class SmsService
if (!env('DEVELOPMENT',false)) {
$sms_key = $this->sendSmsKey($phone, $type);
$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 (!$cache_code) return false;
if ($code != $cache_code) return false;
Cache::delete($sms_key);
}

@ -21,10 +21,6 @@ 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('exchange/config', 'api.Auth/exchangeConfig');
@ -116,7 +112,10 @@ Route::group('api/', function () {
Route::get('assetsLog', 'User/assetsLog');
//消费积分兑分红点
Route::post('exchange/share', 'User/consumeToShare');
//赠送惠通宝
Route::post('send/huitong', 'User/sendHuitong');
//惠通宝兑消费积分
Route::post('exchange/consume', 'User/huitongToConsume');
//切换账号
Route::get('account', 'User/account');

Loading…
Cancel
Save