| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- <?php
- namespace App\Repositories;
- use App\Events\AppCreatedEvent;
- use App\Events\AppDeletedEvent;
- use App\Events\AppUpdatedEvent;
- use App\Models\Mysql\AppModel;
- use KZ2\Laravel\Repositories\Eloquent\Repository;
- class AppRepository extends Repository
- {
- public function model()
- {
- return AppModel::class;
- }
- /**
- * 查询数据返回UID
- * @param string $key
- * @param array $uids
- * @return array
- */
- public function findArray(string $key, array $uids)
- {
- return AppModel::query()->whereIn($key, $uids)->pluck($key)->toArray();
- }
- /**
- * 批量删除
- * @param string $key
- * @param array $uids
- * @return bool
- */
- public function delectUids(string $key, array $uids)
- {
- return AppModel::query()->whereIn($key, $uids)->delete();
- }
- /**
- * 创建一个.
- * @param $item
- * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model
- */
- public function createOne($item)
- {
- $obj = AppModel::query()->create($item);
- // 事件触发.
- event(new AppCreatedEvent($obj->uid));
- return $obj;
- }
- public function updateOne($item, $uid)
- {
- $saveResult = false;
- $obj = AppModel::query()->where(['uid' => $uid])->first();
- if ($obj->count()) {
- event(new AppUpdatedEvent($uid));
- }
- return $saveResult;
- }
- /**
- * 删除一个.
- * @param $uid
- * @return bool|mixed|null
- * @throws \Exception
- */
- public function deleteOne($uid)
- {
- $opResult = false;
- $obj = AppModel::query()->where(['uid' => $uid])->first();
- if ($obj->count()) {
- $opResult = $obj->delete();
- $eventParams = [
- 'uid' => $obj->uid,
- 'icon_url' => $obj->icon_url,
- ];
- event(new AppDeletedEvent($eventParams));
- }
- return $opResult;
- }
- /**
- * 查询应用列表(uid为key)
- * @return \Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection
- */
- public function findListKeyBy()
- {
- return AppModel::query()->get()->keyBy('uid');
- }
- public function getAgentApp($appUid = [])
- {
- return AppModel::query()->whereIn('uid', $appUid)->where('status', 1)->get(['uid', 'name']);
- }
- }
|