DeleteService.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace App\Service;
  3. use App\Model\Employee;
  4. use App\Model\SalesOrderInfo;
  5. use Illuminate\Support\Facades\DB;
  6. class DeleteService extends Service
  7. {
  8. public function getMan($data,$user){
  9. if(empty($data['id']) || empty($data['type']) || empty($data['man_type'])) return [false, '必填参数不能为空!'];
  10. $return = [];
  11. if($data['type'] == 1){
  12. $return = $this->getSaleOrderMan($data);
  13. }
  14. return [true, $return];
  15. }
  16. public function delete($data,$user){
  17. if(empty($data['id']) || empty($data['type']) || empty($data['man_type']) || empty($data['man'])) return [false, '必填参数不能为空!'];
  18. try {
  19. DB::beginTransaction();
  20. if($data['type'] == 1){
  21. $this->delSaleOrderMan($data);
  22. }
  23. DB::commit();
  24. }catch (\Exception $exception){
  25. DB::rollBack();
  26. return [false,$exception->getMessage()];
  27. }
  28. return [true,''];
  29. }
  30. public function getSaleOrderMan($data){
  31. $man_id = SalesOrderInfo::where('del_time',0)
  32. ->where('sales_order_id',$data['id'])
  33. ->where('type',$data['man_type'])
  34. ->get('data_id')->toArray();
  35. $man_id = array_column($man_id,'data_id');
  36. return Employee::whereIn('id',$man_id)->select('id', 'emp_name')->get()->toArray();
  37. }
  38. public function delSaleOrderMan($data){
  39. $time = time();
  40. SalesOrderInfo::where('del_time',0)
  41. ->where('sales_order_id',$data['id'])
  42. ->where('type',$data['man_type'])
  43. ->update(['del_time' => $time]);
  44. if(! empty($data['man'])){
  45. $insert = [];
  46. foreach ($data['man'] as $value){
  47. $insert[] = [
  48. 'sales_order_id' => $data['id'],
  49. 'data_id' => $value,
  50. 'type' => $data['man_type'],
  51. 'crt_time' => $time,
  52. ];
  53. }
  54. SalesOrderInfo::insert($insert);
  55. }
  56. }
  57. }