common.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkPHP [ WE CAN DO IT JUST THINK ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: 流年 <liu21st@gmail.com>
  10. // +----------------------------------------------------------------------
  11. // 应用公共文件
  12. /**
  13. * 获取用户名称
  14. * @param $uid
  15. * @return mixed
  16. */
  17. function getUserNickname($uid){
  18. return \app\admin\model\user\User::where('uid',$uid)->value('nickname');
  19. }
  20. /**
  21. * 获取产品名称
  22. * @param $id
  23. * @return mixed
  24. */
  25. function getProductName($id){
  26. return \app\admin\model\store\StoreProduct::where('id',$id)->value('store_name');
  27. }
  28. /**
  29. * 获取拼团名称
  30. * @param $id
  31. * @return mixed
  32. */
  33. function getCombinationTitle($id){
  34. return \app\admin\model\store\StoreCombination::where('id',$id)->value('title');
  35. }
  36. /**
  37. * 获取订单编号
  38. * @param $id
  39. */
  40. function getOrderId($id){
  41. return \app\admin\model\order\StoreOrder::where('id',$id)->value('order_id');
  42. }
  43. /**
  44. * 根据用户uid获取订单数
  45. * @param $uid
  46. * @return int|string
  47. */
  48. function getOrderCount($uid){
  49. return \app\admin\model\order\StoreOrder::where('uid',$uid)->where('paid',1)->where('refund_status',0)->where('status',2)->count();
  50. }
  51. /**
  52. * 格式化属性
  53. * @param $arr
  54. * @return array
  55. */
  56. function attrFormat($arr){
  57. $data = [];
  58. $res = [];
  59. if(count($arr) > 1){
  60. for ($i=0; $i < count($arr)-1; $i++) {
  61. if($i == 0) $data = $arr[$i]['detail'];
  62. //替代变量1
  63. $rep1 = [];
  64. foreach ($data as $v) {
  65. foreach ($arr[$i+1]['detail'] as $g) {
  66. //替代变量2
  67. $rep2 = ($i!=0?'':$arr[$i]['value']."_").$v."-".$arr[$i+1]['value']."_".$g;
  68. $tmp[] = $rep2;
  69. if($i==count($arr)-2){
  70. foreach (explode('-', $rep2) as $k => $h) {
  71. //替代变量3
  72. $rep3 = explode('_', $h);
  73. //替代变量4
  74. $rep4['detail'][$rep3[0]] = $rep3[1];
  75. }
  76. $res[] = $rep4;
  77. }
  78. }
  79. }
  80. $data = $tmp;
  81. }
  82. }else{
  83. $dataArr = [];
  84. foreach ($arr as $k=>$v){
  85. foreach ($v['detail'] as $kk=>$vv){
  86. $dataArr[$kk] = $v['value'].'_'.$vv;
  87. $res[$kk]['detail'][$v['value']] = $vv;
  88. }
  89. }
  90. $data[] = implode('-',$dataArr);
  91. }
  92. return [$data,$res];
  93. }
  94. function getMonth($time='',$ceil=0){
  95. if(empty($time)){
  96. $firstday = date("Y-m-01",time());
  97. $lastday = date("Y-m-d",strtotime("$firstday +1 month -1 day"));
  98. }else if($time=='n'){
  99. if($ceil!=0)
  100. $season = ceil(date('n') /3)-$ceil;
  101. else
  102. $season = ceil(date('n') /3);
  103. $firstday=date('Y-m-01',mktime(0,0,0,($season - 1) *3 +1,1,date('Y')));
  104. $lastday=date('Y-m-t',mktime(0,0,0,$season * 3,1,date('Y')));
  105. }else if($time=='y'){
  106. $firstday=date('Y-01-01');
  107. $lastday=date('Y-12-31');
  108. }else if($time=='h'){
  109. $firstday = date('Y-m-d', strtotime('this week +'.$ceil.' day')) . ' 00:00:00';
  110. $lastday = date('Y-m-d', strtotime('this week +'.($ceil+1).' day')) . ' 23:59:59';
  111. }
  112. return array($firstday,$lastday);
  113. }