| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
- namespace app\common\repositories\user;
- use app\common\dao\user\UserSignHongbaoDao;
- use app\common\enum\user\UserSignHongbaoEnum;
- use app\common\repositories\BaseRepository;
- use app\common\repositories\store\order\StoreOrderRepository;
- use app\entity\data\user\UserSignHongbaoEntity;
- use think\exception\ValidateException;
- class UserSignHongbaoRepository extends BaseRepository
- {
- public function __construct(UserSignHongbaoDao $dao)
- {
- $this->dao = $dao;
- }
- public function create($data)
- {
- return $this->dao->create($data);
- }
- /**
- * 写入红包记录
- * @param UserSignHongbaoEntity $userSignHongbaoEntity
- * @return UserSignHongbaoEntity
- */
- public function createByEntity(UserSignHongbaoEntity $userSignHongbaoEntity): UserSignHongbaoEntity
- {
- $result = $this->dao->create($userSignHongbaoEntity->toUnderlineArray())->toArray();
- /** @var UserSignHongbaoEntity $entity */
- $entity = UserSignHongbaoEntity::newInstance($result);
- return $entity;
- }
- /**
- * 添加红包记录
- * @param int $uid
- * @param int $type
- * @param float $number
- * @param string $mark
- * @param string $orderType
- * @param string $orderId
- * @return UserSignHongbaoEntity
- */
- public function addUserSingHongbao(int $uid, int $type, float $number, string $mark = '', string $orderType = '', string $orderId = ''): UserSignHongbaoEntity
- {
- if (!empty($orderType)) {
- if (!empty($orderId)) {
- if ($orderType == UserSignHongbaoEnum::ORDER_TYPE['Platform']['code']) {
- /** @var StoreOrderRepository $storeOrderRepository */
- $storeOrderRepository = app()->make(StoreOrderRepository::class);
- $storeOrderEntity = $storeOrderRepository->getStoreOrderEntityByOrderId((int)$orderId);
- if (empty($storeOrderEntity->getOrderId())) {
- throw new ValidateException('未查询到订单信息');
- }
- }
- }
- }
- /** @var UserSignHongbaoEntity $userSignHongbaoEntity */
- $userSignHongbaoEntity = UserSignHongbaoEntity::newInstance();
- $userSignHongbaoEntity->setUid($uid)
- ->setType($type)
- ->setNumber($number)
- ->setMark($mark)
- ->setOrderType($orderType)
- ->setOrderId($orderId)
- ->setAddtime(time())
- ->setStatus(UserSignHongbaoEnum::STATUS['PendingConfirmation']['code']);
- return $this->createByEntity($userSignHongbaoEntity);
- }
- }
|