parent
e88a2f1acf
commit
e248e6b175
|
|
@ -0,0 +1,46 @@
|
||||||
|
<?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\BaseModel;
|
||||||
|
use app\common\model\user\Integral;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Common: 用户积分
|
||||||
|
* Author: wu-hui
|
||||||
|
* Time: 2023/11/07 10:13
|
||||||
|
* Class IntegralDao
|
||||||
|
* @package app\common\dao\user
|
||||||
|
*/
|
||||||
|
class IntegralDao extends BaseDao{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Common: 初始化模型
|
||||||
|
* Author: wu-hui
|
||||||
|
* Time: 2023/11/07 10:13
|
||||||
|
* @return BaseModel
|
||||||
|
*/
|
||||||
|
protected function getModel(): string
|
||||||
|
{
|
||||||
|
return Integral::class;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,47 @@
|
||||||
|
<?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 Integral extends BaseModel
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
* @author xaboy
|
||||||
|
* @day 2020-03-30
|
||||||
|
*/
|
||||||
|
public static function tablePk(): string
|
||||||
|
{
|
||||||
|
return 'integral_id';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
* @author xaboy
|
||||||
|
* @day 2020-03-30
|
||||||
|
*/
|
||||||
|
public static function tableName(): string
|
||||||
|
{
|
||||||
|
return 'integral';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function user()
|
||||||
|
{
|
||||||
|
return $this->hasOne(User::class, 'uid', 'uid');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -33,6 +33,7 @@ use app\common\repositories\system\attachment\AttachmentRepository;
|
||||||
use app\common\repositories\system\merchant\FinancialRecordRepository;
|
use app\common\repositories\system\merchant\FinancialRecordRepository;
|
||||||
use app\common\repositories\system\merchant\MerchantRepository;
|
use app\common\repositories\system\merchant\MerchantRepository;
|
||||||
use app\common\repositories\system\serve\ServeDumpRepository;
|
use app\common\repositories\system\serve\ServeDumpRepository;
|
||||||
|
use app\common\repositories\user\IntegralRepository;
|
||||||
use app\common\repositories\user\UserBillRepository;
|
use app\common\repositories\user\UserBillRepository;
|
||||||
use app\common\repositories\user\UserBrokerageRepository;
|
use app\common\repositories\user\UserBrokerageRepository;
|
||||||
use app\common\repositories\user\UserMerchantRepository;
|
use app\common\repositories\user\UserMerchantRepository;
|
||||||
|
|
@ -496,7 +497,7 @@ class StoreOrderRepository extends BaseRepository
|
||||||
*/
|
*/
|
||||||
public function getNewOrderId($type)
|
public function getNewOrderId($type)
|
||||||
{
|
{
|
||||||
list($msec, $sec) = explode(' ', microtime());
|
[$msec, $sec] = explode(' ', microtime());
|
||||||
$msectime = number_format((floatval($msec) + floatval($sec)) * 1000, 0, '', '');
|
$msectime = number_format((floatval($msec) + floatval($sec)) * 1000, 0, '', '');
|
||||||
$orderId = $type . $msectime . mt_rand(10000, max(intval($msec * 10000) + 10000, 98369));
|
$orderId = $type . $msectime . mt_rand(10000, max(intval($msec * 10000) + 10000, 98369));
|
||||||
return $orderId;
|
return $orderId;
|
||||||
|
|
@ -644,18 +645,33 @@ class StoreOrderRepository extends BaseRepository
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function giveIntegral($groupOrder)
|
public function giveIntegral($groupOrder){
|
||||||
{
|
// Log::info('赠送积分 - group-order' . var_export(is_array($groupOrder->user->toArray()) ? $groupOrder->user->toArray() : $groupOrder->user, true));
|
||||||
if ($groupOrder->give_integral > 0) {
|
// 修改:每个订单单独赠送积分并且实时到账,同时区分商户id
|
||||||
app()->make(UserBillRepository::class)->incBill($groupOrder->uid, 'integral', 'lock', [
|
foreach($groupOrder->orderList as $orderInfo){
|
||||||
'link_id' => $groupOrder['group_order_id'],
|
$giveIntegral = (float)sprintf("%.2f",$orderInfo->give_integral);
|
||||||
'status' => 0,
|
if ($giveIntegral > 0) {
|
||||||
'title' => '下单赠送积分',
|
// 总积分到账
|
||||||
'number' => $groupOrder->give_integral,
|
app()->make(UserRepository::class)->incIntegral((int)$orderInfo->uid,$giveIntegral,'订单赠送积分','lock',[
|
||||||
'mark' => '成功消费' . floatval($groupOrder['pay_price']) . '元,赠送积分' . floatval($groupOrder->give_integral),
|
'number' => $giveIntegral,
|
||||||
'balance' => $groupOrder->user->integral
|
'mark' => '成功消费' . (float)sprintf("%.2f",$orderInfo->pay_price) . '元,赠送积分' . $giveIntegral
|
||||||
]);
|
]);
|
||||||
|
// 商户积分变更
|
||||||
|
app()->make(IntegralRepository::class)->changeIntegral((int)$orderInfo->uid,(int)$orderInfo->mer_id,$giveIntegral);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# 2023-11-7 弃用,由指定时间到账修改为实时到账,并且区分每个商户的积分
|
||||||
|
// if ($groupOrder->give_integral > 0) {
|
||||||
|
// app()->make(UserBillRepository::class)->incBill($groupOrder->uid, 'integral', 'lock', [
|
||||||
|
// 'link_id' => $groupOrder['group_order_id'],
|
||||||
|
// 'status' => 0,
|
||||||
|
// 'title' => '下单赠送积分',
|
||||||
|
// 'number' => $groupOrder->give_integral,
|
||||||
|
// 'mark' => '成功消费' . floatval($groupOrder['pay_price']) . '元,赠送积分' . floatval($groupOrder->give_integral),
|
||||||
|
// 'balance' => $groupOrder->user->integral
|
||||||
|
// ]);
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,61 @@
|
||||||
|
<?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\IntegralDao;
|
||||||
|
use app\common\repositories\BaseRepository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Common: ...
|
||||||
|
* Author: wu-hui
|
||||||
|
* Time: 2023/11/07 10:34
|
||||||
|
* Class IntegralRepository
|
||||||
|
* @package app\common\repositories\user
|
||||||
|
*/
|
||||||
|
class IntegralRepository extends BaseRepository
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var IntegralDao
|
||||||
|
*/
|
||||||
|
protected $dao;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* IntegralRepository constructor.
|
||||||
|
* @param IntegralDao $dao
|
||||||
|
*/
|
||||||
|
public function __construct(IntegralDao $dao)
|
||||||
|
{
|
||||||
|
$this->dao = $dao;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Common: 积分变更
|
||||||
|
* Author: wu-hui
|
||||||
|
* Time: 2023/11/07 10:45
|
||||||
|
* @param int $uid
|
||||||
|
* @param int $mer_id
|
||||||
|
* @param float $changeNumber
|
||||||
|
*/
|
||||||
|
public function changeIntegral(int $uid, int $mer_id, float $changeNumber){
|
||||||
|
$info = $this->dao->findOrCreate([
|
||||||
|
'uid' => $uid,
|
||||||
|
'mer_id' => $mer_id
|
||||||
|
]);
|
||||||
|
$info->number = (float)sprintf("%.2f",$info->number + $changeNumber);
|
||||||
|
$info->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1287,9 +1287,9 @@ class UserRepository extends BaseRepository
|
||||||
'link_id' => 0,
|
'link_id' => 0,
|
||||||
'status' => 1,
|
'status' => 1,
|
||||||
'title' => $title,
|
'title' => $title,
|
||||||
'number' => $data['number'],
|
'number' => $data['number'] ?? $number,
|
||||||
'mark' => $data['mark'],
|
'mark' => $data['mark'],
|
||||||
'balance' =>$data['balance'],
|
'balance' =>$data['balance'] ?? $user->integral,
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@ class AutoClearIntegralListen extends TimerService implements ListenerInterface
|
||||||
$this->tick(1000 * 60 * 20, function () {
|
$this->tick(1000 * 60 * 20, function () {
|
||||||
request()->clearCache();
|
request()->clearCache();
|
||||||
if (!systemConfig('integral_status')) return;
|
if (!systemConfig('integral_status')) return;
|
||||||
|
if ((int)systemConfig('integral_clear_time') <= 0) return;// 过期时间未设置或者为0 则永不过期
|
||||||
$make = app()->make(IntegralRepository::class);
|
$make = app()->make(IntegralRepository::class);
|
||||||
$end = $make->getTimeoutDay();
|
$end = $make->getTimeoutDay();
|
||||||
if ($end == strtotime(date('Y-m-d') . ' 00:00:00')) {
|
if ($end == strtotime(date('Y-m-d') . ' 00:00:00')) {
|
||||||
|
|
@ -52,7 +53,8 @@ class AutoClearIntegralListen extends TimerService implements ListenerInterface
|
||||||
usleep(100);
|
usleep(100);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else if ($end < strtotime('+15 day')) {
|
}
|
||||||
|
else if ($end < strtotime('+15 day')) {
|
||||||
$make1 = app()->make(UserBillRepository::class);
|
$make1 = app()->make(UserBillRepository::class);
|
||||||
$invalidDay = $make->getInvalidDay();
|
$invalidDay = $make->getInvalidDay();
|
||||||
$cache = Cache::store('file');
|
$cache = Cache::store('file');
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue