| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?php
- namespace app\common\repositories\user;
- use app\common\dao\user\UserPvLogDao;
- use app\common\enum\user\UserPvLogEnum;
- use app\common\repositories\BaseRepository;
- use app\common\repositories\store\order\StoreOrderRepository;
- use app\entity\data\user\UserPvLogEntity;
- use think\exception\ValidateException;
- class UserPvLogRepository extends BaseRepository
- {
- public function __construct(UserPvLogDao $dao)
- {
- $this->dao = $dao;
- }
- public function create($data)
- {
- return $this->dao->create($data);
- }
- /**
- * 写入 PV记录
- * @param UserPvLogEntity $userPvLogEntity
- * @return UserPvLogEntity
- */
- public function createByEntity(UserPvLogEntity $userPvLogEntity): UserPvLogEntity
- {
- $result = $this->dao->create($userPvLogEntity->toUnderlineArray())->toArray();
- /** @var UserPvLogEntity $entity */
- $entity = UserPvLogEntity::newInstance($result);
- return $entity;
- }
- /**
- * 添加Pv 记录
- * @param int $uid
- * @param float $pv
- * @param string $mark
- * @param string $orderType
- * @param string $orderId
- * @return UserPvLogEntity
- */
- public function addUserPvLog(int $uid, float $pv, string $mark = '', string $orderType = '', string $orderId = ''): UserPvLogEntity
- {
- if (!empty($orderType)) {
- if (!empty($orderId)) {
- if ($orderType == UserPvLogEnum::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 UserPvLogEntity $userPvLogEntity */
- $userPvLogEntity = UserPvLogEntity::newInstance();
- $userPvLogEntity->setUid($uid)
- ->setPv($pv)
- ->setMark($mark)
- ->setOrderType($orderType)
- ->setOrderId($orderId)
- ->setAddtime(time())
- ->setStatus(UserPvLogEnum::STATUS['PendingConfirmation']['code']);
- return $this->createByEntity($userPvLogEntity);
- }
- }
|