stanley-king 7 лет назад
Родитель
Сommit
04b96b3375

+ 0 - 1
data/logic/delivery.logic.php

@@ -182,7 +182,6 @@ class deliveryLogic
         else {
             Log::record($resp,Log::DEBUG);
         }
-
         return true;
     }
 

+ 1 - 1
helper/room/client.php

@@ -72,7 +72,7 @@ class client extends tcp_client
 
     public function invite($roomid,$user)
     {
-        $param = ['room_id' => $roomid,'op' => 'invite','user' => $user];
+        $param = ["act" => 'factory','room' => $roomid,'op' => 'invite','user' => $user];
         $result = $this->request($param);
         if(empty($result)) return false;
 

+ 58 - 3
helper/room/croom.php

@@ -32,7 +32,7 @@ abstract class croom
         $userid = intval($input['user']);
         if($userid > 0) {
             $room_key = $this->invite($userid);
-            return ['room_key' => $room_key,'room_id' => $this->mRoomid];
+            return ['room_key' => $room_key,'room' => $this->mRoomid];
         } else {
             return false;
         }
@@ -71,10 +71,65 @@ abstract class croom
         return true;
     }
 
-    public function joinOp($participant)
+    private function room_info($participant)
     {
+        $result = [];
+        $result['room'] = $this->mRoomid;
+        $result['users'] = [];
+        foreach ($this->mParticipants as $key => $item)
+        {
+            $result['users'][] = $item;
+            if($key == $participant) {
+                $result['me'] = $item['userid'];
+            }
+        }
+
+        return $result;
+    }
+
+    private function all_users()
+    {
+        $result = [];
+        foreach ($this->mParticipants as $key => $item) {
+            $result[] = $key;
+        }
+        return $result;
+    }
+
+    public function joinOp($input)
+    {
+        $participant = $input['room_key'];
+        if(empty($participant)) {
+            return false;
+        }
+
         $this->mAccReq = true;
-        return $this->join($participant);
+        if($this->join($participant))
+        {
+            $msgs = [];
+            {
+                $msg = [];
+                $msg['receivers'][] = $participant;
+
+                $msg['body']['op']   = 'room_info';
+                $msg['body']['room'] = $this->mRoomid;
+                $msg['body']['content'] = $this->room_info($participant);
+                $msgs[] = $msg;
+            }
+            {
+                $msg = [];
+                $msg['receivers'] = $this->all_users();
+
+                $msg['body']['op']   = 'join';
+                $msg['body']['room'] = $this->mRoomid;
+                $msg['body']['content'] = $this->mParticipants[$participant];
+                $msgs[] = $msg;
+            }
+            return $msgs;
+        }
+        else {
+            return false;
+        }
     }
     public function acc_req() {
         return $this->mAccReq;

+ 50 - 15
helper/room/processor.php

@@ -48,18 +48,41 @@ class processor implements IProcessor
 
     private function onFactory($input)
     {
-        $room = $this->mFactory->create($input);
-        if($room != false) {
-            $user = intval($input['creator']);
-            $this->mRooms[$room->room_id()] = $room;
-            $user_roomKey = $room->invite($user);
-            if($user_roomKey != false) {
-                $ret = ['room_id' => $room->room_id(),'room_key' => $user_roomKey];
-                return $this->success($ret);
+        $err = errcode::ErrRoom;
+        $op = $input['op'];
+        if($op == 'create')
+        {
+            $room = $this->mFactory->create($input);
+            if($room != false) {
+                $user = intval($input['creator']);
+                $this->mRooms[$room->room_id()] = $room;
+                $user_roomKey = $room->invite($user);
+                if($user_roomKey != false) {
+                    $ret = ['room' => $room->room_id(),'room_key' => $user_roomKey];
+                    return $this->success($ret);
+                }
+            }
+            $err = errcode::ErrRoomCreate;
+        }
+        elseif($op == 'invite')
+        {
+            $roomid = intval($input['room']);
+            $room = $this->room($roomid);
+            if($room != false)
+            {
+                $userid = intval($input['user']);
+                if($userid > 0)
+                {
+                    $room_key = $room->invite($userid);
+                    if($room_key != false) {
+                        return $this->success(['room' => $roomid,'room_key' => $room_key]);
+                    }
+                }
             }
+            $err = errcode::ErrRoomInvite;
         }
 
-        return $this->error(errcode::ErrRoomCreate);
+        return $this->error($err);
     }
 
     private function onAccess($input)
@@ -90,21 +113,33 @@ class processor implements IProcessor
 
     private function onRoom($input)
     {
-        $roomid = intval($input['room_id']);
+        $result['act'] = 'room';
+
+        $roomid = intval($input['room']);
         $room = $this->room($roomid);
         if($room != false)
         {
             $function = $input['op'] . 'Op';
+            $roomkey = $input['room_key'];
+
+            $result['room_key'] = $roomkey;
             if (method_exists($room,$function))
             {
-                $ret = $room->$function($input);
-                if($ret === false) {
-                    return $this->error(errcode::ErrRoom);
-                } else {
-                    return $this->success($ret);
+                $msgs = $room->$function($input);
+                if($msgs === false) {
+                    $result['op']  = 'deluser';
+                    return $this->success($result);
+                }
+                else {
+                    $result['msgs'] = $msgs;
+                    $result['op']  = 'broadcast';
+                    return $this->success($result);
                 }
             }
         }
+        else {
+
+        }
     }
 
     private function room($roomid)

+ 1 - 1
helper/search/util.php

@@ -124,7 +124,7 @@ class filter
 
 }
 
-//通过字找到key,通过key 找到词
+//通过字找到key,通过key找到词
 class words
 {
     protected $mDict;

+ 20 - 3
mobile/control/room.php

@@ -6,17 +6,34 @@
  * Time: 上午11:36
  */
 
-require_once(BASE_ROOT_PATH . '/helper/room/room_client.php');
+require_once(BASE_ROOT_PATH . '/helper/search/tcp_client.php');
+require_once(BASE_ROOT_PATH . '/helper/room/client.php');
 
-class roomControl extends mobileControl
+class roomControl extends mbMemberControl
 {
+    private $mRoomID;
+    private $mAddr;
+
     public function __construct() {
         parent::__construct();
+        $this->mRoomID = 30;
+        $this->mAddr = 'ws://192.168.0.200:8080';
+    }
+
+    public function indexOp()
+    {
+        $user = session_helper::memberid();
+        $ret = room\client::instance()->invite($this->mRoomID,$user);
+        if($ret != false) {
+            $ret['addr'] = $this->mAddr;
+            return self::outsuccess($ret,"room/invite",'wap');
+        } else {
+            return self::outerr(errcode::ErrRoom);
+        }
     }
 
     public function create_bargainOp()
     {
         $result = room\client::instance()->create();
-
     }
 }

+ 74 - 0
mobile/templates/default/room/invite.php

@@ -0,0 +1,74 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+    <meta http-equiv="content-type" content="text/html" />
+    <meta name="author" content="https://www.baidu.com" />
+    <meta name="viewport" content="width=750,user-scalable=no,target-densitydpi=device-dpi">
+    <meta name="format-detection" content="telephone=no">
+    <title>websocket test</title>
+    <script>
+
+        var addr    = "<?php echo $output['addr']; ?>";
+        var room    = <?php echo $output['room']; ?>;
+        var roomkey = "<?php echo $output['room_key']; ?>";
+
+        var socket;
+        function Connect()
+        {
+            try{
+                socket = new WebSocket(addr);
+            }catch(e){
+                alert('error');
+                return;
+            }
+            socket.onopen = sOpen;
+            socket.onerror = sError;
+            socket.onmessage= sMessage;
+            socket.onclose= sClose;
+        }
+        function sOpen(){
+            alert('connect success!');
+        }
+        function sError(e){
+
+        }
+        function sMessage(msg){
+            console.log(msg);
+            document.getElementById('onmessage').innerText += "<br>";
+
+            document.getElementById('onmessage').innerText += msg.data;
+        }
+        function sClose(e){
+            alert("connect closed:" + e.code);
+        }
+        function Send(){
+            socket.send(document.getElementById("msg").value);
+        }
+        function login()
+        {
+            var jsonobject = {
+                op:"join",
+                room:room,
+                room_key:roomkey,
+                code:'bargain'
+            };
+            socket.send(JSON.stringify(jsonobject));
+        }
+        function Close(){
+            socket.close();
+        }
+    </script>
+</head>
+
+<body>
+<div>
+    <span id="onmessage"></span>
+</div>
+
+<input id="msg" type="text">
+<button id="connect" onclick="Connect();">Connect</button>
+<button id="send" onclick="Send();">Send</button>
+<button id="login" onclick="login();">join</button>
+<button id="close" onclick="Close();">Close</button>
+</body>
+</html>

+ 16 - 10
shop/control/store_deliver.php

@@ -86,16 +86,22 @@ class store_deliverControl extends BaseSellerControl {
 		    showMessage(Language::get('wrong_argument'),'','html','error');
 		}
 
-		if (chksubmit()){
-		    $logic_order = Logic('order');
-		    $_POST['reciver_info'] = $this->_get_reciver_info();
-		    $result = $logic_order->changeOrderSend($order_info, 'seller', $_SESSION['member_name'], $_POST);
-			if (!$result['state']) {
-			    showMessage($result['msg'],'','html','error');
-			} else {
-			    showDialog($result['msg'],$_POST['ref_url'],'succ');
-			}
-		}
+		if (chksubmit())
+		{
+            $ret = Logic('delivery')->cancel_oms($order_info['order_sn']);
+            if($ret == true)
+            {
+                $logic_order = Logic('order');
+                $_POST['reciver_info'] = $this->_get_reciver_info();
+                $result = $logic_order->changeOrderSend($order_info, 'seller', $_SESSION['member_name'], $_POST);
+                if (!$result['state']) {
+                    showMessage($result['msg'],'','html','error');
+                } else {
+                    showDialog($result['msg'],$_POST['ref_url'],'succ');
+                }
+            }
+            showMessage($result['msg'],'','html','error');
+        }
 
         Tpl::output('order_info',$order_info);
 		//取发货地址

+ 1 - 1
test/TestOrder.php

@@ -24,7 +24,7 @@ class TestOrder extends PHPUnit_Framework_TestCase
     public function testCancelOms()
     {
         $oms = Logic('delivery');
-        $oms->cancel_oms('9000000002010310');
+        $oms->cancel_oms('9000000002963603');
     }
 
     public static function testSuccess()

+ 3 - 2
test/TestRoom.php

@@ -26,7 +26,8 @@ class TestRoom extends PHPUnit_Framework_TestCase
     {
         $user = 36490;
         $ret = room\client::instance()->create_chat($user);
-        $room_id = $ret['room_id'];
-        $ret = room\client::instance()->invite($room_id,36429);
+
+        $room_id = $ret['room'];
+        $retx = room\client::instance()->invite($room_id,36429);
     }
 }