Goods.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. /**
  3. * Goods.php UTF-8
  4. * 金币(积分)兑换商品
  5. *
  6. * @date : 2018/9/28 17:56
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : chenbingling <cbl@huosdk.com>
  10. * @version : HuoMP 1.0
  11. */
  12. namespace huomp\controller\goods;
  13. use huo\model\shop\GoodsModel;
  14. use huo\model\shop\ItgOrderModel;
  15. use huolib\constant\MemItgConst;
  16. class Goods {
  17. /**
  18. * 获取条件
  19. */
  20. public function getWhere($param = []) {
  21. $_map = [];
  22. return $_map;
  23. }
  24. /**
  25. * 获取数据字段
  26. */
  27. public function getField() {
  28. $_field = [
  29. 'id' => 'good_id',
  30. 'goods_name' => 'goods_name',
  31. 'object_type' => 'object_type',
  32. 'remain_cnt' => 'remain_cnt',
  33. 'market_price' => 'market_price',
  34. 'integral' => 'integral',
  35. 'mem_times' => 'mem_times',
  36. 'original_img' => 'original_img',
  37. 'is_real' => 'is_real'
  38. ];
  39. return $_field;
  40. }
  41. /**
  42. *获取所有上架的商品
  43. *
  44. * @param array $param
  45. * @param string $page
  46. * @param string $order
  47. *
  48. * @return array
  49. */
  50. public function getList($param = [], $page = '1,10', $order = '-list_order') {
  51. $_rdata = ['count' => 0, 'list' => []];
  52. $_map = $this->getWhere($param);
  53. if (empty($_map['flag'])) {
  54. $_map['flag'] = ['neq', 5];
  55. }
  56. $_model = new GoodsModel();
  57. $_count = $_model->where($_map)->count('id');
  58. if (empty($_count)) {
  59. return $_rdata;
  60. }
  61. $_field = $this->getField();
  62. $_order = $_model->orderFilter($order);
  63. $_data = $_model->where($_map)->field($_field)->page($page)->order($_order)->select();
  64. if (is_object($_data)) {
  65. $_data = $_data->toArray();
  66. }
  67. if (empty($_data)) {
  68. return $_rdata;
  69. }
  70. $_rdata['count'] = $_count;
  71. $_rdata['list'] = $_data;
  72. return $_rdata;
  73. }
  74. /**
  75. * 获取积分兑换/抽奖记录
  76. *
  77. * @param array $param
  78. * @param string $page
  79. * @param string $order
  80. *
  81. * @return array
  82. */
  83. public function getItgLog($param = [], $page = '1,10', $order = '-id') {
  84. $_rdata = ['count' => 0, 'list' => []];
  85. $_model = new ItgOrderModel();
  86. $_count = $_model->where($param)->count('id');
  87. if (empty($_count)) {
  88. return $_rdata;
  89. }
  90. $_order = $_model->orderFilter($order);
  91. $_field = 'id, mem_id, goods_id, integral,create_time';
  92. $_item = $_model->with('goods')
  93. ->field($_field)
  94. ->where($param)
  95. ->order($_order)
  96. ->page($page)
  97. ->select();
  98. if (is_object($_item)) {
  99. $_item = $_item->toArray();
  100. }
  101. if (empty($_item)) {
  102. return $_rdata;
  103. }
  104. $_list = [];
  105. $_title = '兑换';
  106. if (MemItgConst::SHOP_FLAG_LOTTERY == $param['flag']) {
  107. $_title = '';
  108. }
  109. foreach ($_item as $_k => $_v) {
  110. $_good_name = empty($_v['goods']['goods_name']) ? '' : $_v['goods']['goods_name'];
  111. $_list[] = [
  112. 'title' => $_title.$_good_name,
  113. 'time' => date('y-m-d H:i:s', $_v['create_time']),
  114. 'integral' => $_v['integral'],
  115. ];
  116. }
  117. $_rdata['count'] = $_count;
  118. $_rdata['list'] = $_list;
  119. return $_rdata;
  120. }
  121. }