EmployeeOpenid.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. namespace App\Models\Manager\Personnel;
  3. use Illuminate\Database\Eloquent\Factories\HasFactory;
  4. use Illuminate\Database\Eloquent\Model;
  5. use Illuminate\Support\Facades\DB;
  6. /**
  7. * 员工openid模型
  8. * @author 唐远望
  9. * @version 1.0
  10. * @date 2026-01-19
  11. */
  12. class EmployeeOpenid extends Model
  13. {
  14. use HasFactory;
  15. // 与模型关联的表名
  16. protected $table = 'personnel_employee_openid';
  17. // 是否主动维护时间戳
  18. public $timestamps = false;
  19. // 定义时间戳字段名
  20. // const CREATED_AT = 'insert_time';
  21. // const UPDATED_AT = 'update_time';
  22. /**
  23. * 添加
  24. * @author 唐远望
  25. * @version 1.0
  26. * @date 2025-12-04
  27. */
  28. public function addEmployeeOpenid_content($data)
  29. {
  30. $insert_data = [
  31. 'employee_id' => $data['employee_id'],
  32. 'unionid' => $data['unionid'],
  33. 'openid' => $data['openid'],
  34. 'type' => isset($data['type']) ? $data['type'] : '3',
  35. 'insert_time' => time(),
  36. ];
  37. $EmployeeOpenid_id = $this->insertGetId($insert_data);
  38. return $EmployeeOpenid_id;
  39. }
  40. /**
  41. * 写入数据
  42. * @author 唐远望
  43. * @version 1.0
  44. * @date 2025-12-04
  45. * @param $data
  46. * @return bool
  47. */
  48. public function addEmployeeOpenid($data)
  49. {
  50. DB::beginTransaction();
  51. try {
  52. $insert_data = [
  53. 'employee_id' => $data['employee_id'],
  54. 'unionid' => $data['unionid'],
  55. 'openid' => $data['openid'],
  56. 'type' => isset($data['type']) ? $data['type'] : '3',
  57. 'insert_time' => time(),
  58. ];
  59. $EmployeeOpenid_id = $this->insertGetId($insert_data);
  60. DB::commit();
  61. return $EmployeeOpenid_id;
  62. // 成功处理...
  63. } catch (\Exception $e) {
  64. DB::rollBack();
  65. // 错误处理...
  66. return false;
  67. }
  68. }
  69. /**
  70. * 编辑内容
  71. * @author 唐远望
  72. * @version 1.0
  73. * @date 2025-12-04
  74. * @param $data
  75. * @return bool
  76. */
  77. public function editEmployeeOpenid_content($where, $data)
  78. {
  79. $EmployeeOpenid = $this->where($where)->first();
  80. if (!$EmployeeOpenid) {
  81. return false;
  82. }
  83. $EmployeeOpenid->employee_id = $data['employee_id'];
  84. $EmployeeOpenid->unionid = $data['unionid'];
  85. $EmployeeOpenid->openid = $data['openid'];
  86. $EmployeeOpenid->type = isset($data['type']) ? $data['type'] : '3';
  87. $EmployeeOpenid->update_time = time();
  88. $EmployeeOpenid->save();
  89. return true;
  90. }
  91. /**
  92. * 更新数据
  93. * @author 唐远望
  94. * @version 1.0
  95. * @date 2025-12-04
  96. * @param $data
  97. * @return bool
  98. */
  99. public function updateEmployeeOpenid($EmployeeOpenid, $data)
  100. {
  101. DB::beginTransaction();
  102. try {
  103. $EmployeeOpenid->employee_id = $data['employee_id'];
  104. $EmployeeOpenid->unionid = $data['unionid'];
  105. $EmployeeOpenid->openid = $data['openid'];
  106. $EmployeeOpenid->type = isset($data['type']) ? $data['type'] : '3';
  107. $EmployeeOpenid->update_time = time();
  108. $EmployeeOpenid->save();
  109. DB::commit();
  110. return true;
  111. // 成功处理...
  112. } catch (\Exception $e) {
  113. DB::rollBack();
  114. print_r($e->getMessage());
  115. exit;
  116. // 错误处理...
  117. return false;
  118. }
  119. }
  120. /**
  121. * 删除数据
  122. * @author 唐远望
  123. * @version 1.0
  124. * @date 2025-12-04
  125. * @param $id
  126. * @return bool
  127. */
  128. public function deleteEmployeeOpenid($where)
  129. {
  130. $EmployeeOpenid = $this->where($where)->first();
  131. if (!$EmployeeOpenid) {
  132. return false;
  133. }
  134. $EmployeeOpenid->delete();
  135. return true;
  136. }
  137. }