Goods.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /**
  3. * Goods.php UTF-8
  4. * 商品处理
  5. *
  6. * @date : 2018/5/7 22:43
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : wuyonghong <wyh@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace huo\controller\shop;
  13. use huo\controller\common\Base;
  14. use huo\controller\gift\Gift;
  15. use huo\controller\member\MemCache;
  16. use huo\logic\shop\GoodsLogic;
  17. use huolib\constant\MemItgConst;
  18. use huolib\status\CommonStatus;
  19. use huolib\status\ShopStatus;
  20. class Goods extends Base {
  21. /**
  22. * 获取商品
  23. *
  24. * @param array $where
  25. * @param string $page
  26. *
  27. * @param $mem_id
  28. * @param bool $can_ex
  29. *
  30. * @return array
  31. */
  32. public function getList($where = [], $page = '1,10', $mem_id, $can_ex = false) {
  33. $_order = '-list_order';
  34. $_map['is_real'] = $this->getVal($where, 'is_real', 0);
  35. if (isset($where['flag'])) {
  36. $_map['flag'] = $where['flag'];
  37. }
  38. $_integral = 0;
  39. if (!empty($mem_id) && true == $can_ex) {
  40. $_me_data = MemCache::ins()->getMeInfoById($mem_id);
  41. if (!empty($_me_data['my_integral'])) {
  42. $_integral = $_me_data['my_integral'];
  43. }
  44. }
  45. if (!empty($_integral)) {
  46. $_map['integral'] = ['gt', 0];
  47. }
  48. $_data = (new GoodsLogic())->getList($_map, $page, $_order);
  49. if (is_numeric($_data)) {
  50. return $this->huoError($_data, ShopStatus::getMsg($_data));
  51. }
  52. /*替换积分礼包相关信息*/
  53. if (!empty($_data['count'])) {
  54. foreach ($_data['list'] as $key => $goods) {
  55. if (MemItgConst::GOODS_IS_GIFT == $goods['object_name']) {
  56. $_gift_class = new Gift();
  57. $_gift_data = $_gift_class->getGiftDetail($goods['object_id'], $mem_id);
  58. if (CommonStatus::NO_ERROR == $_gift_data['code']) {
  59. $goods['integral'] = $_gift_data['data']['condition'];
  60. $goods['remain_cnt'] = $_gift_data['data']['remain_cnt'];
  61. $_data['list'][$key] = $goods;
  62. }
  63. }
  64. $_data['list'][$key]['integral'] = (int)$_data['list'][$key]['integral'];
  65. }
  66. }
  67. return $this->retSucMsg(CommonStatus::NO_ERROR, $_data);
  68. }
  69. /**
  70. * @param int $goods_id
  71. *
  72. * @return array
  73. */
  74. public function getDetail($goods_id = 0) {
  75. if (empty($goods_id)) {
  76. return $this->retErrMsg(CommonStatus::INVALID_PARAMS);
  77. }
  78. $_data = GoodsCache::ins()->getInfoByGoodsId($goods_id);
  79. return $this->retSucMsg(CommonStatus::NO_ERROR, $_data);
  80. }
  81. }