SystemMemberMiniapp.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 https://www.sapixx.com All rights reserved.
  4. * @license Licensed (http://www.apache.org/licenses/LICENSE-2.0).
  5. * @author pillar<ltmn@qq.com>
  6. *
  7. * 会员应用管理
  8. */
  9. namespace app\common\model;
  10. use app\common\model\SystemMember;
  11. use think\Model;
  12. use util\Util;
  13. class SystemMemberMiniapp extends Model{
  14. protected $pk = 'id';
  15. /**
  16. * 关联应用
  17. *
  18. * @return void
  19. */
  20. public function miniapp(){
  21. return $this->hasOne('SystemMiniapp','id','miniapp_id');
  22. }
  23. /**
  24. * 应用后台所属管理员
  25. * @return void
  26. */
  27. public function member(){
  28. return $this->hasOne('SystemMember','id','member_id');
  29. }
  30. /**
  31. * 应用绑定的用户端口创始人
  32. * @return void
  33. */
  34. public function user(){
  35. return $this->hasOne('SystemUser','id','uid');
  36. }
  37. /**
  38. * 用户购买的应用
  39. * @return void
  40. */
  41. public function order(){
  42. return $this->hasOne('SystemMemberMiniappOrder','id','miniapp_order_id');
  43. }
  44. /**
  45. * 后台添加编辑
  46. * @param array $param 数组
  47. */
  48. public static function edit(array $param){
  49. $data['member_id'] = $param['member_id'];
  50. $data['appname'] = $param['appname'];
  51. $data['update_time'] = time();
  52. if(isset($param['id']) && $param['id'] > 0){
  53. return self::where('id',$param['id'])->update($data);
  54. }else{
  55. $data['miniapp_id'] = $param['miniapp_id'];
  56. $data['miniapp_order_id'] = $param['miniapp_order_id'];
  57. $data['create_time'] = time();
  58. $last_id = self::insertGetId($data);
  59. return self::where('id',$last_id)->update(['service_id' => uuid(3,true,$last_id)]);
  60. }
  61. }
  62. /**
  63. * 用户添加编辑
  64. * @param array $param 数组
  65. */
  66. public static function editer(array $param){
  67. $data = Util::array_remove_empty($param);
  68. $data['update_time'] = time();
  69. return self::where('id',$param['id'])->update($data);
  70. }
  71. /**
  72. * 锁定用户
  73. * @param integer $id
  74. */
  75. public static function lock(int $id){
  76. $result = self::where(['id' => $id])->find();
  77. $result->is_lock = $result->is_lock ? 0 : 1;
  78. if($result->is_lock == 0){
  79. $member = SystemMember::where(['id' => $result->member_id])->field('is_lock')->find();
  80. if($member->is_lock == 1){
  81. return false;
  82. }
  83. }
  84. return $result->save();
  85. }
  86. }