mc.mod.php 59 KB

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