From e7cf36928f66b39926643eb0c7f5bc1b62f207f8 Mon Sep 17 00:00:00 2001
From: mkm <727897186@qq.com>
Date: Wed, 17 Jul 2024 11:19:56 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E6=88=96=E4=BF=AE?=
 =?UTF-8?q?=E6=94=B9API=E4=BB=A5=E6=94=AF=E6=8C=81=E6=96=B0=E7=9A=84?=
 =?UTF-8?q?=E8=AE=A2=E5=8D=95=E5=88=9B=E5=BB=BA=E5=8A=9F=E8=83=BD=EF=BC=9B?=
 =?UTF-8?q?=20fix:=20=E4=BF=AE=E5=A4=8D=E5=9C=A8=E5=A4=84=E7=90=86?=
 =?UTF-8?q?=E7=94=9F=E9=B2=9C=E4=BA=A7=E5=93=81=E8=AE=A2=E5=8D=95=E6=97=B6?=
 =?UTF-8?q?=E7=9A=84=E5=BC=82=E5=B8=B8=EF=BC=9B=20refactor:=20=E9=87=8D?=
 =?UTF-8?q?=E6=9E=84=E4=BB=A3=E7=A0=81=E4=BB=A5=E4=BC=98=E5=8C=96=E6=80=A7?=
 =?UTF-8?q?=E8=83=BD=E5=92=8C=E5=8F=AF=E8=AF=BB=E6=80=A7=EF=BC=9B=20style:?=
 =?UTF-8?q?=20=E4=BB=A3=E7=A0=81=E9=A3=8E=E6=A0=BC=E8=B0=83=E6=95=B4?=
 =?UTF-8?q?=EF=BC=8C=E5=A2=9E=E5=8A=A0=E7=A9=BA=E6=A0=BC=E3=80=81=E6=A0=BC?=
 =?UTF-8?q?=E5=BC=8F=E5=8C=96=E3=80=81=E4=BF=AE=E5=A4=8D=E7=BC=BA=E5=A4=B1?=
 =?UTF-8?q?=E7=9A=84=E5=88=86=E5=8F=B7=E7=AD=89=EF=BC=9B=20test:=20?=
 =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=B5=8B=E8=AF=95=E4=BB=A5=E9=AA=8C=E8=AF=81?=
 =?UTF-8?q?=E6=96=B0=E8=AE=A2=E5=8D=95=E5=88=9B=E5=BB=BA=E5=8A=9F=E8=83=BD?=
 =?UTF-8?q?=E7=9A=84=E6=AD=A3=E7=A1=AE=E6=80=A7=EF=BC=9B=20docs:=20?=
 =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=9B=B8=E5=85=B3=E6=96=87=E6=A1=A3=EF=BC=8C?=
 =?UTF-8?q?=E5=A6=82README=EF=BC=9B=20build:=20=E6=9B=B4=E6=96=B0=E9=A1=B9?=
 =?UTF-8?q?=E7=9B=AE=E4=BE=9D=E8=B5=96=E6=88=96=E7=89=88=E6=9C=AC=EF=BC=9B?=
 =?UTF-8?q?=20ops:=20=E6=9B=B4=E6=96=B0=E5=9F=BA=E7=A1=80=E8=AE=BE?=
 =?UTF-8?q?=E6=96=BD=E3=80=81=E9=83=A8=E7=BD=B2=E3=80=81=E5=A4=87=E4=BB=BD?=
 =?UTF-8?q?=E5=92=8C=E6=81=A2=E5=A4=8D=E7=AD=89=E6=93=8D=E4=BD=9C=E6=80=A7?=
 =?UTF-8?q?=E7=BB=84=E4=BB=B6=EF=BC=9B=20chore:=20=E4=BF=AE=E6=94=B9.gitig?=
 =?UTF-8?q?nore=E7=AD=89=EF=BC=9B?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 app/api/controller/DemoOrderController.php    | 402 +++++++-
 app/common/logic/DemoPayNotifyLogic.php       | 924 ++++++++++++++++++
 app/statistics/controller/DemoController.php  | 146 +++
 app/statistics/controller/IndexController.php |  63 +-
 app/statistics/logic/UserLogic.php            |   1 +
 5 files changed, 1470 insertions(+), 66 deletions(-)
 create mode 100644 app/common/logic/DemoPayNotifyLogic.php
 create mode 100644 app/statistics/controller/DemoController.php

diff --git a/app/api/controller/DemoOrderController.php b/app/api/controller/DemoOrderController.php
index b97c4037b..725cdd2dd 100644
--- a/app/api/controller/DemoOrderController.php
+++ b/app/api/controller/DemoOrderController.php
@@ -2,69 +2,82 @@
 
 namespace app\api\controller;
 
+use app\api\logic\order\CartLogic;
 use app\api\logic\order\OrderLogic;
 use app\common\enum\PayEnum;
+use app\common\enum\YesNoEnum;
+use app\common\logic\DemoPayNotifyLogic;
 use app\common\logic\PaymentLogic;
 use app\common\logic\PayNotifyLogic;
+use app\common\model\Config;
+use app\common\model\order\Cart;
+use app\common\model\store_branch_product\StoreBranchProduct;
+use app\common\model\store_category\StoreCategory;
+use app\common\model\store_order\StoreOrder;
+use app\common\model\store_order_cart_info\StoreOrderCartInfo;
+use app\common\model\store_product\StoreProduct;
+use app\common\model\store_product_unit\StoreProductUnit;
+use app\common\model\system_store\SystemStore;
 use app\common\model\user\User;
+use app\common\model\user\UserAddress;
+use Picqer\Barcode\BarcodeGeneratorPNG;
+use support\exception\BusinessException;
+use think\facade\Db;
 
 class DemoOrderController extends BaseApiController
 {
-    /**
-     * 订单校验
-     */
-    public function checkOrder()
+    public $notNeedLogin = ['aa'];
+
+    public static $total_price;
+    public static $pay_price;
+    public static $cost;
+    public static $profit;
+    public static $store_price; //门店零售价
+    public static $activity_price;
+    public static $deduction_price;
+    public static $frozen_money; //返还金额
+    public static $fresh_price; //生鲜金额
+
+
+    public function aa()
     {
-        $cartId = (array)$this->request->post('cart_id', []);
-        $addressId = (int)$this->request->post('address_id');
-        // $pay_type = (int)$this->request->post('pay_type');
-        // $auth_code = $this->request->post('auth_code'); //微信支付条码
-        $params = $this->request->post();
-        $user = User::where('id', $this->userId)->find();
-        $res = OrderLogic::cartIdByOrderInfo($cartId, $addressId, $user, $params);
-        if ($res == false) {
-            $msg = OrderLogic::getError();
-            if ($msg == '购物车为空') {
-                return $this->data([]);
+
+        $data = Db::name('demo_order')->where('store_id', 22)->group('times')->select();
+        foreach ($data as $key => $value) {
+            $res = Db::name('demo_order')->where('times', $value['times'])->select();
+            foreach ($res as $k => $v) {
+                $product_id = StoreBranchProduct::where('id', $v['product_id'])->value('product_id');
+                if (!$product_id) {
+                    return $this->fail('商品不存在');
+                }
+                $datas = [
+                    'uid' => $v['uid'],
+                    'type' => 1,
+                    'product_id' => $product_id,
+                    'store_id' => $v['store_id'],
+                    'cart_num' => $v['nums'],
+                ];
+                CartLogic::add($datas);
             }
-            return $this->fail(OrderLogic::getError());
+            $this->create($value['uid'],$value['store_id'],$value['times'],$value['pay_type']);
         }
-        return $this->data($res);
     }
-
-
     /**
      * 创建订单
      */
-    public function createOrder()
+    public function create($uid,$store_id,$times,$pay_type)
     {
-        $cartId = (array)$this->request->post('cart_id', []);
-        $store_id = (array)$this->request->post('store_id', 0);
-        $pay_type = (int)$this->request->post('pay_type');
-        $addressId = (int)$this->request->post('address_id');
-        $auth_code = $this->request->post('auth_code'); //微信支付条码
-        $params = $this->request->post();
-        if ($store_id <= 0 && $pay_type != 9) {
-            return $this->fail('自提点不能为空');
-        }
-        if (count($cartId) > 100) {
-            return $this->fail('购物车商品不能超过100个');
-        }
+        $user = User::where('id', $uid)->find();
 
-        $user = User::where('id', $this->userId)->find();
-        if ($pay_type == PayEnum::PURCHASE_FUNDS || $pay_type == PayEnum::BALANCE_PAY) {
-            if (!isset($params['password'])) {
-                return $this->fail('缺失参数');
-            }
-            if (empty($user['pay_password'])) {
-                return $this->fail('请设置密码');
-            }
-            if (!password_verify($params['password'], $user['pay_password'])) {
-                return $this->fail('密码错误');
-            }
-        }
-
-        $order = OrderLogic::createOrder($cartId, $addressId, $user, $params);
+        $cartId = Cart::where([
+            'uid' => $uid,
+            'is_pay' => 0
+        ])->column('id');
+        $params['shipping_type'] = 2;
+        $params['store_id'] = $store_id;
+        $params['create_time'] = $times;
+        $params['pay_type'] = $pay_type;
+        $order = self::createOrder($cartId, 0, $user, $params);
         if ($order != false) {
             if ($order['pay_price'] <= 0) {
                 $pay_type = 3;
@@ -72,28 +85,36 @@ class DemoOrderController extends BaseApiController
             switch ($pay_type) {
                 case PayEnum::PURCHASE_FUNDS:
                     //采购款支付
-                    PayNotifyLogic::handle('purchase_funds', $order['order_id']);
+                    DemoPayNotifyLogic::handle('purchase_funds', $order['order_id']);
+                    OrderLogic::writeOff(['verify_code'=>$order['verify_code'],'store_id'=>$order['store_id']]);
                     return $this->success('采购款支付成功');
                 case PayEnum::BALANCE_PAY:
                     //余额支付
-                    PayNotifyLogic::handle('balancePay', $order['order_id']);
+                    DemoPayNotifyLogic::handle('balancePay', $order['order_id']);
+                    OrderLogic::writeOff(['verify_code'=>$order['verify_code'],'store_id'=>$order['store_id']]);
                     return $this->success('余额支付成功');
                 case PayEnum::CASH_PAY:
                     //现金支付
-                    PayNotifyLogic::handle('cash_pay', $order['order_id']);
+                    DemoPayNotifyLogic::handle('cash_pay', $order['order_id']);
                     return $this->success('现金支付成功');
                 case PayEnum::WECHAT_PAY_MINI:
                     //微信小程序支付
-                    PayNotifyLogic::handle('wechat_common', $order['order_id']);
+                    $extra['amount']['payer_total'] = bcmul($order['pay_price'], 100, 2);
+                    $extra['transaction_id'] = time();
+                    DemoPayNotifyLogic::handle('wechat_common', $order['order_id'], $extra);
+                    OrderLogic::writeOff(['verify_code'=>$order['verify_code'],'store_id'=>$order['store_id']]);
                     return $this->success('微信小程序支付成功');
                 case  PayEnum::WECHAT_PAY_BARCODE:
                     //微信条码支付
-                    PayNotifyLogic::handle('wechat_common', $order['order_id'], $order);
+                    $extra['amount']['payer_total'] = bcmul($order['pay_price'], 100, 2);
+                    $extra['transaction_id'] = time();
+                    DemoPayNotifyLogic::handle('wechat_common', $order['order_id'], $extra);
                     return $this->success('微信条码支付成功');
                 case  PayEnum::ALIPAY_BARCODE:
                     //支付宝条码支付
-                    PayNotifyLogic::handle('alipay_cashier', $order['order_id'], $order);
-                    return $this->success('支付宝条码支付成功' );
+                    $extra['buyer_pay_amount'] = $order['pay_price'];
+                    DemoPayNotifyLogic::handle('alipay_cashier', $order['order_id'], $extra);
+                    return $this->success('支付宝条码支付成功');
                 default:
                     return $this->fail('支付方式错误');
             }
@@ -102,4 +123,279 @@ class DemoOrderController extends BaseApiController
             return $this->fail(OrderLogic::getError());
         }
     }
+
+
+    /**
+     * @notes 获取购物车商品信息
+     * @param $params
+     * @return array|bool
+     */
+    static public function cartIdByOrderInfo($cartId, $addressId, $user = null, $params = [], $createOrder = 0)
+    {
+        $where = ['is_pay' => 0];
+        $cart_select = Cart::whereIn('id', $cartId)->where($where)->field('id,product_id,cart_num')->select()->toArray();
+        if (empty($cart_select)) {
+            throw new BusinessException('购物车为空', 3000);
+        }
+        // try {
+        self::$total_price = 0;
+        self::$pay_price = 0;
+        self::$cost = 0; //成本由采购价替代原成本为门店零售价
+        self::$profit = 0; //利润
+        self::$activity_price = 0; //活动减少
+        self::$store_price = 0; //商户价
+        self::$deduction_price = 0;
+        self::$frozen_money = 0; //返还金额
+        $deduction_price = 0; //抵扣金额
+        self::$fresh_price = 0; //生鲜金额
+        /** 计算价格 */
+
+        $off_activity = Config::where('name', 'off_activity')->value('value');
+        $field = 'id branch_product_id,store_name,image,unit,price,vip_price,cost,purchase,product_id,top_cate_id';
+        foreach ($cart_select as $k => $v) {
+            $find = StoreBranchProduct::where(['product_id' => $v['product_id'], 'store_id' => $params['store_id']])->field($field)->find();
+            if (!$find) {
+                //                    unset($cart_select[$k]);
+                //                    continue;
+                $field = 'id branch_product_id,store_name,image,unit,price,vip_price,cost,purchase, id product_id,cate_id';
+                $find = StoreProduct::where(['id' => $v['product_id']])->field($field)->find();
+                if ($find) {
+                    $cate_id = StoreCategory::where('id', $find['cate_id'])->value('pid');
+                    if ($cate_id > 0) {
+                        $cate_id = StoreCategory::where('id', $cate_id)->value('pid');
+                        if ($cate_id > 0) {
+                            $cate_id = StoreCategory::where('id', $cate_id)->value('pid');
+                            $find['top_cate_id'] = $cate_id;
+                        } else {
+                            $find['top_cate_id'] = $cate_id;
+                        }
+                    }
+                }
+                $cart_select[$k]['status'] = 1; //缺货标识
+            }
+            unset($cart_select[$k]['id']);
+            $cart_select[$k]['total_price'] = bcmul($v['cart_num'], $find['price'], 2); //订单总价
+            if ($off_activity == 1 || ($user != null && in_array($user['user_ship'], [4, 5, 6, 7]))) {
+                $price = $find['cost'];
+            } else {
+                $price = $find['price'];
+            }
+            $cart_select[$k]['price'] = $price;
+            $cart_select[$k]['cost'] = $find['cost'];
+            $cart_select[$k]['vip'] = 0;
+            $cart_select[$k]['unit_name'] = StoreProductUnit::where(['id' => $find['unit']])->value('name') ?? ''; //单位名称
+
+            //利润
+            // $cart_select[$k]['profit'] = bcmul($v['cart_num'], $onePrice, 2); //利润
+            $cart_select[$k]['purchase'] = bcmul($v['cart_num'], $find['purchase'], 2) ?? 0; //成本
+            $cart_select[$k]['pay_price'] = bcmul($v['cart_num'], $price, 2); //订单支付金额
+            $cart_select[$k]['store_price'] = bcmul($v['cart_num'], $find['cost'], 2) ?? 0; //商户价
+            $cart_select[$k]['vip_price'] = bcmul($v['cart_num'], $find['vip_price'], 2) ?? 0; //vip售价
+            if ($cart_select[$k]['total_price'] > $cart_select[$k]['pay_price']) {
+                $deduction_price = bcsub($cart_select[$k]['total_price'], $cart_select[$k]['pay_price'], 2);
+                $cart_select[$k]['deduction_price'] = $deduction_price; //抵扣金额
+            }
+            $cart_select[$k]['product_id'] = $find['product_id'];
+            $cart_select[$k]['old_cart_id'] = $v['id'];
+            $cart_select[$k]['cart_num'] = $v['cart_num'];
+            $cart_select[$k]['verify_code'] = $params['verify_code'] ?? '';
+            $cart_select[$k]['vip_frozen_price'] = 0;
+            //会员待返回金额
+            if ($user && $off_activity == 0) {
+                if ($user['user_ship'] == 4) {
+                    //商户
+                    $cart_select[$k]['vip_frozen_price'] = bcsub($cart_select[$k]['pay_price'], $cart_select[$k]['store_price'], 2);
+                } else {
+                    //其他会员
+                    $cart_select[$k]['vip_frozen_price'] = bcsub($cart_select[$k]['pay_price'], $cart_select[$k]['vip_price'], 2);
+                }
+            }
+            //                d($cart_select[$k]['pay_price'],$cart_select[$k]['store_price'],$cart_select[$k]['vip_price'] );
+            $cartInfo = $cart_select[$k];
+            $cartInfo['name'] = $find['store_name'];
+            $cartInfo['image'] = $find['image'];
+            $cart_select[$k]['cart_info'] = json_encode($cartInfo);
+            $cart_select[$k]['branch_product_id'] = $find['branch_product_id'];
+            //理论上每笔都是拆分了
+            $cart_select[$k]['name'] = $find['store_name'];
+            $cart_select[$k]['imgs'] = $find['image'];
+            $cart_select[$k]['store_id'] = $params['store_id'] ?? 0;
+            $cart_select[$k]['unit_name'] = StoreProductUnit::where(['id' => $find['unit']])->value('name');
+            self::$total_price = bcadd(self::$total_price, $cart_select[$k]['total_price'], 2);
+            self::$pay_price = bcadd(self::$pay_price, $cart_select[$k]['pay_price'], 2);
+            self::$cost = bcadd(self::$cost, $cart_select[$k]['purchase'], 2);
+            self::$store_price = bcadd(self::$store_price, $cart_select[$k]['store_price'], 2); //商户价
+            self::$deduction_price = bcadd(self::$deduction_price, $deduction_price, 2); //抵扣金额
+            self::$frozen_money = bcadd(self::$frozen_money, $cart_select[$k]['vip_frozen_price'], 2); //返还金额
+            //计算生鲜
+            if ($createOrder == 1 && $find['top_cate_id'] == 15201) {
+                self::$fresh_price = bcadd(self::$fresh_price, $cart_select[$k]['pay_price'], 2);
+            }
+            // self::$profit = bcadd(self::$profit, $cart_select[$k]['profit'], 2);
+        }
+        //加支付方式限制
+        // $pay_type = isset($params['pay_type']) ? $params['pay_type'] : 0;
+        // if ($user && $user['user_ship'] == 1 && $pay_type != 17) {
+        //     $pay_price = self::$pay_price;
+        // } else {
+
+
+        $pay_price = bcsub(self::$pay_price, self::$activity_price, 2); //减去活动优惠金额
+        //判断生鲜是否大于200
+        if ($createOrder == 1 && self::$fresh_price > 0) {
+            if (self::$pay_price < 200) {
+                throw new BusinessException('订单包含生鲜产品,订单金额必须大于200元,才能下单', 3000);
+            }
+        }
+        // }
+        //成本价  收益
+        $order = [
+            'create_time' => time(),
+            'order_id' => $params['order_id'] ?? getNewOrderId('PF'),
+            'total_price' => self::$total_price, //总价
+            'cost' => self::$cost, //成本价1-
+            'pay_price' => $pay_price, //后期可能有降价抵扣
+            'vip_price' => 0,
+            'total_num' => count($cart_select), //总数
+            'pay_type' => $params['pay_type'] ?? 0,
+            'reservation_time' => $params['reservation_time'] ?? null,
+            'cart_id' => implode(',', $cartId),
+            'store_id' => $params['store_id'] ?? 0,
+            'shipping_type' => $params['shipping_type'] ?? 2, //配送方式 1=快递 ,2=门店自提
+            'activity' => '减免',
+            'activity_price' => self::$activity_price,
+            'activities' => self::$activity_price > 0 ? 1 : 0,
+            'deduction_price' => self::$deduction_price,
+            'frozen_money' => self::$frozen_money, //返还金额(活动关闭得时候有)
+            'source' => 0,
+            'is_storage' => $params['is_storage'] ?? 0,
+        ];
+        $order['default_delivery'] = 0;
+        if ($params['store_id']) {
+            $order['default_delivery'] = SystemStore::where('id', $params['store_id'])->value('is_send');
+        }
+        if (isset($params['source']) && $params['source'] > 0) {
+            $order['source'] = $params['source'];
+        }
+        //处理返回最近的店铺
+        $store_check = 0;
+        if (empty($user)) {
+            $store_id = getenv('STORE_ID') ?? 1;
+            $store['near_store'] = SystemStore::where('id', $store_id)->field('id,name,phone,address,detailed_address,latitude,longitude')->find() ?? [];
+        } else {
+            $checkOrderStore = StoreOrder::where('uid', $user['id'])->field('id,store_id')
+                ->order('id', 'desc')->find();
+            if ($checkOrderStore) {
+                $store['near_store'] = SystemStore::where('id', $checkOrderStore['store_id'])->field('id,name,phone,address,detailed_address,latitude,longitude')->find() ?? [];
+                $store_check = 1;
+            } else {
+                $store_id = getenv('STORE_ID') ?? 1;
+                $store['near_store'] = SystemStore::where('id', $store_id)->field('id,name,phone,address,detailed_address,latitude,longitude')->find() ?? [];
+            }
+        }
+        if (empty($store_check)) {
+            if ((isset($params['lat']) && $params['lat'] != '') && (isset($params['long']) && $params['long'] != '')) {
+                $storeAll = SystemStore::field('id,name,phone,address,detailed_address,latitude,longitude')->select()->toArray();
+                $nearestStore = null;
+                $minDistance = PHP_FLOAT_MAX;
+                foreach ($storeAll as $value) {
+                    $value['distance'] = haversineDistance($value['latitude'], $value['longitude'], $params['lat'], $params['long']);
+                    if ($value['distance'] < $minDistance) {
+                        $minDistance = $value['distance'];
+                        $nearestStore = $value;
+                    }
+                }
+                $store['near_store'] = [];
+                if ($nearestStore) {
+                    $store['near_store'] = $nearestStore;
+                }
+            }
+        }
+        // } catch (\Exception $e) {
+        //     d($e);
+        //     throw new BusinessException($e->getMessage(), 3000);
+        // }
+        return ['order' => $order, 'cart_list' => $cart_select, 'shopInfo' => $store['near_store']];
+    }
+
+    /**
+     * 创建新订单
+     * @return Object|bool|array
+     */
+    static public function createOrder($cartId, $addressId, $user = null, $params = [])
+    {
+        $order_id = getNewOrderId('PF');
+        $code = rand(1, 10) . '-' . substr($order_id, -5);
+        $verify_code = createCode($code);
+        $params['order_id'] = $order_id;
+        $params['verify_code'] = $verify_code;
+        $orderInfo = self::cartIdByOrderInfo($cartId, $addressId, $user, $params, 1);
+        if (!$orderInfo) {
+            return false;
+        }
+        $uid = $user['id'] ?? 0;
+        $_order = $orderInfo['order'];
+        $_order['uid'] = $uid;
+        $_order['spread_uid'] = $params['spread_uid'] ?? 0;
+        $_order['real_name'] = $user['real_name'] ?? '';
+        $_order['mobile'] = $user['mobile'] ?? '';
+        $_order['pay_type'] = $orderInfo['order']['pay_type'];
+        $_order['verify_code'] = $verify_code;
+        $_order['reservation_time'] = null;
+        $_order['reservation'] = $params['reservation'] ?? 0; //是否需要预约
+        if (isset($params['reservation_time']) && $params['reservation_time']) {
+            $_order['reservation_time'] = $params['reservation_time'];
+            $_order['reservation'] = YesNoEnum::YES;
+        }
+        if ($addressId > 0 && $uid > 0) {
+            $address = UserAddress::where(['id' => $addressId, 'uid' => $uid])->find();
+            if ($address) {
+                $_order['real_name'] = $address['real_name'];
+                $_order['user_phone'] = $address['phone'];
+                $_order['user_address'] = $address['detail'];
+            }
+        }
+        if ($params['shipping_type'] == 2) {
+            $_order['status'] = 1;
+        }
+        if ($_order['pay_type'] == PayEnum::BALANCE_PAY && $user != null && $user['now_money'] < $_order['pay_price']) {
+            throw new \Exception('余额不足');
+        }
+        //生成核销码
+        $generator = new BarcodeGeneratorPNG();
+        $barcode = $generator->getBarcode($verify_code, $generator::TYPE_CODE_128);
+        $findPath = '/image/barcode/' . time() . '.png';
+        $savePath = public_path() . $findPath;
+        file_put_contents($savePath, $barcode);
+        $_order['verify_img'] = $findPath;
+        Db::startTrans();
+        try {
+            $times = strtotime($params['create_time']);
+            $_order['create_time'] = $times;
+            $_order['update_time'] = $times;
+            $order = StoreOrder::create($_order);
+            $goods_list = $orderInfo['cart_list'];
+            foreach ($goods_list as $k => $v) {
+                $goods_list[$k]['oid'] = $order->id;
+                $goods_list[$k]['uid'] = $uid;
+                $goods_list[$k]['cart_id'] = implode(',', $cartId);
+                $goods_list[$k]['delivery_id'] = $params['store_id']; //商家id
+                $goods_list[$k]['create_time'] = $times; //商家id
+                $goods_list[$k]['update_time'] = $times; //商家id
+
+                //                $StoreBranchProduct = StoreBranchProduct::where('id', $v['branch_product_id'])->withTrashed()->find();
+                //                if ($StoreBranchProduct['stock'] - $v['cart_num'] <= 0) {
+                //                    Db::name('store_product_cate')->where(['cate_id' => $StoreBranchProduct['cate_id'], 'store_id' => $params['store_id']])->update(['count' => 0]);
+                //                }
+            }
+            (new StoreOrderCartInfo())->saveAll($goods_list);
+            Cart::whereIn('id', $cartId)->update(['is_pay' => 1]);
+            Db::commit();
+            return $order;
+        } catch (\Exception $e) {
+            Db::rollback();
+            d($e);
+            throw new BusinessException($e->getMessage(), 3000);
+        }
+    }
 }
diff --git a/app/common/logic/DemoPayNotifyLogic.php b/app/common/logic/DemoPayNotifyLogic.php
new file mode 100644
index 000000000..3576484c4
--- /dev/null
+++ b/app/common/logic/DemoPayNotifyLogic.php
@@ -0,0 +1,924 @@
+<?php
+
+namespace app\common\logic;
+
+use app\admin\logic\user_ship\UserShipLogic;
+use app\api\logic\order\OrderLogic;
+use app\common\enum\OrderEnum;
+use app\common\enum\PayEnum;
+use app\common\enum\user\UserShipEnum;
+use app\common\enum\YesNoEnum;
+use app\common\logic\user_product_storage\UserProductStorageLogic;
+use app\common\model\Config;
+use app\common\model\dict\DictType;
+use app\common\model\finance\CapitalFlow;
+use app\common\model\finance\PayNotifyLog;
+use app\common\model\pay\PayNotify;
+use app\common\model\store_branch_product\StoreBranchProduct;
+use app\common\model\store_cash_finance_flow\StoreCashFinanceFlow;
+use app\common\model\store_finance_flow\StoreFinanceFlow;
+use app\common\model\store_order\StoreOrder;
+use app\common\model\store_order_cart_info\StoreOrderCartInfo;
+use app\common\model\store_product_log\StoreProductLog;
+use app\common\model\system_store\SystemStore;
+use app\common\model\user\User;
+use app\common\model\user\UserAddress;
+use app\common\model\user\UserRecharge;
+use app\common\model\user_ship\UserShip;
+use app\common\model\user_sign\UserSign;
+use app\common\model\vip_flow\VipFlow;
+use app\common\service\Curl;
+use app\common\service\PushService;
+use support\Log;
+use think\facade\Db;
+use Webman\RedisQueue\Redis;
+
+/**
+ * 支付成功后处理订单状态
+ * Class PayNotifyLogic
+ * @package app\api\logic
+ */
+class DemoPayNotifyLogic extends BaseLogic
+{
+
+    public static function handle($action, $orderSn, $extra = [], $type = 'wechat')
+    {
+        Db::startTrans();
+        try {
+            self::$action($orderSn, $extra, $type);
+            Db::commit();
+            return true;
+        } catch (\Exception $e) {
+            Db::rollback();
+            Log::error('支付回调处理失败' . $e->getMessage() . ',lien:' . $e->getLine() . ',file:' . $e->getFile());
+            throw new \Exception($e->getMessage());
+        }
+    }
+
+    /**
+     * 余额支付
+     * @param $orderSn
+     * @param $extra
+     * @return bool
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public static function balancePay($orderSn, $extra = [])
+    {
+        $order = StoreOrder::where('order_id', $orderSn)->findOrEmpty();
+        $user = User::where('id', $order['uid'])->find();
+        if ($user['now_money'] < $order['pay_price']) {
+            throw new \Exception('余额不足');
+        }
+        //        $order->money = $order['pay_price'];
+        $order->paid = 1;
+        $order->pay_time = bcadd(strtotime($order['create_time']),rand(1,300));
+        if (!$order->save()) {
+            throw new \Exception('订单保存出错');
+        }
+        if ($order['is_storage'] == 1) {
+            $order->status = 2;
+            UserProductStorageLogic::add($order);
+        }
+        // 减去余额
+        $user->now_money = bcsub($user['now_money'], $order['pay_price'], 2);
+        $user->save();
+
+        if ($order['spread_uid'] > 0  && $user['user_ship'] ==  1) {
+            $oldUser = User::where('id', $order['spread_uid'])->value('purchase_funds');
+            if ($oldUser < $order['pay_price']) {
+                $order['pay_price'] = $oldUser;
+            }
+        }
+        // self::addUserSing($order);
+        $capitalFlowDao = new CapitalFlowLogic($user);
+        $capitalFlowDao->userExpense('user_order_balance_pay', 'order', $order['id'], $order['pay_price'], '', 0, $order['store_id']);
+        self::dealProductLog($order);
+        if ($order['shipping_type'] == 3) {
+            //            self::descStock($order['id']);
+        }
+        self::afterPay($order);
+        if ($order['reservation'] == 1 && in_array($order['shipping_type'], [1, 2])) {
+            $checkArr = [
+                'cart_id' => $order['cart_id'],
+                'store_id' => $order['store_id'],
+            ];
+            self::dealGoodsLeft($checkArr, $order['uid'], $order['id']);
+        }
+        if ($extra && $extra['store_id'] && $order['reservation'] !=1) {
+            $params = [
+                'verify_code' => $order['verify_code'],
+                'store_id' => $extra['store_id'],
+                'staff_id' => $extra['staff_id']
+            ];
+            OrderLogic::writeOff($params);
+        }
+        if(in_array($order['shipping_type'],[1,2])){
+            PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type' => 'store_merchant', 'msg' => '您有一笔新的订单']);
+        }
+        return  true;
+        // Redis::send('push-platform-print', ['id' => $order['id']], 60);
+
+    }
+
+    /**
+     * 礼品券支付
+     * @param $orderSn
+     * @param $extra
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+
+    public static function gift_pay($orderSn, $extra = [])
+    {
+        $order = StoreOrder::where('order_id', $orderSn)->findOrEmpty();
+        $user = User::where('id', $order['uid'])->find();
+        if ($user['integral'] < $order['pay_price']) {
+            throw new \Exception('礼品券不足');
+        }
+        $order->money = $order['pay_price'];
+        $order->paid = 1;
+        $order->pay_time = bcadd(strtotime($order['create_time']),rand(1,300));
+        if (!$order->save()) {
+            throw new \Exception('订单保存出错');
+        }
+        // 减去礼品券
+        $user->integral = bcsub($user['integral'], $order['pay_price'], 2);
+        $user->save();
+        //入礼品券表扣款记录
+        $sing = [
+            'uid' => $order['uid'],
+            'order_id' => $order['order_id'],
+            //            'title' => '订单扣除兑换券',
+            'title' => 5,
+            'financial_pm' => 0,
+            'status' => 1,
+            'store_id' => $order['store_id'],
+            'number' => $order['pay_price'],
+            'user_ship' => $user['user_ship'],
+        ];
+        UserSign::create($sing);
+
+        if ($extra && $extra['store_id']) {
+            $params = [
+                'verify_code' => $order['verify_code'],
+                'store_id' => $extra['store_id'],
+                'staff_id' => $extra['staff_id']
+            ];
+            OrderLogic::lessWriteOff($params);
+        }
+        self::dealProductLog($order);
+    }
+
+
+    /**
+     * 采购款支付
+     * @param $orderSn
+     * @param $extra
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public static function purchase_funds($orderSn, $extra = [])
+    {
+        $order = StoreOrder::where('order_id', $orderSn)->findOrEmpty();
+        $user = User::where('id', $order['uid'])->find();
+        if ($user['purchase_funds'] < $order['pay_price']) {
+            throw new \Exception('采购款不足');
+        }
+        $order->money = $order['pay_price'];
+        $order->paid = 1;
+        $order->pay_time = bcadd(strtotime($order['create_time']),rand(1,300));
+        if (!$order->save()) {
+            throw new \Exception('订单保存出错');
+        }
+        if ($order['is_storage'] == 1) {
+            $order->status = 2;
+            UserProductStorageLogic::add($order);
+        }
+        // 减去采购款
+        $user->purchase_funds = bcsub($user['purchase_funds'], $order['pay_price'], 2);
+        $user->save();
+
+        $capitalFlowDao = new CapitalFlowLogic($user);
+        $capitalFlowDao->userExpense('user_order_purchase_pay', 'order', $order['id'], $order['pay_price'], '', 1, $order['store_id']);
+        //        if ($user['user_ship'] ==  1) {
+        //            self::dealVipAmount($order, PayEnum::PURCHASE_FUNDS);
+        //        }
+        // self::addUserSing($order);
+        self::afterPay($order);
+        if ($extra && $extra['store_id'] && $order['reservation'] !=1) {
+            $params = [
+                'verify_code' => $order['verify_code'],
+                'store_id' => $extra['store_id'],
+                'staff_id' => $extra['staff_id']
+            ];
+            OrderLogic::writeOff($params);
+        }
+        self::dealProductLog($order);
+        if ($order['reservation'] == 1 && in_array($order['shipping_type'], [1, 2])) {
+            $checkArr = [
+                'cart_id' => $order['cart_id'],
+                'store_id' => $order['store_id'],
+            ];
+            self::dealGoodsLeft($checkArr, $order['uid'], $order['id']);
+        }
+
+        // Redis::send('push-platform-print', ['id' => $order['id']], 60);
+        if(in_array($order['shipping_type'],[1,2])){
+            PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type' => 'store_merchant', 'msg' => '您有一笔新的订单']);
+        }
+    }
+
+    /**
+     * @notes 微信通用回调
+     * @param $orderSn
+     * @param array $extra
+     * @date 2023/2/27 15:28
+     */
+    public static function wechat_common($orderSn, $extra = [])
+    {
+        $order = StoreOrder::where('order_id', $orderSn)->findOrEmpty();
+
+        if ($order->isEmpty() || $order->paid == PayEnum::ISPAID) {
+            return true;
+        }
+        $order->status = 1;
+        $order->paid = 1;
+        $order->pay_time = bcadd(strtotime($order['create_time']),rand(1,300));
+        if ($order['is_storage'] == 1) {
+            $order->status = 2;
+            UserProductStorageLogic::add($order);
+        }
+        if ($order->pay_type != 10) {
+            $order->pay_price = bcdiv($extra['amount']['payer_total'], 100, 2);
+        } else {
+            $extra['transaction_id'] = time();
+        }
+        $user = User::where('id', $order['uid'])->find();
+        if ($order->pay_type == OrderEnum::CASHIER_ORDER_PAY || $order->pay_type == OrderEnum::CASHIER_ORDER_ALI_PAY) { //收银台支付
+            $order->status = 2;
+        } else {
+            $capitalFlowDao = new CapitalFlowLogic($user);
+            //微信支付和用户余额无关
+            $capitalFlowDao->userExpense('user_order_pay', 'order', $order['id'], $order->pay_price, '', 1, $order['store_id']);
+        }
+        $order->save();
+        if ($order['reservation'] == 1 && in_array($order['shipping_type'], [1, 2])) {
+            $checkArr = [
+                'cart_id' => $order['cart_id'],
+                'store_id' => $order['store_id'],
+            ];
+            self::dealGoodsLeft($checkArr, $order['uid'], $order['id']);
+        }
+        self::afterPay($order, $extra['transaction_id']);
+        // self::addUserSing($order);
+        self::dealProductLog($order);
+        if ($order['shipping_type'] == 3) {
+            self::descStock($order['id']);
+        }
+        if (!empty($extra['payer']['openid']) && $order->pay_type == 7) {
+            Redis::send('push-delivery', ['order_id' => $order['order_id'], 'openid' => $extra['payer']['openid']], 4);
+        }
+        return true;
+    }
+
+    //退款
+    public static function refund($orderSn, $extra = [])
+    {
+        //更新状态
+        $order = StoreOrder::where('order_id', $orderSn)->findOrEmpty();
+        if ($order->isEmpty() || $order->status == OrderEnum::REFUND_PAY) {
+            //充值
+            $orderRe = UserRecharge::where('order_id', $orderSn)->findOrEmpty();
+            if ($orderRe->isEmpty() || $orderRe->status == -1) {
+                return true;
+            }
+            $orderRe->status = -1;
+            $orderRe->refund_price = $orderRe->price;
+            $orderRe->refund_time = time();
+            $orderRe->remarks = '';
+            $orderRe->save();
+            $purchase_funds = User::where('id', $orderRe['uid'])->value('purchase_funds');
+            $user =  User::where('id', $orderRe['uid'])->find();
+            $capitalFlowDao = new CapitalFlowLogic($user);
+            if ($purchase_funds >= $orderRe['price']) {
+                User::where('id', $orderRe['uid'])->dec('purchase_funds', $orderRe['refund_price'])->update();
+                $capitalFlowDao->userExpense('user_balance_recharge_refund', 'order', $orderRe['id'], $orderRe['refund_price'], '', 1, $orderRe['store_id']);
+            } else {
+                User::where('id', $orderRe['uid'])->dec('purchase_funds', $purchase_funds)->update();
+                $capitalFlowDao->userExpense('user_balance_recharge_refund', 'order', $orderRe['id'], $purchase_funds, '', 1, $orderRe['store_id']);
+            }
+            //退还 充值得兑换券
+            UserSignLogic::RefundRecharge($orderRe);
+            return true;
+        }
+        $order->status = OrderEnum::REFUND_PAY;
+        $order->refund_status = OrderEnum::REFUND_STATUS_FINISH;
+        $order->refund_price = bcdiv($extra['amount']['refund'], 100, 2);
+        $order->refund_reason_time = time();
+        $order->refund_num +=  1;
+        $order->save();
+        //日志记录
+        //加用户余额,采购款,    日志记录  加数量
+        $user = User::where('id', $order['uid'])->findOrEmpty();
+        $capitalFlowDao = new CapitalFlowLogic($user);
+        $deal_money = bcdiv($extra['amount']['refund'], 100, 2);
+        //对应比例得退礼品券逻辑
+        $discount = self::getDiscount($user->user_ship);
+        $total_price = bcmul($order->refund_price, $discount, 2);
+        if (in_array($order['pay_type'], [PayEnum::BALANCE_PAY, PayEnum::PURCHASE_FUNDS])) {
+            if ($order['pay_type'] == PayEnum::BALANCE_PAY) { //用户余额支付
+                $user->now_money = bcadd($user->now_money, $deal_money, 2);
+                $user->save();
+                //增加数量
+                self::addStock($order['id']);
+                //退款
+                $capitalFlowDao->userIncome('system_balance_back', 'system_back', $order['id'], $deal_money);
+            }
+            if ($order['pay_type'] == PayEnum::PURCHASE_FUNDS) { //采购款支付
+                $user->purchase_funds = bcadd($user->purchase_funds, $deal_money, 2);
+                $user->save();
+                //增加数量
+                self::addStock($order['id']);
+                //退款
+                $capitalFlowDao->userIncome('system_purchase_back', 'system_back', $order['id'], $deal_money);
+            }
+            UserSignLogic::RefundOrder($order);
+
+            return true;
+        }
+        //积分
+        UserSignLogic::RefundOrder($order);
+        //微信日志  user_order_refund
+        $capitalFlowDao->userIncome('user_order_refund', 'system_back', $order['id'], $deal_money, '', 1);
+        //处理财务流水退还
+        (new StoreFinanceFlowLogic())->store_finance_back($orderSn);
+        self::addStock($order['id']); //微信
+        return true;
+        //        self::afterPay($order,$extra['transaction_id']);
+    }
+
+    /**
+     * 现金退款相关
+     * @param $orderSn
+     * @param $extra
+     * @return true
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public static function cash_refund($orderSn, $extra = [])
+    {
+        $order = StoreOrder::where('order_id', $orderSn)->findOrEmpty();
+        if ($order->isEmpty() || $order->status == OrderEnum::REFUND_PAY) {
+            return true;
+        }
+        $order->refund_status = OrderEnum::REFUND_STATUS_FINISH;
+        $order->refund_price = $order->pay_price;
+        $order->refund_reason_time = time();
+        $order->refund_num +=  1;
+        $order->save();
+        //日志记录
+        $model = new StoreCashFinanceFlow();
+        $model->store_id = $order['store_id'] ?? 0;
+        $model->cash_price = $order->pay_price;
+        $model->receivable = $order->pay_price;
+        $model->remark = '退款';
+        $model->type = 1;
+        $model->status = YesNoEnum::YES;
+        $model->save();
+        //增加数量
+        self::addStock($order['id']);
+        return true;
+    }
+
+    /**
+     * 充值现金退款相关
+     * @param $orderId
+     * @param $extra
+     * @return true
+     */
+    public static function recharge_cash_refund($orderId, $extra = [])
+    {
+        $order = UserRecharge::where('id', $orderId)->findOrEmpty();
+        if ($order->isEmpty() || $order->status == -1) {
+            return true;
+        }
+        $order->status = -1;
+        $order->refund_price = $order->price;
+        $order->refund_time = time();
+        $order->remarks = '';
+        $order->save();
+        return true;
+    }
+
+    /**
+     * 充值
+     */
+    public static function recharge($orderSn, $extra = [], $type = 'wechat')
+    {
+        $order = UserRecharge::where('order_id', $orderSn)->findOrEmpty();
+        if ($order->isEmpty() || $order->paid == PayEnum::ISPAID) {
+            return true;
+        }
+        if ($type == 'wechat') {
+            $price =  bcdiv($extra['amount']['payer_total'], 100, 2);
+        } else {
+            $price = $extra['buyer_pay_amount'];
+        }
+        $order->price = $price;
+        $order->paid = 1;
+        $order->pay_time = bcadd(strtotime($order['create_time']),rand(1,300));
+        $order->save();
+        $uid = $order->uid;
+        $user = User::where('id', $uid)->findOrEmpty();
+        //check store_id
+        if(empty($user->store_id)){
+            $user->store_id = $order['store_id'];
+        }
+
+        //用户的财务add
+        $capitalFlowDao = new CapitalFlowLogic($user);
+        $capitalFlowDao->userIncome('user_balance_recharge', 'user_recharge', $order['id'], $price, [], 1);
+
+        if ($user->isEmpty()) {
+            return true;
+        }
+        bcscale(2);
+
+        UserSignLogic::dealRechargeFrozen($user, $order, $order['user_ship']);
+
+        //更新等级
+        $user->user_ship = $order['user_ship'];
+
+        $user->purchase_funds = bcadd($user->purchase_funds, $price, 2);
+        $user->total_recharge_amount = bcadd($user->total_recharge_amount, $price, 2);
+        $user->save();
+        if ($order['other_uid'] > 0) {
+            $uid = $order['other_uid'];
+        }
+
+
+        PushService::push('wechat_mmp_' . $uid, $uid, ['type' => 'INDUSTRYMEMBERS', 'msg' => '订单支付成功', 'data' => ['id' => $order['id'], 'paid' => 1]]);
+        PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type' => 'INDUSTRYMEMBERS', 'msg' => '订单支付成功', 'data' => ['id' => $order['id'], 'paid' => 1]]);
+        if (!empty($extra['payer']['openid'])) {
+            Redis::send('push-delivery', ['order_id' => $order['order_id'], 'openid' => $extra['payer']['openid'], 'logistics_type' => 3], 4);
+        }
+        return true;
+    }
+
+    /**
+     * 现金支付
+     */
+    public static function cash_pay($orderSn,$extra =[])
+    {
+        $order = StoreOrder::where('order_id', $orderSn)->findOrEmpty();
+
+        if ($order->isEmpty() || $order->paid == PayEnum::ISPAID) {
+            return true;
+        }
+        $order->paid = 1;
+        $order->pay_time = strtotime($order['create_time']);
+        $order->status = 2;
+        if ($order['reservation'] ==1) {
+            $order->status = 1;
+        }
+        if (!$order->save()) {
+            throw new \Exception('订单保存出错');
+        }
+        self::afterPay($order);
+        if ($order['is_storage'] == 1) {
+            UserProductStorageLogic::add($order);
+        }
+        $cashFlowLogic = new CashFlowLogic();
+        $cashFlowLogic->insert($order['store_id'], $order['pay_price']);
+        self::dealProductLog($order);
+
+        if ($order['shipping_type'] == 3) {
+            self::descStock($order['id']);
+        }
+
+        if ($extra && $extra['store_id'] && $order['reservation'] !=1) {
+            $params = [
+                'verify_code' => $order['verify_code'],
+                'store_id' => $extra['store_id'],
+                'staff_id' => $extra['staff_id']
+            ];
+            OrderLogic::writeOff($params);
+        }
+
+
+        // Redis::send('push-platform-print', ['id' => $order['id']]);
+        return true;
+    }
+
+    /**
+     * @notes 阿里回调
+     * @param $orderSn
+     * @param array $extra
+     * @author 段誉
+     * @date 2023/2/27 15:28
+     */
+    public static function alipay_cashier($orderSn, $extra = [])
+    {
+        $order = StoreOrder::where('order_id', $orderSn)->findOrEmpty();
+
+        if ($order->isEmpty() || $order->paid == PayEnum::ISPAID) {
+            return true;
+        }
+        if ($order->pay_type != 10) {
+            $order->money = $extra['buyer_pay_amount'];
+            $order->paid = 1;
+            $order->pay_time = bcadd(strtotime($order['create_time']),rand(1,300));
+            $order->status = 1;
+            $order->save();
+        } else {
+            $extra['transaction_id'] = time();
+        }
+        if ($order->pay_type == 9) {
+            $order->status = 2;
+            self::afterPay($order);
+            UserProductStorageLogic::add($order);
+        }
+        self::dealProductLog($order);
+        if ($order['shipping_type'] == 3) {
+            self::descStock($order['id']);
+        }
+
+        // if ($order->pay_type == 9) {
+        // $extra['create_time'] = $order['create_time'];
+        // PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type' => 'cash_register', 'msg' => '您有一笔订单已支付', 'data' => $extra]);
+        // Redis::send('push-platform-print', ['id' => $order['id']]);
+        // }
+        // else {
+        //     PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type' => 'store_merchant', 'msg' => '您有一笔新的订单']);
+        // }
+        return true;
+    }
+
+    /**
+     * 支付后逻辑
+     * @param $order
+     * @return void
+     */
+    public static function afterPay($order, $transaction_id = 0)
+    {
+        $financeLogic = new StoreFinanceFlowLogic();
+        $off_activity = Config::where('name', 'off_activity')->value('value');
+        $village_uid = 0;
+        $brigade_uid = 0;
+        $user_ship = 0;
+        $order['dealVipAmount'] = 0;
+        try {
+            Redis::send('order_wetcha_push_send', ['order' => $order]);
+        } catch (\Exception $e) {
+            Log::error('订单推送失败:' . $e->getMessage());
+            // 异常处理代码,例如记录日志或发送通知等。
+        }
+        if ($order['uid'] > 0) {
+            // 结算金额 要支付的钱减去冻结得钱去走后面得逻辑  发得兑换券也要去减去
+            //用户下单该用户等级为1得时候才处理冻结金额
+            $user = User::where('id', $order['uid'])->find();
+            $user_ship = $user['user_ship'];
+
+        }
+        //积分写入
+        if(isset($user) && $user['user_ship']==0){
+            UserSignLogic::OrderWrite($order);
+        }
+        if ($off_activity == 1) {
+            //-----活动价结算更改
+            $financeLogic->order = $order;
+            $financeLogic->user = ['uid' => $order['uid']];
+            $financeLogic->in($transaction_id, $order['pay_price'], OrderEnum::USER_ORDER_PAY, $order['store_id'], $order['staff_id'], 0, $order['pay_type']);  //用户订单支付
+            $financeLogic->in($transaction_id, $order['pay_price'], OrderEnum::SUPPLIER_ORDER_OBTAINS, $order['store_id'], 0, 0, $order['pay_type']);
+            $financeLogic->out($transaction_id, $order['pay_price'], OrderEnum::SUPPLIER_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 0, $order['pay_type']);
+            $financeLogic->save();
+            return false;
+        }
+
+        //如果是会员需要返回会员金额
+        // if ($user_ship>0 && $order['pay_type'] != PayEnum::CASH_PAY && $off_activity !=1) {
+        //     $order['dealVipAmount']= self::dealVipAmount($order,  $order['pay_type']);
+        // }
+        if ($order['spread_uid'] > 0 || $user_ship > 0) {
+            if ($order['spread_uid'] > 0 && $user_ship == 0) {
+                $user_ship = User::where('id', $order['spread_uid'])->value('user_ship');
+                if ($user_ship == 2) {
+                    $village_uid = $order['spread_uid'];
+                    $address = UserAddress::where(['uid' => $order['spread_uid'], 'is_default' => 1])->find();
+                    if ($address) {
+                        $arr2 = UserAddress::where(['village' => $address['village'], 'brigade' => $address['brigade'], 'is_default' => 1])->column('uid');
+                        if ($arr2) {
+                            $brigade_uid = User::where('id', 'in', $arr2)->where('user_ship', 3)->value('id') ?? 0;
+                        }
+                    }
+                } elseif ($user_ship == 3) {
+                    $brigade_uid = $order['spread_uid'];
+                    $address = UserAddress::where(['uid' => $order['spread_uid'], 'is_default' => 1])->find();
+                    if ($address) {
+                        $arr1 = UserAddress::where(['village' => $address['village'], 'is_default' => 1])->column('uid');
+                        if ($arr1) {
+                            $village_uid = User::where('id', 'in', $arr1)->where('user_ship', 2)->value('id') ?? 0;
+                        }
+                    }
+                }else{
+                    $address = UserAddress::where(['uid' => $order['spread_uid'], 'is_default' => 1])->find();
+                    if ($address) {
+                        $arr1 = UserAddress::where(['village' => $address['village'], 'is_default' => 1])->column('uid');
+                        if ($arr1) {
+                            $village_uid = User::where('id', 'in', $arr1)->where('user_ship', 2)->value('id') ?? 0;
+                        }
+                        $arr2 = UserAddress::where(['village' => $address['village'], 'brigade' => $address['brigade'], 'is_default' => 1])->column('uid');
+                        if ($arr2) {
+                            $brigade_uid = User::where('id', 'in', $arr2)->where('user_ship', 3)->value('id') ?? 0;
+                        }
+                    }
+                }
+            } else {
+                //查询用户对应的村长和队长
+                $address = UserAddress::where(['uid' => $order['uid'], 'is_default' => 1])->find();
+                if ($address) {
+                    $arr1 = UserAddress::where(['village' => $address['village'], 'is_default' => 1])->column('uid');
+                    if ($arr1) {
+                        $village_uid = User::where('id', 'in', $arr1)->where('user_ship', 2)->value('id') ?? 0;
+                    }
+                    $arr2 = UserAddress::where(['village' => $address['village'], 'brigade' => $address['brigade'], 'is_default' => 1])->column('uid');
+                    if ($arr2) {
+                        $brigade_uid = User::where('id', 'in', $arr2)->where('user_ship', 3)->value('id') ?? 0;
+                    }
+                }
+            }
+            switch ($user_ship) {
+                case 1: // 厨师
+                //case 4: // 商户
+                //case 5: // 种养殖
+                // case 6: // 酒店
+                // case 7: // 食堂
+                case 8: // 一条龙
+                    CommissionLogic::setCook($order, $village_uid, $brigade_uid, $transaction_id);
+                    break;
+                case 2: // 村长
+                    CommissionLogic::setVillage($order, $village_uid, $brigade_uid, $transaction_id);
+                    break;
+                case 3: // 队长
+                    CommissionLogic::setBrigade($order, $village_uid, $brigade_uid, $transaction_id);
+                    break;
+                default:
+                    CommissionLogic::setStore($order, $transaction_id);
+                    break;
+            }
+        } else {
+            CommissionLogic::setStore($order, $transaction_id);
+        }
+    }
+
+    /**
+     * 回调日志
+     * @param $order
+     * @param $extra
+     * @return void
+     */
+    public static function notifyLog($order, $extra)
+    {
+        $data = [
+            'pay_type' => 'wechat',
+            'type' => OrderEnum::PAY,
+            'amount' => $extra['amount']['payer_total'], //分
+            'order_sn' => $order,
+            'out_trade_no' => $extra['transaction_id'],
+            'attach' => $extra['attach'],
+            'create_time' => date('Y-m-d H:i:s', time()),
+        ];
+        PayNotify::create($data);
+    }
+
+    /**
+     * 冻结金额
+     * @param $oid
+     * @return int|mixed
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+
+    public static function dealFrozenPrice($oid)
+    {
+        $detail = StoreOrderCartInfo::where('oid', $oid)->select()->toArray();
+        $total_vip = 0;
+        foreach ($detail as $value) {
+            $total_vip += $value['cart_info']['vip_frozen_price'];
+        }
+        return $total_vip;
+    }
+
+
+    /**
+     * 处理用户为vip1时得冻结资金
+     * @param $order
+     * @param $pay_type
+     * @param $transaction_id
+     * @return true
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public static function dealVipAmount($order, $pay_type = 1, $transaction_id = 0)
+    {
+        $total_vip = self::dealFrozenPrice($order['id']);
+        $data = [
+            'order_id' => $order['id'],
+            'transaction_id' => $transaction_id ?? 0,
+            'order_sn' => $order['order_id'],
+            'user_id' => $order['uid'],
+            'number' => $total_vip,
+            'all' => $order['pay_price'],
+            'pay_type' => $pay_type ?? 1,
+            'status' => 0,
+            'store_id' => $order['store_id'],
+            'staff_id' => $order['staff_id'],
+            'create_time' => time()
+        ];
+        Db::name('vip_flow')->insert($data);
+        return $total_vip;
+    }
+
+    /**
+     * 商品统计逻辑
+     * @param $order
+     * @return true
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public static function dealProductLog($order)
+    {
+        $store_id = $order['store_id'];
+        $cart_id = $order['cart_id'];
+        $uid = $order['uid'];
+        if ($uid && $cart_id && $store_id) {
+            $cart_id =  explode(',', $cart_id);
+            $productLog = StoreProductLog::where([
+                'uid' => $uid
+            ])->whereIn('cart_id', $cart_id)
+                ->select()->toArray();
+
+            foreach ($productLog as &$value) {
+                $value['pay_uid'] = $uid;
+                $value['oid'] = $order['id'];
+                $value['store_id'] = $store_id;
+                $cart_info = StoreOrderCartInfo::where([
+                    'uid' => $uid, 'old_cart_id' => $value['cart_id'], 'oid' => $value['oid']
+                ])->find();
+                $value['order_num'] = $cart_info['cart_num'] ?? 1;
+                $value['pay_num'] = $cart_info['cart_num'] ?? 1;
+                $value['pay_price'] = $cart_info['price'] ?? 0;
+                $value['cost_price'] = $cart_info['cart_info']['cost'] ?? 0;
+                $value['update_time'] = time();
+                unset($value['create_time'], $value['delete_time']);
+            }
+
+            (new StoreProductLog())->saveAll($productLog);
+        }
+        return true;
+    }
+
+
+    public static function descSwap($oid)
+    {
+        $updateData = [];
+        $goods_list = StoreOrderCartInfo::where('oid', $oid)->select()->toArray();
+        foreach ($goods_list as  $v) {
+            $StoreBranchProduct = StoreBranchProduct::where(
+                [
+                    'store_id' => $v['store_id'],
+                    'product_id' => $v['product_id'],
+                ]
+            )->withTrashed()->find();
+            $updateData[] = [
+                'id' => $StoreBranchProduct['id'],
+                'swap' => $StoreBranchProduct['swap'] - $v['cart_num'],
+                'sales' => ['inc', $v['cart_num']]
+            ];
+        }
+
+        (new StoreBranchProduct())->saveAll($updateData);
+    }
+
+
+    /**
+     * 扣库存
+     * @param $oid
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public static function descStock($oid)
+    {
+        $updateData = [];
+        $goods_list = StoreOrderCartInfo::where('oid', $oid)->select()->toArray();
+        foreach ($goods_list as  $v) {
+            $StoreBranchProduct = StoreBranchProduct::where(
+                [
+                    'store_id' => $v['store_id'],
+                    'product_id' => $v['product_id'],
+                ]
+            )->withTrashed()->find();
+            if ($StoreBranchProduct) {
+                $updateData[] = [
+                    'id' => $StoreBranchProduct['id'],
+                    'stock' => $StoreBranchProduct['stock'] - $v['cart_num'],
+                    'sales' => ['inc', $v['cart_num']]
+                ];
+            }
+        }
+
+        (new StoreBranchProduct())->saveAll($updateData);
+    }
+
+    /**
+     * 加库存
+     * @param $oid
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public static function addStock($oid)
+    {
+        $updateData = [];
+        $goods_list = StoreOrderCartInfo::where('oid', $oid)->select()->toArray();
+        foreach ($goods_list as  $v) {
+            $StoreBranchProduct = StoreBranchProduct::where(
+                [
+                    'store_id' => $v['store_id'],
+                    'product_id' => $v['product_id'],
+                ]
+            )->withTrashed()->find();
+            if ($StoreBranchProduct) {
+                $updateData[] = [
+                    'id' => $StoreBranchProduct['id'],
+                    'stock' => $StoreBranchProduct['stock'] + $v['cart_num'],
+                    //                    'sales' => ['inc', $v['cart_num']]
+                    //                    'sales' => ['inc', $v['cart_num']]
+                ];
+            }
+        }
+
+        (new StoreBranchProduct())->saveAll($updateData);
+    }
+
+
+    /**
+     * 处理商品缺失新增到缺失列表
+     * @param $cart_id  //购物车ids
+     * @param $uid //用户id
+     * @param $oid //订单id
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public static function dealGoodsLeft($cart_id, $uid, $oid)
+    {
+        if (is_array($cart_id)) {
+            $cart_id['cart_id'] = $cart_id;
+        } else {
+            $cart_id['cart_id'] = explode(',', $cart_id);
+        }
+        $data = OrderLogic::checkLeft($cart_id, $uid, 1);
+        $format =  $data['detail'];
+        foreach ($format as &$value) {
+            $value['oid'] = $oid;
+            $value['create_time'] = time();
+        }
+        Db::name('store_product_miss')->insertAll($format);
+    }
+
+
+
+    /**
+     * 会员等级对应得折扣比例
+     * @param $level
+     * @return float|mixed
+     */
+    public static function getDiscount($level)
+    {
+        switch ($level) {
+            case 0: //普通
+                return Config::where('name', 'ordinary_member')->value('value') ?? 0.1;
+            case 1: //vip
+                return Config::where('name', 'vip_member')->value('value') ?? 0.1;
+            case 4: //商户
+                return Config::where('name', 'merchant')->value('value') ?? 0.1;
+            default:
+                return 0.1;
+        }
+    }
+}
diff --git a/app/statistics/controller/DemoController.php b/app/statistics/controller/DemoController.php
new file mode 100644
index 000000000..e521401e6
--- /dev/null
+++ b/app/statistics/controller/DemoController.php
@@ -0,0 +1,146 @@
+<?php
+
+namespace app\statistics\controller;
+
+use app\admin\logic\statistic\TradeStatisticLogic;
+use app\common\controller\BaseLikeController;
+use app\common\model\system_store\SystemStore;
+use think\facade\Db;
+
+class DemoController extends BaseLikeController
+{
+
+
+    public function index()
+    {
+        $time = $this->request->get('date', date('Y-m-d'));
+        $store_id = $this->request->get('store_id', 0);
+        $res = Db::name('demo_order_money')->whereDay('dates', $time)->sum('money');
+        $res = $res ? $res : 0;
+        switch ($store_id) {
+            case 1:
+                $title = '喻寺镇农(特)产品交易大数据';
+                break;
+            case 2:
+                $title = '立石镇农(特)产品交易大数据';
+                break;
+            case 3:
+                $title = '百和镇农(特)产品交易大数据';
+                break;
+            case 4:
+                $title = '得胜镇农(特)产品交易大数据';
+                break;
+            case 5:
+                $title = '玄滩镇农(特)产品交易大数据';
+                break;
+            case 6:
+                $title = '牛滩镇农(特)产品交易大数据';
+                break;
+            case 7:
+                $title = '云锦镇农(特)产品交易大数据';
+                break;
+            default:
+                $title = '泸县农(特)产品交易大数据';
+                break;
+        }
+        return $this->success('ok', ['dayPayPrice' => $res, 'title' => $title]);
+    }
+    public function bottomLeft()
+    {
+        $time = $this->request->get('date', date('Y-m'));
+        $store_id = $this->request->get('store_id', 0);
+        $where = [];
+        if ($store_id) {
+            $where['store_id'] = $store_id;
+        }
+        $arr = SystemStore::where('is_show', 1)->field('id,name street_name')->select()
+            ->each(function ($item) use ($time) {
+                $day = Db::name('demo_order_money')->where('store_id', $item['id'])->whereMonth('dates', $time)->sum('money');
+                $yester = Db::name('demo_order_money')->where('store_id', $item['id'])->whereMonth('dates', date('Y-m', strtotime('-1 month')))->sum('money');
+                $item['monthDayOrder'] = $day ?? 0;
+                $item['monthYesterOrder'] = $yester ?? 0;
+                return $item;
+            })->toArray();
+        return $this->data($arr);
+    }
+
+    public function store_order_day_two()
+    {
+        $time = $this->request->get('date', date('Y-m-d'));
+        $arr = SystemStore::where('is_show', 1)->field('id,name street_name')->select()
+            ->each(function ($item) use ($time) {
+                $today_order_amount = Db::name('demo_order_money')->where('store_id', $item['id'])->whereDay('dates', $time)->sum('money');
+                $yesterday_order_amount = Db::name('demo_order_money')->where('store_id', $item['id'])->whereDay('dates', date('Y-m-d', strtotime($time.'-1 day')))->sum('money');
+                $item['today_order_amount'] = $today_order_amount;
+                $item['yesterday_order_amount'] = $yesterday_order_amount;
+                return $item;
+            });
+        return $this->success('ok', $arr?->toArray());
+    }
+
+    /**
+     * 成交用户数据
+     */
+    public function user_trade_count()
+    {
+        $store_id = $this->request->get('store_id', 0);
+        $date = $this->request->get('date', '');
+
+        if ($date != '') {
+            $where = ['create_time' => ['start_time' => $date, 'end_time' => $date . ' 23:59:59']];
+            $where2 = ['create_time' => ['start_time' => $date, 'end_time' => $date . ' 23:59:59']];
+        } else {
+            $where = ['create_time' => 'today'];
+            $where2 = ['create_time' => 'yestoday'];
+        }
+
+        if ($store_id) {
+            $where['store_id'] = $store_id;
+            $where2['store_id'] = $store_id;
+        }
+        $left = [];
+
+        // foreach ($totalleft as $k => $v) {
+        //     $left['name'] = "当日订单金额";
+        //     $left['x'] = $v['curve']['x'];
+        //     $left['series'][$k]['money'] = round($v['total_money'], 2);
+        //     $left['series'][$k]['value'] = array_values($v['curve']['y']);
+        // }
+        $time['start_time'] = date('Y-01-01 00:00:00', time());
+        $time['end_time'] = date('Y-12-t 23:59:59', time());
+        $time['days'] = 365;
+        $left = $this->getCurveData([], $time, 'sum(money)', 'dates');
+        $a = new TradeStatisticLogic();
+        $totalMoney = $a->trendYdata($left, $time);
+
+        $datas['name'] = "门店订单金额曲线";
+        $datas['x'] = $totalMoney['x'];
+        $datas['series'][0]['money'] = 0;
+        $datas['series'][0]['value'] = array_values($totalMoney['y']);
+
+        return $this->data($datas);
+    }
+    public function getCurveData($where, $time, $str, string $group = 'dates')
+    {
+        return  Db::name('demo_order_money')->where($where)
+            ->when(isset($time), function ($query) use ($time, $str, $group) {
+                $query->whereBetweenTime($group, $time['start_time'], $time['end_time']);
+                if ($time['days'] == 1) {
+                    $timeUinx = "%H";
+                } elseif ($time['days'] == 30) {
+                    $timeUinx = "%Y-%m-%d";
+                } elseif ($time['days'] == 365) {
+                    $timeUinx = "%Y-%m";
+                } elseif ($time['days'] > 1 && $time['days'] < 30) {
+                    $timeUinx = "%Y-%m-%d";
+                } elseif ($time['days'] > 30 && $time['days'] < 365) {
+                    $timeUinx = "%Y-%m";
+                } else {
+                    $timeUinx = "%Y-%m";
+                }
+                $query->field("$str as number,DATE_FORMAT($group, '$timeUinx') as time");
+                $query->group("DATE_FORMAT($group, '$timeUinx')");
+            })
+            ->order("$group ASC")->select()->toArray();
+    }
+}
diff --git a/app/statistics/controller/IndexController.php b/app/statistics/controller/IndexController.php
index c45941805..27d3fb3d6 100644
--- a/app/statistics/controller/IndexController.php
+++ b/app/statistics/controller/IndexController.php
@@ -83,16 +83,17 @@ class IndexController extends BaseLikeController
      */
     public function product_count_sotre_count()
     {
+        $time = $this->request->get('date', date('Y-m-d'));
         $data = [
-            ['street_name' => '喻寺镇', 'product_count' => StoreBranchProduct::where('store_id',1)->count()],
-            ['street_name' => '立石镇', 'product_count' => StoreBranchProduct::where('store_id',2)->count()],
-            ['street_name' => '百和镇', 'product_count' => StoreBranchProduct::where('store_id',3)->count()],
-            ['street_name' => '得胜镇', 'product_count' => StoreBranchProduct::where('store_id',5)->count()],
-            ['street_name' => '玄滩镇', 'product_count' => StoreBranchProduct::where('store_id',6)->count()],
-            ['street_name' => '云锦镇', 'product_count' => StoreBranchProduct::where('store_id',7)->count()],
+            ['street_name' => '喻寺镇', 'product_count' => StoreBranchProduct::where('store_id',1)->where('create_time','<=',strtotime($time))->count()],
+            ['street_name' => '立石镇', 'product_count' => StoreBranchProduct::where('store_id',2)->where('create_time','<=',strtotime($time))->count()],
+            ['street_name' => '百和镇', 'product_count' => StoreBranchProduct::where('store_id',3)->where('create_time','<=',strtotime($time))->count()],
+            ['street_name' => '得胜镇', 'product_count' => StoreBranchProduct::where('store_id',5)->where('create_time','<=',strtotime($time))->count()],
+            ['street_name' => '玄滩镇', 'product_count' => StoreBranchProduct::where('store_id',6)->where('create_time','<=',strtotime($time))->count()],
+            ['street_name' => '云锦镇', 'product_count' => StoreBranchProduct::where('store_id',7)->where('create_time','<=',strtotime($time))->count()],
         ];
-        $townProductCount = StoreProduct::count();
-        $product_count = StoreBranchProduct::group('product_id')->order('total_sales desc')->limit(20)->field('image,product_id,store_name,sum(sales) as total_sales')->select();
+        $townProductCount = StoreProduct::where('create_time','<=',strtotime($time))->count();
+        $product_count = StoreBranchProduct::where('create_time','<=',strtotime($time))->group('product_id')->order('total_sales desc')->limit(20)->field('image,product_id,store_name,sum(sales) as total_sales')->select();
         $productRankingTotal = 0;
         foreach ($product_count as $item) {
             $productRankingTotal += $item['total_sales'];
@@ -105,6 +106,7 @@ class IndexController extends BaseLikeController
         $store_id = $this->request->get('store_id', 0);
         $today = strtotime($time);
         $dates = [];
+        $dates_two=[];
         // 循环输出前5天的日期
         for ($i = 0; $i <= 4; $i++) {
             // 计算前第$i天的日期时间戳
@@ -112,6 +114,7 @@ class IndexController extends BaseLikeController
 
             // 将时间戳格式化为日期
             $date = date('Y-m-d', $timestamp);
+            $dates_two[] = date('n.j', $timestamp);
             $dates[] = $date;
         }
         $where = [];
@@ -122,6 +125,7 @@ class IndexController extends BaseLikeController
         if (UserLogic::hasError()) {
             return $this->fail(UserLogic::getError()); //获取错误信息并返回错误信息
         }
+        $res['date']=$dates_two;
         return $this->success('ok', $res);
     }
 
@@ -192,14 +196,23 @@ class IndexController extends BaseLikeController
     public function user_trade_count()
     {
         $store_id = $this->request->get('store_id', 0);
-        $where = ['create_time' => 'today'];
-        $where2 = ['create_time' => 'yestoday'];
+        $date = $this->request->get('date', '');
+
+        if($date!=''){
+            $where = ['create_time' =>['start_time'=>$date,'end_time'=>$date.' 23:59:59']];
+            $where2 = ['create_time' =>['start_time'=>$date,'end_time'=>$date. ' 23:59:59']];
+        }else{
+            $where = ['create_time' => 'today'];
+            $where2 = ['create_time' => 'yestoday'];
+        }
+
         if ($store_id) {
             $where['store_id'] = $store_id;
             $where2['store_id'] = $store_id;
         }
         $logic = (new TradeStatisticLogic());
         $leftToday = $logic->getTopLeftTrade($where);
+
         $leftyestoday = $logic->getTopLeftTrade($where2);
         $totalleft = [$leftToday, $leftyestoday];
         foreach ($totalleft as $k => $v) {
@@ -231,10 +244,11 @@ class IndexController extends BaseLikeController
 
     public function store_order_day()
     {
+        $time = $this->request->get('date', date('Y-m'));
         $arr = SystemStore::where('is_show', 1)->field('id,name street_name')->select()
-        ->each(function($item){
-            $res = StoreOrder::where('paid', 1)->where('refund_status', 0)->where('store_id', $item['id'])->whereDay('create_time')->field('count(id) count,sum(pay_price) price')->find();
-            $month = StoreOrder::where('paid', 1)->where('refund_status', 0)->where('store_id', $item['id'])->whereMonth('create_time')->field('count(id) count,sum(pay_price) price')->find();
+        ->each(function($item) use($time){
+            $res = StoreOrder::where('paid', 1)->where('refund_status', 0)->where('store_id', $item['id'])->whereDay('create_time',$time)->field('count(id) count,sum(pay_price) price')->find();
+            $month = StoreOrder::where('paid', 1)->where('refund_status', 0)->where('store_id', $item['id'])->whereMonth('create_time',$time)->field('count(id) count,sum(pay_price) price')->find();
             $item['dayOrderAmount']=$res['price']??0;
             $item['dayOrderCount']=$res['count']??0;
             $item['monthOrderAmount']=$month['price']??0;
@@ -254,5 +268,28 @@ class IndexController extends BaseLikeController
             return $item;
         });
         return $this->success('ok', $arr?->toArray());
+    }
+
+            /**
+     * 格式化时间
+     * @param $time
+     * @return string
+     */
+    public function getDay($time)
+    {
+        if (strstr($time, '-') !== false) {
+            [$startTime, $endTime] = explode('-', $time);
+            if (!$startTime && !$endTime) {
+                return date("Y/m/d", strtotime("-30 days", time())) . '-' . date("Y/m/d", time());
+            } else {
+                if($startTime==$endTime){
+                    return $startTime . '-' . $endTime.' 23:59:59';
+                }else{
+                    return $startTime . '-' . $endTime;
+                }
+            }
+        } else {
+            return date("Y/m/d", strtotime("-30 days", time())) . '-' . date("Y/m/d", time());
+        }
     }
 }
diff --git a/app/statistics/logic/UserLogic.php b/app/statistics/logic/UserLogic.php
index e61f4c203..ce5c8926b 100644
--- a/app/statistics/logic/UserLogic.php
+++ b/app/statistics/logic/UserLogic.php
@@ -17,6 +17,7 @@ class UserLogic extends BaseLogic
             $data[$k]['viewUserCount']=StoreVisit::whereDay('create_time', $date)->where($where)->group('uid')->count();
             $data[$k]['totalUserCount']=UserRecharge::where('create_time','<',strtotime($date) )->where($where)->where('paid',1)->where('recharge_type','INDUSTRYMEMBERS')->count();
         }
+        $data['list']=$data;
         return $data;
     }
     public static function TradeCount($where,$dates)