* @version : HuoMp 1.0 */ namespace huomp\model\weixin; use huo\model\game\GameModel; use huomp\model\common\CommonModel; use huomp\model\game\GameMiniModel; class OaMpModel extends CommonModel { protected $table = 'mp_oa_mp'; /** * 关联game表 * * @return mixed */ public function game() { return $this->hasone(GameModel::className(), 'id', 'app_id')->field( 'id,name,classify as classify_label,status as status_label,icon' ); } /** * 关联game表 * * @return mixed */ public function gmini() { return $this->hasone(GameMiniModel::className(), 'app_id', 'app_id')->field('app_id,mini_app_id'); } /** * 关联账号表 * * @return mixed */ public function mc() { return $this->hasone(MpConfModel::className(), 'mp_id', 'oa_id'); } /** * 添加数据 * * @param $data * * @return bool */ public function addData($data) { if (empty($data)) { return false; } $_data = $data; $_obj = self::create($_data, true); if ($_obj) { return $_obj->id; } return false; } /** * 获取微信关联的游戏个数 * * @param $oa_id * * @return float|int */ public function getSumGame($oa_id) { $_map = ['oa_id' => $oa_id]; return self::where($_map)->count(); } /** * 删除记录 * * @param $id * * @return int */ public function deleteData($id) { $_map = ['id' => $id]; return self::where($_map)->delete(); } /** * 删除记录 * * @param $app_id * * @return int */ public function deleteDataByAppId($app_id) { $_map = ['app_id' => $app_id]; return self::where($_map)->delete(); } /** * 通过应用ID获取公众号ID * * @param int $app_id 小程序应用ID * * @return string */ public function getOaByApp($app_id) { $_map['app_id'] = $app_id; $_map['is_default'] = 2; $_oa_id = $this->where($_map)->value('oa_id'); if (empty($_oa_id)) { return ''; } return $_oa_id; } }