Storemoneylog.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 Storemoneylog extends BaseModel {
  17. const TYPE_BILL=1;
  18. const TYPE_WITHDRAW=2;
  19. const TYPE_ADMIN=3;
  20. const TYPE_VERIFY=4;
  21. const TYPE_DEPOSIT_OUT=5;
  22. const TYPE_DEPOSIT_IN=6;
  23. const TYPE_MEMBER_IN=7;
  24. const TYPE_MEMBER_OUT=8;
  25. const STATE_VALID=1;
  26. const STATE_WAIT=2;
  27. const STATE_AGREE=3;
  28. const STATE_REJECT=4;
  29. public $page_info;
  30. /**
  31. * 取提现单信息总数
  32. * @access public
  33. * @author csdeshang
  34. * @param type $condition 条件
  35. * @return int
  36. */
  37. public function getStoremoneylogWithdrawCount($condition = array()) {
  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. $pdlog_list_paginate = Db::name('storemoneylog')->where($condition)->field($fields)->find();
  50. return $pdlog_list_paginate;
  51. }
  52. /**
  53. * 取得资金变更日志信息
  54. * @access public
  55. * @author csdeshang
  56. * @param type $condition 条件
  57. * @param type $data 字段
  58. * @return array
  59. */
  60. public function editStoremoneylog($condition = array(),$data=array()) {
  61. $pdlog_list_paginate = Db::name('storemoneylog')->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 getStoremoneylogList($condition = array(), $pagesize = '', $fields = '*', $order = '', $limit = 0) {
  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. if(!isset($data['store_id'])){
  94. throw new \think\Exception(lang('param_error'), 10006);
  95. }
  96. $store_info=Db::name('store')->where('store_id',$data['store_id'])->field('store_avaliable_money,store_freeze_money,store_name')->lock(true)->find();
  97. if(!$store_info){
  98. throw new \think\Exception(lang('ds_store_is_not_exist'), 10006);
  99. }
  100. $data['store_name']=$store_info['store_name'];
  101. $store_data=array();
  102. if(isset($data['store_avaliable_money']) && $data['store_avaliable_money']!=0){
  103. if($data['store_avaliable_money']<0 && $store_info['store_avaliable_money']<abs($data['store_avaliable_money'])){//检查资金是否充足
  104. throw new \think\Exception(lang('ds_store_avaliable_money_is_not_enough'), 10006);
  105. }
  106. $store_data['store_avaliable_money']=bcadd($store_info['store_avaliable_money'],$data['store_avaliable_money'],2);
  107. }
  108. if(isset($data['store_freeze_money']) && $data['store_freeze_money']!=0){
  109. if($data['store_freeze_money']<0 && $store_info['store_freeze_money']<abs($data['store_freeze_money'])){//检查资金是否充足
  110. throw new \think\Exception(lang('ds_store_freeze_money_is_not_enough'), 10006);
  111. }
  112. $store_data['store_freeze_money']=bcadd($store_info['store_freeze_money'],$data['store_freeze_money'],2);
  113. }
  114. if(!empty($store_data)){
  115. if(!Db::name('store')->where('store_id',$data['store_id'])->update($store_data)){
  116. throw new \think\Exception(lang('ds_store_money_adjust_fail'), 10006);
  117. }
  118. }
  119. $insert=Db::name('storemoneylog')->insertGetId($data);
  120. if(!$insert){
  121. throw new \think\Exception(lang('ds_store_money_log_insert_fail'), 10006);
  122. }
  123. return $insert;
  124. }
  125. }