SubjectServer.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. <?php
  2. namespace app\admin\server\medical;
  3. use app\admin\model\MedicalCareSubject;
  4. class SubjectServer
  5. {
  6. /**
  7. * Notes:获取业务员列表
  8. * @param string $keywords
  9. * @param int $page
  10. * @param int $limit
  11. * @return array
  12. * User: ZQ
  13. * Date: 2022/9/27
  14. */
  15. public static function getSubjectList($page, $limit,string $keywords)
  16. {
  17. [$list,$count] = MedicalCareSubject::getSubjectList($page, $limit, $keywords);
  18. if (!empty($list)){
  19. foreach ($list as $k => $v){
  20. $list[$k]['subject_create_time'] = date('Y-m-d H:i:s', $v['subject_create_time']);
  21. if (!empty($v['children'])){
  22. foreach ($v['children'] as $key => $val){
  23. $list[$k]['children'][$key]['subject_create_time'] = date('Y-m-d H:i:s', $val['subject_create_time']);
  24. }
  25. }
  26. }
  27. }
  28. return compact('list', 'page', 'limit', 'count');
  29. }
  30. /**
  31. * Notes:修改业务员
  32. * @param string $subject_name
  33. * @param string $subject_type
  34. * @param string $subject_sort
  35. * @param int $subject_id
  36. * @param int $subject_pid
  37. * @return int
  38. * User: ZQ
  39. * Date: 2022/9/13
  40. */
  41. public static function updateSubject($subject_id, $subject_pid, $subject_name, $subject_type, $subject_sort)
  42. {
  43. MedicalCareSubject::affairBegin();
  44. try {
  45. $where = [];
  46. $where['subject_id'] = $subject_id;
  47. $data = [];
  48. if (!empty($subject_name)){
  49. $data['subject_name'] = $subject_name;
  50. }
  51. if (!empty($subject_pid)){
  52. $data['subject_pid'] = $subject_pid;
  53. }
  54. if (!empty($subject_type)){
  55. $data['subject_type'] = $subject_type;
  56. }
  57. if (!empty($subject_sort)){
  58. $data['subject_sort'] = $subject_sort;
  59. }
  60. $result = MedicalCareSubject::where($where)->update($data);
  61. if ($result !== false){
  62. MedicalCareSubject::affairCommit();
  63. return true;
  64. }
  65. throw new \Exception('操作失败!');
  66. }catch (\Exception $exception){
  67. MedicalCareSubject::affairRollback();
  68. throw new \Exception($exception->getMessage(), 500);
  69. }
  70. }
  71. /**
  72. * Notes:删除业务员
  73. * @param int $subject_id
  74. * @return int
  75. * User: ZQ
  76. * Date: 2022/9/3
  77. */
  78. public static function delSubject($subject_id)
  79. {
  80. MedicalCareSubject::affairBegin();
  81. try {
  82. $where = [];
  83. $where['subject_id'] = $subject_id;
  84. $data['subject_del'] = 1;
  85. $result = MedicalCareSubject::where($where)->update($data);
  86. if (!empty($result)){
  87. MedicalCareSubject::affairCommit();
  88. return true;
  89. }else{
  90. return false;
  91. }
  92. }catch (\Exception $exception){
  93. MedicalCareSubject::affairRollback();
  94. throw new \Exception($exception->getMessage(), 500);
  95. }
  96. }
  97. /**
  98. * Notes:查询子集
  99. * @param int $subject_id
  100. * @return array
  101. * User: ZQ
  102. * Date: 2022/9/3
  103. */
  104. public static function childrenCheck($subject_id)
  105. {
  106. $where = [];
  107. $where['subject_pid'] = $subject_id;
  108. $where['subject_del'] = 0;
  109. $result = MedicalCareSubject::where($where)->select()->get()->toArray();
  110. return $result;
  111. }
  112. /**
  113. * Notes: 添加业务员
  114. * @param int $subject_pid
  115. * @param string $subject_name
  116. * @param int $subject_type
  117. * @param int $subject_sort
  118. * @return int
  119. * User: ZQ
  120. * Date: 2022/9/14
  121. */
  122. public static function insertSubject($subject_pid, $subject_name, $subject_type, $subject_sort)
  123. {
  124. MedicalCareSubject::affairBegin();
  125. try {
  126. $data = [];
  127. $data['subject_name'] = $subject_name;
  128. $data['subject_pid'] = $subject_pid;
  129. $data['subject_type'] = $subject_type;
  130. $data['subject_sort'] = $subject_sort;
  131. $data['subject_create_time'] = time();
  132. $result = MedicalCareSubject::insertGetId($data);
  133. if (!empty($result)){
  134. MedicalCareSubject::affairCommit();
  135. return $result;
  136. }
  137. throw new \Exception('操作失败!');
  138. }catch (\Exception $exception){
  139. MedicalCareSubject::affairRollback();
  140. throw new \Exception($exception->getMessage(), 500);
  141. }
  142. }
  143. /**
  144. * Notes:查询业务员
  145. * @param int $subject_id
  146. * @return int
  147. * User: ZQ
  148. * Date: 2022/9/13
  149. */
  150. public static function subjectInfo($subject_id)
  151. {
  152. $where = [];
  153. $where['subject_del'] = 0;
  154. $where['subject_id'] = $subject_id;
  155. $result = MedicalCareSubject::where($where)->first();
  156. if (!empty($result)){
  157. $result['subject_create_time'] = date('Y-m-d H:i:s',$result['subject_create_time']);
  158. }
  159. return $result;
  160. }
  161. /**
  162. * Notes:修改状态
  163. * @param int $subject_status
  164. * @param int $subject_id
  165. * @return int
  166. * User: ZQ
  167. * Date: 2022/9/3
  168. */
  169. public static function updateStatus($subject_id, $subject_status)
  170. {
  171. MedicalCareSubject::affairBegin();
  172. try {
  173. $where = [];
  174. $where['subject_id'] = $subject_id;
  175. $data = [];
  176. $data['subject_status'] = $subject_status;
  177. $result = MedicalCareSubject::where($where)->update($data);
  178. if ($result !== false){
  179. MedicalCareSubject::affairCommit();
  180. return true;
  181. }
  182. throw new \Exception('操作失败!');
  183. }catch (\Exception $exception){
  184. MedicalCareSubject::affairRollback();
  185. throw new \Exception($exception->getMessage(), 500);
  186. }
  187. }
  188. /**
  189. * Notes:获取列表
  190. * @return array
  191. * User: yym
  192. * Date: 2022/10/26
  193. */
  194. public static function getDoctorSubjectList()
  195. {
  196. $list = MedicalCareSubject::getDoctorSubjectList();
  197. $data = array();
  198. if(!empty($list))
  199. {
  200. foreach ($list as $k => $item)
  201. {
  202. if(isset($item['children']) && !empty($item['children']))
  203. {
  204. foreach ($item['children'] as $row)
  205. {
  206. switch ($row['subject_type']){
  207. case 2://特需
  208. $type = '特需';
  209. break;
  210. case 1://专家
  211. $type = '专家';
  212. break;
  213. default:
  214. $type = '普通';
  215. break;
  216. }
  217. $row['subject_name'] = $type . '【' . $item['subject_name'] . '/' . $row['subject_name'] . '】';
  218. $data[] = $row;
  219. }
  220. }
  221. }
  222. }
  223. return $data;
  224. }
  225. }