123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- <?php
- /**
- * OaMpModel.php UTF-8
- *
- *
- * @date : 2018/9/14 20:31
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : wuyonghong <wyh@huosdk.com>
- * @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;
- }
- }
|