No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Ajax.php 117KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803
  1. <?php
  2. /**
  3. * 易优CMS
  4. * ============================================================================
  5. * 版权所有 2016-2028 海口快推科技有限公司,并保留所有权利。
  6. * 网站地址: http://www.eyoucms.com
  7. * ----------------------------------------------------------------------------
  8. * 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
  9. * ============================================================================
  10. * Author: 小虎哥 <1105415366@qq.com>
  11. * Date: 2018-4-3
  12. */
  13. namespace app\api\controller;
  14. use think\Db;
  15. class Ajax extends Base
  16. {
  17. /*
  18. * 初始化操作
  19. */
  20. public function _initialize()
  21. {
  22. parent::_initialize();
  23. }
  24. public function multistation()
  25. {
  26. $token = input('param.token/s');
  27. $auth_code = msubstr($token, 6, 32);
  28. $request_time = msubstr($token, 38, 10);
  29. $querystr = msubstr($token, 48, strlen($token));
  30. $querystr = mchStrCode($querystr, 'DECODE', $auth_code);
  31. $verify_content = preg_replace('/^(.*)-#eyou#([\w\-]+)#cms#-(.*)$/i', '${2}', $querystr);
  32. $file = ROOT_PATH . "EY_{$verify_content}.txt";
  33. $_ajax = input('param._ajax/d');
  34. if (file_exists($file)) {
  35. $fp = fopen($file, 'r');
  36. $file_content = fread($fp, filesize($file));
  37. fclose($fp);
  38. if (!empty($file_content) && $file_content == $verify_content) {
  39. $arr = explode("-#eyou#{$verify_content}#cms#-", $querystr);
  40. $user_name = empty($arr[0]) ? '' : mchStrCode($arr[0], 'DECODE', $auth_code);
  41. $password = empty($arr[1]) ? '' : mchStrCode($arr[1], 'DECODE', $auth_code);
  42. $admin_info = Db::name('admin')->where(['user_name'=>$user_name])->find();
  43. if (empty($admin_info)) {
  44. $this->error('登录失败(账号/密码错误)');
  45. }
  46. $password = func_encrypt($password, true, pwd_encry_type($admin_info['password']));
  47. if ($password != $admin_info['password']) {
  48. $this->error('登录失败(账号/密码错误)');
  49. } else if (empty($admin_info['status'])) {
  50. $this->error('登录失败(账号已禁用)');
  51. }
  52. $opt = input('param.opt/s');
  53. if ('push_archives' == $opt) { // 群发文档
  54. $this->multistation_push_archives('add');
  55. } else if ('edit_archives' == $opt) { // 编辑文档
  56. $this->multistation_push_archives('edit');
  57. } else if ('del_archives' == $opt) { // 删除文档
  58. $this->multistation_del_archives();
  59. } else { // 登录
  60. $third_type = '';
  61. $thirdata = login_third_type();
  62. if ('EyouGzhLogin' == $thirdata['type']) {
  63. $openid = Db::name('admin_wxlogin')->where(['admin_id'=>$admin_info['admin_id'], 'type'=>1])->value('openid');
  64. if (!empty($openid)) {
  65. $third_type = 'EyouGzhLogin';
  66. }
  67. } else if ('WechatLogin' == $thirdata['type']) {
  68. $openid = Db::name('admin_wxlogin')->where(['admin_id'=>$admin_info['admin_id'], 'type'=>2])->value('openid');
  69. if (!empty($openid)) {
  70. $third_type = 'WechatLogin';
  71. }
  72. }
  73. $admin_info = adminLoginAfter($admin_info['admin_id'], $this->session_id, $third_type);
  74. adminLog('后台登录(站群快捷管理)');
  75. session('isset_author', null); // 内置勿动
  76. $web_adminbasefile = tpCache('global.web_adminbasefile');
  77. $web_adminbasefile = !empty($web_adminbasefile) ? $web_adminbasefile : $this->root_dir.'/login.php';
  78. if (stristr($web_adminbasefile, 'index.php')) {
  79. $baseFile = explode('/', request()->baseFile());
  80. $web_adminbasefile = end($baseFile);
  81. $web_adminbasefile = $this->root_dir.'/'.$web_adminbasefile;
  82. }
  83. // $this->redirect($web_adminbasefile);
  84. $this->success('正在登录', $web_adminbasefile);
  85. }
  86. } else {
  87. if (empty($_ajax)) {
  88. $this->error('验证文件失败,请重新按照教程操作');
  89. }
  90. }
  91. }
  92. if (!empty($_ajax)) {
  93. $data = [
  94. 'code' => 0,
  95. 'msg' => '验证文件失败,请重新按照教程操作',
  96. ];
  97. respose($data);
  98. } else {
  99. to_index("404");
  100. }
  101. }
  102. private function multistation_push_archives($opt = 'add')
  103. {
  104. $data = [
  105. 'push_code' => 0,
  106. 'push_msg' => '发布失败',
  107. ];
  108. $post = input('post.');
  109. $archivesInfo = empty($post['archives']) ? '' : json_decode(base64_decode($post['archives']), true);
  110. // @file_put_contents(ROOT_PATH . "/log.txt", date("Y-m-d H:i:s") . " " . var_export($archivesInfo, true) . "\r\n", FILE_APPEND);
  111. if (!empty($archivesInfo['litpic']) && !empty($archivesInfo['is_syn_local'])) {
  112. $ret_litpic = saveRemote($archivesInfo['litpic'],'allimg');
  113. $ret_litpic = json_decode($ret_litpic,true);
  114. $archivesInfo['litpic'] = empty($ret_litpic['url']) ? $archivesInfo['litpic'] : $ret_litpic['url'];
  115. }
  116. $archivesInfo['update_time'] = getTime();
  117. // $litpic_base64 = empty($post['litpic_base64']) ? '' : $post['litpic_base64'];
  118. $arctypeInfo = Db::name('arctype')->where(['id'=>intval($archivesInfo['typeid'])])->find();
  119. if (empty($arctypeInfo)) {
  120. $data['push_msg'] = '网站栏目不存在';
  121. }
  122. $channeltypeInfo = Db::name('channeltype')->where(['id'=>$archivesInfo['channel']])->find();
  123. $arctypeInfo['typeurl'] = typeurl("home/{$channeltypeInfo['ctl_name']}/lists", $arctypeInfo, true, true);
  124. if ('add' == $opt) {
  125. $archivesInfo['add_time'] = getTime();
  126. $r = $aid = Db::name('archives')->insertGetId($archivesInfo);
  127. } else {
  128. $aid = $archivesInfo['aid'];
  129. $r = Db::name('archives')->where(['aid' => $aid])->update($archivesInfo);
  130. }
  131. if ($r !== false) {
  132. //内容远程图片本地化
  133. if (!empty($archivesInfo['is_syn_local'])) {
  134. $archivesInfo = $this->content_remote_to_local($archivesInfo);
  135. }
  136. $ctl_name = $channeltypeInfo['ctl_name'];
  137. $class = "\\app\\admin\\model\\{$ctl_name}";
  138. $model = new $class;
  139. try {
  140. $archivesInfo['aid'] = $aid;
  141. $archivesInfo['arcurl'] = arcurl("home/{$channeltypeInfo['ctl_name']}/view", array_merge($arctypeInfo, $archivesInfo), true, true);
  142. if (!empty($archivesInfo['articlePayInfo'])) {
  143. $archivesInfo['articlePayInfo']['aid'] = $aid;
  144. if ('add' == $opt) {
  145. Db::name('article_pay')->insert($archivesInfo['articlePayInfo']);
  146. } else {
  147. $is_in = Db::name('article_pay')->where('aid',$aid)->find();
  148. if (empty($is_in)){
  149. Db::name('article_pay')->insert($archivesInfo['articlePayInfo']);
  150. }else{
  151. $archivesInfo['articlePayInfo']['update_time'] = getTime();
  152. Db::name('article_pay')->where('aid',$aid)->update($archivesInfo['articlePayInfo']);
  153. }
  154. }
  155. }
  156. $model->afterSave($aid, $archivesInfo, $opt);
  157. // 清除前台缓存
  158. clearHtmlCache([$aid], [$arctypeInfo['id']]);
  159. // 添加查询执行语句到mysql缓存表
  160. model('SqlCacheTable')->InsertSqlCacheTable();
  161. if ('add' == $opt) {
  162. $push_msg = '发布成功';
  163. adminLog('群发新增文档:'.$archivesInfo['title']);
  164. } else {
  165. $push_msg = '编辑成功';
  166. adminLog('群发编辑文档:'.$archivesInfo['title']);
  167. }
  168. $globalConfig = tpCache('global');
  169. $data = [
  170. 'push_code' => 1,
  171. 'push_msg' => $push_msg,
  172. 'arctypeInfo' => [
  173. 'typeurl' => $arctypeInfo['typeurl'],
  174. 'typename' => $arctypeInfo['typename'],
  175. ],
  176. 'archivesInfo' => [
  177. 'aid' => $archivesInfo['aid'],
  178. 'arcurl' => $archivesInfo['arcurl'],
  179. ],
  180. 'globalConfig' => [
  181. 'seo_pseudo' => $globalConfig['seo_pseudo'],
  182. ],
  183. ];
  184. } catch (\Exception $e) {
  185. Db::name('archives')->where(['aid'=>$aid])->delete();
  186. $model->afterDel([$aid]);
  187. $data['push_msg'] = $e->getMessage();
  188. }
  189. }
  190. respose($data);
  191. }
  192. //内容远程图片本地化
  193. private function content_remote_to_local($archivesInfo = []){
  194. foreach (['content','content_ey_m','free_content'] as $k => $v){
  195. $first = 'addonFieldExt';
  196. if ('free_content' == $v){
  197. $first = 'articlePayInfo';
  198. }
  199. $archivesInfo[$first][$v] = htmlspecialchars_decode($archivesInfo[$first][$v]);
  200. $archivesInfo[$first][$v] = remote_to_local($archivesInfo[$first][$v]);
  201. $archivesInfo[$first][$v] = htmlspecialchars($archivesInfo[$first][$v]);
  202. }
  203. return $archivesInfo;
  204. }
  205. private function multistation_del_archives()
  206. {
  207. $data = [
  208. 'push_code' => 0,
  209. 'push_msg' => '删除失败',
  210. ];
  211. $post = input('post.');
  212. $aid = empty($post['aid']) ? 0 : $post['aid'];
  213. if (!empty($aid)) {
  214. try {
  215. $archivesInfo = Db::name('archives')->where(['aid'=>$aid])->find();
  216. $channeltypeInfo = Db::name('channeltype')->where(['id'=>$archivesInfo['channel']])->find();
  217. $ctl_name = $channeltypeInfo['ctl_name'];
  218. $class = "\\app\\admin\\model\\{$ctl_name}";
  219. $model = new $class;
  220. Db::name('archives')->where(['aid'=>$aid])->delete();
  221. $model->afterDel([$aid]);
  222. adminLog('群发删除文档:'.$archivesInfo['title']);
  223. $data = [
  224. 'push_code' => 1,
  225. 'push_msg' => '删除成功',
  226. ];
  227. } catch (\Exception $e) {
  228. $data['push_msg'] = $e->getMessage();
  229. }
  230. }
  231. respose($data);
  232. }
  233. /**
  234. * 清除缓存接口
  235. * @return [type] [description]
  236. */
  237. public function clear_cache()
  238. {
  239. \think\Cache::clear();
  240. delFile(RUNTIME_PATH);
  241. // 重新生成全部数据表缓存字段文件
  242. // $dbtables = \think\Db::query('SHOW TABLE STATUS');
  243. // $tableList = [];
  244. // foreach ($dbtables as $k => $v) {
  245. // if (preg_match('/^'.PREFIX.'/i', $v['Name'])) {
  246. // /*调用命令行的指令*/
  247. // \think\Console::call('optimize:schema', ['--table', $v['Name']]);
  248. // /*--end*/
  249. // }
  250. // }
  251. // try {
  252. // /*清除大数据缓存表 -- 陈风任*/
  253. // Db::name('sql_cache_table')->execute('TRUNCATE TABLE '.config('database.prefix').'sql_cache_table');
  254. // model('SqlCacheTable')->InsertSqlCacheTable(true);
  255. // /* END */
  256. // } catch (\Exception $e) {}
  257. exit('success');
  258. }
  259. /**
  260. * 获取下级地区
  261. */
  262. public function get_region()
  263. {
  264. if (IS_AJAX) {
  265. $pid = input('pid/d', 0);
  266. $res = Db::name('region')->where('parent_id', $pid)->select();
  267. $this->success('请求成功', null, $res);
  268. }
  269. }
  270. /**
  271. * 内容页浏览量的自增接口
  272. */
  273. public function arcclick()
  274. {
  275. if (!IS_AJAX) {
  276. // 第一种方案,js输出
  277. $aids = input('param.aids/d', 0);
  278. if (!empty($aids)) {
  279. $type = input('param.type/s', '');
  280. $archives_db = Db::name('archives');
  281. if ('view' == $type) {
  282. $archives_db->where('aid', $aids)->setInc('click');
  283. eyou_statistics_data(1); // 统计浏览数
  284. }
  285. $click = $archives_db->where('aid', $aids)->value('click');
  286. echo "document.htm.write('" . $click . "');\r\n";
  287. exit;
  288. }
  289. } else {
  290. // 第二种方案,执行ajax
  291. $param = input('param.');
  292. if (isset($param['aids'])) {
  293. $aids = $param['aids'];
  294. if (!empty($aids)) {
  295. $aid_arr = explode(',', $aids);
  296. foreach ($aid_arr as $key => $val) {
  297. $aid_arr[$key] = intval($val);
  298. }
  299. $type = input('param.type/s', '');
  300. $archives_db = Db::name('archives');
  301. if ('view' == $type) {
  302. $archives_db->where(['aid' => ['IN', $aid_arr]])->update([
  303. 'click' => Db::raw('click + 1'),
  304. ]);
  305. eyou_statistics_data(1, count($aid_arr)); // 统计浏览数
  306. }
  307. $data = $archives_db->field('aid,click')->where(['aid' => ['IN', $aid_arr]])->getAllWithIndex('aid');
  308. respose($data);
  309. }
  310. } else {
  311. $click = 0;
  312. $aid = input('param.aid/d', 0);
  313. $type = input('param.type/s', '');
  314. if ($aid > 0) {
  315. $archives_db = Db::name('archives');
  316. if ('view' == $type) {
  317. $archives_db->where(array('aid' => $aid))->setInc('click');
  318. eyou_statistics_data(1); // 统计浏览数
  319. }
  320. $click = $archives_db->where(array('aid' => $aid))->getField('click');
  321. }
  322. echo($click);
  323. exit;
  324. }
  325. }
  326. to_index("404");
  327. }
  328. /**
  329. * 付费文档的订单数/用户数
  330. */
  331. public function freebuynum()
  332. {
  333. $aid = input('param.aid/d', 0);
  334. if (IS_AJAX && !empty($aid)) {
  335. $freebuynum = 0;
  336. $modelid = input('modelid/d', 0);
  337. $modelid = input('channelid/d', $modelid);
  338. if (empty($modelid)) {
  339. $modelid = Db::name('archives')->where(['aid' => $aid])->value('channel');
  340. }
  341. if (1 == $modelid) {
  342. $freebuynum = Db::name('article_order')->where(['product_id' => $aid, 'order_status' => 1])->count();
  343. } else if (5 == $modelid) {
  344. $freebuynum = Db::name('media_order')->where(['product_id' => $aid, 'order_status' => 1])->count();
  345. } else if (4 == $modelid) {
  346. $freebuynum = Db::name('download_order')->where(['product_id' => $aid, 'order_status' => 1])->count();
  347. }
  348. echo($freebuynum);
  349. exit;
  350. } else {
  351. to_index("404");
  352. }
  353. }
  354. /**
  355. * 文档下载次数
  356. */
  357. public function downcount()
  358. {
  359. $aid = input('param.aid/d', 0);
  360. if (IS_AJAX && !empty($aid)) {
  361. $downcount = Db::name('archives')->where(array('aid' => $aid))->getField('downcount');
  362. echo($downcount);
  363. exit;
  364. } else {
  365. to_index("404");
  366. }
  367. }
  368. /**
  369. * 文档收藏次数
  370. */
  371. public function collectnum()
  372. {
  373. $aid = input('param.aid/d', 0);
  374. if (IS_AJAX && !empty($aid)) {
  375. $collectnum = Db::name('users_collection')->where(array('aid' => $aid))->count();
  376. echo($collectnum);
  377. exit;
  378. } else {
  379. to_index("404");
  380. }
  381. }
  382. /**
  383. * 站内通知数量
  384. */
  385. public function notice()
  386. {
  387. if (IS_AJAX) {
  388. $unread_notice_num = 0;
  389. $users_id = session('users_id');
  390. if ($users_id > 0) {
  391. $unread_notice_num = Db::name('users')->where(array('users_id' => $users_id))->value('unread_notice_num');
  392. }
  393. echo($unread_notice_num);
  394. exit;
  395. } else {
  396. to_index("404");
  397. }
  398. }
  399. /**
  400. * arclist列表分页arcpagelist标签接口
  401. */
  402. public function arcpagelist()
  403. {
  404. if (!IS_AJAX) {
  405. to_index("404");
  406. }
  407. $pnum = input('page/d', 0);
  408. $pagesize = input('pagesize/d', 0);
  409. $tagid = input('tagid/s', '');
  410. $tagidmd5 = input('tagidmd5/s', '');
  411. !empty($tagid) && $tagid = preg_replace("/[^a-zA-Z0-9-_]/", '', $tagid);
  412. !empty($tagidmd5) && $tagidmd5 = preg_replace("/[^a-zA-Z0-9_]/", '', $tagidmd5);
  413. if (empty($tagid) || empty($pnum) || empty($tagidmd5)) {
  414. $this->error('参数有误');
  415. }
  416. $data = [
  417. 'code' => 1,
  418. 'msg' => '',
  419. 'lastpage' => 0,
  420. ];
  421. $arcmulti_db = Db::name('arcmulti');
  422. $arcmultiRow = $arcmulti_db->where(['tagid' => $tagidmd5])->find();
  423. if (!empty($arcmultiRow) && !empty($arcmultiRow['querysql'])) {
  424. // arcpagelist标签属性pagesize优先级高于arclist标签属性pagesize
  425. if (0 < intval($pagesize)) {
  426. $arcmultiRow['pagesize'] = $pagesize;
  427. }
  428. // 取出属性并解析为变量
  429. $attarray = unserialize(stripslashes($arcmultiRow['attstr']));
  430. // extract($attarray, EXTR_SKIP); // 把数组中的键名直接注册为了变量
  431. // 通过页面及总数解析当前页面数据范围
  432. $pnum < 2 && $pnum = 2;
  433. $strnum = intval($attarray['row']) + ($pnum - 2) * $arcmultiRow['pagesize'];
  434. // 拼接完整的SQL
  435. $querysql = preg_replace('#LIMIT(\s+)(\d+)(,\d+)?#i', '', $arcmultiRow['querysql']);
  436. $querysql = preg_replace('#SELECT(\s+)(.*)(\s+)FROM#i', 'SELECT COUNT(*) AS totalNum FROM', $querysql);
  437. $queryRow = Db::query($querysql);
  438. if (!empty($queryRow)) {
  439. $tpl_content = '';
  440. $filename = './template/' . THEME_STYLE_PATH . '/' . 'system/arclist_' . $tagid . '.' . \think\Config::get('template.view_suffix');
  441. if (!file_exists($filename)) {
  442. $data['code'] = -1;
  443. $data['msg'] = "模板追加文件 arclist_{$tagid}.htm 不存在!";
  444. $this->error("标签模板不存在", null, $data);
  445. } else {
  446. $tpl_content = @file_get_contents($filename);
  447. }
  448. if (empty($tpl_content)) {
  449. $data['code'] = -1;
  450. $data['msg'] = "模板追加文件 arclist_{$tagid}.htm 没有HTML代码!";
  451. $this->error("标签模板不存在", null, $data);
  452. }
  453. /*拼接完整的arclist标签语法*/
  454. $offset = intval($strnum);
  455. $row = intval($offset) + intval($arcmultiRow['pagesize']);
  456. $innertext = "{eyou:arclist";
  457. foreach ($attarray as $key => $val) {
  458. if (in_array($key, ['tagid', 'offset', 'row'])) {
  459. continue;
  460. }
  461. if ($key == 'keyword') {
  462. if (empty($val)) {
  463. continue;
  464. } else if (preg_match('/^\$eyou(\.|\[)(.*)$/i', $val)) {
  465. $val = input('param.keywords/s');
  466. }
  467. }
  468. $innertext .= " {$key}='{$val}'";
  469. }
  470. $innertext .= " limit='{$offset},{$row}'}";
  471. $innertext .= $tpl_content;
  472. $innertext .= "{/eyou:arclist}";
  473. /*--end*/
  474. $msg = $this->display($innertext); // 渲染模板标签语法
  475. $data['msg'] = $msg;
  476. //是否到了最终页
  477. if (!empty($queryRow[0]['totalNum']) && $queryRow[0]['totalNum'] <= $row) {
  478. $data['lastpage'] = 1;
  479. }
  480. } else {
  481. $data['lastpage'] = 1;
  482. }
  483. }
  484. $this->success('请求成功', null, $data);
  485. }
  486. /**
  487. * 获取表单令牌
  488. */
  489. public function get_token($name = '__token__')
  490. {
  491. $name = preg_replace('/([^\w\-]+)/i', '', $name);
  492. if (IS_AJAX && strstr($name, '_token_')) {
  493. echo $this->request->token($name);
  494. exit;
  495. } else {
  496. to_index("404");
  497. }
  498. }
  499. /**
  500. * 检验会员登录
  501. */
  502. public function check_user()
  503. {
  504. if (IS_AJAX) {
  505. $type = input('param.type/s', 'default');
  506. $img = input('param.img/s');
  507. $afterhtml = input('param.afterhtml/s');
  508. $users_id = session('users_id');
  509. if ('login' == $type) {
  510. if (!empty($users_id)) {
  511. $currentstyle = input('param.currentstyle/s');
  512. $users = M('users')->field('username,nickname,head_pic,sex')
  513. ->where([
  514. 'users_id' => $users_id,
  515. 'lang' => $this->home_lang,
  516. ])->find();
  517. if (!empty($users)) {
  518. $nickname = $users['nickname'];
  519. if (empty($nickname)) {
  520. $nickname = $users['username'];
  521. }
  522. $head_pic = get_head_pic(htmlspecialchars_decode($users['head_pic']), false, $users['sex']);
  523. $users['head_pic'] = func_preg_replace(['http://thirdqq.qlogo.cn'], ['https://thirdqq.qlogo.cn'], $head_pic);
  524. if (!empty($afterhtml)) {
  525. preg_match_all('/~(\w+)~/iUs', $afterhtml, $userfields);
  526. if (!empty($userfields[1])) {
  527. $users['url'] = url('user/Users/login');
  528. foreach ($userfields[1] as $key => $val) {
  529. $replacement = !empty($users[$val]) ? $users[$val] : '';
  530. $afterhtml = str_replace($userfields[0][$key], $users[$val], $afterhtml);
  531. }
  532. $users['html'] = htmlspecialchars_decode($afterhtml);
  533. } else {
  534. $users['html'] = $nickname;
  535. }
  536. } else {
  537. if ('on' == $img) {
  538. $users['html'] = "<img class='{$currentstyle}' alt='{$nickname}' src='{$users['head_pic']}' />";
  539. } else {
  540. $users['html'] = $nickname;
  541. }
  542. }
  543. $users['ey_is_login'] = 1;
  544. cookie('users_id', $users_id);
  545. $this->success('请求成功', null, $users);
  546. }
  547. }
  548. $data = [
  549. 'ey_is_login' => 0,
  550. 'ey_third_party_login' => $this->is_third_party_login(),
  551. 'ey_third_party_qqlogin' => $this->is_third_party_login('qq'),
  552. 'ey_third_party_wxlogin' => $this->is_third_party_login('wx'),
  553. 'ey_third_party_wblogin' => $this->is_third_party_login('wb'),
  554. 'ey_login_vertify' => $this->is_login_vertify(),
  555. ];
  556. $this->success('请先登录', null, $data);
  557. } else if ('reg' == $type) {
  558. if (!empty($users_id)) {
  559. $users['ey_is_login'] = 1;
  560. } else {
  561. $users['ey_is_login'] = 0;
  562. }
  563. $this->success('请求成功', null, $users);
  564. } else if ('logout' == $type) {
  565. if (!empty($users_id)) {
  566. $users['ey_is_login'] = 1;
  567. } else {
  568. $users['ey_is_login'] = 0;
  569. }
  570. $this->success('请求成功', null, $users);
  571. } else if ('cart' == $type) {
  572. if (!empty($users_id)) {
  573. $users['ey_is_login'] = 1;
  574. $users['ey_cart_num_20191212'] = Db::name('shop_cart')->where(['users_id' => $users_id])->sum('product_num');
  575. } else {
  576. $users['ey_is_login'] = 0;
  577. $users['ey_cart_num_20191212'] = 0;
  578. }
  579. $this->success('请求成功', null, $users);
  580. } else if ('collect' == $type) {
  581. if (!empty($users_id)) {
  582. $users['ey_is_login'] = 1;
  583. $users['ey_collect_num_20191212'] = Db::name('users_collection')->where(['users_id' => $users_id])->count();
  584. } else {
  585. $users['ey_is_login'] = 0;
  586. $users['ey_collect_num_20191212'] = 0;
  587. }
  588. $this->success('请求成功', null, $users);
  589. }
  590. $this->error('访问错误');
  591. } else {
  592. to_index("404");
  593. }
  594. }
  595. public function get_info()
  596. {
  597. $str = '5piT5LyYQ01TLQ==';
  598. exit(base64_decode($str) . getCmsVersion());
  599. }
  600. /**
  601. * 是否启用并开启第三方登录
  602. * @return boolean [description]
  603. */
  604. private function is_third_party_login($type = '')
  605. {
  606. static $result = null;
  607. if (null === $result) {
  608. $result = Db::name('weapp')->field('id,code,data')->where([
  609. 'code' => ['IN', ['QqLogin', 'WxLogin', 'Wblogin']],
  610. 'status' => 1,
  611. ])->getAllWithIndex('code');
  612. }
  613. $value = 0;
  614. if (empty($type)) {
  615. $qqlogin = 0;
  616. if (!empty($result['QqLogin']['data'])) {
  617. $qqData = unserialize($result['QqLogin']['data']);
  618. if (!empty($qqData['login_show'])) {
  619. $qqlogin = 1;
  620. }
  621. }
  622. $wxlogin = 0;
  623. if (!empty($result['WxLogin']['data'])) {
  624. $wxData = unserialize($result['WxLogin']['data']);
  625. if (!empty($wxData['login_show'])) {
  626. $wxlogin = 1;
  627. }
  628. }
  629. $wblogin = 0;
  630. if (!empty($result['Wblogin']['data'])) {
  631. $wbData = unserialize($result['Wblogin']['data']);
  632. if (!empty($wbData['login_show'])) {
  633. $wblogin = 1;
  634. }
  635. }
  636. if ($qqlogin == 1 || $wxlogin == 1 || $wblogin == 1) {
  637. $value = 1;
  638. }
  639. } else {
  640. if ('qq' == $type) {
  641. if (!empty($result['QqLogin']['data'])) {
  642. $qqData = unserialize($result['QqLogin']['data']);
  643. if (!empty($qqData['login_show'])) {
  644. $value = 1;
  645. }
  646. }
  647. } else if ('wx' == $type) {
  648. if (!empty($result['WxLogin']['data'])) {
  649. $wxData = unserialize($result['WxLogin']['data']);
  650. if (!empty($wxData['login_show'])) {
  651. $value = 1;
  652. }
  653. }
  654. } else if ('wb' == $type) {
  655. if (!empty($result['Wblogin']['data'])) {
  656. $wbData = unserialize($result['Wblogin']['data']);
  657. if (!empty($wbData['login_show'])) {
  658. $value = 1;
  659. }
  660. }
  661. }
  662. }
  663. return $value;
  664. }
  665. /**
  666. * 是否开启登录图形验证码
  667. * @return boolean [description]
  668. */
  669. private function is_login_vertify()
  670. {
  671. $row = tpSetting('system.system_vertify');
  672. // 获取验证码配置信息
  673. $row = json_decode($row, true);
  674. $baseConfig = \think\Config::get("captcha");
  675. if (!empty($row)) {
  676. foreach ($row['captcha'] as $key => $val) {
  677. if ('default' == $key) {
  678. $baseConfig[$key] = array_merge($baseConfig[$key], $val);
  679. } else {
  680. $baseConfig[$key]['is_on'] = $val['is_on'];
  681. $baseConfig[$key]['config'] = array_merge($baseConfig['default'], $val['config']);
  682. }
  683. }
  684. \think\Config::set('captcha', $baseConfig);
  685. }
  686. // 默认开启验证码
  687. $is_vertify = 1;
  688. $users_login_captcha = empty($baseConfig['users_login']) ? [] : $baseConfig['users_login'];
  689. if (!function_exists('imagettftext') || empty($users_login_captcha['is_on'])) {
  690. $is_vertify = 0; // 函数不存在,不符合开启的条件
  691. }
  692. return $is_vertify;
  693. }
  694. /**
  695. * 获取用户信息
  696. */
  697. public function get_tag_user_info()
  698. {
  699. if (!IS_AJAX) {
  700. to_index("404");
  701. }
  702. $t_uniqid = input('param.t_uniqid/s', '');
  703. if (IS_AJAX && !empty($t_uniqid)) {
  704. $users_id = session('users_id');
  705. if (!empty($users_id)) {
  706. $users = Db::name('users')->field('b.*, a.*')
  707. ->alias('a')
  708. ->join('__USERS_LEVEL__ b', 'a.level = b.level_id', 'LEFT')
  709. ->where([
  710. 'a.users_id' => $users_id,
  711. 'a.lang' => $this->home_lang,
  712. ])->find();
  713. if (!empty($users)) {
  714. $users['reg_time'] = MyDate('Y-m-d H:i:s', $users['reg_time']);
  715. $users['update_time'] = MyDate('Y-m-d H:i:s', $users['update_time']);
  716. } else {
  717. $users = [];
  718. $tableFields1 = Db::name('users')->getTableFields();
  719. $tableFields2 = Db::name('users_level')->getTableFields();
  720. $tableFields = array_merge($tableFields1, $tableFields2);
  721. foreach ($tableFields as $key => $val) {
  722. $users[$val] = '';
  723. }
  724. }
  725. unset($users['password']);
  726. unset($users['paypwd']);
  727. // 头像处理
  728. $head_pic = get_head_pic(htmlspecialchars_decode($users['head_pic']), false, $users['sex']);
  729. $users['head_pic'] = func_preg_replace(['http://thirdqq.qlogo.cn'], ['https://thirdqq.qlogo.cn'], $head_pic);
  730. $users['url'] = url('user/Users/centre');
  731. $dtypes = [];
  732. foreach ($users as $key => $val) {
  733. $html_key = md5($key . '-' . $t_uniqid);
  734. $users[$html_key] = $val;
  735. $dtype = 'txt';
  736. if (in_array($key, ['head_pic'])) {
  737. $dtype = 'img';
  738. } else if (in_array($key, ['url'])) {
  739. $dtype = 'href';
  740. }
  741. $dtypes[$html_key] = $dtype;
  742. unset($users[$key]);
  743. }
  744. $data = [
  745. 'ey_is_login' => 1,
  746. 'users' => $users,
  747. 'dtypes' => $dtypes,
  748. ];
  749. $this->success('请求成功', null, $data);
  750. }
  751. $this->success('请先登录', null, ['ey_is_login' => 0]);
  752. }
  753. $this->error('访问错误');
  754. }
  755. // 验证码获取
  756. public function vertify()
  757. {
  758. $time = getTime();
  759. $type = input('param.type/s', 'default');
  760. $type = preg_replace('/([^\w\-]+)/i', '', $type);
  761. $token = input('param.token/s', '');
  762. $token = preg_replace('/([^\w\-]+)/i', '', $token);
  763. $configList = \think\Config::get('captcha');
  764. $captchaArr = array_keys($configList);
  765. if (in_array($type, $captchaArr)) {
  766. /*验证码插件开关*/
  767. $admin_login_captcha = config('captcha.' . $type);
  768. $config = (!empty($admin_login_captcha['is_on']) && !empty($admin_login_captcha['config'])) ? $admin_login_captcha['config'] : config('captcha.default');
  769. /*--end*/
  770. } else {
  771. $config = config('captcha.default');
  772. }
  773. ob_clean(); // 清空缓存,才能显示验证码
  774. $Verify = new \think\Verify($config);
  775. if (!empty($token)) {
  776. $Verify->entry($token);
  777. } else {
  778. $Verify->entry($type);
  779. }
  780. exit();
  781. }
  782. /*
  783. * 表单提交完成之后操作----短信发送
  784. */
  785. /**
  786. * 表单提交完成之后操作----邮箱发送
  787. */
  788. public function send_email()
  789. {
  790. // 超时后,断掉邮件发送
  791. function_exists('set_time_limit') && set_time_limit(10);
  792. \think\Session::pause(); // 暂停session,防止session阻塞机制
  793. $type = input('param.type/s');
  794. // 留言发送邮件
  795. if (IS_AJAX_POST && 'gbook_submit' == $type) {
  796. // 是否满足发送邮箱的条件
  797. $is_open = Db::name('smtp_tpl')->where(['send_scene' => 1, 'lang' => $this->home_lang])->value('is_open');
  798. $smtp_config = tpCache('smtp');
  799. if (empty($is_open) || empty($smtp_config['smtp_user']) || empty($smtp_config['smtp_pwd'])) {
  800. $this->error("邮箱尚未配置,发送失败");
  801. }
  802. $tid = input('param.tid/d');
  803. $aid = input('param.aid/d');
  804. $form_type = input('param.form_type/d', 0);
  805. $send_email_scene = config('send_email_scene');
  806. $scene = $send_email_scene[1]['scene'];
  807. if (1 == $form_type) {
  808. $info = Db::name('guestbook')->field('a.*, b.form_name')
  809. ->alias('a')
  810. ->join('form b','a.typeid = b.form_id','left')
  811. ->where(['a.aid'=>$aid, 'a.form_type'=>$form_type])
  812. ->find();
  813. } else {
  814. $info = Db::name('guestbook')->field('a.*, b.typename as form_name')
  815. ->alias('a')
  816. ->join('arctype b','a.typeid = b.id','left')
  817. ->where(['a.aid'=>$aid, 'a.form_type'=>$form_type])
  818. ->find();
  819. }
  820. $city = "";
  821. try {
  822. $city_arr = getCityLocation($info['ip']);
  823. if (!empty($city_arr)) {
  824. !empty($city_arr['location']) && $city .= $city_arr['location'];
  825. }
  826. } catch (\Exception $e) {}
  827. $info['city'] = $city;
  828. // 判断标题拼接
  829. $web_name = tpCache('web.web_name');
  830. $web_name = $info['form_name'] . '-' . $web_name;
  831. // 拼装发送的字符串内容
  832. $attr_list = Db::name('guestbook_attribute')->where(['typeid'=>$tid,'form_type'=>$form_type])->order('attr_id asc')->select();
  833. $attr_values = Db::name('guestbook_attr')->field('attr_id,attr_value')->where(['aid'=>$aid,'form_type'=>$form_type])->getAllWithIndex('attr_id');
  834. foreach ($attr_list as $key => $val) {
  835. $val['attr_value'] = empty($attr_values[$val['attr_id']]) ? '' : $attr_values[$val['attr_id']]['attr_value'];
  836. $attr_list[$key] = $val;
  837. }
  838. $content = '';
  839. foreach ($attr_list as $key => $val) {
  840. if ($val['attr_input_type'] == 9) {
  841. $val['attr_value'] = Db::name('region')->where('id', 'in', $val['attr_value'])->column('name');
  842. $val['attr_value'] = implode('', $val['attr_value']);
  843. } else if ($val['attr_input_type'] == 4) {
  844. $val['attr_value'] = filter_line_return($val['attr_value'], '、');
  845. } else if (10 == $val['attr_input_type']) {
  846. $val['attr_value'] = date('Y-m-d H:i:s', $val['attr_value']);
  847. } else if (11 == $val['attr_input_type']) {
  848. $attr_value_arr = explode(",", $val['attr_value']);
  849. $attr_value_str = "";
  850. foreach ($attr_value_arr as $attr_value_k => $attr_value_v) {
  851. $attr_value_v = handle_subdir_pic($attr_value_v, 'img', true);
  852. $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>";
  853. }
  854. $val['attr_value'] = $attr_value_str;
  855. } else {
  856. if (preg_match('/(\.(jpg|gif|png|bmp|jpeg|ico|webp))$/i', $val['attr_value'])) {
  857. if (!stristr($val['attr_value'], '|')) {
  858. $val['attr_value'] = handle_subdir_pic($val['attr_value'], 'img', true);
  859. $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>";
  860. }
  861. } elseif (preg_match('/(\.(' . tpCache('basic.file_type') . '))$/i', $val['attr_value'])) {
  862. if (!stristr($val['attr_value'], '|')) {
  863. $val['attr_value'] = handle_subdir_pic($val['attr_value'], 'img', true);
  864. $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>";
  865. }
  866. }
  867. }
  868. $content .= $val['attr_name'] . ':' . $val['attr_value'] . '<br/>';
  869. }
  870. $content .= '所属表单:' . $info['form_name'] . '<br/>';
  871. $content .= 'IP来源:' . $info['ip'];
  872. if (!empty($info['city'])) {
  873. $content .= "({$info['city']})";
  874. } else {
  875. $content .= "(<a href=\"https://www.baidu.com/s?wd={$info['ip']}\" target=\"_blank\">查看地区</a>)";
  876. }
  877. $content .= '<br/>';
  878. if (2 == $info['source']) {
  879. $content .= "提交来源:手机端<br/>";
  880. } else {
  881. $content .= "提交来源:电脑端<br/>";
  882. }
  883. $content .= '提交时间:' . MyDate('Y-m-d H:i:s', $info['add_time']) . '<br/>';
  884. $html = "<p style='text-align: left;'>{$web_name}</p><p style='text-align: left;'>{$content}</p>";
  885. // 发送邮件
  886. $res = send_email(null, null, $html, $scene);
  887. if (intval($res['code']) == 1) {
  888. $this->success($res['msg']);
  889. } else {
  890. $this->error($res['msg']);
  891. }
  892. }
  893. }
  894. /**
  895. * 手机短信发送
  896. */
  897. public function SendMobileCode()
  898. {
  899. // 超时后,断掉发送
  900. function_exists('set_time_limit') && set_time_limit(5);
  901. // \think\Session::pause(); // 暂停session,防止session阻塞机制
  902. /*$pretime1 = getTime() - 120; // 3分钟内
  903. $ip_prefix = preg_replace('/\d+\.\d+$/i', '', clientIP());
  904. $count = Db::name('sms_log')->where([
  905. 'ip' => ['LIKE', "{$ip_prefix}%"],
  906. 'is_use' => 1,
  907. 'add_time' => ['gt', $pretime1],
  908. ])->count();
  909. if (!empty($count) && 5 <= $count) {
  910. $this->error('发送短信异常~');
  911. }*/
  912. // 发送手机验证码
  913. if (IS_AJAX_POST) {
  914. $post = input('post.');
  915. $source = !empty($post['source']) ? $post['source'] : 0;
  916. // 留言验证类型发送短信处理
  917. if (isset($post['scene']) && in_array($post['scene'], [7])) {
  918. // 是否允许再次发送
  919. $where = [
  920. 'source' => $post['scene'],
  921. 'mobile' => $post['phone'],
  922. 'status' => 1,
  923. 'is_use' => 0,
  924. 'add_time' => ['>', getTime() - 120]
  925. ];
  926. $Result = Db::name('sms_log')->where($where)->order('id desc')->count();
  927. if (!empty($Result)) $this->error('120秒内只能发送一次');
  928. // 图形验证码判断
  929. if (empty($post['code'])) $this->error('请输入图片验证码');
  930. $verify = new \think\Verify();
  931. if (!$verify->check($post['code'], $post['code_token'])) $this->error('图片验证码错误');
  932. // 发送并返回结果
  933. $Result = sendSms(7, $post['phone'], array('content' => mt_rand(1000, 9999)));
  934. if (1 === intval($Result['status'])) {
  935. $this->success('发送成功');
  936. } else {
  937. $this->error($Result['msg']);
  938. }
  939. }
  940. // 订单付款和订单发货类型发送短信处理
  941. else if (isset($post['scene']) && in_array($post['scene'], [5, 6, 20])) {
  942. // 如果没有手机号则返回结束
  943. if (empty($post['mobile'])) return false;
  944. // 处理发送的内容
  945. $data = !empty($post['data']) ? $post['data'] : [];
  946. $data = !empty($data) && !is_array($data) ? json_decode(htmlspecialchars_decode(htmlspecialchars_decode($data)), true) : $data;
  947. // 查询消息通知模板的内容
  948. $sms_config = tpCache('sms');
  949. $sms_type = !empty($sms_config['sms_type']) ? intval($sms_config['sms_type']) : 1;
  950. $tpl_content = Db::name('sms_template')->where(["send_scene" => $post['scene'], "sms_type" => $sms_type, 'is_open' => 1])->value('tpl_content');
  951. if (empty($tpl_content)) return false;
  952. // 发送短信提醒
  953. if (in_array($data['type'], [1, 2])) {
  954. // $preg_res = preg_match('/订单/', $tpl_content);
  955. // 查询订单信息
  956. $field = 'a.order_code, a.express_time, b.product_name';
  957. $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();
  958. switch ($data['type']) {
  959. case '1':
  960. // if (empty($sms_config['sms_shop_order_pay'])) {
  961. // $this->error("配置不接收订单付款短信提醒");
  962. // }
  963. $sendData = [
  964. 'content' => $shopOrder['order_code'],
  965. ];
  966. // $content = $preg_res ? '待发货' : '您有新的待发货订单';
  967. break;
  968. case '2':
  969. $sendData = [
  970. 'content' => $shopOrder['order_code'],
  971. 'express_time' => $shopOrder['express_time'],
  972. 'product_name' => $shopOrder['product_name'],
  973. ];
  974. // $content = $preg_res ? $data['order_code'] : $data['order_code'];
  975. break;
  976. default:
  977. $content = '';
  978. break;
  979. }
  980. } else if (in_array($data['type'], [3])) {
  981. $sendData = [
  982. 'content' => $tpl_content
  983. ];
  984. }
  985. $Result = !empty($sendData) ? sendSms($post['scene'], $post['mobile'], $sendData) : ['status' => 0, 'msg' => '没有发送内容'];
  986. if (intval($Result['status']) == 1) {
  987. $this->success('发送成功!');
  988. } else {
  989. $this->error($Result['msg']);
  990. }
  991. }
  992. //发送表单提醒
  993. else if (isset($post['scene']) && $post['scene'] == 11) {
  994. //查询消息通知模板的内容
  995. $sms_config = tpCache('sms');
  996. // if (empty($sms_config['sms_guestbook_send'])) {
  997. // $this->error("配置不接收留言短信提醒");
  998. // }
  999. $sms_type = $sms_config['sms_type'] ? intval($sms_config['sms_type']) : 1;
  1000. $tpl_content = Db::name('sms_template')->where(["send_scene" => $post['scene'], "sms_type" => $sms_type, 'is_open' => 1])->value('tpl_content');
  1001. if (!$tpl_content) return false;
  1002. $Result = sendSms($post['scene'], $sms_config['sms_test_mobile'], []);
  1003. if (intval($Result['status']) == 1) {
  1004. $this->success('发送成功!');
  1005. } else {
  1006. $this->error($Result['msg']);
  1007. }
  1008. /* END */
  1009. }
  1010. // 其他类型发送短信处理
  1011. else {
  1012. if (isset($post['type']) && in_array($post['type'], ['users_mobile_reg', 'users_mobile_login', 'reg'])) {
  1013. // 数据验证
  1014. $rule = [
  1015. 'mobile' => 'require|token:__mobile_1_token__',
  1016. ];
  1017. $message = [
  1018. 'mobile.require' => '请输入手机号码!',
  1019. ];
  1020. $validate = new \think\Validate($rule, $message);
  1021. if (!$validate->batch()->check($post)) {
  1022. $this->error('表单令牌过期,请尝试刷新页面~');
  1023. }
  1024. $post['is_mobile'] = true;
  1025. }
  1026. $mobile = !empty($post['mobile']) ? $post['mobile'] : session('mobile');
  1027. if (empty($mobile)) $this->error('请先绑定手机号码');
  1028. // 手机可用性验证
  1029. $is_mobile = !empty($post['is_mobile']) ? $post['is_mobile'] : false;
  1030. if (!empty($is_mobile)) {
  1031. /*是否存在手机号码*/
  1032. $where = [
  1033. 'mobile' => $mobile
  1034. ];
  1035. $users_id = session('users_id');
  1036. if (!empty($users_id)) $where['users_id'] = ['NEQ', $users_id];
  1037. $Result = Db::name('users')->where($where)->count();
  1038. /* END */
  1039. if (0 == $post['source']) {
  1040. if (!empty($Result)) $this->error('手机号码已注册');
  1041. } else if (2 == $post['source']) {
  1042. if (empty($Result)) $this->error('手机号码未注册');
  1043. } else if (4 == $post['source']) {
  1044. if (empty($Result)) $this->error('手机号码不存在');
  1045. } else {
  1046. if (!empty($Result)) $this->error('手机号码已存在');
  1047. }
  1048. }
  1049. /*是否允许再次发送*/
  1050. $where = [
  1051. 'mobile' => $mobile,
  1052. 'source' => $source,
  1053. 'status' => 1,
  1054. 'is_use' => 0,
  1055. 'add_time' => ['>', getTime() - 120]
  1056. ];
  1057. $Result = Db::name('sms_log')->where($where)->order('id desc')->count();
  1058. if (!empty($Result) && false == config('sms_debug')) $this->error('120秒内只能发送一次!');
  1059. /* END */
  1060. /*图形验证码判断*/
  1061. if (!empty($post['IsVertify']) || (isset($post['type']) && in_array($post['type'], ['users_mobile_reg', 'users_mobile_login', 'bind', 'other']))) {
  1062. if (empty($post['vertify'])) $this->error('请输入图形验证码!');
  1063. $verify = new \think\Verify();
  1064. if (!$verify->check($post['vertify'], $post['type'])) $this->error('图形验证码错误!', null, ['code' => 'vertify']);
  1065. }
  1066. /* END */
  1067. /*发送并返回结果*/
  1068. $Result = sendSms($source, $mobile, array('content' => mt_rand(1000, 9999)));
  1069. if (intval($Result['status']) == 1) {
  1070. $this->success('发送成功!');
  1071. } else {
  1072. $this->error($Result['msg']);
  1073. }
  1074. /* END */
  1075. }
  1076. }
  1077. }
  1078. // 判断文章内容阅读权限
  1079. public function get_arcrank($aid = '', $vars = '',$tid = '')
  1080. {
  1081. $aid = intval($aid);
  1082. $tid = intval($tid);
  1083. $vars = intval($vars);
  1084. $gourl = input('param.gourl/s');
  1085. $gourl = urldecode($gourl);
  1086. $gourl = !empty($gourl) ? urldecode($gourl) : ROOT_DIR . '/';
  1087. if ((IS_AJAX || !empty($vars)) && !empty($aid)) {
  1088. // 用户ID
  1089. $users_id = session('users_id');
  1090. // 文章查看所需等级值
  1091. $Arcrank = Db::name('archives')->alias('a')
  1092. ->field('a.users_id, a.arcrank,c.typearcrank,c.page_limit')
  1093. ->join('__ARCTYPE__ c', 'a.typeid = c.id', 'LEFT')
  1094. ->where(['a.aid' => $aid])
  1095. ->find();
  1096. $Arcrank['page_limit'] = empty($Arcrank['page_limit']) ? [] : explode(',', $Arcrank['page_limit']);
  1097. //文章存在限制条件,优先使用文章限制条件;如不存在,则使用栏目限制条件。
  1098. if (empty($Arcrank['arcrank']) && (!empty($Arcrank['typearcrank']) && $Arcrank['typearcrank'] > 0 && in_array(2, $Arcrank['page_limit']))) {
  1099. $Arcrank['arcrank'] = $Arcrank['typearcrank'];
  1100. }
  1101. if (!empty($users_id)) {
  1102. // 会员级别等级值
  1103. $UsersDataa = Db::name('users')->alias('a')
  1104. ->field('a.users_id,b.level_value,b.level_name')
  1105. ->join('__USERS_LEVEL__ b', 'a.level = b.level_id', 'LEFT')
  1106. ->where(['a.users_id' => $users_id])
  1107. ->find();
  1108. if (0 == $Arcrank['arcrank']) {
  1109. if (IS_AJAX) {
  1110. $this->success('允许查阅!');
  1111. } else {
  1112. return true;
  1113. }
  1114. } else if (-1 == $Arcrank['arcrank']) {
  1115. $is_admin = session('?admin_id') ? 1 : 0;
  1116. $param_admin_id = input('param.admin_id/d');
  1117. if ($users_id == $Arcrank['users_id']) {
  1118. if (IS_AJAX) {
  1119. $this->success('允许查阅!', null, ['is_admin' => $is_admin, 'msg' => '待审核稿件,仅限自己查看!']);
  1120. } else {
  1121. return true;
  1122. }
  1123. } else if (!empty($is_admin) && !empty($param_admin_id)) {
  1124. if (IS_AJAX) {
  1125. $this->success('允许查阅!', null, ['is_admin' => $is_admin, 'msg' => '待审核稿件,仅限管理员查看!']);
  1126. } else {
  1127. return true;
  1128. }
  1129. } else {
  1130. $msg = '待审核稿件,你没有权限阅读!';
  1131. }
  1132. } else if ($UsersDataa['level_value'] < $Arcrank['arcrank']) {
  1133. $level_name = Db::name('users_level')->where(['level_value' => $Arcrank['arcrank']])->getField('level_name');
  1134. $msg = '__html__内容需要【' . $level_name . '】才可以查看<br/>您为【' . $UsersDataa['level_name'] . '】,请先升级!';
  1135. } else {
  1136. if (IS_AJAX) {
  1137. $this->success('允许查阅!');
  1138. } else {
  1139. return true;
  1140. }
  1141. }
  1142. if (IS_AJAX) {
  1143. $this->error($msg);
  1144. } else {
  1145. return $msg;
  1146. }
  1147. } else {
  1148. if (0 == $Arcrank['arcrank']) {
  1149. if (IS_AJAX) {
  1150. $this->success('允许查阅!');
  1151. } else {
  1152. return true;
  1153. }
  1154. } else if (-1 == $Arcrank['arcrank']) {
  1155. $is_admin = session('?admin_id') ? 1 : 0;
  1156. $param_admin_id = input('param.admin_id/d');
  1157. if (!empty($is_admin) && !empty($param_admin_id)) {
  1158. $this->success('允许查阅!', null, ['is_admin' => $is_admin, 'msg' => '待审核稿件,仅限管理员查看!']);
  1159. } else {
  1160. $msg = '待审核稿件,你没有权限阅读!';
  1161. }
  1162. } else if (!empty($Arcrank['arcrank'])) {
  1163. $level_name = Db::name('users_level')->where(['level_value' => $Arcrank['arcrank']])->getField('level_name');
  1164. $msg = '文章需要【' . $level_name . '】才可以查看,游客不可查看,请登录!';
  1165. } else {
  1166. $msg = '游客不可查看,请登录!';
  1167. }
  1168. if (IS_AJAX) {
  1169. $loginUrl = url('user/Users/login');
  1170. if (stristr($loginUrl, '?')) {
  1171. $gourl = $loginUrl . "&referurl=" . urlencode($gourl);
  1172. } else {
  1173. $gourl = $loginUrl . "?referurl=" . urlencode($gourl);
  1174. }
  1175. $data = [
  1176. 'is_login' => 0,
  1177. 'gourl' => $gourl,
  1178. ];
  1179. $this->error($msg, null, $data);
  1180. } else {
  1181. return $msg;
  1182. }
  1183. }
  1184. } else if ((IS_AJAX || !empty($vars)) && !empty($tid)) {
  1185. // 用户ID
  1186. $users_id = session('users_id');
  1187. // 文章查看所需等级值
  1188. $Arcrank = Db::name('arctype')
  1189. ->field('typearcrank,page_limit')
  1190. ->where(['id' => $tid])
  1191. ->find();
  1192. $Arcrank['page_limit'] = empty($Arcrank['page_limit']) ? [] : explode(',', $Arcrank['page_limit']);
  1193. //文章存在限制条件,优先使用文章限制条件;如不存在,则使用栏目限制条件。
  1194. if (!empty($Arcrank['typearcrank']) && $Arcrank['typearcrank'] > 0 && in_array(1, $Arcrank['page_limit'])) {
  1195. if (!empty($users_id)) {
  1196. // 会员级别等级值
  1197. $UsersDataa = Db::name('users')->alias('a')
  1198. ->field('a.users_id,b.level_value,b.level_name')
  1199. ->join('__USERS_LEVEL__ b', 'a.level = b.level_id', 'LEFT')
  1200. ->where(['a.users_id' => $users_id])
  1201. ->find();
  1202. if ($UsersDataa['level_value'] < $Arcrank['typearcrank']) {
  1203. $level_name = Db::name('users_level')->where(['level_value' => $Arcrank['typearcrank']])->getField('level_name');
  1204. $msg = '__html__内容需要【' . $level_name . '】才可以查看<br/>您为【' . $UsersDataa['level_name'] . '】,请先升级!';
  1205. if (IS_AJAX) {
  1206. $this->error($msg);
  1207. } else {
  1208. return $msg;
  1209. }
  1210. }
  1211. } else {
  1212. $level_name = Db::name('users_level')->where(['level_value' => $Arcrank['typearcrank']])->getField('level_name');
  1213. $msg = '文章需要【' . $level_name . '】才可以查看,游客不可查看,请登录!';
  1214. if (IS_AJAX) {
  1215. $loginUrl = url('user/Users/login');
  1216. if (stristr($loginUrl, '?')) {
  1217. $gourl = $loginUrl . "&referurl=" . urlencode($gourl);
  1218. } else {
  1219. $gourl = $loginUrl . "?referurl=" . urlencode($gourl);
  1220. }
  1221. $data = [
  1222. 'is_login' => 0,
  1223. 'gourl' => $gourl,
  1224. ];
  1225. $this->error($msg, null, $data);
  1226. } else {
  1227. return $msg;
  1228. }
  1229. }
  1230. }
  1231. if (IS_AJAX) {
  1232. $this->success('允许查阅!');
  1233. } else {
  1234. return true;
  1235. }
  1236. } else {
  1237. to_index("404");
  1238. }
  1239. }
  1240. /**
  1241. * 获取会员列表
  1242. * @author 小虎哥 by 2018-4-20
  1243. */
  1244. public function get_tag_memberlist()
  1245. {
  1246. if (IS_AJAX_POST) {
  1247. // 接收html实体代码
  1248. $htmlcode = input('post.htmlcode/s', '');
  1249. $htmlcode = htmlspecialchars_decode($htmlcode);
  1250. $htmlcode = preg_replace('/<\?(\s*)php(\s+)/i', '', $htmlcode);
  1251. // 接收标签参数
  1252. $attarray = input('post.attarray/s', '');
  1253. $attarray = htmlspecialchars_decode($attarray);
  1254. $attarray = json_decode(base64_decode($attarray), true);
  1255. // 查询会员表字段
  1256. $field = [];
  1257. $usersField = Db::name("users")->getTableFields();
  1258. foreach ($usersField as $key => $value) {
  1259. $field[$key] = $value . '_eyoucms_fields';
  1260. }
  1261. // 会员表自定义字段
  1262. $where = [
  1263. 'is_hidden' => 0,
  1264. 'lang' => $this->home_lang,
  1265. // 'dtype' => ['NOT IN', ['imgs']],
  1266. ];
  1267. $usersParams = Db::name("users_parameter")->field('para_id, name')->where($where)->order('para_id asc')->select();
  1268. foreach ($usersParams as $key => $value) {
  1269. $field[count($field)] = $value['name'] . '_eyoucms_params';
  1270. }
  1271. // dump($field);exit;
  1272. // 查询排序
  1273. $orderby = !empty($attarray['orderby']) ? $attarray['orderby'] : '';
  1274. switch ($orderby) {
  1275. case 'logintime': // 兼容写法
  1276. case 'last_login':
  1277. $orderby = "last_login desc";
  1278. break;
  1279. case 'users_id':
  1280. $orderby = "users_id desc";
  1281. break;
  1282. case 'regtime':
  1283. case 'reg_time':
  1284. $orderby = "reg_time desc";
  1285. break;
  1286. default:
  1287. {
  1288. if (in_array($orderby, $usersField)) {
  1289. $orderby = "{$orderby} desc";
  1290. } else {
  1291. $orderby = "users_id desc";
  1292. }
  1293. break;
  1294. }
  1295. }
  1296. // 查询会员表数据
  1297. $where = [
  1298. 'admin_id' => 0,
  1299. 'lang' => $this->home_lang,
  1300. ];
  1301. $limit = !empty($attarray['row']) ? intval($attarray['row']) : 10;
  1302. $list = Db::name("users")->where($where)->order($orderby)->limit($limit)->select();
  1303. // 查询会员自定义数据
  1304. $where = [
  1305. 'lang' => $this->home_lang,
  1306. // 'para_id' => ['NOT IN', [11]],
  1307. ];
  1308. $usersList = Db::name("users_list")->field('para_id, users_id, info')->where($where)->order('para_id asc')->select();
  1309. $usersList = group_same_key($usersList, 'users_id');
  1310. // 查询会员等级数据
  1311. $where = [
  1312. 'lang' => $this->home_lang,
  1313. ];
  1314. $usersLevel = Db::name("users_level")->where($where)->order('level_id asc')->getField('level_id, level_name');
  1315. // 循环处理会员html显示代码
  1316. $html = '';
  1317. foreach ($list as $key => $value) {
  1318. // 内置数据处理
  1319. $value['paypwd'] = '<font style="color: red;">不支持显示支付密码</font>';
  1320. $value['password'] = '<font style="color: red;">不支持显示登录密码</font>';
  1321. $value['head_pic'] = get_head_pic($value['head_pic'], false, $value['sex']);
  1322. $value['level'] = !empty($usersLevel[$value['level']]) ? $usersLevel[$value['level']] : '';
  1323. // 会员自定义数据与内置数据合并
  1324. $infoValue = [];
  1325. if (!empty($usersList[$value['users_id']])) {
  1326. $infoValue = get_arr_column($usersList[$value['users_id']], 'info');
  1327. $infoValue[10] = '" alt="不支持显示自定义多图';
  1328. } else {
  1329. $infoValue = [0 => '', 1 => '', 2 => '', 3 => '', 4 => '', 5 => '', 6 => '', 7 => '', 8 => '', 9 => '', 10 => '" alt="不支持显示自定义多图'];
  1330. }
  1331. $value = array_merge($value, $infoValue);
  1332. // 替换指定字段数据
  1333. $html .= str_replace($field, $value, $htmlcode);
  1334. }
  1335. // dump($html);exit;
  1336. $this->success('读取成功!', null, ['html' => htmlspecialchars_decode($html)]);
  1337. }
  1338. $this->error('加载失败!');
  1339. }
  1340. /**
  1341. * 发布或编辑文档时,百度自动推送
  1342. */
  1343. public function push_zzbaidu($url, $type = 'add')
  1344. {
  1345. if (empty($url)) {
  1346. $this->error('无效url推送');
  1347. }
  1348. $msg = '百度推送URL失败!';
  1349. if (IS_AJAX_POST) {
  1350. \think\Session::pause(); // 暂停session,防止session阻塞机制
  1351. // 获取token的值:http://ziyuan.baidu.com/linksubmit/index?site=http://www.eyoucms.com/
  1352. $sitemap_zzbaidutoken = config('tpcache.sitemap_zzbaidutoken');
  1353. if (empty($sitemap_zzbaidutoken)) {
  1354. $this->error('尚未配置实时推送Url的token!', null, ['code' => 0]);
  1355. } else if (!function_exists('curl_init')) {
  1356. $this->error('请开启php扩展curl_init', null, ['code' => 1]);
  1357. }
  1358. $urlsArr = is_array($url) ? $url : [$url];
  1359. // $type = ('edit' == $type) ? 'update' : 'urls';
  1360. $type = 'urls';
  1361. if (is_http_url($sitemap_zzbaidutoken)) {
  1362. $searchs = ["/urls?", "/update?"];
  1363. $replaces = ["/{$type}?", "/{$type}?"];
  1364. $api = str_replace($searchs, $replaces, $sitemap_zzbaidutoken);
  1365. } else {
  1366. $api = 'http://data.zz.baidu.com/' . $type . '?site=' . $this->request->host(true) . '&token=' . trim($sitemap_zzbaidutoken);
  1367. }
  1368. $ch = curl_init();
  1369. $options = array(
  1370. CURLOPT_URL => $api,
  1371. CURLOPT_POST => true,
  1372. CURLOPT_RETURNTRANSFER => true,
  1373. CURLOPT_POSTFIELDS => implode("\n", $urlsArr),
  1374. CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
  1375. );
  1376. curl_setopt_array($ch, $options);
  1377. $result = curl_exec($ch);
  1378. !empty($result) && $result = json_decode($result, true);
  1379. if (!empty($result['success'])) {
  1380. $this->success('百度推送URL成功!');
  1381. } else {
  1382. $msg = !empty($result['message']) ? $result['message'] : $msg;
  1383. }
  1384. }
  1385. $this->error($msg);
  1386. }
  1387. /**
  1388. * 发布或编辑文档/栏目时,小程序 API 提交
  1389. * 将小程序资源 path 路径,提交到 API 接口中
  1390. */
  1391. public function push_bdminipro($aid = 0, $typeid = 0)
  1392. {
  1393. //先判断是否安装百度小程序插件
  1394. $BdDiyminipro = Db::name('weapp')->where('code', 'BdDiyminipro')->where('status', 1)->find();
  1395. if (empty($BdDiyminipro)) {
  1396. $this->error('未安装可视化百度小程序!');
  1397. } else {
  1398. $data = Db::name('weapp_bd_diyminipro_setting')->where('name', 'setting')->order('mini_id desc')->find();
  1399. $value = json_decode($data['value'], true);
  1400. if (empty($value['appKey']) || empty($value['appSecret'])) {
  1401. $this->error('未配置可视化百度小程序!');
  1402. }
  1403. $access_token = '';
  1404. if (empty($value['access_token']) || empty($value['access_token_extime']) || $value['access_token_extime'] < getTime()) {
  1405. if (!empty($value['appId'])) {
  1406. $values = [];
  1407. $values['appId'] = $value['appId'];
  1408. $url = "http://service.eyysz.cn/index.php?m=api&c=BaiduMiniproClient&a=minipro&" . http_build_query($values);
  1409. $response = httpRequest($url);
  1410. $params = array();
  1411. $params = json_decode($response, true);
  1412. if (!empty($params) && $params['errcode'] == 0) {
  1413. $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';
  1414. $response1 = httpRequest($at_url);
  1415. $params1 = array();
  1416. $params1 = json_decode($response1, true);
  1417. if (!empty($params1['access_token'])) {
  1418. $value['access_token'] = $access_token = $params1['access_token'];
  1419. $value['access_token_extime'] = getTime() + $params1['expires_in'];
  1420. $updateValue = json_encode($value);
  1421. Db::name('weapp_bd_diyminipro_setting')->where('mini_id', $data['mini_id'])->update(['value' => $updateValue, 'update_time' => getTime()]);
  1422. }
  1423. }
  1424. }
  1425. } else {
  1426. $access_token = $value['access_token'];
  1427. }
  1428. if (!empty($access_token)) {
  1429. $res = push_bdminiproapi($access_token, 1, $aid, $typeid);
  1430. if (!empty($res)) {
  1431. $msg = !empty($res['msg']) ? $res['msg'] : $res['error_msg'];
  1432. $this->success($msg);
  1433. }
  1434. }
  1435. }
  1436. }
  1437. /*
  1438. * 视频权限播放逻辑
  1439. */
  1440. public function video_logic()
  1441. {
  1442. $post = input('post.');
  1443. if (IS_AJAX_POST && !empty($post['aid'])) {
  1444. // 查询文档信息
  1445. $field = 'a.*,b.*,c.*';
  1446. $where = [
  1447. 'a.aid' => $post['aid'],
  1448. 'a.is_del' => 0
  1449. ];
  1450. $archivesInfo = Db::name('archives')
  1451. ->alias('a')
  1452. ->field($field)
  1453. ->join('__USERS_LEVEL__ b', 'a.arc_level_id = b.level_id', 'LEFT')
  1454. ->join('__ARCTYPE__ c', 'c.id = a.typeid', 'LEFT')
  1455. ->where($where)
  1456. ->find();
  1457. if (5 == $archivesInfo['channel']) {
  1458. // 获取用户最新信息
  1459. $UsersData = GetUsersLatestData();
  1460. $UsersID = !empty($UsersData['users_id']) ? $UsersData['users_id'] : 0;
  1461. $result['status_value'] = 0; // status_value 0-所有人免费 1-所有人付费 2-会员免费 3-会员付费
  1462. $result['status_name'] = ''; //status_name 要求会员等级时会员级别名称
  1463. $result['play_auth'] = 0; //播放权限
  1464. $result['vip_status'] = 0; //status_value=3时使用 vip_status=1则已升级会员暂未购买
  1465. $users_price = get_discount_price($UsersData['level_discount'], $archivesInfo['users_price']);
  1466. /*是否需要付费*/
  1467. if (0 < $archivesInfo['users_price'] && empty($archivesInfo['users_free'])) {
  1468. if (empty($archivesInfo['arc_level_id'])) {
  1469. //不限会员 付费
  1470. $result['status_value'] = 1;
  1471. $result['users_price'] = $users_price;
  1472. } else {
  1473. //3-限制会员 付费
  1474. $result['status_value'] = 3;
  1475. $result['users_price'] = $users_price;
  1476. if ($archivesInfo['level_value'] <= $UsersData['level_value']) {
  1477. $result['vip_status'] = 1;//已升级会员未购买
  1478. }
  1479. }
  1480. if (!empty($UsersID)) {
  1481. $where = [
  1482. 'users_id' => intval($UsersID),
  1483. 'product_id' => intval($post['aid']),
  1484. 'order_status' => 1
  1485. ];
  1486. // 存在数据则已付费
  1487. $Paid = Db::name('media_order')->where($where)->count();
  1488. //已购买
  1489. if (!empty($Paid)) {
  1490. if (3 == $result['status_value']) {
  1491. if (1 == $result['vip_status']) {
  1492. $result['play_auth'] = 1;
  1493. $result['vip_status'] = 3;//已升级会员已经购买
  1494. } else {
  1495. $result['play_auth'] = 0;
  1496. $result['vip_status'] = 2;//未升级会员已经购买
  1497. }
  1498. } else {
  1499. $result['play_auth'] = 1;
  1500. $result['vip_status'] = 4;//不限会员已经购买
  1501. }
  1502. }
  1503. }
  1504. } else {
  1505. if (0 < intval($archivesInfo['arc_level_id'])) { // 会员免费
  1506. $result['status_value'] = 2;
  1507. if (!empty($UsersID) && $archivesInfo['level_value'] <= $UsersData['level_value']) {
  1508. $result['play_auth'] = 1;
  1509. }
  1510. } else { // 所有人免费
  1511. $result['play_auth'] = 1;
  1512. }
  1513. }
  1514. /*END*/
  1515. /**注册会员免费但是没有登录*/
  1516. // if (empty($UsersID) && !empty($result['status_value'])) {
  1517. // $this->error('请先登录', url('user/Users/login'));
  1518. // }
  1519. $where = [
  1520. 'users_id' => intval($UsersID),
  1521. 'product_id' => intval($post['aid']),
  1522. 'order_status' => 1
  1523. ];
  1524. // 存在数据则已付费
  1525. /*END*/
  1526. $is_pay = 0;
  1527. if (in_array($result['status_value'], [1, 3])) { // 所有人、会员付费
  1528. $is_pay = Db::name('media_order')->where($where)->count();
  1529. }
  1530. $result['is_pay'] = $is_pay;
  1531. if (in_array($result['status_value'], [2, 3])) { // 已满足会员级别要求
  1532. $result['status_name'] = Db::name('users_level')->where('level_id', intval($archivesInfo['arc_level_id']))->value('level_name');
  1533. }
  1534. /*
  1535. if (in_array($result['status_value'], [2,3])){ // 会员免费与会员付费
  1536. $result['status_name'] = Db::name('users_level')->where('level_id', $archivesInfo['arc_level_id'])->value('level_name');
  1537. $vip_status = 0;
  1538. if ($archivesInfo['level_value'] <= $UsersData['level_value']) {
  1539. $vip_status = 1; // 已满足会员级别要求
  1540. }
  1541. }*/
  1542. if ($result['status_value'] == 0) {
  1543. $result['button'] = '免费';
  1544. $result['status_name'] = '免费';
  1545. } else if ($result['status_value'] == 1) { // 所有人付费
  1546. $result['button'] = '付费';
  1547. if (!empty($is_pay)) {
  1548. $result['button'] = '观看';
  1549. }
  1550. } else if ($result['status_value'] == 2) { // 会员免费/单独付费
  1551. $result['button'] = 'VIP';
  1552. $result['button_url'] = "window.location.href = '" . url('user/Level/level_centre', ['aid' => $archivesInfo['aid']]) . "'";
  1553. if (!empty($result['play_auth'])) {
  1554. $result['button'] = '观看';
  1555. }
  1556. } else if ($result['status_value'] == 3) { // 会员付费
  1557. // if(1 == $result['vip_status']){
  1558. // $result['button'] = '立即购买';
  1559. // $result['button_url'] = 'MediaOrderBuy_v878548();';
  1560. // }else
  1561. if (2 == $result['vip_status']) {
  1562. $result['button'] = 'VIP';
  1563. $result['button_url'] = "window.location.href = '" . url('user/Level/level_centre', ['aid' => $archivesInfo['aid']]) . "'";
  1564. } else if (3 == $result['vip_status']) {
  1565. $result['button'] = '观看';
  1566. } else {
  1567. $result['button'] = 'VIP付费';
  1568. $result['button_url'] = "window.location.href = '" . url('user/Level/level_centre', ['aid' => $archivesInfo['aid']]) . "'";
  1569. }
  1570. // if (!empty($is_pay) && !empty($result['vip_status'])){
  1571. // $result['button'] = '观看';
  1572. // }
  1573. }
  1574. if ('观看' == $result['button']) {
  1575. $result['button_url'] = arcurl('home/Media/view', $archivesInfo);
  1576. }
  1577. $this->success('查询成功', null, $result);
  1578. } else {
  1579. $this->error('非视频模型的文档!');
  1580. }
  1581. }
  1582. to_index("404");
  1583. }
  1584. /**
  1585. * 查看站内通知
  1586. */
  1587. public function notice_read()
  1588. {
  1589. $id = input('param.id/d');
  1590. $users_id = session('users.users_id');
  1591. $users_id = intval($users_id);
  1592. if (!empty($id) && !empty($users_id)) {
  1593. $count = Db::name('users_notice_read')
  1594. ->where(['id' => $id])
  1595. ->value("id");
  1596. if (empty($count)) $this->error('未知错误!');
  1597. //未读消息数-1
  1598. $unread_num = Db::name('users')->where(['users_id' => $users_id])->value("unread_notice_num");
  1599. if ($unread_num > 0) {
  1600. $unread_num = $unread_num - 1;
  1601. Db::name('users')->where(['users_id' => $users_id])->update(['unread_notice_num' => $unread_num]);
  1602. }
  1603. Db::name('users_notice_read')->where(['id' => $id])->update(['is_read' => 1]);
  1604. $this->success('保存成功', null, ['unread_num' => $unread_num]);
  1605. }
  1606. }
  1607. /**
  1608. * 收藏与取消
  1609. * @return [type] [description]
  1610. */
  1611. public function collect_save()
  1612. {
  1613. $aid = input('param.aid/d');
  1614. if (IS_AJAX && !empty($aid)) {
  1615. $users_id = session('users_id');
  1616. if (empty($users_id)) {
  1617. $this->error('请先登录!');
  1618. }
  1619. $row = Db::name('users_collection')->where([
  1620. 'users_id' => $users_id,
  1621. 'aid' => $aid,
  1622. ])->find();
  1623. if (empty($row)) {
  1624. $archivesInfo = Db::name('archives')->field('aid,title,litpic,channel,typeid')->find($aid);
  1625. if (!empty($archivesInfo)) {
  1626. $r = Db::name('users_collection')->add([
  1627. 'users_id' => $users_id,
  1628. 'title' => $archivesInfo['title'],
  1629. 'aid' => $aid,
  1630. 'litpic' => $archivesInfo['litpic'],
  1631. 'channel' => $archivesInfo['channel'],
  1632. 'typeid' => $archivesInfo['typeid'],
  1633. 'lang' => $this->home_lang,
  1634. 'add_time' => getTime(),
  1635. 'update_time' => getTime(),
  1636. ]);
  1637. if (!empty($r)) {
  1638. Db::name('archives')->where('aid', $aid)->setInc('collection');
  1639. $this->success('收藏成功', null, ['opt' => 'add']);
  1640. }
  1641. }
  1642. } else {
  1643. $r = Db::name('users_collection')->where([
  1644. 'users_id' => $users_id,
  1645. 'aid' => $aid,
  1646. ])->delete();
  1647. Db::name('archives')->where('aid', $aid)->setDec('collection');
  1648. $this->success('取消成功', null, ['opt' => 'cancel']);
  1649. }
  1650. $this->error('收藏失败', null);
  1651. }
  1652. to_index("404");
  1653. }
  1654. /**
  1655. * 判断是否收藏
  1656. * @return [type] [description]
  1657. */
  1658. public function get_collection()
  1659. {
  1660. if (IS_AJAX) {
  1661. $aid = input('param.aid/d');
  1662. $users_id = session('users_id');
  1663. $total = Db::name('users_collection')->where([
  1664. 'aid' => $aid,
  1665. ])->count();
  1666. if (!empty($users_id)) {
  1667. $count = Db::name('users_collection')->where([
  1668. 'aid' => $aid,
  1669. 'users_id' => $users_id,
  1670. ])->count();
  1671. if (!empty($count)) {
  1672. $this->success('已收藏', null, ['total' => $total]);
  1673. }
  1674. }
  1675. $this->error('未收藏', null, ['total' => $total]);
  1676. }
  1677. to_index("404");
  1678. }
  1679. /**
  1680. * 保存足迹
  1681. */
  1682. public function footprint_save()
  1683. {
  1684. $aid = input('param.aid/d');
  1685. $ajaxLogic = new \app\api\logic\AjaxLogic;
  1686. $data = $ajaxLogic->footprint_save($aid);
  1687. if ($data === false) {
  1688. to_index("404");
  1689. } else {
  1690. $this->success('ok');
  1691. }
  1692. }
  1693. /**
  1694. * 签到
  1695. * @return [type] [description]
  1696. */
  1697. public function signin_save()
  1698. {
  1699. if (IS_AJAX) {
  1700. $users_id = session('users_id');
  1701. if (empty($users_id)) {
  1702. $this->error('请先登录!');
  1703. }
  1704. $signin_conf = getUsersConfigData('score');
  1705. if (!$signin_conf || !isset($signin_conf['score_signin_status']) || $signin_conf['score_signin_status'] != 1) {
  1706. $this->error('未开启签到配置!');
  1707. }
  1708. //今日签到信息
  1709. $now_time = time();
  1710. $today_start = mktime(0, 0, 0, date("m", $now_time), date("d", $now_time), date("Y", $now_time));
  1711. $today_end = mktime(23, 59, 59, date("m", $now_time), date("d", $now_time), date("Y", $now_time));
  1712. $row = Db::name('users_signin')->where(['users_id' => $users_id, 'add_time' => ['BETWEEN', [$today_start, $today_end]]])->value("id");
  1713. if (!$row) {
  1714. $r = Db::name('users_signin')->add([
  1715. 'users_id' => $users_id,
  1716. 'lang' => $this->home_lang,
  1717. 'add_time' => getTime(),
  1718. ]);
  1719. if (!empty($r)) {
  1720. $scores_step = $signin_conf['score_signin_score'] ?: 0;
  1721. Db::name('users')->where(['users_id' => $users_id])->setInc('scores', $scores_step);
  1722. $users_scores = Db::name('users')->where(['users_id' => $users_id])->value("scores");
  1723. Db::name('users_score')->add([
  1724. 'type' => 5,//每日签到
  1725. 'users_id' => $users_id,
  1726. 'ask_id' => 0,
  1727. 'reply_id' => 0,
  1728. 'score' => '+' . $scores_step,
  1729. 'devote' => $scores_step,
  1730. 'money' => 0.00,
  1731. 'info' => '每日签到',
  1732. 'lang' => $this->home_lang,
  1733. 'add_time' => getTime(),
  1734. 'update_time' => getTime(),
  1735. 'current_score' => $users_scores,
  1736. ]);
  1737. $this->success('签到成功', null, ['scores' => $users_scores]);
  1738. }
  1739. $this->error('未知错误', null);
  1740. }
  1741. $this->error('今日已签过到', null);
  1742. }
  1743. to_index("404");
  1744. }
  1745. /**
  1746. * 登录页面清除session多余文件
  1747. */
  1748. public function clear_session()
  1749. {
  1750. if (IS_AJAX_POST) {
  1751. \think\Session::pause(); // 暂停session,防止session阻塞机制
  1752. clear_session_file(); // 清理过期的data/session文件
  1753. } else {
  1754. to_index("404");
  1755. }
  1756. }
  1757. //文章付费
  1758. public function ajax_get_content($aid = 0)
  1759. {
  1760. if (empty($aid)) {
  1761. $this->error('缺少文档id');
  1762. }
  1763. $artData = Db::name('archives')
  1764. ->alias('a')
  1765. ->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')
  1766. ->join('article_content b', 'a.aid = b.aid')
  1767. ->where('a.aid', $aid)
  1768. ->find();
  1769. if (isMobile() && !empty($artData['content_ey_m'])) {
  1770. $artData['content'] = $artData['content_ey_m'];
  1771. }
  1772. $artData['arc_level_value'] = 0;
  1773. if (0 < $artData['arc_level_id']) {
  1774. $artData['arc_level_value'] = Db::name('users_level')->where(['level_id' => $artData['arc_level_id']])->value('level_value');
  1775. }
  1776. if (empty($artData['restric_type'])) { // 免费
  1777. $result['display'] = 0; // 1-显示购买 0-不显示
  1778. $result['content'] = $artData['content'];
  1779. } else {
  1780. /*预览内容*/
  1781. $free_content = '';
  1782. $pay_data = Db::name('article_pay')->field('part_free,free_content')->where('aid', $aid)->find();
  1783. if (!empty($pay_data['part_free'])) {
  1784. $free_content = !empty($pay_data['free_content']) ? $pay_data['free_content'] : '';
  1785. }
  1786. /*end*/
  1787. $users_id = session('users_id');
  1788. !empty($users_id) && $UsersData = GetUsersLatestData();
  1789. $result['content'] = $free_content;
  1790. $result['users_price'] = get_discount_price($UsersData['level_discount'], $artData['users_price']);
  1791. if (1 == $artData['restric_type']) { // 付费
  1792. $result['display'] = 1; // 1-显示购买 0-不显示
  1793. if (!empty($users_id)) {
  1794. $is_pay = Db::name('article_order')->where(['users_id' => $users_id, 'order_status' => 1, 'product_id' => $aid])->find();
  1795. // 已经购买
  1796. if (!empty($is_pay)) {
  1797. $result['display'] = 0; // 1-显示购买 0-不显示
  1798. $result['content'] = $artData['content'];
  1799. }
  1800. }
  1801. }elseif (2 == $artData['restric_type']){ //指定会员 || 非会员付费
  1802. $result['vipDisplay'] = 1;// 1-显示会员限制 0-不显示
  1803. if (!empty($users_id)) {
  1804. if ($UsersData['level_value'] >= $artData['arc_level_value']){
  1805. $result['vipDisplay'] = 0;// 1-显示会员限制 0-不显示
  1806. $result['content'] = $artData['content'];
  1807. }else if (!empty($artData['no_vip_pay'])){
  1808. $is_pay = Db::name('article_order')->where(['users_id' => $users_id, 'order_status' => 1, 'product_id' => $aid])->find();
  1809. // 已经购买
  1810. if (!empty($is_pay)) {
  1811. $result['vipDisplay'] = 0; // 1-显示购买 0-不显示
  1812. $result['content'] = $artData['content'];
  1813. }else{
  1814. if (getCmsVersion() < 'v1.6.2') {
  1815. $result['display'] = 1; // 1-显示购买 0-不显示
  1816. } else {
  1817. $result['display'] = 0; // 1-显示购买 0-不显示
  1818. $result['vipDisplay'] = 1;// 1-显示会员限制 0-不显示
  1819. }
  1820. }
  1821. }
  1822. }
  1823. }elseif (3 == $artData['restric_type']){ //指定会员付费
  1824. $result['vipDisplay'] = 1;// 1-显示会员限制 0-不显示
  1825. $is_pay = Db::name('article_order')->where(['users_id' => $users_id, 'order_status' => 1, 'product_id' => $aid])->find();
  1826. if ($UsersData['level_value'] >= $artData['arc_level_value'] && !empty($is_pay)){
  1827. $result['vipDisplay'] = 0;// 1-显示会员限制 0-不显示
  1828. $result['content'] = $artData['content'];
  1829. }else if (empty($is_pay)){
  1830. if (getCmsVersion() < 'v1.6.2') {
  1831. $result['display'] = 1; // 1-显示购买 0-不显示
  1832. } else {
  1833. $result['display'] = 0; // 1-显示购买 0-不显示
  1834. $result['vipDisplay'] = 1;// 1-显示会员限制 0-不显示
  1835. }
  1836. if ($UsersData['level_value'] >= $artData['arc_level_value']){
  1837. if (isMobile()){
  1838. $result['buy_onclick'] = "ey_article_v968479({$aid});";//第一种跳转页面支付
  1839. }else {
  1840. $result['buy_onclick'] = "ArticleBuyNow({$aid});";//第二种弹框页支付
  1841. }
  1842. }
  1843. }
  1844. }
  1845. }
  1846. $result['content'] = htmlspecialchars_decode($result['content']);
  1847. $titleNew = !empty($artData['title']) ? $artData['title'] : '';
  1848. $result['content'] = img_style_wh($result['content'], $titleNew);
  1849. $result['content'] = handle_subdir_pic($result['content'], 'html');
  1850. if (is_dir('./weapp/Linkkeyword')) {
  1851. $LinkkeywordModel = new \weapp\Linkkeyword\model\LinkkeywordModel();
  1852. if (method_exists($LinkkeywordModel, 'handle_content')) {
  1853. $result['content'] = $LinkkeywordModel->handle_content($result['content']);
  1854. }
  1855. }
  1856. $this->success('success', null, $result);
  1857. }
  1858. //获取第三方上传的域名
  1859. public function get_third_domain()
  1860. {
  1861. $weappList = \think\Db::name('weapp')->field('code,data,status,config')->where([
  1862. 'status' => 1,
  1863. ])->cache(true, EYOUCMS_CACHE_TIME, 'weapp')
  1864. ->getAllWithIndex('code');
  1865. $third_domain = '';
  1866. if (!empty($weappList['Qiniuyun']) && 1 == $weappList['Qiniuyun']['status']) {
  1867. // 七牛云
  1868. $qnyData = json_decode($weappList['Qiniuyun']['data'], true);
  1869. $third_domain = $qnyData['domain'];
  1870. } else if (!empty($weappList['AliyunOss']) && 1 == $weappList['AliyunOss']['status']) {
  1871. // 到OSS
  1872. $ossData = json_decode($weappList['AliyunOss']['data'], true);
  1873. $third_domain = $ossData['domain'];
  1874. } else if (!empty($weappList['Cos']) && 1 == $weappList['Cos']['status']) {
  1875. // 同步图片到COS
  1876. $CosData = json_decode($weappList['Cos']['data'], true);
  1877. $third_domain = $CosData['domain'];
  1878. }
  1879. $this->success('success', null, $third_domain);
  1880. }
  1881. /**
  1882. * 获取表单数据信息
  1883. */
  1884. public function form_submit()
  1885. {
  1886. $form_id = input('post.form_id/d');
  1887. if (IS_POST && !empty($form_id)) {
  1888. $post = input('post.');
  1889. $ip = clientIP();
  1890. /*提交间隔限制*/
  1891. $channel_guestbook_interval = tpSetting('channel_guestbook.channel_guestbook_interval');
  1892. $channel_guestbook_interval = is_numeric($channel_guestbook_interval) ? intval($channel_guestbook_interval) : 60;
  1893. if (0 < $channel_guestbook_interval) {
  1894. $map = array(
  1895. 'ip' => $ip,
  1896. 'form_id' => $form_id,
  1897. 'lang' => $this->home_lang,
  1898. 'add_time' => array('gt', getTime() - $channel_guestbook_interval),
  1899. );
  1900. $count = Db::name('form_list')->where($map)->count('list_id');
  1901. if ($count > 0) {
  1902. if ($this->home_lang == 'cn') {
  1903. $msg = '同一个IP在' . $channel_guestbook_interval . '秒之内不能重复提交!';
  1904. } else if ($this->home_lang == 'zh') {
  1905. $msg = '同一個IP在' . $channel_guestbook_interval . '秒之內不能重複提交!';
  1906. } else {
  1907. $msg = 'The same IP cannot be submitted repeatedly within ' . $channel_guestbook_interval . ' seconds!';
  1908. }
  1909. $this->error($msg);
  1910. }
  1911. }
  1912. /*end*/
  1913. $come_url = input('post.come_url/s');
  1914. $parent_come_url = input('post.parent_come_url/s');
  1915. $come_url = !empty($parent_come_url) ? $parent_come_url : $come_url;
  1916. $come_from = input('post.come_from/s');
  1917. $city = "";
  1918. $newData = array(
  1919. 'form_id' => $form_id,
  1920. 'ip' => $ip,
  1921. 'aid' => !empty($post['aid']) ? $post['aid'] : 0,
  1922. 'come_from' => $come_from,
  1923. 'come_url' => $come_url,
  1924. 'city' => $city,
  1925. 'lang' => $this->home_lang,
  1926. 'add_time' => getTime(),
  1927. 'update_time' => getTime(),
  1928. );
  1929. $data = array_merge($post, $newData);
  1930. // 数据验证
  1931. $token = '__token__';
  1932. foreach ($post as $key => $val) {
  1933. if (preg_match('/^__token__/i', $key)) {
  1934. $token = $key;
  1935. break;
  1936. }
  1937. }
  1938. $rule = [
  1939. 'form_id' => 'require|token:' . $token,
  1940. ];
  1941. $message = [
  1942. 'form_id.require' => '表单缺少标签属性{$field.hidden}',
  1943. ];
  1944. $validate = new \think\Validate($rule, $message);
  1945. if (!$validate->batch()->check($data)) {
  1946. $error = $validate->getError();
  1947. $error_msg = array_values($error);
  1948. $this->error($error_msg[0]);
  1949. } else {
  1950. $formlistRow = [];
  1951. /*处理是否重复表单数据的提交*/
  1952. $formdata = $data;
  1953. foreach ($formdata as $key => $val) {
  1954. if (in_array($key, ['form_id', 'ip', 'aid']) || preg_match('/^field_(\d+)$/i', $key)) {
  1955. continue;
  1956. }
  1957. unset($formdata[$key]);
  1958. }
  1959. $md5data = md5(serialize($formdata));
  1960. $data['md5data'] = $md5data;
  1961. $formlistRow = Db::name('form_list')->field('list_id')->where(['md5data' => $md5data])->find();
  1962. /*--end*/
  1963. if (empty($formlistRow)) { // 非重复表单的才能写入数据库
  1964. $list_id = Db::name('form_list')->insertGetId($data);
  1965. if ($list_id > 0) {
  1966. $this->saveFormValue($list_id, $form_id, $post);
  1967. }
  1968. } else {
  1969. // 存在重复数据的表单,将在后台显示在最前面
  1970. $list_id = $formlistRow['list_id'];
  1971. Db::name('form_list')->where('list_id', $list_id)->update([
  1972. 'is_read' => 0,
  1973. 'add_time' => getTime(),
  1974. 'update_time' => getTime(),
  1975. ]);
  1976. }
  1977. if ($this->home_lang == 'cn') {
  1978. $msg = '操作成功';
  1979. } else if ($this->home_lang == 'zh') {
  1980. $msg = '操作成功';
  1981. } else {
  1982. $msg = 'success';
  1983. }
  1984. $this->success($msg, null, ['form_id' => $form_id, 'list_id' => $list_id]);
  1985. }
  1986. }
  1987. $this->error('表单缺少标签属性{$field.hidden}');
  1988. }
  1989. /**
  1990. * 给指定报名信息添加表单值到 form_value
  1991. * @param int $list_id 报名id
  1992. * @param int $form_id 表单id
  1993. */
  1994. private function saveFormValue($list_id, $form_id, $post)
  1995. {
  1996. /*上传图片或附件*/
  1997. $arr = explode(',', config('global.image_ext'));
  1998. foreach ($_FILES as $fileElementId => $file) {
  1999. try {
  2000. if (!empty($file['name']) && !is_array($file['name'])) {
  2001. $ext = pathinfo($file['name'], PATHINFO_EXTENSION);
  2002. if (in_array($ext, $arr)) {
  2003. $uplaod_data = func_common($fileElementId, 'allimg');
  2004. } else {
  2005. $uplaod_data = func_common_doc($fileElementId, 'files');
  2006. }
  2007. if (0 == $uplaod_data['errcode']) {
  2008. $post[$fileElementId] = $uplaod_data['img_url'];
  2009. } else {
  2010. // return $uplaod_data['errmsg'];
  2011. $post[$fileElementId] = '';
  2012. }
  2013. }
  2014. } catch (\Exception $e) {
  2015. }
  2016. }
  2017. /*end*/
  2018. $notify_content_arr = []; // 添加站内信所需参数
  2019. $send_content_str = ""; //发送短信内容
  2020. $field_list = Db::name("form_field")->where(['form_id' => $form_id])->getField("field_id,field_name,field_type");
  2021. // post 提交的属性 以 field_id _ 和值的 组合为键名
  2022. foreach ($post as $key => $val) {
  2023. if (!strstr($key, 'field_'))
  2024. continue;
  2025. $val = addslashes(htmlspecialchars(strip_tags($val)));
  2026. $field_id = str_replace('field_', '', $key);
  2027. $field_id = intval($field_id);
  2028. is_array($val) && $val = implode(',', $val);
  2029. $val = trim($val);
  2030. $field_value = stripslashes(filter_line_return($val, '。'));
  2031. $adddata = array(
  2032. 'form_id' => $form_id,
  2033. 'list_id' => $list_id,
  2034. 'field_id' => $field_id,
  2035. 'field_value' => $field_value,
  2036. 'add_time' => getTime(),
  2037. 'update_time' => getTime(),
  2038. );
  2039. Db::name('form_value')->add($adddata);
  2040. $field_value = get_form_read_value($field_value, $field_list[$field_id]['field_type'], true);
  2041. array_push($notify_content_arr, $field_value); //添加站内信数据
  2042. $send_content_str .= $field_list[$field_id]['field_name'] . ':' . $field_value . '<br/>';
  2043. }
  2044. /*发送站内信给后台*/
  2045. SendNotifyMessage($notify_content_arr, 1, 1, 0);
  2046. /* END */
  2047. /* 发送短信 */
  2048. $is_open = Db::name('smtp_tpl')->where(['send_scene' => 1, 'lang' => $this->home_lang])->value('is_open');
  2049. $smtp_config = tpCache('smtp');
  2050. if (empty($is_open) || empty($smtp_config['smtp_user']) || empty($smtp_config['smtp_pwd'])) {
  2051. return false;
  2052. }
  2053. $send_email_scene = config('send_email_scene');
  2054. $scene = $send_email_scene[1]['scene'];
  2055. $web_name = tpCache('web.web_name'); //title
  2056. $web_name .= "-表单消息";
  2057. $html = "<p style='text-align: left;'>{$web_name}</p><p style='text-align: left;'>{$send_content_str}</p>";
  2058. if (isMobile()) {
  2059. $html .= "<p style='text-align: left;'>——来源:移动端</p>";
  2060. } else {
  2061. $html .= "<p style='text-align: left;'>——来源:电脑端</p>";
  2062. }
  2063. // 发送邮件
  2064. $res = send_email(null, null, $html, $scene);
  2065. /* END */
  2066. return $res;
  2067. }
  2068. //下载付费
  2069. public function get_download($aid = 0)
  2070. {
  2071. if (empty($aid)) {
  2072. $this->error('缺少文档id');
  2073. }
  2074. $artData = Db::name('archives')
  2075. ->where('aid', $aid)
  2076. ->find();
  2077. $artData['arc_level_value'] = 0;
  2078. if (0 < $artData['arc_level_id']) {
  2079. $artData['arc_level_value'] = Db::name('users_level')->where(['level_id' => $artData['arc_level_id']])->value('level_value');
  2080. }
  2081. $users_id = session('users_id');
  2082. $UsersData = empty($users_id) ? [] : GetUsersLatestData();
  2083. $canDownload = 0;
  2084. $buyVip = 0;
  2085. $msg = '';
  2086. $download_tips = '';
  2087. if (empty($artData['restric_type'])) { // 免费
  2088. $canDownload = 1;
  2089. } else if (1 == $artData['restric_type']) { // 付费
  2090. // 查询是否已购买
  2091. $where = [
  2092. 'order_status' => 1,
  2093. 'product_id' => intval($aid),
  2094. 'users_id' => $users_id
  2095. ];
  2096. $count = Db::name('download_order')->where($where)->count();
  2097. if (!empty($count)) {
  2098. $canDownload = 1;
  2099. $download_tips = '您已购买,可直接下载';
  2100. }
  2101. } else if (2 == $artData['restric_type']) { // 会员专享
  2102. if ($UsersData['level_value'] >= $artData['arc_level_value']) {
  2103. $canDownload = 1;
  2104. $download_tips = "您已是{$UsersData['level_name']},可直接下载";
  2105. } else {
  2106. if (0 == $artData['no_vip_pay']) {
  2107. $buyVip = 1;
  2108. } else {
  2109. $where = [
  2110. 'order_status' => 1,
  2111. 'product_id' => intval($aid),
  2112. 'users_id' => $users_id
  2113. ];
  2114. $count = Db::name('download_order')->where($where)->count();
  2115. if (!empty($count)) {
  2116. $canDownload = 1;
  2117. $download_tips = '您已购买,可直接下载';
  2118. }
  2119. }
  2120. }
  2121. } else if (3 == $artData['restric_type']) { // 会员付费
  2122. if ($UsersData['level_value'] >= $artData['arc_level_value']) {
  2123. // 查询是否已购买
  2124. $where = [
  2125. 'order_status' => 1,
  2126. 'product_id' => intval($aid),
  2127. 'users_id' => $users_id
  2128. ];
  2129. $count = Db::name('download_order')->where($where)->count();
  2130. if (!empty($count)) {
  2131. $canDownload = 1;
  2132. $download_tips = '您已购买,可直接下载';
  2133. }
  2134. } else {
  2135. $buyVip = 1;
  2136. }
  2137. }
  2138. $result['canDownload'] = $canDownload;
  2139. $result['download_tips'] = $download_tips;
  2140. if (1 == $buyVip) {
  2141. $result['onclick'] = 'BuyVipClick();';
  2142. } else {
  2143. if (isMobile()) {
  2144. $result['onclick'] = 'ey_download_v866225(' . $aid . ');';//第一种跳转页面支付
  2145. } else {
  2146. $result['onclick'] = 'DownloadBuyNow1655866225(' . $aid . ');';//第二种弹框页支付
  2147. }
  2148. }
  2149. $this->success('success', null, $result);
  2150. }
  2151. public function get_user_download($aid = 0)
  2152. {
  2153. if (empty($aid)) {
  2154. $this->error('缺少文档id');
  2155. }
  2156. /*$artData = Db::name('archives')
  2157. ->where('aid', $aid)
  2158. ->find();
  2159. $artData['arc_level_value'] = 0;
  2160. if (0 < $artData['arc_level_id']) {
  2161. $artData['arc_level_value'] = Db::name('users_level')->where(['level_id' => $artData['arc_level_id']])->value('level_value');
  2162. }*/
  2163. //dump($artData);
  2164. $users_id = session('users_id');
  2165. if(empty($users_id)){
  2166. $this->error('请先登录!', '/?m=user&c=Users&a=login', []);
  2167. }
  2168. //已经登录,注册时已填写信息
  2169. $art = Db::name('archives')
  2170. ->where('aid', $aid)
  2171. ->find();
  2172. $artData = Db::name('zczygz_content')->where('aid', $aid)
  2173. ->find();
  2174. if(empty($artData) || empty($artData['down'])){
  2175. $this->error('文档不存在,请联系客服!', '', []);
  2176. }
  2177. //查询下载记录
  2178. // 当前时间减去10分钟
  2179. $time_10_minutes_ago = strtotime("-1 minutes");
  2180. // 格式化时间为Y-m-d H:i:s
  2181. $formatted_time = date("Y-m-d H:i:s", $time_10_minutes_ago);
  2182. $down_log = Db::name('users_down')
  2183. ->where('add_time','> time',$formatted_time)
  2184. ->where(['users_id'=>$users_id,'aid' => $aid])->count();
  2185. if(!empty($down_log) && $down_log >= 1){
  2186. $this->error('不允许频繁下载,点击下载后请等待一分钟再重试!', '', []);
  2187. }else{
  2188. $lc_time = date("Y-m-d 00:00:01", time());
  2189. //可以再限制 每天只能下载几次
  2190. $down_log = Db::name('users_down')
  2191. ->where('add_time','> time',$lc_time)
  2192. ->where(['users_id'=>$users_id,'aid' => $aid])->count();
  2193. if(!empty($down_log) && $down_log >= 10){
  2194. $this->error('同一文件今日最多下载10次!', '', []);
  2195. }
  2196. }
  2197. /*
  2198. * 执行下载记录 生成 每条记录有效时间 1小时
  2199. * 过后得重新 点击下载 生成新的下载链接
  2200. * 每天 同一文档 最多下载10次
  2201. * 每条下载记录 最多下载3次 就无效
  2202. */
  2203. // 启动事务
  2204. $run = 0;
  2205. Db::startTrans();
  2206. try{
  2207. $expire_time = strtotime("+60 minutes");
  2208. //记录下载数,二次下载也记录
  2209. $inser_log = [
  2210. 'users_id' => $users_id,
  2211. 'aid' => $aid,
  2212. 'channel' => 103,
  2213. 'typeid' => $art['typeid'],
  2214. 'title' => $art['title'],
  2215. 'add_time' => time(),
  2216. 'update_time' => time(),
  2217. 'expire_time' => $expire_time,
  2218. 'num' => 0
  2219. ];
  2220. $log_id = Db::name('users_down')->insertGetId($inser_log);
  2221. if((int)$log_id > 0){
  2222. //正常得到ID
  2223. }else{
  2224. $run = 1;
  2225. }
  2226. //下载数
  2227. $op = Db::name('archives')->where('aid', $aid)->setInc('downcount');
  2228. if((int)$op !== 1){
  2229. $run = 2;
  2230. }
  2231. if($run === 0){
  2232. $error_msg = '提交';
  2233. // 提交事务
  2234. Db::commit();
  2235. }else{
  2236. Db::rollback();
  2237. }
  2238. } catch (\Exception $e) {
  2239. $run = 3;
  2240. // 回滚事务
  2241. Db::rollback();
  2242. }
  2243. if($run > 0){
  2244. $this->error('事务执行异常!', '', ['event'=>$run,'log'=>$error_msg]);
  2245. }else{
  2246. //
  2247. $result = [
  2248. //'down' => $artData['down']
  2249. 'down' => 'https://www.zc10000.com/api/diyajax/downfile?id='.$log_id
  2250. ];
  2251. $this->success('下载请求成功', null, $result);
  2252. }
  2253. }
  2254. public function get_user_like($aid = 0){
  2255. if (empty($aid)) {
  2256. $this->error('缺少文档id');
  2257. }
  2258. $users_id = session('users_id');
  2259. if(empty($users_id)){
  2260. $this->error('请先登录!', '/?m=user&c=Users&a=login', []);
  2261. }
  2262. //已经登录,注册时已填写信息
  2263. $art = Db::name('archives')
  2264. ->where('aid', $aid)
  2265. ->find();
  2266. if(empty($art)){
  2267. $this->error('文档不存在,请联系客服!', '', []);
  2268. }
  2269. /* //查询下载记录
  2270. // 当前时间减去10分钟
  2271. $time_10_minutes_ago = strtotime("-5 seconds");
  2272. // 格式化时间为Y-m-d H:i:s
  2273. $formatted_time = date("Y-m-d H:i:s", $time_10_minutes_ago);
  2274. $down_log = Db::name('users_like')
  2275. ->where('update_time','> time',$formatted_time)
  2276. ->where(['users_id'=>$users_id,'aid' => $aid])->count();
  2277. if(!empty($down_log) && $down_log >= 1){
  2278. $this->error('不允许频繁点赞或取消,请等待5s后重试!', '', []);
  2279. }*/
  2280. // 启动事务
  2281. $run = 0;
  2282. Db::startTrans();
  2283. try{
  2284. //记录下载数,二次下载也记录
  2285. $row = Db::name('users_like')
  2286. ->where(['users_id'=>$users_id,'aid' => $aid])->find();
  2287. if(!empty($row)){
  2288. //更新
  2289. $inser_log = [
  2290. 'is_del' => (int)$row['is_del']===0?1:0,
  2291. 'update_time' => time(),
  2292. ];
  2293. $log_id = Db::name('users_like')
  2294. ->where(['users_id' => $users_id,'aid' => $aid])
  2295. ->update($inser_log);
  2296. if((int)$log_id !== 1){
  2297. $run = 1;
  2298. }
  2299. }else{
  2300. //新增
  2301. $inser_log = [
  2302. 'users_id' => $users_id,
  2303. 'aid' => $aid,
  2304. 'channel' => 103,
  2305. 'typeid' => $art['typeid'],
  2306. 'title' => $art['title'],
  2307. 'add_time' => time(),
  2308. 'update_time' => time(),
  2309. ];
  2310. $log_id = Db::name('users_like')->insert($inser_log);
  2311. if((int)$log_id !== 1){
  2312. $run = 1;
  2313. }
  2314. }
  2315. if((int)$row['is_del'] === 1 || empty($row)){
  2316. //点赞数
  2317. $op = Db::name('archives')->where('aid', $aid)->setInc('likecount');
  2318. if((int)$op !== 1){
  2319. $run = 2;
  2320. }
  2321. $msg = '点赞成功';
  2322. $type = 1;
  2323. $likecount = $art['likecount'] + 1;
  2324. }else{
  2325. //(取消点赞)
  2326. $msg = '取消成功';
  2327. $type = 0;
  2328. $likecount = $art['likecount'];
  2329. if((int)$art['likecount'] > 0){
  2330. $op = Db::name('archives')->where('aid', $aid)->setDec('likecount');
  2331. if((int)$op !== 1){
  2332. $run = 2;
  2333. }
  2334. $likecount = $art['likecount'] - 1;
  2335. }
  2336. }
  2337. if($run === 0){
  2338. $error_msg = '提交';
  2339. // 提交事务
  2340. Db::commit();
  2341. }else{
  2342. Db::rollback();
  2343. }
  2344. } catch (\Exception $e) {
  2345. $run = 3;
  2346. // 回滚事务
  2347. Db::rollback();
  2348. }
  2349. if($run > 0){
  2350. $this->error('事务执行异常!', '', ['event'=>$run,'log'=>$error_msg]);
  2351. }else{
  2352. //
  2353. $result = [
  2354. 'likecount' => $likecount,
  2355. 'log' => $down_log,
  2356. 'type' => $type
  2357. ];
  2358. $this->success($msg, null, $result);
  2359. }
  2360. }
  2361. public function get_user_collect($aid = 0){
  2362. if (empty($aid)) {
  2363. $this->error('缺少文档id');
  2364. }
  2365. $users_id = session('users_id');
  2366. if(empty($users_id)){
  2367. $this->error('请先登录!', '/?m=user&c=Users&a=login', []);
  2368. }
  2369. //已经登录,注册时已填写信息
  2370. $art = Db::name('archives')
  2371. ->where('aid', $aid)
  2372. ->find();
  2373. if(empty($art)){
  2374. $this->error('文档不存在,请联系客服!', '', []);
  2375. }
  2376. /* //查询下载记录
  2377. // 当前时间减去10分钟
  2378. $time_10_minutes_ago = strtotime("-5 seconds");
  2379. // 格式化时间为Y-m-d H:i:s
  2380. $formatted_time = date("Y-m-d H:i:s", $time_10_minutes_ago);
  2381. $down_log = Db::name('users_collection')
  2382. ->where('update_time','> time',$formatted_time)
  2383. ->where(['users_id'=>$users_id,'aid' => $aid])->count();
  2384. if(!empty($down_log) && $down_log >= 1){
  2385. $this->error('不允许频繁点赞或取消,请等待5s后重试!', '', []);
  2386. }*/
  2387. // 启动事务
  2388. $run = 0;
  2389. Db::startTrans();
  2390. try{
  2391. //记录下载数,二次下载也记录
  2392. $row = Db::name('users_collection')
  2393. ->where(['users_id'=>$users_id,'aid' => $aid])->find();
  2394. if(!empty($row)){
  2395. //更新
  2396. $inser_log = [
  2397. 'is_del' => (int)$row['is_del']===0?1:0,
  2398. 'update_time' => time(),
  2399. ];
  2400. $log_id = Db::name('users_collection')
  2401. ->where(['users_id' => $users_id,'aid' => $aid])
  2402. ->update($inser_log);
  2403. if((int)$log_id !== 1){
  2404. $run = 1;
  2405. }
  2406. }else{
  2407. //新增
  2408. $inser_log = [
  2409. 'users_id' => $users_id,
  2410. 'aid' => $aid,
  2411. 'channel' => 103,
  2412. 'typeid' => $art['typeid'],
  2413. 'title' => $art['title'],
  2414. 'add_time' => time(),
  2415. 'update_time' => time(),
  2416. ];
  2417. $log_id = Db::name('users_collection')->insert($inser_log);
  2418. if((int)$log_id !== 1){
  2419. $run = 1;
  2420. }
  2421. }
  2422. if((int)$row['is_del'] === 1 || empty($row)){
  2423. //点赞数
  2424. $op = Db::name('archives')->where('aid', $aid)->setInc('collection');
  2425. if((int)$op !== 1){
  2426. $run = 2;
  2427. }
  2428. $msg = '收藏成功';
  2429. $type = 1;
  2430. $likecount = $art['collection'] + 1;
  2431. }else{
  2432. //(取消点赞)
  2433. $msg = '取消成功';
  2434. $type = 0;
  2435. $likecount = $art['collection'];
  2436. if((int)$art['collection'] > 0){
  2437. $op = Db::name('archives')->where('aid', $aid)->setDec('collection');
  2438. if((int)$op !== 1){
  2439. $run = 2;
  2440. }
  2441. $likecount = $art['collection'] - 1;
  2442. }
  2443. }
  2444. if($run === 0){
  2445. $error_msg = '提交';
  2446. // 提交事务
  2447. Db::commit();
  2448. }else{
  2449. Db::rollback();
  2450. }
  2451. } catch (\Exception $e) {
  2452. $run = 3;
  2453. // 回滚事务
  2454. Db::rollback();
  2455. }
  2456. if($run > 0){
  2457. $this->error('事务执行异常!', '', ['event'=>$run,'log'=>$error_msg]);
  2458. }else{
  2459. //
  2460. $result = [
  2461. 'collection' => $likecount,
  2462. 'log' => $down_log,
  2463. 'type' => $type
  2464. ];
  2465. $this->success($msg, null, $result);
  2466. }
  2467. }
  2468. public function sendNotice()
  2469. {
  2470. $users_id = input('post.users_id/d');
  2471. $order_id = input('post.order_id/d');
  2472. $send_scene = input('post.send_scene/d');
  2473. if (7 == $send_scene) {
  2474. $params = [
  2475. 'users_id' => $users_id,
  2476. 'result_id' => $order_id,
  2477. ];
  2478. eyou_send_notice($send_scene, $params);
  2479. }
  2480. }
  2481. public function defaultAuthorize()
  2482. {
  2483. // 管理员ID
  2484. $admin_id = input('param.admin_id');
  2485. if (empty($admin_id)) $this->error('获取用户信息错误,请重新生成二维码并扫码!');
  2486. // 公众号配置
  2487. $conf_wechat = tpSetting("OpenMinicode.conf_wechat");
  2488. $conf_wechat = !empty($conf_wechat) ? json_decode($conf_wechat, true) : [];
  2489. // 回调链接
  2490. $url = urlencode(url('api/Ajax/defaultGetWechatUserinfo', ['admin_id' => $admin_id], true, true));
  2491. // 静默授权链接
  2492. $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";
  2493. // 重定向链接
  2494. $this->redirect($redirect);
  2495. }
  2496. public function defaultGetWechatUserinfo()
  2497. {
  2498. // 通过微信code获取用户access_token
  2499. $code = input('param.code/s', '');
  2500. $admin_id = input('param.admin_id/d', 0);
  2501. if (empty($code) || empty($admin_id)) $this->error('获取用户信息错误,请重新生成二维码并扫码!');
  2502. // 公众号配置
  2503. $conf_wechat = tpSetting("OpenMinicode.conf_wechat");
  2504. $conf_wechat = !empty($conf_wechat) ? json_decode($conf_wechat, true) : [];
  2505. // 获取微信用户信息
  2506. $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';
  2507. $result = json_decode(httpRequest($url), true);
  2508. if (empty($result) || (!empty($result['errcode']) && !empty($result['errmsg']))) $this->error('Code已过期,请重新生成二维码并扫码!');
  2509. // 获取成功则进行关联绑定
  2510. if (!empty($result['openid']) && !empty($admin_id)) {
  2511. $update = [
  2512. 'wechat_open_id' => $result['openid'],
  2513. 'update_time' => getTime(),
  2514. ];
  2515. Db::name('admin')->where('admin_id', $admin_id)->update($update);
  2516. }
  2517. // 查询用户是否关注了公众号
  2518. $tokenData = get_wechat_access_token();
  2519. if (!empty($tokenData)) {
  2520. $result['openid'] = Db::name('admin')->where('admin_id', $admin_id)->getField('wechat_open_id');
  2521. $userInfo = 'https://api.weixin.qq.com/cgi-bin/user/info?access_token=' . $tokenData['access_token'] . '&openid=' . $result['openid'] . '&lang=zh_CN';
  2522. $userInfo = json_decode(httpRequest($userInfo), true);
  2523. // 关注则执行关联关注
  2524. if (!empty($userInfo['subscribe']) && $userInfo['openid'] == $result['openid']) {
  2525. $update = [
  2526. 'wechat_followed' => 1,
  2527. 'update_time' => getTime(),
  2528. ];
  2529. Db::name('admin')->where('admin_id', $admin_id)->update($update);
  2530. // 显示成功信息
  2531. $this->redirect(url('api/Ajax/showSuccessInfo', ['info' => '您已关注过,绑定成功!'], true, true));
  2532. }
  2533. } else {
  2534. $this->error($tokenData['msg']);
  2535. }
  2536. // 用户尚未关注公众号,显示公众号二维码
  2537. $this->redirect(url('api/Ajax/showWechatQrCode', ['admin_id' => $admin_id], true, true));
  2538. }
  2539. public function showSuccessInfo()
  2540. {
  2541. $info = input('param.info/s', '');
  2542. echo '<div style="color: red; text-align: center; padding-top: 50%; font-size: 60px;">' . $info . '</div>';
  2543. exit;
  2544. }
  2545. public function showWechatQrCode()
  2546. {
  2547. $admin_id = input('param.admin_id/d', 0);
  2548. if (empty($admin_id)) $this->error('获取用户信息错误,请重新生成二维码并扫码!');
  2549. // 公众号配置
  2550. $conf_wechat = tpSetting("OpenMinicode.conf_wechat");
  2551. $conf_wechat = !empty($conf_wechat) ? json_decode($conf_wechat, true) : [];
  2552. // 生成图片名称及径路
  2553. $qrcodeName = 'wechat_' . md5($admin_id) . ".jpg";
  2554. $qrcodePath = UPLOAD_PATH . 'system/wechat_followed/' . $admin_id . '/';
  2555. $qrcodeUrl = $qrcodePath . $qrcodeName;
  2556. // 检测图片是否存在
  2557. if (file_exists($qrcodeUrl)) {
  2558. $showQrcode = request()->domain() . ROOT_DIR . '/' . $qrcodeUrl;
  2559. echo '<div style="color: red; text-align: center; padding-top: 25%;"> <img src=' . $showQrcode . ' style="width: 90%;"> <div style="font-size: 40px;"> 绑定成功,请长按二维码识别公众号并关注公众号 </div> </div>';
  2560. exit;
  2561. }
  2562. // 获取公众号永久二维码
  2563. if (!empty($conf_wechat['appid'])) {
  2564. $tokenData = get_wechat_access_token();
  2565. if (!empty($tokenData)) {
  2566. // 调用微信接口,返回生成二维码的ticket参数
  2567. $url = 'https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=' . $tokenData['access_token'];
  2568. // 永久二维码
  2569. $data = '{"action_name": "QR_LIMIT_STR_SCENE", "action_info": {"scene": {"scene_str": "' . $admin_id . '"}}}';
  2570. // 调用接口获取数据,解析返回的数据
  2571. $ticketData = json_decode(httpRequest($url, 'POST', $data), true);
  2572. if (empty($ticketData['ticket'])) $this->error('数据错误,请重新生成二维码并扫码!');
  2573. // 调用微信接口,返回已生成二维码图片资源
  2574. $ticket = urlencode($ticketData['ticket']);
  2575. // 调用接口获取图片资源
  2576. $url = 'https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=' . $ticket;
  2577. $result = httpRequest($url, 'GET');
  2578. // 创建指定文件夹
  2579. tp_mkdir($qrcodePath);
  2580. // 拼装完成图片路径
  2581. $qrcodeUrl = $qrcodePath . "/" . $qrcodeName;
  2582. // 将资源加载到图片并返回
  2583. if (@file_put_contents($qrcodeUrl, $result)) {
  2584. $showQrcode = request()->domain() . ROOT_DIR . '/' . $qrcodeUrl;
  2585. echo '<div style="color: red; text-align: center; padding-top: 25%;"> <img src=' . $showQrcode . ' style="width: 90%;"> <div style="font-size: 40px;"> 绑定成功,请长按二维码识别公众号并关注公众号 </div> </div>';
  2586. exit;
  2587. }
  2588. } else {
  2589. $this->error($tokenData['msg']);
  2590. }
  2591. }
  2592. }
  2593. }