PropertySurplusLogLogic.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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(intval($params['status']) === 1){
  70. $res = self::EntryCash($params);
  71. }
  72. if(intval($params['status']) === 2){
  73. $res = self::CancelCash($params);
  74. }
  75. if(!$res){
  76. throw new Exception(self::getError());
  77. }
  78. /*PropertySurplusLog::where('id', $params['id'])->update([
  79. 'in_out' => $params['in_out'],
  80. 'property_commission_id' => $params['property_commission_id'],
  81. 'amount' => $params['amount'],
  82. 'status' => $params['status'],
  83. 'remark' => $params['remark'],
  84. 'property_head_id' => $params['property_head_id'],
  85. ]);*/
  86. Db::commit();
  87. return true;
  88. } catch (\Exception $e) {
  89. Db::rollback();
  90. self::setError($e->getMessage());
  91. return false;
  92. }
  93. }
  94. /**
  95. * @notes 删除
  96. * @param array $params
  97. * @return bool
  98. * @author likeadmin
  99. * @date 2024/09/20 16:31
  100. */
  101. public static function delete(array $params): bool
  102. {
  103. return PropertySurplusLog::destroy($params['id']);
  104. }
  105. /**
  106. * @notes 获取详情
  107. * @param $params
  108. * @return array
  109. * @author likeadmin
  110. * @date 2024/09/20 16:31
  111. */
  112. public static function detail($params): array
  113. {
  114. return PropertySurplusLog::findOrEmpty($params['id'])->toArray();
  115. }
  116. /**
  117. * 提现入账
  118. * @param $params
  119. * @return false|true
  120. */
  121. public static function EntryCash($params)
  122. {
  123. Db::startTrans();
  124. try {
  125. $propertySurplusLogInfo = PropertySurplusLog::where([
  126. "id" => $params['id'],
  127. 'in_out' => 2,
  128. 'status' => 0
  129. ])->findOrEmpty();
  130. if($propertySurplusLogInfo->isEmpty()){
  131. throw new Exception('申请中记录不存在');
  132. }
  133. $propertySurplusLogInfo = $propertySurplusLogInfo->toArray();
  134. $propertyHeadId = $propertySurplusLogInfo['property_head_id'];
  135. $amount = $propertySurplusLogInfo['amount'];
  136. // 更新 出账记录-已入账
  137. PropertySurplusLog::where(['id' => $params['id']])->update(['status' => 1]);
  138. // 更新 物业负责人已提收益
  139. PropertyHead::where(['id' => $propertyHeadId])->update(['extract_profit_amount' => Db::raw('extract_profit_amount+'.$amount)]);
  140. Db::commit();
  141. return true;
  142. }catch (\Exception $e) {
  143. Db::rollback();
  144. self::setError($e->getMessage());
  145. return false;
  146. }
  147. }
  148. /**
  149. * 提现取消
  150. * @param $params
  151. * @return false|true
  152. */
  153. public static function CancelCash($params)
  154. {
  155. Db::startTrans();
  156. try {
  157. $propertySurplusLogInfo = PropertySurplusLog::where([
  158. "id" => $params['id'],
  159. 'in_out' => 2,
  160. 'status' => 0
  161. ])->findOrEmpty();
  162. if($propertySurplusLogInfo->isEmpty()){
  163. throw new Exception('申请中记录不存在');
  164. }
  165. $propertySurplusLogInfo = $propertySurplusLogInfo->toArray();
  166. $propertyHeadId = $propertySurplusLogInfo['property_head_id'];
  167. $amount = $propertySurplusLogInfo['amount'];
  168. // 更新 出账记录-取消
  169. PropertySurplusLog::where(['id' => $params['id']])->update(['status' => 2]);
  170. // 更新 物业负责人剩余收益 金额恢复
  171. PropertyHead::where(['id' => $propertyHeadId])->update(['surplus_profit_amount' => Db::raw('surplus_profit_amount+'.$amount)]);
  172. Db::commit();
  173. return true;
  174. }catch (\Exception $e) {
  175. Db::rollback();
  176. self::setError($e->getMessage());
  177. return false;
  178. }
  179. }
  180. }