| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 | <?phpnamespace App\Service;use App\Model\Employee;use App\Model\SalesOrderInfo;use Illuminate\Support\Facades\DB;class DeleteService extends Service{    public function getMan($data,$user){        if(empty($data['id']) || empty($data['type']) || empty($data['man_type'])) return [false, '必填参数不能为空!'];        $return = [];        if($data['type'] == 1){            $return = $this->getSaleOrderMan($data);        }        return [true, $return];    }    public function delete($data,$user){        if(empty($data['id']) || empty($data['type']) || empty($data['man_type']) || empty($data['man'])) return [false, '必填参数不能为空!'];        try {            DB::beginTransaction();            if($data['type'] == 1){                $this->delSaleOrderMan($data);            }            DB::commit();        }catch (\Exception $exception){            DB::rollBack();            return [false,$exception->getMessage()];        }        return [true,''];    }    public function getSaleOrderMan($data){        $man_id = SalesOrderInfo::where('del_time',0)            ->where('sales_order_id',$data['id'])            ->where('type',$data['man_type'])            ->get('data_id')->toArray();        $man_id = array_column($man_id,'data_id');        return Employee::whereIn('id',$man_id)->select('id', 'emp_name')->get()->toArray();    }    public function delSaleOrderMan($data){         $time = time();         SalesOrderInfo::where('del_time',0)             ->where('sales_order_id',$data['id'])             ->where('type',$data['man_type'])             ->update(['del_time' => $time]);         if(! empty($data['man'])){             $insert = [];             foreach ($data['man'] as $value){                 $insert[] = [                     'sales_order_id' => $data['id'],                     'data_id' => $value,                     'type' => $data['man_type'],                     'crt_time' => $time,                 ];             }             SalesOrderInfo::insert($insert);         }    }    public function fp($data,$user){        if(empty($data['id']) || empty($data['type']) || empty($data['man'])) return [false, '必填参数不能为空!'];        try {            DB::beginTransaction();            if($data['type'] == 1){                $this->fpSaleOrderMan($data);            }            DB::commit();        }catch (\Exception $exception){            DB::rollBack();            return [false,$exception->getMessage()];        }        return [true,''];    }    public function fpSaleOrderMan($data){        $time = time();        if(! empty($data['man'])){            $insert = [];            foreach ($data['man'] as $value){                $insert[] = [                    'sales_order_id' => $data['id'],                    'data_id' => $value,                    'type' => SalesOrderInfo::type_two,                    'crt_time' => $time,                ];            }            SalesOrderInfo::insert($insert);        }    }    public function yj($data,$user){        if(empty($data['id']) || empty($data['type']) || empty($data['man'])) return [false, '必填参数不能为空!'];        try {            DB::beginTransaction();            if($data['type'] == 1){                $this->yjSaleOrderMan($data,$user);            }            DB::commit();        }catch (\Exception $exception){            DB::rollBack();            return [false,$exception->getMessage()];        }        return [true,''];    }    public function yjSaleOrderMan($data,$user){        $time = time();        SalesOrderInfo::where('del_time',0)            ->where('sales_order_id',$data['id'])            ->where('type', SalesOrderInfo::type_two)            ->where('data_id', $user['id'])            ->update(['del_time' => $time]);        if(! empty($data['man'])){            $insert = [];            foreach ($data['man'] as $value){                $insert[] = [                    'sales_order_id' => $data['id'],                    'data_id' => $value,                    'type' => SalesOrderInfo::type_two,                    'crt_time' => $time,                ];            }            SalesOrderInfo::insert($insert);        }    }}
 |