123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284 |
- <?php
- namespace agent\common\controller;
- use huo\controller\agent\AgentCache;
- use huo\controller\common\HuoSession;
- use huo\controller\wap\Option;
- use huo\model\user\AdminLoginLogModel;
- use huo\model\user\AdminOperateLog;
- use huolib\constant\FormatConst;
- use huolib\constant\GameConst;
- use huolib\status\CommonStatus;
- use huolib\status\MemberStatus;
- use huolib\tool\Ip;
- use think\exception\HttpResponseException;
- use think\Response;
- class AgentBaseController extends BaseController {
- public $agent_id = 0;
- protected $response_type;
- protected $classify;
- function _initialize() {
- parent::_initialize();
- $this->agent_id = HuoSession::getAgentId();
- $this->response_type = $this->request->param('format/s', FormatConst::FORMAT_HTML);
- if (APP_DEBUG) {
- $_debug_agent_id = $this->request->param('debug_agent_id/d', 0);
- if (!empty($_debug_agent_id)) {
- $this->agent_id = $_debug_agent_id;
- HuoSession::setAgentId($this->agent_id);
- }
- }
- $this->classify = '';
- }
-
- public function checkLogin($agent_id = 0) {
- $_agent_id = $agent_id;
- if (empty($_agent_id)) {
- $_agent_id = $this->agent_id;
- if (empty($_agent_id)) {
- $_code = MemberStatus::LOGIN_IS_OUT;
- $this->error(lang(MemberStatus::getMsg($_code)), [], $_code);
- }
- }
- return $_agent_id;
- }
-
- protected function getResponseType() {
- $_is_ajax = $this->request->isAjax();
- $this->response_type = $_is_ajax ? config('default_ajax_return') : $this->response_type;
- return $this->response_type;
- }
-
- public function getAgentId() {
- return $this->agent_id;
- }
-
- protected function returnData($data = []) {
- $_msg = $data['msg'];
- $_code = $data['code'];
- $_data = $data['data'];
- if (CommonStatus::NO_ERROR != $_code) {
- $this->error($_msg, $_data, $_code);
- }
- $this->success($_msg, $_data, $_code);
- }
-
- protected function error($msg = '', $data = '', $code = 400, array $header = [], $url = null, $wait = 3) {
- $this->insertActionLog(1,$msg.'||'.json_encode($data));
- $type = $this->getResponseType();
- if (FormatConst::FORMAT_HTML == $type) {
- parent::error($msg, $data, $code, $header, $url, $wait);
- }
- if (empty($data)) {
- $data = null;
- }
- $result = [
- 'code' => $code,
- 'msg' => $msg,
- 'data' => $data,
- ];
- $response = Response::create($result, $type)->header($header);
- throw new HttpResponseException($response);
- }
-
- protected function insertActionLog($type = 0, $remark) {
- $_user_id = cmf_get_current_admin_id();
- if (empty($_user_id)) {
- $_user_id = 0;
- $_username = '';
- } else {
- $_agent_data = AgentCache::ins()->getInfoByAgentId($_user_id);
- $_username = $_agent_data['user_login'];
- }
- $_data['user_id'] = $_user_id;
- $_data['username'] = $_username;
- $_data['type'] = $type;
- $_data['ip'] = $this->request->ip(0, true);
- $_data['addr'] = Ip::getIpHome($_data['ip']);
- $_data['action'] = $this->request->url(true);
- $_data['create_time'] = time();
- $_data['param'] = $this->request->method().':'.http_build_query($this->request->param());
- $_data['remark'] = $remark;
- (new AdminOperateLog())->addLog($_data);
- }
-
- protected function insertLoginLog($type = 0) {
- $_user_id = cmf_get_current_admin_id();
- if (empty($_user_id)) {
- $_user_id = 0;
- $_username = '';
- } else {
- $_agent_data = AgentCache::ins()->getInfoByAgentId($_user_id);
- $_username = $_agent_data['user_login'];
- }
- $_data['user_id'] = $_user_id;
- $_data['username'] = $_username;
- $_data['type'] = $type;
- $_data['ip'] = $this->request->ip(0, true);
- $_data['addr'] = Ip::getIpHome($_data['ip']);
- $_data['device_info'] = $_SERVER["HTTP_USER_AGENT"];
- $_data['login_time'] = time();
- (new AdminLoginLogModel())->addLog($_data);
- }
-
- protected function success($msg = '', $data = '', $code = 200, array $header = [], $url = null, $wait = 3) {
- $this->insertActionLog(2,$msg.'||'.json_encode($data));
- $type = $this->getResponseType();
- if (FormatConst::FORMAT_HTML == $type) {
- parent::success($msg, $data, $code, $header, $url, $wait);
- }
- if (empty($data)) {
- $data = null;
- }
- $result = [
- 'code' => $code,
- 'msg' => $msg,
- 'data' => $data,
- ];
- $header['Access-Control-Allow-Origin'] = '*';
- $header['Access-Control-Allow-Headers'] = 'X-Requested-With,Content-Type,HS-Device-Type,HS-Token,HS-Lang';
- $header['Access-Control-Allow-Methods'] = 'GET,POST,PATCH,PUT,DELETE,OPTIONS';
- $response = Response::create($result, $type)->header($header);
- throw new HttpResponseException($response);
- }
-
- protected function getWebBasic() {
- $_m = new Option();
- $_setting_name = 'agent_basic';
- $_agent_basic_item = $_m->getOptionData($_setting_name);
- $_setting_name = 'agent_index_seo';
- $_agent_index_seo_item = $_m->getOptionData($_setting_name);
- $_setting_name = 'agent_icon';
- $_agent_icon_item = $_m->getOptionData($_setting_name);
- $_setting_name = 'agent_content';
- $_agent_content_item = $_m->getOptionData($_setting_name);
- $_agent_basic = $_agent_index_seo = $_agent_icon = $_agent_content = $_agent_qq = [];
- if (!empty($_agent_basic_item['option_value'])) {
- $_agent_basic = json_decode($_agent_basic_item['option_value'], true);
- }
- if (!empty($_agent_index_seo_item['option_value'])) {
- $_agent_index_seo = json_decode($_agent_index_seo_item['option_value'], true);
- }
- if (!empty($_agent_icon_item['option_value'])) {
- $_agent_icon = json_decode($_agent_icon_item['option_value'], true);
- if (isset($_agent_icon['agent_logo'])) {
- $_agent_icon['agent_logo'] = cmf_get_image_url($_agent_icon['agent_logo']);
- }
- }
- if (!empty($_agent_content_item['option_value'])) {
- $_agent_content = json_decode($_agent_content_item['option_value'], true);
- $_agent_qq = explode(',', $_agent_content['service_qq']);
- }
- $_data = [
- 'title' => isset($_agent_index_seo['title']) ? $_agent_index_seo['title'] : 'title',
- 'keyword' => isset($_agent_index_seo['keyword']) ? $_agent_index_seo['keyword'] : 'keyword',
- 'description' => isset($_agent_index_seo['description']) ? $_agent_index_seo['description']
- : 'description',
- 'company_name' => isset($_agent_basic['company_name']) ? $_agent_basic['company_name']
- : 'company_name',
- 'company_address' => isset($_agent_basic['company_address']) ? $_agent_basic['company_address']
- : 'company_address',
- 'culture_management' => isset($_agent_basic['culture_management']) ? $_agent_basic['culture_management']
- : 'culture_management',
- 'logo' => isset($_agent_icon['agent_logo']) ? $_agent_icon['agent_logo'] : 'logo',
- 'icp' => isset($_agent_basic['record_number']) ? $_agent_basic['record_number']
- : 'record_number',
- 'qq' => []
- ];
- if (!empty($_agent_qq)) {
- foreach ($_agent_qq as $_k => $_v) {
- $_num = $_k + 1;
- $_data['qq'][] = [
- 'name' => "客服".$_num,
- 'qq_num' => $_v,
- ];
- }
- }
- $this->assign('web_basic', $_data);
- return $_data;
- }
- }
|