SalesmanServer.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <?php
  2. namespace app\admin\server\medical;
  3. use app\admin\model\MedicalCareSalesman;
  4. use support\Db;
  5. class SalesmanServer
  6. {
  7. /**
  8. * Notes:获取业务员列表
  9. * @param string $keywords
  10. * @param int $page
  11. * @param int $limit
  12. * @return array
  13. * User: ZQ
  14. * Date: 2022/9/27
  15. */
  16. public static function getSalesmanList(int $page, int $limit,string $keywords)
  17. {
  18. [$list,$count] = MedicalCareSalesman::getSalesmanList($page, $limit, $keywords);
  19. if (!empty($list)){
  20. foreach ($list as $k => $v){
  21. $list[$k]['salesman_create_time'] = date('Y-m-d H:i:s', $v['salesman_create_time']);
  22. if (!empty($v['salesman_update_time'])){
  23. $list[$k]['salesman_update_time'] = date('Y-m-d H:i:s', $v['salesman_update_time']);
  24. }
  25. }
  26. }
  27. return compact('list', 'page', 'limit', 'count');
  28. }
  29. /**
  30. * Notes:修改业务员
  31. * @param string $salesman_name
  32. * @param string $salesman_pwd
  33. * @param string $salesman_phone
  34. * @param string $salesman_resale_name
  35. * @param int $salesman_status
  36. * @param int $salesman_id
  37. * @param int $salesman_shop_id
  38. * @return int
  39. * User: ZQ
  40. * Date: 2022/9/13
  41. */
  42. public static function updateSalesman($salesman_id, $salesman_shop_id, $salesman_name, $salesman_pwd, $salesman_phone, $salesman_resale_name, $salesman_status, $salf, $admin_id)
  43. {
  44. MedicalCareSalesman::affairBegin();
  45. try {
  46. $where = [];
  47. $where['salesman_id'] = $salesman_id;
  48. $data = [];
  49. $data['salesman_name'] = $salesman_name;
  50. $data['salesman_shop_id'] = $salesman_shop_id;
  51. if (!empty($salesman_pwd)){
  52. $data['salesman_salf'] = $salf;
  53. $data['salesman_pwd'] = $salesman_pwd;
  54. }
  55. $data['salesman_phone'] = $salesman_phone;
  56. $data['salesman_resale_name'] = $salesman_resale_name;
  57. $data['salesman_status'] = $salesman_status;
  58. $data['salesman_update_time'] = time();
  59. $result = MedicalCareSalesman::where($where)->update($data);
  60. if ($result !== false){
  61. $msg = '管理员:' . $admin_id . '在:' . date("Y-m-d H:i:s", time()) . '修改业务员: ' . $salesman_id;
  62. plog('medical-salesman-update', '医疗-预约服务业务员-修改业务员', $msg);
  63. MedicalCareSalesman::affairCommit();
  64. return true;
  65. }
  66. throw new \Exception('操作失败!');
  67. }catch (\Exception $exception){
  68. MedicalCareSalesman::affairRollback();
  69. throw new \Exception($exception->getMessage(), 500);
  70. }
  71. }
  72. /**
  73. * Notes:删除业务员
  74. * @param int $salesman_id
  75. * @return int
  76. * User: ZQ
  77. * Date: 2022/9/3
  78. */
  79. public static function delSalesman($salesman_id, $admin_id)
  80. {
  81. MedicalCareSalesman::affairBegin();
  82. try {
  83. $where = [];
  84. $where['salesman_id'] = $salesman_id;
  85. $data['salesman_del'] = 1;
  86. $result = MedicalCareSalesman::where($where)->update($data);
  87. if (!empty($result)){
  88. $msg = '管理员:' . $admin_id . '在:' . date("Y-m-d H:i:s", time()) . '删除业务员-编号: ' . $salesman_id;
  89. plog('medical-salesman-update', '医疗-预约服务业务员-删除业务员', $msg);
  90. MedicalCareSalesman::affairCommit();
  91. return true;
  92. }else{
  93. return false;
  94. }
  95. }catch (\Exception $exception){
  96. MedicalCareSalesman::affairRollback();
  97. throw new \Exception($exception->getMessage(), 500);
  98. }
  99. }
  100. /**
  101. * Notes: 添加业务员
  102. * @param int $salesman_shop_id
  103. * @param string $salesman_name
  104. * @param string $salesman_pwd
  105. * @param string $salesman_phone
  106. * @param string $salesman_resale_name
  107. * @param int $salesman_status
  108. * @return int
  109. * User: ZQ
  110. * Date: 2022/9/14
  111. */
  112. public static function insertSalesman($salesman_shop_id, $salesman_name, $salesman_pwd, $salesman_phone, $salesman_resale_name, $salesman_status, $salf, $admin_id)
  113. {
  114. MedicalCareSalesman::affairBegin();
  115. try {
  116. $data = [];
  117. $data['salesman_name'] = $salesman_name;
  118. $data['salesman_shop_id'] = $salesman_shop_id;
  119. $data['salesman_pwd'] = $salesman_pwd;
  120. $data['salesman_phone'] = $salesman_phone;
  121. $data['salesman_resale_name'] = $salesman_resale_name;
  122. $data['salesman_status'] = $salesman_status;
  123. $data['salesman_salf'] = $salf;
  124. $data['salesman_create_time'] = time();
  125. $result = MedicalCareSalesman::insertGetId($data);
  126. if (!empty($result)){
  127. $msg = '管理员:' . $admin_id . '在:' . date("Y-m-d H:i:s", time()) . '添加业务员-编号: ' . $result;
  128. plog('medical-salesman-update', '医疗-预约服务业务员-添加业务员', $msg);
  129. MedicalCareSalesman::affairCommit();
  130. return $result;
  131. }
  132. throw new \Exception('操作失败!');
  133. }catch (\Exception $exception){
  134. MedicalCareSalesman::affairRollback();
  135. throw new \Exception($exception->getMessage(), 500);
  136. }
  137. }
  138. /**
  139. * Notes:查询业务员
  140. * @param int $salesman_id
  141. * @return int
  142. * User: ZQ
  143. * Date: 2022/9/13
  144. */
  145. public static function salesmanInfo($salesman_id)
  146. {
  147. $where = [];
  148. $where['salesman_del'] = 0;
  149. $where['salesman_id'] = $salesman_id;
  150. $result = MedicalCareSalesman::where($where)
  151. ->leftJoin('merchant_shop', 'shop_id', '=', 'medical_care_salesman.salesman_shop_id')
  152. ->first(['medical_care_salesman.*','merchant_shop.shop_name']);
  153. if (!empty($result)){
  154. $result['salesman_create_time'] = date('Y-m-d H:i:s',$result['salesman_create_time']);
  155. if (!empty($result['salesman_update_time'])){
  156. $result['salesman_update_time'] = date('Y-m-d H:i:s',$result['salesman_update_time']);
  157. }
  158. }
  159. return $result;
  160. }
  161. /**
  162. * Notes:修改状态
  163. * @param int $salesman_status
  164. * @param int $salesman_id
  165. * @return int
  166. * User: ZQ
  167. * Date: 2022/9/3
  168. */
  169. public static function updateStatus($salesman_id, $salesman_status, $admin_id)
  170. {
  171. MedicalCareSalesman::affairBegin();
  172. try {
  173. $where = [];
  174. $where['salesman_id'] = $salesman_id;
  175. $data = [];
  176. $data['salesman_status'] = $salesman_status;
  177. $result = MedicalCareSalesman::where($where)->update($data);
  178. if ($result !== false){
  179. $msg = '管理员:' . $admin_id . '在:' . date("Y-m-d H:i:s", time()) . '修改业务员状态-编号: ' . $salesman_id;
  180. plog('medical-salesman-update', '医疗-预约服务业务员-修改业务员状态', $msg);
  181. MedicalCareSalesman::affairCommit();
  182. return true;
  183. }
  184. throw new \Exception('操作失败!');
  185. }catch (\Exception $exception){
  186. MedicalCareSalesman::affairRollback();
  187. throw new \Exception($exception->getMessage(), 500);
  188. }
  189. }
  190. }