MemberLogRepository.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. <?php
  2. namespace App\Repositories;
  3. use App\Models\MembersLog;
  4. use App\Services\Common\CurlService;
  5. use Illuminate\Container\Container as Application;
  6. use Illuminate\Support\Facades\DB;
  7. use Prettus\Repository\Eloquent\BaseRepository;
  8. use Prettus\Repository\Criteria\RequestCriteria;
  9. /**
  10. * Class MemberRepositoryEloquent.
  11. *
  12. * @package namespace App\Repositories;
  13. */
  14. class MemberLogRepository extends BaseRepository
  15. {
  16. protected $memberInfoRepository;
  17. public function __construct(Application $app,MemberInfoRepository $memberInfoRepository)
  18. {
  19. $this->memberInfoRepository=$memberInfoRepository;
  20. parent::__construct($app);
  21. }
  22. /**
  23. * 操作类型。
  24. * @var array
  25. */
  26. public $type_arr = array(
  27. 1000=>array('type'=>'注册','content'=>'注册成功'),
  28. 1001=>array('type'=>'登录','content'=>'登录成功'),
  29. 1002=>array('type'=>'发布了职位','content'=>'发布了职位(id:%s)'),
  30. 1003=>array('type'=>'修改了职位','content'=>'修改了职位(id:%s)'),
  31. 1004=>array('type'=>'保存企业资料','content'=>'保存企业资料'),
  32. 1005=>array('type'=>'上传营业执照','content'=>'上传营业执照'),
  33. 1006=>array('type'=>'刷新职位','content'=>'刷新职位(id:%s,方式:%u)'),
  34. 1007=>array('type'=>'关闭职位','content'=>'关闭职位(id:%s)'),
  35. 1008=>array('type'=>'恢复显示职位','content'=>'恢复显示职位(id:%s)'),
  36. 1009=>array('type'=>'删除职位','content'=>'删除职位(id:%s)'),
  37. 1010=>array('type'=>'邀请面试','content'=>'邀请面试(职位id:%s,简历id:%u)'),
  38. 1011=>array('type'=>'删除邀请面试记录','content'=>'删除邀请面试记录(记录id:%s)'),
  39. 1012=>array('type'=>'下载简历','content'=>''),
  40. 1013=>array('type'=>'删除职位申请','content'=>'删除职位申请(记录id:%s)'),
  41. // 1014=>array('type'=>'简历保存到电脑','content'=>'将简历保存到电脑(简历id:%s)'),
  42. // 1015=>array('type'=>'修改过滤条件','content'=>'修改职位接收简历的过滤条件(职位id:%s)'),
  43. 1016=>array('type'=>'已收到简历设为已查看','content'=>'将已收到简历设为已查看(记录id:%s)'),
  44. 1017=>array('type'=>'删除已下载简历','content'=>'删除已下载简历(记录id:%s)'),
  45. 1018=>array('type'=>'收藏简历','content'=>'收藏简历(简历id:%s)'),
  46. 1019=>array('type'=>'删除收藏简历','content'=>'删除收藏简历(记录id:%s)'),
  47. 1020=>array('type'=>'删除浏览过的简历','content'=>'删除浏览过的简历(记录id:%s)'),
  48. 1021=>array('type'=>'删除谁看过我的职位','content'=>'删除谁看过我的职位(记录id:%s)'),
  49. 1022=>array('type'=>'删除企业风采','content'=>'删除企业风采(记录id:%s)'),
  50. // 1023=>array('type'=>'修改企业风采备注','content'=>'修改企业风采备注(记录id:%s)'),
  51. // 1024=>array('type'=>'查看系统消息','content'=>'查看系统消息(消息id:%s)'),
  52. 1025=>array('type'=>'删除系统消息','content'=>'删除系统消息(消息id:%s)'),
  53. 1026=>array('type'=>'发送反馈消息','content'=>'发送反馈消息(发送者uid:%s,接收者uid:%u,消息内容:%f)'),
  54. // 1027=>array('type'=>'删除反馈消息','content'=>'删除反馈消息(消息id:%s)'),
  55. // 1028=>array('type'=>'发送简历到邮箱','content'=>'发送简历到邮箱(简历id:%s,接收邮箱:%u)'),
  56. 1029=>array('type'=>'标记收到的简历','content'=>'标记收到的简历(记录id:%s,标记为:%u)'),
  57. 1030=>array('type'=>'标记已下载简历','content'=>'标记已下载简历(记录id:%s,标记为:%u)'),
  58. 1031=>array('type'=>'更换企业模板','content'=>'更换企业模板(模板目录名:%s)'),
  59. 1032=>array('type'=>'举报简历','content'=>'举报简历(简历id:%s)'),
  60. 1033=>array('type'=>'预定招聘会展位','content'=>'预定招聘会展位(招聘会id:%s,展位id:%u)'),
  61. 1034=>array('type'=>'发布招聘会职位','content'=>'发布了招聘会职位【%s】(id:%u)'),
  62. 1035=>array('type'=>'修改招聘会职位','content'=>'修改了招聘会职位【%s】(id:%u)'),
  63. 1036=>array('type'=>'删除招聘会职位','content'=>'删除招聘会职位(id:%s)'),
  64. 1037=>array('type'=>'修改招聘会参展职位','content'=>'修改了招聘会参展职位(id:%s)'),
  65. 8001=>array('type'=>'邮箱验证','content'=>'邮箱验证'),
  66. 8002=>array('type'=>'手机验证','content'=>'手机验证'),
  67. 8003=>array('type'=>'签到','content'=>'签到'),
  68. 9001=>array('type'=>'创建订单','content'=>'创建订单(订单号:%s,付款方式:%u)'),
  69. 9002=>array('type'=>'开通服务','content'=>'开通服务(服务名称:%s,付款方式:%u)'),
  70. 9003=>array('type'=>'索取发票','content'=>'索取发票(订单ID:%s)'),
  71. 9004=>array('type'=>'取消订单','content'=>'取消订单(订单号:%s)'),
  72. 9005=>array('type'=>'删除订单','content'=>'删除订单(订单号:%s)'),
  73. // 9006=>array('type'=>'申请退出诚聘通','content'=>'申请退出诚聘通会员'),
  74. 2001=>array('type'=>'刷新简历','content'=>'刷新简历(简历id:%s)'),
  75. 2002=>array('type'=>'添加屏蔽企业','content'=>'添加屏蔽企业关健字:%s'),
  76. 2003=>array('type'=>'删除屏蔽企业','content'=>'删除屏蔽企业关健字(关键字:%s)'),
  77. 2004=>array('type'=>'保存隐私设置','content'=>'保存隐私设置(简历id:%s)'),
  78. 2005=>array('type'=>'设置简历委托','content'=>'设置简历委托(简历id:%s)'),
  79. 2006=>array('type'=>'取消简历委托','content'=>'取消简历委托(简历id:%s)'),
  80. 2007=>array('type'=>'更换简历模板','content'=>'更换简历模板(简历id:%s,模板目录名:%u)'),
  81. 2008=>array('type'=>'删除简历','content'=>'删除简历(简历id:%s)'),
  82. 2009=>array('type'=>'设置默认简历','content'=>'设置默认简历(简历id:%s)'),
  83. 2010=>array('type'=>'创建简历','content'=>'创建简历(简历id:%s)'),
  84. 2011=>array('type'=>'复制简历','content'=>'复制简历(被复制简历id:%s,新简历id:%u)'),
  85. 2012=>array('type'=>'修改简历','content'=>'修改简历(简历id:%s)'),
  86. 2013=>array('type'=>'删除教育经历','content'=>'删除教育经历(简历id:%s)'),
  87. 2014=>array('type'=>'删除工作经历','content'=>'删除工作经历(简历id:%s)'),
  88. 2015=>array('type'=>'删除培训经历','content'=>'删除培训经历(简历id:%s)'),
  89. 2016=>array('type'=>'删除语言能力','content'=>'删除语言能力(简历id:%s)'),
  90. 2017=>array('type'=>'删除证书','content'=>'删除证书(简历id:%s)'),
  91. 2018=>array('type'=>'添加教育经历','content'=>'添加教育经历(简历id:%s)'),
  92. 2019=>array('type'=>'修改教育经历','content'=>'修改教育经历(简历id:%s)'),
  93. 2020=>array('type'=>'添加工作经历','content'=>'添加工作经历(简历id:%s)'),
  94. 2021=>array('type'=>'修改工作经历','content'=>'修改工作经历(简历id:%s)'),
  95. 2022=>array('type'=>'添加培训经历','content'=>'添加培训经历(简历id:%s)'),
  96. 2023=>array('type'=>'修改培训经历','content'=>'修改培训经历(简历id:%s)'),
  97. 2024=>array('type'=>'保存语言能力','content'=>'保存语言能力(简历id:%s)'),
  98. 2025=>array('type'=>'添加证书','content'=>'添加证书(简历id:%s)'),
  99. 2026=>array('type'=>'修改证书','content'=>'修改证书(简历id:%s)'),
  100. 2027=>array('type'=>'保存个人简介','content'=>'保存个人简介(简历id:%s)'),
  101. 2028=>array('type'=>'保存特长标签','content'=>'保存特长标签(简历id:%s)'),
  102. 2029=>array('type'=>'删除简历附件','content'=>'删除简历附件(简历id:%s)'),
  103. 2030=>array('type'=>'保存附件','content'=>'保存附件(简历id:%s)'),
  104. 2031=>array('type'=>'删除word简历','content'=>'删除word简历(简历id:%s)'),
  105. 2032=>array('type'=>'简历外发','content'=>'简历外发(简历id:%s,接收邮箱:%u)'),
  106. 2033=>array('type'=>'删除简历外发','content'=>'删除简历外发(记录id:%s)'),
  107. 2034=>array('type'=>'面试邀请设为已查看','content'=>'面试邀请设为已查看(记录id:%s)'),
  108. 2035=>array('type'=>'删除收藏的职位','content'=>'删除收藏的职位(记录id:%s)'),
  109. 2036=>array('type'=>'删除谁在关注我','content'=>'删除谁在关注我(记录id:%s)'),
  110. 2037=>array('type'=>'删除浏览过的职位','content'=>'删除浏览过的职位(记录id:%s)'),
  111. 2038=>array('type'=>'删除关注的企业','content'=>'删除关注的企业(记录id:%s)'),
  112. 2039=>array('type'=>'保存职位订阅器','content'=>'保存职位订阅器(记录id:%s)'),
  113. 2040=>array('type'=>'退订职位订阅器','content'=>'退订职位订阅器(记录id:%s)'),
  114. 2041=>array('type'=>'订阅职位订阅器','content'=>'订阅职位订阅器(记录id:%s)'),
  115. 2042=>array('type'=>'举报职位','content'=>'举报职位(职位id:%s)'),
  116. 2043=>array('type'=>'修改个人资料','content'=>'修改个人资料'),
  117. 2044=>array('type'=>'修改了个人头像','content'=>'修改了个人头像'),
  118. 2045=>array('type'=>'修改了登录密码','content'=>'修改了登录密码')
  119. );
  120. /**
  121. * Specify Model class name
  122. *
  123. * @return string
  124. */
  125. // if(!$this->memberLogRepository->createLog(auth('web-member')->user(),2007,[$resume_id,$tpl])){
  126. // throw new \Exception("日志记失败!");
  127. // }
  128. public function model()
  129. {
  130. return MembersLog::class;
  131. }
  132. /**
  133. * Boot up the repository, pushing criteria
  134. */
  135. public function boot()
  136. {
  137. $this->pushCriteria(app(RequestCriteria::class));
  138. }
  139. /**
  140. * @param $log_uid
  141. * @param $log_utype
  142. * @param $type
  143. * @return mixed
  144. */
  145. public function getMemberLog($log_uid, $log_utype, $type)
  146. {
  147. return $this->model->where([
  148. 'log_uid'=>$log_uid,
  149. 'log_utype'=>$log_utype,
  150. 'type'=>$type
  151. ])->orderBy('id', 'desc')->paginate(10);
  152. }
  153. public function addNew($data)
  154. {
  155. $data['log_address'] = getAddressByIp();
  156. return $this->model->create($data);
  157. }
  158. public function getTypes()
  159. {
  160. return $this->model->getTypeArr();
  161. }
  162. /**
  163. * @param $user
  164. * @param $type
  165. * @param $log_value
  166. * @return mixed
  167. * @throws \ErrorException
  168. * @throws \Prettus\Validator\Exceptions\ValidatorException
  169. */
  170. public function createLog($user, $type, $log_value,$is_toString=false)
  171. {
  172. if (empty($user)) {
  173. return true;
  174. }
  175. //把数组中空元素删掉
  176. if (is_array($log_value)){
  177. foreach ($log_value as $key=>$item) {
  178. if (empty($item)){
  179. unset($log_value[$key]);
  180. }
  181. }
  182. }
  183. is_array($log_value) && $is_toString ? $log_value=implode(',',$log_value) : ''; //如果传来数组就拆分
  184. $utyp=$user->utype;
  185. $log_username="";
  186. if($utyp==2){ //个人用户
  187. $memberInfo=$this->memberInfoRepository->getMemberInfo($user->id);
  188. $log_username=$memberInfo?$memberInfo->realname:$user->username;
  189. }elseif($utyp == 1) { //企业
  190. $log_username = $user->companyname;
  191. }else{
  192. $log_username = $user->orgname;
  193. }
  194. $data['log_uid'] = $user->id;
  195. $data['log_username'] = $log_username;
  196. $data['log_value'] = $this->getLogValue($type, $log_value);
  197. $data['log_ip'] = ip2long(request()->ip());
  198. $data['log_address'] = getAddressByIp();
  199. $data['log_utype'] = $user->utype;
  200. $data['log_source'] = $this->verSource();
  201. // $data['subsite_id'] = $user->subsite_id;
  202. $data['type'] = $type;
  203. return $this->model->create($data);
  204. }
  205. public function addDebugLog($log){
  206. $data['log_uid'] = 0;
  207. $data['log_username'] = 0;
  208. $data['log_value'] = json_encode($log);
  209. $data['log_ip'] = ip2long(request()->ip());
  210. $data['log_address'] = getAddressByIp();
  211. $data['log_utype'] = 1;
  212. $data['log_source'] = $this->verSource();
  213. $data['subsite_id'] = 0;
  214. $data['type'] = 0;
  215. return $this->model->create($data);
  216. }
  217. /**
  218. * 获取日志说明。
  219. * @param $key
  220. * @param $date
  221. * @return mixed|null
  222. */
  223. public function getLogValue($key, $date)
  224. {
  225. if (isset($this->type_arr[$key])) {
  226. $content = $this->type_arr[$key]['content'];
  227. $res = str_replace(['%s','%u','%f'], $date, $content);
  228. empty($res) ? $res=$date : "";
  229. return $res;
  230. } else {
  231. return null;
  232. }
  233. }
  234. /**
  235. * 判断是PC端还是手机端。
  236. */
  237. public function verSource()
  238. {
  239. if (isMobile()) {
  240. return '触屏端';
  241. } else {
  242. return '网页版';
  243. }
  244. }
  245. public function typeArrs()
  246. {
  247. return collect($this->type_arr)->map(function ($value) {
  248. return $value['type'];
  249. })->toArray();
  250. }
  251. }