CardUse.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 上海牛之云网络科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace addon\giftcard\model\card;
  11. use app\model\BaseModel;
  12. /**
  13. * 礼品卡使用记录工具类
  14. *
  15. * @author Administrator
  16. *
  17. */
  18. class CardUse extends BaseModel
  19. {
  20. /**
  21. * 生成礼品卡记录
  22. * @param $params
  23. */
  24. public function addCardUseRecords($params)
  25. {
  26. $member_id = $params[ 'member_id' ] ?? 0;
  27. $giftcard_id = $params[ 'giftcard_id' ];
  28. $card_right_type = $params[ 'card_right_type' ];
  29. $use_order_id = $params[ 'use_order_id' ] ?? 0;
  30. $data = array (
  31. 'site_id' => $params[ 'site_id' ],
  32. 'card_id' => $params[ 'card_id' ],
  33. 'member_card_id' => $params[ 'member_card_id' ],
  34. 'giftcard_id' => $giftcard_id,
  35. 'member_id' => $member_id,
  36. 'use_time' => time(),
  37. 'card_right_type' => $card_right_type,
  38. 'order_id' => $use_order_id
  39. );
  40. $records_id = model('giftcard_card_use_records')->add($data);
  41. $goods_list = $params[ 'goods_list' ];
  42. foreach ($goods_list as $k => $v) {
  43. $v[ 'order_id' ] = $use_order_id;
  44. $v[ 'records_id' ] = $records_id;
  45. $this->addCardUseRecordsGoods($v);
  46. }
  47. return $this->success($records_id);
  48. }
  49. /**
  50. * 礼品卡项使用记录
  51. * @param $params
  52. * @return array
  53. */
  54. public function addCardUseRecordsGoods($params)
  55. {
  56. $data = array (
  57. 'site_id' => $params[ 'site_id' ],
  58. 'records_id' => $params[ 'records_id' ],//使用记录id
  59. 'card_goods_id' => $params[ 'id' ],
  60. 'sku_id' => $params[ 'sku_id' ] ?? 0,
  61. 'sku_name' => $params[ 'sku_name' ] ?? '',
  62. 'sku_image' => $params[ 'sku_image' ] ?? '',
  63. 'sku_no' => $params[ 'sku_no' ] ?? '',
  64. 'goods_id' => $params[ 'goods_id' ] ?? 0,
  65. 'goods_name' => $params[ 'goods_name' ] ?? '',
  66. 'balance' => $params[ 'balance' ] ?? 0,//储值余额
  67. 'use_num' => $params[ 'temp_use_num' ] ?? '',
  68. 'order_id' => $params[ 'order_id' ] ?? 0,
  69. 'order_goods_id' => $params[ 'use_order_goods_id' ] ?? 0,
  70. );
  71. model('giftcard_card_use_records_goods')->add($data);
  72. return $this->success();
  73. }
  74. /**
  75. * 获取礼品卡使用记录信息
  76. * @param $condition
  77. * @param string $field
  78. * @return array
  79. */
  80. public function getCardUseRecordsInfo($condition, $field = '*')
  81. {
  82. $info = model('giftcard_card_use_records')->getInfo($condition, $field);
  83. return $this->success($info);
  84. }
  85. /**
  86. * 获取礼品卡使用记录列表
  87. * @param array $condition
  88. * @param string $field
  89. * @param string $order
  90. * @param null $limit
  91. * @return array
  92. */
  93. public function getCardUseRecordsList($condition = [], $field = '*', $order = '', $limit = null)
  94. {
  95. $list = model('giftcard_card_use_records')->getList($condition, $field, $order, '', '', '', $limit);
  96. return $this->success($list);
  97. }
  98. /**
  99. * 获取礼品卡使用记录分页列表
  100. * @param array $condition
  101. * @param int $page
  102. * @param int $page_size
  103. * @param string $order
  104. * @param string $field
  105. * @return array
  106. */
  107. public function getCardUseRecordsPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '*')
  108. {
  109. $list = model('giftcard_card_use_records')->pageList($condition, $field, $order, $page, $page_size);
  110. return $this->success($list);
  111. }
  112. /**
  113. * 获取礼品卡使用记录项信息
  114. * @param $condition
  115. * @param string $field
  116. * @return array
  117. */
  118. public function getCardUseRecordsGoodsInfo($condition, $field = '*')
  119. {
  120. $info = model('giftcard_card_use_records_goods')->getInfo($condition, $field);
  121. return $this->success($info);
  122. }
  123. /**
  124. * 获取礼品卡使用记录项列表
  125. * @param array $condition
  126. * @param string $field
  127. * @param string $order
  128. * @param null $limit
  129. * @return array
  130. */
  131. public function getCardUseRecordsGoodsList($condition = [], $field = '*', $order = '', $limit = null)
  132. {
  133. $list = model('giftcard_card_use_records_goods')->getList($condition, $field, $order, '', '', '', $limit);
  134. return $this->success($list);
  135. }
  136. /**
  137. * 获取礼品卡使用记录项分页列表
  138. * @param array $condition
  139. * @param int $page
  140. * @param int $page_size
  141. * @param string $order
  142. * @param string $field
  143. * @return array
  144. */
  145. public function getCardUseRecordsGoodsPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '*')
  146. {
  147. $list = model('giftcard_card_use_records_goods')->pageList($condition, $field, $order, $page, $page_size);
  148. return $this->success($list);
  149. }
  150. }