UserSignScoreDao.php 2.5 KB

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