人人商城

mc.mod.php 59KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961
  1. <?php
  2. /**
  3. * [WeEngine System] Copyright (c) 2014 WE7.CC
  4. * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
  5. */
  6. function mc_update($uid, $fields) {
  7. global $_W;
  8. if (empty($fields)) {
  9. return false;
  10. }
  11. if (is_string($uid)) {
  12. $openid = $uid;
  13. }
  14. $uid = mc_openid2uid($uid);
  15. $_W['weid'] && $fields['weid'] = $_W['weid'];
  16. $struct = array_keys(mc_fields());
  17. $struct[] = 'birthyear';
  18. $struct[] = 'birthmonth';
  19. $struct[] = 'birthday';
  20. $struct[] = 'resideprovince';
  21. $struct[] = 'residecity';
  22. $struct[] = 'residedist';
  23. $struct[] = 'groupid';
  24. $struct[] = 'salt';
  25. if (isset($fields['birth']) && !is_array($fields['birth'])) {
  26. $birth = explode('-', $fields['birth']);
  27. $fields['birth'] = array(
  28. 'year' => $birth[0],
  29. 'month' => $birth[1],
  30. 'day' => $birth[2],
  31. );
  32. }
  33. if (!empty($fields['birth'])) {
  34. $fields['birthyear'] = $fields['birth']['year'];
  35. $fields['birthmonth'] = $fields['birth']['month'];
  36. $fields['birthday'] = $fields['birth']['day'];
  37. }
  38. if (isset($fields['reside'])) {
  39. $fields['resideprovince'] = $fields['reside']['province'];
  40. $fields['residecity'] = $fields['reside']['city'];
  41. $fields['residedist'] = $fields['reside']['district'];
  42. }
  43. unset($fields['reside'], $fields['birth']);
  44. foreach ($fields as $field => $value) {
  45. if (!in_array($field, $struct) || is_array($value)) {
  46. unset($fields[$field]);
  47. }
  48. }
  49. if (!empty($fields['avatar'])) {
  50. if (strexists($fields['avatar'], 'attachment/images/global/avatars/avatar_')) {
  51. $fields['avatar'] = str_replace($_W['attachurl'], '', $fields['avatar']);
  52. }
  53. }
  54. $member_table = table('member');
  55. $result = $member_table->updateMember($uid, $fields);
  56. if (!empty($openid) && empty($uid)) {
  57. pdo_update('mc_mapping_fans', array('uid' => $result), array('uniacid' => mc_current_real_uniacid(), 'openid' => $openid));
  58. }
  59. cache_build_memberinfo($uid);
  60. return true;
  61. }
  62. function mc_fetch($uid, $fields = array()) {
  63. if (empty($uid)) {
  64. return array();
  65. }
  66. $struct = mc_fields();
  67. $struct = array_keys($struct);
  68. if (!empty($fields)) {
  69. foreach ($fields as $key => $field) {
  70. if (!in_array($field, $struct)) {
  71. unset($fields[$key]);
  72. }
  73. if ($field == 'birth') {
  74. $fields[] = 'birthyear';
  75. $fields[] = 'birthmonth';
  76. $fields[] = 'birthday';
  77. }
  78. if ($field == 'reside') {
  79. $fields[] = 'resideprovince';
  80. $fields[] = 'residecity';
  81. $fields[] = 'residedist';
  82. }
  83. }
  84. unset($fields['birth'], $fields['reside']);
  85. }
  86. $result = array();
  87. if (is_array($uid)) {
  88. foreach ($uid as $id) {
  89. $user_info = mc_fetch_one($id);
  90. if (!empty($user_info) && !empty($fields)) {
  91. foreach ($fields as $field) {
  92. $result[$id][$field] = $user_info[$field];
  93. }
  94. $result[$id]['uid'] = $id;
  95. } else {
  96. $result[$id] = $user_info;
  97. }
  98. }
  99. } else {
  100. $user_info = mc_fetch_one($uid);
  101. if (!empty($user_info) && !empty($fields)) {
  102. foreach ($fields as $field) {
  103. $result[$field] = $user_info[$field];
  104. }
  105. $result['uid'] = $uid;
  106. } else {
  107. $result = $user_info;
  108. }
  109. }
  110. return $result;
  111. }
  112. function mc_fetch_one($uid, $uniacid = 0) {
  113. $uid = mc_openid2uid($uid);
  114. if (empty($uid)) {
  115. return array();
  116. }
  117. $cachekey = cache_system_key('memberinfo', array('uid' => $uid));
  118. $cache = cache_load($cachekey);
  119. if (!empty($cache)) {
  120. return $cache;
  121. }
  122. $params = array('uid' => $uid);
  123. if (!empty($uniacid) && intval($uniacid) > 0) {
  124. $params['uniacid'] = intval($uniacid);
  125. }
  126. $result = pdo_get('mc_members', $params);
  127. if (!empty($result)) {
  128. $result['avatar'] = tomedia($result['avatar']);
  129. $result['credit1'] = floatval($result['credit1']);
  130. $result['credit2'] = floatval($result['credit2']);
  131. $result['credit3'] = floatval($result['credit3']);
  132. $result['credit4'] = floatval($result['credit4']);
  133. $result['credit5'] = floatval($result['credit5']);
  134. $result['credit6'] = floatval($result['credit6']);
  135. } else {
  136. $result = array();
  137. }
  138. cache_write($cachekey, $result);
  139. return $result;
  140. }
  141. function mc_fansinfo($openidOruid, $acid = 0, $uniacid = 0){
  142. global $_W;
  143. if (empty($openidOruid)) {
  144. return array();
  145. }
  146. if (is_numeric($openidOruid)) {
  147. $openid = mc_uid2openid($openidOruid);
  148. if (empty($openid)) {
  149. return array();
  150. }
  151. } else {
  152. $openid = $openidOruid;
  153. }
  154. $fans_table = table('fans');
  155. $fans_table->searchWithOpenid($openid);
  156. if (!empty($uniacid)) {
  157. $fans_table->searchWithUniacid($uniacid);
  158. }
  159. if (!empty($acid)) {
  160. $fans_table->searchWithAcid($acid);
  161. }
  162. $fan = $fans_table->fansInfo($openid);
  163. if (!empty($fan)) {
  164. if (!empty($fan['tag']) && is_string($fan['tag'])) {
  165. if (is_base64($fan['tag'])) {
  166. $fan['tag'] = @base64_decode($fan['tag']);
  167. }
  168. if (is_serialized($fan['tag'])) {
  169. $fan['tag'] = @iunserializer($fan['tag']);
  170. }
  171. if (is_array($fan['tag']) && !empty($fan['tag']['headimgurl'])) {
  172. $fan['tag']['avatar'] = tomedia($fan['tag']['headimgurl']);
  173. unset($fan['tag']['headimgurl']);
  174. if (empty($fan['nickname']) && !empty($fan['tag']['nickname'])) {
  175. $fan['nickname'] = strip_emoji($fan['tag']['nickname']);
  176. }
  177. $fan['gender'] = $fan['sex'] = $fan['tag']['sex'];
  178. $fan['avatar'] = $fan['headimgurl'] = $fan['tag']['avatar'];
  179. }
  180. } else {
  181. $fan['tag'] = array();
  182. }
  183. }
  184. if (empty($fan) && $openid == $_W['openid'] && !empty($_SESSION['userinfo'])) {
  185. $fan['tag'] = iunserializer(base64_decode($_SESSION['userinfo']));
  186. $fan['uid'] = 0;
  187. $fan['openid'] = $fan['tag']['openid'];
  188. $fan['follow'] = 0;
  189. if (empty($fan['nickname']) && !empty($fan['tag']['nickname'])) {
  190. $fan['nickname'] = strip_emoji($fan['tag']['nickname']);
  191. }
  192. $fan['gender'] = $fan['sex'] = $fan['tag']['sex'];
  193. $fan['avatar'] = $fan['headimgurl'] = $fan['tag']['headimgurl'];
  194. $mc_oauth_fan = mc_oauth_fans($fan['openid']);
  195. if (!empty($mc_oauth_fan)) {
  196. $fan['uid'] = $mc_oauth_fan['uid'];
  197. }
  198. }
  199. return $fan;
  200. }
  201. function mc_oauth_fans($openid, $acid = 0){
  202. $fans_table = table('fans');
  203. if (!empty($acid)) {
  204. $fans_table->searchWithAcid($acid);
  205. }
  206. $fan = $fans_table->oauthFans($openid);
  207. return $fan;
  208. }
  209. function mc_oauth_userinfo($acid = 0) {
  210. global $_W;
  211. if (isset($_SESSION['userinfo'])) {
  212. $userinfo = iunserializer(base64_decode($_SESSION['userinfo']));
  213. if (!empty($userinfo) || is_array($userinfo)) {
  214. return $userinfo;
  215. }
  216. }
  217. if ($_W['container'] != 'wechat') {
  218. return array();
  219. }
  220. $result = mc_oauth_account_userinfo();
  221. if (is_error($result)) {
  222. load()->func('tpl');
  223. include template('mc/iswxapp', TEMPLATE_INCLUDEPATH);
  224. exit;
  225. }
  226. return $result;
  227. }
  228. function mc_oauth_account_userinfo($url = '') {
  229. global $_W;
  230. if (!empty($_SESSION['openid']) && intval($_W['account']['level']) >= 3) {
  231. $oauth_account = WeAccount::createByUniacid();
  232. $userinfo = $oauth_account->fansQueryInfo($_SESSION['openid']);
  233. if (!is_error($userinfo) && !empty($userinfo) && is_array($userinfo) && !empty($userinfo['nickname'])) {
  234. $userinfo['nickname'] = stripcslashes($userinfo['nickname']);
  235. $userinfo['avatar'] = $userinfo['headimgurl'];
  236. $_SESSION['userinfo'] = base64_encode(iserializer($userinfo));
  237. $fan = mc_fansinfo($_SESSION['openid']);
  238. if (!empty($fan)) {
  239. $record = array(
  240. 'updatetime' => TIMESTAMP,
  241. 'nickname' => stripslashes($userinfo['nickname']),
  242. 'follow' => $userinfo['subscribe'],
  243. 'followtime' => $userinfo['subscribe_time'],
  244. 'tag' => base64_encode(iserializer($userinfo))
  245. );
  246. pdo_update('mc_mapping_fans', $record, array('openid' => $_SESSION['openid'], 'acid' => $_W['acid'], 'uniacid' => $_W['uniacid']));
  247. } else {
  248. $record = array();
  249. $record['updatetime'] = TIMESTAMP;
  250. $record['nickname'] = stripslashes($userinfo['nickname']);
  251. $record['tag'] = base64_encode(iserializer($userinfo));
  252. $record['openid'] = $_SESSION['openid'];
  253. $record['acid'] = $_W['acid'];
  254. $record['uniacid'] = $_W['uniacid'];
  255. $record['unionid'] = $userinfo['unionid'];
  256. pdo_insert('mc_mapping_fans', $record);
  257. }
  258. if (!empty($fan['uid']) || !empty($_SESSION['uid'])) {
  259. $uid = intval($fan['uid']);
  260. if (empty($uid)) {
  261. $uid = intval($_SESSION['uid']);
  262. }
  263. $member = mc_fetch($uid, array('nickname', 'gender', 'residecity', 'resideprovince', 'nationality', 'avatar'));
  264. $record = array();
  265. if (empty($member['nickname']) && !empty($userinfo['nickname'])) {
  266. $record['nickname'] = stripslashes($userinfo['nickname']);
  267. }
  268. if (empty($member['gender']) && !empty($userinfo['sex'])) {
  269. $record['gender'] = $userinfo['sex'];
  270. }
  271. if (empty($member['residecity']) && !empty($userinfo['city'])) {
  272. $record['residecity'] = $userinfo['city'] . '市';
  273. }
  274. if (empty($member['resideprovince']) && !empty($userinfo['province'])) {
  275. $record['resideprovince'] = $userinfo['province'] . '省';
  276. }
  277. if (empty($member['nationality']) && !empty($userinfo['country'])) {
  278. $record['nationality'] = $userinfo['country'];
  279. }
  280. if (empty($member['avatar']) && !empty($userinfo['headimgurl'])) {
  281. $record['avatar'] = $userinfo['headimgurl'];
  282. }
  283. if (!empty($record)) {
  284. pdo_update('mc_members', $record, array('uid' => $uid));
  285. cache_build_memberinfo($uid);
  286. }
  287. }
  288. return $userinfo;
  289. }
  290. }
  291. if (empty($_W['account']['oauth'])) {
  292. return error(-1, '未指定网页授权公众号, 无法获取用户信息.');
  293. }
  294. if (empty($_W['account']['oauth']['key'])) {
  295. return error(-2, '公众号未设置 appId 或 secret.');
  296. }
  297. if (intval($_W['account']['oauth']['level']) < 4 && !in_array($_W['account']['oauth']['level'], array(ACCOUNT_TYPE_APP_NORMAL, ACCOUNT_TYPE_APP_AUTH, ACCOUNT_TYPE_WXAPP_WORK))) {
  298. return error(-3, '公众号非认证服务号, 无法获取用户信息.');
  299. }
  300. $state = 'we7sid-' . $_W['session_id'];
  301. $_SESSION['dest_url'] = urlencode($_W['siteurl']);
  302. if (!empty($url)) {
  303. $_SESSION['dest_url'] = urlencode($url);
  304. }
  305. $str = '';
  306. if(uni_is_multi_acid()) {
  307. $str = "&j={$_W['acid']}";
  308. }
  309. $oauth_url = uni_account_oauth_host();
  310. $url = $oauth_url . "app/index.php?i={$_W['uniacid']}{$str}&c=auth&a=oauth&scope=userinfo";
  311. $callback = urlencode($url);
  312. $oauth_account = WeAccount::create($_W['account']['oauth']);
  313. $forward = $oauth_account->getOauthUserInfoUrl($callback, $state);
  314. header('Location: ' . $forward);
  315. exit;
  316. }
  317. function mc_require($uid, $fields, $pre = '') {
  318. global $_W, $_GPC;
  319. if (empty($fields) || !is_array($fields)) {
  320. return false;
  321. }
  322. $flipfields = array_flip($fields);
  323. if (in_array('birth', $fields) || in_array('birthyear', $fields) || in_array('birthmonth', $fields) || in_array('birthday', $fields)) {
  324. unset($flipfields['birthyear'], $flipfields['birthmonth'], $flipfields['birthday'], $flipfields['birth']);
  325. $flipfields['birthyear'] = 'birthyear';
  326. $flipfields['birthmonth'] = 'birthmonth';
  327. $flipfields['birthday'] = 'birthday';
  328. }
  329. if (in_array('reside', $fields) || in_array('resideprovince', $fields) || in_array('residecity', $fields) || in_array('residedist', $fields)) {
  330. unset($flipfields['residedist'], $flipfields['resideprovince'], $flipfields['residecity'], $flipfields['reside']);
  331. $flipfields['resideprovince'] = 'resideprovince';
  332. $flipfields['residecity'] = 'residecity';
  333. $flipfields['residedist'] = 'residedist';
  334. }
  335. $fields = array_keys($flipfields);
  336. if (!in_array('uniacid', $fields)) {
  337. $fields[] = 'uniacid';
  338. }
  339. if (!empty($pre)) {
  340. $pre .= '<br/>';
  341. }
  342. if (empty($uid)) {
  343. foreach ($fields as $field) {
  344. $profile[$field] = '';
  345. }
  346. $uniacid = $_W['uniacid'];
  347. } else {
  348. $profile = mc_fetch($uid, $fields);
  349. $uniacid = $profile['uniacid'];
  350. }
  351. $sql = 'SELECT `f`.`field`, `f`.`id` AS `fid`, `mf`.* FROM ' . tablename('profile_fields') . " AS `f` LEFT JOIN " .
  352. tablename('mc_member_fields') . " AS `mf` ON `f`.`id` = `mf`.`fieldid` WHERE `uniacid` = :uniacid ORDER BY
  353. `displayorder` DESC";
  354. $system_fields = pdo_fetchall($sql, array(':uniacid' => $_W['uniacid']), 'field');
  355. if (empty($system_fields)) {
  356. $system_fields = pdo_getall('profile_fields', array(), array('id', 'field', 'title'), '');
  357. }
  358. $titles = array();
  359. foreach ($system_fields as $field) {
  360. $titles[$field['field']] = $field['title'];
  361. }
  362. $message = '';
  363. $ks = array();
  364. foreach ($profile as $k => $v) {
  365. if (empty($v)) {
  366. $ks[] = $k;
  367. $message .= $system_fields[$k]['title'] . ', ';
  368. }
  369. }
  370. if (!empty($message)) {
  371. $title = '完善资料';
  372. if (checksubmit('submit')) {
  373. if (in_array('resideprovince', $fields)) {
  374. $_GPC['resideprovince'] = $_GPC['reside']['province'];
  375. $_GPC['residecity'] = $_GPC['reside']['city'];
  376. $_GPC['residedist'] = $_GPC['reside']['district'];
  377. }
  378. if (in_array('birthyear', $fields)) {
  379. $_GPC['birthyear'] = $_GPC['birth']['year'];
  380. $_GPC['birthmonth'] = $_GPC['birth']['month'];
  381. $_GPC['birthday'] = $_GPC['birth']['day'];
  382. }
  383. $record = array_elements($fields, $_GPC);
  384. if (isset($record['uniacid'])) {
  385. unset($record['uniacid']);
  386. }
  387. foreach ($record as $field => $value) {
  388. if ($field == 'gender') {
  389. continue;
  390. }
  391. if (empty($value)) {
  392. itoast('请填写完整所有资料.', referer(), 'error');
  393. }
  394. }
  395. if (empty($record['nickname']) && !empty($_W['fans']['nickname'])) {
  396. $record['nickname'] = $_W['fans']['nickname'];
  397. }
  398. if (empty($record['avatar']) && !empty($_W['fans']['tag']['avatar'])) {
  399. $record['avatar'] = $_W['fans']['tag']['avatar'];
  400. }
  401. $condition = " AND uid != {$uid} ";
  402. if (in_array('email', $fields)) {
  403. $emailexists = pdo_fetchcolumn("SELECT email FROM " . tablename('mc_members') . " WHERE uniacid = :uniacid AND email = :email " . $condition, array(':uniacid' => $_W['uniacid'], ':email' => trim($record['email'])));
  404. if (!empty($emailexists)) {
  405. itoast('抱歉,您填写的手机号已经被使用,请更新。', 'refresh', 'error');
  406. }
  407. }
  408. if (in_array('mobile', $fields)) {
  409. $mobilexists = pdo_fetchcolumn("SELECT mobile FROM " . tablename('mc_members') . " WHERE uniacid = :uniacid AND mobile = :mobile " . $condition, array(':uniacid' => $_W['uniacid'], ':mobile' => trim($record['mobile'])));
  410. if (!empty($mobilexists)) {
  411. itoast('抱歉,您填写的手机号已经被使用,请更新。', 'refresh', 'error');
  412. }
  413. }
  414. $insertuid = mc_update($uid, $record);
  415. if (empty($uid)) {
  416. pdo_update('mc_oauth_fans', array('uid' => $insertuid), array('oauth_openid' => $_W['openid']));
  417. pdo_update('mc_mapping_fans', array('uid' => $insertuid), array('openid' => $_W['openid']));
  418. }
  419. itoast('资料完善成功.', 'refresh', 'success');
  420. }
  421. load()->func('tpl');
  422. load()->model('activity');
  423. $filter = array();
  424. $filter['status'] = 1;
  425. $coupons = activity_coupon_owned($_W['member']['uid'], $filter);
  426. $tokens = activity_token_owned($_W['member']['uid'], $filter);
  427. $setting = uni_setting($_W['uniacid'], array('creditnames', 'creditbehaviors', 'uc'));
  428. $behavior = $setting['creditbehaviors'];
  429. $creditnames = $setting['creditnames'];
  430. $credits = mc_credit_fetch($_W['member']['uid'], '*');
  431. include template('mc/require', TEMPLATE_INCLUDEPATH);
  432. exit;
  433. }
  434. return $profile;
  435. }
  436. function mc_credit_update($uid, $credittype, $creditval = 0, $log = array()) {
  437. global $_W;
  438. $creditnames = uni_setting_load('creditnames');
  439. $creditnames = $creditnames['creditnames'];
  440. $credittype = trim($credittype);
  441. $credittypes = mc_credit_types();
  442. $clerk_types = array(
  443. '1' => '线上操作',
  444. '2' => '系统后台',
  445. '3' => '店员',
  446. );
  447. if (!in_array($credittype, $credittypes)) {
  448. return error('-1', "指定的用户积分类型 “{$credittype}”不存在.");
  449. }
  450. $creditval = floatval($creditval);
  451. if (empty($creditval)) {
  452. return true;
  453. }
  454. $value = pdo_getcolumn('mc_members', array('uid' => $uid), $credittype);
  455. if ($creditval > 0 || ($value + $creditval >= 0) || $credittype == 'credit6') {
  456. pdo_update('mc_members', array($credittype => $value + $creditval), array('uid' => $uid));
  457. cache_build_memberinfo($uid);
  458. } else {
  459. return error('-1', "积分类型为“{$credittype}”的积分不够,无法操作。");
  460. }
  461. if (empty($log) || !is_array($log)) {
  462. load()->func('logging');
  463. if (!empty($GLOBALS['site']) && $GLOBALS['site'] instanceof WeModuleSite) {
  464. $log = array(
  465. $uid,
  466. $GLOBALS['site']->module['title'] . '模块内消费' . logging_implode($_GET),
  467. $GLOBALS['site']->module['name'],
  468. 0,
  469. );
  470. } elseif (!empty($GLOBALS['_GPC']['m'])) {
  471. $modules = uni_modules();
  472. $log = array(
  473. $uid,
  474. $modules[$GLOBALS['_GPC']['m']]['title'] . '模块内消费' . logging_implode($_GET),
  475. $GLOBALS['_GPC']['m'],
  476. 0,
  477. );
  478. } else {
  479. $log = array($uid, '未记录', 0, 0);
  480. }
  481. }
  482. if ($credittype == 'credit1') {
  483. $credittype_name = $creditnames['credit1']['title'];
  484. } elseif ($credittype == 'credit2') {
  485. $credittype_name = '元';
  486. }
  487. if (empty($log[1])) {
  488. if ($creditval > 0) {
  489. $log[1] = $clerk_types[$log[5]] . ': 添加' . $creditval . $credittype_name;
  490. } else {
  491. $log[1] = $clerk_types[$log[5]] . ': 减少' . -$creditval . $credittype_name;
  492. }
  493. }
  494. $clerk_type = intval($log[5]) ? intval($log[5]) : 1;
  495. $data = array(
  496. 'uid' => $uid,
  497. 'credittype' => $credittype,
  498. 'uniacid' => $_W['uniacid'],
  499. 'num' => $creditval,
  500. 'createtime' => TIMESTAMP,
  501. 'operator' => intval($log[0]),
  502. 'module' => trim($log[2]),
  503. 'clerk_id' => intval($log[3]),
  504. 'store_id' => intval($log[4]),
  505. 'clerk_type' => $clerk_type,
  506. 'remark' => $log[1],
  507. 'real_uniacid' => mc_current_real_uniacid()
  508. );
  509. pdo_insert('mc_credits_record', $data);
  510. return true;
  511. }
  512. function mc_account_change_operator($clerk_type, $store_id, $clerk_id) {
  513. global $stores, $clerks, $_W;
  514. if(empty($stores) || empty($clerks)) {
  515. $clerks = pdo_getall('activity_clerks', array('uniacid' => $_W['uniacid']), array('id', 'name'), 'id');
  516. $stores = pdo_getall('activity_stores', array('uniacid' => $_W['uniacid']), array('id', 'business_name', 'branch_name'), 'id');
  517. }
  518. $data = array(
  519. 'clerk_cn' => '',
  520. 'store_cn' => '',
  521. );
  522. if($clerk_type == 1) {
  523. $data['clerk_cn'] = '系统';
  524. } elseif($clerk_type == 2) {
  525. $data['clerk_cn'] = pdo_getcolumn('users', array('uid' => $clerk_id), 'username');
  526. } elseif($clerk_type == 3) {
  527. if (empty($clerk_id)) {
  528. $data['clerk_cn'] = '本人操作';
  529. } else {
  530. $data['clerk_cn'] = $clerks[$clerk_id]['name'];
  531. }
  532. $data['store_cn'] = $stores[$store_id]['business_name'] . ' ' . $stores[$store_id]['branch_name'];
  533. }
  534. if (empty($data['store_cn'])) {
  535. $data['store_cn'] = '暂无门店信息';
  536. }
  537. if (empty($data['clerk_cn'])) {
  538. $data['clerk_cn'] = '暂无操作员信息';
  539. }
  540. return $data;
  541. }
  542. function mc_credit_fetch($uid, $types = array()) {
  543. if (empty($types) || $types == '*') {
  544. $select = array('credit1', 'credit2', 'credit3', 'credit4', 'credit5', 'credit6');
  545. } else {
  546. $struct = mc_credit_types();
  547. foreach ($types as $key => $type) {
  548. if (!in_array($type, $struct)) {
  549. unset($types[$key]);
  550. }
  551. }
  552. $select = $types;
  553. }
  554. return pdo_get('mc_members', array('uid' => $uid), $select);
  555. }
  556. function mc_credit_types(){
  557. static $struct = array('credit1','credit2','credit3','credit4','credit5','credit6');
  558. return $struct;
  559. }
  560. function mc_groups($uniacid = 0) {
  561. global $_W;
  562. $uniacid = intval($uniacid);
  563. if (empty($uniacid)) {
  564. $uniacid = $_W['uniacid'];
  565. }
  566. return pdo_getall('mc_groups', array('uniacid' => $uniacid), array(), 'groupid', 'credit');
  567. }
  568. function mc_fans_groups($force_update = false) {
  569. global $_W;
  570. $results = pdo_getcolumn('mc_fans_groups', array('uniacid' => $_W['uniacid'], 'acid' => $_W['acid']), 'groups');
  571. if(!empty($results) && !$force_update) {
  572. $results = iunserializer($results);
  573. return $results;
  574. }
  575. $account_api = WeAccount::createByUniacid();
  576. if (!$account_api->isTagSupported()) {
  577. return array();
  578. }
  579. $tags = $account_api->fansTagFetchAll();
  580. if (is_error($tags)) {
  581. itoast($tags['message'], '', 'error');
  582. }
  583. if (!empty($tags['tags'])) {
  584. $tags_tmp = array();
  585. foreach ($tags['tags'] as $da) {
  586. if ($da['id'] == 1) {
  587. continue;
  588. }
  589. $tags_tmp[$da['id']] = $da;
  590. }
  591. }
  592. if (empty($results)) {
  593. $data = array('acid' => $_W['acid'], 'uniacid' => $_W['uniacid'], 'groups' => iserializer($tags_tmp));
  594. pdo_insert('mc_fans_groups', $data);
  595. } else {
  596. $data = array('groups' => iserializer($tags_tmp));
  597. pdo_update('mc_fans_groups', $data, array('uniacid' => $_W['uniacid'], 'acid' => $_W['acid']));
  598. }
  599. return $tags_tmp;
  600. }
  601. function _mc_login($member) {
  602. global $_W;
  603. if (!empty($member) && !empty($member['uid'])) {
  604. $member = pdo_get('mc_members', array('uid' => $member['uid'], 'uniacid' => $_W['uniacid']), array('uid', 'realname', 'mobile', 'email', 'groupid', 'credit1', 'credit2', 'credit6'));
  605. if (!empty($member) && (!empty($member['mobile']) || !empty($member['email']))) {
  606. $_W['member'] = $member;
  607. $_W['member']['groupname'] = $_W['uniaccount']['groups'][$member['groupid']]['title'];
  608. $_SESSION['uid'] = $member['uid'];
  609. mc_group_update();
  610. if (empty($_W['openid'])) {
  611. $fan = mc_fansinfo($member['uid']);
  612. if (!empty($fan)) {
  613. $_SESSION['openid'] = $fan['openid'];
  614. $_W['openid'] = $fan['openid'];
  615. $_W['fans'] = $fan;
  616. $_W['fans']['from_user'] = $_W['openid'];
  617. } else {
  618. $_W['openid'] = $member['uid'];
  619. $_W['fans'] = array(
  620. 'from_user' => $member['uid'],
  621. 'follow' => 0
  622. );
  623. }
  624. }
  625. isetcookie('logout', '', -60000);
  626. return true;
  627. }
  628. }
  629. return false;
  630. }
  631. function mc_fields() {
  632. $fields = cache_load(cache_system_key('usersfields'));
  633. if (empty($fields)) {
  634. load()->model('cache');
  635. cache_build_users_struct();
  636. $fields = cache_load(cache_system_key('usersfields'));
  637. }
  638. return $fields;
  639. }
  640. function mc_acccount_fields($uniacid = 0, $is_available = true) {
  641. global $_W;
  642. if(!$uniacid) {
  643. $uniacid = $_W['uniacid'];
  644. }
  645. $member_table = table('member');
  646. $data = $member_table->accountMemberFields($uniacid, $is_available);
  647. $fields = array();
  648. foreach($data as $row) {
  649. $fields[$row['field']] = $row['title'];
  650. }
  651. return $fields;
  652. }
  653. function mc_init_uc() {
  654. global $_W;
  655. $setting = uni_setting($_W['uniacid'], array('uc'));
  656. if (is_array($setting['uc']) && $setting['uc']['status'] == '1') {
  657. $uc = $setting['uc'];
  658. define('UC_CONNECT', $uc['connect'] == 'mysql' ? 'mysql' : '');
  659. define('UC_DBHOST', $uc['dbhost']);
  660. define('UC_DBUSER', $uc['dbuser']);
  661. define('UC_DBPW', $uc['dbpw']);
  662. define('UC_DBNAME', $uc['dbname']);
  663. define('UC_DBCHARSET', $uc['dbcharset']);
  664. define('UC_DBTABLEPRE', $uc['dbtablepre']);
  665. define('UC_DBCONNECT', $uc['dbconnect']);
  666. define('UC_CHARSET', $uc['charset']);
  667. define('UC_KEY', $uc['key']);
  668. define('UC_API', $uc['api']);
  669. define('UC_APPID', $uc['appid']);
  670. define('UC_IP', $uc['ip']);
  671. require IA_ROOT . '/framework/library/uc/client.php';
  672. return true;
  673. }
  674. return false;
  675. }
  676. function mc_handsel($touid, $fromuid, $handsel, $uniacid = '') {
  677. global $_W;
  678. $touid = intval($touid);
  679. $fromuid = intval($fromuid);
  680. if (empty($uniacid)) {
  681. $uniacid = $_W['uniacid'];
  682. }
  683. $touid_exist = mc_fetch($touid, array('uniacid'));
  684. if (empty($touid_exist)) {
  685. return error(-1, '赠送积分用户不存在');
  686. }
  687. if (empty($handsel['module'])) {
  688. return error(-1, '没有填写模块名称');
  689. }
  690. if (empty($handsel['sign'])) {
  691. return error(-1, '没有填写赠送积分对象信息');
  692. }
  693. if (empty($handsel['action'])) {
  694. return error(-1, '没有填写赠送积分动作');
  695. }
  696. $credit_value = intval($handsel['credit_value']);
  697. $params = array('uniacid' => $uniacid, 'touid' => $touid, 'fromuid' => $fromuid, 'module' => $handsel['module'], 'sign' => $handsel['sign'], 'action' => $handsel['action']);
  698. $handsel_exists = pdo_get('mc_handsel', $params);
  699. if (!empty($handsel_exists)) {
  700. return error(-1, '已经赠送过积分,每个用户只能赠送一次');
  701. }
  702. $creditbehaviors = pdo_fetchcolumn('SELECT creditbehaviors FROM ' . tablename('uni_settings') . ' WHERE uniacid = :uniacid', array(':uniacid' => $uniacid));
  703. $creditbehaviors = iunserializer($creditbehaviors) ? iunserializer($creditbehaviors) : array();
  704. if (empty($creditbehaviors['activity'])) {
  705. return error(-1, '公众号没有配置积分行为参数');
  706. } else {
  707. $credittype = $creditbehaviors['activity'];
  708. }
  709. $data = array(
  710. 'uniacid' => $uniacid,
  711. 'touid' => $touid,
  712. 'fromuid' => $fromuid,
  713. 'module' => $handsel['module'],
  714. 'sign' => $handsel['sign'],
  715. 'action' => $handsel['action'],
  716. 'credit_value' => $credit_value,
  717. 'createtime' => TIMESTAMP
  718. );
  719. pdo_insert('mc_handsel', $data);
  720. $log = array($fromuid, $handsel['credit_log']);
  721. mc_credit_update($touid, $credittype, $credit_value, $log);
  722. return true;
  723. }
  724. function mc_openid2uid($openid) {
  725. global $_W;
  726. if (is_numeric($openid)) {
  727. return $openid;
  728. }
  729. if (is_string($openid)) {
  730. $fans_info = pdo_get('mc_mapping_fans', array('uniacid' => mc_current_real_uniacid(), 'openid' => $openid), array('uid'));
  731. return !empty($fans_info) ? $fans_info['uid'] : false;
  732. }
  733. if (is_array($openid)) {
  734. $uids = array();
  735. foreach ($openid as $k => $v) {
  736. if (is_numeric($v)) {
  737. $uids[] = intval($v);
  738. } elseif (is_string($v)) {
  739. $fans[] = istripslashes(str_replace(' ', '', $v));
  740. }
  741. }
  742. if (!empty($fans)) {
  743. $fans = pdo_getall('mc_mapping_fans', array('uniacid' => mc_current_real_uniacid(), 'openid' => $fans), array('uid', 'openid'), 'uid');
  744. $fans = array_keys($fans);
  745. $uids = array_merge((array)$uids, $fans);
  746. }
  747. return $uids;
  748. }
  749. return false;
  750. }
  751. function mc_uid2openid($uid) {
  752. global $_W;
  753. if (is_numeric($uid)) {
  754. $fans_info = pdo_get('mc_mapping_fans', array('uniacid' => mc_current_real_uniacid(), 'uid' => $uid), 'openid');
  755. return !empty($fans_info['openid']) ? $fans_info['openid'] : false;
  756. }
  757. if (is_string($uid)) {
  758. $openid = trim($uid);
  759. $openid_exist = pdo_get('mc_mapping_fans', array('openid' => $openid));
  760. if (!empty($openid_exist)) {
  761. return $openid;
  762. } else {
  763. return false;
  764. }
  765. }
  766. if (is_array($uid)) {
  767. $openids = array();
  768. foreach ($uid as $key => $value) {
  769. if (is_string($value)) {
  770. $openids[] = $value;
  771. } elseif (is_numeric($value)) {
  772. $uids[] = $value;
  773. }
  774. }
  775. if (!empty($uids)) {
  776. $fans_info = pdo_getall('mc_mapping_fans', array('uniacid' => mc_current_real_uniacid(), 'uid' => $uids), array('uid', 'openid'), 'openid');
  777. $fans_info = array_keys($fans_info);
  778. $openids = array_merge($openids, $fans_info);
  779. }
  780. return $openids;
  781. }
  782. return false;
  783. }
  784. function mc_group_update($uid = 0) {
  785. global $_W;
  786. if(!$_W['uniaccount']['grouplevel']) {
  787. $_W['uniaccount']['grouplevel'] = pdo_getcolumn('uni_settings', array('uniacid' => $_W['uniacid']), 'grouplevel');
  788. if (empty($_W['uniaccount']['grouplevel'])) {
  789. return true;
  790. }
  791. }
  792. $uid = intval($uid);
  793. if($uid <= 0) {
  794. $uid = $_W['member']['uid'];
  795. $user = $_W['member'];
  796. $user['openid'] = $_W['openid'];
  797. } else {
  798. $user = pdo_get('mc_members', array('uniacid' => $_W['uniacid'], 'uid' => $uid), array('uid', 'realname', 'credit1', 'credit6', 'groupid'));
  799. $user['openid'] = pdo_getcolumn('mc_mapping_fans', array('acid' => $_W['acid'], 'uid' => $uid), 'openid');
  800. }
  801. if(empty($user)) {
  802. return false;
  803. }
  804. $groupid = $user['groupid'];
  805. $credit = $user['credit1'] + $user['credit6'];
  806. $groups = mc_groups();
  807. if(empty($groups)) {
  808. return false;
  809. }
  810. $data = array();
  811. foreach($groups as $group) {
  812. $data[$group['groupid']] = $group['credit'];
  813. }
  814. asort($data);
  815. if($_W['uniaccount']['grouplevel'] == 1) {
  816. foreach($data as $k => $da) {
  817. if($credit >= $da) {
  818. $groupid = $k;
  819. }
  820. }
  821. } else {
  822. $now_group_credit = $data[$user['groupid']];
  823. if($now_group_credit < $credit) {
  824. foreach($data as $k => $da) {
  825. if($credit >= $da) {
  826. $groupid = $k;
  827. }
  828. }
  829. }
  830. }
  831. if($groupid > 0 && $groupid != $user['groupid']) {
  832. pdo_update('mc_members', array('groupid' => $groupid), array('uniacid' => $_W['uniacid'], 'uid' => $uid));
  833. cache_build_memberinfo($uid);
  834. mc_notice_group($user['openid'], $_W['uniaccount']['groups'][$user['groupid']]['title'], $_W['uniaccount']['groups'][$groupid]['title']);
  835. }
  836. $user['groupid'] = $groupid;
  837. $_W['member']['groupid'] = $groupid;
  838. $_W['member']['groupname'] = $_W['uniaccount']['groups'][$groupid]['title'];
  839. return $user['groupid'];
  840. }
  841. function mc_notice_init() {
  842. global $_W;
  843. if(empty($_W['account'])) {
  844. $_W['account'] = uni_fetch($_W['uniacid']);
  845. }
  846. if(empty($_W['account'])) {
  847. return error(1, '创建公众号操作类失败');
  848. }
  849. if($_W['account']['level'] < 3) {
  850. return error(1, '公众号没有经过认证,不能使用模板消息和客服消息');
  851. }
  852. $account = WeAccount::createByUniacid($_W['uniacid']);
  853. if(is_null($account)) {
  854. return error(1, '创建公众号操作对象失败');
  855. }
  856. $setting = uni_setting();
  857. $noticetpl = $setting['tplnotice'];
  858. $account->noticetpl = $noticetpl;
  859. return $account;
  860. }
  861. function mc_notice_public($openid, $title, $sender, $content, $url = '', $remark = '') {
  862. $account = mc_notice_init();
  863. if(is_error($account)) {
  864. return error(-1, $account['message']);
  865. }
  866. $data = array(
  867. 'first' => array(
  868. 'value' => $title,
  869. 'color' => '#ff510'
  870. ),
  871. 'keyword1' => array(
  872. 'value' => $sender,
  873. 'color' => '#ff510'
  874. ),
  875. 'keyword2' => array(
  876. 'value' => $content,
  877. 'color' => '#ff510'
  878. ),
  879. 'remark' => array(
  880. 'value' => $remark,
  881. 'color' => '#ff510'
  882. ),
  883. );
  884. $status = $account->sendTplNotice($openid, $account->noticetpl['public'], $data, $url);
  885. return $status;
  886. }
  887. function mc_notice_recharge($openid, $uid = 0, $num = 0, $url = '', $remark = '') {
  888. global $_W;
  889. if(!$uid) {
  890. $uid = $_W['member']['uid'];
  891. }
  892. if(!$uid || !$num || empty($openid)) {
  893. return error(-1, '参数错误');
  894. }
  895. $account = mc_notice_init();
  896. if(is_error($account)) {
  897. return error(-1, $account['message']);
  898. }
  899. $credit = mc_credit_fetch($uid);
  900. $time = date('Y-m-d H:i');
  901. if(empty($url)) {
  902. $url = murl('mc/bond/credits', array('credittype' => 'credit2', 'type' => 'record', 'period' => '1'), true, true);
  903. }
  904. if($_W['account']['level'] == ACCOUNT_SERVICE_VERIFY && !empty($account->noticetpl['recharge']['tpl'])) {
  905. $data = array(
  906. 'first' => array(
  907. 'value' => "您好,您在{$time}进行会员余额充值,充值金额{$num}元,充值后余额为{$credit['credit2']}元",
  908. 'color' => '#ff510'
  909. ),
  910. 'accountType' => array(
  911. 'value' => '会员UID',
  912. 'color' => '#ff510'
  913. ),
  914. 'account' => array(
  915. 'value' => $uid,
  916. 'color' => '#ff510'
  917. ),
  918. 'amount' => array(
  919. 'value' => $num . '元',
  920. 'color' => '#ff510'
  921. ),
  922. 'result' => array(
  923. 'value' => '充值成功',
  924. 'color' => '#ff510'
  925. ),
  926. 'remark' => array(
  927. 'value' => "{$remark}" ,
  928. 'color' => '#ff510'
  929. ),
  930. );
  931. $status = $account->sendTplNotice($openid, $account->noticetpl['recharge']['tpl'], $data, $url);
  932. }
  933. if($_W['account']['level'] == ACCOUNT_SUBSCRIPTION_VERIFY || is_error($status) || empty($account->noticetpl['recharge']['tpl'])) {
  934. $info = "【{$_W['account']['name']}】充值通知\n";
  935. $info .= "您在{$time}进行会员余额充值,充值金额【{$num}】元,充值后余额【{$credit['credit2']}】元。\n";
  936. $info .= !empty($remark) ? "备注:{$remark}\n\n" : '';
  937. $custom = array(
  938. 'msgtype' => 'text',
  939. 'text' => array('content' => urlencode($info)),
  940. 'touser' => $openid,
  941. );
  942. $status = $account->sendCustomNotice($custom);
  943. }
  944. return $status;
  945. }
  946. function mc_notice_credit2($openid, $uid, $credit2_num, $credit1_num = 0, $store = '线下消费', $url = '', $remark = '谢谢惠顾,点击查看详情') {
  947. global $_W;
  948. if(!$uid) {
  949. $uid = $_W['member']['uid'];
  950. }
  951. if(!$uid || !$credit2_num || empty($openid)) {
  952. return error(-1, '参数错误');
  953. }
  954. $account = mc_notice_init();
  955. if(is_error($account)) {
  956. return error(-1, $account['message']);
  957. }
  958. $credit = mc_credit_fetch($uid);
  959. $time = date('Y-m-d H:i');
  960. if(empty($url)) {
  961. $url = murl('mc/bond/credits', array('credittype' => 'credit2', 'type' => 'record', 'period' => '1'), true, true);
  962. }
  963. if($_W['account']['level'] == ACCOUNT_SERVICE_VERIFY && !empty($account->noticetpl['credit2']['tpl'])) {
  964. $data = array(
  965. 'first' => array(
  966. 'value' => "您好,您在{$time}有余额消费",
  967. 'color' => '#ff510'
  968. ),
  969. 'keyword1' => array(
  970. 'value' => abs($credit2_num) . '元',
  971. 'color' => '#ff510'
  972. ),
  973. 'keyword2' => array(
  974. 'value' => floatval($credit1_num) . '积分',
  975. 'color' => '#ff510'
  976. ),
  977. 'keyword3' => array(
  978. 'value' => trim($store),
  979. 'color' => '#ff510'
  980. ),
  981. 'keyword4' => array(
  982. 'value' => $credit['credit2'] . '元',
  983. 'color' => '#ff510'
  984. ),
  985. 'keyword5' => array(
  986. 'value' => $credit['credit1'] . '积分',
  987. 'color' => '#ff510'
  988. ),
  989. 'remark' => array(
  990. 'value' => "{$remark}" ,
  991. 'color' => '#ff510'
  992. ),
  993. );
  994. $status = $account->sendTplNotice($openid, $account->noticetpl['credit2']['tpl'], $data, $url);
  995. }
  996. if($_W['account']['level'] == ACCOUNT_SUBSCRIPTION_VERIFY || is_error($status) || empty($account->noticetpl['credit2']['tpl'])) {
  997. $info = "【{$_W['account']['name']}】消费通知\n";
  998. $info .= "您在{$time}进行会员余额消费,消费金额【{$credit2_num}】元,获得积分【{$credit1_num}】,消费后余额【{$credit['credit2']}】元,消费后积分【{$credit['credit1']}】。\n";
  999. $info .= !empty($remark) ? "备注:{$remark}\n\n" : '';
  1000. $custom = array(
  1001. 'msgtype' => 'text',
  1002. 'text' => array('content' => urlencode($info)),
  1003. 'touser' => $openid,
  1004. );
  1005. $status = $account->sendCustomNotice($custom);
  1006. }
  1007. return $status;
  1008. }
  1009. function mc_notice_credit1($openid, $uid, $credit1_num, $tip, $url = '', $remark = '谢谢惠顾,点击查看详情') {
  1010. global $_W;
  1011. if(!$uid) {
  1012. $uid = $_W['member']['uid'];
  1013. }
  1014. if(!$uid || !$credit1_num || empty($tip)) {
  1015. return error(-1, '参数错误');
  1016. }
  1017. $account = mc_notice_init();
  1018. if(is_error($account)) {
  1019. return error(-1, $account['message']);
  1020. }
  1021. $credit = mc_credit_fetch($uid);
  1022. $time = date('Y-m-d H:i');
  1023. if(empty($url)) {
  1024. $url = murl('mc/bond/credits', array('credittype' => 'credit1', 'type' => 'record', 'period' => '1'), true, true);
  1025. }
  1026. $credit1_num = floatval($credit1_num);
  1027. $type = '消费';
  1028. if($credit1_num > 0) {
  1029. $type = '到账';
  1030. }
  1031. $username = $_W['member']['realname'];
  1032. if(empty($username)) {
  1033. $username = $_W['member']['nickname'];
  1034. }
  1035. if(empty($username)) {
  1036. $username = $uid;
  1037. }
  1038. if($_W['account']['level'] == ACCOUNT_SERVICE_VERIFY && !empty($account->noticetpl['credit1']['tpl'])) {
  1039. $data = array(
  1040. 'first' => array(
  1041. 'value' => "您好,您在{$time}有积分变更",
  1042. 'color' => '#ff510'
  1043. ),
  1044. 'account' => array(
  1045. 'value' => $username,
  1046. 'color' => '#ff510'
  1047. ),
  1048. 'time' => array(
  1049. 'value' => $time,
  1050. 'color' => '#ff510'
  1051. ),
  1052. 'type' => array(
  1053. 'value' => $tip,
  1054. 'color' => '#ff510'
  1055. ),
  1056. 'creditChange' => array(
  1057. 'value' => $type,
  1058. 'color' => '#ff510'
  1059. ),
  1060. 'number' => array(
  1061. 'value' => abs($credit1_num) . '积分',
  1062. 'color' => '#ff510'
  1063. ),
  1064. 'creditName' => array(
  1065. 'value' => '账户积分',
  1066. 'color' => '#ff510'
  1067. ),
  1068. 'amount' => array(
  1069. 'value' => abs($credit['credit1']) . '积分',
  1070. 'color' => '#ff510'
  1071. ),
  1072. 'remark' => array(
  1073. 'value' => "{$remark}" ,
  1074. 'color' => '#ff510'
  1075. ),
  1076. );
  1077. $status = $account->sendTplNotice($openid, $account->noticetpl['credit1']['tpl'], $data, $url);
  1078. }
  1079. if($_W['account']['level'] == ACCOUNT_SUBSCRIPTION_VERIFY || empty($account->noticetpl['credit1']['tpl']) || is_error($status)) {
  1080. $info = "【{$_W['account']['name']}】积分变更通知\n";
  1081. $info .= "您在{$time}有积分{$type},{$type}积分【{$credit1_num}】,变更原因:【{$tip}】,消费后账户积分余额【{$credit['credit1']}】。\n";
  1082. $info .= !empty($remark) ? "备注:{$remark}\n\n" : '';
  1083. $custom = array(
  1084. 'msgtype' => 'text',
  1085. 'text' => array('content' => urlencode($info)),
  1086. 'touser' => $openid,
  1087. );
  1088. $status = $account->sendCustomNotice($custom);
  1089. }
  1090. return $status;
  1091. }
  1092. function mc_notice_group($openid, $old_group, $now_group, $url = '', $remark = '点击查看详情') {
  1093. global $_W;
  1094. $account = mc_notice_init();
  1095. if(is_error($account)) {
  1096. return error(-1, $account['message']);
  1097. }
  1098. $time = date('Y-m-d H:i');
  1099. if(empty($url)) {
  1100. $url = murl('mc/home', array(), true, true);
  1101. }
  1102. if($_W['account']['level'] == ACCOUNT_SERVICE_VERIFY && !empty($account->noticetpl['group']['tpl'])) {
  1103. $data = array(
  1104. 'first' => array(
  1105. 'value' => "您好,您的会员组变更为{$now_group}",
  1106. 'color' => '#ff510'
  1107. ),
  1108. 'grade1' => array(
  1109. 'value' => $old_group,
  1110. 'color' => '#ff510'
  1111. ),
  1112. 'grade2' => array(
  1113. 'value' => $now_group,
  1114. 'color' => '#ff510'
  1115. ),
  1116. 'time' => array(
  1117. 'value' => $time,
  1118. 'color' => '#ff510'
  1119. ),
  1120. 'remark' => array(
  1121. 'value' => "{$remark}",
  1122. 'color' => '#ff510'
  1123. ),
  1124. );
  1125. $status = $account->sendTplNotice($openid, $account->noticetpl['group']['tpl'], $data, $url);
  1126. }
  1127. if($_W['account']['level'] == ACCOUNT_SUBSCRIPTION_VERIFY || is_error($status) || empty($account->noticetpl['group']['tpl'])) {
  1128. $info = "【{$_W['account']['name']}】会员组变更通知\n";
  1129. $info .= "您的会员等级在{$time}由{$old_group}变更为{$now_group}。\n";
  1130. $info .= !empty($remark) ? "备注:{$remark}\n\n" : '';
  1131. $custom = array(
  1132. 'msgtype' => 'text',
  1133. 'text' => array('content' => urlencode($info)),
  1134. 'touser' => $openid,
  1135. );
  1136. $status = $account->sendCustomNotice($custom);
  1137. }
  1138. return $status;
  1139. }
  1140. function mc_notice_nums_plus($openid, $type, $num, $total_num, $remark = '感谢您的支持,祝您生活愉快!') {
  1141. global $_W;
  1142. if(empty($num) || empty($total_num) || empty($type)) {
  1143. return error(-1, '参数错误');
  1144. }
  1145. $account = mc_notice_init();
  1146. if(is_error($account)) {
  1147. return error(-1, $account['message']);
  1148. }
  1149. $time = date('Y-m-d H:i');
  1150. if($_W['account']['level'] == ACCOUNT_SERVICE_VERIFY && !empty($account->noticetpl['nums_plus']['tpl'])) {
  1151. $data = array(
  1152. 'first' => array(
  1153. 'value' => "您好,您的{$type}已充次成功",
  1154. 'color' => '#ff510'
  1155. ),
  1156. 'keyword1' => array(
  1157. 'value' => $time,
  1158. 'color' => '#ff510'
  1159. ),
  1160. 'keyword2' => array(
  1161. 'value' => $num . '次',
  1162. 'color' => '#ff510'
  1163. ),
  1164. 'keyword3' => array(
  1165. 'value' => $total_num . '次',
  1166. 'color' => '#ff510'
  1167. ),
  1168. 'keyword4' => array(
  1169. 'value' => '用完为止',
  1170. 'color' => '#ff510'
  1171. ),
  1172. 'remark' => array(
  1173. 'value' => "{$remark}" ,
  1174. 'color' => '#ff510'
  1175. ),
  1176. );
  1177. $status = $account->sendTplNotice($openid, $account->noticetpl['nums_plus']['tpl'], $data);
  1178. }
  1179. if($_W['account']['level'] == ACCOUNT_SUBSCRIPTION_VERIFY || is_error($status) || empty($account->noticetpl['nums_plus']['tpl'])) {
  1180. $info = "【{$_W['account']['name']}】-【{$type}】充值通知\n";
  1181. $info .= "您的{$type}已充值成功,本次充次【{$num}】次,总剩余【{$total_num}】次。\n";
  1182. $info .= !empty($remark) ? "备注:{$remark}\n\n" : '';
  1183. $custom = array(
  1184. 'msgtype' => 'text',
  1185. 'text' => array('content' => urlencode($info)),
  1186. 'touser' => $openid,
  1187. );
  1188. $status = $account->sendCustomNotice($custom);
  1189. }
  1190. return $status;
  1191. }
  1192. function mc_notice_nums_times($openid, $card_id, $type, $num, $remark = '感谢您对本店的支持,欢迎下次再来!') {
  1193. global $_W;
  1194. if(empty($num) || empty($type) || empty($card_id)) {
  1195. return error(-1, '参数错误');
  1196. }
  1197. $account = mc_notice_init();
  1198. if(is_error($account)) {
  1199. return error(-1, $account['message']);
  1200. }
  1201. $time = date('Y-m-d H:i');
  1202. if($_W['account']['level'] == ACCOUNT_SERVICE_VERIFY && !empty($account->noticetpl['nums_times']['tpl'])) {
  1203. $data = array(
  1204. 'first' => array(
  1205. 'value' => "您好,您的{$type}已成功使用了【1】次。",
  1206. 'color' => '#ff510'
  1207. ),
  1208. 'keyword1' => array(
  1209. 'value' => $card_id,
  1210. 'color' => '#ff510'
  1211. ),
  1212. 'keyword2' => array(
  1213. 'value' => $time,
  1214. 'color' => '#ff510'
  1215. ),
  1216. 'keyword3' => array(
  1217. 'value' => $num . '次',
  1218. 'color' => '#ff510'
  1219. ),
  1220. 'keyword4' => array(
  1221. 'value' => '用完为止',
  1222. 'color' => '#ff510'
  1223. ),
  1224. 'remark' => array(
  1225. 'value' => "{$remark}" ,
  1226. 'color' => '#ff510'
  1227. ),
  1228. );
  1229. $status = $account->sendTplNotice($openid, $account->noticetpl['nums_times']['tpl'], $data);
  1230. }
  1231. if($_W['account']['level'] == ACCOUNT_SUBSCRIPTION_VERIFY || is_error($status) || empty($account->noticetpl['nums_times']['tpl'])) {
  1232. $info = "【{$_W['account']['name']}】-【{$type}】消费通知\n";
  1233. $info .= "您的{$type}已成功使用了一次,总剩余【{$num}】次,消费时间【{$time}】。\n";
  1234. $info .= !empty($remark) ? "备注:{$remark}\n\n" : '';
  1235. $custom = array(
  1236. 'msgtype' => 'text',
  1237. 'text' => array('content' => urlencode($info)),
  1238. 'touser' => $openid,
  1239. );
  1240. $status = $account->sendCustomNotice($custom);
  1241. }
  1242. return $status;
  1243. }
  1244. function mc_notice_times_plus($openid, $card_id, $type, $fee, $days, $endtime = '', $remark = '感谢您对本店的支持,欢迎下次再来!') {
  1245. global $_W;
  1246. $account = mc_notice_init();
  1247. if(is_error($account)) {
  1248. return error(-1, $account['message']);
  1249. }
  1250. if($_W['account']['level'] == ACCOUNT_SERVICE_VERIFY && empty($account->noticetpl['times_plus']['tpl'])) {
  1251. $data = array(
  1252. 'first' => array(
  1253. 'value' => "您好,您的{$type}已续费成功。",
  1254. 'color' => '#ff510'
  1255. ),
  1256. 'keynote1' => array(
  1257. 'value' => $type,
  1258. 'color' => '#ff510'
  1259. ),
  1260. 'keynote2' => array(
  1261. 'value' => $card_id,
  1262. 'color' => '#ff510'
  1263. ),
  1264. 'keynote3' => array(
  1265. 'value' => $fee . '元',
  1266. 'color' => '#ff510'
  1267. ),
  1268. 'keynote4' => array(
  1269. 'value' => $days . '天',
  1270. 'color' => '#ff510'
  1271. ),
  1272. 'keynote5' => array(
  1273. 'value' => $endtime,
  1274. 'color' => '#ff510'
  1275. ),
  1276. 'remark' => array(
  1277. 'value' => "{$remark}" ,
  1278. 'color' => '#ff510'
  1279. ),
  1280. );
  1281. $status = $account->sendTplNotice($openid, $account->noticetpl['times_plus']['tpl'], $data);
  1282. }
  1283. if($_W['account']['level'] == ACCOUNT_SUBSCRIPTION_VERIFY || is_error($status) || empty($account->noticetpl['times_plus']['tpl'])) {
  1284. $info = "【{$_W['account']['name']}】-【{$type}】续费通知\n";
  1285. $info .= "您的{$type}已成功续费,续费时长【{$days}】天,续费金额【{$fee}】元,有效期至【{$endtime}】。\n";
  1286. $info .= !empty($remark) ? "备注:{$remark}\n\n" : '';
  1287. $custom = array(
  1288. 'msgtype' => 'text',
  1289. 'text' => array('content' => urlencode($info)),
  1290. 'touser' => $openid,
  1291. );
  1292. $status = $account->sendCustomNotice($custom);
  1293. }
  1294. return $status;
  1295. }
  1296. function mc_notice_times_times($openid, $title, $type, $endtime = '', $remark = '请注意时间,防止服务失效!') {
  1297. global $_W;
  1298. $account = mc_notice_init();
  1299. if(is_error($account)) {
  1300. return error(-1, $account['message']);
  1301. }
  1302. if($_W['account']['level'] == ACCOUNT_SERVICE_VERIFY && !empty($account->noticetpl['times_times']['tpl'])) {
  1303. $data = array(
  1304. 'first' => array(
  1305. 'value' => $title,
  1306. 'color' => '#ff510'
  1307. ),
  1308. 'name' => array(
  1309. 'value' => $type,
  1310. 'color' => '#ff510'
  1311. ),
  1312. 'expDate' => array(
  1313. 'value' => $endtime,
  1314. 'color' => '#ff510'
  1315. ),
  1316. 'remark' => array(
  1317. 'value' => "{$remark}" ,
  1318. 'color' => '#ff510'
  1319. ),
  1320. );
  1321. $status = $account->sendTplNotice($openid, $account->noticetpl['times_times']['tpl'], $data);
  1322. }
  1323. if($_W['account']['level'] == ACCOUNT_SUBSCRIPTION_VERIFY || is_error($status) || empty($account->noticetpl['times_times']['tpl'])) {
  1324. $info = "【{$_W['account']['name']}】-【{$type}】服务到期通知\n";
  1325. $info .= "您的{$type}即将到期,有效期至【{$endtime}】。\n";
  1326. $info .= !empty($remark) ? "备注:{$remark}\n\n" : '';
  1327. $custom = array(
  1328. 'msgtype' => 'text',
  1329. 'text' => array('content' => urlencode($info)),
  1330. 'touser' => $openid,
  1331. );
  1332. $status = $account->sendCustomNotice($custom);
  1333. }
  1334. return $status;
  1335. }
  1336. function mc_notice_pay_success($openid, $username, $order_sn, $money, $goods_info, $title = '尊敬的客户,您的订单已支付成功', $remark = '', $url = '') {
  1337. global $_W;
  1338. $money = sprintf("%.2f", $money);
  1339. if(empty($money)|| empty($openid)) {
  1340. return error(-1, '参数错误');
  1341. }
  1342. $account = mc_notice_init();
  1343. if(is_error($account)) {
  1344. return error(-1, $account['message']);
  1345. }
  1346. if($_W['account']['level'] == ACCOUNT_SERVICE_VERIFY && !empty($account->noticetpl['pay_success']['tpl'])) {
  1347. $data = array(
  1348. 'first' => array(
  1349. 'value' => $title,
  1350. 'color' => '#ff510'
  1351. ),
  1352. 'keyword1' => array(
  1353. 'value' => $username,
  1354. 'color' => '#ff510'
  1355. ),
  1356. 'keyword2' => array(
  1357. 'value' => $order_sn,
  1358. 'color' => '#ff510'
  1359. ),
  1360. 'keyword3' => array(
  1361. 'value' => $money. '元',
  1362. 'color' => '#ff510'
  1363. ),
  1364. 'keyword4' => array(
  1365. 'value' => $goods_info,
  1366. 'color' => '#ff510'
  1367. ),
  1368. 'remark' => array(
  1369. 'value' => $remark ,
  1370. 'color' => '#ff510'
  1371. ),
  1372. );
  1373. $status = $account->sendTplNotice($openid, $account->noticetpl['pay_success']['tpl'], $data, $url);
  1374. }
  1375. if($_W['account']['level'] == ACCOUNT_SUBSCRIPTION_VERIFY || is_error($status) || empty($account->noticetpl['pay_success']['tpl'])) {
  1376. $info = "【{$_W['account']['name']}】付款成功通知\n";
  1377. $info .= "您编号为{$order_sn}的订单已成功支付{$money}。\n";
  1378. $info .= "商品信息:{$goods_info}。\n";
  1379. $info .= !empty($remark) ? "备注:{$remark}\n\n" : '';
  1380. $custom = array(
  1381. 'msgtype' => 'text',
  1382. 'text' => array('content' => urlencode($info)),
  1383. 'touser' => $openid,
  1384. );
  1385. $status = $account->sendCustomNotice($custom);
  1386. }
  1387. return $status;
  1388. }
  1389. function mc_notice_consume($openid, $title, $content, $url = '') {
  1390. global $_W;
  1391. $account = mc_notice_init();
  1392. if(is_error($account)) {
  1393. return error(-1, $account['message']);
  1394. }
  1395. if($_W['account']['level'] == 4) {
  1396. mc_notice_credit2($openid, $content['uid'], $content['credit2_num'], $content['credit1_num'], $content['store'], '', $content['remark']);
  1397. }
  1398. if($_W['account']['level'] == 3) {
  1399. mc_notice_custom_text($openid, $title, $content);
  1400. }
  1401. return true;
  1402. }
  1403. function mc_notice_custom_text($openid, $title, $info) {
  1404. global $_W;
  1405. $account = mc_notice_init();
  1406. if(is_error($account)) {
  1407. return error(-1, $account['message']);
  1408. }
  1409. $custom = array(
  1410. 'msgtype' => 'text',
  1411. 'text' => array('content' => urlencode($title . '\n' . $info)),
  1412. 'touser' => $openid,
  1413. );
  1414. $status = $account->sendCustomNotice($custom);
  1415. return $status;
  1416. }
  1417. function mc_plugins() {
  1418. $plugins = array(
  1419. 'mc_card_manage' => array(
  1420. 'title' => '会员卡',
  1421. 'name' => 'mc_card_manage',
  1422. 'description' => '提供粉丝可开通会员卡并可以设置充值、消费金额及积分的增减策略',
  1423. ),
  1424. 'activity_discount_manage' => array(
  1425. 'title' => '兑换中心',
  1426. 'name' => 'activity_discount_manage',
  1427. 'description' => '提供粉丝可通过积分进行代金劵、折扣劵或是真实物品的兑换',
  1428. ),
  1429. 'wechat_card_manage' => array(
  1430. 'title' => '微信卡券',
  1431. 'name' => 'wechat_card_manage',
  1432. 'description' => '提供粉丝可通过积分进行代金劵、折扣劵或是真实物品的兑换',
  1433. ),
  1434. );
  1435. return $plugins;
  1436. }
  1437. function mc_init_fans_info($openid, $force_init_member = false){
  1438. global $_W;
  1439. static $account_api;
  1440. if (empty($account_api)) {
  1441. $account_api = WeAccount::createByUniacid();
  1442. }
  1443. if (is_array($openid)) {
  1444. $fans_list = $account_api->fansBatchQueryInfo($openid);
  1445. } else {
  1446. $fans_list = $account_api->fansQueryInfo($openid);
  1447. }
  1448. if (empty($fans_list) || is_error($fans_list)) {
  1449. if ($fans_list['errno'] == '48001') {
  1450. $fans_list = array(
  1451. 'openid' => $openid,
  1452. 'subscribe_time' => TIMESTAMP,
  1453. 'subscribe' => 1,
  1454. );
  1455. } else {
  1456. return true;
  1457. }
  1458. }
  1459. if (!is_array($openid)) {
  1460. $fans_list = array($fans_list);
  1461. }
  1462. foreach ($fans_list as $fans) {
  1463. if (empty($fans['subscribe'])) {
  1464. pdo_update('mc_mapping_fans', array('follow' => 0, 'unfollowtime' => TIMESTAMP), array('openid' => $fans['openid']));
  1465. continue;
  1466. }
  1467. $fans_mapping = mc_fansinfo($fans['openid']);
  1468. unset($fans['remark'], $fans['subscribe_scene'], $fans['qr_scene'], $fans['qr_scene_str']);
  1469. $fans_update_info = array(
  1470. 'openid' => $fans['openid'],
  1471. 'acid' => $_W['acid'],
  1472. 'uniacid' => $_W['uniacid'],
  1473. 'updatetime' => TIMESTAMP,
  1474. 'followtime' => $fans['subscribe_time'],
  1475. 'follow' => $fans['subscribe'],
  1476. 'nickname' => strip_emoji(stripcslashes($fans['nickname'])),
  1477. 'tag' => base64_encode(iserializer($fans)),
  1478. 'unionid' => $fans['unionid'],
  1479. 'groupid' => !empty($fans['tagid_list']) ? (','.join(',', $fans['tagid_list']).',') : '',
  1480. );
  1481. if (empty($fans_update_info['groupid'])) {
  1482. unset($fans_update_info['groupid']);
  1483. }
  1484. if ($force_init_member) {
  1485. $member_update_info = array(
  1486. 'uniacid' => $_W['uniacid'],
  1487. 'nickname' => $fans_update_info['nickname'],
  1488. 'avatar' => $fans['headimgurl'],
  1489. 'gender' => $fans['sex'],
  1490. 'nationality' => $fans['country'],
  1491. 'resideprovince' => $fans['province'] . '省',
  1492. 'residecity' => $fans['city'] . '市',
  1493. );
  1494. if (empty($fans_mapping['uid'])) {
  1495. $email = md5($fans['openid']).'@we7.cc';
  1496. $email_exists_member = pdo_getcolumn('mc_members', array('email' => $email), 'uid');
  1497. if (!empty($email_exists_member)) {
  1498. $uid = $email_exists_member;
  1499. } else {
  1500. $member_update_info['groupid'] = pdo_getcolumn('mc_groups', array('uniacid' => $_W['uniacid'], 'isdefault' => 1), 'groupid');
  1501. $member_update_info['salt'] = random(8);
  1502. $member_update_info['password'] = md5($fans['openid'] . $member_update_info['salt'] . $_W['config']['setting']['authkey']);
  1503. $member_update_info['email'] = $email;
  1504. $member_update_info['createtime'] = TIMESTAMP;
  1505. pdo_insert('mc_members', $member_update_info);
  1506. $uid = pdo_insertid();
  1507. }
  1508. $fans_update_info['uid'] = $uid;
  1509. } else {
  1510. $fans_update_info['uid'] = $fans_mapping['uid'];
  1511. pdo_update('mc_members', $member_update_info, array('uid' => $fans_mapping['uid']));
  1512. cache_delete(cache_system_key('memberinfo', array('uid' => $fans_mapping['uid'])));
  1513. }
  1514. }
  1515. if (!empty($fans_mapping)) {
  1516. pdo_update('mc_mapping_fans', $fans_update_info, array('fanid' => $fans_mapping['fanid']));
  1517. } else {
  1518. $fans_update_info['salt'] = random(8);
  1519. $fans_update_info['unfollowtime'] = 0;
  1520. $fans_update_info['followtime'] = TIMESTAMP;
  1521. pdo_insert('mc_mapping_fans', $fans_update_info);
  1522. $fans_mapping['fanid'] = pdo_insertid();
  1523. }
  1524. if (!empty($fans['tagid_list'])) {
  1525. $groupid = $fans['tagid_list'];
  1526. @sort($groupid, SORT_NATURAL);
  1527. mc_insert_fanstag_mapping($fans_mapping['fanid'], $groupid);
  1528. }
  1529. }
  1530. if (is_string($openid) && !empty($fans_update_info)) {
  1531. return $fans_update_info;
  1532. } else {
  1533. return true;
  1534. }
  1535. }
  1536. function mc_insert_fanstag_mapping($fanid, $groupid_list){
  1537. if (empty($groupid_list)) {
  1538. return true;
  1539. }
  1540. foreach ($groupid_list as $groupid) {
  1541. $record_mapping = array(
  1542. 'fanid' => $fanid,
  1543. 'tagid' => $groupid
  1544. );
  1545. $isfound = pdo_getcolumn('mc_fans_tag_mapping', $record_mapping, 'id');
  1546. if (empty($isfound)) {
  1547. pdo_insert('mc_fans_tag_mapping', $record_mapping);
  1548. }
  1549. }
  1550. pdo_delete('mc_fans_tag_mapping', array('fanid' => $fanid, 'tagid !=' => $groupid_list));
  1551. return true;
  1552. }
  1553. function mc_batch_insert_fanstag_mapping($fanid_list, $tagid_list){
  1554. if (!is_array($fanid_list) || !is_array($tagid_list)) {
  1555. return false;
  1556. }
  1557. $sql = '';
  1558. foreach ($fanid_list as $fanid) {
  1559. foreach ($tagid_list as $tagid) {
  1560. $fanid = intval($fanid);
  1561. $tagid = intval($tagid);
  1562. pdo_insert('mc_fans_tag_mapping', array('fanid' => $fanid, 'tagid' => $tagid), true);
  1563. }
  1564. }
  1565. return true;
  1566. }
  1567. function mc_show_tag($groupid){
  1568. if ($groupid) {
  1569. $fans_tag = mc_fans_groups();
  1570. $tagid_arr = explode(',', trim($groupid, ','));
  1571. foreach ($tagid_arr as $tagid) {
  1572. $tag_show .= $fans_tag[$tagid]['name'] . ', ';
  1573. }
  1574. $tag_show = rtrim($tag_show, ', ');
  1575. } else {
  1576. $tag_show = '无标签';
  1577. }
  1578. return $tag_show;
  1579. }
  1580. function mc_card_settings_hide($item = '') {
  1581. $mcFields = mc_acccount_fields();
  1582. if ($item == 'personal_info') {
  1583. if (empty($mcFields['idcard']) && empty($mcFields['height']) && empty($mcFields['weight']) && empty($mcFields['bloodtype']) && empty($mcFields['zodiac']) && empty($mcFields['constellation']) && empty($mcFields['site']) && empty($mcFields['affectivestatus']) && empty($mcFields['lookingfor']) && empty($mcFields['bio']) && empty($mcFields['interest'])) {
  1584. return true;
  1585. }
  1586. } elseif ($item == 'contact_method') {
  1587. if (empty($mcFields['telephone']) && empty($mcFields['qq']) && empty($mcFields['msn']) && empty($mcFields['taobao']) && empty($mcFields['alipay'])) {
  1588. return true;
  1589. }
  1590. } elseif ($item == 'education_info') {
  1591. if (empty($mcFields['education']) && empty($mcFields['graduateschool']) && empty($mcFields['studentid'])) {
  1592. return true;
  1593. }
  1594. } elseif ($item == 'jobedit') {
  1595. if (empty($mcFields['company']) && empty($mcFields['occupation']) && empty($mcFields['position']) && empty($mcFields['revenue'])) {
  1596. return true;
  1597. }
  1598. } elseif (empty($item)) {
  1599. if (empty($mcFields['idcard']) && empty($mcFields['height']) && empty($mcFields['weight'])
  1600. && empty($mcFields['bloodtype']) && empty($mcFields['zodiac']) && empty($mcFields['constellation'])
  1601. && empty($mcFields['site']) && empty($mcFields['affectivestatus']) && empty($mcFields['lookingfor'])
  1602. && empty($mcFields['bio']) && empty($mcFields['interest']) && empty($mcFields['telephone'])
  1603. && empty($mcFields['qq']) && empty($mcFields['msn']) && empty($mcFields['taobao'])
  1604. && empty($mcFields['alipay']) && empty($mcFields['education']) && empty($mcFields['graduateschool'])
  1605. && empty($mcFields['studentid']) && empty($mcFields['company']) && empty($mcFields['occupation'])
  1606. && empty($mcFields['position']) && empty($mcFields['revenue']) && empty($mcFields['avatar'])
  1607. && empty($mcFields['nickname']) && empty($mcFields['realname']) && empty($mcFields['gender'])
  1608. && empty($mcFields['birthyear']) && empty($mcFields['resideprovince'])) {
  1609. return true;
  1610. }
  1611. }
  1612. return false;
  1613. }
  1614. function mc_card_grant_credit($openid, $card_fee, $storeid = 0, $modulename) {
  1615. global $_W;
  1616. $setting = uni_setting($_W['uniacid'], array('creditbehaviors'));
  1617. load()->model('card');
  1618. $recharges_set = card_params_setting('cardRecharge');
  1619. $card_settings = card_setting();
  1620. $grant_rate = $card_settings['grant_rate'];
  1621. $grant_rate_switch = intval($recharges_set['params']['grant_rate_switch']);
  1622. $grant_credit1_enable = false;
  1623. if (!empty($grant_rate)) {
  1624. if (empty($recharges_set['params']['recharge_type'])) {
  1625. $grant_credit1_enable = true;
  1626. } else {
  1627. if ($grant_rate_switch == '1') {
  1628. $grant_credit1_enable = true;
  1629. }
  1630. }
  1631. }
  1632. if (!empty($grant_credit1_enable)) {
  1633. $num = $card_fee * $grant_rate;
  1634. $tips .= "用户消费{$card_fee}元,余额支付{$card_fee},积分赠送比率为:【1:{$grant_rate}】,共赠送【{$num}】积分";
  1635. mc_credit_update($openid, 'credit1', $num, array('0', $tip, $modulename, 0, $storeid, 3));
  1636. return error(0, $num);
  1637. } else {
  1638. return error(-1, '');
  1639. }
  1640. }
  1641. function mc_current_real_uniacid() {
  1642. global $_W;
  1643. if (!empty($_W['account']['link_uniacid']) || (!empty($_W['account']) && $_W['uniacid'] != $_W['account']['uniacid'])) {
  1644. return $_W['account']['uniacid'];
  1645. } else {
  1646. return $_W['uniacid'];
  1647. }
  1648. }
  1649. function mc_parse_profile($profile) {
  1650. global $_W;
  1651. if (empty($profile)) {
  1652. return array();
  1653. }
  1654. if (!empty($profile['avatar'])) {
  1655. $profile['avatar'] = tomedia($profile['avatar']);
  1656. } else {
  1657. $profile['avatar'] = './resource/images/nopic.jpg';
  1658. }
  1659. $profile['avatarUrl'] = $profile['avatar'];
  1660. $profile['birth'] = array(
  1661. 'year' => $profile['birthyear'],
  1662. 'month' => $profile['birthmonth'],
  1663. 'day' => $profile['birthday'],
  1664. );
  1665. $profile['reside'] = array(
  1666. 'province' => $profile['resideprovince'],
  1667. 'city' => $profile['city'],
  1668. 'district' => $profile['dist']
  1669. );
  1670. if(empty($profile['email']) || (!empty($profile['email']) && substr($profile['email'], -6) == 'we7.cc' && strlen($profile['email']) == 39)) {
  1671. $profile['email'] = '';
  1672. }
  1673. return $profile;
  1674. };
  1675. function mc_member_export_parse($members, $header = array()){
  1676. if (empty($members)) {
  1677. return false;
  1678. }
  1679. $groups = mc_groups();
  1680. $keys = array_keys($header);
  1681. $html = "\xEF\xBB\xBF";
  1682. foreach ($header as $li) {
  1683. $html .= $li . "\t ,";
  1684. }
  1685. $html .= "\n";
  1686. $count = count($members);
  1687. $pagesize = ceil($count/5000);
  1688. for ($j = 1; $j <= $pagesize; $j++) {
  1689. $list = array_slice($members, ($j-1) * 5000, 5000);
  1690. if (!empty($list)) {
  1691. $size = ceil(count($list) / 500);
  1692. for ($i = 0; $i < $size; $i++) {
  1693. $buffer = array_slice($list, $i * 500, 500);
  1694. $user = array();
  1695. foreach ($buffer as $row) {
  1696. if (strexists($row['email'], 'we7.cc')) {
  1697. $row['email'] = '';
  1698. }
  1699. $row['createtime'] = date('Y-m-d H:i:s', $row['createtime']);
  1700. $row['groupid'] = $groups[$row['groupid']]['title'];
  1701. if (!empty($row['birthmonth']) && !empty($row['birthday'])) {
  1702. $row['birthday'] = $row['birthmonth'] . '月' . $row['birthday'] . '日';
  1703. } else {
  1704. $row['birthday'] = '';
  1705. }
  1706. foreach ($keys as $key) {
  1707. $data[] = $row[$key];
  1708. }
  1709. $user[] = implode("\t ,", $data) . "\t ,";
  1710. unset($data);
  1711. }
  1712. $html .= implode("\n", $user) . "\n";
  1713. }
  1714. }
  1715. }
  1716. return $html;
  1717. }
  1718. function mc_fans_has_member_info($tag) {
  1719. if (is_base64($tag)) {
  1720. $tag = base64_decode($tag);
  1721. }
  1722. if (is_serialized($tag)) {
  1723. $tag = iunserializer($tag);
  1724. }
  1725. $profile = array();
  1726. if (!empty($tag)) {
  1727. if(!empty($tag['nickname'])) {
  1728. $profile['nickname'] = $tag['nickname'];
  1729. }
  1730. if(!empty($tag['sex'])) {
  1731. $profile['gender'] =$tag['sex'];
  1732. }
  1733. if(!empty($tag['province'])) {
  1734. $profile['resideprovince'] = $tag['province'];
  1735. }
  1736. if(!empty($tag['city'])) {
  1737. $profile['residecity'] = $tag['city'];
  1738. }
  1739. if(!empty($tag['country'])) {
  1740. $profile['nationality'] = $tag['country'];
  1741. }
  1742. if(!empty($tag['headimgurl'])) {
  1743. $profile['avatar'] = rtrim($tag['headimgurl']);
  1744. }
  1745. }
  1746. return $profile;
  1747. }
  1748. function mc_fans_chats_record_formate($chat_record) {
  1749. load()->model('material');
  1750. if (empty($chat_record)) {
  1751. return array();
  1752. }
  1753. foreach ($chat_record as &$record) {
  1754. if ($record['flag'] == FANS_CHATS_FROM_SYSTEM) {
  1755. $record['content'] = iunserializer($record['content']);
  1756. if (isset($record['content']['media_id']) && !empty($record['content']['media_id'])) {
  1757. $material = material_get($record['content']['media_id']);
  1758. switch($record['msgtype']) {
  1759. case 'image':
  1760. $record['content'] = tomedia($material['attachment']);
  1761. break;
  1762. case 'mpnews':
  1763. $record['content'] = $material['news'][0]['thumb_url'];
  1764. break;
  1765. case 'music':
  1766. $record['content'] = $material['filename'];
  1767. break;
  1768. case 'voice':
  1769. $record['content'] = $material['filename'];
  1770. break;
  1771. case 'voice':
  1772. $record['content'] = $material['filename'];
  1773. break;
  1774. }
  1775. } else {
  1776. $record['content'] = urldecode($record['content']['content']);
  1777. }
  1778. }
  1779. $record['createtime'] = date('Y-m-d H:i', $record['createtime']);
  1780. }
  1781. return $chat_record;
  1782. }
  1783. function mc_send_content_formate($data) {
  1784. $type = addslashes($data['type']);
  1785. if ($type == 'image') {
  1786. $contents = explode(',', htmlspecialchars_decode($data['content']));
  1787. $get_content = array_rand($contents, 1);
  1788. $content = trim($contents[$get_content], '\"');
  1789. }
  1790. if ($type == 'text' || $type == 'voice') {
  1791. $contents = htmlspecialchars_decode($data['content']);
  1792. $contents = explode(',', $contents);
  1793. $get_content = array_rand($contents, 1);
  1794. $content = trim($contents[$get_content], '\"');
  1795. }
  1796. if ($type == 'news' || $type == 'music') {
  1797. $contents = htmlspecialchars_decode($data['content']);
  1798. $contents = json_decode('[' . $contents . ']', true);
  1799. $get_content = array_rand($contents, 1);
  1800. $content = $contents[$get_content];
  1801. }
  1802. $send['touser'] = trim($data['openid']);
  1803. $send['msgtype'] = $type;
  1804. if ($type == 'text') {
  1805. $send['text'] = array('content' => urlencode(emoji_unicode_decode($content)));
  1806. } elseif ($type == 'image') {
  1807. $send['image'] = array('media_id' => $content);
  1808. $material = material_get($content);
  1809. $content = $material['attachment'];
  1810. } elseif ($type == 'voice') {
  1811. $send['voice'] = array('media_id' => $content);
  1812. } elseif($type == 'video') {
  1813. $content = json_decode($content, true);
  1814. $send['video'] = array(
  1815. 'media_id' => $content['mediaid'],
  1816. 'thumb_media_id' => '',
  1817. 'title' => urlencode($content['title']),
  1818. 'description' => ''
  1819. );
  1820. } elseif($type == 'music') {
  1821. $send['music'] = array(
  1822. 'musicurl' => tomedia($content['url']),
  1823. 'hqmusicurl' => tomedia($content['hqurl']),
  1824. 'title' => urlencode($content['title']),
  1825. 'description' => urlencode($content['description']),
  1826. 'thumb_media_id' => $content['thumb_media_id'],
  1827. );
  1828. } elseif($type == 'news') {
  1829. $send['msgtype'] = 'mpnews';
  1830. $send['mpnews'] = array(
  1831. 'media_id' => $content['mediaid']
  1832. );
  1833. }
  1834. return array(
  1835. 'send' => $send,
  1836. 'content' => $content
  1837. );
  1838. }