xieruidong il y a 2 ans
Parent
commit
a0bcb5737a

+ 7 - 5
application/api/controller/User.php

@@ -5,6 +5,8 @@ use app\admin\model\Admin;
 use app\common\controller\Api;
 use app\common\library\Sms;
 use app\common\model\Area;
+use app\common\model\SiteMsg;
+use app\common\model\SiteMsgRead;
 use app\common\model\UserLoginRange;
 use app\common\service\PayTransPerSvc;
 use app\common\service\WxOpenService;
@@ -73,11 +75,11 @@ class User extends Api
                 'userinfo',
             ]);
         $nums=[];
-        $nums['svc_processing']=0;
-        $nums['svc_complete']=0;
-        $nums['coupon']=0;
-        $nums['site_msg_read']=0;
-        $nums['site_msg_unread']=0;
+        $nums['svc_processing']=$user->refund()->filterRefund(1)->count();
+        $nums['svc_complete']=$user->refund()->filterRefund(2)->count();;
+        $nums['coupon']=$user->coupon()->filterUse()->count();
+        $nums['site_msg_read']=SiteMsgRead::where('user_id',$user['id'])->count();
+        $nums['site_msg_unread']=SiteMsg::filterUnread($user['id'])->count();
         $user['nums']=$nums;
         $this->success('', $user);
     }

+ 10 - 3
application/common/model/Refund.php

@@ -11,7 +11,7 @@ use think\Model;
  * @property Orders orders
  * @property User user
  * @property int refund_status
- * @method static static|Query FilterRefund()
+ * @method static static|Query FilterRefund($status=null)
  * @method static static|Query FilterTs()
  */
 class Refund Extends Model
@@ -198,9 +198,16 @@ class Refund Extends Model
     /**
      * 售后中及已售后的
      * @param Query $query
+     * @param null $status 1进行中2已完成
      */
-    public function scopeFilterRefund(Query $query){
-        $query->whereBetween("{$this->getTable()}.refund_status",[self::REFUND_ING,self::REFUND_PASS]);
+    public function scopeFilterRefund(Query $query,$status=null){
+        if(is_null($status)) {
+            $query->whereBetween("{$this->getTable()}.refund_status", [self::REFUND_ING, self::REFUND_PASS]);
+        }elseif ($status==1){
+            $query->where("{$this->getTable()}.refund_status", self::REFUND_ING);
+        }elseif ($status==2){
+            $query->where("{$this->getTable()}.refund_status", self::REFUND_PASS);
+        }
     }
 
     /**

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

@@ -2,6 +2,7 @@
 
 namespace app\common\model;
 
+use think\Db;
 use think\db\Query;
 use think\Model;
 use think\model\relation\HasMany;
@@ -9,6 +10,7 @@ use Yansongda\Supports\Arr;
 
 /**
  * @method static Query|static hot($hot=1)
+ * @method static Query|$this filterUnread($userId)
  */
 class SiteMsg extends Model
 {
@@ -49,6 +51,13 @@ class SiteMsg extends Model
         }
     }
 
+    public function scopeFilterUnread(Query $query,$userId){
+        $query->whereNotExists(
+            SiteMsgRead::where('site_msg_id',Db::raw("{$this->getTable()}.id"))->where('user_id',$userId)->buildSql()
+        )
+            ->whereIn('user_id',[0,$userId]);
+    }
+
     public static function getTitleByType($type,$extend=[]){
         $arr=['','',null];
         switch ($type){

+ 3 - 0
application/common/model/User.php

@@ -242,6 +242,9 @@ class User extends Model
     public function cart(){
         return $this->hasMany(GoodsCart::class);
     }
+    /**
+     * @return UserCoupon
+     */
     public function coupon(){
         return $this->hasMany(UserCoupon::class);
     }

+ 7 - 1
application/common/model/UserCoupon.php

@@ -5,7 +5,9 @@ namespace app\common\model;
 use think\db\Query;
 use think\Model;
 
-
+/**
+ * @method Query|$this filterUse($used=1)
+ */
 class UserCoupon extends Model
 {
     protected $autoWriteTimestamp=true;
@@ -53,6 +55,10 @@ class UserCoupon extends Model
             ->where('time_end','>',$time);
     }
 
+    public function scopeFilterUse(Query $query,$used=1){
+        $query->where('is_use',$used);
+    }
+
     public function needMax(){
         return $this->getAttr('type')==Coupon::T_FULL;
     }