common.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875
  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. $where = ['userid'=>$data['userid']];
  578. $last=Db::name('detailed_'.strtolower($money_type))->where($where)->order('id desc')->find();
  579. if($last)
  580. {
  581. $balance=$last['balance']+$data['money'];
  582. }else{
  583. $user=Db::name('user')->where('id',$data['userid'])->find();
  584. $balance=$user[$money_type]+$data['money'];
  585. }
  586. $changedata=[
  587. 'userid'=>$data['userid'],
  588. 'type'=>$data['type'],
  589. 'money'=>$data['money'],
  590. 'balance'=>$balance,
  591. 'relevant_userid'=>$data['relevant_userid'],
  592. 'status'=>1,
  593. 'create_time'=>time(),
  594. 'remark'=>$data['remark'],
  595. 'user_name'=>get_user_data($data['userid'],'username'),
  596. 'relevant_name'=>$data['relevant_userid']>0?get_user_data($data['relevant_userid'],'username'):'系统',
  597. ];
  598. $ids=Db::name('detailed_'.strtolower($money_type))->insertGetId($changedata);
  599. if($ids)
  600. {
  601. $iden=get_identification_by_type($changedata['type']);
  602. $userbalance[$money_type]=$changedata['balance'];
  603. Db::name('user')->where('id',$changedata['userid'])->update($userbalance);
  604. finance($changedata['type'], $changedata['money']);
  605. bonus_count($changedata['type'], $changedata['money'], $changedata['userid']);
  606. return true;
  607. }else{
  608. return false;
  609. }
  610. }
  611. }
  612. /*推荐奖*/
  613. function bonusorder($userid,$money)
  614. {
  615. $user=db('user')->where(['id'=>$userid])->find();
  616. db('user')->where(['id'=>$userid])->setInc("reg_money",$money);
  617. if($user['refereeid']>0)
  618. {
  619. db('user')->where(['id'=>['in',$user['refereeids']]])->setInc("total_pv",$money);
  620. $bcf=db('bonus_config')->where(['id'=>3])->find();
  621. if($bcf) {
  622. $bonusMoney = round($money * $bcf['value'] * 0.01, 2);
  623. if ($bonusMoney > 0) {
  624. $changedata = [
  625. 'type' => 16,
  626. 'money' => $bonusMoney,
  627. 'userid' =>$user['refereeid'],
  628. 'relevant_userid' => $userid,
  629. 'remark' => $user['mobile'] . '竞拍' . $money . '元藏品推荐人得奖励:' . $bonusMoney,
  630. ];
  631. caiwu($changedata, 'bonus');
  632. db('user')->where(['id'=>$user['refereeid']])->setInc("total_bonus",$bonusMoney);
  633. }
  634. }
  635. }
  636. }
  637. function addtrade($gid)
  638. {
  639. $goodsinfo=db('goods')->where(['id'=>$gid])->find();
  640. if($goodsinfo['topprice']<=$goodsinfo['price1'])
  641. {
  642. $sum=0;
  643. for($i=1;$i<=(int)$goodsinfo['son_nums'];$i++)
  644. {
  645. if($i < (int)$goodsinfo['son_nums'])
  646. {
  647. $price=round(($goodsinfo['price1']/$goodsinfo['son_nums']),0);
  648. $sum+=$price;
  649. }else{
  650. $price=$goodsinfo['price1']-$sum;
  651. }
  652. $data=[
  653. 'catid'=>$goodsinfo['catid'],
  654. 'title'=>$goodsinfo['title'].$i,
  655. 'description'=>$goodsinfo['description'],
  656. 'content'=>$goodsinfo['content'],
  657. 'image'=>$goodsinfo['image'],
  658. 'images'=>$goodsinfo['images'],
  659. 'on_sale'=>0,
  660. 'price'=>$price,
  661. 'price1'=>$price,
  662. 'topprice'=>$goodsinfo['topprice'],
  663. 'son_nums'=>$goodsinfo['son_nums'],
  664. 'utime'=>time(),
  665. 'isnew'=>1,
  666. 'istrade'=>0,
  667. 'stuid'=>$goodsinfo['stuid'],
  668. 'userid'=>$goodsinfo['userid'],
  669. ];
  670. $ids=db('goods')->insertGetId($data);
  671. }
  672. db('goods')->where(['id'=>$goodsinfo['id']])->update(['on_sale'=>0,'price1'=>0,'price'=>0]);
  673. db('trade')->where(['goodsid'=>$goodsinfo['id'],'status'=>3])->update(['isout'=>1]);
  674. }
  675. }
  676. if(!function_exists('get_user_data'))
  677. {
  678. function get_user_data($userid,$field='')
  679. {
  680. $info=Db::name('user')->where('id',$userid)->find();
  681. if(empty($field))
  682. {
  683. return $info;
  684. }else{
  685. return $info[$field];
  686. }
  687. }
  688. }
  689. function get_user_info($userid,$field1='',$field2='')
  690. {
  691. $info=db('user')->where('id',$userid)->find();
  692. return $info[$field1].'('.$info[$field2].')';
  693. }
  694. if(!function_exists('finance'))
  695. {
  696. /* 公司收入-支出 */
  697. function finance($changetype,$money){
  698. $today=strtotime('today');
  699. $money=abs($money);
  700. $map = ['ctime'=>$today];
  701. $info=Db::name("finance")->where($map)->find();
  702. $expend_arr =Db::name('bonus_type')->where('status',1)->column('type');//奖金支出
  703. $income_arr = array('1');
  704. if(!empty($info)){
  705. if(in_array($changetype, $expend_arr)){
  706. $data['expend']=$info['expend']+$money;
  707. }elseif(in_array($changetype, $income_arr)){
  708. $data['income']=$info['income']+$money;
  709. }
  710. if(!empty($data)){
  711. Db::name("finance")->where($map)->update($data);
  712. }
  713. }else{
  714. $data['ctime']=$today;
  715. if(in_array($changetype, $expend_arr)){
  716. $data['expend']=$money;
  717. }elseif(in_array($changetype, $income_arr)){
  718. $data['income']=$money;
  719. }
  720. if(!empty($data)){
  721. Db::name("finance")->insertGetId($data);
  722. }
  723. }
  724. }
  725. }
  726. if(!function_exists('bonus_count'))
  727. {
  728. function bonus_count($changetype,$money,$userid)
  729. {
  730. $count_date=strtotime('today');
  731. $typemap=Db::name('bonus_type')->where(array('status'=>1))->column('type');
  732. $countinfo=Db::name("bonus_count")->where(['statistime'=>$count_date,'userid'=>$userid])->find();
  733. if($countinfo)
  734. {
  735. if(in_array($changetype, $typemap)){
  736. $iden=get_identification_by_type($changetype);
  737. $data[$iden]=$countinfo[$iden]+$money;
  738. $data['total']=$countinfo['total']+$money;
  739. $data['cumulative']=$countinfo['cumulative']+$money;
  740. Db::name("bonus_count")->where(['statistime'=>$count_date,'userid'=>$userid])->update($data);
  741. }
  742. }else{
  743. if(in_array($changetype, $typemap)){
  744. $iden=get_identification_by_type($changetype);
  745. $data[$iden]=$money;
  746. $data['total']=$money;
  747. $data['statistime']=$count_date;
  748. $data['userid']=$userid;
  749. $data['username']=get_user_data($userid,'username');
  750. $lastCount=Db::name('bonus_count')->where(['statistime'=>['lt',$count_date],'userid'=>$userid])->order('id desc')->find();
  751. if($lastCount)
  752. {
  753. $data['cumulative']=$lastCount['cumulative']+$money;
  754. }else{
  755. $data['cumulative']=$money;
  756. }
  757. Db::name("bonus_count")->insertGetId($data);
  758. }
  759. }
  760. }
  761. }
  762. if(!function_exists('get_identification_by_type'))
  763. {
  764. function get_identification_by_type($type)
  765. {
  766. $info=Db::name("bonus_type")->where('type',$type)->find();
  767. return $info['identification'];
  768. }
  769. }
  770. if(!function_exists('get_detailed_type_text'))
  771. {
  772. function get_detailed_type_text($k){
  773. $info=Db::name('detailed_type')->where('id',$k)->find();
  774. return $info['title'];
  775. }
  776. }
  777. if(!function_exists('list_to_arr'))
  778. {
  779. $arr=[];
  780. function list_to_arr($list,$k,$v){
  781. foreach ($list as $vo){
  782. $arr[$vo[$k]]=$vo[$v]?$vo[$v]:0;
  783. }
  784. return $arr;
  785. }
  786. }
  787. if(!function_exists('put_file_from_url_content'))
  788. {
  789. function put_file_from_url_content($url, $saveName, $path) {
  790. // 设置运行时间为无限制
  791. set_time_limit ( 0 );
  792. $url = trim ( $url );
  793. $curl = curl_init ();
  794. // 设置你需要抓取的URL
  795. curl_setopt ( $curl, CURLOPT_URL, $url );
  796. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
  797. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
  798. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  799. // 设置header
  800. //curl_setopt ( $curl, CURLOPT_HEADER, 0 );
  801. // 设置cURL 参数,要求结果保存到字符串中还是输出到屏幕上。
  802. //curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, 1 );
  803. // 运行cURL,请求网页
  804. $file = curl_exec ( $curl );
  805. //var_dump($file);
  806. // 关闭URL请求
  807. curl_close ( $curl );
  808. // 将文件写入获得的数据
  809. $filename = $path . $saveName;
  810. $write = @fopen ( $filename, "w" );
  811. if ($write == false) {
  812. return false;
  813. }
  814. if (fwrite ( $write, $file ) == false) {
  815. return false;
  816. }
  817. if (fclose ( $write ) == false) {
  818. return false;
  819. }
  820. }
  821. }