parent
309fdd9757
commit
8c521fcb13
|
|
@ -9,7 +9,7 @@ namespace app\common\model\user;
|
||||||
use app\common\model\BaseModel;
|
use app\common\model\BaseModel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Common: 用户兑换积分变更记录
|
* Common: 用户酒水卡积分变更记录
|
||||||
* Author: wu-hui
|
* Author: wu-hui
|
||||||
* Time: 2024/01/12 17:23
|
* Time: 2024/01/12 17:23
|
||||||
* Class ExchangeIntegralRecord
|
* Class ExchangeIntegralRecord
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,40 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace app\common\model\user;
|
||||||
|
|
||||||
|
|
||||||
|
use app\common\model\BaseModel;
|
||||||
|
|
||||||
|
class ExchangeQuotaTransfer extends BaseModel
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
* @author xaboy
|
||||||
|
* @day 2020-03-30
|
||||||
|
*/
|
||||||
|
public static function tablePk(): string
|
||||||
|
{
|
||||||
|
return 'id';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
* @author xaboy
|
||||||
|
* @day 2020-03-30
|
||||||
|
*/
|
||||||
|
public static function tableName(): string
|
||||||
|
{
|
||||||
|
return 'exchange_quota_transfer';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function user()
|
||||||
|
{
|
||||||
|
return $this->hasOne(User::class, 'uid', 'uid');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -3,7 +3,12 @@
|
||||||
namespace app\common\repositories\user;
|
namespace app\common\repositories\user;
|
||||||
|
|
||||||
use app\common\dao\user\ExchangeQuotaDao;
|
use app\common\dao\user\ExchangeQuotaDao;
|
||||||
|
use app\common\model\user\ExchangeQuota;
|
||||||
|
use app\common\model\user\ExchangeQuotaRecord;
|
||||||
|
use app\common\model\user\ExchangeQuotaTransfer;
|
||||||
|
use app\common\model\user\User;
|
||||||
use app\common\repositories\BaseRepository;
|
use app\common\repositories\BaseRepository;
|
||||||
|
use think\facade\Db;
|
||||||
|
|
||||||
class ExchangeQuotaRepository extends BaseRepository{
|
class ExchangeQuotaRepository extends BaseRepository{
|
||||||
|
|
||||||
|
|
@ -56,9 +61,73 @@ class ExchangeQuotaRepository extends BaseRepository{
|
||||||
|
|
||||||
return compact('count','list');
|
return compact('count','list');
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Common: 转赠
|
||||||
|
* Author: wu-hui
|
||||||
|
* Time: 2024/01/18 16:04
|
||||||
|
* @param $uid
|
||||||
|
* @param $params
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function transfer($uid,$params){
|
||||||
|
return Db::transaction(function () use ($uid,$params) {
|
||||||
|
// 获取用户信息
|
||||||
|
$currentUser = ExchangeQuota::where('uid',$uid)->findOrEmpty();
|
||||||
|
$currentUserAvailable = (float)sprintf("%.2f",$currentUser->surplus_quota - $currentUser->freeze_quota);
|
||||||
|
$transferUser = ExchangeQuota::where('uid',$params['transfer_uid'])->findOrEmpty();
|
||||||
|
if((int)$transferUser->uid <= 0) $transferUser->uid = $params['transfer_uid'];
|
||||||
|
// 判断:当前用户持有数量是否充足
|
||||||
|
if($currentUserAvailable < $params['transfer_num']) throw new \Exception('转赠额度不能超过剩余可用额度!');
|
||||||
|
// 转账操作 - 减少当前用户额度;增加接收用户额度
|
||||||
|
$currentUserChangeFront = $currentUser->surplus_quota;
|
||||||
|
$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;
|
||||||
|
$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();
|
||||||
|
// 获取用户信息
|
||||||
|
$currentMemberName = User::where('uid',$uid)->value('nickname');
|
||||||
|
$transferMemberName = User::where('uid',$params['transfer_uid'])->value('nickname');
|
||||||
|
// 变更记录
|
||||||
|
$insertData = [
|
||||||
|
// 当前用户变更记录
|
||||||
|
[
|
||||||
|
'uid' => $uid,
|
||||||
|
'product_id' => 0,
|
||||||
|
'order_id' => 0,
|
||||||
|
'order_product_id' => 0,
|
||||||
|
'change_type' => 0,
|
||||||
|
'change_quantity' => (float)$params['transfer_num'],
|
||||||
|
'change_front' => $currentUserChangeFront,
|
||||||
|
'change_after' => (float)$currentUser->surplus_quota,
|
||||||
|
'remark' => "转赠给【{$transferMemberName}】",
|
||||||
|
],
|
||||||
|
// 接收用户变更记录
|
||||||
|
[
|
||||||
|
'uid' => $params['transfer_uid'],
|
||||||
|
'product_id' => 0,
|
||||||
|
'order_id' => 0,
|
||||||
|
'order_product_id' => 0,
|
||||||
|
'change_type' => 1,
|
||||||
|
'change_quantity' => (float)$params['transfer_num'],
|
||||||
|
'change_front' => $transferUserChangeFront,
|
||||||
|
'change_after' => (float)$transferUser->surplus_quota,
|
||||||
|
'remark' => "来自【{$currentMemberName}】的转赠",
|
||||||
|
]
|
||||||
|
];
|
||||||
|
ExchangeQuotaRecord::insertAll($insertData);
|
||||||
|
// 转赠记录
|
||||||
|
ExchangeQuotaTransfer::insert([
|
||||||
|
'uid' => $uid,
|
||||||
|
'transfer_uid' => $params['transfer_uid'],
|
||||||
|
'transfer_num' => (float)$params['transfer_num'],
|
||||||
|
'receipt_num' => (float)$params['receipt_num'],
|
||||||
|
'service_charge' => (float)$params['service_charge'],
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ class ExchangeQuota extends BaseController
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Common: 兑换积分 - 统计
|
* Common: 酒水卡积分 - 统计
|
||||||
* Author: wu-hui
|
* Author: wu-hui
|
||||||
* Time: 2024/01/12 17:38
|
* Time: 2024/01/12 17:38
|
||||||
* @return mixed
|
* @return mixed
|
||||||
|
|
@ -74,13 +74,13 @@ class ExchangeQuota extends BaseController
|
||||||
$model = new User();
|
$model = new User();
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
['className' => 'el-icon-coin','count' => $model->sum('exchange_integral'),'field' => '分','name' => '总兑换积分'],
|
['className' => 'el-icon-coin','count' => $model->sum('exchange_integral'),'field' => '分','name' => '总酒水卡积分'],
|
||||||
];
|
];
|
||||||
|
|
||||||
return app('json')->success($data);
|
return app('json')->success($data);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Common: 兑换积分 - 额度持有信息
|
* Common: 酒水卡积分 - 额度持有信息
|
||||||
* Author: wu-hui
|
* Author: wu-hui
|
||||||
* Time: 2024/01/12 17:39
|
* Time: 2024/01/12 17:39
|
||||||
* @return mixed
|
* @return mixed
|
||||||
|
|
@ -104,7 +104,7 @@ class ExchangeQuota extends BaseController
|
||||||
return app('json')->success(compact('count','list'));
|
return app('json')->success(compact('count','list'));
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Common: 兑换积分 - 变更记录
|
* Common: 酒水卡积分 - 变更记录
|
||||||
* Author: wu-hui
|
* Author: wu-hui
|
||||||
* Time: 2024/01/12 17:40
|
* Time: 2024/01/12 17:40
|
||||||
* @return mixed
|
* @return mixed
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,7 @@ class Exchange extends BaseController{
|
||||||
$info->available = (float)$info->available;
|
$info->available = (float)$info->available;
|
||||||
$info->available_integral = (float)$user->exchange_integral;
|
$info->available_integral = (float)$user->exchange_integral;
|
||||||
$info->diff_rate = 30;// 差价 应补金额,默认为30%
|
$info->diff_rate = 30;// 差价 应补金额,默认为30%
|
||||||
|
$info->transfer_rate = 0;// 转赠手续费比例 0-100
|
||||||
|
|
||||||
return app('json')->success($info);
|
return app('json')->success($info);
|
||||||
}
|
}
|
||||||
|
|
@ -299,8 +300,8 @@ class Exchange extends BaseController{
|
||||||
$statisticsList = [
|
$statisticsList = [
|
||||||
['title' => '总额度','value' => $statistics['total_quota']],
|
['title' => '总额度','value' => $statistics['total_quota']],
|
||||||
['title' => '已使用额度','value' => $statistics['use_quota']],
|
['title' => '已使用额度','value' => $statistics['use_quota']],
|
||||||
['title' => '剩余额度','value' => $statistics['surplus_quota']],
|
// ['title' => '剩余额度','value' => $statistics['surplus_quota']],
|
||||||
['title' => '冻结额度','value' => $statistics['freeze_quota']],
|
// ['title' => '冻结额度','value' => $statistics['freeze_quota']],
|
||||||
['title' => '可用额度','value' => $statistics['available']],
|
['title' => '可用额度','value' => $statistics['available']],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
@ -334,6 +335,34 @@ class Exchange extends BaseController{
|
||||||
|
|
||||||
return app('json')->success($data);
|
return app('json')->success($data);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Common: 额度转赠
|
||||||
|
* Author: wu-hui
|
||||||
|
* Time: 2024/01/18 16:04
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function quotaTransfer(){
|
||||||
|
// 参数
|
||||||
|
$params = $this->request->params([['transfer_num', 0],['receipt_num', 0],['service_charge', 0],['transfer_uid', 0]]);
|
||||||
|
$uid = $this->request->uid();
|
||||||
|
// 判断:信息是否符合要求
|
||||||
|
if($params['transfer_uid'] <= 0) return app('json')->fail("请选择接收用户!");
|
||||||
|
if($params['transfer_num'] <= 0) return app('json')->fail("转赠金额必须大于0!");
|
||||||
|
if($uid == $params['transfer_uid']) return app('json')->fail("接收用户不能是本人!");
|
||||||
|
// 转赠操作
|
||||||
|
try{
|
||||||
|
app()->make(ExchangeQuotaRepository::class)->transfer($uid,$params);
|
||||||
|
|
||||||
|
return app('json')->success('操作成功');
|
||||||
|
}catch(\Exception $e){
|
||||||
|
return app('json')->fail($e->getMessage());
|
||||||
|
}catch(\Throwable $e){
|
||||||
|
return app('json')->fail($e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -90,14 +90,14 @@ class OrderPaySuccessEvent{
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// 支付成功 - 赠送兑换积分
|
// 支付成功 - 赠送酒水卡积分
|
||||||
public function giveExchangeIntegral($groupOrder){
|
public function giveExchangeIntegral($groupOrder){
|
||||||
// 获取用户当前持有
|
// 获取用户当前持有
|
||||||
$userHoldInfo = User::where('uid',$groupOrder->uid)->findOrEmpty();
|
$userHoldInfo = User::where('uid',$groupOrder->uid)->findOrEmpty();
|
||||||
// 循环处理单个商品
|
// 循环处理单个商品
|
||||||
$insertData = [];
|
$insertData = [];
|
||||||
foreach($groupOrder->orderList as $orderInfo){
|
foreach($groupOrder->orderList as $orderInfo){
|
||||||
// 赠送 支付的金额=赠送的兑换积分
|
// 赠送 支付的金额=赠送的酒水卡积分
|
||||||
$changeFront = (float)$userHoldInfo->exchange_integral;
|
$changeFront = (float)$userHoldInfo->exchange_integral;
|
||||||
$userHoldInfo->exchange_integral += (float)$orderInfo->pay_price;// 总额度
|
$userHoldInfo->exchange_integral += (float)$orderInfo->pay_price;// 总额度
|
||||||
// 记录
|
// 记录
|
||||||
|
|
@ -110,7 +110,7 @@ class OrderPaySuccessEvent{
|
||||||
'change_quantity' => (float)$orderInfo->pay_price,
|
'change_quantity' => (float)$orderInfo->pay_price,
|
||||||
'change_front' => $changeFront,
|
'change_front' => $changeFront,
|
||||||
'change_after' => (float)$userHoldInfo->exchange_integral,
|
'change_after' => (float)$userHoldInfo->exchange_integral,
|
||||||
'remark' => "消费赠送兑换积分",
|
'remark' => "消费赠送酒水卡积分",
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
// 修改用户持有
|
// 修改用户持有
|
||||||
|
|
|
||||||
|
|
@ -362,6 +362,8 @@ Route::group('api/', function () {
|
||||||
Route::get('record_quota', 'Exchange/recordQuota');
|
Route::get('record_quota', 'Exchange/recordQuota');
|
||||||
Route::get('record_quota_list', 'Exchange/recordQuotaList');
|
Route::get('record_quota_list', 'Exchange/recordQuotaList');
|
||||||
Route::get('record_integral_list', 'Exchange/recordIntegralList');
|
Route::get('record_integral_list', 'Exchange/recordIntegralList');
|
||||||
|
// 转赠
|
||||||
|
Route::get('quota_transfer', 'Exchange/quotaTransfer');
|
||||||
|
|
||||||
|
|
||||||
})->prefix('api.user.');
|
})->prefix('api.user.');
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue