CommonService.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. public static function change_contract_no()
  59. {
  60. $options = config('redis.');
  61. $redis = new Redis($options);
  62. $key = 'dingtalk_contract_no';
  63. $key2 = 'dingtalk_contract_no_list';
  64. $key11 = $redis->set($key, 1);
  65. $key22 = $redis->rm($key2);
  66. return compact("key11","key22");
  67. }
  68. /**
  69. * 拼接查询字段
  70. *
  71. * @param string $field
  72. * @param string $aliasName
  73. */
  74. public static function getAliasField($field, $aliasName)
  75. {
  76. $field = explode(',', $field);
  77. foreach ($field as &$value) {
  78. $value = $aliasName . $value;
  79. }
  80. return $field;
  81. }
  82. /**
  83. * 判断用户是否是物业主管或信息负责人
  84. *
  85. * @param mixed $user 用户信息
  86. **/
  87. public static function isMaintain($user)
  88. {
  89. if (in_array($user['title'], MaintainConstant::get_type_title_list())) {
  90. return true;
  91. }
  92. return false;
  93. }
  94. /**
  95. * 类型数据
  96. */
  97. public static function get_data()
  98. {
  99. $module_list = get_one_two_array(CommonConstant::get_module_list(), 'id', 'name');
  100. $degree_list = get_one_two_array(OfferConstant::get_degree_list(), 'id', 'name');
  101. $pay_type_list = get_one_two_array(ApplyConstant::get_pay_type_list(), 'id', 'name');
  102. $time_list = get_one_two_array(LeaveConstant::get_time_list(), 'id', 'name');
  103. $data1 = get_one_two_array(ApplyConstant::get_type_list(), 'id', 'name');
  104. $data2 = get_one_two_array(OfferConstant::get_type_list(), 'id', 'name');
  105. $data5 = get_one_two_array(EvectionConstant::get_type_list(), 'id', 'name');
  106. $data6 = get_one_two_array(LeaveConstant::get_type_list(), 'id', 'name');
  107. $data8 = get_one_two_array(MaintainConstant::get_type_list(), 'id', 'name');
  108. $data9 = get_one_two_array(ContractConstant::get_type_list(), 'id', 'name');
  109. return compact("module_list", "degree_list", "pay_type_list", "time_list", "data1", "data2", "data5", "data6", "data8", "data9");
  110. }
  111. /**
  112. * 根据模块获取审批流项
  113. *
  114. * @param integer $module
  115. **/
  116. public static function get_item_list($module)
  117. {
  118. $get_item_list = [];
  119. switch ($module) {
  120. case CommonConstant::MODULE_5:
  121. $get_item_list = EvectionConstant::get_type_list();
  122. break;
  123. case CommonConstant::MODULE_6:
  124. $get_item_list = LeaveConstant::get_time_list();
  125. break;
  126. case CommonConstant::MODULE_8:
  127. $get_item_list = MaintainConstant::get_type_list();
  128. break;
  129. }
  130. return $get_item_list;
  131. }
  132. /**
  133. * 根据模块获取类型列表
  134. *
  135. * @param integer $module
  136. **/
  137. public static function get_type_list($module)
  138. {
  139. $list = [];
  140. switch ($module) {
  141. case CommonConstant::MODULE_1:
  142. $list = ApplyConstant::get_type_list();
  143. break;
  144. case CommonConstant::MODULE_2:
  145. $list = OfferConstant::get_type_list();
  146. break;
  147. case CommonConstant::MODULE_5:
  148. $list = EvectionConstant::get_type_list();
  149. break;
  150. case CommonConstant::MODULE_6:
  151. $list = LeaveConstant::get_type_list();
  152. break;
  153. case CommonConstant::MODULE_8:
  154. $list = MaintainConstant::get_type_list();
  155. break;
  156. case CommonConstant::MODULE_9:
  157. $list = ContractConstant::get_type_list();
  158. break;
  159. }
  160. return $list;
  161. }
  162. }