Преглед изворни кода

采购管理小程序,供应商报价数据

haozi пре 5 година
родитељ
комит
3082448a81

+ 1 - 1
app/Http/Controllers/ProcurementController.php

@@ -174,7 +174,7 @@ class ProcurementController extends Controller
             $procurement=Procurement::query()->find($param['id']);
             $unit_price=$param['unit_price'];
             if (!$unit_price){
-                $priceCoefficient=Configuration::query()->where('name','priceCoefficient')->value('value');
+                $priceCoefficient=Configuration::query()->where('name','价格系数')->value('value');
                 $unit_price=$priceCoefficient*$param['offer'];
             }
             $procurement->update([

+ 19 - 0
app/Http/Controllers/TestController.php

@@ -118,6 +118,7 @@ use Illuminate\Support\Facades\Storage;
 use Illuminate\Support\Str;
 use Maatwebsite\Excel\Facades\Excel;
 use Mockery\Mock;
+use Overtrue\LaravelPinyin\Facades\Pinyin;
 use PhpMyAdmin\Server\Status\Data;
 use Ramsey\Collection\Collection;
 use Zttp\Zttp;
@@ -1656,4 +1657,22 @@ where (commodities.owner_id,commodity_barcodes.code) in (select commodities.owne
             $orderService->syncOrder($item);
         }
     }
+
+    public function testUser()
+    {
+//        $now=Carbon::now()->toDateTimeString();
+//        $procurementQuotations=ProcurementQuotation::query()
+//            ->with('procurement.ownerMaterial.material')
+//            ->where('status',0)
+//            ->whereNull('offer')
+//            ->where('created_at','>=',Carbon::parse($now)->subHours(4))
+//            ->where('created_at','<=',$now)
+//            ->get();
+//        foreach ($procurementQuotations as $procurementQuotation){
+//            $procurementQuotation->append('time',4);
+//        }
+//        dd($procurementQuotations->toJson());
+        $pinyinOwnerName=Pinyin::convert('MEE');
+        dd($pinyinOwnerName);
+    }
 }

+ 11 - 3
app/Http/Controllers/api/procurement/wechat/AuthController.php

@@ -3,6 +3,7 @@
 namespace App\Http\Controllers\api\procurement\wechat;
 
 use App\UserDetail;
+use http\Client\Curl\User;
 use Illuminate\Support\Facades\Auth;
 use App\Http\Controllers\Controller;
 
@@ -34,17 +35,24 @@ class AuthController extends Controller
     {
         $phone=request('phone');
         $user_id=UserDetail::query()->where('mobile_phone',$phone)->value('user_id');
+        if (!$user_id) return response()->json(['status'=>0,'error' => '当前用户不存在!'], 401);
+        $supplierUser=\App\User::query()->whereHas('roles',function($query){
+            $query->where('name','供应商');
+        })->find($user_id);
+        $receiveUser=\App\User::query()->whereHas('roles',function($query){
+            $query->where('name','供应商');
+        })->find($user_id);
+        if (!$supplierUser && !$receiveUser) return response()->json(['status'=>0,'message' => '当前用户没有指定角色,暂不可登录!'], 401);
         $credentials = [
             'id'=>$user_id,
             'password'=>request('password')
         ];
 
-
         if (! $token = auth('api')->attempt($credentials)) {
-            return response()->json(['error' => '很抱歉,您的手机号和密码不匹配'], 401);
+            return response()->json(['status'=>0,'message' => '很抱歉,您的手机号和密码不匹配'], 401);
         }
 
-        return $this->respondWithToken($token);
+        return response()->json(['status'=>1,'message' => $supplierUser?'1':'2','data'=>$token], 200);
     }
 
     /**

+ 26 - 0
app/Http/Controllers/api/procurement/wechat/ProcurementController.php

@@ -0,0 +1,26 @@
+<?php
+
+namespace App\Http\Controllers\api\procurement\wechat;
+
+use App\Http\Controllers\Controller;
+use App\ProcurementQuotation;
+use Carbon\Carbon;
+use Illuminate\Support\Facades\Auth;
+
+class ProcurementController extends Controller
+{
+    public function getQuotation(){
+        $now=Carbon::now()->toDateTimeString();
+        $procurementQuotations=ProcurementQuotation::query()
+            ->with('procurement.ownerMaterial.material')
+            ->where('status',0)
+            ->whereNull('offer')
+            ->where('created_at','>=',Carbon::parse($now)->subHours(4))
+            ->where('created_at','<=',$now)
+            ->get();
+        foreach ($procurementQuotations as $procurementQuotation){
+            $procurementQuotation->append('time',4);
+        }
+        if (!empty($procurementQuotations))return response()->json(['status'=>1,'data'=>$procurementQuotations->toJson()], 200);
+    }
+}

+ 33 - 0
app/ProcurementQuotation.php

@@ -3,9 +3,12 @@
 namespace App;
 
 use App\Traits\ModelTimeFormat;
+use Illuminate\Database\Eloquent\Builder;
 use Illuminate\Database\Eloquent\Model;
 
 use App\Traits\ModelLogChanging;
+use Illuminate\Support\Facades\Auth;
+use Illuminate\Support\Facades\DB;
 
 class ProcurementQuotation extends Model
 {
@@ -16,7 +19,37 @@ class ProcurementQuotation extends Model
         'procurement_id','offer', 'operator', 'quoted_at','status','created_at','supplier_id'
     ];
 
+    const status=[
+        0 => "待报价",
+        1 => "待审核",
+        2 => "待接单",
+        3 => "已失效",
+        4 => "生成中",
+        5 => "待收货",
+        6 => "待确定",
+        7 => "待出账",
+        8 => "已出账",
+        9 => "完结",
+    ];
     public  function supplier(){
         return $this->hasOne('App\Supplier','id','supplier_id');
     }
+    public function procurement(){
+        return $this->belongsTo('App\Procurement','procurement_id','id');
+    }
+
+    protected static function booted()
+    {
+        /** @var User $user */
+        $user = Auth::user();
+        if ($user && !$user->isSuperAdmin()) {
+            /** @var \stdClass $user */
+            $ids = array_column(DB::select(DB::raw("SELECT supplier_id FROM supplier_user WHERE user_id = ?"),[$user->id]),"supplier_id");
+            if (count($ids)>0){
+                static::addGlobalScope('supplier', function (Builder $builder)use ($ids) {
+                    $builder->whereIn('supplier_id',  $ids);
+                });
+            }
+        }
+    }
 }

+ 3 - 2
app/Services/ProcurementService.php

@@ -14,6 +14,7 @@ class ProcurementService
 {
     use ServiceAppAop;
 
+    //选中最低报价
     public function screenLowestQuotation($procurement_id){
         if (!$procurement_id) return null;
         $procurementQuotation=ProcurementQuotation::query()->with('supplier')
@@ -27,11 +28,11 @@ class ProcurementService
         if (!empty($procurement->ownerMaterial->material->supplier))$suppliers=$procurement->ownerMaterial->material->supplier;
         foreach ($suppliers as $supplier){
             $procurementQuotation= new ProcurementQuotation([
-                'procurement_id'=>10,
+                'procurement_id'=>$procurement_id,
                 'supplier_id'=>$supplier->id,
             ]);
             $procurementQuotation->save();
-            //TODO 添加广播推送给指定供应商
+            //TODO 推送给指定耗材类型供应商
         }
     }
 }

+ 1 - 1
app/User.php

@@ -11,7 +11,7 @@ use Illuminate\Support\Facades\Gate;
 use App\Traits\ModelTimeFormat;
 use Tymon\JWTAuth\Contracts\JWTSubject;
 
-class User extends Authenticatable implements JWTSubject
+class User extends Authenticatable /*implements JWTSubject*/
 {
     use ModelLogChanging;
     use ModelTimeFormat;

+ 1 - 0
routes/api.php

@@ -20,5 +20,6 @@ Route::group(['prefix' => 'procurement','middleware'=>'procurement.auth.api'], f
 });
 Route::group(['prefix' => 'procurement'], function ($router) {
     Route::post('login', 'api\procurement\wechat\AuthController@login');
+    Route::get('getQuotation', 'api\procurement\wechat\ProcurementController@getQuotation');
 });