GuaranteeRepository.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 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;
  12. use app\common\dao\store\GuaranteeDao;
  13. use app\common\repositories\BaseRepository;
  14. use app\common\repositories\store\product\ProductRepository;
  15. use FormBuilder\Factory\Elm;
  16. use think\facade\Route;
  17. class GuaranteeRepository extends BaseRepository
  18. {
  19. /**
  20. * @var GuaranteeDao
  21. */
  22. protected $dao;
  23. /**
  24. * GuaranteeRepository constructor.
  25. * @param GuaranteeDao $dao
  26. */
  27. public function __construct(GuaranteeDao $dao)
  28. {
  29. $this->dao = $dao;
  30. }
  31. /**
  32. * TODO 平台列表
  33. * @param $where
  34. * @param $page
  35. * @param $limit
  36. * @return array
  37. * @author Qinii
  38. * @day 5/17/21
  39. */
  40. public function getList($where,$page, $limit)
  41. {
  42. $query = $this->dao->getSearch($where)->order('sort DESC');
  43. $count = $query->count();
  44. $list = $query->page($page,$limit)->select();
  45. return compact('count','list');
  46. }
  47. public function select(array $where)
  48. {
  49. $list = $this->dao->getSearch($where)->field('guarantee_id,guarantee_name,guarantee_info,image')->order('sort DESC')->select();
  50. return $list;
  51. }
  52. /**
  53. * TODO 添加form
  54. * @param int|null $id
  55. * @param array $formData
  56. * @return \FormBuilder\Form
  57. * @author Qinii
  58. * @day 5/17/21
  59. */
  60. public function form(?int $id,array $formData = [])
  61. {
  62. $form = Elm::createForm(is_null($id) ? Route::buildUrl('systemGuaranteeCreate')->build() : Route::buildUrl('systemGuaranteeUpdate', ['id' => $id])->build());
  63. $form->setRule([
  64. Elm::input('guarantee_name', '服务条款')->required(),
  65. Elm::textarea('guarantee_info', '服务内容描述')->autosize([
  66. 'minRows'=>1000,
  67. ])->required(),
  68. Elm::frameImage('image', '服务条款图标(100*100px)', '/' . config('admin.admin_prefix') . '/setting/uploadPicture?field=image&type=1')->value($formData['image']??'')->modal(['modal' => false])->width('896px')->height('480px')->required(),
  69. Elm::switches('status', '是否显示', 1)->activeValue(1)->inactiveValue(0)->inactiveText('关')->activeText('开'),
  70. Elm::number('sort', '排序', 0)->precision(0)->max(99999),
  71. ]);
  72. return $form->setTitle(is_null($id) ? '添加服务条款' : '编辑服务条款')->formData($formData);
  73. }
  74. /**
  75. * TODO 编辑form
  76. * @param $id
  77. * @return \FormBuilder\Form
  78. * @author Qinii
  79. * @day 5/17/21
  80. */
  81. public function updateForm($id)
  82. {
  83. $ret = $this->dao->get($id);
  84. return $this->form($id,$ret->toArray());
  85. }
  86. /**
  87. * TODO 获取详情
  88. * @param $id
  89. * @return array|\think\Model|null
  90. * @author Qinii
  91. * @day 5/17/21
  92. */
  93. public function get($id)
  94. {
  95. $where = [
  96. $this->dao->getPk() => $id,
  97. 'is_del' => 0,
  98. ];
  99. $ret = $this->dao->getWhere($where);
  100. return $ret;
  101. }
  102. public function countGuarantee()
  103. {
  104. /**
  105. * 获取所有条款
  106. * 计算商户数量
  107. * 计算商品数量
  108. */
  109. $ret = $this->dao->getSearch(['status' => 1,'is_del' => 0])->column($this->dao->getPk());
  110. $make = app()->make(GuaranteeValueRepository::class);
  111. $makeProduct = app()->make(ProductRepository::class);
  112. if($ret){
  113. foreach ($ret as $k => $v){
  114. $item = [];
  115. $item['mer_count'] = $make->getSearch(['guarantee_id' => $v])->group('mer_id')->count('*');
  116. $template = $make->getSearch(['guarantee_id' => $v])->group('guarantee_template_id')->column('guarantee_template_id');
  117. $item['product_cout'] = $makeProduct->getSearch(['guarantee_template_id' => $template])->count('*');
  118. $item['update_time'] = date('Y-m-d H:i:s',time());
  119. $this->dao->update($v,$item);
  120. }
  121. }
  122. return ;
  123. }
  124. }