afa 5 сар өмнө
parent
commit
a6c043b0c7

+ 11 - 6
app/api/controller/Inventory.php

@@ -57,17 +57,22 @@ class Inventory extends Base
         $type    = $this->request->post('type/s', '');
         $type_id = $this->request->post('type_id/s', '');
         $spec_id = $this->request->post('spec/s', '');
-        if(!empty($type))    $where['a.type'] = $type;
-        if(!empty($type_id)) $where['a.type_id'] = $type_id;
-        if(!empty($spec_id)) $where['a.variety_id'] = $spec_id;
-
+        $limit = $this->request->post('limit/d', 15);  //条数
+        $time = $this->request->post('create_time/s'); //日期
+        if(!empty($type))    $where[] = ['a.type', '=', $type];
+        if(!empty($type_id)) $where[] = ['a.type_id', '=',$type_id];
+        if(!empty($spec_id)) $where[] = ['a.variety_id', '=',$spec_id];
+        if(!empty($time)){
+            $arr = explode(',', $time);
+            $where[] = ['a.createtime', '>=', strtotime($arr[0])];
+            $where[] = ['a.createtime', '<=', strtotime($arr[1])];
+        }
         $list = $stockLog::alias('a')
                 ->leftjoin('stock_config b', 'a.variety_id = b.id')
                 ->where('a.user_id', $this->userinfo['id'])
                 ->where($where)
-                //->whereTime('a.createtime', '-2 days')
                 ->field('a.*,b.title')
-                ->select();
+                ->paginate($limit);
         $this->success('ok', $list);
     }
 

+ 56 - 0
app/api/controller/MoneyLog.php

@@ -0,0 +1,56 @@
+<?php
+
+namespace app\api\controller;
+
+use app\common\model\StockConfig;
+use app\common\model\ShopList;
+use app\common\model\StockLog;
+use think\exception\ValidateException;
+use app\api\validate\Stock as StockValidate;
+use app\common\model\StockDetail;
+use think\facade\Db;
+
+//记账记录表
+class MoneyLog extends Base
+{
+
+
+
+      //首页数据分组统计品种
+      public function index(StockLog $stockLog)
+      {
+            $data= $stockLog->where('user_id', $this->userinfo['id'])
+                              ->field('type,count(id) as count')
+                              ->group('type')
+                              ->select();
+            $this->success('ok', $data);
+      }
+
+      //记账
+      public function money(StockConfig $stockConfig, StockDetail $stockDetail)
+      {     
+
+
+
+            $result = [];
+            $list = $stockConfig->where('status', $stockConfig::StatusNormal)->field('id,type_id,title')
+            ->orderRaw("field('variety_name','packing_box','material')")->select();
+        
+            $this->success('ok', $result);
+      }
+
+
+      /**
+     * @return void 全部类型图标
+      */
+      public function getConfig()
+      {     
+            $type = $this->request->post('type/s', 'bank_account');
+            if(!in_array($type, ['bank_account', 'money_in_type', 'money_out_type'])) $this->error('参数有误');
+            $this->success('提交成功', site_config('addonsd.'.$type));
+      }
+
+   
+
+   
+}

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

@@ -42,6 +42,13 @@ Route::group('user', function () {
     //库存记录
     Route::rule('stocklog','inventory/stocklog','POST');
 
+    //记账
+    Route::rule('money','MoneyLog/money','POST');
+    //记账记录
+    Route::rule('moneylog','MoneyLog/moneylog','POST');
+    //记账类型配置
+    Route::rule('getMoneyType','moneyLog/getConfig','POST');
+
   })->middleware(AllowCrossDomain::class);
 
 

+ 32 - 0
app/common/model/MoneyLog.php

@@ -0,0 +1,32 @@
+<?php
+declare(strict_types=1);
+
+namespace app\common\model;
+
+use think\Model;
+
+class MoneyLog Extends Model
+{
+    // 自动写入时间戳字段
+    protected $autoWriteTimestamp = true;
+    protected $createTime = 'createtime';
+    protected $updateTime = 'updatetime';
+
+    protected $type = [
+        'createtime'     =>  'timestamp:Y-m-d H:i',
+        'updatetime'     =>  'timestamp:Y-m-d H:i',
+    ];
+
+    //
+    public function users()
+    {
+        return $this->hasOne(User::class,'id','user_id')->field('id,nickname');
+    }
+
+
+    public function stockconfig()
+    {
+        return $this->hasOne(StockConfig::class,'id','variety_id')->field('id,title');
+    }
+    
+}