|
@@ -1,1114 +0,0 @@
|
|
|
-<?php
|
|
|
-
|
|
|
-namespace App\Service;
|
|
|
-
|
|
|
-use App\Model\BasicType;
|
|
|
-use App\Model\BasicTypeAllUse;
|
|
|
-use App\Model\Construction;
|
|
|
-use App\Model\ConstructionInfo;
|
|
|
-use App\Model\Customer;
|
|
|
-use App\Model\CustomerInfo;
|
|
|
-use App\Model\Depart;
|
|
|
-use App\Model\Employee;
|
|
|
-use App\Model\Inventory;
|
|
|
-use App\Model\InvoiceOrder;
|
|
|
-use App\Model\OaOrder;
|
|
|
-use App\Model\OaOrderSub;
|
|
|
-use App\Model\OaOrderSubEmployee;
|
|
|
-use App\Model\PaymentReceipt;
|
|
|
-use App\Model\PaymentReceiptInfo;
|
|
|
-use App\Model\Product;
|
|
|
-use App\Model\ProductAdjustment;
|
|
|
-use App\Model\PurchaseOrder;
|
|
|
-use App\Model\ReturnExchangeOrder;
|
|
|
-use App\Model\SalesOrder;
|
|
|
-use App\Model\SalesOrderInfo;
|
|
|
-use App\Model\SeeRange;
|
|
|
-use App\Model\SportsBag;
|
|
|
-use Illuminate\Support\Facades\DB;
|
|
|
-
|
|
|
-class RangeService extends Service
|
|
|
-{
|
|
|
- //设置可见范围 除了合同
|
|
|
- public function seeRange($data,$user){
|
|
|
- if(empty($data['data_type'])) return [false, "可见范围数据类型不能为空"];
|
|
|
- if(! in_array($data['data_type'], SeeRange::$type)) return [false, "可见范围数据类型错误"];
|
|
|
- if(empty($data['data_id'])) return [false,'可见范围数据ID不能为空'];
|
|
|
-
|
|
|
- $time = time();
|
|
|
- SeeRange::where('del_time',0)
|
|
|
- ->where('data_type',$data['data_type'])
|
|
|
- ->where('data_id',$data['data_id'])
|
|
|
- ->whereIn('type',[SeeRange::data_one, SeeRange::data_two])
|
|
|
- ->update(['del_time' => $time]);
|
|
|
-
|
|
|
- if(! empty($data['depart'])){
|
|
|
- $insert = [];
|
|
|
- foreach ($data['depart'] as $value){
|
|
|
- $insert[] = [
|
|
|
- 'data_id' => $data['data_id'],
|
|
|
- 'data_type' => $data['data_type'],
|
|
|
- 'param_id' => $value,
|
|
|
- 'type' => SeeRange::data_one,
|
|
|
- 'crt_time' => $time,
|
|
|
- ];
|
|
|
- }
|
|
|
- SeeRange::insert($insert);
|
|
|
- }
|
|
|
-
|
|
|
- if(! empty($data['employee'])){
|
|
|
- $insert = [];
|
|
|
- foreach ($data['employee'] as $value){
|
|
|
- $insert[] = [
|
|
|
- 'data_id' => $data['data_id'],
|
|
|
- 'data_type' => $data['data_type'],
|
|
|
- 'param_id' => $value,
|
|
|
- 'type' => SeeRange::data_two,
|
|
|
- 'crt_time' => $time,
|
|
|
- ];
|
|
|
- }
|
|
|
- SeeRange::insert($insert);
|
|
|
- }
|
|
|
-
|
|
|
- return [true,''];
|
|
|
- }
|
|
|
-
|
|
|
- //可见范围删除
|
|
|
- public function RangeDelete($data_id = 0, $data_type = 0){
|
|
|
- if(empty($data_id) || empty($data_type)) return;
|
|
|
-
|
|
|
- SeeRange::where('del_time',0)
|
|
|
- ->where('data_id',$data_id)
|
|
|
- ->where('data_type',$data_type)
|
|
|
- ->update(['del_time'=> time()]);
|
|
|
- }
|
|
|
-
|
|
|
- //获取可见范围详情
|
|
|
- public function RangeDetail($data_id = 0, $data_type = 0){
|
|
|
- if(empty($data_id) || empty($data_type)) return [];
|
|
|
-
|
|
|
- $see = SeeRange::where('del_time',0)
|
|
|
- ->where('data_id',$data_id)
|
|
|
- ->where('data_type',$data_type)
|
|
|
- ->get()->toArray();
|
|
|
- $depart_map = Depart::where('del_time',0)->pluck('title','id')->toArray();
|
|
|
- $emp_map = Employee::where('del_time',0)->pluck('emp_name','id')->toArray();
|
|
|
-
|
|
|
- $depart = $employee = $depart2 = [];
|
|
|
- foreach ($see as $value){
|
|
|
- if ($value['type'] == SeeRange::data_one){
|
|
|
- $name = $depart_map[$value['param_id']] ?? "";
|
|
|
- if(! empty($name)){
|
|
|
- $tmp = [
|
|
|
- 'id' => $value['param_id'],
|
|
|
- 'name' => $depart_map[$value['param_id']] ?? "",
|
|
|
- ];
|
|
|
- $depart[] = $tmp;
|
|
|
- }
|
|
|
- }elseif ($value['type'] == SeeRange::data_two){
|
|
|
- $name = $emp_map[$value['param_id']] ?? '';
|
|
|
- if(! empty($name)){
|
|
|
- $tmp = [
|
|
|
- 'id' => $value['param_id'],
|
|
|
- 'name' => $emp_map[$value['param_id']] ?? '',
|
|
|
- ];
|
|
|
- $employee[] = $tmp;
|
|
|
- }
|
|
|
- }elseif ($value['type'] == SeeRange::data_three){
|
|
|
- $name = $depart_map[$value['param_id']] ?? '';
|
|
|
- if(! empty($name)) {
|
|
|
- $tmp = [
|
|
|
- 'id' => $value['param_id'],
|
|
|
- 'name' => $depart_map[$value['param_id']] ?? '',
|
|
|
- ];
|
|
|
- $depart2[] = $tmp;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return [$depart, $employee, $depart2];
|
|
|
- }
|
|
|
-
|
|
|
- //获取可见范围数据id
|
|
|
- public static function getRangeDataId($user,$data_type){
|
|
|
- $user_id = $user['id'];
|
|
|
- $depart_id = $user['depart_range'];
|
|
|
- $type = SeeRange::data_two;
|
|
|
- $type2 = [SeeRange::data_one,SeeRange::data_three];
|
|
|
- $type2 = implode(',',$type2);
|
|
|
- $depart_str = implode(',',$depart_id);
|
|
|
- if(empty($depart_str)) {
|
|
|
- $string = "param_id = 0";
|
|
|
- }else{
|
|
|
- $string = "param_id IN({$depart_str})";
|
|
|
- }
|
|
|
- // 人为当前用户时, 或部门在当前用户范围内
|
|
|
- $str = "(param_id = $user_id AND type = $type) OR ($string AND type IN ({$type2}))";
|
|
|
-
|
|
|
- // 可见部门 可见人 可以看见
|
|
|
- $data_id = SeeRange::where('del_time',0)
|
|
|
- ->where('data_type', $data_type)
|
|
|
- ->where(function ($query) use($str) {
|
|
|
- $query->whereRaw($str);
|
|
|
- })->select('data_id')->get()->toArray();
|
|
|
- return array_unique(array_column($data_id,'data_id'));
|
|
|
- }
|
|
|
-
|
|
|
- //获取客户可见数据
|
|
|
- public static function customerRange($user,$search){
|
|
|
- // 销售人员/负责人 3协同人 可以看见
|
|
|
- $customer_id = CustomerInfo::where('del_time',0)
|
|
|
- ->where('data_id',$user['id'])
|
|
|
- ->whereIn('type',CustomerInfo::$see_man)
|
|
|
- ->select('customer_id')->get()->toArray();
|
|
|
- $return_id = array_unique(array_column($customer_id,'customer_id'));
|
|
|
- //可见范围id
|
|
|
- $rang_id = Self::getRangeDataId($user,SeeRange::type_one);
|
|
|
- //并和
|
|
|
- $return_id = array_unique(array_merge_recursive($return_id,$rang_id));
|
|
|
-
|
|
|
- if(! empty($search['top_depart_id']) && ! empty($user['is_all_depart'])){
|
|
|
- // 分批查询数据库,避免 IN 查询太长
|
|
|
- $filtered_ids = [];
|
|
|
- foreach (array_chunk($return_id, 500) as $chunk) {
|
|
|
- $filtered_ids = array_merge($filtered_ids, Customer::whereIn('id', $chunk)
|
|
|
- ->where('top_depart_id', $search['top_depart_id'])
|
|
|
- ->where('del_time', 0)
|
|
|
- ->pluck('id')
|
|
|
- ->toArray());
|
|
|
- }
|
|
|
-
|
|
|
- $return_id = $filtered_ids;
|
|
|
-
|
|
|
-// $id = DB::table('customer')
|
|
|
-// ->where('del_time',0)
|
|
|
-// ->where('top_depart_id',$search['top_depart_id'])
|
|
|
-// ->select('id')->get()->toArray();
|
|
|
-// $id = array_column($id,'id');
|
|
|
-// foreach ($return_id as $key => $value){
|
|
|
-// if(! in_array($value,$id)) unset($return_id[$key]);
|
|
|
-// }
|
|
|
- }
|
|
|
-
|
|
|
- return $return_id;
|
|
|
- }
|
|
|
-
|
|
|
- //获取施工单可见数据
|
|
|
- public static function constructionRange($user,$search){
|
|
|
- //单据中选择的签订负责协同人
|
|
|
- $construction_id = ConstructionInfo::where('del_time',0)
|
|
|
- ->where('employee_id',$user['id'])
|
|
|
- ->select('construction_id')
|
|
|
- ->get()->toArray();
|
|
|
- $return_id = array_unique(array_column($construction_id,'construction_id'));
|
|
|
-
|
|
|
- //可见范围id
|
|
|
- $return = Self::getRangeDataId($user,SeeRange::type_two);
|
|
|
- $return_id = array_unique(array_merge_recursive($return_id,$return));
|
|
|
-
|
|
|
- if(! empty($search['top_depart_id']) && ! empty($user['is_all_depart'])){
|
|
|
- $id = DB::table('construction')
|
|
|
- ->where('del_time',0)
|
|
|
- ->where('top_depart_id',$search['top_depart_id'])
|
|
|
- ->select('id')->get()->toArray();
|
|
|
- $id = array_column($id,'id');
|
|
|
- foreach ($return_id as $key => $value){
|
|
|
- if(! in_array($value,$id)) unset($return_id[$key]);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if(isset($search['is_check'])){
|
|
|
- $args = self::constructionCheck($user,$search);
|
|
|
- $result = Construction::whereIn('id',$return_id)
|
|
|
- ->when(! empty($args), function ($query) use ($args) {
|
|
|
- return $query->whereRaw($args);
|
|
|
- })
|
|
|
- ->select('id')
|
|
|
- ->get()->toArray();
|
|
|
- $return_id = array_column($result,'id');
|
|
|
- }
|
|
|
-
|
|
|
- return $return_id;
|
|
|
- }
|
|
|
-
|
|
|
- //获取发货单可见数据
|
|
|
- public static function invoiceRange($user,$search){
|
|
|
- //可见范围id
|
|
|
- $return_id = Self::getRangeDataId($user,SeeRange::type_three);
|
|
|
-
|
|
|
- if(! empty($search['top_depart_id']) && ! empty($user['is_all_depart'])){
|
|
|
- $id = DB::table('invoice_order')
|
|
|
- ->where('del_time',0)
|
|
|
- ->where('top_depart_id',$search['top_depart_id'])
|
|
|
- ->select('id')->get()->toArray();
|
|
|
- $id = array_column($id,'id');
|
|
|
- foreach ($return_id as $key => $value){
|
|
|
- if(! in_array($value,$id)) unset($return_id[$key]);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if(isset($search['is_check'])){
|
|
|
- $args = self::invoiceCheck($user,$search);
|
|
|
- $result = InvoiceOrder::whereIn('id',$return_id)
|
|
|
- ->when(! empty($args), function ($query) use ($args) {
|
|
|
- return $query->whereRaw($args);
|
|
|
- })
|
|
|
- ->select('id')
|
|
|
- ->get()->toArray();
|
|
|
- $return_id = array_column($result,'id');
|
|
|
- }
|
|
|
-
|
|
|
- return $return_id;
|
|
|
- }
|
|
|
-
|
|
|
- //获取产品可见数据
|
|
|
- public static function productRange($user,$search){
|
|
|
- //可见范围id
|
|
|
- $return_id = Self::getRangeDataId($user,SeeRange::type_four);
|
|
|
-
|
|
|
- if(! empty($search['top_depart_id']) && ! empty($user['is_all_depart'])){
|
|
|
- $id = DB::table('product')
|
|
|
- ->where('del_time',0)
|
|
|
- ->where('top_depart_id',$search['top_depart_id'])
|
|
|
- ->select('id')->get()->toArray();
|
|
|
- $id = array_column($id,'id');
|
|
|
- foreach ($return_id as $key => $value){
|
|
|
- if(! in_array($value,$id)) unset($return_id[$key]);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return $return_id;
|
|
|
- }
|
|
|
-
|
|
|
- //获取产品不可见数据
|
|
|
- public static function productRangeNot($user,$search){
|
|
|
- //不可见范围id
|
|
|
- $return_id = Self::getRangeDataId($user,SeeRange::type_four);
|
|
|
-
|
|
|
- //分社管理员
|
|
|
- if(empty($user['is_all_depart']) && ! empty($user['is_manager'])) {
|
|
|
- $depart = array_shift($user['rule_depart']);
|
|
|
- $depart_id = $depart['depart_id'] ?? 0;
|
|
|
- $id = DB::table('product')
|
|
|
- ->where('del_time',0)
|
|
|
- ->where('top_depart_id',$depart_id)
|
|
|
- ->select('id')->get()->toArray();
|
|
|
- $id = array_column($id,'id');
|
|
|
- foreach ($return_id as $key => $value){
|
|
|
- if(in_array($value,$id)) unset($return_id[$key]);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return $return_id;
|
|
|
- }
|
|
|
-
|
|
|
- //获取采购单可见数据
|
|
|
- public static function purchaseRange($user,$search){
|
|
|
- //可见范围id
|
|
|
- $return_id = Self::getRangeDataId($user,SeeRange::type_five);
|
|
|
-
|
|
|
- if(! empty($search['top_depart_id']) && ! empty($user['is_all_depart'])){
|
|
|
- $id = DB::table('purchase_order')
|
|
|
- ->where('del_time',0)
|
|
|
- ->where('top_depart_id',$search['top_depart_id'])
|
|
|
- ->select('id')->get()->toArray();
|
|
|
- $id = array_column($id,'id');
|
|
|
- foreach ($return_id as $key => $value){
|
|
|
- if(! in_array($value,$id)) unset($return_id[$key]);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if(isset($search['is_check'])){
|
|
|
- $args = self::purchaseCheck($user,$search);
|
|
|
- $result = PurchaseOrder::whereIn('id',$return_id)
|
|
|
- ->when(! empty($args), function ($query) use ($args) {
|
|
|
- return $query->whereRaw($args);
|
|
|
- })
|
|
|
- ->select('id')
|
|
|
- ->get()->toArray();
|
|
|
- $return_id = array_column($result,'id');
|
|
|
- }
|
|
|
-
|
|
|
- return $return_id;
|
|
|
- }
|
|
|
-
|
|
|
- //获取退换货单可见数据
|
|
|
- public static function returnExchangeOrderRange($user,$search){
|
|
|
- //可见范围id
|
|
|
- $return_id = Self::getRangeDataId($user,SeeRange::type_six);
|
|
|
- if(! empty($search['top_depart_id']) && ! empty($user['is_all_depart'])){
|
|
|
- $id = DB::table('return_exchange_order')
|
|
|
- ->where('del_time',0)
|
|
|
- ->where('top_depart_id',$search['top_depart_id'])
|
|
|
- ->select('id')->get()->toArray();
|
|
|
- $id = array_column($id,'id');
|
|
|
- foreach ($return_id as $key => $value){
|
|
|
- if(! in_array($value,$id)) unset($return_id[$key]);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if(isset($search['is_check'])){
|
|
|
- $args = self::returnExchangeOrderCheck($user,$search);
|
|
|
- $result = ReturnExchangeOrder::whereIn('id',$return_id)
|
|
|
- ->when(! empty($args), function ($query) use ($args) {
|
|
|
- return $query->whereRaw($args);
|
|
|
- })
|
|
|
- ->select('id')
|
|
|
- ->get()->toArray();
|
|
|
- $return_id = array_column($result,'id');
|
|
|
- }
|
|
|
-
|
|
|
- return $return_id;
|
|
|
- }
|
|
|
-
|
|
|
- //获取合同可见数据
|
|
|
- public static function salesOrderRange($user,$search){
|
|
|
- //单据中选择的签订负责协同人
|
|
|
- $sales_order_id = SalesOrderInfo::where('del_time',0)
|
|
|
- ->whereIn('type',SalesOrderInfo::$man)
|
|
|
- ->where('data_id',$user['id'])
|
|
|
- ->select('sales_order_id')
|
|
|
- ->get()->toArray();
|
|
|
- $sales_order_id = array_unique(array_column($sales_order_id,'sales_order_id'));
|
|
|
-
|
|
|
- $bool = ! empty($search['top_depart_id']) && ! empty($user['is_all_depart']);
|
|
|
- if(! $bool){
|
|
|
- $current_top_depart_id = $user['depart_top'][0] ?? [];
|
|
|
- $current_top_depart_id = $current_top_depart_id['depart_id'] ?? 0;
|
|
|
- //查找是否合同指派了门店
|
|
|
- $dispatch_company = SeeRange::where('del_time',0)
|
|
|
- ->whereIn('data_id',$sales_order_id)
|
|
|
- ->where('param_id', $current_top_depart_id)
|
|
|
- ->where('data_type',SeeRange::type_seven)
|
|
|
- ->where('type',SeeRange::data_three)
|
|
|
- ->select('data_id')
|
|
|
- ->get()->toArray();
|
|
|
- $dispatch_company = array_column($dispatch_company,'data_id');
|
|
|
-
|
|
|
- // 找出仅在 $array1 中存在的元素
|
|
|
- $diff1 = array_diff($sales_order_id, $dispatch_company);
|
|
|
-
|
|
|
- $sales_order_id = SalesOrder::whereIn('id', $diff1)
|
|
|
- ->where('top_depart_id',$current_top_depart_id)
|
|
|
- ->select('id')
|
|
|
- ->get()->toArray();
|
|
|
- $sales_order_id = array_column($sales_order_id,'sales_order_id');
|
|
|
- $sales_order_id = array_merge_recursive($sales_order_id,$dispatch_company);
|
|
|
- }
|
|
|
-
|
|
|
- //指派后 可见范围id
|
|
|
- $return = Self::getRangeDataId($user,SeeRange::type_seven);
|
|
|
-
|
|
|
- $return_id = array_unique(array_merge_recursive($sales_order_id,$return));
|
|
|
- if($bool){
|
|
|
- $id = DB::table('sales_order')
|
|
|
- ->where('del_time',0)
|
|
|
- ->where('top_depart_id',$search['top_depart_id'])
|
|
|
- ->select('id')->get()->toArray();
|
|
|
- $id = array_column($id,'id');
|
|
|
- foreach ($return_id as $key => $value){
|
|
|
- if(! in_array($value,$id)) unset($return_id[$key]);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if(isset($search['is_check'])){
|
|
|
- $args = self::salesOrderCheck($user,$search);
|
|
|
- $result = SalesOrder::whereIn('id',$return_id)
|
|
|
- ->when(! empty($args), function ($query) use ($args) {
|
|
|
- return $query->whereRaw($args);
|
|
|
- })
|
|
|
- ->select('id')
|
|
|
- ->get()->toArray();
|
|
|
- $return_id = array_column($result,'id');
|
|
|
- }
|
|
|
-
|
|
|
- return $return_id;
|
|
|
- }
|
|
|
-
|
|
|
- //获取特殊采购单可见数据
|
|
|
- public static function purchaseSpecialRange($user,$search){
|
|
|
- //可见范围id
|
|
|
- $return_id = Self::getRangeDataId($user,SeeRange::type_ten);
|
|
|
-
|
|
|
-// if(! empty($search['top_depart_id']) && ! empty($user['is_all_depart'])){
|
|
|
-// $id = DB::table('purchase_order')
|
|
|
-// ->where('del_time',0)
|
|
|
-// ->where('top_depart_id',$search['top_depart_id'])
|
|
|
-// ->select('id')->get()->toArray();
|
|
|
-// $id = array_column($id,'id');
|
|
|
-// foreach ($return_id as $key => $value){
|
|
|
-// if(! in_array($value,$id)) unset($return_id[$key]);
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
- return $return_id;
|
|
|
- }
|
|
|
-
|
|
|
- //获取供应商可见数据
|
|
|
- public static function supplierRange($user,$search){
|
|
|
- //可见范围id
|
|
|
- $return_id = Self::getRangeDataId($user,SeeRange::type_nine);
|
|
|
-
|
|
|
- if(! empty($search['top_depart_id']) && ! empty($user['is_all_depart'])){
|
|
|
- $id = DB::table('supplier')
|
|
|
- ->where('del_time',0)
|
|
|
- ->where('top_depart_id',$search['top_depart_id'])
|
|
|
- ->select('id')->get()->toArray();
|
|
|
- $id = array_column($id,'id');
|
|
|
- foreach ($return_id as $key => $value){
|
|
|
- if(! in_array($value,$id)) unset($return_id[$key]);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return $return_id;
|
|
|
- }
|
|
|
-
|
|
|
- //获取活动包可见数据
|
|
|
- public static function sportsBagRange($user,$search){
|
|
|
- //可见范围id
|
|
|
- $return_id = Self::getRangeDataId($user,SeeRange::type_eight);
|
|
|
-
|
|
|
- if(! empty($search['top_depart_id']) && ! empty($user['is_all_depart'])){
|
|
|
- $id = DB::table('sports_bag')
|
|
|
- ->where('del_time',0)
|
|
|
- ->where('top_depart_id',$search['top_depart_id'])
|
|
|
- ->select('id')->get()->toArray();
|
|
|
- $id = array_column($id,'id');
|
|
|
- foreach ($return_id as $key => $value){
|
|
|
- if(! in_array($value,$id)) unset($return_id[$key]);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return $return_id;
|
|
|
- }
|
|
|
-
|
|
|
- //产品不可见部门
|
|
|
- public static function productNotSeeRange($product_id){
|
|
|
- $return = [];
|
|
|
- $result = SeeRange::where('del_time',0)
|
|
|
- ->where('data_type', SeeRange::type_four)
|
|
|
- ->whereIn('data_id',$product_id)
|
|
|
- ->where('type',SeeRange::data_one)
|
|
|
- ->select('param_id as depart_id','data_id as product_id')
|
|
|
- ->get()->toArray();
|
|
|
- foreach ($result as $value){
|
|
|
- $return[$value['product_id']][] = $value['depart_id'];
|
|
|
- }
|
|
|
-
|
|
|
- return $return;
|
|
|
- }
|
|
|
-
|
|
|
- //产品签订人负责人
|
|
|
- public function salesOrderSearch($data){
|
|
|
- $return1 = $return2 = [];
|
|
|
- if(! empty($data['qd'])){
|
|
|
- $emp_id = Employee::where('del_time',0)
|
|
|
- ->where('emp_name','LIKE', '%'.$data['qd'].'%')
|
|
|
- ->select('id')->get()->toArray();
|
|
|
- $emp_id = array_column($emp_id,'id');
|
|
|
- //单据中选择的签订人
|
|
|
- $sales_order_id = SalesOrderInfo::where('del_time',0)
|
|
|
- ->where('type',SalesOrderInfo::type_one)
|
|
|
- ->whereIn('data_id',$emp_id)
|
|
|
- ->select('sales_order_id')
|
|
|
- ->get()->toArray();
|
|
|
- $return1 = array_unique(array_column($sales_order_id,'sales_order_id'));
|
|
|
- }
|
|
|
- if(! empty($data['fz'])){
|
|
|
- $emp_id = Employee::where('del_time',0)
|
|
|
- ->where('emp_name','LIKE', '%'.$data['fz'].'%')
|
|
|
- ->select('id')->get()->toArray();
|
|
|
- $emp_id = array_column($emp_id,'id');
|
|
|
- //单据中选择的负责人
|
|
|
- $sales_order_id = SalesOrderInfo::where('del_time',0)
|
|
|
- ->where('type',SalesOrderInfo::type_two)
|
|
|
- ->whereIn('data_id',$emp_id)
|
|
|
- ->select('sales_order_id')
|
|
|
- ->get()->toArray();
|
|
|
- $return2 = array_unique(array_column($sales_order_id,'sales_order_id'));
|
|
|
- }
|
|
|
-
|
|
|
- if(! empty($data['qd']) && ! empty($data['fz'])){
|
|
|
- $return = array_intersect($return1, $return2);
|
|
|
- }elseif(!empty($data['qd'])){
|
|
|
- $return = $return1;
|
|
|
- }else{
|
|
|
- $return = $return2;
|
|
|
- }
|
|
|
-
|
|
|
- return $return;
|
|
|
- }
|
|
|
-
|
|
|
- //指派门店
|
|
|
- public function salesOrderZpSearch($data){
|
|
|
- $return = SeeRange::where('del_time',0)
|
|
|
- ->where('param_id',$data['zp'])
|
|
|
- ->where('data_type',SeeRange::type_seven)
|
|
|
- ->where('type',SeeRange::data_three)
|
|
|
- ->select('data_id')
|
|
|
- ->get()->toArray();
|
|
|
-
|
|
|
- return array_column($return,'data_id');
|
|
|
- }
|
|
|
-
|
|
|
- //客户创建人
|
|
|
- public function salesOrderCustomerCrtSearch($user,$data){
|
|
|
- $emp_id = Employee::where('del_time',0)
|
|
|
- ->where('emp_name','LIKE', '%'.$data['customer_crt_name'].'%')
|
|
|
- ->select('id')->get()->toArray();
|
|
|
- $emp_id = array_column($emp_id,'id');
|
|
|
-
|
|
|
- $model2 = Customer::Clear($user,$data);
|
|
|
- $customer = $model2->where('del_time',0)
|
|
|
- ->whereIn('crt_id', $emp_id)
|
|
|
- ->select('id')
|
|
|
- ->get()->toArray();
|
|
|
-
|
|
|
- return array_column($customer,'id');
|
|
|
- }
|
|
|
-
|
|
|
- //收付款人搜索
|
|
|
- public function paymentReceiptSearch($data){
|
|
|
- $emp_id = Employee::where('del_time',0)
|
|
|
- ->where('emp_name','LIKE', '%'.$data['belong'].'%')
|
|
|
- ->select('id')->get()->toArray();
|
|
|
- $emp_id = array_column($emp_id,'id');
|
|
|
- //单据中选择的签订人
|
|
|
- $id = PaymentReceiptInfo::where('del_time',0)
|
|
|
- ->where('type',PaymentReceiptInfo::type_two)
|
|
|
- ->whereIn('data_id',$emp_id)
|
|
|
- ->select('payment_receipt_id')
|
|
|
- ->get()->toArray();
|
|
|
- return array_unique(array_column($id,'payment_receipt_id'));
|
|
|
- }
|
|
|
-
|
|
|
- //创建人
|
|
|
- public function crtNameSearch($data){
|
|
|
- $emp_id = Employee::where('del_time',0)
|
|
|
- ->where('emp_name','LIKE', '%'.$data['crt_name'].'%')
|
|
|
- ->select('id')->get()->toArray();
|
|
|
- return array_column($emp_id,'id');
|
|
|
- }
|
|
|
-
|
|
|
- public function crtContactSearch($data){
|
|
|
- $id = CustomerInfo::where('del_time',0)
|
|
|
- ->where('type',CustomerInfo::type_one)
|
|
|
- ->where('contact_info','LIKE', '%'.$data['title_t'].'%')
|
|
|
- ->select('customer_id')->get()->toArray();
|
|
|
- return array_column($id,'customer_id');
|
|
|
- }
|
|
|
-
|
|
|
- //负责人
|
|
|
- public function customerSearch($data){
|
|
|
- $emp_id = Employee::where('del_time',0)
|
|
|
- ->where('emp_name','LIKE', '%'.$data['fz'].'%')
|
|
|
- ->select('id')->get()->toArray();
|
|
|
- $emp_id = array_column($emp_id,'id');
|
|
|
- //单据中选择的负责人
|
|
|
- $customer_id = CustomerInfo::where('del_time',0)
|
|
|
- ->where('type',CustomerInfo::type_two)
|
|
|
- ->whereIn('data_id',$emp_id)
|
|
|
- ->select('customer_id')
|
|
|
- ->get()->toArray();
|
|
|
-
|
|
|
- return array_unique(array_column($customer_id,'customer_id'));;
|
|
|
- }
|
|
|
-
|
|
|
- //获取可见人施工单
|
|
|
- public function RangeConstructionEmpDetail($data_id = 0){
|
|
|
- if(empty($data_id)) return [];
|
|
|
-
|
|
|
- $see = ConstructionInfo::where('del_time',0)
|
|
|
- ->whereIn('construction_id',$data_id)
|
|
|
- ->where('type',ConstructionInfo::type_three)
|
|
|
- ->get()->toArray();
|
|
|
- $emp_map = Employee::where('del_time',0)
|
|
|
- ->whereIn('id',array_column($see,'employee_id'))
|
|
|
- ->pluck('emp_name','id')->toArray();
|
|
|
-
|
|
|
- $employee = [];
|
|
|
- foreach ($see as $value){
|
|
|
- $name = $emp_map[$value['employee_id']] ?? '';
|
|
|
- if(! empty($name)){
|
|
|
- $tmp = [
|
|
|
- 'id' => $value['employee_id'],
|
|
|
- 'emp_name' => $emp_map[$value['employee_id']] ?? '',
|
|
|
- ];
|
|
|
- $employee[$value['construction_id']][] = $tmp;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return $employee;
|
|
|
- }
|
|
|
-
|
|
|
- //客户类型
|
|
|
- public function customerBasicTypeSearch($customer_type, $type){
|
|
|
- $result = BasicType::where('del_time',0)
|
|
|
- ->whereIn('type',$type)
|
|
|
- ->where('title', $customer_type)
|
|
|
- ->select('id')->get()->toArray();
|
|
|
- return array_column($result,'id');
|
|
|
- }
|
|
|
-
|
|
|
- public function customerBasicTypeAllUseSearch($customer_type, $type){
|
|
|
- $result = BasicTypeAllUse::where('del_time',0)
|
|
|
- ->whereIn('type',$type)
|
|
|
- ->where('title', $customer_type)
|
|
|
- ->select('id')->get()->toArray();
|
|
|
- return array_column($result,'id');
|
|
|
- }
|
|
|
-
|
|
|
- //全部 待审 已审核 -----------------------------------------------
|
|
|
- public static function sportsBagCheck($user,$search){
|
|
|
- $args = "";
|
|
|
- if($search['is_check'] == 1) {
|
|
|
- list($status, $id) = self::getWaitForSportsCheck($user,$search);
|
|
|
-
|
|
|
- //待审核
|
|
|
- $check = implode(",", SportsBag::$wait_check);
|
|
|
- $args = "(state IN (" . implode(",", SportsBag::$wait_check) ."))";
|
|
|
-
|
|
|
- if($status) {
|
|
|
- $wait_for_me = $search['wait_for_me'] ?? 0;
|
|
|
- $check_2 = implode(',', array_diff(SportsBag::$wait_check, [SportsBag::STATE_ONE]));
|
|
|
- $id = implode(",", $id);
|
|
|
-
|
|
|
- if($wait_for_me){
|
|
|
- if(empty($id)) {
|
|
|
- $args = "(state IN (" . $check .") and (1=0 or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
|
|
|
- }else{
|
|
|
- $args = "(state IN (" . $check .") and (id IN (" . $id .") or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }elseif($search['is_check'] == 2){
|
|
|
- //已审
|
|
|
- $args = "(state = ". SportsBag::STATE_TWO . ")";
|
|
|
- }
|
|
|
-
|
|
|
- return $args;
|
|
|
- }
|
|
|
-
|
|
|
- private static function getWaitForSportsCheck($user, $search){
|
|
|
- if(! isset($search['wait_for_me'])) return [false, []];
|
|
|
-
|
|
|
- //获取待审核
|
|
|
- $args = "(state = " . SportsBag::STATE_ONE . ")";
|
|
|
- $data = SportsBag::where('del_time',0)
|
|
|
- ->whereRaw($args)
|
|
|
- ->select('order_number','id')
|
|
|
- ->get()->toArray();
|
|
|
- if(empty($data)) return [true, []];
|
|
|
-
|
|
|
- list($status,$msg) = self::getWaitCommon($data,$user);
|
|
|
- return [$status, $msg];
|
|
|
- }
|
|
|
-
|
|
|
- public static function paymentReceiptCheck($user,$search){
|
|
|
- $args = "";
|
|
|
- if($search['is_check'] == 1) {
|
|
|
- list($status, $id) = self::getWaitForPaymentCheck($user,$search);
|
|
|
-
|
|
|
- //待审核
|
|
|
- $check = implode(",", SportsBag::$wait_check);
|
|
|
- $args = "(state IN (" . $check ."))";
|
|
|
-
|
|
|
- if($status) {
|
|
|
- $wait_for_me = $search['wait_for_me'] ?? 0;
|
|
|
- $id = implode(",", $id);
|
|
|
- $check_2 = implode(',', array_diff(SportsBag::$wait_check, [PaymentReceipt::STATE_ONE]));
|
|
|
- if($wait_for_me){
|
|
|
- if(empty($id)) {
|
|
|
- $args = "(state IN (" . $check .") and (1=0 or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
|
|
|
- }else{
|
|
|
- $args = "(state IN (" . $check .") and (id IN (" . $id .") or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }elseif($search['is_check'] == 2){
|
|
|
- //已审
|
|
|
- $args = "(state = ". PaymentReceipt::STATE_TWO . ")";
|
|
|
- }
|
|
|
-
|
|
|
- return $args;
|
|
|
- }
|
|
|
-
|
|
|
- private static function getWaitForPaymentCheck($user, $search){
|
|
|
- if(! isset($search['wait_for_me'])) return [false, []];
|
|
|
-
|
|
|
- //获取待审核
|
|
|
- $args = "(state = " . PaymentReceipt::STATE_ONE . ")";
|
|
|
- $data = PaymentReceipt::where('del_time',0)
|
|
|
- ->whereRaw($args)
|
|
|
- ->select('order_number','id')
|
|
|
- ->get()->toArray();
|
|
|
- if(empty($data)) return [true, []];
|
|
|
-
|
|
|
- list($status,$msg) = self::getWaitCommon($data,$user);
|
|
|
- return [$status, $msg];
|
|
|
- }
|
|
|
-
|
|
|
- public static function salesOrderCheck($user,$search){
|
|
|
- $args = "";
|
|
|
- if($search['is_check'] == 1) {
|
|
|
- list($status, $id) = self::getWaitForSalesCheck($user,$search);
|
|
|
-
|
|
|
- //待审核
|
|
|
- $check = implode(",", SalesOrder::$wait_check);
|
|
|
- $args = "(sales_order_type = " . SalesOrder::Order_type_one . " and state IN (" . $check ."))";
|
|
|
-
|
|
|
- if($status) {
|
|
|
- $wait_for_me = $search['wait_for_me'] ?? 0;
|
|
|
-
|
|
|
- $check_2 = implode(',', array_diff(SalesOrder::$wait_check, [SalesOrder::State_one]));
|
|
|
- $id = implode(",", $id);
|
|
|
- if($wait_for_me){
|
|
|
- if(empty($id)) {
|
|
|
- $args = "(sales_order_type = " . SalesOrder::Order_type_one . " and state IN (" . $check .") and (1=0 or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
|
|
|
- }else{
|
|
|
- $args = "(sales_order_type = " . SalesOrder::Order_type_one . " and state IN (" . $check .") and (id IN (" . $id .") or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }elseif($search['is_check'] == 2){
|
|
|
- //已审 线上订单的已审核是2 其它是 3
|
|
|
- $args = SalesOrder::search;
|
|
|
- }
|
|
|
-
|
|
|
- return $args;
|
|
|
- }
|
|
|
-
|
|
|
- private static function getWaitForSalesCheck($user, $search){
|
|
|
- if(! isset($search['wait_for_me'])) return [false, []];
|
|
|
-
|
|
|
- //获取待审核合同
|
|
|
- $args = "(sales_order_type = " . SalesOrder::Order_type_one . " and state = " . SalesOrder::State_one . ")";
|
|
|
- $data = SalesOrder::where('del_time',0)
|
|
|
- ->whereRaw($args)
|
|
|
- ->select('order_number','id')
|
|
|
- ->get()->toArray();
|
|
|
- if(empty($data)) return [true, []];
|
|
|
-
|
|
|
- list($status,$msg) = self::getWaitCommon($data,$user);
|
|
|
- return [$status, $msg];
|
|
|
- }
|
|
|
-
|
|
|
- public static function invoiceCheck($user,$search){
|
|
|
- $args = "";
|
|
|
- if($search['is_check'] == 1) {
|
|
|
- list($status, $id) = self::getWaitForInvoiceCheck($user,$search);
|
|
|
-
|
|
|
- //待审核
|
|
|
- $check = implode(",", InvoiceOrder::$wait_check);
|
|
|
- $args = "(state IN (" . $check ."))";
|
|
|
-
|
|
|
- if($status) {
|
|
|
- $wait_for_me = $search['wait_for_me'] ?? 0;
|
|
|
-
|
|
|
- $check_2 = implode(',', array_diff(InvoiceOrder::$wait_check, [InvoiceOrder::STATE_ONE]));
|
|
|
- $id = implode(",", $id);
|
|
|
- if($wait_for_me){
|
|
|
- if(empty($id)) {
|
|
|
- $args = "(state IN (" . $check .") and (1=0 or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
|
|
|
- }else{
|
|
|
- $args = "(state IN (" . $check .") and (id IN (" . $id .") or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }elseif($search['is_check'] == 2){
|
|
|
- //已审
|
|
|
- $args = "(state = ". InvoiceOrder::STATE_TWO . ")";
|
|
|
- }
|
|
|
-
|
|
|
- return $args;
|
|
|
- }
|
|
|
-
|
|
|
- private static function getWaitForInvoiceCheck($user, $search){
|
|
|
- if(! isset($search['wait_for_me'])) return [false, []];
|
|
|
-
|
|
|
- //获取待审核数据
|
|
|
- $args = "(state = " . InvoiceOrder::STATE_ONE . ")";
|
|
|
- $data = InvoiceOrder::where('del_time',0)
|
|
|
- ->whereRaw($args)
|
|
|
- ->select('order_number','id')
|
|
|
- ->get()->toArray();
|
|
|
- if(empty($data)) return [true, []];
|
|
|
-
|
|
|
- list($status,$msg) = self::getWaitCommon($data,$user);
|
|
|
- return [$status, $msg];
|
|
|
- }
|
|
|
-
|
|
|
- public static function returnExchangeOrderCheck($user,$search){
|
|
|
- $args = "";
|
|
|
- if($search['is_check'] == 1) {
|
|
|
- list($status, $id) = self::getWaitForReturnExchangeCheck($user,$search);
|
|
|
-
|
|
|
- //待审核
|
|
|
- $check = implode(",", ReturnExchangeOrder::$wait_check);
|
|
|
- $args = "(state IN (" . $check ."))";
|
|
|
-
|
|
|
- if($status) {
|
|
|
- $wait_for_me = $search['wait_for_me'] ?? 0;
|
|
|
-
|
|
|
- $check_2 = implode(',', array_diff(ReturnExchangeOrder::$wait_check, [ReturnExchangeOrder::State_one]));
|
|
|
- $id = implode(",", $id);
|
|
|
- if($wait_for_me){
|
|
|
- if(empty($id)) {
|
|
|
- $args = "(state IN (" . $check .") and (1=0 or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
|
|
|
- }else{
|
|
|
- $args = "(state IN (" . $check .") and (id IN (" . $id .") or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }elseif($search['is_check'] == 2){
|
|
|
- //已审
|
|
|
- $args = "(state = ". ReturnExchangeOrder::State_two . ")";
|
|
|
- }
|
|
|
-
|
|
|
- return $args;
|
|
|
- }
|
|
|
-
|
|
|
- private static function getWaitForReturnExchangeCheck($user, $search){
|
|
|
- if(! isset($search['wait_for_me'])) return [false, []];
|
|
|
-
|
|
|
- //获取待审核数据
|
|
|
- $args = "(state = " . ReturnExchangeOrder::State_one . ")";
|
|
|
- $data = ReturnExchangeOrder::where('del_time',0)
|
|
|
- ->whereRaw($args)
|
|
|
- ->select('order_number','id')
|
|
|
- ->get()->toArray();
|
|
|
- if(empty($data)) return [true, []];
|
|
|
-
|
|
|
- list($status,$msg) = self::getWaitCommon($data,$user);
|
|
|
- return [$status, $msg];
|
|
|
- }
|
|
|
-
|
|
|
- public static function constructionCheck($user,$search){
|
|
|
- $args = "";
|
|
|
- if($search['is_check'] == 1) {
|
|
|
- list($status, $id) = self::getWaitForConstructionCheck($user,$search);
|
|
|
-
|
|
|
- //待审核
|
|
|
- $check = implode(",", Construction::$wait_check);
|
|
|
- $args = "(state IN (" . $check ."))";
|
|
|
-
|
|
|
- if($status) {
|
|
|
- $wait_for_me = $search['wait_for_me'] ?? 0;
|
|
|
-
|
|
|
- $check_2 = implode(',', array_diff(Construction::$wait_check, [Construction::STATE_ONE]));
|
|
|
- $id = implode(",", $id);
|
|
|
- if($wait_for_me){
|
|
|
- if(empty($id)) {
|
|
|
- $args = "(state IN (" . $check .") and (1=0 or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
|
|
|
- }else{
|
|
|
- $args = "(state IN (" . $check .") and (id IN (" . $id .") or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }elseif($search['is_check'] == 2){
|
|
|
- //已审
|
|
|
- $args = "(state >= ". Construction::STATE_TWO . ")";
|
|
|
- }
|
|
|
-
|
|
|
- return $args;
|
|
|
- }
|
|
|
-
|
|
|
- private static function getWaitForConstructionCheck($user, $search){
|
|
|
- if(! isset($search['wait_for_me'])) return [false, []];
|
|
|
-
|
|
|
- //获取待审核数据
|
|
|
- $args = "(state = " . Construction::STATE_ONE . ")";
|
|
|
- $data = Construction::where('del_time',0)
|
|
|
- ->whereRaw($args)
|
|
|
- ->select('order_number','id')
|
|
|
- ->get()->toArray();
|
|
|
- if(empty($data)) return [true, []];
|
|
|
-
|
|
|
- list($status,$msg) = self::getWaitCommon($data,$user);
|
|
|
- return [$status, $msg];
|
|
|
- }
|
|
|
-
|
|
|
- public static function purchaseCheck($user,$search){
|
|
|
- $args = "";
|
|
|
- if($search['is_check'] == 1) {
|
|
|
- list($status, $id) = self::getWaitForPurchaseCheck($user,$search);
|
|
|
-
|
|
|
- //待审核
|
|
|
- $check = implode(",", PurchaseOrder::$wait_check);
|
|
|
- $args = "(state IN (" . $check ."))";
|
|
|
-
|
|
|
- if($status) {
|
|
|
- $wait_for_me = $search['wait_for_me'] ?? 0;
|
|
|
-
|
|
|
- $check_2 = implode(',', array_diff(PurchaseOrder::$wait_check, [PurchaseOrder::STATE_ONE]));
|
|
|
- $id = implode(",", $id);
|
|
|
- if($wait_for_me){
|
|
|
- if(empty($id)) {
|
|
|
- $args = "(state IN (" . $check .") and (1=0 or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
|
|
|
- }else{
|
|
|
- $args = "(state IN (" . $check .") and (id IN (" . $id .") or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }elseif($search['is_check'] == 2){
|
|
|
- //已审
|
|
|
- $args = "(state >= ". PurchaseOrder::STATE_TWO . ")";
|
|
|
- }
|
|
|
-
|
|
|
- return $args;
|
|
|
- }
|
|
|
-
|
|
|
- private static function getWaitForPurchaseCheck($user, $search){
|
|
|
- if(! isset($search['wait_for_me'])) return [false, []];
|
|
|
-
|
|
|
- //获取待审核数据
|
|
|
- $args = "(state = " . PurchaseOrder::STATE_ONE . ")";
|
|
|
- $data = PurchaseOrder::where('del_time',0)
|
|
|
- ->whereRaw($args)
|
|
|
- ->select('order_number','id')
|
|
|
- ->get()->toArray();
|
|
|
- if(empty($data)) return [true, []];
|
|
|
-
|
|
|
- list($status,$msg) = self::getWaitCommon($data,$user);
|
|
|
- return [$status, $msg];
|
|
|
- }
|
|
|
-
|
|
|
- public static function inventoryCheck($user,$search){
|
|
|
- $args = "";
|
|
|
- if($search['is_check'] == 1) {
|
|
|
- list($status, $id) = self::getWaitForinventoryCheck($user,$search);
|
|
|
-
|
|
|
- //待审核
|
|
|
- $check = implode(",", Inventory::$wait_check);
|
|
|
- $args = "(state IN (" . $check ."))";
|
|
|
-
|
|
|
- if($status) {
|
|
|
- $wait_for_me = $search['wait_for_me'] ?? 0;
|
|
|
-
|
|
|
- $check_2 = implode(',', array_diff(Inventory::$wait_check, [Inventory::STATE_ONE]));
|
|
|
- $id = implode(",", $id);
|
|
|
- if($wait_for_me){
|
|
|
- if(empty($id)) {
|
|
|
- $args = "(state IN (" . $check .") and (1=0 or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
|
|
|
- }else{
|
|
|
- $args = "(state IN (" . $check .") and (id IN (" . $id .") or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }elseif($search['is_check'] == 2){
|
|
|
- //已审
|
|
|
- $args = "(state >= ". Inventory::STATE_TWO . ")";
|
|
|
- }
|
|
|
-
|
|
|
- return $args;
|
|
|
- }
|
|
|
-
|
|
|
- private static function getWaitForinventoryCheck($user, $search){
|
|
|
- if(! isset($search['wait_for_me'])) return [false, []];
|
|
|
-
|
|
|
- //获取待审核数据
|
|
|
- $args = "(state = " . Inventory::STATE_ONE . ")";
|
|
|
- $data = Inventory::where('del_time',0)
|
|
|
- ->whereRaw($args)
|
|
|
- ->select('order_number','id')
|
|
|
- ->get()->toArray();
|
|
|
- if(empty($data)) return [true, []];
|
|
|
-
|
|
|
- list($status,$msg) = self::getWaitCommon($data,$user);
|
|
|
- return [$status, $msg];
|
|
|
- }
|
|
|
-
|
|
|
- public static function productAdjustmentCheck($user,$search){
|
|
|
- $args = "";
|
|
|
- if($search['is_check'] == 1) {
|
|
|
- list($status, $id) = self::getProductAdjustmentCheck($user,$search);
|
|
|
-
|
|
|
- //待审核
|
|
|
- $check = implode(",", ProductAdjustment::$wait_check);
|
|
|
- $args = "(state IN (" . $check ."))";
|
|
|
-
|
|
|
- if($status) {
|
|
|
- $wait_for_me = $search['wait_for_me'] ?? 0;
|
|
|
-
|
|
|
- $check_2 = implode(',', array_diff(ProductAdjustment::$wait_check, [ProductAdjustment::STATE_ONE]));
|
|
|
- $id = implode(",", $id);
|
|
|
- if($wait_for_me){
|
|
|
- if(empty($id)) {
|
|
|
- $args = "(state IN (" . $check .") and (1=0 or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
|
|
|
- }else{
|
|
|
- $args = "(state IN (" . $check .") and (id IN (" . $id .") or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }elseif($search['is_check'] == 2){
|
|
|
- //已审
|
|
|
- $args = "(state >= ". ProductAdjustment::STATE_TWO . ")";
|
|
|
- }
|
|
|
-
|
|
|
- return $args;
|
|
|
- }
|
|
|
-
|
|
|
- private static function getProductAdjustmentCheck($user, $search){
|
|
|
- if(! isset($search['wait_for_me'])) return [false, []];
|
|
|
-
|
|
|
- //获取待审核数据
|
|
|
- $args = "(state = " . ProductAdjustment::STATE_ONE . ")";
|
|
|
- $data = ProductAdjustment::where('del_time',0)
|
|
|
- ->whereRaw($args)
|
|
|
- ->select('order_number','id')
|
|
|
- ->get()->toArray();
|
|
|
- if(empty($data)) return [true, []];
|
|
|
-
|
|
|
- list($status,$msg) = self::getWaitCommon($data,$user);
|
|
|
- return [$status, $msg];
|
|
|
- }
|
|
|
-
|
|
|
- private static function getWaitCommon($data,$user){
|
|
|
- $data_map = array_column($data,'id','order_number');
|
|
|
- //查找对应审批流数据
|
|
|
- $orderNoGroups = OaOrder::whereIn('order_no', array_column($data,'order_number'))
|
|
|
- ->get()
|
|
|
- ->groupBy('order_no');
|
|
|
- $maxIds = $orderNoGroups->map(function ($group) {
|
|
|
- return $group->max('id');
|
|
|
- });
|
|
|
- $map = $maxIds->toArray();
|
|
|
- if(empty($map)) return [true, []];
|
|
|
- $oa_order_id = array_values($map);
|
|
|
- $map2 = array_flip($map);
|
|
|
- unset($map);
|
|
|
-
|
|
|
- //获取审批流下的人
|
|
|
- $list = OaOrderSub::whereIn('oa_order_id', $oa_order_id)
|
|
|
- ->whereIn('state',[0,1])
|
|
|
- ->select('id','state','oa_order_id')
|
|
|
- ->orderBy('id', 'desc')
|
|
|
- ->get()->toArray();
|
|
|
- $subEmployeeList = OaOrderSubEmployee::whereIn('oa_order_id', $oa_order_id)
|
|
|
- ->where('employee_id',$user['id'])
|
|
|
- ->get()->toArray();
|
|
|
- if(empty($subEmployeeList)) return [true, []];
|
|
|
-
|
|
|
- //每条数据对应的人
|
|
|
- $emp_id_key_list = [];
|
|
|
- foreach ($subEmployeeList as $v) {
|
|
|
- $emp_id_key_list[$v['oa_order_sub_id']][] = $v['employee_id'];
|
|
|
- }
|
|
|
- unset($subEmployeeList);
|
|
|
-
|
|
|
- $flag = $id = [];
|
|
|
- foreach ($list as $v) {
|
|
|
- //不存在单号或者已存在单号返回数据
|
|
|
- if(empty($v['oa_order_id']) || isset($flag[$v['oa_order_id']])) continue;
|
|
|
- $emp_tmp = $emp_id_key_list[$v['id']] ?? [];
|
|
|
- $flag[$v['oa_order_id']] = $emp_tmp;
|
|
|
- $order_number = $map2[$v['oa_order_id']] ?? "";
|
|
|
- $sales_id = $data_map[$order_number] ?? 0;
|
|
|
- if(in_array($user['id'], $emp_tmp)) $id[] = $sales_id;
|
|
|
- }
|
|
|
- unset($flag);
|
|
|
-
|
|
|
- return [true, $id];
|
|
|
- }
|
|
|
- //全部 待审 已审核 -----------------------------------------------
|
|
|
-}
|