|
|
@@ -3,8 +3,22 @@ declare(strict_types=1);
|
|
|
namespace SixShop\Points\Entity;
|
|
|
|
|
|
use SixShop\Core\Entity\BaseEntity;
|
|
|
+use SixShop\Points\Model\UserPointModel;
|
|
|
|
|
|
class UserPointEntity extends BaseEntity
|
|
|
{
|
|
|
-
|
|
|
+ public function add(int $userID, int $point): UserPointModel
|
|
|
+ {
|
|
|
+ $userPoint = $this->where('user_id', $userID)->findOrEmpty();
|
|
|
+ if ($userPoint->isEmpty()) {
|
|
|
+ $userPoint = $this->create([
|
|
|
+ 'user_id' => $userID,
|
|
|
+ 'point' => $point,
|
|
|
+ ]);
|
|
|
+ } else {
|
|
|
+ $userPoint->inc('point', $point)->save();
|
|
|
+ }
|
|
|
+ // tood log
|
|
|
+ return $userPoint;
|
|
|
+ }
|
|
|
}
|