diff --git a/app/common/repositories/user/ExchangeQuotaRepository.php b/app/common/repositories/user/ExchangeQuotaRepository.php index db34b53..b9c3b75 100644 --- a/app/common/repositories/user/ExchangeQuotaRepository.php +++ b/app/common/repositories/user/ExchangeQuotaRepository.php @@ -75,9 +75,10 @@ class ExchangeQuotaRepository extends BaseRepository{ public function transfer($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); - $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($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->surplus_quota = (float)sprintf("%.2f",(float)$currentUser->surplus_quota - (float)$params['transfer_num']); $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->surplus_quota = (float)sprintf("%.2f",(float)$transferUser->surplus_quota + (float)$params['receipt_num']); $transferUser->save(); @@ -107,6 +109,7 @@ class ExchangeQuotaRepository extends BaseRepository{ 'change_after' => (float)$currentUser->surplus_quota, 'remark' => "转赠给【{$transferMemberName}】", 'source' => 4, + 'quota_type' => $quotaType ], // 接收用户变更记录 [ @@ -120,6 +123,7 @@ class ExchangeQuotaRepository extends BaseRepository{ 'change_after' => (float)$transferUser->surplus_quota, 'remark' => "来自【{$currentMemberName}】的转赠", 'source' => 4, + 'quota_type' => $quotaType ] ]; ExchangeQuotaRecord::insertAll($insertData); @@ -130,6 +134,7 @@ class ExchangeQuotaRepository extends BaseRepository{ 'transfer_num' => (float)$params['transfer_num'], 'receipt_num' => (float)$params['receipt_num'], 'service_charge' => (float)$params['service_charge'], + 'quota_type' => $quotaType ]); }); } diff --git a/app/controller/api/Auth.php b/app/controller/api/Auth.php index c82e7f2..7d61be6 100644 --- a/app/controller/api/Auth.php +++ b/app/controller/api/Auth.php @@ -162,17 +162,13 @@ class Auth extends BaseController } // 用户是否为兑换站点管理员 $data['is_exchange_saff'] = app()->make(ExchangePickupPointRepository::class)->userIsStaff($user->uid); - // 用户持有可用酒卡额度及积分 - $info = app()->make(ExchangeQuotaRepository::class) - ->getSearch([]) - ->field([ - 'uid', - // 可用额度=剩余额度-冻结额度 - '(surplus_quota - freeze_quota) as available' - ]) - ->where('uid',$user->uid) - ->findOrEmpty(); - $data['available'] = (float)$info->available; + // 用户持有可用酒卡额度 + $data['available'] = (float)app()->make(ExchangeQuotaRepository::class) + ->searchModel(['uid'=>$user->uid]) + ->value('(surplus_quota - freeze_quota)'); + $data['vegetable_available'] = (float)app()->make(ExchangeQuotaRepository::class) + ->searchModel(['uid'=>$user->uid,'quota_type'=>2]) + ->value('(surplus_quota - freeze_quota)'); return app('json')->success($data); } diff --git a/app/controller/api/user/Exchange.php b/app/controller/api/user/Exchange.php index 4cd0da7..2817147 100644 --- a/app/controller/api/user/Exchange.php +++ b/app/controller/api/user/Exchange.php @@ -35,19 +35,19 @@ class Exchange extends BaseController{ * @return mixed */ public function getUserHold(){ - $params = $this->request->params(['consume_uid']); + $params = $this->request->params(['consume_uid','quota_type']); $uid = $this->request->uid(); // 判断:是否存在指定消费者,不存在则使用当前登录用户 $uid = (int)$params['consume_uid'] > 0 ? (int)$params['consume_uid'] : $uid; + $params['uid'] = $uid; // 获取额度 $info = app()->make(ExchangeQuotaRepository::class) - ->getSearch([]) + ->searchModel($params) ->field([ - 'uid', + '*', // 可用额度=剩余额度-冻结额度 '(surplus_quota - freeze_quota) as available' ]) - ->where('uid',$uid) ->findOrEmpty(); $user = app()->make(UserRepository::class)->getSearch([])->where('uid',$uid)->findOrEmpty(); $info->available = (float)$info->available; @@ -294,15 +294,16 @@ class Exchange extends BaseController{ * @return mixed */ public function recordQuota(){ - $uid = $this->request->uid(); + $params = $this->request->params(['quota_type']); + $params['uid'] =$this->request->uid(); + $statistics = app()->make(ExchangeQuotaRepository::class) - ->getSearch([]) + ->searchModel($params) ->field([ '*', // 可用额度=剩余额度-冻结额度 '(surplus_quota - freeze_quota) as available' ]) - ->where('uid',$uid) ->findOrEmpty() ->toArray(); @@ -324,7 +325,7 @@ class Exchange extends BaseController{ */ public function recordQuotaList(){ [$page, $limit] = $this->getPage(); - $params = $this->request->params(['uid']); + $params = $this->request->params(['quota_type']); $params['uid'] = $this->request->uid(); $data = app()->make(ExchangeQuotaRecordRepository::class)->getList((array)$params,(int)$page,(int)$limit); @@ -352,7 +353,13 @@ class Exchange extends BaseController{ */ 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(); // 判断:信息是否符合要求 if($params['transfer_uid'] <= 0) return app('json')->fail("请选择接收用户!");