GiftCardInfo.php 3.2 KB

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