WechatQrcodeCateServices.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace app\services\wechat;
  3. use app\dao\wechat\WechatQrcodeCateDao;
  4. use app\services\BaseServices;
  5. use crmeb\exceptions\AdminException;
  6. use crmeb\services\FormBuilder as Form;
  7. use think\facade\Route as Url;
  8. /**
  9. * Class WechatQrcodeCateServices
  10. * @package app\services\wechat
  11. * @method getCateList() 分类列表
  12. */
  13. class WechatQrcodeCateServices extends BaseServices
  14. {
  15. /**
  16. * WechatQrcodeCateServices constructor.
  17. * @param WechatQrcodeCateDao $dao
  18. */
  19. public function __construct(WechatQrcodeCateDao $dao)
  20. {
  21. $this->dao = $dao;
  22. }
  23. /**
  24. * 添加编辑分类表单
  25. * @param int $id
  26. * @return array
  27. * @throws \FormBuilder\Exception\FormBuilderException
  28. * @throws \think\db\exception\DataNotFoundException
  29. * @throws \think\db\exception\DbException
  30. * @throws \think\db\exception\ModelNotFoundException
  31. */
  32. public function createForm($id = 0)
  33. {
  34. $info = $this->dao->get($id);
  35. $f[] = Form::hidden('id', $id);
  36. $f[] = Form::input('cate_name', '分类名称', $info['cate_name'] ?? '')->maxlength(30)->required();
  37. return create_form('添加分类', $f, Url::buildUrl('/app/wechat_qrcode/cate/save'), 'POST');
  38. }
  39. /**
  40. * 保存数据
  41. * @param $data
  42. * @return bool
  43. */
  44. public function saveData($data)
  45. {
  46. $id = $data['id'];
  47. $data['add_time'] = time();
  48. if ($id) {
  49. unset($data['id']);
  50. $res = $this->dao->update($id, $data);
  51. } else {
  52. $res = $this->dao->save($data);
  53. }
  54. if (!$res) throw new AdminException(100006);
  55. return true;
  56. }
  57. /**
  58. * 删除分类
  59. * @param int $id
  60. * @return bool
  61. */
  62. public function delCate($id = 0)
  63. {
  64. $count = app()->make(WechatQrcodeServices::class)->count(['cate_id' => $id]);
  65. if ($count) throw new AdminException(400454);
  66. if (!$id) throw new AdminException(100100);
  67. $res = $this->dao->update($id, ['is_del' => 1]);
  68. if (!$res) throw new AdminException(100008);
  69. return true;
  70. }
  71. }