common.php 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409
  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 threeElementCertification($id_card,$name,$phone)
  196. {
  197. $host = "http://sjsys.market.alicloudapi.com";
  198. $path = "/communication/personal/1979";
  199. $method = "POST";
  200. $appcode = "你自己的AppCode";
  201. $headers = array();
  202. array_push($headers, "Authorization:APPCODE " . $appcode);
  203. //根据API的要求,定义相对应的Content-Type
  204. array_push($headers, "Content-Type".":"."application/x-www-form-urlencoded; charset=UTF-8");
  205. $querys = "";
  206. $bodys = "idcard=$id_card****&mobile=$phone****&name=$name";
  207. $url = $host . $path;
  208. $curl = curl_init();
  209. curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
  210. curl_setopt($curl, CURLOPT_URL, $url);
  211. curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
  212. curl_setopt($curl, CURLOPT_FAILONERROR, false);
  213. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  214. curl_setopt($curl, CURLOPT_HEADER, true);
  215. if (1 == strpos("$".$host, "https://")) {
  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. var_dump(curl_exec($curl));
  221. }
  222. // 实名认证
  223. function user_certification($id_card,$name){
  224. $host = "http://checkone.market.alicloudapi.com";
  225. $path = "/chinadatapay/1882";
  226. $method = "POST";
  227. $appcode = "c8fd88cc95dd46fa8c50b05d219824ed";
  228. $headers = array();
  229. array_push($headers, "Authorization:APPCODE " . $appcode);
  230. //根据API的要求,定义相对应的Content-Type
  231. array_push($headers, "Content-Type".":"."application/x-www-form-urlencoded; charset=UTF-8");
  232. $bodys = "idcard=".$id_card."&name=".$name;
  233. $url = $host . $path;
  234. $curl = curl_init();
  235. curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
  236. curl_setopt($curl, CURLOPT_URL, $url);
  237. curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
  238. curl_setopt($curl, CURLOPT_FAILONERROR, false);
  239. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  240. curl_setopt($curl, CURLOPT_HEADER, false);
  241. if (1 == strpos("$".$host, "https://"))
  242. {
  243. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  244. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  245. }
  246. curl_setopt($curl, CURLOPT_POSTFIELDS, $bodys);
  247. $res = curl_exec($curl);
  248. if($res){
  249. $res = json_decode($res,true);
  250. if($res['data']['result'] == 1){
  251. return 1;
  252. }else{
  253. return 0;
  254. }
  255. }else{
  256. return 0;
  257. }
  258. }
  259. /**
  260. * 大师提前分钟数存入redis
  261. */
  262. function setAdvanceMinutes(){
  263. $redis = new \think\cache\driver\Redis();
  264. $value = Db::name('system_config')->where('name','advance_minutes')->value('value');
  265. $redis->set('advance_minutes',$value);
  266. }
  267. /**
  268. * 获取大师提前分钟数
  269. */
  270. function getAdvanceMinutes(){
  271. $redis = new \think\cache\driver\Redis();
  272. $value = $redis->get('advance_minutes');
  273. if (empty($value)){
  274. $value = Db::name('system_config')->where('name','advance_minutes')->value('value');
  275. $redis->set('advance_minutes',$value);
  276. }
  277. return $value;
  278. }
  279. /**
  280. * 获取自动取消分钟数
  281. */
  282. function getCancelTime(){
  283. return Db::name('system_config')->where('name','cancel_time')->value('value');
  284. }
  285. /**
  286. * 用户信息存入redis hash
  287. */
  288. function setMemberInfoHash($member_id){
  289. $info = Db::name('store_member')->where('id',$member_id)->find();
  290. $redis = new \think\cache\driver\Redis();
  291. $array = ['member'.$member_id=>json_encode($info)];
  292. $redis->hMSet('memberInfo',$array);
  293. }
  294. /**
  295. * redis获取用户信息
  296. */
  297. function getMemberInfoHash($member_id){
  298. $redis = new \think\cache\driver\Redis();
  299. $info = $redis->hGet('memberInfo','member'.$member_id);
  300. if (!$info){
  301. $info = Db::name('store_member')->where('id',$member_id)->find();
  302. $array = ['member'.$member_id=>json_encode($info)];
  303. $redis->hMSet('memberInfo',$array);
  304. }else{
  305. $info = json_decode($info,true);
  306. }
  307. return $info;
  308. }
  309. /**
  310. * 获取藏品库存
  311. */
  312. function getCollectionInventory($id){
  313. $redis = new \think\cache\driver\Redis();
  314. $count = $redis->get('collection_count_'.$id);
  315. // if (empty($count)){
  316. // $redis->set('collection_count_'.$id,0);
  317. // }
  318. return $count ? $count : 0;
  319. }
  320. /**
  321. * 减掉藏品库存
  322. */
  323. function loseCollectionInventory($id,$num){
  324. $redis = new \think\cache\driver\Redis();
  325. $redis->Decrby('collection_count_'.$id,$num);
  326. }
  327. /**
  328. * 加藏品库存
  329. */
  330. function addCollectionInventory($id,$num){
  331. $redis = new \think\cache\driver\Redis();
  332. $redis->Incrby('collection_count_'.$id,$num);
  333. }
  334. /**
  335. * 用户购买藏品排名更新
  336. */
  337. function saveRanking($id){
  338. }
  339. function getRanking($id,$inc= 1){
  340. $redis = new \think\cache\driver\Redis();
  341. if($inc == 1) {
  342. $count = $redis->Incr('ranking'.$id);
  343. }else{
  344. $count = $redis->get('ranking'.$id);
  345. if (empty($count)) $redis->set('ranking'.$id,0);
  346. $count = empty($count) ? 0 : $count;
  347. }
  348. return $count;
  349. }
  350. /**
  351. * 藏品信息存入redis hash
  352. */
  353. function setCollectionInfoHash($id){
  354. $info = Db::name('store_collection')->where('id',$id)->find();
  355. $redis = new \think\cache\driver\Redis();
  356. $array = ['collection'.$id=>json_encode($info)];
  357. $redis->hMSet('collectionInfo',$array);
  358. }
  359. /**
  360. * 获取用户购买数量
  361. */
  362. function getByCount($mid,$id){
  363. $redis = new \think\cache\driver\Redis();
  364. $count = $redis->get('UserByCount_'.$mid.$id);
  365. if (empty($count) && $count!=0){
  366. $count = 0;
  367. $redis->Incrby('UserByCount_'.$mid.$id,$count);
  368. }
  369. return $count;
  370. }
  371. /**
  372. * 用户购买数量增加
  373. */
  374. function IncrByCount($mid,$id,$number){
  375. $redis = new \think\cache\driver\Redis();
  376. $redis->Incrby('UserByCount_'.$mid.$id,$number);
  377. }
  378. /**
  379. * 用户购买数量减少
  380. */
  381. function DecrByCount($mid,$id,$number){
  382. $redis = new \think\cache\driver\Redis();
  383. $redis->Decrby('UserByCount_'.$mid.$id,$number);
  384. }
  385. /**
  386. * 获取藏品hash redis长度
  387. */
  388. function getLenCollection($id){
  389. $redis = new \think\cache\driver\Redis();
  390. $count = $redis->Llen('collectionHash_'.$id);
  391. if (!$count){
  392. $count = Db::name('hash')
  393. ->where('goods_id',$id)
  394. ->where('status',0)
  395. ->count();
  396. }
  397. return $count;
  398. }
  399. /**
  400. * 获取藏品信息
  401. */
  402. function getCollectionInfoHash($id)
  403. {
  404. $redis = new \think\cache\driver\Redis();
  405. $info = $redis->hGet('collectionInfo','collection'.$id);
  406. if (!$info){
  407. $info = Db::name('store_collection')->where('id',$id)->find();
  408. $array = ['collection'.$id=>json_encode($info)];
  409. $redis->hMSet('collectionInfo',$array);
  410. }else{
  411. $info = json_decode($info,true);
  412. }
  413. return $info;
  414. }
  415. /**
  416. * 收集下单用户id
  417. */
  418. function setCollectionBuyUser($mid){
  419. $redis = new \think\cache\driver\Redis();
  420. $array = [$mid=>1];
  421. $redis->hMSet('buyUserInfo',$array);
  422. }
  423. /*
  424. * 微信支付账户
  425. */
  426. function retrunWxConfig(){
  427. $config = [
  428. 'app_id' => 'wx8e47a12d0a1c007f',
  429. 'mch_id' =>'1627327076',
  430. 'key' =>'dguiadak46574hbfkjshfns55f87s5sd',
  431. ];
  432. return $config;
  433. }
  434. /**
  435. * 获取离线账户
  436. */
  437. function getOfflineAccount(){
  438. $url = 'http://192.144.219.204:8083/ddc/createAccount';
  439. return file_get_contents($url);
  440. }
  441. /**
  442. * 获取链账户
  443. */
  444. function getWalletAddress($phone){
  445. $url = getIpAddress().'register?accountName='.$phone;
  446. $res=curlRequest($url);
  447. if ($res){
  448. $res = json_decode($res,true);
  449. if ($res['code']=='200'){
  450. return $res['result']['userAddressStr'];
  451. }
  452. }
  453. return false;
  454. }
  455. /**
  456. * 获取公司生成的hash
  457. */
  458. function getCompanyHash($id){
  459. $redis = new \think\cache\driver\Redis();
  460. $hash = $redis->lPop('collectionHash_'.$id);
  461. if (!$hash){
  462. $hash = Db::name('hash')->where('goods_id',$id)
  463. ->where('status',0)
  464. ->order('id asc')
  465. ->field('hash,create_at,tokenid')
  466. ->limit(1)
  467. ->find();
  468. }else{
  469. $hash = json_decode($hash,true);
  470. }
  471. return $hash;
  472. }
  473. /**
  474. * 获取排名
  475. */
  476. function getTag($id,$now,$num){
  477. $len = strlen($num);
  478. $re = 'XL'.$id.'#';
  479. switch ($len){
  480. case 1:
  481. $re = $re.'0'.$now;
  482. break;
  483. case 2:
  484. if ($now<10){
  485. $re = $re.'0'.$now;
  486. }else{
  487. $re = $re.$now;
  488. }
  489. break;
  490. case 3:
  491. if ($now<10){
  492. $re = $re.'00'.$now;
  493. }elseif ($now>=10 && $now<100){
  494. $re = $re.'0'.$now;
  495. }else{
  496. $re = $re.$now;
  497. }
  498. break;
  499. case 4:
  500. if ($now<10){
  501. $re = $re.'000'.$now;
  502. }elseif ($now>=10 && $now<100){
  503. $re = $re.'00'.$now;
  504. }elseif ($now>=100 && $now<1000){
  505. $re = $re.'0'.$now;
  506. }else{
  507. $re = $re.$now;
  508. }
  509. break;
  510. case 5:
  511. if ($now<10){
  512. $re = $re.'0000'.$now;
  513. }elseif ($now>=10 && $now<100){
  514. $re = $re.'000'.$now;
  515. }elseif ($now>=100 && $now<1000){
  516. $re = $re.'00'.$now;
  517. }elseif ($now>=1000 && $now<10000){
  518. $re = $re.'0'.$now;
  519. }else{
  520. $re = $re.$now;
  521. }
  522. break;
  523. case 6:
  524. if ($now<10){
  525. $re = $re.'00000'.$now;
  526. }elseif ($now>=10 && $now<100){
  527. $re = $re.'0000'.$now;
  528. }elseif ($now>=100 && $now<1000){
  529. $re = $re.'000'.$now;
  530. }elseif ($now>=1000 && $now<10000){
  531. $re = $re.'00'.$now;
  532. }elseif ($now>=10000 && $now<100000){
  533. $re = $re.'0'.$now;
  534. }else{
  535. $re = $re.$now;
  536. }
  537. break;
  538. }
  539. $re = $re.'/'.$num;
  540. return $re;
  541. }
  542. /**
  543. * 判断藏品是否设置过提醒
  544. */
  545. function getRemind($mid,$c_id){
  546. return Db::name('store_collection_remind')->where('mid',$mid)->where('c_id',$c_id)->count();
  547. }
  548. /**
  549. * 变更会员积分等
  550. * @param int $money 余额
  551. * @param int $user_id 会员ID
  552. * @param string $memo 备注
  553. */
  554. function memberMoneyChange($num, $type , $m_id, $title, $pm = 0,$link_id=0,$change_type = 0)
  555. {
  556. $member = Db::name('store_member')->where('id',$m_id)->find();
  557. $is_inc = $pm == 1 ? 1 : -1;
  558. switch ($type){
  559. case 1: //积分
  560. $before = $member['integral'];
  561. if ($pm==1)
  562. $after = $member['integral']+$num;
  563. else
  564. $after = $member['integral']-$num;
  565. $update_data = ['integral'=>Db::raw('integral +'.$num*$is_inc)];
  566. break;
  567. case 2: //抢购卡
  568. $before = $member['snap_card'];
  569. if ($pm==1)
  570. $after = $member['snap_card']+$num;
  571. else
  572. $after = $member['snap_card']-$num;
  573. $update_data = ['snap_card'=>Db::raw('snap_card +'.$num*$is_inc)];
  574. break;
  575. case 3: //余额
  576. $before = $member['money'];
  577. if ($pm==1)
  578. $after = $member['money']+$num;
  579. else
  580. $after = $member['money']-$num;
  581. $update_data = ['money'=>Db::raw('money +'.$num*$is_inc)];
  582. break;
  583. }
  584. try {
  585. Db::name('store_member')->where('id',$m_id)->update($update_data);
  586. $data = [
  587. 'm_id'=>$m_id,
  588. 'type'=>$type,
  589. 'pm'=>$pm,
  590. 'title'=>$title,
  591. 'change'=>$num,
  592. 'before'=>$before,
  593. 'after'=>$after,
  594. 'link_id'=>$link_id,
  595. 'change_type'=>$change_type
  596. ];
  597. Db::name('store_member_log')->insert($data);
  598. return true;
  599. }catch (\Exception $e){
  600. return false;
  601. }
  602. }
  603. /**
  604. * 变更会员等级
  605. * @param int $vid 等级
  606. * @param int $user_id 会员ID
  607. * @param array $other 其他
  608. */
  609. function memberVipChange($vid, $user_id, $other = [])
  610. {
  611. return true;// 象链没有会员等级
  612. $member = Db::name('store_member')->where('id',$user_id)->find();
  613. //数据
  614. $before = $member['vip'];
  615. $after = $vid;
  616. //新等级小于等级 则不升级
  617. if($after <= $before && $other['status'] == 1){
  618. return false;
  619. }
  620. //等级相同 不操作
  621. if($after == $before){
  622. return false;
  623. }
  624. $update_data['vip'] = $vid;
  625. Db::startTrans();
  626. try {
  627. Db::name('store_member')->where('id',$user_id)->update($update_data);
  628. $data = [
  629. 'mid' => $user_id,
  630. 'oldvid' => $before,
  631. 'vid' => $after,
  632. 'type' => $other['type'],
  633. 'status' => $other['status'],
  634. 'desc' => $other['desc'],
  635. 'order_table' => $other['order_table'],
  636. 'order_id' => $other['order_id'],
  637. ];
  638. Db::name('store_vipuser')->insert($data);
  639. Db::commit();
  640. return true;
  641. }catch (\Exception $e){
  642. Db::rollback();
  643. return false;
  644. }
  645. }
  646. /**
  647. * 获取会员等级
  648. */
  649. function getMemberVipInfo($uid, $field = '' )
  650. {
  651. $memberVip = Db::name('store_member')->where('id',$uid)->value('vip');
  652. if(!$field){
  653. $vipInfo = Db::name('store_vip')
  654. ->where('id',$memberVip)
  655. ->where('is_del',0)
  656. ->where('status',1)
  657. ->value('discount');
  658. }else{
  659. $vipInfo = Db::name('store_vip')->field($field)
  660. ->where('id',$memberVip)
  661. ->where('is_del',0)
  662. ->where('status',1)
  663. ->find();
  664. }
  665. return $vipInfo;
  666. }
  667. /**
  668. * 优先购匹配藏品会员等级
  669. * @param int $user_id 会员Id
  670. * @param int $memberVip 会员等级
  671. * @param string $vids 藏品配置等级
  672. * @param array $other 其他
  673. */
  674. function memberBuyGoodsVip($user_id,$memberVip, $vids = '', $other = [])
  675. {
  676. $vidData = explode(',',$vids);
  677. if(!in_array($memberVip,$vidData)){
  678. return [];
  679. }
  680. //获取等级详情
  681. $vipInfo = Db::name('store_vip')->field('id,name,advance_minutes,advance_count')
  682. ->where('id',$memberVip)
  683. ->where('is_del',0)
  684. ->where('status',1)
  685. ->find();
  686. //获取用户已经购买数量
  687. $userByCount = getByCount($user_id,$other['gid']);
  688. if($userByCount >= $vipInfo['advance_count'] ){
  689. return [];
  690. }
  691. return $vipInfo;
  692. }
  693. /**
  694. * 验证会员优先购
  695. * @param int $user_id 会员Id
  696. * @param int $goods_id 藏品id
  697. */
  698. function checkMemberPriority($user_id,$goods_id)
  699. {
  700. $import_user = Db::name('store_collection_first')->where('c_id',$goods_id)->cache(300)->column('num','uid');
  701. if(isset($import_user[$user_id]) && $import_user[$user_id] > 0) return $import_user[$user_id];// 导入设置优先购
  702. $power_coll = Db::name('collection_power')->where('before_id',$goods_id)->cache(300)->column('coll_id'); // 藏品拥有者优先购
  703. if(empty($power_coll)) return false;
  704. $has_collect = Db::name('store_order_info')
  705. ->where('mid',$user_id)
  706. ->where('c_id','in',implode(',',$power_coll))
  707. ->where('status','neq','2')
  708. ->where('is_destruction',1)
  709. ->where('resale_status',1)
  710. ->cache(300)
  711. ->count();
  712. return $has_collect ? true : false;
  713. }
  714. /**
  715. * 手续费折扣
  716. * @param int $user_id 会员Id
  717. * @param array $other 其他
  718. */
  719. function getMemberServiceCharge($user_id)
  720. {
  721. // 设置
  722. $power_coll = Db::name('collection_power')->where('discount','>',0)
  723. ->order('discount desc ,id desc')
  724. ->cache(300)->column('discount','coll_id');
  725. if(empty($power_coll)) return 1;
  726. $has_collect = Db::name('store_order_info')
  727. ->field('c_id')
  728. ->whereIn('c_id',implode(',',array_keys($power_coll)))
  729. ->where('mid',$user_id)
  730. ->where('status','neq','2')
  731. ->where('is_destruction',1)
  732. ->where('resale_status',1)
  733. ->group('c_id')
  734. ->cache(300)
  735. ->select();
  736. $discount = 100;
  737. // var_dump($power_coll,$has_collect);
  738. foreach ($has_collect as $v) {
  739. if( isset($power_coll[$v['c_id']])) $discount = $power_coll[$v['c_id']];
  740. }
  741. return bcdiv($discount,100,2);
  742. }
  743. /**
  744. * 获取单个系统配置信息
  745. */
  746. function getConfigValue($name){
  747. return Db::name('system_config')->where('name',$name)->cache(300)->value('value');
  748. }
  749. /**
  750. * 判断藏品状态
  751. */
  752. function checkCollectionState($id=''){
  753. if ($id){
  754. $info = Db::name('store_collection')->field('id,sell_time,state,now_inventory')->where('id',$id)->find();
  755. $now_inventory = getCollectionInventory($id);
  756. if ($info['state']==1){
  757. if ($now_inventory<=0){
  758. Db::name('store_collection')->where('id',$info['id'])->update(['state'=>3]);
  759. }
  760. }else if($info['state']==2){
  761. if (strtotime($info['sell_time'])<=time()){
  762. Db::name('store_collection')->where('id',$info['id'])->update(['state'=>1]);
  763. }
  764. }else if($info['state']==3){
  765. if ($now_inventory>0){
  766. Db::name('store_collection')->where('id',$info['id'])->update(['state'=>1]);
  767. }
  768. }
  769. }else{
  770. $list = Db::name('store_collection')
  771. ->field('id,sell_time,state,now_inventory')
  772. ->where('is_deleted',0)
  773. ->select();
  774. foreach ($list as &$v){
  775. $now_inventory = getCollectionInventory($v['id']);
  776. if ($v['state']==1){
  777. if ($now_inventory<=0 || $v['now_inventory'] == 0){
  778. Db::name('store_collection')->where('id',$v['id'])->update(['state'=>3]);
  779. }
  780. }elseif ($v['state']==2){
  781. if (strtotime($v['sell_time'])<=time()){
  782. Db::name('store_collection')->where('id',$v['id'])->update(['state'=>1]);
  783. }
  784. }elseif ($v['state']==3){
  785. if ($now_inventory>0){
  786. Db::name('store_collection')->where('id',$v['id'])->update(['state'=>1]);
  787. }
  788. }
  789. }
  790. }
  791. }
  792. /**
  793. * 判断藏品状态
  794. */
  795. function checkSynCollectionState($id=''){
  796. if ($id){
  797. $info = Db::name('store_collection')->where('id',$id)->find();
  798. $now_inventory = getCollectionInventory($id);
  799. if ($info['sy_state']==1){
  800. if ($now_inventory<=0){
  801. Db::name('store_collection')->where('id',$info['id'])->update(['sy_state'=>4]);
  802. }elseif(strtotime($info['end_time'])<time()){
  803. Db::name('store_collection')->where('id',$info['id'])->update(['sy_state'=>3]);
  804. }
  805. }elseif ($info['sy_state']==2){
  806. if (strtotime($info['sell_time'])<=time()){
  807. Db::name('store_collection')->where('id',$info['id'])->update(['sy_state'=>1]);
  808. }elseif ($now_inventory<=0){
  809. Db::name('store_collection')->where('id',$info['id'])->update(['sy_state'=>4]);
  810. }
  811. }
  812. }else{
  813. $list = Db::name('store_collection')
  814. ->where('type',2)
  815. ->whereIn('sy_state','1,2')
  816. ->where('is_deleted',0)
  817. ->select();
  818. foreach ($list as &$v){
  819. $now_inventory = getCollectionInventory($v['id']);
  820. if ($v['sy_state']==1){
  821. if ($now_inventory<=0){
  822. Db::name('store_collection')->where('id',$v['id'])->update(['sy_state'=>4]);
  823. }elseif($v['end_time'] && strtotime($v['end_time'])<time()){
  824. Db::name('store_collection')->where('id',$v['id'])->update(['sy_state'=>3]);
  825. }
  826. }elseif ($v['sy_state']==2){
  827. if (strtotime($v['sell_time'])<=time()){
  828. Db::name('store_collection')->where('id',$v['id'])->update(['sy_state'=>1]);
  829. }elseif ($now_inventory<=0){
  830. Db::name('store_collection')->where('id',$v['id'])->update(['sy_state'=>4]);
  831. }
  832. }
  833. }
  834. }
  835. }
  836. /**
  837. * redis加锁
  838. */
  839. function redisSetNx($id,$exptime=3){
  840. $redis = new \think\cache\driver\Redis();
  841. $key = 'stock_'.$id;
  842. $is_lock = $redis->setnx($key,time()+$exptime);
  843. if ($is_lock){
  844. return true;
  845. }else{
  846. //加锁失败的情况下,判断锁是否已经存在,如果存在切已经过期,删除锁,重新加锁
  847. $val = $redis->get($key);
  848. if ($val && $val<time()){
  849. $redis->del($key);
  850. }
  851. return $redis->setnx($key,time()+$exptime);
  852. }
  853. }
  854. /**
  855. * 删除锁
  856. */
  857. function DelRedisSetNx($id){
  858. $redis = new \think\cache\driver\Redis();
  859. $key = 'stock_'.$id;
  860. $redis->del($key);
  861. }
  862. /**
  863. * 盲盒信息存入redis hash
  864. */
  865. function setBoxInfoHash($id){
  866. $info = Db::name('store_collection')->where('id',$id)->find();
  867. $redis = new \think\cache\driver\Redis();
  868. $array = ['collection'.$id=>json_encode($info)];
  869. $redis->hMSet('collectionInfo',$array);
  870. }
  871. /**
  872. * 获取0的数量
  873. */
  874. function get0number($n){
  875. if ($n==1){
  876. return '00000000000';
  877. }elseif ($n==2){
  878. return '0000000000';
  879. }elseif ($n==3){
  880. return '000000000';
  881. }elseif ($n==4){
  882. return '00000000';
  883. }elseif ($n==5){
  884. return '0000000';
  885. }elseif ($n==6){
  886. return '000000';
  887. }elseif ($n==7){
  888. return '00000';
  889. }elseif ($n==8){
  890. return '0000';
  891. }elseif ($n==9){
  892. return '000';
  893. }elseif ($n==10){
  894. return '00';
  895. }elseif ($n==11){
  896. return '0';
  897. }
  898. }
  899. /***********************************************人脸识别*****************************************************************/
  900. /**
  901. * 获取accesstoken
  902. * @return mixed
  903. */
  904. function getAccessToken(){
  905. $appid_id =getFaceInfo()['appid'];
  906. $secret = getFaceInfo()['secret'];
  907. $grant_type = 'client_credential';
  908. $version = '1.0.0';
  909. $url = "https://miniprogram-kyc.tencentcloudapi.com/api/oauth2/access_token?app_id=".$appid_id."&secret=".$secret."&grant_type=".$grant_type."&version=".$version;
  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. * 获取api_ticket
  919. */
  920. function getApiTicket($type,$userId=''){
  921. $appid_id =getFaceInfo()['appid'];
  922. $access_token = getAccessToken()['access_token'];
  923. $version = '1.0.0';
  924. $url = "https://miniprogram-kyc.tencentcloudapi.com/api/oauth2/api_ticket?app_id=".$appid_id."&access_token=".$access_token."&type=".$type."&version=".$version;
  925. if ($type=='NONCE'){
  926. $url .= "&user_id=".$userId;
  927. }
  928. $result = curlRequest($url);
  929. $result = json_decode($result,true);
  930. if ($result['code']==0){
  931. return $result;
  932. }
  933. echo $result['msg'];die;
  934. }
  935. /**
  936. * 生成签名
  937. */
  938. function generateSign($userId){
  939. $wbappid = getFaceInfo()['appid'];
  940. $version = '1.0.0';
  941. $ticket = getApiTicket('SIGN')['tickets'][0]['value'];
  942. $nonce = get32Str();
  943. // $array = ['wbappid'=>$wbappid, 'userId'=>"$userId",'nonce'=>$nonce, 'version'=>$version, 'ticket'=>$ticket];
  944. $array = [$wbappid, "$userId",$nonce, $version, $ticket];
  945. file_put_contents("signLog.txt", json_encode($array) . "\n" . "\n", FILE_APPEND);
  946. sort($array);
  947. $str='';
  948. foreach ($array as $kk=>$vv){
  949. $str .=$vv;
  950. }
  951. // echo $str;die;
  952. $result = strtoupper(sha1($str));
  953. $res['sign'] = $result;
  954. $res['nonce'] = $nonce;
  955. $res['appid'] = $wbappid;
  956. return $res;
  957. }
  958. /**
  959. * 合作方后台上送身份信息
  960. */
  961. function getfaceid($name,$idNo,$userId){
  962. $webankAppId = getFaceInfo()['appid'];
  963. $orderNo = get32Str();
  964. $sign = generateSign($userId);
  965. $data = [
  966. 'webankAppId'=>$webankAppId,
  967. 'orderNo'=>$orderNo,
  968. 'name'=>$name,
  969. 'idNo'=>$idNo,
  970. 'userId'=>"$userId",
  971. 'version'=>'1.0.0',
  972. 'sign'=>$sign['sign'],
  973. 'nonce'=>$sign['nonce']
  974. ];
  975. $headers = [];
  976. array_push($headers, "Content-Type".":"."application/json; charset=UTF-8");
  977. $url = 'https://miniprogram-kyc.tencentcloudapi.com/api/server/getfaceid?orderNo='.$orderNo;
  978. $result = curlRequest($url,$headers,json_encode($data),'POST');
  979. $result = json_decode($result,true);
  980. if ($result['code']==0){
  981. $data = [
  982. 'appid'=>$sign['appid'],
  983. 'userID'=>"$userId",
  984. 'sign'=>$sign['sign'],
  985. 'nonce'=>$sign['nonce'],
  986. 'sdksign'=>SdkSign($userId,$sign['nonce']),
  987. 'result'=>$result['result'],
  988. ];
  989. return $data;
  990. }
  991. echo $result['msg'];die;
  992. }
  993. /**
  994. * 生成 SDK 接口调用步骤使用签名
  995. */
  996. function SdkSign($userId,$nonce){
  997. $wbappid = getFaceInfo()['appid'];
  998. $version = '1.0.0';
  999. $ticket = getApiTicket('NONCE',$userId)['tickets'][0]['value'];
  1000. //$nonce = get32Str();
  1001. $array = [$wbappid, "$userId",$nonce, $version, $ticket];
  1002. file_put_contents("sdksignLog.txt", json_encode($array) . "\n" . "\n", FILE_APPEND);
  1003. sort($array);
  1004. $str='';
  1005. foreach ($array as $kk=>$vv){
  1006. $str .=$vv;
  1007. }
  1008. $result = strtoupper(sha1($str));
  1009. return $result;
  1010. }
  1011. function getFaceInfo(){
  1012. //正式
  1013. $date = [
  1014. 'appid'=>'IDAKcvCn',
  1015. 'secret'=>'L1id3z5zROK8SVXg72ZyZXc8ziniYLKpOnIzN1gecrBaEMaKIlKrreyRGCLU2z4l'
  1016. ];
  1017. //测试
  1018. // $date = [
  1019. // 'appid'=>'TIDA3uGO',
  1020. // 'secret'=>'z41IysbEhRy5oR4Qs2kFfVkrufXIJMtsJOQ3eulkWwXwdKG772LSSiZsKKwfsv9n'
  1021. // ];
  1022. return $date;
  1023. }
  1024. //将数组转成uri字符串
  1025. function formatBizQueryParaMap($paraMap, $urlencode)
  1026. {
  1027. $buff = "";
  1028. ksort($paraMap);
  1029. foreach ($paraMap as $k => $v)
  1030. {
  1031. if($urlencode)
  1032. {
  1033. $v = urlencode($v);
  1034. }
  1035. // $buff .= strtolower($k) . "=" . $v . "&";
  1036. $buff .= $v;
  1037. }
  1038. if (strlen($buff) > 0)
  1039. {
  1040. $reqPar = substr($buff, 0, strlen($buff)-1);
  1041. }
  1042. return $reqPar;
  1043. }
  1044. /**
  1045. * 生成??位随机数
  1046. */
  1047. function get32Str($length='32'){
  1048. // $str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
  1049. $str = 'abcdefghijklmnopqrstuvwxyz0123456789';
  1050. $len = strlen($str)-1;
  1051. $randstr = '';
  1052. for ($i=0;$i<$length;$i++) {
  1053. $num=mt_rand(0,$len);
  1054. $randstr .= $str[$num];
  1055. }
  1056. return $randstr;
  1057. }
  1058. function get_order_sn(){
  1059. $order_id_main = date('YmdHis') . rand(10000000,99999999);
  1060. $order_id_len = strlen($order_id_main);
  1061. $order_id_sum = 0;
  1062. for($i=0; $i<$order_id_len; $i++){
  1063. $order_id_sum += (int)(substr($order_id_main,$i,1));
  1064. }
  1065. $osn = $order_id_main . str_pad((100 - $order_id_sum % 100) % 100,2,'0',STR_PAD_LEFT);
  1066. return $osn;
  1067. }
  1068. ///**
  1069. // * 生成二维码
  1070. // */
  1071. //function setqrcode($value,$name){
  1072. // $dir = dirname(realpath(dirname($_SERVER['SCRIPT_FILENAME']))) . '/public/user';
  1073. // if(!file_exists($dir)){
  1074. // //检查是否有该文件夹,如果没有就创建,并给予最高权限
  1075. // mkdir($dir, 0700,true);
  1076. // }
  1077. // $filename = $dir.'/'.$name.'.png';
  1078. // QRcode::png($value,$filename,QR_ECLEVEL_L,7);
  1079. // return 'http://'.$_SERVER['HTTP_HOST']."/user/".$name.'.png';
  1080. //}
  1081. /**
  1082. * 生成二维码
  1083. */
  1084. function setqrcode($value,$name){
  1085. $dir = dirname(realpath(dirname($_SERVER['SCRIPT_FILENAME']))) . '/public/user';
  1086. if(!file_exists($dir)){
  1087. //检查是否有该文件夹,如果没有就创建,并给予最高权限
  1088. mkdir($dir, 0700,true);
  1089. }
  1090. $filename = $dir.'/'.$name.'.png';
  1091. QRcode::png($value,$filename,QR_ECLEVEL_L,7);
  1092. $storage_type = getConfigValue('storage_type');
  1093. if ($storage_type == 'oss'){
  1094. $ossClient = new OssClient(getConfigValue('storage_oss_keyid'), getConfigValue('storage_oss_secret'), getConfigValue('storage_oss_endpoint'));
  1095. $file_path = dirname($_SERVER['SCRIPT_FILENAME']) . "/user/".$name.".png";
  1096. $newName = date('Ymd').'/'.get_order_sn().'.png';
  1097. $result = $ossClient->uploadFile(getConfigValue('storage_oss_bucket'), $newName, $file_path);
  1098. $url = $result['info']['url'];
  1099. unlink($file_path);
  1100. }else{
  1101. $url = 'http://'.$_SERVER['HTTP_HOST']."/user/".$name.'.png';
  1102. }
  1103. return $url;
  1104. }
  1105. //生成邀请二维码
  1106. function setintivecode($user_id){
  1107. $name = $user_id."_".time();
  1108. $address = 'https://'.$_SERVER['HTTP_HOST'].'/h5/pages/mine/zhuce?invite_code='.$user_id;
  1109. $url = setqrcode($address,$name);
  1110. return $url;
  1111. }
  1112. //邀请地址
  1113. function getintiveaddress($user_id){
  1114. $address = 'https://'.$_SERVER['HTTP_HOST'].'/h5/pages/mine/zhuce?invite_code='.$user_id;
  1115. return $address;
  1116. }
  1117. /**
  1118. * @param $url
  1119. * @param array $headers
  1120. * @param array $body
  1121. * @param string $method
  1122. * @return bool|string
  1123. */
  1124. function curlRequest($url, $headers = [], $body = [], $method = "GET")
  1125. {
  1126. $ch = curl_init();
  1127. curl_setopt($ch, CURLOPT_URL, $url);
  1128. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);//设置请求头
  1129. curl_setopt($ch, CURLOPT_POSTFIELDS, $body);//设置请求体
  1130. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); //定义请求类型
  1131. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  1132. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  1133. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  1134. curl_setopt($ch, CURLOPT_HTTP_VERSION, 'CURL_HTTP_VERSION_1_1');
  1135. $output = curl_exec($ch);
  1136. curl_close($ch);
  1137. return $output;
  1138. }
  1139. /**
  1140. * 盲盒藏品库存和藏品状态判断
  1141. * @param $proArr
  1142. * @return int|string
  1143. */
  1144. function checkBox(){
  1145. $list = Db::name('store_blind_box')
  1146. ->where('status',1)
  1147. ->where('is_del',1)
  1148. ->field('id,is_prize,prize')
  1149. ->select();
  1150. foreach ($list as &$v){
  1151. if ($v['is_prize']==1){
  1152. $info = Db::name('store_collection')->where('id',$v['prize'])->find();
  1153. if ($info['now_inventory']<=0 || $info['status']==0 || $info['is_deleted']==1){
  1154. Db::name('store_blind_box')->where('id',$v['id'])->update(['status'=>0]);
  1155. }
  1156. }
  1157. }
  1158. }
  1159. //计算中奖概率
  1160. function get_rand($proArr) {
  1161. $result = '';
  1162. //概率数组的总概率精度
  1163. $proSum = array_sum($proArr);
  1164. // var_dump($proSum);
  1165. //概率数组循环
  1166. foreach ($proArr as $key => $proCur) {
  1167. $randNum = mt_rand(1, $proSum); //返回随机整数
  1168. if ($randNum <= $proCur) {
  1169. $result = $key;
  1170. break;
  1171. } else {
  1172. $proSum -= $proCur;
  1173. }
  1174. }
  1175. unset ($proArr);
  1176. return $result;
  1177. }
  1178. /**
  1179. * 调试函数
  1180. */
  1181. function debug($str){
  1182. $str = var_export($str,true).PHP_EOL;
  1183. $str.= date('Y-m-d H:i:s').' ';
  1184. $str.= $_SERVER['REMOTE_ADDR'].' ';
  1185. $str.= $_SERVER['REQUEST_METHOD'].': ';
  1186. // $str.=$_SERVER['HTTP_HOST'];
  1187. $str.= $_SERVER['REQUEST_URI'].''.PHP_EOL.PHP_EOL;
  1188. $str='<?php exit();?>'.PHP_EOL.$str;
  1189. error_log($str,3,"debug.log");
  1190. }
  1191. /**
  1192. * 获取链上ip
  1193. */
  1194. function getIpAddress(){
  1195. $address = 'http://8.136.12.232:8088/';
  1196. return $address;
  1197. }
  1198. function arrayToXml($arr)
  1199. {
  1200. $xml = "<xml>";
  1201. foreach ($arr as $key => $val) {
  1202. if (is_numeric($val)) {
  1203. $xml .= "<" . $key . ">" . $val . "</" . $key . ">";
  1204. } else
  1205. $xml .= "<" . $key . "><![CDATA[" . $val . "]]></" . $key . ">";
  1206. }
  1207. $xml .= "</xml>";
  1208. return $xml;
  1209. }
  1210. /**
  1211. * 验证银行卡号
  1212. * @param string $bankCardNo 银行卡号
  1213. * @return bool 是否合法(true:合法,false:不合法)
  1214. */
  1215. function check_bankCard($bankCardNo){
  1216. $arr_no = str_split($bankCardNo);
  1217. $last_n = $arr_no[count($arr_no)-1];
  1218. krsort($arr_no);
  1219. $i = 1;
  1220. $total = 0;
  1221. foreach ($arr_no as $n){
  1222. if($i%2==0){
  1223. $ix = $n*2;
  1224. if($ix>=10){
  1225. $nx = 1 + ($ix % 10);
  1226. $total += $nx;
  1227. }else{
  1228. $total += $ix;
  1229. }
  1230. }else{
  1231. $total += $n;
  1232. }
  1233. $i++;
  1234. }
  1235. $total -= $last_n;
  1236. $total *= 9;
  1237. if($last_n == ($total%10)){
  1238. return 1;
  1239. }
  1240. return 0;
  1241. }
  1242. /*
  1243. *收银台接口:三个都要
  1244. *银行卡快捷支付接口:三个都要
  1245. *余额支付接口:基础+API
  1246. *提现接口:基础
  1247. **/
  1248. function risk_item($user_info,$goods_name,$frms_client_chnl =16 )
  1249. {
  1250. return [
  1251. //基本参数中的
  1252. 'frms_ware_category' => 4007 ,
  1253. 'goods_name' => $goods_name ,
  1254. 'user_info_mercht_userno' => $user_info['id'] ,
  1255. 'user_info_dt_register' => date('YmdHis',strtotime($user_info['create_at'])) ,
  1256. 'user_info_bind_phone' => $user_info['phone'] ,
  1257. //实名类参数中的
  1258. 'user_info_full_name' => $user_info['true_name'],
  1259. 'user_info_id_no' => $user_info['id_card'],
  1260. 'user_info_identify_state' => 1,
  1261. 'user_info_identify_type' => 2,
  1262. 'user_info_id_type' => 0,
  1263. //API调用必传参数中的
  1264. 'frms_client_chnl'=>$frms_client_chnl,//业务来源
  1265. 'frms_ip_addr'=> request()->ip(),
  1266. 'user_auth_flag'=>1,
  1267. ];
  1268. }