GiftCardInfo.php 3.2 KB

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