Browse Source

录入员

afa 5 tháng trước cách đây
mục cha
commit
de55bd427b

+ 4 - 2
app/admin/controller/user/Index.php

@@ -59,8 +59,9 @@ class Index extends Backend
         $result = false;
         Db::startTrans();
         try {
-            $params['salt'] = str_rand(4);
-            $params['password']= md5(md5($params['password'].$params['salt'])) ;
+            $params['salt']   = str_rand(4);
+            $params['password']= md5(md5($params['password'].$params['salt']));
+            $params['avatar']  = empty($params['avatar'])? request()->domain().'/assets/img/logo.jpg': $params['avatar'];//默认头像
             $result = $this->model->save($params);
             if($this->callback){
                 $callback=$this->callback;
@@ -124,6 +125,7 @@ class Index extends Backend
             }else{
                 unset($params['password']);
             }
+            $params['avatar']  = empty($params['avatar'])? request()->domain().'/assets/img/logo.jpg': $params['avatar'];//默认头像
             $result = $row->save($params);
             if($this->callback){
                 $callback=$this->callback;

+ 30 - 15
app/api/controller/MoneyLog.php

@@ -53,7 +53,6 @@ class MoneyLog extends Base
                   $day = getDaysOfYear($time);
                   $result['day_expenditure'] = ($result['expenditure'] > 0)? bcdiv($result['expenditure'], $day, 2): 0;
             }
-           
             $this->success('ok', $result);
       }
 
@@ -91,20 +90,15 @@ class MoneyLog extends Base
             $result = false;
             Db::startTrans();
             try {
-                validate(MoneyValidate::class)->scene('edit')->check($data);
-
-                $rows = $monuyModel
-                    ->where('id', $data['id'])
-                    ->where('user_id', $this->userinfo['id'])
-                    ->whereDay('createtime')
-                    ->where('status', $monuyModel::STATUS_NORMAL)
-                    ->find();
-                if(!$rows) $this->error('数据不存在');
-                $data['create_month'] = date('Ym', strtotime($data['create_date']));;//更新月份
-                //保存数据
-                $result = $rows->save($data);
-
-                Db::commit();
+                  validate(MoneyValidate::class)->scene('edit')->check($data);
+                  
+                  $rows = $monuyModel->where('id', $data['id'])->where('user_id', $this->userinfo['id'])->whereDay('createtime')->where('status', $monuyModel::STATUS_NORMAL)->find();
+                  if(!$rows) $this->error('数据不存在');
+                  //发货数据
+                  $data['create_month'] = date('Ym', strtotime($data['create_date']));;//创建月份
+                  $result = $rows->save($data);
+
+                  Db::commit();
             }catch (ValidateException $e) {
                   Db::rollback();
                   return $this->error($e->getError());
@@ -141,6 +135,27 @@ class MoneyLog extends Base
             $this->success();
       }
 
+
+      //支收总览
+      public function getCountAll(MonuyModel $monuyModel)
+      {   
+
+            $type = $this->request->post('type/d', 0); //1月 2年 3自定义
+            $time = $this->request->post('time/s', '');
+            $uids = $this->request->post('user_ids/s', '');
+            //支收
+            $count = $monuyModel::getCountAllBalance($type, $time, $uids);
+
+            //记账账户余额
+            $user = $monuyModel::getCountAllUserBalance($type, $time, $uids);
+            
+            //月统计
+            $month = $monuyModel::getCountAllMonthBalance($type, $time, $uids);
+         
+            $this->success('ok', compact('count', 'user', 'month'));
+      }
+
+
       /**
      * @return void 全部类型图标
       */

+ 7 - 0
app/api/controller/User.php

@@ -81,4 +81,11 @@ class User extends Base
         MysqlAdapter::logout($this->userinfo['id']);
         return  $this->success('ok');
     }
+
+    //获取全部人员
+    public function getAllUser(UserModel $userModel)
+    {
+        $list = $userModel->where('status', 'normal')->field('id,nickname,avatar')->select();
+        return $this->success('ok', $list);
+    }
 }

+ 6 - 0
app/api/route/route.php

@@ -60,6 +60,12 @@ Route::group('user', function () {
     //记账统计每天
     Route::rule('getMoneyCountDay','MoneyLog/getCountDay','POST');
 
+    //获取全部人员
+    Route::rule('getAllUser','User/getAllUser','POST');
+    //支收总览
+    Route::rule('getMoneyCountAll','MoneyLog/getCountAll','POST');
+
+
   })->middleware(AllowCrossDomain::class);
 
 

+ 61 - 1
app/common/model/MoneyLog.php

@@ -63,7 +63,6 @@ class MoneyLog Extends Model
 
     //按照类型年统计 收入- 支出
     public static function getCountYearBalance(string $time = '')
-
     {
         $income = self::where('type', self::TYPE_INCOME)->where('status', self::STATUS_NORMAL);
         if(!empty($time)){
@@ -96,5 +95,66 @@ class MoneyLog Extends Model
         return $list;
     }
 
+    //支收总览
+    public static function getCountAllBalance(int $type, string $time = '', string $user_ids='')
+    {
+        $list = self::where('status', self::STATUS_NORMAL);
+        if($type == 1 && !empty($time)) $list = $list->whereMonth('create_date', $time);
+        if($type == 2 && !empty($time)) $list = $list->whereYear('create_date', $time);
+        if($type == 3 && !empty($time)){
+            $expTime = explode(',', $time);
+            $list = $list->whereTime('create_date', [$expTime[0], $expTime[1]]);
+        }
+        if(!empty($user_ids)) $list = $list->whereIn('user_id', $user_ids);
+        $list = $list
+                ->field('type, sum(if(type=1,`change`,0)) as income, sum(if(type=2,`change`, 0)) as expenditure')
+                ->group('type')
+                ->select();
+        return $list;
+    }
+
+
+    //统计用户余额
+    public static function getCountAllUserBalance(int $type, string $time = '', string $user_ids='')
+    {
+        $list = self::alias('a')
+            ->join('user b', 'a.user_id=b.id')
+            ->where('a.status', self::STATUS_NORMAL);
+
+        if($type == 1 && !empty($time)) $list = $list->whereMonth('create_date', $time);
+        if($type == 2 && !empty($time)) $list = $list->whereYear('create_date', $time);
+        if($type == 3 && !empty($time)){
+            $expTime = explode(',', $time);
+            $list = $list->whereTime('create_date', [$expTime[0], $expTime[1]]);
+        }
+        if(!empty($user_ids)) $list = $list->whereIn('user_id', $user_ids);
+        $list = $list
+                ->field('a.user_id, sum(if(a.type=1,`change`,0)) as income, sum(if(a.type=2,`change`, 0)) as expenditure,b.nickname,b.avatar')
+                ->group('user_id')
+                ->select();
+        return $list;
+    }
+
+    //统计所有月统计
+    public static function getCountAllMonthBalance(int $type, string $time = '', string $user_ids='')
+    {
+        $list = self::where('status', self::STATUS_NORMAL);
 
+        if($type == 1 && !empty($time)) $list = $list->whereMonth('create_date', $time);
+        //年
+        if($type == 2 && !empty($time)) $list = $list->whereYear('create_date', $time);
+        //自定义
+        if($type == 3 && !empty($time)){
+            $expTime = explode(',', $time);
+            $list = $list->whereTime('create_date', [$expTime[0], $expTime[1]]);
+        }
+        if(!empty($user_ids)) $list = $list->whereIn('user_id', $user_ids);
+        //月
+        $list = $list
+            ->field('create_month, sum(if(type=1,`change`,0)) as income, sum(if(type=2,`change`, 0)) as expenditure')
+            ->group('create_month')
+            ->order('create_month desc')
+            ->select();
+        return $list;
+    }
 }

BIN
public/assets/img/logo.jpg