作者 何书鹏
1 个管道 的构建 通过 耗费 1 秒

1

... ... @@ -101,7 +101,7 @@ class Cart extends Api
* @ApiMethod (GET)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="cart_id", type="integer", required=true, description="购物车ID")
* @ApiParams (name="goods_style", type="object", required=true, sample="{'1':'11','5':'15','7':'2','14':'25','15':'\/uploads\/20200711\/3689359dcdf1146d234930cae4958110.jpg','13':'21','12':'18'}", description="商品格 {'风格ID':'规格值'}")
* @ApiParams (name="goods_style", type="object", required=true, sample="{'1':'11','5':'15','7':'2','14':'25','15':'\/uploads\/20200711\/3689359dcdf1146d234930cae4958110.jpg','13':'21','12':'18'}", description="商品格 {'风格ID':'规格值'}")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturnParams (name="data", type="object", description="扩展数据返回")
... ... @@ -127,6 +127,38 @@ class Cart extends Api
}
/**
* 购物车-修改规格
* @ApiMethod (GET)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="cart_id", type="integer", required=true, description="购物车ID")
* @ApiParams (name="spec_sku_id", type="string", required=true, sample="1_5", description="商品规格")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturnParams (name="data", type="object", description="扩展数据返回")
* @ApiReturn ({
'code':'1',
'msg':'返回成功'
})
*/
public function editGoodsSpec(){
$cart_id = $this->request->request('cart_id',0);
$spec_sku_id = $this->request->request('spec_sku_id','');
$cart = $this->model->get($cart_id);
empty($cart) && $this->error(__('购物车信息不存在'));
empty($spec_sku_id) && $this->error(__('请选择规格'));
// 检查库存
$goods = Goods::get($cart['goods_id'],['spec_rel.spec']);
$goods_sku = $goods->getGoodsSku($spec_sku_id);
if($goods['ismake'] == '0' && $goods_sku['stock_num'] < $cart['goods_num']){
$this->error(__('商品库存不足'.$cart['goods_num'].'件'));
}
$cart->spec_sku_id = $spec_sku_id;
$cart->goods_price = $goods_sku['goods_price'];
$cart->save();
$this->success(__('成功'));
}
/**
* 购物车-修改商品数量
* @ApiMethod (GET)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
... ... @@ -146,6 +178,11 @@ class Cart extends Api
$cart = $this->model->get($cart_id);
empty($cart) && $this->error(__('购物车信息不存在'));
$goods_num < 1 && $this->error(__('商品数量不能小于1'));
$goods = Goods::get($cart['goods_id'],['spec_rel.spec']);
$goods_sku = $goods->getGoodsSku($cart['spec_sku_id']);
if($goods['ismake'] == '0' && $goods_sku['stock_num'] < $goods_num){
$this->error(__('商品库存不足'.$goods_num.'件'));
}
$cart->goods_num = $goods_num;
$cart->save();
$this->success(__('成功'));
... ...
... ... @@ -225,8 +225,6 @@ class Index extends Api
}
}
$goods['appraise'] = \app\common\model\GoodsAppraise::getList(['goods_id'=>$goods_id],1,1);
$goods['spec_data'] = $goods['spec_type'] == '2' ? $goods->getManySpecData($goods['spec_rel'], $goods['spec']) : null;
$goods->hidden(['spec','spec_rel'])->toArray();
// 返回结果
$this->success(__('成功'),compact('goods'));
}
... ... @@ -278,4 +276,25 @@ class Index extends Api
$list = \app\common\model\Style::styleList($goods_style['style_template_id']);
$this->success(__('成功'),compact('list'));
}
/**
* 规格
* @ApiMethod (GET)
* @ApiParams (name="goods_id", type="integer", required=true, description="商品ID")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturnParams (name="data", type="object", description="扩展数据返回")
* @ApiReturn ({
'code':'1',
'msg':'返回成功'
})
*/
public function specData()
{
$goods_id = $this->request->request('goods_id');
$goods = Goods::get($goods_id);
empty($goods) && $this->error(__('商品信息不存在'));
$spec_data = $goods['spec_type'] == '2' ? $goods->getManySpecData($goods['spec_rel'], $goods['spec']) : null;
$this->success(__('成功'),compact('spec_data'));
}
}
... ...
... ... @@ -184,8 +184,7 @@ class Order extends Api
* 我的订单-查询物流
* @ApiMethod (GET)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="express_no", type="integer", required=true, description="物流单号")
* @ApiParams (name="express_code", type="integer", required=true, description="物流公司编号")
* @ApiParams (name="order_id", type="integer", required=true, description="订单ID")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturnParams (name="data", type="object", description="扩展数据返回")
... ... @@ -194,14 +193,15 @@ class Order extends Api
'msg':'返回成功'
})
*/
public function orderTraces($express_no,$express_code)
public function orderTraces($order_id)
{
$kdniao = new \addons\kdniao\library\Kdniao();
$wuliu = $kdniao->getOrderTracesByJson($express_code, $express_no);
$wuliu == -1 && $this->error('未设置接口配置!请在插件管理中配置!');
$wuliu = json_decode($wuliu, true);
//物流信息倒序
$this->success('成功',isset($wuliu['Traces']) && count($wuliu['Traces']) ? array_reverse($wuliu['Traces']) : [['AcceptStation' => '暂无物流信息', 'AcceptTime' => date('Y-m-d H:i:s', time())]]);
if(!$order = $this->model->getUserOrderDetail($order_id, $this->user['id'])){
$this->error($this->model->getError());
}
if ($data = $order->orderTraces()) {
$this->success(__('查询物流成功'),$data);
}
$this->error($order->getError());
}
/**
... ...
... ... @@ -120,6 +120,7 @@ class Cart extends Model
'goods_id' => $data['goods_id'],
'spec_sku_id' => $data['spec_sku_id'],
'goods_style' => $data['goods_style'],
'user_size_id' => $data['user_size_id'],
'isbuynow' => '0'
]);
if(!empty($cart)){
... ...
... ... @@ -258,6 +258,25 @@ class Order extends Model
}
/**
* 查询物流
*/
public function orderTraces()
{
if ($this['delivery_status'] == '0') {
$this->setError('该订单不合法');
return false;
}
$kdniao = new \addons\kdniao\library\Kdniao();
$wuliu = $kdniao->getOrderTracesByJson($this['express_code'], $this['express_no']);
if($wuliu == -1){
$this->setError('未设置接口配置!请在插件管理中配置!');
return false;
}
$wuliu = json_decode($wuliu, true);
return isset($wuliu['Traces']) && count($wuliu['Traces']) ? array_reverse($wuliu['Traces']) : [['AcceptStation' => '暂无物流信息', 'AcceptTime' => date('Y-m-d H:i:s', time())]];
}
/**
* 申请退款
*/
public function toRefund($post)
... ...
... ... @@ -44,7 +44,6 @@ class UserSize extends Model
$this->allowField(true)->save(array_merge([
'user_id' => $user['id'],
], $data));
halt($this);
// 没有默认收货地址,就把该收货地址设为默认
!$this->get(['user_id'=>$user['id'],'isdefault'=>'1']) && $this->update(['id'=>$this['id'],'isdefault'=>'1']);
return true;
... ...
此 diff 太大无法显示。