|
|
|
<?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\ProductAssistRepository;
|
|
|
|
use app\common\repositories\store\product\ProductRepository;
|
|
|
|
use think\facade\Log;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @mixin UserAssetsLogDao
|
|
|
|
*/
|
|
|
|
class UserAssetsLogRepository extends BaseRepository
|
|
|
|
{
|
|
|
|
const ASSET_TYPE_CONSUME = 1; // 消费积分
|
|
|
|
const ASSET_TYPE_SHARE_POINT = 2; // 分红点
|
|
|
|
const ASSET_TYPE_WELFARE = 3; // 福利积分
|
|
|
|
const ASSET_TYPE_HUITONG = 4; // 惠通宝
|
|
|
|
const ASSET_TYPE_CONTRIBUTION = 5; // 贡献值
|
|
|
|
|
|
|
|
const CHANGE_TYPE_ORDER_GET = 1; // 订单获取
|
|
|
|
const CHANGE_TYPE_SIGN = 2; // 签到
|
|
|
|
const CHANGE_TYPE_SHARE = 3; // 分红
|
|
|
|
const CHANGE_TYPE_ORDER_PAY = 4; // 订单消费
|
|
|
|
const CHANGE_TYPE_SPREAD = 5; // 推广
|
|
|
|
const CHANGE_TYPE_CULTIVATE = 6; // 培育
|
|
|
|
const CHANGE_TYPE_TRANSFER = 7; // 赠与
|
|
|
|
const CHANGE_TYPE_EXCHANGE = 8; // 兑换
|
|
|
|
|
|
|
|
const STATUS_FROZEN = 0; // 冻结
|
|
|
|
const STATUS_SUCCESS = 1; // 成功
|
|
|
|
const STATUS_REFUND = 2; // 退款
|
|
|
|
|
|
|
|
public function __construct(UserAssetsLogDao $dao, UserAssetsRepository $userAssetsRepository, ProductRepository $productRepository)
|
|
|
|
{
|
|
|
|
$this->dao = $dao;
|
|
|
|
$this->userAssetsRepository = $userAssetsRepository;
|
|
|
|
$this->productRepository = $productRepository;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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_ORDER_GET => "订单获取",
|
|
|
|
self::CHANGE_TYPE_SIGN => "签到",
|
|
|
|
self::CHANGE_TYPE_SHARE => "分红",
|
|
|
|
self::CHANGE_TYPE_ORDER_PAY => "订单消费",
|
|
|
|
self::CHANGE_TYPE_SPREAD => "推广",
|
|
|
|
self::CHANGE_TYPE_CULTIVATE => "培育",
|
|
|
|
self::CHANGE_TYPE_TRANSFER => "赠与",
|
|
|
|
self::CHANGE_TYPE_EXCHANGE => "兑换",
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
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 $groupOrder
|
|
|
|
* @create 2024/3/15 17:22
|
|
|
|
* @update 2024/3/15 17:22
|
|
|
|
* @author zhangkxiang
|
|
|
|
* @editor
|
|
|
|
*/
|
|
|
|
public function userPayEvent($groupOrder)
|
|
|
|
{
|
|
|
|
$logList = array();
|
|
|
|
$consume = $welfare = $huitong = $contribution = 0;
|
|
|
|
// 循环groupOrder, 按照商家订单处理
|
|
|
|
foreach ($groupOrder['orderList'] as $orderItem) {
|
|
|
|
$base = 0;
|
|
|
|
// 1. 本人的消费积分
|
|
|
|
$logList[] = array(
|
|
|
|
'uid' => $groupOrder['uid'],
|
|
|
|
'asset_type' => self::ASSET_TYPE_CONSUME,
|
|
|
|
'type' => self::CHANGE_TYPE_ORDER_GET,
|
|
|
|
'status' => self::STATUS_FROZEN,
|
|
|
|
'order_id' => $orderItem['order_id'],
|
|
|
|
'count' => $orderItem['pay_price'],
|
|
|
|
);
|
|
|
|
$consume += $orderItem['pay_price'];
|
|
|
|
|
|
|
|
foreach ($orderItem['orderProduct'] as $orderProduct) {
|
|
|
|
// 获取商品详情(奖励积分
|
|
|
|
$product = $this->productRepository->detail($orderProduct['product_id'], null);
|
|
|
|
Log::info("product" . json_encode($product));
|
|
|
|
$rate = floatval($orderProduct['total_price']) / floatval($orderProduct['product_price']) * 100;
|
|
|
|
if ($rate >= $product['cash_rate']) {
|
|
|
|
$base += $product['base'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 如果该订单奖励基数大于0
|
|
|
|
if($base){
|
|
|
|
// 2. 本人的福利积分
|
|
|
|
$orderWelfare = round($base * 0.1, 2);
|
|
|
|
$welfare+= $orderWelfare;
|
|
|
|
$logList[] = array(
|
|
|
|
'uid' => $groupOrder['uid'],
|
|
|
|
'asset_type' => self::ASSET_TYPE_WELFARE,
|
|
|
|
'type' => self::CHANGE_TYPE_ORDER_GET,
|
|
|
|
'status' => self::STATUS_FROZEN,
|
|
|
|
'order_id' => $orderItem['order_id'],
|
|
|
|
'count' => $orderWelfare,
|
|
|
|
);
|
|
|
|
|
|
|
|
// 3. 本人的惠通宝
|
|
|
|
$orderHuitong = round($base * 0.05, 2);
|
|
|
|
$huitong+= $orderHuitong;
|
|
|
|
$logList[] = array(
|
|
|
|
'uid' => $groupOrder['uid'],
|
|
|
|
'asset_type' => self::ASSET_TYPE_HUITONG,
|
|
|
|
'type' => self::CHANGE_TYPE_ORDER_GET,
|
|
|
|
'status' => self::STATUS_FROZEN,
|
|
|
|
'order_id' => $orderItem['order_id'],
|
|
|
|
'count' => $orderHuitong,
|
|
|
|
);
|
|
|
|
|
|
|
|
// 4. 本人的贡献值
|
|
|
|
$orderContribution = round($base * 0.01, 2);
|
|
|
|
$contribution+= $orderContribution;
|
|
|
|
$logList[] = array(
|
|
|
|
'uid' => $groupOrder['uid'],
|
|
|
|
'asset_type' => self::ASSET_TYPE_HUITONG,
|
|
|
|
'type' => self::CHANGE_TYPE_ORDER_GET,
|
|
|
|
'status' => self::STATUS_FROZEN,
|
|
|
|
'order_id' => $orderItem['order_id'],
|
|
|
|
'count' => $orderContribution,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->addLog($logList);
|
|
|
|
$this->userAssetsRepository->orderEvent($groupOrder['uid'], self::STATUS_FROZEN, compact('consume', 'welfare', 'huitong', 'contribution'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function addLog($list)
|
|
|
|
{
|
|
|
|
$this->dao->insertAll($list);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function userRefund()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|