Ver código fonte

Merge branch 'master' of http://git.huaml.com/zhh/huahuibao

shish 11 meses atrás
pai
commit
b6d5c9395d

+ 50 - 0
app-hd/controllers/ChatController.php

@@ -14,6 +14,8 @@ use GatewayClient\Gateway;
 
 class ChatController extends BaseController
 {
+    public $guestAccess = ['message-server-call'];
+
     //聊天 ssh 2019.12.28
     public function actionIndex()
     {
@@ -169,4 +171,52 @@ class ChatController extends BaseController
         $c = ChatService::getUnReadMsgCount($this->shopId, 'message');
         util::success(['msg_count'=>$c]);
     }
+
+    // 给暂无价格商品报价
+    public function actionCreateQuotedPrice()
+    {
+        $post = Yii::$app->request->post();
+        $key = $post['key'];
+        $price = floatval($post['price']);
+        $keyArr = explode('-', $key);
+        $shopId = intval($keyArr[0]);
+        if($this->shopId != $shopId){
+            util::error(-1, '校验失败,并不是你的客户');
+        }
+
+        $goodsId = $keyArr[2];
+        $goods = GoodsClass::getById($goodsId, false, 'id, priceType');
+        if ($goods['priceType'] != 0) {
+            util::error(-1, '此商品无需走报价');
+        }
+
+        $val = Yii::$app->redis->executeCommand('GET', [$key]);
+        if (!empty($saveAuthCode)) { // 修改报价
+            Yii::info('修改报价:' . $key . ' -- 旧价:' . $val . ', 新价:' . $price);
+        }
+
+        Yii::$app->redis->executeCommand('SETEX', [$key, 864000, $price]);
+        util::success(['oldPice'=>$val, 'newPrice'=>$price]);
+    }
+
+    // message_server 远程调用专用方法,可用于:1.@商家--客户发了商品消息  2.有未读消息的通知(可以额外添加触发条件)3.哦哦
+    public function actionMessageServerCall()
+    {
+        Yii::info('message_server 远程调用');
+
+        $callbackData = Yii::$app->request->post();
+        if (empty($callbackData)) {
+            $postStr = file_get_contents('php://input');
+            // 处理转义字符,将JSON字符串正确解析为数组
+            //$postStr = stripslashes($postStr);
+            $callbackData = json_decode($postStr, true);
+
+            if (empty($callbackData)) {
+                util::fail('回调请求的数据为空');
+            }
+        }
+
+        Yii::info(json_encode($callbackData));
+        return $this->asJson(['return_code' => 0, 'return_msg' => 'OK']); // 成功状态的返回数据
+    }
 }

+ 39 - 0
app-mall/controllers/ChatController.php

@@ -12,6 +12,7 @@ use GatewayClient\Gateway;
 
 class ChatController extends BaseController
 {
+    public $guestAccess = ['message-server-call'];
 
     //聊天首页,前端使用
     public function actionIndex()
@@ -135,4 +136,42 @@ class ChatController extends BaseController
         $c = ChatService::getUnReadMsgCount(intval($this->userId), 'message');
         util::success(['msg_count'=>$c]);
     }
+
+    //用 redis key 获取商品报价
+    public function actionGetQuotedPrice()
+    {
+        $key = Yii::$app->request->post('key');
+        $keyArr = explode('-', $key);
+        $userId = intval($keyArr[1]);
+        if ($userId != $this->userId) {
+            util::error(-1, '校验失败');
+        }
+
+        $val = Yii::$app->redis->executeCommand('GET', [$key]);
+        if (empty($val)) {
+            util::success(['price'=>-1]);
+        }
+        util::success(['price'=>$val]);
+    }
+
+    // message_server 远程调用专用方法,可用于:1.有未读消息的通知(可以额外添加触发条件)2.
+    public function actionMessageServerCall()
+    {
+        Yii::info('message_server 远程调用');
+
+        $callbackData = Yii::$app->request->post();
+        if (empty($callbackData)) {
+            $postStr = file_get_contents('php://input');
+            // 处理转义字符,将JSON字符串正确解析为数组
+            //$postStr = stripslashes($postStr);
+            $callbackData = json_decode($postStr, true);
+
+            if (empty($callbackData)) {
+                util::fail('回调请求的数据为空');
+            }
+        }
+
+        Yii::info(json_encode($callbackData));
+        return $this->asJson(['return_code' => 0, 'return_msg' => 'OK']); // 成功状态的返回数据
+    }
 }

+ 8 - 0
app-mall/controllers/GoodsController.php

@@ -25,6 +25,14 @@ class GoodsController extends BaseController
         $intro = isset($setting['goodsIntroduce']) ? $setting['goodsIntroduce'] : '';
         $info['commonIntro'] = $intro;
 
+        // 查询报价 shopId-userId-goodsId
+        $key = $this->shopId . '-' . $this->userId . '-' . $id;
+        $val = Yii::$app->redis->executeCommand('GET', [$key]);
+        if (floatval($val) > 0) {
+            $info['price'] = $val;
+            $info['priceType'] = 2;
+        }
+
         $pixTextGoods = PicTextGoodsClass::getByCondition(['mainId'=>$this->mainId, 'goodsId'=>$id], true);
         $info['picTextGoods'] = $pixTextGoods;
 

+ 9 - 0
app-mall/controllers/OrderController.php

@@ -411,6 +411,15 @@ class OrderController extends BaseController
         if ($stock <= 0) {
             util::fail('库存不足');
         }
+        // 从redis查询报价 shopId-userId-goodsId
+        $key = $this->shopId . '-' . $this->userId . '-' . $goodsId;
+        $val = Yii::$app->redis->executeCommand('GET', [$key]);
+        if (floatval($val) > 0) {
+            $goodsInfo->price = $val;
+            $goodsInfo->priceType = 2;
+        }
+
+
         //事务处理
         $connection = Yii::$app->db;
         $transaction = $connection->beginTransaction();

+ 1 - 1
biz-mall/message/services/ChatService.php

@@ -212,7 +212,7 @@ class ChatService extends BaseService
             $shopId = $val['shopId'];
             $float = floatval($val['time']);
             $decimalPart = $float - floor($float);
-            $unReadNum = intval($decimalPart * 10000);
+            $unReadNum = intval($decimalPart * 10000 + 0.5); // 加0.5 -- 使用四舍五入来处理浮点数精度问题
             $time = intval($val['time']);
             $date = date("Y-m-d H:i", $time);