main
fengxinyhyl 10 months ago
parent 778d7638e7
commit 023f290e1e
  1. 91
      app/common/repositories/user/UserAssetsLogRepository.php
  2. 35
      app/common/repositories/user/UserAssetsRepository.php
  3. 19
      app/controller/api/Auth.php

@ -45,6 +45,7 @@ class UserAssetsLogRepository extends BaseRepository
const CHANGE_TYPE_DIAMOND_LOTTERY = 10; // 抽奖
const CHANGE_TYPE_DIAMOND = 11; // 兑换钻石
const CHANGE_TYPE_STOCK = 12; // 兑换本票
const CHANGE_TYPE_USE = 13; // 消费
const STATUS_GET = 1; // 获取
const STATUS_USE = 2; // 使用
@ -88,6 +89,7 @@ class UserAssetsLogRepository extends BaseRepository
self::CHANGE_TYPE_DIAMOND_LOTTERY => '抽奖',
self::CHANGE_TYPE_DIAMOND => '兑换钻石',
self::CHANGE_TYPE_STOCK => '兑换本票',
self::CHANGE_TYPE_USE => '消费',
);
}
@ -112,7 +114,6 @@ class UserAssetsLogRepository extends BaseRepository
}
/**
* notes 订单收货事件处理
* @param $orderItem
@ -157,12 +158,92 @@ class UserAssetsLogRepository extends BaseRepository
}
private function _getValue($value)
/**
* notes 分享奖励
* @create 2024/4/9 15:11
* @update 2024/4/9 15:11
* @author zhangkxiang
* @editor
*/
public function shareAward($orderId)
{
if ($value < 0.01) {
return 0.01;
/**
* @var StoreOrderRepository $orderRepository
*/
$orderRepository = app(StoreOrderRepository::class);
$order = $orderRepository->getDetail($orderId);
// Log::info('order is '.json_encode($order));
$LogList = array();
foreach ($order['orderProduct'] as $productItem) {
$product = $this->productRepository->get($productItem['product_id']);
Log::info("product is " . json_encode($product));
$profit = $productItem['total_price'] - $productItem['cost'];
if ($product['is_hot']) {
$integralOne = $product['hot_integral_one'];
$integralTwo = $product['hot_integral_two'];
$diamondOne = $product['hot_diamond_one'];
$diamondTwo = $product['hot_diamond_two'];
} else {
$integralOne = $product['normal_integral_one'];
$integralTwo = $product['normal_integral_two'];
$diamondOne = $product['normal_diamond_one'];
$diamondTwo = $product['normal_diamond_two'];
}
if ($order['spread_uid']) {
$tmp = array('diamond' => $diamondOne, 'integral' => $this->_getValue($profit * $integralOne / 100));
$LogList[] = array(
'uid' => $order['spread_uid'],
'asset_type' => self::ASSET_TYPE_INTEGRAL,
'type' => self::CHANGE_TYPE_SHARE,
'status' => self::STATUS_GET,
'product_id' => $productItem['product_id'],
'order_id' => $orderId,
'count' => $tmp['integral'],
);
$LogList[] = array(
'uid' => $order['spread_uid'],
'asset_type' => self::ASSET_TYPE_DIAMOND,
'type' => self::CHANGE_TYPE_SHARE,
'status' => self::STATUS_GET,
'product_id' => $productItem['product_id'],
'order_id' => $orderId,
'count' => $diamondOne,
);
$this->userAssetsRepository->updateAssets($order['spread_uid'], $tmp);
}
if ($order['top_uid']) {
$tmp = array('diamond' => $diamondTwo, 'integral' => $this->_getValue($profit * $integralTwo / 100));
$LogList[] = array(
'uid' => $order['top_uid'],
'asset_type' => self::ASSET_TYPE_INTEGRAL,
'type' => self::CHANGE_TYPE_SHARE,
'status' => self::STATUS_GET,
'product_id' => $productItem['product_id'],
'order_id' => $orderId,
'count' => $tmp['integral'],
);
$LogList[] = array(
'uid' => $order['top_uid'],
'asset_type' => self::ASSET_TYPE_DIAMOND,
'type' => self::CHANGE_TYPE_SHARE,
'status' => self::STATUS_GET,
'product_id' => $productItem['product_id'],
'order_id' => $orderId,
'count' => $diamondTwo,
);
$this->userAssetsRepository->updateAssets($order['top_uid'], $tmp);
}
}
return $value;
$this->addLog($LogList);
}
private function _getValue($value)
{
return round($value, 2);
}

@ -58,18 +58,51 @@ class UserAssetsRepository extends BaseRepository
$item = $this->dao->get($uid);
if ($item) {
return $item->toArray();
}else{
} else {
$ret = array(
'uid' => $uid,
'integral_buy' => 0.00,
'integral_withdraw' => 0.00,
'diamond' => 0.00,
'stock' => 0.00,
'create_time' => date('Y-m-d H:i:s'),
);
$this->dao->create($ret);
return $ret;
}
}
public function updateAssets($uid, $data, $add = true)
{
$assets = $this->assets($uid);
$update = array('integral_buy' => 0, 'integral_withdraw' => 0, 'diamond' => 0, 'stock' => 0);
if (isset($data['integral']) and $data['integral']) {
$tmp = $this->getIntegral($data['integral']);
$update['integral_buy'] = $tmp['integral_buy'];
$update['integral_withdraw'] = $tmp['integral_withdraw'];
}
if(isset($data['diamond']) and $data['diamond']){
$update['diamond'] = $data['diamond'];
}
if(isset($data['stock']) and $data['stock']){
$update['stock'] = $data['stock'];
}
$updateData = array();
foreach ($update as $key => $value){
if($value){
$updateData[$key] = $add ? $assets[$key] + $value : $assets[$key] - $value;
}
}
$this->dao->update($uid, $updateData);
}
public function getIntegral($total)
{
$integral_buy = round($total * 0.2, 2);
$integral_withdraw = round($total * 0.8, 2);
return array('integral_buy' => $integral_buy, 'integral_withdraw' => $integral_withdraw);
}

@ -18,6 +18,7 @@ use app\common\repositories\store\order\StoreGroupOrderRepository;
use app\common\repositories\store\order\StoreOrderRepository;
use app\common\repositories\store\order\StoreRefundOrderRepository;
use app\common\repositories\system\notice\SystemNoticeConfigRepository;
use app\common\repositories\user\UserAssetsLogRepository;
use app\common\repositories\user\UserOrderRepository;
use app\common\repositories\user\UserRechargeRepository;
use app\common\repositories\user\UserRepository;
@ -56,7 +57,23 @@ class Auth extends BaseController
{
public function test()
{
event('order.take', array('order' => array('order_id' => 1)));
// $data = [
// 'tempId' => '',
// 'id' => '',
// ];
// Queue::push(SendSmsJob::class,$data);
// $status = app()->make(SystemNoticeConfigRepository::class)->getNoticeStatusByConstKey($data['tempId']);
// if ($status['notice_sms'] == 1) {
// SmsService::sendMessage($data);
// }
// if ($status['notice_wechat'] == 1) {
// app()->make(WechatTemplateMessageService::class)->sendTemplate($data);
// }
// if ($status['notice_routine'] == 1) {
// app()->make(WechatTemplateMessageService::class)->subscribeSendTemplate($data);
// }
app(UserAssetsLogRepository::class)->shareAward(1);
return app('json')->success();
}

Loading…
Cancel
Save