StoreUser.php 1.1 KB

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