cqp há 5 meses atrás
pai
commit
4652b0c83b

+ 2 - 0
app/Http/Middleware/CheckWx.php

@@ -118,6 +118,8 @@ class CheckWx
                 }
             }
 
+            $request->merge(['from_wx' => 1]);
+
             $request->userData = $data;
         }
 

+ 1 - 0
app/Model/PurchaseOrderSpecial.php

@@ -27,4 +27,5 @@ class PurchaseOrderSpecial extends UseScopeBaseModel
         self::TYPE_ONE => '仅安装',
     ];
     const range_function = 'purchaseSpecialRange';
+    const menu_id = 44;
 }

+ 94 - 13
app/Service/CheckService.php

@@ -8,6 +8,8 @@ use App\Model\Customer;
 use App\Model\Depart;
 use App\Model\Employee;
 use App\Model\InOutRecord;
+use App\Model\Inventory;
+use App\Model\InventorySub;
 use App\Model\InvoiceOrder;
 use App\Model\InvoiceOrderInfo;
 use App\Model\OrderOperation;
@@ -29,7 +31,6 @@ use App\Model\SeeRange;
 use App\Model\SportsBag;
 use App\Model\Storehouse;
 use App\Model\Supplier;
-use App\Service\OaService;
 use Illuminate\Support\Facades\DB;
 
 class CheckService extends Service
@@ -51,6 +52,7 @@ class CheckService extends Service
     const eve  = 11; //接受派单
     const twl  = 12; //活动包
     const thi  = 13; //虚拟采购单
+    const fourteen  = 14; //盘点
 
     //中文对照
     public $map = [
@@ -66,7 +68,8 @@ class CheckService extends Service
         self::ten => '收付款确认',
         self::eve => '接受门店派单',
         self::twl => '活动包',
-        self::thi => '虚拟采购单'
+        self::thi => '虚拟采购单',
+        self::fourteen => '盘点单',
     ];
 
     //入库操作
@@ -100,6 +103,7 @@ class CheckService extends Service
         self::ten => 'waitPaymentReceipt', //收付款确认
         self::twl => 'waitSportsBag', //活动包确认
         self::thi => 'waitPurchaseSpecial', //虚拟采购单
+        self::fourteen => 'waitInventory', //盘点单
     ];
 
     public static $finished = [
@@ -120,6 +124,7 @@ class CheckService extends Service
         self::ten => 'confirmPaymentReceipt', // 确认收付款单
         self::twl => 'confirmSportsBag', // 确认活动包
         self::thi => 'confirmPurchaseSpecial', //虚拟采购单
+        self::fourteen => 'confirmInventory', //盘点单
     ];
 
     //单据库存流水
@@ -127,7 +132,8 @@ class CheckService extends Service
         self::two => 'recordInvoiceOrder',
         self::three => 'recordPurchaseOrder',
         self::five => 'recordConstruction',
-        self::six => 'recordReturnExchangeOrder'
+        self::six => 'recordReturnExchangeOrder',
+        self::fourteen => 'recordInventory',
     ];
 
     //自动生成
@@ -269,18 +275,32 @@ class CheckService extends Service
     }
 
     public function waitPurchaseSpecial($data){
-    $model = PurchaseOrderSpecial::where('id',$data['id'])
-        ->where('del_time',0)
-        ->first();
-    if(empty($model)) return [false, '虚拟采购订单不存在或已被删除'];
-    if($model->state > PurchaseOrderSpecial::STATE_ZERO) return [false, '请确认虚拟采购订单状态,操作失败'];
+        $model = PurchaseOrderSpecial::where('id',$data['id'])
+            ->where('del_time',0)
+            ->first();
+        if(empty($model)) return [false, '虚拟采购订单不存在或已被删除'];
+        if($model->state > PurchaseOrderSpecial::STATE_ZERO) return [false, '请确认虚拟采购订单状态,操作失败'];
+
+        //待入库
+        PurchaseOrderSpecial::where('del_time',0)->where('id',$data['id'])
+            ->update(['state' => PurchaseOrder::STATE_ONE]);
 
-    //待入库
-    PurchaseOrderSpecial::where('del_time',0)->where('id',$data['id'])
-        ->update(['state' => PurchaseOrder::STATE_ONE]);
+        return [true, $model->toArray()];
+    }
 
-    return [true, $model->toArray()];
-}
+    public function waitInventory($data){
+        $model = Inventory::where('id',$data['id'])
+            ->where('del_time',0)
+            ->first();
+        if(empty($model)) return [false, '盘点单不存在或已被删除'];
+        if($model->state > Inventory::STATE_ZERO) return [false, '请确认盘点单状态,操作失败'];
+
+        //待入库
+        Inventory::where('del_time',0)->where('id',$data['id'])
+            ->update(['state' => Inventory::STATE_ONE]);
+
+        return [true, $model->toArray()];
+    }
 
     public function waitConstruction($data){
         $model = Construction::where('id',$data['id'])
@@ -975,6 +995,67 @@ class CheckService extends Service
         return [true,''];
     }
 
+    public function confirmInventory($data){
+        $model = Inventory::where('order_number',$data['order_number'])
+            ->where('del_time',0)
+            ->first();
+        if(empty($model)) return [false,'盘点单不存在或已被删除'];
+        if($model->state != Inventory::STATE_ONE) return [false,'请确认盘点单状态,操作失败'];
+
+        if($data['type'] == self::TYPE_ONE){
+            $model->state = Inventory::STATE_TWO;
+            $model->save();
+        }else{
+            //驳回
+            $model->state = Inventory::State_minus_one;
+            $model->save();
+        }
+
+        return [true, $model->toArray()];
+    }
+
+    public function recordInventory($data, $order){
+        $result = InventorySub::where('del_time',0)
+            ->where('inventory_id',$order['id'])
+            ->get()->toArray();
+        if(empty($result)) return [false,'盘点单明细信息不存在或已被删除'];
+
+        $prefix = Inventory::prefix;
+        $insert = [];
+        $time = time();
+        foreach ($result as $value){
+            $key = $value['product_id'] . $value['storehouse_id'];
+
+            $number = 0;
+            if($value['add_num'] > 0){
+                $number = $value['add_num'];
+            }elseif($value['reduce_num'] > 0){
+                $number = -($value['reduce_num']);
+            }
+
+            if(isset($insert[$key])){
+                $insert[$key]['number'] += $number;
+            }else{
+                $insert[$key] = [
+                    'product_id' => $value['product_id'],
+                    'number' => $number,
+                    'order_type' => $prefix,
+                    'order_number' => $order['order_number'],
+                    'crt_time' => $time,
+                    'storehouse_id' => $value['storehouse_id'],
+                    'depart_id' => $order['depart_id'],
+                    'top_depart_id' => $order['top_depart_id'],
+                    'price' => $value['price'],
+                ];
+            }
+        }
+
+        $bool = InOutRecord::insert($insert);
+        if(! $bool) return [false,'流水写入失败'];
+
+        return [true,''];
+    }
+
     public function settleSalesOrder($data,$user){
         $model = SalesOrder::where('order_number', $data['order_number'])
             ->where('del_time',0)

+ 48 - 8
app/Service/ConstructionService.php

@@ -28,6 +28,7 @@ use App\Model\SalesOrderProductInfo;
 use App\Model\ScheduleInfo;
 use App\Model\SeeRange;
 use App\Model\Storehouse;
+use Carbon\Carbon;
 use Illuminate\Support\Facades\DB;
 //use Barryvdh\DomPDF\Facade as PDF;
 use Barryvdh\DomPDF\PDF;
@@ -541,13 +542,7 @@ class ConstructionService extends Service
         return [true, $construction];
     }
 
-    /**
-     * 施工订单列表
-     * @param $data
-     * @param $user
-     * @return array
-     */
-    public function constructionList($data,$user){
+    public function constructionCommon($data,$user){
         $model = Construction::Clear($user,$data);
         $model = $model->where('del_time',0)
             ->orderby('id', 'desc');
@@ -614,14 +609,59 @@ class ConstructionService extends Service
             $model->whereIn('install_position',$id);
         }
         if(! empty($data['order_number'])) $model->where('order_number', 'LIKE', '%'.$data['order_number'].'%');
-
         if(! empty($data['select_field'])) return $model->get()->toArray();
+        if(! empty($data['wx_crt_time'][0]) && ! empty($data['wx_crt_time'][1])) {
+            $model->where('crt_time','>=',$data['wx_crt_time'][0]);
+            $model->where('crt_time','<=',$data['wx_crt_time'][1]);
+        }
+
+        return $model;
+    }
+
+    /**
+     * 施工订单列表
+     * @param $data
+     * @param $user
+     * @return array
+     */
+    public function constructionList($data,$user){
+        $model = $this->constructionCommon($data, $user);
+        if(is_array($model)) return $model;
         $list = $this->limit($model,'',$data);
         $list = $this->fillData($list);
 
+        $count = $this->countData("crt_time", $data, $user);
+        $list['today'] = $count[0] ?? 0;
+        $list['yesterday'] = $count[1] ?? 0;
+
         return [true, $list];
     }
 
+    public function countData($column = "", $data, $user){
+        if(empty($column) || empty($data['from_wx'])) return [0, 0];
+
+
+        // 获取今天的开始和结束时间戳
+        $todayStart = Carbon::today()->startOfDay()->timestamp;
+        $todayEnd = Carbon::today()->endOfDay()->timestamp;
+
+        // 获取昨天的开始和结束时间戳
+        $yesterdayStart = Carbon::yesterday()->startOfDay()->timestamp;
+        $yesterdayEnd = Carbon::yesterday()->endOfDay()->timestamp;
+
+        $data['wx_' . $column] = [$todayStart, $todayEnd];
+        $model = $this->constructionCommon($data, $user);
+        // 查询今天的数据条数
+        $todayCount = $model->count();
+
+        $data['wx_' . $column] = [$yesterdayStart, $yesterdayEnd];
+        $model = $this->constructionCommon($data, $user);
+        // 查询昨天的数据条数
+        $yesterdayCount = $model->count();
+
+        return [$todayCount, $yesterdayCount];
+    }
+
     /**
      * 参数规则
      * @param $data

+ 86 - 8
app/Service/CustomerService.php

@@ -10,6 +10,7 @@ use App\Model\Employee;
 use App\Model\FollowUpRecord;
 use App\Model\Product;
 use App\Model\SeeRange;
+use Carbon\Carbon;
 use Illuminate\Support\Facades\DB;
 
 /**
@@ -515,13 +516,7 @@ class CustomerService extends Service
         return [true, $customer];
     }
 
-    /**
-     * 客户列表
-     * @param $data
-     * @param $user
-     * @return array
-     */
-    public function customerList($data,$user){
+    public function customerCommonSearch($data,$user){
         $model = Customer::Clear($user,$data);
         $model = $model->where('del_time',0)
             ->select('title','id','model_type','customer_intention','customer_from','customer_type','car_type','consulting_product','intention_product','progress_stage','address1','address2','crt_id','crt_time','mark','importance','company','company_short_name','depart_id','state_type','customer_state','pond_state','top_depart_id','fp_time','fp_top_depart_id')
@@ -602,13 +597,34 @@ class CustomerService extends Service
             $model->whereIn('id',array_column($customer_info,'customer_id'));
         }
 
+        if(! empty($data['wx_crt_time'][0]) && ! empty($data['wx_crt_time'][1])) {
+            $model->where('crt_time','>=',$data['wx_crt_time'][0]);
+            $model->where('crt_time','<=',$data['wx_crt_time'][1]);
+        }
+
+        return $model;
+    }
+
+    /**
+     * 客户列表
+     * @param $data
+     * @param $user
+     * @return array
+     */
+    public function customerList($data,$user){
+        $model = $this->customerCommonSearch($data,$user);
         $list = $this->limit($model,'',$data);
         $list = $this->fillData($list,$data);
 
+        //微信数据
+        $count = $this->countData("crt_time", $data, $user);
+        $list['today'] = $count[0] ?? 0;
+        $list['yesterday'] = $count[1] ?? 0;
+
         return [true, $list];
     }
 
-    public function customerList2($data,$user){
+    public function customer2CommonSearch($data,$user){
         $model = Customer::Clear($user,$data);
         $model = $model->where('del_time',0)
             ->where('fp_time','>',0)
@@ -669,10 +685,24 @@ class CustomerService extends Service
             $model->where('fp_time','>=',$return[0]);
             $model->where('fp_time','<=',$return[1]);
         }
+        if(! empty($data['wx_fp_time'][0]) && ! empty($data['wx_fp_time'][1])) {
+            $model->where('fp_time','>=',$data['wx_fp_time'][0]);
+            $model->where('fp_time','<=',$data['wx_fp_time'][1]);
+        }
+
+        return $model;
+    }
 
+    public function customerList2($data,$user){
+        $model = $this->customer2CommonSearch($data, $user);
         $list = $this->limit($model,'',$data);
         $list = $this->fillData($list,$data);
 
+        //微信数据
+        $count = $this->countData2("fp_time", $data, $user);
+        $list['today'] = $count[0] ?? 0;
+        $list['yesterday'] = $count[1] ?? 0;
+
         return [true, $list];
     }
 
@@ -896,6 +926,54 @@ class CustomerService extends Service
         return $data;
     }
 
+    public function countData($column = "", $data, $user){
+        if(empty($column) || empty($data['from_wx'])) return [0, 0];
+
+        // 获取今天的开始和结束时间戳
+        $todayStart = Carbon::today()->startOfDay()->timestamp;
+        $todayEnd = Carbon::today()->endOfDay()->timestamp;
+
+        // 获取昨天的开始和结束时间戳
+        $yesterdayStart = Carbon::yesterday()->startOfDay()->timestamp;
+        $yesterdayEnd = Carbon::yesterday()->endOfDay()->timestamp;
+
+        $data['wx_' . $column] = [$todayStart, $todayEnd];
+        $model = $this->customerCommonSearch($data, $user);
+        // 查询今天的数据条数
+        $todayCount = $model->count();
+
+        $data['wx_' . $column] = [$yesterdayStart, $yesterdayEnd];
+        $model = $this->customerCommonSearch($data, $user);
+        // 查询昨天的数据条数
+        $yesterdayCount = $model->count();
+
+        return [$todayCount, $yesterdayCount];
+    }
+
+    public function countData2($column = "", $data, $user){
+        if(empty($column) || empty($data['from_wx'])) return [0, 0];
+
+        // 获取今天的开始和结束时间戳
+        $todayStart = Carbon::today()->startOfDay()->timestamp;
+        $todayEnd = Carbon::today()->endOfDay()->timestamp;
+
+        // 获取昨天的开始和结束时间戳
+        $yesterdayStart = Carbon::yesterday()->startOfDay()->timestamp;
+        $yesterdayEnd = Carbon::yesterday()->endOfDay()->timestamp;
+
+        $data['wx_' . $column] = [$todayStart, $todayEnd];
+        $model = $this->customer2CommonSearch($data, $user);
+        // 查询今天的数据条数
+        $todayCount = $model->count();
+
+        $data['wx_' . $column] = [$yesterdayStart, $yesterdayEnd];
+        $model = $this->customer2CommonSearch($data, $user);
+        // 查询昨天的数据条数
+        $yesterdayCount = $model->count();
+
+        return [$todayCount, $yesterdayCount];
+    }
+
     //获取客资门店
     public function getCustomerDepart($customer_id = []){
         if(empty($customer_id)) return [];

+ 12 - 2
app/Service/InventoryService.php

@@ -37,10 +37,13 @@ class InventoryService extends Service
                         'counted_num' => $value['counted_num'],
                         'add_num' => $value['add_num'],
                         'reduce_num' => $value['reduce_num'],
+                        'price' => $value['price'] ?? 0,
                         'inventory_id' => $inventory_model->id
                     ];
                 }
                 InventorySub::insert($sub);
+
+                ProductInventoryService::changeLockNumber($user,$msg[0],$msg[1]);
             }
 
             DB::commit();
@@ -78,10 +81,13 @@ class InventoryService extends Service
                         'counted_num' => $value['counted_num'],
                         'add_num' => $value['add_num'],
                         'reduce_num' => $value['reduce_num'],
+                        'price' => $value['price'] ?? 0,
                         'inventory_id' => $inventory_model->id
                     ];
                 }
                 InventorySub::insert($sub);
+
+                ProductInventoryService::changeLockNumber($user,$msg[0],[]);
             }
 
             DB::commit();
@@ -123,7 +129,7 @@ class InventoryService extends Service
 
         $sub = InventorySub::where('del_time',0)
             ->where('inventory_id', $data['id'])
-            ->select('product_id','counted_num','add_num','reduce_num')
+            ->select('product_id','counted_num','add_num','reduce_num','price')
             ->get()->toArray();
         $map = (new ProductService())->getProductDetail(array_column($sub,'product_id'));
         foreach ($sub as $key => $value){
@@ -251,6 +257,10 @@ class InventoryService extends Service
             if(! $bool) return [false, '盘盈数量不合法,需是大于等于0的两位数值'];
             $bool = $this->checkNumber($value['reduce_num']);
             if(! $bool) return [false, '盘亏数量不合法,需是大于等于0的两位数值'];
+            if(isset($value['price'])){
+                $bool = $this->checkNumber($value['price']);
+                if(! $bool) return [false, '盘点单价不合法,需是大于等于0的两位数值'];
+            }
 
             $key = $value['product_id'] . ',' .$data['storehouse_id'];
             if(! isset($product_submit[$key])) $product_submit[$key] = 0;
@@ -297,7 +307,7 @@ class InventoryService extends Service
             if(! $status) return [false, $msg];
         }
 
-        return [true, ''];
+        return [true, [$product_submit_reduce, $product_save_reduce]];
     }
 
     /**

+ 173 - 65
app/Service/OaService.php

@@ -19,6 +19,7 @@ use App\Model\OaSub;
 use App\Model\OaSubEmployee;
 use App\Model\OaSubReportEmployee;
 use App\Model\OaSubRule;
+use App\Model\PurchaseOrderSpecial;
 use App\Model\RollFilm;
 use App\Model\RollFilmCombine;
 use App\Model\RollFilmCompany;
@@ -419,55 +420,114 @@ class OaService extends Service
         $order_no = $data['order_number'];
         $type = isset($data['opt_case']) ? $data['opt_case'] : 0;
 
-        //特殊的审批
-        $list = Oa::from('oa as o')
-            ->leftJoin('oa_sub as os', 'os.oa_id', 'o.id')
-            ->select('os.sort', 'os.type', 'os.sub_id')
-            ->where('o.del_time', 0)
-            ->where('o.sub_type', 2)
-            ->where('os.del_time', 0)
-            ->where('o.menu_id', $menu_id);
-        if (!empty($type)) $list = $list->where('os.sort', 1);
-        $list = $list->orderBy('os.sort')->get()->toArray();
-        if(empty($list)){
-            $list = Oa::from('oa as o')
-                ->leftJoin('oa_sub as os', 'os.oa_id', 'o.id')
-                ->select('os.sort', 'os.type', 'os.sub_id')
-                ->where('o.del_time', 0)
-                ->where('os.del_time', 0)
-                ->where('o.channel', $this->user['depart_top'][0]['depart_id'])
-                ->where('o.menu_id', $menu_id);
-            if (!empty($type)) $list = $list->where('os.sort', 1);
-            $list = $list->orderBy('os.sort')->get()->toArray();
-        }
-
-        if (empty($list)) {
-            list($parent_status,$parent_msg) = $this->returnOa($order_no, 1, $type);
-            if(!$parent_status) return [false, $parent_msg];
-            return [true, ''];
-        }
+        //如果是虚拟采购单 自动生成
+        if($menu_id == PurchaseOrderSpecial::menu_id){
+            list($status, $msg) = $this->createPurchaseSpecial($data);
+            return [$status, $msg];
+        }else{
 
-        try {
-            DB::beginTransaction();
+            //获取工作流
+            $list = $this->getOaProcess($menu_id);
 
-            list($employee_ids, $oa_sub_id,$order_detail) = $this->oaCommon($menu_id, ['order_number' => $orderObject], 1,0,$this->user);
-            if (empty($employee_ids)) {
+            //不存在直接审核通过
+            if(empty($list)){
                 list($parent_status,$parent_msg) = $this->returnOa($order_no, 1, $type);
-                if(!$parent_status) {
-                    DB::rollBack();
-                    return [false, $parent_msg];
+                if(!$parent_status) return [false, $parent_msg];
+                return [true, ''];
+            }
+
+            try {
+                DB::beginTransaction();
+
+                list($employee_ids, $oa_sub_id,$order_detail) = $this->oaCommon($menu_id, ['order_number' => $orderObject], 1,0,$this->user);
+                if (empty($employee_ids)) {
+                    list($parent_status,$parent_msg) = $this->returnOa($order_no, 1, $type);
+                    if(!$parent_status) {
+                        DB::rollBack();
+                        return [false, $parent_msg];
+                    }
+                    else{
+                        DB::commit();
+                        return [true, '审核成功'];
+                    }
                 }
-                else{
-                    DB::commit();
-                    return [true, '审核成功'];
+
+                $order = new OaOrder();
+                $order->menu_id = $menu_id;
+                $order->order_no = $order_no;
+                $order->opt_case = $type;
+                $order->channel = $this->user['depart_top'][0]['depart_id'];
+                $order->save();
+                $id = $order->id;
+
+                $oa_order_sub = new OaOrderSub();
+                $oa_order_sub->oa_order_id = $id;
+                $oa_order_sub->sort = 1;
+                $oa_order_sub->remark = '';
+                $oa_order_sub->type = 1;
+                $oa_order_sub->oa_sub_id = $oa_sub_id;
+                $oa_order_sub->save();
+                $oa_order_sub_id = $oa_order_sub->id;
+
+                //组织数据
+                $insert = $send_data = [];
+                $emp_map = Employee::whereIn('id',$employee_ids)->pluck('emp_name','id')->toArray();
+                $sys_menu = SysMenu::where('id', $menu_id)->value('title') ?? "";
+                foreach ($employee_ids as $employee_id) {
+                    $emp_tmp = $emp_map[$employee_id] ?? "";
+                    $send_data[] = [
+                        'employee_id' => $employee_id,
+                        'type' => 1,
+                        'state' => 0,
+                        'menu_id' => $menu_id,
+                        'order_number' => $order_detail['order_number'],
+                        'tmp_data' => [
+                            $order_detail['order_number'],
+                            $order_detail['crt_name'].'('.$sys_menu.')',
+                            $emp_tmp,
+                            date('Y-m-d H:i:s'),
+                        ],
+                    ];
+                    $insert[] = [
+                        'oa_order_id' => $id,
+                        'oa_order_sub_id' => $oa_order_sub_id,
+                        'employee_id' => $employee_id,
+                    ];
                 }
+                OaOrderSubEmployee::insert($insert);
+                DB::commit();
+
+                //发送消息
+                $this->sendWxOaCheckMessage($send_data);
+
+                return [true, '']; //success
+            } catch (\Exception $e) {
+                DB::rollBack();
+                $this->returnOa($order_no, 2, $type);
+                return [false, $e->getFile() . ':' .$e->getLine() . ':' . $e->getMessage()];
+            }
+        }
+    }
+
+    public function createPurchaseSpecial($data){
+        try {
+            $order = $data['order'] ?? [];
+
+            $depart = Depart::where('id', $order['supplier'])->first();
+            if(empty($depart) || empty($depart->notify_id)) {
+                //不存在直接审核通过
+                list($parent_status,$parent_msg) = $this->returnOa($data['order_number'], 1, $data['opt_case']);
+                if(!$parent_status) return [false, $parent_msg];
+                return [true, ''];
             }
+            $employee_ids = [$depart->notify_id];
+
+            DB::beginTransaction();
 
             $order = new OaOrder();
-            $order->menu_id = $menu_id;
-            $order->order_no = $order_no;
-            $order->opt_case = $type;
-            $order->channel = $this->user['depart_top'][0]['depart_id'];
+            $order->menu_id = $data['menu_id'];
+            $order->order_no = $data['order_number'];
+            $order->opt_case = $data['opt_case'];
             $order->save();
             $id = $order->id;
 
@@ -476,25 +536,25 @@ class OaService extends Service
             $oa_order_sub->sort = 1;
             $oa_order_sub->remark = '';
             $oa_order_sub->type = 1;
-            $oa_order_sub->oa_sub_id = $oa_sub_id;
+            $oa_order_sub->oa_sub_id = 0;
             $oa_order_sub->save();
             $oa_order_sub_id = $oa_order_sub->id;
 
             //组织数据
             $insert = $send_data = [];
             $emp_map = Employee::whereIn('id',$employee_ids)->pluck('emp_name','id')->toArray();
-            $sys_menu = SysMenu::where('id', $menu_id)->value('title') ?? "";
+            $sys_menu = SysMenu::where('id', $data['menu_id'])->value('title') ?? "";
             foreach ($employee_ids as $employee_id) {
                 $emp_tmp = $emp_map[$employee_id] ?? "";
                 $send_data[] = [
                     'employee_id' => $employee_id,
                     'type' => 1,
                     'state' => 0,
-                    'menu_id' => $menu_id,
-                    'order_number' => $order_detail['order_number'],
+                    'menu_id' => $data['menu_id'],
+                    'order_number' => $data['order_number'],
                     'tmp_data' => [
-                        $order_detail['order_number'],
-                        $order_detail['crt_name'].'('.$sys_menu.')',
+                        $data['order_number'],
+                        "系统生成".'('.$sys_menu.')',
                         $emp_tmp,
                         date('Y-m-d H:i:s'),
                     ],
@@ -506,19 +566,47 @@ class OaService extends Service
                 ];
             }
             OaOrderSubEmployee::insert($insert);
+
             DB::commit();
 
             //发送消息
             $this->sendWxOaCheckMessage($send_data);
 
-            return [true, '']; //success
+            return [true, ''];
         } catch (\Exception $e) {
             DB::rollBack();
-            $this->returnOa($order_no, 2, $type);
+            $this->returnOa($data['order_number'], 2, $data['opt_case']);
             return [false, $e->getFile() . ':' .$e->getLine() . ':' . $e->getMessage()];
         }
     }
 
+    //获取工作流
+    public function getOaProcess($menu_id){
+        //特殊的审批
+        $list = Oa::from('oa as o')
+            ->leftJoin('oa_sub as os', 'os.oa_id', 'o.id')
+            ->select('os.sort', 'os.type', 'os.sub_id')
+            ->where('o.del_time', 0)
+            ->where('o.sub_type', 2)
+            ->where('os.del_time', 0)
+            ->where('o.menu_id', $menu_id);
+        if (!empty($type)) $list = $list->where('os.sort', 1);
+        $list = $list->orderBy('os.sort')->get()->toArray();
+        if(empty($list)){
+            $list = Oa::from('oa as o')
+                ->leftJoin('oa_sub as os', 'os.oa_id', 'o.id')
+                ->select('os.sort', 'os.type', 'os.sub_id')
+                ->where('o.del_time', 0)
+                ->where('os.del_time', 0)
+                ->where('o.channel', $this->user['depart_top'][0]['depart_id'])
+                ->where('o.menu_id', $menu_id);
+            if (!empty($type)) $list = $list->where('os.sort', 1);
+            $list = $list->orderBy('os.sort')->get()->toArray();
+        }
+
+        return $list;
+    }
+
     public function oaCommon($menu_id, $param, $sort = 1, $parent_id = 0,$user='')
     {
         //创建request副本对象 没有参数让检索出来的数据为空数组
@@ -885,31 +973,51 @@ class OaService extends Service
         $user_id = $user['id'];
         $order_no = $data['order_no'];
         $menu_id = $data['menu_id'];
-        //特殊的审批
-        $oa_id = Oa::where('menu_id',$menu_id)->where('del_time', 0)->where('sub_type',2)->exists();
-        if($oa_id){
-            $detail = OaOrder::where('order_no', $order_no)
-                ->orderBy('id', 'desc')
-                ->where('menu_id', $menu_id)
-                ->first();
+
+        if($menu_id == PurchaseOrderSpecial::menu_id){
+            //虚拟采购单
+            list($status, $msg) = $this->oaOrderStatePurchase($data,$user);
+            return [$status, $msg];
         }else{
-            $detail = OaOrder::where('order_no', $order_no)
-                ->where('channel',$this->user['depart_top'][0]['depart_id'])
-                ->orderBy('id', 'desc')
-                ->where('menu_id', $menu_id)
-                ->first();
+            //特殊的审批
+            $oa_id = Oa::where('menu_id',$menu_id)->where('del_time', 0)->where('sub_type',2)->exists();
+            if($oa_id){
+                $detail = OaOrder::where('order_no', $order_no)
+                    ->orderBy('id', 'desc')
+                    ->where('menu_id', $menu_id)
+                    ->first();
+            }else{
+                $detail = OaOrder::where('order_no', $order_no)
+                    ->where('channel',$this->user['depart_top'][0]['depart_id'])
+                    ->orderBy('id', 'desc')
+                    ->where('menu_id', $menu_id)
+                    ->first();
+            }
+
+            if (empty($detail))  return [true, ['state' => 0]];
+            if ($detail->state == 2) return [true, ['state' => 0]];
+            $oa_detail = OaOrderSubEmployee::where('employee_id', $user_id)->where('oa_order_id', $detail->id)->pluck('oa_order_sub_id')->toArray();
+            if (empty($oa_detail)) return [true, ['state' => 0]];
+            $state = OaOrderSub::wherein('id', $oa_detail)->where('state', '<>', 2)->orderBy('sort', 'desc')->first();
+            if (in_array($state->state, [0, 2])) return [true, ['state' => 1, 'id' => $state->id]];
+
+            return [true, ['state' => 0]];
         }
+    }
 
+    public function oaOrderStatePurchase($data,$user){
+        $detail = OaOrder::where('order_no', $data['order_no'])
+            ->orderBy('id', 'desc')
+            ->where('menu_id', $data['menu_id'])
+            ->first();
         if (empty($detail))  return [true, ['state' => 0]];
         if ($detail->state == 2) return [true, ['state' => 0]];
-        $oa_detail = OaOrderSubEmployee::where('employee_id', $user_id)->where('oa_order_id', $detail->id)->pluck('oa_order_sub_id')->toArray();
+        $oa_detail = OaOrderSubEmployee::where('employee_id', $user['id'])->where('oa_order_id', $detail->id)->pluck('oa_order_sub_id')->toArray();
         if (empty($oa_detail)) return [true, ['state' => 0]];
-        $state = OaOrderSub::wherein('id', $oa_detail)->where('state', '<>', 2)->orderBy('sort', 'desc')->first();
+        $state = OaOrderSub::whereIn('id', $oa_detail)->where('state', '<>', 2)->orderBy('sort', 'desc')->first();
         if (in_array($state->state, [0, 2])) return [true, ['state' => 1, 'id' => $state->id]];
 
         return [true, ['state' => 0]];
-
-
     }
 
     public function checkAllOver($data)

+ 41 - 3
app/Service/PaymentReceiptService.php

@@ -10,6 +10,7 @@ use App\Model\PurchaseOrder;
 use App\Model\PurchaseOrderSpecial;
 use App\Model\ReturnExchangeOrder;
 use App\Model\SalesOrder;
+use Carbon\Carbon;
 use Illuminate\Support\Facades\DB;
 
 class PaymentReceiptService extends Service
@@ -416,7 +417,7 @@ class PaymentReceiptService extends Service
         return $return;
     }
 
-    public function customerList($data,$user){
+    public function customerCommon($data,$user){
         $model = PaymentReceipt::Clear($user,$data);
         $model = $model->where('del_time',0)
             ->select('type','id','data_type','order_number','data_order_no','amount','account','pay_way','crt_id','crt_time','mark','state','payment_receipt_date')
@@ -452,9 +453,22 @@ class PaymentReceiptService extends Service
             $id = (new RangeService())->paymentReceiptSearch($data);
             $model->whereIn('id',$id);
         }
+        if(! empty($data['wx_crt_time'][0]) && ! empty($data['wx_crt_time'][1])) {
+            $model->where('crt_time','>=',$data['wx_crt_time'][0]);
+            $model->where('crt_time','<=',$data['wx_crt_time'][1]);
+        }
+
+        return $model;
+    }
 
+    public function customerList($data,$user){
+        $model = $this->customerCommon($data, $user);
         $list = $this->limit($model,'',$data);
-        $list = $this->fillData($list);
+        $list = $this->fillData($list, $data);
+
+        $count = $this->countData("crt_time", $data, $user);
+        $list['today'] = $count[0] ?? 0;
+        $list['yesterday'] = $count[1] ?? 0;
 
         return [true, $list];
     }
@@ -760,7 +774,7 @@ class PaymentReceiptService extends Service
         return [true, ''];
     }
 
-    public function fillData($data){
+    public function fillData($data, $ergs){
         if(empty($data['data'])) return $data;
 
         $emp = Employee::whereIn('id',array_unique(array_column($data['data'],'crt_id')))
@@ -799,6 +813,30 @@ class PaymentReceiptService extends Service
         return $data;
     }
 
+    public function countData($column = "", $data, $user){
+        if(empty($column) || empty($data['from_wx'])) return [0, 0];
+
+        // 获取今天的开始和结束时间戳
+        $todayStart = Carbon::today()->startOfDay()->timestamp;
+        $todayEnd = Carbon::today()->endOfDay()->timestamp;
+
+        // 获取昨天的开始和结束时间戳
+        $yesterdayStart = Carbon::yesterday()->startOfDay()->timestamp;
+        $yesterdayEnd = Carbon::yesterday()->endOfDay()->timestamp;
+
+        $data['wx_' . $column] = [$todayStart, $todayEnd];
+        $model = $this->customerCommon($data, $user);
+        // 查询今天的数据条数
+        $todayCount = $model->count();
+
+        $data['wx_' . $column] = [$yesterdayStart, $yesterdayEnd];
+        $model = $this->customerCommon($data, $user);
+        // 查询昨天的数据条数
+        $yesterdayCount = $model->count();
+
+        return [$todayCount, $yesterdayCount];
+    }
+
     public function getStateMake($data){
         if(empty($data)) return [];
 

+ 2 - 0
app/Service/ProductInventoryService.php

@@ -7,6 +7,7 @@ use App\Model\Construction;
 use App\Model\ConstructionProductInfo;
 use App\Model\Depart;
 use App\Model\InOutRecord;
+use App\Model\Inventory;
 use App\Model\InvoiceOrder;
 use App\Model\InvoiceOrderInfo;
 use App\Model\OrderOperation;
@@ -319,6 +320,7 @@ class ProductInventoryService extends Service
         }
         $array[InvoiceOrder::prefix] = '发货单';
         $array[PurchaseOrder::prefix] = '采购单';
+        $array[Inventory::prefix] = '盘点单';
 
         return $array;
     }

+ 46 - 8
app/Service/PurchaseOrderService.php

@@ -19,6 +19,7 @@ use App\Model\SportsBag;
 use App\Model\SportsBagProductInfo;
 use App\Model\Storehouse;
 use App\Model\Supplier;
+use Carbon\Carbon;
 use Illuminate\Http\Request;
 use Illuminate\Support\Facades\DB;
 
@@ -429,18 +430,12 @@ class PurchaseOrderService extends Service
         return [true, ['file' => ['old' => $old]]];
     }
 
-    /**
-     * 获取采购单列表
-     * @param $data
-     * @param $user
-     * @return array
-     */
-    public function getList($data,$user){
+    public function purchaseCommon($data,$user){
         $model = PurchaseOrder::Clear($user,$data);
         $model = $model->where('del_time',0)
             ->select('order_number','id','depart_id','top_depart_id','mark','crt_time','state','crt_id','order_type','sales_order_id','supplier','purchase_id','purchase_total','discount_fee','other_fee','total','storehouse_id','invoice_state')
             ->orderby('id', 'desc');
-        
+
         if(! empty($data['purchase_id'])) $model->where('id', $data['purchase_id']);
         if(! empty($data['order_number'])) $model->where('order_number', 'LIKE', '%'.$data['order_number'].'%');
         if(! empty($data['depart_id'])) $model->where('depart_id', $data['depart_id']);
@@ -496,10 +491,29 @@ class PurchaseOrderService extends Service
             $model->whereIn('order_type',[PurchaseOrder::Order_type_three,PurchaseOrder::Order_type_four])
                 ->where('state',">=",PurchaseOrder::STATE_TWO);
         }
+        if(! empty($data['wx_crt_time'][0]) && ! empty($data['wx_crt_time'][1])) {
+            $model->where('crt_time','>=',$data['wx_crt_time'][0]);
+            $model->where('crt_time','<=',$data['wx_crt_time'][1]);
+        }
+
+        return $model;
+    }
 
+    /**
+     * 获取采购单列表
+     * @param $data
+     * @param $user
+     * @return array
+     */
+    public function getList($data,$user){
+        $model = $this->purchaseCommon($data, $user);
         $list = $this->limit($model,'',$data);
         $list = $this->fillListData($list,$data,$user);
 
+        $count = $this->countData("crt_time", $data, $user);
+        $list['today'] = $count[0] ?? 0;
+        $list['yesterday'] = $count[1] ?? 0;
+
         return [true, $list];
     }
 
@@ -634,6 +648,30 @@ class PurchaseOrderService extends Service
         return $data;
     }
 
+    public function countData($column = "", $data, $user){
+        if(empty($column) || empty($data['from_wx'])) return [0, 0];
+
+        // 获取今天的开始和结束时间戳
+        $todayStart = Carbon::today()->startOfDay()->timestamp;
+        $todayEnd = Carbon::today()->endOfDay()->timestamp;
+
+        // 获取昨天的开始和结束时间戳
+        $yesterdayStart = Carbon::yesterday()->startOfDay()->timestamp;
+        $yesterdayEnd = Carbon::yesterday()->endOfDay()->timestamp;
+
+        $data['wx_' . $column] = [$todayStart, $todayEnd];
+        $model = $this->purchaseCommon($data, $user);
+        // 查询今天的数据条数
+        $todayCount = $model->count();
+
+        $data['wx_' . $column] = [$yesterdayStart, $yesterdayEnd];
+        $model = $this->purchaseCommon($data, $user);
+        // 查询昨天的数据条数
+        $yesterdayCount = $model->count();
+
+        return [$todayCount, $yesterdayCount];
+    }
+
     public function fsdhOrder($data){
         if(empty($data['data'])) return [];
 

+ 2 - 3
app/Service/PurchaseOrderSpecialService.php

@@ -184,7 +184,7 @@ class PurchaseOrderSpecialService extends Service
         //坏账金额 = 已审核退货退款金额 - 红冲金额
         $order['payment_receipt_list']['bad_amount'] = bcsub($order['return_exchange_amount'], $order['payment_receipt_list']['red_amount'],2);
         //未回款金额 = 总金额 - 已回款金额 - 坏账金额 - 红冲
-        $total = bcadd($order['purchase_total'],$order['other_fee'],2);
+        $total = $order['purchase_total'];
         $order['payment_receipt_list']['not_receipt_amount'] = bcsub(bcsub(bcsub($total, $order['payment_receipt_list']['receipt_amount'],2), $order['payment_receipt_list']['bad_amount'], 2),$order['payment_receipt_list']['red_amount'],2);
         //回款单信息 审核过的
 
@@ -324,8 +324,7 @@ class PurchaseOrderSpecialService extends Service
             $fee1 = bcsub($one1 ,$red,2);
             $data['data'][$key]['fee1'] = $fee1;
             //未收金额
-            $total = bcadd($value['purchase_total'],$value['other_fee'],2);
-            $fee2 = bcsub(bcsub($total, $bad, 2),$red,2);
+            $fee2 = bcsub(bcsub($value['purchase_total'], $bad, 2),$red,2);
             $data['data'][$key]['fee2'] = $fee2;
             //红冲金额
             $data['data'][$key]['fee3'] = $red;

+ 40 - 1
app/Service/ReturnExchangeOrderService.php

@@ -12,6 +12,7 @@ use App\Model\SalesOrder;
 use App\Model\SalesOrderProductInfo;
 use App\Model\SeeRange;
 use App\Model\Storehouse;
+use Carbon\Carbon;
 use Illuminate\Support\Facades\DB;
 
 class ReturnExchangeOrderService extends Service
@@ -292,7 +293,7 @@ class ReturnExchangeOrderService extends Service
         return [true,''];
     }
 
-    public function getList($data,$user){
+    public function returnCommon($data,$user){
         $model = ReturnExchangeOrder::Clear($user,$data);
         $model = $model->where('del_time',0)
             ->select('id','order_number','data_id','difference_amount','state','crt_time','crt_id','mark','model_type','storehouse_id','type')
@@ -326,12 +327,50 @@ class ReturnExchangeOrderService extends Service
             }
         }
 
+       if(! empty($data['wx_crt_time'][0]) && ! empty($data['wx_crt_time'][1])) {
+            $model->where('crt_time','>=',$data['wx_crt_time'][0]);
+            $model->where('crt_time','<=',$data['wx_crt_time'][1]);
+       }
+
+       return $model;
+    }
+
+    public function getList($data,$user){
+        $model = $this->returnCommon($data, $user);
         $list = $this->limit($model,'',$data);
         $list = $this->fillListData($list);
 
+        $count = $this->countData("crt_time", $data, $user);
+        $list['today'] = $count[0] ?? 0;
+        $list['yesterday'] = $count[1] ?? 0;
+
         return [true, $list];
     }
 
+    public function countData($column = "", $data, $user){
+        if(empty($column) || empty($data['from_wx'])) return [0, 0];
+
+        // 获取今天的开始和结束时间戳
+        $todayStart = Carbon::today()->startOfDay()->timestamp;
+        $todayEnd = Carbon::today()->endOfDay()->timestamp;
+
+        // 获取昨天的开始和结束时间戳
+        $yesterdayStart = Carbon::yesterday()->startOfDay()->timestamp;
+        $yesterdayEnd = Carbon::yesterday()->endOfDay()->timestamp;
+
+        $data['wx_' . $column] = [$todayStart, $todayEnd];
+        $model = $this->returnCommon($data, $user);
+        // 查询今天的数据条数
+        $todayCount = $model->count();
+
+        $data['wx_' . $column] = [$yesterdayStart, $yesterdayEnd];
+        $model = $this->returnCommon($data, $user);
+        // 查询昨天的数据条数
+        $yesterdayCount = $model->count();
+
+        return [$todayCount, $yesterdayCount];
+    }
+
     public function getDataId($search,$user,$data){
         if($search < 0){
             $model2 = SalesOrder::Clear($user,$data);

+ 46 - 7
app/Service/SalesOrderService.php

@@ -27,6 +27,7 @@ use App\Model\SportsBagProductInfo;
 use App\Model\U8Job;
 use App\Model\WxEmployee;
 use App\Service\Weixin\WxSendMessageService;
+use Carbon\Carbon;
 use Illuminate\Support\Facades\DB;
 
 /**
@@ -742,13 +743,7 @@ class SalesOrderService extends Service
         return [true, $sales];
     }
 
-    /**
-     * 订单列表
-     * @param $data
-     * @param $user
-     * @return array
-     */
-    public function salesOrderList($data,$user){
+    public function salesOrderCommon($data,$user){
         $model = SalesOrder::Clear($user,$data);
         $model = $model->where('del_time',0)
             ->select('id','sales_order_type','model_type','order_number','selling_price','vin_no','car_type','order_type','customer_id','sign_time','crt_id','crt_time','mark','product_total','rate','construction_time','handover_time','other_fee','discount_fee','contract_fee','pay_way','car_type','year','mileage','color','original_set','processing','state','invoice_state','plat_type','plat_order','install_method','install_position','customer_contact','is_confirm','dispatch_time_second','contact_order_no')
@@ -866,10 +861,29 @@ class SalesOrderService extends Service
             $return = $service->constructionList($for_search,$user);
             $model->whereIn('id', array_unique(array_column($return,'sales_order_id')));
         }
+        if(! empty($data['wx_crt_time'][0]) && ! empty($data['wx_crt_time'][1])) {
+            $model->where('crt_time','>=',$data['wx_crt_time'][0]);
+            $model->where('crt_time','<=',$data['wx_crt_time'][1]);
+        }
+
+        return $model;
+    }
 
+    /**
+     * 订单列表
+     * @param $data
+     * @param $user
+     * @return array
+     */
+    public function salesOrderList($data,$user){
+        $model = $this->salesOrderCommon($data, $user);
         $list = $this->limit($model,'',$data);
         $list = $this->fillData($list,$data);
 
+        $count = $this->countData("crt_time", $data, $user);
+        $list['today'] = $count[0] ?? 0;
+        $list['yesterday'] = $count[1] ?? 0;
+
         return [true, $list];
     }
 
@@ -1188,6 +1202,31 @@ class SalesOrderService extends Service
         return $data;
     }
 
+    public function countData($column = "", $data, $user){
+        if(empty($column) || empty($data['from_wx'])) return [0, 0];
+
+
+        // 获取今天的开始和结束时间戳
+        $todayStart = Carbon::today()->startOfDay()->timestamp;
+        $todayEnd = Carbon::today()->endOfDay()->timestamp;
+
+        // 获取昨天的开始和结束时间戳
+        $yesterdayStart = Carbon::yesterday()->startOfDay()->timestamp;
+        $yesterdayEnd = Carbon::yesterday()->endOfDay()->timestamp;
+
+        $data['wx_' . $column] = [$todayStart, $todayEnd];
+        $model = $this->salesOrderCommon($data, $user);
+        // 查询今天的数据条数
+        $todayCount = $model->count();
+
+        $data['wx_' . $column] = [$yesterdayStart, $yesterdayEnd];
+        $model = $this->salesOrderCommon($data, $user);
+        // 查询昨天的数据条数
+        $yesterdayCount = $model->count();
+
+        return [$todayCount, $yesterdayCount];
+    }
+
     public function getSalesOrderProduct($data_id)
     {
         $product = [];

+ 4 - 0
config/header/44.php

@@ -31,6 +31,10 @@ return [
         'value' => '其它费用',
     ],
     [
+        'key' => 'discount_fee',
+        'value' => '优惠金额',
+    ],
+    [
         'key' => 'fee1',
         'value' => '已结金额',
     ],

+ 2 - 1
config/morequery.php

@@ -64,12 +64,13 @@ return [
         "wx/roleList",
     ],
 
-    //34 施工单 35 退换货单 37 订单合同  38 T9采购单  45 分社采购单 48 收付款单
+    //34 施工单 35 退换货单 37 订单合同  38 T9采购单  44 虚拟采购单 45 分社采购单 48 收付款单
     "detail_message" => [
         34 => '/pages/ConstructionOrder/add/detail/detail?order_number=',
         35 => '/pages/ReturnExchangeOrder/detail/detail?order_number=',
         37 => '/pageA/pages/SalesOrder/detail/detail?order_number=',
         38 => '',
+        44 => '',
         45 => '/pageA/pages/ProcureOrder/ProcureDetail/ProcureDetail?order_number=',
         48 => '/pages/PayOrder/detail/detail?order_number=',
     ],

+ 3 - 0
config/wx/msg.php

@@ -14,6 +14,9 @@ return [
         '38_1' => 1,
         '38_2' => 2,
         '38_3_2' => 3,
+        '44_1' => 1,
+        '44_2' => 2,
+        '44_3_2' => 3,
         '45_1' => 1,
         '45_2' => 2,
         '45_3_2' => 3,

+ 1 - 1
routes/api.php

@@ -260,7 +260,7 @@ Route::group(['middleware'=> ['checkLogin']],function ($route){
     $route->any('inventoryList', 'Api\InventoryController@inventoryList');
     $route->any('inventoryEdit', 'Api\InventoryController@inventoryEdit');
     $route->any('inventoryDetail', 'Api\InventoryController@inventoryDetail');
-    $route->any('inventoryAdd', 'Api\InventoryController@inventoryAdd')->middleware('OrderDeal');
+    $route->any('inventoryAdd', 'Api\InventoryController@inventoryAdd')->middleware('OrderDeal')->middleware('OrderDeal');
     $route->any('inventoryDel', 'Api\InventoryController@inventoryDel');
     $route->any('inventoryImport', 'Api\InventoryController@inventoryImport')->middleware('OrderDeal');