PropertyHeadLogic.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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\common\model\property\PropertyHead;
  17. use app\common\logic\BaseLogic;
  18. use app\common\model\user\User;
  19. use think\facade\Db;
  20. /**
  21. * PropertyHead逻辑
  22. * Class PropertyHeadLogic
  23. * @package app\adminapi\logic
  24. */
  25. class PropertyHeadLogic extends BaseLogic
  26. {
  27. /**
  28. * @notes 添加
  29. * @param array $params
  30. * @return bool
  31. * @author likeadmin
  32. * @date 2024/09/19 10:48
  33. */
  34. public static function add(array $params): bool
  35. {
  36. Db::startTrans();
  37. try {
  38. PropertyHead::create([
  39. 'property_name' => $params['property_name'],
  40. 'village_name' => $params['village_name'],
  41. 'address' => $params['address'],
  42. 'head_name' => $params['head_name'],
  43. 'head_mobile' => $params['head_mobile'],
  44. 'ratio' => $params['ratio'],
  45. 'head_bank_card' => $params['head_bank_card'],
  46. 'lon' => $params['lon'],
  47. 'lat' => $params['lat'],
  48. 'remark' => $params['remark'],
  49. 'bind_date'=>!empty($params['bind_date'])?$params['bind_date']:0
  50. ]);
  51. Db::commit();
  52. return true;
  53. } catch (\Exception $e) {
  54. Db::rollback();
  55. self::setError($e->getMessage());
  56. return false;
  57. }
  58. }
  59. /**
  60. * @notes 编辑
  61. * @param array $params
  62. * @return bool
  63. * @author likeadmin
  64. * @date 2024/09/19 10:48
  65. */
  66. public static function edit(array $params): bool
  67. {
  68. $headMobile = PropertyHead::where('id', $params['id'])->value('head_mobile');
  69. Db::startTrans();
  70. try {
  71. // 手机号不同时做判断
  72. if($headMobile != $params['head_mobile']){
  73. $user = User::where(['mobile' => $params['head_mobile']])->findOrEmpty();
  74. if (!$user->isEmpty()) {
  75. throw new \Exception('该手机号已被注册');
  76. }
  77. // 更换用户手机号 account
  78. User::where(['mobile' => $headMobile])->save(['mobile' => $params['head_mobile']]);
  79. }
  80. PropertyHead::where('id', $params['id'])->update([
  81. 'property_name' => $params['property_name'],
  82. 'village_name' => $params['village_name'],
  83. 'address' => $params['address'],
  84. 'head_name' => $params['head_name'],
  85. 'head_mobile' => $params['head_mobile'],
  86. 'ratio' => $params['ratio'],
  87. 'head_bank_card' => $params['head_bank_card'],
  88. 'lon' => $params['lon'],
  89. 'lat' => $params['lat'],
  90. 'remark' => $params['remark'],
  91. 'bind_date'=>!empty($params['bind_date'])?$params['bind_date']:0
  92. ]);
  93. Db::commit();
  94. return true;
  95. } catch (\Exception $e) {
  96. Db::rollback();
  97. self::setError($e->getMessage());
  98. return false;
  99. }
  100. }
  101. /**
  102. * @notes 删除
  103. * @param array $params
  104. * @return bool
  105. * @author likeadmin
  106. * @date 2024/09/19 10:48
  107. */
  108. public static function delete(array $params): bool
  109. {
  110. return PropertyHead::destroy($params['id']);
  111. }
  112. /**
  113. * @notes 获取详情
  114. * @param $params
  115. * @return array
  116. * @author likeadmin
  117. * @date 2024/09/19 10:48
  118. */
  119. public static function detail($params): array
  120. {
  121. return PropertyHead::findOrEmpty($params['id'])->toArray();
  122. }
  123. public static function updateUserId(string $head_mobile,int $userId): bool
  124. {
  125. Db::startTrans();
  126. try {
  127. PropertyHead::where('head_mobile', $head_mobile)->update(['user_id' => $userId]);
  128. Db::commit();
  129. return true;
  130. } catch (\Exception $e) {
  131. Db::rollback();
  132. self::setError($e->getMessage());
  133. return false;
  134. }
  135. }
  136. public static function selectList(): array
  137. {
  138. return PropertyHead::where('id','>',0)->select()->toArray();
  139. }
  140. }