Storemoneylog.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 STATE_VALID=1;
  24. const STATE_WAIT=2;
  25. const STATE_AGREE=3;
  26. const STATE_REJECT=4;
  27. public $page_info;
  28. /**
  29. * 取提现单信息总数
  30. * @access public
  31. * @author csdeshang
  32. * @param type $condition 条件
  33. * @return int
  34. */
  35. public function getStoremoneylogWithdrawCount($condition = array()) {
  36. return Db::name('storemoneylog')->where(array('storemoneylog_type'=>self::TYPE_WITHDRAW))->where($condition)->count();
  37. }
  38. /**
  39. * 取得资金变更日志信息
  40. * @access public
  41. * @author csdeshang
  42. * @param type $condition 条件
  43. * @param type $fields 字段
  44. * @return array
  45. */
  46. public function getStoremoneylogInfo($condition = array(),$fields='') {
  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. $pdlog_list_paginate = Db::name('storemoneylog')->where($condition)->update($data);
  60. return $pdlog_list_paginate;
  61. }
  62. /**
  63. * 取得资金变更日志列表
  64. * @access public
  65. * @author csdeshang
  66. * @param type $condition 条件
  67. * @param type $pagesize 页面信息
  68. * @param type $fields 字段
  69. * @param type $order 排序
  70. * @param type $limit 限制
  71. * @return array
  72. */
  73. public function getStoremoneylogList($condition = array(), $pagesize = '', $fields = '*', $order = '', $limit = 0) {
  74. if ($pagesize) {
  75. $pdlog_list_paginate = Db::name('storemoneylog')->where($condition)->field($fields)->order($order)->paginate(['list_rows'=>$pagesize,'query' => request()->param()],false);
  76. $this->page_info = $pdlog_list_paginate;
  77. return $pdlog_list_paginate->items();
  78. } else {
  79. $pdlog_list_paginate = Db::name('storemoneylog')->where($condition)->field($fields)->order($order)->limit($limit)->select()->toArray();
  80. return $pdlog_list_paginate;
  81. }
  82. }
  83. /**
  84. * 变更资金
  85. * @access public
  86. * @author csdeshang
  87. * @param type $data
  88. * @return type
  89. */
  90. public function changeStoremoney($data = array()) {
  91. if(!isset($data['store_id'])){
  92. throw new \think\Exception(lang('param_error'), 10006);
  93. }
  94. $store_info=Db::name('store')->where('store_id',$data['store_id'])->field('store_avaliable_money,store_freeze_money,store_name')->lock(true)->find();
  95. if(!$store_info){
  96. throw new \think\Exception(lang('ds_store_is_not_exist'), 10006);
  97. }
  98. $data['store_name']=$store_info['store_name'];
  99. $store_data=array();
  100. if(isset($data['store_avaliable_money']) && $data['store_avaliable_money']!=0){
  101. if($data['store_avaliable_money']<0 && $store_info['store_avaliable_money']<abs($data['store_avaliable_money'])){//检查资金是否充足
  102. throw new \think\Exception(lang('ds_store_avaliable_money_is_not_enough'), 10006);
  103. }
  104. $store_data['store_avaliable_money']=bcadd($store_info['store_avaliable_money'],$data['store_avaliable_money'],2);
  105. }
  106. if(isset($data['store_freeze_money']) && $data['store_freeze_money']!=0){
  107. if($data['store_freeze_money']<0 && $store_info['store_freeze_money']<abs($data['store_freeze_money'])){//检查资金是否充足
  108. throw new \think\Exception(lang('ds_store_freeze_money_is_not_enough'), 10006);
  109. }
  110. $store_data['store_freeze_money']=bcadd($store_info['store_freeze_money'],$data['store_freeze_money'],2);
  111. }
  112. if(!empty($store_data)){
  113. if(!Db::name('store')->where('store_id',$data['store_id'])->update($store_data)){
  114. throw new \think\Exception(lang('ds_store_money_adjust_fail'), 10006);
  115. }
  116. }
  117. $insert=Db::name('storemoneylog')->insertGetId($data);
  118. if(!$insert){
  119. throw new \think\Exception(lang('ds_store_money_log_insert_fail'), 10006);
  120. }
  121. return $insert;
  122. }
  123. }