common.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872
  1. <?php
  2. use fast\Form;
  3. use Think\Db;
  4. if (!function_exists('build_select')) {
  5. /**
  6. * 生成下拉列表
  7. * @param string $name
  8. * @param mixed $options
  9. * @param mixed $selected
  10. * @param mixed $attr
  11. * @return string
  12. */
  13. function build_select($name, $options, $selected = [], $attr = [])
  14. {
  15. $options = is_array($options) ? $options : explode(',', $options);
  16. $selected = is_array($selected) ? $selected : explode(',', $selected);
  17. return Form::select($name, $options, $selected, $attr);
  18. }
  19. }
  20. if (!function_exists('get_table_column')) {
  21. function get_table_column($table,$pk,$column='')
  22. {
  23. $info=Db::name($table)->find($pk);
  24. if($column)
  25. {
  26. return $info[$column];
  27. }else{
  28. return $info;
  29. }
  30. }
  31. }
  32. if (!function_exists('array_sort')) {
  33. function array_sort($array,$row,$type){
  34. $array_temp = array();
  35. foreach($array as $v){
  36. $array_temp[$v[$row]] = $v;
  37. }
  38. if($type == 'asc'){
  39. ksort($array_temp);
  40. }elseif($type == 'desc'){
  41. krsort($array_temp);
  42. }else{
  43. }
  44. return $array_temp;
  45. }
  46. }
  47. if (!function_exists('goeasy_sms')) {
  48. function goeasy_sms($content)
  49. {
  50. $url = 'http://rest-hangzhou.goeasy.io/publish';
  51. $channel="1";
  52. $post_data = array("appkey"=>"BC-d2dd64b1ad024d67aa7a795798961668","channel"=>$channel,"content"=>$content);
  53. php_ajax($url,$post_data);
  54. }
  55. function php_ajax($url, $post_data) {
  56. $postdata = http_build_query($post_data);
  57. $options = array(
  58. 'http' => array(
  59. 'method' => 'POST',
  60. 'header' => 'Content-type:application/x-www-form-urlencoded',
  61. 'content' => $postdata,
  62. 'timeout' => 15 * 60
  63. )
  64. );
  65. $context = stream_context_create($options);
  66. $result = file_get_contents($url, false, $context);
  67. return $result;
  68. }
  69. }
  70. if (!function_exists('curl_api')) {
  71. /**
  72. * curl请求(POST)
  73. * @param $url 请求地址
  74. * @param array $data 请求参数
  75. * @return bool|string 返回结果
  76. * @author laravel开发员
  77. * @date 2019/6/5
  78. */
  79. function curl_api_get($url, $header=[], $timeout=20)
  80. {
  81. // 初始化
  82. $ch = curl_init();
  83. // 设置post方式提交
  84. // curl_setopt($ch, CURLOPT_POST, 1);
  85. // 设置头文件的信息作为数据流输出
  86. curl_setopt($ch, CURLOPT_HEADER, 0);
  87. // 超时
  88. curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
  89. // 是否要求返回数据
  90. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  91. // 请求头
  92. if($header){
  93. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  94. }
  95. // 设置抓取的url
  96. curl_setopt($ch, CURLOPT_URL, $url);
  97. // 是否检测服务器的证书是否由正规浏览器认证过的授权CA颁发的
  98. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  99. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  100. // 执行命令
  101. $result = curl_exec($ch);
  102. // 关闭URL请求(释放句柄)
  103. curl_close($ch);
  104. return $result;
  105. }
  106. }
  107. // 公共助手函数
  108. if (!function_exists('__')) {
  109. /**
  110. * 获取语言变量值
  111. * @param string $name 语言变量名
  112. * @param array $vars 动态变量值
  113. * @param string $lang 语言
  114. * @return mixed
  115. */
  116. function __($name, $vars = [], $lang = '')
  117. {
  118. if (is_numeric($name) || !$name) {
  119. return $name;
  120. }
  121. if (!is_array($vars)) {
  122. $vars = func_get_args();
  123. array_shift($vars);
  124. $lang = '';
  125. }
  126. return \think\Lang::get($name, $vars, $lang);
  127. }
  128. }
  129. if (!function_exists('time_format')) {
  130. function time_format($time = NULL, $format='Y-m-d H:i'){
  131. $time = $time === NULL ? NOW_TIME : intval($time);
  132. return date($format, $time);
  133. }
  134. }
  135. if (!function_exists('get_money_name_byident')) {
  136. /**
  137. * 获取币种名称
  138. * @param unknown $k
  139. * @return Ambigous <>
  140. */
  141. function get_money_name_byident($k){
  142. $money_type_info=Db::name('money_type')->where('identification',"$k")->find();
  143. return $money_type_info['name'];
  144. }
  145. }
  146. if (!function_exists('get_recharge_status')) {
  147. function get_recharge_status($k){
  148. $arr=array('1'=>'审核中','2'=>'已完成','-1'=>'已拒绝');
  149. return $arr[$k];
  150. }
  151. }
  152. function randnumber($k)
  153. {
  154. $str='0123456789';
  155. $code=str_shuffle($str);
  156. return substr($code, 0,$k);
  157. }
  158. if (!function_exists('get_paytype')) {
  159. function get_paytype($k){
  160. $arr=array('1'=>'支付宝','2'=>'微信','3'=>'银行卡');
  161. return $arr[$k];
  162. }
  163. }
  164. if (!function_exists('format_bytes')) {
  165. /**
  166. * 将字节转换为可读文本
  167. * @param int $size 大小
  168. * @param string $delimiter 分隔符
  169. * @return string
  170. */
  171. function format_bytes($size, $delimiter = '')
  172. {
  173. $units = array('B', 'KB', 'MB', 'GB', 'TB', 'PB');
  174. for ($i = 0; $size >= 1024 && $i < 6; $i++) {
  175. $size /= 1024;
  176. }
  177. return round($size, 2) . $delimiter . $units[$i];
  178. }
  179. }
  180. if (!function_exists('datetime')) {
  181. /**
  182. * 将时间戳转换为日期时间
  183. * @param int $time 时间戳
  184. * @param string $format 日期时间格式
  185. * @return string
  186. */
  187. function datetime($time, $format = 'Y-m-d H:i:s')
  188. {
  189. $time = is_numeric($time) ? $time : strtotime($time);
  190. return date($format, $time);
  191. }
  192. }
  193. if (!function_exists('human_date')) {
  194. /**
  195. * 获取语义化时间
  196. * @param int $time 时间
  197. * @param int $local 本地时间
  198. * @return string
  199. */
  200. function human_date($time, $local = null)
  201. {
  202. return \fast\Date::human($time, $local);
  203. }
  204. }
  205. if (!function_exists('cdnurl')) {
  206. /**
  207. * 获取上传资源的CDN的地址
  208. * @param string $url 资源相对地址
  209. * @param boolean $domain 是否显示域名 或者直接传入域名
  210. * @return string
  211. */
  212. function cdnurl($url, $domain = false)
  213. {
  214. $regex = "/^((?:[a-z]+:)?\/\/|data:image\/)(.*)/i";
  215. $url = preg_match($regex, $url) ? $url : \think\Config::get('upload.cdnurl') . $url;
  216. if ($domain && !preg_match($regex, $url)) {
  217. $domain = is_bool($domain) ? request()->domain() : $domain;
  218. $url = $domain . $url;
  219. }
  220. return $url;
  221. }
  222. }
  223. if (!function_exists('is_really_writable')) {
  224. /**
  225. * 判断文件或文件夹是否可写
  226. * @param string $file 文件或目录
  227. * @return bool
  228. */
  229. function is_really_writable($file)
  230. {
  231. if (DIRECTORY_SEPARATOR === '/') {
  232. return is_writable($file);
  233. }
  234. if (is_dir($file)) {
  235. $file = rtrim($file, '/') . '/' . md5(mt_rand());
  236. if (($fp = @fopen($file, 'ab')) === false) {
  237. return false;
  238. }
  239. fclose($fp);
  240. @chmod($file, 0777);
  241. @unlink($file);
  242. return true;
  243. } elseif (!is_file($file) or ($fp = @fopen($file, 'ab')) === false) {
  244. return false;
  245. }
  246. fclose($fp);
  247. return true;
  248. }
  249. }
  250. if (!function_exists('rmdirs')) {
  251. /**
  252. * 删除文件夹
  253. * @param string $dirname 目录
  254. * @param bool $withself 是否删除自身
  255. * @return boolean
  256. */
  257. function rmdirs($dirname, $withself = true)
  258. {
  259. if (!is_dir($dirname)) {
  260. return false;
  261. }
  262. $files = new RecursiveIteratorIterator(
  263. new RecursiveDirectoryIterator($dirname, RecursiveDirectoryIterator::SKIP_DOTS),
  264. RecursiveIteratorIterator::CHILD_FIRST
  265. );
  266. foreach ($files as $fileinfo) {
  267. $todo = ($fileinfo->isDir() ? 'rmdir' : 'unlink');
  268. $todo($fileinfo->getRealPath());
  269. }
  270. if ($withself) {
  271. @rmdir($dirname);
  272. }
  273. return true;
  274. }
  275. }
  276. if (!function_exists('copydirs')) {
  277. /**
  278. * 复制文件夹
  279. * @param string $source 源文件夹
  280. * @param string $dest 目标文件夹
  281. */
  282. function copydirs($source, $dest)
  283. {
  284. if (!is_dir($dest)) {
  285. mkdir($dest, 0755, true);
  286. }
  287. foreach (
  288. $iterator = new RecursiveIteratorIterator(
  289. new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS),
  290. RecursiveIteratorIterator::SELF_FIRST
  291. ) as $item
  292. ) {
  293. if ($item->isDir()) {
  294. $sontDir = $dest . DS . $iterator->getSubPathName();
  295. if (!is_dir($sontDir)) {
  296. mkdir($sontDir, 0755, true);
  297. }
  298. } else {
  299. copy($item, $dest . DS . $iterator->getSubPathName());
  300. }
  301. }
  302. }
  303. }
  304. if (!function_exists('mb_ucfirst')) {
  305. function mb_ucfirst($string)
  306. {
  307. return mb_strtoupper(mb_substr($string, 0, 1)) . mb_strtolower(mb_substr($string, 1));
  308. }
  309. }
  310. if (!function_exists('addtion')) {
  311. /**
  312. * 附加关联字段数据
  313. * @param array $items 数据列表
  314. * @param mixed $fields 渲染的来源字段
  315. * @return array
  316. */
  317. function addtion($items, $fields)
  318. {
  319. if (!$items || !$fields) {
  320. return $items;
  321. }
  322. $fieldsArr = [];
  323. if (!is_array($fields)) {
  324. $arr = explode(',', $fields);
  325. foreach ($arr as $k => $v) {
  326. $fieldsArr[$v] = ['field' => $v];
  327. }
  328. } else {
  329. foreach ($fields as $k => $v) {
  330. if (is_array($v)) {
  331. $v['field'] = isset($v['field']) ? $v['field'] : $k;
  332. } else {
  333. $v = ['field' => $v];
  334. }
  335. $fieldsArr[$v['field']] = $v;
  336. }
  337. }
  338. foreach ($fieldsArr as $k => &$v) {
  339. $v = is_array($v) ? $v : ['field' => $v];
  340. $v['display'] = isset($v['display']) ? $v['display'] : str_replace(['_ids', '_id'], ['_names', '_name'], $v['field']);
  341. $v['primary'] = isset($v['primary']) ? $v['primary'] : '';
  342. $v['column'] = isset($v['column']) ? $v['column'] : 'name';
  343. $v['model'] = isset($v['model']) ? $v['model'] : '';
  344. $v['table'] = isset($v['table']) ? $v['table'] : '';
  345. $v['name'] = isset($v['name']) ? $v['name'] : str_replace(['_ids', '_id'], '', $v['field']);
  346. }
  347. unset($v);
  348. $ids = [];
  349. $fields = array_keys($fieldsArr);
  350. foreach ($items as $k => $v) {
  351. foreach ($fields as $m => $n) {
  352. if (isset($v[$n])) {
  353. $ids[$n] = array_merge(isset($ids[$n]) && is_array($ids[$n]) ? $ids[$n] : [], explode(',', $v[$n]));
  354. }
  355. }
  356. }
  357. $result = [];
  358. foreach ($fieldsArr as $k => $v) {
  359. if ($v['model']) {
  360. $model = new $v['model'];
  361. } else {
  362. //$model = $v['name'] ? \think\Db::name($v['name']) : \think\Db::table($v['table']);
  363. }
  364. $primary = $v['primary'] ? $v['primary'] : $model->getPk();
  365. $result[$v['field']] = $model->where($primary, 'in', $ids[$v['field']])->column("{$primary},{$v['column']}");
  366. }
  367. foreach ($items as $k => &$v) {
  368. foreach ($fields as $m => $n) {
  369. if (isset($v[$n])) {
  370. $curr = array_flip(explode(',', $v[$n]));
  371. $v[$fieldsArr[$n]['display']] = implode(',', array_intersect_key($result[$n], $curr));
  372. }
  373. }
  374. }
  375. return $items;
  376. }
  377. }
  378. if (!function_exists('var_export_short')) {
  379. /**
  380. * 返回打印数组结构
  381. * @param string $var 数组
  382. * @param string $indent 缩进字符
  383. * @return string
  384. */
  385. function var_export_short($var, $indent = "")
  386. {
  387. switch (gettype($var)) {
  388. case "string":
  389. return '"' . addcslashes($var, "\\\$\"\r\n\t\v\f") . '"';
  390. case "array":
  391. $indexed = array_keys($var) === range(0, count($var) - 1);
  392. $r = [];
  393. foreach ($var as $key => $value) {
  394. $r[] = "$indent "
  395. . ($indexed ? "" : var_export_short($key) . " => ")
  396. . var_export_short($value, "$indent ");
  397. }
  398. return "[\n" . implode(",\n", $r) . "\n" . $indent . "]";
  399. case "boolean":
  400. return $var ? "TRUE" : "FALSE";
  401. default:
  402. return var_export($var, true);
  403. }
  404. }
  405. }
  406. if (!function_exists('mbsubstr')) {
  407. function mbsubstr($str, $start = 0, $length, $charset = "utf-8", $suffix = true)
  408. {
  409. if (function_exists("mb_substr")) {
  410. $slice = mb_substr($str, $start, $length, $charset);
  411. } elseif (function_exists('iconv_substr')) {
  412. $slice = iconv_substr($str, $start, $length, $charset);
  413. } else {
  414. $re['utf-8'] = "/[x01-x7f]|[xc2-xdf][x80-xbf]|[xe0-xef][x80-xbf]{2}|[xf0-xff][x80-xbf]{3}/";
  415. $re['gb2312'] = "/[x01-x7f]|[xb0-xf7][xa0-xfe]/";
  416. $re['gbk'] = "/[x01-x7f]|[x81-xfe][x40-xfe]/";
  417. $re['big5'] = "/[x01-x7f]|[x81-xfe]([x40-x7e]|xa1-xfe])/";
  418. preg_match_all($re[$charset], $str, $match);
  419. $slice = join("", array_slice($match[0], $start, $length));
  420. }
  421. $fix = '';
  422. if (strlen($slice) < strlen($str)) {
  423. $fix = '...';
  424. }
  425. return $suffix ? $slice . $fix : $slice;
  426. }
  427. }
  428. if (!function_exists('letter_avatar')) {
  429. /**
  430. * 首字母头像
  431. * @param $text
  432. * @return string
  433. */
  434. function letter_avatar($text)
  435. {
  436. $total = unpack('L', hash('adler32', $text, true))[1];
  437. $hue = $total % 360;
  438. list($r, $g, $b) = hsv2rgb($hue / 360, 0.3, 0.9);
  439. $bg = "rgb({$r},{$g},{$b})";
  440. $color = "#ffffff";
  441. $first = mb_strtoupper(mb_substr($text, 0, 1));
  442. $src = base64_encode('<svg xmlns="http://www.w3.org/2000/svg" version="1.1" height="100" width="100"><rect fill="' . $bg . '" x="0" y="0" width="100" height="100"></rect><text x="50" y="50" font-size="50" text-copy="fast" fill="' . $color . '" text-anchor="middle" text-rights="admin" alignment-baseline="central">' . $first . '</text></svg>');
  443. $value = 'data:image/svg+xml;base64,' . $src;
  444. return $value;
  445. }
  446. }
  447. if (!function_exists('hsv2rgb')) {
  448. function hsv2rgb($h, $s, $v)
  449. {
  450. $r = $g = $b = 0;
  451. $i = floor($h * 6);
  452. $f = $h * 6 - $i;
  453. $p = $v * (1 - $s);
  454. $q = $v * (1 - $f * $s);
  455. $t = $v * (1 - (1 - $f) * $s);
  456. switch ($i % 6) {
  457. case 0:
  458. $r = $v;
  459. $g = $t;
  460. $b = $p;
  461. break;
  462. case 1:
  463. $r = $q;
  464. $g = $v;
  465. $b = $p;
  466. break;
  467. case 2:
  468. $r = $p;
  469. $g = $v;
  470. $b = $t;
  471. break;
  472. case 3:
  473. $r = $p;
  474. $g = $q;
  475. $b = $v;
  476. break;
  477. case 4:
  478. $r = $t;
  479. $g = $p;
  480. $b = $v;
  481. break;
  482. case 5:
  483. $r = $v;
  484. $g = $p;
  485. $b = $q;
  486. break;
  487. }
  488. return [
  489. floor($r * 255),
  490. floor($g * 255),
  491. floor($b * 255)
  492. ];
  493. }
  494. }
  495. if(!function_exists('get_config_value'))
  496. {
  497. function get_config_value($str){
  498. $data_arr=explode('-',$str);
  499. //字段
  500. $data_zd=$data_arr['0'];
  501. //id
  502. $data_id=$data_arr['1'];
  503. //模型
  504. $data_mod=$data_arr['2'];
  505. if(empty($data_mod)){
  506. $data_mod="bonus_config";
  507. }
  508. $info=Db::name($data_mod)->where('id',$data_id)->find();
  509. return $info[$data_zd];
  510. }
  511. }
  512. function get_user_level_text($k)
  513. {
  514. $info=db('user_level')->where(['id'=>$k])->find();
  515. return $info['name'];
  516. }
  517. /**
  518. * 获取密码加密后的字符串
  519. * @param string $password 密码
  520. * @param string $salt 密码盐
  521. * @return string
  522. */
  523. if(!function_exists('getEncryptPassword'))
  524. {
  525. function getEncryptPassword($password, $salt = '')
  526. {
  527. return md5(md5($password) . $salt);
  528. }
  529. }
  530. function sendmsg($mobile,$content)
  531. {
  532. $url="http://dx.ipyy.net/sms.aspx?action=send&userid=&account=gxfc0430&password=49ur8t58yy6&mobile=".$mobile."&content=".$content;
  533. //初始化curl
  534. $ch = curl_init();
  535. curl_setopt($ch,CURLOPT_URL, $url);
  536. //设置header
  537. curl_setopt($ch, CURLOPT_HEADER, FALSE);
  538. //要求结果为字符串且输出到屏幕上
  539. curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  540. //post提交方式mobileVerify
  541. //运行curl
  542. $data = curl_exec($ch);
  543. $arr=xmlToArray($data);
  544. file_put_contents('1.txt',json_encode($arr));
  545. return $arr;
  546. //返回结果
  547. if($arr['returnstatus'] == 'Success'){
  548. return true;
  549. }else{
  550. return $arr;
  551. }
  552. }
  553. function xmlToArray($xml){
  554. //禁止引用外部xml实体
  555. libxml_disable_entity_loader(true);
  556. $xmlstring = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA);
  557. $val = json_decode(json_encode($xmlstring),true);
  558. return $val;
  559. }
  560. if(!function_exists('check_psdtwo'))
  561. {
  562. function check_psdtwo($pwd,$uid)
  563. {
  564. $info=get_user_data($uid);
  565. if(getEncryptPassword($pwd,$info['salt']) != $info['password2'])
  566. {
  567. return false;
  568. }else{
  569. return true;
  570. }
  571. }
  572. }
  573. if(!function_exists('caiwu'))
  574. {
  575. function caiwu($data,$money_type)
  576. {
  577. $last=Db::name('detailed_'.strtolower($money_type))->where(['userid'=>$data['userid']])->order('id desc')->find();
  578. if($last)
  579. {
  580. $balance=$last['balance']+$data['money'];
  581. }else{
  582. $user=Db::name('user')->where('id',$data['userid'])->find();
  583. $balance=$user[$money_type]+$data['money'];
  584. }
  585. $changedata=[
  586. 'userid'=>$data['userid'],
  587. 'type'=>$data['type'],
  588. 'money'=>$data['money'],
  589. 'balance'=>$balance,
  590. 'relevant_userid'=>$data['relevant_userid'],
  591. 'status'=>1,
  592. 'create_time'=>time(),
  593. 'remark'=>$data['remark'],
  594. 'user_name'=>get_user_data($data['userid'],'username'),
  595. 'relevant_name'=>$data['relevant_userid']>0?get_user_data($data['relevant_userid'],'username'):'系统',
  596. ];
  597. $ids=Db::name('detailed_'.strtolower($money_type))->insertGetId($changedata);
  598. if($ids)
  599. {
  600. $iden=get_identification_by_type($changedata['type']);
  601. $userbalance[$money_type]=$changedata['balance'];
  602. Db::name('user')->where('id',$changedata['userid'])->update($userbalance);
  603. finance($changedata['type'], $changedata['money']);
  604. bonus_count($changedata['type'], $changedata['money'], $changedata['userid']);
  605. return true;
  606. }else{
  607. return false;
  608. }
  609. }
  610. }
  611. /*推荐奖*/
  612. function bonusorder($userid,$money)
  613. {
  614. $user=db('user')->where(['id'=>$userid])->find();
  615. db('user')->where(['id'=>$userid])->setInc("reg_money",$money);
  616. if($user['refereeid']>0)
  617. {
  618. db('user')->where(['id'=>['in',$user['refereeids']]])->setInc("total_pv",$money);
  619. $bcf=db('bonus_config')->where(['id'=>3])->find();
  620. if($bcf) {
  621. $bonusMoney = round($money * $bcf['value'] * 0.01, 2);
  622. if ($bonusMoney > 0) {
  623. $changedata = [
  624. 'type' => 16,
  625. 'money' => $bonusMoney,
  626. 'userid' =>$user['refereeid'],
  627. 'relevant_userid' => $userid,
  628. 'remark' => $user['mobile'] . '竞拍' . $money . '元藏品推荐人得奖励:' . $bonusMoney,
  629. ];
  630. caiwu($changedata, 'bonus');
  631. db('user')->where(['id'=>$user['refereeid']])->setInc("total_bonus",$bonusMoney);
  632. }
  633. }
  634. }
  635. }
  636. function addtrade($gid)
  637. {
  638. $goodsinfo=db('goods')->where(['id'=>$gid])->find();
  639. if($goodsinfo['topprice']<=$goodsinfo['price1'])
  640. {
  641. $sum=0;
  642. for($i=1;$i<=(int)$goodsinfo['son_nums'];$i++)
  643. {
  644. if($i < (int)$goodsinfo['son_nums'])
  645. {
  646. $price=round(($goodsinfo['price1']/$goodsinfo['son_nums']),0);
  647. $sum+=$price;
  648. }else{
  649. $price=$goodsinfo['price1']-$sum;
  650. }
  651. $data=[
  652. 'catid'=>$goodsinfo['catid'],
  653. 'title'=>$goodsinfo['title'].$i,
  654. 'description'=>$goodsinfo['description'],
  655. 'content'=>$goodsinfo['content'],
  656. 'image'=>$goodsinfo['image'],
  657. 'images'=>$goodsinfo['images'],
  658. 'on_sale'=>0,
  659. 'price'=>$price,
  660. 'price1'=>$price,
  661. 'topprice'=>$goodsinfo['topprice'],
  662. 'son_nums'=>$goodsinfo['son_nums'],
  663. 'utime'=>time(),
  664. 'isnew'=>1,
  665. 'istrade'=>0,
  666. 'stuid'=>$goodsinfo['stuid'],
  667. 'userid'=>$goodsinfo['userid'],
  668. ];
  669. $ids=db('goods')->insertGetId($data);
  670. }
  671. db('goods')->where(['id'=>$goodsinfo['id']])->update(['on_sale'=>0,'price1'=>0,'price'=>0]);
  672. db('trade')->where(['goodsid'=>$goodsinfo['id'],'status'=>3])->update(['isout'=>1]);
  673. }
  674. }
  675. if(!function_exists('get_user_data'))
  676. {
  677. function get_user_data($userid,$field='')
  678. {
  679. $info=Db::name('user')->where('id',$userid)->find();
  680. if(empty($field))
  681. {
  682. return $info;
  683. }else{
  684. return $info[$field];
  685. }
  686. }
  687. }
  688. function get_user_info($userid,$field1='',$field2='')
  689. {
  690. $info=db('user')->where('id',$userid)->find();
  691. return $info[$field1].'('.$info[$field2].')';
  692. }
  693. if(!function_exists('finance'))
  694. {
  695. /* 公司收入-支出 */
  696. function finance($changetype,$money){
  697. $today=strtotime('today');
  698. $money=abs($money);
  699. $map = ['ctime'=>$today];
  700. $info=Db::name("finance")->where($map)->find();
  701. $expend_arr =Db::name('bonus_type')->where('status',1)->column('type');//奖金支出
  702. $income_arr = array('1');
  703. if(!empty($info)){
  704. if(in_array($changetype, $expend_arr)){
  705. $data['expend']=$info['expend']+$money;
  706. }elseif(in_array($changetype, $income_arr)){
  707. $data['income']=$info['income']+$money;
  708. }
  709. if(!empty($data)){
  710. Db::name("finance")->where($map)->update($data);
  711. }
  712. }else{
  713. $data['ctime']=$today;
  714. if(in_array($changetype, $expend_arr)){
  715. $data['expend']=$money;
  716. }elseif(in_array($changetype, $income_arr)){
  717. $data['income']=$money;
  718. }
  719. if(!empty($data)){
  720. Db::name("finance")->insertGetId($data);
  721. }
  722. }
  723. }
  724. }
  725. if(!function_exists('bonus_count'))
  726. {
  727. function bonus_count($changetype,$money,$userid)
  728. {
  729. $count_date=strtotime('today');
  730. $typemap=Db::name('bonus_type')->where(array('status'=>1))->column('type');
  731. $countinfo=Db::name("bonus_count")->where(['statistime'=>$count_date,'userid'=>$userid])->find();
  732. if($countinfo)
  733. {
  734. if(in_array($changetype, $typemap)){
  735. $iden=get_identification_by_type($changetype);
  736. $data[$iden]=$countinfo[$iden]+$money;
  737. $data['total']=$countinfo['total']+$money;
  738. $data['cumulative']=$countinfo['cumulative']+$money;
  739. Db::name("bonus_count")->where(['statistime'=>$count_date,'userid'=>$userid])->update($data);
  740. }
  741. }else{
  742. if(in_array($changetype, $typemap)){
  743. $iden=get_identification_by_type($changetype);
  744. $data[$iden]=$money;
  745. $data['total']=$money;
  746. $data['statistime']=$count_date;
  747. $data['userid']=$userid;
  748. $data['username']=get_user_data($userid,'username');
  749. $lastCount=Db::name('bonus_count')->where(['statistime'=>['lt',$count_date],'userid'=>$userid])->order('id desc')->find();
  750. if($lastCount)
  751. {
  752. $data['cumulative']=$lastCount['cumulative']+$money;
  753. }else{
  754. $data['cumulative']=$money;
  755. }
  756. Db::name("bonus_count")->insertGetId($data);
  757. }
  758. }
  759. }
  760. }
  761. if(!function_exists('get_identification_by_type'))
  762. {
  763. function get_identification_by_type($type)
  764. {
  765. $info=Db::name("bonus_type")->where('type',$type)->find();
  766. return $info['identification'];
  767. }
  768. }
  769. if(!function_exists('get_detailed_type_text'))
  770. {
  771. function get_detailed_type_text($k){
  772. $info=Db::name('detailed_type')->where('id',$k)->find();
  773. return $info['title'];
  774. }
  775. }
  776. if(!function_exists('list_to_arr'))
  777. {
  778. $arr=[];
  779. function list_to_arr($list,$k,$v){
  780. foreach ($list as $vo){
  781. $arr[$vo[$k]]=$vo[$v]?$vo[$v]:0;
  782. }
  783. return $arr;
  784. }
  785. }
  786. if(!function_exists('put_file_from_url_content'))
  787. {
  788. function put_file_from_url_content($url, $saveName, $path) {
  789. // 设置运行时间为无限制
  790. set_time_limit ( 0 );
  791. $url = trim ( $url );
  792. $curl = curl_init ();
  793. // 设置你需要抓取的URL
  794. curl_setopt ( $curl, CURLOPT_URL, $url );
  795. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
  796. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
  797. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  798. // 设置header
  799. //curl_setopt ( $curl, CURLOPT_HEADER, 0 );
  800. // 设置cURL 参数,要求结果保存到字符串中还是输出到屏幕上。
  801. //curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, 1 );
  802. // 运行cURL,请求网页
  803. $file = curl_exec ( $curl );
  804. // 关闭URL请求
  805. curl_close ( $curl );
  806. // 将文件写入获得的数据
  807. $filename = $path . $saveName;
  808. $write = @fopen ( $filename, "w" );
  809. if ($write == false) {
  810. return false;
  811. }
  812. if (fwrite ( $write, $file ) == false) {
  813. return false;
  814. }
  815. if (fclose ( $write ) == false) {
  816. return false;
  817. }
  818. }
  819. }