作者 耿培杰

接口开发

... ... @@ -74,4 +74,13 @@ function period_date($startDate, $endDate){
function get_week($date){
$weekArr=["周日","周一","周二","周三","周四","周五","周六"];
return $weekArr[date("w",strtotime($date))];
}
/**
* 获取惟一订单号
* @return string
*/
function get_order_num()
{
return date('Ymd') . substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
}
\ No newline at end of file
... ...
... ... @@ -2,6 +2,7 @@
namespace app\api\controller;
use app\api\model\UserScoreLog;
use app\common\controller\Api;
use think\Db;
use think\Validate;
... ... @@ -15,6 +16,13 @@ class Order extends Api
protected $carModel;
protected $areaExtendModel;
protected $integralGoodsModel;
protected $goodsModel;
protected $ticketCodeModel;
protected $userTicketModel;
protected $orderAddressModel;
protected $orderAddressInvoiceModel;
protected $orderInfoModel;
protected $userModel;
protected function _initialize()
{
... ... @@ -23,6 +31,13 @@ class Order extends Api
$this->carModel = new \app\api\model\Car();
$this->areaExtendModel = new \app\api\model\AreaExtend();
$this->integralGoodsModel = new \app\api\model\IntegralGoods();
$this->goodsModel = new \app\api\model\Goods();
$this->ticketCodeModel = new \app\api\model\Ticketcode();
$this->userTicketModel = new \app\api\model\UserTicket();
$this->orderAddressModel = new \app\api\model\OrderAddress();
$this->orderAddressInvoiceModel = new \app\api\model\OrderAddressInvoice();
$this->orderInfoModel = new \app\api\model\OrderInfo();
$this->userModel = new \app\api\model\User();
}
/**
... ... @@ -39,14 +54,24 @@ class Order extends Api
* @ApiParams (name=postage_type, type=string, required=true, description="配送类型:1=普通配送,2=闪送")
* @ApiRoute (/api/order/order)
* @ApiReturn({
"code": 1,
"msg": "success",
"time": "1587691008",
"data": {
"price": 263.7, 总价
"discount_price": 12.3, 折扣价
"original_price": 246, 原价
"ticketcode_discount_price": 5, 优惠码优惠价
"ticket_discount_price": 10, 优惠券优惠价
"integral": 0, 积分
"postage": "30.00" 运费
}
},
})
*/
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();
... ... @@ -59,13 +84,11 @@ class Order extends Api
$countyId = $this->request->param('county_id');
$postageType = $this->request->param('postage_type');
if (empty($carId)) $this->error('缺少参数 car_id!');
if (empty($provinceId)) $this->error('缺少参数 province_id!');
if (empty($cityId)) $this->error('缺少参数 city_id!');
if (empty($countyId)) $this->error('缺少参数 county_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
... ... @@ -125,23 +148,31 @@ class Order extends Api
if (!empty($v['integral'])) $data['integral'] += $v['integral'];
}
//判断积分
if ($data['integral'] > $this->user['score']) $this->error('积分不足');
//获取运费
$is_special = $this->areaExtendModel->where(['province_id' => $provinceId])->value('is_special');
//特殊地区满200免运费
if ($is_special == 1 && $data['price'] >= 200) {
$postage = 0;
//其他地区满300免运费
} 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');
if (!$postage) {
$postage = $this->areaExtendModel->where(['province_id' => $provinceId])->value('postage2');
}
} else {
//配送为普通配送
$postage = $this->areaExtendModel->where($postageWhere)->value('postage1');
}
if (!$postage) {
$postage = $this->areaExtendModel->where(['province_id' => $provinceId])->value('postage1');
if (!$postage) {
$postage = $this->areaExtendModel->where(['province_id' => $provinceId])->value('postage1');
}
}
}
$data['postage'] = $postage;
... ... @@ -170,16 +201,30 @@ class Order extends Api
* @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=pay_type, type=string, required=false, description="支付类型:1=微信支付,2=余额支付")
* @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="商品收货地址市id")
* @ApiParams (name=county_id, type=string, required=true, description="商品收货地址县id")
* @ApiParams (name=address, type=string, required=true, description="商品收货地址")
* @ApiParams (name=name, type=string, required=true, description="商品收货人")
* @ApiParams (name=mobile, 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=postage_type, type=string, required=true, description="配送类型:1=普通配送,2=闪送")
* @ApiParams (name=postage_date, type=string, required=false, description="配送日期")
* @ApiParams (name=postage_time, type=string, required=false, description="配送时间")
* @ApiParams (name=invoice_status, type=string, required=true, description="发票状态:1=个人或事业单位,2=企业,3=不需要开发票")
* @ApiParams (name=invoice_type, type=string, required=false, description="发票类型:1=纸质发票,2=电子发票")
* @ApiParams (name=invoice_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_province_id, type=string, required=false, description="发票收货地址省id")
* @ApiParams (name=invoice_city_id, type=string, required=false, description="发票收货地址市id")
* @ApiParams (name=invoice_county_id, type=string, required=false, description="发票收货地址县id")
* @ApiParams (name=invoice_address, type=string, required=false, description="发票收货地址")
* @ApiParams (name=invoice_name, type=string, required=false, description="发票收货人")
* @ApiParams (name=invoice_mobile, type=string, required=false, description="发票收货电话")
* @ApiParams (name=order_note, type=string, required=false, description="订单备注")
* @ApiRoute (/api/order/createOrder)
* @ApiReturn({
... ... @@ -189,7 +234,293 @@ class Order extends Api
*/
public function createOrder()
{
$userId = $this->getUserId();
$param = $this->request->param();
$param['user_id'] = $userId;
$validate = new Validate([
'car_id' => 'require',
'pay_type' => 'require',
'name' => 'require',
'mobile' => 'require',
'address' => 'require',
'province_id' => 'require',
'city_id' => 'require',
'county_id' => 'require',
'postage_type' => 'require',
'invoice_status' => 'require',
]);
$validate->message([
'car_id' => '缺少参数 car_id!',
'pay_type' => '缺少参数 pay_type!',
'name' => '缺少参数 name!',
'mobile' => '缺少参数 mobile!',
'address' => '缺少参数 address!',
'province_id' => '缺少参数 province_id!',
'city_id' => '缺少参数 city_id!',
'county_id' => '缺少参数 county_id!',
'postage_type' => '缺少参数 postage_type!',
'invoice_status' => '缺少参数 invoice_status!',
]);
if (!$validate->check($param)) {
$this->error($validate->getError());
}
//判断优惠券和优惠码不能同时使用
if (!empty($param['ticket_code']) && !empty($param['ticket_user_id'])) $this->error('优惠券与优惠码不能同时使用!');
//获取普通商品id
$goodsIds = $this->carModel->where(['id' => ['in', $param['car_id']], 'type' => 1])->column('goods_id');
//获取积分商品id
$goodsIntegralIds = $this->carModel->where(['id' => ['in', $param['car_id']], 'type' => 2])->column('goods_id');
//获取普通商品状态
if ($goodsIds) {
$goodsList = $this->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'] . '商品库存不足');
}
}
//获取积分商品状态
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'] . '商品库存不足');
}
}
//判断优惠码是否可用
if (!empty($param['ticket_code'])) {
$ticketCodeInfo = $this->ticketCodeModel->where('code', $param['ticket_code'])->find();
if (!$ticketCodeInfo) $this->error('优惠码不存在!');
if ($ticketCodeInfo['validtime'] < time()) $this->error('优惠码已过期!');
if ($ticketCodeInfo['user_id']) $this->error('优惠码已使用!');
}
//判断优惠券是否可用
if (!empty($param['ticket_user_id'])) {
$ticketInfo = $this->userTicketModel->where(['user_id' => $userId, 'id' => $param['ticket_user_id'], 'status' => 1])->find();
if (!$ticketInfo) $this->error('优惠码不存在!');
}
//获取原价,现价,折扣
$priceArr = $this->carModel->getCarMoney(['id' => ['in', $param['car_id']]]);
$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'];
}
//判断积分
if ($data['integral'] > $this->user['score']) $this->error('积分不足');
//获取运费
$is_special = $this->areaExtendModel->where(['province_id' => $param['province_id']])->value('is_special');
//特殊地区满200免运费
if ($is_special == 1 && $data['price'] >= 200) {
$postage = 0;
//其他地区满300免运费
} elseif ($data['price'] >= 300) {
$postage = 0;
} else {
//都不满足获取对应的运费
$postageWhere = ['province_id' => $param['province_id'], 'city_id' => $param['city_id'], 'county_id' => $param['county_id']];
if ($param['postage_type'] == 2) {
//配送为闪送
$postage = $this->areaExtendModel->where($postageWhere)->value('postage2');
if (!$postage) {
$postage = $this->areaExtendModel->where(['province_id' => $param['province_id']])->value('postage2');
}
} else {
//配送为普通配送
$postage = $this->areaExtendModel->where($postageWhere)->value('postage1');
if (!$postage) {
$postage = $this->areaExtendModel->where(['province_id' => $param['province_id']])->value('postage1');
}
}
}
$data['postage'] = $postage;
$data['price'] += $postage;
Db::startTrans();
try {
//使用优惠码
if (!empty($ticketCodeInfo)) {
$data['price'] = $data['price'] - $ticketCodeInfo['price'];
$data['ticketcode_discount_price'] = $ticketCodeInfo['price'];
$data['ticketcode_id'] = $ticketCodeInfo['id'];
$this->ticketCodeModel->where('id', $ticketCodeInfo['id'])->update(['user_id' => $userId]);
}
//使用优惠券
if (!empty($ticketInfo)) {
$data['price'] = $data['price'] - $ticketInfo['price'];
$data['ticket_discount_price'] = $ticketInfo['price'];
$data['user_ticket_id'] = $ticketInfo['id'];
$this->userTicketModel->where('id', $ticketInfo['id'])->update(['status' => 2]);
}
//order表数据
$orderData = [
'order_num' => get_order_num(),
'user_id' => $userId,
'pay_type' => $param['pay_type'],
'goods_total' => $data['original_price'],
'pay_total' => $data['price'],
'discount_price' => $data['discount_price'],
'score' => $data['integral'],
'postage_total' => $postage,
'postage_type' => $param['postage_type'],
'postage_date' => $param['postage_date'],
'postage_time' => $param['postage_time'],
'user_ticket_id' => !empty($data['user_ticket_id']) ? $data['user_ticket_id'] : '',
'ticket_price' => !empty($data['ticket_discount_price']) ? $data['ticket_discount_price'] : '',
'ticketcode_id' => !empty($data['ticketcode_id']) ? $data['ticketcode_id'] : '',
'ticketcode_price' => !empty($data['ticketcode_discount_price']) ? $data['ticketcode_discount_price'] : '',
'invoice_status' => $param['invoice_status'],
'invoice_type' => !empty($param['invoice_type']) ? $param['invoice_type'] : '',
'invoice_email' => !empty($param['invoice_email']) ? $param['invoice_email'] : '',
'taitou' => !empty($param['taitou']) ? $param['taitou'] : '',
'duty_num' => !empty($param['duty_num']) ? $param['duty_num'] : '',
'order_note' => !empty($param['order_note']) ? $param['order_note'] : '',
'type' => 1,
'status' => 1,
'createtime' => time(),
'updatetime' => time(),
];
$res1 = $this->orderModel->insertGetId($orderData);
//收货地址数据
$orderAddress = [
'order_id' => $res1,
'name' => $param['name'],
'mobile' => $param['mobile'],
'address' => $param['address'],
'province_id' => $param['province_id'],
'city_id' => $param['city_id'],
'county_id' => $param['county_id'],
'createtime' => time(),
'updatetime' => time(),
];
$res2 = $this->orderAddressModel->insertData($orderAddress);
if ($param['invoice_status'] != 3) {
//收货地址数据
$orderAddressInvoice = [
'order_id' => $res1,
'name' => $param['invoice_name'],
'mobile' => $param['invoice_mobile'],
'address' => $param['invoice_address'],
'province_id' => $param['invoice_province_id'],
'city_id' => $param['invoice_city_id'],
'county_id' => $param['invoice_county_id'],
'createtime' => time(),
'updatetime' => time(),
];
$res3 = $this->orderAddressInvoiceModel->insertData($orderAddress);
}
$where = ['order_address_id' => $res2, 'id' => $res1];
if (!empty($res3)) $where['order_address_invoice_id'] = $res3;
$this->orderModel->update($where);
$list = $this->carModel->getCarMoney(['id' => ['in', $param['car_id']]]);
$orderInfoData = [];
foreach ($list as $k => $goodsItem) {
$goodsItem['user_type'] = $this->user['type'];
$orderInfoData[$k] = [
'order_id' => $res1,
'pay_type' => $param['pay_type'],
'user_id' => $userId,
'goods_id' => $goodsItem['id'],
'ch_goods_name' => $goodsItem['ch_name'],
'en_goods_name' => $goodsItem['en_name'],
'goods_image' => $goodsItem['image'],
'number' => $goodsItem['number'],
'type' => $goodsItem['type'],
'score' => !empty($goodsItem['integral']) ? $goodsItem['integral'] : '',
'goods_total' => get_price($goodsItem),
'pay_total' => $data['price'],
'postage_total' => $postage,
'status' => 1,
];
}
$res4 = $this->orderInfoModel->saveAll($orderInfoData);
//有积分商品减积分
if (!empty($goodsItem['integral'])) {
$userScoreLogModel = new UserScoreLog();
$res5 = $userScoreLogModel->setDecScore($userId, $goodsItem['integral']);
}
//减库存
if ($res1 && $res2 && $res4 && (empty($res3) || $res3) && (empty($res5) || $res5)) {
Db::commit();
return true;
} else {
return false;
}
} catch (Exception $e) {
Db::rollback();
return false;
}
}
/**
* @ApiTitle (订单付款)
* @ApiSummary (订单付款)
* @ApiMethod (POST)
* @ApiRoute (/api/order/orderPay)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name=order_id, type=string, required=true, description="订单id")
* @ApiReturn ({
})
*/
public function orderPay()
{
$param = $this->request->param();
$rule = [
'order_id' => 'require',
];
$msg = [
'order_id' => '缺少参数 order_id!',
];
$validate = new Validate($rule, $msg);
$result = $validate->check($param);
if (!$result) {
$this->error(__($validate->getError()));
}
$order = $this->orderModel->where(['id' => $param['order_id']])->find();
$amount = $order['pay_total'];
$payType = $order['pay_type'];
if ($payType == 2) {
//余额支付
if ($this->user['money'] >= $amount) {
$res = $this->orderModel->balancePay($param['order_id'], $this->auth->id, $amount);
if ($res) $this->success('支付成功');
else $this->error('支付失败');
} else {
$this->error('余额不足');
}
} elseif ($payType == '1') {
//微信支付
}
}
}
... ...
... ... @@ -45,16 +45,20 @@ class Car extends Model
$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')
->field('g.id,goods_price*number goods_price,g.vip_price*number vip_price,g.is_vip_price,g.ch_name,g.en_name,g.image,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')
->field('g.id,goods_price*number goods_price,c.number,integral*number integral,g.ch_name,g.en_name,g.image')
->select();
$list = array_merge($goodsList,$integralGoodsList);
foreach ($list as $k => $v){
if (!empty($v['is_vip_price'])) $list[$k]['type'] = 1;
else $list[$k]['type'] = 2;
}
return $list;
}
}
... ...
... ... @@ -2,6 +2,7 @@
namespace app\api\model;
use think\Db;
use think\Model;
... ... @@ -179,4 +180,44 @@ class Goods extends Model
->find();
return $stockNum;
}
/**
* 获取仓库id
* @param $goodsId
* @param $areaId
* @return mixed
*/
public function getDepot($goodsId,$areaId,$number){
$depot = $this->alias('g')
->join('fa_depot d','g.id=d.goods_id')
->where(['g.id' => $goodsId, 'd.area_id' => $areaId])
->field('d.id,d.stock_num')
->find();
$this->recursion($depot,'',$number,$goodsId);
if (!empty($depot) && $number == 0){
return $depot['id'];
}else{
$depotid = Db::name('depot')->where('goods_id',$goodsId)->order('weigh DESC')->value('id');
return $depotid;
}
}
public function recursion($depot,$ids,$number,$goodsId){
//判断仓库是否满足商品数量
if(!empty($depot) && $depot['stock_num'] < $number){
$number -= $depot['stock_num'];
$ids .= $depot['id'].',';
$newdepot = $this->alias('g')
->join('fa_depot d','g.id=d.goods_id')
->where(['goods_id'=>$goodsId,'id'=>['not in',rtrim($ids,',')]])
->field('d.id,d.stock_num')
->order('weigh DESC')
->find();
$this->recursion($newdepot,$ids,$number,$goodsId);
}elseif (!empty($depot) && $depot['stock_num'] > $number){
}
}
}
... ...
... ... @@ -23,7 +23,7 @@ class IntegralGoods extends Model
return $data;
}
public function selectPageData($where,$page,$limit)
public function selectPageData($where, $page, $limit)
{
$where['g.status'] = 1;
... ... @@ -37,7 +37,7 @@ class IntegralGoods extends Model
->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)
->page($page, $limit)
->select();
return ['total' => $total, 'list' => $list];
}
... ... @@ -68,12 +68,35 @@ class IntegralGoods extends Model
* @param $where
* @return mixed
*/
public function getAreaStockNum($where){
public function getAreaStockNum($where)
{
$stockNum = $this->alias('g')
->join('fa_integral_depot d','g.id=d.goods_id')
->join('fa_integral_depot d', 'g.id=d.goods_id')
->where($where)
->field('d.stock_num,g.ch_name')
->find();
return $stockNum;
}
/**
* 获取仓库id
* @param $goodsId
* @param $areaId
* @return mixed
*/
public function getDepot($goodsId, $areaId)
{
$depotid = $this->alias('g')
->join('fa_integral_depot d', 'g.id=d.goods_id')
->where(['g.id' => $goodsId, 'd.area_id' => $areaId])
->field('d.stock_num,g.ch_name')
->value('d.id');
if ($depotid) {
return $depotid;
} else {
$depotid = Db::name('depot')->where('goods_id', $goodsId)->order('weigh DESC')->value('id');
return $depotid;
}
}
}
... ...
... ... @@ -2,10 +2,82 @@
namespace app\api\model;
use think\Db;
use think\Model;
class Order extends Model
{
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
/**
* 余额支付
* @param $order_id 订单id
* @param $user_id 用户id
* @param $money 支付金额
* @return boolean
*/
public function balancePay($order_id, $user_id, $money)
{
Db::startTrans();
try {
$oldmoney = Db::name('user')->where('id', $user_id)->value('money');
$oldscore = Db::name('user')->where('id', $user_id)->value('score');
//减去用户余额
$res1 = Db::name('user')->where('id', $user_id)->setDec('money', $money);
//将订单状态修改为已支付
$res2 = $this->where('id', $order_id)->update(['status' => 2,'paytime'=>time()]);
//将订单商品状态修改为待发货
$res3 = Db::name('order_info')->where('order_id',$order_id)->update(['status' => 2,'paytime'=>time()]);
//积分变动表记录
$scoredata = [
'user_id' => $user_id,
'type' => 1, //购物返积分
'score' => intval($money),
'before' => $oldscore,
'after' => $oldscore+intval($money),
'createtime' => time(),
];
$res4 = Db::name('user_score_log')->insert($scoredata);
//余额支付变动记录
$data = [
'user_id' => $user_id,
'type' => 3, //购物消费
'money' => $money,
'before' => $oldmoney,
'after' => $oldmoney-$money,
'createtime' => time(),
];
$res5 = Db::name('user_money_log')->insert($data);
//
$user_pid = Db::name('user')->where('id',$user_id)->value('pid');
//判断是否有上级进行返利
if ($user_pid){
$parentInfo = Db::name('user')->where('id',$user_pid)->find();
$rebatedata = [
'user_id' => $user_pid,
'type' => 4, //佣金收入(返利)
'money' => $money,
'before' => $parentInfo['money'],
'after' => $parentInfo['money']+$money,
'createtime' => time(),
];
$res5 = Db::name('user_money_log')->insert($data);
}
if ($res1 && $res2 && $res3 && $res4 && $res5) {
Db::commit();
return true;
}else{
return false;
}
} catch (Exception $e) {
Db::rollback();
return false;
}
}
}
... ...
<?php
namespace app\api\model;
use think\Model;
class OrderAddress extends Model
{
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
public function insertData($data){
$areaModel = new Area();
$province = $areaModel->where('id',$data['province_id'])->field('name,pinyin')->find();
$city = $areaModel->where('id',$data['city_id'])->field('name,pinyin')->find();
$county = $areaModel->where('id',$data['county_id'])->field('name,pinyin')->find();
unset($data['province_id']);
unset($data['city_id']);
unset($data['county_id']);
$data['ch_province_name'] = $province['name'];
$data['ch_city_name'] = $city['name'];
$data['ch_county_name'] = $county['name'];
$data['en_province_name'] = $province['pinyin'];
$data['en_city_name'] = $city['pinyin'];
$data['en_county_name'] = $county['pinyin'];
$res = $this->insertGetId($data);
if ($res) return $res;
else return false;
}
}
... ...
<?php
namespace app\api\model;
use think\Model;
class OrderAddressInvoice extends Model
{
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
public function insertData($data){
$areaModel = new Area();
$province = $areaModel->where('id',$data['province_id'])->field('name,pinyin')->find();
$city = $areaModel->where('id',$data['city_id'])->field('name,pinyin')->find();
$county = $areaModel->where('id',$data['county_id'])->field('name,pinyin')->find();
unset($data['province_id']);
unset($data['city_id']);
unset($data['county_id']);
$data['ch_province_name'] = $province['name'];
$data['ch_city_name'] = $city['name'];
$data['ch_county_name'] = $county['name'];
$data['en_province_name'] = $province['pinyin'];
$data['en_city_name'] = $city['pinyin'];
$data['en_county_name'] = $county['pinyin'];
$res = $this->insertGetId($data);
if ($res) return $res;
else return false;
}
}
... ...
<?php
namespace app\api\model;
use think\Model;
class OrderInfo extends Model
{
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
}
... ...
... ... @@ -4,6 +4,7 @@ namespace app\api\model;
use app\common\model\MoneyLog;
use app\common\model\ScoreLog;
use think\Db;
use think\Model;
class UserScoreLog extends Model
... ... @@ -12,7 +13,7 @@ class UserScoreLog extends Model
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $updateTime = false;
protected $append = [
'type_text'
... ... @@ -50,4 +51,30 @@ class UserScoreLog extends Model
->select();
return ['total' => $total, 'list' => $list];
}
public function setDecScore($userId,$score){
Db::startTrans();
$oldscore = Db::name('user')->where('id', $userId)->value('score');
try {
$res1 = Db::name('user')->where('id',$userId)->setDec('score',$score);
$data = [
'user_id' => $userId,
'type' => 2,
'score' => $score,
'before' => $oldscore,
'after' => $oldscore-$score,
'createtime' => time(),
];
$res2 = $this->save($data);
if ($res1 && $res2 ) {
Db::commit();
return true;
}else{
return false;
}
} catch (Exception $e) {
Db::rollback();
return false;
}
}
}
... ...
... ... @@ -4322,7 +4322,18 @@
<div class="row">
<div class="col-md-12">
<pre id="sample_response34">{
"code": 1,
"msg": "success",
"time": "1587691008",
"data": {
"price": 263.7, 总价
"discount_price": 12.3, 折扣价
"original_price": 246, 原价
"ticketcode_discount_price": 5, 优惠码优惠价
"ticket_discount_price": 10, 优惠券优惠价
"integral": 0, 积分
"postage": "30.00" 运费
}
},
}</pre>
</div>
... ... @@ -4399,6 +4410,12 @@
<td>购物车id 例 1,2,3</td>
</tr>
<tr>
<td>pay_type</td>
<td>string</td>
<td></td>
<td>支付类型:1=微信支付,2=余额支付</td>
</tr>
<tr>
<td>ticket_user_id</td>
<td>string</td>
<td></td>
... ... @@ -4411,31 +4428,79 @@
<td>优惠码</td>
</tr>
<tr>
<td>province_id</td>
<td>string</td>
<td></td>
<td>商品收货地址省id</td>
</tr>
<tr>
<td>city_id</td>
<td>string</td>
<td></td>
<td>商品收货地址市id</td>
</tr>
<tr>
<td>county_id</td>
<td>string</td>
<td></td>
<td>商品收货地址县id</td>
</tr>
<tr>
<td>address</td>
<td>string</td>
<td></td>
<td>商品收货地址</td>
</tr>
<tr>
<td>name</td>
<td>string</td>
<td></td>
<td>商品收货人</td>
</tr>
<tr>
<td>mobile</td>
<td>string</td>
<td></td>
<td>商品收货电话</td>
</tr>
<tr>
<td>present_id</td>
<td>string</td>
<td></td>
<td>赠品id</td>
</tr>
<tr>
<td>delivery</td>
<td>postage_type</td>
<td>string</td>
<td></td>
<td>配送类型:1=普通配送,2=闪送</td>
</tr>
<tr>
<td>postage_date</td>
<td>string</td>
<td></td>
<td>配送日期</td>
</tr>
<tr>
<td>postage_time</td>
<td>string</td>
<td></td>
<td>配送时间</td>
</tr>
<tr>
<td>invoice_status</td>
<td>string</td>
<td></td>
<td>发票状态:1=个人或事业单位,2=企业,3=不需要开发票</td>
</tr>
<tr>
<td>invoice_type</td>
<td>string</td>
<td></td>
<td>发票类型:1=个人或事业单位,2=企业</td>
<td>发票类型:1=纸质发票,2=电子发票</td>
</tr>
<tr>
<td>email</td>
<td>invoice_email</td>
<td>string</td>
<td></td>
<td>电子发票邮箱</td>
... ... @@ -4453,12 +4518,42 @@
<td>发票税号</td>
</tr>
<tr>
<td>invoice_province_id</td>
<td>string</td>
<td></td>
<td>发票收货地址省id</td>
</tr>
<tr>
<td>invoice_city_id</td>
<td>string</td>
<td></td>
<td>发票收货地址市id</td>
</tr>
<tr>
<td>invoice_county_id</td>
<td>string</td>
<td></td>
<td>发票收货地址县id</td>
</tr>
<tr>
<td>invoice_address</td>
<td>string</td>
<td></td>
<td>发票收货地址</td>
</tr>
<tr>
<td>invoice_name</td>
<td>string</td>
<td></td>
<td>发票收货人</td>
</tr>
<tr>
<td>invoice_mobile</td>
<td>string</td>
<td></td>
<td>发票收货电话</td>
</tr>
<tr>
<td>order_note</td>
<td>string</td>
<td></td>
... ... @@ -4498,6 +4593,10 @@
<input type="string" class="form-control input-sm" id="car_id" required placeholder="购物车id 例 1,2,3" name="car_id">
</div>
<div class="form-group">
<label class="control-label" for="pay_type">pay_type</label>
<input type="string" class="form-control input-sm" id="pay_type" placeholder="支付类型:1=微信支付,2=余额支付" name="pay_type">
</div>
<div class="form-group">
<label class="control-label" for="ticket_user_id">ticket_user_id</label>
<input type="string" class="form-control input-sm" id="ticket_user_id" placeholder="用户优惠券id" name="ticket_user_id">
</div>
... ... @@ -4506,24 +4605,56 @@
<input type="string" class="form-control input-sm" id="ticket_code" placeholder="优惠码" name="ticket_code">
</div>
<div class="form-group">
<label class="control-label" for="province_id">province_id</label>
<input type="string" class="form-control input-sm" id="province_id" required placeholder="商品收货地址省id" name="province_id">
</div>
<div class="form-group">
<label class="control-label" for="city_id">city_id</label>
<input type="string" class="form-control input-sm" id="city_id" required placeholder="商品收货地址市id" name="city_id">
</div>
<div class="form-group">
<label class="control-label" for="county_id">county_id</label>
<input type="string" class="form-control input-sm" id="county_id" required placeholder="商品收货地址县id" name="county_id">
</div>
<div class="form-group">
<label class="control-label" for="address">address</label>
<input type="string" class="form-control input-sm" id="address" required placeholder="商品收货地址" name="address">
</div>
<div class="form-group">
<label class="control-label" for="name">name</label>
<input type="string" class="form-control input-sm" id="name" required placeholder="商品收货人" name="name">
</div>
<div class="form-group">
<label class="control-label" for="mobile">mobile</label>
<input type="string" class="form-control input-sm" id="mobile" required placeholder="商品收货电话" name="mobile">
</div>
<div class="form-group">
<label class="control-label" for="present_id">present_id</label>
<input type="string" class="form-control input-sm" id="present_id" placeholder="赠品id" name="present_id">
</div>
<div class="form-group">
<label class="control-label" for="delivery">delivery</label>
<input type="string" class="form-control input-sm" id="delivery" placeholder="配送时间" name="delivery">
<label class="control-label" for="postage_type">postage_type</label>
<input type="string" class="form-control input-sm" id="postage_type" required placeholder="配送类型:1=普通配送,2=闪送" name="postage_type">
</div>
<div class="form-group">
<label class="control-label" for="postage_date">postage_date</label>
<input type="string" class="form-control input-sm" id="postage_date" placeholder="配送日期" name="postage_date">
</div>
<div class="form-group">
<label class="control-label" for="postage_time">postage_time</label>
<input type="string" class="form-control input-sm" id="postage_time" placeholder="配送时间" name="postage_time">
</div>
<div class="form-group">
<label class="control-label" for="invoice_status">invoice_status</label>
<input type="string" class="form-control input-sm" id="invoice_status" required placeholder="发票状态:1=个人或事业单位,2=企业,3=不需要开发票" name="invoice_status">
</div>
<div class="form-group">
<label class="control-label" for="invoice_type">invoice_type</label>
<input type="string" class="form-control input-sm" id="invoice_type" placeholder="发票类型:1=个人或事业单位,2=企业" name="invoice_type">
<input type="string" class="form-control input-sm" id="invoice_type" placeholder="发票类型:1=纸质发票,2=电子发票" name="invoice_type">
</div>
<div class="form-group">
<label class="control-label" for="email">email</label>
<input type="string" class="form-control input-sm" id="email" placeholder="电子发票邮箱" name="email">
<label class="control-label" for="invoice_email">invoice_email</label>
<input type="string" class="form-control input-sm" id="invoice_email" placeholder="电子发票邮箱" name="invoice_email">
</div>
<div class="form-group">
<label class="control-label" for="taitou">taitou</label>
... ... @@ -4534,10 +4665,30 @@
<input type="string" class="form-control input-sm" id="duty_num" placeholder="发票税号" name="duty_num">
</div>
<div class="form-group">
<label class="control-label" for="invoice_province_id">invoice_province_id</label>
<input type="string" class="form-control input-sm" id="invoice_province_id" required placeholder="发票收货地址省id" name="invoice_province_id">
</div>
<div class="form-group">
<label class="control-label" for="invoice_city_id">invoice_city_id</label>
<input type="string" class="form-control input-sm" id="invoice_city_id" required placeholder="发票收货地址市id" name="invoice_city_id">
</div>
<div class="form-group">
<label class="control-label" for="invoice_county_id">invoice_county_id</label>
<input type="string" class="form-control input-sm" id="invoice_county_id" required placeholder="发票收货地址县id" name="invoice_county_id">
</div>
<div class="form-group">
<label class="control-label" for="invoice_address">invoice_address</label>
<input type="string" class="form-control input-sm" id="invoice_address" placeholder="发票收货地址" name="invoice_address">
</div>
<div class="form-group">
<label class="control-label" for="invoice_name">invoice_name</label>
<input type="string" class="form-control input-sm" id="invoice_name" required placeholder="发票收货人" name="invoice_name">
</div>
<div class="form-group">
<label class="control-label" for="invoice_mobile">invoice_mobile</label>
<input type="string" class="form-control input-sm" id="invoice_mobile" required placeholder="发票收货电话" name="invoice_mobile">
</div>
<div class="form-group">
<label class="control-label" for="order_note">order_note</label>
<input type="string" class="form-control input-sm" id="order_note" placeholder="订单备注" name="order_note">
</div>
... ... @@ -8969,7 +9120,7 @@
<div class="row mt0 footer">
<div class="col-md-6" align="left">
Generated on 2020-04-23 22:22:29 </div>
Generated on 2020-04-24 15:14:00 </div>
<div class="col-md-6" align="right">
<a href="./" target="_blank">E-MP market</a>
</div>
... ...