作者 耿培杰

接口开发

<?php
/*
* 获取会员默认价格
*/
function get_vip_price_default($money){
return $money*0.95;
}
/*
* 获取员工代理默认价格
*/
function get_staff_price_default($money){
return $money*0.90;
}
/*
* 根据商品状态和用户身份获取最终价格
*/
function get_price($arr){
//会员特价
if(!empty($arr['is_vip_price']) && $arr['is_vip_price'] == 1 && $arr['user_type'] == 2) return $arr['vip_price'];
//员工或代理与会员折扣不同
if($arr['user_type'] == 3 || $arr['user_type'] == 4){
return get_staff_price_default($arr['goods_price']);
}elseif ($arr['user_type'] == 2){
//会员基础价,九五折
return get_vip_price_default($arr['goods_price']);
}
//原价
return $arr['goods_price'];
}
/*
* 根据商品状态和用户身份获取折扣价
*/
function get_discount_price($arr){
//会员特价
if(!empty($arr['is_vip_price']) && $arr['is_vip_price'] == 1 && $arr['user_type'] == 2) return $arr['goods_price'] - $arr['vip_price'];
//员工或代理与会员折扣不同
if($arr['user_type'] == 3 || $arr['user_type'] == 4) {
return $arr['goods_price'] - get_staff_price_default($arr['goods_price']);
}elseif ($arr['user_type'] == 2){
//会员基础价,九五折
return $arr['goods_price'] - get_vip_price_default($arr['goods_price']);
}
//原价
return 0;
}
/**
* 期间日期
* @param $startDate
* @param $endDate
* @return array
*/
function period_date($startDate, $endDate){
$startTime = strtotime($startDate);
$endTime = strtotime($endDate);
$arr = array();
$i = 0;
while ($startTime <= $endTime){
$arr[$i]['date'] = date('m-d', $startTime) . '/' . get_week(date('Y-m-d', $startTime));
$arr[$i]['week'] = date('w', $startTime);
$startTime = strtotime('+1 day', $startTime);
$i+=1;
}
return $arr;
}
/**
* 根据日期返回星期
* @param $date string 2020-4-22
* @return string
*/
function get_week($date){
$weekArr=["周日","周一","周二","周三","周四","周五","周六"];
return $weekArr[date("w",strtotime($date))];
}
\ No newline at end of file
... ...
... ... @@ -31,18 +31,22 @@ class Car extends Api
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1587472510",
"time": "1587610459",
"data": {
"total": 1,
"list": [
{
"content": "content", 评论内容
"images": [
"http://q7s0a1rb4.bkt.clouddn.com/uploads/20200420/26f5e51b8ac7fbd6f1c649cc45a18265.png" 评论图片
],
"createtime": "2020-04-20", 评论日期
"avatar": "avatar", 用户头像
"nickname": "admin" 用户昵称
"createtime": "1970-01-01",
"ch_country_name": "丹麦", 原产地中文名称
"en_country_name": "Denmark", 原产地英文名称
"number": 3, 数量
"goods_id": 3, 商品id
"ch_name": "猪肉", 中文名称
"en_name": "EMP selected", 英文名称
"image": "http://q7s0a1rb4.bkt.clouddn.com/uploads/20200420/26f5e51b8ac7fbd6f1c649cc45a18265.png", 缩略图
"goods_price": "60.00", 原价
"group_price": 30, 拼团价格
"is_group": "2" 团购:1=开启,2=关闭
}
]
}
... ... @@ -59,6 +63,47 @@ class Car extends Api
$this->success('SUCCESS',$data);
}
/**
* @ApiTitle (获取购物车金额)
* @ApiSummary (获取购物车金额,购物车递增递减后调用此接口刷新金额)
* @ApiMethod (POST)
* @ApiRoute (/api/car/getCarMoney)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name=car_id, type=string, required=false, description="购物车id 例 1,2,3")
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1587610459",
"data": {
"price": 316, 折扣后价格
"discount_price": 50, 折扣金额
"original_price": 366 原价
}
})
*/
public function getCarMoney(){
$userId = $this->getUserId();
$where['c.user_id'] = $userId;
$carid = $this->request->param('car_id');
$priceArr = $this->carModel->getCarMoney(['id'=>['in',$carid]]);
$price = 0; //折扣后价格
$discount_price = 0; //折扣金额
$original_price = 0; //原价
$data['integral'] = 0; //积分
foreach ($priceArr as $k=>$v){
$priceArr[$k]['user_type'] = $this->user['type'];
$price += get_price($v);
$discount_price += get_discount_price($v);
$original_price += $v['goods_price'];
if (!empty($v['integral'])) $data['integral'] += $v['integral'];
}
$data['price'] = round($price,2);
$data['discount_price'] = round($discount_price,2);
$data['original_price'] = $original_price;
$this->success('SUCCESS',$data);
}
/**
* @ApiTitle (添加购物车)
... ...
<?php
namespace app\api\controller;
use app\common\controller\Api;
use think\Db;
use think\Validate;
/**
* 订单接口
*/
class Order extends Api
{
protected $orderModel;
protected $carModel;
protected $areaExtendModel;
protected $integralGoodsModel;
protected function _initialize()
{
parent::_initialize();
$this->orderModel = new \app\api\model\Order();
$this->carModel = new \app\api\model\Car();
$this->areaExtendModel = new \app\api\model\AreaExtend();
$this->integralGoodsModel = new \app\api\model\IntegralGoods();
}
/**
* @ApiTitle (确认订单(购物车))
* @ApiSummary (确认订单(购物车))
* @ApiMethod (POST)
* @ApiHeaders (name=token, type=string, required=true description="请求的Token")
* @ApiParams (name=car_id, type=string, required=true, description="购物车id 例 1,2,3")
* @ApiParams (name=ticket_user_id, type=string, required=false, description="用户优惠券id")
* @ApiParams (name=ticket_code, type=string, required=false, description="优惠码")
* @ApiParams (name=province_id, type=string, required=true, description="省id")
* @ApiParams (name=city_id, type=string, required=true, description="市")
* @ApiParams (name=county_id, type=string, required=true, description="县")
* @ApiParams (name=postage_type, type=string, required=true, description="配送类型:1=普通配送,2=闪送")
* @ApiRoute (/api/order/order)
* @ApiReturn({
},
})
*/
public function order()
{
$carModel = new \app\api\model\Car();
$userAddressModel = new \app\api\model\UserAddress();
$goodsModel = new \app\api\model\Goods();
$ticketCodeModel = new \app\api\model\Ticketcode();
$userTicketModel = new \app\api\model\UserTicket();
$userId = $this->getUserId();
$carId = $this->request->param('car_id');
$ticketId = $this->request->param('ticket_user_id');
$ticketCode = $this->request->param('ticket_code');
$provinceId = $this->request->param('province_id');
$cityId = $this->request->param('city_id');
$countyId = $this->request->param('county_id');
$postageType = $this->request->param('postage_type');
if (empty($carId)) $this->error('缺少参数 car_id!');
//判断优惠券和优惠码不能同时使用
if (!empty($ticketCode) && !empty($ticketId)) $this->error('优惠券与优惠码不能同时使用!');
if (empty($provinceId)) {
//获取用户默认地址
$address = $userAddressModel->getDefaultData(['user_id' => $userId]);
$provinceId = $address['province_id'];
}
//获取普通商品id
$goodsIds = $carModel->where(['id' => ['in', $carId], 'type' => 1])->column('goods_id');
//获取积分商品id
$goodsIntegralIds = $carModel->where(['id' => ['in', $carId], 'type' => 2])->column('goods_id');
//获取普通商品状态
if ($goodsIds) {
$goodsList = $goodsModel->selectGoodsStatus(['id' => ['in', $goodsIds]]);
//判断商品是否有库存和状态
foreach ($goodsList as $k => $v) {
if ($v['status'] == 2) $this->error($v['ch_name'] . '商品已下架');
if ($v['stock_num'] == 0) $this->error($v['ch_name'] . '商品库存不足');
//判断用户收货区域是否有库存
$areaStock = $goodsModel->getAreaStockNum(['g.id' => $v['id'], 'd.area_id' => $provinceId]);
if (!$areaStock) $data['is_lack_stock'] = 1;
}
}
//获取积分商品状态
if ($goodsIntegralIds) {
$goodsIntegralList = $this->integralGoodsModel->selectGoodsStatus(['id' => ['in', $goodsIntegralIds]]);
//判断商品是否有库存和状态
foreach ($goodsIntegralList as $k => $v) {
if ($v['status'] == 2) $this->error($v['ch_name'] . '商品已下架');
if ($v['stock_num'] == 0) $this->error($v['ch_name'] . '商品库存不足');
//判断用户收货区域是否有库存
$areaStock = $this->integralGoodsModel->getAreaStockNum(['g.id' => $v['id'], 'd.area_id' => $provinceId]);
if (!$areaStock) $data['is_lack_stock'] = 1;
}
}
//判断优惠码是否可用
if (!empty($ticketCode)) {
$ticketCodeInfo = $ticketCodeModel->where('code', $ticketCode)->field('user_id,validtime')->find();
if (!$ticketCodeInfo) $this->error('优惠码不存在!');
if ($ticketCodeInfo['validtime'] < time()) $this->error('优惠码已过期!');
if ($ticketCodeInfo['user_id']) $this->error('优惠码已使用!');
}
//判断优惠券是否可用
if (!empty($ticketId)) {
$ticketInfo = $userTicketModel->where(['user_id' => $userId, 'id' => $ticketId, 'status' => 1])->find();
if (!$ticketInfo) $this->error('优惠码不存在!');
}
//获取原价,现价,折扣
$priceArr = $this->carModel->getCarMoney(['id' => ['in', $carId]]);
$data['price'] = 0; //折扣后价格
$data['discount_price'] = 0; //折扣金额
$data['original_price'] = 0; //原价
$data['integral'] = 0; //积分
foreach ($priceArr as $k => $v) {
$priceArr[$k]['user_type'] = $this->user['type'];
$data['price'] += round(get_price($v), 2);
$data['discount_price'] += round(get_discount_price($v), 2);
$data['original_price'] += $v['goods_price'];
if (!empty($v['integral'])) $data['integral'] += $v['integral'];
}
//获取运费
$is_special = $this->areaExtendModel->where(['province_id' => $provinceId])->value('is_special');
if ($is_special == 1 && $data['price'] >= 200) {
$postage = 0;
} elseif ($data['price'] >= 300) {
$postage = 0;
} else {
//配送为闪送
$postageWhere = ['province_id' => $provinceId, 'city_id' => $cityId, 'county_id' => $countyId];
if ($postageType == 2) {
$postage = $this->areaExtendModel->where($postageWhere)->value('postage2');
} else {
$postage = $this->areaExtendModel->where($postageWhere)->value('postage1');
}
if (!$postage) {
$postage = $this->areaExtendModel->where(['province_id' => $provinceId])->value('postage1');
}
}
$data['postage'] = $postage;
$data['price'] += $postage;
//使用优惠码
if (!empty($ticketCodeInfo)) {
$data['price'] = $data['price'] - $ticketCodeInfo['price'];
$data['ticketcode_discount_price'] = $ticketCodeInfo['price'];
}
//使用优惠券
if (!empty($ticketInfo)) {
$data['price'] = $data['price'] - $ticketInfo['price'];
$data['ticket_discount_price'] = $ticketInfo['price'];
}
$this->success('success', $data);
}
/**
* @ApiTitle (创建订单(购物车))
* @ApiSummary (创建订单(购物车))
* @ApiMethod (POST)
* @ApiHeaders (name=token, type=string, required=true description="请求的Token")
* @ApiParams (name=car_id, type=string, required=true, description="购物车id 例 1,2,3")
* @ApiParams (name=ticket_user_id, type=string, required=false, description="用户优惠券id")
* @ApiParams (name=ticket_code, type=string, required=false, description="优惠码")
* @ApiParams (name=address, type=string, required=true, description="商品收货地址")
* @ApiParams (name=present_id, type=string, required=false, description="赠品id")
* @ApiParams (name=delivery, type=string, required=false, description="配送时间")
* @ApiParams (name=invoice_type, type=string, required=false, description="发票类型:1=个人或事业单位,2=企业")
* @ApiParams (name=email, type=string, required=false, description="电子发票邮箱")
* @ApiParams (name=taitou, type=string, required=false, description="发票抬头")
* @ApiParams (name=duty_num, type=string, required=false, description="发票税号")
* @ApiParams (name=invoice_address, type=string, required=false, description="发票收货地址")
* @ApiParams (name=order_note, type=string, required=false, description="订单备注")
* @ApiRoute (/api/order/createOrder)
* @ApiReturn({
},
})
*/
public function createOrder()
{
}
}
... ...
... ... @@ -21,10 +21,15 @@ class Present extends Api
"code": 1,
"msg": "SUCCESS",
"time": "1553839125",
"data": {
"id": "id",// 地区id
"name": "name",// 名称
"data": [
{
"id": 3, 赠品id
"ch_name": "赠品3", 中文名称
"en_name": "present3", 英文名称
"image": "http://q7s0a1rb4.bkt.clouddn.com/uploads/20200420/26f5e51b8ac7fbd6f1c649cc45a18265.png" 缩略图
},
]
})
*/
public function getPresentList(){
... ...
... ... @@ -3,8 +3,10 @@
namespace app\api\controller;
use app\api\model\Area;
use app\api\model\AreaExtend;
use app\api\model\KeywordLog;
use app\api\model\Slide;
use app\api\model\WeekTemplate;
use app\common\controller\Api;
use think\Db;
use think\Validate;
... ... @@ -99,4 +101,67 @@ class Sundry extends Api
$this->success('SUCCESS',$data);
}
/**
* @ApiTitle (获取配送时间)
* @ApiSummary (获取配送时间)
* @ApiMethod (POST)
* @ApiRoute (/api/sundry/getDeliveryTime)
* @ApiHeaders (name=token, type=string, required=false, description="请求的Token")
* @ApiParams (name=province_id, type=string, required=true, description="省")
* @ApiParams (name=city_id, type=string, required=false, description="市")
* @ApiParams (name=county_id, type=string, required=false, description="县")
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1553839125",
"data": {
"id": "id",// 地区id
"name": "name",// 名称
},
})
*/
public function getDeliveryTime(){
$model = new AreaExtend();
$params = $this->request->param();
if (!empty($params['province_id'])) $where['province_id'] = $params['province_id'];
else $this->error('缺少参数 province_id!');
if (!empty($params['city_id'])) $where['city_id'] = $params['city_id'];
if (!empty($params['county_id'])) $where['county_id'] = $params['county_id'];
$data = $model->where($where)->field('is_special,starttime1,endtime1,starttime2,endtime2')->find();
$startDate = date("Y-m-d",strtotime('+'.$data['starttime1'].' days',time()));
$endDate = date("Y-m-d",strtotime('+'.$data['endtime1'].' days',time()));
$data['date'] = period_date($startDate,$endDate);
$this->success('SUCCESS',$data);
}
/**
* @ApiTitle (获取闪送配送时间)
* @ApiSummary (获取闪送配送时间)
* @ApiMethod (POST)
* @ApiRoute (/api/sundry/getDeliveryFastTime)
* @ApiHeaders (name=token, type=string, required=false, description="请求的Token")
* @ApiParams (name=week, type=string, required=true, description="星期 getDeliveryTime接口返回的week字段")
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1553839125",
"data": {
"id": "id",// 地区id
"name": "name",// 名称
},
})
*/
public function getDeliveryFastTime(){
$model = new WeekTemplate();
$week = $this->request->param('week');
if (empty($week)) $this->error('缺少参数 week!');
$data = $model->selectData(['type'=>$week]);
foreach ($data as $k=>$v){
$data[$k] = $v['starttime'].'-'.$v['endtime'];
}
$this->success('SUCCESS',$data);
}
}
... ...
<?php
namespace app\api\controller;
use think\Db;
use think\Validate;
use app\common\controller\Api;
/**
* 优惠码接口
*/
class Ticketcode extends Api
{
/**
* @ApiTitle (检查优惠码)
* @ApiSummary (检查优惠码)
* @ApiMethod (POST)
* @ApiRoute (/api/ticketcode/checkTicketCode)
* @ApiHeaders (name=token, type=string, required=false, description="请求的Token")
* @ApiParams (name=ticket_code, type=string, required=false, description="优惠码")
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1553839125",
"data": {
"id": "id",// 地区id
"name": "name",// 名称
},
})
*/
public function checkTicketCode()
{
$ticketCodeModel = new \app\api\model\Ticketcode();
//判断优惠码是否可用
$ticketCode = $this->request->param('ticket_code');
if (!$ticketCode) $this->error('缺少参数 ticket_code!');
$ticketCodeInfo = $ticketCodeModel->where('code', $ticketCode)->field('user_id,validtime')->find();
if (!$ticketCodeInfo) $this->error('优惠码不存在!');
if ($ticketCodeInfo['validtime'] < time()) $this->error('优惠码已过期!');
if ($ticketCodeInfo['user_id']) $this->error('优惠码已使用!');
$this->success('SUCCESS');
}
}
... ...
... ... @@ -88,7 +88,7 @@ class UserAddress extends Api
* @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=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="省")
... ... @@ -110,7 +110,7 @@ class UserAddress extends Api
$data = $this->request->param();
$data['user_id'] = $userId;
$validate = new Validate([
'user_address_id' => 'require',
'id' => 'require',
'name' => 'require',
'mobile' => ['^1\d{10}$','require'],
'province_id' => 'require',
... ... @@ -121,7 +121,7 @@ class UserAddress extends Api
]);
$validate->message([
'user_address_id' => '缺少参数 user_address_id!',
'id' => '缺少参数 id!',
'name' => '缺少参数 name!',
'mobile.require' => '缺少参数 mobile!',
'province_id' => '缺少参数 province_id!',
... ... @@ -141,7 +141,7 @@ class UserAddress extends Api
}
$res = $model->save($data);
$res = $model->update($data);
if ($res) $this->success('SUCCESS');
else $this->error('ERROR');
}
... ... @@ -152,7 +152,7 @@ class UserAddress extends Api
* @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")
* @ApiParams (name=id, type=string, required=true, description="地址id")
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
... ... @@ -164,9 +164,9 @@ class UserAddress extends Api
{
$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;
$id = $this->request->param('id');
if (empty($id)) $this->error('缺少参数 id!');
$where['id'] = $id;
$res = $model->where($where)->delete();
if ($res) $this->success('SUCCESS');
else $this->error('ERROR');
... ... @@ -178,7 +178,7 @@ class UserAddress extends Api
* @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")
* @ApiParams (name=id, type=string, required=true, description="地址id")
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
... ... @@ -191,9 +191,9 @@ class UserAddress extends Api
$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;
$id = $this->request->param('id');
if (empty($id)) $this->error('缺少参数 id!');
$where['id'] = $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();
... ... @@ -230,4 +230,26 @@ class UserAddress extends Api
$this->success('SUCCESS',$data);
}
/**
* @ApiTitle (获取用户默认地址)
* @ApiSummary (获取用户默认地址)
* @ApiMethod (POST)
* @ApiRoute (/api/user_address/getUserAddressDefault)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1587361014",
"data":
})
*/
public function getUserAddressDefault()
{
$model = new UserAddressModel();
$userId = $this->getUserId();
$data = $model->getDefaultData(['user_id'=>$userId]);
$this->success('SUCCESS',$data);
}
}
\ No newline at end of file
... ...
<?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 UserInvoice extends Api
{
protected $userModel;
public function _initialize()
{
parent::_initialize();
$this->userModel = new User();
}
/**
* @ApiTitle (添加用户发票)
* @ApiSummary (添加用户发票)
* @ApiMethod (POST)
* @ApiRoute (/api/user_invoice/addUserInvoice)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name=type, type=string, required=true, description="类型:1=个人或事业单位,2=企业")
* @ApiParams (name=taitou, type=string, required=true, description="发票抬头")
* @ApiParams (name=duty_num, type=string, required=false, description="税号")
* @ApiParams (name=is_default, type=string, required=true, description="默认:1=是,2=否")
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1587361014",
"data":
})
*/
public function addUserInvoice()
{
$model = new \app\api\model\UserInvoice();
$userId = $this->getUserId();
$data = $this->request->param();
$data['user_id'] = $userId;
$validate = new Validate([
'type' => 'require',
'taitou' => 'require',
'is_default' => 'require',
]);
$validate->message([
'type' => '缺少参数 type!',
'taitou' => '缺少参数 taitou!',
'is_default' => '缺少参数 is_default!',
]);
if (!$validate->check($data)) {
$this->error($validate->getError());
}
if ($data['is_default'] == 1){
$model->where(['user_id'=>$userId,'type'=>$data['type']])->update(['is_default'=>2]);
}
$res = $model->save($data);
if ($res) $this->success('SUCCESS');
else $this->error('ERROR');
}
/**
* @ApiTitle (编辑用户收货地址)
* @ApiSummary (编辑用户收货地址)
* @ApiMethod (POST)
* @ApiRoute (/api/user_invoice/editUserInvoice)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name=id, type=string, required=true, description="发票id")
* @ApiParams (name=type, type=string, required=true, description="类型:1=个人或事业单位,2=企业")
* @ApiParams (name=taitou, type=string, required=true, description="发票抬头")
* @ApiParams (name=duty_num, type=string, required=false, description="税号")
* @ApiParams (name=is_default, type=string, required=true, description="默认:1=是,2=否")
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1587361014",
"data":
})
*/
public function editUserInvoice()
{
$model = new \app\api\model\UserInvoice();
$userId = $this->getUserId();
$data = $this->request->param();
$data['user_id'] = $userId;
$validate = new Validate([
'id' => 'require',
'type' => 'require',
'taitou' => 'require',
'is_default' => 'require',
]);
$validate->message([
'id' => '缺少参数 id!',
'type' => '缺少参数 type!',
'taitou' => '缺少参数 taitou!',
'is_default' => '缺少参数 is_default!',
]);
if (!$validate->check($data)) {
$this->error($validate->getError());
}
if ($data['is_default'] == 1){
$model->where(['user_id'=>$userId,'type'=>$data['type']])->update(['is_default'=>2]);
}
$res = $model->update($data);
if ($res) $this->success('SUCCESS');
else $this->error('ERROR');
}
/**
* @ApiTitle (删除用户发票)
* @ApiSummary (删除用户发票)
* @ApiMethod (POST)
* @ApiRoute (/api/user_invoice/delUserInvoice)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name=id, type=string, required=true, description="发票id")
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1587361014",
"data":
})
*/
public function delUserInvoice()
{
$model = new \app\api\model\UserInvoice();
$userId = $this->getUserId();
$id = $this->request->param('id');
if (empty($id)) $this->error('缺少参数 id!');
$where['id'] = $id;
$res = $model->where($where)->delete();
if ($res) $this->success('SUCCESS');
else $this->error('ERROR');
}
/**
* @ApiTitle (用户发票详情)
* @ApiSummary (用户发票详情)
* @ApiMethod (POST)
* @ApiRoute (/api/user_invoice/getUserInvoiceInfo)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name=id, type=string, required=true, description="发票id")
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1587361014",
"data":
})
*/
public function getUserInvoiceInfo()
{
$model = new \app\api\model\UserInvoice();
$userId = $this->getUserId();
$id = $this->request->param('id');
if (empty($id)) $this->error('缺少参数 id!');
$where['id'] = $id;
$data = $model->where($where)->find();
$this->success('SUCCESS',$data);
}
/**
* @ApiTitle (用户发票列表)
* @ApiSummary (用户发票列表)
* @ApiMethod (POST)
* @ApiRoute (/api/user_invoice/getUserInvoiceIList)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1587361014",
"data":
})
*/
public function getUserInvoiceIList()
{
$model = new \app\api\model\UserInvoice();
$userId = $this->getUserId();
$where['user_id'] = $userId;
$data = $model->where($where)->select();
$this->success('SUCCESS',$data);
}
/**
* @ApiTitle (获取用户默认发票)
* @ApiSummary (获取用户默认发票)
* @ApiMethod (POST)
* @ApiRoute (/api/user_invoice/getUserInvoiceDefault)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name=type, type=string, required=true, description="类型:1=个人或事业单位,2=企业")
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1587361014",
"data":
})
*/
public function getUserInvoiceDefault()
{
$model = new \app\api\model\UserInvoice();
$userId = $this->getUserId();
$type = $this->request->param('type');
if (empty($type)) $this->error('缺少参数 type!');
$data = $model->where(['user_id'=>$userId,'type'=>$type,'is_default'=>1])->find();
$this->success('SUCCESS',$data);
}
}
\ No newline at end of file
... ...
<?php
namespace app\api\model;
use think\Model;
class AreaExtend extends Model
{
}
... ...
... ... @@ -34,9 +34,27 @@ class Car extends Model
->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')
->field('c.createtime,cou.ch_name ch_country_name,cou.en_name en_country_name,c.number,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];
}
public function getCarMoney($where){
$goodsId = $this->where($where)->where(['type'=>1])->column('id');
$goodsList = $this->alias('c')
->join('fa_goods g','c.goods_id=g.id')
->where(['c.id'=>['in',$goodsId]])
->field('goods_price*number goods_price,g.vip_price*number vip_price,g.is_vip_price,c.number')
->select();
$integralGoodsId = $this->where($where)->where(['type'=>2])->column('id');
$integralGoodsList = $this->alias('c')
->join('fa_integral_goods g','c.goods_id=g.id')
->where(['c.id'=>['in',$integralGoodsId]])
->field('goods_price*number goods_price,c.number,integral')
->select();
$list = array_merge($goodsList,$integralGoodsList);
return $list;
}
}
... ...
... ... @@ -86,53 +86,6 @@ class Goods extends Model
}
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);
... ... @@ -202,4 +155,28 @@ class Goods extends Model
->find();
return $data;
}
public function selectGoodsStatus($where)
{
$list = $this->alias('g')
// ->join('fa_depot d', 'g.id=d.goods_id')
->where($where)
->field('g.id,g.ch_name,g.status,g.stock_num')
->select();
return $list;
}
/**
* 获取仓库库存
* @param $where
* @return mixed
*/
public function getAreaStockNum($where){
$stockNum = $this->alias('g')
->join('fa_depot d','g.id=d.goods_id')
->where($where)
->field('d.stock_num,g.ch_name')
->find();
return $stockNum;
}
}
... ...
... ... @@ -52,4 +52,28 @@ class IntegralGoods extends Model
->find();
return $data;
}
public function selectGoodsStatus($where)
{
$list = $this->alias('g')
// ->join('fa_depot d', 'g.id=d.goods_id')
->where($where)
->field('g.id,g.ch_name,g.status,g.stock_num')
->select();
return $list;
}
/**
* 获取仓库库存
* @param $where
* @return mixed
*/
public function getAreaStockNum($where){
$stockNum = $this->alias('g')
->join('fa_integral_depot d','g.id=d.goods_id')
->where($where)
->field('d.stock_num,g.ch_name')
->find();
return $stockNum;
}
}
... ...
<?php
namespace app\api\model;
use think\Model;
class Order extends Model
{
}
... ...
<?php
namespace app\api\model;
use think\Model;
class Ticket extends Model
{
}
... ...
<?php
namespace app\api\model;
use think\Model;
class Ticketcode extends Model
{
}
... ...
... ... @@ -15,4 +15,15 @@ class UserAddress extends Model
protected $updateTime = 'updatetime';
protected $deleteTime = false;
public function getDefaultData($where)
{
$areaModel = new Area();
$where['is_default'] = 1;
$data = $this->where($where)->field('createtime,updatetime,is_default,id,user_id',true)->find();
$ids = $data['province_id'] . ',' . $data['city_id'] . ',' . $data['county_id'];
$area = $areaModel->where(['id' => ['in', $ids]])->column('name');
$data['address'] = implode('', $area) . $data['address'];
return $data;
}
}
... ...
<?php
namespace app\api\model;
use think\Model;
class UserInvoice extends Model
{
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = false;
// 追加属性
protected $append = [
];
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 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;
}
}
... ...
<?php
namespace app\api\model;
use think\Model;
class WeekTemplate extends Model
{
public function selectData($where){
$where['status'] = ['eq','1'];
$data = $this->where($where)->field('starttime,endtime')->order('weigh desc')->select();
return $data;
}
}
... ...
此 diff 太大无法显示。