AfterSale.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeshop100%开源免费商用商城系统
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | 商业版本务必购买商业授权,以免引起法律纠纷
  8. // | 禁止对系统程序代码以任何目的,任何形式的再发布
  9. // | gitee下载:https://gitee.com/likeshop_gitee
  10. // | github下载:https://github.com/likeshop-github
  11. // | 访问官网:https://www.likeshop.cn
  12. // | 访问社区:https://home.likeshop.cn
  13. // | 访问手册:http://doc.likeshop.cn
  14. // | 微信公众号:likeshop技术社区
  15. // | likeshop团队 版权所有 拥有最终解释权
  16. // +----------------------------------------------------------------------
  17. // | author: likeshopTeam
  18. // +----------------------------------------------------------------------
  19. namespace app\common\model;
  20. use app\common\enum\AfterSaleEnum;
  21. use app\common\service\FileService;
  22. use think\model\concern\SoftDelete;
  23. use app\common\model\User;
  24. /**
  25. * 售后类
  26. * Class AfterSale
  27. * @package app\common\model
  28. */
  29. class AfterSale extends BaseModel
  30. {
  31. use SoftDelete;
  32. /**
  33. * @notes 关联售后商品模型
  34. * @return \think\model\relation\HasOne
  35. * @author Tab
  36. * @date 2021/8/2 14:34
  37. */
  38. public function afterSaleGoods()
  39. {
  40. return $this->hasMany(AfterSaleGoods::class, 'after_sale_id', 'id')
  41. ->field('after_sale_id, order_goods_id as goods_snap');
  42. }
  43. /**
  44. * @notes 售后类型获取器
  45. * @param $value
  46. * @return string
  47. * @author Tab
  48. * @date 2021/8/2 14:37
  49. */
  50. public function getRefundTypeDescAttr($value)
  51. {
  52. $desc = [1 => '整单退款', 2 => '商品售后'];
  53. return $desc[$value] ?? '';
  54. }
  55. /**
  56. * @notes 售后方式获取器
  57. * @param $value
  58. * @return string
  59. * @author Tab
  60. * @date 2021/8/2 14:38
  61. */
  62. public function getRefundMethodDescAttr($value)
  63. {
  64. $desc = [1 => '仅退款', 2 => '退货退款'];
  65. return $desc[$value] ?? '';
  66. }
  67. /**
  68. * @notes 获取售后状态描述
  69. * @param $value
  70. * @return string
  71. * @author Tab
  72. * @date 2021/8/2 14:43
  73. */
  74. public function getStatusDescAttr($value)
  75. {
  76. return AfterSaleEnum::getStatusDesc($value);
  77. }
  78. /**
  79. * @notes 获取售后子状态描述
  80. * @param $value
  81. * @return string
  82. * @author Tab
  83. * @date 2021/8/2 14:44
  84. */
  85. public function getSubStatusDescAttr($value)
  86. {
  87. return AfterSaleEnum::getSubStatusDesc($value);
  88. }
  89. /**
  90. * @notes 商品编码搜索器
  91. * @param $query
  92. * @param $value
  93. * @param $data
  94. * @author Tab
  95. * @date 2021/8/2 17:56
  96. */
  97. public function searchGoodsInfoAttr($query, $value, $data)
  98. {
  99. if(!isset($data['goods_info']) || empty($data['goods_info'])) {
  100. return false;
  101. }
  102. $goodsId = Goods::where('name|code', 'like', '%'.$data['goods_info'].'%')->value('id');
  103. $afterSaleIds = AfterSaleGoods::where('goods_id', $goodsId)->column('after_sale_id');
  104. $query->where('as.id', 'in', $afterSaleIds);
  105. }
  106. /**
  107. * @notes 凭证修改器
  108. * @param $voucher
  109. * @return false|string
  110. * @author Tab
  111. * @date 2021/8/26 10:22
  112. */
  113. public function setVoucherAttr($voucher)
  114. {
  115. foreach($voucher as &$value) {
  116. FileService::setFileUrl($value);
  117. }
  118. if (empty($voucher)) {
  119. return '';
  120. }
  121. return json_encode($voucher, JSON_UNESCAPED_UNICODE);
  122. }
  123. /**
  124. * @notes 凭证获取器
  125. * @param $voucher
  126. * @return mixed|string
  127. * @author Tab
  128. * @date 2021/8/26 10:23
  129. */
  130. public function getVoucherAttr($voucher)
  131. {
  132. return empty($voucher) ? '' : json_decode($voucher, true);
  133. }
  134. public function getExpressNameAttr($value)
  135. {
  136. return empty($value) ? '-' : $value;
  137. }
  138. public function getInvoiceNoAttr($value)
  139. {
  140. return empty($value) ? '-' : $value;
  141. }
  142. public function getExpressTimeAttr($value)
  143. {
  144. return empty($value) ? '-' : date('Y-m-d H:i:s');
  145. }
  146. }