param('applet_id'); } } return self::$applet_id; } /** * 定义全局的查询范围 * @param Query $query * @return bool */ public function scopeApplet_id(Query $query) { if (!$this->isGlobalScopeAppletId) return false; $applet_id = self::getAppletId(); $applet_id > 0 && $query->where($query->getTable() . '.applet_id', $applet_id); return true; } /** * 查找单条记录 * @param $data * @param array $with * @return array|static|null */ public static function get($data, $with = []) { try { $query = (new static)->with($with); return is_array($data) ? $query->where($data)->find() : $query->find((int)$data); } catch (\Exception $e) { return false; } } /** * 获取当前调用来源的应用名称 * 例如:admin, api, store, task * @return string|bool */ protected static function getCalledModule() { if (preg_match('/app\\\(\w+)/', get_called_class(), $class)) { return $class[1]; } return 'common'; } /** * 返回错误信息 * @return string */ public function getError() { return empty($this->error) ? false : $this->error; } }