Storedepositlog.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. namespace app\common\model;
  3. use think\facade\Db;
  4. /**
  5. * ============================================================================
  6. * DSMall多用户商城
  7. * ============================================================================
  8. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  9. * 网站地址: http://www.csdeshang.com
  10. * ----------------------------------------------------------------------------
  11. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  12. * 不允许对程序代码以任何形式任何目的的再发布。
  13. * ============================================================================
  14. * 数据层模型
  15. */
  16. class Storedepositlog extends BaseModel {
  17. const TYPE_RECHARGE=1;
  18. const TYPE_WITHDRAW=2;
  19. const TYPE_ADMIN=3;
  20. const TYPE_VERIFY=4;
  21. const TYPE_PAY=5;
  22. const TYPE_VIEW=6;
  23. const STATE_VALID=1;
  24. const STATE_WAIT=2;
  25. const STATE_AGREE=3;
  26. const STATE_REJECT=4;
  27. const STATE_PAYED=5;
  28. const STATE_CANCEL=6;
  29. const STATE_PAYING=7;
  30. public $page_info;
  31. /**
  32. * 取提现单信息总数
  33. * @access public
  34. * @author csdeshang
  35. * @param type $condition 条件
  36. * @return int
  37. */
  38. public function getStoredepositlogWithdrawCount($condition = array()) {
  39. return Db::name('storedepositlog')->where(array('storedepositlog_type'=>self::TYPE_WITHDRAW))->where($condition)->count();
  40. }
  41. /**
  42. * 取得资金变更日志信息
  43. * @access public
  44. * @author csdeshang
  45. * @param type $condition 条件
  46. * @param type $fields 字段
  47. * @return array
  48. */
  49. public function getStoredepositlogInfo($condition = array(),$fields='') {
  50. $pdlog_list_paginate = Db::name('storedepositlog')->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 editStoredepositlog($condition = array(),$data=array()) {
  62. $pdlog_list_paginate = Db::name('storedepositlog')->where($condition)->update($data);
  63. return $pdlog_list_paginate;
  64. }
  65. /**
  66. * 取得资金变更日志列表
  67. * @access public
  68. * @author csdeshang
  69. * @param type $condition 条件
  70. * @param type $pagesize 页面信息
  71. * @param type $fields 字段
  72. * @param type $order 排序
  73. * @param type $limit 限制
  74. * @return array
  75. */
  76. public function getStoredepositlogList($condition = array(), $pagesize = '', $fields = '*', $order = '', $limit = 0) {
  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. 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_deposit,store_freeze_deposit,store_payable_deposit,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_deposit']) && $data['store_avaliable_deposit']!=0){
  104. if($data['store_avaliable_deposit']<0 && $store_info['store_avaliable_deposit']<abs($data['store_avaliable_deposit'])){//检查资金是否充足
  105. throw new \think\Exception(lang('ds_store_avaliable_deposit_is_not_enough'), 10006);
  106. }
  107. $store_data['store_avaliable_deposit']=bcadd($store_info['store_avaliable_deposit'],$data['store_avaliable_deposit'],2);
  108. }
  109. if(isset($data['store_freeze_deposit']) && $data['store_freeze_deposit']!=0){
  110. if($data['store_freeze_deposit']<0 && $store_info['store_freeze_deposit']<abs($data['store_freeze_deposit'])){//检查资金是否充足
  111. throw new \think\Exception(lang('ds_store_freeze_deposit_is_not_enough'), 10006);
  112. }
  113. $store_data['store_freeze_deposit']=bcadd($store_info['store_freeze_deposit'],$data['store_freeze_deposit'],2);
  114. }
  115. if(isset($data['store_payable_deposit']) && $data['store_payable_deposit']!=0){
  116. if($data['store_payable_deposit']<0 && $store_info['store_payable_deposit']<abs($data['store_payable_deposit'])){//检查资金是否充足
  117. throw new \think\Exception(lang('ds_store_payable_deposit_is_not_enough'), 10006);
  118. }
  119. $store_data['store_payable_deposit']=bcadd($store_info['store_payable_deposit'],$data['store_payable_deposit'],2);
  120. }
  121. if(!empty($store_data)){
  122. if(!Db::name('store')->where('store_id',$data['store_id'])->update($store_data)){
  123. throw new \think\Exception(lang('ds_store_deposit_adjust_fail'), 10006);
  124. }
  125. }
  126. $insert=Db::name('storedepositlog')->insertGetId($data);
  127. if(!$insert){
  128. throw new \think\Exception(lang('ds_store_deposit_log_insert_fail'), 10006);
  129. }
  130. return $insert;
  131. }
  132. }