MemberHistory.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Author: 芸众商城 www.yunzshop.com
  5. * Date: 2017/2/23
  6. * Time: 上午10:43
  7. */
  8. namespace app\frontend\modules\member\models;
  9. class MemberHistory extends \app\common\models\MemberHistory
  10. {
  11. /**
  12. * 不可填充字段.
  13. *
  14. * @var array
  15. */
  16. protected $guarded = [''];
  17. public function goods()
  18. {
  19. return $this->hasOne(\app\common\modules\shop\ShopConfig::current()->get('goods.models.commodity_classification'),'id','goods_id');
  20. }
  21. /*
  22. *
  23. * @param int memberId
  24. * @param int goodsId
  25. *
  26. * @return object */
  27. public static function getHistoryByGoodsId($memberId, $goodsId)
  28. {
  29. return static::uniacid()->where('member_id', $memberId)->where('goods_id', $goodsId)->first();
  30. }
  31. /*
  32. *
  33. * @param int memberId
  34. * @param int goodsId
  35. *
  36. * @return object */
  37. public static function getHistoryById($historyId)
  38. {
  39. return static::uniacid()->where('id', $historyId)->first();
  40. }
  41. /**
  42. * Get member browsing records
  43. *
  44. * @param int $memberId 会员ID
  45. *
  46. * @return object $list */
  47. public static function getMemberHistoryList($memberId)
  48. {
  49. $data = MemberHistory::uniacid()
  50. ->where('member_id', $memberId)
  51. ->has('goods')
  52. ->with(['goods' => function ($query) {
  53. return $query->select('id', 'thumb', 'price', 'market_price', 'title');
  54. }])
  55. ->orderBy('updated_at', 'desc')
  56. ->paginate();
  57. foreach ($data as &$itme) {
  58. $itme['vip_level_status'] = $itme->goods->vip_level_status;
  59. }
  60. $data = $data->toArray();
  61. if (app('plugins')->isEnabled('point-mall')) {
  62. $data = \Yunshop\PointMall\api\models\PointMallGoodsModel::setHistoryPointGoods($data);
  63. }
  64. $data['member_histories'] = $data['data'];
  65. unset($data['data']);
  66. if (!empty($data['member_histories'])){
  67. foreach ($data['member_histories'] as &$value) {
  68. //过滤空数组
  69. if(!empty($value['goods']['thumb'])) {
  70. $value['goods']['thumb'] = yz_tomedia($value['goods']['thumb']);
  71. }
  72. }
  73. }
  74. return $data;
  75. }
  76. public static function getMemberHistoryCount($memberId)
  77. {
  78. $data = MemberHistory::uniacid()
  79. ->where('member_id', $memberId)
  80. ->has('goods')
  81. ->count();
  82. return $data;
  83. }
  84. }