PropertyHeadLogic.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. ]);
  50. Db::commit();
  51. return true;
  52. } catch (\Exception $e) {
  53. Db::rollback();
  54. self::setError($e->getMessage());
  55. return false;
  56. }
  57. }
  58. /**
  59. * @notes 编辑
  60. * @param array $params
  61. * @return bool
  62. * @author likeadmin
  63. * @date 2024/09/19 10:48
  64. */
  65. public static function edit(array $params): bool
  66. {
  67. $headMobile = PropertyHead::where('id', $params['id'])->value('head_mobile');
  68. Db::startTrans();
  69. try {
  70. // 手机号不同时做判断
  71. if($headMobile != $params['head_mobile']){
  72. $user = User::where(['mobile' => $params['head_mobile']])->findOrEmpty();
  73. if (!$user->isEmpty()) {
  74. throw new \Exception('该手机号已被注册');
  75. }
  76. // 更换用户手机号 account
  77. User::where(['mobile' => $headMobile])->save(['mobile' => $params['head_mobile']]);
  78. }
  79. PropertyHead::where('id', $params['id'])->update([
  80. 'property_name' => $params['property_name'],
  81. 'village_name' => $params['village_name'],
  82. 'address' => $params['address'],
  83. 'head_name' => $params['head_name'],
  84. 'head_mobile' => $params['head_mobile'],
  85. 'ratio' => $params['ratio'],
  86. 'head_bank_card' => $params['head_bank_card'],
  87. 'lon' => $params['lon'],
  88. 'lat' => $params['lat'],
  89. 'remark' => $params['remark']
  90. ]);
  91. Db::commit();
  92. return true;
  93. } catch (\Exception $e) {
  94. Db::rollback();
  95. self::setError($e->getMessage());
  96. return false;
  97. }
  98. }
  99. /**
  100. * @notes 删除
  101. * @param array $params
  102. * @return bool
  103. * @author likeadmin
  104. * @date 2024/09/19 10:48
  105. */
  106. public static function delete(array $params): bool
  107. {
  108. return PropertyHead::destroy($params['id']);
  109. }
  110. /**
  111. * @notes 获取详情
  112. * @param $params
  113. * @return array
  114. * @author likeadmin
  115. * @date 2024/09/19 10:48
  116. */
  117. public static function detail($params): array
  118. {
  119. return PropertyHead::findOrEmpty($params['id'])->toArray();
  120. }
  121. public static function updateUserId(string $head_mobile,int $userId): bool
  122. {
  123. Db::startTrans();
  124. try {
  125. PropertyHead::where('head_mobile', $head_mobile)->update(['user_id' => $userId]);
  126. Db::commit();
  127. return true;
  128. } catch (\Exception $e) {
  129. Db::rollback();
  130. self::setError($e->getMessage());
  131. return false;
  132. }
  133. }
  134. public static function selectList(): array
  135. {
  136. return PropertyHead::where('id','>',0)->select()->toArray();
  137. }
  138. }