GiftCardInfo.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. /**
  35. * @notes 关联用户模型
  36. * @return \think\model\relation\HasOne
  37. * @author ljj
  38. * @date 2022/3/30 5:16 下午
  39. */
  40. public function user()
  41. {
  42. return $this->hasOne(User::class, 'id', 'user_id')
  43. ->field('id,sn,nickname,avatar,real_name,mobile,sex,create_time');
  44. }
  45. public function giftCard(){
  46. return $this->hasOne(GiftCard::class, 'id', 'gc_id');
  47. }
  48. /**
  49. * @notes 使用状态
  50. * @param $value
  51. * @param $data
  52. * @return string|string[]
  53. * @author ljj
  54. * @date 2022/3/30 5:38 下午
  55. */
  56. public function getIsUsedDescAttr($value, $data)
  57. {
  58. return $data['is_used'] ? '已使用' : '未使用';
  59. }
  60. public function getUsedUserNameAttr($value,$data){
  61. return $data['user_id'] ? User::where(['id'=>$data['user_id']])->value('nickname') :'';
  62. }
  63. public function getBatchNoAttr($value,$data){
  64. return $data['gc_id'] ? GiftCard::where(['id'=>$data['gc_id']])->value('date') :'';
  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 getUsedTimeAttr($value, $data)
  75. {
  76. return $data['used_time'] ? date('Y-m-d H:i:s',$data['used_time']): '';
  77. }
  78. }