CommonService.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <?php
  2. namespace app\common\service;
  3. use app\common\constant\ApplyConstant;
  4. use app\common\constant\CommonConstant;
  5. use app\common\constant\ContractConstant;
  6. use app\common\constant\EvectionConstant;
  7. use app\common\constant\LeaveConstant;
  8. use app\common\constant\MaintainConstant;
  9. use app\common\constant\OfferConstant;
  10. use think\cache\driver\Redis;
  11. /**
  12. * 公共服务类
  13. */
  14. class CommonService
  15. {
  16. /**
  17. * 生成合同编号
  18. *
  19. * @param integer $type 合同类型
  20. **/
  21. public static function get_contract_no($type)
  22. {
  23. $options = config('redis.');
  24. $redis = new Redis($options);
  25. $key = 'dingtalk_contract_no';
  26. $key2 = 'dingtalk_contract_no_list';
  27. if ($redis->handler()->llen($key2) > 0) {
  28. $number = $redis->handler()->lpop($key2);
  29. } else {
  30. if ($redis->has($key)) {
  31. $number = $redis->get($key);
  32. } else {
  33. $number = 1;
  34. }
  35. $redis->set($key, $number + 1);
  36. }
  37. $new_number = filling_method($number, $number);
  38. $type_no = ContractConstant::get_type_no_list()[$type];
  39. $date = date('Ymd');
  40. $data = 'SET' . $type_no . $date . $new_number;
  41. return $data;
  42. }
  43. /**
  44. * 释放合同编号
  45. *
  46. * @param string $contract_no 合同编号
  47. **/
  48. public static function set_contract_no($contract_no)
  49. {
  50. $options = config('redis.');
  51. $redis = new Redis($options);
  52. $key2 = 'dingtalk_contract_no_list';
  53. return $redis->handler()->rpush($key2, substr($contract_no, 13));
  54. }
  55. /**
  56. * 拼接查询字段
  57. *
  58. * @param string $field
  59. * @param string $aliasName
  60. */
  61. public static function getAliasField($field, $aliasName)
  62. {
  63. $field = explode(',', $field);
  64. foreach ($field as &$value) {
  65. $value = $aliasName . $value;
  66. }
  67. return $field;
  68. }
  69. /**
  70. * 判断用户是否是物业主管或信息负责人
  71. *
  72. * @param mixed $user 用户信息
  73. **/
  74. public static function isMaintain($user)
  75. {
  76. if (in_array($user['title'], MaintainConstant::get_type_title_list())) {
  77. return true;
  78. }
  79. return false;
  80. }
  81. /**
  82. * 类型数据
  83. */
  84. public static function get_data()
  85. {
  86. $module_list = get_one_two_array(CommonConstant::get_module_list(), 'id', 'name');
  87. $degree_list = get_one_two_array(OfferConstant::get_degree_list(), 'id', 'name');
  88. $pay_type_list = get_one_two_array(ApplyConstant::get_pay_type_list(), 'id', 'name');
  89. $time_list = get_one_two_array(LeaveConstant::get_time_list(), 'id', 'name');
  90. $data1 = get_one_two_array(ApplyConstant::get_type_list(), 'id', 'name');
  91. $data2 = get_one_two_array(OfferConstant::get_type_list(), 'id', 'name');
  92. $data5 = get_one_two_array(EvectionConstant::get_type_list(), 'id', 'name');
  93. $data6 = get_one_two_array(LeaveConstant::get_type_list(), 'id', 'name');
  94. $data8 = get_one_two_array(MaintainConstant::get_type_list(), 'id', 'name');
  95. $data9 = get_one_two_array(ContractConstant::get_type_list(), 'id', 'name');
  96. return compact("module_list", "degree_list", "pay_type_list", "time_list", "data1", "data2", "data5", "data6", "data8", "data9");
  97. }
  98. /**
  99. * 根据模块获取审批流项
  100. *
  101. * @param integer $module
  102. **/
  103. public static function get_item_list($module)
  104. {
  105. $get_item_list = [];
  106. switch ($module) {
  107. case CommonConstant::MODULE_5:
  108. $get_item_list = EvectionConstant::get_type_list();
  109. break;
  110. case CommonConstant::MODULE_6:
  111. $get_item_list = LeaveConstant::get_time_list();
  112. break;
  113. case CommonConstant::MODULE_8:
  114. $get_item_list = MaintainConstant::get_type_list();
  115. break;
  116. }
  117. return $get_item_list;
  118. }
  119. /**
  120. * 根据模块获取类型列表
  121. *
  122. * @param integer $module
  123. **/
  124. public static function get_type_list($module)
  125. {
  126. $list = [];
  127. switch ($module) {
  128. case CommonConstant::MODULE_1:
  129. $list = ApplyConstant::get_type_list();
  130. break;
  131. case CommonConstant::MODULE_2:
  132. $list = OfferConstant::get_type_list();
  133. break;
  134. case CommonConstant::MODULE_5:
  135. $list = EvectionConstant::get_type_list();
  136. break;
  137. case CommonConstant::MODULE_6:
  138. $list = LeaveConstant::get_type_list();
  139. break;
  140. case CommonConstant::MODULE_8:
  141. $list = MaintainConstant::get_type_list();
  142. break;
  143. case CommonConstant::MODULE_9:
  144. $list = ContractConstant::get_type_list();
  145. break;
  146. }
  147. return $list;
  148. }
  149. }