SdkPluginConfLogic.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <?php
  2. /**
  3. * SdkPluginConfLogic.php UTF-8
  4. *
  5. * @date : 2018/5/31 15:34
  6. *
  7. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  8. * @author : chenbingling <cbl@huosdk.com>
  9. * @version : HUOSDK 8.0
  10. */
  11. namespace huo\logic\app;
  12. use huo\controller\app\SdkPluginCache;
  13. use huo\model\app\SdkPluginConfModel;
  14. use huo\model\app\SpcCodeModel;
  15. use huo\model\common\CommonModel;
  16. use huolib\constant\CommonConst;
  17. use huolib\status\GameStatus;
  18. class SdkPluginConfLogic extends CommonModel {
  19. protected $_bas_file
  20. = [
  21. 'id',
  22. 'client_id',
  23. 'code',
  24. 'url',
  25. 'version',
  26. 'is_default',
  27. 'create_time',
  28. 'update_time',
  29. ];
  30. /***
  31. * 查询条件
  32. *
  33. * @param $param
  34. *
  35. * @return array
  36. */
  37. protected function getWhere($param = []) {
  38. $_map = [];
  39. if (isset($param['code']) && !empty($param['code'])) {
  40. $_map['sdk_plugin_conf_model.code'] = $param['code'];
  41. }
  42. if (isset($param['client_id']) && !empty($param['client_id'])) {
  43. $_map['sdk_plugin_conf_model.client_id'] = $param['client_id'];
  44. }
  45. if (isset($param['version']) && !empty($param['version'])) {
  46. $_map['version'] = ['like', $param['version'].'%'];
  47. }
  48. if (!empty($param['start_time']) && !empty($param['start_time'])) {
  49. $_map['sdk_plugin_conf_model.create_time'] = ['between', [strtotime($param['start_time']),
  50. CommonConst::CONST_DAY_SECONDS + strtotime(
  51. $param['end_time']
  52. )]];
  53. } else if (!empty($param['start_time'])) {
  54. $_map['sdk_plugin_conf_model.create_time'] = ['gt', strtotime($param['start_time'])];
  55. } else if (!empty($param['end_time'])) {
  56. $_map['sdk_plugin_conf_model.create_time'] = ['lt', CommonConst::CONST_DAY_SECONDS + strtotime(
  57. $param['end_time']
  58. )];
  59. }
  60. return $_map;
  61. }
  62. /***
  63. * 获取所有插件列表
  64. *
  65. * @param array $where
  66. * @param string $page
  67. * @param array $field
  68. *
  69. * @return int
  70. * @throws \think\db\exception\DataNotFoundException
  71. * @throws \think\db\exception\ModelNotFoundException
  72. * @throws \think\exception\DbException
  73. */
  74. public function getPluginList($where = [], $page = '1,10', $field = []) {
  75. $_field = array_merge($this->_bas_file, $field);
  76. $_map = $this->getWhere($where);
  77. $_sdk_model = new SdkPluginConfModel();
  78. $_cnt = $_sdk_model->with('spc')->where($_map)->count('sdk_plugin_conf_model.id');
  79. if (empty($_cnt)) {
  80. return GameStatus::SERVER_CNT_ZERO;
  81. }
  82. $_data = $_sdk_model->with('spc')
  83. ->where($_map)
  84. ->page($page)
  85. ->order('id desc')
  86. ->select();
  87. if (is_object($_data)) {
  88. $_data = $_data->toArray();
  89. }
  90. $_list = [];
  91. foreach ($_data as $_value) {
  92. foreach ($_field as $_v) {
  93. $_temp[$_v] = $_value[$_v];
  94. }
  95. $_temp['name'] = $_value['spc']['name'];
  96. $_list[] = $_temp;
  97. }
  98. $_rdata['count'] = $_cnt;
  99. $_rdata['list'] = $_list;
  100. return $_rdata;
  101. }
  102. /**
  103. * 获取SPCcode Name 键值对
  104. */
  105. public function getCodeNames() {
  106. $_spc = (new SpcCodeModel())->column('name', 'code');
  107. return $_spc;
  108. }
  109. /**
  110. * 添加插件
  111. *
  112. * @param $param
  113. *
  114. * @return false|int
  115. */
  116. public function addSdkPlugin($param) {
  117. $_res = (new SdkPluginConfModel())->allowField(true)->save($param);
  118. return $_res;
  119. }
  120. /**
  121. * 获得插件信息
  122. *
  123. * @param $id
  124. *
  125. * @param array $field
  126. *
  127. * @return array
  128. * @throws \think\Exception
  129. * @throws \think\db\exception\DataNotFoundException
  130. * @throws \think\db\exception\ModelNotFoundException
  131. * @throws \think\exception\DbException
  132. */
  133. public function getDetail($id, $field = []) {
  134. $_model = new SdkPluginConfModel();
  135. if (!empty($field)) {
  136. $_model->field($field);
  137. }
  138. $_data = $_model->where('id', $id)->find()->toArray();
  139. return $_data;
  140. }
  141. /***
  142. * 更新插件信息
  143. *
  144. * @param $id
  145. * @param $param
  146. *
  147. * @return bool
  148. */
  149. public function updateSdkPlugin($id, $param) {
  150. if (empty($id) || empty($param)) {
  151. return false;
  152. }
  153. $_map['id'] = $id;
  154. $_rs = SdkPluginCache::ins()->updateSdkPlugin($param, $_map);
  155. if (false == $_rs) {
  156. return false;
  157. }
  158. return true;
  159. }
  160. /**
  161. * 获取版本插件列表
  162. *
  163. * @param $client_id //客户端id
  164. *
  165. * @return array
  166. * @throws \think\Exception
  167. * @throws \think\db\exception\DataNotFoundException
  168. * @throws \think\db\exception\ModelNotFoundException
  169. * @throws \think\exception\DbException
  170. */
  171. public function getPluginByClientId($client_id) {
  172. $_model = new SdkPluginConfModel();
  173. $_rdata = [];
  174. $_spc = $this->getCodeNames();
  175. $_map = [];
  176. $_map['sdk_plugin_conf_model.client_id'] = ['in', [0, $client_id]];
  177. $_map['sdk_plugin_conf_model.is_default'] = CommonConst::CONST_NOT_DELETE;
  178. $_field = [
  179. 'sdk_plugin_conf_model.code' => 'code',
  180. 'spc.name' => 'plugin_name',
  181. 'sdk_plugin_conf_model.update_desc' => 'update_desc',
  182. 'sdk_plugin_conf_model.url' => 'url',
  183. 'sdk_plugin_conf_model.version' => 'version',
  184. 'sdk_plugin_conf_model.sign' => 'sign',
  185. 'sdk_plugin_conf_model.md5' => 'md5',
  186. 'sdk_plugin_conf_model.type' => 'type',
  187. 'sdk_plugin_conf_model.has_so' => 'has_so'
  188. ];
  189. $_count = 0;
  190. $_list = [];
  191. foreach ($_spc as $_k => $_v) {
  192. $_data = $_model->with('spc')
  193. ->where($_map)
  194. ->where('sdk_plugin_conf_model.code', $_k)
  195. ->field($_field)
  196. ->order('update_time desc')
  197. ->find();
  198. if (!empty($_data)) {
  199. $_data = $_data->toArray();
  200. $_temp = [];
  201. foreach ($_field as $_value) {
  202. $_temp[$_value] = $_data[$_value];
  203. }
  204. $_temp['url'] = 'http:'.$_temp['url'];
  205. $_list[] = $_temp;
  206. $_count++;
  207. }
  208. }
  209. $_rdata['count'] = $_count;
  210. $_rdata['list'] = $_list;
  211. return $_rdata;
  212. }
  213. }