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