AllwinUser.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. namespace app\allwin\model;
  9. use think\Model;
  10. class AllwinUser extends Model{
  11. protected $pk = 'id';
  12. //和主用户表绑定关系
  13. public function user(){
  14. return $this->hasOne('app\common\model\SystemUser','id','uid');
  15. }
  16. //查询用户所属店铺
  17. public function store(){
  18. return $this->hasOne('AllwinStore','id','store_id');
  19. }
  20. //获取用户所在店铺ID
  21. public function getUserStoreId(int $uid){
  22. return self::where(['uid' => $uid])->field('store_id')->find();
  23. }
  24. //添加或编辑
  25. public static function editer(int $uid,int $store_id){
  26. $rel = self::where(['uid' => $uid])->find();
  27. if(empty($rel)){
  28. self::insert(['uid' => $uid,'store_id' => $store_id]);
  29. }else{
  30. $rel->uid = $uid;
  31. $rel->store_id = $store_id;
  32. $rel->save();
  33. }
  34. }
  35. }