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

1

@@ -101,7 +101,7 @@ class Cart extends Api @@ -101,7 +101,7 @@ class Cart extends Api
101 * @ApiMethod (GET) 101 * @ApiMethod (GET)
102 * @ApiHeaders (name=token, type=string, required=true, description="请求的Token") 102 * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
103 * @ApiParams (name="cart_id", type="integer", required=true, description="购物车ID") 103 * @ApiParams (name="cart_id", type="integer", required=true, description="购物车ID")
104 - * @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':'规格值'}") 104 + * @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':'规格值'}")
105 * @ApiReturnParams (name="code", type="integer", required=true, sample="0") 105 * @ApiReturnParams (name="code", type="integer", required=true, sample="0")
106 * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功") 106 * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
107 * @ApiReturnParams (name="data", type="object", description="扩展数据返回") 107 * @ApiReturnParams (name="data", type="object", description="扩展数据返回")
@@ -127,6 +127,38 @@ class Cart extends Api @@ -127,6 +127,38 @@ class Cart extends Api
127 } 127 }
128 128
129 /** 129 /**
  130 + * 购物车-修改规格
  131 + * @ApiMethod (GET)
  132 + * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  133 + * @ApiParams (name="cart_id", type="integer", required=true, description="购物车ID")
  134 + * @ApiParams (name="spec_sku_id", type="string", required=true, sample="1_5", description="商品规格")
  135 + * @ApiReturnParams (name="code", type="integer", required=true, sample="0")
  136 + * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
  137 + * @ApiReturnParams (name="data", type="object", description="扩展数据返回")
  138 + * @ApiReturn ({
  139 + 'code':'1',
  140 + 'msg':'返回成功'
  141 + })
  142 + */
  143 + public function editGoodsSpec(){
  144 + $cart_id = $this->request->request('cart_id',0);
  145 + $spec_sku_id = $this->request->request('spec_sku_id','');
  146 + $cart = $this->model->get($cart_id);
  147 + empty($cart) && $this->error(__('购物车信息不存在'));
  148 + empty($spec_sku_id) && $this->error(__('请选择规格'));
  149 + // 检查库存
  150 + $goods = Goods::get($cart['goods_id'],['spec_rel.spec']);
  151 + $goods_sku = $goods->getGoodsSku($spec_sku_id);
  152 + if($goods['ismake'] == '0' && $goods_sku['stock_num'] < $cart['goods_num']){
  153 + $this->error(__('商品库存不足'.$cart['goods_num'].'件'));
  154 + }
  155 + $cart->spec_sku_id = $spec_sku_id;
  156 + $cart->goods_price = $goods_sku['goods_price'];
  157 + $cart->save();
  158 + $this->success(__('成功'));
  159 + }
  160 +
  161 + /**
130 * 购物车-修改商品数量 162 * 购物车-修改商品数量
131 * @ApiMethod (GET) 163 * @ApiMethod (GET)
132 * @ApiHeaders (name=token, type=string, required=true, description="请求的Token") 164 * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
@@ -146,6 +178,11 @@ class Cart extends Api @@ -146,6 +178,11 @@ class Cart extends Api
146 $cart = $this->model->get($cart_id); 178 $cart = $this->model->get($cart_id);
147 empty($cart) && $this->error(__('购物车信息不存在')); 179 empty($cart) && $this->error(__('购物车信息不存在'));
148 $goods_num < 1 && $this->error(__('商品数量不能小于1')); 180 $goods_num < 1 && $this->error(__('商品数量不能小于1'));
  181 + $goods = Goods::get($cart['goods_id'],['spec_rel.spec']);
  182 + $goods_sku = $goods->getGoodsSku($cart['spec_sku_id']);
  183 + if($goods['ismake'] == '0' && $goods_sku['stock_num'] < $goods_num){
  184 + $this->error(__('商品库存不足'.$goods_num.'件'));
  185 + }
149 $cart->goods_num = $goods_num; 186 $cart->goods_num = $goods_num;
150 $cart->save(); 187 $cart->save();
151 $this->success(__('成功')); 188 $this->success(__('成功'));
@@ -225,8 +225,6 @@ class Index extends Api @@ -225,8 +225,6 @@ class Index extends Api
225 } 225 }
226 } 226 }
227 $goods['appraise'] = \app\common\model\GoodsAppraise::getList(['goods_id'=>$goods_id],1,1); 227 $goods['appraise'] = \app\common\model\GoodsAppraise::getList(['goods_id'=>$goods_id],1,1);
228 - $goods['spec_data'] = $goods['spec_type'] == '2' ? $goods->getManySpecData($goods['spec_rel'], $goods['spec']) : null;  
229 - $goods->hidden(['spec','spec_rel'])->toArray();  
230 // 返回结果 228 // 返回结果
231 $this->success(__('成功'),compact('goods')); 229 $this->success(__('成功'),compact('goods'));
232 } 230 }
@@ -278,4 +276,25 @@ class Index extends Api @@ -278,4 +276,25 @@ class Index extends Api
278 $list = \app\common\model\Style::styleList($goods_style['style_template_id']); 276 $list = \app\common\model\Style::styleList($goods_style['style_template_id']);
279 $this->success(__('成功'),compact('list')); 277 $this->success(__('成功'),compact('list'));
280 } 278 }
  279 +
  280 + /**
  281 + * 规格
  282 + * @ApiMethod (GET)
  283 + * @ApiParams (name="goods_id", type="integer", required=true, description="商品ID")
  284 + * @ApiReturnParams (name="code", type="integer", required=true, sample="0")
  285 + * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
  286 + * @ApiReturnParams (name="data", type="object", description="扩展数据返回")
  287 + * @ApiReturn ({
  288 + 'code':'1',
  289 + 'msg':'返回成功'
  290 + })
  291 + */
  292 + public function specData()
  293 + {
  294 + $goods_id = $this->request->request('goods_id');
  295 + $goods = Goods::get($goods_id);
  296 + empty($goods) && $this->error(__('商品信息不存在'));
  297 + $spec_data = $goods['spec_type'] == '2' ? $goods->getManySpecData($goods['spec_rel'], $goods['spec']) : null;
  298 + $this->success(__('成功'),compact('spec_data'));
  299 + }
281 } 300 }
@@ -184,8 +184,7 @@ class Order extends Api @@ -184,8 +184,7 @@ class Order extends Api
184 * 我的订单-查询物流 184 * 我的订单-查询物流
185 * @ApiMethod (GET) 185 * @ApiMethod (GET)
186 * @ApiHeaders (name=token, type=string, required=true, description="请求的Token") 186 * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
187 - * @ApiParams (name="express_no", type="integer", required=true, description="物流单号")  
188 - * @ApiParams (name="express_code", type="integer", required=true, description="物流公司编号") 187 + * @ApiParams (name="order_id", type="integer", required=true, description="订单ID")
189 * @ApiReturnParams (name="code", type="integer", required=true, sample="0") 188 * @ApiReturnParams (name="code", type="integer", required=true, sample="0")
190 * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功") 189 * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
191 * @ApiReturnParams (name="data", type="object", description="扩展数据返回") 190 * @ApiReturnParams (name="data", type="object", description="扩展数据返回")
@@ -194,14 +193,15 @@ class Order extends Api @@ -194,14 +193,15 @@ class Order extends Api
194 'msg':'返回成功' 193 'msg':'返回成功'
195 }) 194 })
196 */ 195 */
197 - public function orderTraces($express_no,$express_code) 196 + public function orderTraces($order_id)
198 { 197 {
199 - $kdniao = new \addons\kdniao\library\Kdniao();  
200 - $wuliu = $kdniao->getOrderTracesByJson($express_code, $express_no);  
201 - $wuliu == -1 && $this->error('未设置接口配置!请在插件管理中配置!');  
202 - $wuliu = json_decode($wuliu, true);  
203 - //物流信息倒序  
204 - $this->success('成功',isset($wuliu['Traces']) && count($wuliu['Traces']) ? array_reverse($wuliu['Traces']) : [['AcceptStation' => '暂无物流信息', 'AcceptTime' => date('Y-m-d H:i:s', time())]]); 198 + if(!$order = $this->model->getUserOrderDetail($order_id, $this->user['id'])){
  199 + $this->error($this->model->getError());
  200 + }
  201 + if ($data = $order->orderTraces()) {
  202 + $this->success(__('查询物流成功'),$data);
  203 + }
  204 + $this->error($order->getError());
205 } 205 }
206 206
207 /** 207 /**
@@ -120,6 +120,7 @@ class Cart extends Model @@ -120,6 +120,7 @@ class Cart extends Model
120 'goods_id' => $data['goods_id'], 120 'goods_id' => $data['goods_id'],
121 'spec_sku_id' => $data['spec_sku_id'], 121 'spec_sku_id' => $data['spec_sku_id'],
122 'goods_style' => $data['goods_style'], 122 'goods_style' => $data['goods_style'],
  123 + 'user_size_id' => $data['user_size_id'],
123 'isbuynow' => '0' 124 'isbuynow' => '0'
124 ]); 125 ]);
125 if(!empty($cart)){ 126 if(!empty($cart)){
@@ -258,6 +258,25 @@ class Order extends Model @@ -258,6 +258,25 @@ class Order extends Model
258 } 258 }
259 259
260 /** 260 /**
  261 + * 查询物流
  262 + */
  263 + public function orderTraces()
  264 + {
  265 + if ($this['delivery_status'] == '0') {
  266 + $this->setError('该订单不合法');
  267 + return false;
  268 + }
  269 + $kdniao = new \addons\kdniao\library\Kdniao();
  270 + $wuliu = $kdniao->getOrderTracesByJson($this['express_code'], $this['express_no']);
  271 + if($wuliu == -1){
  272 + $this->setError('未设置接口配置!请在插件管理中配置!');
  273 + return false;
  274 + }
  275 + $wuliu = json_decode($wuliu, true);
  276 + return isset($wuliu['Traces']) && count($wuliu['Traces']) ? array_reverse($wuliu['Traces']) : [['AcceptStation' => '暂无物流信息', 'AcceptTime' => date('Y-m-d H:i:s', time())]];
  277 + }
  278 +
  279 + /**
261 * 申请退款 280 * 申请退款
262 */ 281 */
263 public function toRefund($post) 282 public function toRefund($post)
@@ -44,7 +44,6 @@ class UserSize extends Model @@ -44,7 +44,6 @@ class UserSize extends Model
44 $this->allowField(true)->save(array_merge([ 44 $this->allowField(true)->save(array_merge([
45 'user_id' => $user['id'], 45 'user_id' => $user['id'],
46 ], $data)); 46 ], $data));
47 - halt($this);  
48 // 没有默认收货地址,就把该收货地址设为默认 47 // 没有默认收货地址,就把该收货地址设为默认
49 !$this->get(['user_id'=>$user['id'],'isdefault'=>'1']) && $this->update(['id'=>$this['id'],'isdefault'=>'1']); 48 !$this->get(['user_id'=>$user['id'],'isdefault'=>'1']) && $this->update(['id'=>$this['id'],'isdefault'=>'1']);
50 return true; 49 return true;
此 diff 太大无法显示。