Rechargecard.php 3.3 KB

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