示例#1
0
        public async Task reply(ActionContext ac)
        {
            string shopid = ac[typeof(ShopVarWork)];
            User prin = (User) ac.Principal;
            string wx = ac[this];

            string text = null;
            if (ac.GET)
            {
                ac.GivePane(200, m =>
                {
                    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;
                using (var dc = ac.NewDbContext())
                {
                    if (dc.Query1("SELECT msgs FROM chats WHERE shopid = @1 AND wx = @2", p => p.Set(shopid).Set(wx)))
                    {
                        dc.Let(out msgs);
                        msgs = msgs.AddOf(new ChatMsg {name = prin.name, text = text});
                        dc.Execute("UPDATE chats SET msgs = @1 WHERE shopid = @2 AND wx = @3", p => p.Set(msgs).Set(shopid).Set(wx));
                    }
                }
                await WeiXinUtility.PostSendAsync(wx, "【商家消息】" + prin.name + ":" + text + "(http://shop.144000.tv/pub/" + shopid + "/)");
                ac.GivePane(200);
            }
        }
示例#2
0
        public async Task abort(ActionContext ac)
        {
            long id = ac[this];

            if (ac.GET)
            {
                ac.GivePane(200, m => { m.FORM_().CALLOUT("确定要撤销此单,实收金额退回给买家?")._FORM(); });
            }
            else
            {
                decimal total = 0, cash = 0;
                using (var dc = ac.NewDbContext())
                {
                    if (dc.Query1("SELECT total, cash FROM orders WHERE id = @1", p => p.Set(id)))
                    {
                        dc.Let(out total).Let(out cash);
                    }
                }
                string err = await WeiXinUtility.PostRefundAsync(id, total, cash);

                if (err == null) // success
                {
                    using (var dc = ac.NewDbContext())
                    {
                        dc.Execute("UPDATE orders SET status = @1 WHERE id = @2", p => p.Set(Order.ABORTED).Set(id));
                    }
                    ac.GivePane(200);
                }
                else // err
                {
                    ac.GivePane(200, m => { m.FORM_().CALLOUT(err).CALLOUT("确定重复操作吗?")._FORM(); });
                }
            }
        }
示例#3
0
        public async Task refundq(ActionContext ac)
        {
            long id = ac[this];

            string err = await WeiXinUtility.PostRefundQueryAsync(id);

            if (err == null) // success
            {
                ac.GivePane(200, m =>
                {
                    m.FORM_();
                    m.CALLOUT("退款成功", false);
                    m._FORM();
                });
            }
            else
            {
                ac.GivePane(200, m =>
                {
                    m.FORM_();
                    m.CALLOUT(err);
                    m.CHECKBOX("ok", false, "重新提交退款请求", true);
                    m.BUTTON("", 1, "确认");
                    m._FORM();
                });
            }
        }
示例#4
0
        ///
        /// The application entry point.
        ///
        public static void Main(string[] args)
        {
            bool deploy = args.Length > 0;

            Db pg = new Db
            {
                host     = "106.14.45.109",
                port     = 5432,
                username = "******",
                password = "******"
            };

            WeiXinUtility.Setup("weixin.json", "apiclient_cert.p12", deploy);

            TryCreate <ShopService>(
                new ServiceContext("shop")
            {
                addrs  = new[] { "http://localhost:8080" },
                cipher = 0x4a78be76,
                cache  = true,
                db     = pg
            },
                deploy
                );

            StartAll();
        }
示例#5
0
        public async Task sendnotif(ActionContext ac)
        {
            long[] key   = ac.Query[nameof(key)];
            short  notif = 0;

            if (ac.GET)
            {
                ac.GivePane(200, m =>
                {
                    if (key == null)
                    {
                        m.CALLOUT("请先选择目标订单");
                    }
                    else
                    {
                        m.FORM_();
                        m.RADIOS(nameof(notif), notif, NOTIFS, label: "通知内容", required: true);
                        m._FORM();
                    }
                });
            }
            else
            {
                var f = await ac.ReadAsync <Form>();

                notif = f[nameof(notif)];
                List <Dual <long, string> > rows = new List <Dual <long, string> >(16);
                using (var dc = ac.NewDbContext())
                {
                    dc.Sql("SELECT id, wx FROM orders WHERE id")._IN_(key);
                    if (dc.Query())
                    {
                        while (dc.Next())
                        {
                            long   id;
                            string wx;
                            dc.Let(out id).Let(out wx);
                            rows.Add(new Dual <long, string>(id, wx));
                        }
                    }
                }

                for (int i = 0; i < rows.Count; i++)
                {
                    Dual <long, string> row = rows[i];
                    await WeiXinUtility.PostSendAsync(row.B, "【商家通知】" + NOTIFS[notif] + "(订单编号:" + row.A + ")");
                }

                ac.GivePane(200);
            }
        }
示例#6
0
        public async Task check(ActionContext ac)
        {
            long id = ac[this];

            decimal cash = await WeiXinUtility.PostOrderQueryAsync(id);

            if (cash > 0)
            {
                using (var dc = Service.NewDbContext())
                {
                    dc.Execute("UPDATE orders SET cash = @1 WHERE id = @2", p => p.Set(cash).Set(id));
                }
            }
            ac.GiveRedirect("../");
        }
示例#7
0
        public async Task prepay(ActionContext ac)
        {
            string wx = ac[typeof(UserVarWork)];
            long   id = ac[this];

            decimal total = 0;

            using (var dc = ac.NewDbContext())
            {
                total = (decimal)dc.Scalar("SELECT total FROM orders WHERE id = @1 AND wx = @2", p => p.Set(id).Set(wx));
            }
            string prepay_id = await WeiXinUtility.PostUnifiedOrderAsync(id, total, wx, ac.RemoteAddr, "http://shop.144000.tv/notify");

            ac.Give(200, WeiXinUtility.BuildPrepayContent(prepay_id));
        }
示例#8
0
        public async Task got(ActionContext ac)
        {
            long   id    = ac[this];
            string mgrwx = null;

            using (var dc = ac.NewDbContext())
            {
                var shopid = (string)dc.Scalar("UPDATE orders SET shipped = localtimestamp, status = @1 WHERE id = @2  RETURNING shopid", p => p.Set(Order.SHIPPED).Set(id));
                if (shopid != null)
                {
                    mgrwx = (string)dc.Scalar("SELECT mgrwx FROM shops WHERE id = @1", p => p.Set(shopid));
                }
            }
            if (mgrwx != null)
            {
                await WeiXinUtility.PostSendAsync(mgrwx, "【买家确收】订单编号:" + id);
            }

            ac.GiveRedirect("../");
        }
示例#9
0
        public async Task pay(ActionContext ac)
        {
            List <Transfer> lst = new List <Transfer>(16);

            using (var dc = ac.NewDbContext())
            {
                // retrieve
                if (dc.Query("SELECT r.id, mgrwx, mgr, cash FROM repays AS r, shops AS s WHERE r.shopid = s.id AND r.status = 0"))
                {
                    while (dc.Next())
                    {
                        Transfer tr;
                        dc.Let(out tr.id).Let(out tr.mgrwx).Let(out tr.mgr).Let(out tr.cash);
                        lst.Add(tr);
                    }
                }
            }

            // transfer for each
            foreach (var tr in lst)
            {
                string err = await WeiXinUtility.PostTransferAsync(tr.id, tr.mgrwx, tr.mgr, tr.cash, "订单结款");

                // update status
                using (var dc = ac.NewDbContext())
                {
                    if (err != null)
                    {
                        dc.Execute("UPDATE repays SET err = @1 WHERE id = @2", p => p.Set(err).Set(tr.id));
                    }
                    else
                    {
                        User prin = (User)ac.Principal;
                        dc.Execute("UPDATE repays SET payer = @1, paid = localtimestamp, err = NULL, status = 1 WHERE id = @2", p => p.Set(prin.name).Set(tr.id));
                    }
                }
            }
            ac.GiveRedirect();
        }
示例#10
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);
            }
        }