添加文件

main
fengxinyhyl 10 months ago
parent b5d907fb46
commit 513e4cded9
  1. 49
      app/common/dao/user/UserAssetsDao.php
  2. 65
      app/common/dao/user/UserAssetsLogDao.php
  3. 35
      app/common/model/user/UserAssets.php
  4. 40
      app/common/model/user/UserAssetsLog.php
  5. 13
      app/common/repositories/system/merchant/MerchantRepository.php
  6. 208
      app/common/repositories/user/UserAssetsLogRepository.php
  7. 225
      app/common/repositories/user/UserAssetsRepository.php

@ -0,0 +1,49 @@
<?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\dao\user;
use app\common\dao\BaseDao;
use app\common\model\user\UserAssets;
use app\common\model\user\UserSpreadLog;
class UserAssetsDao extends BaseDao
{
protected function getModel(): string
{
return UserAssets::class;
}
public function add($uid, $spread_uid, $old_spread_uid, $admin_id = 0)
{
$this->create(compact('uid', 'spread_uid', 'admin_id', 'old_spread_uid'));
}
public function getShareData(){
$total = UserAssets::sum('share_point');
$list = UserAssets::where('share_point','>',0)->field("uid, share_point")->select();
if($total){
return array('total'=>$total, 'list'=>$list->toArray());
}
return array('total'=>0, 'list'=>[]);
}
public function getTotalHuitong(){
return UserAssets::sum('huitong');
}
public function getSum($field){
return UserAssets::sum($field);
}
}

@ -0,0 +1,65 @@
<?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\dao\user;
use app\common\dao\BaseDao;
use app\common\model\user\UserAssetsLog;
class UserAssetsLogDao extends BaseDao
{
/**
* notes
* @return UserAssetsLog
* @create 2024/3/18 15:16
* @update 2024/3/18 15:16
* @author zhangkxiang
* @editor
*/
protected function getModel(): string
{
return UserAssetsLog::class;
}
public function add($uid, $spread_uid, $old_spread_uid, $admin_id = 0)
{
$this->create(compact('uid', 'spread_uid', 'admin_id', 'old_spread_uid'));
}
public function search(int $uid, array $where)
{
$userWhere = array();
if($uid){
$userWhere[] = array('uid', '=', $uid);
}
$query = UserAssetsLog::getDB()->where($userWhere)->where($where);
return $query;
}
public function orderData(int $orderId, array $where)
{
return UserAssetsLog::getDB()->where('order_id', $orderId)->where($where)->group('uid, asset_type')->field('uid,asset_type, sum(count) as count')->select();
}
public function updateOrderStatus($orderId, $status){
return UserAssetsLog::where('order_id', $orderId)->update(array('status' => $status));
}
public function getSum($where){
return UserAssetsLog::where($where)->sum('count');
}
}

@ -0,0 +1,35 @@
<?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\model\user;
use app\common\model\BaseModel;
class UserAssets extends BaseModel
{
public static function tablePk(): ?string
{
return 'uid';
}
public static function tableName(): string
{
return 'user_assets';
}
public function user()
{
return $this->hasOne(User::class, 'uid', 'uid');
}
}

@ -0,0 +1,40 @@
<?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\model\user;
use app\common\model\BaseModel;
class UserAssetsLog extends BaseModel
{
// 设置json类型字段
protected $json = ['ext'];
// 设置JSON数据返回数组
protected $jsonAssoc = true;
public static function tablePk(): ?string
{
return 'id';
}
public static function tableName(): string
{
return 'user_assets_log';
}
public function user()
{
return $this->hasOne(User::class, 'uid', 'uid');
}
}

@ -29,6 +29,8 @@ use app\common\repositories\store\shipping\ShippingTemplateRepository;
use app\common\repositories\store\StoreCategoryRepository;
use app\common\repositories\system\attachment\AttachmentCategoryRepository;
use app\common\repositories\system\attachment\AttachmentRepository;
use app\common\repositories\system\config\ConfigClassifyRepository;
use app\common\repositories\system\config\ConfigValueRepository;
use app\common\repositories\system\operate\OperateLogRepository;
use app\common\repositories\system\serve\ServeOrderRepository;
use app\common\repositories\user\UserBillRepository;
@ -250,6 +252,17 @@ class MerchantRepository extends BaseRepository
app()->make(ShippingTemplateRepository::class)->createDefault($merchant->mer_id);
app()->make(ProductCopyRepository::class)->defaulCopyNum($merchant->mer_id);
/** @var ConfigClassifyRepository $make */
$make = app()->make(ConfigClassifyRepository::class);
$cid = $make->keyById("integral");
if($cid){
$children = array_column($make->children($cid, 'config_classify_id')->toArray(), 'config_classify_id');
$children[] = $cid;
$configValue = app()->make(ConfigValueRepository::class);
$configValue->save($children, array('mer_integral_rate' => 100, 'mer_integral_status' => '1'), $merchant['mer_id']);
}
// 记录商户创建日志
if (!empty($admin_info) && !empty($update_infos)) {
event('create_operate_log', [

@ -0,0 +1,208 @@
<?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\UserAssetsLogDao;
use app\common\repositories\BaseRepository;
use app\common\repositories\store\product\ProductRepository;
use app\common\repositories\system\groupData\GroupDataRepository;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\facade\Log;
/**
* @mixin UserAssetsLogDao
*/
class UserAssetsLogRepository extends BaseRepository
{
const ASSET_TYPE_INTEGRAL = 1; // 积分
const ASSET_TYPE_DIAMOND = 2; // 钻石
const ASSET_TYPE_STOCK = 3; // 本票
const CHANGE_TYPE_RECOMMEND_PRODUCT = 1; // 爆单商品
const CHANGE_TYPE_SHARE = 2; // 分享奖
const CHANGE_TYPE_SERVER = 3; // 服务奖
const CHANGE_TYPE_SAVE = 4; // 预存
const CHANGE_TYPE_WITHDRAW = 5; // 积分提现
const CHANGE_TYPE_INTEGRAL_SEND = 6; // 积分转让
const CHANGE_TYPE_INTEGRAL_GET = 7; // 积分接收
const CHANGE_TYPE_DIAMOND_SEND = 8; // 钻石转让
const CHANGE_TYPE_DIAMOND_GET = 9; // 钻石接收
const CHANGE_TYPE_DIAMOND_LOTTERY = 10; // 抽奖
const CHANGE_TYPE_DIAMOND = 11; // 兑换钻石
const CHANGE_TYPE_STOCK = 12; // 兑换本票
const STATUS_GET = 1; // 获取
const STATUS_USE = 2; // 使用
const STATUS_WITHDRAW = 3; // 提现
public function __construct(UserAssetsLogDao $dao, UserAssetsRepository $userAssetsRepository, ProductRepository $productRepository, GroupDataRepository $groupRepository)
{
$this->dao = $dao;
$this->userAssetsRepository = $userAssetsRepository;
$this->productRepository = $productRepository;
$this->groupDataRepository = $groupRepository;
}
/**
* notes 获取资产变动类型
* @return string[]
* @create 2024/3/15 15:30
* @update 2024/3/15 15:30
* @author zhangkxiang
* @editor
*/
public function getChangeType()
{
return array(
self::CHANGE_TYPE_RECOMMEND_PRODUCT => '爆单商品',
self::CHANGE_TYPE_SHARE => '分享奖',
self::CHANGE_TYPE_SERVER => '服务奖',
self::CHANGE_TYPE_SAVE => '预存',
self::CHANGE_TYPE_WITHDRAW => '积分提现',
self::CHANGE_TYPE_INTEGRAL_SEND => '积分转让',
self::CHANGE_TYPE_INTEGRAL_GET => '积分接收',
self::CHANGE_TYPE_DIAMOND_SEND => '钻石转让',
self::CHANGE_TYPE_DIAMOND_GET => '钻石接收',
self::CHANGE_TYPE_DIAMOND_LOTTERY => '抽奖',
self::CHANGE_TYPE_DIAMOND => '兑换钻石',
self::CHANGE_TYPE_STOCK => '兑换本票',
);
}
public function getAssetType()
{
return array(
self::ASSET_TYPE_INTEGRAL => '积分',
self::ASSET_TYPE_DIAMOND => '钻石',
self::ASSET_TYPE_STOCK => '本票',
);
}
public function getList(array $where, $page, $limit)
{
$query = $this->dao->search($where);
$count = $query->count();
$list = $query->page($page, $limit)->with(['spread' => function ($query) {
$query->field('uid,nickname,avatar');
}])->select();
return compact('count', 'list');
}
/**
* notes 订单收货事件处理
* @param $orderItem
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @create 2024/3/19 15:03
* @update 2024/3/19 15:03
* @author zhangkxiang
* @editor
*/
public function userTakeEvent($orderItem)
{
// 订单发送冻结资产发放
$refundList = $this->_getOrderData($orderItem['order_id'], self::STATUS_FROZEN);
if ($refundList) {
foreach ($refundList as $refund) {
$this->userAssetsRepository->orderEvent($refund['uid'], self::STATUS_SUCCESS, $refund);
}
}
// 更新该订单的所有数据为退款状态
$this->dao->updateOrderStatus($orderItem['order_id'], self::STATUS_SUCCESS);
}
private function _getValue($value)
{
if ($value < 0.01) {
return 0.01;
}
return $value;
}
/**
* notes 插入变动日志,如果小于0.01则插入0.01
* @param $list
* @create 2024/3/17 22:09
* @update 2024/3/17 22:09
* @author zhangkxiang
* @editor
*/
public function addLog($list)
{
foreach ($list as $key => $item) {
$list[$key]['ext'] = $item['ext'] ?? array();
}
$this->dao->insertAll($list);
}
/**
* notes 获取资产变动日志
* @param $uid
* @param $where
* @param $page
* @param $limit
* @return array
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @create 2024/3/18 17:37
* @update 2024/3/18 17:37
* @author zhangkxiang
* @editor
*/
public function list($uid, $where, $page, $limit)
{
$query = $this->dao->search($uid, $where);
$count = $query->count();
$data = $query->page($page, $limit)->order('id desc')->select();
$list = array();
$changeType = $this->getChangeType();
$assetsType = $this->getAssetType();
$userRepository = app(UserRepository::class);
foreach ($data as $item) {
$item['type'] = $changeType[$item['type']] ?? '未知';
$item['asset_type'] = $assetsType[$item['asset_type']] ?? '未知';
if ($item['count'] > 0) {
$item['count'] = "+" . $item['count'];
}
$user = $userRepository->get($item['uid']);
if ($user) {
$item['user_nickname'] = $user['nickname'];
$item['user_phone'] = $user['phone'];
} else {
$item['user_nickname'] = '平台';
$item['user_phone'] = '未知';
}
$list[] = $item;
}
return compact('count', 'list');
}
public function getSum($where)
{
return $this->dao->getSum($where);
}
}

@ -0,0 +1,225 @@
<?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 app\common\repositories\system\groupData\GroupDataRepository;
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;
}
public function getConfig()
{
// 配置信息
/**
* @var GroupDataRepository $groupDataRepository
*/
$groupDataRepository = app()->make(GroupDataRepository::class);
$config = $groupDataRepository->getGroupDataLst(0, 100, 1, 100);
return array_column($config['list'], "value", 'key');
}
/**
* 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();
}else{
$ret = array(
'uid' => $uid,
'integral_buy' => 0.00,
'integral_withdraw' => 0.00,
'diamond' => 0.00,
'stock' => 0.00,
);
$this->dao->create($ret);
return $ret;
}
}
/**
* notes
* @param $uid
* @param $count
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @create 2024/3/19 22:33
* @update 2024/3/19 22:33
* @author zhangkxiang
* @editor
*/
public function consumeToShare($uid, $count)
{
$config = $this->getConfig();
$assets = $this->assets($uid);
if ($assets['consume'] < $config['consume_to_share'] * $count) {
throw new \Exception('消费积分不足');
}
$logList = array();
$consume = -1 * $config['consume_to_share'] * $count;
$logList[] = array(
'uid' => $uid,
'asset_type' => UserAssetsLogRepository::ASSET_TYPE_CONSUME,
'type' => UserAssetsLogRepository::CHANGE_TYPE_SHARE_EXCHANGE,
'status' => UserAssetsLogRepository::STATUS_SUCCESS,
'count' => $consume,
);
$logList[] = array(
'uid' => $uid,
'asset_type' => UserAssetsLogRepository::ASSET_TYPE_SHARE_POINT,
'type' => UserAssetsLogRepository::CHANGE_TYPE_SHARE_EXCHANGE,
'status' => UserAssetsLogRepository::STATUS_SUCCESS,
'count' => $count,
);
app()->make(UserAssetsLogRepository::class)->addLog($logList);
$this->dao->update($uid, array('consume' => $assets['consume'] + $consume, 'share_point' => $assets['share_point'] + $count, 'share_point_time' => time()));
}
/**
* notes 惠通宝转账
* @param $uid
* @param $phone
* @param $count
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @create 2024/3/20 11:01
* @update 2024/3/20 11:01
* @author zhangkxiang
* @editor
*/
public function sendHuitong($uid, $phone, $count)
{
$assets = $this->assets($uid);
if ($assets['huitong'] < $count) {
throw new \Exception('惠通宝不足');
}
/**
* @var UserRepository $userRepository
*/
$userRepository = app()->make(UserRepository::class);
$toUser = $userRepository->getUserByPhone($phone);
if (!$toUser) {
throw new \Exception('用户不存在');
}
$fromUser = $userRepository->get($uid);
$logList[] = array(
'uid' => $toUser['uid'],
'asset_type' => UserAssetsLogRepository::ASSET_TYPE_HUITONG,
'type' => UserAssetsLogRepository::CHANGE_TYPE_HUITONG_GET,
'status' => UserAssetsLogRepository::STATUS_SUCCESS,
'count' => $count,
'ext' => array(
'from_uid' => $uid,
'from_phone' => $fromUser['phone'],
),
);
$logList[] = array(
'uid' => $uid,
'asset_type' => UserAssetsLogRepository::ASSET_TYPE_HUITONG,
'type' => UserAssetsLogRepository::CHANGE_TYPE_HUITONG_SEND,
'status' => UserAssetsLogRepository::STATUS_SUCCESS,
'count' => -1 * $count,
'ext' => array(
'to_uid' => $toUser['uid'],
'to_phone' => $toUser['phone'],
),
);
app()->make(UserAssetsLogRepository::class)->addLog($logList);
$this->dao->update($uid, array('huitong' => $assets['huitong'] - $count));
$toAssets = $this->assets($toUser['uid']);
$this->dao->update($toUser['uid'], array('huitong' => $toAssets['huitong'] + $count));
}
/**
* notes
* @param $uid
* @param $count
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @create 2024/3/19 22:33
* @update 2024/3/19 22:33
* @author zhangkxiang
* @editor
*/
public function huitongToConsume($uid, $count)
{
$current = app(HuitongRepository::class)->getCurrent();
$assets = $this->assets($uid);
if ($assets['huitong'] < $count) {
throw new \Exception('惠通宝不足');
}
$logList = array();
$consume = $current * $count;
$logList[] = array(
'uid' => $uid,
'asset_type' => UserAssetsLogRepository::ASSET_TYPE_CONSUME,
'type' => UserAssetsLogRepository::CHANGE_TYPE_HUITONG,
'status' => UserAssetsLogRepository::STATUS_SUCCESS,
'count' => $consume,
);
$huitong = -1 * $count;
$logList[] = array(
'uid' => $uid,
'asset_type' => UserAssetsLogRepository::ASSET_TYPE_HUITONG,
'type' => UserAssetsLogRepository::CHANGE_TYPE_HUITONG,
'status' => UserAssetsLogRepository::STATUS_SUCCESS,
'count' => $huitong,
);
app()->make(UserAssetsLogRepository::class)->addLog($logList);
$this->dao->update($uid, array('consume' => $assets['consume'] + $consume, 'huitong' => $assets['huitong'] + $huitong));
}
public function getSum($field)
{
return $this->dao->getSum($field);
}
public function getWhereCount($where)
{
return $this->dao->getWhereCount($where);
}
}
Loading…
Cancel
Save