1
0

PropertyHeadLogic.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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\common\model\property\PropertyHead;
  16. use app\common\logic\BaseLogic;
  17. use think\facade\Db;
  18. /**
  19. * PropertyHead逻辑
  20. * Class PropertyHeadLogic
  21. * @package app\adminapi\logic
  22. */
  23. class PropertyHeadLogic extends BaseLogic
  24. {
  25. /**
  26. * @notes 添加
  27. * @param array $params
  28. * @return bool
  29. * @author likeadmin
  30. * @date 2024/09/19 10:48
  31. */
  32. public static function add(array $params): bool
  33. {
  34. Db::startTrans();
  35. try {
  36. PropertyHead::create([
  37. 'property_name' => $params['property_name'],
  38. 'village_name' => $params['village_name'],
  39. 'address' => $params['address'],
  40. 'head_name' => $params['head_name'],
  41. 'head_mobile' => $params['head_mobile'],
  42. 'commission_rules' => $params['commission_rules'],
  43. 'head_bank_card' => $params['head_bank_card'],
  44. 'remark' => $params['remark']
  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 10:48
  60. */
  61. public static function edit(array $params): bool
  62. {
  63. Db::startTrans();
  64. try {
  65. PropertyHead::where('id', $params['id'])->update([
  66. 'property_name' => $params['property_name'],
  67. 'village_name' => $params['village_name'],
  68. 'address' => $params['address'],
  69. 'head_name' => $params['head_name'],
  70. 'head_mobile' => $params['head_mobile'],
  71. 'commission_rules' => $params['commission_rules'],
  72. 'head_bank_card' => $params['head_bank_card'],
  73. 'remark' => $params['remark']
  74. ]);
  75. Db::commit();
  76. return true;
  77. } catch (\Exception $e) {
  78. Db::rollback();
  79. self::setError($e->getMessage());
  80. return false;
  81. }
  82. }
  83. /**
  84. * @notes 删除
  85. * @param array $params
  86. * @return bool
  87. * @author likeadmin
  88. * @date 2024/09/19 10:48
  89. */
  90. public static function delete(array $params): bool
  91. {
  92. return PropertyHead::destroy($params['id']);
  93. }
  94. /**
  95. * @notes 获取详情
  96. * @param $params
  97. * @return array
  98. * @author likeadmin
  99. * @date 2024/09/19 10:48
  100. */
  101. public static function detail($params): array
  102. {
  103. return PropertyHead::findOrEmpty($params['id'])->toArray();
  104. }
  105. public static function updateUserId(string $head_mobile,int $userId): bool
  106. {
  107. Db::startTrans();
  108. try {
  109. PropertyHead::where('head_mobile', $head_mobile)->update(['user_id' => $userId]);
  110. Db::commit();
  111. return true;
  112. } catch (\Exception $e) {
  113. Db::rollback();
  114. self::setError($e->getMessage());
  115. return false;
  116. }
  117. }
  118. }