Commit f5d50c18 by wkliang

产品相关

parent 85b0c389
var system = require("../../../system") var system = require("../../../system")
const settings = require("../../../../config/settings")
const CtlBase = require("../../ctlms.base"); const CtlBase = require("../../ctlms.base");
const md5 = require("MD5");
const uuidv4 = require('uuid/v4');
const logCtl = system.getObject("web.common.oplogCtl");
class ProductCtl extends CtlBase { class ProductCtl extends CtlBase {
constructor() { constructor() {
super(); super();
this.userSve = system.getObject("service.uc.userSve"); this.prodSve = system.getObject("service.product.productSve");
this.redisClient = system.getObject("util.redisClient"); this.redisClient = system.getObject("util.redisClient");
} }
...@@ -22,6 +18,51 @@ class ProductCtl extends CtlBase { ...@@ -22,6 +18,51 @@ class ProductCtl extends CtlBase {
return system.getResultFail(500, "接口异常:" + error.message); return system.getResultFail(500, "接口异常:" + error.message);
} }
} }
async getPage (pobj, pobj2, req) {
try {
let res = await this.prodSve.getPage(pobj)
return system.getResultSuccess(res)
} catch (error) {
return system.getResultFail(500, err,message)
}
}
async getAllDic (pobj, pobj2, req) {
try {
let res = await this.prodSve.getAllDic(pobj)
return system.getResultSuccess(res)
} catch (error) {
return system.getResultFail(500, err,message)
}
}
async getByIds (pobj, pobj2, req) {
try {
let res = await this.prodSve.getByIds(pobj)
return system.getResultSuccess(res)
} catch (error) {
return system.getResultFail(500, err,message)
}
}
async getItems (pobj, pobj2, req) {
try {
let res = await this.prodSve.getItems(pobj)
return system.getResultSuccess(res)
} catch (error) {
return system.getResultFail(500, err,message)
}
}
async createOrUpdate (pobj, pobj2, req) {
try {
let res = await this.prodSve.createOrUpdate(pobj)
return system.getResultSuccess(res)
} catch (error) {
return system.getResultFail(500, err,message)
}
}
} }
module.exports = ProductCtl; module.exports = ProductCtl;
\ No newline at end of file
const system = require("../../../system");
const ServiceBase = require("../../svems.base")
class ProductService extends ServiceBase {
constructor() {
super();
}
async getPage (params) {
try {
return await this.callms("engine_product", "getPage", params)
} catch (error) {
throw error
}
}
async getAllDic (params) {
try {
return await this.callms("engine_product", "getAllDic", params)
} catch (error) {
throw error
}
}
async getByIds (params) {
try {
return await this.callms("engine_product", "getByIds", params)
} catch (error) {
throw error
}
}
async getItems (params) {
try {
return await this.callms("engine_product", "getItems", params)
} catch (error) {
throw error
}
}
async createOrUpdate (params) {
try {
return await this.callms("engine_product", "createOrUpdate", params)
} catch (error) {
throw error
}
}
}
module.exports = ProductService;
\ No newline at end of file
...@@ -186,7 +186,7 @@ class System { ...@@ -186,7 +186,7 @@ class System {
let local = "http://127.0.0.1"; let local = "http://127.0.0.1";
let dev = "http://39.107.234.14"; let dev = "http://39.107.234.14";
return { return {
// 签约引擎 // 产品引擎
engine_product: local + ":3571" + path, engine_product: local + ":3571" + path,
// 计费引擎 // 计费引擎
engine_fee: local + ":3103" + path, engine_fee: local + ":3103" + path,
...@@ -196,7 +196,7 @@ class System { ...@@ -196,7 +196,7 @@ class System {
engine_sign: local + ":3103" + path, engine_sign: local + ":3103" + path,
// 用户服务 // 用户服务
sve_uc: local + ":3651" + path, sve_uc: dev + ":3651" + path,
// 商户服务 // 商户服务
sve_merchant: dev + ":3103" + path, sve_merchant: dev + ":3103" + path,
// 订单服务 // 订单服务
......
...@@ -2,60 +2,70 @@ ...@@ -2,60 +2,70 @@
var system = require("../../base/system"); var system = require("../../base/system");
var fs = require('fs'); var fs = require('fs');
var marked = require("marked"); var marked = require("marked");
const os = require("os")
module.exports = function (app) { module.exports = function (app) {
app.get('/doc', function (req, res) { app.get('/doc', function (req, res) {
var path = process.cwd() + "/app/front/entry/public/apidoc/README.md"; // var path = process.cwd() + "/app/front/entry/public/apidoc/README.md";
// var path = process.cwd() + "/xgg-saas-platform/app/front/entry/public/apidoc/README.md"; // var path = process.cwd() + "/esign-admin/app/front/entry/public/apidoc/README.md";
fs.readFile(path, function(err, data){ var path = `${process.cwd()}${os.type == 'Windows_NT' ?
if(err){ "/esign-admin/app/front/entry/public/apidoc/README.md" :
"/app/front/entry/public/apidoc/README.md"}`;
fs.readFile(path, function (err, data) {
if (err) {
console.log(err); console.log(err);
res.send("文件不存在!"); res.send("文件不存在!");
} else{ } else {
console.log(data); console.log(data);
str = marked(data.toString()); str = marked(data.toString());
res.render('apidoc',{str}); res.render('apidoc', { str });
} }
}); });
}); });
app.get('/doc/:forder', function (req, res) { app.get('/doc/:forder', function (req, res) {
var path = process.cwd() + "/app/front/entry/public/apidoc/README.md"; // var path = process.cwd() + "/app/front/entry/public/apidoc/README.md";
// var path = process.cwd() + "/xgg-saas-platform/app/front/entry/public/apidoc/README.md"; // var path = process.cwd() + "/esign-admin/app/front/entry/public/apidoc/README.md";
var path = `${process.cwd()}${os.type == 'Windows_NT' ?
"/esign-admin/app/front/entry/public/apidoc/README.md" :
"/app/front/entry/public/apidoc/README.md"}`;
fs.readFile(path, function(err, data){ fs.readFile(path, function (err, data) {
if(err){ if (err) {
console.log(err); console.log(err);
res.send("文件不存在!"); res.send("文件不存在!");
} else{ } else {
console.log(data); console.log(data);
str = marked(data.toString()); str = marked(data.toString());
res.render('apidoc',{str}); res.render('apidoc', { str });
} }
}); });
}); });
app.get('/doc/:forder/:fileName', function (req, res) { app.get('/doc/:forder/:fileName', function (req, res) {
var forder = req.params["forder"]; var forder = req.params["forder"];
var fileName = req.params["fileName"] || "README.md"; var fileName = req.params["fileName"] || "README.md";
var path = process.cwd() + "/app/front/entry/public/apidoc"; // var path = process.cwd() + "/app/front/entry/public/apidoc";
// var path = process.cwd() + "/xgg-saas-platform/app/front/entry/public/apidoc"; // var path = process.cwd() + "/esign-admin/app/front/entry/public/apidoc";
if(forder) { var path = `${process.cwd()}${os.type == 'Windows_NT' ?
path = path + "/" + forder + "/" + fileName; "/esign-admin/app/front/entry/public/apidoc" :
"/app/front/entry/public/apidoc"}`;
if (forder) {
path = path + "/" + forder + "/" + fileName;
} else { } else {
path = path + "/" + fileName; path = path + "/" + fileName;
} }
fs.readFile(path, function(err, data){ fs.readFile(path, function (err, data) {
if(err){ if (err) {
console.log(err); console.log(err);
res.send("文件不存在!"); res.send("文件不存在!");
} else{ } else {
console.log(data); console.log(data);
str = marked(data.toString()); str = marked(data.toString());
console.log(str); console.log(str);
res.render('apidoc',{str}); res.render('apidoc', { str });
} }
}); });
}); });
}; };
[返回主目录](/doc) <a name="return">[返回主目录](/doc)</a>
<br><br>
<a name="menu">目录</a> <a name="menu">目录</a>
1. [添加](#add)
1. [更新](#upd) 1. [产品分页查询](#getPage)
1. [删除](#del) 2. [查询字典(根据 type 查询所有 name 数据)](#getAllDic)
1. [菜单树](#tree) 3. [根据 id 数组查询](#getByIds)
1. [菜单树-子菜单模式](#byPid) 4. [获取组合产品子产品列表](#getItems)
1. [明细](#queryById) 5. [添加/更新产品](#createOrUpdate)
## **<a name="add"> 添加</a>** ## **<a name="getPage"> 产品分页查询 </a>**
[返回到目录](#menu) [返回到目录](#menu)
##### URL
[/web/uc/authCtl/addAuth]
#### 参数格式 `JSON`
#### HTTP请求方式 `POST`
``` javascript #### 参数格式 `JSON`
{ #### HTTP 请求方式 `POST`
"pid": 2, // 父节点id
"menuType": 1, // 菜单类型 1菜单, 2接口
"name": "个体户系统", // 菜单名称
"icon": "123", // 菜单icon 选填
"path": "/aaa/bbb" // 菜单路由 选填
}
``` #### 接口地址 `/web/product/productCtl/getPage`
#### 参数说明
| 参数名 | 参数类型 | 必选项 | 备注 |
| -------- | -------- | ------ | -------------------- |
| page | number | 可选 | 页数 默认 1 |
| limit | number | 可选 | 每页条数 默认 10 |
| types | list | 可选 | 所选类别 默认 [0, 1] |
| keywords | string | 可选 | 关键字 |
#### 参数示例
#### 返回结果
```javascript ```javascript
{
"types": [0],
"keywords": "s",
"page": 1,
"limit": 1
}
```
{ #### 返回结果
"status": 0,
"msg": "success",
"data": null,
"requestid": "2dc587798f974902b06123ce34c39090"
}
```javascript
{
"status":0,
"msg":"success",
"data":{
"count":1,
"rows":[
{
"id":7,
"source_id":10001, // 产品来源 id
"product_name":"ssda", // 产品名称
"product_type":0, // 产品类型
"product_desc":"0", // 产品描述
"price":0, // 产品价格
"cost":0,
"created_at":"2020-06-29T11:31:35.000Z",
"updated_at":"2020-06-29T11:31:41.000Z",
"deleted_at":null,
"version":0
}]
},
"requestid":"453c672537b8469d848e4c2899273d4d"
}
``` ```
## **<a name="getAllDic"> 产品字典 </a>**
## **<a name="upd"> 更新</a>**
[返回到目录](#menu) [返回到目录](#menu)
##### URL
[/web/uc/authCtl/updAuth]
#### 参数格式 `JSON`
#### HTTP请求方式 `POST`
``` javascript #### 参数格式 `JSON`
{ #### HTTP 请求方式 `POST`
"id": 8, // 菜单id
"pid": 2, // 父节点id
"menuType": 1, // 菜单类型 1菜单, 2接口
"name": "个体户系统", // 菜单名称
"icon": "123", // 菜单icon 选填
"path": "/aaa/bbb" // 菜单路由 选填
} #### 接口地址 `/web/product/productCtl/getAllDic`
``` #### 参数说明
## **<a name="del"> 删除</a>** | 参数名 | 参数类型 | 必选项 | 备注 |
[返回到目录](#menu) | ------ | -------- | ------ | -------------------- |
##### URL | types | list | 可选 | 所选类别 默认 [0, 1] |
[/web/uc/authCtl/delAuth]
#### 参数格式 `JSON`
#### HTTP请求方式 `POST`
``` javascript #### 参数示例
{ ```javascript
"id": 1, //记录ID 必传 {
} "types": [0]
}
```
#### 返回结果
```javascript
{
"status":0,
"msg":"success",
"data":[
{
"id":7,
"product_type":0, // 产品类型
"product_name":"ssda" // 产品名称
}],
"requestid":"7451247abe9546d88a93c274d5d9c90a"
}
``` ```
## **<a name="getByIds"> 根据 id 数组查询 </a>**
## **<a name="tree"> 菜单树</a>**
[返回到目录](#menu) [返回到目录](#menu)
##### URL
[/web/uc/authCtl/tree]
#### 参数格式 `JSON`
#### HTTP请求方式 `POST`
``` javascript #### 参数格式 `JSON`
#### HTTP 请求方式 `POST`
{ #### 接口地址 `/web/product/productCtl/getByIds`
"id": 1, //记录ID 必传
}
#### 参数说明
| 参数名 | 参数类型 | 必选项 | 备注 |
| ------ | -------- | ------ | ------------ |
| ids | list | 必选 | 产品 id 列表 |
#### 参数示例
```javascript
{
"ids": [1, 2, 6, 7]
}
``` ```
#### 返回结果 #### 返回结果
```javascript ```javascript
{ {
"status": 0, "status":0,
"msg": "success", "msg":"success",
"data": { "data":[
{ {
"id": 1, // 菜单id "id":6,
"pid": 0, // 父节点id "source_id":10001,
"menuType": 1, // 菜单类型 1菜单, 2接口 "product_name":"asdf", // 产品名称
"name": "个体户系统", // 菜单名称 "product_type":1, // 产品类型
"icon": "123", // 菜单icon "product_desc":"0", // 产品描述
"path": "aaaaaaaaa", // 菜单路由 "price":0, // 产品价格
"childs": [...] // 子菜单 "cost":0,
} "created_at":"2020-06-29T03:17:00.000Z",
}, "updated_at":"2020-06-29T03:32:12.000Z",
"requestid": "007fd384e47641d2a71e9f3ef6292843" "deleted_at":null,
"version":0
},
{
"id":7,
"source_id":10001,
"product_name":"ssda",
"product_type":0,
"product_desc":"0",
"price":0,
"cost":0,
"created_at":"2020-06-29T11:31:35.000Z",
"updated_at":"2020-06-29T11:31:41.000Z",
"deleted_at":null,
"version":0
}],
"requestid":"d71d44c5c285435784ff386dc0024be7"
} }
``` ```
## **<a name="getItems"> 获取组合产品子产品列表 </a>**
## **<a name="byPid"> 菜单树-子菜单模式</a>**
[返回到目录](#menu) [返回到目录](#menu)
##### URL
[/web/uc/authCtl/byPid]
#### 参数格式 `JSON`
#### HTTP请求方式 `POST`
``` javascript #### 参数格式 `JSON`
#### HTTP 请求方式 `POST`
#### 接口地址 `/web/product/productCtl/getItems`
#### 参数说明
{ | 参数名 | 参数类型 | 必选项 | 备注 |
"pid": 1, // 必传 | ------ | -------- | ------ | ----------- |
} | id | number | 必选 | 组合商品 id |
#### 参数示例
```javascript
{
"id": 6
}
``` ```
#### 返回结果 #### 返回结果
```javascript ```javascript
{ {
"status": 0, "status":0,
"msg": "success", "msg":"success",
"data": [ "data":[
{
"id":1,
"source_id":10001,
"product_name":"ss", // 产品名称
"product_type":0, // 产品类型
"product_desc":"0", // 产品描述
"price":0, // 产品价格
"cost":0,
"created_at":"2020-06-28T17:37:28.000Z",
"updated_at":"2020-06-28T17:37:31.000Z",
"deleted_at":null,
"version":0
},
{ {
"id": 1, // 菜单id "id":7,
"pid": 0, // 父节点id "source_id":10001,
"menuType": 1, // 菜单类型 1菜单, 2接口 "product_name":"ssda",
"name": "个体户系统", // 菜单名称 "product_type":0,
"icon": "123", // 菜单icon "product_desc":"0",
"path": "aaaaaaaaa", // 菜单路由 "price":0,
} "cost":0,
], "created_at":"2020-06-29T11:31:35.000Z",
"requestid": "b340e352d57548d880540bcd05fbfee3" "updated_at":"2020-06-29T11:31:41.000Z",
"deleted_at":null,
"version":0
}],
"requestid":"91c226b3a1024cc5a78dc25acb27ff46"
} }
``` ```
## **<a name="queryById"> 明细</a>** ## **<a name="createOrUpdate"> 添加/更新产品 </a>**
[返回到目录](#menu) [返回到目录](#menu)
##### URL
[/web/uc/authCtl/queryById]
#### 参数格式 `JSON`
#### HTTP请求方式 `POST`
``` javascript #### 参数格式 `JSON`
#### HTTP 请求方式 `POST`
{ #### 接口地址 `/web/product/productCtl/createOrUpdate`
"id": 1, //记录ID 必传
}
#### 参数说明
| 参数名 | 参数类型 | 必选项 | 备注 |
| ------------ | -------- | -------- | -------------------------------------------------------------------------------- |
| id | number | 可选 | 更新产品的主键 如果没有则为创建 |
| source_id | number | 可选 | 产品来源 id 默认 10001 |
| product_name | string | 必选 | 产品名称 |
| product_type | number | 必选 | 产品类型 0: 单产品 1: 组合产品 |
| price | number | 可选 | 默认 0 |
| cost | number | 可选 | 默认 0 |
| api | string | 可选 | |
| items | list | 限定必选 | 子产品 id 列表 <br> 如果 product_type 为 1 则必有此项 <br> 如果为 0 则必没有此项 |
#### 参数示例
```javascript
{
"source_id": 10001,
"product_name": "testa",
"product_type": 1,
"product_desc": "testa",
"price": 1,
"cost": 0,
"api": "testurla",
"items":[8, 9, 10]
}
``` ```
#### 返回结果 #### 返回结果
```javascript
{ ```javascript
"status": 0, {
"msg": "success", "status":0,
"data": { "msg":"success",
"id": 1, // 菜单id "data":{
"pid": 0, // 父节点id
"menuType": 1, // 菜单类型 1菜单, 2接口
"name": "个体户系统", // 菜单名称
"icon": "123", // 菜单icon
"path": "aaaaaaaaa", // 菜单路由
}, },
"requestid": "6b34ba91355f407ab0592d3d8e39544c" "requestid":"e6f7a5e50e404296ad47c92f43a54de4"
} }
```
```
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment