rabin 1 år sedan
förälder
incheckning
12b9cabf2a

+ 4 - 0
package/email/index.php

@@ -0,0 +1,4 @@
+<?php
+define('DEVER_PACKAGE',  'email');
+define('DEVER_APP_SETUP', dirname(__FILE__) . DIRECTORY_SEPARATOR);
+include(dirname(__FILE__) . DIRECTORY_SEPARATOR . '../../boot.php');

+ 59 - 4
src/dai/seller/api/Manage.php

@@ -158,14 +158,23 @@ class Manage extends Auth
         $id = Dever::input('order_id');
         $order = Dever::db('order', 'seller')->find($id);
 
+        /*
         $code = Dever::load('manage', 'seller')->kmPwd($order['id'], $order['cdate']);
         if ($code != $value) {
             Dever::error('密码错误');
+        }*/
+
+        if (!$value) {
+            Dever::error('请输入正确的邮箱');
+        }
+        if (!preg_match(Dever::rule('email'), $value)) {
+            Dever::error('请输入正确的邮箱');
         }
 
         $result = array();
         $result['msg'] = '提取成功';
-        $result['url'] = Dever::url('seller/manage.tqKmAct', array('order_id' => $order['id'], 'value' => $value));
+        //$result['url'] = Dever::url('seller/manage.tqKmAct', array('order_id' => $order['id'], 'value' => $value));
+        \Dever\Helper\Cmd::run('seller/manage.tqKmAct', array('order_id' => $order['id'], 'value' => $value));
 
         # 增加提取日志
         $log['seller_id'] = $order['seller_id'];
@@ -173,6 +182,7 @@ class Manage extends Auth
         $log['admin_id'] = $this->uid;
         $log['system_id'] = $this->system['id'];
         $log['admin_name'] = $this->user['name'];
+        $log['email'] = $value;
 
         Dever::db('order_km', 'seller')->insert($log);
         return $result;
@@ -189,13 +199,58 @@ class Manage extends Auth
         }
 
         $code = Dever::load('manage', 'seller')->kmPwd($order[0]['id'], $order[0]['cdate']);
+        /*
         if ($code != $value) {
             Dever::error('密码错误');
         }
-
-        $order = Dever::db('order', 'seller')->select($id);
+        */
         $data = Dever::load('manage', 'seller')->outKm(array('body' => $order));
         
-        Dever::load('export', 'excel')->act($data['body'], $data['head'], '导出卡密', 0, '', false, false, $code);
+        $file = Dever::load('export', 'excel')->act($data['body'], $data['head'], '导出卡密', 0, '', false, false, $code, 'km' . $id);
+
+        $seller = Dever::db('info', 'seller')->find($order[0]['seller_id']);
+        $email = $value;
+        $username = $seller['name'];
+        $title = '您有新的卡密请查收';
+        $content = '请您打开附件提取卡密,提取密码请联系商务人员';
+        $this->send($email, $username, $title, $content, $file);
+        Dever::db('info', 'seller')->update($seller['id'], array('email' => $value));
+        return '卡密提取成功';
+    }
+
+    # 发送邮件
+    public function send($email, $username, $title, $content, $file = '')
+    {
+        $config = Dever::config('setting')['email'];
+
+        Dever::apply('PHPMailer', 'email', 'src');
+        Dever::apply('Exception', 'email', 'src');
+        Dever::apply('SMTP', 'email', 'src');
+        $mail = new \PHPMailer\PHPMailer\PHPMailer();
+
+        $mail->isSMTP();
+        //$mail->SMTPDebug = 2;
+        $mail->CharSet = 'UTF-8';
+        $mail->Host = $config['smtp'];
+        $mail->Port = 465;
+        $mail->SMTPSecure = 'ssl';
+        $mail->SMTPAuth = true;
+        $mail->Username = $config['username'];
+        $mail->Password = $config['password'];
+        $mail->setFrom($config['from'][0], 'API充值系统');
+        $mail->addAddress($email, $username);
+        $mail->Subject = "=?utf-8?B?" . base64_encode($title) . "?=";
+        $mail->Body = $content;
+        $mail->isHTML(true);
+        if ($file) {
+            $mail->addAttachment($file);
+        }
+        if (!$mail->send()) {
+            Dever::log($email . '-' . $username . '-' . $mail->ErrorInfo, 'email');
+            Dever::alert("Mailer Error: " . $mail->ErrorInfo);
+        } else {
+            @unlink($file);
+            return 'ok';
+        }
     }
 }

+ 7 - 3
src/dai/seller/lib/Manage.php

@@ -478,6 +478,7 @@ class Manage extends Auth
     public function showOrderExpandKm($data)
     {
         if ($data && strstr($data['account'], 'km_')) {
+            $seller = Dever::db('info', 'seller')->find($data['seller_id']);
             $result['type'] = 'desc';
             $result['content'][] = array
             (
@@ -488,10 +489,10 @@ class Manage extends Auth
                 'column' => 1,
                 'content' => array
                 (
-                    array('提取密码', array
+                    array('提取邮箱', array
                     (
-                        'input' => '请输入密码',
-                        'value' => '',
+                        'input' => '请输入邮箱',
+                        'value' => $seller['email'],
                         'button' => '提取',
                         'remote' => Dever::url('seller/manage.tqKm', array('order_id' => $data['id'])),
                     )),
@@ -501,6 +502,9 @@ class Manage extends Auth
             $content = array();
             if ($log) {
                 foreach ($log as $v) {
+                    if ($v['email']) {
+                        $v['admin_name'] .= ' 提取邮箱:' . $v['email'];
+                    }
                     $content[] = array(date('Y-m-d H:i:s', $v['cdate']), '操作人:' . $v['admin_name']);
                 }
             }

+ 6 - 0
src/dai/seller/table/info.php

@@ -24,6 +24,12 @@ return array
             'type'      => 'varchar(64)',
         ),
 
+        'email' => array
+        (
+            'name'      => '邮箱',
+            'type'      => 'varchar(200)',
+        ),
+
         'discount' => array
         (
             'name'      => '默认折扣',

+ 6 - 0
src/dai/seller/table/order_km.php

@@ -34,5 +34,11 @@ return array
             'name'      => '管理员名称',
             'type'      => 'varchar(100)',
         ),
+
+        'email' => array
+        (
+            'name'      => '邮箱',
+            'type'      => 'varchar(200)',
+        ),
     ),
 );