Exemplo n.º 1
0
    def handle(self, *args, **options):
        print args

        file_path = 'account_no_product_list.xlsx'
        workbook = xlsxwriter.Workbook(file_path)
        table = workbook.add_worksheet()
        alist = [u'帐号名称', u'公司名称', u"联系人", u"手机号"]

        table.write_row('A1', alist)
        accounts = UserProfile.objects.filter(
            is_active=True, role=1, product_count=0).order_by('created_at')
        tmp_line = 1
        for account in accounts:
            tmp_line += 1
            tmp_list = [
                account.name, account.company_name, account.contacter,
                account.phone
            ]

            table.write_row('A{}'.format(tmp_line), tmp_list)

        workbook.close()
        receivers = [
            '*****@*****.**', '*****@*****.**',
            '*****@*****.**', '*****@*****.**'
        ]
        mode = ''
        if len(args) == 1:
            if args[0] == 'test':
                mode = 'test'
                receivers = ['*****@*****.**']
        title = u'未添加商品帐号{}'.format(datetime.now())
        content = u'您好,未添加商品帐号'

        sendmail(receivers, title, content, mode, file_path)
Exemplo n.º 2
0
def __send_email(user_id, emails, content_described, content):
    try:
        for email in emails.split('|'):
            if email.find('@') > -1:
                sendmail(email, content_described, content)
    except:
        notify_message = u"发送邮件失败user_id({}), cause:\n{}".format(
            user_id, unicode_full_stack())
        watchdog.warning(notify_message)
Exemplo n.º 3
0
    def handle(self, *args, **options):
        print args

        week_day = datetime.now().weekday()
        current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")

        first_day = "{}-01".format(current_time.rsplit('-', 1)[0])

        file_path = 'product_cps.xlsx'
        workbook = xlsxwriter.Workbook(file_path)
        table = workbook.add_worksheet()
        alist = [u'商品', u'供货商', u'开始时间', u'结束时间']
        table.write_row('A1', alist)
        promote_details = PromoteDetail.objects.filter(promote_status=1)

        product_ids = [p.product_id for p in promote_details]
        products = Product.objects.filter(id__in=product_ids)
        productid2name = dict([(p.id, p.name) for p in products])
        supplier_ids = [p.supplier for p in products]
        supplierid2name = dict([
            (s.id, s.name)
            for s in Supplier.objects.filter(id__in=supplier_ids)
        ])
        productid2supplierid = dict([(p.id, p.supplier) for p in products])
        tmp_line = 1
        for promote_detail in promote_details:
            if promote_detail.product_id != -1:
                tmp_line += 1

                tmp_list = [
                    productid2name[promote_detail.product_id], supplierid2name[
                        productid2supplierid[promote_detail.product_id]],
                    promote_detail.promote_time_from.strftime(
                        "%Y-%m-%d %H:%M:%S"),
                    promote_detail.promote_time_to.strftime(
                        "%Y-%m-%d %H:%M:%S")
                ]
                table.write_row('A{}'.format(tmp_line), tmp_list)
        workbook.close()

        receivers = ['*****@*****.**', '*****@*****.**']
        mode = ''
        if len(args) == 1:
            if args[0] == 'test':
                mode = 'test'
        title = u'微众自运营平台product_cps'
        content = u'您好'

        sendmail(receivers, title, content, mode, file_path)
Exemplo n.º 4
0
def _send_email(user, emails, content_described, content):
    """
	发送邮件
	:param user:
	:param emails:
	:param content_described:
	:param content:
	:return:
	"""
    try:
        for email in emails.split('|'):
            if email.find('@') > -1:
                sendmail(email, content_described, content)
    except:
        notify_message = u"发送邮件失败user_id({}), cause:\n{}".format(
            user.id, unicode_full_stack())
        watchdog_warning(notify_message)
Exemplo n.º 5
0
    def handle(self, *args, **options):
        """
        同步商品到新的自营平台。

        """
        # product_models.A.objects.filter()

        # user_id = models.IntegerField(default=0)  # 对应自营平台user_id
        # account_id = models.IntegerField(default=0)  # UserProfile id
        # supplier_id = models.IntegerField(default=0)  # 云上通的供货商id
        # store_name = models.CharField(max_length=1024, default='')  # y供货商名称
        file_path = 'PRODUCT_SHELVE_OFF.xlsx'
        current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        workbook   = xlsxwriter.Workbook(file_path)
        table = workbook.add_worksheet()
        alist = [u"商品名称", u"下架原因"]

        product_ids = product_models.ProductRevokeLogs.objects.all().values('product_id').distinct()
        products = product_models.Product.objects.filter(id__in=product_ids)
        tmp_line = 1
        for product in products:
            name = product.product_name
            reason = ""
            for log in product_models.ProductRevokeLogs.objects.filter(product_id=product.id):
                reason = reason + log.revoke_reasons


            tmp_line += 1
            tmp_list = [name, reason]

            table.write_row('A{}'.format(tmp_line),tmp_list)

        workbook.close()
        receivers = ['*****@*****.**', '*****@*****.**']
        mode = ''
        if len(args) == 1:
            if args[0] == 'test':
                mode = 'test'
                receivers = ['*****@*****.**']
        title = u'下架商品及原因{}'.format(current_time)
        content = u'您好,下架商品及原因'

        sendmail(receivers, title, content, mode, file_path)
Exemplo n.º 6
0
    def handle(self, *args, **options):
        print args

        week_day = datetime.now().weekday()
        current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")

        last_week_days = []
        #获取上周的时间(多取1天的时间,最后1天为本周1)
        for i in xrange(8):
            date = (datetime.now() -
                    timedelta(week_day - i + 7)).strftime(DATE_FORMAT)
            last_week_days.append(date)

        heads = [u'总订单', u'总订单金额', u'首单', u'首单金额', u'复购', u'复购金额']
        tmp_line = 1
        head_lists = []
        for last_week_day in last_week_days[:7]:
            for head in heads:
                tmp = last_week_day + head
                head_lists.append(tmp)

        file_path = u'order{}.xlsx'.format(last_week_days[0])
        workbook = xlsxwriter.Workbook(file_path)
        table = workbook.add_worksheet()

        head_lists = [u'平台名称'] + head_lists
        table.write_row('A1', head_lists)
        user_profiles = UserProfile.objects.filter(
            webapp_type=1).filter(~Q(user_id__in=[968, 930, 816, 16, 529]))
        for user_profile in user_profiles:
            tmp_line += 1
            user_id = user_profile.user_id
            nick_name = user_profile.store_name
            webapp_id = user_profile.webapp_id
            statistics_days = [nick_name]
            for i in xrange(7):
                orders_total = Order.objects.filter(
                    webapp_id=webapp_id,
                    created_at__gte=last_week_days[i],
                    created_at__lt=last_week_days[i + 1],
                    status__in=[2, 3, 4, 5],
                    origin_order_id__lte=0)
                orders_total_count = orders_total.count()
                orders_first = Order.objects.filter(
                    webapp_id=webapp_id,
                    created_at__gte=last_week_days[i],
                    created_at__lt=last_week_days[i + 1],
                    status__in=[2, 3, 4, 5],
                    is_first_order=True,
                    origin_order_id__lte=0)
                orders_first_count = orders_first.count()
                orders_not_first = Order.objects.filter(
                    webapp_id=webapp_id,
                    created_at__gte=last_week_days[i],
                    created_at__lt=last_week_days[i + 1],
                    status__in=[2, 3, 4, 5],
                    is_first_order=False,
                    origin_order_id__lte=0)
                orders_not_first_count = orders_not_first.count()
                paid_amount_total = 0.0
                paid_amount_total_first = 0.0
                paid_amount_total_not_first = 0.0
                for order in orders_total:
                    tmp_paid_amount = order.final_price + order.weizoom_card_money
                    paid_amount_total += tmp_paid_amount

                for order in orders_first:
                    tmp_paid_amount = order.final_price + order.weizoom_card_money
                    paid_amount_total_first += tmp_paid_amount

                for order in orders_not_first:
                    tmp_paid_amount = order.final_price + order.weizoom_card_money
                    paid_amount_total_not_first += tmp_paid_amount

                statistics_days.extend([
                    orders_total_count,
                    round(paid_amount_total, 2), orders_first_count,
                    round(paid_amount_total_first, 2), orders_not_first_count,
                    round(paid_amount_total_not_first, 2)
                ])

            table.write_row('A{}'.format(tmp_line), statistics_days)

        workbook.close()

        receivers = [
            '*****@*****.**', '*****@*****.**',
            '*****@*****.**'
        ]
        mode = ''
        if len(args) == 1:
            if args[0] == 'test':
                mode = 'test'
        title = u'微众自运营平台订单数量{}'.format(current_time)
        content = u'您好,这是上周统计的微众自运营平台订单数量'
        from core.sendmail import sendmail
        sendmail(receivers, title, content, mode, file_path)
    def handle(self, *args, **options):
        print args

        week_day = datetime.now().weekday()
        current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")

        first_day = "{}-01 00:00:00".format(current_time.rsplit('-', 1)[0])
        first_datetime = dateutil.parse_datetime(first_day)
        file_path = 'order_statistices_in_month_by_hour.xlsx'

        workbook = xlsxwriter.Workbook(file_path)
        table = workbook.add_worksheet()
        alist = [u"日期"]

        date_list = dateutil.get_date_range_list(first_datetime,
                                                 datetime.now())

        for d in date_list:
            alist.append(dateutil.date2string(d))

        table.write_row('A1', alist)

        for i in range(24):
            table.write(i + 1, 0, "%s:00 ~ %s:59" % (i, i))

        webapp_ids = [
            a.webapp_id for a in UserProfile.objects.filter(webapp_type=1)
        ]

        tmp_line = 1
        for d in date_list:
            tmp_line += 1
            date_str = dateutil.date2string(d)
            end_datetime = "%s 23:59:00" % date_str
            orders = Order.objects.filter(webapp_id__in=webapp_ids,
                                          status__in=[3, 4, 5],
                                          payment_time__gte=d,
                                          payment_time__lte=end_datetime,
                                          origin_order_id__in=[0, -1])

            for i in range(24):
                print "%s %s:00" % (date_str, i), "----", "%s %s:59" % (
                    date_str, i), "count()==", orders.filter(
                        webapp_id__in=webapp_ids,
                        payment_time__gte="%s %s:00" % (date_str, i),
                        payment_time__lte="%s %s:59" % (date_str, i),
                        origin_order_id__in=[0, -1]).count()
                total_price = orders.filter(
                    webapp_id__in=webapp_ids,
                    payment_time__gte="%s %s:00" % (date_str, i),
                    payment_time__lte="%s %s:59" % (date_str, i),
                    origin_order_id__in=[0, -1]).aggregate(
                        Sum('product_price'))['product_price__sum']
                if not total_price:
                    total_price = 0
                table.write(i + 1, tmp_line - 1, total_price)

        workbook.close()

        receivers = ['*****@*****.**', '*****@*****.**']
        mode = ''
        if len(args) == 1:
            if args[0] == 'test':
                mode = 'test'
                receivers = ['*****@*****.**']
        title = u'微众自运营平台当月时间段订单金额{}'.format(current_time)
        content = u'您好,微众自运营平台当月时间段订单金额'

        sendmail(receivers, title, content, mode, file_path)
Exemplo n.º 8
0
def apply_course(request):
	#获取当前会员
	try:
		member = request.member
		member_id = member.id
		member_name = member.username
	except:
		member_id = request.GET.get('member_id', '')
		member = member_module_api.get_member_by_id(int(member_id))
	course_name = request.GET.get('course_name', '')
	apply_number = int(request.GET.get('count', 0))
	owner_id = request.webapp_owner_id
	course_id = int(request.GET.get('course_id', 0))
	referrer = request.GET.get('referrer', '')
	cousrses= ShengjingCourseRegistration.objects.filter(member_id=member_id, course_id=course_id)
	if cousrses:
		course = cousrses[0]
		course.apply_number = apply_number
		course.save()
	else:
		course = ShengjingCourseRegistration()
		course.member_id = member_id
		course.course_id = course_id
		course.apply_number = apply_number
		course.owner_id = owner_id
		course.referrer = referrer
		course.save()
	_, member_info = get_binding_info_by_member(member)

	if member_info:
		companys = member_info.companys
		company_names = [c.name for c in companys]
		phone = member_info.phone_number
		member_name = member_info.name
	else:
		#没获取到对应的会员信息
		watchdog_error(u'报名时没有对应的盛景会员的信息  系统会员ID: %s' % member_id, user_id=request.user.id)
		company_names = []
		phone = ''
		member_name = ''
	company_name_strs = '_'.join(company_names)
	content = u'报名时间: %s<br>报名课程:%s<br>报名人:%s<br>所属公司:%s<br>电话:%s<br>预计参课人数: %s' % (datetime.today().strftime("%Y-%m-%d %H:%M"), course_name, member_name, company_name_strs, phone, apply_number)
	#是否是决策人	
	try:
		items = crm_api_views.get_userinfo_by_phone_number(member_info.phone_number)
	except:
		watchdog_error(u'盛景获取课程详情判断是否是决策人API出错')
		items = []
	try:
		phone_number = items['phone']
	except:
		phone_number = ''
	if not phone_number:
		content = content + u'<br>推荐人:%s' % referrer
#	try:
#		webapp_owner_id = request.webapp_owner_id
#	except:
	webapp_owner_id = request.GET.get('webapp_owner_id', '')
	emails = ShengjingEmailSettings.objects.filter(owner_id=webapp_owner_id)

	# 增加积分
	after_applied_course = ShengjingIntegralStrategySttings.objects.get(webapp_id=member.webapp_id).after_applied_course
	integral_caculator = IntegralCaculator()
	integral_caculator.increase_member_integral(member, after_applied_course, u'在线预约课程 获得积分')

	if emails:
		email= emails[0].course_registration_email
	else:
		watchdog_error(u'没有设置课程报名邮箱    邮箱内容: %s' % content, user_id=request.user.id)
		email = u''
	if email:
		sendmail(email, u'%s 报名' % course_name, content)
	
	response = create_response(200)
	return response.get_response()
Exemplo n.º 9
0
workbook   = xlsxwriter.Workbook(file_path)
table = workbook.add_worksheet()
alist = [u'商品', u'113销量数量', u'113订单数量',u'113销售金额',  u'114销量数量', u'114订单数量',u'114销售金额', u'115销量数量', u'115订单数量',u'115销售金额',  u'116销量数量', u'116订单数量',u'116销售金额']
table.write_row('A1',alist)
tmp_line = 1
products = Product.objects.filter(id__in=product_ids)
for product in products:
        tmp_line += 1
        tmp_list = [product.name]
        for d in ["2016-11-03", "2016-11-04", "2016-11-05", "2016-11-06"]:
                order_has_products = OrderHasProduct.objects.filter(product_id=product.id, order__origin_order_id__lte=0, order__status__in=sales_order_status, order__payment_time=d)
                order_counts = order_has_products.count()
                product_sales = order_has_products.aggregate(Sum('number'))['number__sum']
                product_sales = product_sales if product_sales else 0
                product_price_sum = order_has_products.aggregate(Sum('total_price'))['total_price__sum']
                product_price_sum = product_price_sum if product_price_sum else 0.0
                tmp_list.extend([order_counts, product_sales, product_price_sum])


	table.write_row('A{}'.format(tmp_line),tmp_list)
workbook.close()
mode = ''
receivers = ['*****@*****.**']
if len(args) == 1:
	if args[0] == 'test':
		mode = 'test'
title = u'微众自运营CPS商品销量{}'.format(current_time)
content = u'您好'

sendmail(receivers, title, content, mode, file_path)
Exemplo n.º 10
0
    def handle(self, *args, **options):
        print args

        week_day = datetime.now().weekday()
        current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")

        first_day = "{}-01".format(current_time.rsplit('-', 1)[0])

        file_path = 'product_pool_sales.xlsx'
        workbook = xlsxwriter.Workbook(file_path)
        table = workbook.add_worksheet()
        alist = [
            u'商品', u'供货商', u'分类', u'当月销量数量', u'当月销量金额', u'累计销售数量', u'累计销售金额'
        ]
        table.write_row('A1', alist)
        pool_weapp_profile = UserProfile.objects.filter(webapp_type=2).first()
        owner_pool = User.objects.get(id=pool_weapp_profile.user_id)

        product_ids = Product.objects.filter(
            owner=owner_pool,
            shelve_type__in=(PRODUCT_SHELVE_TYPE_ON,
                             PRODUCT_SHELVE_TYPE_OFF)).values_list('id',
                                                                   flat=True)
        manager_supplier_ids2name = dict([
            (s.id, s.name) for s in Supplier.objects.filter(
                owner_id=pool_weapp_profile.user_id)
        ])

        supplier_ids2name = {}
        product_id2store_name, product_id2sync_time = utils.get_sync_product_store_name(
            product_ids)
        #添加分类
        product_id2classification = {}
        relations = ClassificationHasProduct.objects.filter(
            product_id__in=product_ids)
        for r in relations:
            product_id2classification[r.product_id] = r.classification.name
        tmp_line = 1
        for product_id in product_ids:
            tmp_line += 1
            product = Product.objects.get(id=product_id)
            product_name = product.name

            store_name = manager_supplier_ids2name.get(product.supplier, "")
            if store_name:
                is_sync = True
            if not store_name:
                store_name = supplier_ids2name[
                    product.
                    supplier] if product.supplier and supplier_ids2name.has_key(
                        product.supplier) else product_id2store_name.get(
                            product.id, "")
                is_sync = product_id2store_name.has_key(product.id)
            if store_name:
                if is_sync:
                    supplier_name_export = u'同[{}]'.format(store_name)
                else:
                    supplier_name_export = u'自[{}]'.format(store_name)
            else:
                supplier_name_export = ''

            product_sales = 0
            weizoom_card = 0.0
            coupon_money = 0.0
            integral_money = 0.0
            cash = 0.0
            total = 0.0

            order_has_products = OrderHasProduct.objects.filter(
                product_id=product_id,
                order__origin_order_id__lte=0,
                order__status__in=sales_order_status,
                order__payment_time__gte=first_day)
            product_sales = order_has_products.aggregate(
                Sum('number'))['number__sum']
            product_sales = product_sales if product_sales else 0
            product_price_sum = order_has_products.aggregate(
                Sum('total_price'))['total_price__sum']
            product_price_sum = product_price_sum if product_price_sum else 0.0

            all_order_has_products = OrderHasProduct.objects.filter(
                product_id=product_id,
                order__origin_order_id__lte=0,
                order__status__in=sales_order_status)
            all_product_sales = all_order_has_products.aggregate(
                Sum('number'))['number__sum']
            all_product_sales = all_product_sales if all_product_sales else 0
            all_product_sum = all_order_has_products.aggregate(
                Sum('total_price'))['total_price__sum']
            all_product_sum = all_product_sum if all_product_sum else 0.0
            tmp_list = [
                product_name, supplier_name_export,
                product_id2classification.get(product_id, ''), product_sales,
                round(product_price_sum, 2), all_product_sales,
                round(all_product_sum, 2)
            ]
            table.write_row('A{}'.format(tmp_line), tmp_list)

        workbook.close()

        receivers = [
            '*****@*****.**', '*****@*****.**',
            '*****@*****.**', '*****@*****.**'
        ]
        mode = ''
        if len(args) == 1:
            if args[0] == 'test':
                mode = 'test'
        title = u'微众自运营平台商品销量{}'.format(current_time)
        content = u'您好,这是本月统计的微众自运营平台商品销量'

        sendmail(receivers, title, content, mode, file_path)
Exemplo n.º 11
0
    def handle(self, *args, **options):
        print args

        week_day = datetime.now().weekday()
        current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")

        first_day = "{}-01".format(current_time.rsplit('-', 1)[0])

        file_path = 'product_pool_55.xlsx'
        workbook = xlsxwriter.Workbook(file_path)
        table = workbook.add_worksheet()
        alist = [u'未上架55分成商品', u"供货商"]

        pool_weapp_profile = UserProfile.objects.filter(webapp_type=2).first()
        owner_pool = User.objects.get(id=pool_weapp_profile.user_id)

        id2usr_profiles = dict([(s.id, s) for s in UserProfile.objects.filter(
            webapp_type=1).filter(~Q(user_id__in=[968, 930, 816, 16, 529]))])
        manager_supplier_ids2name = dict([
            (s.id, s.name) for s in Supplier.objects.filter(
                owner_id=pool_weapp_profile.user_id, type=0)
        ])
        product_ids = Product.objects.filter(
            owner=owner_pool,
            supplier__in=manager_supplier_ids2name.keys()).values_list(
                'id', flat=True)

        product_ids = ProductPool.objects.filter(
            status=PP_STATUS_ON_POOL, product_id__in=product_ids).filter(~Q(
                woid__in=[968, 930, 816, 16, 529])).values_list('product_id',
                                                                flat=True)
        id2products = dict([
            (s.id, s) for s in Product.objects.filter(id__in=product_ids)
        ])
        woid_pids2pool = dict([(str(p.woid) + '_' + str(p.product_id), p)
                               for p in ProductPool.objects.filter(
                                   product_id__in=product_ids).filter(~Q(
                                       woid__in=[968, 930, 816, 16, 529]))])
        woid_pids = woid_pids2pool.keys()
        for id, value in id2usr_profiles.items():
            alist.append(value.store_name)
        table.write_row('A1', alist)

        tmp_line = 1
        for product_id, product in id2products.items():
            tmp_line += 1
            tmp_list = [
                product.name, manager_supplier_ids2name[product.supplier]
            ]

            for profile_id, profile in id2usr_profiles.items():
                current_key = str(profile.user_id) + '_' + str(product_id)
                if current_key in woid_pids:
                    if woid_pids2pool[current_key].status == PP_STATUS_ON_POOL:
                        tmp_list.append(u"否")
                    else:
                        tmp_list.append(u"是")
                else:
                    tmp_list.append(u"未同步")

            table.write_row('A{}'.format(tmp_line), tmp_list)

        workbook.close()
        receivers = [
            '*****@*****.**', '*****@*****.**',
            '*****@*****.**'
        ]
        mode = ''
        if len(args) == 1:
            if args[0] == 'test':
                mode = 'test'
                receivers = ['*****@*****.**']
        title = u'微众自运营平台未上架55分成商品{}'.format(current_time)
        content = u'您好,微众自运营平台未上架55分成商品'

        sendmail(receivers, title, content, mode, file_path)