rechargecard.model.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. /**
  3. * 平台充值卡
  4. *
  5. */
  6. defined('InShopNC') or exit('Access Invalid!');
  7. class rechargecardModel extends Model
  8. {
  9. public function __construct()
  10. {
  11. parent::__construct('rechargecard');
  12. }
  13. /**
  14. * 获取充值卡列表
  15. *
  16. * @param array $condition 条件数组
  17. * @param int $pageSize 分页长度
  18. *
  19. * @return array 充值卡列表
  20. */
  21. public function getRechargeCardList($condition, $pageSize = 20, $limit = null)
  22. {
  23. if ($condition) {
  24. $this->where($condition);
  25. }
  26. $this->order('id desc');
  27. if ($limit) {
  28. $this->limit($limit);
  29. } else {
  30. $this->page($pageSize);
  31. }
  32. return $this->select();
  33. }
  34. /**
  35. * 通过卡号获取单条充值卡数据
  36. *
  37. * @param string $sn 卡号
  38. *
  39. * @return array|null 充值卡数据
  40. */
  41. public function getRechargeCardBySN($sn)
  42. {
  43. return $this->where(array(
  44. 'sn' => (string) $sn,
  45. ))->find();
  46. }
  47. /**
  48. * 设置充值卡为已使用
  49. *
  50. * @param int $id 表字增ID
  51. * @param int $memberId 会员ID
  52. * @param string $memberName 会员名称
  53. *
  54. * @return boolean
  55. */
  56. public function setRechargeCardUsedById($id, $memberId, $memberName)
  57. {
  58. return $this->where(array(
  59. 'id' => (string) $id,
  60. ))->update(array(
  61. 'tsused' => time(),
  62. 'state' => 1,
  63. 'member_id' => $memberId,
  64. 'member_name' => $memberName,
  65. ));
  66. }
  67. /**
  68. * 通过ID删除充值卡(自动添加未使用标记)
  69. *
  70. * @param int|array $id 表字增ID(s)
  71. *
  72. * @return boolean
  73. */
  74. public function delRechargeCardById($id)
  75. {
  76. return $this->where(array(
  77. 'id' => array('in', (array) $id),
  78. 'state' => 0,
  79. ))->delete();
  80. }
  81. /**
  82. * 通过给定的卡号数组过滤出来不能被新插入的卡号(卡号存在的)
  83. *
  84. * @param array $sns 卡号数组
  85. *
  86. * @return array
  87. */
  88. public function getOccupiedRechargeCardSNsBySNs(array $sns)
  89. {
  90. $array = $this->field('sn')->where(array(
  91. 'sn' => array('in', $sns),
  92. ))->select();
  93. $data = array();
  94. foreach ((array) $array as $v) {
  95. $data[] = $v['sn'];
  96. }
  97. return $data;
  98. }
  99. public function getRechargeCardCount($condition) {
  100. return $this->where($condition)->count();
  101. }
  102. }