UserWithdrawalLimitRecordDao.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace app\common\dao\user;
  3. use app\common\dao\BaseDao;
  4. use app\common\enum\user\UserWithdrawalLimitRecordEnum;
  5. use app\common\model\BaseModel;
  6. use app\common\model\user\UserWithdrawalLimitRecord;
  7. use app\entity\data\user\UserWithdrawalLimitRecordEntity;
  8. use think\db\exception\DataNotFoundException;
  9. use think\db\exception\DbException;
  10. use think\db\exception\ModelNotFoundException;
  11. class UserWithdrawalLimitRecordDao extends BaseDao
  12. {
  13. /**
  14. * @return BaseModel
  15. */
  16. protected function getModel(): string
  17. {
  18. return UserWithdrawalLimitRecord::class;
  19. }
  20. /**
  21. * @param array $idList
  22. * @return UserWithdrawalLimitRecordEntity[]
  23. */
  24. public function getUserWithdrawalLimitRecordEntityListByIdList(array $idList): array
  25. {
  26. $entityList = [];
  27. try {
  28. /** @var UserWithdrawalLimitRecord $model */
  29. $model = $this->getModel();
  30. $dataRes = $model::getDB()
  31. ->whereIn('id', $idList)
  32. ->select()
  33. ->toArray();
  34. if (!empty($dataRes)) {
  35. $entityList = array_map(function ($data) {
  36. return UserWithdrawalLimitRecordEntity::newInstance($data);
  37. }, $dataRes);
  38. }
  39. } catch (\Exception $e) {
  40. }
  41. return $entityList;
  42. }
  43. /**
  44. * 批量更新
  45. * @param $dataList
  46. * @return array
  47. */
  48. public function saveAll($dataList): array
  49. {
  50. try {
  51. return $this->getModel()::getInstance()->allowField(array_keys(reset($dataList)))->saveAll($dataList)->toArray();
  52. } catch (\Exception $e) {
  53. return [];
  54. }
  55. }
  56. /**
  57. * @param string $typeShop
  58. * @param array $orderSnList
  59. * @return UserWithdrawalLimitRecordEntity[]
  60. */
  61. public function getUserWithdrawalLimitRecordEntityListByOrderSnListAndPending(string $typeShop, array $orderSnList): array
  62. {
  63. $entityList = [];
  64. try {
  65. /** @var UserWithdrawalLimitRecord $model */
  66. $model = $this->getModel();
  67. $dataList = $model::getDB()
  68. ->where('type_shop', '=', $typeShop)
  69. ->whereIn('order_sn', $orderSnList)
  70. ->where('status', '=', UserWithdrawalLimitRecordEnum::STATUS['PENDING']['code'])
  71. ->select()
  72. ->toArray();
  73. if (!empty($dataList)) {
  74. $entityList = array_map(function ($data) {
  75. return UserWithdrawalLimitRecordEntity::newInstance($data);
  76. }, $dataList);
  77. }
  78. } catch (DataNotFoundException|ModelNotFoundException|DbException $e) {
  79. }
  80. return $entityList;
  81. }
  82. }