AccountDao.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace App\Dao\Account;
  3. use App\Models\Account\OfficialAccount;
  4. class AccountDao
  5. {
  6. /**
  7. * 查询小程序列表
  8. *
  9. * @param array $where
  10. * @param int $limit
  11. * @return array
  12. */
  13. public function getMiniApps(array $where = [], int $limit = 0): array
  14. {
  15. $fields = ['id', 'name', 'app_id', 'app_secret', 'access_token', 'access_token_expires_at',
  16. 'client_token', 'client_token_expires_at', 'is_enabled', 'is_sandbox'];
  17. $query = OfficialAccount::select($fields)->where('is_enabled', 1);
  18. // 查询sandbox应用
  19. if (isset($where['is_sandbox']) && in_array($where['is_sandbox'], [0, 1])) {
  20. $query->where('is_sandbox', $where['is_sandbox']);
  21. }
  22. // limit查询长度
  23. if ($limit) {
  24. $query->limit($limit);
  25. }
  26. $result = $query->get();
  27. return $result ? $result->toArray() : [];
  28. }
  29. /**
  30. * 获取小程序信息
  31. *
  32. * @param $appId
  33. * @return array
  34. */
  35. public function getMiniAppByAppId($appId): array
  36. {
  37. if (empty($appId)) {
  38. return [];
  39. }
  40. $result = OfficialAccount::where('app_id', $appId)->first();
  41. return $result ? $result->toArray() : [];
  42. }
  43. /**
  44. * @param $where
  45. * @param $data
  46. * @return false
  47. */
  48. public function updateMiniApp($where, $data): bool
  49. {
  50. if (empty($where) || empty($data)) {
  51. return false;
  52. }
  53. return OfficialAccount::where($where)->update($data);
  54. }
  55. }