审查视图

application/api/controller/Cars.php 27.0 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
<?php

namespace app\api\controller;

use app\admin\model\Car;
use app\common\controller\Api;
use think\Validate;
use think\Db;
/**
 * 购物车接口
 */
class Cars extends Api
{
    protected $noNeedLogin = [];
    protected $noNeedRight = ['*'];
    protected $uid = '';
    public function _initialize()
    {
        parent::_initialize();
        $this->uid = $this->auth->getUserId();
    }

    /**
     * @ApiTitle    (加入购物车)
     * @ApiSummary  (加入购物车)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/cars/addCar)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     *
     * @ApiParams   (name="goods_id", type="inter", required=true, description="商品id")
     * @ApiParams   (name="style", type="string", required=true, description="商品款式")
     * @ApiParams   (name="price", type="inter", required=true, description="商品价格(新人价格或销售价)")
     * @ApiParams   (name="goods_number", type="inter", required=true, description="商品数量")
     *
     * @ApiReturn({
        "code": 1,
        "msg": "成功",
        "time": "1575103466",
        "data": null
    })
     */
    public function addCar(){
        if($this->request->isPost()){
            $data = $this->request->post();
            $rule = config('verify.add_car');
            $validate = new Validate($rule['rule'],$rule['msg']);
            if (!$validate->check($data)) {
                $this->error($validate->getError());
            }

            //检测库存
jinglong authored
52 53
            $stock_res = Common::findSoftWhereData('goods',['id'=>$data['goods_id']],'id,stock,style g_style');
            if($stock_res){
jinglong authored
54 55 56
                //检测库存
                $check_stock = Common::checkStock($data['style'],$data['goods_number'],$stock_res['g_style'],$stock_res['stock']);
                if(!$check_stock){
57
                    $this->error('库存不足');
58
                }
jinglong authored
59
60 61 62 63 64
            }
            //查询有无记录
            $where = [
                'uid'=>$this->uid,
                'g_id'=>$data['goods_id'],
jinglong authored
65
                'style'=>trim($data['style']),
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
            ];
            $res = Common::findWhereData('car',$where,'id,g_id');
            $carModel = new Car();
            if($res){
                $carModel->where($where)->setInc('goods_number',$data['goods_number']);
            }else{
                $data['g_id'] = $data['goods_id'];
                $data['uid'] = $this->uid;
                unset($data['goods_id']);
                $carModel->create($data);
            }
            $this->success('成功');
        }else{
            $this->error('请求方式错误');
        }
    }

    /**
     * @ApiTitle    (购物车列表)
     * @ApiSummary  (购物车列表)
     * @ApiMethod   (GET)
     * @ApiRoute    (/api/cars/carList)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     *
     * @ApiReturn({
        "code": 1,
        "msg": "成功",
        "time": "1575102913",
        "data": {
            "data": [
                {
                    "id": 1,//购物车id
                    "image": "http://jinglong.springchunjia.cn/uploads/20191127/287ca016a4d41a239ec77c91d982309d.png",//商品图片
                    "price": 100,//商品价格
jinglong authored
100
                    "style": "",//商品款式
101 102 103 104
                    "goods_id": 1,//商品id
                    "goods_number": 2,//商品数量
                    "name": "MONENT 动感系列动感系列动感系列",//商品名称
                    "introduce": "轻波款,为客厅缀上霞光淡雾"//商品简介
105
                    "stock": "12"//商品库存
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
                },
                {
                    "id": 2,
                    "price": 100,
                    "goods_id": 2,
                    "goods_number": 1,
                    "name": "MONENT 动感系列动感系列",
                    "introduce": "轻波款,为客厅缀上霞光淡雾"
                }
            ],
            "total_price": 300
        }
    })
     */
    public function carList(){
        if($this->request->isGet()){
            $res = Db::name('car')
                ->alias('c')
jinglong authored
124
                ->join('goods g','c.g_id = g.id')
125
                ->where(['c.uid'=>$this->uid])
126
                ->field('c.id,c.g_id goods_id,c.price,c.goods_number,c.style,g.name,g.image,g.style g_style,g.stock,g.introduce')
127 128 129 130 131 132
                ->useSoftDelete('g.deletetime')
                ->select();
            $total_price = 0;
            foreach ($res as &$value){
                $value['image'] = $this->auth->absolutionUrlOne($value['image']);
                $total_price += $value['price'] * $value['goods_number'];
jinglong authored
133 134 135 136

                //检测库存
                $check_stock = Common::checkStock($value['style'],$value['goods_number'],$value['g_style'],$value['stock']);
                if(!$check_stock){
137 138 139
                    $s_index = array_search($value['style'],Common::salePrice($value['g_style']));
                    $stock = Common::salePrice($value['stock'])[$s_index];
                    $value['goods_number'] = $stock;
jinglong authored
140
                }
jinglong authored
141
jinglong authored
142 143 144
                $s_index = array_search($value['style'],Common::salePrice($value['g_style']));
                $stock = Common::salePrice($value['stock'])[$s_index];
                $value['stock'] = $stock;
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
            }
//            $total_price = array_sum(array_map(function ($product_row) {
//                return $product_row['price'] * $product_row['goods_number'];
//            }, $res));
            $arr['data'] = $res;
            $arr['total_price'] = $total_price;
            $this->success('成功',$arr);
        }else{
            $this->error('请求方式错误');
        }
    }

    /**
     * @ApiTitle    (删除购物车)
     * @ApiSummary  (删除购物车)
     * @ApiMethod   (GET)
     * @ApiRoute    (/api/cars/deleteCar)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     *
     * @ApiParams   (name="car_id", type="inter", required=true, description="购物车id")
     *
     * @ApiReturn({
        "code": 1,
        "msg": "成功",
        "time": "1575103466",
        "data": null
    })
     */
    public function deleteCar(){
        if($this->request->isGet()){
            $car_id = $this->request->get('car_id');
            $rule = config('verify.delete_car');
            $validate = new Validate($rule['rule'],$rule['msg']);
            if (!$validate->check(['car_id'=>$car_id])) {
                $this->error($validate->getError());
            }

            $carModel = new Car();
            $res = $carModel->where(['id'=>$car_id,'uid'=>$this->uid])->delete();
            if($res){
                $this->success('成功');
            }else{
                $this->error('失败');
            }
        }else{
            $this->error('请求方式错误');
        }
    }

    /**
jinglong authored
195 196 197 198 199
     * @ApiTitle    (猜你喜欢商品列表)
     * @ApiSummary  (猜你喜欢商品列表)
     * @ApiMethod   (GET)
     * @ApiRoute    (/api/cars/likeGodsList)
     *
200 201
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     *
jinglong authored
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
     * @ApiParams   (name="page", type="inter", required=true, description="分页页码")
     *
     * @ApiReturn({
        "code": 1,
        "msg": "成功",
        "time": "1574941706",
        "data": {
            "data": [
                {
                    "id": 7,//商品id
                    "image": "http://jinglong.springchunjia.cn/uploads/20191128/8a677f5a0418059bf1b974c50026af13.png",//图片路径
                    "name": "MONENT 动感系列",//商品名称
                    "tag": [//商品标签
                        "日式简约",
                        "隐秘乡奢",
                        "家庭情侣"
                    ],
                    "style": [//商品规格
                        "主餐匙,茶匙各1件",
                        "古堡灰"
                    ],
                    "sale_price": 2299//销售价格
                    "expense_price": //运费(0:显示包运费标签)
225
                    "is_new_tag": 0//新人价格标签(0:不显示,1:显示)
jinglong authored
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
                },
                {
                    "id": 4,
                    "image": "http://jinglong.springchunjia.cn/uploads/20191128/93971e55b83d1a09c1831f8197514305.png",
                    "name": "MONENT 动感系列",
                    "tag": [
                        "AB级",
                        "ABX级",
                        "ABN级"
                    ],
                    "new_price": 2499,
                    "sale_price": 2599
                },
            ],
            "total_page": 1
        }
    })
     */
    public function likeGodsList(){
        if($this->request->isGet()){
            $page = $this->request->get('page');
            $rule = config('verify.page');
            $validate = new Validate($rule['rule'],$rule['msg']);
            if (!$validate->check(['page'=>$page])) {
                $this->error($validate->getError());
            }
jinglong authored
252 253
            $limit = config('verify.goods_limit');
            $arr = Common::goodsList('',$page,$this->uid,$limit,'hots desc,id desc');
jinglong authored
254 255 256 257 258 259 260
            $this->success('成功',$arr);
        }else{
            $this->error('请求方式错误');
        }
    }

    /**
261 262
     * @ApiTitle    (商品结算)
     * @ApiSummary  (商品结算)
jinglong authored
263
     * @ApiMethod   (POST)
264 265 266 267 268 269
     * @ApiRoute    (/api/cars/settleGoods)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     *
     * @ApiParams   (name="goods_id", type="string", required=true, description="商品id(多个以逗号隔开,如:1,3,4)")
     * @ApiParams   (name="price", type="string", required=true, description="商品价格(多个以逗号隔开,如:100,10,200)")
     * @ApiParams   (name="goods_number", type="string", required=true, description="商品数量(多个以逗号隔开,如:10,10,10)")
jinglong authored
270
     * @ApiParams   (name="style", type="string", required=true, description="商品款式(多个以逗号隔开,如:‘款式1,款式2,款式3’)")
271 272 273 274 275 276 277 278 279 280 281 282 283 284
     *
     * @ApiReturn({
        "code": 1,
        "msg": "成功",
        "time": "1575106933",
        "data": {
            "data": [
                {
                    "id": 2,//商品id
                    "name": "MONENT 动感系列动感系列",//商品名称
                    "image": "http://jinglong.springchunjia.cn/uploads/20191128/8a677f5a0418059bf1b974c50026af13.png",//商品图片路径
                    "introduce": "轻波款,为客厅缀上霞光淡雾",//商品简介
                    "price": "250",//商品价格
                    "goods_number": "5"//商品数量
jinglong authored
285
                    "style": "款式1"//商品款式
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306
                },
                {
                    "id": 1,
                    "name": "MONENT 动感系列动感系列动感系列",
                    "image": "http://jinglong.springchunjia.cn/uploads/20191128/93971e55b83d1a09c1831f8197514305.png",
                    "introduce": "轻波款,为客厅缀上霞光淡雾",
                    "price": "100",
                    "goods_number": "3"
                }
            ],
            "total_goods_price": 1550,//商品总金额
            "total_expense_price": 10,//运费总金额
            "total_price": 1560//总金额(商品总金额+运费总金额)
        }
    })
     */
    public function settleGoods(){
        if($this->request->isPost()){
            $goods_id = $this->request->post('goods_id');
            $price = $this->request->post('price');
            $goods_number = $this->request->post('goods_number');
jinglong authored
307
            $style = $this->request->post('style');
308 309
            $rule = config('verify.settle_goods');
            $validate = new Validate($rule['rule'],$rule['msg']);
jinglong authored
310
            if (!$validate->check(['goods_id'=>$goods_id,'price'=>$price,'goods_number'=>$goods_number,'style'=>$style])) {
311 312 313 314 315 316
                $this->error($validate->getError());
            }

            $goods_id_s = explode(',',$goods_id);
            $price_s = explode(',',$price);
            $goods_number_s = explode(',',$goods_number);
jinglong authored
317
            $style_s = explode(',',$style);
318
            //合并数组
jinglong authored
319 320
            $key = ['goods_id','price','goods_number','style'];
            $res_goods = Common::array_merge_more($key,$goods_id_s,$price_s,$goods_number_s,$style_s);
321
            //查询商品
322
            $res = Common::selectSoftWhereData('goods',['id'=>['in',$goods_id_s]],'id,name,image,expense_price,stock,style g_style,introduce');
jinglong authored
323
324 325
            $total_price = 0;//总商品费用(不含运费)
            $total_expense_price = 0;//总运费
326
jinglong authored
327 328 329 330 331 332 333
            foreach($res_goods as &$g_value){
                $g_value['id'] = $g_value['goods_id'];
                foreach ($res as $value){
                    if($value['id'] == $g_value['goods_id']){
                        $g_value['name'] = $value['name'];
                        $g_value['image'] = $this->auth->absolutionUrlOne($value['image']);
                        $g_value['introduce'] = $value['introduce'];
334
                        //检测库存
jinglong authored
335 336
                        $check_stock = Common::checkStock($g_value['style'],$g_value['goods_number'],$value['g_style'],$value['stock']);
                        if(!$check_stock){
337
                            $this->error('规格:'.$g_value['style'].'库存不足');
jinglong authored
338
                        }
jinglong authored
339
                        $total_expense_price += $value['expense_price'];
340 341 342
                        break;
                    }
                }
jinglong authored
343
                $total_price += $g_value['price'] * $g_value['goods_number'];
344
            }
jinglong authored
345
            $arr['data'] = $res_goods;
346 347 348
            $arr['total_goods_price'] = $total_price;
            $arr['total_expense_price'] = $total_expense_price;
            $arr['total_price'] = $total_price + $total_expense_price;
jinglong authored
349
350 351 352 353 354 355
            $this->success('成功',$arr);
        }else{
            $this->error('请求方式错误');
        }
    }
jinglong authored
356 357 358 359 360 361
    /**
     * @ApiTitle    (结算可使用优惠券)
     * @ApiSummary  (结算可使用优惠券)
     * @ApiMethod   (GET)
     * @ApiRoute    (/api/cars/settleUseCoupon)
     *
362 363
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     *
jinglong authored
364
     * @ApiParams   (name="goods_id", type="string", required=true, description="商品id(多个以逗号隔开,如:1,3,4)")
jinglong authored
365
     * @ApiParams   (name="price", type="string", required=true, description="商品金额(多个以逗号隔开,如:100,200,300)")
jinglong authored
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380
     * @ApiParams   (name="total_goods_price", type="inter", required=true, description="商品总金额")
     *
     * @ApiReturn({
        "code": 1,
        "msg": "成功",
        "time": "1575372162",
        "data": [
            {
                "id": 2,//优惠券id
                "coupon_tag": "无门槛",//优惠券(无门槛,折扣券,满减券)
                "coupon_price": "¥300",//(折扣或减少金额)
                "coupon_tag1": "无门槛",优惠券(无门槛,满多少可用)
                "coupon_name": "全场优惠券",//优惠券名称
                "end_time": "2020.1.31",//优惠券有效期
                "type": "全场通用"//优惠券用途
381 382
                "is_discount": "0"//是否为折扣(0:否,1:是)
                "price_tag": 100 //折扣或者减少金额
jinglong authored
383 384 385 386
                 "use_goods_id": [//适用商品id
                    "15",
                    "16"
                ]
jinglong authored
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402
            },
            {
                "id": 10,
                "coupon_tag": "折扣券",
                "coupon_price": "9.5折",
                "coupon_tag1": "满2000可用",
                "coupon_name": "商品优惠券",
                "end_time": "2020.1.31",
                "type": "商品可用"
            }
        ]
    })
     */
    public function settleUseCoupon(){
        if($this->request->isGet()){
            $goods_id = $this->request->get('goods_id');
jinglong authored
403
            $price = $this->request->get('price');
jinglong authored
404 405 406
            $total_goods_price = $this->request->get('total_goods_price');
            $rule = config('verify.settle_use_coupon');
            $validate = new Validate($rule['rule'],$rule['msg']);
jinglong authored
407
            if (!$validate->check(['goods_id'=>$goods_id,'price'=>$price,'total_goods_price'=>$total_goods_price])) {
jinglong authored
408 409 410
                $this->error($validate->getError());
            }
jinglong authored
411
            //查询已经领取过,未使用
jinglong authored
412 413 414 415 416 417
            $flag = config('verify.flag');
            $type = config('verify.type');
            $receive = Common::selectWhereData('rcoupon',['uid'=>$this->uid,'is_use'=>$flag[0]],'id,c_id');
            $receive_s = array_column($receive,'c_id');

            $goods_id_s = explode(',',$goods_id);
jinglong authored
418
            $price_s = explode(',',$price);
jinglong authored
419
            //查询商品所属品牌id
jinglong authored
420
            $res1 = Common::selectSoftWhereData('goods',['id'=>['in',$goods_id_s],'type'=>$flag[1]],'id,t_id');
jinglong authored
421 422 423 424
            $b_id_s = array_unique(array_values(array_column($res1,'t_id')));

            $time = time();
            $where['id'] = ['in',$receive_s];
425
            $where['start_time'] = ['<',$time];
jinglong authored
426 427
            $where['end_time'] = ['>',$time];
jinglong authored
428 429
            $data = Common::selectWhereData('coupon',$where,'id,type,coupon_name,c_type,bg_id,coupon_type,full_reduce,reduce,discount,coupon_number,end_time','sort desc,id desc');
jinglong authored
430 431 432
            //整合商品id,商品总金额
            $k = ['goods_id','price'];
            $res_goods = $this->auth->array_merge_more($k,$goods_id_s,$price_s);
433
            
jinglong authored
434
            $res = [];
435 436 437
            $key = 0;
            foreach($data as $value){
                $key+=0;
jinglong authored
438 439 440
                $flag = 0;
                if(!empty($b_id_s)){
                    //有品牌,看商品所属品牌
jinglong authored
441
                    if($value['type'] == $type[0]){
jinglong authored
442
                        $flag = 1;
443 444
                    }else if($value['type'] == $type[1]){
                        if(in_array($value['bg_id'],$b_id_s)){
jinglong authored
445 446 447
                            //去除不是该商品的
                            $flag = 1;
                        }
448 449 450 451 452
                    }else{
                        //品类
                        if(in_array($value['bg_id'],$goods_id_s)){
                            $flag = 1;
                        }
jinglong authored
453
                    }
jinglong authored
454 455 456 457
                }else{
                    //无品牌
                    if($value['type'] == $type[0]){//是全场券
                        $flag = 1;
458
                    }else{
jinglong authored
459 460 461 462
                        if($value['type'] == $type[2] && in_array($value['bg_id'],$goods_id_s)){
                            //去除不是该商品的
                            $flag = 1;
                        }
463
                    }
jinglong authored
464 465 466 467
                }
                if($flag == 1){
                    //无门槛,有门槛
                    if($value['c_type'] == 0){
468
                        $res[$key]['id'] = $value['id'];
jinglong authored
469
                        //无门槛
jinglong authored
470
                        if($value['coupon_type'] == 0){
jinglong authored
471 472
                            //减少券,去掉满减金额,折扣字段,
                            unset($value['full_reduce']);
jinglong authored
473
                            unset($value['discount']);
jinglong authored
474
                            $res[$key]['coupon_tag'] = '无门槛';
jinglong authored
475
                            $res[$key]['coupon_price'] = '¥'.$value['reduce'];
jinglong authored
476
                            $res[$key]['coupon_tag1'] = '无门槛';
477 478 479

                            $res[$key]['is_discount'] = 0;//是否为折扣(0:否,1:是)
                            $res[$key]['price_tag'] = $value['reduce'];
jinglong authored
480
                        }else{
jinglong authored
481 482
                            //折扣券,去掉满减金额,减少金额字段,
                            unset($value['full_reduce']);
jinglong authored
483 484 485
                            unset($value['reduce']);
                            $res[$key]['coupon_tag'] = '折扣券';
                            $res[$key]['coupon_price'] = $value['discount'].'折';
jinglong authored
486
                            $res[$key]['coupon_tag1'] = '无门槛';
487 488 489

                            $res[$key]['is_discount'] = 1;//是否为折扣(0:否,1:是)
                            $res[$key]['price_tag'] = $value['discount'];
jinglong authored
490
                        }
491 492 493 494 495
                        $res[$key]['coupon_name'] = $value['coupon_name'];//优惠券名称
                        $res[$key]['end_time'] = date('Y.n.j',$value['end_time']);//优惠券有效期
                        //全场,品牌,商品
                        if($value['type'] == 0){
                            $res[$key]['type'] = '全场通用';
jinglong authored
496
497 498
                        }else if($value['type'] == 1){
                            $res[$key]['type'] = '部分品牌可用';
jinglong authored
499
500 501
                        }else{
                            $res[$key]['type'] = '部分商品可用';
jinglong authored
502
503
                        }
jinglong authored
504 505
                        $res[$key]['type_tag'] = $value['type'];
                        $res[$key]['bg_id'] = $value['bg_id'];
jinglong authored
506
                        $res[$key]['c_type'] = $value['c_type'];
507
                        $key++;
jinglong authored
508 509
                    }else{
                        //有门槛
jinglong authored
510
                        $res[$key]['id'] = $value['id'];
jinglong authored
511
jinglong authored
512 513 514 515 516 517
                        if($value['coupon_type'] == 0){
                            //减少券,去掉折扣字段,
                            unset($value['discount']);
                            $res[$key]['coupon_tag'] = '满减券';
                            $res[$key]['coupon_price'] = '¥'.$value['reduce'];
                            $res[$key]['coupon_tag1'] = '满'.$value['full_reduce'].'可用';
jinglong authored
518
jinglong authored
519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535
                            $res[$key]['is_discount'] = 0;//是否为折扣(0:否,1:是)
                            $res[$key]['price_tag'] = $value['reduce'];
                        }else{
                            //折扣券,去掉减少金额字段,
                            unset($value['reduce']);
                            $res[$key]['coupon_tag'] = '折扣券';
                            $res[$key]['coupon_price'] = $value['discount'].'折';
                            $res[$key]['coupon_tag1'] = '满'.$value['full_reduce'].'可用';

                            $res[$key]['is_discount'] = 1;//是否为折扣(0:否,1:是)
                            $res[$key]['price_tag'] = $value['discount'];
                        }
                        $res[$key]['coupon_name'] = $value['coupon_name'];//优惠券名称
                        $res[$key]['end_time'] = date('Y.n.j',$value['end_time']);//优惠券有效期
                        //全场,品牌,商品
                        if($value['type'] == 0){
                            $res[$key]['type'] = '全场通用';
jinglong authored
536
jinglong authored
537 538
                        }else if($value['type'] == 1){
                            $res[$key]['type'] = '部分品牌可用';
jinglong authored
539
jinglong authored
540 541
                        }else{
                            $res[$key]['type'] = '部分商品可用';
jinglong authored
542 543

                        }
jinglong authored
544 545 546 547 548
                        $res[$key]['type_tag'] = $value['type'];
                        $res[$key]['bg_id'] = $value['bg_id'];
                        $res[$key]['c_type'] = $value['c_type'];
                        $res[$key]['full_reduce'] = $value['full_reduce'];
                        $key++;
549
                    }
jinglong authored
550 551
                }
            }
jinglong authored
552 553 554 555 556 557
            foreach($res as &$r_value){
                if($r_value['type_tag'] == $type[0]){
                    //全场
                    $r_value['use_goods_id'] = $goods_id_s;
                }else if($r_value['type_tag'] == $type[1]){
                    //品牌
jinglong authored
558
                    $arr = [];
jinglong authored
559 560
                    foreach($res1 as $value1){
                        if($r_value['bg_id'] == $value1['t_id']){
jinglong authored
561
                            array_push($arr,$value1['id']);
jinglong authored
562 563
                        }
                    }
jinglong authored
564
                    $r_value['use_goods_id'] = $arr;
jinglong authored
565 566 567 568 569 570 571 572
                }else{
                    //商品
                    $r_value['use_goods_id'] = [];
                    foreach($goods_id_s as $g_value){
                        if($r_value['bg_id'] == $g_value){
                            $r_value['use_goods_id'] = [$r_value['bg_id']];
                        }
                    }
jinglong authored
573
                    $r_value['use_goods_str'] = implode(',',$r_value['use_goods_id']);
jinglong authored
574 575
                }
            }
576
jinglong authored
577
            $res2 = [];
jinglong authored
578
            //满减金额的优惠券
jinglong authored
579 580 581 582 583 584 585 586 587
            foreach($res as $res_value){
                $res2_flag = 0;
                if($res_value['c_type'] == 1){
                    if($res_value['type_tag'] == $type[0]){
                        //全场
                        //商品总金额大于等于满减金额
                        if(($total_goods_price <=> $res_value['full_reduce']) == -1){
                            $res2_flag = 1;
                        }
jinglong authored
588 589 590 591 592 593 594 595 596 597 598 599 600 601
                    }else if($res_value['type_tag'] == $type[1]){
                        //品牌
                        $price = 0;
                        foreach($res_goods as $goods_value){
                            foreach($res_value['use_goods_id'] as $u_value){
                                //品牌下的商品id
                                if($u_value == $goods_value['goods_id']){
                                    $price += $goods_value['price'];
                                }
                            }
                        }
                        if(($price <=> $res_value['full_reduce']) == -1){
                            $res2_flag = 1;
                        }
jinglong authored
602
                    }else{
jinglong authored
603
                        //商品
jinglong authored
604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619
                        $price = 0;
                        foreach($res_goods as $goods_value){
                            if($res_value['use_goods_str'] == $goods_value['goods_id']){
                                $price += $goods_value['price'];
                            }
                        }
                        if(($price <=> $res_value['full_reduce']) == -1){
                            $res2_flag = 1;
                        }
                    }
                }
                if($res2_flag == 0){
                    array_push($res2,$res_value);
                }
            }
            $this->success('成功',$res2);
jinglong authored
620 621 622 623 624
        }else{
            $this->error('请求方式错误');
        }
    }
625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653
    /**
     * @ApiTitle    (获取最近订单的地址)
     * @ApiSummary  (获取最近订单的地址)
     * @ApiMethod   (GET)
     * @ApiRoute    (/api/cars/getOrderAddress)
     *
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     *
     * @ApiReturn({
        "code": 1,
        "msg": "成功",
        "time": "1575462785",
        "data": {
            "id": 2,
            "receive_name": "景龙1",
            "receive_mobile": "13752011725",
            "receive_address": "天津市南开区1"
        }
    })
     */
    public function getOrderAddress(){
        if($this->request->isGet()){
            $res = Common::findSoftWhereData('order',['uid'=>$this->uid],'id,receive_name,receive_mobile,receive_address');
            $this->success('成功',$res);
        }else{
            $this->error('请求方式错误');
        }
    }
654
}