1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803 |
- <?php
- /**
- * 易优CMS
- * ============================================================================
- * 版权所有 2016-2028 海口快推科技有限公司,并保留所有权利。
- * 网站地址: http://www.eyoucms.com
- * ----------------------------------------------------------------------------
- * 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
- * ============================================================================
- * Author: 小虎哥 <1105415366@qq.com>
- * Date: 2018-4-3
- */
-
- namespace app\api\controller;
-
- use think\Db;
-
- class Ajax extends Base
- {
- /*
- * 初始化操作
- */
- public function _initialize()
- {
- parent::_initialize();
- }
-
- public function multistation()
- {
- $token = input('param.token/s');
- $auth_code = msubstr($token, 6, 32);
- $request_time = msubstr($token, 38, 10);
- $querystr = msubstr($token, 48, strlen($token));
- $querystr = mchStrCode($querystr, 'DECODE', $auth_code);
- $verify_content = preg_replace('/^(.*)-#eyou#([\w\-]+)#cms#-(.*)$/i', '${2}', $querystr);
- $file = ROOT_PATH . "EY_{$verify_content}.txt";
- $_ajax = input('param._ajax/d');
- if (file_exists($file)) {
- $fp = fopen($file, 'r');
- $file_content = fread($fp, filesize($file));
- fclose($fp);
- if (!empty($file_content) && $file_content == $verify_content) {
- $arr = explode("-#eyou#{$verify_content}#cms#-", $querystr);
- $user_name = empty($arr[0]) ? '' : mchStrCode($arr[0], 'DECODE', $auth_code);
- $password = empty($arr[1]) ? '' : mchStrCode($arr[1], 'DECODE', $auth_code);
- $admin_info = Db::name('admin')->where(['user_name'=>$user_name])->find();
- if (empty($admin_info)) {
- $this->error('登录失败(账号/密码错误)');
- }
- $password = func_encrypt($password, true, pwd_encry_type($admin_info['password']));
- if ($password != $admin_info['password']) {
- $this->error('登录失败(账号/密码错误)');
- } else if (empty($admin_info['status'])) {
- $this->error('登录失败(账号已禁用)');
- }
-
- $opt = input('param.opt/s');
- if ('push_archives' == $opt) { // 群发文档
- $this->multistation_push_archives('add');
- } else if ('edit_archives' == $opt) { // 编辑文档
- $this->multistation_push_archives('edit');
- } else if ('del_archives' == $opt) { // 删除文档
- $this->multistation_del_archives();
- } else { // 登录
- $third_type = '';
- $thirdata = login_third_type();
- if ('EyouGzhLogin' == $thirdata['type']) {
- $openid = Db::name('admin_wxlogin')->where(['admin_id'=>$admin_info['admin_id'], 'type'=>1])->value('openid');
- if (!empty($openid)) {
- $third_type = 'EyouGzhLogin';
- }
- } else if ('WechatLogin' == $thirdata['type']) {
- $openid = Db::name('admin_wxlogin')->where(['admin_id'=>$admin_info['admin_id'], 'type'=>2])->value('openid');
- if (!empty($openid)) {
- $third_type = 'WechatLogin';
- }
- }
- $admin_info = adminLoginAfter($admin_info['admin_id'], $this->session_id, $third_type);
- adminLog('后台登录(站群快捷管理)');
- session('isset_author', null); // 内置勿动
-
- $web_adminbasefile = tpCache('global.web_adminbasefile');
- $web_adminbasefile = !empty($web_adminbasefile) ? $web_adminbasefile : $this->root_dir.'/login.php';
- if (stristr($web_adminbasefile, 'index.php')) {
- $baseFile = explode('/', request()->baseFile());
- $web_adminbasefile = end($baseFile);
- $web_adminbasefile = $this->root_dir.'/'.$web_adminbasefile;
- }
- // $this->redirect($web_adminbasefile);
- $this->success('正在登录', $web_adminbasefile);
- }
- } else {
- if (empty($_ajax)) {
- $this->error('验证文件失败,请重新按照教程操作');
- }
- }
- }
-
- if (!empty($_ajax)) {
- $data = [
- 'code' => 0,
- 'msg' => '验证文件失败,请重新按照教程操作',
- ];
- respose($data);
- } else {
- to_index("404");
- }
- }
-
- private function multistation_push_archives($opt = 'add')
- {
- $data = [
- 'push_code' => 0,
- 'push_msg' => '发布失败',
- ];
- $post = input('post.');
- $archivesInfo = empty($post['archives']) ? '' : json_decode(base64_decode($post['archives']), true);
- // @file_put_contents(ROOT_PATH . "/log.txt", date("Y-m-d H:i:s") . " " . var_export($archivesInfo, true) . "\r\n", FILE_APPEND);
-
- if (!empty($archivesInfo['litpic']) && !empty($archivesInfo['is_syn_local'])) {
- $ret_litpic = saveRemote($archivesInfo['litpic'],'allimg');
- $ret_litpic = json_decode($ret_litpic,true);
- $archivesInfo['litpic'] = empty($ret_litpic['url']) ? $archivesInfo['litpic'] : $ret_litpic['url'];
- }
- $archivesInfo['update_time'] = getTime();
-
- // $litpic_base64 = empty($post['litpic_base64']) ? '' : $post['litpic_base64'];
- $arctypeInfo = Db::name('arctype')->where(['id'=>intval($archivesInfo['typeid'])])->find();
- if (empty($arctypeInfo)) {
- $data['push_msg'] = '网站栏目不存在';
- }
- $channeltypeInfo = Db::name('channeltype')->where(['id'=>$archivesInfo['channel']])->find();
- $arctypeInfo['typeurl'] = typeurl("home/{$channeltypeInfo['ctl_name']}/lists", $arctypeInfo, true, true);
- if ('add' == $opt) {
- $archivesInfo['add_time'] = getTime();
- $r = $aid = Db::name('archives')->insertGetId($archivesInfo);
- } else {
- $aid = $archivesInfo['aid'];
- $r = Db::name('archives')->where(['aid' => $aid])->update($archivesInfo);
- }
- if ($r !== false) {
- //内容远程图片本地化
- if (!empty($archivesInfo['is_syn_local'])) {
- $archivesInfo = $this->content_remote_to_local($archivesInfo);
- }
-
- $ctl_name = $channeltypeInfo['ctl_name'];
- $class = "\\app\\admin\\model\\{$ctl_name}";
- $model = new $class;
- try {
- $archivesInfo['aid'] = $aid;
- $archivesInfo['arcurl'] = arcurl("home/{$channeltypeInfo['ctl_name']}/view", array_merge($arctypeInfo, $archivesInfo), true, true);
- if (!empty($archivesInfo['articlePayInfo'])) {
- $archivesInfo['articlePayInfo']['aid'] = $aid;
- if ('add' == $opt) {
- Db::name('article_pay')->insert($archivesInfo['articlePayInfo']);
- } else {
- $is_in = Db::name('article_pay')->where('aid',$aid)->find();
- if (empty($is_in)){
- Db::name('article_pay')->insert($archivesInfo['articlePayInfo']);
- }else{
- $archivesInfo['articlePayInfo']['update_time'] = getTime();
- Db::name('article_pay')->where('aid',$aid)->update($archivesInfo['articlePayInfo']);
- }
- }
- }
- $model->afterSave($aid, $archivesInfo, $opt);
- // 清除前台缓存
- clearHtmlCache([$aid], [$arctypeInfo['id']]);
- // 添加查询执行语句到mysql缓存表
- model('SqlCacheTable')->InsertSqlCacheTable();
- if ('add' == $opt) {
- $push_msg = '发布成功';
- adminLog('群发新增文档:'.$archivesInfo['title']);
- } else {
- $push_msg = '编辑成功';
- adminLog('群发编辑文档:'.$archivesInfo['title']);
- }
- $globalConfig = tpCache('global');
- $data = [
- 'push_code' => 1,
- 'push_msg' => $push_msg,
- 'arctypeInfo' => [
- 'typeurl' => $arctypeInfo['typeurl'],
- 'typename' => $arctypeInfo['typename'],
- ],
- 'archivesInfo' => [
- 'aid' => $archivesInfo['aid'],
- 'arcurl' => $archivesInfo['arcurl'],
- ],
- 'globalConfig' => [
- 'seo_pseudo' => $globalConfig['seo_pseudo'],
- ],
- ];
- } catch (\Exception $e) {
- Db::name('archives')->where(['aid'=>$aid])->delete();
- $model->afterDel([$aid]);
- $data['push_msg'] = $e->getMessage();
- }
- }
- respose($data);
- }
-
- //内容远程图片本地化
- private function content_remote_to_local($archivesInfo = []){
- foreach (['content','content_ey_m','free_content'] as $k => $v){
- $first = 'addonFieldExt';
- if ('free_content' == $v){
- $first = 'articlePayInfo';
- }
- $archivesInfo[$first][$v] = htmlspecialchars_decode($archivesInfo[$first][$v]);
- $archivesInfo[$first][$v] = remote_to_local($archivesInfo[$first][$v]);
- $archivesInfo[$first][$v] = htmlspecialchars($archivesInfo[$first][$v]);
- }
- return $archivesInfo;
- }
-
- private function multistation_del_archives()
- {
- $data = [
- 'push_code' => 0,
- 'push_msg' => '删除失败',
- ];
- $post = input('post.');
- $aid = empty($post['aid']) ? 0 : $post['aid'];
- if (!empty($aid)) {
- try {
- $archivesInfo = Db::name('archives')->where(['aid'=>$aid])->find();
- $channeltypeInfo = Db::name('channeltype')->where(['id'=>$archivesInfo['channel']])->find();
- $ctl_name = $channeltypeInfo['ctl_name'];
- $class = "\\app\\admin\\model\\{$ctl_name}";
- $model = new $class;
- Db::name('archives')->where(['aid'=>$aid])->delete();
- $model->afterDel([$aid]);
- adminLog('群发删除文档:'.$archivesInfo['title']);
- $data = [
- 'push_code' => 1,
- 'push_msg' => '删除成功',
- ];
- } catch (\Exception $e) {
- $data['push_msg'] = $e->getMessage();
- }
- }
- respose($data);
- }
-
- /**
- * 清除缓存接口
- * @return [type] [description]
- */
- public function clear_cache()
- {
- \think\Cache::clear();
- delFile(RUNTIME_PATH);
-
- // 重新生成全部数据表缓存字段文件
- // $dbtables = \think\Db::query('SHOW TABLE STATUS');
- // $tableList = [];
- // foreach ($dbtables as $k => $v) {
- // if (preg_match('/^'.PREFIX.'/i', $v['Name'])) {
- // /*调用命令行的指令*/
- // \think\Console::call('optimize:schema', ['--table', $v['Name']]);
- // /*--end*/
- // }
- // }
-
- // try {
- // /*清除大数据缓存表 -- 陈风任*/
- // Db::name('sql_cache_table')->execute('TRUNCATE TABLE '.config('database.prefix').'sql_cache_table');
- // model('SqlCacheTable')->InsertSqlCacheTable(true);
- // /* END */
- // } catch (\Exception $e) {}
-
- exit('success');
- }
-
- /**
- * 获取下级地区
- */
- public function get_region()
- {
- if (IS_AJAX) {
- $pid = input('pid/d', 0);
- $res = Db::name('region')->where('parent_id', $pid)->select();
- $this->success('请求成功', null, $res);
- }
- }
-
- /**
- * 内容页浏览量的自增接口
- */
- public function arcclick()
- {
- if (!IS_AJAX) {
- // 第一种方案,js输出
- $aids = input('param.aids/d', 0);
- if (!empty($aids)) {
- $type = input('param.type/s', '');
- $archives_db = Db::name('archives');
- if ('view' == $type) {
- $archives_db->where('aid', $aids)->setInc('click');
- eyou_statistics_data(1); // 统计浏览数
- }
- $click = $archives_db->where('aid', $aids)->value('click');
- echo "document.htm.write('" . $click . "');\r\n";
- exit;
- }
- } else {
- // 第二种方案,执行ajax
- $param = input('param.');
- if (isset($param['aids'])) {
- $aids = $param['aids'];
- if (!empty($aids)) {
- $aid_arr = explode(',', $aids);
- foreach ($aid_arr as $key => $val) {
- $aid_arr[$key] = intval($val);
- }
- $type = input('param.type/s', '');
- $archives_db = Db::name('archives');
- if ('view' == $type) {
- $archives_db->where(['aid' => ['IN', $aid_arr]])->update([
- 'click' => Db::raw('click + 1'),
- ]);
- eyou_statistics_data(1, count($aid_arr)); // 统计浏览数
- }
- $data = $archives_db->field('aid,click')->where(['aid' => ['IN', $aid_arr]])->getAllWithIndex('aid');
- respose($data);
- }
- } else {
- $click = 0;
- $aid = input('param.aid/d', 0);
- $type = input('param.type/s', '');
- if ($aid > 0) {
- $archives_db = Db::name('archives');
- if ('view' == $type) {
- $archives_db->where(array('aid' => $aid))->setInc('click');
- eyou_statistics_data(1); // 统计浏览数
- }
- $click = $archives_db->where(array('aid' => $aid))->getField('click');
- }
- echo($click);
- exit;
- }
- }
- to_index("404");
- }
-
- /**
- * 付费文档的订单数/用户数
- */
- public function freebuynum()
- {
- $aid = input('param.aid/d', 0);
- if (IS_AJAX && !empty($aid)) {
- $freebuynum = 0;
- $modelid = input('modelid/d', 0);
- $modelid = input('channelid/d', $modelid);
-
- if (empty($modelid)) {
- $modelid = Db::name('archives')->where(['aid' => $aid])->value('channel');
- }
-
- if (1 == $modelid) {
- $freebuynum = Db::name('article_order')->where(['product_id' => $aid, 'order_status' => 1])->count();
- } else if (5 == $modelid) {
- $freebuynum = Db::name('media_order')->where(['product_id' => $aid, 'order_status' => 1])->count();
- } else if (4 == $modelid) {
- $freebuynum = Db::name('download_order')->where(['product_id' => $aid, 'order_status' => 1])->count();
- }
-
- echo($freebuynum);
- exit;
- } else {
- to_index("404");
- }
- }
-
- /**
- * 文档下载次数
- */
- public function downcount()
- {
- $aid = input('param.aid/d', 0);
- if (IS_AJAX && !empty($aid)) {
- $downcount = Db::name('archives')->where(array('aid' => $aid))->getField('downcount');
- echo($downcount);
- exit;
- } else {
- to_index("404");
- }
- }
-
- /**
- * 文档收藏次数
- */
- public function collectnum()
- {
- $aid = input('param.aid/d', 0);
- if (IS_AJAX && !empty($aid)) {
- $collectnum = Db::name('users_collection')->where(array('aid' => $aid))->count();
- echo($collectnum);
- exit;
- } else {
- to_index("404");
- }
- }
-
- /**
- * 站内通知数量
- */
- public function notice()
- {
- if (IS_AJAX) {
- $unread_notice_num = 0;
- $users_id = session('users_id');
- if ($users_id > 0) {
- $unread_notice_num = Db::name('users')->where(array('users_id' => $users_id))->value('unread_notice_num');
- }
- echo($unread_notice_num);
- exit;
- } else {
- to_index("404");
- }
- }
-
- /**
- * arclist列表分页arcpagelist标签接口
- */
- public function arcpagelist()
- {
- if (!IS_AJAX) {
- to_index("404");
- }
-
- $pnum = input('page/d', 0);
- $pagesize = input('pagesize/d', 0);
- $tagid = input('tagid/s', '');
- $tagidmd5 = input('tagidmd5/s', '');
- !empty($tagid) && $tagid = preg_replace("/[^a-zA-Z0-9-_]/", '', $tagid);
- !empty($tagidmd5) && $tagidmd5 = preg_replace("/[^a-zA-Z0-9_]/", '', $tagidmd5);
-
- if (empty($tagid) || empty($pnum) || empty($tagidmd5)) {
- $this->error('参数有误');
- }
-
- $data = [
- 'code' => 1,
- 'msg' => '',
- 'lastpage' => 0,
- ];
-
- $arcmulti_db = Db::name('arcmulti');
- $arcmultiRow = $arcmulti_db->where(['tagid' => $tagidmd5])->find();
- if (!empty($arcmultiRow) && !empty($arcmultiRow['querysql'])) {
- // arcpagelist标签属性pagesize优先级高于arclist标签属性pagesize
- if (0 < intval($pagesize)) {
- $arcmultiRow['pagesize'] = $pagesize;
- }
-
- // 取出属性并解析为变量
- $attarray = unserialize(stripslashes($arcmultiRow['attstr']));
- // extract($attarray, EXTR_SKIP); // 把数组中的键名直接注册为了变量
-
- // 通过页面及总数解析当前页面数据范围
- $pnum < 2 && $pnum = 2;
- $strnum = intval($attarray['row']) + ($pnum - 2) * $arcmultiRow['pagesize'];
-
- // 拼接完整的SQL
- $querysql = preg_replace('#LIMIT(\s+)(\d+)(,\d+)?#i', '', $arcmultiRow['querysql']);
- $querysql = preg_replace('#SELECT(\s+)(.*)(\s+)FROM#i', 'SELECT COUNT(*) AS totalNum FROM', $querysql);
- $queryRow = Db::query($querysql);
- if (!empty($queryRow)) {
- $tpl_content = '';
- $filename = './template/' . THEME_STYLE_PATH . '/' . 'system/arclist_' . $tagid . '.' . \think\Config::get('template.view_suffix');
- if (!file_exists($filename)) {
- $data['code'] = -1;
- $data['msg'] = "模板追加文件 arclist_{$tagid}.htm 不存在!";
- $this->error("标签模板不存在", null, $data);
- } else {
- $tpl_content = @file_get_contents($filename);
- }
- if (empty($tpl_content)) {
- $data['code'] = -1;
- $data['msg'] = "模板追加文件 arclist_{$tagid}.htm 没有HTML代码!";
- $this->error("标签模板不存在", null, $data);
- }
-
- /*拼接完整的arclist标签语法*/
- $offset = intval($strnum);
- $row = intval($offset) + intval($arcmultiRow['pagesize']);
- $innertext = "{eyou:arclist";
- foreach ($attarray as $key => $val) {
- if (in_array($key, ['tagid', 'offset', 'row'])) {
- continue;
- }
- if ($key == 'keyword') {
- if (empty($val)) {
- continue;
- } else if (preg_match('/^\$eyou(\.|\[)(.*)$/i', $val)) {
- $val = input('param.keywords/s');
- }
- }
- $innertext .= " {$key}='{$val}'";
- }
- $innertext .= " limit='{$offset},{$row}'}";
- $innertext .= $tpl_content;
- $innertext .= "{/eyou:arclist}";
- /*--end*/
- $msg = $this->display($innertext); // 渲染模板标签语法
- $data['msg'] = $msg;
-
- //是否到了最终页
- if (!empty($queryRow[0]['totalNum']) && $queryRow[0]['totalNum'] <= $row) {
- $data['lastpage'] = 1;
- }
-
- } else {
- $data['lastpage'] = 1;
- }
- }
-
- $this->success('请求成功', null, $data);
- }
-
- /**
- * 获取表单令牌
- */
- public function get_token($name = '__token__')
- {
- $name = preg_replace('/([^\w\-]+)/i', '', $name);
- if (IS_AJAX && strstr($name, '_token_')) {
- echo $this->request->token($name);
- exit;
- } else {
- to_index("404");
- }
- }
-
- /**
- * 检验会员登录
- */
- public function check_user()
- {
- if (IS_AJAX) {
- $type = input('param.type/s', 'default');
- $img = input('param.img/s');
- $afterhtml = input('param.afterhtml/s');
- $users_id = session('users_id');
- if ('login' == $type) {
- if (!empty($users_id)) {
- $currentstyle = input('param.currentstyle/s');
- $users = M('users')->field('username,nickname,head_pic,sex')
- ->where([
- 'users_id' => $users_id,
- 'lang' => $this->home_lang,
- ])->find();
- if (!empty($users)) {
- $nickname = $users['nickname'];
- if (empty($nickname)) {
- $nickname = $users['username'];
- }
- $head_pic = get_head_pic(htmlspecialchars_decode($users['head_pic']), false, $users['sex']);
- $users['head_pic'] = func_preg_replace(['http://thirdqq.qlogo.cn'], ['https://thirdqq.qlogo.cn'], $head_pic);
- if (!empty($afterhtml)) {
- preg_match_all('/~(\w+)~/iUs', $afterhtml, $userfields);
- if (!empty($userfields[1])) {
- $users['url'] = url('user/Users/login');
- foreach ($userfields[1] as $key => $val) {
- $replacement = !empty($users[$val]) ? $users[$val] : '';
- $afterhtml = str_replace($userfields[0][$key], $users[$val], $afterhtml);
- }
- $users['html'] = htmlspecialchars_decode($afterhtml);
- } else {
- $users['html'] = $nickname;
- }
- } else {
- if ('on' == $img) {
- $users['html'] = "<img class='{$currentstyle}' alt='{$nickname}' src='{$users['head_pic']}' />";
- } else {
- $users['html'] = $nickname;
- }
- }
- $users['ey_is_login'] = 1;
- cookie('users_id', $users_id);
- $this->success('请求成功', null, $users);
- }
- }
-
- $data = [
- 'ey_is_login' => 0,
- 'ey_third_party_login' => $this->is_third_party_login(),
- 'ey_third_party_qqlogin' => $this->is_third_party_login('qq'),
- 'ey_third_party_wxlogin' => $this->is_third_party_login('wx'),
- 'ey_third_party_wblogin' => $this->is_third_party_login('wb'),
- 'ey_login_vertify' => $this->is_login_vertify(),
- ];
- $this->success('请先登录', null, $data);
- } else if ('reg' == $type) {
- if (!empty($users_id)) {
- $users['ey_is_login'] = 1;
- } else {
- $users['ey_is_login'] = 0;
- }
- $this->success('请求成功', null, $users);
- } else if ('logout' == $type) {
- if (!empty($users_id)) {
- $users['ey_is_login'] = 1;
- } else {
- $users['ey_is_login'] = 0;
- }
- $this->success('请求成功', null, $users);
- } else if ('cart' == $type) {
- if (!empty($users_id)) {
- $users['ey_is_login'] = 1;
- $users['ey_cart_num_20191212'] = Db::name('shop_cart')->where(['users_id' => $users_id])->sum('product_num');
- } else {
- $users['ey_is_login'] = 0;
- $users['ey_cart_num_20191212'] = 0;
- }
- $this->success('请求成功', null, $users);
- } else if ('collect' == $type) {
- if (!empty($users_id)) {
- $users['ey_is_login'] = 1;
- $users['ey_collect_num_20191212'] = Db::name('users_collection')->where(['users_id' => $users_id])->count();
- } else {
- $users['ey_is_login'] = 0;
- $users['ey_collect_num_20191212'] = 0;
- }
- $this->success('请求成功', null, $users);
- }
- $this->error('访问错误');
- } else {
- to_index("404");
- }
- }
-
- public function get_info()
- {
- $str = '5piT5LyYQ01TLQ==';
- exit(base64_decode($str) . getCmsVersion());
- }
-
- /**
- * 是否启用并开启第三方登录
- * @return boolean [description]
- */
- private function is_third_party_login($type = '')
- {
- static $result = null;
- if (null === $result) {
- $result = Db::name('weapp')->field('id,code,data')->where([
- 'code' => ['IN', ['QqLogin', 'WxLogin', 'Wblogin']],
- 'status' => 1,
- ])->getAllWithIndex('code');
- }
- $value = 0;
- if (empty($type)) {
- $qqlogin = 0;
- if (!empty($result['QqLogin']['data'])) {
- $qqData = unserialize($result['QqLogin']['data']);
- if (!empty($qqData['login_show'])) {
- $qqlogin = 1;
- }
- }
-
- $wxlogin = 0;
- if (!empty($result['WxLogin']['data'])) {
- $wxData = unserialize($result['WxLogin']['data']);
- if (!empty($wxData['login_show'])) {
- $wxlogin = 1;
- }
- }
-
- $wblogin = 0;
- if (!empty($result['Wblogin']['data'])) {
- $wbData = unserialize($result['Wblogin']['data']);
- if (!empty($wbData['login_show'])) {
- $wblogin = 1;
- }
- }
-
- if ($qqlogin == 1 || $wxlogin == 1 || $wblogin == 1) {
- $value = 1;
- }
- } else {
- if ('qq' == $type) {
- if (!empty($result['QqLogin']['data'])) {
- $qqData = unserialize($result['QqLogin']['data']);
- if (!empty($qqData['login_show'])) {
- $value = 1;
- }
- }
- } else if ('wx' == $type) {
- if (!empty($result['WxLogin']['data'])) {
- $wxData = unserialize($result['WxLogin']['data']);
- if (!empty($wxData['login_show'])) {
- $value = 1;
- }
- }
- } else if ('wb' == $type) {
- if (!empty($result['Wblogin']['data'])) {
- $wbData = unserialize($result['Wblogin']['data']);
- if (!empty($wbData['login_show'])) {
- $value = 1;
- }
- }
- }
- }
-
- return $value;
- }
-
- /**
- * 是否开启登录图形验证码
- * @return boolean [description]
- */
- private function is_login_vertify()
- {
- $row = tpSetting('system.system_vertify');
- // 获取验证码配置信息
- $row = json_decode($row, true);
- $baseConfig = \think\Config::get("captcha");
- if (!empty($row)) {
- foreach ($row['captcha'] as $key => $val) {
- if ('default' == $key) {
- $baseConfig[$key] = array_merge($baseConfig[$key], $val);
- } else {
- $baseConfig[$key]['is_on'] = $val['is_on'];
- $baseConfig[$key]['config'] = array_merge($baseConfig['default'], $val['config']);
- }
- }
- \think\Config::set('captcha', $baseConfig);
- }
-
- // 默认开启验证码
- $is_vertify = 1;
- $users_login_captcha = empty($baseConfig['users_login']) ? [] : $baseConfig['users_login'];
- if (!function_exists('imagettftext') || empty($users_login_captcha['is_on'])) {
- $is_vertify = 0; // 函数不存在,不符合开启的条件
- }
-
- return $is_vertify;
- }
-
- /**
- * 获取用户信息
- */
- public function get_tag_user_info()
- {
- if (!IS_AJAX) {
- to_index("404");
- }
-
- $t_uniqid = input('param.t_uniqid/s', '');
- if (IS_AJAX && !empty($t_uniqid)) {
- $users_id = session('users_id');
- if (!empty($users_id)) {
- $users = Db::name('users')->field('b.*, a.*')
- ->alias('a')
- ->join('__USERS_LEVEL__ b', 'a.level = b.level_id', 'LEFT')
- ->where([
- 'a.users_id' => $users_id,
- 'a.lang' => $this->home_lang,
- ])->find();
- if (!empty($users)) {
- $users['reg_time'] = MyDate('Y-m-d H:i:s', $users['reg_time']);
- $users['update_time'] = MyDate('Y-m-d H:i:s', $users['update_time']);
- } else {
- $users = [];
- $tableFields1 = Db::name('users')->getTableFields();
- $tableFields2 = Db::name('users_level')->getTableFields();
- $tableFields = array_merge($tableFields1, $tableFields2);
- foreach ($tableFields as $key => $val) {
- $users[$val] = '';
- }
- }
- unset($users['password']);
- unset($users['paypwd']);
- // 头像处理
- $head_pic = get_head_pic(htmlspecialchars_decode($users['head_pic']), false, $users['sex']);
- $users['head_pic'] = func_preg_replace(['http://thirdqq.qlogo.cn'], ['https://thirdqq.qlogo.cn'], $head_pic);
- $users['url'] = url('user/Users/centre');
- $dtypes = [];
- foreach ($users as $key => $val) {
- $html_key = md5($key . '-' . $t_uniqid);
- $users[$html_key] = $val;
-
- $dtype = 'txt';
- if (in_array($key, ['head_pic'])) {
- $dtype = 'img';
- } else if (in_array($key, ['url'])) {
- $dtype = 'href';
- }
- $dtypes[$html_key] = $dtype;
-
- unset($users[$key]);
- }
-
- $data = [
- 'ey_is_login' => 1,
- 'users' => $users,
- 'dtypes' => $dtypes,
- ];
- $this->success('请求成功', null, $data);
- }
- $this->success('请先登录', null, ['ey_is_login' => 0]);
- }
- $this->error('访问错误');
- }
-
- // 验证码获取
- public function vertify()
- {
- $time = getTime();
- $type = input('param.type/s', 'default');
- $type = preg_replace('/([^\w\-]+)/i', '', $type);
- $token = input('param.token/s', '');
- $token = preg_replace('/([^\w\-]+)/i', '', $token);
- $configList = \think\Config::get('captcha');
- $captchaArr = array_keys($configList);
- if (in_array($type, $captchaArr)) {
- /*验证码插件开关*/
- $admin_login_captcha = config('captcha.' . $type);
- $config = (!empty($admin_login_captcha['is_on']) && !empty($admin_login_captcha['config'])) ? $admin_login_captcha['config'] : config('captcha.default');
- /*--end*/
- } else {
- $config = config('captcha.default');
- }
-
- ob_clean(); // 清空缓存,才能显示验证码
- $Verify = new \think\Verify($config);
- if (!empty($token)) {
- $Verify->entry($token);
- } else {
- $Verify->entry($type);
- }
- exit();
- }
- /*
- * 表单提交完成之后操作----短信发送
- */
- /**
- * 表单提交完成之后操作----邮箱发送
- */
- public function send_email()
- {
- // 超时后,断掉邮件发送
- function_exists('set_time_limit') && set_time_limit(10);
- \think\Session::pause(); // 暂停session,防止session阻塞机制
-
- $type = input('param.type/s');
-
- // 留言发送邮件
- if (IS_AJAX_POST && 'gbook_submit' == $type) {
-
- // 是否满足发送邮箱的条件
- $is_open = Db::name('smtp_tpl')->where(['send_scene' => 1, 'lang' => $this->home_lang])->value('is_open');
- $smtp_config = tpCache('smtp');
- if (empty($is_open) || empty($smtp_config['smtp_user']) || empty($smtp_config['smtp_pwd'])) {
- $this->error("邮箱尚未配置,发送失败");
- }
-
- $tid = input('param.tid/d');
- $aid = input('param.aid/d');
- $form_type = input('param.form_type/d', 0);
-
- $send_email_scene = config('send_email_scene');
- $scene = $send_email_scene[1]['scene'];
-
- if (1 == $form_type) {
- $info = Db::name('guestbook')->field('a.*, b.form_name')
- ->alias('a')
- ->join('form b','a.typeid = b.form_id','left')
- ->where(['a.aid'=>$aid, 'a.form_type'=>$form_type])
- ->find();
- } else {
- $info = Db::name('guestbook')->field('a.*, b.typename as form_name')
- ->alias('a')
- ->join('arctype b','a.typeid = b.id','left')
- ->where(['a.aid'=>$aid, 'a.form_type'=>$form_type])
- ->find();
- }
- $city = "";
- try {
- $city_arr = getCityLocation($info['ip']);
- if (!empty($city_arr)) {
- !empty($city_arr['location']) && $city .= $city_arr['location'];
- }
- } catch (\Exception $e) {}
- $info['city'] = $city;
-
- // 判断标题拼接
- $web_name = tpCache('web.web_name');
- $web_name = $info['form_name'] . '-' . $web_name;
-
- // 拼装发送的字符串内容
- $attr_list = Db::name('guestbook_attribute')->where(['typeid'=>$tid,'form_type'=>$form_type])->order('attr_id asc')->select();
- $attr_values = Db::name('guestbook_attr')->field('attr_id,attr_value')->where(['aid'=>$aid,'form_type'=>$form_type])->getAllWithIndex('attr_id');
- foreach ($attr_list as $key => $val) {
- $val['attr_value'] = empty($attr_values[$val['attr_id']]) ? '' : $attr_values[$val['attr_id']]['attr_value'];
- $attr_list[$key] = $val;
- }
- $content = '';
- foreach ($attr_list as $key => $val) {
- if ($val['attr_input_type'] == 9) {
- $val['attr_value'] = Db::name('region')->where('id', 'in', $val['attr_value'])->column('name');
- $val['attr_value'] = implode('', $val['attr_value']);
- } else if ($val['attr_input_type'] == 4) {
- $val['attr_value'] = filter_line_return($val['attr_value'], '、');
- } else if (10 == $val['attr_input_type']) {
- $val['attr_value'] = date('Y-m-d H:i:s', $val['attr_value']);
- } else if (11 == $val['attr_input_type']) {
- $attr_value_arr = explode(",", $val['attr_value']);
- $attr_value_str = "";
- foreach ($attr_value_arr as $attr_value_k => $attr_value_v) {
- $attr_value_v = handle_subdir_pic($attr_value_v, 'img', true);
- $attr_value_str .= "<a href='{$attr_value_v}' target='_blank'><img src='{$attr_value_v}' width='60' height='60' style='float: unset;cursor: pointer;' /></a>";
- }
- $val['attr_value'] = $attr_value_str;
- } else {
- if (preg_match('/(\.(jpg|gif|png|bmp|jpeg|ico|webp))$/i', $val['attr_value'])) {
- if (!stristr($val['attr_value'], '|')) {
- $val['attr_value'] = handle_subdir_pic($val['attr_value'], 'img', true);
- $val['attr_value'] = "<a href='{$val['attr_value']}' target='_blank'><img src='{$val['attr_value']}' width='60' height='60' style='float: unset;cursor: pointer;' /></a>";
- }
- } elseif (preg_match('/(\.(' . tpCache('basic.file_type') . '))$/i', $val['attr_value'])) {
- if (!stristr($val['attr_value'], '|')) {
- $val['attr_value'] = handle_subdir_pic($val['attr_value'], 'img', true);
- $val['attr_value'] = "<a href='{$val['attr_value']}' download='" . time() . "'><img src=\"" . $this->request->domain() . ROOT_DIR . "/public/static/common/images/file.png\" alt=\"\" style=\"width: 16px;height: 16px;\">点击下载</a>";
- }
- }
- }
- $content .= $val['attr_name'] . ':' . $val['attr_value'] . '<br/>';
- }
- $content .= '所属表单:' . $info['form_name'] . '<br/>';
- $content .= 'IP来源:' . $info['ip'];
- if (!empty($info['city'])) {
- $content .= "({$info['city']})";
- } else {
- $content .= "(<a href=\"https://www.baidu.com/s?wd={$info['ip']}\" target=\"_blank\">查看地区</a>)";
- }
- $content .= '<br/>';
- if (2 == $info['source']) {
- $content .= "提交来源:手机端<br/>";
- } else {
- $content .= "提交来源:电脑端<br/>";
- }
- $content .= '提交时间:' . MyDate('Y-m-d H:i:s', $info['add_time']) . '<br/>';
- $html = "<p style='text-align: left;'>{$web_name}</p><p style='text-align: left;'>{$content}</p>";
-
- // 发送邮件
- $res = send_email(null, null, $html, $scene);
- if (intval($res['code']) == 1) {
- $this->success($res['msg']);
- } else {
- $this->error($res['msg']);
- }
- }
- }
-
- /**
- * 手机短信发送
- */
- public function SendMobileCode()
- {
- // 超时后,断掉发送
- function_exists('set_time_limit') && set_time_limit(5);
- // \think\Session::pause(); // 暂停session,防止session阻塞机制
-
- /*$pretime1 = getTime() - 120; // 3分钟内
- $ip_prefix = preg_replace('/\d+\.\d+$/i', '', clientIP());
- $count = Db::name('sms_log')->where([
- 'ip' => ['LIKE', "{$ip_prefix}%"],
- 'is_use' => 1,
- 'add_time' => ['gt', $pretime1],
- ])->count();
- if (!empty($count) && 5 <= $count) {
- $this->error('发送短信异常~');
- }*/
-
- // 发送手机验证码
- if (IS_AJAX_POST) {
- $post = input('post.');
- $source = !empty($post['source']) ? $post['source'] : 0;
-
- // 留言验证类型发送短信处理
- if (isset($post['scene']) && in_array($post['scene'], [7])) {
- // 是否允许再次发送
- $where = [
- 'source' => $post['scene'],
- 'mobile' => $post['phone'],
- 'status' => 1,
- 'is_use' => 0,
- 'add_time' => ['>', getTime() - 120]
- ];
- $Result = Db::name('sms_log')->where($where)->order('id desc')->count();
- if (!empty($Result)) $this->error('120秒内只能发送一次');
-
- // 图形验证码判断
- if (empty($post['code'])) $this->error('请输入图片验证码');
- $verify = new \think\Verify();
- if (!$verify->check($post['code'], $post['code_token'])) $this->error('图片验证码错误');
-
- // 发送并返回结果
- $Result = sendSms(7, $post['phone'], array('content' => mt_rand(1000, 9999)));
- if (1 === intval($Result['status'])) {
- $this->success('发送成功');
- } else {
- $this->error($Result['msg']);
- }
- }
- // 订单付款和订单发货类型发送短信处理
- else if (isset($post['scene']) && in_array($post['scene'], [5, 6, 20])) {
- // 如果没有手机号则返回结束
- if (empty($post['mobile'])) return false;
- // 处理发送的内容
- $data = !empty($post['data']) ? $post['data'] : [];
- $data = !empty($data) && !is_array($data) ? json_decode(htmlspecialchars_decode(htmlspecialchars_decode($data)), true) : $data;
- // 查询消息通知模板的内容
- $sms_config = tpCache('sms');
- $sms_type = !empty($sms_config['sms_type']) ? intval($sms_config['sms_type']) : 1;
- $tpl_content = Db::name('sms_template')->where(["send_scene" => $post['scene'], "sms_type" => $sms_type, 'is_open' => 1])->value('tpl_content');
- if (empty($tpl_content)) return false;
- // 发送短信提醒
- if (in_array($data['type'], [1, 2])) {
- // $preg_res = preg_match('/订单/', $tpl_content);
- // 查询订单信息
- $field = 'a.order_code, a.express_time, b.product_name';
- $shopOrder = Db::name('shop_order')->alias('a')->field($field)->join('__SHOP_ORDER_DETAILS__ b', 'a.order_id = b.order_id', 'LEFT')->where('a.order_code', $data['order_code'])->find();
- switch ($data['type']) {
- case '1':
- // if (empty($sms_config['sms_shop_order_pay'])) {
- // $this->error("配置不接收订单付款短信提醒");
- // }
- $sendData = [
- 'content' => $shopOrder['order_code'],
- ];
- // $content = $preg_res ? '待发货' : '您有新的待发货订单';
- break;
- case '2':
- $sendData = [
- 'content' => $shopOrder['order_code'],
- 'express_time' => $shopOrder['express_time'],
- 'product_name' => $shopOrder['product_name'],
- ];
- // $content = $preg_res ? $data['order_code'] : $data['order_code'];
- break;
- default:
- $content = '';
- break;
- }
- } else if (in_array($data['type'], [3])) {
- $sendData = [
- 'content' => $tpl_content
- ];
- }
- $Result = !empty($sendData) ? sendSms($post['scene'], $post['mobile'], $sendData) : ['status' => 0, 'msg' => '没有发送内容'];
- if (intval($Result['status']) == 1) {
- $this->success('发送成功!');
- } else {
- $this->error($Result['msg']);
- }
- }
- //发送表单提醒
- else if (isset($post['scene']) && $post['scene'] == 11) {
- //查询消息通知模板的内容
- $sms_config = tpCache('sms');
- // if (empty($sms_config['sms_guestbook_send'])) {
- // $this->error("配置不接收留言短信提醒");
- // }
- $sms_type = $sms_config['sms_type'] ? intval($sms_config['sms_type']) : 1;
- $tpl_content = Db::name('sms_template')->where(["send_scene" => $post['scene'], "sms_type" => $sms_type, 'is_open' => 1])->value('tpl_content');
- if (!$tpl_content) return false;
-
- $Result = sendSms($post['scene'], $sms_config['sms_test_mobile'], []);
- if (intval($Result['status']) == 1) {
- $this->success('发送成功!');
- } else {
- $this->error($Result['msg']);
- }
- /* END */
- }
- // 其他类型发送短信处理
- else {
- if (isset($post['type']) && in_array($post['type'], ['users_mobile_reg', 'users_mobile_login', 'reg'])) {
- // 数据验证
- $rule = [
- 'mobile' => 'require|token:__mobile_1_token__',
- ];
- $message = [
- 'mobile.require' => '请输入手机号码!',
- ];
- $validate = new \think\Validate($rule, $message);
- if (!$validate->batch()->check($post)) {
- $this->error('表单令牌过期,请尝试刷新页面~');
- }
-
- $post['is_mobile'] = true;
- }
- $mobile = !empty($post['mobile']) ? $post['mobile'] : session('mobile');
- if (empty($mobile)) $this->error('请先绑定手机号码');
- // 手机可用性验证
- $is_mobile = !empty($post['is_mobile']) ? $post['is_mobile'] : false;
- if (!empty($is_mobile)) {
- /*是否存在手机号码*/
- $where = [
- 'mobile' => $mobile
- ];
- $users_id = session('users_id');
- if (!empty($users_id)) $where['users_id'] = ['NEQ', $users_id];
- $Result = Db::name('users')->where($where)->count();
- /* END */
- if (0 == $post['source']) {
- if (!empty($Result)) $this->error('手机号码已注册');
- } else if (2 == $post['source']) {
- if (empty($Result)) $this->error('手机号码未注册');
- } else if (4 == $post['source']) {
- if (empty($Result)) $this->error('手机号码不存在');
- } else {
- if (!empty($Result)) $this->error('手机号码已存在');
- }
- }
-
- /*是否允许再次发送*/
- $where = [
- 'mobile' => $mobile,
- 'source' => $source,
- 'status' => 1,
- 'is_use' => 0,
- 'add_time' => ['>', getTime() - 120]
- ];
- $Result = Db::name('sms_log')->where($where)->order('id desc')->count();
-
- if (!empty($Result) && false == config('sms_debug')) $this->error('120秒内只能发送一次!');
- /* END */
-
- /*图形验证码判断*/
- if (!empty($post['IsVertify']) || (isset($post['type']) && in_array($post['type'], ['users_mobile_reg', 'users_mobile_login', 'bind', 'other']))) {
- if (empty($post['vertify'])) $this->error('请输入图形验证码!');
- $verify = new \think\Verify();
- if (!$verify->check($post['vertify'], $post['type'])) $this->error('图形验证码错误!', null, ['code' => 'vertify']);
- }
- /* END */
-
- /*发送并返回结果*/
- $Result = sendSms($source, $mobile, array('content' => mt_rand(1000, 9999)));
- if (intval($Result['status']) == 1) {
- $this->success('发送成功!');
- } else {
- $this->error($Result['msg']);
- }
- /* END */
- }
- }
- }
-
- // 判断文章内容阅读权限
- public function get_arcrank($aid = '', $vars = '',$tid = '')
- {
- $aid = intval($aid);
- $tid = intval($tid);
- $vars = intval($vars);
- $gourl = input('param.gourl/s');
- $gourl = urldecode($gourl);
- $gourl = !empty($gourl) ? urldecode($gourl) : ROOT_DIR . '/';
- if ((IS_AJAX || !empty($vars)) && !empty($aid)) {
- // 用户ID
- $users_id = session('users_id');
- // 文章查看所需等级值
- $Arcrank = Db::name('archives')->alias('a')
- ->field('a.users_id, a.arcrank,c.typearcrank,c.page_limit')
- ->join('__ARCTYPE__ c', 'a.typeid = c.id', 'LEFT')
- ->where(['a.aid' => $aid])
- ->find();
- $Arcrank['page_limit'] = empty($Arcrank['page_limit']) ? [] : explode(',', $Arcrank['page_limit']);
- //文章存在限制条件,优先使用文章限制条件;如不存在,则使用栏目限制条件。
- if (empty($Arcrank['arcrank']) && (!empty($Arcrank['typearcrank']) && $Arcrank['typearcrank'] > 0 && in_array(2, $Arcrank['page_limit']))) {
- $Arcrank['arcrank'] = $Arcrank['typearcrank'];
- }
-
- if (!empty($users_id)) {
- // 会员级别等级值
- $UsersDataa = Db::name('users')->alias('a')
- ->field('a.users_id,b.level_value,b.level_name')
- ->join('__USERS_LEVEL__ b', 'a.level = b.level_id', 'LEFT')
- ->where(['a.users_id' => $users_id])
- ->find();
- if (0 == $Arcrank['arcrank']) {
- if (IS_AJAX) {
- $this->success('允许查阅!');
- } else {
- return true;
- }
- } else if (-1 == $Arcrank['arcrank']) {
- $is_admin = session('?admin_id') ? 1 : 0;
- $param_admin_id = input('param.admin_id/d');
- if ($users_id == $Arcrank['users_id']) {
- if (IS_AJAX) {
- $this->success('允许查阅!', null, ['is_admin' => $is_admin, 'msg' => '待审核稿件,仅限自己查看!']);
- } else {
- return true;
- }
- } else if (!empty($is_admin) && !empty($param_admin_id)) {
- if (IS_AJAX) {
- $this->success('允许查阅!', null, ['is_admin' => $is_admin, 'msg' => '待审核稿件,仅限管理员查看!']);
- } else {
- return true;
- }
- } else {
- $msg = '待审核稿件,你没有权限阅读!';
- }
- } else if ($UsersDataa['level_value'] < $Arcrank['arcrank']) {
- $level_name = Db::name('users_level')->where(['level_value' => $Arcrank['arcrank']])->getField('level_name');
- $msg = '__html__内容需要【' . $level_name . '】才可以查看<br/>您为【' . $UsersDataa['level_name'] . '】,请先升级!';
-
- } else {
- if (IS_AJAX) {
- $this->success('允许查阅!');
- } else {
- return true;
- }
- }
- if (IS_AJAX) {
- $this->error($msg);
- } else {
- return $msg;
- }
- } else {
- if (0 == $Arcrank['arcrank']) {
- if (IS_AJAX) {
- $this->success('允许查阅!');
- } else {
- return true;
- }
- } else if (-1 == $Arcrank['arcrank']) {
- $is_admin = session('?admin_id') ? 1 : 0;
- $param_admin_id = input('param.admin_id/d');
- if (!empty($is_admin) && !empty($param_admin_id)) {
- $this->success('允许查阅!', null, ['is_admin' => $is_admin, 'msg' => '待审核稿件,仅限管理员查看!']);
- } else {
- $msg = '待审核稿件,你没有权限阅读!';
- }
- } else if (!empty($Arcrank['arcrank'])) {
- $level_name = Db::name('users_level')->where(['level_value' => $Arcrank['arcrank']])->getField('level_name');
- $msg = '文章需要【' . $level_name . '】才可以查看,游客不可查看,请登录!';
- } else {
- $msg = '游客不可查看,请登录!';
- }
- if (IS_AJAX) {
- $loginUrl = url('user/Users/login');
- if (stristr($loginUrl, '?')) {
- $gourl = $loginUrl . "&referurl=" . urlencode($gourl);
- } else {
- $gourl = $loginUrl . "?referurl=" . urlencode($gourl);
- }
- $data = [
- 'is_login' => 0,
- 'gourl' => $gourl,
- ];
- $this->error($msg, null, $data);
- } else {
- return $msg;
- }
- }
- } else if ((IS_AJAX || !empty($vars)) && !empty($tid)) {
- // 用户ID
- $users_id = session('users_id');
- // 文章查看所需等级值
- $Arcrank = Db::name('arctype')
- ->field('typearcrank,page_limit')
- ->where(['id' => $tid])
- ->find();
- $Arcrank['page_limit'] = empty($Arcrank['page_limit']) ? [] : explode(',', $Arcrank['page_limit']);
- //文章存在限制条件,优先使用文章限制条件;如不存在,则使用栏目限制条件。
- if (!empty($Arcrank['typearcrank']) && $Arcrank['typearcrank'] > 0 && in_array(1, $Arcrank['page_limit'])) {
- if (!empty($users_id)) {
- // 会员级别等级值
- $UsersDataa = Db::name('users')->alias('a')
- ->field('a.users_id,b.level_value,b.level_name')
- ->join('__USERS_LEVEL__ b', 'a.level = b.level_id', 'LEFT')
- ->where(['a.users_id' => $users_id])
- ->find();
- if ($UsersDataa['level_value'] < $Arcrank['typearcrank']) {
- $level_name = Db::name('users_level')->where(['level_value' => $Arcrank['typearcrank']])->getField('level_name');
- $msg = '__html__内容需要【' . $level_name . '】才可以查看<br/>您为【' . $UsersDataa['level_name'] . '】,请先升级!';
- if (IS_AJAX) {
- $this->error($msg);
- } else {
- return $msg;
- }
- }
- } else {
- $level_name = Db::name('users_level')->where(['level_value' => $Arcrank['typearcrank']])->getField('level_name');
- $msg = '文章需要【' . $level_name . '】才可以查看,游客不可查看,请登录!';
- if (IS_AJAX) {
- $loginUrl = url('user/Users/login');
- if (stristr($loginUrl, '?')) {
- $gourl = $loginUrl . "&referurl=" . urlencode($gourl);
- } else {
- $gourl = $loginUrl . "?referurl=" . urlencode($gourl);
- }
- $data = [
- 'is_login' => 0,
- 'gourl' => $gourl,
- ];
- $this->error($msg, null, $data);
- } else {
- return $msg;
- }
- }
- }
- if (IS_AJAX) {
- $this->success('允许查阅!');
- } else {
- return true;
- }
- } else {
- to_index("404");
- }
- }
-
- /**
- * 获取会员列表
- * @author 小虎哥 by 2018-4-20
- */
- public function get_tag_memberlist()
- {
- if (IS_AJAX_POST) {
- // 接收html实体代码
- $htmlcode = input('post.htmlcode/s', '');
- $htmlcode = htmlspecialchars_decode($htmlcode);
- $htmlcode = preg_replace('/<\?(\s*)php(\s+)/i', '', $htmlcode);
-
- // 接收标签参数
- $attarray = input('post.attarray/s', '');
- $attarray = htmlspecialchars_decode($attarray);
- $attarray = json_decode(base64_decode($attarray), true);
-
- // 查询会员表字段
- $field = [];
- $usersField = Db::name("users")->getTableFields();
- foreach ($usersField as $key => $value) {
- $field[$key] = $value . '_eyoucms_fields';
- }
-
- // 会员表自定义字段
- $where = [
- 'is_hidden' => 0,
- 'lang' => $this->home_lang,
- // 'dtype' => ['NOT IN', ['imgs']],
- ];
- $usersParams = Db::name("users_parameter")->field('para_id, name')->where($where)->order('para_id asc')->select();
- foreach ($usersParams as $key => $value) {
- $field[count($field)] = $value['name'] . '_eyoucms_params';
- }
- // dump($field);exit;
-
- // 查询排序
- $orderby = !empty($attarray['orderby']) ? $attarray['orderby'] : '';
- switch ($orderby) {
- case 'logintime': // 兼容写法
- case 'last_login':
- $orderby = "last_login desc";
- break;
-
- case 'users_id':
- $orderby = "users_id desc";
- break;
-
- case 'regtime':
- case 'reg_time':
- $orderby = "reg_time desc";
- break;
-
- default:
- {
- if (in_array($orderby, $usersField)) {
- $orderby = "{$orderby} desc";
- } else {
- $orderby = "users_id desc";
- }
- break;
- }
- }
-
- // 查询会员表数据
- $where = [
- 'admin_id' => 0,
- 'lang' => $this->home_lang,
- ];
- $limit = !empty($attarray['row']) ? intval($attarray['row']) : 10;
- $list = Db::name("users")->where($where)->order($orderby)->limit($limit)->select();
-
- // 查询会员自定义数据
- $where = [
- 'lang' => $this->home_lang,
- // 'para_id' => ['NOT IN', [11]],
- ];
- $usersList = Db::name("users_list")->field('para_id, users_id, info')->where($where)->order('para_id asc')->select();
- $usersList = group_same_key($usersList, 'users_id');
-
- // 查询会员等级数据
- $where = [
- 'lang' => $this->home_lang,
- ];
- $usersLevel = Db::name("users_level")->where($where)->order('level_id asc')->getField('level_id, level_name');
-
- // 循环处理会员html显示代码
- $html = '';
- foreach ($list as $key => $value) {
- // 内置数据处理
- $value['paypwd'] = '<font style="color: red;">不支持显示支付密码</font>';
- $value['password'] = '<font style="color: red;">不支持显示登录密码</font>';
- $value['head_pic'] = get_head_pic($value['head_pic'], false, $value['sex']);
- $value['level'] = !empty($usersLevel[$value['level']]) ? $usersLevel[$value['level']] : '';
- // 会员自定义数据与内置数据合并
- $infoValue = [];
- if (!empty($usersList[$value['users_id']])) {
- $infoValue = get_arr_column($usersList[$value['users_id']], 'info');
- $infoValue[10] = '" alt="不支持显示自定义多图';
- } else {
- $infoValue = [0 => '', 1 => '', 2 => '', 3 => '', 4 => '', 5 => '', 6 => '', 7 => '', 8 => '', 9 => '', 10 => '" alt="不支持显示自定义多图'];
- }
- $value = array_merge($value, $infoValue);
- // 替换指定字段数据
- $html .= str_replace($field, $value, $htmlcode);
- }
-
- // dump($html);exit;
- $this->success('读取成功!', null, ['html' => htmlspecialchars_decode($html)]);
- }
- $this->error('加载失败!');
- }
-
- /**
- * 发布或编辑文档时,百度自动推送
- */
- public function push_zzbaidu($url, $type = 'add')
- {
- if (empty($url)) {
- $this->error('无效url推送');
- }
- $msg = '百度推送URL失败!';
- if (IS_AJAX_POST) {
- \think\Session::pause(); // 暂停session,防止session阻塞机制
-
- // 获取token的值:http://ziyuan.baidu.com/linksubmit/index?site=http://www.eyoucms.com/
- $sitemap_zzbaidutoken = config('tpcache.sitemap_zzbaidutoken');
- if (empty($sitemap_zzbaidutoken)) {
- $this->error('尚未配置实时推送Url的token!', null, ['code' => 0]);
- } else if (!function_exists('curl_init')) {
- $this->error('请开启php扩展curl_init', null, ['code' => 1]);
- }
-
- $urlsArr = is_array($url) ? $url : [$url];
- // $type = ('edit' == $type) ? 'update' : 'urls';
- $type = 'urls';
-
- if (is_http_url($sitemap_zzbaidutoken)) {
- $searchs = ["/urls?", "/update?"];
- $replaces = ["/{$type}?", "/{$type}?"];
- $api = str_replace($searchs, $replaces, $sitemap_zzbaidutoken);
- } else {
- $api = 'http://data.zz.baidu.com/' . $type . '?site=' . $this->request->host(true) . '&token=' . trim($sitemap_zzbaidutoken);
- }
-
- $ch = curl_init();
- $options = array(
- CURLOPT_URL => $api,
- CURLOPT_POST => true,
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_POSTFIELDS => implode("\n", $urlsArr),
- CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
- );
- curl_setopt_array($ch, $options);
- $result = curl_exec($ch);
- !empty($result) && $result = json_decode($result, true);
- if (!empty($result['success'])) {
- $this->success('百度推送URL成功!');
- } else {
- $msg = !empty($result['message']) ? $result['message'] : $msg;
- }
- }
-
- $this->error($msg);
- }
-
- /**
- * 发布或编辑文档/栏目时,小程序 API 提交
- * 将小程序资源 path 路径,提交到 API 接口中
- */
- public function push_bdminipro($aid = 0, $typeid = 0)
- {
- //先判断是否安装百度小程序插件
- $BdDiyminipro = Db::name('weapp')->where('code', 'BdDiyminipro')->where('status', 1)->find();
- if (empty($BdDiyminipro)) {
- $this->error('未安装可视化百度小程序!');
- } else {
- $data = Db::name('weapp_bd_diyminipro_setting')->where('name', 'setting')->order('mini_id desc')->find();
- $value = json_decode($data['value'], true);
- if (empty($value['appKey']) || empty($value['appSecret'])) {
- $this->error('未配置可视化百度小程序!');
- }
- $access_token = '';
- if (empty($value['access_token']) || empty($value['access_token_extime']) || $value['access_token_extime'] < getTime()) {
- if (!empty($value['appId'])) {
- $values = [];
- $values['appId'] = $value['appId'];
- $url = "http://service.eyysz.cn/index.php?m=api&c=BaiduMiniproClient&a=minipro&" . http_build_query($values);
- $response = httpRequest($url);
- $params = array();
- $params = json_decode($response, true);
- if (!empty($params) && $params['errcode'] == 0) {
- $at_url = 'https://openapi.baidu.com/oauth/2.0/token?grant_type=client_credentials&client_id=' . $params['errmsg']['appKey'] . '&client_secret=' . $params['errmsg']['appSecret'] . '&scope=smartapp_snsapi_base';
- $response1 = httpRequest($at_url);
- $params1 = array();
- $params1 = json_decode($response1, true);
- if (!empty($params1['access_token'])) {
- $value['access_token'] = $access_token = $params1['access_token'];
- $value['access_token_extime'] = getTime() + $params1['expires_in'];
- $updateValue = json_encode($value);
- Db::name('weapp_bd_diyminipro_setting')->where('mini_id', $data['mini_id'])->update(['value' => $updateValue, 'update_time' => getTime()]);
- }
- }
- }
- } else {
- $access_token = $value['access_token'];
- }
- if (!empty($access_token)) {
- $res = push_bdminiproapi($access_token, 1, $aid, $typeid);
- if (!empty($res)) {
- $msg = !empty($res['msg']) ? $res['msg'] : $res['error_msg'];
- $this->success($msg);
- }
- }
- }
- }
-
- /*
- * 视频权限播放逻辑
- */
- public function video_logic()
- {
- $post = input('post.');
- if (IS_AJAX_POST && !empty($post['aid'])) {
-
- // 查询文档信息
- $field = 'a.*,b.*,c.*';
- $where = [
- 'a.aid' => $post['aid'],
- 'a.is_del' => 0
- ];
- $archivesInfo = Db::name('archives')
- ->alias('a')
- ->field($field)
- ->join('__USERS_LEVEL__ b', 'a.arc_level_id = b.level_id', 'LEFT')
- ->join('__ARCTYPE__ c', 'c.id = a.typeid', 'LEFT')
- ->where($where)
- ->find();
-
- if (5 == $archivesInfo['channel']) {
- // 获取用户最新信息
- $UsersData = GetUsersLatestData();
- $UsersID = !empty($UsersData['users_id']) ? $UsersData['users_id'] : 0;
- $result['status_value'] = 0; // status_value 0-所有人免费 1-所有人付费 2-会员免费 3-会员付费
- $result['status_name'] = ''; //status_name 要求会员等级时会员级别名称
- $result['play_auth'] = 0; //播放权限
- $result['vip_status'] = 0; //status_value=3时使用 vip_status=1则已升级会员暂未购买
- $users_price = get_discount_price($UsersData['level_discount'], $archivesInfo['users_price']);
-
- /*是否需要付费*/
- if (0 < $archivesInfo['users_price'] && empty($archivesInfo['users_free'])) {
- if (empty($archivesInfo['arc_level_id'])) {
- //不限会员 付费
- $result['status_value'] = 1;
- $result['users_price'] = $users_price;
- } else {
- //3-限制会员 付费
- $result['status_value'] = 3;
- $result['users_price'] = $users_price;
- if ($archivesInfo['level_value'] <= $UsersData['level_value']) {
- $result['vip_status'] = 1;//已升级会员未购买
- }
- }
-
- if (!empty($UsersID)) {
- $where = [
- 'users_id' => intval($UsersID),
- 'product_id' => intval($post['aid']),
- 'order_status' => 1
- ];
- // 存在数据则已付费
- $Paid = Db::name('media_order')->where($where)->count();
- //已购买
- if (!empty($Paid)) {
- if (3 == $result['status_value']) {
- if (1 == $result['vip_status']) {
- $result['play_auth'] = 1;
- $result['vip_status'] = 3;//已升级会员已经购买
- } else {
- $result['play_auth'] = 0;
- $result['vip_status'] = 2;//未升级会员已经购买
- }
- } else {
- $result['play_auth'] = 1;
- $result['vip_status'] = 4;//不限会员已经购买
- }
- }
- }
- } else {
- if (0 < intval($archivesInfo['arc_level_id'])) { // 会员免费
- $result['status_value'] = 2;
- if (!empty($UsersID) && $archivesInfo['level_value'] <= $UsersData['level_value']) {
- $result['play_auth'] = 1;
- }
- } else { // 所有人免费
- $result['play_auth'] = 1;
- }
- }
- /*END*/
-
- /**注册会员免费但是没有登录*/
- // if (empty($UsersID) && !empty($result['status_value'])) {
- // $this->error('请先登录', url('user/Users/login'));
- // }
-
- $where = [
- 'users_id' => intval($UsersID),
- 'product_id' => intval($post['aid']),
- 'order_status' => 1
- ];
- // 存在数据则已付费
- /*END*/
-
- $is_pay = 0;
- if (in_array($result['status_value'], [1, 3])) { // 所有人、会员付费
- $is_pay = Db::name('media_order')->where($where)->count();
- }
- $result['is_pay'] = $is_pay;
-
- if (in_array($result['status_value'], [2, 3])) { // 已满足会员级别要求
- $result['status_name'] = Db::name('users_level')->where('level_id', intval($archivesInfo['arc_level_id']))->value('level_name');
- }
-
- /*
- if (in_array($result['status_value'], [2,3])){ // 会员免费与会员付费
- $result['status_name'] = Db::name('users_level')->where('level_id', $archivesInfo['arc_level_id'])->value('level_name');
- $vip_status = 0;
- if ($archivesInfo['level_value'] <= $UsersData['level_value']) {
- $vip_status = 1; // 已满足会员级别要求
- }
- }*/
-
- if ($result['status_value'] == 0) {
- $result['button'] = '免费';
- $result['status_name'] = '免费';
- } else if ($result['status_value'] == 1) { // 所有人付费
- $result['button'] = '付费';
- if (!empty($is_pay)) {
- $result['button'] = '观看';
- }
- } else if ($result['status_value'] == 2) { // 会员免费/单独付费
- $result['button'] = 'VIP';
- $result['button_url'] = "window.location.href = '" . url('user/Level/level_centre', ['aid' => $archivesInfo['aid']]) . "'";
- if (!empty($result['play_auth'])) {
- $result['button'] = '观看';
- }
- } else if ($result['status_value'] == 3) { // 会员付费
- // if(1 == $result['vip_status']){
- // $result['button'] = '立即购买';
- // $result['button_url'] = 'MediaOrderBuy_v878548();';
- // }else
- if (2 == $result['vip_status']) {
- $result['button'] = 'VIP';
- $result['button_url'] = "window.location.href = '" . url('user/Level/level_centre', ['aid' => $archivesInfo['aid']]) . "'";
- } else if (3 == $result['vip_status']) {
- $result['button'] = '观看';
- } else {
- $result['button'] = 'VIP付费';
- $result['button_url'] = "window.location.href = '" . url('user/Level/level_centre', ['aid' => $archivesInfo['aid']]) . "'";
- }
- // if (!empty($is_pay) && !empty($result['vip_status'])){
- // $result['button'] = '观看';
- // }
- }
- if ('观看' == $result['button']) {
- $result['button_url'] = arcurl('home/Media/view', $archivesInfo);
- }
-
- $this->success('查询成功', null, $result);
- } else {
- $this->error('非视频模型的文档!');
- }
- }
- to_index("404");
- }
-
- /**
- * 查看站内通知
- */
- public function notice_read()
- {
- $id = input('param.id/d');
- $users_id = session('users.users_id');
- $users_id = intval($users_id);
- if (!empty($id) && !empty($users_id)) {
- $count = Db::name('users_notice_read')
- ->where(['id' => $id])
- ->value("id");
- if (empty($count)) $this->error('未知错误!');
-
- //未读消息数-1
- $unread_num = Db::name('users')->where(['users_id' => $users_id])->value("unread_notice_num");
- if ($unread_num > 0) {
- $unread_num = $unread_num - 1;
- Db::name('users')->where(['users_id' => $users_id])->update(['unread_notice_num' => $unread_num]);
- }
- Db::name('users_notice_read')->where(['id' => $id])->update(['is_read' => 1]);
- $this->success('保存成功', null, ['unread_num' => $unread_num]);
- }
- }
-
- /**
- * 收藏与取消
- * @return [type] [description]
- */
- public function collect_save()
- {
- $aid = input('param.aid/d');
- if (IS_AJAX && !empty($aid)) {
-
- $users_id = session('users_id');
- if (empty($users_id)) {
- $this->error('请先登录!');
- }
-
- $row = Db::name('users_collection')->where([
- 'users_id' => $users_id,
- 'aid' => $aid,
- ])->find();
- if (empty($row)) {
- $archivesInfo = Db::name('archives')->field('aid,title,litpic,channel,typeid')->find($aid);
- if (!empty($archivesInfo)) {
- $r = Db::name('users_collection')->add([
- 'users_id' => $users_id,
- 'title' => $archivesInfo['title'],
- 'aid' => $aid,
- 'litpic' => $archivesInfo['litpic'],
- 'channel' => $archivesInfo['channel'],
- 'typeid' => $archivesInfo['typeid'],
- 'lang' => $this->home_lang,
- 'add_time' => getTime(),
- 'update_time' => getTime(),
- ]);
- if (!empty($r)) {
- Db::name('archives')->where('aid', $aid)->setInc('collection');
- $this->success('收藏成功', null, ['opt' => 'add']);
- }
- }
- } else {
- $r = Db::name('users_collection')->where([
- 'users_id' => $users_id,
- 'aid' => $aid,
- ])->delete();
- Db::name('archives')->where('aid', $aid)->setDec('collection');
- $this->success('取消成功', null, ['opt' => 'cancel']);
- }
- $this->error('收藏失败', null);
- }
- to_index("404");
- }
-
- /**
- * 判断是否收藏
- * @return [type] [description]
- */
- public function get_collection()
- {
- if (IS_AJAX) {
- $aid = input('param.aid/d');
- $users_id = session('users_id');
- $total = Db::name('users_collection')->where([
- 'aid' => $aid,
- ])->count();
- if (!empty($users_id)) {
- $count = Db::name('users_collection')->where([
- 'aid' => $aid,
- 'users_id' => $users_id,
- ])->count();
- if (!empty($count)) {
- $this->success('已收藏', null, ['total' => $total]);
- }
- }
- $this->error('未收藏', null, ['total' => $total]);
- }
- to_index("404");
- }
-
- /**
- * 保存足迹
- */
- public function footprint_save()
- {
- $aid = input('param.aid/d');
- $ajaxLogic = new \app\api\logic\AjaxLogic;
- $data = $ajaxLogic->footprint_save($aid);
- if ($data === false) {
- to_index("404");
- } else {
- $this->success('ok');
- }
- }
-
- /**
- * 签到
- * @return [type] [description]
- */
- public function signin_save()
- {
- if (IS_AJAX) {
- $users_id = session('users_id');
- if (empty($users_id)) {
- $this->error('请先登录!');
- }
- $signin_conf = getUsersConfigData('score');
- if (!$signin_conf || !isset($signin_conf['score_signin_status']) || $signin_conf['score_signin_status'] != 1) {
- $this->error('未开启签到配置!');
- }
-
- //今日签到信息
- $now_time = time();
- $today_start = mktime(0, 0, 0, date("m", $now_time), date("d", $now_time), date("Y", $now_time));
- $today_end = mktime(23, 59, 59, date("m", $now_time), date("d", $now_time), date("Y", $now_time));
- $row = Db::name('users_signin')->where(['users_id' => $users_id, 'add_time' => ['BETWEEN', [$today_start, $today_end]]])->value("id");
-
- if (!$row) {
- $r = Db::name('users_signin')->add([
- 'users_id' => $users_id,
- 'lang' => $this->home_lang,
- 'add_time' => getTime(),
- ]);
- if (!empty($r)) {
- $scores_step = $signin_conf['score_signin_score'] ?: 0;
- Db::name('users')->where(['users_id' => $users_id])->setInc('scores', $scores_step);
- $users_scores = Db::name('users')->where(['users_id' => $users_id])->value("scores");
-
- Db::name('users_score')->add([
- 'type' => 5,//每日签到
- 'users_id' => $users_id,
- 'ask_id' => 0,
- 'reply_id' => 0,
- 'score' => '+' . $scores_step,
- 'devote' => $scores_step,
- 'money' => 0.00,
- 'info' => '每日签到',
- 'lang' => $this->home_lang,
- 'add_time' => getTime(),
- 'update_time' => getTime(),
- 'current_score' => $users_scores,
- ]);
- $this->success('签到成功', null, ['scores' => $users_scores]);
- }
- $this->error('未知错误', null);
- }
- $this->error('今日已签过到', null);
- }
- to_index("404");
- }
-
- /**
- * 登录页面清除session多余文件
- */
- public function clear_session()
- {
- if (IS_AJAX_POST) {
- \think\Session::pause(); // 暂停session,防止session阻塞机制
- clear_session_file(); // 清理过期的data/session文件
- } else {
- to_index("404");
- }
- }
-
- //文章付费
- public function ajax_get_content($aid = 0)
- {
- if (empty($aid)) {
- $this->error('缺少文档id');
- }
- $artData = Db::name('archives')
- ->alias('a')
- ->field('a.title,a.restric_type,a.arc_level_id,a.users_price,a.no_vip_pay,a.add_time,b.content,b.content_ey_m')
- ->join('article_content b', 'a.aid = b.aid')
- ->where('a.aid', $aid)
- ->find();
- if (isMobile() && !empty($artData['content_ey_m'])) {
- $artData['content'] = $artData['content_ey_m'];
- }
-
- $artData['arc_level_value'] = 0;
- if (0 < $artData['arc_level_id']) {
- $artData['arc_level_value'] = Db::name('users_level')->where(['level_id' => $artData['arc_level_id']])->value('level_value');
- }
-
- if (empty($artData['restric_type'])) { // 免费
- $result['display'] = 0; // 1-显示购买 0-不显示
- $result['content'] = $artData['content'];
- } else {
- /*预览内容*/
- $free_content = '';
- $pay_data = Db::name('article_pay')->field('part_free,free_content')->where('aid', $aid)->find();
- if (!empty($pay_data['part_free'])) {
- $free_content = !empty($pay_data['free_content']) ? $pay_data['free_content'] : '';
- }
- /*end*/
- $users_id = session('users_id');
- !empty($users_id) && $UsersData = GetUsersLatestData();
-
- $result['content'] = $free_content;
- $result['users_price'] = get_discount_price($UsersData['level_discount'], $artData['users_price']);
-
- if (1 == $artData['restric_type']) { // 付费
- $result['display'] = 1; // 1-显示购买 0-不显示
-
- if (!empty($users_id)) {
- $is_pay = Db::name('article_order')->where(['users_id' => $users_id, 'order_status' => 1, 'product_id' => $aid])->find();
- // 已经购买
- if (!empty($is_pay)) {
- $result['display'] = 0; // 1-显示购买 0-不显示
- $result['content'] = $artData['content'];
- }
- }
- }elseif (2 == $artData['restric_type']){ //指定会员 || 非会员付费
- $result['vipDisplay'] = 1;// 1-显示会员限制 0-不显示
-
- if (!empty($users_id)) {
- if ($UsersData['level_value'] >= $artData['arc_level_value']){
- $result['vipDisplay'] = 0;// 1-显示会员限制 0-不显示
- $result['content'] = $artData['content'];
- }else if (!empty($artData['no_vip_pay'])){
- $is_pay = Db::name('article_order')->where(['users_id' => $users_id, 'order_status' => 1, 'product_id' => $aid])->find();
- // 已经购买
- if (!empty($is_pay)) {
- $result['vipDisplay'] = 0; // 1-显示购买 0-不显示
- $result['content'] = $artData['content'];
- }else{
- if (getCmsVersion() < 'v1.6.2') {
- $result['display'] = 1; // 1-显示购买 0-不显示
- } else {
- $result['display'] = 0; // 1-显示购买 0-不显示
- $result['vipDisplay'] = 1;// 1-显示会员限制 0-不显示
- }
- }
- }
- }
- }elseif (3 == $artData['restric_type']){ //指定会员付费
- $result['vipDisplay'] = 1;// 1-显示会员限制 0-不显示
-
- $is_pay = Db::name('article_order')->where(['users_id' => $users_id, 'order_status' => 1, 'product_id' => $aid])->find();
- if ($UsersData['level_value'] >= $artData['arc_level_value'] && !empty($is_pay)){
- $result['vipDisplay'] = 0;// 1-显示会员限制 0-不显示
- $result['content'] = $artData['content'];
- }else if (empty($is_pay)){
- if (getCmsVersion() < 'v1.6.2') {
- $result['display'] = 1; // 1-显示购买 0-不显示
- } else {
- $result['display'] = 0; // 1-显示购买 0-不显示
- $result['vipDisplay'] = 1;// 1-显示会员限制 0-不显示
- }
- if ($UsersData['level_value'] >= $artData['arc_level_value']){
- if (isMobile()){
- $result['buy_onclick'] = "ey_article_v968479({$aid});";//第一种跳转页面支付
- }else {
- $result['buy_onclick'] = "ArticleBuyNow({$aid});";//第二种弹框页支付
- }
- }
- }
- }
- }
-
- $result['content'] = htmlspecialchars_decode($result['content']);
- $titleNew = !empty($artData['title']) ? $artData['title'] : '';
- $result['content'] = img_style_wh($result['content'], $titleNew);
- $result['content'] = handle_subdir_pic($result['content'], 'html');
- if (is_dir('./weapp/Linkkeyword')) {
- $LinkkeywordModel = new \weapp\Linkkeyword\model\LinkkeywordModel();
- if (method_exists($LinkkeywordModel, 'handle_content')) {
- $result['content'] = $LinkkeywordModel->handle_content($result['content']);
- }
- }
-
- $this->success('success', null, $result);
- }
-
- //获取第三方上传的域名
- public function get_third_domain()
- {
- $weappList = \think\Db::name('weapp')->field('code,data,status,config')->where([
- 'status' => 1,
- ])->cache(true, EYOUCMS_CACHE_TIME, 'weapp')
- ->getAllWithIndex('code');
- $third_domain = '';
- if (!empty($weappList['Qiniuyun']) && 1 == $weappList['Qiniuyun']['status']) {
- // 七牛云
- $qnyData = json_decode($weappList['Qiniuyun']['data'], true);
- $third_domain = $qnyData['domain'];
- } else if (!empty($weappList['AliyunOss']) && 1 == $weappList['AliyunOss']['status']) {
- // 到OSS
- $ossData = json_decode($weappList['AliyunOss']['data'], true);
- $third_domain = $ossData['domain'];
- } else if (!empty($weappList['Cos']) && 1 == $weappList['Cos']['status']) {
- // 同步图片到COS
- $CosData = json_decode($weappList['Cos']['data'], true);
- $third_domain = $CosData['domain'];
- }
- $this->success('success', null, $third_domain);
- }
-
- /**
- * 获取表单数据信息
- */
- public function form_submit()
- {
- $form_id = input('post.form_id/d');
- if (IS_POST && !empty($form_id)) {
- $post = input('post.');
- $ip = clientIP();
-
- /*提交间隔限制*/
- $channel_guestbook_interval = tpSetting('channel_guestbook.channel_guestbook_interval');
- $channel_guestbook_interval = is_numeric($channel_guestbook_interval) ? intval($channel_guestbook_interval) : 60;
- if (0 < $channel_guestbook_interval) {
- $map = array(
- 'ip' => $ip,
- 'form_id' => $form_id,
- 'lang' => $this->home_lang,
- 'add_time' => array('gt', getTime() - $channel_guestbook_interval),
- );
- $count = Db::name('form_list')->where($map)->count('list_id');
- if ($count > 0) {
- if ($this->home_lang == 'cn') {
- $msg = '同一个IP在' . $channel_guestbook_interval . '秒之内不能重复提交!';
- } else if ($this->home_lang == 'zh') {
- $msg = '同一個IP在' . $channel_guestbook_interval . '秒之內不能重複提交!';
- } else {
- $msg = 'The same IP cannot be submitted repeatedly within ' . $channel_guestbook_interval . ' seconds!';
- }
- $this->error($msg);
- }
- }
- /*end*/
-
- $come_url = input('post.come_url/s');
- $parent_come_url = input('post.parent_come_url/s');
- $come_url = !empty($parent_come_url) ? $parent_come_url : $come_url;
- $come_from = input('post.come_from/s');
- $city = "";
- $newData = array(
- 'form_id' => $form_id,
- 'ip' => $ip,
- 'aid' => !empty($post['aid']) ? $post['aid'] : 0,
- 'come_from' => $come_from,
- 'come_url' => $come_url,
- 'city' => $city,
- 'lang' => $this->home_lang,
- 'add_time' => getTime(),
- 'update_time' => getTime(),
- );
- $data = array_merge($post, $newData);
- // 数据验证
- $token = '__token__';
- foreach ($post as $key => $val) {
- if (preg_match('/^__token__/i', $key)) {
- $token = $key;
- break;
- }
- }
- $rule = [
- 'form_id' => 'require|token:' . $token,
- ];
- $message = [
- 'form_id.require' => '表单缺少标签属性{$field.hidden}',
- ];
- $validate = new \think\Validate($rule, $message);
- if (!$validate->batch()->check($data)) {
- $error = $validate->getError();
- $error_msg = array_values($error);
- $this->error($error_msg[0]);
- } else {
- $formlistRow = [];
- /*处理是否重复表单数据的提交*/
- $formdata = $data;
- foreach ($formdata as $key => $val) {
- if (in_array($key, ['form_id', 'ip', 'aid']) || preg_match('/^field_(\d+)$/i', $key)) {
- continue;
- }
- unset($formdata[$key]);
- }
- $md5data = md5(serialize($formdata));
- $data['md5data'] = $md5data;
- $formlistRow = Db::name('form_list')->field('list_id')->where(['md5data' => $md5data])->find();
- /*--end*/
- if (empty($formlistRow)) { // 非重复表单的才能写入数据库
- $list_id = Db::name('form_list')->insertGetId($data);
- if ($list_id > 0) {
- $this->saveFormValue($list_id, $form_id, $post);
- }
- } else {
- // 存在重复数据的表单,将在后台显示在最前面
- $list_id = $formlistRow['list_id'];
- Db::name('form_list')->where('list_id', $list_id)->update([
- 'is_read' => 0,
- 'add_time' => getTime(),
- 'update_time' => getTime(),
- ]);
- }
-
- if ($this->home_lang == 'cn') {
- $msg = '操作成功';
- } else if ($this->home_lang == 'zh') {
- $msg = '操作成功';
- } else {
- $msg = 'success';
- }
- $this->success($msg, null, ['form_id' => $form_id, 'list_id' => $list_id]);
- }
- }
-
- $this->error('表单缺少标签属性{$field.hidden}');
- }
-
- /**
- * 给指定报名信息添加表单值到 form_value
- * @param int $list_id 报名id
- * @param int $form_id 表单id
- */
- private function saveFormValue($list_id, $form_id, $post)
- {
- /*上传图片或附件*/
- $arr = explode(',', config('global.image_ext'));
- foreach ($_FILES as $fileElementId => $file) {
- try {
- if (!empty($file['name']) && !is_array($file['name'])) {
- $ext = pathinfo($file['name'], PATHINFO_EXTENSION);
- if (in_array($ext, $arr)) {
- $uplaod_data = func_common($fileElementId, 'allimg');
- } else {
- $uplaod_data = func_common_doc($fileElementId, 'files');
- }
- if (0 == $uplaod_data['errcode']) {
- $post[$fileElementId] = $uplaod_data['img_url'];
- } else {
- // return $uplaod_data['errmsg'];
- $post[$fileElementId] = '';
- }
- }
- } catch (\Exception $e) {
- }
- }
- /*end*/
- $notify_content_arr = []; // 添加站内信所需参数
- $send_content_str = ""; //发送短信内容
- $field_list = Db::name("form_field")->where(['form_id' => $form_id])->getField("field_id,field_name,field_type");
- // post 提交的属性 以 field_id _ 和值的 组合为键名
- foreach ($post as $key => $val) {
- if (!strstr($key, 'field_'))
- continue;
- $val = addslashes(htmlspecialchars(strip_tags($val)));
- $field_id = str_replace('field_', '', $key);
- $field_id = intval($field_id);
- is_array($val) && $val = implode(',', $val);
- $val = trim($val);
- $field_value = stripslashes(filter_line_return($val, '。'));
- $adddata = array(
- 'form_id' => $form_id,
- 'list_id' => $list_id,
- 'field_id' => $field_id,
- 'field_value' => $field_value,
- 'add_time' => getTime(),
- 'update_time' => getTime(),
- );
- Db::name('form_value')->add($adddata);
- $field_value = get_form_read_value($field_value, $field_list[$field_id]['field_type'], true);
- array_push($notify_content_arr, $field_value); //添加站内信数据
- $send_content_str .= $field_list[$field_id]['field_name'] . ':' . $field_value . '<br/>';
-
- }
- /*发送站内信给后台*/
- SendNotifyMessage($notify_content_arr, 1, 1, 0);
- /* END */
- /* 发送短信 */
- $is_open = Db::name('smtp_tpl')->where(['send_scene' => 1, 'lang' => $this->home_lang])->value('is_open');
- $smtp_config = tpCache('smtp');
- if (empty($is_open) || empty($smtp_config['smtp_user']) || empty($smtp_config['smtp_pwd'])) {
- return false;
- }
- $send_email_scene = config('send_email_scene');
- $scene = $send_email_scene[1]['scene'];
- $web_name = tpCache('web.web_name'); //title
- $web_name .= "-表单消息";
- $html = "<p style='text-align: left;'>{$web_name}</p><p style='text-align: left;'>{$send_content_str}</p>";
- if (isMobile()) {
- $html .= "<p style='text-align: left;'>——来源:移动端</p>";
- } else {
- $html .= "<p style='text-align: left;'>——来源:电脑端</p>";
- }
- // 发送邮件
- $res = send_email(null, null, $html, $scene);
- /* END */
- return $res;
- }
-
- //下载付费
- public function get_download($aid = 0)
- {
- if (empty($aid)) {
- $this->error('缺少文档id');
- }
- $artData = Db::name('archives')
- ->where('aid', $aid)
- ->find();
-
- $artData['arc_level_value'] = 0;
- if (0 < $artData['arc_level_id']) {
- $artData['arc_level_value'] = Db::name('users_level')->where(['level_id' => $artData['arc_level_id']])->value('level_value');
- }
-
- $users_id = session('users_id');
- $UsersData = empty($users_id) ? [] : GetUsersLatestData();
-
- $canDownload = 0;
- $buyVip = 0;
- $msg = '';
- $download_tips = '';
- if (empty($artData['restric_type'])) { // 免费
- $canDownload = 1;
- } else if (1 == $artData['restric_type']) { // 付费
- // 查询是否已购买
- $where = [
- 'order_status' => 1,
- 'product_id' => intval($aid),
- 'users_id' => $users_id
- ];
- $count = Db::name('download_order')->where($where)->count();
- if (!empty($count)) {
- $canDownload = 1;
- $download_tips = '您已购买,可直接下载';
- }
- } else if (2 == $artData['restric_type']) { // 会员专享
- if ($UsersData['level_value'] >= $artData['arc_level_value']) {
- $canDownload = 1;
- $download_tips = "您已是{$UsersData['level_name']},可直接下载";
- } else {
- if (0 == $artData['no_vip_pay']) {
- $buyVip = 1;
- } else {
- $where = [
- 'order_status' => 1,
- 'product_id' => intval($aid),
- 'users_id' => $users_id
- ];
- $count = Db::name('download_order')->where($where)->count();
- if (!empty($count)) {
- $canDownload = 1;
- $download_tips = '您已购买,可直接下载';
- }
- }
- }
- } else if (3 == $artData['restric_type']) { // 会员付费
- if ($UsersData['level_value'] >= $artData['arc_level_value']) {
- // 查询是否已购买
- $where = [
- 'order_status' => 1,
- 'product_id' => intval($aid),
- 'users_id' => $users_id
- ];
- $count = Db::name('download_order')->where($where)->count();
- if (!empty($count)) {
- $canDownload = 1;
- $download_tips = '您已购买,可直接下载';
- }
- } else {
- $buyVip = 1;
- }
- }
- $result['canDownload'] = $canDownload;
- $result['download_tips'] = $download_tips;
-
- if (1 == $buyVip) {
- $result['onclick'] = 'BuyVipClick();';
- } else {
- if (isMobile()) {
- $result['onclick'] = 'ey_download_v866225(' . $aid . ');';//第一种跳转页面支付
- } else {
- $result['onclick'] = 'DownloadBuyNow1655866225(' . $aid . ');';//第二种弹框页支付
- }
- }
-
-
- $this->success('success', null, $result);
- }
-
- public function get_user_download($aid = 0)
- {
- if (empty($aid)) {
- $this->error('缺少文档id');
- }
- /*$artData = Db::name('archives')
- ->where('aid', $aid)
- ->find();
-
- $artData['arc_level_value'] = 0;
- if (0 < $artData['arc_level_id']) {
- $artData['arc_level_value'] = Db::name('users_level')->where(['level_id' => $artData['arc_level_id']])->value('level_value');
- }*/
-
- //dump($artData);
-
-
- $users_id = session('users_id');
-
- if(empty($users_id)){
- $this->error('请先登录!', '/?m=user&c=Users&a=login', []);
- }
-
-
- //已经登录,注册时已填写信息
- $art = Db::name('archives')
- ->where('aid', $aid)
- ->find();
-
- $artData = Db::name('zczygz_content')->where('aid', $aid)
- ->find();
- if(empty($artData) || empty($artData['down'])){
- $this->error('文档不存在,请联系客服!', '', []);
- }
-
- //查询下载记录
- // 当前时间减去10分钟
- $time_10_minutes_ago = strtotime("-1 minutes");
- // 格式化时间为Y-m-d H:i:s
- $formatted_time = date("Y-m-d H:i:s", $time_10_minutes_ago);
-
- $down_log = Db::name('users_down')
- ->where('add_time','> time',$formatted_time)
- ->where(['users_id'=>$users_id,'aid' => $aid])->count();
- if(!empty($down_log) && $down_log >= 1){
- $this->error('不允许频繁下载,点击下载后请等待一分钟再重试!', '', []);
- }else{
- $lc_time = date("Y-m-d 00:00:01", time());
- //可以再限制 每天只能下载几次
- $down_log = Db::name('users_down')
- ->where('add_time','> time',$lc_time)
- ->where(['users_id'=>$users_id,'aid' => $aid])->count();
- if(!empty($down_log) && $down_log >= 10){
- $this->error('同一文件今日最多下载10次!', '', []);
- }
- }
-
- /*
- * 执行下载记录 生成 每条记录有效时间 1小时
- * 过后得重新 点击下载 生成新的下载链接
- * 每天 同一文档 最多下载10次
- * 每条下载记录 最多下载3次 就无效
- */
- // 启动事务
- $run = 0;
- Db::startTrans();
- try{
- $expire_time = strtotime("+60 minutes");
- //记录下载数,二次下载也记录
- $inser_log = [
- 'users_id' => $users_id,
- 'aid' => $aid,
- 'channel' => 103,
- 'typeid' => $art['typeid'],
- 'title' => $art['title'],
- 'add_time' => time(),
- 'update_time' => time(),
- 'expire_time' => $expire_time,
- 'num' => 0
- ];
- $log_id = Db::name('users_down')->insertGetId($inser_log);
- if((int)$log_id > 0){
- //正常得到ID
- }else{
- $run = 1;
- }
-
- //下载数
- $op = Db::name('archives')->where('aid', $aid)->setInc('downcount');
- if((int)$op !== 1){
- $run = 2;
- }
-
- if($run === 0){
- $error_msg = '提交';
- // 提交事务
- Db::commit();
- }else{
- Db::rollback();
- }
- } catch (\Exception $e) {
- $run = 3;
- // 回滚事务
- Db::rollback();
- }
-
- if($run > 0){
- $this->error('事务执行异常!', '', ['event'=>$run,'log'=>$error_msg]);
- }else{
- //
- $result = [
- //'down' => $artData['down']
- 'down' => 'https://www.zc10000.com/api/diyajax/downfile?id='.$log_id
- ];
- $this->success('下载请求成功', null, $result);
- }
- }
-
- public function get_user_like($aid = 0){
-
- if (empty($aid)) {
- $this->error('缺少文档id');
- }
-
- $users_id = session('users_id');
-
- if(empty($users_id)){
- $this->error('请先登录!', '/?m=user&c=Users&a=login', []);
- }
-
- //已经登录,注册时已填写信息
- $art = Db::name('archives')
- ->where('aid', $aid)
- ->find();
-
- if(empty($art)){
- $this->error('文档不存在,请联系客服!', '', []);
- }
-
- /* //查询下载记录
- // 当前时间减去10分钟
- $time_10_minutes_ago = strtotime("-5 seconds");
- // 格式化时间为Y-m-d H:i:s
- $formatted_time = date("Y-m-d H:i:s", $time_10_minutes_ago);
-
- $down_log = Db::name('users_like')
- ->where('update_time','> time',$formatted_time)
- ->where(['users_id'=>$users_id,'aid' => $aid])->count();
- if(!empty($down_log) && $down_log >= 1){
- $this->error('不允许频繁点赞或取消,请等待5s后重试!', '', []);
- }*/
-
- // 启动事务
- $run = 0;
- Db::startTrans();
- try{
- //记录下载数,二次下载也记录
- $row = Db::name('users_like')
- ->where(['users_id'=>$users_id,'aid' => $aid])->find();
- if(!empty($row)){
- //更新
- $inser_log = [
- 'is_del' => (int)$row['is_del']===0?1:0,
- 'update_time' => time(),
- ];
- $log_id = Db::name('users_like')
- ->where(['users_id' => $users_id,'aid' => $aid])
- ->update($inser_log);
- if((int)$log_id !== 1){
- $run = 1;
- }
- }else{
- //新增
- $inser_log = [
- 'users_id' => $users_id,
- 'aid' => $aid,
- 'channel' => 103,
- 'typeid' => $art['typeid'],
- 'title' => $art['title'],
- 'add_time' => time(),
- 'update_time' => time(),
- ];
- $log_id = Db::name('users_like')->insert($inser_log);
- if((int)$log_id !== 1){
- $run = 1;
- }
- }
-
- if((int)$row['is_del'] === 1 || empty($row)){
- //点赞数
- $op = Db::name('archives')->where('aid', $aid)->setInc('likecount');
- if((int)$op !== 1){
- $run = 2;
- }
- $msg = '点赞成功';
- $type = 1;
- $likecount = $art['likecount'] + 1;
- }else{
- //(取消点赞)
- $msg = '取消成功';
- $type = 0;
- $likecount = $art['likecount'];
- if((int)$art['likecount'] > 0){
- $op = Db::name('archives')->where('aid', $aid)->setDec('likecount');
- if((int)$op !== 1){
- $run = 2;
- }
- $likecount = $art['likecount'] - 1;
- }
- }
-
- if($run === 0){
- $error_msg = '提交';
- // 提交事务
- Db::commit();
- }else{
- Db::rollback();
- }
- } catch (\Exception $e) {
- $run = 3;
- // 回滚事务
- Db::rollback();
- }
-
- if($run > 0){
- $this->error('事务执行异常!', '', ['event'=>$run,'log'=>$error_msg]);
- }else{
- //
- $result = [
- 'likecount' => $likecount,
- 'log' => $down_log,
- 'type' => $type
- ];
- $this->success($msg, null, $result);
- }
- }
-
- public function get_user_collect($aid = 0){
-
- if (empty($aid)) {
- $this->error('缺少文档id');
- }
-
- $users_id = session('users_id');
-
- if(empty($users_id)){
- $this->error('请先登录!', '/?m=user&c=Users&a=login', []);
- }
-
- //已经登录,注册时已填写信息
- $art = Db::name('archives')
- ->where('aid', $aid)
- ->find();
-
- if(empty($art)){
- $this->error('文档不存在,请联系客服!', '', []);
- }
-
- /* //查询下载记录
- // 当前时间减去10分钟
- $time_10_minutes_ago = strtotime("-5 seconds");
- // 格式化时间为Y-m-d H:i:s
- $formatted_time = date("Y-m-d H:i:s", $time_10_minutes_ago);
-
- $down_log = Db::name('users_collection')
- ->where('update_time','> time',$formatted_time)
- ->where(['users_id'=>$users_id,'aid' => $aid])->count();
- if(!empty($down_log) && $down_log >= 1){
- $this->error('不允许频繁点赞或取消,请等待5s后重试!', '', []);
- }*/
-
- // 启动事务
- $run = 0;
- Db::startTrans();
- try{
- //记录下载数,二次下载也记录
- $row = Db::name('users_collection')
- ->where(['users_id'=>$users_id,'aid' => $aid])->find();
- if(!empty($row)){
- //更新
- $inser_log = [
- 'is_del' => (int)$row['is_del']===0?1:0,
- 'update_time' => time(),
- ];
- $log_id = Db::name('users_collection')
- ->where(['users_id' => $users_id,'aid' => $aid])
- ->update($inser_log);
- if((int)$log_id !== 1){
- $run = 1;
- }
- }else{
- //新增
- $inser_log = [
- 'users_id' => $users_id,
- 'aid' => $aid,
- 'channel' => 103,
- 'typeid' => $art['typeid'],
- 'title' => $art['title'],
- 'add_time' => time(),
- 'update_time' => time(),
- ];
- $log_id = Db::name('users_collection')->insert($inser_log);
- if((int)$log_id !== 1){
- $run = 1;
- }
- }
-
- if((int)$row['is_del'] === 1 || empty($row)){
- //点赞数
- $op = Db::name('archives')->where('aid', $aid)->setInc('collection');
- if((int)$op !== 1){
- $run = 2;
- }
- $msg = '收藏成功';
- $type = 1;
- $likecount = $art['collection'] + 1;
- }else{
- //(取消点赞)
- $msg = '取消成功';
- $type = 0;
- $likecount = $art['collection'];
- if((int)$art['collection'] > 0){
- $op = Db::name('archives')->where('aid', $aid)->setDec('collection');
- if((int)$op !== 1){
- $run = 2;
- }
- $likecount = $art['collection'] - 1;
- }
- }
-
- if($run === 0){
- $error_msg = '提交';
- // 提交事务
- Db::commit();
- }else{
- Db::rollback();
- }
- } catch (\Exception $e) {
- $run = 3;
- // 回滚事务
- Db::rollback();
- }
-
- if($run > 0){
- $this->error('事务执行异常!', '', ['event'=>$run,'log'=>$error_msg]);
- }else{
- //
- $result = [
- 'collection' => $likecount,
- 'log' => $down_log,
- 'type' => $type
- ];
- $this->success($msg, null, $result);
- }
- }
-
- public function sendNotice()
- {
- $users_id = input('post.users_id/d');
- $order_id = input('post.order_id/d');
- $send_scene = input('post.send_scene/d');
- if (7 == $send_scene) {
- $params = [
- 'users_id' => $users_id,
- 'result_id' => $order_id,
- ];
- eyou_send_notice($send_scene, $params);
- }
- }
-
- public function defaultAuthorize()
- {
- // 管理员ID
- $admin_id = input('param.admin_id');
- if (empty($admin_id)) $this->error('获取用户信息错误,请重新生成二维码并扫码!');
-
- // 公众号配置
- $conf_wechat = tpSetting("OpenMinicode.conf_wechat");
- $conf_wechat = !empty($conf_wechat) ? json_decode($conf_wechat, true) : [];
-
- // 回调链接
- $url = urlencode(url('api/Ajax/defaultGetWechatUserinfo', ['admin_id' => $admin_id], true, true));
-
- // 静默授权链接
- $redirect = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" . strval($conf_wechat['appid']) . "&redirect_uri=" . $url . "&response_type=code&scope=snsapi_base&state=eyoucms&#wechat_redirect";
-
- // 重定向链接
- $this->redirect($redirect);
- }
-
- public function defaultGetWechatUserinfo()
- {
- // 通过微信code获取用户access_token
- $code = input('param.code/s', '');
- $admin_id = input('param.admin_id/d', 0);
- if (empty($code) || empty($admin_id)) $this->error('获取用户信息错误,请重新生成二维码并扫码!');
-
- // 公众号配置
- $conf_wechat = tpSetting("OpenMinicode.conf_wechat");
- $conf_wechat = !empty($conf_wechat) ? json_decode($conf_wechat, true) : [];
-
- // 获取微信用户信息
- $url = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid=' . strval($conf_wechat['appid']) . '&secret=' . strval($conf_wechat['appsecret']) . '&code=' . $code . '&grant_type=authorization_code';
- $result = json_decode(httpRequest($url), true);
- if (empty($result) || (!empty($result['errcode']) && !empty($result['errmsg']))) $this->error('Code已过期,请重新生成二维码并扫码!');
-
- // 获取成功则进行关联绑定
- if (!empty($result['openid']) && !empty($admin_id)) {
- $update = [
- 'wechat_open_id' => $result['openid'],
- 'update_time' => getTime(),
- ];
- Db::name('admin')->where('admin_id', $admin_id)->update($update);
- }
-
- // 查询用户是否关注了公众号
- $tokenData = get_wechat_access_token();
- if (!empty($tokenData)) {
- $result['openid'] = Db::name('admin')->where('admin_id', $admin_id)->getField('wechat_open_id');
- $userInfo = 'https://api.weixin.qq.com/cgi-bin/user/info?access_token=' . $tokenData['access_token'] . '&openid=' . $result['openid'] . '&lang=zh_CN';
- $userInfo = json_decode(httpRequest($userInfo), true);
- // 关注则执行关联关注
- if (!empty($userInfo['subscribe']) && $userInfo['openid'] == $result['openid']) {
- $update = [
- 'wechat_followed' => 1,
- 'update_time' => getTime(),
- ];
- Db::name('admin')->where('admin_id', $admin_id)->update($update);
- // 显示成功信息
- $this->redirect(url('api/Ajax/showSuccessInfo', ['info' => '您已关注过,绑定成功!'], true, true));
- }
- } else {
- $this->error($tokenData['msg']);
- }
-
- // 用户尚未关注公众号,显示公众号二维码
- $this->redirect(url('api/Ajax/showWechatQrCode', ['admin_id' => $admin_id], true, true));
- }
-
- public function showSuccessInfo()
- {
- $info = input('param.info/s', '');
- echo '<div style="color: red; text-align: center; padding-top: 50%; font-size: 60px;">' . $info . '</div>';
- exit;
- }
-
- public function showWechatQrCode()
- {
- $admin_id = input('param.admin_id/d', 0);
- if (empty($admin_id)) $this->error('获取用户信息错误,请重新生成二维码并扫码!');
-
- // 公众号配置
- $conf_wechat = tpSetting("OpenMinicode.conf_wechat");
- $conf_wechat = !empty($conf_wechat) ? json_decode($conf_wechat, true) : [];
-
- // 生成图片名称及径路
- $qrcodeName = 'wechat_' . md5($admin_id) . ".jpg";
- $qrcodePath = UPLOAD_PATH . 'system/wechat_followed/' . $admin_id . '/';
- $qrcodeUrl = $qrcodePath . $qrcodeName;
-
- // 检测图片是否存在
- if (file_exists($qrcodeUrl)) {
- $showQrcode = request()->domain() . ROOT_DIR . '/' . $qrcodeUrl;
- echo '<div style="color: red; text-align: center; padding-top: 25%;"> <img src=' . $showQrcode . ' style="width: 90%;"> <div style="font-size: 40px;"> 绑定成功,请长按二维码识别公众号并关注公众号 </div> </div>';
- exit;
- }
-
- // 获取公众号永久二维码
- if (!empty($conf_wechat['appid'])) {
- $tokenData = get_wechat_access_token();
- if (!empty($tokenData)) {
- // 调用微信接口,返回生成二维码的ticket参数
- $url = 'https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=' . $tokenData['access_token'];
- // 永久二维码
- $data = '{"action_name": "QR_LIMIT_STR_SCENE", "action_info": {"scene": {"scene_str": "' . $admin_id . '"}}}';
- // 调用接口获取数据,解析返回的数据
- $ticketData = json_decode(httpRequest($url, 'POST', $data), true);
- if (empty($ticketData['ticket'])) $this->error('数据错误,请重新生成二维码并扫码!');
-
- // 调用微信接口,返回已生成二维码图片资源
- $ticket = urlencode($ticketData['ticket']);
- // 调用接口获取图片资源
- $url = 'https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=' . $ticket;
- $result = httpRequest($url, 'GET');
-
- // 创建指定文件夹
- tp_mkdir($qrcodePath);
- // 拼装完成图片路径
- $qrcodeUrl = $qrcodePath . "/" . $qrcodeName;
- // 将资源加载到图片并返回
- if (@file_put_contents($qrcodeUrl, $result)) {
- $showQrcode = request()->domain() . ROOT_DIR . '/' . $qrcodeUrl;
- echo '<div style="color: red; text-align: center; padding-top: 25%;"> <img src=' . $showQrcode . ' style="width: 90%;"> <div style="font-size: 40px;"> 绑定成功,请长按二维码识别公众号并关注公众号 </div> </div>';
- exit;
- }
- } else {
- $this->error($tokenData['msg']);
- }
- }
- }
-
- }
|