作者 耿培杰

接口开发

<?php
namespace app\api\controller;
use app\common\controller\Api;
use think\Db;
use think\Validate;
use think\Config;
/**
* 购物车接口
*/
class Car extends Api
{
protected $carModel;
protected function _initialize()
{
parent::_initialize();
$this->carModel = new \app\api\model\Car;
}
/**
* @ApiTitle (获取购物车列表)
* @ApiSummary (获取购物车列表)
* @ApiMethod (POST)
* @ApiRoute (/api/car/getCarList)
* @ApiHeaders (name=token, type=string, required=false, description="请求的Token")
* @ApiParams (name=page, type=string, required=false, description="页数")
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1587472510",
"data": {
"total": 1,
"list": [
{
"content": "content", 评论内容
"images": [
"http://q7s0a1rb4.bkt.clouddn.com/uploads/20200420/26f5e51b8ac7fbd6f1c649cc45a18265.png" 评论图片
],
"createtime": "2020-04-20", 评论日期
"avatar": "avatar", 用户头像
"nickname": "admin" 用户昵称
}
]
}
})
*/
public function getCarList(){
$userId = $this->getUserId();
$where['c.user_id'] = $userId;
$page = $this->request->param('page');
$limit = Config::get('paginate.index_rows');
$data = $this->carModel->selectPageData($where,$page,$limit);
$this->success('SUCCESS',$data);
}
/**
* @ApiTitle (添加购物车)
* @ApiSummary (添加购物车)
* @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=团购商品")
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1587472510",
"data": {
"total": 1,
"list": [
{
"content": "content", 评论内容
"images": [
"http://q7s0a1rb4.bkt.clouddn.com/uploads/20200420/26f5e51b8ac7fbd6f1c649cc45a18265.png" 评论图片
],
"createtime": "2020-04-20", 评论日期
"avatar": "avatar", 用户头像
"nickname": "admin" 用户昵称
}
]
}
})
*/
public function addCar(){
$userId = $this->getUserId();
$data = $this->request->param();
$data['user_id'] = $userId;
$validate = new Validate([
'goods_id' => 'require',
'type' => 'require',
'number' => 'require',
]);
$validate->message([
'goods_id' => '缺少参数 goods_id!',
'type' => '缺少参数 type!',
'number' => '缺少参数 number!',
]);
if (!$validate->check($data)) {
$this->error($validate->getError());
}
$res = $this->carModel->save($data);
if ($res) $this->success('SUCCESS');
else $this->error('ERROR');
}
}
... ...
<?php
namespace app\api\controller;
use app\common\controller\Api;
/**
* 分类接口
*/
class Category extends Api
{
protected $categoryModel;
protected $categoryGroupModel;
public function _initialize()
{
parent::_initialize();
$this->categoryModel = new \app\api\model\Category;
$this->categoryGroupModel = new \app\api\model\CategoryGroup;
}
/**
* @ApiTitle (首页分类)
* @ApiSummary (首页分类)
* @ApiMethod (POST)
* @ApiRoute (/api/category/getCategoryIndex)
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1553839125",
"data": {
"id": "id",//幻灯片id
"goods_id": "shop_id",//商品id(可跳转商品详情)
"title": "title",//标题
"image": "image",//图片
},
})
*/
public function getCategoryIndex(){
$data['category1'] = $this->categoryGroupModel->selectData(['sitelist'=>['like','%' . 1 . '%']],4);
$data['category2'] = $this->categoryGroupModel->selectData(['sitelist'=>['like','%' . 2 . '%']],3);
$data['category3'] = $this->categoryModel->selectData(['pid'=>0],5);
$this->success('SUCCESS',$data);
}
}
... ...
<?php
namespace app\api\controller;
use app\common\controller\Api;
use think\Db;
use think\Validate;
use think\Config;
/**
* 评价接口
*/
class Evaluate extends Api
{
protected $evaluateModel;
protected function _initialize()
{
parent::_initialize();
$this->evaluateModel = new \app\api\model\Evaluate;
}
/**
* @ApiTitle (获取商品评价)
* @ApiSummary (获取商品评价)
* @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=page, type=string, required=false, description="页数")
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1587472510",
"data": {
"total": 1,
"list": [
{
"content": "content", 评论内容
"images": [
"http://q7s0a1rb4.bkt.clouddn.com/uploads/20200420/26f5e51b8ac7fbd6f1c649cc45a18265.png" 评论图片
],
"createtime": "2020-04-20", 评论日期
"avatar": "avatar", 用户头像
"nickname": "admin" 用户昵称
}
]
}
})
*/
public function getGoodsEvaluate(){
$goods_id = $this->request->param('goods_id');
if (!$goods_id) $this->error('缺少参数 goods_id!');
$page = $this->request->param('page');
$limit = Config::get('paginate.index_rows');
$where['e.goods_id'] = $goods_id;
$data = $this->evaluateModel->selectPageData($where,$page,$limit);
$this->success('SUCCESS',$data);
}
/**
* @ApiTitle (添加商品评价)
* @ApiSummary (添加商品评价)
* @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=images, type=string, required=false, description="图片 例1.jpg,2.jpg")
* @ApiParams (name=content, type=string, required=true, description="评价内容")
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1587472510",
"data": {
"total": 1,
"list": [
{
"content": "content", 评论内容
"images": [
"http://q7s0a1rb4.bkt.clouddn.com/uploads/20200420/26f5e51b8ac7fbd6f1c649cc45a18265.png" 评论图片
],
"createtime": "2020-04-20", 评论日期
"avatar": "avatar", 用户头像
"nickname": "admin" 用户昵称
}
]
}
})
*/
public function addGoodsEvaluate(){
$userId = $this->getUserId();
$data = $this->request->param();
$data['user_id'] = $userId;
$validate = new Validate([
'goods_id' => 'require',
'content' => 'require',
]);
$validate->message([
'goods_id' => '缺少参数 goods_id!',
'content' => '缺少参数 content!',
]);
if (!$validate->check($data)) {
$this->error($validate->getError());
}
$data = $this->evaluateModel->save($data);
$this->success('SUCCESS',$data);
}
}
... ...
<?php
namespace app\api\controller;
use app\common\controller\Api;
use think\Config;
/**
* 商品接口
*/
class Goods extends Api
{
protected $goodsModel;
protected $keywordLogModel;
public function _initialize()
{
parent::_initialize();
$this->goodsModel = new \app\api\model\Goods;
$this->keywordLogModel = new \app\api\model\KeywordLog;
}
/**
* @ApiTitle (本店热榜)
* @ApiSummary (本店热榜)
* @ApiMethod (POST)
* @ApiRoute (/api/goods/getHotGoods)
* @ApiParams (name=limit, type=string, required=false, description="显示条数 默认10条")
* @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", 缩略图
"sales_actual": "100", 实际销量
}
]
})
*/
public function getHotGoods()
{
$limit = $this->request->param('limit')?$this->request->param('limit'):10;
$where = [];
$data = $this->goodsModel->selectHotData($where, $limit);
$this->success('请求成功', $data);
}
/**
* @ApiTitle (商品列表)
* @ApiSummary (商品列表)
* @ApiMethod (POST)
* @ApiRoute (/api/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": [
{
"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 getGoodsList()
{
$page = $this->request->param('page');
$limit = Config::get('paginate.index_rows');
$where = [];
$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/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);
}
/**
* @ApiTitle (推荐商品列表)
* @ApiSummary (推荐商品列表)
* @ApiMethod (POST)
* @ApiRoute (/api/goods/getRecommendGoods)
* @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", 售价
"country_ch_name": "意大利", 原产地中文
"country_en_name": "Ltaly", 原产地英文
"is_vip_price": "2", 会员特价:1=开启,2=关闭
"stock_num": 55 库存
}
]
})
*/
public function getRecommendGoods()
{
$where['g.is_recommend'] = 1;
$data = $this->goodsModel->selectData($where, 10);
$this->success('请求成功', $data);
}
/**
* @ApiTitle (团购商品列表(首页))
* @ApiSummary (团购商品列表(首页))
* @ApiMethod (POST)
* @ApiRoute (/api/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/goods/getGoodsInfo)
* @ApiParams (name=goods_id, type=string, required=false, description="商品id")
* @ApiReturn({
"code": 1,
"msg": "请求成功",
"time": "1587463117",
"data": [
{
"code": 1,
"msg": "请求成功",
"time": "1587471193",
"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": "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, 实际销量
"group_price": null, 拼团价格
"vip_price": "0.00", 会员特价
"is_vip_price": "2", 会员特价:1=开启,2=关闭
"is_group": "2", 团购:1=开启,2=关闭
"ch_country_name": "意大利",
"en_country_name": "Ltaly"
}
}
]
})
*/
public function getGoodsInfo()
{
$goods_id = $this->request->param('goods_id');
if (!$goods_id) $this->error('缺少参数 goods_id!');
$where = ['g.id'=>$goods_id];
$data = $this->goodsModel->getInfo($where);
// if ($data['status'] == 2) $this->error('商品已下架');
$this->success('请求成功', $data);
}
}
... ...
<?php
namespace app\api\controller;
use app\api\model\KeywordLog;
use app\api\model\Slide;
use app\common\controller\Api;
use think\Db;
use think\Validate;
/**
* 杂项接口
*/
class Sundry extends Api
{
protected function _initialize()
{
parent::_initialize();
}
/**
* @ApiTitle (幻灯片)
* @ApiSummary (幻灯片)
* @ApiMethod (POST)
* @ApiRoute (/api/sundry/getSlide)
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1553839125",
"data": {
"id": "id",//幻灯片id
"goods_id": "shop_id",//商品id(可跳转商品详情)
"title": "title",//标题
"image": "image",//图片
},
})
*/
public function getSlide(){
$slideModel = new Slide();
$data = $slideModel->selectData([]);
$this->success('SUCCESS',$data);
}
/**
* @ApiTitle (获取用户搜索记录)
* @ApiSummary (获取用户搜索记录)
* @ApiMethod (POST)
* @ApiRoute (/api/sundry/getUserKeyword)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name=limit, type=string, required=false, description="显示条数 默认8条")
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1553839125",
"data": {
"id": "id",//幻灯片id
"goods_id": "shop_id",//商品id(可跳转商品详情)
"title": "title",//标题
"image": "image",//图片
},
})
*/
public function getUserKeyword(){
$limit = $this->request->param('limit')?$this->request->param('limit'):8;
$model = new KeywordLog();
$userId = $this->getUserId();
$data = $model->selectData(['user_id'=>$userId],$limit);
$this->success('SUCCESS',$data);
}
}
... ...
<?php
namespace app\api\model;
use think\Model;
class Brand extends Model
{
// 表名
protected $name = 'brand';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = false;
// 追加属性
protected $append = [
'status_text'
];
protected static function init()
{
self::afterInsert(function ($row) {
$pk = $row->getPk();
$row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
});
}
public function getStatusList()
{
return ['1' => __('Status 1'), '2' => __('Status 2')];
}
public function getStatusTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
$list = $this->getStatusList();
return isset($list[$value]) ? $list[$value] : '';
}
}
... ...
<?php
namespace app\api\model;
use think\Model;
class Car extends Model
{
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = false;
public function getCreatetimeAttr($value)
{
return date('Y-m-d',$value);
}
public function getImageAttr($value)
{
return cdnurl($value);
}
public function selectPageData($where,$page,$limit){
$total =$this->alias('c')
->where($where)
->count();
$list = $this->alias('c')
->join('fa_goods g','c.goods_id=g.id')
->join('fa_country cou','cou.id=g.country_id')
->where($where)
->field('c.createtime,cou.ch_name ch_country_name,cou.en_name en_country_name,g.id goods_id,g.ch_name,g.en_name,g.image,g.goods_price,g.group_price,g.vip_price,g.is_vip_price,g.is_group')
->page($page,$limit)
->select();
return ['total' => $total, 'list' => $list];
}
}
... ...
<?php
namespace app\api\model;
use think\Model;
class Category extends Model
{
// 表名
protected $name = 'category';
public function getImageAttr($value)
{
if($value) $value = cdnurl($value);
return $value;
}
public function selectData($where, $limit)
{
$where['status'] = ['eq', '1'];
$data = $this->where($where)->field('id,name ch_name,en_name,image')->order('weigh desc')->limit($limit)->select();
return $data;
}
}
... ...
<?php
namespace app\api\model;
use think\Model;
class Category2 extends Model
{
// 表名
protected $name = 'category2';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = false;
// 追加属性
protected $append = [
'status_text'
];
protected static function init()
{
self::afterInsert(function ($row) {
$pk = $row->getPk();
$row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
});
}
public function getStatusList()
{
return ['1' => __('Status 1'), '2' => __('Status 2')];
}
public function getStatusTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
$list = $this->getStatusList();
return isset($list[$value]) ? $list[$value] : '';
}
}
... ...
<?php
namespace app\api\model;
use think\Model;
class CategoryGroup extends Model
{
// 表名
protected $name = 'category_group';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = false;
// 追加属性
protected $append = [
];
protected static function init()
{
self::afterInsert(function ($row) {
$pk = $row->getPk();
$row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
});
}
public function getStatusList()
{
return ['1' => __('Status 1'), '2' => __('Status 2')];
}
public function getSitelistList()
{
return ['1' => __('Sitelist 1'), '2' => __('Sitelist 2'), '3' => __('Sitelist 3')];
}
public function getStatusTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
$list = $this->getStatusList();
return isset($list[$value]) ? $list[$value] : '';
}
public function getSitelistTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['sitelist']) ? $data['sitelist'] : '');
$valueArr = explode(',', $value);
$list = $this->getSitelistList();
return implode(',', array_intersect_key($list, array_flip($valueArr)));
}
protected function setSitelistAttr($value)
{
return is_array($value) ? implode(',', $value) : $value;
}
public function getImageAttr($value)
{
if($value) $value = cdnurl($value);
return $value;
}
public function getIndexImageAttr($value)
{
if($value) $value = cdnurl($value);
return $value;
}
public function selectData($where, $limit)
{
$where['status'] = ['eq', '1'];
$data = $this->where($where)->field('id,ch_name,en_name,ch_index_name,en_index_name,index_image,image')->order('weigh desc')->limit($limit)->select();
return $data;
}
}
... ...
<?php
namespace app\api\model;
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()
{
return ['1' => __('Status 1'), '2' => __('Status 2')];
}
public function getStatusTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
$list = $this->getStatusList();
return isset($list[$value]) ? $list[$value] : '';
}
}
... ...
<?php
namespace app\api\model;
use think\Model;
class Command extends Model
{
// 表名
protected $name = 'command';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
// 追加属性
protected $append = [
'executetime_text',
'type_text',
'status_text'
];
public function getStatusList()
{
return ['successed' => __('Successed'), 'failured' => __('Failured')];
}
public function getExecutetimeTextAttr($value, $data)
{
$value = $value ? $value : $data['executetime'];
return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
}
public function getTypeTextAttr($value, $data)
{
$value = $value ? $value : $data['type'];
$list = ['crud' => '一键生成CRUD', 'menu' => '一键生成菜单', 'min' => '一键压缩打包', 'api' => '一键生成文档'];
return isset($list[$value]) ? $list[$value] : '';
}
public function getStatusTextAttr($value, $data)
{
$value = $value ? $value : $data['status'];
$list = $this->getStatusList();
return isset($list[$value]) ? $list[$value] : '';
}
protected function setExecutetimeAttr($value)
{
return $value && !is_numeric($value) ? strtotime($value) : $value;
}
}
... ...
<?php
namespace app\api\model;
use think\Model;
class Country extends Model
{
// 表名
protected $name = 'country';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = false;
// 追加属性
protected $append = [
'status_text'
];
protected static function init()
{
self::afterInsert(function ($row) {
$pk = $row->getPk();
$row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
});
}
public function getStatusList()
{
return ['1' => __('Status 1'), '2' => __('Status 2')];
}
public function getStatusTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
$list = $this->getStatusList();
return isset($list[$value]) ? $list[$value] : '';
}
}
... ...
<?php
namespace app\api\model;
use think\Model;
class Depot extends Model
{
// 表名
protected $name = 'depot';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = false;
// 追加属性
protected $append = [
];
public function goods()
{
return $this->belongsTo('Goods', 'goods_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
public function area()
{
return $this->belongsTo('Area', 'area_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
}
... ...
<?php
namespace app\api\model;
use think\Model;
class Evaluate extends Model
{
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = false;
public function getImagesAttr($value)
{
$arr = explode(',', $value);
$data = [];
foreach ($arr as $k => $v) {
$data[$k] = cdnurl($value);
}
return $data;
}
public function getCreatetimeAttr($value)
{
return date('Y-m-d',$value);
}
public function selectPageData($where,$page,$limit){
$total =$this->alias('e')
->join('fa_user u','e.user_id=u.id')
->where($where)
->count();
$list = $this->alias('e')
->join('fa_user u','e.user_id=u.id')
->where($where)
->field('e.content,e.images,e.createtime,u.avatar,u.nickname')
->page($page,$limit)
->select();
return ['total' => $total, 'list' => $list];
}
}
... ...
<?php
namespace app\api\model;
use think\Model;
class Exhibition extends Model
{
// 表名
protected $name = 'exhibition';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = false;
// 追加属性
protected $append = [
'sex_text',
'store_type_text',
'status_text'
];
public function getSexList()
{
return ['1' => __('Sex 1'), '2' => __('Sex 2')];
}
public function getStoreTypeList()
{
return ['1' => __('Store_type 1'), '2' => __('Store_type 2')];
}
public function getStatusList()
{
return ['1' => __('Status 1'), '2' => __('Status 2')];
}
public function getSexTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['sex']) ? $data['sex'] : '');
$list = $this->getSexList();
return isset($list[$value]) ? $list[$value] : '';
}
public function getStoreTypeTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['store_type']) ? $data['store_type'] : '');
$list = $this->getStoreTypeList();
return isset($list[$value]) ? $list[$value] : '';
}
public function getStatusTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
$list = $this->getStatusList();
return isset($list[$value]) ? $list[$value] : '';
}
public function user()
{
return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
}
... ...
<?php
namespace app\api\model;
use think\Model;
class Goods extends Model
{
// 表名
protected $name = 'goods';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = false;
// 追加属性
protected $append = [
];
protected static function init()
{
self::afterInsert(function ($row) {
$pk = $row->getPk();
$row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
});
}
public function getIsGroupList()
{
return ['1' => __('Is_group 1'), '2' => __('Is_group 2')];
}
public function getIsVipPriceList()
{
return ['1' => __('Is_vip_price 1'), '2' => __('Is_vip_price 2')];
}
public function getIsRecommendList()
{
return ['1' => __('Is_recommend 1'), '2' => __('Is_recommend 2')];
}
public function getStatusList()
{
return ['1' => __('Status 1'), '2' => __('Status 2')];
}
public function getIsGroupTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['is_group']) ? $data['is_group'] : '');
$list = $this->getIsGroupList();
return isset($list[$value]) ? $list[$value] : '';
}
public function getIsVipPriceTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['is_vip_price']) ? $data['is_vip_price'] : '');
$list = $this->getIsVipPriceList();
return isset($list[$value]) ? $list[$value] : '';
}
public function getIsRecommendTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['is_recommend']) ? $data['is_recommend'] : '');
$list = $this->getIsRecommendList();
return isset($list[$value]) ? $list[$value] : '';
}
public function getStatusTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
$list = $this->getStatusList();
return isset($list[$value]) ? $list[$value] : '';
}
public function brand()
{
return $this->belongsTo('Brand', 'brand_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
public function category()
{
return $this->belongsTo('Category', 'category_one_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
public function category2()
{
return $this->belongsTo('Category2', 'category2_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
public function level()
{
return $this->belongsTo('Level', 'level_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
public function country()
{
return $this->belongsTo('Country', 'country_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
public function part()
{
return $this->belongsTo('Part', 'part_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
public function categorygroup()
{
return $this->belongsTo('CategoryGroup', 'category_group_ids', 'id', [], 'LEFT')->setEagerlyType(0);
}
public function depot()
{
return $this->belongsTo('Depot', 'depot_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
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 selectHotData($where, $limit)
{
$where['g.status'] = 1;
$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')
->limit($limit)
->order('g.sales_actual desc')
->select();
return $data;
}
public function selectData($where, $limit)
{
$where['g.status'] = 1;
$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,c.ch_name ch_country_name,c.en_name en_country_name,is_vip_price,group_price,stock_num')
->limit($limit)
->order('g.weigh desc')
->select();
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 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')
->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 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')
->find();
return $data;
}
}
... ...
<?php
namespace app\api\model;
use think\Model;
class KeywordLog extends Model
{
public function selectData($where, $limit)
{
$data = $this
->where($where)
->limit($limit)
->order('createtime desc')
->column('content');
return $data;
}
}
... ...
<?php
namespace app\api\model;
use think\Model;
class Level extends Model
{
// 表名
protected $name = 'level';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = false;
// 追加属性
protected $append = [
'status_text'
];
protected static function init()
{
self::afterInsert(function ($row) {
$pk = $row->getPk();
$row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
});
}
public function getStatusList()
{
return ['1' => __('Status 1'), '2' => __('Status 2')];
}
public function getStatusTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
$list = $this->getStatusList();
return isset($list[$value]) ? $list[$value] : '';
}
}
... ...
<?php
namespace app\api\model;
use think\Model;
class Part extends Model
{
// 表名
protected $name = 'part';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = false;
// 追加属性
protected $append = [
'status_text'
];
protected static function init()
{
self::afterInsert(function ($row) {
$pk = $row->getPk();
$row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
});
}
public function getStatusList()
{
return ['1' => __('Status 1'), '2' => __('Status 2')];
}
public function getStatusTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
$list = $this->getStatusList();
return isset($list[$value]) ? $list[$value] : '';
}
}
... ...
<?php
namespace app\api\model;
use think\Model;
class Slide extends Model
{
// 表名
protected $name = 'slide';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = false;
// 追加属性
protected $append = [
];
protected static function init()
{
self::afterInsert(function ($row) {
$pk = $row->getPk();
$row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
});
}
public function getStatusList()
{
return ['1' => __('Status 1'), '2' => __('Status 2')];
}
public function getStatusTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
$list = $this->getStatusList();
return isset($list[$value]) ? $list[$value] : '';
}
public function getImageAttr($value){
return cdnurl($value);
}
public function selectData($where){
$where['status'] = ['eq','1'];
$data = $this->where($where)->order('weigh desc')->select();
return $data;
}
}
... ...
<?php
namespace app\api\model;
use app\common\model\MoneyLog;
use app\common\model\ScoreLog;
use think\Model;
class User extends Model
{
// 表名
protected $name = 'user';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
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()
{
return ['1' => __('Male'), '0' => __('Female')];
}
public function getStatusList()
{
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)
{
$value = $value ? $value : $data['logintime'];
return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $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)
{
return $value && !is_numeric($value) ? strtotime($value) : $value;
}
protected function setLogintimeAttr($value)
{
return $value && !is_numeric($value) ? strtotime($value) : $value;
}
protected function setJointimeAttr($value)
{
return $value && !is_numeric($value) ? strtotime($value) : $value;
}
public function group()
{
return $this->belongsTo('UserGroup', 'group_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
}
... ...
<?php
namespace app\api\model;
use think\Model;
class Video extends Model
{
// 表名
protected $name = 'video';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = false;
// 追加属性
protected $append = [
'status_text'
];
public function getStatusList()
{
return ['1' => __('Status 1'), '2' => __('Status 2')];
}
public function getStatusTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
$list = $this->getStatusList();
return isset($list[$value]) ? $list[$value] : '';
}
}
... ...
... ... @@ -222,6 +222,7 @@ return [
'type' => 'bootstrap',
'var_page' => 'page',
'list_rows' => 15,
'index_rows' => 15,
],
//验证码配置
'captcha' => [
... ...
... ... @@ -9,7 +9,7 @@ return [
/**
* CDN地址
*/
'cdnurl' => '',
'cdnurl' => 'http://q7s0a1rb4.bkt.clouddn.com',
/**
* 文件保存格式
*/
... ...
此 diff 太大无法显示。