Files
yycea/application/common/model/wdsxh/points/UserWechatPointsLog.php
2026-03-17 09:56:06 +08:00

171 lines
5.9 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者,助力中小企业发展
// +----------------------------------------------------------------------
// | Copyright (c) 20172024 www.wdadmin.cn All rights reserved.
// +----------------------------------------------------------------------
// | Wdadmin系统产品软件并不是自由软件不加密并不代表开源未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn> www.wdadmin.cn
// +----------------------------------------------------------------------
/**
* Class UserWechatPointsLog
* Desc 微信用户积分日志Model
* Create on 2025/3/11 8:47
* Create by wangyafang
*/
namespace app\common\model\wdsxh\points;
use app\api\model\wdsxh\UserWechat;
use think\Db;
use think\Exception;
use think\exception\PDOException;
use think\exception\ValidateException;
use think\Model;
class UserWechatPointsLog extends Model
{
// 表名
protected $name = 'wdsxh_user_wechat_points_log';
// 自动写入时间戳字段
protected $autoWriteTimestamp = true;
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = false;
protected $deleteTime = false;
protected $type = [
'createtime' => 'timestamp:Y-m-d H:i:s',
];
/**
* Desc 活动积分
* @param $change 1增加积分 2减少积分
* Create on 2025/3/11 9:10
* Create by wangyafang
*/
public static function activity($change, $avtivityApplyObj, $activityObj ,$memo)
{
$userWeachatObj = (new UserWechat())->get($avtivityApplyObj['wechat_id']);
if ($change == 1) {
$after = bcadd($userWeachatObj['points'],$activityObj['points']);
} else {
$after = bcsub($userWeachatObj['points'],$activityObj['points']);
}
$pointsLogData = array(
'wechat_id'=>$avtivityApplyObj['wechat_id'],
'points'=>$activityObj['points'],
'before'=>$userWeachatObj['points'],
'after'=>$after,
'memo'=>$memo,
'change'=>$change,
'activity_id'=>$activityObj['id'],
'source'=>1,
);
self::handle($pointsLogData,$userWeachatObj);
}
/**
* Desc 处理积分
* @param $pointsLogData 积分数据
* @param $userWeachatObj 微信用户数据
* Create on 2025/3/11 9:10
* Create by wangyafang
*/
private static function handle($pointsLogData,$userWeachatObj)
{
$pointsLogModel = new UserWechatPointsLog();
try{
$pointsLogModel->data($pointsLogData);
$pointsLogModel->allowField(true)->save();
$userWeachatObj->points = $pointsLogData['after'];
$userWeachatObj->save();
} catch (ValidateException|PDOException|Exception $e) {
Db::rollback();
error_log('PointsLog error: ' . $e->getMessage());
}
}
/**
* Desc 积分商城
* @param $change 1增加积分 2减少积分
* Create on 2025/3/11 9:10
* Create by wangyafang
*/
public static function pointsMall($change, $orderObj, $goodsObj ,$memo)
{
$userWeachatObj = (new UserWechat())->get($orderObj['wechat_id']);
$after = bcsub($userWeachatObj['points'],$orderObj['total_points']);
$pointsLogData = array(
'wechat_id'=>$orderObj['wechat_id'],
'points'=>$orderObj['total_points'],
'before'=>$userWeachatObj['points'],
'after'=>$after,
'memo'=>$memo,
'change'=>$change,
'points_mall_goods_id'=>$goodsObj['id'],
);
self::handle($pointsLogData,$userWeachatObj);
}
/**
* Desc 增加积分
* @param $change 1增加积分
* @param $source 积分来源:3发布供需4入会成功5邀请会员
* Create on 2025/11/22 14:11
* Create by wangyafang
*/
public static function addPoints($change, $memo , $wechat_id, $add_points , $source)
{
$userWeachatObj = (new UserWechat())->get($wechat_id);
$after = bcadd($userWeachatObj['points'],$add_points);
$pointsLogData = array(
'wechat_id'=>$wechat_id,
'points'=>$add_points,
'before'=>$userWeachatObj['points'],
'after'=>$after,
'memo'=>$memo,
'change'=>$change,
'source'=>$source,
);
self::handle($pointsLogData,$userWeachatObj);
}
/**
* Desc 增加积分
* @param $change 1增加积分
* @param $source 积分来源:3发布供需4入会成功5邀请会员
* Create on 2025/11/22 14:11
* Create by wangyafang
*/
public static function joinMemberAddPoints($change, $memo , $wechat_id, $add_points , $source)
{
$userWeachatObj = (new UserWechat())->get($wechat_id);
$after = bcadd($userWeachatObj['points'],$add_points);
$pointsLogData = array(
'wechat_id'=>$wechat_id,
'points'=>$add_points,
'before'=>$userWeachatObj['points'],
'after'=>$after,
'memo'=>$memo,
'change'=>$change,
'source'=>$source,
);
self::handle($pointsLogData,$userWeachatObj);
$parent_wechat_id = (new UserWechat())->where('id',$wechat_id)->value('parent_wechat_id');
$invite_member_get_points = (new \app\admin\model\wdsxh\points\PointsConfig())->where('id',1)->value('invite_member_get_points');
if($parent_wechat_id && $invite_member_get_points>0){
UserWechatPointsLog::addPoints(1,'邀请会员',$parent_wechat_id,$invite_member_get_points,5);
}
}
}