添加:积分管理相关接口(商户积分列表、积分转换接口)
This commit is contained in:
parent
717b148550
commit
9925ef1918
|
|
@ -15,6 +15,7 @@ namespace app\common\model\user;
|
||||||
|
|
||||||
|
|
||||||
use app\common\model\BaseModel;
|
use app\common\model\BaseModel;
|
||||||
|
use app\common\model\system\merchant\Merchant;
|
||||||
|
|
||||||
class Integral extends BaseModel
|
class Integral extends BaseModel
|
||||||
{
|
{
|
||||||
|
|
@ -44,4 +45,8 @@ class Integral extends BaseModel
|
||||||
return $this->hasOne(User::class, 'uid', 'uid');
|
return $this->hasOne(User::class, 'uid', 'uid');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function mer(){
|
||||||
|
return $this->hasOne(Merchant::class,'mer_id','mer_id');
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -108,10 +108,30 @@ class IntegralRepository extends BaseRepository
|
||||||
|
|
||||||
return compact('integral','convert_integral','convert_rate');
|
return compact('integral','convert_integral','convert_rate');
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Common: 获取商户积分列表
|
||||||
|
* Author: wu-hui
|
||||||
|
* Time: 2023/11/10 14:20
|
||||||
|
* @param int $uid
|
||||||
|
* @param int $page
|
||||||
|
* @param int $limit
|
||||||
|
* @return array
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\DbException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
*/
|
||||||
|
public function getMerIntegralList(int $uid,int $page,int $limit):array{
|
||||||
|
$query = $this->dao->getSearch(['uid'=>$uid])
|
||||||
|
->where('mer_id','>',0)
|
||||||
|
->with(['mer'=>function($query){
|
||||||
|
$query->field('mer_id,mer_name,mer_avatar,mer_integral_platform_rate')->bind(['mer_name','mer_avatar','mer_integral_platform_rate']);
|
||||||
|
}])
|
||||||
|
->order('create_time DESC');
|
||||||
|
$count = $query->count();
|
||||||
|
$list = $query->page($page,$limit)->select();
|
||||||
|
|
||||||
|
return compact('count','list');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -54,10 +54,12 @@ class UserBillRepository extends BaseRepository
|
||||||
'integral/sys_inc' => '系统增加积分',
|
'integral/sys_inc' => '系统增加积分',
|
||||||
'integral/timeout' => '积分过期',
|
'integral/timeout' => '积分过期',
|
||||||
'integral/mer_give' => '商户赠送',
|
'integral/mer_give' => '商户赠送',
|
||||||
|
'integral/convert' => '积分转换',
|
||||||
'mer_integral/deduction' => '积分抵扣',
|
'mer_integral/deduction' => '积分抵扣',
|
||||||
'mer_integral/refund' => '订单退款',
|
'mer_integral/refund' => '订单退款',
|
||||||
'mer_integral/lock' => '下单赠送积分',
|
'mer_integral/lock' => '下单赠送积分',
|
||||||
'mer_integral/mer_give' => '商户赠送',
|
'mer_integral/mer_give' => '商户赠送',
|
||||||
|
'mer_integral/convert' => '积分转换',
|
||||||
'mer_lock_money/order' => '商户佣金冻结',
|
'mer_lock_money/order' => '商户佣金冻结',
|
||||||
'now_money/brokerage' => '佣金转入余额',
|
'now_money/brokerage' => '佣金转入余额',
|
||||||
'now_money/pay_product' => '购买商品',
|
'now_money/pay_product' => '购买商品',
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ namespace app\controller\api\user;
|
||||||
use app\common\repositories\store\IntegralRepository;
|
use app\common\repositories\store\IntegralRepository;
|
||||||
use app\common\repositories\store\service\StoreServiceRepository;
|
use app\common\repositories\store\service\StoreServiceRepository;
|
||||||
use app\common\repositories\system\CacheRepository;
|
use app\common\repositories\system\CacheRepository;
|
||||||
|
use app\common\repositories\user\IntegralGiveRecordRepository;
|
||||||
use app\common\repositories\user\MemberinterestsRepository;
|
use app\common\repositories\user\MemberinterestsRepository;
|
||||||
use app\common\repositories\user\UserBillRepository;
|
use app\common\repositories\user\UserBillRepository;
|
||||||
use app\common\repositories\user\UserBrokerageRepository;
|
use app\common\repositories\user\UserBrokerageRepository;
|
||||||
|
|
@ -26,10 +27,12 @@ use app\validate\api\UserBaseInfoValidate;
|
||||||
use crmeb\basic\BaseController;
|
use crmeb\basic\BaseController;
|
||||||
use crmeb\services\MiniProgramService;
|
use crmeb\services\MiniProgramService;
|
||||||
use crmeb\services\SmsService;
|
use crmeb\services\SmsService;
|
||||||
|
use Exception;
|
||||||
use think\App;
|
use think\App;
|
||||||
use think\db\exception\DataNotFoundException;
|
use think\db\exception\DataNotFoundException;
|
||||||
use think\db\exception\DbException;
|
use think\db\exception\DbException;
|
||||||
use think\db\exception\ModelNotFoundException;
|
use think\db\exception\ModelNotFoundException;
|
||||||
|
use think\facade\Db;
|
||||||
|
|
||||||
class User extends BaseController
|
class User extends BaseController
|
||||||
{
|
{
|
||||||
|
|
@ -426,8 +429,10 @@ class User extends BaseController
|
||||||
}
|
}
|
||||||
$nextClearDay = date('m月d日', $nextClearDay);
|
$nextClearDay = date('m月d日', $nextClearDay);
|
||||||
$clear = compact('nextClearDay', 'status', 'nextClearIntegral');
|
$clear = compact('nextClearDay', 'status', 'nextClearIntegral');
|
||||||
|
// 获取用户平台积分
|
||||||
|
$platform_integral = app()->make(\app\common\repositories\user\IntegralRepository::class)->getMerIntegral((int)$this->user->uid,(int)0);
|
||||||
|
|
||||||
return app('json')->success(compact('integral', 'lockIntegral', 'deductionIntegral', 'totalGainIntegral', 'clear'));
|
return app('json')->success(compact('integral', 'lockIntegral', 'deductionIntegral', 'totalGainIntegral', 'clear','platform_integral'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function integralList(UserBillRepository $repository)
|
public function integralList(UserBillRepository $repository)
|
||||||
|
|
@ -440,6 +445,85 @@ class User extends BaseController
|
||||||
return app('json')->success($data);
|
return app('json')->success($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Common: 获取用户商户积分列表
|
||||||
|
* Author: wu-hui
|
||||||
|
* Time: 2023/11/10 14:21
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function merIntegralList(){
|
||||||
|
[$page, $limit] = $this->getPage();
|
||||||
|
$data = app()->make(\app\common\repositories\user\IntegralRepository::class)->getMerIntegralList((int)$this->user->uid,(int)$page,(int)$limit);
|
||||||
|
|
||||||
|
return app('json')->success($data);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Common: 积分转换
|
||||||
|
* Author: wu-hui
|
||||||
|
* Time: 2023/11/10 15:37
|
||||||
|
* @param $merId
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function merIntegralConvert($merId){
|
||||||
|
$params = $this->request->params(['convert_integral']);
|
||||||
|
$convertIntegral = (float)abs($params['convert_integral']);
|
||||||
|
if($convertIntegral <= 0) return app('json')->fail('转换数量不能小于0!');
|
||||||
|
// 转换操作
|
||||||
|
try {
|
||||||
|
Db::transaction(function () use ($merId, $convertIntegral) {
|
||||||
|
$mer_integral_platform_rate = (float)merchantConfig($merId,'mer_integral_platform_rate');
|
||||||
|
if($mer_integral_platform_rate <= 0) throw new Exception('转换失败,商户未设置转换比例!');
|
||||||
|
$uid = $this->request->uid();
|
||||||
|
$user = app()->make(UserRepository::class)->get($uid);
|
||||||
|
$integralMake = app()->make(\app\common\repositories\user\IntegralRepository::class);
|
||||||
|
$bills = [];
|
||||||
|
// 计算转换后的积分 应得平台积分
|
||||||
|
$convertAfterIntegral = (float)sprintf("%.2f",$convertIntegral * $mer_integral_platform_rate);
|
||||||
|
// 减少商户积分
|
||||||
|
$integralMake->changeIntegral((int)$uid,(int)$merId,(float)sprintf('%.2f',0 - $convertIntegral));
|
||||||
|
$user->integral = bcsub($user->integral,$convertIntegral,2);
|
||||||
|
$bills[] = [
|
||||||
|
'uid' => $uid,
|
||||||
|
'link_id' => $merId,
|
||||||
|
'pm' => 0,
|
||||||
|
'title' => '积分转换',
|
||||||
|
'category' => 'mer_integral',
|
||||||
|
'type' => 'convert',
|
||||||
|
'number' => $convertIntegral,
|
||||||
|
'balance' => $user->integral,
|
||||||
|
'mark' => "将({$convertIntegral})本商户积分转换为平台积分,获得{$convertAfterIntegral}平台积分",
|
||||||
|
'mer_id' => $merId,
|
||||||
|
'status' => 1
|
||||||
|
];
|
||||||
|
// 增加平台积分
|
||||||
|
$integralMake->changeIntegral((int)$uid,(int)0,(float)sprintf('%.2f', $convertAfterIntegral));
|
||||||
|
$user->integral = bcadd($user->integral,$convertAfterIntegral,2);
|
||||||
|
$bills[] = [
|
||||||
|
'uid' => $uid,
|
||||||
|
'link_id' => $merId,
|
||||||
|
'pm' => 0,
|
||||||
|
'title' => '积分转换',
|
||||||
|
'category' => 'integral',
|
||||||
|
'type' => 'convert',
|
||||||
|
'number' => $convertAfterIntegral,
|
||||||
|
'balance' => $user->integral,
|
||||||
|
'mark' => "将({$convertIntegral})商户积分转换为平台积分,获得{$convertAfterIntegral}平台积分",
|
||||||
|
'mer_id' => 0,
|
||||||
|
'status' => 1
|
||||||
|
];
|
||||||
|
// 修改总积分
|
||||||
|
$user->save();
|
||||||
|
// 添加记录
|
||||||
|
app()->make(UserBillRepository::class)->insertAll($bills);
|
||||||
|
});
|
||||||
|
|
||||||
|
return app('json')->success('操作成功');
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
return app('json')->fail($e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function services()
|
public function services()
|
||||||
{
|
{
|
||||||
$uid = $this->user->uid;
|
$uid = $this->user->uid;
|
||||||
|
|
|
||||||
|
|
@ -202,6 +202,9 @@ Route::group('api/', function () {
|
||||||
//积分
|
//积分
|
||||||
Route::get('integral/info', 'User/integralInfo');
|
Route::get('integral/info', 'User/integralInfo');
|
||||||
Route::get('integral/lst', 'User/integralList');
|
Route::get('integral/lst', 'User/integralList');
|
||||||
|
Route::post('integral/mer_list', 'User/merIntegralList');
|
||||||
|
Route::post('integral/integral_convert/:merId', 'User/merIntegralConvert');
|
||||||
|
|
||||||
|
|
||||||
//客服列表
|
//客服列表
|
||||||
Route::get('services', 'User/services');
|
Route::get('services', 'User/services');
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue