update shop image

This commit is contained in:
HibiKier 2022-07-03 13:55:26 +08:00
parent 6f82488af7
commit e5c036cee8
5 changed files with 81 additions and 16 deletions

View File

@ -243,6 +243,16 @@ __Docker 最新版本由 [Sakuracio](https://github.com/Sakuracio) 提供__
## 更新 ## 更新
### 2022/7/3
* BagUser提供方法`check_props`方法,用于判断用户是否含有该道具并是否使用
* 优化商品显示图片,提供限制,限购,折扣提示
* 修复图库内图片无法被连续删除的问题 [@pull/879](https://github.com/HibiKier/zhenxun_bot/pull/879)
### 2022/6/28
* 修复色图插件api修改无法搜索图片 [@pull/866](https://github.com/HibiKier/zhenxun_bot/pull/866)
### 2022/6/26 ### 2022/6/26
* 替换了bt URL * 替换了bt URL

View File

@ -1,3 +1,5 @@
from PIL import Image
from models.goods_info import GoodsInfo from models.goods_info import GoodsInfo
from utils.image_utils import BuildImage from utils.image_utils import BuildImage
from models.sign_group_user import SignGroupUser from models.sign_group_user import SignGroupUser
@ -63,8 +65,9 @@ async def create_shop_help() -> str:
_list.append(goods) _list.append(goods)
A = BuildImage(1000, h, color="#f9f6f2") A = BuildImage(1000, h, color="#f9f6f2")
current_h = 0 current_h = 0
total_n = 0
for goods in _list: for goods in _list:
bk = BuildImage(700, 80, font_size=15, color="#f9f6f2", font="CJGaoDeGuo.otf") bk = BuildImage(1180, 80, font_size=15, color="#f9f6f2", font="CJGaoDeGuo.otf")
goods_image = BuildImage( goods_image = BuildImage(
600, 80, font_size=20, color="#a29ad6", font="CJGaoDeGuo.otf" 600, 80, font_size=20, color="#a29ad6", font="CJGaoDeGuo.otf"
) )
@ -76,16 +79,27 @@ async def create_shop_help() -> str:
) )
await name_image.aline((380, -5, 280, 45), "#a29ad6", 5) await name_image.aline((380, -5, 280, 45), "#a29ad6", 5)
await name_image.atext((390, 0), "售价:", center_type="by_height") await name_image.atext((390, 0), "售价:", center_type="by_height")
await name_image.atext( if goods.goods_discount != 1:
(440, 0), str(goods.goods_price), (255, 255, 255), center_type="by_height" discount_price = int(goods.goods_discount * goods.goods_price)
) old_price_image = BuildImage(0, 0, plain_text=str(goods.goods_price), font_color=(194, 194, 194), font="CJGaoDeGuo.otf", font_size=15)
await old_price_image.aline((0, int(old_price_image.h / 2), old_price_image.w + 1, int(old_price_image.h / 2)), (0, 0, 0))
await name_image.apaste(
old_price_image, (440, 0), True
)
await name_image.atext(
(440, 15), str(discount_price), (255, 255, 255)
)
else:
await name_image.atext(
(440, 0), str(goods.goods_price), (255, 255, 255), center_type="by_height"
)
await name_image.atext( await name_image.atext(
( (
440 440
+ BuildImage(0, 0, plain_text=str(goods.goods_price), font_size=25).w, + BuildImage(0, 0, plain_text=str(goods.goods_price), font_size=25).w,
0, 0,
), ),
" 金币", f" 金币",
center_type="by_height", center_type="by_height",
) )
await name_image.acircle_corner(5) await name_image.acircle_corner(5)
@ -93,15 +107,18 @@ async def create_shop_help() -> str:
await goods_image.atext((15, 50), f"简介:{goods.goods_description}") await goods_image.atext((15, 50), f"简介:{goods.goods_description}")
await goods_image.acircle_corner(20) await goods_image.acircle_corner(20)
await bk.apaste(goods_image, alpha=True) await bk.apaste(goods_image, alpha=True)
n = 0
_w = 550
# 添加限时图标和时间 # 添加限时图标和时间
if goods.goods_limit_time > 0: if goods.goods_limit_time > 0:
n += 140
_limit_time_logo = BuildImage( _limit_time_logo = BuildImage(
40, 40, background=f"{IMAGE_PATH}/other/time.png" 40, 40, background=f"{IMAGE_PATH}/other/time.png"
) )
await bk.apaste(_limit_time_logo, (600, 0), True) await bk.apaste(_limit_time_logo, (_w + 50, 0), True)
await bk.apaste( await bk.apaste(
BuildImage(0, 0, plain_text="限时!", font_size=23, font="CJGaoDeGuo.otf"), BuildImage(0, 0, plain_text="限时!", font_size=23, font="CJGaoDeGuo.otf"),
(640, 10), (_w + 90, 10),
True, True,
) )
limit_time = time.strftime( limit_time = time.strftime(
@ -110,28 +127,66 @@ async def create_shop_help() -> str:
y_m_d = limit_time[0] y_m_d = limit_time[0]
_h_m = limit_time[1].split(":") _h_m = limit_time[1].split(":")
h_m = _h_m[0] + "" + _h_m[1] + "" h_m = _h_m[0] + "" + _h_m[1] + ""
await bk.atext((605, 38), str(y_m_d)) await bk.atext((_w + 55, 38), str(y_m_d))
await bk.atext((615, 57), str(h_m)) await bk.atext((_w + 65, 57), str(h_m))
await bk.aline((550, -1, 710, -1), "#a29ad6", 5) _w += 140
await bk.aline((550, 80, 710, 80), "#a29ad6", 5) if goods.goods_discount != 1:
n += 140
_discount_logo = BuildImage(30, 30, background=f"{IMAGE_PATH}/other/discount.png")
await bk.apaste(_discount_logo, (_w + 50, 10), True)
await bk.apaste(
BuildImage(0, 0, plain_text="折扣!", font_size=23, font="CJGaoDeGuo.otf"),
(_w + 90, 15),
True,
)
await bk.apaste(
BuildImage(0, 0, plain_text=f"{10 * goods.goods_discount:.1f}", font_size=30, font="CJGaoDeGuo.otf", font_color=(85, 156, 75)),
(_w + 50, 44),
True,
)
_w += 140
if goods.daily_limit != 0:
n += 140
_daily_limit_logo = BuildImage(35, 35, background=f"{IMAGE_PATH}/other/daily_limit.png")
await bk.apaste(_daily_limit_logo, (_w + 50, 10), True)
await bk.apaste(
BuildImage(0, 0, plain_text="限购!", font_size=23, font="CJGaoDeGuo.otf"),
(_w + 90, 20),
True,
)
await bk.apaste(
BuildImage(0, 0, plain_text=f"{goods.daily_limit}", font_size=30, font="CJGaoDeGuo.otf"),
(_w + 72, 45),
True,
)
if total_n < n:
total_n = n
if n:
await bk.aline((550, -1, 550 + n, -1), "#a29ad6", 5)
await bk.aline((550, 80, 550 + n, 80), "#a29ad6", 5)
# 添加限时图标和时间
idx += 1 idx += 1
await A.apaste(bk, (0, current_h), True) await A.apaste(bk, (0, current_h), True)
current_h += 90 current_h += 90
w = 1000 w = 850
if total_n:
w += total_n
h = A.h + 230 + 100 h = A.h + 230 + 100
h = 1000 if h < 1000 else h h = 1000 if h < 1000 else h
shop_logo = BuildImage(100, 100, background=f"{IMAGE_PATH}/other/shop_text.png") shop_logo = BuildImage(100, 100, background=f"{IMAGE_PATH}/other/shop_text.png")
shop = BuildImage(w, h, font_size=20, color="#f9f6f2") shop = BuildImage(w, h, font_size=20, color="#f9f6f2")
shop.paste(A, (20, 230)) zx_img = BuildImage(0, 0, background=f"{IMAGE_PATH}/zhenxun/toukan_3.png")
zx_img = BuildImage(0, 0, background=f"{IMAGE_PATH}/zhenxun/toukan.png") zx_img.transpose(Image.FLIP_LEFT_RIGHT)
zx_img.replace_color_tran(((240, 240, 240), (255, 255, 255)), (249, 246, 242)) zx_img.replace_color_tran(((240, 240, 240), (255, 255, 255)), (249, 246, 242))
await shop.apaste(zx_img, (780, 100)) await shop.apaste(zx_img, (0, 100))
shop.paste(A, (20 + zx_img.w, 230))
await shop.apaste(shop_logo, (450, 30), True) await shop.apaste(shop_logo, (450, 30), True)
shop.text( shop.text(
(int((1000 - shop.getsize("注【通过 序号 或者 商品名称 购买】")[0]) / 2), 170), (int((1000 - shop.getsize("注【通过 序号 或者 商品名称 购买】")[0]) / 2), 170),
"注【通过 序号 或者 商品名称 购买】", "注【通过 序号 或者 商品名称 购买】",
) )
shop.text((20, h - 100), "神秘药水\t\t售价9999999金币\n\t\t鬼知道会有什么效果~") shop.text((20 + zx_img.w, h - 100), "神秘药水\t\t售价9999999金币\n\t\t鬼知道会有什么效果~")
return shop.pic2bs4() return shop.pic2bs4()

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 136 KiB