StaffCollect.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace addons\qingdongams\model;
  3. use think\Exception;
  4. use think\Model;
  5. use traits\model\SoftDelete;
  6. /**
  7. *重点关注表
  8. */
  9. class StaffCollect Extends Model {
  10. use SoftDelete;
  11. // 表名,不含前缀
  12. protected $name = 'qingdongams_staff_collect';
  13. const CUSTOMER_TYPE = 1;//客户
  14. // 开启自动写入时间戳字段
  15. protected $autoWriteTimestamp = 'int';
  16. // 定义时间戳字段名
  17. protected $createTime = 'createtime';
  18. protected $updateTime = 'updatetime';
  19. protected $deleteTime = 'deletetime';
  20. //添加重点关注
  21. public static function addCollect($type, $id) {
  22. $staff = Staff::info();
  23. $data = [
  24. 'relation_type' => $type,
  25. 'relation_id' => $id,
  26. 'staff_id' => $staff->id
  27. ];
  28. $Model = new self;
  29. // 调用当前模型对应的User验证器类进行数据验证
  30. $result = $Model->save($data);
  31. if (false === $result) {
  32. // 验证失败 输出错误信息
  33. throw new Exception($Model->getError());
  34. }
  35. return true;
  36. }
  37. //取消重点关注
  38. public static function cancel($type, $id) {
  39. $Model = new self;
  40. // 调用当前模型对应的User验证器类进行数据验证
  41. $result = $Model->destroy(['relation_type' => $type, 'relation_id' => $id]);
  42. if (false === $result) {
  43. // 验证失败 输出错误信息
  44. throw new Exception($Model->getError());
  45. }
  46. return true;
  47. }
  48. //是否重点关注
  49. public static function isCollect($type, $id) {
  50. $staff = Staff::info();
  51. $where = [
  52. 'relation_type' => $type,
  53. 'relation_id' => $id,
  54. 'staff_id' => $staff->id
  55. ];
  56. $Model = new self;
  57. // 调用当前模型对应的User验证器类进行数据验证
  58. if ($Model->where($where)->find()) {
  59. return true;
  60. }
  61. return false;
  62. }
  63. }