Storemoneylog.php 4.9 KB

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