PropertyCommissionLogic.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. namespace app\adminapi\logic\property;
  3. use app\common\enum\GoodsEnum;
  4. use app\common\enum\PayEnum;
  5. use app\common\enum\WorkEnum;
  6. use app\common\logic\BaseLogic;
  7. use app\common\model\coupon\UserCoupon;
  8. use app\common\model\dict\DictData;
  9. use app\common\model\goods\Goods;
  10. use app\common\model\master_worker\MasterWorker;
  11. use app\common\model\orders\RechargeOrder;
  12. use app\common\model\property\PropertyCommission;
  13. use app\common\model\property\PropertyHead;
  14. use app\common\model\property\PropertyOrder;
  15. use app\common\model\property\PropertySurplusLog;
  16. use app\common\model\property\PropertyUser;
  17. use app\common\model\recharge\OrderGoods;
  18. use app\common\model\works\ServiceWork;
  19. use app\workerapi\logic\ServiceWorkLogLogic;
  20. use think\Exception;
  21. use think\facade\Db;
  22. /**
  23. * 物业分成收益逻辑
  24. * Class PropertyCommissionLogic
  25. * @package app\api\logic
  26. */
  27. class PropertyCommissionLogic extends BaseLogic
  28. {
  29. /**
  30. * 提现入账申请通过
  31. * @param $params
  32. * @return false|true
  33. */
  34. public static function EntryCash($params)
  35. {
  36. Db::startTrans();
  37. try {
  38. $propertySurplusLogInfo = PropertySurplusLog::where([
  39. "id" => $params['id'],
  40. 'in_out' => 2,
  41. 'status' => 0
  42. ])->findOrEmpty();
  43. if($propertySurplusLogInfo->isEmpty()){
  44. throw new Exception('申请中记录不存在');
  45. }
  46. $propertySurplusLogInfo = $propertySurplusLogInfo->toArray();
  47. $propertyHeadId = $propertySurplusLogInfo['property_head_id'];
  48. $amount = $propertySurplusLogInfo['amount'];
  49. // 更新 出账记录-已入账
  50. PropertySurplusLog::where(['id' => $params['id']])->update(['status' => 1]);
  51. // 更新 物业负责人已提收益
  52. PropertyHead::where(['id' => $propertyHeadId])->update(['extract_profit_amount' => Db::raw('extract_profit_amount+'.$amount)]);
  53. Db::commit();
  54. return true;
  55. }catch (\Exception $e) {
  56. Db::rollback();
  57. self::setError($e->getMessage());
  58. return false;
  59. }
  60. }
  61. /**
  62. * 提现取消
  63. * @param $params
  64. * @return false|true
  65. */
  66. public static function CancelCash($params)
  67. {
  68. Db::startTrans();
  69. try {
  70. $propertySurplusLogInfo = PropertySurplusLog::where([
  71. "id" => $params['id'],
  72. 'in_out' => 2,
  73. 'status' => 0
  74. ])->findOrEmpty();
  75. if($propertySurplusLogInfo->isEmpty()){
  76. throw new Exception('申请中记录不存在');
  77. }
  78. $propertySurplusLogInfo = $propertySurplusLogInfo->toArray();
  79. $propertyHeadId = $propertySurplusLogInfo['property_head_id'];
  80. $amount = $propertySurplusLogInfo['amount'];
  81. // 更新 出账记录-取消
  82. PropertySurplusLog::where(['id' => $params['id']])->update(['status' => 2]);
  83. // 更新 物业负责人剩余收益 金额恢复
  84. PropertyHead::where(['id' => $propertyHeadId])->update(['surplus_profit_amount' => Db::raw('surplus_profit_amount+'.$amount)]);
  85. Db::commit();
  86. return true;
  87. }catch (\Exception $e) {
  88. Db::rollback();
  89. self::setError($e->getMessage());
  90. return false;
  91. }
  92. }
  93. /**
  94. * @notes 获取详情
  95. * @param $params
  96. * @return array
  97. * @author likeadmin
  98. * @date 2024/09/20 16:17
  99. */
  100. public static function detail($params): array
  101. {
  102. return PropertyCommission::findOrEmpty($params['id'])->toArray();
  103. }
  104. }