作者 耿培杰

接口开发

... ... @@ -26,7 +26,7 @@ class Car extends Api
* @ApiSummary (获取购物车列表)
* @ApiMethod (POST)
* @ApiRoute (/api/car/getCarList)
* @ApiHeaders (name=token, type=string, required=false, description="请求的Token")
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name=page, type=string, required=false, description="页数")
* @ApiReturn({
"code": 1,
... ... @@ -66,9 +66,9 @@ class Car extends Api
* @ApiMethod (POST)
* @ApiRoute (/api/car/addCar)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name=goods_id, type=string, required=false, description="商品id")
* @ApiParams (name=number, type=string, required=false, description="数量")
* @ApiParams (name=type, type=string, required=false, description="类型:1=普通商品,2=积分商品,3=团购商品")
* @ApiParams (name=goods_id, type=string, required=true, description="商品id")
* @ApiParams (name=number, type=string, required=true, description="数量")
* @ApiParams (name=type, type=string, required=true, description="类型:1=普通商品,2=积分商品,3=团购商品")
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
... ... @@ -108,9 +108,64 @@ class Car extends Api
if (!$validate->check($data)) {
$this->error($validate->getError());
}
$last = $this->carModel->where(['user_id'=>$userId,'goods_id'=>$data['goods_id']])->count();
if ($last) $this->error('该商品已添加购物车');
$res = $this->carModel->save($data);
if ($res) $this->success('SUCCESS');
else $this->error('ERROR');
}
/**
* @ApiTitle (购物车数量递增)
* @ApiSummary (购物车数量递增)
* @ApiMethod (POST)
* @ApiRoute (/api/car/setIncCar)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name=car_id, type=string, required=true, description="购物车id")
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1587472510",
"data": {
}
})
*/
public function setIncCar(){
$userId = $this->getUserId();
$car_id = $this->request->param('car_id');
if (empty($car_id)) $this->error('缺少参数 car_id!');
$where['user_id'] = $userId;
$where['id'] = $car_id;
$res = $this->carModel->where($where)->setInc('number',1);
if ($res) $this->success('SUCCESS');
else $this->error('ERROR');
}
/**
* @ApiTitle (购物车数量递减)
* @ApiSummary (购物车数量递减)
* @ApiMethod (POST)
* @ApiRoute (/api/car/setDecCar)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name=car_id, type=string, required=true, description="购物车id")
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1587472510",
"data": {
}
})
*/
public function setDecCar(){
$userId = $this->getUserId();
$car_id = $this->request->param('car_id');
if (empty($car_id)) $this->error('缺少参数 car_id!');
$where['user_id'] = $userId;
$where['id'] = $car_id;
$res = $this->carModel->where($where)->setDec('number',1);
if ($res) $this->success('SUCCESS');
else $this->error('ERROR');
}
}
... ...
... ... @@ -43,4 +43,99 @@ class Category extends Api
$data['category3'] = $this->categoryModel->selectData(['pid'=>0],5);
$this->success('SUCCESS',$data);
}
/**
* @ApiTitle (分类页列表)
* @ApiSummary (分类页列表)
* @ApiMethod (POST)
* @ApiRoute (/api/category/getCategory)
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1587524078",
"data": {
"category1": [ 顶部分组列表
{
"id": 2, 分组id
"ch_name": "素食", 中文名称
"en_name": "vegetarian", 英文名称
"ch_index_name": "素食", 中文首页名称
"en_index_name": "vegetarian", 英文首页名称
"index_image": "http://q7s0a1rb4.bkt.clouddn.com/assets/img/qrcode.png", 首页图片
"image": "" 图片
}
],
"category2": [ 左侧一级分类列表
{
"id": 8, 分类id
"ch_name": "乳品蛋类", 中文名称
"en_name": "Eggs in the dairy", 英文名称
"image": "" 图片
},
{
"id": 1,
"ch_name": "生鲜产品",
"en_name": "fresh product",
"image": "http://q7s0a1rb4.bkt.clouddn.com/uploads/20200420/26f5e51b8ac7fbd6f1c649cc45a18265.png"
}
],
"category3": [ 右侧二级分类列表
{
"ch_name": "乳品蛋类", 一级分类中文名称
"en_name": "Eggs in the dairy", 一级分类英文名称
"list": [ 二级分类列表
{
"id": 11, 分类id
"ch_name": "酸奶/甜点", 二级分类中文名称
"en_name": "Yogurt/dessert", 二级分类英文名称
"image": ""
},
{
"id": 10,
"ch_name": "鸡蛋",
"en_name": "henapple",
"image": ""
},
{
"id": 9,
"ch_name": "牛奶",
"en_name": "milk",
"image": ""
}
]
},
{
"ch_name": "生鲜产品",
"en_name": "fresh product",
"list": [
{
"id": 5,
"ch_name": "水产海鲜",
"en_name": "aquaculture seafood",
"image": "http://q7s0a1rb4.bkt.clouddn.com/uploads/20200420/26f5e51b8ac7fbd6f1c649cc45a18265.png"
},
{
"id": 2,
"ch_name": "肉类",
"en_name": "meat",
"image": ""
}
]
}
]
}
})
*/
public function getCategory(){
$data['category1'] = $this->categoryGroupModel->selectData(['sitelist'=>['like','%' . 3 . '%']],4);
$data['category2'] = $this->categoryModel->selectData(['pid'=>0]);
$data['category3'] = [];
foreach ($data['category2'] as $k=>$v){
$data['category3'][$k]['ch_name'] = $v['ch_name'];
$data['category3'][$k]['en_name'] = $v['en_name'];
$data['category3'][$k]['list'] = $this->categoryModel->selectData(['pid'=>$v['id']]);
}
$this->success('SUCCESS',$data);
}
}
... ...
<?php
namespace app\api\controller;
use app\api\model\ChoosePage;
use app\api\model\Exhibition;
use app\api\model\Video;
use app\common\controller\Api;
use think\Db;
use think\Validate;
use think\Config;
/**
* 选购助手接口
*/
class Choose extends Api
{
protected function _initialize()
{
parent::_initialize();
}
/**
* @ApiTitle (获取选购助手列表)
* @ApiSummary (获取选购助手列表)
* @ApiMethod (POST)
* @ApiRoute (/api/choose/getChooseList)
* @ApiHeaders (name=token, type=string, required=false, description="请求的Token")
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1587518501",
"data": [
{
"id": 1,
"title": "公司介绍", 标题
"image": "http://q7s0a1rb4.bkt.clouddn.com/uploads/20200420/26f5e51b8ac7fbd6f1c649cc45a18265.png", 图片
},
{
"id": 2,
"title": "展会活动",
"image": "http://q7s0a1rb4.bkt.clouddn.com/uploads/20200420/26f5e51b8ac7fbd6f1c649cc45a18265.png",
}}
}
})
*/
public function getChooseList(){
$model = new ChoosePage();
$data = $model->selectData([]);
$this->success('SUCCESS',$data);
}
/**
* @ApiTitle (获取选购助手图文详情)
* @ApiSummary (获取选购助手图文详情)
* @ApiMethod (POST)
* @ApiRoute (/api/choose/getChooseInfo)
* @ApiHeaders (name=token, type=string, required=false, description="请求的Token")
* @ApiParams (name=choose_id, type=string, required=true, description="选购助手id")
* @ApiReturn({
})
*/
public function getChooseInfo(){
$model = new ChoosePage();
$choose_id = $this->request->param('choose_id');
if (!$choose_id) $this->error('缺少参数 choose_id!');
$data = $model->where(['id'=>$choose_id])->find();
$this->success('SUCCESS',$data);
}
/**
* @ApiTitle (获取选购助手短视频列表)
* @ApiSummary (获取选购助手短视频列表)
* @ApiMethod (POST)
* @ApiRoute (/api/choose/getChooseVideo)
* @ApiHeaders (name=token, type=string, required=false, description="请求的Token")
* @ApiParams (name=page, type=string, required=true, description="页数")
* @ApiReturn({
})
*/
public function getChooseVideo(){
$model = new Video();
$page = $this->request->param('page');
$limit = Config::get('paginate.index_rows');
$data = $model->selectPageData([],$page,$limit);
$this->success('SUCCESS',$data);
}
/**
* @ApiTitle (添加展会预约(个人预约))
* @ApiSummary (添加展会预约(个人预约))
* @ApiMethod (POST)
* @ApiRoute (/api/choose/addExhibitionType1)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name=name, type=string, required=true, description="姓名")
* @ApiParams (name=phone, type=string, required=true, description="手机号")
* @ApiParams (name=sex, type=string, required=true, description="性别")
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1587472510",
"data":
]
}
})
*/
public function addExhibitionType1(){
$model = new Exhibition();
$userId = $this->getUserId();
$data = $this->request->param();
$data['user_id'] = $userId;
$data['status'] = 1; //个人预约
$validate = new Validate([
'name' => 'require',
'phone' => ['^1\d{10}$','require'],
'sex' => 'require',
]);
$validate->message([
'name' => '缺少参数 name!',
'phone.require' => '缺少参数 phone!',
'sex' => '缺少参数 sex!',
'phone' => '手机号格式错误',
]);
if (!$validate->check($data)) {
$this->error($validate->getError());
}
$data = $model->save($data);
$this->success('SUCCESS',$data);
}
/**
* @ApiTitle (添加展会预约(商家预约))
* @ApiSummary (添加展会预约(商家预约))
* @ApiMethod (POST)
* @ApiRoute (/api/choose/addExhibitionType2)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name=name, type=string, required=true, description="姓名")
* @ApiParams (name=phone, type=string, required=true, description="手机号")
* @ApiParams (name=sex, type=string, required=true, description="性别")
* @ApiParams (name=store_type, type=string, required=true, description="商家类型")
* @ApiParams (name=num, type=string, required=true, description="参展人数")
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1587472510",
"data":
})
*/
public function addExhibitionType2(){
$model = new Exhibition();
$userId = $this->getUserId();
$data = $this->request->param();
$data['user_id'] = $userId;
$data['status'] = 2; //商家预约
$validate = new Validate([
'name' => 'require',
'phone' => ['^1\d{10}$','require'],
'sex' => 'require',
'store_type' => 'require',
'num' => 'require',
]);
$validate->message([
'name' => '缺少参数 name!',
'phone.require' => '缺少参数 phone!',
'phone' => '手机号格式错误',
'sex' => '缺少参数 sex!',
'store_type' => '缺少参数 store_type!',
'num' => '缺少参数 num!',
]);
if (!$validate->check($data)) {
$this->error($validate->getError());
}
$data = $model->save($data);
$this->success('SUCCESS',$data);
}
}
... ...
... ... @@ -27,7 +27,7 @@ class Evaluate extends Api
* @ApiMethod (POST)
* @ApiRoute (/api/evaluate/getGoodsEvaluate)
* @ApiHeaders (name=token, type=string, required=false, description="请求的Token")
* @ApiParams (name=goods_id, type=string, required=false, description="商品id")
* @ApiParams (name=goods_id, type=string, required=true, description="商品id")
* @ApiParams (name=page, type=string, required=false, description="页数")
* @ApiReturn({
"code": 1,
... ... @@ -67,7 +67,7 @@ class Evaluate extends Api
* @ApiMethod (POST)
* @ApiRoute (/api/evaluate/addGoodsEvaluate)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name=goods_id, type=string, required=false, description="商品id")
* @ApiParams (name=goods_id, type=string, required=true, description="商品id")
* @ApiParams (name=images, type=string, required=false, description="图片 例1.jpg,2.jpg")
* @ApiParams (name=content, type=string, required=true, description="评价内容")
* @ApiReturn({
... ... @@ -110,6 +110,6 @@ class Evaluate extends Api
$data = $this->evaluateModel->save($data);
$this->success('SUCCESS',$data);
$this->success('SUCCESS');
}
}
... ...
... ... @@ -11,12 +11,14 @@ use think\Config;
class Goods extends Api
{
protected $goodsModel;
protected $categoryModel;
protected $keywordLogModel;
public function _initialize()
{
parent::_initialize();
$this->goodsModel = new \app\api\model\Goods;
$this->categoryModel = new \app\api\model\Category;
$this->keywordLogModel = new \app\api\model\KeywordLog;
}
... ... @@ -50,12 +52,10 @@ class Goods extends Api
}
/**
* @ApiTitle (商品列表)
* @ApiSummary (商品列表)
* @ApiTitle (推荐商品列表)
* @ApiSummary (推荐商品列表)
* @ApiMethod (POST)
* @ApiRoute (/api/goods/getGoodsList)
* @ApiParams (name=keyword, type=string, required=false, description="关键字搜索")
* @ApiParams (name=page, type=string, required=false, description="页数")
* @ApiRoute (/api/goods/getRecommendGoods)
* @ApiReturn({
"code": 1,
"msg": "请求成功",
... ... @@ -66,9 +66,7 @@ class Goods extends Api
"ch_name": "EMP精选 澳洲白肉油桃 500~540g 4只装", 中文名称
"en_name": "EMP selected Australian white meat nectarines Australian meat nectarines", 英文名称
"image": "http://q7s0a1rb4.bkt.clouddn.com/uploads/20200420/26f5e51b8ac7fbd6f1c649cc45a18265.png", 缩略图
"goods_price": "0.00", 普通售价
"group_price": "0.00", 拼团售价 拼团售价优先级最高
"vip_price": "0.00", 会员售价
"goods_price": "0.00", 售价
"country_ch_name": "意大利", 原产地中文
"country_en_name": "Ltaly", 原产地英文
"is_vip_price": "2", 会员特价:1=开启,2=关闭
... ... @@ -77,29 +75,21 @@ class Goods extends Api
]
})
*/
public function getGoodsList()
public function getRecommendGoods()
{
$page = $this->request->param('page');
$limit = Config::get('paginate.index_rows');
$where = [];
$where['g.is_recommend'] = 1;
$keyword = $this->request->param('keyword');
if ($keyword){
$where['g.ch_name|g.en_name|g.ch_content|g.en_content'] = ['like','%'.$keyword.'%'];
//添加搜索记录
if ($this->userId) $this->keywordLogModel->save(['user_id'=>$this->userId,'content'=>$keyword,'createtime'=>time()]);
}
$data = $this->goodsModel->selectData($where, 10);
$data = $this->goodsModel->selectPageData($where,$page,$limit);
$this->success('请求成功', $data);
}
/**
* @ApiTitle (团购商品列表)
* @ApiSummary (团购商品列表)
* @ApiTitle (团购商品列表(首页))
* @ApiSummary (团购商品列表(首页))
* @ApiMethod (POST)
* @ApiRoute (/api/goods/getGroupGoodsList)
* @ApiParams (name=page, type=string, required=false, description="页数")
* @ApiRoute (/api/goods/getGroupGoodsIndex)
* @ApiReturn({
"code": 1,
"msg": "请求成功",
... ... @@ -121,19 +111,21 @@ class Goods extends Api
]
})
*/
public function getGroupGoodsList()
public function getGroupGoodsIndex()
{
$page = $this->request->param('page');
$limit = Config::get('paginate.index_rows');
$where['g.is_group'] = 1;
$data = $this->goodsModel->selectPageData($where,$page,$limit);
$data = $this->goodsModel->selectData($where, 5);
$this->success('请求成功', $data);
}
/**
* @ApiTitle (推荐商品列表)
* @ApiSummary (推荐商品列表)
* @ApiTitle (团购商品列表)
* @ApiSummary (团购商品列表)
* @ApiMethod (POST)
* @ApiRoute (/api/goods/getRecommendGoods)
* @ApiRoute (/api/goods/getGroupGoodsList)
* @ApiParams (name=page, type=string, required=false, description="页数")
* @ApiReturn({
"code": 1,
"msg": "请求成功",
... ... @@ -144,7 +136,9 @@ class Goods extends Api
"ch_name": "EMP精选 澳洲白肉油桃 500~540g 4只装", 中文名称
"en_name": "EMP selected Australian white meat nectarines Australian meat nectarines", 英文名称
"image": "http://q7s0a1rb4.bkt.clouddn.com/uploads/20200420/26f5e51b8ac7fbd6f1c649cc45a18265.png", 缩略图
"goods_price": "0.00", 售价
"goods_price": "0.00", 普通售价
"group_price": "0.00", 拼团售价 拼团售价优先级最高
"vip_price": "0.00", 会员售价
"country_ch_name": "意大利", 原产地中文
"country_en_name": "Ltaly", 原产地英文
"is_vip_price": "2", 会员特价:1=开启,2=关闭
... ... @@ -153,21 +147,21 @@ class Goods extends Api
]
})
*/
public function getRecommendGoods()
public function getGroupGoodsList()
{
$where['g.is_recommend'] = 1;
$data = $this->goodsModel->selectData($where, 10);
$page = $this->request->param('page');
$limit = Config::get('paginate.index_rows');
$where['g.is_group'] = 1;
$data = $this->goodsModel->selectPageData($where,$page,$limit);
$this->success('请求成功', $data);
}
/**
* @ApiTitle (团购商品列表(首页))
* @ApiSummary (团购商品列表(首页))
* @ApiTitle (商品列表)
* @ApiSummary (商品列表)
* @ApiMethod (POST)
* @ApiRoute (/api/goods/getGroupGoodsIndex)
* @ApiRoute (/api/goods/getGoodsList)
* @ApiParams (name=page, type=string, required=false, description="页数")
* @ApiReturn({
"code": 1,
"msg": "请求成功",
... ... @@ -189,22 +183,216 @@ class Goods extends Api
]
})
*/
public function getGroupGoodsIndex()
public function getGoodsList()
{
$where['g.is_group'] = 1;
$page = $this->request->param('page');
$limit = Config::get('paginate.index_rows');
$where = [];
$data = $this->goodsModel->selectData($where, 5);
$keyword = $this->request->param('keyword');
if ($keyword){
$where['g.ch_name|g.en_name|g.ch_content|g.en_content'] = ['like','%'.$keyword.'%'];
//添加搜索记录
if ($this->userId) $this->keywordLogModel->save(['user_id'=>$this->userId,'content'=>$keyword,'createtime'=>time()]);
}
$data = $this->goodsModel->selectPageData($where,$page,$limit);
$this->success('请求成功', $data);
}
/**
* @ApiTitle (分类商品列表)
* @ApiSummary (分类商品列表)
* @ApiMethod (POST)
* @ApiRoute (/api/goods/getCategoryGoodsList)
* @ApiParams (name=category_two_id, type=string, required=true, description="二级分类id")
* @ApiParams (name=category_three_id, type=string, required=false, description="三级分类id")
* @ApiParams (name=category_group_id, type=string, required=false, description="分组id")
* @ApiParams (name=country_id, type=string, required=false, description="国家id")
* @ApiParams (name=brand_id, type=string, required=false, description="品牌id")
* @ApiParams (name=level_id, type=string, required=false, description="等级id")
* @ApiParams (name=part_id, type=string, required=false, description="部位id")
* @ApiParams (name=category2_id, type=string, required=false, description="品类id")
* @ApiParams (name=page, type=string, required=false, description="页数")
* @ApiReturn({
"code": 1,
"msg": "请求成功",
"time": "1587539236",
"data": {
"country": { 国家
"1": {
"id": 1, 国家id
"ch_name": "意大利", 中文名称
"en_name": "Ltaly" 英文名称
}
},
"brand": { 品牌
"1": {
"id": 1, 品牌id
"ch_name": "HAR", 中文名称
"en_name": "HAR" 英文名称
}
},
"level": { 等级
"1": {
"id": 1, 等级id
"ch_name": "草饲", 中文名称
"en_name": "Forage fed" 英文名称
}
},
"part": { 部位
"1": { 部位id
"id": 1,
"ch_name": "战斧", 中文名称
"en_name": "Tomahawk" 英文名称
}
},
"category2": [], 品类
"list": {
"total": 1, 总条数
"list": [
{
"goods_id": 1, 商品id
"ch_name": "EMP精选 澳洲白肉油桃 500~540g 4只装", 中文名称
"en_name": "EMP selected Australian white meat nectarines Australian meat nectarines", 英文名称
"image": "http://q7s0a1rb4.bkt.clouddn.com/uploads/20200420/26f5e51b8ac7fbd6f1c649cc45a18265.png", 缩略图
"goods_price": "123.00", 价格
"ch_country_name": "意大利", 中文名称
"en_country_name": "Ltaly", 英文名称
"is_vip_price": "2", 会员特价:1=开启,2=关闭
"is_group": "2", 团购:1=开启,2=关闭
"group_price": null, 拼团售价 拼团售价优先级最高
"vip_price": "0.00", 会员售价
"stock_num": 55 库存
}
]
}
}
})
*/
public function getCategoryGoodsList()
{
$params = $this->request->param();
if (empty($params['category_two_id'])) $this->error('缺少参数 category_two_id!');
$page = $params['page'];
$limit = Config::get('paginate.index_rows');
$where['category_two_id'] = $params['category_two_id'];
if (!empty($params['category_three_id'])) $where['category_three_id'] = $params['category_three_id'];
if (!empty($params['category_group_id'])) $where['category_group_ids'] = ['like','%,'.$params['category_group_id'].',%'];
if (!empty($params['country_id'])) $where['country_id'] = $params['country_id'];
if (!empty($params['brand_id'])) $where['brand_id'] = $params['brand_id'];
if (!empty($params['level_id'])) $where['level_id'] = $params['level_id'];
if (!empty($params['part_id'])) $where['part_id'] = $params['part_id'];
if (!empty($params['category2_id'])) $where['category2_id'] = $params['category2_id'];
//获取筛选标签,国家,品牌,等级,部位,品类
$data = $this->categoryModel->getExtend($where);
//获取三级分类
$data['category_three'] = $this->categoryModel->selectData(['pid'=>$params['category_two_id']]);
//获取列表数据
$data['list'] = $this->goodsModel->selectPageData($where,$page,$limit);
$this->success('请求成功', $data);
}
/**
* @ApiTitle (搜索商品列表)
* @ApiSummary (搜索商品列表)
* @ApiMethod (POST)
* @ApiRoute (/api/goods/getSearchGoodsList)
* @ApiParams (name=keyword, type=string, required=false, description="关键字搜索")
* @ApiParams (name=country_id, type=string, required=false, description="国家id")
* @ApiParams (name=brand_id, type=string, required=false, description="品牌id")
* @ApiParams (name=level_id, type=string, required=false, description="等级id")
* @ApiParams (name=part_id, type=string, required=false, description="部位id")
* @ApiParams (name=category2_id, type=string, required=false, description="品类id")
* @ApiParams (name=page, type=string, required=false, description="页数")
* @ApiReturn({
"code": 1,
"msg": "请求成功",
"time": "1587539236",
"data": {
"country": { 国家
"1": {
"id": 1, 国家id
"ch_name": "意大利", 中文名称
"en_name": "Ltaly" 英文名称
}
},
"brand": { 品牌
"1": {
"id": 1, 品牌id
"ch_name": "HAR", 中文名称
"en_name": "HAR" 英文名称
}
},
"level": { 等级
"1": {
"id": 1, 等级id
"ch_name": "草饲", 中文名称
"en_name": "Forage fed" 英文名称
}
},
"part": { 部位
"1": { 部位id
"id": 1,
"ch_name": "战斧", 中文名称
"en_name": "Tomahawk" 英文名称
}
},
"category2": [], 品类
"list": {
"total": 1, 总条数
"list": [
{
"goods_id": 1, 商品id
"ch_name": "EMP精选 澳洲白肉油桃 500~540g 4只装", 中文名称
"en_name": "EMP selected Australian white meat nectarines Australian meat nectarines", 英文名称
"image": "http://q7s0a1rb4.bkt.clouddn.com/uploads/20200420/26f5e51b8ac7fbd6f1c649cc45a18265.png", 缩略图
"goods_price": "123.00", 价格
"ch_country_name": "意大利", 中文名称
"en_country_name": "Ltaly", 英文名称
"is_vip_price": "2", 会员特价:1=开启,2=关闭
"is_group": "2", 团购:1=开启,2=关闭
"group_price": null, 拼团售价 拼团售价优先级最高
"vip_price": "0.00", 会员售价
"stock_num": 55 库存
}
]
}
}
})
*/
public function getSearchGoodsList()
{
$params = $this->request->param();
if (empty($params['keyword'])) $this->error('缺少参数 keyword!');
$page = $params['page'];
$limit = Config::get('paginate.index_rows');
$where = [];
if (!empty($params['country_id'])) $where['country_id'] = $params['country_id'];
if (!empty($params['brand_id'])) $where['brand_id'] = $params['brand_id'];
if (!empty($params['level_id'])) $where['level_id'] = $params['level_id'];
if (!empty($params['part_id'])) $where['part_id'] = $params['part_id'];
if (!empty($params['category2_id'])) $where['category2_id'] = $params['category2_id'];
$goodsWhere = $where;
$where['ch_name|en_name|ch_content|en_content'] = ['like','%'.$params['keyword'].'%'];
$goodsWhere['g.ch_name|g.en_name|g.ch_content|g.en_content'] = ['like','%'.$params['keyword'].'%'];
//获取筛选标签,国家,品牌,等级,部位,品类
$data = $this->categoryModel->getExtend($where);
//获取列表数据
$data['list'] = $this->goodsModel->selectPageData($goodsWhere,$page,$limit);
$this->success('请求成功', $data);
}
/**
* @ApiTitle (商品详情)
* @ApiSummary (商品详情)
* @ApiMethod (POST)
* @ApiRoute (/api/goods/getGoodsInfo)
* @ApiParams (name=goods_id, type=string, required=false, description="商品id")
* @ApiParams (name=goods_id, type=string, required=true, description="商品id")
* @ApiReturn({
"code": 1,
"msg": "请求成功",
... ... @@ -240,6 +428,7 @@ class Goods extends Api
"is_group": "2", 团购:1=开启,2=关闭
"ch_country_name": "意大利",
"en_country_name": "Ltaly"
"is_car": 0 购物车:1=加入,2=未加入
}
}
]
... ... @@ -251,7 +440,14 @@ class Goods extends Api
if (!$goods_id) $this->error('缺少参数 goods_id!');
$where = ['g.id'=>$goods_id];
$data = $this->goodsModel->getInfo($where);
// if ($data['status'] == 2) $this->error('商品已下架');
if ($data['status'] == 2) $this->error('商品已下架');
$userId = $this->userId;
if ($userId){
$carModel = new \app\api\model\Car;
$data['is_car'] = $carModel->where(['user_id'=>$userId,'goods_id'=>$data['goods_id']])->count();
}
$this->success('请求成功', $data);
}
}
... ...
<?php
namespace app\api\controller;
use app\common\controller\Api;
use think\Config;
/**
* 团购商品接口
*/
class GroupGoods extends Api
{
protected $goodsModel;
protected $categoryModel;
protected $keywordLogModel;
public function _initialize()
{
parent::_initialize();
$this->goodsModel = new \app\api\model\Goods;
$this->categoryModel = new \app\api\model\Category;
$this->keywordLogModel = new \app\api\model\KeywordLog;
}
/**
* @ApiTitle (团购商品列表(首页))
* @ApiSummary (团购商品列表(首页))
* @ApiMethod (POST)
* @ApiRoute (/api/group_goods/getGroupGoodsIndex)
* @ApiReturn({
"code": 1,
"msg": "请求成功",
"time": "1587463117",
"data": [
{
"goods_id": 1, 商品id
"ch_name": "EMP精选 澳洲白肉油桃 500~540g 4只装", 中文名称
"en_name": "EMP selected Australian white meat nectarines Australian meat nectarines", 英文名称
"image": "http://q7s0a1rb4.bkt.clouddn.com/uploads/20200420/26f5e51b8ac7fbd6f1c649cc45a18265.png", 缩略图
"goods_price": "0.00", 普通售价
"group_price": "0.00", 拼团售价 拼团售价优先级最高
"vip_price": "0.00", 会员售价
"country_ch_name": "意大利", 原产地中文
"country_en_name": "Ltaly", 原产地英文
"is_vip_price": "2", 会员特价:1=开启,2=关闭
"stock_num": 55 库存
}
]
})
*/
public function getGroupGoodsIndex()
{
$where['g.is_group'] = 1;
$data = $this->goodsModel->selectData($where, 5);
$this->success('请求成功', $data);
}
/**
* @ApiTitle (团购商品列表)
* @ApiSummary (团购商品列表)
* @ApiMethod (POST)
* @ApiRoute (/api/group_goods/getGroupGoodsList)
* @ApiParams (name=page, type=string, required=false, description="页数")
* @ApiReturn({
"code": 1,
"msg": "请求成功",
"time": "1587463117",
"data": [
{
"goods_id": 1, 商品id
"ch_name": "EMP精选 澳洲白肉油桃 500~540g 4只装", 中文名称
"en_name": "EMP selected Australian white meat nectarines Australian meat nectarines", 英文名称
"image": "http://q7s0a1rb4.bkt.clouddn.com/uploads/20200420/26f5e51b8ac7fbd6f1c649cc45a18265.png", 缩略图
"goods_price": "0.00", 普通售价
"group_price": "0.00", 拼团售价 拼团售价优先级最高
"vip_price": "0.00", 会员售价
"country_ch_name": "意大利", 原产地中文
"country_en_name": "Ltaly", 原产地英文
"is_vip_price": "2", 会员特价:1=开启,2=关闭
"stock_num": 55 库存
}
]
})
*/
public function getGroupGoodsList()
{
$page = $this->request->param('page');
$limit = Config::get('paginate.index_rows');
$where['g.is_group'] = 1;
$data = $this->goodsModel->selectPageData($where,$page,$limit);
$this->success('请求成功', $data);
}
}
... ...
<?php
namespace app\api\controller;
use app\common\controller\Api;
use think\Config;
/**
* 积分商品接口
*/
class IntegralGoods extends Api
{
protected $integralGoodsModel;
public function _initialize()
{
parent::_initialize();
$this->integralGoodsModel = new \app\api\model\IntegralGoods;
}
/**
* @ApiTitle (积分商品列表)
* @ApiSummary (积分商品列表)
* @ApiMethod (POST)
* @ApiRoute (/api/integral_goods/getGoodsList)
* @ApiParams (name=keyword, type=string, required=false, description="关键字搜索")
* @ApiParams (name=page, type=string, required=false, description="页数")
* @ApiReturn({
"code": 1,
"msg": "请求成功",
"time": "1587463117",
"data": [
{
"integral_goods_id": 1, 商品id
"ch_name": "EMP精选 澳洲白肉油桃 500~540g 4只装", 中文名称
"en_name": "EMP selected Australian white meat nectarines Australian meat nectarines", 英文名称
"image": "http://q7s0a1rb4.bkt.clouddn.com/uploads/20200420/26f5e51b8ac7fbd6f1c649cc45a18265.png", 缩略图
"integral": "100", 积分
"goods_price": "0.00", 售价
"original_price": "123.00", 原价
"country_ch_name": "意大利", 原产地中文
"country_en_name": "Ltaly", 原产地英文
"stock_num": 55 库存
}
]
})
*/
public function getGoodsList()
{
$page = $this->request->param('page');
$limit = Config::get('paginate.index_rows');
$where = [];
$data = $this->integralGoodsModel->selectPageData($where,$page,$limit);
$this->success('请求成功', $data);
}
/**
* @ApiTitle (积分商品详情)
* @ApiSummary (积分商品详情)
* @ApiMethod (POST)
* @ApiRoute (/api/integral_goods/getGoodsInfo)
* @ApiParams (name=integral_goods_id, type=string, required=true, description="积分商品id")
* @ApiReturn({
"code": 1,
"msg": "请求成功",
"time": "1587463117",
"data": [
{
"code": 1,
"msg": "请求成功",
"time": "1587471193",
"data": {
"integral_goods_id": 1, 商品id
"ch_name": "EMP精选 澳洲白肉油桃 500~540g 4只装", 中文名称
"en_name": "EMP selected Australian white meat nectarines Australian meat nectarines", 英文名称
"image": "http://q7s0a1rb4.bkt.clouddn.com/uploads/20200420/26f5e51b8ac7fbd6f1c649cc45a18265.png", 缩略图
"integral": "100", 积分
"goods_price": "123.00", 价格
"original_price": "123.00", 原价
"images": [
"http://q7s0a1rb4.bkt.clouddn.com/uploads/20200420/26f5e51b8ac7fbd6f1c649cc45a18265.png"
], 轮播图
"goods_no": "", 商品编码
"ch_specification": "", 中文包装规格
"en_specification": "", 英文包装规格
"ch_save_where": "", 中文保存条件
"en_save_where": "", 英文保存条件
"ch_period": "", 中文有效期
"en_period": "", 英文有效期
"ch_content": "", 中文详情
"en_content": "", 英文详情
"stock_num": 55, 库存
"sales_actual": 3, 实际销量
"ch_country_name": "意大利",
"en_country_name": "Ltaly"
}
}
]
})
*/
public function getGoodsInfo()
{
$integral_goods_id = $this->request->param('integral_goods_id');
if (!$integral_goods_id) $this->error('缺少参数 integral_goods_id!');
$where = ['g.id'=>$integral_goods_id];
$data = $this->integralGoodsModel->getInfo($where);
if ($data['status'] == 2) $this->error('商品已下架');
$this->success('请求成功', $data);
}
}
... ...
<?php
namespace app\api\controller;
use app\api\model\UserAddress;
use app\api\model\UserMoneyLog;
use app\api\model\UserScoreLog;
use app\api\model\UserTicket;
use app\common\controller\Api;
use think\Config;
use think\Db;
use app\api\model\User;
use think\Validate;
/**
* 会员接口
*/
class Member extends Api
{
protected $userModel;
public function _initialize()
{
parent::_initialize();
$this->userModel = new User();
}
/**
* @ApiTitle (用户信息)
* @ApiSummary (用户信息)
* @ApiMethod (POST)
* @ApiRoute (/api/member/getUserInfo)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1587361014",
"data": {
"id": 1, 用户id
"nickname": "admin1", 昵称
"avatar": "http://q7s0a1rb4.bkt.clouddn.com/assets/img/qrcode.png", 头像
"type": "2", 用户类型:1=普通用户,2=会员,3=员工,4=代理
"type_text": "会员"
"money": "1" 余额
"score": "1" 积分
}
})
*/
public function getUserInfo()
{
$userId = $this->getUserId();
$userInfo = $this->userModel->where('id',$userId)->field('id,nickname,avatar,type,money,score')->find();
$this->success('SUCCESS', $userInfo);
}
/**
* @ApiTitle (我的优惠券)
* @ApiSummary (我的优惠券)
* @ApiMethod (POST)
* @ApiRoute (/api/member/getUserTicket)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name=status, type=string, required=true, description="状态:1=未使用,2=已使用,3=已过期")
* @ApiParams (name=page, type=string, required=true, description="页数")
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1587558975",
"data": {
"total": 1,
"list": [
{
"user_ticket_id": 1, 用户优惠券id
"pasttime": "2017-07-10 18:28", 截至时间
"price": "5.00", 优惠价格
"ch_name": "邀请用户", 优惠券中文名称
"en_name": null 优惠券英文名称
}
]
}
})
*/
public function getUserTicket()
{
$model = new UserTicket();
$userId = $this->getUserId();
$status = $this->request->param('status');
$page = $this->request->param('page');
$limit = Config::get('paginate.index_rows');
if (empty($status)) $this->error('缺少参数 status!');
$where['user_id'] = $userId;
$where['status'] = $status;
$data = $model->selectPageData($where,$page,$limit);
$this->success('SUCCESS', $data);
}
/**
* @ApiTitle (我的绑定)
* @ApiSummary (我的绑定)
* @ApiMethod (POST)
* @ApiRoute (/api/member/getUserLower)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name=page, type=string, required=true, description="页数")
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1587361014",
"data": {
"user_id": 1, 用户id
"nickname": "admin1", 昵称
"avatar": "http://q7s0a1rb4.bkt.clouddn.com/assets/img/qrcode.png", 头像
}
})
*/
public function getUserLower()
{
$userId = $this->getUserId();
$page = $this->request->param('page');
$limit = Config::get('paginate.index_rows');
$where['pid'] = $userId;
$data = $this->userModel->selectPageData($where,$page,$limit);
$this->success('SUCCESS', $data);
}
/**
* @ApiTitle (余额明细)
* @ApiSummary (余额明细)
* @ApiMethod (POST)
* @ApiRoute (/api/member/getMoneyLog)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name=date, type=string, required=true, description="日期 例2020-2-1")
* @ApiParams (name=page, type=string, required=true, description="页数")
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1587361014",
"data": {
"user_id": 1, 用户id
"nickname": "admin1", 昵称
"avatar": "http://q7s0a1rb4.bkt.clouddn.com/assets/img/qrcode.png", 头像
}
})
*/
public function getMoneyLog()
{
$model = new UserMoneyLog();
$userId = $this->getUserId();
$page = $this->request->param('page');
$date = $this->request->param('date');
$limit = Config::get('paginate.index_rows');
$betweenTime = ['1970-1-1',date('Y-m-d')];
if ($date){
$dateArr = explode('-',$date);
$lastDay = cal_days_in_month(CAL_GREGORIAN, $dateArr[1], $dateArr[0]);
$lastDate = $dateArr[0].'-'.$dateArr[1].'-'.$lastDay;
$betweenTime = [$date,$lastDate];
}
$where['user_id'] = $userId;
$data = $model->selectPageData($where,$page,$limit,$betweenTime);
$this->success('SUCCESS', $data);
}
/**
* @ApiTitle (积分明细)
* @ApiSummary (积分明细)
* @ApiMethod (POST)
* @ApiRoute (/api/member/getScoreLog)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name=date, type=string, required=true, description="日期 例2020-2-1")
* @ApiParams (name=page, type=string, required=true, description="页数")
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1587560895",
"data": {
"total": 1,
"list": [
{
"score": "10.00", 变更积分
"after": "10.00", 变更后积分
"type": "type",
"createtime": "2020-04-20 16:13"
}
]
}
})
*/
public function getScoreLog()
{
$model = new UserScoreLog();
$userId = $this->getUserId();
$page = $this->request->param('page');
$date = $this->request->param('date');
$limit = Config::get('paginate.index_rows');
$betweenTime = ['1970-1-1',date('Y-m-d')];
if ($date){
$dateArr = explode('-',$date);
$lastDay = cal_days_in_month(CAL_GREGORIAN, $dateArr[1], $dateArr[0]);
$lastDate = $dateArr[0].'-'.$dateArr[1].'-'.$lastDay;
$betweenTime = [$date,$lastDate];
}
$where['user_id'] = $userId;
$data = $model->selectPageData($where,$page,$limit,$betweenTime);
$this->success('SUCCESS', $data);
}
}
\ No newline at end of file
... ...
<?php
namespace app\api\controller;
use think\Db;
use think\Validate;
use app\common\controller\Api;
/**
* 赠品接口
*/
class Present extends Api
{
/**
* @ApiTitle (获取赠品列表)
* @ApiSummary (获取赠品列表)
* @ApiMethod (POST)
* @ApiRoute (/api/present/getPresentList)
* @ApiHeaders (name=token, type=string, required=false, description="请求的Token")
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1553839125",
"data": {
"id": "id",// 地区id
"name": "name",// 名称
},
})
*/
public function getPresentList(){
$model = new \app\api\model\Present;
$data = $model->selectData([]);
$this->success('SUCCESS',$data);
}
}
... ...
... ... @@ -2,6 +2,7 @@
namespace app\api\controller;
use app\api\model\Area;
use app\api\model\KeywordLog;
use app\api\model\Slide;
use app\common\controller\Api;
... ... @@ -69,4 +70,33 @@ class Sundry extends Api
$this->success('SUCCESS',$data);
}
/**
* @ApiTitle (获取地区)
* @ApiSummary (获取地区)
* @ApiMethod (POST)
* @ApiRoute (/api/sundry/getArea)
* @ApiHeaders (name=token, type=string, required=false, description="请求的Token")
* @ApiParams (name=province_id, type=string, required=false, description="省")
* @ApiParams (name=city_id, type=string, required=false, description="市")
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1553839125",
"data": {
"id": "id",// 地区id
"name": "name",// 名称
},
})
*/
public function getArea(){
$areaModel = new Area();
$params = $this->request->param();
$where['pid'] = 0;
if (!empty($params['province_id'])) $where['pid'] = $params['province_id'];
if (!empty($params['city_id'])) $where['pid'] = $params['city_id'];
$data = $areaModel->where($where)->field('id,name')->select();
$this->success('SUCCESS',$data);
}
}
... ...
... ... @@ -12,7 +12,7 @@ use think\Validate;
use wxapp\aes\WXBizDataCrypt;
/**
* 会员接口
* 授权接口
*/
class User extends Api
{
... ...
<?php
namespace app\api\controller;
use app\api\model\Area;
use app\api\model\UserAddress as UserAddressModel;
use app\common\controller\Api;
use think\Config;
use think\Db;
use app\api\model\User;
use think\Validate;
/**
* 用户地址接口
*/
class UserAddress extends Api
{
protected $userModel;
public function _initialize()
{
parent::_initialize();
$this->userModel = new User();
}
/**
* @ApiTitle (添加用户收货地址)
* @ApiSummary (添加用户收货地址)
* @ApiMethod (POST)
* @ApiRoute (/api/user_address/addUserAddress)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name=name, type=string, required=true, description="收货人")
* @ApiParams (name=mobile, type=string, required=true, description="收货人手机号")
* @ApiParams (name=province_id, type=string, required=true, description="省")
* @ApiParams (name=city_id, type=string, required=true, description="市")
* @ApiParams (name=county_id, type=string, required=true, description="县")
* @ApiParams (name=address, type=string, required=true, description="详细地址")
* @ApiParams (name=is_default, type=string, required=true, description="默认:1=是,2=否")
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1587361014",
"data":
})
*/
public function addUserAddress()
{
$model = new UserAddressModel();
$userId = $this->getUserId();
$data = $this->request->param();
$data['user_id'] = $userId;
$validate = new Validate([
'name' => 'require',
'mobile' => ['^1\d{10}$','require'],
'province_id' => 'require',
'city_id' => 'require',
'county_id' => 'require',
'address' => 'require',
'is_default' => 'require',
]);
$validate->message([
'name' => '缺少参数 name!',
'mobile.require' => '缺少参数 mobile!',
'province_id' => '缺少参数 province_id!',
'city_id' => '缺少参数 city_id!',
'county_id' => '缺少参数 county_id!',
'address' => '缺少参数 address!',
'mobile' => '手机格式错误!',
'is_default' => '缺少参数 is_default!',
]);
if (!$validate->check($data)) {
$this->error($validate->getError());
}
if ($data['is_default'] == 1){
$model->where(['user_id'=>$userId])->update(['is_default'=>2]);
}
$res = $model->save($data);
if ($res) $this->success('SUCCESS');
else $this->error('ERROR');
}
/**
* @ApiTitle (编辑用户收货地址)
* @ApiSummary (编辑用户收货地址)
* @ApiMethod (POST)
* @ApiRoute (/api/user_address/editUserAddress)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name=user_address_id, type=string, required=true, description="地址id")
* @ApiParams (name=name, type=string, required=true, description="收货人")
* @ApiParams (name=mobile, type=string, required=true, description="收货人手机号")
* @ApiParams (name=province_id, type=string, required=true, description="省")
* @ApiParams (name=city_id, type=string, required=true, description="市")
* @ApiParams (name=county_id, type=string, required=true, description="县")
* @ApiParams (name=address, type=string, required=true, description="详细地址")
* @ApiParams (name=is_default, type=string, required=true, description="默认:1=是,2=否")
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1587361014",
"data":
})
*/
public function editUserAddress()
{
$model = new UserAddressModel();
$userId = $this->getUserId();
$data = $this->request->param();
$data['user_id'] = $userId;
$validate = new Validate([
'user_address_id' => 'require',
'name' => 'require',
'mobile' => ['^1\d{10}$','require'],
'province_id' => 'require',
'city_id' => 'require',
'county_id' => 'require',
'address' => 'require',
'is_default' => 'require',
]);
$validate->message([
'user_address_id' => '缺少参数 user_address_id!',
'name' => '缺少参数 name!',
'mobile.require' => '缺少参数 mobile!',
'province_id' => '缺少参数 province_id!',
'city_id' => '缺少参数 city_id!',
'county_id' => '缺少参数 county_id!',
'address' => '缺少参数 address!',
'mobile' => '手机格式错误!',
'is_default' => '缺少参数 is_default!',
]);
if (!$validate->check($data)) {
$this->error($validate->getError());
}
if ($data['is_default'] == 1){
$model->where(['user_id'=>$userId])->update(['is_default'=>2]);
}
$res = $model->save($data);
if ($res) $this->success('SUCCESS');
else $this->error('ERROR');
}
/**
* @ApiTitle (删除用户收货地址)
* @ApiSummary (删除用户收货地址)
* @ApiMethod (POST)
* @ApiRoute (/api/user_address/delUserAddress)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name=user_address_id, type=string, required=true, description="地址id")
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1587361014",
"data":
})
*/
public function delUserAddress()
{
$model = new UserAddressModel();
$userId = $this->getUserId();
$user_address_id = $this->request->param('user_address_id');
if (empty($user_address_id)) $this->error('缺少参数 user_address_id!');
$where['id'] = $user_address_id;
$res = $model->where($where)->delete();
if ($res) $this->success('SUCCESS');
else $this->error('ERROR');
}
/**
* @ApiTitle (用户收货地址详情)
* @ApiSummary (用户收货地址详情)
* @ApiMethod (POST)
* @ApiRoute (/api/user_address/getUserAddressInfo)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name=user_address_id, type=string, required=true, description="地址id")
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1587361014",
"data":
})
*/
public function getUserAddressInfo()
{
$model = new UserAddressModel();
$areaModel = new Area();
$userId = $this->getUserId();
$user_address_id = $this->request->param('user_address_id');
if (empty($user_address_id)) $this->error('缺少参数 user_address_id!');
$where['id'] = $user_address_id;
$data = $model->where($where)->find();
$data['province'] = $areaModel->where('id',$data['province_id'])->field('id,name')->find();
$data['city'] = $areaModel->where('id',$data['city_id'])->field('id,name')->find();
$data['county'] = $areaModel->where('id',$data['county_id'])->field('id,name')->find();
$this->success('SUCCESS',$data);
}
/**
* @ApiTitle (用户收货地址列表)
* @ApiSummary (用户收货地址列表)
* @ApiMethod (POST)
* @ApiRoute (/api/user_address/getUserAddressIList)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1587361014",
"data":
})
*/
public function getUserAddressIList()
{
$model = new UserAddressModel();
$areaModel = new Area();
$userId = $this->getUserId();
$where['user_id'] = $userId;
$data = $model->where($where)->field('id,province_id,city_id,county_id,address,name,mobile,is_default')->select();
foreach ($data as $k => $v){
$ids = $data[$k]['province_id'].','.$data[$k]['city_id'].','.$data[$k]['county_id'];
$area = $areaModel->where(['id'=>['in',$ids]])->column('name');
$data[$k]['address'] = implode('',$area).$v['address'];
}
$this->success('SUCCESS',$data);
}
}
\ No newline at end of file
... ...
<?php
namespace app\api\model;
use think\Model;
class Area extends Model
{
}
... ...
... ... @@ -2,6 +2,7 @@
namespace app\api\model;
use think\Db;
use think\Model;
class Category extends Model
... ... @@ -15,10 +16,36 @@ class Category extends Model
return $value;
}
public function selectData($where, $limit)
public function selectData($where, $limit=null)
{
$where['status'] = ['eq', '1'];
$data = $this->where($where)->field('id,name ch_name,en_name,image')->order('weigh desc')->limit($limit)->select();
return $data;
}
public function getExtend($where)
{
$goodsModel = new Goods();
$ids = $goodsModel->where($where)->column('country_id,brand_id,level_id,part_id,category2_id');
$countryids = [];
$brandids = [];
$levelids = [];
$partids = [];
$category2ids = [];
foreach ($ids as $k=>$v){
$countryids[$k] = $v['country_id'];
$brandids[$k] = $v['brand_id'];
$levelids[$k] = $v['level_id'];
$partids[$k] = $v['part_id'];
$category2ids[$k] = $v['category2_id'];
}
$data['country'] = Db::name('country')->where(['id'=>['in',array_unique($countryids)]])->column('id,ch_name,en_name');
$data['brand'] = Db::name('brand')->where(['id'=>['in',array_unique($brandids)]])->column('id,ch_name,en_name');
$data['level'] = Db::name('level')->where(['id'=>['in',array_unique($levelids)]])->column('id,ch_name,en_name');
$data['part'] = Db::name('part')->where(['id'=>['in',array_unique($partids)]])->column('id,ch_name,en_name');
$data['category2'] = Db::name('category2')->where(['id'=>['in',array_unique($category2ids)]])->column('id,ch_name,en_name');
return $data;
}
}
... ...
... ... @@ -7,43 +7,26 @@ use think\Model;
class ChoosePage extends Model
{
// 表名
protected $name = 'choose_page';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = false;
// 追加属性
protected $append = [
'status_text'
];
public function getStatusList()
public function getImageAttr($value)
{
return ['1' => __('Status 1'), '2' => __('Status 2')];
if ($value) $value = cdnurl($value);
return $value;
}
public function getStatusTextAttr($value, $data)
public function getActivitytimeAttr($value)
{
$value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
$list = $this->getStatusList();
return isset($list[$value]) ? $list[$value] : '';
if ($value) $value = date('Y-m-d',$value);
return $value;
}
public function selectData($where)
{
$where['status'] = 1;
$data = $this
->where($where)
->field('id,title,image')
->order('weigh desc')
->select();
return $data;
}
}
... ...
... ... @@ -7,11 +7,6 @@ use think\Model;
class Exhibition extends Model
{
// 表名
protected $name = 'exhibition';
... ...
... ... @@ -154,9 +154,9 @@ class Goods extends Model
$data = $this->alias('g')
->join('fa_country c', 'g.country_id=c.id')
->where($where)
->field('g.id goods_id,g.ch_name,g.en_name,g.image,g.sales_actual')
->field('g.id goods_id,g.ch_name,g.en_name,g.image,g.sales_actual+g.sales_initial sales')
->limit($limit)
->order('g.sales_actual desc')
->order('sales desc')
->select();
return $data;
}
... ... @@ -185,7 +185,7 @@ class Goods extends Model
$list = $this->alias('g')
->join('fa_country c', 'g.country_id=c.id')
->where($where)
->field('g.id goods_id,g.ch_name,g.en_name,g.image,g.goods_price,c.ch_name ch_country_name,c.en_name en_country_name,is_vip_price,group_price,stock_num')
->field('g.id goods_id,g.ch_name,g.en_name,g.image,g.goods_price,c.ch_name ch_country_name,c.en_name en_country_name,is_vip_price,is_group,group_price,vip_price,stock_num')
->order('g.weigh desc')
->page($page,$limit)
->select();
... ... @@ -198,7 +198,7 @@ class Goods extends Model
$data = $this->alias('g')
->join('fa_country c', 'g.country_id=c.id')
->where($where)
->field('g.id goods_id,g.ch_name,g.en_name,g.image,g.goods_price,g.images,g.goods_no,g.ch_specification,g.en_specification,g.ch_save_where,g.en_save_where,g.ch_period,g.en_period,g.ch_content,g.en_content,g.stock_num,g.sales_actual,g.group_price,g.vip_price,g.is_vip_price,g.is_group,c.ch_name ch_country_name,c.en_name en_country_name')
->field('g.id goods_id,g.ch_name,g.en_name,g.image,g.status,g.goods_price,g.images,g.goods_no,g.ch_specification,g.en_specification,g.ch_save_where,g.en_save_where,g.ch_period,g.en_period,g.ch_content,g.en_content,g.stock_num,g.sales_actual,g.group_price,g.vip_price,g.is_vip_price,g.is_group,c.ch_name ch_country_name,c.en_name en_country_name')
->find();
return $data;
}
... ...
<?php
namespace app\api\model;
use think\Model;
class IntegralGoods extends Model
{
public function getImageAttr($value)
{
if ($value) $value = cdnurl($value);
return $value;
}
public function getImagesAttr($value)
{
$arr = explode(',', $value);
$data = [];
foreach ($arr as $k => $v) {
$data[$k] = cdnurl($value);
}
return $data;
}
public function selectPageData($where,$page,$limit)
{
$where['g.status'] = 1;
$total = $this->alias('g')
->join('fa_country c', 'g.country_id=c.id')
->where($where)
->count();
$list = $this->alias('g')
->join('fa_country c', 'g.country_id=c.id')
->where($where)
->field('g.id integral_goods_id,g.ch_name,g.en_name,g.image,g.original_price,g.goods_price,g.integral,c.ch_name ch_country_name,c.en_name en_country_name,stock_num')
->order('g.weigh desc')
->page($page,$limit)
->select();
return ['total' => $total, 'list' => $list];
}
public function getInfo($where)
{
$where['g.status'] = 1;
$data = $this->alias('g')
->join('fa_country c', 'g.country_id=c.id')
->where($where)
->field('g.id integral_goods_id,g.ch_name,g.en_name,g.image,g.status,g.original_price,g.goods_price,g.integral,g.images,g.goods_no,g.ch_specification,g.en_specification,g.ch_save_where,g.en_save_where,g.ch_period,g.en_period,g.ch_content,g.en_content,g.stock_num,g.sales_actual,c.ch_name ch_country_name,c.en_name en_country_name')
->find();
return $data;
}
}
... ...
<?php
namespace app\api\model;
use think\Model;
class Present extends Model
{
public function getImageAttr($value)
{
if ($value) $value = cdnurl($value);
return $value;
}
public function selectData($where, $limit=null)
{
$where['status'] = ['eq', '1'];
$data = $this->where($where)->field('id,ch_name,en_name,image')->order('weigh desc')->limit($limit)->select();
return $data;
}
}
... ...
... ... @@ -16,47 +16,7 @@ class User extends Model
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
// 追加属性
protected $append = [
'prevtime_text',
'logintime_text',
'jointime_text'
];
public function getOriginData()
{
return $this->origin;
}
protected static function init()
{
self::beforeUpdate(function ($row) {
$changed = $row->getChangedData();
//如果有修改密码
if (isset($changed['password'])) {
if ($changed['password']) {
$salt = \fast\Random::alnum();
$row->password = \app\common\library\Auth::instance()->getEncryptPassword($changed['password'], $salt);
$row->salt = $salt;
} else {
unset($row->password);
}
}
});
self::beforeUpdate(function ($row) {
$changedata = $row->getChangedData();
if (isset($changedata['money'])) {
$origin = $row->getOriginData();
MoneyLog::create(['user_id' => $row['id'], 'money' => $changedata['money'] - $origin['money'], 'before' => $origin['money'], 'after' => $changedata['money'], 'memo' => '管理员变更金额']);
}
if (isset($changedata['score'])) {
$origin = $row->getOriginData();
ScoreLog::create(['user_id' => $row['id'], 'score' => $changedata['score'] - $origin['score'], 'before' => $origin['score'], 'after' => $changedata['score'], 'memo' => '管理员变更积分']);
}
});
}
public function getGenderList()
{
... ... @@ -68,42 +28,27 @@ class User extends Model
return ['normal' => __('Normal'), 'hidden' => __('Hidden')];
}
public function getPrevtimeTextAttr($value, $data)
{
$value = $value ? $value : $data['prevtime'];
return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
}
public function getLogintimeTextAttr($value, $data)
public function getCreatetimeAttr($value)
{
$value = $value ? $value : $data['logintime'];
return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
return date('Y-m-d H:i:s',$value);
}
public function getJointimeTextAttr($value, $data)
{
$value = $value ? $value : $data['jointime'];
return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
}
protected function setPrevtimeAttr($value)
public function group()
{
return $value && !is_numeric($value) ? strtotime($value) : $value;
return $this->belongsTo('UserGroup', 'group_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
protected function setLogintimeAttr($value)
{
return $value && !is_numeric($value) ? strtotime($value) : $value;
}
public function selectPageData($where,$page,$limit){
protected function setJointimeAttr($value)
{
return $value && !is_numeric($value) ? strtotime($value) : $value;
}
$total =$this
->where($where)
->count();
public function group()
{
return $this->belongsTo('UserGroup', 'group_id', 'id', [], 'LEFT')->setEagerlyType(0);
$list = $this
->where($where)
->field('id user_id,nickname,avatar,createtime')
->page($page,$limit)
->select();
return ['total' => $total, 'list' => $list];
}
}
... ...
<?php
namespace app\api\model;
use think\Model;
class UserAddress extends Model
{
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = false;
}
... ...
<?php
namespace app\api\model;
use app\common\model\MoneyLog;
use app\common\model\ScoreLog;
use think\Model;
class UserMoneyLog extends Model
{
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $append = [
'type_text'
];
public function getCreatetimeAttr($value)
{
return date('Y-m-d H:i', $value);
}
public function getTypeList()
{
return ['1' => '提现', '2' => '充值', '3' => '购物消费', '4' => '佣金收入', '5' => '工资发放'];
}
public function getTypeTextAttr($value,$data)
{
$value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
$list = $this->getTypeList();
return isset($list[$value]) ? $list[$value] : '';
}
public function selectPageData($where, $page, $limit,$betweenTime)
{
$total = $this
->where($where)
->whereTime('createtime','between',$betweenTime)
->count();
$list = $this
->where($where)
->whereTime('createtime','between',$betweenTime)
->field('money,after,type,createtime')
->page($page, $limit)
->select();
return ['total' => $total, 'list' => $list];
}
}
... ...
<?php
namespace app\api\model;
use app\common\model\MoneyLog;
use app\common\model\ScoreLog;
use think\Model;
class UserScoreLog extends Model
{
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $append = [
'type_text'
];
public function getCreatetimeAttr($value)
{
return date('Y-m-d H:i', $value);
}
public function getTypeList()
{
return ['1' => '购物返积分', '2' => '积分商城兑换'];
}
public function getTypeTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
$list = $this->getTypeList();
return isset($list[$value]) ? $list[$value] : '';
}
public function selectPageData($where, $page, $limit,$betweenTime)
{
$total = $this
->where($where)
->whereTime('createtime','between',$betweenTime)
->count();
$list = $this
->where($where)
->whereTime('createtime','between',$betweenTime)
->field('score,after,type,createtime')
->page($page, $limit)
->select();
return ['total' => $total, 'list' => $list];
}
}
... ...
<?php
namespace app\api\model;
use think\Model;
class UserTicket extends Model
{
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = false;
public function getPasttimeAttr($value)
{
return date('Y-m-d H:i',$value);
}
public function selectPageData($where,$page,$limit){
$total =$this
->where($where)
->count();
$list = $this->alias('ut')
->join('fa_ticket t','ut.ticket_id=t.id')
->where($where)
->field('ut.id user_ticket_id,ut.pasttime,t.price,t.ch_name,t.en_name')
->page($page,$limit)
->select();
return ['total' => $total, 'list' => $list];
}
}
... ...
... ... @@ -43,7 +43,28 @@ class Video extends Model
return isset($list[$value]) ? $list[$value] : '';
}
public function getVideoImageAttr($value)
{
if ($value) $value = cdnurl($value);
return $value;
}
public function getVideoAttr($value)
{
if ($value) $value = cdnurl($value);
return $value;
}
public function selectPageData($where,$page,$limit){
$where['status'] = 1;
$total = $this
->where($where)
->count();
$list = $this
->where($where)
->page($page,$limit)
->select();
return ['total' => $total, 'list' => $list];
}
}
... ...
此 diff 太大无法显示。