UserSignVrDao.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace app\common\dao\user;
  3. use app\common\dao\BaseDao;
  4. use app\common\model\BaseModel;
  5. use app\common\model\user\UserSignVr;
  6. use app\entity\CommonEntity;
  7. use app\entity\data\user\UserSignVrEntity;
  8. class UserSignVrDao extends BaseDao
  9. {
  10. /**
  11. * @return BaseModel
  12. */
  13. protected function getModel(): string
  14. {
  15. return UserSignVr::class;
  16. }
  17. /**
  18. * @param array $idList
  19. * @return CommonEntity[]
  20. */
  21. public function getUserSignVrEntityListByIdList(array $idList): array
  22. {
  23. $entityList = [];
  24. try {
  25. /** @var UserSignVr $model */
  26. $model = $this->getModel();
  27. $dataRes = $model::getDB()
  28. ->whereIn('id', $idList)
  29. ->select()
  30. ->toArray();
  31. if (!empty($dataRes)) {
  32. $entityList = array_map(function ($data) {
  33. return UserSignVrEntity::newInstance($data);
  34. }, $dataRes);
  35. }
  36. } catch (\Exception $e) {
  37. }
  38. return $entityList;
  39. }
  40. /**
  41. * 批量更新
  42. * @param $dataList
  43. * @return array
  44. */
  45. public function saveAll($dataList): array
  46. {
  47. try {
  48. return $this->getModel()::getInstance()->allowField(array_keys(reset($dataList)))->saveAll($dataList)->toArray();
  49. } catch (\Exception $e) {
  50. return [];
  51. }
  52. }
  53. /**
  54. * 根据订单id和type类型查找vr
  55. */
  56. public function getVrFromTypeOrderId($orderId)
  57. {
  58. try {
  59. return $this::getModel()::getDB()->where('order_id', '=', $orderId)->where('type','=',2)->value('number');
  60. } catch (\Exception $e){
  61. return [];
  62. }
  63. }
  64. /**
  65. * 根据order_id获取vr值(用于备份用户变更记录)
  66. */
  67. public function getVrForBackupFromOrderId($orderId)
  68. {
  69. try {
  70. $value = $this::getModel()::getDB()
  71. ->where('order_id', '=', $orderId)
  72. ->where('type', '=', 2)
  73. ->value('number');
  74. return $value ?: 0;
  75. } catch (\Exception $e) {
  76. return 0;
  77. }
  78. }
  79. }