Rechargecard.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 Rechargecard extends BaseModel
  16. {
  17. public $page_info;
  18. /**
  19. * 获取充值卡列表
  20. * @access public
  21. * @author csdeshang
  22. * @param type $condition 查询条件
  23. * @param type $pagesize 分页
  24. * @param type $limit 限制
  25. * @return type
  26. */
  27. public function getRechargecardList($condition, $pagesize = 20, $limit = 0) {
  28. $order = 'rc_id desc';
  29. if ($pagesize) {
  30. $res = Db::name('rechargecard')->where($condition)->order($order)->paginate(['list_rows'=>$pagesize,'query' => request()->param()],false);
  31. $this->page_info = $res;
  32. return $res->items();
  33. } else {
  34. return Db::name('rechargecard')->where($condition)->order($order)->limit($limit)->select()->toArray();
  35. }
  36. }
  37. /**
  38. * 通过卡号获取单条充值卡数据
  39. * @access public
  40. * @author csdeshang
  41. * @param type $sn 卡号
  42. * @return type
  43. */
  44. public function getRechargecardBySN($sn)
  45. {
  46. return Db::name('rechargecard')->where(array(
  47. 'rc_sn' => (string) $sn,
  48. ))->find();
  49. }
  50. /**
  51. * 设置充值卡为已使用
  52. * @access public
  53. * @author csdeshang
  54. * @param type $id 表字增ID
  55. * @param type $memberId 会员ID
  56. * @param type $memberName 会员名称
  57. * @return type
  58. */
  59. public function setRechargecardUsedById($id, $memberId, $memberName)
  60. {
  61. return Db::name('rechargecard')->where(array('rc_id' => (string) $id,))->update(array('rc_tsused' => TIMESTAMP, 'rc_state' => 1, 'member_id' => $memberId, 'member_name' => $memberName,));
  62. }
  63. /**
  64. * 通过ID删除充值卡(自动添加未使用标记)
  65. * @access public
  66. * @author csdeshang
  67. * @param type $id 表自增id
  68. * @return type
  69. */
  70. public function delRechargecard($condition)
  71. {
  72. return Db::name('rechargecard')->where($condition)->delete();
  73. }
  74. /**
  75. * 通过给定的卡号数组过滤出来不能被新插入的卡号(卡号存在的)
  76. * @access public
  77. * @author csdeshang
  78. * @param array $sns 卡号数组
  79. * @return type
  80. */
  81. public function getOccupiedRechargecardSNsBySNs(array $sns)
  82. {
  83. $array = Db::name('rechargecard')->field('rc_sn')->where('rc_sn','in',$sns)->select()->toArray();
  84. $data = array();
  85. foreach ((array) $array as $v) {
  86. $data[] = $v['rc_sn'];
  87. }
  88. return $data;
  89. }
  90. /**
  91. * 获取充值卡数量
  92. * @access public
  93. * @author csdeshang
  94. * @param type $condition 条件
  95. * @return type
  96. */
  97. public function getRechargecardCount($condition) {
  98. return Db::name('rechargecard')->where($condition)->count();
  99. }
  100. /**
  101. * 保存充值卡
  102. * @access public
  103. * @author csdeshang
  104. * @param array $data 参数内容
  105. * @return boolean
  106. */
  107. public function addRechargecardAll($data) {
  108. return Db::name('rechargecard')->insertAll($data);
  109. }
  110. }