UserSignGongxianDao.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. namespace app\common\dao\user;
  3. use app\common\dao\BaseDao;
  4. use app\common\enum\user\UserSignGongxianEnum;
  5. use app\common\model\BaseModel;
  6. use app\common\model\user\UserSignGongxian;
  7. use app\entity\CommonEntity;
  8. use app\entity\data\user\UserSignGongxianEntity;
  9. use think\db\exception\DataNotFoundException;
  10. use think\db\exception\DbException;
  11. use think\db\exception\ModelNotFoundException;
  12. class UserSignGongxianDao extends BaseDao
  13. {
  14. /**
  15. * @return BaseModel
  16. */
  17. protected function getModel(): string
  18. {
  19. return UserSignGongxian::class;
  20. }
  21. /**
  22. * @param array $idList
  23. * @return CommonEntity[]
  24. */
  25. public function getUserSignGongxianEntityListByIdList(array $idList): array
  26. {
  27. $entityList = [];
  28. try {
  29. /** @var UserSignGongxian $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 UserSignGongxianEntity::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 UserSignGongxianEntity[]
  48. */
  49. public function getUserSignGongxianEntityListByOrderIdListAndPending(string $orderType, array $orderIdList): array
  50. {
  51. $entityList = [];
  52. try {
  53. $dataList = UserSignGongxian::getDB()
  54. ->where('order_type', '=', $orderType)
  55. ->whereIn('order_id', $orderIdList)
  56. ->where('status', '=', UserSignGongxianEnum::STATUS['PendingConfirmation']['code'])
  57. ->select()
  58. ->toArray();
  59. if (!empty($dataList)) {
  60. $entityList = array_map(function ($data) {
  61. return UserSignGongxianEntity::newInstance($data);
  62. }, $dataList);
  63. }
  64. } catch (DataNotFoundException|ModelNotFoundException|DbException $e) {
  65. }
  66. return $entityList;
  67. }
  68. /**
  69. * 批量更新
  70. * @param $dataList
  71. * @return array
  72. */
  73. public function saveAll($dataList): array
  74. {
  75. try {
  76. return $this->getModel()::getInstance()->allowField(array_keys(reset($dataList)))->saveAll($dataList)->toArray();
  77. } catch (\Exception $e) {
  78. return [];
  79. }
  80. }
  81. /**
  82. * 根据order_id与uid查找贡献值(status=1, type=1)
  83. */
  84. public function getGongxianFromUidOrderId($orderId, $uid)
  85. {
  86. try {
  87. return $this::getModel()::getDB()
  88. ->where('order_id', '=', $orderId)
  89. ->where('status', '=', 1)
  90. ->where('type', '=', 1)
  91. ->where('uid', '=', $uid)
  92. ->value('number');
  93. } catch (\Exception $e) {
  94. return [];
  95. }
  96. }
  97. }