xieruidong 2 years ago
parent
commit
1d7029c974

+ 1 - 1
application/common/model/Coupon.php

@@ -51,7 +51,7 @@ class Coupon extends Model
                     UserCoupon::toUser($user, $this);
                 }
             }
-
+            SiteMsg::sendMsg(SiteMsg::TYPE_COUPON,$user);
         }
 
     }

+ 8 - 0
application/common/model/OrderVoucher.php

@@ -6,6 +6,7 @@ use think\Model;
 
 /**
  * @property Orders orders
+ * @property User user
  */
 class OrderVoucher extends Model
 {
@@ -14,6 +15,9 @@ class OrderVoucher extends Model
     public function orders(){
         return $this->belongsTo(Orders::class,'order_id');
     }
+    public function user(){
+        return $this->belongsTo(User::class);
+    }
 
     public function makeAudit($pass){
         $this['status']=$pass;
@@ -23,6 +27,10 @@ class OrderVoucher extends Model
                 $order->makePay();
             }
         }
+        SiteMsg::sendMsg(
+            $pass?SiteMsg::TYPE_ORDER_OFFLINE_PAY_PASS:SiteMsg::TYPE_ORDER_OFFLINE_PAY_REJECT,
+            $this->user
+        );
         $this->save();
     }
 }

+ 9 - 0
application/common/model/Refund.php

@@ -8,6 +8,7 @@ use think\Model;
 /**
  * 短信验证码
  * @property Orders orders
+ * @property User user
  */
 class Refund Extends Model
 {
@@ -70,6 +71,9 @@ class Refund Extends Model
     public function orders(){
         return $this->belongsTo(Orders::class,'order_id');
     }
+    public function user(){
+        return $this->belongsTo(User::class);
+    }
     public function allowCancel(){
         return in_array($this['refund_status'],[
             self::REFUND_ING,
@@ -129,6 +133,11 @@ class Refund Extends Model
                 $refund->pay();
             }
         }
+
+        SiteMsg::sendMsg(
+            $pass?SiteMsg::TYPE_ORDER_REFUND_PASS:SiteMsg::TYPE_ORDER_REFUND_REJECT,
+            $this->user
+        );
     }
 
 

+ 38 - 7
application/common/model/SiteMsg.php

@@ -13,8 +13,8 @@ class SiteMsg extends Model
     protected $autoWriteTimestamp=true;
     protected $updateTime=null;
     const TYPE_COUPON='coupon';
-    const TYPE_ORDER_PAY_PASS='order_pay_pass';
-    const TYPE_ORDER_PAY_REJECT='order_pay_reject';
+    const TYPE_ORDER_OFFLINE_PAY_PASS='order_offline_pay_pass';
+    const TYPE_ORDER_OFFLINE_PAY_REJECT='order_offline_pay_reject';
     const TYPE_ORDER_REFUND_PASS='order_refund_pass';
     const TYPE_ORDER_REFUND_REJECT='order_refund_reject';
     const TYPE_NEW_GOODS='new_goods';
@@ -28,15 +28,46 @@ class SiteMsg extends Model
         });
     }
 
-    public static function sendMsg($msgType,$user,$title=null,$content=null){
-
+    public static function sendMsg($msgType,$user,$extend=[]){
+        list($title,$content)=self::getTitleByType($msgType,$extend);
+        if($title && $content){
+            return self::create([
+                'msg_type'=>$msgType,
+                'user_id'=>$user instanceof User?$user['id']:$user,
+                'title'=>$title,
+                'content'=>$content,
+            ]);
+        }
     }
 
-    public static function getTitleByType($type){
-        $arr=[];
+    public static function getTitleByType($type,$extend=[]){
+        $arr=['',''];
         switch ($type){
             case self::TYPE_COUPON:
-                $arr[0]='';
+                $arr[0]='您获得了新的优惠券';
+                $arr[1]='您获得了新的优惠券券,请注意查收';
+                break;
+            case self::TYPE_ORDER_OFFLINE_PAY_PASS:
+                $arr[0]='您的线下付款核销已通过';
+                $arr[1]='您的线下付款核销已通过,请注意查看';
+                break;
+            case self::TYPE_ORDER_OFFLINE_PAY_REJECT:
+                $arr[0]='您的线下付款核销未通过';
+                $arr[1]='您的线下付款核销未通过,请注意查看';
+                break;
+            case self::TYPE_ORDER_REFUND_PASS:
+                $arr[0]='您申请的退货退款已通过';
+                $arr[1]='您申请的退货退款已通过,请注意查看';
+                break;
+            case self::TYPE_ORDER_REFUND_REJECT:
+                $arr[0]='您申请的退货退款未通过';
+                $arr[1]='您申请的退货退款未通过,请注意查看';
+                break;
+            case self::TYPE_NEW_GOODS:
+                $arr[0]='有新产品上新啦';
+                $arr[1]='有新产品上新啦,请注意查看';
+                break;
         }
+        return $arr;
     }
 }