Storemoneylog.php 5.1 KB

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