common.php 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439
  1. <?php
  2. use app\common\library\QRcode;
  3. use think\Db;
  4. use OSS\OssClient;
  5. function IntToChr($index, $start = 65) {
  6. $str = '';
  7. if (floor($index / 26) > 0) {
  8. $str .= IntToChr(floor($index / 26)-1);
  9. }
  10. return $str . chr($index % 26 + $start);
  11. }
  12. /**
  13. * 秒转换为天
  14. */
  15. function get_stay_time($remain_time, $is_hour = 1, $is_minutes = 1)
  16. {
  17. $day = floor($remain_time / (3600*24));
  18. $day = $day > 0 ? $day.'天' : '';
  19. $hour = floor(($remain_time % (3600*24)) / 3600);
  20. $hour = $hour > 0 ? $hour.'小时' : '';
  21. if($is_hour && $is_minutes) {
  22. $minutes = floor((($remain_time % (3600*24)) % 3600) / 60);
  23. $minutes = $minutes > 0 ? $minutes.'分钟' : '';
  24. return $day.$hour.$minutes;
  25. }
  26. if($hour) {
  27. return $day.$hour;
  28. }
  29. return $day;
  30. }
  31. //获取全图片地址 $image_data
  32. function image_path($image_data){
  33. if(empty($image_data)){
  34. return $image_data;
  35. }
  36. if (strpos($image_data,'|')!==false){
  37. $image_res = explode('|',$image_data);
  38. }elseif(strpos($image_data,',')!==false){
  39. $image_res = explode(',',$image_data);
  40. }else{
  41. $image_res = array($image_data);
  42. }
  43. return $image_res;
  44. }
  45. // 获取模板区域
  46. function get_city_area()
  47. {
  48. $field=['id','pid','name'];
  49. $list=Db::table('store_area')->where('pid',0)->field($field)->select();
  50. foreach ($list as $k=>&$v){
  51. $v['children']= Db::table('store_area')->where('pid',$v['id'])->field($field)->select();
  52. }
  53. return $list;
  54. }
  55. function http_curl($url,$type='get',$res='json',$arr=''){
  56. $headers = array();
  57. //根据API的要求,定义相对应的Content-Type
  58. array_push($headers, "Content-Type".":"."application/x-www-form-urlencoded; charset=UTF-8;application/json");
  59. $curl = curl_init();
  60. curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $type);
  61. curl_setopt($curl, CURLOPT_URL, $url);
  62. curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
  63. curl_setopt($curl, CURLOPT_FAILONERROR, false);
  64. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  65. curl_setopt($curl, CURLOPT_HEADER, false);
  66. $output = curl_exec($curl);
  67. curl_close($curl);
  68. if($res=='json'){
  69. if($output === false){
  70. //请求失败,返回错误信息
  71. return curl_error($curl);
  72. }else{
  73. //请求成功,返回信息
  74. return json_decode($output,true);
  75. }
  76. }
  77. }
  78. // 获取物流信息
  79. function get_delivery($send_no = 'JD0053309649641',$express_code=''){
  80. error_reporting(E_ALL || ~E_NOTICE);
  81. $AppKey = 204008273;
  82. $AppSecret ='t9PavvfCeK5v2XidwyK5pWDp8b0hzMq4';
  83. $AppCode ='47f640e3529d43e28365311a530db2b7';//开通服务后 买家中心-查看AppCode
  84. $host = "https://wuliu.market.alicloudapi.com";//api访问链接
  85. $path = "/kdi";//API访问后缀
  86. $method = "GET";
  87. $body ='';
  88. $headers = array();
  89. array_push($headers, "Authorization:APPCODE " . $AppCode);
  90. $querys = "no={$send_no}&type={$express_code}"; //参数写在这里
  91. $url = $host . $path . "?" . $querys;
  92. $curl = curl_init();
  93. curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
  94. curl_setopt($curl, CURLOPT_URL, $url);
  95. curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
  96. curl_setopt($curl, CURLOPT_FAILONERROR, false);
  97. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  98. curl_setopt($curl, CURLOPT_HEADER, true);
  99. if (1 == strpos("$" . $host, "https://")) {
  100. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  101. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  102. }
  103. $out_put = curl_exec($curl);
  104. $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
  105. list($header, $body) = explode("\r\n\r\n", $out_put, 2);
  106. if ($httpCode == 200) {
  107. return json_decode($body,true)['result'];
  108. } else {
  109. return [];
  110. }
  111. }
  112. // 元石日志
  113. function crystal_log($user_id,$crystal,$desc,$type,$rel_id=0)
  114. {
  115. $log_data = [
  116. 'user_id' => $user_id,
  117. 'create_at' => date('Y-m-d H:i:s'),
  118. 'crystal' => $crystal,
  119. 'desc' => $desc,
  120. 'type' => $type,
  121. 'rel_id' => $rel_id,
  122. ];
  123. Db::table('crystal_info')->insert($log_data);
  124. }
  125. /**
  126. * 判断是否为合法的身份证号码
  127. * @param $mobile
  128. * @return int
  129. */
  130. function isCreditNo($vStr){
  131. $vCity = array(
  132. '11','12','13','14','15','21','22',
  133. '23','31','32','33','34','35','36',
  134. '37','41','42','43','44','45','46',
  135. '50','51','52','53','54','61','62',
  136. '63','64','65','71','81','82','91'
  137. );
  138. if (!preg_match('/^([\d]{17}[xX\d]|[\d]{15})$/', $vStr)) return false;
  139. if (!in_array(substr($vStr, 0, 2), $vCity)) return false;
  140. $vStr = preg_replace('/[xX]$/i', 'a', $vStr);
  141. $vLength = strlen($vStr);
  142. if ($vLength == 18) {
  143. $vBirthday = substr($vStr, 6, 4) . '-' . substr($vStr, 10, 2) . '-' . substr($vStr, 12, 2);
  144. } else {
  145. $vBirthday = '19' . substr($vStr, 6, 2) . '-' . substr($vStr, 8, 2) . '-' . substr($vStr, 10, 2);
  146. }
  147. if (date('Y-m-d', strtotime($vBirthday)) != $vBirthday) return false;
  148. if ($vLength == 18) {
  149. $vSum = 0;
  150. for ($i = 17 ; $i >= 0 ; $i--) {
  151. $vSubStr = substr($vStr, 17 - $i, 1);
  152. $vSum += (pow(2, $i) % 11) * (($vSubStr == 'a') ? 10 : intval($vSubStr , 11));
  153. }
  154. if($vSum % 11 != 1) return false;
  155. }
  156. return true;
  157. }
  158. //实名认证(云盾身份认证(身份证二要素核验)
  159. function identifyCertification($id_card,$name){
  160. $host = "https://safrvcert.market.alicloudapi.com";
  161. $path = "/safrv_2meta_id_name/";
  162. $method = "GET";
  163. $appcode = "95ec5cd8c54d4ced9220caebdaa5d750";
  164. $headers = array();
  165. array_push($headers, "Authorization:APPCODE " . $appcode);
  166. $querys = "__userId=__userId&identifyNum=$id_card&userName=$name&verifyKey=verifyKey";
  167. $bodys = "";
  168. $url = $host . $path . "?" . $querys;
  169. $curl = curl_init();
  170. curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
  171. curl_setopt($curl, CURLOPT_URL, $url);
  172. curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
  173. curl_setopt($curl, CURLOPT_FAILONERROR, false);
  174. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  175. curl_setopt($curl, CURLOPT_HEADER, false);
  176. if (1 == strpos("$".$host, "https://"))
  177. {
  178. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  179. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  180. }
  181. curl_setopt($curl, CURLOPT_POSTFIELDS, $bodys);
  182. $res = curl_exec($curl);
  183. if($res){
  184. $res = json_decode($res,true);
  185. if($res['code'] == 200 && $res['message']=='success'){
  186. return 1;
  187. }else{
  188. return 0;
  189. }
  190. }else{
  191. return 0;
  192. }
  193. }
  194. //实名认证(云盾身份认证(身份证二要素核验)
  195. function identifyCertifications($id_card,$name){
  196. $name = urlencode($name);
  197. $host = "https://id2meta.market.alicloudapi.com";
  198. $path = "/id2meta";
  199. $method = "GET";
  200. $appcode = "90aaffbffd6c4567b182bf4142638eb7";
  201. $headers = array();
  202. array_push($headers, "Authorization:APPCODE ".$appcode);
  203. //$querys = "identifyNum=".$id_card."&userName=".$name;
  204. $querys = "identifyNum=$id_card&userName=$name";
  205. $bodys = "";
  206. $url = $host . $path . "?" . $querys;
  207. $curl = curl_init();
  208. curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
  209. curl_setopt($curl, CURLOPT_URL, $url);
  210. curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
  211. curl_setopt($curl, CURLOPT_FAILONERROR, false);
  212. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  213. curl_setopt($curl, CURLOPT_HEADER, false);
  214. if (1 == strpos("$".$host, "https://"))
  215. {
  216. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  217. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  218. }
  219. curl_setopt($curl, CURLOPT_POSTFIELDS, $bodys);
  220. $res = curl_exec($curl);
  221. if($res){
  222. $res = json_decode($res,true);
  223. if($res['code'] == 200 && $res['data']['bizCode']=='1'){
  224. return 1;
  225. }else{
  226. return 0;
  227. }
  228. }else{
  229. return 0;
  230. }
  231. }
  232. //实名认证三要素
  233. function userThreecertification($id_card,$name,$mobile){
  234. $host = "https://mobilecert.market.alicloudapi.com";
  235. $path = "/mobile3Meta";
  236. $method = "GET";
  237. $appcode = "e3f104dac72f441f854ff53de62c4cd9";
  238. $headers = array();
  239. array_push($headers, "Authorization:APPCODE " . $appcode);
  240. $querys = "identifyNum=".$id_card."&mobile=".$mobile."&userName=".urlencode($name);
  241. $bodys = "";
  242. $url = $host . $path . "?" . $querys;
  243. $curl = curl_init();
  244. curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
  245. curl_setopt($curl, CURLOPT_URL, $url);
  246. curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
  247. curl_setopt($curl, CURLOPT_FAILONERROR, false);
  248. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  249. curl_setopt($curl, CURLOPT_HEADER, false);
  250. if (1 == strpos("$".$host, "https://"))
  251. {
  252. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  253. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  254. }
  255. curl_setopt($curl, CURLOPT_POSTFIELDS, $bodys);
  256. $res = curl_exec($curl);
  257. if($res){
  258. $res = json_decode($res,true);
  259. if($res['data']['bizCode'] == 1){
  260. return 1;
  261. }else{
  262. return 0;
  263. }
  264. }else{
  265. return 0;
  266. }
  267. }
  268. // 实名认证
  269. function user_certification($id_card,$name){
  270. $host = "http://checkone.market.alicloudapi.com";
  271. $path = "/chinadatapay/1882";
  272. $method = "POST";
  273. $appcode = "c8fd88cc95dd46fa8c50b05d219824ed";
  274. $headers = array();
  275. array_push($headers, "Authorization:APPCODE " . $appcode);
  276. //根据API的要求,定义相对应的Content-Type
  277. array_push($headers, "Content-Type".":"."application/x-www-form-urlencoded; charset=UTF-8");
  278. $bodys = "idcard=".$id_card."&name=".$name;
  279. $url = $host . $path;
  280. $curl = curl_init();
  281. curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
  282. curl_setopt($curl, CURLOPT_URL, $url);
  283. curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
  284. curl_setopt($curl, CURLOPT_FAILONERROR, false);
  285. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  286. curl_setopt($curl, CURLOPT_HEADER, false);
  287. if (1 == strpos("$".$host, "https://"))
  288. {
  289. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  290. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  291. }
  292. curl_setopt($curl, CURLOPT_POSTFIELDS, $bodys);
  293. $res = curl_exec($curl);
  294. if($res){
  295. $res = json_decode($res,true);
  296. if($res['data']['result'] == 1){
  297. return 1;
  298. }else{
  299. return 0;
  300. }
  301. }else{
  302. return 0;
  303. }
  304. }
  305. function shoucang(){
  306. $host = "http://180.76.141.31:8888/cz/call";
  307. $method = "POST";
  308. $headers = array();
  309. array_push($headers, "Content-Type".":"."application/json; charset=UTF-8");
  310. $bodys = array(
  311. 'key' => 'test2',
  312. 'userkey' => '12344',
  313. 'product' => json_encode(array('name'=>'test','count'=>7))
  314. );
  315. $curl = curl_init();
  316. curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
  317. curl_setopt($curl, CURLOPT_URL, $host);
  318. curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
  319. curl_setopt($curl, CURLOPT_FAILONERROR, false);
  320. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  321. curl_setopt($curl, CURLOPT_HEADER, false);
  322. if (1 == strpos("$".$host, "https://"))
  323. {
  324. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  325. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  326. }
  327. curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($bodys));
  328. $res = curl_exec($curl);
  329. var_dump($res);exit();
  330. }
  331. /**
  332. * 大师提前分钟数存入redis
  333. */
  334. function setAdvanceMinutes(){
  335. $redis = new \think\cache\driver\Redis();
  336. $value = Db::name('system_config')->where('name','advance_minutes')->value('value');
  337. $redis->set('advance_minutes',$value);
  338. }
  339. /**
  340. * 获取大师提前分钟数
  341. */
  342. function getAdvanceMinutes(){
  343. $redis = new \think\cache\driver\Redis();
  344. $value = $redis->get('advance_minutes');
  345. if (empty($value)){
  346. $value = Db::name('system_config')->where('name','advance_minutes')->value('value');
  347. $redis->set('advance_minutes',$value);
  348. }
  349. return $value;
  350. }
  351. /**
  352. * 获取自动取消分钟数
  353. */
  354. function getCancelTime(){
  355. return Db::name('system_config')->where('name','cancel_time')->value('value');
  356. }
  357. /**
  358. * 用户信息存入redis hash
  359. */
  360. function setMemberInfoHash($member_id){
  361. $info = Db::name('store_member')->where('id',$member_id)->find();
  362. $redis = new \think\cache\driver\Redis();
  363. $array = ['member'.$member_id=>json_encode($info)];
  364. $redis->hMSet('memberInfo',$array);
  365. }
  366. /**
  367. * redis获取用户信息
  368. */
  369. function getMemberInfoHash($member_id){
  370. $redis = new \think\cache\driver\Redis();
  371. $info = $redis->hGet('memberInfo','member'.$member_id);
  372. if (!$info){
  373. $info = Db::name('store_member')->where('id',$member_id)->find();
  374. $array = ['member'.$member_id=>json_encode($info)];
  375. $redis->hMSet('memberInfo',$array);
  376. }else{
  377. $info = json_decode($info,true);
  378. }
  379. return $info;
  380. }
  381. /**
  382. * 用户抢购卡数量存入redis 字符串
  383. */
  384. function setMembercard($member_id){
  385. $snap_card = Db::name('store_member')->where('id',$member_id)->value('snap_card');
  386. $redis = new \think\cache\driver\Redis();
  387. $redis->set('membercard_'.$member_id,$snap_card);
  388. }
  389. /**
  390. * 获取用户抢购卡数量
  391. */
  392. function getMembercard($member_id){
  393. $redis = new \think\cache\driver\Redis();
  394. $count = $redis->get('membercard_'.$member_id);
  395. if (empty($count)){
  396. $count = Db::name('store_member')->where('id',$member_id)->value('snap_card');
  397. $redis->set('membercard_'.$member_id,$count);
  398. }
  399. return $count;
  400. }
  401. /**
  402. * 减掉用户抢购卡数量(减1)
  403. */
  404. function loseMembercard($id){
  405. $redis = new \think\cache\driver\Redis();
  406. $redis->Decr('membercard_'.$id);
  407. }
  408. /**
  409. * 增加用户抢购卡数量(加1)
  410. */
  411. function addMembercard($id){
  412. $redis = new \think\cache\driver\Redis();
  413. $redis->Incr('membercard_'.$id);
  414. }
  415. /**
  416. * 获取藏品库存
  417. */
  418. function getCollectionInventory($id){
  419. $redis = new \think\cache\driver\Redis();
  420. $count = $redis->get('collection_count_'.$id);
  421. // if (empty($count)){
  422. // $redis->set('collection_count_'.$id,0);
  423. // }
  424. return $count>0 ? $count : 0;
  425. }
  426. /**
  427. * 减掉藏品库存
  428. */
  429. function loseCollectionInventory($id,$num){
  430. $redis = new \think\cache\driver\Redis();
  431. $redis->Decrby('collection_count_'.$id,$num);
  432. }
  433. /**
  434. * 加藏品库存
  435. */
  436. function addCollectionInventory($id,$num){
  437. $redis = new \think\cache\driver\Redis();
  438. $redis->Incrby('collection_count_'.$id,$num);
  439. }
  440. /**
  441. * 用户购买藏品排名更新
  442. */
  443. function saveRanking($id){
  444. $redis = new \think\cache\driver\Redis();
  445. $redis->Incr('ranking'.$id);
  446. }
  447. /**
  448. * 获取用户购买藏品排名更新
  449. */
  450. function getRanking($id){
  451. $redis = new \think\cache\driver\Redis();
  452. $count = $redis->get('ranking'.$id);
  453. if (empty($count)){
  454. $redis->set('ranking'.$id,0);
  455. }
  456. $count = empty($count) ? 0 : $count;
  457. return $count;
  458. }
  459. /**
  460. * 藏品信息存入redis hash
  461. */
  462. function setCollectionInfoHash($id){
  463. $info = Db::name('store_collection')->where('id',$id)->find();
  464. $redis = new \think\cache\driver\Redis();
  465. $array = ['collection'.$id=>json_encode($info)];
  466. $redis->hMSet('collectionInfo',$array);
  467. }
  468. /**
  469. * 获取用户购买数量
  470. */
  471. function getByCount($mid,$id){
  472. $redis = new \think\cache\driver\Redis();
  473. $count = $redis->get('UserByCount_'.$mid.$id);
  474. if (empty($count) && $count!=0){
  475. // $count = Db::name('store_order')
  476. // ->where('mid',$mid)
  477. // ->where('c_id',$id)
  478. // ->whereIn('status','0,1')
  479. // ->sum('num');
  480. // $count = $count ? $count : 0;
  481. $count = 0;
  482. $redis->Incrby('UserByCount_'.$mid.$id,$count);
  483. }
  484. return $count;
  485. }
  486. /**
  487. * 用户购买数量增加
  488. */
  489. function IncrByCount($mid,$id,$number){
  490. $redis = new \think\cache\driver\Redis();
  491. $redis->Incrby('UserByCount_'.$mid.$id,$number);
  492. }
  493. /**
  494. * 用户购买数量减少
  495. */
  496. function DecrByCount($mid,$id,$number){
  497. $redis = new \think\cache\driver\Redis();
  498. $redis->Decrby('UserByCount_'.$mid.$id,$number);
  499. }
  500. /**
  501. * 获取藏品hash redis长度
  502. */
  503. function getLenCollection($id){
  504. $redis = new \think\cache\driver\Redis();
  505. $count = $redis->Llen('collectionHash_'.$id);
  506. if (!$count){
  507. $count = Db::name('hash')
  508. ->where('goods_id',$id)
  509. ->where('status',0)
  510. ->count();
  511. }
  512. return $count;
  513. }
  514. /**
  515. * 获取藏品信息
  516. */
  517. function getCollectionInfoHash($id)
  518. {
  519. $redis = new \think\cache\driver\Redis();
  520. $info = $redis->hGet('collectionInfo','collection'.$id);
  521. if (!$info){
  522. $info = Db::name('store_collection')->where('id',$id)->find();
  523. $array = ['collection'.$id=>json_encode($info)];
  524. $redis->hMSet('collectionInfo',$array);
  525. }else{
  526. $info = json_decode($info,true);
  527. }
  528. return $info;
  529. }
  530. /**
  531. * 收集下单用户id
  532. */
  533. function setCollectionBuyUser($mid){
  534. $redis = new \think\cache\driver\Redis();
  535. $array = [$mid=>1];
  536. $redis->hMSet('buyUserInfo',$array);
  537. }
  538. /*
  539. * 微信支付账户
  540. */
  541. function retrunWxConfig(){
  542. $config = [
  543. 'app_id' => 'wxb5a55711e16751c4',
  544. 'mch_id' =>'1628119673',
  545. 'key' =>'eLA2g2ZnrZYA5mZ16r0ncEduQXpLbgId',
  546. ];
  547. return $config;
  548. }
  549. /**
  550. * 获取离线账户
  551. */
  552. function getOfflineAccount(){
  553. $url = 'http://192.144.219.204:8083/ddc/createAccount';
  554. return file_get_contents($url);
  555. }
  556. /**
  557. * 获取链账户
  558. */
  559. function getWalletAddress($phone){
  560. $url = getIpAddress().'register?accountName='.$phone;
  561. $res=curlRequest($url);
  562. if ($res){
  563. $res = json_decode($res,true);
  564. if ($res['code']=='200'){
  565. return $res['result']['userAddressStr'];
  566. }
  567. }
  568. return false;
  569. }
  570. /**
  571. * 获取公司生成的hash
  572. */
  573. function getCompanyHash($id){
  574. $hash = Db::name('hash')->where('goods_id',$id)
  575. ->where('status',0)
  576. ->order('id asc')
  577. ->field('hash,create_at,tokenid')
  578. ->limit(1)
  579. ->find();
  580. return $hash;
  581. }
  582. /**
  583. * 获取排名
  584. */
  585. function getTag($id,$now,$num){
  586. $len = strlen($num);
  587. $re = 'YZCS'.$id.'#';
  588. switch ($len){
  589. case 1:
  590. $re = $re.'0'.$now;
  591. break;
  592. case 2:
  593. if ($now<10){
  594. $re = $re.'0'.$now;
  595. }else{
  596. $re = $re.$now;
  597. }
  598. break;
  599. case 3:
  600. if ($now<10){
  601. $re = $re.'00'.$now;
  602. }elseif ($now>=10 && $now<100){
  603. $re = $re.'0'.$now;
  604. }else{
  605. $re = $re.$now;
  606. }
  607. break;
  608. case 4:
  609. if ($now<10){
  610. $re = $re.'000'.$now;
  611. }elseif ($now>=10 && $now<100){
  612. $re = $re.'00'.$now;
  613. }elseif ($now>=100 && $now<1000){
  614. $re = $re.'0'.$now;
  615. }else{
  616. $re = $re.$now;
  617. }
  618. break;
  619. case 5:
  620. if ($now<10){
  621. $re = $re.'0000'.$now;
  622. }elseif ($now>=10 && $now<100){
  623. $re = $re.'000'.$now;
  624. }elseif ($now>=100 && $now<1000){
  625. $re = $re.'00'.$now;
  626. }elseif ($now>=1000 && $now<10000){
  627. $re = $re.'0'.$now;
  628. }else{
  629. $re = $re.$now;
  630. }
  631. break;
  632. case 6:
  633. if ($now<10){
  634. $re = $re.'00000'.$now;
  635. }elseif ($now>=10 && $now<100){
  636. $re = $re.'0000'.$now;
  637. }elseif ($now>=100 && $now<1000){
  638. $re = $re.'000'.$now;
  639. }elseif ($now>=1000 && $now<10000){
  640. $re = $re.'00'.$now;
  641. }elseif ($now>=10000 && $now<100000){
  642. $re = $re.'0'.$now;
  643. }else{
  644. $re = $re.$now;
  645. }
  646. break;
  647. }
  648. $re = $re.'/'.$num;
  649. return $re;
  650. }
  651. /**
  652. * 判断藏品是否设置过提醒
  653. */
  654. function getRemind($mid,$c_id){
  655. return Db::name('store_collection_remind')->where('mid',$mid)->where('c_id',$c_id)->count();
  656. }
  657. /**
  658. * 变更会员积分等
  659. * @param int $money 余额
  660. * @param int $user_id 会员ID
  661. * @param string $memo 备注
  662. */
  663. function memberMoneyChange($num, $type , $m_id, $title, $pm = 0,$link_id=0, $other = [])
  664. {
  665. $member = Db::name('store_member')->where('id',$m_id)->find();
  666. switch ($type){
  667. case 1: //积分
  668. $before = $member['integral'];
  669. if ($pm==1)
  670. $after = $member['integral']+$num;
  671. else
  672. $after = $member['integral']-$num;
  673. $update_data = ['integral'=>$after];
  674. break;
  675. case 2: //抢购卡
  676. $before = $member['snap_card'];
  677. if ($pm==1)
  678. $after = $member['snap_card']+$num;
  679. else
  680. $after = $member['snap_card']-$num;
  681. $update_data = ['snap_card'=>$after];
  682. break;
  683. case 3: //余额
  684. $before = $member['money'];
  685. if ($pm==1)
  686. $after = $member['money']+$num;
  687. else
  688. $after = $member['money']-$num;
  689. $update_data = ['money'=>$after];
  690. break;
  691. }
  692. Db::startTrans();
  693. try {
  694. Db::name('store_member')->where('id',$m_id)->update($update_data);
  695. $data = [
  696. 'm_id'=>$m_id,
  697. 'type'=>$type,
  698. 'pm'=>$pm,
  699. 'title'=>$title,
  700. 'change'=>$num,
  701. 'before'=>$before,
  702. 'after'=>$after,
  703. 'link_id'=>$link_id,
  704. 'order_id' => !empty($other['order_id']) ? $other['order_id'] : 0,
  705. 'source' => !empty($other['source']) ? $other['source'] : 0
  706. ];
  707. Db::name('store_member_log')->insert($data);
  708. Db::commit();
  709. return true;
  710. }catch (\Exception $e){
  711. Db::rollback();
  712. return false;
  713. }
  714. }
  715. /**
  716. * 一级市场给直推返利
  717. */
  718. function superiorRebate($data=[]){
  719. $pid = Db::name('store_member')->where('id','=',$data['uid'])->where('pid','neq',0)->field('pid')->find();
  720. if($pid){
  721. $bili = Db::name('system_config')->where('name','=','direct_push_reward')->field('value')->find();
  722. $number =($bili['value']/100)*$data['money'];
  723. memberMoneyChange($number,3,$pid['pid'],'推荐奖励',1,0,['order_id'=>$data['order_id'],'source'=>5]);
  724. }
  725. }
  726. /**
  727. * 获取单个系统配置信息
  728. */
  729. function getConfigValue($name){
  730. return Db::name('system_config')->where('name',$name)->value('value');
  731. }
  732. /**
  733. * 判断藏品状态
  734. */
  735. function checkCollectionState($id=''){
  736. if ($id){
  737. $info = Db::name('store_collection')->whereIn('type','1,3')->where('id',$id)->find();
  738. $now_inventory = getCollectionInventory($id);
  739. if ($info['state']==1){
  740. if ($now_inventory<=0){
  741. Db::name('store_collection')->whereIn('type','1,3')->where('id',$info['id'])->update(['state'=>3]);
  742. }
  743. }else if($info['state']==2){
  744. if (strtotime($info['sell_time'])<=time()){
  745. Db::name('store_collection')->whereIn('type','1,3')->where('id',$info['id'])->update(['state'=>1]);
  746. }
  747. }else if($info['state']==3){
  748. if ($now_inventory>0){
  749. Db::name('store_collection')->whereIn('type','1,3')->where('id',$info['id'])->update(['state'=>1]);
  750. }
  751. }
  752. }else{
  753. $list = Db::name('store_collection')
  754. ->whereIn('type','1,3')
  755. ->whereIn('state','1,2,3')
  756. ->where('is_deleted',0)
  757. ->select();
  758. foreach ($list as &$v){
  759. $now_inventory = getCollectionInventory($v['id']);
  760. if ($v['state']==1){
  761. if ($now_inventory<=0){
  762. Db::name('store_collection')->whereIn('type','1,3')->where('id',$v['id'])->update(['state'=>3]);
  763. }
  764. }elseif ($v['state']==2){
  765. if (strtotime($v['sell_time'])<=time()){
  766. Db::name('store_collection')->whereIn('type','1,3')->where('id',$v['id'])->update(['state'=>1]);
  767. }
  768. }elseif ($v['state']==3){
  769. if ($now_inventory>0){
  770. Db::name('store_collection')->whereIn('type','1,3')->where('id',$v['id'])->update(['state'=>1]);
  771. }
  772. }
  773. }
  774. }
  775. }
  776. /**
  777. * 判断藏品状态
  778. */
  779. function checkSynCollectionState($id=''){
  780. if ($id){
  781. $info = Db::name('store_collection')->where('id',$id)->find();
  782. $now_inventory = getCollectionInventory($id);
  783. if ($info['sy_state']==1){
  784. if ($now_inventory<=0){
  785. Db::name('store_collection')->where('id',$info['id'])->update(['sy_state'=>4]);
  786. }elseif(strtotime($info['end_time'])<time()){
  787. Db::name('store_collection')->where('id',$info['id'])->update(['sy_state'=>3]);
  788. }
  789. }elseif ($info['sy_state']==2){
  790. if (strtotime($info['sell_time'])<=time()){
  791. Db::name('store_collection')->where('id',$info['id'])->update(['sy_state'=>1]);
  792. }elseif ($now_inventory<=0){
  793. Db::name('store_collection')->where('id',$info['id'])->update(['sy_state'=>4]);
  794. }
  795. }
  796. }else{
  797. $list = Db::name('store_collection')
  798. ->where('type',2)
  799. ->whereIn('sy_state','1,2')
  800. ->where('is_deleted',0)
  801. ->select();
  802. foreach ($list as &$v){
  803. $now_inventory = getCollectionInventory($v['id']);
  804. if ($v['sy_state']==1){
  805. if ($now_inventory<=0){
  806. Db::name('store_collection')->where('id',$v['id'])->update(['sy_state'=>4]);
  807. }elseif(strtotime($v['end_time'])<time()){
  808. Db::name('store_collection')->where('id',$v['id'])->update(['sy_state'=>3]);
  809. }
  810. }elseif ($v['sy_state']==2){
  811. if (strtotime($v['sell_time'])<=time()){
  812. Db::name('store_collection')->where('id',$v['id'])->update(['sy_state'=>1]);
  813. }elseif ($now_inventory<=0){
  814. Db::name('store_collection')->where('id',$v['id'])->update(['sy_state'=>4]);
  815. }
  816. }
  817. }
  818. }
  819. }
  820. /**
  821. * redis加锁
  822. */
  823. function redisSetNx($key,$exptime){
  824. $redis = new \think\cache\driver\Redis();
  825. $is_lock = $redis->setnx($key,time()+$exptime);
  826. if ($is_lock){
  827. return true;
  828. }else{
  829. //加锁失败的情况下,判断锁是否已经存在,如果存在切已经过期,删除锁,重新加锁
  830. $val = $redis->get($key);
  831. if ($val && $val<time()){
  832. $redis->del($key);
  833. }
  834. return $redis->setnx($key,time()+$exptime);
  835. }
  836. }
  837. /**
  838. * 删除锁
  839. */
  840. function DelRedisSetNx($key){
  841. $redis = new \think\cache\driver\Redis();
  842. $redis->del($key);
  843. }
  844. /**
  845. * 盲盒信息存入redis hash
  846. */
  847. function setBoxInfoHash($id){
  848. $info = Db::name('store_collection')->where('id',$id)->find();
  849. $redis = new \think\cache\driver\Redis();
  850. $array = ['collection'.$id=>json_encode($info)];
  851. $redis->hMSet('collectionInfo',$array);
  852. }
  853. /**
  854. * 获取0的数量
  855. */
  856. function get0number($n){
  857. if ($n==1){
  858. return '00000000000';
  859. }elseif ($n==2){
  860. return '0000000000';
  861. }elseif ($n==3){
  862. return '000000000';
  863. }elseif ($n==4){
  864. return '00000000';
  865. }elseif ($n==5){
  866. return '0000000';
  867. }elseif ($n==6){
  868. return '000000';
  869. }elseif ($n==7){
  870. return '00000';
  871. }elseif ($n==8){
  872. return '0000';
  873. }elseif ($n==9){
  874. return '000';
  875. }elseif ($n==10){
  876. return '00';
  877. }elseif ($n==11){
  878. return '0';
  879. }
  880. }
  881. /***********************************************人脸识别*****************************************************************/
  882. /**
  883. * 获取accesstoken
  884. * @return mixed
  885. */
  886. function getAccessToken(){
  887. $appid_id =getFaceInfo()['appid'];
  888. $secret = getFaceInfo()['secret'];
  889. $grant_type = 'client_credential';
  890. $version = '1.0.0';
  891. $url = "https://miniprogram-kyc.tencentcloudapi.com/api/oauth2/access_token?app_id=".$appid_id."&secret=".$secret."&grant_type=".$grant_type."&version=".$version;
  892. $result = curlRequest($url);
  893. $result = json_decode($result,true);
  894. if ($result['code']==0){
  895. return $result;
  896. }
  897. echo $result['msg'];die;
  898. }
  899. /**
  900. * 获取api_ticket
  901. */
  902. function getApiTicket($type,$userId=''){
  903. $appid_id =getFaceInfo()['appid'];
  904. $access_token = getAccessToken()['access_token'];
  905. $version = '1.0.0';
  906. $url = "https://miniprogram-kyc.tencentcloudapi.com/api/oauth2/api_ticket?app_id=".$appid_id."&access_token=".$access_token."&type=".$type."&version=".$version;
  907. if ($type=='NONCE'){
  908. $url .= "&user_id=".$userId;
  909. }
  910. $result = curlRequest($url);
  911. $result = json_decode($result,true);
  912. if ($result['code']==0){
  913. return $result;
  914. }
  915. echo $result['msg'];die;
  916. }
  917. /**
  918. * 生成签名
  919. */
  920. function generateSign($userId){
  921. $wbappid = getFaceInfo()['appid'];
  922. $version = '1.0.0';
  923. $ticket = getApiTicket('SIGN')['tickets'][0]['value'];
  924. $nonce = get32Str();
  925. // $array = ['wbappid'=>$wbappid, 'userId'=>"$userId",'nonce'=>$nonce, 'version'=>$version, 'ticket'=>$ticket];
  926. $array = [$wbappid, "$userId",$nonce, $version, $ticket];
  927. file_put_contents("signLog.txt", json_encode($array) . "\n" . "\n", FILE_APPEND);
  928. sort($array);
  929. $str='';
  930. foreach ($array as $kk=>$vv){
  931. $str .=$vv;
  932. }
  933. // echo $str;die;
  934. $result = strtoupper(sha1($str));
  935. $res['sign'] = $result;
  936. $res['nonce'] = $nonce;
  937. $res['appid'] = $wbappid;
  938. return $res;
  939. }
  940. /**
  941. * 合作方后台上送身份信息
  942. */
  943. function getfaceid($name,$idNo,$userId){
  944. $webankAppId = getFaceInfo()['appid'];
  945. $orderNo = get32Str();
  946. $sign = generateSign($userId);
  947. $data = [
  948. 'webankAppId'=>$webankAppId,
  949. 'orderNo'=>$orderNo,
  950. 'name'=>$name,
  951. 'idNo'=>$idNo,
  952. 'userId'=>"$userId",
  953. 'version'=>'1.0.0',
  954. 'sign'=>$sign['sign'],
  955. 'nonce'=>$sign['nonce']
  956. ];
  957. $headers = [];
  958. array_push($headers, "Content-Type".":"."application/json; charset=UTF-8");
  959. $url = 'https://miniprogram-kyc.tencentcloudapi.com/api/server/getfaceid?orderNo='.$orderNo;
  960. $result = curlRequest($url,$headers,json_encode($data),'POST');
  961. $result = json_decode($result,true);
  962. if ($result['code']==0){
  963. $data = [
  964. 'appid'=>$sign['appid'],
  965. 'userID'=>"$userId",
  966. 'sign'=>$sign['sign'],
  967. 'nonce'=>$sign['nonce'],
  968. 'sdksign'=>SdkSign($userId,$sign['nonce']),
  969. 'result'=>$result['result'],
  970. ];
  971. return $data;
  972. }
  973. echo $result['msg'];die;
  974. }
  975. /**
  976. * 生成 SDK 接口调用步骤使用签名
  977. */
  978. function SdkSign($userId,$nonce){
  979. $wbappid = getFaceInfo()['appid'];
  980. $version = '1.0.0';
  981. $ticket = getApiTicket('NONCE',$userId)['tickets'][0]['value'];
  982. //$nonce = get32Str();
  983. $array = [$wbappid, "$userId",$nonce, $version, $ticket];
  984. file_put_contents("sdksignLog.txt", json_encode($array) . "\n" . "\n", FILE_APPEND);
  985. sort($array);
  986. $str='';
  987. foreach ($array as $kk=>$vv){
  988. $str .=$vv;
  989. }
  990. $result = strtoupper(sha1($str));
  991. return $result;
  992. }
  993. function getFaceInfo(){
  994. //正式
  995. $date = [
  996. 'appid'=>'IDAKcvCn',
  997. 'secret'=>'L1id3z5zROK8SVXg72ZyZXc8ziniYLKpOnIzN1gecrBaEMaKIlKrreyRGCLU2z4l'
  998. ];
  999. //测试
  1000. // $date = [
  1001. // 'appid'=>'TIDA3uGO',
  1002. // 'secret'=>'z41IysbEhRy5oR4Qs2kFfVkrufXIJMtsJOQ3eulkWwXwdKG772LSSiZsKKwfsv9n'
  1003. // ];
  1004. return $date;
  1005. }
  1006. //将数组转成uri字符串
  1007. function formatBizQueryParaMap($paraMap, $urlencode)
  1008. {
  1009. $buff = "";
  1010. ksort($paraMap);
  1011. foreach ($paraMap as $k => $v)
  1012. {
  1013. if($urlencode)
  1014. {
  1015. $v = urlencode($v);
  1016. }
  1017. // $buff .= strtolower($k) . "=" . $v . "&";
  1018. $buff .= $v;
  1019. }
  1020. if (strlen($buff) > 0)
  1021. {
  1022. $reqPar = substr($buff, 0, strlen($buff)-1);
  1023. }
  1024. return $reqPar;
  1025. }
  1026. /**
  1027. * 生成??位随机数
  1028. */
  1029. function get32Str($length='32'){
  1030. // $str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
  1031. $str = 'abcdefghijklmnopqrstuvwxyz0123456789';
  1032. $len = strlen($str)-1;
  1033. $randstr = '';
  1034. for ($i=0;$i<$length;$i++) {
  1035. $num=mt_rand(0,$len);
  1036. $randstr .= $str[$num];
  1037. }
  1038. return $randstr;
  1039. }
  1040. function get_order_sn(){
  1041. $order_id_main = date('YmdHis') . rand(10000000,99999999);
  1042. $order_id_len = strlen($order_id_main);
  1043. $order_id_sum = 0;
  1044. for($i=0; $i<$order_id_len; $i++){
  1045. $order_id_sum += (int)(substr($order_id_main,$i,1));
  1046. }
  1047. $osn = $order_id_main . str_pad((100 - $order_id_sum % 100) % 100,2,'0',STR_PAD_LEFT);
  1048. return $osn;
  1049. }
  1050. /**
  1051. * 生成二维码
  1052. */
  1053. function setqrcode($value,$name){
  1054. $dir = dirname(realpath(dirname($_SERVER['SCRIPT_FILENAME']))) . '/public/user';
  1055. if(!file_exists($dir)){
  1056. //检查是否有该文件夹,如果没有就创建,并给予最高权限
  1057. mkdir($dir, 0700,true);
  1058. }
  1059. $filename = $dir.'/'.$name.'.png';
  1060. QRcode::png($value,$filename,QR_ECLEVEL_L,7);
  1061. $storage_type = getConfigValue('storage_type');
  1062. if ($storage_type == 'oss'){
  1063. $ossClient = new OssClient(getConfigValue('storage_oss_keyid'), getConfigValue('storage_oss_secret'), getConfigValue('storage_oss_endpoint'));
  1064. $file_path = dirname($_SERVER['SCRIPT_FILENAME']) . "/user/".$name.".png";
  1065. $newName = date('Ymd').'/'.get_order_sn().'.png';
  1066. $result = $ossClient->uploadFile(getConfigValue('storage_oss_bucket'), $newName, $file_path);
  1067. $url = $result['info']['url'];
  1068. unlink($file_path);
  1069. }else{
  1070. $url = 'https://'.$_SERVER['SERVER_NAME']."/user/".$name.'.png';
  1071. }
  1072. return $url;
  1073. }
  1074. //生成邀请二维码
  1075. function setintivecode($user_id){
  1076. $name = $user_id."_".time();
  1077. $address = 'https://'.$_SERVER['SERVER_NAME'].'/web/h5/pages/mine/zhuce?invite_code='.$user_id;
  1078. $url = setqrcode($address,$name);
  1079. return $url;
  1080. }
  1081. //邀请地址
  1082. function getintiveaddress($user_id){
  1083. $address = 'https://'.$_SERVER['SERVER_NAME'].'/web/h5/pages/mine/zhuce?invite_code='.$user_id;
  1084. return $address;
  1085. }
  1086. /**
  1087. * @param $url
  1088. * @param array $headers
  1089. * @param array $body
  1090. * @param string $method
  1091. * @return bool|string
  1092. */
  1093. function curlRequest($url, $headers = [], $body = [], $method = "GET")
  1094. {
  1095. $ch = curl_init();
  1096. curl_setopt($ch, CURLOPT_URL, $url);
  1097. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);//设置请求头
  1098. curl_setopt($ch, CURLOPT_POSTFIELDS, $body);//设置请求体
  1099. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); //定义请求类型
  1100. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  1101. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  1102. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  1103. curl_setopt($ch, CURLOPT_HTTP_VERSION, 'CURL_HTTP_VERSION_1_1');
  1104. $output = curl_exec($ch);
  1105. curl_close($ch);
  1106. return $output;
  1107. }
  1108. /**
  1109. * 盲盒藏品库存和藏品状态判断
  1110. * @param $proArr
  1111. * @return int|string
  1112. */
  1113. function checkBox(){
  1114. $list = Db::name('store_blind_box')
  1115. ->where('status',1)
  1116. ->where('is_del',1)
  1117. ->field('id,is_prize,prize')
  1118. ->select();
  1119. foreach ($list as &$v){
  1120. if ($v['is_prize']==1){
  1121. $info = Db::name('store_collection')->where('id',$v['prize'])->find();
  1122. if ($info['now_inventory']<=0 || $info['status']==0 || $info['is_deleted']==1){
  1123. Db::name('store_blind_box')->where('id',$v['id'])->update(['status'=>0]);
  1124. }
  1125. }
  1126. }
  1127. }
  1128. //计算中奖概率
  1129. function get_rand($proArr) {
  1130. $result = '';
  1131. //概率数组的总概率精度
  1132. $proSum = array_sum($proArr);
  1133. // var_dump($proSum);
  1134. //概率数组循环
  1135. foreach ($proArr as $key => $proCur) {
  1136. $randNum = mt_rand(1, $proSum); //返回随机整数
  1137. if ($randNum <= $proCur) {
  1138. $result = $key;
  1139. break;
  1140. } else {
  1141. $proSum -= $proCur;
  1142. }
  1143. }
  1144. unset ($proArr);
  1145. return $result;
  1146. }
  1147. /**
  1148. * 调试函数
  1149. */
  1150. function debug($str){
  1151. $str = var_export($str,true).PHP_EOL;
  1152. $str.= date('Y-m-d H:i:s').' ';
  1153. $str.= $_SERVER['REMOTE_ADDR'].' ';
  1154. $str.= $_SERVER['REQUEST_METHOD'].': ';
  1155. // $str.=$_SERVER['HTTP_HOST'];
  1156. $str.= $_SERVER['REQUEST_URI'].''.PHP_EOL.PHP_EOL;
  1157. $str='<?php exit();?>'.PHP_EOL.$str;
  1158. error_log($str,3,"debug.log");
  1159. }
  1160. /**
  1161. * 获取链上ip
  1162. */
  1163. function getIpAddress(){
  1164. $address = 'http://39.105.159.207:8083/';
  1165. return $address;
  1166. }
  1167. /**
  1168. * 判断藏品是否已经购买
  1169. */
  1170. function getBuyCollection($mid,$c_id){
  1171. return Db::name('store_order_info')->where('mid',$mid)->where('c_id',$c_id)->where('status','neq',2)->where('resale_status',1)->count();
  1172. }
  1173. /**
  1174. * 判断会员购买藏品是否可以优先购
  1175. */
  1176. function getUserBuyCollection($data = []){
  1177. $ret = [];
  1178. //查询会员是否购买
  1179. /* if($data['first_cid'] > 0){
  1180. $buyNum = Db::name('store_order_info')->where('mid',$data['uid'])->where('c_id',$data['first_cid'])->where('status','neq',2)->where('resale_status',1)->count();
  1181. if($buyNum <= 0){
  1182. return $ret;
  1183. }
  1184. }*/
  1185. //查询会员是否在名单里
  1186. $firstList = Db::name('store_collection_first')->where('c_id',$data['c_id'])->where('uid',$data['uid'])->find();
  1187. if(empty($firstList)) return $data;
  1188. //获取用户已经购买数量
  1189. $userByCount = getByCount($data['uid'],$data['c_id']);
  1190. if($userByCount >= $firstList['num']) return 3;
  1191. //判断藏品是否未开售
  1192. if ($data['state'] == 2){
  1193. $sell_time = strtotime($data['sell_time'])-($data['first_time']*60);
  1194. if ($sell_time <= time()){
  1195. $ret['state'] = 1;
  1196. }
  1197. else {
  1198. $ret['state'] = $data['state'];
  1199. }
  1200. $ret['sell_time'] = date('Y-m-d H:i:s',$sell_time);
  1201. }else{
  1202. $ret['state'] = $data['state'];
  1203. $ret['sell_time'] = $data['sell_time'];
  1204. }
  1205. return $ret;
  1206. }
  1207. /**
  1208. * 用的预约状态
  1209. */
  1210. function getSalestatus($data=[]){
  1211. $user_status = Db::name('store_sale_log')
  1212. ->where(array('u_id'=>$data['uid'],'coll_id'=>$data['coll_id']))
  1213. ->field('status,is_win')->find();
  1214. return $user_status;
  1215. }
  1216. /**
  1217. * 盲盒藏品库存和藏品状态判断
  1218. * @param $proArr
  1219. * @return int|string
  1220. */
  1221. function checkBoxCollection($coll_id){
  1222. $list = Db::name('store_box')
  1223. ->where('status',1)
  1224. ->where('coll_id',$coll_id)
  1225. ->where('is_del',1)
  1226. ->field('id,is_prize,prize')
  1227. ->select();
  1228. foreach ($list as &$v){
  1229. if ($v['is_prize']==1){
  1230. $info = Db::name('store_collection')->where('id',$v['prize'])->find();
  1231. $now_inventory = getCollectionInventory($info['id']);
  1232. if ($now_inventory<=0 || $info['status']==0 || $info['is_deleted']==1){
  1233. Db::name('store_box')->where('id',$v['id'])->update(['status'=>0]);
  1234. }
  1235. }
  1236. }
  1237. }
  1238. function getSign($secret, $data)
  1239. {
  1240. if(isset($data['sign'])){
  1241. unset($data['sign']);
  1242. }
  1243. // 去空
  1244. $data = array_filter($data);
  1245. //签名步骤一:按字典序排序参数
  1246. ksort($data);
  1247. // var_dump($data);
  1248. $string_a = http_build_query($data);
  1249. $string_a = urldecode($string_a);
  1250. //签名步骤二:在string后加入mch_key
  1251. $string_sign_temp = $string_a . "&key=" . $secret;
  1252. // var_dump($string_sign_temp);
  1253. //签名步骤三:MD5加密
  1254. $sign = md5($string_sign_temp);
  1255. // 签名步骤四:所有字符转为大写
  1256. $result = strtoupper($sign);
  1257. // var_dump($result);
  1258. return $result;
  1259. }
  1260. /**
  1261. * @Note 验证签名
  1262. * @param $data
  1263. * @param $orderStatus
  1264. * @return bool
  1265. */
  1266. function verifySign($data, $secret) {
  1267. // 验证参数中是否有签名
  1268. if (!isset($data['sign']) || !$data['sign']) {
  1269. return false;
  1270. }
  1271. // 要验证的签名串
  1272. $sign = $data['sign'];
  1273. unset($data['sign']);
  1274. // 生成新的签名、验证传过来的签名
  1275. $sign2 = getSign($secret, $data);
  1276. return $sign2;
  1277. }