common.php 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830
  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 = "0077fde8e0474401b8e090b780da1a97";
  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 user_certification($id_card,$name){
  196. $host = "http://checkone.market.alicloudapi.com";
  197. $path = "/chinadatapay/1882";
  198. $method = "POST";
  199. $appcode = "30be8bdcc65842919980a8276ffc4995";
  200. $headers = array();
  201. array_push($headers, "Authorization:APPCODE " . $appcode);
  202. //根据API的要求,定义相对应的Content-Type
  203. array_push($headers, "Content-Type".":"."application/x-www-form-urlencoded; charset=UTF-8");
  204. $bodys = "idcard=".$id_card."&name=".$name;
  205. $url = $host . $path;
  206. $curl = curl_init();
  207. curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
  208. curl_setopt($curl, CURLOPT_URL, $url);
  209. curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
  210. curl_setopt($curl, CURLOPT_FAILONERROR, false);
  211. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  212. curl_setopt($curl, CURLOPT_HEADER, false);
  213. if (1 == strpos("$".$host, "https://"))
  214. {
  215. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  216. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  217. }
  218. curl_setopt($curl, CURLOPT_POSTFIELDS, $bodys);
  219. $res = curl_exec($curl);
  220. dump($res);die;
  221. if($res){
  222. $res = json_decode($res,true);
  223. if($res['data']['result'] == 1){
  224. return 1;
  225. }else{
  226. return 0;
  227. }
  228. }else{
  229. return 0;
  230. }
  231. }
  232. function idcardlingyu1($id_card,$name)
  233. {
  234. $data = array(
  235. 'appId' => 'QYeloNCb',
  236. 'appKey' => 'Q0PR2wle',
  237. 'name' => $name,
  238. 'idNum'=>$id_card
  239. );
  240. $data_string = json_encode($data,JSON_UNESCAPED_UNICODE);
  241. // $data_string = $data;
  242. $curl_con = curl_init();
  243. curl_setopt($curl_con, CURLOPT_URL,$url);
  244. curl_setopt($curl_con, CURLOPT_HEADER, false);
  245. curl_setopt($curl_con, CURLOPT_POST, true);
  246. curl_setopt($curl_con, CURLOPT_RETURNTRANSFER, TRUE);
  247. curl_setopt($curl_con, CURLOPT_CONNECTTIMEOUT, 5);
  248. curl_setopt($curl_con, CURLOPT_HTTPHEADER, array(
  249. 'Content-Type: application/json',
  250. 'Content-Length: ' . strlen($data_string))
  251. );
  252. curl_setopt($curl_con, CURLOPT_POSTFIELDS, $data_string);
  253. $res = curl_exec($curl_con);
  254. $status = curl_getinfo($curl_con);
  255. curl_close($curl_con);
  256. if (isset($status['http_code']) && $status['http_code'] == 200) {
  257. return $res;
  258. } else {
  259. return FALSE;
  260. }
  261. }
  262. function idcardlingyu($id_card,$name){
  263. $url = 'http://139.224.206.237:3333/user/api/id-card-auth';
  264. $header = array(
  265. 'Content-Type:application/x-www-form-urlencoded;boundary=ebf9f03029db4c2799ae16b5428b06bd1',
  266. );
  267. $data = array(
  268. 'appId' => 'QYeloNCb',
  269. 'appKey' => 'Q0PR2wle',
  270. 'name' => $name,
  271. 'idNum'=>$id_card
  272. );
  273. $ch = curl_init();
  274. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  275. curl_setopt($ch, CURLOPT_URL, $url);
  276. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  277. curl_setopt($ch, CURLOPT_POST, true);
  278. curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
  279. $sResult = curl_exec($ch);
  280. if($sError=curl_error($ch)){
  281. die($sError);
  282. }
  283. curl_close($ch);
  284. $res = json_decode($sResult,true);
  285. // dump($res);
  286. if (isset($res) && $res['code']=='200000'){
  287. return true;
  288. }
  289. return false;
  290. }
  291. //四要素
  292. function idcardlingyufour($id_card,$name,$bank_card,$bank_mobile){
  293. $url = 'http://139.224.206.237:3333/user/api/cardAuth';
  294. $header = array(
  295. 'Content-Type:application/x-www-form-urlencoded;boundary=ebf9f03029db4c2799ae16b5428b06bd1',
  296. );
  297. $data = array(
  298. 'appId' => 'QYeloNCb',
  299. 'appKey' => 'Q0PR2wle',
  300. 'name' => $name,
  301. 'idNum'=>$id_card,
  302. 'cardNo'=>$bank_card,
  303. 'mobile'=>$bank_mobile
  304. );
  305. $ch = curl_init();
  306. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  307. curl_setopt($ch, CURLOPT_URL, $url);
  308. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  309. curl_setopt($ch, CURLOPT_POST, true);
  310. curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
  311. $sResult = curl_exec($ch);
  312. if($sError=curl_error($ch)){
  313. die($sError);
  314. }
  315. curl_close($ch);
  316. $res = json_decode($sResult,true);
  317. //dump($res);die;
  318. $array['success'] = 0;
  319. if (isset($res) && $res['code']=='200000'){
  320. if (isset($res['data']['result']) && $res['data']['result']=='01'){
  321. $array['success']=1;
  322. $array['remark'] ='验证成功';
  323. }else{
  324. $array['remark'] = $res['data']['remark'];
  325. }
  326. }else{
  327. $array['remark'] ='认证失败';
  328. }
  329. return $array;
  330. }
  331. function shoucang(){
  332. $host = "http://180.76.141.31:8888/cz/call";
  333. $method = "POST";
  334. $headers = array();
  335. array_push($headers, "Content-Type".":"."application/json; charset=UTF-8");
  336. $bodys = array(
  337. 'key' => 'test2',
  338. 'userkey' => '12344',
  339. 'product' => json_encode(array('name'=>'test','count'=>7))
  340. );
  341. $curl = curl_init();
  342. curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
  343. curl_setopt($curl, CURLOPT_URL, $host);
  344. curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
  345. curl_setopt($curl, CURLOPT_FAILONERROR, false);
  346. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  347. curl_setopt($curl, CURLOPT_HEADER, false);
  348. if (1 == strpos("$".$host, "https://"))
  349. {
  350. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  351. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  352. }
  353. curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($bodys));
  354. $res = curl_exec($curl);
  355. var_dump($res);exit();
  356. }
  357. /**
  358. * 大师提前分钟数存入redis
  359. */
  360. function setAdvanceMinutes(){
  361. $redis = new \think\cache\driver\Redis();
  362. $value = Db::name('system_config')->where('name','advance_minutes')->value('value');
  363. $redis->set('advance_minutes',$value);
  364. }
  365. /**
  366. * 获取大师提前分钟数
  367. */
  368. function getAdvanceMinutes(){
  369. $redis = new \think\cache\driver\Redis();
  370. $value = $redis->get('advance_minutes');
  371. if (empty($value)){
  372. $value = Db::name('system_config')->where('name','advance_minutes')->value('value');
  373. $redis->set('advance_minutes',$value);
  374. }
  375. return $value;
  376. }
  377. /**
  378. * 获取自动取消分钟数
  379. */
  380. function getCancelTime(){
  381. return Db::name('system_config')->where('name','cancel_time')->value('value');
  382. }
  383. /**
  384. * 用户信息存入redis hash
  385. */
  386. function setMemberInfoHash($member_id){
  387. $info = Db::name('store_member')->where('id',$member_id)->find();
  388. $redis = new \think\cache\driver\Redis();
  389. $array = ['member'.$member_id=>json_encode($info)];
  390. $redis->hMSet('memberInfo',$array);
  391. }
  392. /**
  393. * redis获取用户信息
  394. */
  395. function getMemberInfoHash($member_id){
  396. $redis = new \think\cache\driver\Redis();
  397. $info = $redis->hGet('memberInfo','member'.$member_id);
  398. if (!$info){
  399. $info = Db::name('store_member')->where('id',$member_id)->find();
  400. $array = ['member'.$member_id=>json_encode($info)];
  401. $redis->hMSet('memberInfo',$array);
  402. }else{
  403. $info = json_decode($info,true);
  404. }
  405. return $info;
  406. }
  407. /**
  408. * 用户抢购卡数量存入redis 字符串
  409. */
  410. function setMembercard($member_id){
  411. $snap_card = Db::name('store_member')->where('id',$member_id)->value('snap_card');
  412. $redis = new \think\cache\driver\Redis();
  413. $redis->set('membercard_'.$member_id,$snap_card);
  414. }
  415. /**
  416. * 获取用户抢购卡数量
  417. */
  418. function getMembercard($member_id){
  419. $redis = new \think\cache\driver\Redis();
  420. $count = $redis->get('membercard_'.$member_id);
  421. if (empty($count)){
  422. $count = Db::name('store_member')->where('id',$member_id)->value('snap_card');
  423. $redis->set('membercard_'.$member_id,$count);
  424. }
  425. return $count;
  426. }
  427. /**
  428. * 减掉用户抢购卡数量(减1)
  429. */
  430. function loseMembercard($id){
  431. $redis = new \think\cache\driver\Redis();
  432. $redis->Decr('membercard_'.$id);
  433. }
  434. /**
  435. * 增加用户抢购卡数量(加1)
  436. */
  437. function addMembercard($id){
  438. $redis = new \think\cache\driver\Redis();
  439. $redis->Incr('membercard_'.$id);
  440. }
  441. /**
  442. * 获取藏品库存
  443. */
  444. function getCollectionInventory($id){
  445. $redis = new \think\cache\driver\Redis();
  446. $count = $redis->get('collection_count_'.$id);
  447. return $count ? $count : 0;
  448. }
  449. /**
  450. * 减掉藏品库存
  451. */
  452. function loseCollectionInventory($id,$num){
  453. $redis = new \think\cache\driver\Redis();
  454. $redis->Decrby('collection_count_'.$id,$num);
  455. }
  456. /**
  457. * 加藏品库存
  458. */
  459. function addCollectionInventory($id,$num){
  460. $redis = new \think\cache\driver\Redis();
  461. $redis->Incrby('collection_count_'.$id,$num);
  462. }
  463. /**
  464. * 用户购买藏品排名更新
  465. */
  466. function saveRanking($id){
  467. $redis = new \think\cache\driver\Redis();
  468. $redis->Incr('ranking'.$id);
  469. }
  470. /**
  471. * 获取用户购买藏品排名更新
  472. */
  473. function getRanking($id){
  474. $redis = new \think\cache\driver\Redis();
  475. $count = $redis->get('ranking'.$id);
  476. if (empty($count)){
  477. $redis->set('ranking'.$id,0);
  478. }
  479. $count = empty($count) ? 0 : $count;
  480. return $count;
  481. }
  482. /**
  483. * 藏品信息存入redis hash
  484. */
  485. function setCollectionInfoHash($id){
  486. $info = Db::name('store_collection')->where('id',$id)->find();
  487. $redis = new \think\cache\driver\Redis();
  488. $array = ['collection'.$id=>json_encode($info)];
  489. $redis->hMSet('collectionInfo',$array);
  490. }
  491. /**
  492. * 获取用户购买数量
  493. */
  494. function getByCount($mid,$id){
  495. $redis = new \think\cache\driver\Redis();
  496. $count = $redis->get('UserByCount_'.$mid.$id);
  497. if (empty($count) && $count!=0){
  498. // $count = Db::name('store_order')
  499. // ->where('mid',$mid)
  500. // ->where('c_id',$id)
  501. // ->whereIn('status','0,1')
  502. // ->sum('num');
  503. // $count = $count ? $count : 0;
  504. $count = 0;
  505. $redis->Incrby('UserByCount_'.$mid.$id,$count);
  506. }
  507. return $count;
  508. }
  509. /**
  510. * 用户购买数量增加
  511. */
  512. function IncrByCount($mid,$id,$number){
  513. $redis = new \think\cache\driver\Redis();
  514. $redis->Incrby('UserByCount_'.$mid.$id,$number);
  515. }
  516. /**
  517. * 用户购买数量减少
  518. */
  519. function DecrByCount($mid,$id,$number){
  520. $redis = new \think\cache\driver\Redis();
  521. $redis->Decrby('UserByCount_'.$mid.$id,$number);
  522. }
  523. /**
  524. * 获取藏品hash redis长度
  525. */
  526. function getLenCollection($id){
  527. $redis = new \think\cache\driver\Redis();
  528. $count = $redis->Llen('collectionHash_'.$id);
  529. if (!$count){
  530. $count = Db::name('hash')
  531. ->where('goods_id',$id)
  532. ->where('status',0)
  533. ->count();
  534. }
  535. return $count;
  536. }
  537. /**
  538. * 获取藏品信息
  539. */
  540. function getCollectionInfoHash($id)
  541. {
  542. $redis = new \think\cache\driver\Redis();
  543. $info = $redis->hGet('collectionInfo','collection'.$id);
  544. if (!$info){
  545. $info = Db::name('store_collection')->where('id',$id)->find();
  546. $array = ['collection'.$id=>json_encode($info)];
  547. $redis->hMSet('collectionInfo',$array);
  548. }else{
  549. $info = json_decode($info,true);
  550. }
  551. return $info;
  552. }
  553. /**
  554. * 收集下单用户id
  555. */
  556. function setCollectionBuyUser($mid){
  557. $redis = new \think\cache\driver\Redis();
  558. $array = [$mid=>1];
  559. $redis->hMSet('buyUserInfo',$array);
  560. }
  561. /*
  562. * 微信支付账户
  563. */
  564. function retrunWxConfig(){
  565. $config = [
  566. 'app_id' => 'wxa6980453638c9c78',
  567. 'mch_id' =>'1623128602',
  568. 'key' =>'qwertyuiopASDFGHJKLZXCVBNM123456',
  569. ];
  570. return $config;
  571. }
  572. /**
  573. * 获取离线账户
  574. */
  575. function getOfflineAccount(){
  576. $url = 'http://192.144.219.204:8083/ddc/createAccount';
  577. return file_get_contents($url);
  578. }
  579. /**
  580. * 获取链账户
  581. */
  582. function getWalletAddress($phone){
  583. $url = 'http://39.107.12.194:8088/register?accountName='.$phone;
  584. $res=curlRequest($url);
  585. if ($res){
  586. $res = json_decode($res,true);
  587. if ($res['code']=='200'){
  588. return $res['result']['userAddressStr'];
  589. }
  590. }
  591. return false;
  592. }
  593. /**
  594. * 获取公司生成的hash
  595. */
  596. function getCompanyHash($id){
  597. $redis = new \think\cache\driver\Redis();
  598. $hash = $redis->lPop('collectionHash_'.$id);
  599. if (!$hash){
  600. $hash = Db::name('hash')->where('goods_id',$id)
  601. ->where('status',0)
  602. ->order('id asc')
  603. ->field('hash,create_at')
  604. ->limit(1)
  605. ->find();
  606. }else{
  607. $hash = json_decode($hash,true);
  608. }
  609. return $hash;
  610. }
  611. /**
  612. * 获取排名
  613. */
  614. function getTag($id,$now,$num){
  615. $len = strlen($num);
  616. $re = getConfigValue('tag_prefix').$id.'#';
  617. switch ($len){
  618. case 1:
  619. $re = $re.'0'.$now;
  620. break;
  621. case 2:
  622. if ($now<10){
  623. $re = $re.'0'.$now;
  624. }else{
  625. $re = $re.$now;
  626. }
  627. break;
  628. case 3:
  629. if ($now<10){
  630. $re = $re.'00'.$now;
  631. }elseif ($now>=10 && $now<100){
  632. $re = $re.'0'.$now;
  633. }else{
  634. $re = $re.$now;
  635. }
  636. break;
  637. case 4:
  638. if ($now<10){
  639. $re = $re.'000'.$now;
  640. }elseif ($now>=10 && $now<100){
  641. $re = $re.'00'.$now;
  642. }elseif ($now>=100 && $now<1000){
  643. $re = $re.'0'.$now;
  644. }else{
  645. $re = $re.$now;
  646. }
  647. break;
  648. case 5:
  649. if ($now<10){
  650. $re = $re.'0000'.$now;
  651. }elseif ($now>=10 && $now<100){
  652. $re = $re.'000'.$now;
  653. }elseif ($now>=100 && $now<1000){
  654. $re = $re.'00'.$now;
  655. }elseif ($now>=1000 && $now<10000){
  656. $re = $re.'0'.$now;
  657. }else{
  658. $re = $re.$now;
  659. }
  660. break;
  661. case 6:
  662. if ($now<10){
  663. $re = $re.'00000'.$now;
  664. }elseif ($now>=10 && $now<100){
  665. $re = $re.'0000'.$now;
  666. }elseif ($now>=100 && $now<1000){
  667. $re = $re.'000'.$now;
  668. }elseif ($now>=1000 && $now<10000){
  669. $re = $re.'00'.$now;
  670. }elseif ($now>=10000 && $now<100000){
  671. $re = $re.'0'.$now;
  672. }else{
  673. $re = $re.$now;
  674. }
  675. break;
  676. case 7:
  677. if ($now<10){
  678. $re = $re.'000000'.$now;
  679. }elseif ($now>=10 && $now<100){
  680. $re = $re.'00000'.$now;
  681. }elseif ($now>=100 && $now<1000){
  682. $re = $re.'0000'.$now;
  683. }elseif ($now>=1000 && $now<10000){
  684. $re = $re.'000'.$now;
  685. }elseif ($now>=10000 && $now<100000){
  686. $re = $re.'00'.$now;
  687. }elseif ($now>=100000 && $now<1000000){
  688. $re = $re.'0'.$now;
  689. }else{
  690. $re = $re.$now;
  691. }
  692. break;
  693. }
  694. $re = $re.'/'.$num;
  695. return $re;
  696. }
  697. /**
  698. * 判断藏品是否设置过提醒
  699. */
  700. function getRemind($mid,$c_id){
  701. return Db::name('store_collection_remind')->where('mid',$mid)->where('c_id',$c_id)->count();
  702. }
  703. /**
  704. * 变更会员积分等
  705. * @param int $money 余额
  706. * @param int $user_id 会员ID
  707. * @param string $memo 备注
  708. */
  709. function memberMoneyChange($num, $type , $m_id, $title, $pm = 0,$link_id=0)
  710. {
  711. $member = Db::name('store_member')->where('id',$m_id)->find();
  712. switch ($type){
  713. case 1: //积分
  714. $before = $member['integral'];
  715. if ($pm==1)
  716. $after = $member['integral']+$num;
  717. else
  718. $after = $member['integral']-$num;
  719. $update_data = ['integral'=>$after];
  720. break;
  721. case 2: //抢购卡
  722. $before = $member['snap_card'];
  723. if ($pm==1)
  724. $after = $member['snap_card']+$num;
  725. else
  726. $after = $member['snap_card']-$num;
  727. $update_data = ['snap_card'=>$after];
  728. break;
  729. case 3: //余额
  730. $before = $member['money'];
  731. if ($pm==1)
  732. $after = $member['money']+$num;
  733. else
  734. $after = $member['money']-$num;
  735. $update_data = ['money'=>$after];
  736. break;
  737. }
  738. Db::startTrans();
  739. try {
  740. Db::name('store_member')->where('id',$m_id)->update($update_data);
  741. $data = [
  742. 'm_id'=>$m_id,
  743. 'type'=>$type,
  744. 'pm'=>$pm,
  745. 'title'=>$title,
  746. 'change'=>$num,
  747. 'before'=>$before,
  748. 'after'=>$after,
  749. 'link_id'=>$link_id
  750. ];
  751. Db::name('store_member_log')->insert($data);
  752. Db::commit();
  753. return true;
  754. }catch (\Exception $e){
  755. Db::rollback();
  756. return false;
  757. }
  758. }
  759. /**
  760. * 获取单个系统配置信息
  761. */
  762. function getConfigValue($name){
  763. return Db::name('system_config')->where('name',$name)->value('value');
  764. }
  765. /**
  766. * 判断藏品状态
  767. */
  768. function checkCollectionState($id=''){
  769. if ($id){
  770. $info = Db::name('store_collection')->where('id',$id)->find();
  771. $now_inventory = getCollectionInventory($id);
  772. if (!empty($v['endtime']) && strtotime($info['endtime'])<time()){
  773. Db::name('store_collection')->where('id',$info['id'])->update(['state'=>4]);
  774. }else{
  775. if ($info['state']==1){
  776. if ($now_inventory<=0){
  777. // Db::name('store_collection')->where('id',$info['id'])->update(['state'=>3]);
  778. }
  779. }else if($info['state']==2){
  780. if (strtotime($info['sell_time'])<=time()){
  781. Db::name('store_collection')->where('id',$info['id'])->update(['state'=>1]);
  782. }
  783. }else if($info['state']==3){
  784. if ($now_inventory>0){
  785. Db::name('store_collection')->where('id',$info['id'])->update(['state'=>1]);
  786. }
  787. }else if($info['state']==4){
  788. if ($now_inventory>0){
  789. Db::name('store_collection')->where('id',$info['id'])->update(['state'=>1]);
  790. }elseif (strtotime($info['sell_time'])<=time()){
  791. Db::name('store_collection')->where('id',$info['id'])->update(['state'=>1]);
  792. }elseif ($now_inventory<=0){
  793. //Db::name('store_collection')->where('id',$info['id'])->update(['state'=>3]);
  794. }
  795. }
  796. }
  797. setCollectionInfoHash($id);
  798. }else{
  799. $list = Db::name('store_collection')
  800. ->whereIn('state','1,2,3,4')
  801. ->where('status',1)
  802. ->where('is_deleted',0)
  803. ->select();
  804. foreach ($list as &$v){
  805. $now_inventory = getCollectionInventory($v['id']);
  806. if (!empty($v['endtime']) && strtotime($v['endtime'])<time()){
  807. Db::name('store_collection')->where('id',$v['id'])->update(['state'=>4]);
  808. }else{
  809. if ($v['state']==1){
  810. if ($now_inventory<=0){
  811. // Db::name('store_collection')->where('id',$v['id'])->update(['state'=>3]);
  812. }
  813. }elseif ($v['state']==2){
  814. if (strtotime($v['sell_time'])<=time()){
  815. Db::name('store_collection')->where('id',$v['id'])->update(['state'=>1]);
  816. }
  817. }elseif ($v['state']==3){
  818. if ($now_inventory>0){
  819. Db::name('store_collection')->where('id',$v['id'])->update(['state'=>1]);
  820. }
  821. }else if($v['state']==4){
  822. if ($now_inventory>0){
  823. Db::name('store_collection')->where('id',$v['id'])->update(['state'=>1]);
  824. }elseif (strtotime($v['sell_time'])<=time()){
  825. Db::name('store_collection')->where('id',$v['id'])->update(['state'=>1]);
  826. }elseif ($now_inventory<=0){
  827. // Db::name('store_collection')->where('id',$v['id'])->update(['state'=>3]);
  828. }
  829. }
  830. }
  831. setCollectionInfoHash($v['id']);
  832. }
  833. }
  834. }
  835. /**
  836. * 判断藏品状态
  837. */
  838. function checkSynCollectionState($id=''){
  839. if ($id){
  840. $info = Db::name('store_collection')->where('id',$id)->find();
  841. $now_inventory = getCollectionInventory($id);
  842. if ($info['sy_state']==1){
  843. if ($now_inventory<=0){
  844. Db::name('store_collection')->where('id',$info['id'])->update(['sy_state'=>4]);
  845. }elseif(strtotime($info['end_time'])<time()){
  846. Db::name('store_collection')->where('id',$info['id'])->update(['sy_state'=>3]);
  847. }
  848. }elseif ($info['sy_state']==2){
  849. if (strtotime($info['sell_time'])<=time()){
  850. Db::name('store_collection')->where('id',$info['id'])->update(['sy_state'=>1]);
  851. }elseif ($now_inventory<=0){
  852. Db::name('store_collection')->where('id',$info['id'])->update(['sy_state'=>4]);
  853. }
  854. }
  855. }else{
  856. $list = Db::name('store_collection')
  857. ->where('type',2)
  858. ->whereIn('sy_state','1,2')
  859. ->where('is_deleted',0)
  860. ->select();
  861. foreach ($list as &$v){
  862. $now_inventory = getCollectionInventory($v['id']);
  863. if ($v['sy_state']==1){
  864. if ($now_inventory<=0){
  865. Db::name('store_collection')->where('id',$v['id'])->update(['sy_state'=>4]);
  866. }elseif(strtotime($v['end_time'])<time()){
  867. Db::name('store_collection')->where('id',$v['id'])->update(['sy_state'=>3]);
  868. }
  869. }elseif ($v['sy_state']==2){
  870. if (strtotime($v['sell_time'])<=time()){
  871. Db::name('store_collection')->where('id',$v['id'])->update(['sy_state'=>1]);
  872. }elseif ($now_inventory<=0){
  873. Db::name('store_collection')->where('id',$v['id'])->update(['sy_state'=>4]);
  874. }
  875. }
  876. }
  877. }
  878. }
  879. /**
  880. * redis加锁
  881. */
  882. function redisSetNx($key,$exptime){
  883. $redis = new \think\cache\driver\Redis(['select'=>2]);
  884. $is_lock = $redis->setnx($key,time()+$exptime);
  885. if ($is_lock){
  886. return true;
  887. }else{
  888. //加锁失败的情况下,判断锁是否已经存在,如果存在切已经过期,删除锁,重新加锁
  889. $val = $redis->get($key);
  890. if ($val && $val<time()){
  891. $redis->del($key);
  892. }
  893. return $redis->setnx($key,time()+$exptime);
  894. }
  895. }
  896. /**
  897. * 删除锁
  898. */
  899. function DelRedisSetNx($key){
  900. $redis = new \think\cache\driver\Redis(['select'=>2]);
  901. $redis->del($key);
  902. }
  903. /**
  904. * 盲盒信息存入redis hash
  905. */
  906. function setBoxInfoHash($id){
  907. $info = Db::name('store_collection')->where('id',$id)->find();
  908. $redis = new \think\cache\driver\Redis();
  909. $array = ['collection'.$id=>json_encode($info)];
  910. $redis->hMSet('collectionInfo',$array);
  911. }
  912. /**
  913. * 获取0的数量
  914. */
  915. function get0number($n){
  916. if ($n==1){
  917. return '00000000000';
  918. }elseif ($n==2){
  919. return '0000000000';
  920. }elseif ($n==3){
  921. return '000000000';
  922. }elseif ($n==4){
  923. return '00000000';
  924. }elseif ($n==5){
  925. return '0000000';
  926. }elseif ($n==6){
  927. return '000000';
  928. }elseif ($n==7){
  929. return '00000';
  930. }elseif ($n==8){
  931. return '0000';
  932. }elseif ($n==9){
  933. return '000';
  934. }elseif ($n==10){
  935. return '00';
  936. }elseif ($n==11){
  937. return '0';
  938. }
  939. }
  940. /***********************************************人脸识别*****************************************************************/
  941. /**
  942. * 获取accesstoken
  943. * @return mixed
  944. */
  945. function getAccessToken(){
  946. $appid_id =getFaceInfo()['appid'];
  947. $secret = getFaceInfo()['secret'];
  948. $grant_type = 'client_credential';
  949. $version = '1.0.0';
  950. $url = "https://miniprogram-kyc.tencentcloudapi.com/api/oauth2/access_token?app_id=".$appid_id."&secret=".$secret."&grant_type=".$grant_type."&version=".$version;
  951. $result = curlRequest($url);
  952. $result = json_decode($result,true);
  953. if ($result['code']==0){
  954. return $result;
  955. }
  956. echo $result['msg'];die;
  957. }
  958. /**
  959. * 获取api_ticket
  960. */
  961. function getApiTicket($type,$userId=''){
  962. $appid_id =getFaceInfo()['appid'];
  963. $access_token = getAccessToken()['access_token'];
  964. $version = '1.0.0';
  965. $url = "https://miniprogram-kyc.tencentcloudapi.com/api/oauth2/api_ticket?app_id=".$appid_id."&access_token=".$access_token."&type=".$type."&version=".$version;
  966. if ($type=='NONCE'){
  967. $url .= "&user_id=".$userId;
  968. }
  969. $result = curlRequest($url);
  970. $result = json_decode($result,true);
  971. if ($result['code']==0){
  972. return $result;
  973. }
  974. echo $result['msg'];die;
  975. }
  976. /**
  977. * 生成签名
  978. */
  979. function generateSign($userId){
  980. $wbappid = getFaceInfo()['appid'];
  981. $version = '1.0.0';
  982. $ticket = getApiTicket('SIGN')['tickets'][0]['value'];
  983. $nonce = get32Str();
  984. // $array = ['wbappid'=>$wbappid, 'userId'=>"$userId",'nonce'=>$nonce, 'version'=>$version, 'ticket'=>$ticket];
  985. $array = [$wbappid, "$userId",$nonce, $version, $ticket];
  986. file_put_contents("signLog.txt", json_encode($array) . "\n" . "\n", FILE_APPEND);
  987. sort($array);
  988. $str='';
  989. foreach ($array as $kk=>$vv){
  990. $str .=$vv;
  991. }
  992. // echo $str;die;
  993. $result = strtoupper(sha1($str));
  994. $res['sign'] = $result;
  995. $res['nonce'] = $nonce;
  996. $res['appid'] = $wbappid;
  997. return $res;
  998. }
  999. /**
  1000. * 合作方后台上送身份信息
  1001. */
  1002. function getfaceid($name,$idNo,$userId){
  1003. $webankAppId = getFaceInfo()['appid'];
  1004. $orderNo = get32Str();
  1005. $sign = generateSign($userId);
  1006. $data = [
  1007. 'webankAppId'=>$webankAppId,
  1008. 'orderNo'=>$orderNo,
  1009. 'name'=>$name,
  1010. 'idNo'=>$idNo,
  1011. 'userId'=>"$userId",
  1012. 'version'=>'1.0.0',
  1013. 'sign'=>$sign['sign'],
  1014. 'nonce'=>$sign['nonce']
  1015. ];
  1016. $headers = [];
  1017. array_push($headers, "Content-Type".":"."application/json; charset=UTF-8");
  1018. $url = 'https://miniprogram-kyc.tencentcloudapi.com/api/server/getfaceid?orderNo='.$orderNo;
  1019. $result = curlRequest($url,$headers,json_encode($data),'POST');
  1020. $result = json_decode($result,true);
  1021. if ($result['code']==0){
  1022. $data = [
  1023. 'appid'=>$sign['appid'],
  1024. 'userID'=>"$userId",
  1025. 'sign'=>$sign['sign'],
  1026. 'nonce'=>$sign['nonce'],
  1027. 'sdksign'=>SdkSign($userId,$sign['nonce']),
  1028. 'result'=>$result['result'],
  1029. ];
  1030. return $data;
  1031. }
  1032. echo $result['msg'];die;
  1033. }
  1034. /**
  1035. * 生成 SDK 接口调用步骤使用签名
  1036. */
  1037. function SdkSign($userId,$nonce){
  1038. $wbappid = getFaceInfo()['appid'];
  1039. $version = '1.0.0';
  1040. $ticket = getApiTicket('NONCE',$userId)['tickets'][0]['value'];
  1041. //$nonce = get32Str();
  1042. $array = [$wbappid, "$userId",$nonce, $version, $ticket];
  1043. file_put_contents("sdksignLog.txt", json_encode($array) . "\n" . "\n", FILE_APPEND);
  1044. sort($array);
  1045. $str='';
  1046. foreach ($array as $kk=>$vv){
  1047. $str .=$vv;
  1048. }
  1049. $result = strtoupper(sha1($str));
  1050. return $result;
  1051. }
  1052. function getFaceInfo(){
  1053. //正式
  1054. $date = [
  1055. 'appid'=>'IDAKcvCn',
  1056. 'secret'=>'L1id3z5zROK8SVXg72ZyZXc8ziniYLKpOnIzN1gecrBaEMaKIlKrreyRGCLU2z4l'
  1057. ];
  1058. //测试
  1059. // $date = [
  1060. // 'appid'=>'TIDA3uGO',
  1061. // 'secret'=>'z41IysbEhRy5oR4Qs2kFfVkrufXIJMtsJOQ3eulkWwXwdKG772LSSiZsKKwfsv9n'
  1062. // ];
  1063. return $date;
  1064. }
  1065. //将数组转成uri字符串
  1066. function formatBizQueryParaMap($paraMap, $urlencode)
  1067. {
  1068. $buff = "";
  1069. ksort($paraMap);
  1070. foreach ($paraMap as $k => $v)
  1071. {
  1072. if($urlencode)
  1073. {
  1074. $v = urlencode($v);
  1075. }
  1076. // $buff .= strtolower($k) . "=" . $v . "&";
  1077. $buff .= $v;
  1078. }
  1079. if (strlen($buff) > 0)
  1080. {
  1081. $reqPar = substr($buff, 0, strlen($buff)-1);
  1082. }
  1083. return $reqPar;
  1084. }
  1085. /**
  1086. * 生成32位随机数
  1087. */
  1088. function get32Str($length='32'){
  1089. $str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
  1090. $len = strlen($str)-1;
  1091. $randstr = '';
  1092. for ($i=0;$i<$length;$i++) {
  1093. $num=mt_rand(0,$len);
  1094. $randstr .= $str[$num];
  1095. }
  1096. return $randstr;
  1097. }
  1098. /**
  1099. * 盲盒藏品库存和藏品状态判断
  1100. * @param $proArr
  1101. * @return int|string
  1102. */
  1103. function checkBoxCollection($coll_id){
  1104. $list = Db::name('store_box')
  1105. ->where('status',1)
  1106. ->where('coll_id',$coll_id)
  1107. ->where('is_del',1)
  1108. ->field('id,is_prize,prize')
  1109. ->select();
  1110. foreach ($list as &$v){
  1111. if ($v['is_prize']==1){
  1112. $info = Db::name('store_collection')->where('id',$v['prize'])->find();
  1113. $now_inventory = getCollectionInventory($info['id']);
  1114. if ($now_inventory<=0 || $info['status']==0 || $info['is_deleted']==1){
  1115. Db::name('store_box')->where('id',$v['id'])->update(['status'=>0]);
  1116. }
  1117. }
  1118. }
  1119. }
  1120. function get_order_sn(){
  1121. $order_id_main = date('YmdHis') . rand(10000000,99999999);
  1122. $order_id_len = strlen($order_id_main);
  1123. $order_id_sum = 0;
  1124. for($i=0; $i<$order_id_len; $i++){
  1125. $order_id_sum += (int)(substr($order_id_main,$i,1));
  1126. }
  1127. $osn = $order_id_main . str_pad((100 - $order_id_sum % 100) % 100,2,'0',STR_PAD_LEFT);
  1128. return $osn;
  1129. }
  1130. /**
  1131. * 生成二维码
  1132. */
  1133. function setqrcode($value,$name){
  1134. $dir = dirname(realpath(dirname($_SERVER['SCRIPT_FILENAME']))) . '/public/user';
  1135. if(!file_exists($dir)){
  1136. //检查是否有该文件夹,如果没有就创建,并给予最高权限
  1137. mkdir($dir, 0700,true);
  1138. }
  1139. $filename = $dir.'/'.$name.'.png';
  1140. QRcode::png($value,$filename,QR_ECLEVEL_L,7);
  1141. $storage_type = getConfigValue('storage_type');
  1142. if ($storage_type == 'oss'){
  1143. $ossClient = new OssClient(getConfigValue('storage_oss_keyid'), getConfigValue('storage_oss_secret'), getConfigValue('storage_oss_endpoint'));
  1144. $file_path = dirname($_SERVER['SCRIPT_FILENAME']) . "/user/".$name.".png";
  1145. $newName = date('Ymd').'/'.get_order_sn().'.png';
  1146. $result = $ossClient->uploadFile(getConfigValue('storage_oss_bucket'), $newName, $file_path);
  1147. $url = $result['info']['url'];
  1148. unlink($file_path);
  1149. }else{
  1150. $url = 'http://'.$_SERVER['SERVER_NAME']."/user/".$name.'.png';
  1151. }
  1152. return $url;
  1153. }
  1154. //生成邀请二维码
  1155. function setintivecode($user_id){
  1156. $name = $user_id."_".time();
  1157. $address = 'https://'.$_SERVER['SERVER_NAME'].'/pages/mine/zhuce?invite_code='.$user_id;
  1158. $url = setqrcode($address,$name);
  1159. return $url;
  1160. }
  1161. //邀请地址
  1162. function getintiveaddress($user_id){
  1163. $address = 'https://'.$_SERVER['SERVER_NAME'].'/pages/mine/zhuce?invite_code='.$user_id;
  1164. return $address;
  1165. }
  1166. /**
  1167. * @param $url
  1168. * @param array $headers
  1169. * @param array $body
  1170. * @param string $method
  1171. * @return bool|string
  1172. */
  1173. function curlRequest($url, $headers = [], $body = [], $method = "GET")
  1174. {
  1175. $ch = curl_init();
  1176. curl_setopt($ch, CURLOPT_URL, $url);
  1177. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);//设置请求头
  1178. curl_setopt($ch, CURLOPT_POSTFIELDS, $body);//设置请求体
  1179. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); //定义请求类型
  1180. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  1181. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  1182. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  1183. curl_setopt($ch, CURLOPT_HTTP_VERSION, 'CURL_HTTP_VERSION_1_1');
  1184. $output = curl_exec($ch);
  1185. curl_close($ch);
  1186. return $output;
  1187. }
  1188. /**
  1189. * 盲盒藏品库存和藏品状态判断
  1190. * @param $proArr
  1191. * @return int|string
  1192. */
  1193. function checkBox(){
  1194. $list = Db::name('store_blind_box')
  1195. ->where('status',1)
  1196. ->where('is_del',1)
  1197. ->field('id,is_prize,prize')
  1198. ->select();
  1199. foreach ($list as &$v){
  1200. if ($v['is_prize']==1){
  1201. $info = Db::name('store_collection')->where('id',$v['prize'])->find();
  1202. if ($info['now_inventory']<=0 || $info['status']==0 || $info['is_deleted']==1){
  1203. Db::name('store_blind_box')->where('id',$v['id'])->update(['status'=>0]);
  1204. }
  1205. }
  1206. }
  1207. }
  1208. //计算中奖概率
  1209. function get_rand($proArr) {
  1210. $result = '';
  1211. //概率数组的总概率精度
  1212. $proSum = array_sum($proArr);
  1213. // var_dump($proSum);
  1214. //概率数组循环
  1215. foreach ($proArr as $key => $proCur) {
  1216. $randNum = mt_rand(1, $proSum); //返回随机整数
  1217. if ($randNum <= $proCur) {
  1218. $result = $key;
  1219. break;
  1220. } else {
  1221. $proSum -= $proCur;
  1222. }
  1223. }
  1224. unset ($proArr);
  1225. return $result;
  1226. }
  1227. /**
  1228. * 获取链上ip
  1229. */
  1230. function getIpAddress(){
  1231. $address = 'http://120.27.21.5:8083/';
  1232. return $address;
  1233. }
  1234. /**
  1235. * 调试函数
  1236. */
  1237. function debug($str){
  1238. $str = var_export($str,true).PHP_EOL;
  1239. $str.= date('Y-m-d H:i:s').' ';
  1240. $str.= $_SERVER['REMOTE_ADDR'].' ';
  1241. $str.= $_SERVER['REQUEST_METHOD'].': ';
  1242. // $str.=$_SERVER['HTTP_HOST'];
  1243. $str.= $_SERVER['REQUEST_URI'].''.PHP_EOL.PHP_EOL;
  1244. $str='<?php exit();?>'.PHP_EOL.$str;
  1245. error_log($str,3,"debug.log");
  1246. }
  1247. function getAge($id){
  1248. # 1.从身份证中获取出生日期
  1249. $id = $id;//身份证
  1250. $birth_Date = strtotime(substr($id, 6, 8));//截取日期并转为时间戳
  1251. # 2.格式化[出生日期]
  1252. $Year = date('Y', $birth_Date);//yyyy
  1253. $Month = date('m', $birth_Date);//mm
  1254. $Day = date('d', $birth_Date);//dd
  1255. # 3.格式化[当前日期]
  1256. $current_Y = date('Y');//yyyy
  1257. $current_M = date('m');//mm
  1258. $current_D = date('d');//dd
  1259. # 4.计算年龄()
  1260. $age = $current_Y - $Year;//今年减去生日年
  1261. if($Month > $current_M || $Month == $current_M && $Day > $current_D){//深层判断(日)
  1262. $age--;//如果出生月大于当前月或出生月等于当前月但出生日大于当前日则减一岁
  1263. }
  1264. # 返回
  1265. return $age;
  1266. }
  1267. /**
  1268. * 金额校验函数
  1269. * @param $value
  1270. * @param bool $isZero
  1271. * @param bool $negative
  1272. * @return bool
  1273. */
  1274. function isAmount($value, $isZero=false, $negative=false){
  1275. // 必须是整数或浮点数,且允许为负
  1276. if (!preg_match("/^[-]?\d+(.\d{1,2})?$/", $value)){
  1277. return false;
  1278. }
  1279. // 不为 0
  1280. if (!$isZero && empty((int)($value*100))){
  1281. return false;
  1282. }
  1283. // 不为负数
  1284. if (!$negative && (int)($value * 100) < 0){
  1285. return false;
  1286. }
  1287. return true;
  1288. }
  1289. //注册邀请奖励
  1290. function pull_new($mid){
  1291. checkactivity();
  1292. //判断有没有正在进行的活动
  1293. $act = Db::name('store_activity')
  1294. ->where('is_del',1)
  1295. ->where('state',1)
  1296. ->where('status',2)
  1297. ->find();
  1298. if ($act){
  1299. $user1 = getMemberInfoHash($mid); //获取用户信息
  1300. if ($user1['pid']){
  1301. //先判断有没有单人拉新奖励活动
  1302. $info = Db::name('store_activities')
  1303. ->where('ac_id',$act['id'])
  1304. ->where('is_del',1)
  1305. ->where('type',2)
  1306. ->where('state',1)
  1307. ->find();
  1308. if ($info){
  1309. $pro_info = getCollectionInfoHash($info['c_id2']);
  1310. $now_inventory = getCollectionInventory($info['c_id2']);
  1311. if ($now_inventory>0){
  1312. $is_nft = Db::name('hash2')->where('goods_id',$info['c_id2'])->find();
  1313. if (!$is_nft || !$is_nft['success']){
  1314. }else{
  1315. //获取排名
  1316. $rank = getRanking($info['c_id2'])+1;
  1317. $tag = getTag($info['c_id2'],$rank,$pro_info['inventory']);
  1318. saveRanking($info['c_id2']);
  1319. $collectors_hash = '';
  1320. $date = [
  1321. 'order_no'=>get_order_sn(),
  1322. 'tag'=>$tag,
  1323. 'mid'=>$mid,
  1324. 'c_id'=>$info['c_id2'],
  1325. 'name'=>$pro_info['name'],
  1326. 'cover'=>$pro_info['cover'],
  1327. 'pro_info'=>json_encode($pro_info,true),
  1328. 'type'=>$pro_info['type'],
  1329. 'tokenid'=>$is_nft['class_id'],
  1330. 'nfttype'=>$is_nft['operationId'],
  1331. 'collectors_hash'=>$collectors_hash,
  1332. 'remark'=>'新人被邀请奖励'
  1333. ];
  1334. if (Db::name('store_order_info')->insert($date)){
  1335. loseCollectionInventory($info['c_id2'],1);
  1336. }
  1337. }
  1338. }
  1339. }
  1340. //判断邀请人邀请的人数
  1341. $count = Db::name('store_activities_invite_log')
  1342. ->where('mid',$user1['pid'])
  1343. ->where('create_at','egt',$act['start_at'])
  1344. ->where('create_at','elt',$act['end_at'])
  1345. ->count();
  1346. if ($count){
  1347. if ($count==1){
  1348. if ($info){
  1349. $pro_info = getCollectionInfoHash($info['c_id']);
  1350. $now_inventory = getCollectionInventory($info['c_id']);
  1351. if ($now_inventory>0){
  1352. $is_nft = Db::name('hash2')->where('goods_id',$info['c_id'])->find();
  1353. if (!$is_nft || !$is_nft['success']){
  1354. }else{
  1355. //获取排名
  1356. $rank = getRanking($info['c_id'])+1;
  1357. $tag = getTag($info['c_id'],$rank,$pro_info['inventory']);
  1358. saveRanking($info['c_id']);
  1359. $collectors_hash = '';
  1360. $dates = [
  1361. 'order_no'=>get_order_sn(),
  1362. 'tag'=>$tag,
  1363. 'mid'=>$user1['pid'],
  1364. 'c_id'=>$info['c_id'],
  1365. 'name'=>$pro_info['name'],
  1366. 'cover'=>$pro_info['cover'],
  1367. 'pro_info'=>json_encode($pro_info,true),
  1368. 'type'=>$pro_info['type'],
  1369. 'tokenid'=>$is_nft['class_id'],
  1370. 'nfttype'=>$is_nft['operationId'],
  1371. 'collectors_hash'=>$collectors_hash,
  1372. 'remark'=>'邀请单人奖励'
  1373. ];
  1374. if (Db::name('store_order_info')->insert($dates)){
  1375. loseCollectionInventory($info['c_id'],1);
  1376. }
  1377. }
  1378. }
  1379. }
  1380. }else{
  1381. //查询有没有当前人数的活动
  1382. $info = Db::name('store_activities')
  1383. ->where('ac_id',$act['id'])
  1384. ->where('is_del',1)
  1385. ->where('type',3)
  1386. ->where('state',1)
  1387. ->where('num',$count)
  1388. ->find();
  1389. if ($info){
  1390. $pro_info = getCollectionInfoHash($info['c_id']);
  1391. $now_inventory = getCollectionInventory($info['c_id']);
  1392. if ($now_inventory>0){
  1393. $is_nft = Db::name('hash2')->where('goods_id',$info['c_id'])->find();
  1394. if (!$is_nft || !$is_nft['success']){
  1395. }else{
  1396. //获取排名
  1397. $rank = getRanking($info['c_id'])+1;
  1398. $tag = getTag($info['c_id'],$rank,$pro_info['inventory']);
  1399. saveRanking($info['c_id']);
  1400. $collectors_hash = '';
  1401. $dates = [
  1402. 'order_no'=>get_order_sn(),
  1403. 'tag'=>$tag,
  1404. 'mid'=>$user1['pid'],
  1405. 'c_id'=>$info['c_id'],
  1406. 'name'=>$pro_info['name'],
  1407. 'cover'=>$pro_info['cover'],
  1408. 'pro_info'=>json_encode($pro_info,true),
  1409. 'type'=>$pro_info['type'],
  1410. 'tokenid'=>$is_nft['class_id'],
  1411. 'nfttype'=>$is_nft['operationId'],
  1412. 'collectors_hash'=>$collectors_hash,
  1413. 'remark'=>'邀请'.$count.'人奖励'
  1414. ];
  1415. if (Db::name('store_order_info')->insert($dates)){
  1416. loseCollectionInventory($info['c_id'],1);
  1417. }
  1418. }
  1419. }
  1420. }
  1421. }
  1422. }
  1423. }else{
  1424. //判断新人注册是否有活动
  1425. $info = Db::name('store_activities')
  1426. ->where('ac_id',$act['id'])
  1427. ->where('is_del',1)
  1428. ->where('state',1)
  1429. ->where('type',1)
  1430. ->find();
  1431. if ($info){
  1432. $pro_info = getCollectionInfoHash($info['c_id']);
  1433. $now_inventory = getCollectionInventory($info['c_id']);
  1434. if ($now_inventory>0){
  1435. $is_nft = Db::name('hash2')->where('goods_id',$info['c_id'])->find();
  1436. if (!$is_nft || !$is_nft['success']){
  1437. }else{
  1438. //获取排名
  1439. $rank = getRanking($info['c_id'])+1;
  1440. $tag = getTag($info['c_id'],$rank,$pro_info['inventory']);
  1441. saveRanking($info['c_id']);
  1442. $collectors_hash = '';
  1443. $date = [
  1444. 'order_no'=>get_order_sn(),
  1445. 'tag'=>$tag,
  1446. 'mid'=>$mid,
  1447. 'c_id'=>$info['c_id'],
  1448. 'name'=>$pro_info['name'],
  1449. 'cover'=>$pro_info['cover'],
  1450. 'pro_info'=>json_encode($pro_info,true),
  1451. 'type'=>$pro_info['type'],
  1452. 'tokenid'=>$is_nft['class_id'],
  1453. 'nfttype'=>$is_nft['operationId'],
  1454. 'collectors_hash'=>$collectors_hash,
  1455. 'remark'=>'新人注册奖励'
  1456. ];
  1457. if (Db::name('store_order_info')->insert($date)){
  1458. loseCollectionInventory($info['c_id'],1);
  1459. }
  1460. }
  1461. }
  1462. }
  1463. }
  1464. }
  1465. return true;
  1466. }
  1467. function pullNew($mid){
  1468. //判断给拉新奖励
  1469. $user1 = getMemberInfoHash($mid); //获取用户信息
  1470. if ($user1['pid']){
  1471. //获取奖励列表
  1472. $ids = Db::name('store_collection')
  1473. ->where('is_deleted',0)
  1474. ->where('pull_new',1)
  1475. ->column('id');
  1476. if ($ids){
  1477. $array = [];
  1478. foreach ($ids as &$v){
  1479. $now_inventory = getCollectionInventory($v);
  1480. if ($now_inventory>1){
  1481. array_push($array,$v);
  1482. }
  1483. }
  1484. if ($array){
  1485. $vaule = array_rand($array);
  1486. $id = $array[$vaule];
  1487. $info = getCollectionInfoHash($id);
  1488. $is_nft = Db::name('hash2')->where('goods_id',$id)->where('success',1)->find();
  1489. //获取排名
  1490. $rank = getRanking($id)+1;
  1491. $tag = getTag($id,$rank,$info['inventory']);
  1492. saveRanking($id);
  1493. $collectors_hash = '';
  1494. $date = [
  1495. 'order_no'=>get_order_sn(),
  1496. 'tag'=>$tag,
  1497. 'mid'=>$user1['pid'],
  1498. 'c_id'=>$id,
  1499. 'name'=>$info['name'],
  1500. 'cover'=>$info['cover'],
  1501. 'pro_info'=>json_encode($info,true),
  1502. 'type'=>$info['type'],
  1503. 'tokenid'=>$is_nft['class_id'],
  1504. 'nfttype'=>$is_nft['operationId'],
  1505. 'collectors_hash'=>$collectors_hash,
  1506. 'remark'=>'拉新奖励'
  1507. ];
  1508. Db::name('store_order_info')->insert($date);
  1509. // //获取排名
  1510. // $rank = getRanking($id)+1;
  1511. // $tag = getTag($id,$rank,$info['inventory']);
  1512. // saveRanking($id);
  1513. // $collectors_hash = '';
  1514. // $data = [
  1515. // 'order_no'=>get_order_sn(),
  1516. // 'tag'=>$tag,
  1517. // 'mid'=>$mid,
  1518. // 'c_id'=>$id,
  1519. // 'name'=>$info['name'],
  1520. // 'cover'=>$info['cover'],
  1521. // 'pro_info'=>json_encode($info,true),
  1522. // 'type'=>$info['type'],
  1523. // 'tokenid'=>$is_nft['class_id'],
  1524. // 'nfttype'=>$is_nft['operationId'],
  1525. // 'collectors_hash'=>$collectors_hash,
  1526. // 'collectors_hash_time'=>'',
  1527. // 'remark'=>'被拉新奖励'
  1528. // ];
  1529. // Db::name('store_order_info')->insert($data);
  1530. }
  1531. }
  1532. //获取奖励列表
  1533. $ids2 = Db::name('store_collection')
  1534. ->where('is_deleted',0)
  1535. ->where('pull_new2',1)
  1536. ->column('id');
  1537. if ($ids2){
  1538. $array2 = [];
  1539. foreach ($ids2 as &$v){
  1540. $now_inventory2 = getCollectionInventory($v);
  1541. if ($now_inventory2>1){
  1542. array_push($array,$v);
  1543. }
  1544. }
  1545. if ($array2){
  1546. $vaule = array_rand($array2);
  1547. $id2 = $array2[$vaule];
  1548. $info2 = getCollectionInfoHash($id2);
  1549. $is_nft2 = Db::name('hash2')->where('goods_id',$id2)->where('success',1)->find();
  1550. //获取排名
  1551. $rank = getRanking($id2)+1;
  1552. $tag = getTag($id2,$rank,$info2['inventory']);
  1553. saveRanking($id2);
  1554. $collectors_hash = '';
  1555. $data2 = [
  1556. 'order_no'=>get_order_sn(),
  1557. 'tag'=>$tag,
  1558. 'mid'=>$mid,
  1559. 'c_id'=>$id2,
  1560. 'name'=>$info2['name'],
  1561. 'cover'=>$info2['cover'],
  1562. 'pro_info'=>json_encode($info2,true),
  1563. 'type'=>$info2['type'],
  1564. 'tokenid'=>$is_nft2['class_id'],
  1565. 'nfttype'=>$is_nft2['operationId'],
  1566. 'collectors_hash'=>$collectors_hash,
  1567. 'remark'=>'被拉新奖励'
  1568. ];
  1569. Db::name('store_order_info')->insert($data2);
  1570. }
  1571. }
  1572. }
  1573. }
  1574. /**
  1575. * 判断邀请人活动
  1576. * @param $proArr
  1577. * @return int|string
  1578. */
  1579. function checkactivity($id=''){
  1580. if ($id){
  1581. $info = Db::name('store_activity')->where('id',$id)->find();
  1582. if (time()<strtotime($info['start_at'])){
  1583. Db::name('store_activity')->where('id',$id)->update(['status'=>1]);
  1584. }elseif (time()>strtotime($info['start_at']) && time()<strtotime($info['end_at'])){
  1585. Db::name('store_activity')->where('id',$id)->update(['status'=>2]);
  1586. }elseif (time()>strtotime($info['end_at'])){
  1587. Db::name('store_activity')->where('id',$id)->update(['status'=>3]);
  1588. }
  1589. }else{
  1590. $list = Db::name('store_activity')->where('is_del',1)->select();
  1591. foreach ($list as &$v){
  1592. if (time()<strtotime($v['start_at'])){
  1593. Db::name('store_activity')->where('id',$v['id'])->update(['status'=>1]);
  1594. }elseif (time()>strtotime($v['start_at']) && time()<strtotime($v['end_at'])){
  1595. Db::name('store_activity')->where('id',$v['id'])->update(['status'=>2]);
  1596. }elseif (time()>strtotime($v['end_at'])){
  1597. Db::name('store_activity')->where('id',$v['id'])->update(['status'=>3]);
  1598. }
  1599. }
  1600. }
  1601. }
  1602. /**
  1603. * 登录日志
  1604. */
  1605. function LoginLog($mid){
  1606. $data = [
  1607. 'mid'=>$mid,
  1608. 'ip'=>request()->ip()
  1609. ];
  1610. Db::name('store_login_log')->insert($data);
  1611. }
  1612. /**
  1613. * 判断银行卡号格式
  1614. */
  1615. function checkbank($no=""){
  1616. if(empty($no)) return false;
  1617. $arr_no = str_split($no);
  1618. $last_n = $arr_no[count($arr_no)-1];
  1619. krsort($arr_no);
  1620. $i = 1;
  1621. $total = 0;
  1622. foreach ($arr_no as $n){
  1623. if($i%2==0){
  1624. $ix = $n*2;
  1625. if($ix>=10){
  1626. $nx = 1 + ($ix % 10);
  1627. $total += $nx;
  1628. }else{
  1629. $total += $ix;
  1630. }
  1631. }else{
  1632. $total += $n;
  1633. }
  1634. $i++;
  1635. }
  1636. $total -= $last_n;
  1637. $x = 10 - ($total % 10);
  1638. if($x == $last_n){
  1639. return true;
  1640. }else{
  1641. return false;
  1642. }
  1643. }