wupengfei 2 năm trước cách đây
mục cha
commit
edcb6fe4a4

+ 0 - 333
application/api/controller/Order.php

@@ -1,333 +0,0 @@
-<?php
-namespace app\api\controller;
-use app\common\model\GoodsOrder;
-use app\common\model\GoodsOrderItem;
-use app\common\model\StoreGoods;
-use app\common\model\StoreGoodsItem;
-use app\common\model\User;
-use think\Db;
-use think\Exception;
-
-/**
- * @title 商城订单
- * @controller Order
- * @group base
- */
-class Order extends Base
-{
-    public function initialize()
-    {
-        parent::initialize();
-        parent::checkLogin();
-    }
-
-    /**
-     * @title 创建订单
-     * @desc  创建订单
-     * @author  qc
-     * @url /api/Order/createOrder
-     * @method POST
-     * @header name:Authorization require:1 desc:Token
-     * @param name:goods_json type:string require:1  default:0 desc:商品json信息[{'goods_id':'商品id',spec_id:'规格id';'num':'数量'}]
-     * @param name:pro_name type:string default:-- desc:收货地址--省
-     * @param name:city_name type:string default:-- desc:收货地址--市
-     * @param name:county_name type:string default:-- desc:收货地址--区
-     * @param name:add_detail type:string default:-- desc:收货地址--详情
-     * @param name:user_name type:string default:-- desc:收货人
-     * @param name:phone type:string default:-- desc:收货人联系方式
-     * @param name:remark type:string default:1 desc:订单备注
-     * @return name:order_id type:int default:1 desc:订单id
-     */
-    public function createOrder()
-    {
-        $goods_json = input('post.goods_json','');
-        $pro_name = input('post.pro_name','');
-        $city_name = input('post.city_name','');
-        $county_name = input('post.county_name','');
-        $add_detail = input('post.add_detail','');
-        $user_name = input('post.user_name','');
-        $phone = input('post.phone','');
-        $remark = input('post.remark','');
-        if(!$goods_json) $this->error('请选择商品');
-        if(!$pro_name || !$city_name || !$county_name || !$add_detail) $this->error('请完善收货地址');
-        if(!$user_name || !$phone) $this->error('请完善收货人信息');
-        $goods_data = json_decode($goods_json,true);
-        $goods_ids = array_column($goods_data,'goods_id');
-        $goods_list = StoreGoods::field('specs,lists',true)->where('id','in',implode(',',$goods_ids))->where('status',1)->where('is_deleted',0)->with('itemList')->select()->toArray();
-        if(count($goods_list) != count($goods_ids)) $this->error('所选商品已下架');
-        $goods_column = array_column($goods_list,null,'id');
-        $ret_data = ['pay_status'=>0,'config'=>[],'order_id'=>0];
-        Db::startTrans();
-        try{
-            // 验证商品库存start
-            $check_goods =  0;
-            $error_goods =  '';
-            $price_goods =  0; // 商品总金额
-            $original_total = 0; // 商品总原价
-            $order_item = [];// 订单列表
-            foreach ($goods_data as $gv) {
-                $goods_spec = $goods_column[$gv['goods_id']]['item_list'];
-                $spec_column = array_column($goods_spec,null,'id');
-                if(!isset($spec_column[$gv['spec_id']])){
-                    $check_goods =  1;
-                    $error_goods = $goods_column[$gv['goods_id']]['name'];
-                    break;
-                }else if($spec_column[$gv['spec_id']]['stock'] < $gv['num']){
-                    $check_goods =  2;
-                    $error_goods = $goods_column[$gv['goods_id']]['name'];
-                    break;
-                }
-                $price_goods += $gv['num'] * $spec_column[$gv['spec_id']]['sell_price'];
-                $original_total += $gv['num'] * $spec_column[$gv['spec_id']]['original_price'];
-                $order_item[] = [
-                    'user_id' => $this->user_id,
-                    'goods_id' => $gv['goods_id'],
-                    'goods_no' => $spec_column[$gv['spec_id']]['goods_no'],
-                    'goods_name' => $goods_column[$gv['goods_id']]['name'],
-                    'goods_spec' =>  $spec_column[$gv['spec_id']]['goods_spec'],
-                    'spec_title' =>  $spec_column[$gv['spec_id']]['spec_title'],
-                    'spec_id' => $gv['spec_id'],
-                    'cover' =>   $spec_column[$gv['spec_id']]['cover'],
-                    'original_price' =>  $spec_column[$gv['spec_id']]['original_price'],
-                    'sell_price' =>  $spec_column[$gv['spec_id']]['sell_price'],
-                    'num' => $gv['num'],
-                ];
-                StoreGoods::where('id',$gv['goods_id'])->setDec('stock',$gv['num']);
-                StoreGoodsItem::where('id',$gv['spec_id'])->setDec('stock',$gv['num']);
-            }
-            if($check_goods == 1) $this->exception('所选商品'.$error_goods.'已下架');
-            if($check_goods == 2) $this->exception('所选商品'.$error_goods.'规格库存不足');
-            // 验证商品库存end
-            $order_insert = [
-                'user_id' => $this->user_id,
-                'order_no' => get_order_sn(),
-                'goods_num' => array_sum(array_column($goods_data,'num')),
-                'pro_name' => $pro_name,
-                'city_name' =>$city_name,
-                'county_name' => $county_name,
-                'add_detail' => $add_detail,
-                'user_name' => $user_name,
-                'phone' => $phone,
-                'remark' => $remark,
-            ];
-            $order_insert['price_total'] = $price_goods;
-            $order_insert['price_goods'] = $price_goods ;
-            $order_insert['original_total'] = $original_total ;
-            $order_insert['price_express'] = 0 ;
-            $order_info = GoodsOrder::create($order_insert);// 生成订单
-            array_walk($order_item,function (&$v,$k)use ($order_info){
-                $v['order_id'] = $order_info->id;
-            });
-            (new GoodsOrderItem())->insertAll($order_item);// 生成订单商品详情
-            $ret_data['order_id'] =  $order_info->id;
-            Db::commit();
-        }catch (\Exception $e){
-            Db::rollback();
-            $this->error($e->getMessage());
-        }
-        $this->success($ret_data);
-    }
-
-
-
-    /**
-     * @title 订单支付
-     * @desc  订单支付
-     * @author  qc
-     * @url /api/Order/payOrder
-     * @method POST
-     * @header name:Authorization require:1 desc:Token
-     * @param  name:order_id type:int require:1  default:0 desc:订单id
-     * @return name:config type:array default:0 desc:小程序支付配置
-     * @return name:config.appId type:string default:-- desc:appid
-     * @return name:config.nonceStr type:string default:-- desc:随机字符串
-     * @return name:config.signType type:string default:-- desc:签名类型
-     * @return name:config.paySign type:string default:-- desc:签名
-     * @return name:config.timestamp type:string default:-- desc:时间戳
-     */
-
-    public function payOrder()
-    {
-        $order_id = input('post.order_id');
-        $order_info = GoodsOrder::with('orderItem')->where('id',$order_id)->find()->toArray();
-        if($order_info['status'] != 0) $this->error('订单状态错误');
-        if($order_info['cancel_state'] != 0 || $order_info['is_deleted'] != 0) $this->error('订单异常');
-        if($order_info['price_total'] <= 0) $this->error('订单金额错误');
-        $user_info = User::where('id',$this->user_id)->find()->toArray();
-        $ret_data = ['pay_status'=>0,'config'=>[]];
-        Db::startTrans();
-        try {
-            $notify_url = $this->request->root(true) . '/api/we_chat_pay/goodsOrderNotify';
-            $pay_no = $order_info['pay_no'] ?  $order_info['pay_no'] : get_order_sn();
-            Db::name('store_order')->where(['uid'=>$this->user_id,'id'=>$order_id])->update(['pay_no'=>$pay_no]);
-            $config = WeChatPay::wxPay('订单支付',$pay_no,$order_info['price_total'],$notify_url,'JSAPI',$user_info['openid']);
-            if(!$config) throw  new  Exception('支付配置错误');
-            $ret_data['config'] = $config;
-            Db::commit();
-        }catch (\Exception $e) {
-            Db::rollback();
-            $this->error($e->getMessage());
-        }
-        $this->success('ok',$ret_data);
-    }
-
-
-    /**
-     * @title 获取订单列表
-     * @desc 获取订单列表
-     * @author qc
-     * @method GET
-     * @url /api/Order/getOrderList
-     * @header name:Authorization require:1 desc:Token
-     * @param  name:page type:int  default:1 desc:页数
-     * @param  name:page_num type:int default:20 desc:每页数
-     * @param  name:status type:int default:-1  desc:订单状态(-1全部,0待支付,1已支付(待发货),2已发货(待收货),3已收货(待评论)4已完成,8已退款,9取消)
-     * @param  name:pay_state type:int default:-1  desc:支付状态(-1全部,0未支付,1已支付)
-     * @return name:id type:int default:--  desc:订单id
-     * @return name:order_no type:string default:--  desc:订单号
-     * @return name:price_total type:float default:--  desc:订单金额
-     * @return name:status type:int default:--  desc:订单状态(0待支付,1已支付(待发货),2已发货(待收货),3已收货(待评论)4已完成,8已退款,9取消)
-     * @return name:create_at type:string default:--  desc:下单时间
-     * @return name:remark type:string default:--  desc:订单备注
-     * @return name:order_item type:array default:--  desc:订单商品列表
-     * @return name:order_item.name type:float default:--  desc:商品名
-     * @return name:order_item.cover type:float default:--  desc:商品图
-     * @return name:order_item.sell_price type:float default:--  desc:购买价格
-     * @return name:order_item.goods_spec type:float default:--  desc:规格
-     * @return name:order_item.num type:int default:--  desc:数量
-     */
-    public function getOrderList()
-    {
-        $status = input('get.status',-1);
-        $pay_state = input('get.pay_state',-1);
-        $cancel_state = input('get.cancel_state',-1);
-        $refund_state = input('get.apply_refund',-1);
-        $where = [];
-        $where[] = ['user_id','=',$this->user_id];
-        if($status > -1) $where[] = ['status','=',$status];
-        if($pay_state > -1) $where[] = ['pay_state','=',$pay_state];
-        if($cancel_state > -1) $where[] = ['cancel_state','=',$cancel_state];
-        if($refund_state == 0) $where[] = ['refund_state','=',$refund_state];
-        if($refund_state == 1) $where[] = ['refund_state','in','1,2,3,4'];
-        $list = GoodsOrder::field('id,order_no,status,create_at,remark')->with(['orderItem'])->where($where)->order('id desc ')
-            ->limit($this->off_set,$this->page_num)
-            ->select()->toArray();
-        $this->success('ok',['list'=>$list]);
-    }
-
-
-    /**
-     * @title 获取订单详情
-     * @desc 获取订单详情
-     * @author qc
-     * @method GET
-     * @url /api/Order/getOrderDetail
-     * @header name:Authorization require:1 desc:Token
-     * @param name:order_id type:int default:--  desc:订单id
-     * @return name:id type:int default:--  desc:订单id
-     * @return name:order_no type:string default:--  desc:订单号
-     * @return name:price_total type:float default:--  desc:待支付金额(
-     * @return name:price_goods type:float default:--  desc:商品金额
-     * @return name:price_express type:0 default:--  desc:运费金额
-     * @return name:original_total type:float default:--  desc:总原价(下划线)
-     * @return name:original_total type:float default:--  desc:总原价(下划线)
-     * @return name:pay_state type:int default:--  desc:支付状态(0未支付1已支付)
-     * @return name:pay_type type:int default:--  desc:支付方式(1微信)
-     * @return name:pay_no type:string default:--  desc:支付号
-     * @return name:pay_at type:string default:--  desc:支付时间
-     * @return name:cancel_state type:int default:--  desc:取消状态(0未取消1已取消)
-     * @return name:cancel_at type:string default:--  desc:取消时间
-     * @return name:cancel_desc type:string default:--  desc:取消原因
-     * @return name:express_state type:int default:--  desc:发货状态(0未发货,1已发货,2已签收)
-     * @return name:express_company_title type:string default:--  desc:发货快递公司名称
-     * @return name:express_send_no type:string default:--  desc:物流单号
-     * @return name:express_send_at type:string default:--  desc:发货时间
-     * @return name:status type:int default:--  desc:订单状态(0待支付,1已支付(待发货),2已发货(待收货),3已收货(待评论)4已完成,8已退款,9取消)
-     * @return name:create_at type:string default:--  desc:下单时间
-     * @return name:pay_at type:string default:--  desc:支付时间
-     * @return name:remark type:string default:--  desc:订单备注
-     * @return name:goods_num type:int default:--  desc:订单商品总数量
-     * @return name:pro_name type:string default:--  desc:省名称(收货地址)
-     * @return name:city_name type:string default:--  desc:市名称(收货地址)
-     * @return name:county_name type:string default:--  desc:县区名称(收货地址)
-     * @return name:street_name type:string default:--  desc:街道名称(收货地址)
-     * @return name:add_detail type:string default:--  desc:详细地址(收货地址)
-     * @return name:user_name type:string default:--  desc:收货人
-     * @return name:phone type:string default:--  desc:收货人联系电话
-     * @return name:order_item type:array default:--  desc:订单商品列表(按商品id分组)
-     * @return name:order_item.name type:float default:--  desc:商品名
-     * @return name:order_item.cover type:float default:--  desc:商品图
-     * @return name:order_item.sell_price type:float default:--  desc:购买价格
-     * @return name:order_item.goods_spec type:float default:--  desc:规格
-     * @return name:order_item.num type:int default:--  desc:数量
-     */
-    public function getOrderDetail()
-    {
-        $order_id = input('get.order_id');
-        $detail = GoodsOrder::where('id',$order_id)->find()->toArray();
-        $detail['order_item']  = (new GoodsOrderItem())->getOrderItem($order_id);
-        $this->success('ok',['detail'=>$detail]);
-    }
-
-
-
-    /**
-     * @title 取消订单
-     * @desc  取消订单
-     * @author  qc
-     * @url /api/Order/cancelOrder
-     * @method POST
-     * @header name:Authorization require:1 desc:Token
-     * @param  name:order_id type:int require:1  default:0 desc:订单id
-     */
-    public function cancelOrder()
-    {
-        $order_id = input('post.order_id');
-        Db::startTrans();
-        try {
-            $detail = GoodsOrder::with('orderItem')->where('id',$order_id)->find()->toArray();
-            if($detail['status'] != 0) $this->exception('订单状态有误');
-            // 取消订单状态
-            GoodsOrder::update(['status'=>9],['id'=>$order_id]);
-            // 订单处理
-            foreach ($detail['order_item'] as $item_info) {
-                //  更改订单详情状态
-                GoodsOrderItem::update(['status'=>9],['id'=>$item_info['id']]);
-                // 商品规格库存返回
-                StoreGoodsItem::where('id',$item_info['spec_id'])->setInc('stock',$item_info['num']);
-                // 商品总库存增加
-                StoreGoods::where('id',$item_info['goods_id'])->setInc('stock',$item_info['num']);
-            }
-            Db::commit();
-        }catch (\Exception $e){
-            $this->ret_msg = $e->getMessage();
-            $this->is_commit = false;
-            Db::rollback();
-        }
-        $this->is_commit ? $this->success('取消成功') : $this->error($this->ret_msg);
-    }
-
-
-
-    /**
-     * @title 确认收货
-     * @desc  确认收货
-     * @author  qc
-     * @url /api/Order/confirmReceipt
-     * @method POST
-     * @header name:Authorization require:1 desc:Token
-     * @param  name:order_id type:int require:1  default:0 desc:订单id
-     */
-    public function confirmReceipt()
-    {
-        $order_id = input('post.order_id');
-        $detail = GoodsOrder::with('orderItem')->where('id',$order_id)->find()->toArray();
-        if($detail['status'] == 0) $this->error('订单未支付');
-        if($detail['status'] == 1) $this->error('订单未发货');
-        if($detail['status'] == 3) $this->error('订单已收货');
-        GoodsOrder::update(['status'=>3,'express_state'=>2],['id'=>$order_id]);
-        GoodsOrderItem::update(['status'=>3,'express_state'=>2],['order_id'=>$order_id]);
-        $this->success('已确认收货');
-    }
-
-}

+ 8 - 1
application/api/controller/Qc.php

@@ -39,7 +39,14 @@ class Qc extends Base {
 
     public function index()
     {
-        echo 1;
+        $order_item = [
+            ['sell_price'=>0.3],
+            ['sell_price'=>0.6],
+            ['sell_price'=>0.5],
+            ['sell_price'=>0.3],
+        ];
+        array_multisort(array_column($order_item,'sell_price'),SORT_DESC,$order_item);
+        var_dump($order_item);
     }
 
 

+ 0 - 305
application/api/controller/Trolley.php

@@ -1,305 +0,0 @@
-<?php
-namespace app\api\controller;
-use app\common\model\StoreGoods;
-use app\common\model\StoreGoodsItem;
-use app\common\service\ExpressService;
-use think\Db;
-use app\common\model\ShoppingTrolley;
-use app\common\model\DeliveryAddress;
-use think\Exception;
-
-/**
- * @title 购物车
- * @controller Trolley
- * @group base
- */
-class Trolley extends Base
-{
-
-    protected $no_login = ['delComment'];// 不需要登录的
-
-    public function initialize()
-    {
-        parent::initialize();
-        $path = explode('/',$this->request->path());
-        if(!in_array(end($path),$this->no_login)) parent::checkLogin();
-    }
-
-    /**
-     * @title 获取购物车商品数量
-     * @desc  获取购物车商品数量
-     * @author  qc
-     * @url /api/Trolley/getTrolleyNum
-     * @method GET
-     * @header name:Authorization require:1 desc:Token
-     * @param name:goods_id type:int default:-- desc:商品id(商品id不传查全部的)
-     * @return name:total_num type:int default:-- desc:购物车商品数量
-     */
-    public function getTrolleyNum()
-    {
-        $where = [];
-        $where['user_id'] = $this->user_id;
-        if($goods_id = input('get.goods_id',0)) $where['goods_id'] = $goods_id;
-        $total_num = ShoppingTrolley::where($where)->sum('num');
-        $this->success('ok',['total_num'=>$total_num]);
-    }
-
-    /**
-     * @title 获取购物车列表
-     * @desc  获取购物车列表
-     * @author  qc
-     * @url /api/Trolley/getTrolleyList
-     * @method GET
-     * @header name:Authorization require:1 desc:Token
-     * @return name:id type:int default:-- desc:购物车记录id
-     * @return name:goods_id type:int default:-- desc:商品id
-     * @return name:goods_name type:string default:-- desc:商品名称
-     * @return name:goods_status type:int default:-- desc:商品状态(1上架,0下架)
-     * @return name:cover type:string default:-- desc:商品封面
-     * @return name:deleted_status type:string default:-- desc:商品删除状态(1删除,0未删除)
-     * @return name:num type:int default:-- desc:数量
-     * @return name:goods_id type:int default:-- desc:商品id
-     * @return name:goods_id type:int default:-- desc:商品id
-     * @return name:spec_id type:int default:-- desc:规格id
-     * @return name:goods_spec type:int default:-- desc:规格
-     * @return name:goods_no type:int default:-- desc:货号
-     * @return name:original_price type:float default:-- desc:规格原价(下划线价格)
-     * @return name:sell_price type:float default:-- desc:规格售价
-     */
-    public function getTrolleyList()
-    {
-        $join_field = 't.id,t.num,t.spec_id,t.goods_id,i.goods_spec,g.cover,i.goods_no,i.is_deleted,i.original_price,i.sell_price,i.weight,g.name goods_name,g.status goods_status,g.is_deleted deleted_status';
-        $list = ShoppingTrolley::field($join_field)
-            ->alias('t')
-            ->where(['t.user_id'=>$this->user_id])
-            ->leftJoin('StoreGoodsItem i','i.id = t.spec_id')
-            ->leftJoin('StoreGoods g','t.goods_id = g.id')
-            ->order('t.id desc')
-            ->select()->toArray();
-        $this->success('ok',['list'=>$list]);
-    }
-
-    /**
-     * @title 商品添加购物车(按规格加入)
-     * @desc  商品某个规格加入多少
-     * @author  qc
-     * @url /api/Trolley/addTrolley
-     * @method POST
-     * @header name:Authorization require:1 desc:Token
-     * @param  name:goods_id type:int require:1  default:0 desc:商品id
-     * @param  name:spec_id type:int  require:1 default:0 desc:规格id
-     * @param  name:num type:int default:1 desc:数量
-     */
-    public function addTrolley()
-    {
-        $goods_id = input('post.goods_id');
-        $spec_id = input('post.spec_id');
-        $num    = input('post.num',1);
-        if(!$goods_id || !$spec_id)  $this->error('请选择商品');
-        if($num <=0 ) $this->error('添加数量有误');
-        Db::startTrans();
-        try {
-            // 商品详情
-            $goods_info = StoreGoods::with(['itemList'=>function($query)use($spec_id){
-                return $query->where('id',$spec_id)->where('is_deleted',0);
-            }])->where('id',$goods_id)->where('is_deleted',0)->where('status',1)->find();
-            if(!$goods_info) throw new Exception('商品已下架');
-            $goods_info = $goods_info->toArray();
-            if(empty($goods_info['item_list'])) throw new Exception('该规格已下架');
-            if($goods_info['item_list'][0]['stock'] < $num) throw new Exception('库存不足');
-            $trolley_id = ShoppingTrolley::checkTrolley($this->user_id,$goods_id,$spec_id);
-            // 添加到购物车
-            if($trolley_id) {
-                ShoppingTrolley::where('id',$trolley_id)->setInc('num',$num);
-            }else{
-                $trolley_info = [
-                    'user_id' => $this->user_id,
-                    'goods_id' => $goods_id,
-                    'spec_id' => $spec_id,
-                    'goods_no' => $goods_info['item_list'][0]['goods_no'],
-                    'num' => $num,
-                ];
-                ShoppingTrolley::create($trolley_info);
-            }
-            // 扣减库存
-            StoreGoods::where('id',$goods_id)->setDec('stock',$num);
-            StoreGoodsItem::where('id',$spec_id)->setDec('stock',$num);
-            Db::commit();
-        }catch (\Exception $e){
-            $this->is_commit = false;
-            $this->ret_msg = $e->getMessage();
-            Db::rollback();
-        }
-        $this->is_commit ? $this->success('添加成功'):$this->error($this->ret_msg);
-    }
-
-    /**
-     * @title 修改购物车商品数量
-     * @desc  修改购物车商品数量
-     * @author  qc
-     * @url /api/Trolley/changeTrolleyNum
-     * @method POST
-     * @header name:Authorization require:1 desc:Token
-     * @param  name:trolley_id type:int require:1  default:0 desc:购物车记录id
-     * @param name:num type:int require:1 default:1 desc:变更数量
-     * @param name:type type:int require:1 default:1 desc:变更类型(1增加2扣减)
-     */
-    public function changeTrolleyNum()
-    {
-        $trolley_id = input('post.trolley_id');
-        $num = input('post.num',1);
-        $type = input('post.type',1);
-        if(!in_array($type,[1,2])) $this->error('变更可类型错误');
-        Db::startTrans();
-        try {
-            $trolley_info = ShoppingTrolley::get($trolley_id);
-            if(!$trolley_info) $this->exception('记录不存在!');
-            $goods_info = StoreGoods::getGoodsSpec($trolley_info->goods_id,$trolley_info->spec_id);
-            if($type == 1){
-                if(!$goods_info) $this->exception('商品已下架');
-                if(empty($goods_info['item_list'])) $this->exception('该规格已下架');
-                if($goods_info['item_list'][0]['stock'] < $num)$this->exception('库存不足');
-                ShoppingTrolley::where('id',$trolley_id)->setInc('num',$num);
-                StoreGoods::where('id',$trolley_info->goods_id)->setDec('stock',$num);// 扣减商品库存
-                StoreGoodsItem::where('id',$trolley_info->spec_id)->setDec('stock',$num);// 扣减规格库存
-            }else{
-                if($trolley_info->num < $num) $this->exception('扣减数量有误');
-                if($trolley_info->num > $num){
-                    ShoppingTrolley::where('id',$trolley_id)->setDec('num',$num);//扣减数量
-                }else{
-                    ShoppingTrolley::where('id',$trolley_id)->delete();//删除记录
-                }
-                StoreGoods::where('id',$trolley_info->goods_id)->setInc('stock',$num);//增加商品库存
-                StoreGoodsItem::where('id',$trolley_info->spec_id)->setInc('stock',$num);//增加规格库存
-            }
-            Db::commit();
-        }catch (\Exception $e){
-            $this->ret_msg = $e->getMessage();
-            $this->is_commit = false;
-            Db::rollback();
-        }
-        $this->is_commit ? $this->success('操作成功') : $this->error($this->ret_msg);
-    }
-
-    /**
-     * @title 删除购物车记录
-     * @desc  删除购物车记录
-     * @author  qc
-     * @url /api/Trolley/cancelTrolleyList
-     * @method POST
-     * @header name:Authorization require:1 desc:Token
-     * @param  name:ids type:string require:1  default:0 desc:购物车记录id(多条用逗号隔开)
-     */
-    public function cancelTrolleyList()
-    {
-        $ids = input('post.ids');
-        if(!$ids) $this->error('请选择要删除的数据');
-        $trolley_list = ShoppingTrolley::where('id','in',$ids)->select();
-        Db::startTrans();
-        foreach ($trolley_list as $trolley_info) {
-            StoreGoods::where('id',$trolley_info->goods_id)->setInc('stock',$trolley_info->num);//增加商品库存
-            StoreGoodsItem::where('id',$trolley_info->spec_id)->setInc('stock',$trolley_info->num);//增加规格库存
-        }
-        ShoppingTrolley::where('id','in',$ids)->delete();
-        Db::commit();
-        $this->success('删除成功');
-
-    }
-
-    /**
-     * @title 某商品是否添加到购物
-     * @desc  获取某商品添加到购物车规格及数量
-     * @author  qc
-     * @url /api/Trolley/getTrolleyByGoodsId
-     * @method GET
-     * @header name:Authorization require:1 desc:Token
-     * @param  name:goods_id type:int  default:1 desc:商品id
-     * @return name:spec_id type:int default:-- desc:规格id
-     * @return name:num type:int default:-- desc:数量
-     */
-    public function getTrolleyByGoodsId()
-    {
-        $goods_id = input('get.goods_id');
-        $list = ShoppingTrolley::field('id,goods_id,spec_id,goods_no,num')
-            ->where(['user_id'=>$this->user_id,'goods_id'=>$goods_id])
-            ->order('id desc')
-            ->select();
-        $this->success('ok',['list'=>$list?$list->toArray() : null ]);
-    }
-
-
-    /**
-     * @title 购物车订单确认
-     * @desc  购物车订单确认
-     * @author  qc
-     * @url /api/Trolley/confirmTrolleyList
-     * @method GET
-     * @header name:Authorization require:1 desc:Token
-     * @param  name:ids type:int  default:1 desc:购物车记录id(多条用逗号隔开)
-     * @return name:goods_id type:int default:-- desc:商品id
-     * @return name:goods_name type:string default:-- desc:商品名称
-     * @return name:goods_status type:int default:-- desc:商品状态(1上架,0下架)
-     * @return name:deleted_status type:string default:-- desc:删除状态(1删除,0未删除)
-     * @return name:cover type:string default:-- desc:封面
-     * @return name:item_list type:array default:-- desc:添加该商品的规格列表
-     * @return name:item_list.spec_id type:int default:-- desc:规格id
-     * @return name:item_list.goods_no type:int default:-- desc:货号
-     * @return name:item_list.original_price type:float default:-- desc:规格原价
-     * @return name:item_list.sell_price type:float default:-- desc:规格售价
-     * @return name:item_list.goods_spec type:string default:-- desc:规格
-     * @return name:total_money type:float default:-- desc:商品总金额【不含运费】
-     * @return name:freight type:float default:-- desc:运费
-     * @return name:freight_code type:int default:1 desc:运费提示编号【1所选地址支持发货,0所选地址不支持发货】
-     * @return name:freight_msg type:string default:-- desc:运费提示信息【freight_code=1忽略】
-     */
-    public function confirmTrolleyList()
-    {
-        $ids = input('get.ids');
-        $trolley_goods = ShoppingTrolley::field('goods_id')
-            ->where('user_id',$this->user_id)
-            ->where('id','in',$ids)
-            ->group('goods_id')
-            ->select();
-        if(!$trolley_goods) $this->error('请选择商品');
-        $goods_ids = array_column($trolley_goods->toArray(),'goods_id');
-        $freight = 0;
-        $list = [];
-        $total_money = 0;
-        $goods_list = StoreGoods::where('id','in',$goods_ids)->select()->toArray();
-        $address_info = DeliveryAddress::where(['user_id'=>$this->user_id,'is_mr'=>1])->find();
-        foreach ($goods_list as $goods_info){
-            $trolley_data =  ['goods_id'=>$goods_info['id'],'goods_name'=>$goods_info['name'],'goods_status'=>$goods_info['status'],'cover'=>$goods_info['cover'],'deleted_status'=>$goods_info['is_deleted']];
-            $trolley_data['item_list'] = ShoppingTrolley::field('t.*,i.original_price,i.sell_price,i.goods_spec')
-                ->alias('t')
-                ->where('t.id','in',$ids)
-                ->where('t.goods_id',$goods_info['id'])
-                ->leftJoin('StoreGoodsItem i','i.id = t.spec_id')
-                ->select()->toArray();
-            foreach ($trolley_data['item_list'] as $iv){
-                $total_money = bcadd(bcmul($iv['num'],$iv['sell_price'],2),$total_money,2);
-            }
-            $list[] = $trolley_data;
-            $fre_num = array_sum(array_column($trolley_data['item_list'],'num'));
-            if($address_info) {
-                $goods_freight = ExpressService::getGoodsExpressPrice($goods_info,$address_info->id,$fre_num);
-                if($goods_freight['code'] !=200){
-                    $this->is_commit =  false;
-                    $this->ret_msg =  $goods_freight['msg'];
-                }
-                $freight +=  $goods_freight['freight']; //  商品运费
-            }
-        }
-        $this->success('ok',[
-            'list'=>$list,
-            'total_money'=>$total_money,
-            'address_info'=>$address_info ? $address_info->toArray():null,
-            'freight' =>$freight,
-            'freight_msg' => $this->ret_msg,
-            'freight_code' => $this->is_commit ? 1 :0
-        ]);
-    }
-
-
-
-
-}

+ 21 - 0
application/api/controller/WashManage.php

@@ -7,6 +7,7 @@ use app\common\model\DeliveryAddress;
 use app\common\model\GoodsOrder;
 use app\common\model\StoreOrderRefund;
 use app\common\model\User;
+use app\common\model\UserCouponList;
 use app\common\model\WashOrder;
 use app\common\model\WashCate;
 use app\common\model\WashClothes;
@@ -201,6 +202,7 @@ class WashManage extends Base
      * @param name:remark type:string default:-- desc:订单备注
      * @param name:images type:string default:-- desc:图片(多张|隔开)
      * @param name:address_id type:int default:-- desc:地址id
+     * @param name:coupon_id type:int default:-- desc:优惠券id
      */
     public function createOrder()
     {
@@ -208,6 +210,7 @@ class WashManage extends Base
         $address_id = input('post.address_id','');
         $remark = input('post.remark','');
         $images = input('post.images','');
+        $coupon_id = input('post.coupon_id','');
         $goods_data = json_decode($goods_json,true);
         $goods_column = array_column($goods_data,null,'goods_id');
         $goods_ids = array_keys($goods_column);
@@ -225,6 +228,19 @@ class WashManage extends Base
         $ret_data = ['pay_status'=>0,'config'=>[],'order_id'=>0];
         Db::startTrans();
         try {
+            $coupon_info = [];
+            if($coupon_id) {
+                $module = $this->module + 1;
+                $coupon_info = UserCouponList::where(['l.user_id'=>$this->user_id,'l.status'=>1,'l.id'=>$coupon_id])
+                    ->alias('l.*,c.title,c.module,c.coupon_type,c.is_new')
+                    ->when($module,function ($query)use ($module){
+                        if($module > 1 )  $query->where('module','in','1,'. $module);
+                    })->leftJoin('CouponConfig c','c.id = l.coupon_id')
+                    ->find();
+                if(empty($coupon_info)) $coupon_info = $this->exception('所选优惠券有误');
+                $coupon_info =  $coupon_info->toArray();
+            }
+
             $address = DeliveryAddress::field('id,pro_name,city_name,county_name,mer_name,detail,phone,name,sex')
                 ->where('user_id',$this->user_id)->where('id',$address_id)->find()->toArray();
             $price_total = 0;
@@ -242,6 +258,7 @@ class WashManage extends Base
                 'user_name' => $address['name'],
                 'remark' => $remark,
                 'images' => $images,
+                'coupon_id' => $coupon_id,
                 'module' => $this->module,
             ];
 
@@ -260,6 +277,10 @@ class WashManage extends Base
                     'num' => $goods_column[$v['id']]['num'],
                 ];
             });
+
+            array_multisort(array_column($order_item,'sell_price'),SORT_DESC,$order_item);
+
+
             $order_info['price_total'] = bcadd($postage,$price_total,2);
             $order_info['postage'] = $postage;
             $order_info = WashOrder::create($order_info)->toArray();

+ 2 - 1
config/apidoc.php

@@ -1,13 +1,14 @@
 <?php
 return [
     // 文档标题
-    'title'=>'雄文网接口文档',
+    'title'=>'涤能',
     // 版权申明
     'copyright'=>'Powered By HG',
     //生成文档的控制器
     'controllers' => [
         'api\\controller\\Address',
         'api\\controller\\Area',
+        'api\\controller\\Coupon',
         'api\\controller\\Expedite',
         'api\\controller\\Login',
         'api\\controller\\Upload',