LogRemark.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * 日志记录
  4. * @author system
  5. * @version 1.0
  6. * @date 2016-12-28 11:54:01
  7. *
  8. */
  9. namespace App\Services\Log;
  10. use App\Models\LogRemarkModel;
  11. use App\Services\Base\BaseProcess;
  12. class LogRemark extends BaseProcess
  13. {
  14. /**
  15. * 模型
  16. */
  17. private $_model;
  18. /**
  19. * 初始化
  20. */
  21. public function __construct()
  22. {
  23. if( ! $this->_model ) $this->_model = new LogRemarkModel();
  24. }
  25. /**
  26. * 添加日志记录
  27. * @param $system 所属系统
  28. * @param $system_primary 所属系统ID
  29. * @param $system_key 所属系统二级主键ID
  30. * @param array $data
  31. * @return static
  32. */
  33. public function createRecord($system, $system_primary, $system_key, array $data)
  34. {
  35. $data['system'] = $system;
  36. $data['system_primary'] = $system_primary;
  37. $data['system_key'] = $system_key;
  38. if( isset($data['status']) ){
  39. $model = $this->_model
  40. ->where('system', $data['system'])
  41. ->where('system_primary', $data['system_primary'])
  42. ->where('system_key', $data['system_key'])
  43. ->where('status', $data['status'])
  44. ->first();
  45. }else{
  46. $model = $this->_model
  47. ->where('system', $data['system'])
  48. ->where('system_primary', $data['system_primary'])
  49. ->where('system_key', $data['system_key'])
  50. ->first();
  51. }
  52. return $model ? $model->update($data) : $this->_model->create($data);
  53. }
  54. }