GoodsGather.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeshop开源商城系统
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | gitee下载:https://gitee.com/likeshop_gitee
  7. // | github下载:https://github.com/likeshop-github
  8. // | 访问官网:https://www.likeshop.cn
  9. // | 访问社区:https://home.likeshop.cn
  10. // | 访问手册:http://doc.likeshop.cn
  11. // | 微信公众号:likeshop技术社区
  12. // | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
  13. // | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
  14. // | 禁止对系统程序代码以任何目的,任何形式的再发布
  15. // | likeshop团队版权所有并拥有最终解释权
  16. // +----------------------------------------------------------------------
  17. // | author: likeshop.cn.team
  18. // +----------------------------------------------------------------------
  19. namespace app\common\model;
  20. use app\common\enum\GoodsEnum;
  21. use app\common\enum\YesNoEnum;
  22. use think\model\concern\SoftDelete;
  23. class GoodsGather extends BaseModel
  24. {
  25. use SoftDelete;
  26. protected $deleteTime = 'delete_time';
  27. // 设置json类型字段
  28. protected $json = ['gather_info'];
  29. // 设置JSON数据返回数组
  30. protected $jsonAssoc = true;
  31. /**
  32. * @notes 商品信息
  33. * @param $value
  34. * @param $data
  35. * @return array
  36. * @author ljj
  37. * @date 2023/3/14 2:52 下午
  38. */
  39. public function getGoodsInfoAttr($value,$data)
  40. {
  41. $result = [];
  42. if ($data['gather_status'] == YesNoEnum::YES) {
  43. // switch ($data['channel']) {
  44. // case GoodsEnum::GATHER_CHANNEL_TMALL:
  45. // case GoodsEnum::GATHER_CHANNEL_TAOBAO:
  46. // $result['goods_name'] = $data['gather_info']['data']['item']['title'];
  47. // $result['goods_image'] = isset($data['gather_info']['data']['item']['images'][0]) ? ltrim($data['gather_info']['data']['item']['images'][0],'//') : '';
  48. // $result['goods_image'] = checkHttp($result['goods_image']);
  49. // $result['is_more_sku'] = 0;
  50. // unset($data['gather_info']['data']['item']['sku'][0]);
  51. // if (count($data['gather_info']['data']['item']['sku']) > 1) {
  52. // $result['is_more_sku'] = 1;
  53. // }
  54. // break;
  55. // case GoodsEnum::GATHER_CHANNEL_JD:
  56. // $result['goods_name'] = $data['gather_info']['data']['item']['name'];
  57. // $result['goods_image'] = isset($data['gather_info']['data']['item']['images'][0]) ? ltrim($data['gather_info']['data']['item']['images'][0],'//') : '';
  58. // $result['goods_image'] = checkHttp($result['goods_image']);
  59. // $result['is_more_sku'] = 0;
  60. // if (count($data['gather_info']['data']['item']['sku']) > 1) {
  61. // $result['is_more_sku'] = 1;
  62. // }
  63. // break;
  64. // case GoodsEnum::GATHER_CHANNEL_1688:
  65. // $result['goods_name'] = $data['gather_info']['data']['title'];
  66. // $result['goods_image'] = isset($data['gather_info']['data']['images'][0]) ? ltrim($data['gather_info']['data']['images'][0],'//') : '';
  67. // $result['goods_image'] = checkHttp($result['goods_image']);
  68. // $result['is_more_sku'] = 0;
  69. // if (count($data['gather_info']['data']['skuMap']) > 1) {
  70. // $result['is_more_sku'] = 1;
  71. // }
  72. // break;
  73. // }
  74. $goods_gather_goods = GoodsGatherGoods::where(['gather_id'=>$data['id']])->findOrEmpty()->toArray();
  75. $result['goods_name'] = $goods_gather_goods['name'];
  76. $result['goods_image'] = $goods_gather_goods['goods_image'][0] ?? 0;
  77. $result['goods_image'] = checkHttp($result['goods_image']);
  78. $result['is_more_sku'] = 0;
  79. if ($goods_gather_goods['spec_type'] == 2) {
  80. $result['is_more_sku'] = 1;
  81. }
  82. }
  83. return $result;
  84. }
  85. /**
  86. * @notes 采集状态
  87. * @param $value
  88. * @param $data
  89. * @return string|string[]
  90. * @author ljj
  91. * @date 2023/3/14 2:55 下午
  92. */
  93. public function getGatherStatusDescAttr($value,$data)
  94. {
  95. return YesNoEnum::getGatherStatusDesc($data['gather_status']);
  96. }
  97. /**
  98. * @notes 采集渠道
  99. * @param $value
  100. * @param $data
  101. * @return string|string[]
  102. * @author ljj
  103. * @date 2023/3/14 2:56 下午
  104. */
  105. public function getChannelDescAttr($value,$data)
  106. {
  107. return GoodsEnum::getGatherChannelDesc($data['channel']);
  108. }
  109. }