UserSignFugouDao.php 2.5 KB

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