CheckService.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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. const six = 6; //退料单审核
  34. const seven = 7; //调拨单详情审核
  35. const eight = 8; //调拨单入库审核
  36. const nine = 9; //调拨单出库审核
  37. const ten = 10; //盘点单详情审核
  38. const eleven = 11; //盘点单入库审核
  39. const twl = 12; //盘点单出库审核
  40. const thirteen = 13; //计费领料单审核
  41. //中文对照
  42. public $map = [
  43. self::one => '领料单申领区域审批',
  44. self::two => '领料单发货区域审批',
  45. self::three => '领料单收货区域审批',
  46. self::four => '领料单入库区域审批',
  47. self::five => '施工单审核',
  48. self::six => '退料单审核',
  49. self::seven => '调拨单详情审核',
  50. self::eight => '调拨单入库审核',
  51. self::nine => '调拨单出库审核',
  52. self::ten => '盘点单详情审核',
  53. self::eleven => '盘点单入库审核',
  54. self::twl => '盘点单出库审核',
  55. self::thirteen => '计费领料单审核',
  56. ];
  57. const TYPE_ONE = 1;//通过
  58. const TYPE_TWO = 2;//不通过
  59. //对应具体单子的具体操作数值(将待审批改为通过或者未审批)
  60. public static $opt_case = [
  61. self::one => 'check_material_order_apply', //领料单申领区域审批
  62. self::two => 'check_material_order_send', //领料单发货区域审批
  63. self::three => 'check_material_order_take', //领料单收货区域审批
  64. self::four => 'check_material_order_In', //领料单入库区域审批 审批通过后有入库流水
  65. self::five => 'check_construction', //施工单审核 审批通过后有出库流水
  66. self::six => 'check_material_return', //退料单审核 审批通过后有出库流水
  67. self::seven => 'check_transfer_sub', //调拨单详情审核
  68. self::eight => 'check_transfer_in_sub', //调拨单入库审核 审批通过后有入库流水
  69. self::nine => 'check_transfer_out_sub', //调拨单出库审核 审批通过后有出库流水
  70. self::ten => 'check_inventory_sub', //盘点单详情审核
  71. self::eleven => 'check_inventory_in_sub', //盘点单入库审核 审批通过后有入库流水
  72. self::twl => 'check_inventory_out_sub', //盘点单出库审核 审批通过后有出库流水
  73. self::thirteen => 'check_material_charge', //计费领料单审核
  74. ];
  75. //单子审批通过后产生流水
  76. public static $record = [
  77. self::four => 'record_material_order_In',
  78. self::five => 'record_construction',
  79. self::six => 'record_material_return',
  80. self::eight => 'record_transfer_in_sub',
  81. self::nine => 'record_transfer_out_sub',
  82. self::eleven => 'record_inventory_in_sub',
  83. self::twl => 'record_inventory_out_sub',
  84. ];
  85. //将状态改为待审核
  86. public static $opt_case2 = [
  87. self::one => 'set_status_to_one',
  88. self::two => '',
  89. self::three => '',
  90. self::four => '',
  91. self::five => '',
  92. self::six => '',
  93. self::seven => '',
  94. self::eight => '',
  95. self::nine => '',
  96. self::ten => '',
  97. self::eleven => '',
  98. self::twl => '',
  99. self::thirteen => '',
  100. ];
  101. //将状态改为待审核
  102. public function set_status_to_one($data){
  103. return [true,''];
  104. }
  105. /**
  106. * order_number 单据名称
  107. * opt_case 审核单据的区域 有已经定义的方法
  108. */
  109. public function checkAll($data,$user){
  110. if(empty($data['order_number']) || empty($data['opt_case']) || ! isset(self::$opt_case2[$data['opt_case']])) return [false,'必传参数不能为空或者参数值错误!'];
  111. //具体方法
  112. $function = self::$opt_case2[$data['opt_case']];
  113. try{
  114. DB::beginTransaction();
  115. //更新单据的状态 从待审变成已审核
  116. list($bool,$msg) = $this->$function($data);
  117. if(! $bool){
  118. DB::rollBack();
  119. return [false, $msg];
  120. }
  121. //创建审批流
  122. $args = [
  123. 'order_no' => $data['order_number'],
  124. 'menu_id' => $data['menu_id'] ?? 0,
  125. 'type' => $data['opt_case']
  126. ];
  127. $oa = new OaService();
  128. $bool = $oa->createOaOrder($args);
  129. DB::commit();
  130. return [true, ''];
  131. }catch (\Throwable $exception){
  132. DB::rollBack();
  133. return [false, $exception->getMessage()];
  134. }
  135. }
  136. //创建审批流 将状态改为待审核 结束
  137. //将待审核状态改为审批通过或者驳回
  138. public function check_status($data){
  139. return true;
  140. }
  141. //产生流水
  142. public function record_create($data){
  143. $result = [];
  144. //写入流水
  145. InOutRecord::insert($result);
  146. return true;
  147. }
  148. /**
  149. * 业务单据审核统一入库
  150. * order_number 订单编号
  151. * type 1 =》 通过 2 =》 驳回
  152. * opt_case 具体审核类型 已定义同名静态变量
  153. */
  154. public function createRecordAndInventory($data = []){
  155. if(empty($data['order_number']) || empty($data['type']) || empty($data['opt_case']) || ! isset(self::$opt_case[$data['opt_case']])) return [false,300];
  156. //具体方法
  157. $function = self::$opt_case[$data['opt_case']];
  158. try{
  159. DB::beginTransaction();
  160. //更新单据的状态
  161. $bool = $this->$function($data);
  162. if($bool && $data['type'] == self::TYPE_ONE && isset(self::$record[$data['opt_case']])){
  163. //审批通过 创建流水
  164. $function_record = self::$record[$data['opt_case']];
  165. $boolean = $this->$function_record($data);
  166. if(! $boolean) { //创建流水失败 数据库回滚
  167. DB::rollBack();
  168. return [false, 300];
  169. }
  170. //更新库存
  171. $inventory = new InventoryService();
  172. $boole = $inventory->changeInventory($data);
  173. if(! $boole){
  174. DB::rollBack();
  175. return [false, 300];
  176. }
  177. }
  178. DB::commit();
  179. return [true, 200];
  180. }catch (\Throwable $exception){
  181. DB::rollBack();
  182. return [false, 201];
  183. }
  184. }
  185. }