1
0

PropertySurplusLogLogic.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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\model\property\PropertySurplusLog;
  17. use app\common\logic\BaseLogic;
  18. use think\Exception;
  19. use think\facade\Db;
  20. /**
  21. * PropertySurplusLog逻辑
  22. * Class PropertySurplusLogLogic
  23. * @package app\adminapi\logic
  24. */
  25. class PropertySurplusLogLogic extends BaseLogic
  26. {
  27. /**
  28. * @notes 添加
  29. * @param array $params
  30. * @return bool
  31. * @author likeadmin
  32. * @date 2024/09/20 16:31
  33. */
  34. public static function add(array $params): bool
  35. {
  36. Db::startTrans();
  37. try {
  38. PropertySurplusLog::create([
  39. 'in_out' => $params['in_out'],
  40. 'property_commission_id' => $params['property_commission_id'],
  41. 'amount' => $params['amount'],
  42. 'status' => $params['status'],
  43. 'remark' => $params['remark'],
  44. 'property_head_id' => $params['property_head_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/20 16:31
  60. */
  61. public static function edit(array $params): bool
  62. {
  63. Db::startTrans();
  64. try {
  65. $status = PropertySurplusLog::where('id', $params['id'])->value('status');
  66. if($status != 0){
  67. throw new Exception('状态不允许操作');
  68. }
  69. if($params['status'] == 1){
  70. self::EntryCash($params);
  71. }
  72. if($params['status'] == 1){
  73. self::CancelCash($params);
  74. }
  75. /*PropertySurplusLog::where('id', $params['id'])->update([
  76. 'in_out' => $params['in_out'],
  77. 'property_commission_id' => $params['property_commission_id'],
  78. 'amount' => $params['amount'],
  79. 'status' => $params['status'],
  80. 'remark' => $params['remark'],
  81. 'property_head_id' => $params['property_head_id'],
  82. ]);*/
  83. Db::commit();
  84. return true;
  85. } catch (\Exception $e) {
  86. Db::rollback();
  87. self::setError($e->getMessage());
  88. return false;
  89. }
  90. }
  91. /**
  92. * @notes 删除
  93. * @param array $params
  94. * @return bool
  95. * @author likeadmin
  96. * @date 2024/09/20 16:31
  97. */
  98. public static function delete(array $params): bool
  99. {
  100. return PropertySurplusLog::destroy($params['id']);
  101. }
  102. /**
  103. * @notes 获取详情
  104. * @param $params
  105. * @return array
  106. * @author likeadmin
  107. * @date 2024/09/20 16:31
  108. */
  109. public static function detail($params): array
  110. {
  111. return PropertySurplusLog::findOrEmpty($params['id'])->toArray();
  112. }
  113. /**
  114. * 提现入账
  115. * @param $params
  116. * @return false|true
  117. */
  118. public static function EntryCash($params)
  119. {
  120. Db::startTrans();
  121. try {
  122. $propertySurplusLogInfo = PropertySurplusLog::where([
  123. "id" => $params['id'],
  124. 'in_out' => 2,
  125. 'status' => 0
  126. ])->findOrEmpty();
  127. if($propertySurplusLogInfo->isEmpty()){
  128. throw new Exception('申请中记录不存在');
  129. }
  130. $propertySurplusLogInfo = $propertySurplusLogInfo->toArray();
  131. $propertyHeadId = $propertySurplusLogInfo['property_head_id'];
  132. $amount = $propertySurplusLogInfo['amount'];
  133. // 更新 出账记录-已入账
  134. PropertySurplusLog::where(['id' => $params['id']])->update(['status' => 1]);
  135. // 更新 物业负责人已提收益
  136. PropertyHead::where(['id' => $propertyHeadId])->update(['extract_profit_amount' => Db::raw('extract_profit_amount+'.$amount)]);
  137. Db::commit();
  138. return true;
  139. }catch (\Exception $e) {
  140. Db::rollback();
  141. self::setError($e->getMessage());
  142. return false;
  143. }
  144. }
  145. /**
  146. * 提现取消
  147. * @param $params
  148. * @return false|true
  149. */
  150. public static function CancelCash($params)
  151. {
  152. Db::startTrans();
  153. try {
  154. $propertySurplusLogInfo = PropertySurplusLog::where([
  155. "id" => $params['id'],
  156. 'in_out' => 2,
  157. 'status' => 0
  158. ])->findOrEmpty();
  159. if($propertySurplusLogInfo->isEmpty()){
  160. throw new Exception('申请中记录不存在');
  161. }
  162. $propertySurplusLogInfo = $propertySurplusLogInfo->toArray();
  163. $propertyHeadId = $propertySurplusLogInfo['property_head_id'];
  164. $amount = $propertySurplusLogInfo['amount'];
  165. // 更新 出账记录-取消
  166. PropertySurplusLog::where(['id' => $params['id']])->update(['status' => 2]);
  167. // 更新 物业负责人剩余收益 金额恢复
  168. PropertyHead::where(['id' => $propertyHeadId])->update(['surplus_profit_amount' => Db::raw('surplus_profit_amount+'.$amount)]);
  169. Db::commit();
  170. return true;
  171. }catch (\Exception $e) {
  172. Db::rollback();
  173. self::setError($e->getMessage());
  174. return false;
  175. }
  176. }
  177. }