zhangdehua 1 год назад
Родитель
Сommit
17d51d37a1

+ 43 - 0
app/common/model/ShareKey.php

@@ -0,0 +1,43 @@
+<?php
+// +----------------------------------------------------------------------
+// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
+// +----------------------------------------------------------------------
+// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
+// +----------------------------------------------------------------------
+// | Author: 萤火科技 <admin@yiovo.com>
+// +----------------------------------------------------------------------
+declare (strict_types=1);
+
+namespace app\common\model;
+
+use cores\BaseModel;
+
+/**
+ * 文章模型
+ * Class ShareKey
+ * @package app\common\model
+ */
+class ShareKey extends BaseModel
+{
+    // 定义表名
+    protected $name = 'share_key';
+
+    // 定义主键
+    protected $pk = 'key_id';
+
+    // 追加字段
+    protected $append = [];
+
+
+    /**
+     * 文章详情
+     * @param int $keyId
+     * @return array|null|static
+     */
+    public static function detail(int $keyId)
+    {
+        return self::get($keyId);
+    }
+}

+ 3 - 2
app/index/common.php

@@ -32,8 +32,9 @@ function getPlatform()
 function encrypt(string $data, $key = 'vp-256-bit-secret-key')
 {
     $method = 'AES-256-CBC';
-    $iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length($method));
-    $iv =  mb_convert_encoding($iv,'utf8');
+    //$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length($method));
+    $iv = random_bytes(openssl_cipher_iv_length($method));
+    //$iv =  mb_convert_encoding($iv,'utf8');
     $encrypted = openssl_encrypt($data, $method, $key, 0, $iv);
     // 将iv和加密数据拼接在一起,然后进行base64编码
     return base64_encode($iv . $encrypted);

+ 12 - 4
app/index/controller/Checkout.php

@@ -14,6 +14,7 @@ namespace app\index\controller;
 
 use app\index\model\Order;
 use app\index\model\Order as OrderModel;
+use app\index\model\ShareKey;
 use app\index\model\User as UserModel;
 use app\index\service\order\PaySuccess;
 use app\index\service\User;
@@ -234,11 +235,18 @@ class Checkout extends Controller
         if (isset($order['user_id'])) {
             $key = Cache::get(UserModel::SHARE_PREFIX . $order['user_id']);
             if (!empty($key)) {
-                $fromUserId = decrypt($key);
+                $dbKey = ShareKey::getShareKey($key);
+                //没使用过的key才发放积分
+                if (!empty($dbKey) && $dbKey['is_delete'] == 0){
+                    $fromUserId = decrypt($key);
+
+                    $describe = "Giveaway after successful sharing";
+                    $payPoints = intval(bcmul($order['pay_price'], '100', 0));
+                    UserModel::setIncPoints(intval($fromUserId), -$payPoints, $describe);
+                    Cache::delete(UserModel::SHARE_PREFIX . $order['user_id']);
+                    ShareKey::delKey($key);
+                }
 
-                $describe = "Giveaway after successful sharing";
-                $payPoints = intval(bcmul($order['pay_price'], '100', 0));
-                UserModel::setIncPoints(intval($fromUserId), -$payPoints, $describe);
             }
         }
 

+ 5 - 1
app/index/controller/Index.php

@@ -6,6 +6,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\Session;
 use think\response\View;
 
 /**
@@ -123,6 +124,9 @@ class Index extends Controller
         if (empty($goodsId)) {
             return \redirect('index');
         }
+
+        $key = $this->request->param('key', '');
+
         $goodsModel = new GoodsModel();
         $goods = $goodsModel->getDetails($goodsId)->toArray();
         $goods['content'] = html_entity_decode($goods['content']);
@@ -130,7 +134,7 @@ class Index extends Controller
         $model = new CommentModel;
         $total = $model->rowsTotal($goodsId);
 
-        return view('productDetails', ['goods' => $goods, 'comment_total' => $total]);
+        return view('productDetails', ['goods' => $goods, 'comment_total' => $total, 'key' => $key]);
     }
 
     public function aboutUs(): View

+ 7 - 2
app/index/controller/User.php

@@ -2,11 +2,13 @@
 
 namespace app\index\controller;
 
+use app\index\model\ShareKey;
 use app\index\service\passport\MailCaptcha as MailCaptchaService;
 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 think\facade\Log;
 use think\facade\Session;
 
 /**
@@ -117,11 +119,14 @@ class User extends Controller
 
         $encryptUserId = encrypt(strval($userId));
 
-        $url = url('/index/index/productDetail?goodsId=' . $goodsId . '&key=' . $encryptUserId);
+        $url = 'Your friend shared a product with you. Click on the link to view it now:'
+            . config('app.app_host') . '/index/index/productDetail.html?goodsId=' . $goodsId . '&key=' . $encryptUserId;
         //todo 发邮件
+        Log::info($url);
 
         $MailCaptchaService = new MailCaptchaService;
-        if ($MailCaptchaService->sendText($mailbox,'From Your Friend',$url)) {
+        if ($MailCaptchaService->sendText($mailbox, 'From Your Friend', $url)) {
+            ShareKey::save(["key_string" => $encryptUserId, 'user_id' => $userId, 'create_time' => time(), 'is_delete' => 0, 'update_time' => time()]);
             return $this->renderSuccess('Sent Successful!Please check your new mails.');
         }
 

+ 40 - 0
app/index/model/ShareKey.php

@@ -0,0 +1,40 @@
+<?php
+// +----------------------------------------------------------------------
+// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
+// +----------------------------------------------------------------------
+// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
+// +----------------------------------------------------------------------
+// | Author: 萤火科技 <admin@yiovo.com>
+// +----------------------------------------------------------------------
+declare (strict_types = 1);
+
+namespace app\index\model;
+
+use app\common\model\ShareKey as ShareKeyModel;
+
+/**
+ * 系统设置模型
+ * Class Setting
+ * @package app\api\model
+ */
+class ShareKey extends ShareKeyModel
+{
+    /**
+     * 获取积分名称
+     * @return string
+     */
+    public static function getShareKey($key)
+    {
+        if (empty($key))return null;
+        return static::where('key_string', $key)->find();
+    }
+
+
+    public static function delKey($key)
+    {
+        if (empty($key))return null;
+        return static::where('key_string', $key)->update(['is_delete'=>1,'update_time'=>time()]);
+    }
+}

+ 5 - 5
app/index/service/passport/MailCaptcha.php

@@ -69,7 +69,7 @@ class MailCaptcha extends BaseService
         $mail = new PHPMailer(true);
         try {
             //Server settings
-            $mail->SMTPDebug = SMTP::DEBUG_SERVER;//DEBUG_OFF                   //Enable verbose debug output
+            $mail->SMTPDebug = SMTP::DEBUG_OFF;//DEBUG_OFF,DEBUG_SERVER           //Enable verbose debug output
             $mail->SMTPOptions = array(
                 'ssl' => array(
                     'verify_peer' => false,
@@ -101,7 +101,7 @@ class MailCaptcha extends BaseService
             //$mail->isHTML(true);                                  //Set email format to HTML
             $mail->Subject = 'Captcha';
             $mail->Body = 'Your captcha is ' . $smsCaptcha['code'] . '.Please use it in 15 minutes';
-            $mail->AltBody = 'This is the Your captcha for vapes';
+            $mail->AltBody = 'This is the Your captcha for Free Shipping Vapes';
 
             $mail->send();
             //echo 'Message has been sent';
@@ -130,7 +130,7 @@ class MailCaptcha extends BaseService
         $mail = new PHPMailer(true);
         try {
             //Server settings
-            $mail->SMTPDebug = SMTP::DEBUG_SERVER;                      //Enable verbose debug output
+            $mail->SMTPDebug = SMTP::DEBUG_OFF;                      //Enable verbose debug output
             $mail->isSMTP();                                            //Send using SMTP
             $mail->Host = 'smtp.163.com';                     //Set the SMTP server to send through
             $mail->SMTPAuth = true;                                   //Enable SMTP authentication
@@ -154,9 +154,9 @@ class MailCaptcha extends BaseService
             }
 
             $mail->send();
-            echo 'Message has been sent';
+            //echo 'Message has been sent';
         } catch (Exception $e) {
-            echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
+            //echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
             Log::error(__CLASS__ . ':' . __METHOD__, ['errMsg' => $e->getMessage(), 'mailError' => $mail->ErrorInfo]);
             return false;
         }

+ 11 - 1
app/index/view/index/productDetails.html

@@ -144,6 +144,12 @@
 
         var goodsId = {$goods.goods_id};
         var goodsSkuId = {$goods['skuList'][0]['goods_sku_id']};
+        var key = "{$key}";
+        const VAPES_SHARE_KEY = "vapes_share_key"
+        if (key != ""){
+            localStorage.setItem(VAPES_SHARE_KEY, key);
+        }
+        console.log(key);
 
         //富文本处理
         function initRichText() {
@@ -160,10 +166,14 @@
                 showToast("Please enter the quantity of products")
                 return
             }
+            const localKey = localStorage.getItem(VAPES_SHARE_KEY);
+
+
             var dp = {
                 goodsId: goodsId,
                 goodsSkuId: goodsSkuId,
-                goodsNum: number
+                goodsNum: number,
+                key: localKey
             }
             $.ajax({
                 url: "/index/cart/add",