Storedepositlog.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. namespace app\common\model;
  3. use think\facade\Db;
  4. /**
  5. *
  6. *
  7. * ----------------------------------------------------------------------------
  8. *
  9. * 数据层模型
  10. */
  11. class Storedepositlog extends BaseModel
  12. {
  13. const TYPE_RECHARGE = 1;
  14. const TYPE_WITHDRAW = 2;
  15. const TYPE_ADMIN = 3;
  16. const TYPE_VERIFY = 4;
  17. const TYPE_PAY = 5;
  18. const TYPE_VIEW = 6;
  19. const STATE_VALID = 1;
  20. const STATE_WAIT = 2;
  21. const STATE_AGREE = 3;
  22. const STATE_REJECT = 4;
  23. const STATE_PAYED = 5;
  24. const STATE_CANCEL = 6;
  25. const STATE_PAYING = 7;
  26. public $page_info;
  27. /**
  28. * 取提现单信息总数
  29. * @access public
  30. * @author csdeshang
  31. * @param type $condition 条件
  32. * @return int
  33. */
  34. public function getStoredepositlogWithdrawCount($condition = array())
  35. {
  36. return Db::name('storedepositlog')->where(array('storedepositlog_type' => self::TYPE_WITHDRAW))->where($condition)->count();
  37. }
  38. /**
  39. * 取得资金变更日志信息
  40. * @access public
  41. * @author csdeshang
  42. * @param type $condition 条件
  43. * @param type $fields 字段
  44. * @return array
  45. */
  46. public function getStoredepositlogInfo($condition = array(), $fields = '')
  47. {
  48. $pdlog_list_paginate = Db::name('storedepositlog')->where($condition)->field($fields)->find();
  49. return $pdlog_list_paginate;
  50. }
  51. /**
  52. * 取得资金变更日志信息
  53. * @access public
  54. * @author csdeshang
  55. * @param type $condition 条件
  56. * @param type $data 字段
  57. * @return array
  58. */
  59. public function editStoredepositlog($condition = array(), $data = array())
  60. {
  61. $pdlog_list_paginate = Db::name('storedepositlog')->where($condition)->update($data);
  62. return $pdlog_list_paginate;
  63. }
  64. /**
  65. * 取得资金变更日志列表
  66. * @access public
  67. * @author csdeshang
  68. * @param type $condition 条件
  69. * @param type $pagesize 页面信息
  70. * @param type $fields 字段
  71. * @param type $order 排序
  72. * @param type $limit 限制
  73. * @return array
  74. */
  75. public function getStoredepositlogList($condition = array(), $pagesize = '', $fields = '*', $order = '', $limit = 0)
  76. {
  77. if ($pagesize) {
  78. $pdlog_list_paginate = Db::name('storedepositlog')->where($condition)->field($fields)->order($order)->paginate(['list_rows' => $pagesize, 'query' => request()->param()], false);
  79. $this->page_info = $pdlog_list_paginate;
  80. return $pdlog_list_paginate->items();
  81. } else {
  82. $pdlog_list_paginate = Db::name('storedepositlog')->where($condition)->field($fields)->order($order)->limit($limit)->select()->toArray();
  83. return $pdlog_list_paginate;
  84. }
  85. }
  86. /**
  87. * 变更资金
  88. * @access public
  89. * @author csdeshang
  90. * @param type $data
  91. * @return type
  92. */
  93. public function changeStoredeposit($data = array())
  94. {
  95. if (!isset($data['store_id'])) {
  96. throw new \think\Exception(lang('param_error'), 10006);
  97. }
  98. $store_info = Db::name('store')->where('store_id', $data['store_id'])->field('store_avaliable_deposit,store_freeze_deposit,store_payable_deposit,store_name')->lock(true)->find();
  99. if (!$store_info) {
  100. throw new \think\Exception(lang('ds_store_is_not_exist'), 10006);
  101. }
  102. $data['store_name'] = $store_info['store_name'];
  103. $store_data = array();
  104. if (isset($data['store_avaliable_deposit']) && $data['store_avaliable_deposit'] != 0) {
  105. if ($data['store_avaliable_deposit'] < 0 && $store_info['store_avaliable_deposit'] < abs($data['store_avaliable_deposit'])) { //检查资金是否充足
  106. throw new \think\Exception(lang('ds_store_avaliable_deposit_is_not_enough'), 10006);
  107. }
  108. $store_data['store_avaliable_deposit'] = bcadd($store_info['store_avaliable_deposit'], $data['store_avaliable_deposit'], 2);
  109. }
  110. if (isset($data['store_freeze_deposit']) && $data['store_freeze_deposit'] != 0) {
  111. if ($data['store_freeze_deposit'] < 0 && $store_info['store_freeze_deposit'] < abs($data['store_freeze_deposit'])) { //检查资金是否充足
  112. throw new \think\Exception(lang('ds_store_freeze_deposit_is_not_enough'), 10006);
  113. }
  114. $store_data['store_freeze_deposit'] = bcadd($store_info['store_freeze_deposit'], $data['store_freeze_deposit'], 2);
  115. }
  116. if (isset($data['store_payable_deposit']) && $data['store_payable_deposit'] != 0) {
  117. if ($data['store_payable_deposit'] < 0 && $store_info['store_payable_deposit'] < abs($data['store_payable_deposit'])) { //检查资金是否充足
  118. throw new \think\Exception(lang('ds_store_payable_deposit_is_not_enough'), 10006);
  119. }
  120. $store_data['store_payable_deposit'] = bcadd($store_info['store_payable_deposit'], $data['store_payable_deposit'], 2);
  121. }
  122. if (!empty($store_data)) {
  123. if (!Db::name('store')->where('store_id', $data['store_id'])->update($store_data)) {
  124. throw new \think\Exception(lang('ds_store_deposit_adjust_fail'), 10006);
  125. }
  126. }
  127. $insert = Db::name('storedepositlog')->insertGetId($data);
  128. if (!$insert) {
  129. throw new \think\Exception(lang('ds_store_deposit_log_insert_fail'), 10006);
  130. }
  131. return $insert;
  132. }
  133. }