|
@@ -3,22 +3,43 @@ declare(strict_types=1);
|
|
|
namespace SixShop\Points\Entity;
|
|
namespace SixShop\Points\Entity;
|
|
|
|
|
|
|
|
use SixShop\Core\Entity\BaseEntity;
|
|
use SixShop\Core\Entity\BaseEntity;
|
|
|
-use SixShop\Points\Model\UserPointModel;
|
|
|
|
|
|
|
+use SixShop\Points\Enum\UserPointTypeEnum;
|
|
|
|
|
+use SixShop\Points\Model\UserPointLogModel;
|
|
|
|
|
|
|
|
class UserPointEntity extends BaseEntity
|
|
class UserPointEntity extends BaseEntity
|
|
|
{
|
|
{
|
|
|
- public function add(int $userID, int $point): UserPointModel
|
|
|
|
|
|
|
+ public function change(
|
|
|
|
|
+ int $userID,
|
|
|
|
|
+ int $point,
|
|
|
|
|
+ UserPointTypeEnum $type,
|
|
|
|
|
+ int $bizType,
|
|
|
|
|
+ int $bizID,
|
|
|
|
|
+ string $remark,
|
|
|
|
|
+ int $freezePoint = 0,
|
|
|
|
|
+ ): self
|
|
|
{
|
|
{
|
|
|
$userPoint = $this->where('user_id', $userID)->findOrEmpty();
|
|
$userPoint = $this->where('user_id', $userID)->findOrEmpty();
|
|
|
if ($userPoint->isEmpty()) {
|
|
if ($userPoint->isEmpty()) {
|
|
|
- $userPoint = $this->create([
|
|
|
|
|
|
|
+ $userPoint->save([
|
|
|
'user_id' => $userID,
|
|
'user_id' => $userID,
|
|
|
'point' => $point,
|
|
'point' => $point,
|
|
|
|
|
+ 'freeze_point' => $freezePoint,
|
|
|
]);
|
|
]);
|
|
|
} else {
|
|
} else {
|
|
|
- $userPoint->inc('point', $point)->save();
|
|
|
|
|
|
|
+ $userPoint->inc('point', $point)
|
|
|
|
|
+ ->inc('freeze_point', $freezePoint)->save();
|
|
|
}
|
|
}
|
|
|
- // tood log
|
|
|
|
|
|
|
+ UserPointLogModel::create( [
|
|
|
|
|
+ 'user_id' => $userID,
|
|
|
|
|
+ 'point' => $point,
|
|
|
|
|
+ 'type' => $type,
|
|
|
|
|
+ 'biz_type' => $bizType,
|
|
|
|
|
+ 'biz_id' => $bizID,
|
|
|
|
|
+ 'remark' => $remark,
|
|
|
|
|
+ 'freeze_point' => $freezePoint,
|
|
|
|
|
+ 'after_point' => $userPoint->point,
|
|
|
|
|
+ 'after_freeze_point' => $userPoint->freeze_point,
|
|
|
|
|
+ ]);
|
|
|
return $userPoint;
|
|
return $userPoint;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|