GiftCardInfo.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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\model\GiftCard;
  21. use app\common\model\User;
  22. use app\common\service\FileService;
  23. use think\model\concern\SoftDelete;
  24. /**
  25. * 积分订单模型
  26. * Class IntegralOrder
  27. * @package app\common\model
  28. */
  29. class GiftCardInfo extends BaseModel
  30. {
  31. use SoftDelete;
  32. protected $deleteTime = 'delete_time';
  33. /**
  34. * @notes 获取二维码URL
  35. * @param $value
  36. * @param $data
  37. * @return string
  38. * @author
  39. * @date
  40. */
  41. public function getQrCodeUrlAttr($value, $data)
  42. {
  43. if (!empty($data['qr_code_path'])) {
  44. return FileService::getFileUrl($data['qr_code_path']);
  45. }
  46. return '';
  47. }
  48. // ... existing code ...
  49. /**
  50. * @notes 关联用户模型
  51. * @return \think\model\relation\HasOne
  52. * @author ljj
  53. * @date 2022/3/30 5:16 下午
  54. */
  55. public function user()
  56. {
  57. return $this->hasOne(User::class, 'id', 'user_id')
  58. ->field('id,sn,nickname,avatar,real_name,mobile,sex,create_time');
  59. }
  60. public function giftCard(){
  61. return $this->hasOne(GiftCard::class, 'id', 'gc_id');
  62. }
  63. /**
  64. * @notes 使用状态
  65. * @param $value
  66. * @param $data
  67. * @return string|string[]
  68. * @author ljj
  69. * @date 2022/3/30 5:38 下午
  70. */
  71. public function getIsUsedDescAttr($value, $data)
  72. {
  73. return $data['is_used'] ? '已使用' : '未使用';
  74. }
  75. public function getUsedUserNameAttr($value,$data){
  76. return $data['user_id'] ? User::where(['id'=>$data['user_id']])->value('nickname') :'';
  77. }
  78. public function getBatchNoAttr($value,$data){
  79. return $data['gc_id'] ? GiftCard::where(['id'=>$data['gc_id']])->value('date') :'';
  80. }
  81. /**
  82. * @notes 使用状态
  83. * @param $value
  84. * @param $data
  85. * @return string|string[]
  86. * @author ljj
  87. * @date 2022/3/30 5:38 下午
  88. */
  89. public function getUsedTimeAttr($value, $data)
  90. {
  91. return $data['used_time'] ? date('Y-m-d H:i:s',$data['used_time']): '';
  92. }
  93. }