Ejemplo n.º 1
0
        /// <summary>
        /// 生成商品,并判断是否开启创建任务计划
        /// </summary>
        /// <param name="msgCode">商品</param>
        /// <param name="urls">采集到的URL</param>
        /// <param name="isAutoSend"></param>
        /// <param name="callback">处理回调通知</param>
        private void QqForm_BuildGoodsHandler(long msgCode, List <string> urls, bool isAutoSend, Action <MessageCallBackType, int, int> callback)
        {
            if (weChatGroups == null)
            {
                weChatGroups = LogicHotTao.Instance(MyUserInfo.currentUserId).GetUserWeChatGroupListByUserId(MyUserInfo.currentUserId);
            }
            int groupCount = weChatGroups.Count();

            if (urls != null)
            {
                callback?.Invoke(MessageCallBackType.正在准备, 0, 0);
                List <Dictionary <string, string> > list = new List <Dictionary <string, string> >();
                Dictionary <string, string>         data = new Dictionary <string, string>();
                if (urls.Count() > 0)
                {
                    data["url"] = urls[0];
                }
                else
                {
                    data["url"] = "";
                }

                if (urls.Count() > 1)
                {
                    data["url2"] = urls[1];
                }
                else
                {
                    data["url2"] = "";
                }
                list.Add(data);

                string jsonUrls = JsonConvert.SerializeObject(list);
                //根据地址,获取商品优惠信息
                List <GoodsSelectedModel> goodsData = LogicGoods.Instance.getGoodsByLink(MyUserInfo.LoginToken, jsonUrls);
                try
                {
                    if (goodsData != null && goodsData.Count() > 0)
                    {
                        bool isUpdate = false;
                        //保存商品到本地数据库
                        int gid = LogicGoods.Instance.SaveGoods(goodsData[0], MyUserInfo.currentUserId, out isUpdate);
                        if (isUpdate)
                        {
                            return;
                        }

                        List <GoodsTaskModel> goodsidList = new List <GoodsTaskModel>();
                        goodsidList.Add(new GoodsTaskModel()
                        {
                            id = gid
                        });
                        List <GoodsTaskModel> pidList = new List <GoodsTaskModel>();
                        foreach (var group in weChatGroups)
                        {
                            if (pidList.FindIndex(r => { return(r.id == group.id); }) < 0)
                            {
                                pidList.Add(new GoodsTaskModel()
                                {
                                    id = group.id
                                });
                            }
                        }
                        string goodsText = JsonConvert.SerializeObject(goodsidList);
                        string pidsText  = JsonConvert.SerializeObject(pidList);

                        if (groupCount > 0 && isAutoSend)
                        {
                            // var taskplan = LogicHotTao.Instance(MyUserInfo.currentUserId).FindExecTaskPlanByUserId(MyUserInfo.currentUserId);
                            int taskId = 0;
                            callback?.Invoke(MessageCallBackType.开始创建计划, 0, groupCount);
                            //添加任务计划
                            var result = LogicHotTao.Instance(MyUserInfo.currentUserId).AddUserTaskPlan(new TaskPlanModel()
                            {
                                userid    = MyUserInfo.currentUserId,
                                title     = goodsData[0].goodsName,
                                startTime = DateTime.Now.AddHours(-1),
                                endTime   = DateTime.Now.AddHours(5),
                                pidsText  = pidsText,
                                goodsText = goodsText,
                                id        = 0
                            });
                            taskId = Convert.ToInt32(result.id);

                            #region 开始转链准备
                            string appkey    = string.Empty;
                            string appsecret = string.Empty;
                            if (myConfig == null)
                            {
                                myConfig = new ConfigModel();
                            }
                            else
                            {
                                ConfigSendTimeModel cfgTime = string.IsNullOrEmpty(myConfig.send_time_config) ? null : JsonConvert.DeserializeObject <ConfigSendTimeModel>(myConfig.send_time_config);
                                if (cfgTime != null)
                                {
                                    appkey    = cfgTime.appkey;
                                    appsecret = cfgTime.appsecret;
                                }
                            }

                            if (string.IsNullOrEmpty(appkey) && string.IsNullOrEmpty(appsecret))
                            {
                                appkey    = Resources.taobaoappkey;
                                appsecret = Resources.taobaoappsecret;
                            }

                            //开始转链
                            int i = 1;
                            LogicHotTao.Instance(MyUserInfo.currentUserId).BuildTaskTpwd(MyUserInfo.LoginToken, MyUserInfo.currentUserId, taskId, MyUserInfo.sendtemplate, appkey, appsecret, (share) =>
                            {
                                callback?.Invoke(MessageCallBackType.开始转链, i, groupCount);
                                i++;
                            });
                            #endregion
                            callback?.Invoke(MessageCallBackType.转链完成, 0, groupCount);
                        }
                    }
                    callback?.Invoke(MessageCallBackType.完成, 0, 0);
                }
                catch (Exception ex)
                {
                    log.Error(ex);
                }
            }
        }
Ejemplo n.º 2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtWeChatTitle.Text))
            {
                txtWeChatTitle.Focus();
                return;
            }
            MessageAlert alert = new MessageAlert();
            //Loading ld = new Loading();
            SetAutoReplyControl   replyControl      = hotAutoForm as SetAutoReplyControl;
            SetAutoRemoveChatroom autoRemoveControl = hotAutoForm as SetAutoRemoveChatroom;
            SendMessage           sendControl       = hotAutoForm as SendMessage;
            string groupTitle = txtWeChatTitle.Text;
            string groupPid   = txtPid.Text;

            ((Action)(delegate()
            {
                int flag = 0;
                UserWechatListModel data = new UserWechatListModel();
                if (hotTask != null)
                {
                    //data = LogicUser.Instance.UpdateUserWeChatTitle(MyUserInfo.LoginToken, editId, txtWeChatTitle.Text);

                    if (LogicHotTao.Instance(MyUserInfo.currentUserId).UpdateUserWeChatTitle(editId, groupTitle, groupPid, addType))
                    {
                        data.pid = groupPid;
                        data.wechattitle = groupTitle;
                        flag = 1;
                    }
                }
                else if (replyControl != null || sendControl != null)
                {
                    flag = LogicUser.Instance.UpdateUserWeChatTitle(MyUserInfo.LoginToken, txtWeChatTitle.Text, 0);
                }
                else if (autoRemoveControl != null)
                {
                    flag = LogicUser.Instance.UpdateUserWeChatTitle(MyUserInfo.LoginToken, txtWeChatTitle.Text, 1);
                }


                if (flag > 0)
                {
                    alert.Message = "保存成功";
                }
                else
                {
                    alert.Message = "保存失败,请检查是否重复";
                }

                //ld.CloseForm();
                this.BeginInvoke((Action)(delegate()
                {
                    alert.ShowDialog(this);
                    if (flag > 0)
                    {
                        if (hotTask != null)
                        {
                            //hotTask.SetPidView(data, editId > 0 ? CurrentRowIndex : -1);
                            hotTask.loadUserPidGridView();
                        }
                        else
                        {
                            if (replyControl != null)
                            {
                                replyControl.LoadDgvChatRoom();
                                if (hotForm.wxlogin != null)
                                {
                                    hotForm.wxlogin.LoadAutoHandleData();
                                }
                            }
                            else if (autoRemoveControl != null)
                            {
                                autoRemoveControl.LoadDgvChatRoom();
                            }
                            else if (sendControl != null)
                            {
                                sendControl.LoadDgvChatRoom();
                                if (hotForm.wxlogin != null)
                                {
                                    hotForm.wxlogin.LoadAutoHandleData();
                                }
                            }
                        }
                        this.Close();
                    }
                }));
            })).BeginInvoke(null, null);
            //ld.ShowDialog(hotForm);
        }
Ejemplo n.º 3
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            MessageAlert alert = new MessageAlert();

            if (!isJoinImage && string.IsNullOrEmpty(txtTaskTitle.Text))
            {
                alert.Message = "请输入任务标题";
                alert.ShowDialog(this);
                txtTaskTitle.Focus();
                return;
            }
            else
            {
                if (txtTaskTitle.Text.Length > 8)
                {
                    alert.Message = "商品简述最多8个字";
                    alert.ShowDialog(this);
                    txtTaskTitle.Focus();
                    return;
                }
            }
            if (string.IsNullOrEmpty(txtStartTime.Text))
            {
                txtStartTime.Focus();
                return;
            }
            if (string.IsNullOrEmpty(txtEndTime.Text))
            {
                txtEndTime.Focus();
                return;
            }
            string goodsText = JsonConvert.SerializeObject(hotGoodsText);
            string pidsText  = JsonConvert.SerializeObject(hotPidsText);

            TaskPlanModel model = new TaskPlanModel()
            {
                userid    = MyUserInfo.currentUserId,
                title     = isJoinImage ? "【合成图片转发】" + txtTaskTitle.Text : txtTaskTitle.Text,
                startTime = Convert.ToDateTime(txtStartTime.Text),
                endTime   = Convert.ToDateTime(txtEndTime.Text),
                pidsText  = pidsText,
                goodsText = goodsText,
                id        = taskid,
                status    = 0,
                isTpwd    = isJoinImage ? 1 : 0
            };
            Loading ld = new Loading();

            ((Action)(delegate()
            {
                TaskPlanModel data = LogicHotTao.Instance(MyUserInfo.currentUserId).AddUserTaskPlan(model);

                if (data != null)
                {
                    if (isJoinImage)
                    {
                        BuildText(Convert.ToInt32(data.id));
                    }
                    ld.CloseForm();
                    this.BeginInvoke((Action)(delegate()   //等待结束
                    {
                        if (hotTask != null)
                        {
                            //hotTask.SetTaskView(data, taskid > 0 ? CurrentRowIndex : -1);
                            hotTask.LoadTaskPlanGridView();
                        }
                        txtTaskTitle.Clear();
                        alert.Message = "保存成功";
                        alert.CallBack += () => { this.Close(); };
                        alert.ShowDialog(this);
                    }));
                }
                else
                {
                    ld.CloseForm();
                    this.BeginInvoke((Action)(delegate()   //等待结束
                    {
                        alert.Message = "保存失败";
                        alert.ShowDialog(this);
                    }));
                }
            })).BeginInvoke(null, null);
            ld.ShowDialog(hotForm);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 开始执行发送
        /// </summary>
        /// <param name="str">The string.</param>
        /// <param name="image">The image.</param>
        private void StartSend()
        {
            List <WindowInfo> wins = WinApi.GetAllDesktopWindows();

            if (wins == null || wins.Count() == 0)
            {
                return;
            }
            //获取任务数据
            var taskdata = LogicHotTao.Instance(MyUserInfo.currentUserId).FindByUserTaskPlanList(MyUserInfo.currentUserId);

            if (taskdata == null || taskdata.Count() == 0)
            {
                return;
            }

            //获取待执行的任务数据
            taskdata = taskdata.FindAll(item =>
            {
                return(item.status == 0 && item.isTpwd == 1 && item.startTime.CompareTo(DateTime.Now) < 0);
            }).OrderBy(x => x.startTime).ToList();

            if (taskdata == null || taskdata.Count() == 0)
            {
                return;
            }
            //排序
            taskdata = taskdata.OrderBy(x => x.startTime).ToList();

            foreach (var item in taskdata)
            {
                if (!isStartTask || MyUserInfo.currentUserId == 0)
                {
                    break;
                }

                if (item.endTime.CompareTo(DateTime.Now) < 0)
                {
                    break;
                }

                textResult.Clear();
                imageResult.Clear();

                int taskid = Convert.ToInt32(item.id);

                List <UserPidTaskModel> lst = JsonConvert.DeserializeObject <List <UserPidTaskModel> >(item.goodsText);
                List <int> ids = new List <int>();
                //如果群数据和商品数据都为空时
                if (lst == null || lst.Count() == 0)
                {
                    if (!isStartTask || MyUserInfo.currentUserId == 0)
                    {
                        break;
                    }
                    LogicHotTao.Instance(MyUserInfo.currentUserId).UpdateUserTaskPlanExecStatus(taskid, 2);
                    continue;
                }

                lst.ForEach(it =>
                {
                    if (!ids.Contains(it.id))
                    {
                        ids.Add(it.id);
                    }
                });
                //获取商品数据
                var goodslist = LogicHotTao.Instance(MyUserInfo.currentUserId).FindByUserGoodsList(MyUserInfo.currentUserId, ids);
                if (goodslist == null || goodslist.Count() == 0)
                {
                    if (!isStartTask || MyUserInfo.currentUserId == 0)
                    {
                        break;
                    }
                    LogicHotTao.Instance(MyUserInfo.currentUserId).UpdateUserTaskPlanExecStatus(taskid, 2);
                    continue;
                }
                //发送商品数据
                var result = SendGoods(goodslist, item, wins);

                if (result)
                {
                    if (!isStartTask || MyUserInfo.currentUserId == 0)
                    {
                        break;
                    }
                    LogicHotTao.Instance(MyUserInfo.currentUserId).UpdateUserTaskPlanExecStatus(taskid, 2);
                    //每个任务之间,休息一下
                    SleepTask();
                }
                else
                {
                    break;
                }
            }
        }