wupengfei 2 vuotta sitten
vanhempi
commit
3f95848f7f
2 muutettua tiedostoa jossa 31 lisäystä ja 48 poistoa
  1. 7 30
      application/api/controller/Task.php
  2. 24 18
      application/api/controller/WashManage.php

+ 7 - 30
application/api/controller/Task.php

@@ -3,6 +3,7 @@ namespace app\api\controller;
 
 use app\common\model\LabelMessage;
 use app\common\model\User;
+use app\common\model\UserCouponList;
 use app\common\model\UserMessage;
 
 /**
@@ -13,45 +14,21 @@ use app\common\model\UserMessage;
  */
 class Task extends Base
 {
-    // 会员消息推送
-    public function taskUserMessage(){
-        $list = UserMessage::field('id,user_id,content')->where('jg_type',1)->where('jg_status',0)->limit(0,50)->order('id')->select();
-        foreach ($list as $v) {
-            UserMessage::where(['id'=>$v['id']])->update(['jg_status'=>1]);
-            Jpush($v['user_id'],$v['content']);
-        }
-    }
+
 
 
     /**
-     * @title 标签推送[根据标签id]
-     * @desc  标签推送
+     * @title 清理过期优惠券
+     * @desc
      * @author  qc
-     * @url /api/Task/taskLabelMessage
+     * @url /api/Task/delCoupon
      */
-    //按照标签推送
-    public function taskLabelMessage()
-    {
-        $list = LabelMessage::where('jg_status',0)->where('is_deleted',0)->select()->toArray();
-        foreach ($list as $v) {
-            LabelMessage::where(['id'=>$v['id']])->update(['jg_status'=>1]);
-            $user_list = User::field('id')
-                ->where('label','like','%|'.$v['label_id'].'|%')
-                ->where('status','=',1)
-                ->where('type','=',1)
-                ->where('is_deleted','=',0)->select()->toArray();;
-            foreach ($user_list as $user_info) {
-              $res =  Jpush($user_info['id'],$v['content']);
-            }
-        }
+    public function delCoupon(){
+        UserCouponList::where(['past_at','> time',date('Y-m-d H:i:s')])->update(['status'=>'3']);
     }
 
 
 
 
 
-
-
-
-
 }

+ 24 - 18
application/api/controller/WashManage.php

@@ -191,7 +191,7 @@ class WashManage extends Base
 
 
     /**
-     * @title 创建订单
+     * @title 创建订单【订单金额(price_total)为0时,不需要调支付,订单直接完成】
      * @desc  创建订单
      * @author  qc
      * @url /api/Wash_manage/createOrder
@@ -228,19 +228,6 @@ 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;
@@ -277,9 +264,25 @@ class WashManage extends Base
                     'num' => $goods_column[$v['id']]['num'],
                 ];
             });
-
+            // 数组降序
             array_multisort(array_column($order_item,'sell_price'),SORT_DESC,$order_item);
-
+            // 计算优惠券抵扣金额
+            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();
+                if($coupon_info['coupon_type'] == 1 && $coupon_info['low_amount'] < $price_total) $this->exception('优惠券使用金额限制,最低:'.$coupon_info['low_amount'].'元');
+                $coupon_cash = $coupon_info['coupon_type'] == 1 ? $coupon_info['amount'] : $order_item[0]['sell_price'];
+                $price_total = bcsub($price_total , $coupon_cash,2);
+                $order_info['coupon_cash'] = $coupon_cash;
+                UserCouponList::where('id',$coupon_id)->update(['status'=>2,'used_time'=>date('Y-m-d H:i:s')]);
+            }
 
             $order_info['price_total'] = bcadd($postage,$price_total,2);
             $order_info['postage'] = $postage;
@@ -337,6 +340,7 @@ class WashManage extends Base
      * @return name:phone type:string default:--  desc:收货人联系电话
      * @return name:sex type:int  require:1  default:-- desc:性别(1男2女)
      * @return name:second type:int default:-- desc:倒计时(单位秒)
+     * @return name:coupon_cash type:float default:-- desc:优惠券抵扣金额
      * @return name:afresh_order type:int default:--  desc:重洗订单id,没申请是0
      * @return name:order_item type:array default:--  desc:订单商品列表
      * @return name:order_item.name type:string default:--  desc:商品名
@@ -348,7 +352,7 @@ class WashManage extends Base
     public function getOrderDetail()
     {
         $order_id = input('get.id');
-        $field = 'id,module,order_no,status,price_total,pay_state,images,pay_no,is_deleted,pay_at,cancel_state,goods_num,remark,pro_name,city_name,county_name,add_detail,user_name,phone,postage,create_at,finish_int,finish_time,sex';
+        $field = 'id,module,order_no,status,price_total,pay_state,images,pay_no,is_deleted,pay_at,cancel_state,goods_num,remark,pro_name,city_name,county_name,add_detail,user_name,phone,postage,create_at,finish_int,finish_time,sex,coupon_id,coupon_cash';
         $detail = WashOrder::field($field)
             ->with('orderItem')->where('id',$order_id)->find()->toArray();
         if($detail['is_deleted'] == 1) $this->error('订单已删除');
@@ -395,6 +399,7 @@ class WashManage extends Base
      * @return name:add_detail type:string default:--  desc:详细地址(收货地址)
      * @return name:user_name type:string default:--  desc:收货人
      * @return name:sex type:int default:-- desc:性别(1男2女)
+     * @return name:coupon_cash type:float default:-- desc:优惠券抵扣金额
      * @return name:phone type:string default:--  desc:收货人联系电话
      * @return name:order_item type:array default:--  desc:订单商品列表
      * @return name:order_item.name type:float default:--  desc:商品名
@@ -426,7 +431,7 @@ class WashManage extends Base
                 $where[] = ['status','=','3'];
                 break;
         }
-        $field = 'id,module,order_no,status,price_total,pay_state,pay_no,pay_at,cancel_state,goods_num,remark,pro_name,city_name,county_name,add_detail,user_name,phone,postage,create_at,finish_int,finish_time,sex';
+        $field = 'id,module,order_no,status,price_total,pay_state,pay_no,pay_at,cancel_state,goods_num,remark,pro_name,city_name,county_name,add_detail,user_name,phone,postage,create_at,finish_int,finish_time,sex,coupon_id,coupon_cash';
         $list = WashOrder::field($field)->with(['orderItem'])->where($where)->order('id desc ')
             ->limit($this->off_set,$this->page_num)
             ->select()->toArray();
@@ -488,6 +493,7 @@ class WashManage extends Base
         if($order_info['is_deleted'] == 1) $this->error('订单已删除');
         if($order_info['cancel_state'] == 1) $this->error('订单已取消');
         if($order_info['status'] == 8) $this->error('订单已取消');
+        if($order_info['coupon_id'])  UserCouponList::where('id',$order_info['coupon_id'])->update(['status'=>2,'used_time'=>'']);
         if($order_info['status'] == 0){
             WashOrder::where('id',$order_id)->update(['status'=>9,'cancel_state'=>1,'cancel_at'=>date('Y-m-d H:i:s')]);
         }else{