afa 5 сар өмнө
parent
commit
3a11bdf420

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

@@ -60,7 +60,7 @@ class Index extends Backend
         Db::startTrans();
         try {
             $params['salt'] = str_rand(4);
-            $params['password']= md5(md5($params['salt'].$params['password'])) ;
+            $params['password']= md5(md5($params['password'].$params['salt'])) ;
             $result = $this->model->save($params);
             if($this->callback){
                 $callback=$this->callback;
@@ -120,7 +120,7 @@ class Index extends Backend
         try {
            if(!empty($params['password'])) {
                 $params['salt'] = str_rand(4);
-                $params['password']= md5(md5($params['salt'].$params['password'])) ;
+                $params['password']= md5(md5($params['password'].$params['salt'])) ;
             }
             $result = $row->save($params);
             if($this->callback){

+ 79 - 0
app/api/controller/Inventory.php

@@ -0,0 +1,79 @@
+<?php
+
+namespace app\api\controller;
+
+use app\api\service\auth\MysqlAdapter;
+use app\api\service\auth\ApiAuthService;
+use app\api\validate\User as UserValidate;
+use think\exception\ValidateException;
+use think\facade\Db;
+
+class Inventory extends Base
+{
+
+
+
+    //出入库
+    public function stock()
+    {
+
+        
+        $data = $this->request->post();
+        $result = false;
+        Db::startTrans();
+        try {
+           
+            validate(ShopValidate::class)->scene('add')->check($data);
+
+            $data['user_id'] = $this->userinfo['id'];
+            $data['variety'] = json_encode($data['variety'], JSON_UNESCAPED_UNICODE);
+            $result = $userEnterLog::create($data);
+
+            Db::commit();
+        }catch (ValidateException $e) {
+      
+            return $this->error($e->getError());
+        } catch (\Exception $e) {
+            Db::rollback();
+            $this->error($e->getMessage());
+        }
+        if ($result === false) {
+            $this->error(__('没有新增任何数据'));
+        }
+        $this->success();
+      
+    }
+
+
+    //出入库记录
+    public function stocklog(ApiAuthService $authService)
+    {
+        
+        $data = $this->request->post();
+        $result = false;
+        Db::startTrans();
+        try {
+           
+            validate(ShopValidate::class)->scene('add')->check($data);
+
+            $data['user_id'] = $this->userinfo['id'];
+            $data['variety'] = json_encode($data['variety'], JSON_UNESCAPED_UNICODE);
+            $result = $userEnterLog::create($data);
+
+            Db::commit();
+        }catch (ValidateException $e) {
+      
+            return $this->error($e->getError());
+        } catch (\Exception $e) {
+            Db::rollback();
+            $this->error($e->getMessage());
+        }
+        if ($result === false) {
+            $this->error(__('没有新增任何数据'));
+        }
+        $this->success();
+    }
+
+
+   
+}

+ 25 - 24
app/api/controller/Shops.php

@@ -2,13 +2,13 @@
 
 namespace app\api\controller;
 
-use app\common\model\ApiUser;
-use app\common\model\Orders;
+use app\common\model\UserEnterLog;
+use app\api\validate\Shop as ShopValidate;
 use app\common\model\ShopList;
 use think\facade\Db;
 use think\Exception;
 use think\facade\Request;
-use think\Log;
+use think\exception\ValidateException;
 
 class Shops extends Base
 {
@@ -47,29 +47,30 @@ class Shops extends Base
     }
 
 
-    function doCurlPostRequest($url = '',Array $data = array())
+    //添加记录
+    public function create(UserEnterLog $userEnterLog)
     {
-        $data_string = json_encode($data,JSON_UNESCAPED_UNICODE);
-        // $data_string = $data;
-        $curl_con = curl_init();
-        curl_setopt($curl_con, CURLOPT_URL,$url);
-        curl_setopt($curl_con, CURLOPT_HEADER, false);
-        curl_setopt($curl_con, CURLOPT_POST, true);
-        curl_setopt($curl_con, CURLOPT_RETURNTRANSFER, TRUE);
-        curl_setopt($curl_con, CURLOPT_CONNECTTIMEOUT, 5);
-        curl_setopt($curl_con, CURLOPT_HTTPHEADER, array(
-                'Content-Type: application/json',
-                'Content-Length: ' . strlen($data_string))
-        );
-        curl_setopt($curl_con, CURLOPT_POSTFIELDS, $data_string);
-        $res = curl_exec($curl_con);
-        $status = curl_getinfo($curl_con);
-        curl_close($curl_con);
+    
+        $data = $this->request->post();
+        $result = false;
+        try {
+            validate(ShopValidate::class)->scene('add')->check($data);
 
-        if (isset($status['http_code']) && $status['http_code'] == 200) {
-            return $res;
-        } else {
-            return FALSE;
+            $data['user_id'] = $this->userinfo['id'];
+            $data['variety'] = json_encode($data['variety'], JSON_UNESCAPED_UNICODE);
+            $result = $userEnterLog::create($data);
+            
+        }catch (ValidateException $e) {
+            return $this->error($e->getError());
+        } catch (\Exception $e) {
+            $this->error($e->getMessage());
         }
+        if ($result === false) {
+            $this->error(__('没有新增任何数据'));
+        }
+        $this->success();
+
     }
+
+ 
 }

+ 2 - 2
app/api/middleware/AllowCrossDomain.php

@@ -14,7 +14,7 @@ class AllowCrossDomain
                 ->header([
                     'Access-Control-Allow-Origin' => '*', // 或具体域名
                     'Access-Control-Allow-Methods' => 'GET,POST,PUT,DELETE,OPTIONS',
-                    'Access-Control-Allow-Headers' => 'Content-Type,Authorization,Accept-Language',
+                    'Access-Control-Allow-Headers' => 'Content-Type,Authorization,Accept-Language,token',
                     'Access-Control-Max-Age' => '86400',
                 ]);
         }
@@ -26,7 +26,7 @@ class AllowCrossDomain
         $response->header([
             'Access-Control-Allow-Origin' => '*', // 或 'https://sz-test-3.hxiaoju.top'
             'Access-Control-Allow-Methods' => 'GET,POST,PUT,DELETE,OPTIONS',
-            'Access-Control-Allow-Headers' => 'Content-Type,Authorization,Accept-Language',
+            'Access-Control-Allow-Headers' => 'Content-Type,Authorization,Accept-Language,token',
             'Access-Control-Max-Age' => '86400',
         ]);
 

+ 18 - 9
app/api/route/route.php

@@ -8,18 +8,27 @@ use app\api\middleware\AllowCrossDomain;
 Route::group('user', function () {
 
      
-      Route::rule('login','user/login','POST');
-      Route::rule('userinfo','user/userinfo','GET|POST');
-      Route::rule('logout','user/logout','GET|POST');
+    Route::rule('login','user/login','POST');
+    Route::rule('userinfo','user/userinfo','GET|POST');
+    Route::rule('logout','user/logout','GET|POST');
 
-      //平台
-      Route::rule('platform','shops/getPlatform','POST');
+    //平台
+    Route::rule('platform','shops/getPlatform','POST');
 
-      //店铺
-      Route::rule('shops','shops/getShop','POST');
+    //店铺
+    Route::rule('shops','shops/getShop','POST');
 
-      //规格
-      Route::rule('specs','shops/getSpec','POST');
+    //规格
+    Route::rule('specs','shops/getSpec','POST');
+
+    //添加记录
+    Route::rule('create','shops/create','POST');
+
+    //出入库
+    Route::rule('stock','inventory/stock','POST');
+
+    //库存记录
+    Route::rule('stocklog','inventory/stocklog','POST');
 
   })->middleware(AllowCrossDomain::class);
 

+ 25 - 0
app/api/validate/Shop.php

@@ -0,0 +1,25 @@
+<?php
+namespace app\api\validate;
+
+use think\Validate;
+
+class Shop extends Validate
+{
+    protected $rule =   [
+        'plat_id'  => 'require|number',
+        'shop_id'  => 'require|number',
+        'variety' => 'require',    
+    ];
+    
+    protected $message  =   [
+        'plat_id'      => '参数有误',
+        'shop_id'     => '参数有误',
+        'variety'     => '参数有误',    
+    ];
+
+
+ 
+    protected $scene = [
+        'add'  =>  ['plat_id','shop_id','variety'],
+    ]; 
+}

+ 15 - 0
app/common/model/UserEnterLog.php

@@ -0,0 +1,15 @@
+<?php
+declare(strict_types=1);
+
+namespace app\common\model;
+
+use think\Model;
+
+class UserEnterLog Extends Model
+{
+
+
+
+    
+
+}