* @version : HUOSDK 8.0 */ namespace huo\logic\app; use huo\controller\app\SdkPluginCache; use huo\model\app\SdkPluginConfModel; use huo\model\app\SpcCodeModel; use huo\model\common\CommonModel; use huolib\constant\CommonConst; use huolib\status\GameStatus; class SdkPluginConfLogic extends CommonModel { protected $_bas_file = [ 'id', 'client_id', 'code', 'url', 'version', 'is_default', 'create_time', 'update_time', ]; /*** * 查询条件 * * @param $param * * @return array */ protected function getWhere($param = []) { $_map = []; if (isset($param['code']) && !empty($param['code'])) { $_map['sdk_plugin_conf_model.code'] = $param['code']; } if (isset($param['client_id']) && !empty($param['client_id'])) { $_map['sdk_plugin_conf_model.client_id'] = $param['client_id']; } if (isset($param['version']) && !empty($param['version'])) { $_map['version'] = ['like', $param['version'].'%']; } if (!empty($param['start_time']) && !empty($param['start_time'])) { $_map['sdk_plugin_conf_model.create_time'] = ['between', [strtotime($param['start_time']), CommonConst::CONST_DAY_SECONDS + strtotime( $param['end_time'] )]]; } else if (!empty($param['start_time'])) { $_map['sdk_plugin_conf_model.create_time'] = ['gt', strtotime($param['start_time'])]; } else if (!empty($param['end_time'])) { $_map['sdk_plugin_conf_model.create_time'] = ['lt', CommonConst::CONST_DAY_SECONDS + strtotime( $param['end_time'] )]; } return $_map; } /*** * 获取所有插件列表 * * @param array $where * @param string $page * @param array $field * * @return int * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function getPluginList($where = [], $page = '1,10', $field = []) { $_field = array_merge($this->_bas_file, $field); $_map = $this->getWhere($where); $_sdk_model = new SdkPluginConfModel(); $_cnt = $_sdk_model->with('spc')->where($_map)->count('sdk_plugin_conf_model.id'); if (empty($_cnt)) { return GameStatus::SERVER_CNT_ZERO; } $_data = $_sdk_model->with('spc') ->where($_map) ->page($page) ->order('id desc') ->select(); if (is_object($_data)) { $_data = $_data->toArray(); } $_list = []; foreach ($_data as $_value) { foreach ($_field as $_v) { $_temp[$_v] = $_value[$_v]; } $_temp['name'] = $_value['spc']['name']; $_list[] = $_temp; } $_rdata['count'] = $_cnt; $_rdata['list'] = $_list; return $_rdata; } /** * 获取SPCcode Name 键值对 */ public function getCodeNames() { $_spc = (new SpcCodeModel())->column('name', 'code'); return $_spc; } /** * 添加插件 * * @param $param * * @return false|int */ public function addSdkPlugin($param) { $_res = (new SdkPluginConfModel())->allowField(true)->save($param); return $_res; } /** * 获得插件信息 * * @param $id * * @param array $field * * @return array * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function getDetail($id, $field = []) { $_model = new SdkPluginConfModel(); if (!empty($field)) { $_model->field($field); } $_data = $_model->where('id', $id)->find()->toArray(); return $_data; } /*** * 更新插件信息 * * @param $id * @param $param * * @return bool */ public function updateSdkPlugin($id, $param) { if (empty($id) || empty($param)) { return false; } $_map['id'] = $id; $_rs = SdkPluginCache::ins()->updateSdkPlugin($param, $_map); if (false == $_rs) { return false; } return true; } /** * 获取版本插件列表 * * @param $client_id //客户端id * * @return array * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function getPluginByClientId($client_id) { $_model = new SdkPluginConfModel(); $_rdata = []; $_spc = $this->getCodeNames(); $_map = []; $_map['sdk_plugin_conf_model.client_id'] = ['in', [0, $client_id]]; $_map['sdk_plugin_conf_model.is_default'] = CommonConst::CONST_NOT_DELETE; $_field = [ 'sdk_plugin_conf_model.code' => 'code', 'spc.name' => 'plugin_name', 'sdk_plugin_conf_model.update_desc' => 'update_desc', 'sdk_plugin_conf_model.url' => 'url', 'sdk_plugin_conf_model.version' => 'version', 'sdk_plugin_conf_model.sign' => 'sign', 'sdk_plugin_conf_model.md5' => 'md5', 'sdk_plugin_conf_model.type' => 'type', 'sdk_plugin_conf_model.has_so' => 'has_so' ]; $_count = 0; $_list = []; foreach ($_spc as $_k => $_v) { $_data = $_model->with('spc') ->where($_map) ->where('sdk_plugin_conf_model.code', $_k) ->field($_field) ->order('update_time desc') ->find(); if (!empty($_data)) { $_data = $_data->toArray(); $_temp = []; foreach ($_field as $_value) { $_temp[$_value] = $_data[$_value]; } $_temp['url'] = 'http:'.$_temp['url']; $_list[] = $_temp; $_count++; } } $_rdata['count'] = $_count; $_rdata['list'] = $_list; return $_rdata; } }