Skip to content

Commit

Permalink
Merge pull request #53 from Chadwuo/one-piece
Browse files Browse the repository at this point in the history
v2.2.16
  • Loading branch information
Chadwuo authored Jul 28, 2023
2 parents 022d93e + 14ccbd2 commit 719b0cf
Show file tree
Hide file tree
Showing 6 changed files with 474 additions and 456 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

礼尚往来,是中华民族的传统美德,老一辈人一般会在举行宴席的时候用手写人情簿的方式来记录每一个亲友的送礼。这种方式存在很多弊端,比如人情簿丢失、无法携带在身边、很难搜索到某个人的送礼记录、由于手写原因无法辨认清楚内容等等。

「礼记」致力于记录和管理人情来往记录,给你方便快捷的人情记账体验!专业又懂你的人情记账软件,共享记账,全家人共享账本,多维度查询统计人情来往
「礼记」致力于记录和管理人情往来中的随礼、礼金、份子钱、送礼、收礼,专业又懂你的人情记账簿,全家人共享账本,多维度查询统计亲友间往来记录。每一份人情都值得礼记

---

Expand Down
51 changes: 29 additions & 22 deletions miniprogram/alicloud/services/friend.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
import pinyin from 'wl-pinyin';
import pinyin from "wl-pinyin";
const app = getApp();

/**
* 获取全部亲友数据集合
*
* @author chadwuo
*/
exports.getFriendList = async () => {
exports.getFriendList = async (parameter) => {
const db = app.mpserverless.db;
const dataScope = app.userDataScope;

const { searchValue } = parameter || {};
try {
const { result } = await db.collection('friend').find({
userId: {
$in: dataScope,
},
const { result } = await db.collection("friend").find({
$and: [
{ name: { $regex: searchValue } },
{
userId: {
$in: dataScope,
},
},
],
});

return {
Expand All @@ -36,7 +43,7 @@ exports.getFriendList = async () => {
exports.getFriend = async (parameter) => {
const db = app.mpserverless.db;
try {
const { result } = await db.collection('friend').findOne({
const { result } = await db.collection("friend").findOne({
_id: parameter._id,
});
return {
Expand All @@ -59,16 +66,16 @@ exports.getFriend = async (parameter) => {
exports.getFriendGifts = async (parameter) => {
const db = app.mpserverless.db;
try {
const { result } = await db.collection('friend').findOne({
const { result } = await db.collection("friend").findOne({
_id: parameter._id,
});
// 送礼集合
const { result: giftOutList } = await db.collection('gift_out').find({
const { result: giftOutList } = await db.collection("gift_out").find({
friendId: parameter._id,
});
// 收礼集合
const { result: giftReceiveList } = await db
.collection('gift_receive')
.collection("gift_receive")
.aggregate([
{
$match: {
Expand All @@ -83,16 +90,16 @@ exports.getFriendGifts = async (parameter) => {
{
$lookup: {
// 左连接
from: 'book', // 关联到de表
localField: 'bookId', // 左表关联的字段
foreignField: '_id', // 右表关联的字段
as: 'bookInfo',
from: "book", // 关联到de表
localField: "bookId", // 左表关联的字段
foreignField: "_id", // 右表关联的字段
as: "bookInfo",
},
},
{
$unwind: {
// 拆分子数组
path: '$bookInfo',
path: "$bookInfo",
preserveNullAndEmptyArrays: true, // 空的数组也拆分
},
},
Expand Down Expand Up @@ -122,7 +129,7 @@ exports.addFriend = async (parameter) => {
const userInfo = app.userInfo;
const db = app.mpserverless.db;
try {
const { result } = await db.collection('friend').insertOne({
const { result } = await db.collection("friend").insertOne({
userId: userInfo._id,
name: parameter.name.trim(),
firstLetter: pinyin.getFirstLetter(parameter.name.substr(0, 1)),
Expand All @@ -149,7 +156,7 @@ exports.addFriend = async (parameter) => {
exports.updateFriend = async (parameter) => {
const db = app.mpserverless.db;
try {
await db.collection('friend').updateOne(
await db.collection("friend").updateOne(
{
_id: parameter._id,
},
Expand All @@ -164,7 +171,7 @@ exports.updateFriend = async (parameter) => {
);
return {
success: true,
data: '',
data: "",
};
} catch (e) {
return {
Expand All @@ -183,20 +190,20 @@ exports.deleteFriend = async (parameter) => {
const db = app.mpserverless.db;
try {
// 删除亲友下所有送礼记录
await db.collection('gift_out').deleteMany({
await db.collection("gift_out").deleteMany({
friendId: parameter._id,
});
// 删除亲友下所有收礼记录
await db.collection('gift_receive').deleteMany({
await db.collection("gift_receive").deleteMany({
friendId: parameter._id,
});
// 删除亲友
await db.collection('friend').deleteOne({
await db.collection("friend").deleteOne({
_id: parameter._id,
});
return {
success: true,
data: '',
data: "",
};
} catch (e) {
return {
Expand Down
Loading

0 comments on commit 719b0cf

Please sign in to comment.