添加:菜卡额度记录查看接口

添加:菜卡额度转赠接口
This commit is contained in:
wuhui_zzw 2024-02-03 14:07:37 +08:00
parent 87618c742a
commit 62145d52ea
3 changed files with 31 additions and 23 deletions

View File

@ -75,9 +75,10 @@ class ExchangeQuotaRepository extends BaseRepository{
public function transfer($uid,$params){ public function transfer($uid,$params){
return Db::transaction(function () use ($uid,$params) { return Db::transaction(function () use ($uid,$params) {
// 获取用户信息 // 获取用户信息
$currentUser = ExchangeQuota::where('uid',$uid)->findOrEmpty(); $quotaType = $params['quota_type'] ?? 1;
$currentUser = $this->searchModel(['uid'=>$uid,'quota_type'=>$quotaType])->findOrEmpty();
$currentUserAvailable = (float)sprintf("%.2f",$currentUser->surplus_quota - $currentUser->freeze_quota); $currentUserAvailable = (float)sprintf("%.2f",$currentUser->surplus_quota - $currentUser->freeze_quota);
$transferUser = ExchangeQuota::where('uid',$params['transfer_uid'])->findOrEmpty(); $transferUser = $this->searchModel(['uid'=>$params['transfer_uid'],'quota_type'=>$quotaType])->findOrEmpty();
if((int)$transferUser->uid <= 0) $transferUser->uid = $params['transfer_uid']; if((int)$transferUser->uid <= 0) $transferUser->uid = $params['transfer_uid'];
// 判断:当前用户持有数量是否充足 // 判断:当前用户持有数量是否充足
if($currentUserAvailable < $params['transfer_num']) throw new \Exception('转赠额度不能超过剩余可用额度!'); if($currentUserAvailable < $params['transfer_num']) throw new \Exception('转赠额度不能超过剩余可用额度!');
@ -86,7 +87,8 @@ class ExchangeQuotaRepository extends BaseRepository{
$currentUser->total_quota = (float)sprintf("%.2f",(float)$currentUser->total_quota - (float)$params['transfer_num']); $currentUser->total_quota = (float)sprintf("%.2f",(float)$currentUser->total_quota - (float)$params['transfer_num']);
$currentUser->surplus_quota = (float)sprintf("%.2f",(float)$currentUser->surplus_quota - (float)$params['transfer_num']); $currentUser->surplus_quota = (float)sprintf("%.2f",(float)$currentUser->surplus_quota - (float)$params['transfer_num']);
$currentUser->save(); $currentUser->save();
$transferUserChangeFront = $currentUser->surplus_quota; $transferUserChangeFront = $transferUser->surplus_quota;
$transferUser->quota_type = $quotaType;
$transferUser->total_quota = (float)sprintf("%.2f",(float)$transferUser->total_quota + (float)$params['receipt_num']); $transferUser->total_quota = (float)sprintf("%.2f",(float)$transferUser->total_quota + (float)$params['receipt_num']);
$transferUser->surplus_quota = (float)sprintf("%.2f",(float)$transferUser->surplus_quota + (float)$params['receipt_num']); $transferUser->surplus_quota = (float)sprintf("%.2f",(float)$transferUser->surplus_quota + (float)$params['receipt_num']);
$transferUser->save(); $transferUser->save();
@ -107,6 +109,7 @@ class ExchangeQuotaRepository extends BaseRepository{
'change_after' => (float)$currentUser->surplus_quota, 'change_after' => (float)$currentUser->surplus_quota,
'remark' => "转赠给【{$transferMemberName}", 'remark' => "转赠给【{$transferMemberName}",
'source' => 4, 'source' => 4,
'quota_type' => $quotaType
], ],
// 接收用户变更记录 // 接收用户变更记录
[ [
@ -120,6 +123,7 @@ class ExchangeQuotaRepository extends BaseRepository{
'change_after' => (float)$transferUser->surplus_quota, 'change_after' => (float)$transferUser->surplus_quota,
'remark' => "来自【{$currentMemberName}】的转赠", 'remark' => "来自【{$currentMemberName}】的转赠",
'source' => 4, 'source' => 4,
'quota_type' => $quotaType
] ]
]; ];
ExchangeQuotaRecord::insertAll($insertData); ExchangeQuotaRecord::insertAll($insertData);
@ -130,6 +134,7 @@ class ExchangeQuotaRepository extends BaseRepository{
'transfer_num' => (float)$params['transfer_num'], 'transfer_num' => (float)$params['transfer_num'],
'receipt_num' => (float)$params['receipt_num'], 'receipt_num' => (float)$params['receipt_num'],
'service_charge' => (float)$params['service_charge'], 'service_charge' => (float)$params['service_charge'],
'quota_type' => $quotaType
]); ]);
}); });
} }

View File

@ -162,17 +162,13 @@ class Auth extends BaseController
} }
// 用户是否为兑换站点管理员 // 用户是否为兑换站点管理员
$data['is_exchange_saff'] = app()->make(ExchangePickupPointRepository::class)->userIsStaff($user->uid); $data['is_exchange_saff'] = app()->make(ExchangePickupPointRepository::class)->userIsStaff($user->uid);
// 用户持有可用酒卡额度及积分 // 用户持有可用酒卡额度
$info = app()->make(ExchangeQuotaRepository::class) $data['available'] = (float)app()->make(ExchangeQuotaRepository::class)
->getSearch([]) ->searchModel(['uid'=>$user->uid])
->field([ ->value('(surplus_quota - freeze_quota)');
'uid', $data['vegetable_available'] = (float)app()->make(ExchangeQuotaRepository::class)
// 可用额度=剩余额度-冻结额度 ->searchModel(['uid'=>$user->uid,'quota_type'=>2])
'(surplus_quota - freeze_quota) as available' ->value('(surplus_quota - freeze_quota)');
])
->where('uid',$user->uid)
->findOrEmpty();
$data['available'] = (float)$info->available;
return app('json')->success($data); return app('json')->success($data);
} }

View File

@ -35,19 +35,19 @@ class Exchange extends BaseController{
* @return mixed * @return mixed
*/ */
public function getUserHold(){ public function getUserHold(){
$params = $this->request->params(['consume_uid']); $params = $this->request->params(['consume_uid','quota_type']);
$uid = $this->request->uid(); $uid = $this->request->uid();
// 判断:是否存在指定消费者,不存在则使用当前登录用户 // 判断:是否存在指定消费者,不存在则使用当前登录用户
$uid = (int)$params['consume_uid'] > 0 ? (int)$params['consume_uid'] : $uid; $uid = (int)$params['consume_uid'] > 0 ? (int)$params['consume_uid'] : $uid;
$params['uid'] = $uid;
// 获取额度 // 获取额度
$info = app()->make(ExchangeQuotaRepository::class) $info = app()->make(ExchangeQuotaRepository::class)
->getSearch([]) ->searchModel($params)
->field([ ->field([
'uid', '*',
// 可用额度=剩余额度-冻结额度 // 可用额度=剩余额度-冻结额度
'(surplus_quota - freeze_quota) as available' '(surplus_quota - freeze_quota) as available'
]) ])
->where('uid',$uid)
->findOrEmpty(); ->findOrEmpty();
$user = app()->make(UserRepository::class)->getSearch([])->where('uid',$uid)->findOrEmpty(); $user = app()->make(UserRepository::class)->getSearch([])->where('uid',$uid)->findOrEmpty();
$info->available = (float)$info->available; $info->available = (float)$info->available;
@ -294,15 +294,16 @@ class Exchange extends BaseController{
* @return mixed * @return mixed
*/ */
public function recordQuota(){ public function recordQuota(){
$uid = $this->request->uid(); $params = $this->request->params(['quota_type']);
$params['uid'] =$this->request->uid();
$statistics = app()->make(ExchangeQuotaRepository::class) $statistics = app()->make(ExchangeQuotaRepository::class)
->getSearch([]) ->searchModel($params)
->field([ ->field([
'*', '*',
// 可用额度=剩余额度-冻结额度 // 可用额度=剩余额度-冻结额度
'(surplus_quota - freeze_quota) as available' '(surplus_quota - freeze_quota) as available'
]) ])
->where('uid',$uid)
->findOrEmpty() ->findOrEmpty()
->toArray(); ->toArray();
@ -324,7 +325,7 @@ class Exchange extends BaseController{
*/ */
public function recordQuotaList(){ public function recordQuotaList(){
[$page, $limit] = $this->getPage(); [$page, $limit] = $this->getPage();
$params = $this->request->params(['uid']); $params = $this->request->params(['quota_type']);
$params['uid'] = $this->request->uid(); $params['uid'] = $this->request->uid();
$data = app()->make(ExchangeQuotaRecordRepository::class)->getList((array)$params,(int)$page,(int)$limit); $data = app()->make(ExchangeQuotaRecordRepository::class)->getList((array)$params,(int)$page,(int)$limit);
@ -352,7 +353,13 @@ class Exchange extends BaseController{
*/ */
public function quotaTransfer(){ public function quotaTransfer(){
// 参数 // 参数
$params = $this->request->params([['transfer_num', 0],['receipt_num', 0],['service_charge', 0],['transfer_uid', 0]]); $params = $this->request->params([
['transfer_num', 0],
['receipt_num', 0],
['service_charge', 0],
['transfer_uid', 0],
'quota_type'
]);
$uid = $this->request->uid(); $uid = $this->request->uid();
// 判断:信息是否符合要求 // 判断:信息是否符合要求
if($params['transfer_uid'] <= 0) return app('json')->fail("请选择接收用户!"); if($params['transfer_uid'] <= 0) return app('json')->fail("请选择接收用户!");