Storemoneylog.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. namespace app\common\model;
  3. use think\facade\Db;
  4. /**
  5. * ============================================================================
  6. *
  7. * ============================================================================
  8. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  9. * 网站地址: https://www.valimart.net/
  10. * ----------------------------------------------------------------------------
  11. *
  12. * ============================================================================
  13. * 数据层模型
  14. */
  15. class Storemoneylog extends BaseModel {
  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. return Db::name('storemoneylog')->where(array('storemoneylog_type'=>self::TYPE_WITHDRAW))->where($condition)->count();
  38. }
  39. /**
  40. * 取得资金变更日志信息
  41. * @access public
  42. * @author csdeshang
  43. * @param type $condition 条件
  44. * @param type $fields 字段
  45. * @return array
  46. */
  47. public function getStoremoneylogInfo($condition = array(),$fields='') {
  48. $pdlog_list_paginate = Db::name('storemoneylog')->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 editStoremoneylog($condition = array(),$data=array()) {
  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. if ($pagesize) {
  76. $pdlog_list_paginate = Db::name('storemoneylog')->where($condition)->field($fields)->order($order)->paginate(['list_rows'=>$pagesize,'query' => request()->param()],false);
  77. $this->page_info = $pdlog_list_paginate;
  78. return $pdlog_list_paginate->items();
  79. } else {
  80. $pdlog_list_paginate = Db::name('storemoneylog')->where($condition)->field($fields)->order($order)->limit($limit)->select()->toArray();
  81. return $pdlog_list_paginate;
  82. }
  83. }
  84. /**
  85. * 变更资金
  86. * @access public
  87. * @author csdeshang
  88. * @param type $data
  89. * @return type
  90. */
  91. public function changeStoremoney($data = array()) {
  92. if(!isset($data['store_id'])){
  93. throw new \think\Exception(lang('param_error'), 10006);
  94. }
  95. $store_info=Db::name('store')->where('store_id',$data['store_id'])->field('store_avaliable_money,store_freeze_money,store_name')->lock(true)->find();
  96. if(!$store_info){
  97. throw new \think\Exception(lang('ds_store_is_not_exist'), 10006);
  98. }
  99. $data['store_name']=$store_info['store_name'];
  100. $store_data=array();
  101. if(isset($data['store_avaliable_money']) && $data['store_avaliable_money']!=0){
  102. if($data['store_avaliable_money']<0 && $store_info['store_avaliable_money']<abs($data['store_avaliable_money'])){//检查资金是否充足
  103. throw new \think\Exception(lang('ds_store_avaliable_money_is_not_enough'), 10006);
  104. }
  105. $store_data['store_avaliable_money']=bcadd($store_info['store_avaliable_money'],$data['store_avaliable_money'],2);
  106. }
  107. if(isset($data['store_freeze_money']) && $data['store_freeze_money']!=0){
  108. if($data['store_freeze_money']<0 && $store_info['store_freeze_money']<abs($data['store_freeze_money'])){//检查资金是否充足
  109. throw new \think\Exception(lang('ds_store_freeze_money_is_not_enough'), 10006);
  110. }
  111. $store_data['store_freeze_money']=bcadd($store_info['store_freeze_money'],$data['store_freeze_money'],2);
  112. }
  113. if(!empty($store_data)){
  114. if(!Db::name('store')->where('store_id',$data['store_id'])->update($store_data)){
  115. throw new \think\Exception(lang('ds_store_money_adjust_fail'), 10006);
  116. }
  117. }
  118. $insert=Db::name('storemoneylog')->insertGetId($data);
  119. if(!$insert){
  120. throw new \think\Exception(lang('ds_store_money_log_insert_fail'), 10006);
  121. }
  122. return $insert;
  123. }
  124. }