MerchantContributionDao.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace app\common\dao\system\merchant;
  3. use app\common\dao\BaseDao;
  4. use app\common\model\system\merchant\MerchantContribution;
  5. use app\entity\CommonEntity;
  6. use app\entity\data\merchant\MerchantContributionEntity;
  7. class MerchantContributionDao extends BaseDao
  8. {
  9. protected function getModel(): string
  10. {
  11. return MerchantContribution::class;
  12. }
  13. /**
  14. * 根据商家的让利比例 获取对应的 配置信息
  15. * @param float $profitSharing
  16. * @return CommonEntity
  17. */
  18. public function getMerchantContributionEntityByProfitSharing(float $profitSharing): CommonEntity
  19. {
  20. $data = [];
  21. try {
  22. /** @var MerchantContribution $model */
  23. $model = $this->getModel();
  24. $dataRes = $model::getDB()->select()->toArray();
  25. if (!empty($dataRes)) {
  26. foreach ($dataRes as $item) {
  27. if ($item['start'] <= $profitSharing && $item['end'] >= $profitSharing) {
  28. $data = $item;
  29. break;
  30. }
  31. }
  32. }
  33. } catch (\Exception $e) {
  34. }
  35. // 类型转换
  36. if (!empty($data)) $data['create_time'] = strtotime($data['create_time']);
  37. return MerchantContributionEntity::newInstance($data);
  38. }
  39. }