1
0

PropertyUserLogic.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeadmin快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
  8. // | github下载:https://github.com/likeshop-github/likeadmin
  9. // | 访问官网:https://www.likeadmin.cn
  10. // | likeadmin团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: likeadminTeam
  13. // +----------------------------------------------------------------------
  14. namespace app\adminapi\logic\property;
  15. use app\adminapi\logic\user\UserLogic;
  16. use app\api\logic\LoginLogic;
  17. use app\common\model\property\PropertyUser;
  18. use app\common\logic\BaseLogic;
  19. use app\common\model\user\User;
  20. use think\facade\Db;
  21. /**
  22. * PropertyUser逻辑
  23. * Class PropertyUserLogic
  24. * @package app\adminapi\logic
  25. */
  26. class PropertyUserLogic extends BaseLogic
  27. {
  28. /**
  29. * @notes 添加
  30. * @param array $params
  31. * @return bool
  32. * @author likeadmin
  33. * @date 2024/09/19 14:35
  34. */
  35. public static function add(array $params): bool
  36. {
  37. Db::startTrans();
  38. try {
  39. PropertyUser::create([
  40. 'property_head_id' => $params['property_head_id'],
  41. 'householder_name' => $params['householder_name'],
  42. 'householder_mobile' => $params['householder_mobile'],
  43. 'address' => $params['address'],
  44. 'user_id' => $params['user_id'],
  45. ]);
  46. Db::commit();
  47. return true;
  48. } catch (\Exception $e) {
  49. Db::rollback();
  50. self::setError($e->getMessage());
  51. return false;
  52. }
  53. }
  54. /**
  55. * @notes 编辑
  56. * @param array $params
  57. * @return bool
  58. * @author likeadmin
  59. * @date 2024/09/19 14:35
  60. */
  61. public static function edit(array $params): bool
  62. {
  63. Db::startTrans();
  64. try {
  65. PropertyUser::where('id', $params['id'])->update([
  66. 'property_head_id' => $params['property_head_id'],
  67. 'householder_name' => $params['householder_name'],
  68. 'householder_mobile' => $params['householder_mobile'],
  69. 'address' => $params['address'],
  70. 'user_id' => $params['user_id'],
  71. ]);
  72. Db::commit();
  73. return true;
  74. } catch (\Exception $e) {
  75. Db::rollback();
  76. self::setError($e->getMessage());
  77. return false;
  78. }
  79. }
  80. /**
  81. * @notes 删除
  82. * @param array $params
  83. * @return bool
  84. * @author likeadmin
  85. * @date 2024/09/19 14:35
  86. */
  87. public static function delete(array $params): bool
  88. {
  89. return PropertyUser::destroy($params['id']);
  90. }
  91. /**
  92. * @notes 获取详情
  93. * @param $params
  94. * @return array
  95. * @author likeadmin
  96. * @date 2024/09/19 14:35
  97. */
  98. public static function detail($params): array
  99. {
  100. return PropertyUser::findOrEmpty($params['id'])->toArray();
  101. }
  102. public static function getPropertyUserIdByMobile(array $params)
  103. {
  104. $propertyUser = PropertyUser::where(['householder_mobile' => $params['householder_mobile']])->findOrEmpty();
  105. if ($propertyUser->isEmpty()) {
  106. //注册用户
  107. $userId = UserLogic::getUserIdByMobile($params['householder_mobile']);
  108. $propertyUser = PropertyUser::create([
  109. 'property_head_id' => $params['property_head_id'],
  110. 'householder_name' => $params['householder_name'],
  111. 'householder_mobile' => $params['householder_mobile'],
  112. 'address' => $params['address']??'',
  113. 'user_id' => $userId??0,
  114. ]);
  115. }
  116. return $propertyUser->id;
  117. }
  118. }