123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408 |
- <?php
- /**
- * OaMpLogichp UTF-8
- * 公众号关联小程序逻辑
- *
- * @date : 2018/9/11 17:20
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : chenbingling <cbl@huosdk.com>
- * @version : HuoMP 1.0
- */
- namespace huomp\logic\game;
- use huolib\constant\CommonConst;
- use huolib\constant\MpConfConst;
- use huomp\model\common\CommonModel;
- use huomp\model\weixin\MpConfModel;
- use huomp\model\weixin\OaMpModel;
- use think\db\exception\DataNotFoundException;
- use think\db\exception\ModelNotFoundException;
- use think\exception\DbException;
- class OaMpLogic extends CommonModel {
- /**
- * 公众号列表条件
- *
- * @param array $param
- *
- * @return array
- */
- protected function getWxWhere($param = []) {
- $_map = [];
- if (!empty($param['start_time']) && !empty($param['start_time'])) {
- $_map['create_time'] = ['between', [strtotime($param['start_time']),
- CommonConst::CONST_DAY_SECONDS + strtotime($param['end_time'])]];
- } else if (!empty($param['start_time'])) {
- $_map['create_time'] = ['gt', strtotime($param['start_time'])];
- } else if (!empty($param['end_time'])) {
- $_map['create_time'] = ['lt', CommonConst::CONST_DAY_SECONDS + strtotime($param['end_time'])];
- }
- if (!empty($param['mobile'])) {
- $_map['mobile'] = $param['mobile'];
- }
- if (!empty($param['master'])) {
- $_map['master'] = $param['master'];
- }
- if (!empty($param['company'])) {
- $_map['company'] = $param['company'];
- }
- if (!empty($param['mp_id'])) {
- $_map['mp_id'] = $param['mp_id'];
- }
- if (!empty($param['wx_id'])) {
- $_map['mp_id'] = $param['wx_id'];
- }
- if (!empty($param['mch_id'])) {
- $_map['mp_id'] = $param['mch_id'];
- }
- if (!empty($param['email'])) {
- $_map['email'] = $param['email'];
- }
- if (!empty($param['wx_email'])) {
- $_map['email'] = $param['wx_email'];
- }
- if (!empty($param['type'])) {
- $_map['type'] = $param['type'];
- }
- if (!empty($param['wx_name'])) {
- $_map['wx_name'] = $param['wx_name'];
- }
- if (!empty($param['wx_account'])) {
- $_map['wx_account'] = $param['wx_account'];
- }
- $_map['is_delete'] = CommonConst::CONST_NOT_DELETE;
- $_map['delete_time'] = 0;
- return $_map;
- }
- /**
- * 公众号列表字段
- *
- * @param int $type
- *
- * @return array
- */
- protected function getWxBaseField($type = MpConfConst::MP_CONF_TYPE_7) {
- $_field = [];
- switch ($type) {
- case MpConfConst::MP_CONF_TYPE_3: /* 3 移动应用 */
- break;
- case MpConfConst::MP_CONF_TYPE_5: /* 5 网站应用 */
- break;
- case MpConfConst::MP_CONF_TYPE_6: /* 6 小程序 */
- $_field = [
- 'wx_name' => 'wx_name',
- 'mp_id' => 'wx_id',
- 'wx_logo' => 'wx_logo',
- 'qr_code' => 'qr_code',
- ];
- break;
- case MpConfConst::MP_CONF_TYPE_8: /* 8 支付 */
- $_field = [
- 'mp_id' => 'mch_id',
- 'wx_name' => 'mch_name',
- 'ext_info' => 'ext_info',
- ];
- break;
- case MpConfConst::MP_CONF_TYPE_9: /* 9 开发平台 */
- $_field = [
- 'wx_name' => 'wx_name',
- 'mp_id' => 'wx_id',
- 'email' => 'wx_email'
- ];
- break;
- case MpConfConst::MP_CONF_TYPE_10: /* 10 第三方平台 */
- break;
- case MpConfConst::MP_CONF_TYPE_7: /* 7 公众号 */
- default:
- $_field = [
- 'wx_name' => 'wx_name',
- 'mp_id' => 'wx_id',
- 'wx_logo' => 'wx_logo',
- 'wx_account' => 'wx_account',
- 'qr_code' => 'qr_code',
- 'email' => 'wx_email'
- ];
- }
- $_field['id'] = 'id';
- $_field['app_id'] = 'app_id';
- $_field['master'] = 'linkman';
- $_field['mobile'] = 'mobile';
- $_field['create_time'] = 'create_time';
- $_field['update_time'] = 'update_time';
- $_field['parent_id'] = 'parent_id';
- return $_field;
- }
- /* 获取公众号列表 */
- public function getWxList($param, $page = '1,10', $order = '-create_time') {
- $_rdata = ['count' => 0, 'list' => []];
- $_map = $this->getWxWhere($param);
- $_wx_model = new MpConfModel();
- $_count = $_wx_model->where($_map)->count('id');
- if (empty($_count)) {
- return $_rdata;
- }
- $_field = $this->getWxBaseField($param['type']);
- $_order = $_wx_model->orderFilter($order);
- try {
- $_list = $_wx_model->with('ext,game')
- ->where($_map)
- ->field($_field)
- ->page($page)
- ->order($_order)
- ->select();
- } catch (DataNotFoundException $e) {
- return $_rdata;
- } catch (ModelNotFoundException $e) {
- return $_rdata;
- } catch (DbException $e) {
- return $_rdata;
- }
- if (is_object($_list)) {
- $_list = $_list->toArray();
- }
- if (empty($_list)) {
- return $_rdata;
- }
- switch ($param['type']) {
- case MpConfConst::MP_CONF_TYPE_3: /* 3 移动应用 */
- break;
- case MpConfConst::MP_CONF_TYPE_5: /* 5 网站应用 */
- break;
- case MpConfConst::MP_CONF_TYPE_6: /* 6 小程序 */
- foreach ($_list as $_k => $_v) {
- if (empty($_v['game']) || $_v['game']['is_delete'] == CommonConst::CONST_DELETED) {
- unset($_list[$_k]);
- }
- }
- break;
- case MpConfConst::MP_CONF_TYPE_8: /* 8 支付 */
- //获取关联的公众号
- foreach ($_list as $_k => $_v) {
- $_wx_data = (new OaMchLogic())->getWxByMchId($_v['mch_id']);
- $_list[$_k] = array_merge($_list[$_k], $_wx_data);
- /* 判断证书是否上传 */
- $_list[$_k]['ext_info']['sslcert_exist'] = file_exists($_v['ext_info']['sslcert_path']) ? '已上传'
- : '未上传';
- $_list[$_k]['ext_info']['sslkey_exist'] = file_exists($_v['ext_info']['sslkey_path']) ? '已上传'
- : '未上传';
- }
- break;
- case MpConfConst::MP_CONF_TYPE_9: /* 9 开发平台 */
- break;
- case MpConfConst::MP_CONF_TYPE_10: /* 10 第三方平台 */
- break;
- case MpConfConst::MP_CONF_TYPE_7: /* 7 公众号 */
- default:
- foreach ($_list as $_k => $_v) {
- $_list[$_k]['game_sum'] = (new OaMpModel())->getSumGame($_v['wx_id']);
- }
- }
- $_rdata['count'] = $_count;
- $_rdata['list'] = $_list;
- return $_rdata;
- }
- /**
- * 获取公众号关联游戏列表
- *
- * @param $wx_id
- * @param string $page
- * @param string $order
- *
- * @return array
- */
- public function getGames($wx_id, $page = '1,10', $order = '-id') {
- $_rdata = ['count' => 0, 'list' => []];
- $_map = ['oa_id' => $wx_id];
- $_model = new OaMpModel();
- $_count = $_model->where($_map)->count('id');
- if (empty($_count)) {
- return $_rdata;
- }
- $_order = $_model->orderFilter($order);
- try {
- $_datas = $_model->with('game,gmini')
- ->where($_map)
- ->page($page)
- ->order($_order)
- ->select();
- } catch (DataNotFoundException $e) {
- return $_rdata;
- } catch (ModelNotFoundException $e) {
- return $_rdata;
- } catch (DbException $e) {
- return $_rdata;
- }
- if (is_object($_datas)) {
- $_datas = $_datas->toArray();
- }
- if (empty($_datas)) {
- return $_rdata;
- }
- $_list = [];
- foreach ($_datas as $_k => $_v) {
- $_data = [];
- $_data['id'] = $_v['id'];
- $_data['app_id'] = $_v['app_id'];
- $_data['game'] = empty($_v['game']) ? '' : $_v['game']['name'];
- $_data['status'] = empty($_v['game']) ? '' : $_v['game']['status_label'];
- $_data['classify'] = empty($_v['game']) ? '' : $_v['game']['classify_label'];
- $_data['icon'] = empty($_v['game']) ? '' : $_v['game']['icon'];
- $_data['mini_app_id'] = empty($_v['gmini']) ? '' : $_v['gmini']['mini_app_id'];
- $_list[] = $_data;
- }
- $_rdata['count'] = $_count;
- $_rdata['list'] = $_list;
- return $_rdata;
- }
- /**
- * 游戏关联公众号条件
- *
- * @param array $param
- *
- * @return array
- */
- public function getGwWhere($param = []) {
- $_map = ['app_id' => $param['app_id']];
- $_where = $this->getWxWhere($param);
- $_where['type'] = MpConfConst::MP_CONF_TYPE_7; //只能是公众号
- if (!empty($param['wx_email']) || !empty($param['wx_name']) || !empty($param['linkman'])
- || !empty($param['mobile'])) {
- $_wxids = (new MpConfModel())->where($_where)->column('mp_id');
- $_map['oa_id'] = ['in', $_wxids];
- }
- return $_map;
- }
- /**
- * 获取游戏关联公众号列表
- *
- * @param $param
- * @param string $page
- * @param string $order
- *
- * @return array
- */
- public function getGameWxs($param, $page = '1,10', $order = '-id') {
- $_rdata = ['count' => 0, 'list' => []];
- $_map = $this->getGwWhere($param);
- $_model = new OaMpModel();
- $_count = $_model->where($_map)->count('id');
- if (empty($_count)) {
- return $_rdata;
- }
- $_order = $_model->orderFilter($order);
- try {
- $_datas = $_model->with('mc')
- ->where($_map)
- ->page($page)
- ->order($_order)
- ->select();
- } catch (DataNotFoundException $e) {
- return $_rdata;
- } catch (ModelNotFoundException $e) {
- return $_rdata;
- } catch (DbException $e) {
- return $_rdata;
- }
- if (is_object($_datas)) {
- $_datas = $_datas->toArray();
- }
- if (empty($_datas)) {
- return $_rdata;
- }
- $_list = [];
- foreach ($_datas as $_k => $_v) {
- $_data = [];
- $_data['id'] = $_v['id'];
- $_data['wx_id'] = empty($_v['mc']) ? '' : $_v['mc']['mp_id'];
- $_data['wx_name'] = empty($_v['mc']) ? '' : $_v['mc']['wx_name'];
- $_data['wx_logo'] = empty($_v['mc']) ? '' : $_v['mc']['wx_logo'];
- $_data['wx_account'] = empty($_v['mc']) ? '' : $_v['mc']['wx_account'];
- $_data['qr_code'] = empty($_v['mc']) ? '' : $_v['mc']['qr_code'];
- $_data['wx_email'] = empty($_v['mc']) ? '' : $_v['mc']['email'];
- $_data['linkman'] = empty($_v['mc']) ? '' : $_v['mc']['master'];
- $_data['mobile'] = empty($_v['mc']) ? '' : $_v['mc']['mobile'];
- $_data['is_default'] = $_v['is_default'];
- $_data['is_default_label'] = MpConfConst::MP_OA_MCH_DEFAULT_2 == $_v['is_default'] ? '默认' : '非默认';
- $_list[] = $_data;
- }
- $_rdata['count'] = $_count;
- $_rdata['list'] = $_list;
- return $_rdata;
- }
- /**
- * 获取公众号绑定的游戏id数组
- *
- * @param $oa_id
- *
- * @return array
- */
- public function getAppIdsByOaId($oa_id) {
- return (new OaMpModel())->where(['oa_id' => $oa_id])->column('app_id');
- }
- /**
- * 获取游戏绑定的公众号id数组
- *
- * @param $app_id
- *
- * @return array
- */
- public function getOaIdsByAppId($app_id) {
- return (new OaMpModel())->where(['app_id' => $app_id])->column('oa_id');
- }
- /**
- *设置默认
- *
- * @param $id
- * @param int $is_default
- *
- * @return bool
- */
- public function setDefault($id, $is_default = MpConfConst::MP_OA_MCH_DEFAULT_2) {
- $_model = new OaMpModel();
- $_data = $_model->getInfoById($id);
- $_map = ['app_id' => $_data['app_id']];
- /* 先将全部设置为非默认 */
- $_model->update(['is_default' => MpConfConst::MP_OA_MCH_DEFAULT_1], $_map);
- $_map = ['id' => $id];
- $_data = ['is_default' => $is_default];
- $_rs = $_model->update($_data, $_map);
- if (false == $_rs) {
- return false;
- }
- return true;
- }
- /**
- * 获取小程序默认公众号APPID
- *
- * @param $app_id
- *
- * @return mixed
- */
- public function getDefaultOaId($app_id) {
- $_map = ['app_id' => $app_id, 'is_default' => MpConfConst::MP_OA_MCH_DEFAULT_2];
- $_oa_id = (new OaMpModel())->where($_map)->value('oa_id');
- if (empty($_oa_id)) {
- return '';
- }
- return $_oa_id;
- }
- }
|