Cash.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace app\api\model\plus\agent;
  3. use app\common\exception\BaseException;
  4. use app\common\model\plus\agent\Cash as CashModel;
  5. /**
  6. * 分销商提现明细模型
  7. */
  8. class Cash extends CashModel
  9. {
  10. /**
  11. * 隐藏字段
  12. */
  13. protected $hidden = [
  14. 'update_time',
  15. ];
  16. /**
  17. * 获取分销商提现明细
  18. */
  19. public function getList($user_id, $apply_status = -1,$limit=15)
  20. {
  21. $model = $this;
  22. $apply_status > -1 && $model = $model->where('apply_status', '=', $apply_status);
  23. return $model->where('user_id', '=', $user_id)->order(['create_time' => 'desc'])
  24. ->paginate($limit);
  25. }
  26. /**
  27. * 提交申请
  28. */
  29. public function submit($agent, $data)
  30. {
  31. // 数据验证
  32. $this->validation($agent, $data);
  33. // 新增申请记录
  34. $this->save(array_merge($data, [
  35. 'user_id' => $agent['user_id'],
  36. 'apply_status' => 10,
  37. 'app_id' => self::$app_id,
  38. ]));
  39. // 冻结用户资金
  40. $agent->freezeMoney($data['money']);
  41. return true;
  42. }
  43. /**
  44. * 数据验证
  45. */
  46. private function validation($agent, $data)
  47. {
  48. // 结算设置
  49. $settlement = Setting::getItem('settlement');
  50. // 最低提现佣金
  51. if ($data['money'] <= 0) {
  52. throw new BaseException(['msg' => '提现金额不正确']);
  53. }
  54. if ($agent['money'] <= 0) {
  55. throw new BaseException(['msg' => '当前用户没有可提现佣金']);
  56. }
  57. if ($data['money'] > $agent['money']) {
  58. throw new BaseException(['msg' => '提现金额不能大于可提现佣金']);
  59. }
  60. if ($data['money'] < $settlement['min_money']) {
  61. throw new BaseException(['msg' => '最低提现金额为' . $settlement['min_money']]);
  62. }
  63. if (!in_array($data['pay_type'], $settlement['pay_type'])) {
  64. throw new BaseException(['msg' => '提现方式不正确']);
  65. }
  66. if ($data['pay_type'] == '20') {
  67. if (empty($data['alipay_name']) || empty($data['alipay_account'])) {
  68. throw new BaseException(['msg' => '请补全提现信息']);
  69. }
  70. } elseif ($data['pay_type'] == '30') {
  71. if (empty($data['bank_name']) || empty($data['bank_account']) || empty($data['bank_card'])) {
  72. throw new BaseException(['msg' => '请补全提现信息']);
  73. }
  74. }
  75. }
  76. }