|
|
@@ -389,7 +389,7 @@ class UserBillRepository extends BaseRepository
|
|
389
|
389
|
* @param string $mark
|
|
390
|
390
|
* @return UserBillEntity
|
|
391
|
391
|
*/
|
|
392
|
|
- public function addUserBill(int $uid, int $typeShop, int $orderId, int $commissionType, float $number, string $mark): UserBillEntity
|
|
|
392
|
+ public function addUserBill(int $uid, int $commissionType, int $pm, float $number, string $category, string $type, string $source, int $orderType, int $typeShop = 0, int $orderId = 0, string $mark = '', string $title = ''): UserBillEntity
|
|
393
|
393
|
{
|
|
394
|
394
|
|
|
395
|
395
|
$orderSn = '';
|
|
|
@@ -410,10 +410,11 @@ class UserBillRepository extends BaseRepository
|
|
410
|
410
|
$userBillEntity = UserBillEntity::newInstance();
|
|
411
|
411
|
$userBillEntity->setUid($uid)
|
|
412
|
412
|
->setLinkId($orderId)
|
|
413
|
|
- ->setPm(UserBillEnum::PM['INCOME']['code'])
|
|
414
|
|
- ->setTitle(ArrayUtil::getEnumNameByCode($commissionType, UserBillEnum::COMMISSION_TYPE))
|
|
415
|
|
- ->setCategory('now_money')
|
|
416
|
|
- ->setType('commission')
|
|
|
413
|
+ //UserBillEnum::PM['INCOME']['code']
|
|
|
414
|
+ ->setPm($pm)
|
|
|
415
|
+ ->setTitle($title ?: ArrayUtil::getEnumNameByCode($commissionType, UserBillEnum::COMMISSION_TYPE))
|
|
|
416
|
+ ->setCategory($category)
|
|
|
417
|
+ ->setType($type)
|
|
417
|
418
|
->setNumber($number)
|
|
418
|
419
|
->setMark($mark)
|
|
419
|
420
|
->setStatus(UserBillEnum::STATUS['PENDING']['code'])
|
|
|
@@ -421,8 +422,9 @@ class UserBillRepository extends BaseRepository
|
|
421
|
422
|
->setOrderSn($orderSn)
|
|
422
|
423
|
->setTypeShop($typeShop)
|
|
423
|
424
|
->setMerId($merId)
|
|
424
|
|
- ->setSource(UserBillEnum::SOURCE['ONLINE']['code'])
|
|
425
|
|
- ->setOrderType(UserBillEnum::ORDER_TYPE['SELF_OPERATED']['code'])
|
|
|
425
|
+ // UserBillEnum::SOURCE['ONLINE']['code']
|
|
|
426
|
+ ->setSource($source)
|
|
|
427
|
+ ->setOrderType($orderType)
|
|
426
|
428
|
->setIsRedBrokerage(UserBillEnum::IS_RED_BROKERAGE['NORMAL']['code'])
|
|
427
|
429
|
->setGzc(UserBillEnum::GZC_STATUS['NOT_ENTERED']['code'])
|
|
428
|
430
|
->setIsGzc(UserBillEnum::IS_GZC['NOT_STARTED']['code']);
|
|
|
@@ -479,4 +481,48 @@ class UserBillRepository extends BaseRepository
|
|
479
|
481
|
{
|
|
480
|
482
|
return $this->dao->getUserBillEntityListByOrderIdListAndPending($typeShop, $orderIdList);
|
|
481
|
483
|
}
|
|
|
484
|
+
|
|
|
485
|
+ /**
|
|
|
486
|
+ * 将 Vr 记录设置为生效状态 并对用户的 Vr 字段进行增减
|
|
|
487
|
+ * @param int $id
|
|
|
488
|
+ * @return UserBillEntity
|
|
|
489
|
+ */
|
|
|
490
|
+ public function execute(int $id): UserBillEntity
|
|
|
491
|
+ {
|
|
|
492
|
+ $UserBillEntity = $this->getUserBillEntityByBillId($id);
|
|
|
493
|
+ if (empty($UserBillEntity->getBillId()) || empty($UserBillEntity->getUid())) {
|
|
|
494
|
+ throw new ValidateException('无效的账单记录');
|
|
|
495
|
+ }
|
|
|
496
|
+ if (!empty($UserBillEntity->getTakeTime())) {
|
|
|
497
|
+ throw new ValidateException('该账单记录已更新,请勿重复操作');
|
|
|
498
|
+ }
|
|
|
499
|
+
|
|
|
500
|
+ /** @var UserRepository $userRepository */
|
|
|
501
|
+ $userRepository = app()->make(UserRepository::class);
|
|
|
502
|
+ $userEntity = $userRepository->getUserEntityByUid($UserBillEntity->getUid());
|
|
|
503
|
+ if (empty($userEntity->getUid())) {
|
|
|
504
|
+ throw new ValidateException('未查询到用户信息');
|
|
|
505
|
+ }
|
|
|
506
|
+ if ($UserBillEntity->getType() == UserBill::TYPE['Consume']['code']) {
|
|
|
507
|
+ $surplus = bcsub($userEntity->getVr(), $UserBillEntity->getNumber(), 2);
|
|
|
508
|
+ if ($surplus < 0.00) {
|
|
|
509
|
+ throw new ValidateException('用户VR不足');
|
|
|
510
|
+ }
|
|
|
511
|
+ } else {
|
|
|
512
|
+ $surplus = bcadd($userEntity->getVr(), $UserBillEntity->getNumber(), 2);
|
|
|
513
|
+ }
|
|
|
514
|
+ try {
|
|
|
515
|
+ $UserBillEntity
|
|
|
516
|
+ ->setSurplus($surplus)
|
|
|
517
|
+ ->setSettlementTime(date('Y-m-d H:i:s'));
|
|
|
518
|
+ $userRepository->update($userEntity->getUid(), ['vr' => $surplus]);
|
|
|
519
|
+ $this->dao->update($UserBillEntity->getId(), [
|
|
|
520
|
+ 'surplus' => $UserBillEntity->getSurplus(),
|
|
|
521
|
+ 'settlement_time' => $UserBillEntity->getSettlementTime()
|
|
|
522
|
+ ]);
|
|
|
523
|
+ } catch (DbException $e) {
|
|
|
524
|
+
|
|
|
525
|
+ }
|
|
|
526
|
+ return $UserBillEntity;
|
|
|
527
|
+ }
|
|
482
|
528
|
}
|