Ejemplo n.º 1
0
 public void Write <R>(IDataOutput <R> o, int proj = 0x00ff) where R : IDataOutput <R>
 {
     if (msgs != null && msgs.Length > 0)
     {
         int start = msgs.Length - NUM;
         if (start < 0)
         {
             start = 0;
         }
         for (int i = start; i < msgs.Length; i++)
         {
             ChatMsg msg = msgs[i];
             o.Put(nameof(msg.name), msg.text, msg.name);
         }
     }
 }
Ejemplo n.º 2
0
 public void all(ActionContext ac)
 {
     string shopid = ac[typeof(ShopVarWork)];
     string wx = ac[this];
     ac.GivePane(200, m =>
     {
         using (var dc = ac.NewDbContext())
         {
             if (dc.Query1("SELECT msgs FROM chats WHERE shopid = @1 AND wx = @2", p => p.Set(shopid).Set(wx)))
             {
                 ChatMsg[] msgs;
                 dc.Let(out msgs);
                 m.CARD_();
                 for (int i = 0; i < msgs.Length; i++)
                 {
                     ChatMsg msg = msgs[i];
                     m.CARDITEM(msg.name, msg.text);
                 }
                 m._CARD();
             }
         }
     });
 }
Ejemplo n.º 3
0
        public async Task custsvc(ActionContext ac, int subcmd)
        {
            string shopid = ac[this];

            User prin = (User)ac.Principal;

            string text = null;

            if (ac.GET)
            {
                ac.GivePane(200, m =>
                {
                    using (var dc = ac.NewDbContext())
                    {
                        if (dc.Query1("SELECT msgs FROM chats WHERE shopid = @1 AND wx = @2", p => p.Set(shopid).Set(prin.wx)))
                        {
                            ChatMsg[] msgs;
                            dc.Let(out msgs);
                            m.CARD_();
                            for (int i = 0; i < msgs.Length; i++)
                            {
                                ChatMsg msg = msgs[i];
                                m.CARDITEM(msg.name, msg.text);
                            }
                            m._CARD();
                        }
                    }
                    m.FORM_();
                    m.TEXT(nameof(text), text, "发送信息", pattern: "[\\S]*", max: 30, required: true);
                    m._FORM();
                });
            }
            else
            {
                var f = await ac.ReadAsync <Form>();

                text = f[nameof(text)];
                ChatMsg[] msgs;
                string    mgrwx = null;
                using (var dc = ac.NewDbContext())
                {
                    if (dc.Query1("SELECT msgs FROM chats WHERE shopid = @1 AND wx = @2", p => p.Set(shopid).Set(prin.wx)))
                    {
                        dc.Let(out msgs);
                        msgs = msgs.AddOf(new ChatMsg()
                        {
                            name = prin.name, text = text
                        });
                        dc.Execute("UPDATE chats SET msgs = @1, quested = localtimestamp WHERE shopid = @2 AND wx = @3", p => p.Set(msgs).Set(shopid).Set(prin.wx));
                    }
                    else
                    {
                        msgs = new[]
                        {
                            new ChatMsg()
                            {
                                name = prin.name, text = text
                            }
                        };
                        dc.Execute("INSERT INTO chats (shopid, wx, name, msgs, quested) VALUES (@1, @2, @3, @4, localtimestamp)", p => p.Set(shopid).Set(prin.wx).Set(prin.name).Set(msgs));
                    }

                    mgrwx = (string)dc.Scalar("SELECT mgrwx FROM shops WHERE id = @1", p => p.Set(shopid));
                }
                await WeiXinUtility.PostSendAsync(mgrwx, "【买家消息】" + prin.name + ":" + text);

                ac.GivePane(200);
            }
        }