GuaranteeRepository.php 3.8 KB

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