123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- <?php
- /**
- * @param string $address 地址
- * @return array
- */
- use think\Db;
- use Dm\Request\V20151123 as Dm;
- /**
- * 秒转换为天
- */
- function get_stay_time($remain_time, $is_hour = 1, $is_minutes = 1)
- {
- $day = floor($remain_time / (3600*24));
- $day = $day > 0 ? $day.'天' : '';
- $hour = floor(($remain_time % (3600*24)) / 3600);
- $hour = $hour > 0 ? $hour.'小时' : '';
- if($is_hour && $is_minutes) {
- $minutes = floor((($remain_time % (3600*24)) % 3600) / 60);
- $minutes = $minutes > 0 ? $minutes.'分钟' : '';
- return $day.$hour.$minutes;
- }
- if($hour) {
- return $day.$hour;
- }
- return $day;
- }
- /**
- * get请求
- * @param $url
- * @param string $msg
- * @return mixed
- */
- function requestGet($url , $msg = ''){
- // 1. 初始化一个cURL会话
- $ch = curl_init();
- //设置选项,包括URL
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_HEADER, 0);
- //执行并获取HTML文档内容
- $response = curl_exec($ch);
- // 4. 释放cURL句柄,关闭一个cURL会话
- curl_close($ch);
- return $response;
- }
- //获取全图片地址 $image_data
- function image_path($image_data){
- if(empty($image_data)){
- return $image_data;
- }
- if (strpos($image_data,'|')!==false){
- $image_res = explode('|',$image_data);
- }elseif(strpos($image_data,',')!==false){
- $image_res = explode(',',$image_data);
- }else{
- $image_res = array($image_data);
- }
- return $image_res;
- }
- function get_order_sn(){
- $order_id_main = date('YmdHis') . rand(10000000,99999999);
- $order_id_len = strlen($order_id_main);
- $order_id_sum = 0;
- for($i=0; $i<$order_id_len; $i++){
- $order_id_sum += (int)(substr($order_id_main,$i,1));
- }
- $osn = $order_id_main . str_pad((100 - $order_id_sum % 100) % 100,2,'0',STR_PAD_LEFT);
- return $osn;
- }
- //通过服务类型,手机型号获取价格
- function get_goods_price($goods_id,$serve_type_id,$phone_type_id = 0){
- $goods_info = Db::name('store_goods')->field('id,cate_id')->where('status',1)->where('id',$goods_id)->where('is_deleted',0)->find();
- if(empty($goods_info)){
- $this->error('服务信息有误');
- }
- $data = array('code'=>1,'msg'=>'获取成功');
- if($goods_info['cate_id'] == 0){ //金刚区服务
- if(empty($phone_type_id)){
- $data['code'] = 0;
- $data['msg'] = '参数错误';
- }
- $serve_type_name = Db::name('store_goods_type')->where('id',$serve_type_id)->value('spec_name');
- $phone_type_name = Db::name('store_goods_type')->where('id',$phone_type_id)->value('spec_name');
- $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');
- }else{
- $serve_type_name = Db::name('store_goods_type')->where('id',$serve_type_id)->value('spec_name');
- $goods_price = Db::name('store_goods_list')->where('goods_id',$goods_id)->where('goods_spec','like','%'.$serve_type_name.'%')->value('price_selling');
- }
- if($goods_price <= 0){
- $data['code'] = 0;
- $data['msg'] = '价格信息有误';
- }
- $data['price'] = $goods_price;
- return $data;
- }
- //邮箱推送
- function mail_push($mail_str,$order_id){
- //查询订单信息
- $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();
- $order_info['goods_title'] = Db::name('store_goods')->where('id',$order_info['goods_id'])->value('title');
- $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'];
- require_once env('root_path').'/vendor/aliyunmail/aliyun-php-sdk-core/Config.php';
- //需要设置对应的region名称,如华东1(杭州)设为cn-hangzhou,新加坡Region设为ap-southeast-1,澳洲Region设为ap-southeast-2。
- $iClientProfile = DefaultProfile::getProfile("cn-hangzhou", "LTAI5tSMNtYuD3TdEkM65fyp", "lcmARfziFDS4PUJ0K7AKTf3Ytl3Z8O");
- $client = new DefaultAcsClient($iClientProfile);
- $request = new Dm\SingleSendMailRequest();
- $request->setAccountName("feisu@tsguangsu.com");
- $request->setFromAlias("飞速");
- $request->setAddressType(1);
- $request->setTagName("feisu");
- $request->setReplyToAddress("true");
- $request->setToAddress($mail_str);
- $request->setSubject("新订单通知,请及时处理");
- $request->setHtmlBody($body);
- try {
- $client->getAcsResponse($request);
- }
- catch (ClientException $e) {
- print_r($e->getErrorCode());
- print_r($e->getErrorMessage());
- }
- catch (ServerException $e) {
- print_r($e->getErrorCode());
- print_r($e->getErrorMessage());
- }
- }
|