1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- <?php
- namespace App\Dao\Account;
- use App\Models\Account\OfficialAccount;
- class AccountDao
- {
- /**
- * 查询小程序列表
- *
- * @param array $where
- * @param int $limit
- * @return array
- */
- public function getMiniApps(array $where = [], int $limit = 0): array
- {
- $fields = ['id', 'name', 'app_id', 'app_secret', 'access_token', 'access_token_expires_at',
- 'client_token', 'client_token_expires_at', 'is_enabled', 'is_sandbox'];
- $query = OfficialAccount::select($fields)->where('is_enabled', 1);
- // 查询sandbox应用
- if (isset($where['is_sandbox']) && in_array($where['is_sandbox'], [0, 1])) {
- $query->where('is_sandbox', $where['is_sandbox']);
- }
- // limit查询长度
- if ($limit) {
- $query->limit($limit);
- }
- $result = $query->get();
- return $result ? $result->toArray() : [];
- }
- /**
- * 获取小程序信息
- *
- * @param $appId
- * @return array
- */
- public function getMiniAppByAppId($appId): array
- {
- if (empty($appId)) {
- return [];
- }
- $result = OfficialAccount::where('app_id', $appId)->first();
- return $result ? $result->toArray() : [];
- }
- /**
- * @param $where
- * @param $data
- * @return false
- */
- public function updateMiniApp($where, $data): bool
- {
- if (empty($where) || empty($data)) {
- return false;
- }
- return OfficialAccount::where($where)->update($data);
- }
- }
|