where("paid",1); $today = getModelTime($query, "today","pay_time") -> field("pay_price") -> select(); foreach($today as $value){ $todaySalesPrice += $value['pay_price']; } $todaySalesPrice = sprintf("%01.2f", $todaySalesPrice); $todaySalesNumber = count($today); $query1 = StoreGroupOrder::getDb() -> where("paid",1); $seven = getModelTime($query1, "lately7","pay_time") -> field("pay_price") -> select(); foreach($seven as $value){ $sevenSalesPrice += $value['pay_price']; } $sevenSalesPrice = sprintf("%01.2f", $sevenSalesPrice); $sevenSalesNumber = count($seven); $merchantNumber = Db::name("merchant") -> count(); $where=[ 'is_used'=>1, 'mer_status'=>1, 'is_show'=>1, 'is_hide'=>0, 'is_del' => 0 ]; $merchantProductNumber = Db::name("store_product") -> where($where) -> count(); $query2 = StoreGroupOrder::getDb() -> where("paid",1); $sales = $query2 -> field("pay_price") -> select(); foreach($sales as $value){ $salesPrice += $value['pay_price']; } $salesPrice = sprintf("%01.2f", $salesPrice); $salesNumber = count($sales); $refund = Db::name("store_refund_order") -> where("status",3) -> field("refund_price") -> select(); foreach($refund as $value){ $refundPrice += $value['refund_price']; } $refundPrice = sprintf("%01.2f", $refundPrice); $refundNumber = count($refund); return app('json')->success(compact( "todaySalesPrice", "todaySalesNumber", "sevenSalesPrice", "sevenSalesNumber", "merchantNumber", "merchantProductNumber", "salesPrice", "salesNumber", "refundPrice", "refundNumber" )); } //销量top20 public function sales_product_top(){ $where=[ 'is_used'=>1, 'mer_status'=>1, 'is_show'=>1, 'is_hide'=>0, 'is_del' => 0 ]; $top = Db::name('store_product') -> where($where) -> order("sales desc") -> field("product_id,store_name,cost as cost_price,spu_id,price,plate_mer_profit,sales") -> limit(20)-> select(); return app('json')->success($top); } //退款top20 public function refund_product_top(){ $top = Db::query("SELECT * FROM ( SELECT COUNT( order_product_id ) AS total, sp.product_id,sp.store_name,sp.cost as cost_price,sp.spu_id,sp.price,sp.plate_mer_profit,sp.sales FROM rrx_store_refund_product as srp JOIN rrx_store_refund_order as sro on srp.refund_order_id = sro.refund_order_id JOIN rrx_store_product as sp on sp.product_id = srp.order_product_id GROUP BY order_product_id ) AS new_refund_product ORDER BY total DESC LIMIT 20"); return app('json')->success($top); } }