You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
122 lines
4.5 KiB
122 lines
4.5 KiB
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
|
// +----------------------------------------------------------------------
|
|
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
|
// +----------------------------------------------------------------------
|
|
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
|
// +----------------------------------------------------------------------
|
|
// | Author: CRMEB Team <admin@crmeb.com>
|
|
// +----------------------------------------------------------------------
|
|
|
|
|
|
namespace app\common\repositories\user;
|
|
|
|
|
|
use app\common\dao\user\UserAssetsDao;
|
|
use app\common\repositories\BaseRepository;
|
|
use think\db\exception\DataNotFoundException;
|
|
use think\db\exception\DbException;
|
|
use think\db\exception\ModelNotFoundException;
|
|
|
|
/**
|
|
* @mixin UserAssetsDao
|
|
*/
|
|
class UserAssetsRepository extends BaseRepository
|
|
{
|
|
|
|
|
|
public function __construct(UserAssetsDao $dao)
|
|
{
|
|
$this->dao = $dao;
|
|
}
|
|
|
|
|
|
/**
|
|
* notes 获取用户资产
|
|
* @param $uid
|
|
* @return array
|
|
* @create 2024/3/18 14:48
|
|
* @update 2024/3/18 14:48
|
|
* @author zhangkxiang
|
|
* @editor
|
|
*/
|
|
public function assets($uid)
|
|
{
|
|
$item = $this->dao->get($uid);
|
|
if($item){
|
|
return $item->toArray();
|
|
}
|
|
return array(
|
|
'uid' => 0,
|
|
'consume' => 0.00,
|
|
'consume_frozen' => 0.00,
|
|
'share_point' => 0.00,
|
|
'welfare' => 0.00,
|
|
'welfare_frozen' => 0.00,
|
|
'huitong' => 0.00,
|
|
'huitong_frozen' => 0.00,
|
|
'contribution' => 0.00,
|
|
'contribution_frozen' => 0.00,
|
|
);
|
|
}
|
|
|
|
|
|
/**
|
|
* notes 订单状态发生变更,影响用户资产
|
|
* @param $uid
|
|
* @param $status
|
|
* @param $data
|
|
* @throws DataNotFoundException
|
|
* @throws DbException
|
|
* @throws ModelNotFoundException
|
|
* @create 2024/3/15 17:23
|
|
* @update 2024/3/15 17:23
|
|
* @author zhangkxiang
|
|
* @editor
|
|
*/
|
|
public function orderEvent($uid, $status, $data = array())
|
|
{
|
|
$assets = array();
|
|
$info = $this->dao->get($uid);
|
|
if($info){
|
|
// 购买订单获得冻结资产
|
|
if($status == UserAssetsLogRepository::STATUS_FROZEN) {
|
|
$assets = array(
|
|
'consume_frozen' => $info['consume_frozen'] + $data['consume'],
|
|
'welfare_frozen' => $info['welfare_frozen'] + $data['welfare'],
|
|
'huitong_frozen' => $info['huitong_frozen'] + $data['huitong'],
|
|
'contribution_frozen' => $info['contribution_frozen'] + $data['contribution'],
|
|
);
|
|
}elseif ($status == UserAssetsLogRepository::STATUS_SUCCESS){
|
|
$assets = array(
|
|
'consume' => $info['consume'] + $data['consume'],
|
|
'welfare' => $info['welfare'] + $data['welfare'],
|
|
'huitong' => $info['huitong'] + $data['huitong'],
|
|
'contribution' => $info['contribution'] + $data['contribution'],
|
|
'consume_frozen' => $info['consume_frozen'] - $data['consume'],
|
|
'welfare_frozen' => $info['welfare_frozen'] - $data['welfare'],
|
|
'huitong_frozen' => $info['huitong_frozen'] - $data['huitong'],
|
|
'contribution_frozen' => $info['contribution_frozen'] - $data['contribution'],
|
|
);
|
|
}elseif ($status == UserAssetsLogRepository::STATUS_REFUND){
|
|
$assets = array(
|
|
'consume_frozen' => $info['consume_frozen'] - $data['consume'],
|
|
'welfare_frozen' => $info['welfare_frozen'] - $data['welfare'],
|
|
'huitong_frozen' => $info['huitong_frozen'] - $data['huitong'],
|
|
'contribution_frozen' => $info['contribution_frozen'] - $data['contribution'],
|
|
);
|
|
}
|
|
$this->dao->update($uid, $assets);
|
|
}else{
|
|
$assets = array(
|
|
'uid' => $uid,
|
|
'consume_frozen' => $data['consume'] ?? 0,
|
|
'welfare_frozen' => $data['welfare'] ?? 0,
|
|
'huitong_frozen' => $data['huitong'] ?? 0,
|
|
'contribution_frozen' => $data['contribution'] ?? 0,
|
|
);
|
|
$this->dao->create($assets);
|
|
}
|
|
}
|
|
}
|
|
|