UserSignScoreDao.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. Log::info('$dataRes - getUserSignScoreEntityListByIdList');
  37. Log::info($dataRes);
  38. if (!empty($dataRes)) {
  39. $entityList = array_map(function ($data) {
  40. return UserSignScoreEntity::newInstance($data);
  41. }, $dataRes);
  42. }
  43. } catch (\Exception $e) {
  44. }
  45. return $entityList;
  46. }
  47. /**
  48. * @param string $orderType
  49. * @param array $orderIdList
  50. * @return UserSignScoreEntity[]
  51. */
  52. public function getUserSignScoreEntityListByOrderIdListAndPending(string $orderType, array $orderIdList): array
  53. {
  54. $entityList = [];
  55. try {
  56. $dataList = UserSignScore::getDB()
  57. ->where('order_type', '=', $orderType)
  58. ->whereIn('order_id', $orderIdList)
  59. ->where('status', '=', UserSignScoreEnum::STATUS['Pending']['code'])
  60. ->select()
  61. ->toArray();
  62. if (!empty($dataList)) {
  63. $entityList = array_map(function ($data) {
  64. return UserSignScoreEntity::newInstance($data);
  65. }, $dataList);
  66. }
  67. } catch (DataNotFoundException|ModelNotFoundException|DbException $e) {
  68. }
  69. return $entityList;
  70. }
  71. /**
  72. * 批量更新
  73. * @param $dataList
  74. * @return array
  75. */
  76. public function saveAll($dataList): array
  77. {
  78. try {
  79. return $this->getModel()->saveAll($dataList)->toArray();
  80. } catch (\Exception $e) {
  81. return [];
  82. }
  83. }
  84. }