xieruidong 2 years ago
parent
commit
b164a5359a

+ 84 - 0
app/data/controller/api/auth/Purchase.php

@@ -0,0 +1,84 @@
+<?php
+
+namespace app\data\controller\api\auth;
+
+use app\data\controller\api\Auth;
+use app\data\controller\api\Data;
+use app\data\model\DataCollectionLog;
+use app\data\model\DataPoolTalent;
+use app\data\model\DataRecruitment;
+use app\data\model\DataTeachingKnowledge;
+use app\data\model\DataUserApplyJobInfo;
+use app\data\model\DataUserApplyJobInfoChild;
+use app\data\model\ShopCoordination;
+use app\data\model\ShopOcean;
+use app\data\model\ShopProduction;
+use app\data\model\ShopPurchase;
+use app\data\service\MessageService;
+use think\admin\Storage;
+use think\db\Query;
+use think\exception\HttpResponseException;
+use think\admin\Controller;
+use hg\apidoc\annotation\Title;
+use hg\apidoc\annotation\Method;
+use hg\apidoc\annotation\Param;
+use hg\apidoc\annotation\Header;
+use hg\apidoc\annotation\Returned;
+use think\facade\Validate;
+use think\Request;
+
+/**
+ * @Title("采购订单")
+ */
+class Purchase extends Auth
+{
+    protected $noNeedLogin=[];
+
+
+    /**
+     * @Title("列表")
+     * @Method("get")
+     * @Param ("page",desc="第几页")
+     * @Param ("limit",desc="每页几条")
+     * @Param ("tab",desc="1采购2生产3外协4海运")
+     * @Param ("sort",desc="1按距离排序2按价格排序")
+     * @Param ("sort_dir",desc="asc正序,desc倒序")
+     * @Param ("longitude",desc="当前用户的经度")
+     * @Param ("latitude",desc="当前用户的纬度")
+     */
+    public function list(Request $request,ShopPurchase $shopPurchase,ShopCoordination $shopCoordination,ShopOcean $shopOcean,ShopProduction $shopProduction)
+    {
+        $this->_vali([
+            'longitude.require'=>'经度必须',
+            'latitude.require'=>'纬度必须',
+        ],'get');
+        switch ($request['tab']){
+            case 1:
+                $query=$shopPurchase->newQuery();
+                break;
+            case 2:
+                $query=$shopProduction->newQuery();
+                break;
+            case 3:
+                $query=$shopCoordination->newQuery();
+                break;
+            case 4:
+                $query=$shopOcean->newQuery();
+                break;
+            default:
+                $this->error('类型必须');
+        }
+        if($request['sort']==1){
+            $query
+                ->field("*,round(st_distance_sphere(point(120.012484,30.298926),point(`longitude`,`latitude`))) as distance")
+                ->order('distance',$request['sort_dir']);
+        }elseif ($request['sort']==2){
+            $query->order('amount',$request['sort_dir']);
+        }
+        $query->with(['merchant']);
+        $list=$query
+            ->paginate($request['limit']?:15);
+        $this->success('',$list);
+    }
+
+}

+ 4 - 0
app/data/controller/api/business/Purchase.php

@@ -62,6 +62,7 @@ class Purchase extends Controller
             'create_time'=>date('Y-m-d H:i:s'),
             'longitude'=>$admin_id->merchant->longitude,
             'latitude'=>$admin_id->merchant->latitude,
+            'amount'=>min(array_column($data['item'],'price')),
         ];
         Db::startTrans();
         try {
@@ -131,6 +132,7 @@ class Purchase extends Controller
             'post_address'=>$data['post_address'],
             'longitude'=>$admin_id->merchant->longitude,
             'latitude'=>$admin_id->merchant->latitude,
+            'amount'=>min(array_column($data['item'],'price')),
             'create_time'=>date('Y-m-d H:i:s')
         ];
         Db::startTrans();
@@ -195,6 +197,7 @@ class Purchase extends Controller
             'file'=>$data['file'],
             'longitude'=>$admin_id->merchant->longitude,
             'latitude'=>$admin_id->merchant->latitude,
+            'amount'=>min(array_column($data['item'],'price')),
             'create_time'=>date('Y-m-d H:i:s')
         ];
         Db::startTrans();
@@ -259,6 +262,7 @@ class Purchase extends Controller
             'post_address'=>$data['post_address'],
             'longitude'=>$admin_id->merchant->longitude,
             'latitude'=>$admin_id->merchant->latitude,
+            'amount'=>min(array_column($data['item'],'price')),
             'create_time'=>date('Y-m-d H:i:s')
         ];
         Db::startTrans();

+ 3 - 1
app/data/model/ShopCoordination.php

@@ -6,5 +6,7 @@ use think\admin\Model;
 
 class ShopCoordination extends Model
 {
-
+    public function merchant(){
+        return $this->belongsTo(DataMerchants::class,'admin_id','admin_id');
+    }
 }

+ 3 - 0
app/data/model/ShopOcean.php

@@ -6,5 +6,8 @@ use think\admin\Model;
 
 class ShopOcean extends Model
 {
+    public function merchant(){
+        return $this->belongsTo(DataMerchants::class,'admin_id','admin_id');
+    }
 
 }

+ 3 - 0
app/data/model/ShopProduction.php

@@ -7,4 +7,7 @@ use think\admin\Model;
 class ShopProduction extends Model
 {
 
+    public function merchant(){
+        return $this->belongsTo(DataMerchants::class,'admin_id','admin_id');
+    }
 }

+ 3 - 1
app/data/model/ShopPurchase.php

@@ -6,5 +6,7 @@ use think\admin\Model;
 
 class ShopPurchase extends Model
 {
-
+    public function merchant(){
+        return $this->belongsTo(DataMerchants::class,'admin_id','admin_id');
+    }
 }

+ 1 - 0
config/apidoc.php

@@ -47,6 +47,7 @@ return [
                     \app\data\controller\api\Xw::class,
                     \app\data\controller\api\ResCenter::class,
                     \app\data\controller\api\Bidding::class,
+                    \app\data\controller\api\auth\Purchase::class,