|
|
|
|
|
|
|
|
namespace Lc\ShopBundle\Services ; |
|
|
namespace Lc\ShopBundle\Services ; |
|
|
|
|
|
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
|
|
|
|
use Lc\ShopBundle\Context\CreditHistoryInterface; |
|
|
use Lc\ShopBundle\Context\MerchantInterface; |
|
|
use Lc\ShopBundle\Context\MerchantInterface; |
|
|
use Lc\ShopBundle\Context\MerchantUtilsInterface; |
|
|
use Lc\ShopBundle\Context\MerchantUtilsInterface; |
|
|
use Lc\ShopBundle\Context\UserInterface; |
|
|
use Lc\ShopBundle\Context\UserInterface; |
|
|
|
|
|
|
|
|
{ |
|
|
{ |
|
|
$merchant = $this->getMerchant($merchant) ; |
|
|
$merchant = $this->getMerchant($merchant) ; |
|
|
$classUserMerchant = $this->em->getClassMetadata(UserMerchantInterface::class)->getName(); |
|
|
$classUserMerchant = $this->em->getClassMetadata(UserMerchantInterface::class)->getName(); |
|
|
|
|
|
|
|
|
$userMerchant = new $classUserMerchant ; |
|
|
$userMerchant = new $classUserMerchant ; |
|
|
$userMerchant->setUser($user) ; |
|
|
$userMerchant->setUser($user) ; |
|
|
$userMerchant->setMerchant($merchant) ; |
|
|
$userMerchant->setMerchant($merchant) ; |
|
|
$userMerchant->setCredit(0) ; |
|
|
$userMerchant->setCredit(0) ; |
|
|
$userMerchant->setCreditActive(true) ; |
|
|
$userMerchant->setCreditActive(true) ; |
|
|
|
|
|
|
|
|
|
|
|
$this->em->persist($userMerchant) ; |
|
|
|
|
|
$this->em->flush() ; |
|
|
|
|
|
|
|
|
|
|
|
return $userMerchant ; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function updateCreditActive($user, $merchant = null, $creditActive = true) |
|
|
|
|
|
{ |
|
|
|
|
|
$userMerchant = $this->getUserMerchant($user, $merchant) ; |
|
|
|
|
|
if(!$userMerchant) { |
|
|
|
|
|
$userMerchant = $this->createUserMerchant($user, $merchant) ; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$userMerchant->setCreditActive($creditActive) ; |
|
|
|
|
|
|
|
|
|
|
|
$this->em->persist($userMerchant) ; |
|
|
|
|
|
$this->em->flush() ; |
|
|
|
|
|
|
|
|
return $userMerchant ; |
|
|
return $userMerchant ; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function activeCredit($user, $merchant = null) |
|
|
|
|
|
{ |
|
|
|
|
|
return $this->updateCreditActive($user, $merchant, true) ; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function unactiveCredit($user, $merchant = null) |
|
|
|
|
|
{ |
|
|
|
|
|
return $this->updateCreditActive($user, $merchant, false) ; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public function createCreditHistory($user, $amount, $meanPayment, $comment = null, $merchant = null) |
|
|
public function createCreditHistory($user, $amount, $meanPayment, $comment = null, $merchant = null) |
|
|
{ |
|
|
{ |
|
|
$merchant = $this->getMerchant($merchant) ; |
|
|
|
|
|
|
|
|
$userMerchant = $this->getUserMerchant($user, $merchant) ; |
|
|
|
|
|
|
|
|
|
|
|
if($userMerchant && $userMerchant->isCreditActive()) { |
|
|
|
|
|
$classCreditHistory = $this->em->getClassMetadata(CreditHistoryInterface::class)->getName(); |
|
|
|
|
|
|
|
|
|
|
|
$creditHistory = new $classCreditHistory ; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return $creditHistory ; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function addCredit($user, $amount, $merchant = null) |
|
|
public function addCredit($user, $amount, $merchant = null) |