CheckService.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. namespace App\Service;
  3. use App\Model\Construction;
  4. use App\Model\ConstructionOrderSub;
  5. use App\Model\InOutRecord;
  6. use App\Model\Inventory;
  7. use App\Model\InventoryInSub;
  8. use App\Model\InventoryOutSub;
  9. use App\Model\MaterialCharge;
  10. use App\Model\MaterialOrder;
  11. use App\Model\MaterialOrderInSub;
  12. use App\Model\MaterialReturn;
  13. use App\Model\RollFilmInventory;
  14. use App\Model\Setting;
  15. use App\Model\Transfer;
  16. use App\Model\TransferInSub;
  17. use App\Model\TransferOutSub;
  18. use App\Model\Warranty;
  19. use App\Service\Oa\OaService;
  20. use Illuminate\Support\Facades\DB;
  21. /**
  22. * 所有审批相关与流水
  23. * @package App\Models
  24. */
  25. class CheckService extends Service
  26. {
  27. //审批操作对应的数值
  28. const one = 1; //收货
  29. const two = 2; //发货
  30. const three = 3; //采购
  31. const four = 4; //销售订单
  32. const five = 5; //施工单
  33. //中文对照
  34. public $map = [
  35. self::one => '收货单',
  36. self::two => '发货单',
  37. self::three => '采购单',
  38. self::four => '销售订单',
  39. self::five => '施工单',
  40. ];
  41. const TYPE_ONE = 1;//通过
  42. const TYPE_TWO = 2;//不通过
  43. public static $opt_case = [
  44. ];
  45. public static $record = [
  46. ];
  47. public function checkAll($data,$user){
  48. if(empty($data['order_number']) || empty($data['opt_case'])) return [false,'必传参数不能为空或者参数值错误!'];
  49. //具体方法
  50. $function = self::$opt_case[$data['opt_case']];
  51. try{
  52. DB::beginTransaction();
  53. //更新单据的状态 从待审变成已审核
  54. list($bool,$msg) = $this->$function($data);
  55. if(! $bool){
  56. DB::rollBack();
  57. return [false, $msg];
  58. }
  59. DB::commit();
  60. return [true, ''];
  61. }catch (\Throwable $exception){
  62. DB::rollBack();
  63. return [false, $exception->getMessage()];
  64. }
  65. }
  66. public function createRecordAndInventory($data = []){
  67. if(empty($data['order_number']) || empty($data['type']) || empty($data['opt_case']) || ! isset(self::$opt_case[$data['opt_case']])) return [false,300];
  68. //具体方法
  69. $function = self::$opt_case[$data['opt_case']];
  70. try{
  71. DB::beginTransaction();
  72. //更新单据的状态
  73. $bool = $this->$function($data);
  74. if($bool && $data['type'] == self::TYPE_ONE && isset(self::$record[$data['opt_case']])){
  75. //审批通过 创建流水
  76. $function_record = self::$record[$data['opt_case']];
  77. $boolean = $this->$function_record($data);
  78. if(! $boolean) { //创建流水失败 数据库回滚
  79. DB::rollBack();
  80. return [false, 300];
  81. }
  82. //更新库存
  83. $inventory = new InventoryService();
  84. $boole = $inventory->changeInventory($data);
  85. if(! $boole){
  86. DB::rollBack();
  87. return [false, 300];
  88. }
  89. }
  90. DB::commit();
  91. return [true, 200];
  92. }catch (\Throwable $exception){
  93. DB::rollBack();
  94. return [false, 201];
  95. }
  96. }
  97. }