ExpressRepository.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\common\repositories\store\shipping;
  12. use app\common\repositories\BaseRepository;
  13. use app\common\dao\store\shipping\ExpressDao as dao;
  14. use FormBuilder\Factory\Elm;
  15. use think\facade\Route;
  16. /**
  17. * Class ExpressRepository
  18. * @package app\common\repositories\store\shipping
  19. * @day 2020/6/13
  20. * @mixin dao
  21. */
  22. class ExpressRepository extends BaseRepository
  23. {
  24. /**
  25. * ExpressRepository constructor.
  26. * @param dao $dao
  27. */
  28. public function __construct(dao $dao)
  29. {
  30. $this->dao = $dao;
  31. }
  32. /**
  33. * @Author:Qinii
  34. * @Date: 2020/5/13
  35. * @param string $value
  36. * @param string $name
  37. * @return bool
  38. */
  39. public function nameExists(string $value,?int $id)
  40. {
  41. return $this->dao->merFieldExists('name',$value,null,$id);
  42. }
  43. /**
  44. * @Author:Qinii
  45. * @Date: 2020/5/13
  46. * @param string $value
  47. * @param $code
  48. * @return bool
  49. */
  50. public function codeExists(string $value,?int $id)
  51. {
  52. return $this->dao->merFieldExists('code',$value,null,$id);
  53. }
  54. /**
  55. * @Author:Qinii
  56. * @Date: 2020/5/13
  57. * @param int $value
  58. * @return bool
  59. */
  60. public function fieldExists(int $value)
  61. {
  62. return $this->dao->merFieldExists($this->dao->getPk(),$value);
  63. }
  64. /**
  65. * @Author:Qinii
  66. * @Date: 2020/5/13
  67. * @param array $where
  68. * @param int $page
  69. * @param int $limit
  70. * @return array
  71. */
  72. public function search(array $where,int $page, int $limit)
  73. {
  74. $query = $this->dao->search($where);
  75. $count = $query->count($this->dao->getPk());
  76. $list = $query->page($page, $limit)->select();
  77. return compact('count', 'list');
  78. }
  79. /**
  80. * @Author:Qinii
  81. * @Date: 2020/5/22
  82. * @param int $merId
  83. * @param int|null $id
  84. * @param array $formData
  85. * @return \FormBuilder\Form
  86. */
  87. public function form(int $merId, ?int $id = null, array $formData = [])
  88. {
  89. $form = Elm::createForm(is_null($id) ? Route::buildUrl('systemExpressCreate')->build() : Route::buildUrl('systemExpressUpdate', ['id' => $id])->build());
  90. $form->setRule([
  91. Elm::input('name', '快递公司名称')->required(),
  92. Elm::input('code', '快递公司编码')->required(),
  93. Elm::switches('is_show', '是否显示', 1)->activeValue(1)->inactiveValue(0)->inactiveText('关闭')->activeText('开启'),
  94. Elm::number('sort', '排序', 0),
  95. ]);
  96. return $form->setTitle(is_null($id) ? '添加快递公司' : '编辑快递公司')->formData($formData);
  97. }
  98. /**
  99. * @Author:Qinii
  100. * @Date: 2020/5/22
  101. * @param int|null $merId
  102. * @param $id
  103. * @return \FormBuilder\Form
  104. */
  105. public function updateForm(?int$merId,$id)
  106. {
  107. return $this->form($merId, $id, $this->dao->get($id, $merId)->toArray());
  108. }
  109. /**
  110. * @Author:Qinii
  111. * @Date: 2020/5/22
  112. * @param $id
  113. * @param $data
  114. * @return int
  115. */
  116. public function switchStatus($id,$data)
  117. {
  118. return $this->dao->update($id,$data);
  119. }
  120. public function options()
  121. {
  122. return $this->dao->selectWhere(['is_show' => 1], 'name label,id value')->toArray();
  123. }
  124. }