init commit
This commit is contained in:
171
application/common/model/wdsxh/points/UserWechatPointsLog.php
Normal file
171
application/common/model/wdsxh/points/UserWechatPointsLog.php
Normal file
@@ -0,0 +1,171 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力中小企业发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user