Skip to content

Commit

Permalink
Merge pull request #28 from coolhwm/dev
Browse files Browse the repository at this point in the history
堂食外卖、访客详情、客户详情、优惠券领取记录、优惠券投放
  • Loading branch information
coolhwm committed Oct 27, 2017
2 parents 1c2447c + d414bd6 commit e3b8c69
Show file tree
Hide file tree
Showing 42 changed files with 1,415 additions and 182 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,19 @@
- [x] 制券;
- [x] 编辑/删除;
- [x] 卡券核销;
- [ ] 发放卡券;
- [x] 发放卡券;
- [x] 优惠券发放记录;
- [ ] 会员卡管理;
- [ ] 积分管理;
- [x] 满减优惠管理;
- [ ] 满送/秒杀活动

### 用户管理
- [x] 用户列表;
- [ ] 用户详情;
- [ ] 用户订单;
- [x] 用户详情;
- [x] 用户订单;
- [x] 常购商品;
- [x] 用户统计;
- [ ] 客服消息;


Expand All @@ -82,6 +85,8 @@
- 2017/09/08:增加卖家确认送达功能;
- 2017/09/24:增加分类管理、配送员管理、店铺管理、优惠管理;
- 2017/10/09:增加卡券核销;
- 2017/10/25:增加用户详情、用户订单、常购商品、用户优惠券、用户统计;
- 2017/10/27:堂食外卖、访客详情、优惠券领取记录、优惠券投放

## License
MIT
106 changes: 97 additions & 9 deletions src/api/coupon.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,48 @@

import base from './base';
import Page from '../utils/Page';

export default class coupon extends base {
/**
* 客户历史订单分页
* @param customerId
* @returns {Promise.<Pagination>}
*/
static async cutomerCouponPage (customerId) {
const url = `${this.baseUrl}/customers/${customerId}/coupon_list`;
return new Page(url, this._processCustomerCouponItem.bind(this));
}

/**
* 处理客户优惠券
* @param item
* @private
*/
static _processCustomerCouponItem(item) {
if (item.coupon == null) {
return;
}
Object.assign(item, item.coupon);

item.acceptTime = this._convertTimestapeToDay(item.acceptTime);
item.beginTime = this._convertTimestapeToDay(item.beginTime);
item.dueTime = this._convertTimestapeToDay(item.dueTime);
item.name = item.name ? item.name : '优惠券';

switch (item.status) {
case 'USED':
item.status = '进行中';
break;
case 'NEVER_USED':
item.status = '未开始';
break;
case 'EXPIRED':
item.status = '已失效';
break;
default:
item.status = '无效'
}
}

/**
* 分页方法
*/
Expand All @@ -11,25 +51,39 @@ export default class coupon extends base {
return new Page(url, this.processCouponItem.bind(this));
}

/**
* 优惠券使用情况分页方法
*/
static pagePick (couponId, type) {
if (type == 'NEVER_USED') {
const url = `${this.baseUrl}/coupons/${couponId}/used_info`;
return new Page(url, this.processCouponNeverUsed.bind(this));
} else {
const url = `${this.baseUrl}/coupons/${couponId}/used_info`;
return new Page(url, this.processCouponUsed.bind(this));
}
}

/**
* 新增卡券
*/
static async create(coupon) {
static async create (coupon) {
const url = `${this.baseUrl}/coupons`;
return await this.post(url, coupon);
}

/**
* 删除卡券
*/
static async remove(couponId) {
static async remove (couponId) {
const url = `${this.baseUrl}/coupons/${couponId}`;
return await this.delete(url);
}

/**
* 查询卡券信息
*/
static info(couponId) {
static info (couponId) {
const url = `${this.baseUrl}/coupons/${couponId}`;
return this.get(url).then(data => {
this.processCouponItem(data);
Expand All @@ -40,23 +94,23 @@ export default class coupon extends base {
/**
* 编辑卡券
*/
static async update(couponId, coupon) {
static async update (couponId, coupon) {
const url = `${this.baseUrl}/coupons/${couponId}`;
return await this.put(url, coupon);
}

/**
* 使用卡券
*/
static async use(id) {
static async use (id) {
const url = `${this.baseUrl}/coupons/use/${id}`;
return await this.put(url);
}

/**
* 数据处理
*/
static processCouponItem(coupon) {
static processCouponItem (coupon) {
if (coupon == null) {
return;
}
Expand All @@ -65,17 +119,51 @@ export default class coupon extends base {
coupon.name = coupon.name ? coupon.name : '优惠券';
}

/**
* 优惠券使用未使用情况数据处理
*/
static processCouponNeverUsed (item) {
const coupon = {};
if (item.customer) {
coupon.name = item.customer.nickName;
coupon.avatar = item.customer.avatarUrl;
}
coupon.key = '领取时间';
coupon.value = item.acceptTime;
return coupon;
}
/**
* 优惠券使用已使用情况数据处理
*/
static processCouponUsed (item) {
const coupon = {};
if (item.customer) {
coupon.name = item.customer.nickName;
coupon.avatar = item.customer.avatarUrl;
}
coupon.key = '使用时间';
coupon.value = item.usedTime;
return coupon;
}

/**
* 处理时间格式
*/
static _convertTimestapeToDay(timestape) {
static _convertTimestapeToDay (timestape) {
if (timestape == null) {
return;
}
let temp = timestape;
if (timestape.indexOf(' ') != -1) {
temp = timestape.substring(0, timestape.indexOf(' '))
temp = timestape.substring(0, timestape.indexOf(' '));
}
return temp.replace(/-/g, '.');
}
/**
* 卖家发放优惠券给买家数据处理
*/
static async send (coupon) {
const url = `${this.baseUrl}/coupons/send`;
return await this.post(url, coupon);
}
}
77 changes: 77 additions & 0 deletions src/api/customer_info.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import base from './base';
import Page from '../utils/Page';

export default class customerInfo extends base {
/**
* 获取客户地址
* @param customerId
* @returns {Promise.<TResult>}
*/
static async addressList(customerId) {
const url = `${this.baseUrl}/customers/${customerId}/detail_info`;
return this.get(url).then(data => {
data.addressList.forEach(v => {
if (v.sex == '1') {
v.name += ' 先生';
} else {
v.name += ' 女士';
}
});

return data.addressList;
});
}

/**
* 获取客户详细信息
*/
static async detailInfo(customerId) {
const url = `${this.baseUrl}/customers/${customerId}/detail_info`;
return this.get(url).then(data => {
let price = data.countCustomerInfo.totalPrice;
if (price > 1000 * 1000) {
data.countCustomerInfo.totalPrice = (price / 1000).toFixed(2) + 'k';
}
const lastTime = data.countCustomerInfo.lastOrderTime;
data.countCustomerInfo.lastOrderTime = this._dealDate(lastTime);
data.address = this._dealAddres(data.addressList);
return data;
});
}

/**
* 处理日期为 MM/DD
* @param date
* @returns {string}
* @private
*/
static _dealDate(date) {
try {
return date.substring(5, 10).replace('-', '/');
} catch (e) {
return '-';
}
}

/**
* 过滤地址为isDefault = 1,若无则为第一个
* @param addressList
* @returns {*}
* @private
*/
static _dealAddres(addressList) {
if (addressList && addressList.length > 0) {
let address;
let arr = addressList.filter(v => v.isDefault == '1');
if (arr.length > 0) {
address = arr[0];
} else {
address = addressList[0];
}

return address;
} else {
return null;
}
}
}
Loading

0 comments on commit e3b8c69

Please sign in to comment.