where('is_del', 0)->when(isset($where['status']) && $where['status'] !== '', function ($query) use ($where) { $query->where('status', $where['status']); })->when(isset($where['keyword']) && $where['keyword'] !== '', function ($query) use ($where) { $query->whereLike('nickname', "%{$where['keyword']}%"); })->when(isset($where['mer_id']) && $where['mer_id'] !== '', function ($query) use ($where) { $query->where('mer_id', $where['mer_id']); })->when(isset($where['customer']) && $where['customer'] !== '', function ($query) use ($where) { $query->where('customer', $where['customer']); })->when(isset($where['is_verify']) && $where['is_verify'] !== '', function ($query) use ($where) { $query->where('is_verify', $where['is_verify']); })->when(isset($where['uid']) && $where['uid'] !== '', function ($query) use ($where) { $query->where('uid', $where['uid']); })->order('sort DESC,create_time DESC'); } public function getService($uid, $merId = null) { return StoreService::getDB()->where('uid', $uid)->when($merId, function ($query, $merId) { $query->where('mer_id', $merId); })->where('is_del', 0)->find(); } /** * @param int $merId * @param int $id * @return bool * @author zfy * @day 2020-05-13 */ public function merExists(int $merId, int $id) { return StoreService::getDB()->where($this->getPk(), $id)->where('mer_id', $merId)->where('is_del', 0)->count($this->getPk()) > 0; } /** * @param $merId * @param $uid * @param int|null $except * @return bool * @author zfy * @day 2020/5/29 */ public function issetService($merId, $uid, ?int $except = null) { return StoreService::getDB()->where('uid', $uid)->when($except, function ($query, $except) { $query->where($this->getPk(), '<>', $except); })->where('mer_id', $merId)->where('is_del', 0)->count($this->getPk()) > 0; } /** * @param $uid * @param int|null $except * @return bool * @author zfy * @day 2020/5/29 */ public function isBindService($uid, ?int $except = null) { return StoreService::getDB()->where('uid', $uid)->when($except, function ($query, $except) { $query->where($this->getPk(), '<>', $except); })->where('is_del', 0)->count($this->getPk()) > 0; } /** * @param int $id * @return int * @throws DbException * @author zfy * @day 2020/5/29 */ public function delete(int $id) { return StoreService::getDB()->where($this->getPk(), $id)->update(['is_del' => 1]); } /** * @param $merId * @return array|Model|null * @throws DbException * @throws DataNotFoundException * @throws ModelNotFoundException * @author zfy * @day 2020/5/29 */ public function getChatService($merId) { return StoreService::getDB()->where('mer_id', $merId)->where('is_del', 0)->where('status', 1)->order('status DESC, sort DESC, create_time ASC') ->hidden(['is_del'])->find(); } public function getRandService($merId) { $services = StoreService::getDB()->where('mer_id', $merId)->where('is_del', 0)->where('status', 1)->order('status DESC, sort DESC, create_time ASC') ->hidden(['is_del'])->select(); if (!$services || !count($services)) return null; if (count($services) === 1) $services[0]; return $services[max(random_int(0, count($services) - 1), 0)]; } /** * @param $id * @return array|Model|null * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException * @author zfy * @day 2020/5/29 */ public function getValidServiceInfo($id) { return StoreService::getDB()->where('service_id', $id)->where('status', 1)->where('is_del', 0)->hidden(['is_del'])->find(); } /** * @param $merId * @return array * @author zfy * @day 2020/7/1 */ public function getNoticeServiceInfo($merId) { return StoreService::getDB()->where('mer_id', $merId)->where('status', 1)->where('notify', 1) ->where('is_del', 0)->column('uid,phone,nickname'); } }