Store.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2025 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace app\admin\model;
  13. use app\common\model\Store as StoreModel;
  14. use app\admin\model\store\User as StoreUserModel;
  15. use think\model\relation\HasOne;
  16. /**
  17. * 商家记录表模型
  18. * Class Store
  19. * @package app\admin\model
  20. */
  21. class Store extends StoreModel
  22. {
  23. /**
  24. * 关联商家用户记录 (超级管理员)
  25. * @return HasOne
  26. */
  27. public function superUser(): HasOne
  28. {
  29. $module = self::getCalledModule();
  30. return $this->hasOne("app\\{$module}\\model\\store\\User")
  31. ->where('is_super', '=', 1);
  32. }
  33. /**
  34. * 获取列表数据
  35. * @param bool $isRecycle
  36. * @return \think\Paginator
  37. * @throws \think\db\exception\DbException
  38. */
  39. public function getList(bool $isRecycle = false): \think\Paginator
  40. {
  41. return $this->with(['superUser'])
  42. ->where('is_recycle', '=', (int)$isRecycle)
  43. ->where('is_delete', '=', 0)
  44. ->order(['sort' => 'asc', 'create_time' => 'desc'])
  45. ->paginate(15);
  46. }
  47. /**
  48. * 更新记录
  49. * @param array $data
  50. * @return bool|mixed
  51. */
  52. public function edit(array $data)
  53. {
  54. if (!empty($data['password']) && ($data['password'] !== $data['password_confirm'])) {
  55. $this->error = '确认密码不正确';
  56. return false;
  57. }
  58. if ($this['superUser']['user_name'] !== $data['user_name']
  59. && StoreUserModel::checkExist($data['user_name'])) {
  60. $this->error = '商家用户名已存在';
  61. return false;
  62. }
  63. return $this->transaction(function () use ($data) {
  64. // 更新商户记录
  65. $this->save(['sort' => $data['sort']]);
  66. // 更新商家用户信息
  67. (new StoreUserModel)->edit((int)$this['store_id'], $data);
  68. return true;
  69. });
  70. }
  71. /**
  72. * 移入移出回收站
  73. * @param bool $isRecycle
  74. * @return bool|false
  75. */
  76. public function recycle(bool $isRecycle = true): bool
  77. {
  78. return $this->save(['is_recycle' => (int)$isRecycle]);
  79. }
  80. }