Kaynağa Gözat

获取广告订单金额及获取广告订单列表排序

15313670163 4 ay önce
ebeveyn
işleme
e00fcc7b0a

+ 35 - 18
app/JsonRpc/OrderService.php

@@ -492,6 +492,38 @@ class OrderService implements OrderServiceInterface
         return Result::success($result);
     }
     /**
+     * 获取广告金额
+     * @param
+     * @return void
+     */
+    public function getPrice(array $data): array
+    {
+        // $data['pid'] = [
+        //     0 => 11,
+        //     1 => 12
+        // ];
+        $startTime = strtotime($data['starttime']);
+        $endTime = strtotime($data['endtime']);
+        $con_time = ($endTime - $startTime) / (24 * 60 * 60);
+        $days = round($con_time, 2);    //计算共计多少天
+        $price = 0;
+        if(is_array($data['pid'])){
+            $ad_price = AdPlace::whereIn('id', $data['pid'])->select('id','price')->get();
+            foreach($ad_price as $v){
+                $price += number_format($v['price']*$days, 2, '.', '');
+            }
+            // var_dump("222222222222222222",$ad_price);
+        }elseif(is_numeric($data['pid'])){
+            $ad_price = AdPlace::where('id',$data['pid'])->first();
+            $price = number_format($ad_price['price']*$days, 2, '.', '');
+            // var_dump($price);
+        }else{
+            $price = 0;
+            // var_dump("333333333333333333",$price);
+        }
+        return Result::success($price);
+    }
+    /**
      * 添加广告订单
      * @param
      * @return void
@@ -503,8 +535,7 @@ class OrderService implements OrderServiceInterface
         $startTime = strtotime($data['starttime']);
         $endTime = strtotime($data['endtime']);
         $con_time = ($endTime - $startTime) / (24 * 60 * 60);
-        $roundedValue = round($con_time, 2);
-        $days = number_format($roundedValue, 2, '.', '');
+        $days = round($con_time, 2);//计算共计多少天
         $timestamp = date('YmdHis', $time);
         $catetime = date('Y-m-d H:i:s', $time);
         $randomNumber = mt_rand(1000, 9999);
@@ -524,6 +555,7 @@ class OrderService implements OrderServiceInterface
                 'width' => $order_size['width'],
                 'height' => $order_size['height'],
                 'days' => $days,
+                'price' => $data['price'],
                 'created_at' => date('Y-m-d H:i:s', time()),
                 'updated_at' => date('Y-m-d H:i:s', time()),
 
@@ -545,14 +577,6 @@ class OrderService implements OrderServiceInterface
                         'pid' => $ads['id'],
                         'website_id' => $ads['website_id'],
                     ];
-                    // $log = [
-                    //     'order_id' => $orderid,
-                    //     'user_id' => $data['user_id'],
-                    //     'pid' => $ads['id'],
-                    //     'website_id' => $ads['website_id'],
-                    //     'action' => '添加',
-                    //     'time' => $catetime
-                    // ];
                 }
             } else {
 
@@ -569,14 +593,6 @@ class OrderService implements OrderServiceInterface
                     'created_at' => date('Y-m-d H:i:s', time()),
                     'updated_at' => date('Y-m-d H:i:s', time()),
                 ];
-                // $log = [
-                //     'order_id' => $orderid,
-                //     'user_id' => $data['user_id'],
-                //     'pid' => $adplace,
-                //     'website_id' => $ads['website_id'],
-                //     'action' => '添加',
-                //     'time' => $catetime
-                // ];
             }
             $orderad_id = OrderAd::insert($order_ad);
             Db::commit();
@@ -611,6 +627,7 @@ class OrderService implements OrderServiceInterface
         $orders = Order::where($where) 
         ->limit($data['pageSize'])
         ->offset(($data['page'] - 1) * $data['pageSize'])
+        ->orderBy("updated_at", "desc")
         ->get()->all();
         //订单状态:1:通过;2:驳回;3:撤回;4:修改;5:过期;6:待审核;7:结束
         $status = [1,4,5,7];

+ 12 - 0
app/JsonRpc/OrderServiceInterface.php

@@ -22,6 +22,18 @@ interface OrderServiceInterface
 
     public function getOrderListAdmin(array $data): array;
 
+    
+    /**
+     * @param array $data
+     *  @return array
+     */
+
+     public function getPrice(array $data): array;
+
+    /**
+     * @param array $data
+     *  @return array
+     */
     public function addAD(array $data): array;
 
     /**