common.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. /**
  3. * @param string $address 地址
  4. * @return array
  5. */
  6. use think\Db;
  7. use Dm\Request\V20151123 as Dm;
  8. /**
  9. * 秒转换为天
  10. */
  11. function get_stay_time($remain_time, $is_hour = 1, $is_minutes = 1)
  12. {
  13. $day = floor($remain_time / (3600*24));
  14. $day = $day > 0 ? $day.'天' : '';
  15. $hour = floor(($remain_time % (3600*24)) / 3600);
  16. $hour = $hour > 0 ? $hour.'小时' : '';
  17. if($is_hour && $is_minutes) {
  18. $minutes = floor((($remain_time % (3600*24)) % 3600) / 60);
  19. $minutes = $minutes > 0 ? $minutes.'分钟' : '';
  20. return $day.$hour.$minutes;
  21. }
  22. if($hour) {
  23. return $day.$hour;
  24. }
  25. return $day;
  26. }
  27. /**
  28. * get请求
  29. * @param $url
  30. * @param string $msg
  31. * @return mixed
  32. */
  33. function requestGet($url , $msg = ''){
  34. // 1. 初始化一个cURL会话
  35. $ch = curl_init();
  36. //设置选项,包括URL
  37. curl_setopt($ch, CURLOPT_URL, $url);
  38. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  39. curl_setopt($ch, CURLOPT_HEADER, 0);
  40. //执行并获取HTML文档内容
  41. $response = curl_exec($ch);
  42. // 4. 释放cURL句柄,关闭一个cURL会话
  43. curl_close($ch);
  44. return $response;
  45. }
  46. //获取全图片地址 $image_data
  47. function image_path($image_data){
  48. if(empty($image_data)){
  49. return $image_data;
  50. }
  51. if (strpos($image_data,'|')!==false){
  52. $image_res = explode('|',$image_data);
  53. }elseif(strpos($image_data,',')!==false){
  54. $image_res = explode(',',$image_data);
  55. }else{
  56. $image_res = array($image_data);
  57. }
  58. return $image_res;
  59. }
  60. function get_order_sn(){
  61. $order_id_main = date('YmdHis') . rand(10000000,99999999);
  62. $order_id_len = strlen($order_id_main);
  63. $order_id_sum = 0;
  64. for($i=0; $i<$order_id_len; $i++){
  65. $order_id_sum += (int)(substr($order_id_main,$i,1));
  66. }
  67. $osn = $order_id_main . str_pad((100 - $order_id_sum % 100) % 100,2,'0',STR_PAD_LEFT);
  68. return $osn;
  69. }
  70. //通过服务类型,手机型号获取价格
  71. function get_goods_price($goods_id,$serve_type_id,$phone_type_id = 0){
  72. $goods_info = Db::name('store_goods')->field('id,cate_id')->where('status',1)->where('id',$goods_id)->where('is_deleted',0)->find();
  73. if(empty($goods_info)){
  74. $this->error('服务信息有误');
  75. }
  76. $data = array('code'=>1,'msg'=>'获取成功');
  77. if($goods_info['cate_id'] == 0){ //金刚区服务
  78. if(empty($phone_type_id)){
  79. $data['code'] = 0;
  80. $data['msg'] = '参数错误';
  81. }
  82. $serve_type_name = Db::name('store_goods_type')->where('id',$serve_type_id)->value('spec_name');
  83. $phone_type_name = Db::name('store_goods_type')->where('id',$phone_type_id)->value('spec_name');
  84. $goods_price = Db::name('store_goods_list')->where('goods_id',$goods_id)->where('goods_spec','like','%'.$serve_type_name.'%')->where('goods_spec','like','%'.$phone_type_name.'%')->value('price_selling');
  85. }else{
  86. $serve_type_name = Db::name('store_goods_type')->where('id',$serve_type_id)->value('spec_name');
  87. $goods_price = Db::name('store_goods_list')->where('goods_id',$goods_id)->where('goods_spec','like','%'.$serve_type_name.'%')->value('price_selling');
  88. }
  89. if($goods_price <= 0){
  90. $data['code'] = 0;
  91. $data['msg'] = '价格信息有误';
  92. }
  93. $data['price'] = $goods_price;
  94. return $data;
  95. }
  96. //邮箱推送
  97. function mail_push($mail_str,$order_id){
  98. //查询订单信息
  99. $order_info = Db::name('store_order')->field('goods_id,serve_type,client_tel,client_qq,price_amount,describe,create_at')->where('id',$order_id)->find();
  100. $order_info['goods_title'] = Db::name('store_goods')->where('id',$order_info['goods_id'])->value('title');
  101. $body = "服务类目:".$order_info['goods_title']."<br/>服务类型:".$order_info['serve_type']."<br/>用户手机:".$order_info['client_tel']."<br/>用户QQ:".$order_info['client_qq']."<br/>订单金额:".$order_info['price_amount']."<br/>附加信息:".$order_info['describe']."<br/>下单时间:".$order_info['create_at'];
  102. require_once env('root_path').'/vendor/aliyunmail/aliyun-php-sdk-core/Config.php';
  103. //需要设置对应的region名称,如华东1(杭州)设为cn-hangzhou,新加坡Region设为ap-southeast-1,澳洲Region设为ap-southeast-2。
  104. $iClientProfile = DefaultProfile::getProfile("cn-hangzhou", "LTAI5tSMNtYuD3TdEkM65fyp", "lcmARfziFDS4PUJ0K7AKTf3Ytl3Z8O");
  105. $client = new DefaultAcsClient($iClientProfile);
  106. $request = new Dm\SingleSendMailRequest();
  107. $request->setAccountName("feisu@tsguangsu.com");
  108. $request->setFromAlias("飞速");
  109. $request->setAddressType(1);
  110. $request->setTagName("feisu");
  111. $request->setReplyToAddress("true");
  112. $request->setToAddress($mail_str);
  113. $request->setSubject("新订单通知,请及时处理");
  114. $request->setHtmlBody($body);
  115. try {
  116. $client->getAcsResponse($request);
  117. }
  118. catch (ClientException $e) {
  119. print_r($e->getErrorCode());
  120. print_r($e->getErrorMessage());
  121. }
  122. catch (ServerException $e) {
  123. print_r($e->getErrorCode());
  124. print_r($e->getErrorMessage());
  125. }
  126. }