Esempio n. 1
0
    def post(self, request, **payload):
        try:
            user_id = payload.get('user_id')
            address = request.POST.get('address')
            handle_type = request.POST.get('handle_type')
            if handle_type == 'finish':
                if not address:
                    return JsonResponse({'ret': -2, 'msg': '地址数据为空'})
                mysql = Mysql()
                sql = "SELECT * FROM user_star_sign WHERE user_id = %s FOR UPDATE"
                mysql.getOne(sql, param=[user_id])
                sql = "SELECT * FROM user_star_sign WHERE \
                        user_id = %s \
                        AND one > 0 \
                        AND two > 0 \
                        AND three > 0 \
                        AND four > 0 \
                        AND five > 0 \
                        AND six > 0 \
                        AND seven > 0 \
                        AND eight > 0 \
                        AND nine > 0 \
                        AND ten > 0 \
                        AND eleven > 0 \
                        AND twelve > 0 \
                        AND state = 0"

                check = mysql.getOne(sql, param=[user_id])
                if not check:
                    mysql.dispose()
                    return JsonResponse({'ret': -2, 'msg': '碎片不足或已被领取'})
                sql = "UPDATE user_star_sign SET address = %s, \
                    state = 1 WHERE user_id = %s"

                mysql.update(sql, param=[address, user_id])
                patch_type = [i for i in range(1, 13)]
                getPatch(user_id, patch_type, 11, 0, mysql)
                mysql.dispose()
                return JsonResponse({'ret': 0, 'msg': '领取成功'})
            if handle_type == 'update':
                mysql = Mysql()
                sql = "SELECT * FROM user_star_sign WHERE state = 1 \
                    AND user_id = %s FOR UPDATE"

                user_info = mysql.getOne(sql, param=[user_id])
                if not user_info:
                    mysql.dispose()
                    return JsonResponse({'ret': -2, 'msg': '网络繁忙'})
                sql = "UPDATE user_star_sign SET address = %s \
                    WHERE user_id = %s AND state = 1"

                mysql.update(sql, param=[address, user_id])
                mysql.dispose()
                return JsonResponse({'ret': 0, 'msg': '领取成功'})
            return JsonResponse({'ret': -2, 'msg': '参数错误'})

        except Exception as e:
            mysql.errdispose()
            erroLog(e)
            return JsonResponse({'ret': -2, 'msg': '网络错误'})
Esempio n. 2
0
    def post(self, request):
        try:
            self.info['product_id'] = request.POST.get('product_id')
            self.info['productTypeId'] = request.POST.get('type_id')
            self.info['productName'] = request.POST.get('product_name')
            self.info['productImg'] = request.POST.get('product_img')
            self.info['hehecoin'] = request.POST.get('hhcoin')
            self.info['price'] = request.POST.get('price')
            self.info['remark'] = request.POST.get('remark')
            self.info['notes'] = request.POST.get('notes')
            self.info['user_goods_limit'] = request.POST.get(
                'user_goods_limit')  #个人总限量
            mysql = Mysql()
            sql = "UPDATE product SET productTypeId=%s, productName=%s,\
                productImg=%s, hehecoin=%s, minPrice=%s, user_goods_limit=%s,\
                maxPrice=%s, remark=%s, notes=%s WHERE id=%s"

            mysql.update(sql,
                         param=[
                             self.info['productTypeId'],
                             self.info['productName'], self.info['productImg'],
                             self.info['hehecoin'], self.info['price'],
                             self.info['user_goods_limit'], self.info['price'],
                             self.info['remark'], self.info['notes'],
                             self.info['product_id']
                         ])
            mysql.dispose()
            return JsonResponse({'ret': 0, 'msg': '编辑商品成功'})
        except Exception as e:
            print(e)
            mysql.errdispose()
            erroLog(e)
            return JsonResponse({'ret': -2, 'msg': '编辑商品失败'})
Esempio n. 3
0
    def post(self, request):
        try:
            self.info['store_id'] = request.POST.get('store_id')
            self.info['type_id'] = request.POST.get('type_id')
            self.info['product_name'] = request.POST.get('product_name')
            self.info['user_goods_limit'] = request.POST.get(
                'user_goods_limit')
            self.info['product_img'] = request.POST.get(
                'product_img')  #列表取第一张 多张逗号分隔
            self.info['hhcoin'] = request.POST.get('hhcoin')
            self.info['price'] = request.POST.get('price')
            self.info['remark'] = request.POST.get('remark')
            self.info['notes'] = request.POST.get('notes')
            mysql = Mysql()
            sql = "INSERT INTO product SET productTypeId=%s, productName=%s, \
                    user_goods_limit=%s, productImg=%s, upper_shelf=0, \
                    hehecoin=%s, minPrice=%s, maxPrice=%s, label=0, \
                    remark=%s, store_id=%s, notes=%s"

            mysql.insertOne(
                sql,
                param=[
                    self.info['type_id'], self.info['product_name'],
                    self.info['user_goods_limit'], self.info['product_img'],
                    self.info['hhcoin'], self.info['price'],
                    self.info['price'], self.info['remark'],
                    self.info['store_id'], self.info['notes']
                ])
            mysql.dispose()
            return JsonResponse({'ret': 0, 'msg': '添加商品成功'})
        except Exception as e:
            print(e)
            mysql.errdispose()
            erroLog(e)
            return JsonResponse({'ret': -2, 'msg': '添加商品失败'})
Esempio n. 4
0
 def get(self, request):
     try:
         qqq = 1
         zzz
         return HttpResponse(1)
     except Exception as e:
         erroLog(e)
         return HttpResponse(1)
Esempio n. 5
0
    def post(self, request):
        try:
            unionid = request.POST.get('unionid')
            position = request.POST.get('position')
            mysql = Mysql()
            sql = "SELECT * FROM h5_user WHERE unionid = %s FOR UPDATE"
            user_info = mysql.getOne(sql, param=[unionid])
            if not user_info:
                mysql.dispose()
                return JsonResponse({'ret': -2, 'msg': '无用户信息'})
            sql = 'SELECT * FROM gzh_user WHERE unionid = %s AND state = 1'
            gzh_info = mysql.getOne(sql, param=[unionid])
            if not gzh_info:
                mysql.dispose()
                return JsonResponse({'ret': -1, 'msg': '未关注公众号'})
            sql = "SELECT COUNT(*) AS numbers FROM h5_luckdraw_log \
                WHERE unionid = %s AND create_time BETWEEN %s AND %s"

            numbers = mysql.getOne(
                sql, param=[unionid, self.START_TIME, self.END_TIME])
            if numbers:
                if numbers.get('numbers') >= 12:
                    mysql.dispose()
                    return JsonResponse({'ret': -2, 'msg': '当日抽奖次数达到上限'})
            if user_info.get('lucky_draw_times') < 1:
                mysql.dispose()
                return JsonResponse({'ret': -2, 'msg': '抽奖次数不足'})
            sql = 'SELECT * FROM h5_luckdraw_log WHERE unionid = %s \
            AND position = %s AND create_time BETWEEN %s AND %s'

            luckdraw_postion = mysql.getOne(
                sql, param=[unionid, position, self.START_TIME, self.END_TIME])
            if luckdraw_postion:
                mysql.dispose()
                return JsonResponse({'ret': -2, 'msg': '网络繁忙'})
            sql = "UPDATE h5_user SET lucky_draw_times = \
                lucky_draw_times - 1 WHERE unionid = %s"

            mysql.update(sql, param=[unionid])
            patch_id = randomH5Patch()
            sql = "INSERT INTO h5_luckdraw_log SET unionid = %s, \
                patch_id = %s, state = 0, position=%s"

            mysql.insertOne(sql, param=[unionid, patch_id, position])
            mysql.dispose()
            return JsonResponse({
                'ret': 0,
                'msg': '抽奖成功',
                'result': {
                    'patch_id': patch_id,
                    'patch_name': STAR_SIGIN[patch_id]
                }
            })
        except Exception as e:
            mysql.errdispose()
            erroLog(e)
            return JsonResponse({'ret': -2, 'msg': '网络错误'})
Esempio n. 6
0
 def save_data(self):
     try:
         mysql = Mysql()
         # 获取userid
         sql = "UPDATE mer_orders SET wxid = %s, state = '1', \
             wx_money = %s, pay_time = NOW() WHERE order_num = %s "
         state = mysql.update(sql, param=[
             self.Info['wxid'],
             self.Info['total_fee'],
             self.Info['orderNum']
         ])
         mysql.dispose()
     except Exception as e:
         erroLog(e)
         print(e)
Esempio n. 7
0
 def post(self, request):
     try:
         phone = request.POST.get('phone')
         code = request.POST.get('code')
         conn = Open_Redis().getConn(7)
         if conn.exists(phone):
             cache = conn.get(phone)
             if cache.decode('utf-8') != code:
                 return HttpResponse(returnJson(-2, '验证码失效'))
             token = getToken({'user_id' : 907}, 24)
             token = {'token' : token}
             return HttpResponse(returnJson(0, '登录成功', result=token))
         return HttpResponse(returnJson(-1, '不存在验证码请重新发送'))
     except Exception as e:
         erroLog(e)
         return HttpResponse(returnJson(-2, '网络错误'))
Esempio n. 8
0
    def get(self, request):
        try:
            unionid = request.GET.get('unionid')
            if not unionid:
                return JsonResponse({'ret': -2, 'msg': '缺少参数'})
            mysql = Mysql()
            sql = 'SELECT * FROM h5_user WHERE unionid = %s'
            share_info = mysql.getOne(sql, param=[unionid])
            if not share_info:
                mysql.dispose()
                return JsonResponse({'ret': -2, 'msg': '公众号信息未授权'})
            # sql = 'SELECT id FROM userInfo WHERE unionId = %s'
            # user_id = mysql.getOne(sql, param=[unionid])
            # if not user_id:
            #     mysql.dispose()
            #     return JsonResponse({
            #         'ret' : -2,
            #         'msg' : '小程序信息未授权'
            #     })
            user_id = user_id.get('id')
            sql = 'SELECT one, two, three, four, five, six, seven, \
                eight, nine, ten, eleven, twelve \
                FROM user_star_sign WHERE user_id = %s'

            patch_info = mysql.getOne(sql, param=[user_id])
            sql = "SELECT hu.nickname,  hu.headimgurl \
                    FROM h5_help_log AS hl \
                    LEFT JOIN h5_user AS hu ON hl.help_unionid = hu.unionid \
                    WHERE leader_unionid = %s"

            helpuser_info = mysql.getAll(sql, param=[unionid])
            mysql.dispose()
            data = {
                'ret': 0,
                'msg': '查询成功',
                'resule': {
                    'patch_info': patch_info,
                    'help_user': helpuser_info,
                    'lucky_draw_times': share_info.get('lucky_draw_times')
                }
            }
            return JsonResponse(data)

        except Exception as e:
            erroLog(e)
            mysql.errdispose()
            return JsonResponse({'ret': -2, 'msg': '网络错误'})
Esempio n. 9
0
    def get(self, request, **payload):
        try:
            user_id = payload.get('user_id')
            mysql = Mysql()
            data = {}
            sql = "SELECT * FROM user_star_sign WHERE user_id = %s"
            result = mysql.getAll(sql, param=[user_id])
            data = {'ret': 0, 'result': result}
            if not result:
                sql = "INSERT INTO user_star_sign SET user_id = %s "
                mysql.insertOne(sql, param=[user_id])
                sql = "SELECT * FROM user_star_sign WHERE user_id = %s"
                info = mysql.getAll(sql, param=[user_id])
                data = {'ret': 0, 'msg': '查询成功', 'result': info}

            sql = "SELECT unionId FROM userInfo WHERE id = %s"
            user_info = mysql.getOne(sql, param=[user_id])
            if user_info.get('unionId'):
                sql = "SELECT * FROM h5_luckdraw_log WHERE unionid = %s AND state = 0"
                luckdraw_log = mysql.getAll(sql,
                                            param=[user_info.get('unionId')])
                if luckdraw_log:
                    patch_list = []
                    for i in luckdraw_log:
                        patch_list.append(i.get('patch_id'))
                        sql = 'UPDATE h5_luckdraw_log SET state = 1 WHERE id = %s'
                        mysql.update(sql, param=[i.get('id')])
                    getPatch(user_id, patch_list, 3, 1, mysql)
                    data['msg'] = '查询成功 碎片领取成功'
                    sql = "SELECT * FROM user_star_sign WHERE user_id = %s"
                    info = mysql.getAll(sql, param=[user_id])
                    data['result'] = info
                else:
                    data['msg'] = '查询成功 无碎片领取'
            else:
                data['ret'] = -1
                data['msg'] = '查询成功 但未绑定unionid 可能会导致h5抽奖碎片领取失败'
            mysql.dispose()
            return HttpResponse(callJson(data))
        except Exception as e:
            print(e)
            mysql.errdispose()
            erroLog(e)
            return JsonResponse({'ret': -2, 'msg': '网络错误'})
Esempio n. 10
0
 def post(self, request):
     try:
         phone = request.POST.get('phone')
         print(phone)
         if not phone:
             print(phone)
             return HttpResponse(returnJson(-2, '手机号码错误'))
         conn = Open_Redis().getConn(7)
         cache = conn.exists(phone)
         if conn.exists(phone):
             return HttpResponse(returnJson(-1, '已有验证码 请勿重新发送'))
         code = sendSms(phone)
         if code:
             code = {'code' : code}
             return HttpResponse(returnJson(0, '成功', code))
         return HttpResponse(returnJson(-2, '验证码发送失败'))
     except Exception as e:
         erroLog(e)
         return HttpResponse(returnJson(-2, '网络繁忙'))
Esempio n. 11
0
 def post(self, request):
     try:
         product_id = request.POST.get('product_id')
         mysql = Mysql()
         sql = "SELECT * FROM product WHERE id = %s AND upper_shelf=1"
         check = mysql.getOne(sql, param=[product_id])
         if check:
             mysql.dispose()
             return JsonResponse({'ret': -2, 'msg': '删除失败 商品上架中'})
         sql = "UPDATE product SET state = 0 WHERE id = %s"
         mysql.update(sql, param=[product_id])
         sql = "UPDATE stock SET state = 0 WHERE product_id = %s"
         mysql.update(sql, param=[product_id])
         mysql.dispose()
         return JsonResponse({'ret': 0, 'msg': '删除成功'})
     except Exception as e:
         print(e)
         mysql.errdispose()
         erroLog(e)
         return JsonResponse({'ret': -2, 'msg': '删除失败'})
Esempio n. 12
0
    def post(self, request):
        try:
            handle_type = request.POST.get('handle_type')
            unionid = request.POST.get('unionid')

            if handle_type == 'share':
                mysql = Mysql()
                sql = 'SELECT id as share_id FROM h5_user WHERE unionid = %s'
                share_info = mysql.getOne(sql, param=[unionid])
                if not share_info:
                    mysql.dispose()
                    return JsonResponse({'ret': -2, 'msg': '公众号信息未授权'})
                sql = 'SELECT * FROM gzh_user WHERE unionid = %s AND state = 1'
                gzh_info = mysql.getOne(sql, param=[unionid])
                if not gzh_info:
                    mysql.dispose()
                    return JsonResponse({'ret': -1, 'msg': '未关注公众号'})
                mysql.dispose()
                return JsonResponse({
                    'ret': 0,
                    'msg': '分享成功',
                    'result': share_info
                })

            if handle_type == 'help':
                mysql = Mysql()
                share_id = request.POST.get('share_id')
                print(share_id)
                unionid = request.POST.get('unionid')
                sql = 'SELECT * FROM h5_user WHERE unionid = %s'
                user_info = mysql.getOne(sql, param=[unionid])
                if not share_id and not unionid:
                    return JsonResponse({'ret': -2, 'msg': '参错错误'})
                if not user_info:
                    mysql.dispose()
                    return JsonResponse({'ret': -2, 'msg': '助力者公众号信息未授权'})
                sql = 'SELECT * FROM gzh_user WHERE unionid = %s AND state = 1'
                gzh_info = mysql.getOne(sql, param=[unionid])
                if not gzh_info:
                    mysql.dispose()
                    return JsonResponse({'ret': -1, 'msg': '未关注公众号'})
                sql = 'SELECT * FROM h5_user WHERE id = %s FOR UPDATE'
                share_info = mysql.getOne(sql, param=[share_id])
                sql = 'SELECT * FROM h5_help_log WHERE leader_unionid = %s AND help_unionid = %s'
                check = mysql.getOne(
                    sql, param=[share_info.get('unionid'), unionid])
                if check or share_info.get('unionid') == unionid:
                    mysql.dispose()
                    return JsonResponse({'ret': -2, 'msg': '已经助力, 请勿重复'})
                sql = 'INSERT INTO h5_help_log SET leader_unionid = %s, help_unionid = %s'
                mysql.insertOne(sql,
                                param=[share_info.get('unionid'), unionid])
                sql = 'UPDATE h5_user SET lucky_draw_times = lucky_draw_times + 1, \
                    help_times = help_times + 1 WHERE id = %s'

                mysql.update(sql, param=[share_id])
                sql = 'UPDATE h5_user SET lucky_draw_times = lucky_draw_times + 1 \
                    WHERE unionid = %s'

                mysql.update(sql, param=[unionid])
                mysql.dispose()
                return JsonResponse({'ret': 0, 'msg': '助力成功'})

            return JsonResponse({'ret': -2, 'msg': '参数错误'})

        except Exception as e:
            erroLog(e)
            return JsonResponse({'ret': -2, 'msg': '网络错误'})
Esempio n. 13
0
    def post(self, request, **payload):
        try:
            user_id = payload.get('user_id')
            handle_type = request.POST.get('handle_type')
            mysql = Mysql()

            if handle_type == 'mobile':
                sql = "SELECT mobile FROM userInfo WHERE id = %s"
                check = mysql.getOne(sql, param=[user_id])
                mysql.dispose()
                if not check:
                    return JsonResponse({'ret': -2, 'msg': '请绑定手机号'})
                state = starSignLog(user_id, 4)
                if state:
                    return JsonResponse({'ret': -2, 'msg': '已经领取'})
                path_type = randomPath()
                path_type = [path_type]
                suc = getPatch(user_id, path_type, 4, 1)
                return JsonResponse(suc)

            if handle_type == 'school':
                sql = "SELECT school_id FROM userInfo WHERE id = %s"
                check = mysql.getOne(sql, param=[user_id])
                mysql.dispose()
                if not check:
                    return JsonResponse({'ret': -2, 'msg': '请绑定校徽'})
                state = starSignLog(user_id, 5)
                if state:
                    return JsonResponse({'ret': -2, 'msg': '已经领取'})
                path_type = randomPath()
                path_type = [path_type]
                suc = getPatch(user_id, path_type, 5, 1)
                return JsonResponse(suc)

            if handle_type == 'step':
                sql = "SELECT * FROM coin_log WHERE userid = %s AND handleType = 3 \
                    AND handletime BETWEEN %s AND %s"

                check = mysql.getOne(sql,
                                     param=[user_id, START_TIME, END_TIME])
                mysql.dispose()
                if not check:
                    return JsonResponse({'ret': -2, 'msg': '未进行过微信步数'})
                state = starSignLog(user_id, 6)
                if state:
                    return JsonResponse({'ret': -2, 'msg': '已经领取'})
                path_type = randomPath()
                path_type = [path_type]
                suc = getPatch(user_id, path_type, 6, 1)
                return JsonResponse(suc)

            if handle_type == 'answer':
                sql = "SELECT * FROM quiz_log WHERE user_id = %s \
                    AND create_time BETWEEN %s AND %s"

                check = mysql.getOne(sql,
                                     param=[user_id, START_TIME, END_TIME])
                mysql.dispose()
                if not check:
                    return JsonResponse({'ret': -2, 'msg': '未进行过每日一答'})
                state = starSignLog(user_id, 7)
                if state:
                    return JsonResponse({'ret': -2, 'msg': '已经领取'})
                path_type = randomPath()
                path_type = [path_type]
                suc = getPatch(user_id, path_type, 7, 1)
                return JsonResponse(suc)

            if handle_type == 'click_card':
                sql = "SELECT * FROM click_card WHERE userid = %s \
                    AND checkTime BETWEEN %s AND %s"

                check = mysql.getOne(sql,
                                     param=[user_id, START_TIME, END_TIME])
                mysql.dispose()
                if not check:
                    return JsonResponse({'ret': -2, 'msg': '未进行过打卡'})
                state = starSignLog(user_id, 8)
                if state:
                    return JsonResponse({'ret': -2, 'msg': '已经领取'})
                path_type = randomPath()
                path_type = [path_type]
                suc = getPatch(user_id, path_type, 8, 1)
                return JsonResponse(suc)

            if handle_type == 'see':
                '''
                0未进行
                1已进行未领取
                2已领取
                '''
                sql = 'SELECT mobile, school_id FROM userInfo WHERE id = %s'
                user_info = mysql.getOne(sql, param=[user_id])
                check_mobile = 1 if user_info.get('mobile') else 0
                check_school = 1 if user_info.get('school_id') else 0

                sql = 'SELECT id FROM coin_log WHERE userid = %s AND handleType = 3 \
                    AND handletime BETWEEN %s AND %s'

                check_step = mysql.getOne(
                    sql, param=[user_id, START_TIME, END_TIME])
                check_step = 1 if check_step else 0

                sql = 'SELECT id FROM quiz_log WHERE user_id = %s \
                    AND create_time BETWEEN %s AND %s'

                check_answer = mysql.getOne(
                    sql, param=[user_id, START_TIME, END_TIME])
                check_answer = 1 if check_answer else 0

                sql = "SELECT id FROM click_card WHERE userid = %s \
                    AND checkTime BETWEEN %s AND %s"

                check_click_card = mysql.getOne(
                    sql, param=[user_id, START_TIME, END_TIME])
                check_click_card = 1 if check_click_card else 0

                sql = "SELECT id FROM star_sign_log WHERE user_id = %s AND handle_type = %s"
                log_info = mysql.getOne(sql, param=[user_id, 4])
                check_mobile = 2 if log_info else check_mobile

                sql = "SELECT id FROM star_sign_log WHERE user_id = %s AND handle_type = %s"
                log_info = mysql.getOne(sql, param=[user_id, 5])
                check_school = 2 if log_info else check_school

                sql = "SELECT id FROM star_sign_log WHERE user_id = %s AND handle_type = %s"
                log_info = mysql.getOne(sql, param=[user_id, 6])

                check_step = 2 if log_info else check_step

                sql = "SELECT id FROM star_sign_log WHERE user_id = %s AND handle_type = %s"
                log_info = mysql.getOne(sql, param=[user_id, 7])
                check_answer = 2 if log_info else check_answer

                sql = "SELECT id FROM star_sign_log WHERE user_id = %s AND handle_type = %s"
                log_info = mysql.getOne(sql, param=[user_id, 8])
                check_click_card = 2 if log_info else check_click_card
                mysql.dispose()

                data = {
                    'ret': 0,
                    'msg': '查询成功',
                    'result': {
                        'mobile': check_mobile,
                        'school': check_school,
                        'step': check_step,
                        'answer': check_answer,
                        'click_card': check_click_card
                    }
                }
                return JsonResponse(data)

            mysql.dispose()
            return JsonResponse({'ret': -2, 'msg': '参数错误'})
        except Exception as e:
            mysql.errdispose()
            erroLog(e)
            return JsonResponse({'ret': -2, 'msg': '网络错误'})
Esempio n. 14
0
    def post(self, request, **payload):
        try:
            user_id = payload.get('user_id')
            handle_type = request.POST.get('handle_type')
            #查看
            if handle_type == 'see':
                sql = "SELECT * FROM starry_market"
                data = query(sql)
                return HttpResponse(callJson(data))
            #购买
            if handle_type == 'buy':
                patch_id = int(request.POST.get('patch_id'))
                mysql = Mysql()
                sql = "SELECT * FROM starry_market WHERE id = %s FOR UPDATE"
                path_info = mysql.getOne(sql, param=[patch_id])
                if path_info.get('number') <= 0:
                    mysql.dispose()
                    return JsonResponse({'ret': -2, 'msg': '商品数量不足'})
                need_hhcoin = path_info.get('hhcoin')
                sql = "SELECT * FROM userInfo WHERE id = %s FOR UPDATE"
                user_info = mysql.getOne(sql, param=[user_id])
                if user_info.get('hhcoin') < need_hhcoin:
                    mysql.dispose()
                    return JsonResponse({'ret': -2, 'msg': '盒盒币不足'})
                up_sql, log_sql = Type_Log.coin_handle(user_id, 15,
                                                       need_hhcoin, 0)
                mysql.update(up_sql)
                mysql.insertOne(log_sql)
                up_sql, log_sql = starryMarketLog(user_id, patch_id,
                                                  NUMBER_DICT[patch_id],
                                                  need_hhcoin, 0, 1, mysql)
                mysql.update(up_sql)
                mysql.insertOne(log_sql)
                mysql.dispose()
                getPatch(user_id, [patch_id], 10, 1)
                return JsonResponse({'ret': 0, 'msg': '购买成功'})
            #出售
            if handle_type == 'sell':
                patch_id = int(request.POST.get('patch_id'))
                numbes = int(request.POST.get('numbes'))
                print('patchid')
                print(patch_id)
                print('出售数量')
                print(numbes)
                if numbes <= 0:
                    return JsonResponse({'ret': -2, 'msg': '网络繁忙'})
                mysql = Mysql()
                sql = "SELECT * FROM starry_market WHERE id = %s FOR UPDATE"
                path_info = mysql.getOne(sql, param=[patch_id])
                sql = f"SELECT * FROM user_star_sign WHERE {NUMBER_DICT[patch_id]} >= {numbes} AND user_id = {user_id}"
                user_path = mysql.getOne(sql)
                if not user_path:
                    mysql.dispose()
                    return JsonResponse({'ret': -2, 'msg': '用户碎片不足'})
                sql = "SELECT * FROM userInfo WHERE id = %s FOR UPDATE"
                user_info = mysql.getOne(sql, param=[user_id])
                up_sql, log_sql = Type_Log.coin_handle(
                    user_id, 15, PATCH_SELL_MONEY[patch_id], 1)
                mysql.update(up_sql)
                mysql.insertOne(log_sql)
                up_sql, log_sql = starryMarketLog(user_id, patch_id,
                                                  NUMBER_DICT[patch_id],
                                                  PATCH_SELL_MONEY[patch_id],
                                                  1, numbes, mysql)
                mysql.update(up_sql)
                mysql.insertOne(log_sql)
                mysql.dispose()
                getPatch(user_id, [patch_id], 10, 0)
                return JsonResponse({'ret': 0, 'msg': '出售成功'})
            #查看日志
            if handle_type == 'log':
                sql = "SELECT * FROM starry_market_log WHERE user_id = %s"
                data = query(sql, param=[user_id])
                return HttpResponse(callJson(data))

        except Exception as e:
            erroLog(e)
            return JsonResponse({'ret': -2, 'msg': '网络错误'})
Esempio n. 15
0
    def post(self, request, **payload):
        try:
            user_id = request.session.get('user_id')
            handle_type = request.POST.get('handle_type')

            if handle_type == 'one':
                mysql = Mysql()
                sql = "SELECT * FROM userInfo WHERE id = %s FOR UPDATE"
                user_info = mysql.getOne(sql, param=[user_id])
                if user_info.get('hhcoin') < 50:
                    return JsonResponse({'ret': -2, 'msg': '盒盒币不足'})
                up_sql, log_sql = Type_Log.coin_handle(user_id, 14, 50, 0)
                mysql.update(up_sql)
                mysql.insertOne(log_sql)
                #抽碎片
                path_type = randomWxPatch()
                if isinstance(path_type, dict):
                    self.addHhcoin(user_id, [path_type.get('hhcoin')], mysql)
                    mysql.dispose()
                    return JsonResponse({
                        'ret': 0,
                        'msg': f"抽中盒盒币{path_type.get('hhcoin')}个",
                        'result': {
                            'patch': [],
                            'hhcoin': [path_type.get('hhcoin')]
                        }
                    })
                getPatch(user_id, [path_type], 9, 1, mysql)
                mysql.dispose()
                data = {
                    'ret': 0,
                    'msg': f'抽奖成功, 获得了{STAR_SIGIN[path_type]}',
                    'result': {
                        'patch': [path_type],
                        'hhcoin': []
                    }
                }
                return JsonResponse(data)

            if handle_type == 'ten':
                mysql = Mysql()
                sql = "SELECT * FROM userInfo WHERE id = %s FOR UPDATE"
                user_info = mysql.getOne(sql, param=[user_id])
                if user_info.get('hhcoin') < 450:
                    mysql.dispose()
                    return JsonResponse({'ret': -2, 'msg': '盒盒币不足'})
                up_sql, log_sql = Type_Log.coin_handle(user_id, 14, 450, 0)
                mysql.update(up_sql)
                mysql.insertOne(log_sql)
                #抽碎片
                result = list(map(randomWxPatch, [i for i in range(10)]))
                patch_list = list(filter(lambda x: isinstance(x, int), result))
                hhcoin_list = [
                    x.get('hhcoin') for x in result if x not in patch_list
                ]
                self.addHhcoin(user_id, hhcoin_list, mysql)
                getPatch(user_id, patch_list, 9, 1, mysql)
                mysql.dispose()
                data = {
                    'ret': 0,
                    'msg': '抽奖成功',
                    'result': {
                        'patch': patch_list,
                        'hhcoin': hhcoin_list
                    }
                }
                return JsonResponse(data)

            if handle_type == 'log':
                mysql = Mysql()
                sql = "SELECT star_sign_id, create_time FROM star_sign_log \
                    WHERE user_id = %s AND handle_type = 9"

                patch_info = mysql.getAll(sql, param=[user_id])
                sql = "SELECT num, handletime FROM coin_log WHERE userid = %s \
                    AND handleType = 14 AND consumeType = 1"

                hhcoin_info = mysql.getAll(sql, param=[user_id])
                mysql.dispose()
                data = {
                    'ret': 0,
                    'msg': '查询成功',
                    'result': {
                        'patch_info': patch_info,
                        'hhcoin_info': hhcoin_info
                    }
                }
                return HttpResponse(callJson(data))

            else:
                return JsonResponse({'ret': -2, 'msg': '参数错误'})
        except Exception as e:
            mysql.errdispose()
            erroLog(e)
            return JsonResponse({'ret': -2, 'msg': '网络错误'})