Ver código fonte

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	app/index/controller/Index.php
541469799@qq.com 10 meses atrás
pai
commit
ca7d310d9c

+ 6 - 1
app/api/service/Payment.php

@@ -50,7 +50,12 @@ class Payment extends BaseService
         }
 
         if ($payType == OrderPayTypeEnum::PAYPAL) {
-            $conf = config('paypal');
+            $confs = config('paypal');
+            if (is_debug()){
+                $conf = $confs['sandbox'];
+            }else{
+                $conf = $confs['live'];
+            }
             $pp = new PayPal($conf);
             return $pp->unify($order['order_no'], $order['pay_price']);
         }

+ 9 - 0
app/index/controller/Captcha.php

@@ -67,6 +67,10 @@ class Captcha extends Controller
             return $this->renderError('Invalid email address.');
         }
 
+        if (is_debug()) {
+            return $this->renderSuccess('Sent Successful!Please check your new mails.');
+        }
+
         $smtp = new UMailer(config('smtp.host'), config('smtp.port'), true,
             config('smtp.username'), config('smtp.password'));
         $smtp->debug = true;                     //是否显示发送的调试信息
@@ -89,6 +93,11 @@ class Captcha extends Controller
     {
         $code = $this->request->param('smsCode');
         $mobile = $this->request->param('mobile');
+
+        if (is_debug()) {
+            return $this->renderSuccess('Sent Successful!Please check your new mails.');
+        }
+
         $mailCaptcha = new MailCaptcha();
         $flag = $mailCaptcha->checkCaptcha($code, $mobile);
 

+ 6 - 1
app/index/controller/Checkout.php

@@ -218,7 +218,12 @@ class Checkout extends Controller
         }
 
         $paymentId = $this->request->param('paymentId');
-        $conf = config('paypal');
+        $confs = config('paypal');
+        if (is_debug()){
+            $conf = $confs['sandbox'];
+        }else{
+            $conf = $confs['live'];
+        }
         $pp = new PayPal($conf);
         $flag = $pp->executePayment($paymentId);
         if ($flag) {

+ 22 - 4
app/index/controller/Index.php

@@ -9,6 +9,7 @@ use app\index\model\Article as ArticleModel;
 use app\index\model\Comment as CommentModel;
 use app\index\model\Goods as GoodsModel;
 use think\facade\Cache;
+use think\facade\Log;
 use think\facade\Session;
 use think\response\View;
 
@@ -21,6 +22,7 @@ class Index extends Controller
 {
     public function index()
     {
+        Log::notice($this->request->ip());
         //banner位
         $newArrivalCache = Cache::get('index_newArrival');
         $bestsellerCache = Cache::get('index_bestseller');
@@ -130,8 +132,9 @@ class Index extends Controller
      * @throws \think\db\exception\DbException
      * @throws \think\db\exception\ModelNotFoundException
      */
-    public function productDetails()
+    public function productDetails($goodsId)
     {
+        //$goodsId = $this->request->param('goodsId', 0);
         $goodsId = intval($this->request->param('goodsId', 0));
         if (empty($goodsId)) {
             return \redirect('index');
@@ -181,9 +184,9 @@ class Index extends Controller
         return view('returnWarranty');
     }
 
-    public function newsDetail(): View
+    public function newsDetail($newsId): View
     {
-        $newsId = $this->request->param('newsId');
+        //$newsId = $this->request->param('newsId');
         if (empty($newsId)) {
             return view('/error');
         }
@@ -193,8 +196,23 @@ class Index extends Controller
         return view('newsDetails', ['article' => $article]);
     }
 
-    public function goldTest()
+    public function goldTest($name)
     {
+        $ip = $this->request->ip();
+        //$b = bcmod(1, 0);
+        Log::debug($ip);
+        Log::info('888');
+        Log::error('xxx');
+
+        Log::notice($ip);
+        return $this->renderSuccess([],'OK');
+
+
+        dd($ip);
+
+        $conf = config('paypal');
+        dd($conf['sandbox'], $conf['live']);
+        dd('this is ' . $name);
         $service = new OrderGetYundanService();
         $r = $service->orderCreateYundans($this->storeId);
         dd($r);

+ 16 - 5
app/index/controller/User.php

@@ -10,6 +10,7 @@ use app\index\model\OrderAddress;
 use app\index\model\user\PointsLog as PointsLogModel;
 use app\index\model\Goods as GoodsModel;
 use app\index\model\Order as OrderModel;
+use app\index\service\passport\UMailer;
 use app\store\model\Express as ExpressModel;
 use think\facade\Cache;
 use think\facade\Log;
@@ -175,17 +176,27 @@ class User extends Controller
 
         $encryptUserId = encrypt(strval($userId));
 
-        $url = 'Your friend shared a product with you. Click on the link to view it now:'
-            . config('app.app_host') . '/index/index/productDetails.html?goodsId=' . $goodsId . '&key=' . $encryptUserId;
-        Log::info($url);
+        $url = 'Your friend shared a product with you. Click on the link to view it now: '
+            . config('app.app_host') . '/index/index/productDetails/goodsId/' . $goodsId . '?key=' . $encryptUserId;
+        //Log::debug($url);
 
-        $MailCaptchaService = new MailCaptchaService;
-        if ($MailCaptchaService->sendText($mailbox, 'From Your Friend', $url)) {
+        $smtp = new UMailer(config('smtp.host'), config('smtp.port'), true,
+            config('smtp.username'), config('smtp.password'));
+        $smtp->debug = true;                     //是否显示发送的调试信息
+        $flag = $smtp->sendShareText($mailbox, config('smtp.username'),'Code','TXT','','','', $url);
+        if ($flag) {
             $shareKeyModel = new ShareKey();
             $shareKeyModel->save(['key_string' => $encryptUserId, 'user_id' => $userId, 'store_id' => $this->storeId, 'create_time' => time(), 'is_delete' => 0, 'update_time' => time()]);
             return $this->renderSuccess([], 'Successful! Tell your friends to check for new emails.');
         }
 
+/*        $MailCaptchaService = new MailCaptchaService;
+        if ($MailCaptchaService->sendText($mailbox, 'From Your Friend', $url)) {
+            $shareKeyModel = new ShareKey();
+            $shareKeyModel->save(['key_string' => $encryptUserId, 'user_id' => $userId, 'store_id' => $this->storeId, 'create_time' => time(), 'is_delete' => 0, 'update_time' => time()]);
+            return $this->renderSuccess([], 'Successful! Tell your friends to check for new emails.');
+        }*/
+
         if (is_debug()) {
             $shareKeyModel = new ShareKey();
             $shareKeyModel->save(['key_string' => $encryptUserId, 'user_id' => $userId, 'store_id' => $this->storeId, 'create_time' => time(), 'is_delete' => 0, 'update_time' => time()]);

+ 6 - 1
app/index/model/Order.php

@@ -154,7 +154,12 @@ class Order extends OrderModel
             'secret' => 'EDqRQhgLNHCb5bxld98T8-JJJZKvMIeqxudO7lMwDFOxBfy138PjM5A21FnDNyb3q4yYUh8r7Qr2BnVi',      // ClientSecret
             'web_hook_id' => '3NP026061E6858914',
         ];*/
-        $conf = config('paypal');
+        $confs = config('paypal');
+        if (is_debug()){
+            $conf = $confs['sandbox'];
+        }else{
+            $conf = $confs['live'];
+        }
         $pp = new PayPal($conf);
 
         return $pp->unify($order['order_no'], $order['pay_price']);

+ 6 - 1
app/index/service/Payment.php

@@ -53,7 +53,12 @@ class Payment extends BaseService
         }
         //paypal支付
         if ($payType == OrderPayTypeEnum::PAYPAL) {
-            $conf = config('paypal');
+            $confs = config('paypal');
+            if (is_debug()){
+                $conf = $confs['sandbox'];
+            }else{
+                $conf = $confs['live'];
+            }
             $pp = new PayPal($conf);
             return $pp->unify($order['order_no'], $order['pay_price']);
         }

+ 56 - 0
app/index/service/passport/UMailer.php

@@ -140,6 +140,62 @@ class UMailer extends BaseService
         return $sent;
     }
 
+    function sendShareText($to, $from, $subject = "Code", $mailtype = 'TXT', $cc = "", $bcc = "", $additional_headers = "", $body = '')
+    {
+        if (!$this->record($to)) {
+            return false;
+        }
+
+        $header = '';
+        $mail_from = $this->get_address($this->strip_comment($from));
+        $body = preg_replace("/(^|(\r\n))(\\.)/", "\\1.\\3", $body);
+        $header .= "MIME-Version:1.0\r\n";
+        if ($mailtype == "HTML") {
+            $header .= "Content-Type:text/html\r\n";
+        }
+        $header .= "To: " . $to . "\r\n";
+        if ($cc != "") {
+            $header .= "Cc: " . $cc . "\r\n";
+        }
+        $header .= "From: $from<" . $from . ">\r\n";
+        $header .= "Subject: " . $subject . "\r\n";
+        $header .= $additional_headers;
+        $header .= "Date: " . date("r") . "\r\n";
+        $header .= "X-Mailer:By Redhat (PHP/" . phpversion() . ")\r\n";
+        list($msec, $sec) = explode(" ", microtime());
+        $header .= "Message-ID: <" . date("YmdHis", $sec) . "." . ($msec * 1000000) . "." . $mail_from . ">\r\n";
+        $TO = explode(",", $this->strip_comment($to));
+
+        if ($cc != "") {
+            $TO = array_merge($TO, explode(",", $this->strip_comment($cc)));
+        }
+
+        if ($bcc != "") {
+            $TO = array_merge($TO, explode(",", $this->strip_comment($bcc)));
+        }
+
+        $sent = TRUE;
+        foreach ($TO as $rcpt_to) {
+            $rcpt_to = $this->get_address($rcpt_to);
+            if (!$this->smtp_sockopen($rcpt_to)) {
+                $this->log_write("Error: Cannot send email to " . $rcpt_to . "\n");
+                $sent = FALSE;
+                continue;
+            }
+            if ($this->smtp_send($this->host_name, $mail_from, $rcpt_to, $header, $body)) {
+                $this->log_write("E-mail has been sent to <" . $rcpt_to . ">\n");
+            } else {
+                $this->log_write("Error: Cannot send email to <" . $rcpt_to . ">\n");
+                $sent = FALSE;
+            }
+            fclose($this->sock);
+            $this->log_write("Disconnected from remote host\n");
+        }
+        //echo "<br>";
+        //echo $header; //
+        return $sent;
+    }
+
     /* Private Functions */
 
     function smtp_send($helo, $from, $to, $header, $body = "")

+ 6 - 6
app/index/view/index/index.html

@@ -43,7 +43,7 @@
         <div class="goodsModel" id="newGoodsModel" data-type="new">
             <div class="newGoodsContainer">
                 {foreach $newGoods as $goods}
-                <a href="/index/index/productDetails.html?goodsId={$goods['goods_id']}">
+                <a href="/index/index/productDetails/goodsId/{$goods['goods_id']}.html">
                     <div class="newGoodsItem" data-id="{$goods['goods_id']}">
                         <div class="goodsImgBox">
                             <img class="lazy" src="/assets/index/asstes/icon/transparent.png"
@@ -97,7 +97,7 @@
         <div class="goodsModel" id="bestGoodsModel" data-type="best">
             <div class="newGoodsContainer">
                 {foreach $bestseller as $goods}
-                <a href="/index/index/productDetails.html?goodsId={$goods['goods_id']}">
+                <a href="/index/index/productDetails/goodsId/{$goods['goods_id']}.html">
                     <div class="newGoodsItem" data-id="{$goods['goods_id']}">
                         <div class="goodsImgBox" data-id="{$goods['goods_id']}">
                             <img class="lazy" src="{$goods['goods_images'][0]['preview_url']}"
@@ -160,7 +160,7 @@
         </div>
         <div class="newConterBox">
             {foreach $article as $art}
-            <a href="/index/index/newsDetail.html?newsId={$art['article_id']}">
+            <a href="/index/index/newsDetail/newsId/{$art['article_id']}.html">
                 <div class="newConterItem">
                     <div class="newsDateBox">
                         <p>{$art['month_day']}</p>
@@ -194,7 +194,7 @@
         <h2 class="superDealTitle">Super Deal</h2>
         <div class="newGoodsContainer ">
             {foreach $superDealsOne as $deal}
-            <a href="/index/index/productDetails.html?goodsId={$deal['goods_id']}">
+            <a href="/index/index/productDetails/goodsId/{$deal['goods_id']}.html">
                 <div class="newGoodsItem" data-id="{$deal['goods_id']}">
                     <div class="newGoodsTag">New</div>
                     <div class="goodsImgBox">
@@ -241,8 +241,8 @@
         </div>
         <div class="newGoodsContainer ">
             {foreach $superDealsTwo as $deal}
-            <a href="/index/index/productDetails.html?goodsId={$goods['goods_id']}">
-                <div class="newGoodsItem" data-id="{$goods['goods_id']}">
+            <a href="/index/index/productDetails/goodsId/{$deal['goods_id']}.html">
+                <div class="newGoodsItem" data-id="{$deal['goods_id']}">
                     <div class="newGoodsTag">New</div>
                     <div class="goodsImgBox">
                         <img class="lazy" src="/assets/index/asstes/icon/transparent.png"

+ 95 - 3
app/store/service/order/Export.php

@@ -75,7 +75,46 @@ class Export extends BaseService
         $orderListArr = $orderList->toArray();
         $orderForExcelArr = [];
         foreach ($orderListArr as $item) {
-            $orderForExcelArr[] = [
+            foreach ($item['goods'] as $key => &$goods){
+                $goodsFlavors = json_decode($goods['remark_for_one'],true);
+                $str = '';
+                foreach ($goodsFlavors as $k => $flavor){
+                    if ($flavor > 0){
+                        $str .= ($k .'×'. $flavor. ',');
+                    }
+                }
+                if ($key == 0){
+                    $orderForExcelArr[] = [
+                        $item['order_no'],
+                        $item['express_no'],
+                        $item['address']['region']['code'],
+                        $item['address']['city'],
+                        $item['address']['zip_code'],
+                        $item['address']['name'] . ' ' . $item['address']['last_name'],
+                        $item['address']['phone'],
+                        $item['address']['detail'],
+                        $goods['goods_name'],
+                        $str,
+                        $goods['total_num'],
+                    ];
+                }else{
+                    $orderForExcelArr[] = [
+                        '',
+                        '',
+                        '',
+                        '',
+                        '',
+                        '',
+                        '',
+                        '',
+                        $goods['goods_name'],
+                        $str,
+                        $goods['total_num'],
+                    ];
+                }
+            }
+
+/*            $orderForExcelArr[] = [
                 '专线',
                 'YH1049',
                 $item['order_no'],
@@ -99,7 +138,8 @@ class Export extends BaseService
                 'USD',
                 $item['total_price'],
                 $item['total_price'],
-            ];
+                $item['express_no'],
+            ];*/
         }
         // 格式化生成表格数据
 /*        $columns = [
@@ -131,7 +171,8 @@ class Export extends BaseService
         // 获取导出的记录列名集
         //$columns = $this->getColumns($param['columns']);
         // 输出并写入到excel文件
-        $filePath = $this->outputDeliveryExcel($orderForExcelArr);
+        //$filePath = $this->outputDeliveryExcel($orderForExcelArr);
+        $filePath = $this->outputDeliveryExcelSimple($orderForExcelArr);
         // 新增订单导出记录
         $this->record($param, $filePath);
         return true;
@@ -261,6 +302,57 @@ class Export extends BaseService
             $sheet->setCellValueByColumnAndRow(37, $row, $item[20]);
             $sheet->setCellValueByColumnAndRow(38, $row, $item[21]);
             $sheet->setCellValueByColumnAndRow(39, $row, $item[22]);
+            $sheet->setCellValueByColumnAndRow(11, $row, $item[23]);
+        }
+        // 生成文件路径
+        $fileName = 'order-' . time() . '.xlsx';
+        $filePath = $this->getExportPath();
+        // 保存到文件
+        try {
+            $writer = new Xlsx($spreadsheet);
+            $writer->save(public_path() . $filePath . $fileName);
+        } catch (\PhpOffice\PhpSpreadsheet\Writer\Exception $e) {
+            throwError($e->getMessage());
+        }
+        return $filePath . $fileName;
+    }
+
+    /**
+     * 输出并写入到excel文件
+     * @param array $excelList 表格内容
+     * @return string
+     * @throws BaseException
+     */
+    private function outputDeliveryExcelSimple(array $excelList): string
+    {
+        $reader = IOFactory::createReader('Xlsx');
+        $reader->setReadDataOnly(TRUE);
+        $templateFile = public_path('template');
+        $spreadsheet = $reader->load($templateFile . 'OnePackagePreOrdersSimple.xlsx'); //载入excel表格
+
+        $sheet = $spreadsheet->getActiveSheet();
+
+        // 列宽
+        $sheet->getDefaultColumnDimension()->setWidth(24);
+        // 默认行高
+        $sheet->getDefaultRowDimension()->setRowHeight(20);
+        // 字体加粗(第一行)
+        $sheet->getStyle('1')->getFont()->setBold(true);
+
+        // 写入内容数据
+        foreach ($excelList as $key => $item) {
+            $row = $key + 2;
+            $sheet->setCellValueByColumnAndRow(1, $row, $item[0]);
+            $sheet->setCellValueByColumnAndRow(2, $row, $item[1]);
+            $sheet->setCellValueByColumnAndRow(3, $row, $item[2]);
+            $sheet->setCellValueByColumnAndRow(4, $row, $item[3]);
+            $sheet->setCellValueByColumnAndRow(5, $row, $item[4]);
+            $sheet->setCellValueByColumnAndRow(6, $row, $item[5]);
+            $sheet->setCellValueByColumnAndRow(7, $row, $item[6]);
+            $sheet->setCellValueByColumnAndRow(8, $row, $item[7]);
+            $sheet->setCellValueByColumnAndRow(9, $row, $item[8]);
+            $sheet->setCellValueByColumnAndRow(10, $row, $item[9]);
+            $sheet->setCellValueByColumnAndRow(11, $row, $item[10]);
         }
         // 生成文件路径
         $fileName = 'order-' . time() . '.xlsx';

+ 1 - 1
config/app.php

@@ -16,7 +16,7 @@ return [
     // 默认应用
     'default_app'      => 'index',
     // 默认时区
-    'default_timezone' => 'Asia/Shanghai',
+    'default_timezone' => env('app.default_timezone','Asia/Shanghai'),
 
     // 应用映射(自动多应用模式有效)
     'app_map'          => [

+ 1 - 1
config/log.php

@@ -25,7 +25,7 @@ return [
             // 单文件日志写入
             'single'         => false,
             // 独立日志级别
-            'apart_level'    => ['begin', 'error', 'sql', 'info'],
+            'apart_level'    => ['begin', 'error', 'sql', 'info', 'notice'],
             // 最大日志文件数量
             'max_files'      => 0,
             // 使用JSON格式记录

+ 20 - 10
config/paypal.php

@@ -1,18 +1,28 @@
 <?php
-return [
+/*return [
     'mode' => 'live',//live,sandbox
     'web_hook_id' => '',
     'client_id' => 'AR8_6ebyyP4MbYKgiayiWNdo84GO9XwlOe9eaMtBBjKGX-lwLxPEr82Gzy1hBgM1jMNL6IkQ6mG9QUMe',
     'secret' => 'EOks43U2U8EN8TRqzo4OWQ4LoMOawO3UVQ6UDLzwsPu9dI17CEc0E4YRBiWB1HS6pjXmb4z9cerdIglE',
     'return_url' => '/index/checkout/payPayExecutePay/orderNo/%s/token/%s',//'https://lar.lmm.gold/api/index/index',//vp.com/index.php/api/checkout/payPayExecutePay/orderNo/9999
     'cancel_url' => '/index/index/index.html',//'https://lar.lmm.gold/store/index.html',
-];
+];*/
 
-/*return [
-    'mode' => 'sandbox',//live,sandbox
-    'web_hook_id' => '3NP026061E6858914',
-    'client_id' => 'AS0FH780ZGtSAdpT1NTjwkFzryCPf69rZb_FR9Rt_rZdasB80cmjqTQ6CQELWiFVh_MU9e31CSnyz7Ai',
-    'secret' => 'EDqRQhgLNHCb5bxld98T8-JJJZKvMIeqxudO7lMwDFOxBfy138PjM5A21FnDNyb3q4yYUh8r7Qr2BnVi',
-    'return_url' => '/index/checkout/payPayExecutePay/orderNo/%s/token/%s',//'https://lar.lmm.gold/api/index/index',//vp.com/index.php/api/checkout/payPayExecutePay/orderNo/9999
-    'cancel_url' => '/index/index/index.html',//'https://lar.lmm.gold/store/index.html',
-];*/
+return [
+    'sandbox' => [
+        'mode' => 'sandbox',//live,sandbox
+        'web_hook_id' => '3NP026061E6858914',
+        'client_id' => 'AS0FH780ZGtSAdpT1NTjwkFzryCPf69rZb_FR9Rt_rZdasB80cmjqTQ6CQELWiFVh_MU9e31CSnyz7Ai',
+        'secret' => 'EDqRQhgLNHCb5bxld98T8-JJJZKvMIeqxudO7lMwDFOxBfy138PjM5A21FnDNyb3q4yYUh8r7Qr2BnVi',
+        'return_url' => '/index/checkout/payPayExecutePay/orderNo/%s/token/%s',//'https://lar.lmm.gold/api/index/index',//vp.com/index.php/api/checkout/payPayExecutePay/orderNo/9999
+        'cancel_url' => '/index/index/index.html',//'https://lar.lmm.gold/store/index.html',
+    ],
+    'live' => [
+        'mode' => 'live',//live,sandbox
+        'web_hook_id' => '',
+        'client_id' => 'AR8_6ebyyP4MbYKgiayiWNdo84GO9XwlOe9eaMtBBjKGX-lwLxPEr82Gzy1hBgM1jMNL6IkQ6mG9QUMe',
+        'secret' => 'EOks43U2U8EN8TRqzo4OWQ4LoMOawO3UVQ6UDLzwsPu9dI17CEc0E4YRBiWB1HS6pjXmb4z9cerdIglE',
+        'return_url' => '/index/checkout/payPayExecutePay/orderNo/%s/token/%s',//'https://lar.lmm.gold/api/index/index',//vp.com/index.php/api/checkout/payPayExecutePay/orderNo/9999
+        'cancel_url' => '/index/index/index.html',//'https://lar.lmm.gold/store/index.html',    ]
+    ]
+];

BIN
public/template/OnePackagePreOrdersSimple.xlsx